Skip to content

Commit 9a36077

Browse files
authored
Fix error in unrecognized register name handling for "SBFrame.register" (#88047)
The code returned lldb.SBValue() when you passed in an unrecognized register name. But referring to "lldb" is apparently not legal within the module. I changed this to just return SBValue(), but then this construct: (lldb) script >>> for reg_set in lldb.target.process.thread[0].frames[0].register ... print(reg) Runs forever printing "No Value". The __getitem__(key) gets called with a monotonically increasing by 1 series of integers. I don't know why Python decided the class we defined should have a generator that returns positive integers in order, but we can add a more useful one here by returning an iterator over the flattened list of registers. Note, the not very aptly named "SBFrame.registers" is an iterator over register sets, not registers, so the two are not redundant.
1 parent 95fbd8d commit 9a36077

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lldb/bindings/interface/SBFrameExtensions.i

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ STRING_EXTENSION_OUTSIDE(SBFrame)
4444
def __init__(self, regs):
4545
self.regs = regs
4646

47+
def __iter__(self):
48+
return self.get_registers()
49+
50+
def get_registers(self):
51+
for i in range(0,len(self.regs)):
52+
rs = self.regs[i]
53+
for j in range (0,rs.num_children):
54+
reg = rs.GetChildAtIndex(j)
55+
yield reg
56+
4757
def __getitem__(self, key):
4858
if type(key) is str:
4959
for i in range(0,len(self.regs)):
@@ -52,7 +62,7 @@ STRING_EXTENSION_OUTSIDE(SBFrame)
5262
reg = rs.GetChildAtIndex(j)
5363
if reg.name == key: return reg
5464
else:
55-
return lldb.SBValue()
65+
return SBValue()
5666

5767
return registers_access(self.registers)
5868

lldb/test/API/python_api/frame/TestFrames.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ def test_get_arg_vals_for_call_stack(self):
7373
gpr_reg_set = lldbutil.get_GPRs(frame)
7474
pc_value = gpr_reg_set.GetChildMemberWithName("pc")
7575
self.assertTrue(pc_value, "We should have a valid PC.")
76+
# Make sure we can also get this from the "register" property:
77+
iterator_pc_value = 0
78+
found_pc = False
79+
for reg in frame.register:
80+
if reg.name == "pc":
81+
found_pc = True
82+
iterator_pc_value = int(reg.GetValue(), 0)
83+
break
84+
7685
pc_value_int = int(pc_value.GetValue(), 0)
86+
self.assertTrue(found_pc, "Found the PC value in the register list")
87+
self.assertEqual(iterator_pc_value, pc_value_int, "The methods of finding pc match")
88+
7789
# Make sure on arm targets we dont mismatch PC value on the basis of thumb bit.
7890
# Frame PC will not have thumb bit set in case of a thumb
7991
# instruction as PC.

0 commit comments

Comments
 (0)