'Aliasing memory addresses in GDB

I am looking for a way (directly or best approximation/alternative) to assign aliases to memory addresses in GDB, which would then show up with every function that prints this address (such as x, find, info proc map and so on). Ideally, I'd also be able to set some sort of a range, which would then be used together with alias, to output offsets rather than direct addresses.

For example, using imaginary commands alias and set-offset-range

(gdb) info proc mem

      0x55c10c43e000     0x55c10c44f000    0x11000        0x0 /usr/bin/htop
      0x55c10c44f000     0x55c10c47d000    0x2e000    0x11000 /usr/bin/htop
      0x55c10c47d000     0x55c10c48c000     0xf000    0x3f000 /usr/bin/htop
      0x55c10c48d000     0x55c10c492000     0x5000    0x4e000 /usr/bin/htop
      0x55c10c492000     0x55c10c493000     0x1000    0x53000 /usr/bin/htop
      0x55c10c493000     0x55c10c495000     0x2000        0x0 
      0x55c10dee7000     0x55c10e185000   0x29e000        0x0 [heap]
...

(gdb) alias 0x55c10dee7000 'heap'       <-------------------
(gdb) set-offset-range $heap 0x29e00    <-------------------
(gdb) info proc map

      0x55c10c43e000     0x55c10c44f000    0x11000        0x0 /usr/bin/htop
      0x55c10c44f000     0x55c10c47d000    0x2e000    0x11000 /usr/bin/htop
      0x55c10c47d000     0x55c10c48c000     0xf000    0x3f000 /usr/bin/htop
      0x55c10c48d000     0x55c10c492000     0x5000    0x4e000 /usr/bin/htop
      0x55c10c492000     0x55c10c493000     0x1000    0x53000 /usr/bin/htop
      0x55c10c493000     0x55c10c495000     0x2000        0x0 
               $heap     ($heap+0x29e000)   0x29e000      0x0 [heap]

(gdb) x/32xb $heap
$heap:      0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
$heap+8:    0x91    0x02    0x00    0x00    0x00    0x00    0x00    0x00

Bonus question: if I need similar output tweaks in the future - what section of GDB manual should I be looking at to learn more about it?

gdb


Solution 1:[1]

After some looking around and consulting helpful people on #gdb, turns out this isn't possible - either with gdb or Python extension API.

A workaround is to use ld to generate an artifical object file and fill it with synthetic symbols using --defsym flag, then load that object file into gdb using add-symbol-file.

I won't accept the workaround as solution, so if anyone has a better idea - bring it forth please.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Z.