Skip to content

Commit

Permalink
[lldb/Core] Fix crash in ValueObject::CreateChildAtIndex
Browse files Browse the repository at this point in the history
The patch fixes a crash in ValueObject::CreateChildAtIndex caused by a
null pointer dereferencing. This is a corner case that is happening when
trying to dereference a variable with an incomplete type, and this same
variable doesn't have a synthetic value to get the child ValueObject.

If this happens, lldb will now return a null pointer that will results
in an error message.

rdar://65181171

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
  • Loading branch information
medismailben committed Jul 7, 2020
1 parent 9dfea03 commit 7177e63
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 56 deletions.
13 changes: 9 additions & 4 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,15 @@ ValueObject *ValueObject::CreateChildAtIndex(size_t idx,
language_flags);
}

if (!valobj && synthetic_array_member)
valobj = GetSyntheticValue()
->GetChildAtIndex(synthetic_index, synthetic_array_member)
.get();
// In case of an incomplete type, LLDB will try to use the ValueObject's
// synthetic value to create the child ValueObject.
if (!valobj && synthetic_array_member) {
if (ValueObjectSP synth_valobj_sp = GetSyntheticValue()) {
valobj = synth_valobj_sp
->GetChildAtIndex(synthetic_index, synthetic_array_member)
.get();
}
}

return valobj;
}
Expand Down
6 changes: 2 additions & 4 deletions lldb/test/API/functionalities/target_var/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include Makefile.rules
C_SOURCES := main.c

a.out: globals.ll
$(CC) $(CFLAGS) -g -c $^ -o globals.o
$(LD) $(LDFLAGS) -g globals.o -o $@
include Makefile.rules
2 changes: 2 additions & 0 deletions lldb/test/API/functionalities/target_var/TestTargetVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ def testTargetVarExpr(self):
self.build()
lldbutil.run_to_name_breakpoint(self, 'main')
self.expect("target variable i", substrs=['i', '42'])
self.expect("target variable var", patterns=['\(incomplete \*\) var = 0[xX](0)*dead'])
self.expect("target variable var[0]", error=True, substrs=["can't find global variable 'var[0]'"])
6 changes: 0 additions & 6 deletions lldb/test/API/functionalities/target_var/globals.c

This file was deleted.

42 changes: 0 additions & 42 deletions lldb/test/API/functionalities/target_var/globals.ll

This file was deleted.

7 changes: 7 additions & 0 deletions lldb/test/API/functionalities/target_var/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int i = 42;
int *p = &i;

struct incomplete;
struct incomplete *var = (struct incomplete *)0xdead;

int main() { return *p; }

0 comments on commit 7177e63

Please sign in to comment.