Skip to content

Commit 50b4e96

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 (cherry picked from commit 1418677)
1 parent 761429b commit 50b4e96

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
@@ -611,7 +611,8 @@ SBValue SBFrame::FindValue(const char *name, ValueType value_type,
611611
stop_if_block_is_inlined_function,
612612
[frame](Variable *v) { return v->IsInScope(frame); },
613613
&variable_list);
614-
if (value_type == eValueTypeVariableGlobal) {
614+
if (value_type == eValueTypeVariableGlobal
615+
|| value_type == eValueTypeVariableStatic) {
615616
const bool get_file_globals = true;
616617
VariableList *frame_vars = frame->GetVariableList(get_file_globals,
617618
nullptr);

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

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

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

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

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

155155
# 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)