Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting in gdb

Tags:

gdb

Say, for example, I have a C source file with a method like foo(a) where a is a character.

I want to print the output of foo for every character is there an easier way than going through systematically and entering p foo('a') then p foo('b')?

Ideally I'd really like to script it so it's a bit quicker.

like image 982
Sam Avatar asked Jan 20 '23 01:01

Sam


2 Answers

I managed to figure it out, my code was basically:

define foo_test
    set $a = 97
    set $b = 123

    while $a < $b
        p (char)foo($a)
        set $a = $a + 1
    end
end
like image 76
Sam Avatar answered Jan 31 '23 09:01

Sam


perl -e 'foreach $i ("a" .. "z") { print "print foo('\''$i'\'')\n"; }' > /tmp/t.$$ &&
gdb --batch -x /tmp/t.$$ ./a.out ; rm -f /tmp/t.$$

You should also look into GDB Python scripting.

like image 27
Employed Russian Avatar answered Jan 31 '23 10:01

Employed Russian