2 Test the lldb disassemble command on foundation framework.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class FoundationDisassembleTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
16 def test_foundation_disasm(self
):
17 """Do 'disassemble -n func' on each and every 'Code' symbol entry from the Foundation.framework."""
20 # Enable synchronous mode
21 self
.dbg
.SetAsync(False)
23 # Create a target by the debugger.
24 target
= self
.dbg
.CreateTarget(self
.getBuildArtifact("a.out"))
25 self
.assertTrue(target
, VALID_TARGET
)
27 # Now launch the process, and do not stop at entry point.
28 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
29 self
.assertTrue(process
, PROCESS_IS_VALID
)
31 foundation_framework
= None
32 for module
in target
.modules
:
33 if module
.file.basename
== "Foundation":
34 foundation_framework
= module
.file.fullpath
38 foundation_framework
is not None, "Foundation.framework path located"
40 self
.runCmd("image dump symtab '%s'" % foundation_framework
)
41 raw_output
= self
.res
.GetOutput()
42 # Now, grab every 'Code' symbol and feed it into the command:
43 # 'disassemble -n func'.
45 # The symbol name is on the last column and trails the flag column which
46 # looks like '0xhhhhhhhh', i.e., 8 hexadecimal digits.
49 \ Code\ {9} # ' Code' followed by 9 SPCs,
50 .* # the wildcard chars,
51 0x[0-9a-f]{8} # the flag column, and
52 \ (.+)$ # finally the function symbol.
56 for line
in raw_output
.split(os
.linesep
):
57 match
= codeRE
.search(line
)
60 self
.runCmd('image lookup -s "%s"' % func
)
61 self
.runCmd('disassemble --force -n "%s"' % func
)
64 def test_simple_disasm(self
):
65 """Test the lldb 'disassemble' command"""
68 # Create a target by the debugger.
69 target
= self
.dbg
.CreateTarget(self
.getBuildArtifact("a.out"))
70 self
.assertTrue(target
, VALID_TARGET
)
72 # Stop at +[NSString stringWithFormat:].
73 symbol_name
= "+[NSString stringWithFormat:]"
74 break_results
= lldbutil
.run_break_set_command(
75 self
, "_regexp-break %s" % (symbol_name
)
78 lldbutil
.check_breakpoint_result(
79 self
, break_results
, symbol_name
=symbol_name
, num_locations
=1
82 # Stop at -[MyString initWithNSString:].
83 lldbutil
.run_break_set_by_symbol(
85 "-[MyString initWithNSString:]",
86 num_expected_locations
=1,
90 # Stop at the "description" selector.
91 lldbutil
.run_break_set_by_selector(
92 self
, "description", num_expected_locations
=1, module_name
="a.out"
95 # Stop at -[NSAutoreleasePool release].
96 break_results
= lldbutil
.run_break_set_command(
97 self
, "_regexp-break -[NSAutoreleasePool release]"
99 lldbutil
.check_breakpoint_result(
102 symbol_name
="-[NSAutoreleasePool release]",
106 self
.runCmd("run", RUN_SUCCEEDED
)
108 # First stop is +[NSString stringWithFormat:].
111 "Stop at +[NSString stringWithFormat:]",
112 substrs
=["Foundation`+[NSString stringWithFormat:]"],
115 # Do the disassemble for the currently stopped function.
116 self
.runCmd("disassemble -f")
118 self
.runCmd("process continue")
119 # Skip another breakpoint for +[NSString stringWithFormat:].
120 self
.runCmd("process continue")
122 # Followed by a.out`-[MyString initWithNSString:].
125 "Stop at a.out`-[MyString initWithNSString:]",
126 substrs
=["a.out`-[MyString initWithNSString:]"],
129 # Do the disassemble for the currently stopped function.
130 self
.runCmd("disassemble -f")
132 self
.runCmd("process continue")
134 # Followed by -[MyString description].
137 "Stop at -[MyString description]",
138 substrs
=["a.out`-[MyString description]"],
141 # Do the disassemble for the currently stopped function.
142 self
.runCmd("disassemble -f")
144 self
.runCmd("process continue")
145 # Skip another breakpoint for -[MyString description].
146 self
.runCmd("process continue")
148 # Followed by -[NSAutoreleasePool release].
151 "Stop at -[NSAutoreleasePool release]",
152 substrs
=["Foundation`-[NSAutoreleasePool release]"],
155 # Do the disassemble for the currently stopped function.
156 self
.runCmd("disassemble -f")