Search code examples
memorymemory-managementgdbgdbserver

Why gdb needs a memory map of ram and rom of the target for debugging


please can some one guide me why gdb needs a memory map of RAM and ROM of the target for debugging.

If we enable verbose console in gdb then we can see some traces clearly showing: and also fro the ROM.

Is this memory used for code placement or for some other purpose.....please clarify me.

Thanks.


Solution

  • If you are talking about memory map defined with gdb's mem command, it's because gdb needs to know how to treat memory.

    By default it assumes it can write to all of memory and cache all of it.

    This is important for different reasons, one most common scenario being user trying to set a breakpoint. By default "software" breakpoints are used, which requires gdb to replace original instruction at address where breakpoint is set with special breakpoint instruction. If memory is read-only it can not do that, and has to use hardware breakpoints, which are limited in number or might even not be available. Having memory regions defined relieves user for having to manually select most appropriate breakpoint instruction (break/hbreak) manually, as gdb will automatically use hardware breakpoints in read-only regions.

    Details are explained in this chapter of GDB manual.