-3

I am trying to dump the contents of a binary file, which is obtained as a raw bin content of a C struct in my embeded SW. Currently I am able to achieve this by executing the following in GDB

  1. File path/to/myelf.elf
  2. run path/to/myelf.elf
  3. Ctrl-C to send SIGINT
  4. restore path/to/mybin.bin 0xADDRESS
  5. p *(*my_c_strct) 0xADDRESS

Even though all this works without connecting to my board using JTAG, my question is why do I have to "run" the elf file and "restore" contents of the bin file to a memory and then only able to "print" my_c_struct?

In an ideal world I would like to be able to have a tool to which if I provide the following it will dump my struct content. May be there is another tool I can use in GNU tool chain for this that I am unaware of!

  1. Provide the symbol file
  2. Provide my bin dump
  3. And then print my_c_struct

Thank you ALL.

AK S
  • 174
  • 1
  • 5

1 Answers1

1

You didn't explain how you are "restoring" contents. I am guessing you use the GDB restore command.

why do I have to "run" the elf file

The restore command performs fopen/fread, and then writes target memory, and for that it needs an inferior process (which is created by the run command).

and "restore" contents of the bin file to a memory

Obviously GDB needs to somehow have access to the data to display it. One way (they way you are doing it) is to have the data in memory.

Another way is to tell GDB what the memory looked like at execution time, achieved with the core command.

Unfortunately, that command needs an actual properly formatted core file to tell it where in memory the bits were at execution time. You could package your data into a core file with a Perl script, but this is likely more trouble than it's worth.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362