I would like to be able to set a breakpoint in GDB, and have it run to that point - and in the process, print out lines it has \"stepped through\".
Here is an exampl
As a new answer, since the previous is already hogged :) Basically, if the point is to observe execution of source (and/or assembly) code lines as the program as running - as the motivation is often for me when looking into "automatic printout" -- then, basically, a very quick way is to use GDB TUI mode; I quote:
c - gdb behavior : value optimized out - Stack Overflow #1354762
Use the GDB TUI mode. My copy of GDB enables it when I type the minus and Enter. Then type C-x 2 (that is hold down Control and press X, release both and then press 2). That will put it into split source and disassembly display. Then use stepi and nexti to move one machine instruction at a time. Use C-x o to switch between the TUI windows.
The trick here is that, even if you hit continue
- this time source will be shown and indicated on the TUI; and followed as the program runs:
... and this for me avoids many situations where I'd have to script the breakpoints in "auto-stepping context" (although there are still such situations).. Docs about TUI: TUI - Debugging with GDB
Cheers!