Hi,
I'm running a program that does processing on a file. I want to be able to supply the program with several files, and by attaching to it with gdb, I want to get a memory dump at a certain point in the code for each of the files. I want the dump for each file to go to a file with the same filename as the input file (maybe after formatting it a little, say adding a suffix)
So suppose I have a function called HereIsTheFileName(char* filename), and another function called DumpThisMemoryRegion(void* startAddr, void* endAddr), I want to do something like the following:
To get the file name to an environment variable:
- break HereIsTheFileName
- commands 1
- set $filename = malloc(strlen(filename) + 1)
- call memcpy($filename, filename, strlen(filename) + 1)
- end
Then to dump the memory to the filename I saved earlier:
- break DumpThisMemoryRegion
- commands 2
- append binary memory "%s.memory"%$filename startAddr endAddr
- end
(I would even settle for the filename as it is, without formatting, if that turns out to be the difficult part)
However, I couldn't get gdb to accept anything except an exlicit file name for the append/dump commands. when I ran "append binary memory $filename ..." I got the output in the file "/workdir/$filename". Is there any way to make gdb choose the file name at runtime?
Thanks!