2010-12-14 23:50:59 +00:00
|
|
|
"""
|
|
|
|
Test some lldb command abbreviations.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, time
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
2012-09-22 00:05:11 +00:00
|
|
|
import lldbutil
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
class AbbreviationsTestCase(TestBase):
|
2012-10-25 23:52:28 +00:00
|
|
|
|
2011-06-26 21:27:27 +00:00
|
|
|
mydir = os.path.join("functionalities", "abbreviation")
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
def test_nonrunning_command_abbreviations (self):
|
|
|
|
self.expect("ap script",
|
2013-05-17 15:03:59 +00:00
|
|
|
startstr = "The following built-in commands may relate to 'script':",
|
2010-12-14 23:50:59 +00:00
|
|
|
substrs = ['breakpoint command add',
|
|
|
|
'breakpoint command list',
|
|
|
|
'breakpoint list',
|
2011-04-21 00:39:18 +00:00
|
|
|
'command alias',
|
2010-12-14 23:50:59 +00:00
|
|
|
'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>'])
|
2010-12-14 23:50:59 +00:00
|
|
|
self.runCmd("com u gurp")
|
|
|
|
self.expect("gurp",
|
|
|
|
COMMAND_FAILED_AS_EXPECTED, error = True,
|
|
|
|
substrs = ["error: 'gurp' is not a valid command."])
|
|
|
|
|
2012-05-16 23:25:54 +00:00
|
|
|
# Only one matching command: execute it.
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("h",
|
|
|
|
startstr = "The following is a list of built-in, permanent debugger commands:")
|
|
|
|
|
2012-10-25 23:52:28 +00:00
|
|
|
# Execute cleanup function during test tear down
|
|
|
|
def cleanup():
|
|
|
|
self.runCmd("command alias t thread select")
|
|
|
|
self.addTearDownHook(cleanup)
|
|
|
|
|
2012-05-16 23:25:54 +00:00
|
|
|
# Several matching commands: list them and error out.
|
2012-10-05 19:16:31 +00:00
|
|
|
self.runCmd("command unalias t")
|
2012-05-16 23:25:54 +00:00
|
|
|
self.expect("t",
|
|
|
|
COMMAND_FAILED_AS_EXPECTED, error = True,
|
|
|
|
substrs = ["Ambiguous command 't'. Possible matches:",
|
|
|
|
"target", "thread", "type"])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2011-08-16 23:24:13 +00:00
|
|
|
self.expect("com sou ./change_prompt.lldb",
|
2010-12-14 23:50:59 +00:00
|
|
|
patterns = ["Executing commands in '.*change_prompt.lldb'"])
|
|
|
|
|
|
|
|
self.expect("settings show prompt",
|
2012-01-19 19:22:41 +00:00
|
|
|
startstr = 'prompt (string) = "[with-three-trailing-spaces] "')
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
self.runCmd("settings clear prompt")
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("settings show prompt",
|
2011-04-19 22:32:36 +00:00
|
|
|
startstr = 'prompt (string) = "(lldb) "')
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
self.expect("lo li",
|
2011-03-22 01:14:58 +00:00
|
|
|
startstr = "Logging categories for ")
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2013-03-06 02:19:38 +00:00
|
|
|
self.runCmd("se se prompt 'Sycamore> '")
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("se sh prompt",
|
2012-01-19 19:22:41 +00:00
|
|
|
startstr = 'prompt (string) = "Sycamore> "')
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
self.runCmd("se cl prompt")
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("set sh prompt",
|
2011-04-19 22:32:36 +00:00
|
|
|
startstr = 'prompt (string) = "(lldb) "')
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2011-04-21 20:48:32 +00:00
|
|
|
# We don't want to display the stdout if not in TraceOn() mode.
|
|
|
|
if not self.TraceOn():
|
2011-04-21 22:50:23 +00:00
|
|
|
self.HideStdout()
|
2011-04-21 20:48:32 +00:00
|
|
|
|
2010-12-14 23:50:59 +00:00
|
|
|
self.runCmd (r'''sc print "\n\n\tHello!\n"''')
|
|
|
|
|
|
|
|
|
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
2012-04-06 00:56:05 +00:00
|
|
|
@dsym_test
|
2010-12-14 23:50:59 +00:00
|
|
|
def test_with_dsym (self):
|
|
|
|
self.buildDsym ()
|
|
|
|
self.running_abbreviations ()
|
|
|
|
|
2012-04-06 00:56:05 +00:00
|
|
|
@dwarf_test
|
2010-12-14 23:50:59 +00:00
|
|
|
def test_with_dwarf (self):
|
|
|
|
self.buildDwarf ()
|
|
|
|
self.running_abbreviations ()
|
|
|
|
|
|
|
|
def running_abbreviations (self):
|
|
|
|
exe = os.path.join (os.getcwd(), "a.out")
|
2013-08-26 23:57:52 +00:00
|
|
|
# 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,
|
2010-12-15 00:58:49 +00:00
|
|
|
patterns = [ "Current executable set to .*a.out.*" ])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2012-08-23 20:22:16 +00:00
|
|
|
# By default, the setting interpreter.expand-regex-aliases is false.
|
2012-10-12 17:34:26 +00:00
|
|
|
self.expect("_regexp-br product", matching=False,
|
2012-08-23 20:25:04 +00:00
|
|
|
substrs = [ "breakpoint set --name" ])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2012-09-22 00:05:11 +00:00
|
|
|
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)
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2012-09-22 00:05:11 +00:00
|
|
|
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)
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2011-02-19 02:53:09 +00:00
|
|
|
self.runCmd("br co a -s python 1 -o 'print frame'")
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("br co l 1",
|
|
|
|
substrs = [ "Breakpoint 1:",
|
|
|
|
"Breakpoint commands:",
|
|
|
|
"print frame" ])
|
|
|
|
|
2011-05-22 07:14:46 +00:00
|
|
|
self.runCmd("br co del 1")
|
2010-12-14 23:50:59 +00:00
|
|
|
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",
|
2013-06-17 19:00:31 +00:00
|
|
|
"3: file = 'main.cpp', line = 32, locations = 1"])
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("br cl -l 32 -f main.cpp",
|
|
|
|
startstr = "1 breakpoints cleared:",
|
2013-06-17 19:00:31 +00:00
|
|
|
substrs = ["3: file = 'main.cpp', line = 32, locations = 1"])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2011-04-22 00:33:09 +00:00
|
|
|
# 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"))
|
2010-12-14 23:50:59 +00:00
|
|
|
self.expect("pro la",
|
|
|
|
patterns = [ "Process .* launched: "])
|
|
|
|
|
|
|
|
self.expect("pro st",
|
|
|
|
patterns = [ "Process .* stopped",
|
|
|
|
"thread #1:",
|
|
|
|
"a.out",
|
2012-08-09 20:29:34 +00:00
|
|
|
"sum\(a=1238, b=78392\)",
|
2012-10-25 23:52:28 +00:00
|
|
|
"at main.cpp\:25",
|
2010-12-14 23:50:59 +00:00
|
|
|
"stop reason = breakpoint 2.1" ])
|
|
|
|
|
2011-04-22 00:13:28 +00:00
|
|
|
# ARCH, if not specified, defaults to x86_64.
|
|
|
|
if self.getArchitecture() in ["", 'x86_64', 'i386']:
|
2011-10-24 18:37:00 +00:00
|
|
|
self.expect("dis -f",
|
2011-04-25 17:40:47 +00:00
|
|
|
startstr = "a.out`sum(int, int)",
|
2012-12-21 00:26:22 +00:00
|
|
|
substrs = [' mov',
|
2011-04-22 00:13:28 +00:00
|
|
|
' addl ',
|
2012-12-21 00:26:22 +00:00
|
|
|
'ret'])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
self.expect("i d l main.cpp",
|
|
|
|
patterns = ["Line table for .*main.cpp in `a.out"])
|
|
|
|
|
|
|
|
self.expect("i d se",
|
2011-03-29 23:22:29 +00:00
|
|
|
patterns = ["Dumping sections for [0-9]+ modules."])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
self.expect("i d symf",
|
2011-03-29 23:22:29 +00:00
|
|
|
patterns = ["Dumping debug symbols for [0-9]+ modules."])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
self.expect("i d symt",
|
2011-03-29 23:22:29 +00:00
|
|
|
patterns = ["Dumping symbol table for [0-9]+ modules."])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
2011-10-24 23:01:06 +00:00
|
|
|
if sys.platform.startswith("darwin"):
|
|
|
|
self.expect("i li",
|
|
|
|
substrs = [ 'a.out',
|
|
|
|
'/usr/lib/dyld',
|
2012-02-27 21:08:54 +00:00
|
|
|
'/usr/lib/libSystem.B.dylib'])
|
2010-12-14 23:50:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|
|
|
|
|