当到达断点时,gdb 不提供回溯,但它在命令文件中指定

gdb doesn't give a backtrace when a breakpoint is reached but it is specified in the commands file

我正在尝试在到达 C 代码中的一行时获取回溯。

我将命令文件提供给 gdb,它工作正常,但到达断点时没有任何反应。

我正在使用带有 gdb 版本 9.1-3 的 Debian 测试

我的代码是用 CFLAGS 编译的:

-Og -g3 -m32 -gdwarf-4 -fvar-tracking-assignments -w

gcc 版本是 (Debian 9.3.0-10) 9.3.0

使用其他版本的 dwarf 似乎没有任何区别。

我包含的命令文件是:

set confirm off
set pagination off
set logging file gdbrogue.txt
set logging overwrite on
set logging on
set breakpoint pending on
#set trace-commands on
directory /home/me/src/github/rogue-54-for-rogomatic
symbol-file -readnow /usr/local/bin/rogue
skip file hardscroll.c
skip file hashmap.c
skip file lib_addch.c
skip file lib_addstr.c
skip file lib_clreol.c
skip file lib_erase.c
skip file lib_getch.c
skip file lib_move.c
skip file lib_mvcur.c
skip file lib_refresh.c 
skip file lib_touch.c
skip file lib_tparm.c
skip file lib_tputs.c
skip file lib_winch.c
skip file lib_window.c
skip file tty_update.c
skip function look
skip function msg
skip function read
skip function unctrl
skip function __kernel_vsyscall
define my_prt_mlist
  set $current = mlist
  while ($current > 0)
      printf "curr %p  prev %p  next %p\n", $current, $current->l_prev, $current->l_next
      printf "  t_type %c\n", $current->t_type
      printf "  t_pos.y %d t_pos.x %d\n", $current->t_pos.y, $current->t_pos.x
      if ($current->t_dest > 0)
        printf "  t_dest->y %d t_dest->x %d\n", $current->t_dest->y, $current->t_dest->x
    end
  set $current = $current->l_next
  end
end
break chase.c:32 if (level == 7)
commands
    printf "player(y,x) (%d,%d)\n", player.t_pos.y, player.t_pos.x
    my_prt_mlist
end
break chase.c:455 if (level == 7)
commands
    printf "player(y,x) (%d,%d)\n", player.t_pos.y, player.t_pos.x
    my_prt_mlist
    backtrace full
end
while (level < 7)
  next
end
while (level == 7)
  step
end
while (level > 7)
  next
end

输出显示到达中断但没有回溯显示?

