183 lines
7.0 KiB
Python
Raw Normal View History

"""
Test some lldb command abbreviations.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
import lldbutil
class AbbreviationsTestCase(TestBase):
mydir = os.path.join("functionalities", "abbreviation")
def test_nonrunning_command_abbreviations (self):
self.expect("ap script",
startstr = "The following built-in commands may relate to 'script':",
substrs = ['breakpoint command add',
'breakpoint command list',
'breakpoint list',
'command alias',
'expression',
'script'])
self.runCmd("com a alias com al")
self.runCmd("alias gurp help")
Centralized a lot of the status information for processes, threads, and stack frame down in the lldb_private::Process, lldb_private::Thread, lldb_private::StackFrameList and the lldb_private::StackFrame classes. We had some command line commands that had duplicate versions of the process status output ("thread list" and "process status" for example). Removed the "file" command and placed it where it should have been: "target create". Made an alias for "file" to "target create" so we stay compatible with GDB commands. We can now have multple usable targets in lldb at the same time. This is nice for comparing two runs of a program or debugging more than one binary at the same time. The new command is "target select <target-idx>" and also to see a list of the current targets you can use the new "target list" command. The flow in a debug session can be: (lldb) target create /path/to/exe/a.out (lldb) breakpoint set --name main (lldb) run ... hit breakpoint (lldb) target create /bin/ls (lldb) run /tmp Process 36001 exited with status = 0 (0x00000000) (lldb) target list Current targets: target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped ) * target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited ) (lldb) target select 0 Current targets: * target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped ) target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited ) (lldb) bt * thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1 frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16 frame #1: 0x0000000100000b64 a.out`start + 52 Above we created a target for "a.out" and ran and hit a breakpoint at "main". Then we created a new target for /bin/ls and ran it. Then we listed the targest and selected our original "a.out" program, so we showed two concurent debug sessions going on at the same time. llvm-svn: 129695
2011-04-18 08:33:37 +00:00
self.expect("gurp target create",
substrs = ['Syntax: target create <cmd-options> <filename>'])
self.runCmd("com u gurp")
self.expect("gurp",
COMMAND_FAILED_AS_EXPECTED, error = True,
substrs = ["error: 'gurp' is not a valid command."])
# Only one matching command: execute it.
self.expect("h",
startstr = "The following is a list of built-in, permanent debugger commands:")
# Execute cleanup function during test tear down
def cleanup():
self.runCmd("command alias t thread select")
self.addTearDownHook(cleanup)
# Several matching commands: list them and error out.
self.runCmd("command unalias t")
self.expect("t",
COMMAND_FAILED_AS_EXPECTED, error = True,
substrs = ["Ambiguous command 't'. Possible matches:",
"target", "thread", "type"])
self.expect("com sou ./change_prompt.lldb",
patterns = ["Executing commands in '.*change_prompt.lldb'"])
self.expect("settings show prompt",
startstr = 'prompt (string) = "[with-three-trailing-spaces] "')
self.runCmd("settings clear prompt")
self.expect("settings show prompt",
startstr = 'prompt (string) = "(lldb) "')
self.expect("lo li",
startstr = "Logging categories for ")
self.runCmd("se se prompt 'Sycamore> '")
self.expect("se sh prompt",
startstr = 'prompt (string) = "Sycamore> "')
self.runCmd("se cl prompt")
self.expect("set sh prompt",
startstr = 'prompt (string) = "(lldb) "')
# We don't want to display the stdout if not in TraceOn() mode.
if not self.TraceOn():
self.HideStdout()
self.runCmd (r'''sc print "\n\n\tHello!\n"''')
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> class HelloWatchpointTestCase(TestBase): mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") @dsym_test def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDsym(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() @dwarf_test def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDwarf(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 00:56:05 +00:00
@dsym_test
def test_with_dsym (self):
self.buildDsym ()
self.running_abbreviations ()
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> class HelloWatchpointTestCase(TestBase): mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") @dsym_test def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDsym(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() @dwarf_test def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDwarf(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 00:56:05 +00:00
@dwarf_test
def test_with_dwarf (self):
self.buildDwarf ()
self.running_abbreviations ()
def running_abbreviations (self):
exe = os.path.join (os.getcwd(), "a.out")
# Use "file", i.e., no abbreviation. We're exactly matching the command
# verbatim when dealing with remote testsuite execution.
# For more details, see TestBase.runCmd().
self.expect("file " + exe,
patterns = [ "Current executable set to .*a.out.*" ])
# By default, the setting interpreter.expand-regex-aliases is false.
self.expect("_regexp-br product", matching=False,
substrs = [ "breakpoint set --name" ])
match_object = lldbutil.run_break_set_command (self, "br s -n sum")
lldbutil.check_breakpoint_result (self, match_object, symbol_name='sum', symbol_match_exact=False, num_locations=1)
match_object = lldbutil.run_break_set_command (self, "br s -f main.cpp -l 32")
lldbutil.check_breakpoint_result (self, match_object, file_name='main.cpp', line_number=32, num_locations=1)
self.runCmd("br co a -s python 1 -o 'print frame'")
self.expect("br co l 1",
substrs = [ "Breakpoint 1:",
"Breakpoint commands:",
"print frame" ])
self.runCmd("br co del 1")
self.expect("breakpoint command list 1",
startstr = "Breakpoint 1 does not have an associated command.")
self.expect("br di",
startstr = 'All breakpoints disabled. (3 breakpoints)')
self.expect("bre e",
startstr = "All breakpoints enabled. (3 breakpoints)")
self.expect("break list",
substrs = ["1: name = 'product', locations = 1",
"2: name = 'sum', locations = 1",
"3: file = 'main.cpp', line = 32, locations = 1"])
self.expect("br cl -l 32 -f main.cpp",
startstr = "1 breakpoints cleared:",
substrs = ["3: file = 'main.cpp', line = 32, locations = 1"])
# Add a future to terminate the current process being debugged.
#
# The test framework relies on detecting either "run" or "process launch"
# command to automatically kill the inferior upon tear down.
# But we'll be using "pro la" command to launch the inferior.
self.addTearDownHook(lambda: self.runCmd("process kill"))
self.expect("pro la",
patterns = [ "Process .* launched: "])
self.expect("pro st",
patterns = [ "Process .* stopped",
"thread #1:",
"a.out",
"sum\(a=1238, b=78392\)",
"at main.cpp\:25",
"stop reason = breakpoint 2.1" ])
# ARCH, if not specified, defaults to x86_64.
if self.getArchitecture() in ["", 'x86_64', 'i386']:
self.expect("dis -f",
startstr = "a.out`sum(int, int)",
substrs = [' mov',
' addl ',
'ret'])
self.expect("i d l main.cpp",
patterns = ["Line table for .*main.cpp in `a.out"])
self.expect("i d se",
patterns = ["Dumping sections for [0-9]+ modules."])
self.expect("i d symf",
patterns = ["Dumping debug symbols for [0-9]+ modules."])
self.expect("i d symt",
patterns = ["Dumping symbol table for [0-9]+ modules."])
if sys.platform.startswith("darwin"):
self.expect("i li",
substrs = [ 'a.out',
'/usr/lib/dyld',
'/usr/lib/libSystem.B.dylib'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()