From ec4d04e507a7e2dec5f5b8739a6d4feaea0bc2f4 Mon Sep 17 00:00:00 2001 From: Eugene Leviant Date: Fri, 29 Jan 2016 12:17:09 +0000 Subject: [PATCH] Fix crash in lldb-mi when stack variable name is nullptr. This always happens when execution stops in try scope with unnamed catch clause llvm-svn: 259189 --- .../test/tools/lldb-mi/stack/TestMiStack.py | 13 +++++++++++++ .../lldbsuite/test/tools/lldb-mi/stack/main.cpp | 15 +++++++++++++++ lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp | 7 ++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py index 14dab38bb338..1ae728ef8044 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py @@ -199,7 +199,20 @@ class MiStackTestCase(lldbmi_testcase.MiTestCaseBase): self.expect("\^done,locals=\[{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") self.runCmd("-stack-list-locals --simple-values") self.expect("\^done,locals=\[{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") + + # Test -stack-list-locals in a function with catch clause, + # having unnamed parameter + # Run to BP_catch_unnamed + line = line_number('main.cpp', '// BP_catch_unnamed') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"6\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + # Test -stack-list-locals: use --no-values + self.runCmd("-stack-list-locals --no-values") + self.expect("\^done,locals=\[name=\"i\",name=\"j\"\]") @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races def test_lldbmi_stack_list_variables(self): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp b/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp index e11f83e108ec..32db32d2fd16 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +#include + struct inner { int var_d; @@ -114,6 +116,18 @@ int do_tests_with_args() return 0; } +void catch_unnamed_test() +{ + try + { + int i = 1, j = 2; + throw std::exception(); // BP_catch_unnamed + } + catch(std::exception&) + { + } +} + int main(int argc, char const *argv[]) { @@ -121,6 +135,7 @@ main(int argc, char const *argv[]) local_struct_test(); local_array_test(); local_pointer_test(); + catch_unnamed_test(); do_tests_with_args(); return 0; diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp index ef99ac9a4207..389da4eb48dc 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp @@ -452,7 +452,12 @@ CMICmnLLDBDebugSessionInfo::MIResponseForVariableInfoInternal(const VariableInfo { CMICmnMIValueTuple miValueTuple; lldb::SBValue value = vwrSBValueList.GetValueAtIndex(i); - const CMICmnMIValueConst miValueConst(value.GetName()); + // If one stops inside try block with, which catch clause type is unnamed + // (e.g std::exception&) then value name will be nullptr as well as value pointer + const char* name = value.GetName(); + if (name == nullptr) + continue; + const CMICmnMIValueConst miValueConst(name); const CMICmnMIValueResult miValueResultName("name", miValueConst); if (vbMarkArgs && vbIsArgs) {