PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: gdb (GNU DeBugger) multiple 'step' script - (doesn't skip line output)  (Read 1502 times)

Bruce Huber

  • Little Newbie
  • *
  • Posts: 29

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:
Code: [Select]
# file: step_mult.gdb
# source:
# 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

    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

Sample result:
Code: [Select]
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)