| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 1 | """Test calling functions in static methods with a stripped binary.""" | 
|  | 2 |  | 
|  | 3 | import os, time | 
|  | 4 | import unittest2 | 
|  | 5 | import lldb | 
|  | 6 | import lldbutil | 
|  | 7 | from lldbtest import * | 
|  | 8 |  | 
|  | 9 | class TestObjCStaticMethodStripped(TestBase): | 
|  | 10 |  | 
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 11 | mydir = TestBase.compute_mydir(__file__) | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 12 |  | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 13 | def setUp(self): | 
|  | 14 | # Call super's setUp(). | 
|  | 15 | TestBase.setUp(self) | 
|  | 16 | # Find the line numbers to break inside main(). | 
|  | 17 | self.main_source = "static.m" | 
|  | 18 | self.break_line = line_number(self.main_source, '// Set breakpoint here.') | 
|  | 19 |  | 
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame^] | 20 | @skipUnlessDarwin | 
|  | 21 | @python_api_test | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 22 | #<rdar://problem/12042992> | 
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame^] | 23 | def test_with_python_api(self): | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 24 | """Test calling functions in static methods with a stripped binary.""" | 
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame^] | 25 | if self.getArchitecture() == 'i386': | 
|  | 26 | self.skipTest("requires modern objc runtime") | 
|  | 27 | self.build() | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 28 | exe = os.path.join(os.getcwd(), "a.out.stripped") | 
|  | 29 |  | 
|  | 30 | target = self.dbg.CreateTarget(exe) | 
|  | 31 | self.assertTrue(target, VALID_TARGET) | 
|  | 32 |  | 
|  | 33 | bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) | 
|  | 34 | self.assertTrue(bpt, VALID_BREAKPOINT) | 
|  | 35 |  | 
|  | 36 | # Now launch the process, and do not stop at entry point. | 
| Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 37 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) | 
| Sean Callanan | 7f5ac65 | 2013-04-24 19:07:29 +0000 | [diff] [blame] | 38 |  | 
|  | 39 | self.assertTrue(process, PROCESS_IS_VALID) | 
|  | 40 |  | 
|  | 41 | # The stop reason of the thread should be breakpoint. | 
|  | 42 | thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt) | 
|  | 43 |  | 
|  | 44 | # Make sure we stopped at the first breakpoint. | 
|  | 45 | self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") | 
|  | 46 | self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") | 
|  | 47 |  | 
|  | 48 | # Now make sure we can call a function in the static method we've stopped in. | 
|  | 49 | frame = thread_list[0].GetFrameAtIndex(0) | 
|  | 50 | self.assertTrue (frame, "Got a valid frame 0 frame.") | 
|  | 51 |  | 
|  | 52 | cmd_value = frame.EvaluateExpression ("(char *) sel_getName (_cmd)") | 
|  | 53 | self.assertTrue (cmd_value.IsValid()) | 
|  | 54 | sel_name = cmd_value.GetSummary() | 
|  | 55 | self.assertTrue (sel_name == "\"doSomethingWithString:\"", "Got the right value for the selector as string.") | 
|  | 56 |  | 
|  | 57 | cmd_value = frame.EvaluateExpression ("[Foo doSomethingElseWithString:string]") | 
|  | 58 | self.assertTrue (cmd_value.IsValid()) | 
|  | 59 | string_length = cmd_value.GetValueAsUnsigned() | 
|  | 60 | self.assertTrue (string_length == 27, "Got the right value from another class method on the same class.") | 
|  | 61 |  | 
|  | 62 | if __name__ == '__main__': | 
|  | 63 | import atexit | 
|  | 64 | lldb.SBDebugger.Initialize() | 
|  | 65 | atexit.register(lambda: lldb.SBDebugger.Terminate()) | 
|  | 66 | unittest2.main() |