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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With