如何使GDB获得堆栈跟踪可重复? [英] How to make gdb get stacktrace repeatably?
本文介绍了如何使GDB获得堆栈跟踪可重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
像
for((;;)) {
gdb -batch -n -ex 'set pagination off' -ex 'thread apply all bt' ffplay_g `pidof ffplay_g` >> /tmp/qq;
}
,但速度更快,无需每次都重新加载GDB和符号?
, but faster, without reloading GDB and symbols every time?
回溯需要由定时器,而不是由触发一些断点服用。
Backtraces need to be taken by timer, not by triggering some breakpoints.
推荐答案
所推荐的评论如果你想坚持使用gdb,那么为什么不脚本GDB会话?您的控制器进程可以睡50毫秒,再醒来,发送^ C,T A一个BT,C,然后回去睡觉。 - 杰里米·W·谢尔曼
http://vi-server.org/vi/bin/gdbdriver.pl
#!/usr/bin/perl -w
use strict;
use IPC::Open2;
my $init = "run";
my $command = "bt";
my $delay = 1;
my $need_int=0;
$init = shift @ARGV;
$delay = shift @ARGV;
$command = shift @ARGV;
die("Usage: gdbpriver.pl '' 0.1 'bt' gdb -q /path/to/proc 33344\n\tgdbdriver.pl init_command period_seconds backtrace_command startup_arguments\n") unless $ARGV[0];
my $pid = open2(\*OUT, \*IN, @ARGV);
print "pid=$pid\n";
print IN "set pagination off\n";
print IN "$init\n";
while(<OUT>) {
if (/Starting program:/) {
$need_int=1;
last;
}
last if /\(gdb\)/;
}
sub intr() {
kill 9, $pid;
exit(0);
}
$SIG{'INT'} = \&intr;
sub spipe() {
print "PIPE!\n";
}
$SIG{'PIPE'} = \&spipe;
if($need_int) {
kill 2, $pid;
}
for(;;) {
print IN "$command\n"; # backtrace
print IN "c\n"; # continue the program
while(<OUT>) {
last if /Continuing./;
print;
}
select undef, undef, undef, $delay; # sorry, nanosleep fails
print "INT\n";
kill 2, $pid; # SIGINT to gdb to make it interrupt the program
}
这篇关于如何使GDB获得堆栈跟踪可重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文