Q:

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

I'm trying to get a backtrace when a line in the C code is reached.
I feed the command file to gdb and it works except for when it reaches the breakpoint nothing happens.
I am using Debian Testing with the gdb version 9.1-3
my code is compiled with the CFLAGS:
-Og -g3 -m32 -gdwarf-4 -fvar-tracking-assignments -w
gcc version is (Debian 9.3.0-10) 9.3.0
using other versions of dwarf doesn't seem to make any difference.
The file of commands I am including is :
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

the ouput shows the break being reached but no backtrace shows up?
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);

Any ideas what I am doing wrong here or is this a gdb/gcc bug?
I have looked for similar problems and answers, but none seem to have this specific issue.
Thanks!  :)

A:

Ok, after some various trials and reading I have finally gotten at least a modified version of the above script to work.  It seems that the while loops of nexts and steps override any asking of output.  When I removed the loops at the end the listing the backtrace does show up.
new gdb script
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 '\001'
#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", '\000' <repeats 49 times>
        pidfp = <optimized out>
[Inferior 1 (process 10955) detached]

