파이썬 gdb.execute ('...')로 등가 I는 (C에서)과 같은 구조를 가질 경우는 <code>a.x=1</code> 및 <code>a.y={2,3}</code>와 <code>a</code> lldb
typedef struct {
int x;
int[2] y;
} A;
그것의 인스턴스를 말한다.
파이썬 스크립팅에서 a.y[1]
에 액세스하려면 실제로이 매우 유연한 명령을 수행해야합니까?
script print lldb.frame.FindVariable('a').GetChildMemberWithName('y').GetChildAtIndex(1)
나는 C에서 구조체 변수의 멤버를 인쇄 할 때 나에게 도움이 함수를 작성했습니다 : 다음
command script import lldb_cmds.py
및 전화로로드 할 수 있습니다
# lldb_cmds.py
import lldb
def get_nested_val_c(vnames,idx=None):
"""
vnames is a list of strings ['a','b','c',...] that will be evaluated as if
you called
a.b.c.,...
So for [a,b,c] you get:
a.b.c
If idx is given, it is evaluated as
a.b.c[idx]
"""
try:
x=lldb.frame.FindVariable(vnames[0])
for v_ in vnames[1:]:
x=x.GetChildMemberWithName(v_)
except TypeError:
x=lldb.frame.FindVariable(vnames)
if idx == None:
return x
try:
x=x.GetChildAtIndex(idx[0])
for i_ in idx[1:]:
x=x.GetChildAtIndex(i_,False,True)
except TypeError:
x=x.GetChildAtIndex(idx)
(위와 같은) with
python lldb_cmds.get_nested_val_c[['a','y'],1)
그러나 짧은 길이 있습니까? 그래, 난 당신이
p a.y[1]
을 쓸 수 있지만 동안은 lldb에 루프가있을 것 같지 않기 때문에, 어떻게 그런 긴 문장에 의지하지 않고 변수 색인이를 인쇄 할 수 알아?
(그리고 그래 난 당신이 예를 들어 쓸 수 있습니다 알고 p *(int(*)[2])a.y
하지만 일반적으로 요구하고 있습니다.)