2013-06-26 2 views
2

이유는 잘못된 답을 얻고있다 :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 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. 

이 작업을 수행하기 위해 어떤 대안이 있는가 또한이 시도 주소의 유형을 확인하고

(gdb) python print address.type 
struct list_head * 
(gdb) python print offset.type 
struct list_head * 

에 의해 상쇄?

+0

'python diff = long (주소) - 긴 (오프셋)'이 작동합니까? – user4815162342

+0

고마워. :-) 그것은 내가 원한 정확하게 작동했다. –

답변

1

두 개의 포인터 유형 값을 뺍니다. 이것은 결과를 C에서와 같이 객체의 크기로 나눈 값입니다.

대신 "오프셋"에 포인터 유형이 아닌 정수형이 있는지 확인하십시오.

마지막 예제에서는 문자열을 빼는 중입니다. 너는 그렇게 할 수 없다. 전화를 계산에서 인쇄로 "16 진수"로 이동하면 인쇄가 작동합니다.

+0

Tromey :-) –

+0

tromey, 'print-struct-follow-pointers.py' 스크립트가 여기에 작성되었습니다. http://stackoverflow.com/questions/16787289/gdb-python-parsing-structures-each-field- and-print-them-with-proper-value-if 스크립트에서'is_pointer (v)'조건과 비슷하다면, if is_typedef (v)에 의해 하나 이상의 조건을 검사하고있다 : 'type_ = v.type.strip_typedefs()''print 'type = % s'% (type_)' 일부 구조체의 경우 올바른 유형을 인쇄하지만 일부 구조체의 경우'type = struct {...} '를 출력합니다. 정확한 이유를 찾을 수 없습니다. –

+0

해결되었습니다. :-) 익명 구조 때문에 .. !! gdb 안에 python 키워드'with'와'as'를 지원하지 않습니까? 왜 작동하지 않는거야? 코드는 http://stackoverflow.com/questions/17448736/gdb-python-why-below-code-is-not-working-under-gdb 여기에 있습니다. –