• Welcome to PlanetSquires Forums.
 

gdb (GNU DeBugger) multiple 'step' script - (doesn't skip line output)

Started by Bruce Huber, December 07, 2017, 09:02:37 PM

Previous topic - Next topic

Bruce Huber

Using gdb, sometimes I 'step' into code a lot of times to see what the running sequence is.  But that is very tedious when I need to see a large amount of the execution.  So I looked for a way to automate the gdb 'step' command.  And I learned that gdb has scripts...

Note: The gdb 'step [count]' and 'continue' commands do NOT output the skipped lines.  Only 'step' gives the output of the source line that is executing and any resolved (if possible) function parameters.

gdb automated 'step' Script:
# file: step_mult.gdb
# source: https://stackoverflow.com/questions/5812411/gdb-automatic-nexting
#
# BEH - Added comments to help you (me, actually) remember how to use this script...
#
# gdb 'step' command:
#   - Runs your app one line at a time - including inside loops, etc.
#   - Displays each stepped source line with resolved function parameters, etc.
#   - 'step [count]' SKIPS the display of the next [count] source lines.
#       - But what if I want to step a lot and still see all of the results???
#       - Sure would be nice if there were something to automate that.
#
# For the times when you want to...
#   - step, step, step and see the results for all those lines...
#   - Although it is tedious to do that a lot manually (maybe 100's or 1000's of times)...
#   - TA DA !!! That's what this step_mult.gdb script is for.
#
# After loading your app in gdb - load this script and start your app running:
#   (gdb) source x?:/path?/step_mult.gdb
#   (gdb) start
#
# After gdb stops at the default breakpoint at your app's main():
#   - Either default to the $step_mult_max value (below)...
#       (gdb) step_mult
#   - Or pass the number of steps you want to auto-step this time...
#       (gdb) step_mult [count]
#   - And it will be like you manually executed gdb's 'step' that many times.
#
# Good gdb option to set when using automatic stepping:
#   Outputs all of gdb's results to gdb.txt (default) file...
#       (gdb) set logging on
#
# If $step_mult_max is > actual steps available, this script will stop when app ends.


define step_mult
    # Set max to whatever you want.
    #set $step_mult_max = 10
    set $step_mult_max = 11000
    if $argc >= 1
        set $step_mult_max = $arg0
    end

    set $step_mult_count = 0
    while ($step_mult_count < $step_mult_max)
        set $step_mult_count = $step_mult_count + 1
        # Uncomment the [printf] if you want to see 'step #N' in your output...
        #printf "step #%d\n", $step_mult_count
        step
    end
end
 

Sample result:
D:\FreeBASIC\00_BRUCE\PCG32_FULL>gdb.exe pcg__small-test.exe
GNU gdb (GDB) 7.6.1
... (deleted gdb boilerplate text)

Reading symbols from D:\FreeBASIC\00_BRUCE\PCG32_FULL\pcg__small-test.exe...done.

(gdb) source step_mult.gdb
(gdb) start

Temporary breakpoint 1 at 0x403a0c: file D:\FreeBASIC\00_BRUCE\PCG32_FULL\pcg__small-test.bas, line 5.
Starting program: D:\FreeBASIC\00_BRUCE\PCG32_FULL/pcg__small-test.exe
[New Thread 23620.0x69c4]
[New Thread 23620.0x6854]

Temporary breakpoint 1, main (__FB_ARGC__=<error reading variable>, __FB_ARGV__=<error reading variable>)
    at D:\FreeBASIC\00_BRUCE\PCG32_FULL\pcg__small-test.bas:5
5       dim rounds as long = 5

(gdb) step_mult 5
6       dim as pcg32_random_t rng
8       pcg_setseq_64_srandom_r(@rng, 42u, 54u)
PCG_SETSEQ_64_SRANDOM_R (RNG=<error reading variable>, INITSTATE=<error reading variable>, INITSEQ=<error reading variable>) at D:\FREEBASIC\00_BRUCE\PCG32_FULL\PCG_VARIANTS.BI:275
275        rng->state = 0u
276        rng->inc = (initseq shl 1u) or 1u
277        pcg_setseq_64_step_r(rng)
(gdb)