roomin (cp=0x582403cc) at chase.c:445
445 roomin(coord *cp) {
452   if (((cp->x > MAXCOLS) || (cp->y > MAXLINES)) ||
454     msg("in some bizarre place (%d, %d)", unc(*cp));

Breakpoint 2, roomin (cp=0x582403cc) at chase.c:455
455     return NULL;
do_chase (th=0x5823ede0) at chase.c:142
142   door = (chat(th->t_pos.y, th->t_pos.x) == DOOR);

知道我在这里做错了什么或者这是一个 gdb/gcc 错误吗?

我寻找过类似的问题和答案,但 none 似乎有这个特定问题。

谢谢! :)

好的,经过各种试验和阅读,我终于至少得到了上述脚本的修改版本。似乎 nexts 和 steps 的 while 循环覆盖了任何输出请求。当我删除列表末尾的循环时,回溯确实出现了。

新的 gdb 脚本

set confirm off
set pagination off
set logging file gdbrogue.txt
set logging overwrite on
set logging on
set breakpoint pending on
#set trace-commands on
directory /home/me/src/github/rogue-54-for-rogomatic
symbol-file -readnow /usr/local/bin/rogue
skip file hardscroll.c
skip file hashmap.c
skip file lib_addch.c
skip file lib_addstr.c
skip file lib_clreol.c
skip file lib_erase.c
skip file lib_getch.c
skip file lib_move.c
skip file lib_mvcur.c
skip file lib_refresh.c 
skip file lib_touch.c
skip file lib_tparm.c
skip file lib_tputs.c
skip file lib_winch.c
skip file lib_window.c
skip file tty_update.c
skip function look
skip function msg
skip function read
skip function unctrl
skip function __kernel_vsyscall
define my_prt_mlist
  set $current = mlist
  while ($current > 0)
      printf "curr %p  prev %p  next %p\n", $current, $current->l_prev, $current->l_next
      printf "  t_type %c\n", $current->t_type
      printf "  t_pos.y %d t_pos.x %d\n", $current->t_pos.y, $current->t_pos.x
      if ($current->t_dest > 0)
        printf "    t_dest->y %d t_dest->x %d\n", $current->t_dest->y, $current->t_dest->x
    end
  set $current = $current->l_next
  end
end
break chase.c:453 if (level == 7)
commands
    my_prt_mlist
    backtrace full
end
cont
File hardscroll.c will be skipped when stepping.
File hashmap.c will be skipped when stepping.
File lib_addch.c will be skipped when stepping.
File lib_addstr.c will be skipped when stepping.
File lib_clreol.c will be skipped when stepping.
File lib_erase.c will be skipped when stepping.
File lib_getch.c will be skipped when stepping.
File lib_move.c will be skipped when stepping.
File lib_mvcur.c will be skipped when stepping.
File lib_refresh.c will be skipped when stepping.
File lib_touch.c will be skipped when stepping.
File lib_tparm.c will be skipped when stepping.
File lib_tputs.c will be skipped when stepping.
File lib_winch.c will be skipped when stepping.
File lib_window.c will be skipped when stepping.
File tty_update.c will be skipped when stepping.
Function look will be skipped when stepping.
Function msg will be skipped when stepping.
Function read will be skipped when stepping.
Function unctrl will be skipped when stepping.
Function __kernel_vsyscall will be skipped when stepping.
Breakpoint 1 at 0x5662b9a7: file chase.c, line 454.

Breakpoint 1, roomin (cp=0x577483cc) at chase.c:454
454     msg("in some bizarre place (%d, %d)", unc(*cp));
curr 0x577483c0  prev (nil)  next 0x57748480
  t_type Z
  t_pos.y 18 t_pos.x 8
    t_dest->y 10 t_dest->x 19
curr 0x57748480  prev 0x577483c0  next 0x57747dc0
  t_type S
  t_pos.y 8 t_pos.x 19
    t_dest->y 10 t_dest->x 19
curr 0x57747dc0  prev 0x57748480  next 0x57746de0
  t_type S
  t_pos.y 9 t_pos.x 65
    t_dest->y 10 t_dest->x 19
curr 0x57746de0  prev 0x57747dc0  next 0x57748300
  t_type C
  t_pos.y 10 t_pos.x 8
    t_dest->y 542792192 t_dest->x 18
curr 0x57748300  prev 0x57746de0  next 0x577482a0
  t_type B
  t_pos.y 10 t_pos.x 47
curr 0x577482a0  prev 0x57748300  next 0x577481e0
  t_type Z
  t_pos.y 10 t_pos.x 30
curr 0x577481e0  prev 0x577482a0  next 0x57748120
  t_type R
  t_pos.y 10 t_pos.x 29
curr 0x57748120  prev 0x577481e0  next 0x577480c0
  t_type O
  t_pos.y 12 t_pos.x 37
curr 0x577480c0  prev 0x57748120  next 0x57748060
  t_type I
  t_pos.y 12 t_pos.x 39
curr 0x57748060  prev 0x577480c0  next 0x57747fa0
  t_type Z
  t_pos.y 11 t_pos.x 43
curr 0x57747fa0  prev 0x57748060  next 0x57746c00
  t_type H
  t_pos.y 10 t_pos.x 45
curr 0x57746c00  prev 0x57747fa0  next 0x57746d80
  t_type I
  t_pos.y 18 t_pos.x 15
curr 0x57746d80  prev 0x57746c00  next (nil)
  t_type L
  t_pos.y 5 t_pos.x 22
#0  roomin (cp=0x577483cc) at chase.c:454
        rp = <optimized out>
        fp = <optimized out>
#1  0x5662c3c1 in do_chase (th=0x57746de0) at chase.c:137
        cp = <optimized out>
        rer = 0x56653364 <passages+132>
        ree = <optimized out>
        mindist = 32767
        curdist = <optimized out>
        stoprun = false
        door = <optimized out>
        obj = <optimized out>
        this = {x = 65, y = 9}
#2  0x5662c74d in move_monst (tp=0x57746de0) at chase.c:68
No locals.
#3  0x5662c7f3 in runners () at chase.c:41
        tp = 0x57746de0
        next = 0x57748300
        wastarget = false
        orig_pos = {x = 8, y = 10}
#4  0x5662df79 in do_daemons (flag=2) at daemon.c:114
        dev = 0x56655e20 <d_list>
#5  0x5662de0e in command () at command.c:484
        ch = <optimized out>
        ntimes = -1
        fp = <optimized out>
        mp = <optimized out>
        countch = 115 's'
        direction = 75 'K'
        newcount = 1 '[=11=]1'
#6  0x566311b7 in playit () at main.c:322
        opts = <optimized out>
#7  0x5663162d in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at main.c:188
        env = <optimized out>
        lowtime = <optimized out>
        pid = <optimized out>
        pidfilename = "roguepid.10955", '[=11=]0' <repeats 49 times>
        pidfp = <optimized out>
[Inferior 1 (process 10955) detached]