From 298de8f6a3698c46c538c37dcd8f84a87e2e4095 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Wed, 3 Aug 2016 22:46:11 +0000 Subject: [PATCH] Errors compiling breakpoint conditions will cause the breakpoint not to be hit This was a shadowed variable error from the big Expression Parser plugin-ification. I also added a test case for this. llvm-svn: 277662 --- .../TestBreakpointConditions.py | 44 ++++++++++++++++++++++ lldb/source/Breakpoint/BreakpointLocation.cpp | 5 ++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py index 0d34dd8..8380159 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py @@ -36,6 +36,13 @@ class BreakpointConditionsTestCase(TestBase): self.build() self.breakpoint_conditions_python() + @skipIfWindows # Requires EE to support COFF on Windows (http://llvm.org/pr22232) + @add_test_categories(['pyapi']) + def test_breakpoint_invalid_condition_and_python_api(self): + """Use Python APIs to set breakpoint conditions.""" + self.build() + self.breakpoint_invalid_conditions_python() + def setUp(self): # Call super's setUp(). TestBase.setUp(self) @@ -186,3 +193,40 @@ class BreakpointConditionsTestCase(TestBase): value = frame0.EvaluateExpression("$0", options) self.assertTrue(value.GetError().Fail(), "Conditions should not make result variables.") process.Continue() + + def breakpoint_invalid_conditions_python(self): + """Use Python APIs to set breakpoint conditions.""" + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint on main.c by name 'c'. + breakpoint = target.BreakpointCreateByName('c', 'a.out') + #print("breakpoint:", breakpoint) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() == 1, + VALID_BREAKPOINT) + + # Set the condition on the breakpoint. + breakpoint.SetCondition('no_such_variable == not_this_one_either') + self.expect(breakpoint.GetCondition(), exe=False, + startstr = 'no_such_variable == not_this_one_either') + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # Frame #0 should be on self.line1 and the break condition should hold. + from lldbsuite.test.lldbutil import get_stopped_thread + thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") + frame0 = thread.GetFrameAtIndex(0) + var = frame0.FindValue('val', lldb.eValueTypeVariableArgument) + self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1) + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp b/lldb/source/Breakpoint/BreakpointLocation.cpp index 5baf472..e1b1af0 100644 --- a/lldb/source/Breakpoint/BreakpointLocation.cpp +++ b/lldb/source/Breakpoint/BreakpointLocation.cpp @@ -272,6 +272,8 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) return false; } + error.Clear(); + DiagnosticManager diagnostics; if (condition_hash != m_condition_hash || !m_user_expression_sp || !m_user_expression_sp->MatchesContext(exe_ctx)) @@ -282,7 +284,6 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) if (comp_unit) language = comp_unit->GetLanguage(); - Error error; m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(condition_text, nullptr, language, @@ -302,7 +303,7 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) error.SetErrorStringWithFormat("Couldn't parse conditional expression:\n%s", diagnostics.GetString().c_str()); m_user_expression_sp.reset(); - return false; + return true; } m_condition_hash = condition_hash; -- 2.7.4