GDB script too slow, need help/suggestions
I am writing a gdb script to analyse a core file. The purpose of whom is as follows:
1] I am looking for packets which are scattered in the 64Mb space. The packet has a magic number of 4 bytes. Hence I have to read 4 bytes at a time. 2] I have to read a total of 64Mb of data starting from a given address. 3] Once i find the packet I should print the deatils of the packet and continue looking for other packets. 4]开发者_运维问答 Hence in my script the main loop runs for 64*1024*1024/4 =16777216 times in the worse case. Whats the problem: The script is taking about 3 hours or more which is totally impractical. I am assuming this is because its a interpreted language, also the number of loops is pretty large. Any suggestions/improvements are welcome. Kindly help me here.If you think the problem is with gdb being slow you could dump the memory area you are interested in with "dump binary memory" then use a small program written in whatever you think will be faster to analyse the dump.
the find command should do everything you want, without having to loop every 4 bytes or so, it stores the address of the last found packet in $_ (untested, but should be something to the effect of)
(gdb) python x = list()
(gdb) set $start_addr = 0x....
(gdb) set $last_end = $start_addr
(gdb) set $_ = $start_addr+1
(gdb) while $_ != $last_end
>find $last_end, $start_addr + 64*1024*1024, 0x42
>set $last_end = $_
>python x.append(gdb.parse_and_eval("$_"))
>end
(gdb) python print map(lambda(y): str(y), x)
if you don't have python you can use set logging overwrite off,set logging on,print,set logging off
精彩评论