How to read a memory dump in binary from GDB?

aja*_*elu 5 linux gdb c++11

At the time of a crash I have a post crash handler where I try to dump whats in certain memory regions

auto memdump = std::fstream("FileMemDump.bin", std::ios::out | std::ios::binary);
auto memRegion = getMemoryRegion();
std::cout << "Memory region start: " << memRegion.start << " size: " << memRegion.size;
memdump.write((char*)memRegion.start, memRegion.size);
memdump.close();
Run Code Online (Sandbox Code Playgroud)

and after the file has created a core file So after I load the core in the following manner :

#gdb ./exec ./core.file
Run Code Online (Sandbox Code Playgroud)

I give the restore command; the start address is what is printed from the above log... and it fails with the following message

(gdb) restore ./FileMemDump.bin binary 0 0xFFAA0000
You can't do that without a process to debug.
Run Code Online (Sandbox Code Playgroud)

a. Are the options given to the std::fstream OK or

b. Is it possible call the gdb-dump command from with in the code (since dump from gdb can be restored)

or what I am trying to do is not feasible


EDIT:

  1. The big picture : In my process I want to use memory mapped IO -- at the time of init I allocate huge pages and mmap() it to a /dev device and similarly I mmap() the nonvolatile dimm area as well (we do not use conventional malloc)

With this ; when the process asserts/cores I am not able to access the hugepages or the non volatile dimm areas

  1. 我试图创建一个致命的钩子,将这些内存区域转储到二进制文件中。在这个问题中,我要求将这些内存区域还原到GDB核心中以检查这些内存区域

mmap()的参数

fp = open("/dev/mem", O_RDWR);
mmap(NULL,
     region.size,
     PROT_READ | PROT_WRITE,
     MAP_SHARED | MAP_NORESERVE,
     fp,
     phybaseaddr);

Run Code Online (Sandbox Code Playgroud)