Custom core file

Nikolay Martyanov
2016-09-28T13:31:00Z

Hello guys!

I have a self-written bare-metal hypervisor for x86 arch and I'd like to
perform postmortem debugging of it's core (not VM, hypervisor itself!).
So the idea is to save physical memory state and later use GDB to
interpret it.

As I understand, GDB can interpret only `core files`. But I didn't found
a lot of info about this file format.
Some sources say it should be a specific ELF file with several mandatory
".note" sections.
Others say `core file` can be in any format and adaptation should be
done on BFD-level of GDB.

I looked through the code in corelow.c. Now my undestanding is somthing
like:

1. Save data section of my hypervisor
2. Save current stack state of my hypervisor
3. Save current registers state (MSR?)
4. Define "sys/user.h"-like header with layout description of above
mentioned structures
5. Using this header, implement function analog to
`trad_unix_core_file_p()` in file analog to `trad-core.c` (It translates
my `struct user` to `struct trad_core_struct`)
6. Implement functions like `supply_*regset()` in file like
`i386-myhyper-nat.c`
7. ??? (magic I didn't realized yet)
8. Profit!

Note, steps 1-3 say nothing about ELF-format. It embarrasses me...

So my question is: am I looking in a right direction? Can you point me
in to the issues in the plan (or even my understanding)?
Or may be there are any other ways to feed a raw physical memory to GDB?

Thanks,
Nikolay