在 gdb 中取消引用两次

Dereference twice in gdb

我发现自己正在执行以下操作来找到指针的位置,然后找到它指向的字符串:

// char* strings[2] = {"Hello", "Brando"};

>>> x/g $rbp-32               
0x7fffffffe0d0: 0x0000555555554a3e
>>> x/s 0x0000555555554a3e <-- manually typed in now
0x555555554a3e: "Hello"

有没有更好的方法来进行双重解引用?最后我想做一些类似的事情?

>>> xx $rbp-32
0x7fffffffe0d0: 0x0000555555554a3e: "Hello"
(gdb) p *(char**)($rbp-0x20)
 = 0x555555556004 "Hello"

(gdb) p *(char**)($rbp-0x20)@2
 = {0x555555556004 "Hello", 0x55555555600a "Brando"}

# This could easily be transformed into a user-defined command so as to avoid repetition.
(gdb) printf "0x%x: 0x%x: %s\n", ($rbp-0x20), *(char**)($rbp-0x20), *(char**)($rbp-0x20)
0xffffdb00: 0x55556004: Hello

could you please explain what the @2 does?

来自documentation

you can print the contents of array with

p *array@len
The left operand of ‘@’ must reside in memory. Array values made with ‘@’ in this way behave just like other arrays in terms of subscripting, and are coerced to pointers when used in expressions.