2010-09-18 06:28:51 +08:00
|
|
|
"""
|
|
|
|
Set breakpoints on objective-c class and instance methods in foundation.
|
|
|
|
Also lookup objective-c data types and evaluate expressions.
|
|
|
|
"""
|
2010-09-17 04:54:06 +08:00
|
|
|
|
|
|
|
import os, time
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
|
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
|
|
|
class FoundationTestCase(TestBase):
|
|
|
|
|
|
|
|
mydir = "foundation"
|
|
|
|
|
2010-09-18 05:14:02 +08:00
|
|
|
def test_break_with_dsym(self):
|
2011-04-12 13:54:46 +08:00
|
|
|
"""Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
|
2010-09-17 04:54:06 +08:00
|
|
|
self.buildDsym()
|
|
|
|
self.break_on_objc_methods()
|
|
|
|
|
2010-09-18 05:14:02 +08:00
|
|
|
def test_break_with_dwarf(self):
|
2011-04-12 13:54:46 +08:00
|
|
|
"""Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
|
2010-09-17 04:54:06 +08:00
|
|
|
self.buildDwarf()
|
|
|
|
self.break_on_objc_methods()
|
|
|
|
|
2010-10-16 07:35:32 +08:00
|
|
|
#@unittest2.expectedFailure
|
2010-10-13 05:20:11 +08:00
|
|
|
# rdar://problem/8542091
|
2010-09-30 01:58:12 +08:00
|
|
|
# rdar://problem/8492646
|
2010-09-18 06:28:51 +08:00
|
|
|
def test_data_type_and_expr_with_dsym(self):
|
|
|
|
"""Lookup objective-c data types and evaluate expressions."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.data_type_and_expr_objc()
|
|
|
|
|
2010-10-16 07:35:32 +08:00
|
|
|
#@unittest2.expectedFailure
|
2010-10-13 05:20:11 +08:00
|
|
|
# rdar://problem/8542091
|
2010-09-30 01:58:12 +08:00
|
|
|
# rdar://problem/8492646
|
2010-09-18 06:28:51 +08:00
|
|
|
def test_data_type_and_expr_with_dwarf(self):
|
|
|
|
"""Lookup objective-c data types and evaluate expressions."""
|
|
|
|
self.buildDwarf()
|
|
|
|
self.data_type_and_expr_objc()
|
|
|
|
|
2010-12-16 04:47:34 +08:00
|
|
|
@python_api_test
|
|
|
|
def test_print_ivars_correctly_with_dsym (self):
|
|
|
|
self.buildDsym()
|
|
|
|
self.print_ivars_correctly()
|
|
|
|
|
|
|
|
@python_api_test
|
|
|
|
def test_print_ivars_correctly_with_dwarf (self):
|
|
|
|
self.buildDwarf()
|
|
|
|
self.print_ivars_correctly()
|
|
|
|
|
2010-09-17 04:54:06 +08:00
|
|
|
def break_on_objc_methods(self):
|
2011-04-12 13:54:46 +08:00
|
|
|
"""Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
|
2010-09-17 04:54:06 +08:00
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
# Stop at +[NSString stringWithFormat:].
|
2011-04-12 13:54:46 +08:00
|
|
|
self.expect("_regexp-break +[NSString stringWithFormat:]", BREAKPOINT_CREATED,
|
2010-10-13 03:29:49 +08:00
|
|
|
substrs = ["Breakpoint created: 1: name = '+[NSString stringWithFormat:]', locations = 1"])
|
2010-09-17 04:54:06 +08:00
|
|
|
|
2010-09-17 07:57:33 +08:00
|
|
|
# Stop at -[MyString initWithNSString:].
|
|
|
|
self.expect("breakpoint set -n '-[MyString initWithNSString:]'", BREAKPOINT_CREATED,
|
|
|
|
startstr = "Breakpoint created: 2: name = '-[MyString initWithNSString:]', locations = 1")
|
|
|
|
|
|
|
|
# Stop at the "description" selector.
|
|
|
|
self.expect("breakpoint set -S description", BREAKPOINT_CREATED,
|
|
|
|
startstr = "Breakpoint created: 3: name = 'description', locations = 1")
|
|
|
|
|
2010-09-17 04:54:06 +08:00
|
|
|
# Stop at -[NSAutoreleasePool release].
|
2011-04-12 13:54:46 +08:00
|
|
|
self.expect("_regexp-break -[NSAutoreleasePool release]", BREAKPOINT_CREATED,
|
2010-10-13 03:29:49 +08:00
|
|
|
substrs = ["Breakpoint created: 4: name = '-[NSAutoreleasePool release]', locations = 1"])
|
2010-09-17 04:54:06 +08:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# First stop is +[NSString stringWithFormat:].
|
|
|
|
self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]",
|
|
|
|
substrs = ["Foundation`+[NSString stringWithFormat:]"])
|
|
|
|
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
2010-12-07 06:09:04 +08:00
|
|
|
# Second stop is still +[NSString stringWithFormat:].
|
|
|
|
self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]",
|
|
|
|
substrs = ["Foundation`+[NSString stringWithFormat:]"])
|
|
|
|
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
2010-09-17 07:57:33 +08:00
|
|
|
# Followed by a.out`-[MyString initWithNSString:].
|
|
|
|
self.expect("thread backtrace", "Stop at a.out`-[MyString initWithNSString:]",
|
|
|
|
substrs = ["a.out`-[MyString initWithNSString:]"])
|
|
|
|
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
|
|
|
# Followed by -[MyString description].
|
|
|
|
self.expect("thread backtrace", "Stop at -[MyString description]",
|
|
|
|
substrs = ["a.out`-[MyString description]"])
|
|
|
|
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
2010-12-07 06:09:04 +08:00
|
|
|
# Followed by the same -[MyString description].
|
|
|
|
self.expect("thread backtrace", "Stop at -[MyString description]",
|
|
|
|
substrs = ["a.out`-[MyString description]"])
|
|
|
|
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
2010-09-17 04:54:06 +08:00
|
|
|
# Followed by -[NSAutoreleasePool release].
|
|
|
|
self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]",
|
|
|
|
substrs = ["Foundation`-[NSAutoreleasePool release]"])
|
|
|
|
|
2010-10-13 05:20:11 +08:00
|
|
|
def setUp(self):
|
2010-10-15 01:31:24 +08:00
|
|
|
# Call super's setUp().
|
|
|
|
TestBase.setUp(self)
|
2010-10-13 05:20:11 +08:00
|
|
|
# Find the line number to break inside main().
|
2010-12-16 04:47:34 +08:00
|
|
|
self.main_source = "main.m"
|
|
|
|
self.line = line_number(self.main_source, '// Set break point at this line.')
|
2010-10-13 05:20:11 +08:00
|
|
|
|
2010-09-18 06:28:51 +08:00
|
|
|
def data_type_and_expr_objc(self):
|
|
|
|
"""Lookup objective-c data types and evaluate expressions."""
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
# Stop at -[MyString description].
|
|
|
|
self.expect("breakpoint set -n '-[MyString description]", BREAKPOINT_CREATED,
|
|
|
|
startstr = "Breakpoint created: 1: name = '-[MyString description]', locations = 1")
|
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# The backtrace should show we stop at -[MyString description].
|
|
|
|
self.expect("thread backtrace", "Stop at -[MyString description]",
|
|
|
|
substrs = ["a.out`-[MyString description]"])
|
|
|
|
|
|
|
|
# Lookup objc data type MyString and evaluate some expressions.
|
|
|
|
|
|
|
|
self.expect("image lookup -t NSString", DATA_TYPES_DISPLAYED_CORRECTLY,
|
2010-09-30 01:50:35 +08:00
|
|
|
substrs = ['name = "NSString"',
|
2010-10-13 05:20:11 +08:00
|
|
|
'clang_type = "@interface NSString'])
|
2010-09-18 06:28:51 +08:00
|
|
|
|
|
|
|
self.expect("image lookup -t MyString", DATA_TYPES_DISPLAYED_CORRECTLY,
|
2010-09-30 01:50:35 +08:00
|
|
|
substrs = ['name = "MyString"',
|
2010-10-13 05:20:11 +08:00
|
|
|
'clang_type = "@interface MyString',
|
|
|
|
'NSString * str;',
|
|
|
|
'NSDate * date;'])
|
2010-09-18 06:28:51 +08:00
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
self.expect("frame variable -T -s", VARIABLES_DISPLAYED_CORRECTLY,
|
2010-10-02 07:34:28 +08:00
|
|
|
substrs = ["ARG: (MyString *) self"],
|
|
|
|
patterns = ["ARG: \(.*\) _cmd",
|
|
|
|
"(struct objc_selector *)|(SEL)"])
|
2010-09-18 06:28:51 +08:00
|
|
|
|
2010-11-12 03:15:04 +08:00
|
|
|
# rdar://problem/8651752
|
|
|
|
# don't crash trying to ask clang how many children an empty record has
|
|
|
|
self.runCmd("frame variable *_cmd")
|
|
|
|
|
2010-09-30 01:58:12 +08:00
|
|
|
# rdar://problem/8492646
|
|
|
|
# test/foundation fails after updating to tot r115023
|
|
|
|
# self->str displays nothing as output
|
2011-05-04 11:43:18 +08:00
|
|
|
self.expect("frame variable -T self->str", VARIABLES_DISPLAYED_CORRECTLY,
|
2010-09-18 06:28:51 +08:00
|
|
|
startstr = "(NSString *) self->str")
|
|
|
|
|
|
|
|
# rdar://problem/8447030
|
|
|
|
# 'frame variable self->date' displays the wrong data member
|
2011-05-04 11:43:18 +08:00
|
|
|
self.expect("frame variable -T self->date", VARIABLES_DISPLAYED_CORRECTLY,
|
2010-09-18 06:28:51 +08:00
|
|
|
startstr = "(NSDate *) self->date")
|
|
|
|
|
2010-10-13 05:20:11 +08:00
|
|
|
# This should display the str and date member fields as well.
|
2011-05-04 11:43:18 +08:00
|
|
|
self.expect("frame variable -T *self", VARIABLES_DISPLAYED_CORRECTLY,
|
2010-12-16 06:50:54 +08:00
|
|
|
substrs = ["(MyString) *self",
|
2010-10-13 05:20:11 +08:00
|
|
|
"(NSString *) str",
|
|
|
|
"(NSDate *) date"])
|
|
|
|
|
|
|
|
# This should fail expectedly.
|
2010-10-19 08:52:07 +08:00
|
|
|
self.expect("expression self->non_existent_member",
|
|
|
|
COMMAND_FAILED_AS_EXPECTED, error=True,
|
2010-10-13 05:20:11 +08:00
|
|
|
startstr = "error: 'MyString' does not have a member named 'non_existent_member'")
|
|
|
|
|
|
|
|
# Use expression parser.
|
2010-11-12 08:55:31 +08:00
|
|
|
self.runCmd("expression self->str")
|
|
|
|
self.runCmd("expression self->date")
|
2010-09-30 02:05:03 +08:00
|
|
|
|
2010-10-19 08:52:07 +08:00
|
|
|
# (lldb) expression self->str
|
2010-10-13 05:20:11 +08:00
|
|
|
# error: instance variable 'str' is protected
|
2010-09-18 06:28:51 +08:00
|
|
|
# error: 1 errors parsing expression
|
2010-10-13 05:20:11 +08:00
|
|
|
#
|
2010-10-19 08:52:07 +08:00
|
|
|
# (lldb) expression self->date
|
2010-10-13 05:20:11 +08:00
|
|
|
# error: instance variable 'date' is protected
|
2010-09-18 06:28:51 +08:00
|
|
|
# error: 1 errors parsing expression
|
2010-10-13 05:20:11 +08:00
|
|
|
#
|
|
|
|
|
2010-10-16 03:29:15 +08:00
|
|
|
self.runCmd("breakpoint delete 1")
|
2010-10-13 05:20:11 +08:00
|
|
|
self.expect("breakpoint set -f main.m -l %d" % self.line,
|
|
|
|
BREAKPOINT_CREATED,
|
|
|
|
startstr = "Breakpoint created: 2: file ='main.m', line = %d, locations = 1" %
|
|
|
|
self.line)
|
|
|
|
self.runCmd("process continue")
|
|
|
|
|
|
|
|
# rdar://problem/8542091
|
|
|
|
# test/foundation: expr -o -- my not working?
|
|
|
|
#
|
|
|
|
# Test new feature with r115115:
|
|
|
|
# Add "-o" option to "expression" which prints the object description if available.
|
2010-10-19 08:52:07 +08:00
|
|
|
self.expect("expression -o -- my", "Object description displayed correctly",
|
2010-10-16 07:35:32 +08:00
|
|
|
patterns = ["Hello from.*a.out.*with timestamp: "])
|
2010-09-18 06:28:51 +08:00
|
|
|
|
2010-12-16 04:47:34 +08:00
|
|
|
@unittest2.expectedFailure
|
|
|
|
# See: <rdar://problem/8717050> lldb needs to use the ObjC runtime symbols for ivar offsets
|
|
|
|
# Only fails for the ObjC 2.0 runtime.
|
|
|
|
def print_ivars_correctly(self) :
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(target, VALID_TARGET)
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
break1 = target.BreakpointCreateByLocation(self.main_source, self.line)
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(break1, VALID_BREAKPOINT)
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
2011-01-24 01:46:22 +08:00
|
|
|
error = lldb.SBError()
|
2011-02-04 07:15:53 +08:00
|
|
|
self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error)
|
2010-12-16 04:47:34 +08:00
|
|
|
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(self.process, PROCESS_IS_VALID)
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
|
|
thread = self.process.GetThreadAtIndex(0)
|
|
|
|
if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
|
2011-04-28 01:43:07 +08:00
|
|
|
from lldbutil import stop_reason_to_str
|
2010-12-16 04:47:34 +08:00
|
|
|
self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
|
2011-04-28 01:43:07 +08:00
|
|
|
stop_reason_to_str(thread.GetStopReason()))
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
# Make sure we stopped at the first breakpoint.
|
|
|
|
|
|
|
|
cur_frame = thread.GetFrameAtIndex(0)
|
|
|
|
|
|
|
|
line_number = cur_frame.GetLineEntry().GetLine()
|
|
|
|
self.assertTrue (line_number == self.line, "Hit the first breakpoint.")
|
|
|
|
|
|
|
|
my_var = cur_frame.FindVariable("my")
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(my_var, "Made a variable object for my")
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
str_var = cur_frame.FindVariable("str")
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(str_var, "Made a variable object for str")
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
# Now make sure that the my->str == str:
|
|
|
|
|
|
|
|
my_str_var = my_var.GetChildMemberWithName("str")
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(my_str_var, "Found a str ivar in my")
|
2010-12-16 04:47:34 +08:00
|
|
|
|
|
|
|
str_value = int(str_var.GetValue(cur_frame), 0)
|
|
|
|
|
|
|
|
my_str_value = int(my_str_var.GetValue(cur_frame), 0)
|
2010-09-17 04:54:06 +08:00
|
|
|
|
2010-12-16 04:47:34 +08:00
|
|
|
self.assertTrue(str_value == my_str_value, "Got the correct value for my->str")
|
|
|
|
|
2010-09-17 04:54:06 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|