GDB Cannot access memory at address …

Posted on June 7, 2008 by ZDima.
Categories: Development, UNIX Dev.

I always have problem with my SuSE x86-64 machine when it come to use gdb because we are using -gstabs+ option to generate debug information.

Avery time I run GDB it will tell me that it cannot access memory:

  1. GNU gdb 6.8
  2. This GDB was configured as "x86_64-suse-linux"...Using host libthread_db library "/lib64/libthread_db.so.1".
  3.  
  4. (gdb) b main
  5. Breakpoint 1 at 0x4005c3: file t.cpp, line 12.
  6. (gdb) set args 1 2 3 4
  7. (gdb) run
  8. Starting program: /home/dmitriy/source/test/gdb/t 1 2 3 4
  9.  
  10. Breakpoint 1, main (n=Cannot access memory at address 0x8000fb6a84fc
  11. ) at t.cpp:12
  12. 12      }
  13. (gdb) p n
  14. Cannot access memory at address 0x8000fb6a84fc

So I get tired of seeing this message and unable to use gdb and decided to debug the debugger.

It did not take much time to found why address was not accessible: the GDB incorrectly calculates the address!

It suppose to get address of the variable by (rsp+offset). Unfortunately, the offset
was incorrect. Compiler set offset for something like -4, -8, etc. But GDB will read it as 0×7FFFFFF8, which is a positive number and after rsp+offset it usually goes to something like 0×8000fb6a84fc, instead of 0×7FFFfb6a84fc.

After digging the GDB code I conclude (I could be wrong) that the settings for sind-extend option is not correct for x86-64.

I found reference that indicates: The addressing modes were not dramatically changed from 32-bit mode, except that addressing was extended to 64 bits, physical addressing is now sign extended.

In the GDB source, elfxx-target.h defines elf_backend_sign_extend_vma as 0 (not sign-extended).

In order to override this settings I added into bfd/elf64-x86-64.c line:

  1. --- ../gdb-6.8.src/bfd/elf64-x86-64.c   2008-06-07 19:27:36.000000000 -0400
  2. +++ bfd/elf64-x86-64.c  2008-06-07 18:30:47.000000000 -0400
  3. @@ -3875,6 +3875,9 @@
  4. #define elf_backend_hash_symbol \
  5. elf64_x86_64_hash_symbol
  6.  
  7. +/* DZ */
  8. +#define elf_backend_sign_extend_vma            1
  9. +
  10. #include "elf64-target.h"
  11.  
  12. /* FreeBSD support.  */

After recompiling GDB I can see all variables!!!.

no comments yet.

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>