- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有任何 Raspberry Pi 优化/特定的 backtrace() 实现?我正在使用标准 backtrace() 代码,但期待 my_backtrace 函数的更详细输出。
void my_backtrace(){
void *stack[10];
int n = backtrace(stack, 10);
std::cout << "Last frames==" << n << std::endl;
backtrace_symbols_fd(stack, n, STDOUT_FILENO);
}
最佳答案
//--There is list of options:
//a) backtrace in combination with abi::__cxa_demangle
//b) GDB
//c) [libunwind][1], [http://www.nongnu.org/libunwind/docs.html]
//d) libbfd-dev
//e) [backward-cpp][1], [https://github.com/bombela/backward-cpp]
//f) [libbacktrace][1], [https://github.com/ErwanLegrand/libbacktrace]
//-----------------------------------------------
#include <execinfo.h>
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sstream>
#include <sys/wait.h>
//-----------------------------------------------
//Based on GDB
//-----------------------------------------------
void print_trace_gdb() {
char pid_buf[30];
sprintf(pid_buf, "%d", getpid());
char name_buf[512];
name_buf[readlink("/proc/self/exe", name_buf, 511)]=0;
int child_pid = fork();
if (!child_pid) {
dup2(2,1); // redirect output to stderr
fprintf(stdout,"stack trace for %s pid=%s\n",name_buf, pid_buf);
execlp("gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL);
//if gdb failed to start
abort();
} else {
waitpid(child_pid,NULL,0);
}
}
//-----------------------------------------------
void rec_function(int ii)
{
if ( ii == 0 ) {std::cout << "int value==" << ii << "\n";}
else {rec_function(--ii);}
print_trace_gdb();
}
//-----------------------------------------------
int main()
{
int jj=1;
std::cout << "\n---begin test-----\n";
std::cout << "int value==" << jj << "\n";
rec_function(jj);
std::cout << "---end test-----\n";
}
Output from this code is
---begin test-----
int value==1
int value==0
stack trace for /opt/cpp/linux_backtrace_gdb pid=4181
0x00007f878b5ca4ca in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
[Current thread is 1 (process 4181)]
#0 0x00007f878b5ca4ca in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x0000000000400e69 in print_trace_gdb () at linux_backtrace_gdb.cpp:25
#2 0x0000000000400ed2 in rec_function (ii=0) at linux_backtrace_gdb.cpp:34
#3 0x0000000000400ecd in rec_function (ii=0) at linux_backtrace_gdb.cpp:33
#4 0x0000000000400f29 in main () at linux_backtrace_gdb.cpp:43
stack trace for /opt/cpp/linux_backtrace_gdb pid=4181
0x00007f878b5ca4ca in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
[Current thread is 1 (process 4181)]
#0 0x00007f878b5ca4ca in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x0000000000400e69 in print_trace_gdb () at linux_backtrace_gdb.cpp:25
#2 0x0000000000400ed2 in rec_function (ii=0) at linux_backtrace_gdb.cpp:34
#3 0x0000000000400f29 in main () at linux_backtrace_gdb.cpp:43
---end test-----
关于c++ - Raspberry Pi 优化的 backtrace(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41698803/
好的,我已经使用 Linux Dwarf ldw 库将 backtrace_symbols 输出转换为源代码和行号,但遇到了障碍。 backtrace_symbols 给出内存中的偏移量,在用作 Dw
我正在尝试让 Emacs 24.3.1 在出现错误时打开 *Backtrace* 缓冲区,但我尝试的任何方法似乎都不起作用。这包括评估 (setq debug-on-error t)、运行 toggl
当我的应用崩溃时,我使用 backtrace 和 backtrace_symbols 来收集调用堆栈。 void InstallSignalHandler(void) { signal(SIG
我在一个自定义的 malloc() 中使用了 backtrace() 函数,像这样: void *malloc(size_t size) {printf("my malloc!\n")
我正在查看 gdb 中的回溯,它看起来非常困惑,因为对标准库和 boost 进行了所有调用。例如。我在调用堆栈上看到 boost::bind 和 std::allocator,以及对标准库或 Boos
我的 iPhone 应用程序最近被 App Store 拒绝,“因为它在启动时崩溃”。但是,我无法重现此崩溃。该应用程序在模拟器和具有相同硬件和软件的设备上都能完美运行,Apple 对其进行了测试(运
在创建用于单元测试的辅助方法时,失败的控制台输出仅指示实际发生断言的行。 # Just an example method. def test_equal(a, b) assert_equal a
我按照 this post 中的描述打印了当前堆栈指针 void myFunc1(void) { char *p; char b=0x11; p = &b; print
我有一个继承自 Base 的 Derived 类,但我的其中一个函数发生了崩溃。我打开 gdb 试图弄清楚发生了什么,并试图打印出回溯。然而,当我 100% 知道路径是:Derived::func -
我有多个项目。每个项目创建自己的 so 文件。出于某种原因,回溯不会打印函数,因此会在崩溃时生成文件。 我用 -rdynamic 编译。例如:-std=c++14 -pthread -pedantic
我试图准确捕获哪个方法,或者至少是哪个类使我的代码崩溃 回溯在收到 SIGSEGV 信号后返回的消息。是不是因为崩溃的方法在另一个线程上执行,因此回溯无法这样做(请参阅我的日志的第一行 - 进程 ID
我的日志记录代码使用 backtrace() 的返回值确定当前堆栈深度(用于 pretty-print 目的),但我可以从分析中看出这是一个非常昂贵的调用。 我不认为有更便宜的方法来做到这一点?请注意
我正在开发通过 NDK 与 Android 配合使用的 native 应用程序。我需要调用backtrace()发生崩溃时的功能。问题是没有对于 NDK。 还有其他方法可以获取该回溯吗? 最佳答案 A
我有一个在 linux 64 位系统下运行的发行版服务器进程。它崩溃了并留下了一个核心转储文件。我使用 gdb 调试它是这样的: gdb svr 核心转储文件 并得到以下回溯: (gdb) where
在GDB,做backtrace full将以十进制打印所有局部变量及其值。 有没有办法以十六进制而不是十进制打印局部变量值? (我想要类似于 print/x myVar 的东西。) 最佳答案 您可能想
启用错误调试时,我遇到了 Backtrace 缓冲区中损坏文本的问题。像这样。 示例 它用日语说也许。但是,我无法理解该消息。有谁知道解决方法?我可以用英文显示消息。任何帮助,将不胜感激。提前致谢。
是否有任何 Raspberry Pi 优化/特定的 backtrace() 实现?我正在使用标准 backtrace() 代码,但期待 my_backtrace 函数的更详细输出。 void my_b
我正在运行此测试,因为我想查看程序的堆栈跟踪。下面是我的程序: public class NanoTime { public static void main (String[] args) {
在 Linux 下运行的 ARM 平台上创建回溯时,我遇到了奇怪的行为。有时回溯输出似乎已损坏,具体取决于故障之前执行的代码。 这是我的Crash.cpp代码: #include #include
Clang 编译器提供了许多有用的运行时检查,例如-fsanitize=unsigned-integer-overflow .当其中一项检查失败时,我可以打印回溯(例如使用 gdb)吗?目前我得到了问
我是一名优秀的程序员,十分优秀!