llvm-project/lldb/test/foundation/TestFoundationDisassembly.py
Greg Clayton 8b82f087a0 Moved the execution context that was in the Debugger into
the CommandInterpreter where it was always being used.

Make sure that Modules can track their object file offsets correctly to
allow opening of sub object files (like the "__commpage" on darwin).

Modified the Platforms to be able to launch processes. The first part of this
move is the platform soon will become the entity that launches your program
and when it does, it uses a new ProcessLaunchInfo class which encapsulates
all process launching settings. This simplifies the internal APIs needed for
launching. I want to slowly phase out process launching from the process
classes, so for now we can still launch just as we used to, but eventually
the platform is the object that should do the launching.

Modified the Host::LaunchProcess in the MacOSX Host.mm to correctly be able
to launch processes with all of the new eLaunchFlag settings. Modified any
code that was manually launching processes to use the Host::LaunchProcess
functions.

Fixed an issue where lldb_private::Args had implicitly defined copy 
constructors that could do the wrong thing. This has now been fixed by adding
an appropriate copy constructor and assignment operator.

Make sure we don't add empty ModuleSP entries to a module list.

Fixed the commpage module creation on MacOSX, but we still need to train
the MacOSX dynamic loader to not get rid of it when it doesn't have an entry
in the all image infos.

Abstracted many more calls from in ProcessGDBRemote down into the 
GDBRemoteCommunicationClient subclass to make the classes cleaner and more
efficient.

Fixed the default iOS ARM register context to be correct and also added support
for targets that don't support the qThreadStopInfo packet by selecting the
current thread (only if needed) and then sending a stop reply packet.

Debugserver can now start up with a --unix-socket (-u for short) and can 
then bind to port zero and send the port it bound to to a listening process
on the other end. This allows the GDB remote platform to spawn new GDB server
instances (debugserver) to allow platform debugging.

llvm-svn: 129351
2011-04-12 05:54:46 +00:00

134 lines
5.3 KiB
Python

"""
Test the lldb disassemble command on foundation framework.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
class FoundationDisassembleTestCase(TestBase):
mydir = "foundation"
# rdar://problem/8504895
# Crash while doing 'disassemble -n "-[NSNumber descriptionWithLocale:]"
@unittest2.skipIf(TestBase.skipLongRunningTest(), "Skip this long running test")
def test_foundation_disasm(self):
"""Do 'disassemble -n func' on each and every 'Code' symbol entry from the Foundation.framework."""
self.buildDefault()
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.runCmd("run", RUN_SUCCEEDED)
self.runCmd("image list")
raw_output = self.res.GetOutput()
# Grok the full path to the foundation framework.
for line in raw_output.split(os.linesep):
match = re.search(" (/.*/Foundation.framework/.*)$", line)
if match:
foundation_framework = match.group(1)
break
self.assertTrue(match, "Foundation.framework path located")
self.runCmd("image dump symtab %s" % foundation_framework)
raw_output = self.res.GetOutput()
# Now, grab every 'Code' symbol and feed it into the command:
# 'disassemble -n func'.
#
# The symbol name is on the last column and trails the flag column which
# looks like '0xhhhhhhhh', i.e., 8 hexadecimal digits.
codeRE = re.compile(r"""
\ Code\ {9} # ' Code' followed by 9 SPCs,
.* # the wildcard chars,
0x[0-9a-f]{8} # the flag column, and
\ (.+)$ # finally the function symbol.
""", re.VERBOSE)
for line in raw_output.split(os.linesep):
match = codeRE.search(line)
if match:
func = match.group(1)
#print "line:", line
#print "func:", func
self.runCmd('disassemble -n "%s"' % func)
def test_simple_disasm_with_dsym(self):
"""Test the lldb 'disassemble' command"""
self.buildDsym()
self.do_simple_disasm()
def test_simple_disasm_with_dwarf(self):
"""Test the lldb 'disassemble' command"""
self.buildDwarf()
self.do_simple_disasm()
def do_simple_disasm(self):
"""Do a bunch of simple disassemble commands."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Stop at +[NSString stringWithFormat:].
self.expect("_regexp-break +[NSString stringWithFormat:]", BREAKPOINT_CREATED,
substrs = ["Breakpoint created: 1: name = '+[NSString stringWithFormat:]', locations = 1"])
# 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")
# Stop at -[NSAutoreleasePool release].
self.expect("_regexp-break -[NSAutoreleasePool release]", BREAKPOINT_CREATED,
substrs = ["Breakpoint created: 4: name = '-[NSAutoreleasePool release]', locations = 1"])
self.runCmd("run", RUN_SUCCEEDED)
# First stop is +[NSString stringWithFormat:].
self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]",
substrs = ["Foundation`+[NSString stringWithFormat:]"])
# Do the disassemble for the currently stopped function.
self.runCmd("disassemble -f")
self.runCmd("process continue")
# Skip another breakpoint for +[NSString stringWithFormat:].
self.runCmd("process continue")
# Followed by a.out`-[MyString initWithNSString:].
self.expect("thread backtrace", "Stop at a.out`-[MyString initWithNSString:]",
substrs = ["a.out`-[MyString initWithNSString:]"])
# Do the disassemble for the currently stopped function.
self.runCmd("disassemble -f")
self.runCmd("process continue")
# Followed by -[MyString description].
self.expect("thread backtrace", "Stop at -[MyString description]",
substrs = ["a.out`-[MyString description]"])
# Do the disassemble for the currently stopped function.
self.runCmd("disassemble -f")
self.runCmd("process continue")
# Skip another breakpoint for -[MyString description].
self.runCmd("process continue")
# Followed by -[NSAutoreleasePool release].
self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]",
substrs = ["Foundation`-[NSAutoreleasePool release]"])
# Do the disassemble for the currently stopped function.
self.runCmd("disassemble -f")
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()