gdb

What is the fastest way to find where an address is mapped in GDB?


Currently I manually go through the list of memory mappings in info proc mappings to see in what range the address falls in. Isn't there an easier way?

(gdb) i proc map
process 23912
Mapped address spaces:

      Start Addr           End Addr       Size     Offset objfile
        0x601000           0x6ce000    0xcd000        0x0 [heap]
  0x7fffe6d65000     0x7fffe6d67000     0x2000        0x0 /usr/lib64/libXau.so.6.0.0
  0x7fffe6d67000     0x7fffe6f67000   0x200000     0x2000 /usr/lib64/libXau.so.6.0.0
  0x7fffe6f67000     0x7fffe6f68000     0x1000     0x2000 /usr/lib64/libXau.so.6.0.0
  0x7fffe6f68000     0x7fffe6f69000     0x1000     0x3000 /usr/lib64/libXau.so.6.0.0
  0x7fffe6f69000     0x7fffe6f89000    0x20000        0x0 /usr/lib64/libxcb.so.1.1.0
  0x7fffe6f89000     0x7fffe7188000   0x1ff000    0x20000 /usr/lib64/libxcb.so.1.1.0
  0x7fffe7188000     0x7fffe7189000     0x1000    0x1f000 /usr/lib64/libxcb.so.1.1.0
  0x7fffe7189000     0x7fffe718a000     0x1000    0x20000 /usr/lib64/libxcb.so.1.1.0
  0x7fffe718a000     0x7fffe718c000     0x2000        0x0 /usr/lib64/libXss.so.1.0.0
  0x7fffe718c000     0x7fffe738c000   0x200000     0x2000 /usr/lib64/libXss.so.1.0.0
  0x7fffe738c000     0x7fffe738d000     0x1000     0x2000 /usr/lib64/libXss.so.1.0.0
  0x7fffe738d000     0x7fffe738e000     0x1000     0x3000 /usr/lib64/libXss.so.1.0.0
...

Solution

  • You want info sym. Here it is from different frames in the stack of a simple program:

    (gdb) info sym $pc
    _fxstat + 20 in section .text of /lib64/libc.so.6
    

    or

    (gdb) info sym $pc
    std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) + 422 in section .text of /lib64/libstdc++.so.6
    

    or

    (gdb) info sym $pc
    main + 25 in section .text of /tmp/q