Skip to content

Commit 1418677

Browse files
committed
Fix SBValue::FindValue for file static variables
This was just a thinko. The API StackFrame::GetVariableList takes a bool for "get_file_globals" which if true will also find file statics and file globals. But we only were passing that as true if the ValueType was eValueTypeVariableGlobal, which meant that we never find file statics. It's okay if we cast too wide a net when we do GetVariableList as later on we check against the ValueType to filter globals from statics. There was a test that had a whole bunch of globals and tested FindValue on all of them, but had no statics. So I just made one of the globals a file static, which verifies the fix. Differential Revision: https://reviews.llvm.org/D151392
1 parent aaa33b6 commit 1418677

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lldb/source/API/SBFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ SBValue SBFrame::FindValue(const char *name, ValueType value_type,
602602
stop_if_block_is_inlined_function,
603603
[frame](Variable *v) { return v->IsInScope(frame); },
604604
&variable_list);
605-
if (value_type == eValueTypeVariableGlobal) {
605+
if (value_type == eValueTypeVariableGlobal
606+
|| value_type == eValueTypeVariableStatic) {
606607
const bool get_file_globals = true;
607608
VariableList *frame_vars = frame->GetVariableList(get_file_globals,
608609
nullptr);

lldb/test/API/python_api/process/TestProcessAPI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_read_memory(self):
4949
)
5050
frame = thread.GetFrameAtIndex(0)
5151

52-
# Get the SBValue for the global variable 'my_char'.
53-
val = frame.FindValue("my_char", lldb.eValueTypeVariableGlobal)
52+
# Get the SBValue for the file static variable 'my_char'.
53+
val = frame.FindValue("my_char", lldb.eValueTypeVariableStatic)
5454
self.DebugSBValue(val)
5555

5656
# Due to the typemap magic (see lldb.swig), we pass in 1 to ReadMemory and
@@ -149,8 +149,8 @@ def test_write_memory(self):
149149
)
150150
frame = thread.GetFrameAtIndex(0)
151151

152-
# Get the SBValue for the global variable 'my_char'.
153-
val = frame.FindValue("my_char", lldb.eValueTypeVariableGlobal)
152+
# Get the SBValue for the static variable 'my_char'.
153+
val = frame.FindValue("my_char", lldb.eValueTypeVariableStatic)
154154
self.DebugSBValue(val)
155155

156156
# If the variable does not have a load address, there's no sense

lldb/test/API/python_api/process/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// This simple program is to test the lldb Python API related to process.
55

6-
char my_char = 'u';
6+
static char my_char = 'u';
77
char my_cstring[] = "lldb.SBProcess.ReadCStringFromMemory() works!";
88
char *my_char_ptr = (char *)"Does it work?";
99
uint32_t my_uint32 = 12345;

0 commit comments

Comments
 (0)