爲什麼我得到錯誤的答案,在做算術運算:gdb python:如何對gdb.value進行算術運算?
(gdb) python address = gdb.parse_and_eval('&(((struct my_struct *)next->priv).wait_list)')
(gdb) python print address
0x410027a00728
(gdb) python offset = gdb.parse_and_eval('&((struct wait_list_t *)0)->list')
(gdb) python print offset
0x0
(gdb) python diff = address - offset
gdb) python print diff
0x410027a0072
同時輸出應爲0x410027a00728
。 我檢查地址的類型和
(gdb) python print address.type
struct list_head *
(gdb) python print offset.type
struct list_head *
抵消我想這也
(gdb) python y = hex(long(address))
(gdb) python print y
0x410027A14FF0L
(gdb) python z = hex(long(offset))
(gdb) python print z
0x0L
(gdb) python diff = y - z
Traceback (most recent call last):
File "<string>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Error while executing Python code.
是否有任何替代做到這一點?
'python diff = long(address) - long(offset)'有效嗎? – user4815162342
謝謝。:-)它正是我想要的。 –