Scripts in 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 foo for each character, is there an easier way than systematic and input p foo('a') , then p foo('b') ?

Ideally, I would really like the script to do this a little faster.

+4
source share
3 answers

I managed to find 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 
+7
source
 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 learn the Python GDB script.

+2
source

It looks like the first thing you should add is some “Breakpoint command lists”, they will let you run some gdb commands after the breakpoint hits.

So, if you add so that your print start is executed when someone calls the foo functions, you should be close.

0
source

Source: https://habr.com/ru/post/1347200/


All Articles