Some question about gdb unknown memory

Pedro Alves
Fri Jun 17 13:03:38 GMT 2022

On 2022-06-17 11:40, Luis Machado via Gdb wrote:
> [switching to gdb@]
> On 5/20/22 07:51, joe jo wrote:
>> Hi
>> I met some questions when I used GDB to debugging my project. I'm writing this mail for some help.
>> At first I set up my one gdb-server and use GDB to connect it.
>> The problem happened when I use 'x' command to observe some unknown memory.
>> In my design, when gdb ask for some unknown memorys or registers, my server will return '?' or some other signal. For instance, when my gdbserver receive command 'm90000000,4' and memory after 90000002 is unknown, the server will return XXXX????. Otherwise, the server will return unknown register like 1234???000?0000 when receive 'g' command
>> However, when recieve ?, GDB will report errors like "Invalid hex digit 63".
>> I have read the source code of binutils-gdb/gdb/remote.c to find the reason of error, but I still don't know how can I notice GDB about those unknown memory.
>> In addition, I wonder how to use MI to sent the information about unknow memory to a eclipse-based front-end

What do you mean exactly by "unknown memory"?

Note this, here:

‘m addr,length’
Read length addressable memory units starting at address addr (...).



Memory contents; each byte is transmitted as a two-digit hexadecimal number. The reply may contain
fewer addressable memory units than requested if the server was able to read only part
of the region of memory.

So if GDB sends 'm90000000,4', and there's only 2 bytes available to read, you can return those two bytes.
If GDB really needs the remaining 2 bytes, then it will try to read the remaining bytes, with 'm90000002,2',
and if memory at 90000002 isn't accessible, the stub should return an error reply, and GDB will say something
like, "cannot access memory at $ADDR".

>> I look forward to hearing from you soon.
>> Joe Jo
> Only registers can have unknown/unavailable values, marked as lowercase 'x' in the register packet reply. Memory reads don't have such support, so '?' is essentially not recognized as something valid.

More information about the Gdb mailing list