Expanding a GDB variable for use in a loop (with dprintf)? -


i trace execution of function, printing out each line has executed - in gdb, use dprintf this. since it's big function (from line 113 line 200 in myfile.cpp), came following loop set dprintf type breakpoints on each line of function:

set $n=113 while ($n<200) dprintf myfile.cpp:$n, " myfile:testf %d\n", $n set $n=$n+1 end 

this works, when comes setting dprintf style breakpoints:

(gdb) info br num     type           disp enb address    1       dprintf        keep y   0x080a7272 in namespace::myfile::testfunc(int&)                                             @ /path/to/myfile.cpp:113         printf " myfile:testf %d\n", $n 2       dprintf        keep y   0x080a727d in namespace::myfile::testfunc(int&)                                             @ /path/to/myfile.cpp:114         printf " myfile:testf %d\n", $n ... 

... however, if doesn't work respective dprintf format string, gdb variable $n not expanded number string, wanted.

so there way expand $n variable, such dprintfs end like: printf " myfile:testf %d\n", 113, printf " myfile:testf %d\n", 114, , on?

well, turns out there's eval function (https://unix.stackexchange.com/questions/151502/how-to-save-the-result-of-printf-to-a-variable-in-gdb) helps - loop should re-written this:

set $n=113 while ($n<200) eval "dprintf myfile.cpp:%d, \" myfile:testf %d\"", $n, $n set $n=$n+1 end 

running in gdb produce dprintf breakpoints like:

1       dprintf        keep y   0x080a7272 in namespace::myfile::testfunc(int&)                                             @ /path/to/myfile.cpp:113         printf " myfile:testf 113" 

... , on, - guess - needed...


Comments

Popular posts from this blog

ruby on rails - Permission denied @ sys_fail2 - (D:/RoR/projects/grp/public/uploads/ -

c++ - nodejs socket.io closes connection before upgrading to websocket -

python - PyQt: Label not showing correct number of length -