def test_hide_runtime_support_values(self): self.build() _, process, _, _ = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.mm')) var_opts = lldb.SBVariablesOptions() var_opts.SetIncludeArguments(True) var_opts.SetIncludeLocals(True) var_opts.SetInScopeOnly(True) var_opts.SetIncludeStatics(False) var_opts.SetIncludeRuntimeSupportValues(False) var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget) values = self.frame().GetVariables(var_opts) def shows_var(name): for value in values: if value.name == name: return True return False # ObjC method. values = self.frame().GetVariables(var_opts) self.assertFalse(shows_var("this")) self.assertTrue(shows_var("self")) self.assertTrue(shows_var("_cmd")) self.assertTrue(shows_var("c")) process.Continue() # C++ method. values = self.frame().GetVariables(var_opts) self.assertTrue(shows_var("this")) self.assertFalse(shows_var("self")) self.assertFalse(shows_var("_cmd"))
def test_vla(self): self.build() _, process, _, _ = lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec('main.c')) # Make sure no helper expressions show up in frame variable. var_opts = lldb.SBVariablesOptions() var_opts.SetIncludeArguments(False) var_opts.SetIncludeLocals(True) var_opts.SetInScopeOnly(True) var_opts.SetIncludeStatics(False) var_opts.SetIncludeRuntimeSupportValues(False) var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget) all_locals = self.frame().GetVariables(var_opts) for value in all_locals: self.assertFalse("vla_expr" in value.name) def test(a, array): for i in range(a): self.expect("fr v vla[%d]" % i, substrs=["int", "%d" % (a - i)]) self.expect("expr vla[%d]" % i, substrs=["int", "%d" % (a - i)]) self.expect("fr v vla", substrs=array) self.expect("expr vla", error=True, substrs=["incomplete"]) test(2, ["int []", "[0] = 2, [1] = 1"]) process.Continue() test(4, ["int []", "[0] = 4, [1] = 3, [2] = 2, [3] = 1"])
def test_swift_hide_runtime_support(self): """Test that we hide runtime support values""" # This is the function to remove the custom settings in order to have a # clean slate for the next test case. def cleanup(): self.runCmd( 'settings set target.display-runtime-support-values true', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd("settings set target.display-runtime-support-values false") self.build() lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.swift')) self.expect('frame variable -d run', substrs=['_0_0'], matching=False) self.expect('frame variable -d run', substrs=['193627'], matching=True) var_opts = lldb.SBVariablesOptions() var_opts.SetIncludeArguments(True) var_opts.SetIncludeLocals(True) var_opts.SetInScopeOnly(True) var_opts.SetIncludeStatics(True) var_opts.SetIncludeRuntimeSupportValues(False) var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget) values = self.frame().GetVariables(var_opts) found = False for value in values: if '_0_0' in value.name: found = True if '$' in value.name: found = True self.assertFalse(found, "found the thing I was not expecting") var_opts.SetIncludeRuntimeSupportValues(True) values = self.frame().GetVariables(var_opts) found = False for value in values: if '_0_0' in value.name: found = True self.assertTrue(found, "not found the thing I was expecting") self.runCmd("settings set target.display-runtime-support-values true") self.expect('frame variable -d run', substrs=['_0_0'], matching=True) self.runCmd("settings set target.display-runtime-support-values false") self.expect('frame variable -d run', substrs=['_0_0'], matching=False)
def test_variable_list(self): self.build() _, process, _, _ = lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec('main.c')) # Make sure no helper expressions show up in frame variable. var_opts = lldb.SBVariablesOptions() var_opts.SetIncludeArguments(False) var_opts.SetIncludeLocals(True) var_opts.SetInScopeOnly(True) var_opts.SetIncludeStatics(False) var_opts.SetIncludeRuntimeSupportValues(False) var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget) all_locals = self.frame().GetVariables(var_opts) for value in all_locals: self.assertFalse("vla_expr" in value.name)
def test_objc_exceptions_at_throw(self): self.build() target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) self.assertTrue(target, VALID_TARGET) launch_info = lldb.SBLaunchInfo(["a.out", "0"]) lldbutil.run_to_name_breakpoint(self, "objc_exception_throw", launch_info=launch_info) self.expect( "thread list", substrs=['stopped', 'stop reason = hit Objective-C exception']) self.expect('thread exception', substrs=[ '(NSException *) exception = ', '"SomeReason"', ]) target = self.dbg.GetSelectedTarget() thread = target.GetProcess().GetSelectedThread() frame = thread.GetSelectedFrame() opts = lldb.SBVariablesOptions() opts.SetIncludeRecognizedArguments(True) variables = frame.GetVariables(opts) self.assertEqual(variables.GetSize(), 1) self.assertEqual(variables.GetValueAtIndex(0).name, "exception") self.assertEqual( variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) lldbutil.run_to_source_breakpoint(self, "// Set break point at this line.", lldb.SBFileSpec("main.mm"), launch_info=launch_info) self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) target = self.dbg.GetSelectedTarget() thread = target.GetProcess().GetSelectedThread() frame = thread.GetSelectedFrame() # No exception being currently thrown/caught at this point self.assertFalse(thread.GetCurrentException().IsValid()) self.assertFalse(thread.GetCurrentExceptionBacktrace().IsValid()) self.expect('frame variable e1', substrs=['(NSException *) e1 = ', '"SomeReason"']) self.expect('frame variable --dynamic-type no-run-target *e1', substrs=[ '(NSException) *e1 = ', 'name = ', '"ExceptionName"', 'reason = ', '"SomeReason"', 'userInfo = ', '1 key/value pair', 'reserved = ', 'nil', ]) e1 = frame.FindVariable("e1") self.assertTrue(e1) self.assertEqual(e1.type.name, "NSException *") self.assertEqual(e1.GetSummary(), '"SomeReason"') self.assertEqual( e1.GetChildMemberWithName("name").description, "ExceptionName") self.assertEqual( e1.GetChildMemberWithName("reason").description, "SomeReason") userInfo = e1.GetChildMemberWithName("userInfo").dynamic self.assertEqual(userInfo.summary, "1 key/value pair") self.assertEqual( userInfo.GetChildAtIndex(0).GetChildAtIndex(0).description, "some_key") self.assertEqual( userInfo.GetChildAtIndex(0).GetChildAtIndex(1).description, "some_value") self.assertEqual( e1.GetChildMemberWithName("reserved").description, "<nil>") self.expect('frame variable e2', substrs=['(NSException *) e2 = ', '"SomeReason"']) self.expect('frame variable --dynamic-type no-run-target *e2', substrs=[ '(NSException) *e2 = ', 'name = ', '"ThrownException"', 'reason = ', '"SomeReason"', 'userInfo = ', '1 key/value pair', 'reserved = ', ]) e2 = frame.FindVariable("e2") self.assertTrue(e2) self.assertEqual(e2.type.name, "NSException *") self.assertEqual(e2.GetSummary(), '"SomeReason"') self.assertEqual( e2.GetChildMemberWithName("name").description, "ThrownException") self.assertEqual( e2.GetChildMemberWithName("reason").description, "SomeReason") userInfo = e2.GetChildMemberWithName("userInfo").dynamic self.assertEqual(userInfo.summary, "1 key/value pair") self.assertEqual( userInfo.GetChildAtIndex(0).GetChildAtIndex(0).description, "some_key") self.assertEqual( userInfo.GetChildAtIndex(0).GetChildAtIndex(1).description, "some_value") reserved = e2.GetChildMemberWithName("reserved").dynamic self.assertGreater(reserved.num_children, 0) callStackReturnAddresses = [ reserved.GetChildAtIndex(i).GetChildAtIndex(1) for i in range(0, reserved.GetNumChildren()) if reserved.GetChildAtIndex(i).GetChildAtIndex(0).description == "callStackReturnAddresses" ][0].dynamic children = [ callStackReturnAddresses.GetChildAtIndex(i) for i in range(0, callStackReturnAddresses.num_children) ] pcs = [i.unsigned for i in children] names = [ target.ResolveSymbolContextForAddress(lldb.SBAddress( pc, target), lldb.eSymbolContextSymbol).GetSymbol().name for pc in pcs ] for n in ["objc_exception_throw", "foo(int)", "main"]: self.assertTrue( n in names, "%s is in the exception backtrace (%s)" % (n, names))
def exiting_expression_test(self, before_one_thread_timeout, unwind): """function_to_call sleeps for g_timeout microseconds, then calls pthread_exit. This test calls function_to_call with an overall timeout of 500 microseconds, and a one_thread_timeout as passed in. It also sets unwind_on_exit for the call to the unwind passed in. This allows you to have the thread exit either before the one thread timeout is passed. """ (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( self, "Break here and cause the thread to exit", self.main_source_file) # We'll continue to this breakpoint after running our expression: return_bkpt = target.BreakpointCreateBySourceRegex( "Break here to make sure the thread exited", self.main_source_file) frame = thread.frames[0] tid = thread.GetThreadID() # Find the timeout: var_options = lldb.SBVariablesOptions() var_options.SetIncludeArguments(False) var_options.SetIncludeLocals(False) var_options.SetIncludeStatics(True) value_list = frame.GetVariables(var_options) g_timeout = value_list.GetFirstValueByName("g_timeout") self.assertTrue(g_timeout.IsValid(), "Found g_timeout") error = lldb.SBError() timeout_value = g_timeout.GetValueAsUnsigned(error) self.assertTrue( error.Success(), "Couldn't get timeout value: %s" % (error.GetCString())) one_thread_timeout = 0 if (before_one_thread_timeout): one_thread_timeout = timeout_value * 2 else: one_thread_timeout = int(timeout_value / 2) options = lldb.SBExpressionOptions() options.SetUnwindOnError(unwind) options.SetOneThreadTimeoutInMicroSeconds(one_thread_timeout) options.SetTimeoutInMicroSeconds(4 * timeout_value) result = frame.EvaluateExpression("function_to_call()", options) # Make sure the thread actually exited: thread = process.GetThreadByID(tid) self.assertFalse(thread.IsValid(), "The thread exited") # Make sure the expression failed: self.assertFalse(result.GetError().Success(), "Expression failed.") # Make sure we can keep going: threads = lldbutil.continue_to_breakpoint(process, return_bkpt) if not threads: self.fail("didn't get any threads back after continuing") self.assertEqual(len(threads), 1, "One thread hit our breakpoint") thread = threads[0] frame = thread.frames[0] # Now get the return value, if we successfully caused the thread to exit # it should be 10, not 20. ret_val = frame.FindVariable("ret_val") self.assertTrue(ret_val.GetError().Success(), "Found ret_val") ret_val_value = ret_val.GetValueAsSigned(error) self.assertTrue(error.Success(), "Got ret_val's value") self.assertEqual(ret_val_value, 10, "We put the right value in ret_val")
def test_frame_recognizer_not_only_first_instruction(self): self.build() exe = self.getBuildArtifact("a.out") # Clear internal & plugins recognizers that get initialized at launch. self.runCmd("frame recognizer clear") self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) self.expect("frame recognizer list", substrs=['no matching results found.']) # Create a target. target, process, thread, _ = lldbutil.run_to_name_breakpoint( self, "foo", exe_name=exe) # Move the PC one instruction further. self.runCmd("next") # Add a frame recognizer in that target. self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo -n bar" ) # It's not applied to foo(), because frame's PC is not at the first instruction of the function. self.expect("frame recognizer info 0", substrs=['frame 0 not recognized by any recognizer']) # Add a frame recognizer with --first-instruction-only=true. self.runCmd("frame recognizer clear") self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo -n bar --first-instruction-only=true" ) # It's not applied to foo(), because frame's PC is not at the first instruction of the function. self.expect("frame recognizer info 0", substrs=['frame 0 not recognized by any recognizer']) # Now add a frame recognizer with --first-instruction-only=false. self.runCmd("frame recognizer clear") self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo -n bar --first-instruction-only=false" ) # This time it should recognize the frame. self.expect( "frame recognizer info 0", substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) opts = lldb.SBVariablesOptions() opts.SetIncludeRecognizedArguments(True) frame = thread.GetSelectedFrame() variables = frame.GetVariables(opts) self.assertEqual(variables.GetSize(), 2) self.assertEqual(variables.GetValueAtIndex(0).name, "a") self.assertEqual(variables.GetValueAtIndex(0).signed, 42) self.assertEqual( variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) self.assertEqual(variables.GetValueAtIndex(1).name, "b") self.assertEqual(variables.GetValueAtIndex(1).signed, 56) self.assertEqual( variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument)
def test_frame_recognizer_1(self): self.build() exe = self.getBuildArtifact("a.out") # Clear internal & plugins recognizers that get initialized at launch self.runCmd("frame recognizer clear") self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) self.expect("frame recognizer list", substrs=['no matching results found.']) self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo" ) self.expect( "frame recognizer list", substrs=[ '0: recognizer.MyFrameRecognizer, module a.out, symbol foo' ]) self.runCmd( "frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x" ) self.expect( "frame recognizer list", substrs=[ '1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)', '0: recognizer.MyFrameRecognizer, module a.out, symbol foo' ]) self.runCmd("frame recognizer delete 0") # Test that it deleted the recognizer with id 0. self.expect( "frame recognizer list", substrs=[ '1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)' ]) self.expect("frame recognizer list", matching=False, substrs=['MyFrameRecognizer']) # Test that an invalid index and deleting the same index again # is an error and doesn't do any changes. self.expect("frame recognizer delete 2", error=True, substrs=["error: '2' is not a valid recognizer id."]) self.expect("frame recognizer delete 0", error=True, substrs=["error: '0' is not a valid recognizer id."]) # Recognizers should have the same state as above. self.expect( "frame recognizer list", substrs=[ '1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)' ]) self.expect("frame recognizer list", matching=False, substrs=['MyFrameRecognizer']) self.runCmd("frame recognizer clear") self.expect("frame recognizer list", substrs=['no matching results found.']) self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo" ) target, process, thread, _ = lldbutil.run_to_name_breakpoint( self, "foo", exe_name=exe) frame = thread.GetSelectedFrame() self.expect("frame variable", substrs=['(int) a = 42', '(int) b = 56']) # Recognized arguments don't show up by default... variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 0) # ...unless you set target.display-recognized-arguments to 1... self.runCmd("settings set target.display-recognized-arguments 1") variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 2) # ...and you can reset it back to 0 to hide them again... self.runCmd("settings set target.display-recognized-arguments 0") variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 0) # ... or explicitly ask for them with SetIncludeRecognizedArguments(True). opts = lldb.SBVariablesOptions() opts.SetIncludeRecognizedArguments(True) variables = frame.GetVariables(opts) self.assertEqual(variables.GetSize(), 2) self.assertEqual(variables.GetValueAtIndex(0).name, "a") self.assertEqual(variables.GetValueAtIndex(0).signed, 42) self.assertEqual( variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) self.assertEqual(variables.GetValueAtIndex(1).name, "b") self.assertEqual(variables.GetValueAtIndex(1).signed, 56) self.assertEqual( variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument) self.expect( "frame recognizer info 0", substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) self.expect("frame recognizer info 999", error=True, substrs=['no frame with index 999']) self.expect("frame recognizer info 1", substrs=['frame 1 not recognized by any recognizer']) # FIXME: The following doesn't work yet, but should be fixed. """
def do_test(self): """Test that we hide runtime support values""" # This is the function to remove the custom settings in order to have a # clean slate for the next test case. def cleanup(): self.runCmd( 'settings set target.display-runtime-support-values true', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd("settings set target.display-runtime-support-values false") exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.expect('frame variable -d run', substrs=['$swift.type.T'], matching=False) self.expect('frame variable -d run', substrs=['193627'], matching=True) var_opts = lldb.SBVariablesOptions() var_opts.SetIncludeArguments(True) var_opts.SetIncludeLocals(True) var_opts.SetInScopeOnly(True) var_opts.SetIncludeStatics(True) var_opts.SetIncludeRuntimeSupportValues(False) var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget) values = self.frame.GetVariables(var_opts) found = False for value in values: if value.name == "$swift.type.T": found = True self.assertFalse(found, "found the thing I was not expecting") var_opts.SetIncludeRuntimeSupportValues(True) values = self.frame.GetVariables(var_opts) found = False for value in values: if value.name == "$swift.type.T": found = True self.assertTrue(found, "not found the thing I was expecting") self.runCmd("settings set target.display-runtime-support-values true") self.expect('frame variable -d run', substrs=['$swift.type.T'], matching=True) self.runCmd("settings set target.display-runtime-support-values false") self.expect('frame variable -d run', substrs=['$swift.type.T'], matching=False)
def test_frame_recognizer_1(self): self.build() target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) self.assertTrue(target, VALID_TARGET) self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) self.expect("frame recognizer list", substrs=['no matching results found.']) self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo" ) self.expect( "frame recognizer list", substrs=[ '0: recognizer.MyFrameRecognizer, module a.out, function foo' ]) self.runCmd( "frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x" ) self.expect( "frame recognizer list", substrs=[ '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)', '0: recognizer.MyFrameRecognizer, module a.out, function foo' ]) self.runCmd("frame recognizer delete 0") self.expect( "frame recognizer list", substrs=[ '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)' ]) self.runCmd("frame recognizer clear") self.expect("frame recognizer list", substrs=['no matching results found.']) self.runCmd( "frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo" ) lldbutil.run_break_set_by_symbol(self, "foo") self.runCmd("r") self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) process = target.GetProcess() thread = process.GetSelectedThread() frame = thread.GetSelectedFrame() self.assertEqual(frame.GetSymbol().GetName(), "foo") self.assertFalse(frame.GetLineEntry().IsValid()) self.expect("frame variable", substrs=['(int) a = 42', '(int) b = 56']) # Recognized arguments don't show up by default... variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 0) # ...unless you set target.display-recognized-arguments to 1... self.runCmd("settings set target.display-recognized-arguments 1") variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 2) # ...and you can reset it back to 0 to hide them again... self.runCmd("settings set target.display-recognized-arguments 0") variables = frame.GetVariables(lldb.SBVariablesOptions()) self.assertEqual(variables.GetSize(), 0) # ... or explicitly ask for them with SetIncludeRecognizedArguments(True). opts = lldb.SBVariablesOptions() opts.SetIncludeRecognizedArguments(True) variables = frame.GetVariables(opts) self.assertEqual(variables.GetSize(), 2) self.assertEqual(variables.GetValueAtIndex(0).name, "a") self.assertEqual(variables.GetValueAtIndex(0).signed, 42) self.assertEqual( variables.GetValueAtIndex(0).GetValueType(), lldb.eValueTypeVariableArgument) self.assertEqual(variables.GetValueAtIndex(1).name, "b") self.assertEqual(variables.GetValueAtIndex(1).signed, 56) self.assertEqual( variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument) self.expect( "frame recognizer info 0", substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) self.expect("frame recognizer info 999", error=True, substrs=['no frame with index 999']) self.expect("frame recognizer info 1", substrs=['frame 1 not recognized by any recognizer']) # FIXME: The following doesn't work yet, but should be fixed. """