Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / foundation / TestFoundationDisassembly.py
blob301f9cb90f5c9d738d9a35ff1346e7e821a527d2
1 """
2 Test the lldb disassemble command on foundation framework.
3 """
5 import os
6 import lldb
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
15 @skipIfAsan
16 def test_foundation_disasm(self):
17 """Do 'disassemble -n func' on each and every 'Code' symbol entry from the Foundation.framework."""
18 self.build()
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
35 break
37 self.assertTrue(
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.
47 codeRE = re.compile(
48 r"""
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.
53 """,
54 re.VERBOSE,
56 for line in raw_output.split(os.linesep):
57 match = codeRE.search(line)
58 if match:
59 func = match.group(1)
60 self.runCmd('image lookup -s "%s"' % func)
61 self.runCmd('disassemble --force -n "%s"' % func)
63 @skipIfAsan
64 def test_simple_disasm(self):
65 """Test the lldb 'disassemble' command"""
66 self.build()
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(
84 self,
85 "-[MyString initWithNSString:]",
86 num_expected_locations=1,
87 sym_exact=True,
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(
100 self,
101 break_results,
102 symbol_name="-[NSAutoreleasePool release]",
103 num_locations=1,
106 self.runCmd("run", RUN_SUCCEEDED)
108 # First stop is +[NSString stringWithFormat:].
109 self.expect(
110 "thread backtrace",
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:].
123 self.expect(
124 "thread backtrace",
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].
135 self.expect(
136 "thread backtrace",
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].
149 self.expect(
150 "thread backtrace",
151 "Stop at -[NSAutoreleasePool release]",
152 substrs=["Foundation`-[NSAutoreleasePool release]"],
155 # Do the disassemble for the currently stopped function.
156 self.runCmd("disassemble -f")