Home | History | Annotate | Download | only in abbreviation
      1 """
      2 Test some lldb command abbreviations.
      3 """
      4 
      5 import os, time
      6 import unittest2
      7 import lldb
      8 from lldbtest import *
      9 import lldbutil
     10 
     11 class AbbreviationsTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "abbreviation")
     14 
     15     def test_nonrunning_command_abbreviations (self):
     16         self.expect("ap script",
     17                     startstr = "The following built-in commands may relate to 'script':",
     18                     substrs = ['breakpoint command add',
     19                                'breakpoint command list',
     20                                'breakpoint list',
     21                                'command alias',
     22                                'expression',
     23                                'script'])
     24 
     25         self.runCmd("com a alias com al")
     26         self.runCmd("alias gurp help")
     27         self.expect("gurp target create",
     28                     substrs = ['Syntax: target create <cmd-options> <filename>'])
     29         self.runCmd("com u gurp")
     30         self.expect("gurp",
     31                     COMMAND_FAILED_AS_EXPECTED, error = True,
     32                     substrs = ["error: 'gurp' is not a valid command."])
     33 
     34         # Only one matching command: execute it.
     35         self.expect("h",
     36                     startstr = "The following is a list of built-in, permanent debugger commands:")
     37 
     38         # Execute cleanup function during test tear down
     39         def cleanup():
     40             self.runCmd("command alias t thread select")
     41         self.addTearDownHook(cleanup)
     42 
     43         # Several matching commands: list them and error out.
     44         self.runCmd("command unalias t")
     45         self.expect("t",
     46                     COMMAND_FAILED_AS_EXPECTED, error = True,
     47                     substrs = ["Ambiguous command 't'. Possible matches:",
     48                                "target", "thread", "type"])
     49 
     50         self.expect("com sou ./change_prompt.lldb",
     51                     patterns = ["Executing commands in '.*change_prompt.lldb'"])
     52 
     53         self.expect("settings show prompt",
     54                     startstr = 'prompt (string) = "[with-three-trailing-spaces]   "')
     55 
     56 
     57         self.runCmd("settings clear prompt")
     58         self.expect("settings show prompt",
     59                     startstr = 'prompt (string) = "(lldb) "')
     60 
     61 
     62         self.expect("lo li",
     63                     startstr = "Logging categories for ")
     64 
     65         self.runCmd("se se prompt 'Sycamore> '")
     66         self.expect("se sh prompt",
     67                     startstr = 'prompt (string) = "Sycamore> "')
     68 
     69         self.runCmd("se cl prompt")
     70         self.expect("set sh prompt",
     71                     startstr = 'prompt (string) = "(lldb) "')
     72 
     73         # We don't want to display the stdout if not in TraceOn() mode.
     74         if not self.TraceOn():
     75             self.HideStdout()
     76 
     77         self.runCmd (r'''sc print "\n\n\tHello!\n"''')
     78 
     79 
     80     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     81     @dsym_test
     82     def test_with_dsym (self):
     83         self.buildDsym ()
     84         self.running_abbreviations ()
     85 
     86     @dwarf_test
     87     def test_with_dwarf (self):
     88         self.buildDwarf ()
     89         self.running_abbreviations ()
     90 
     91     def running_abbreviations (self):
     92         exe = os.path.join (os.getcwd(), "a.out")
     93         self.expect("fil " + exe,
     94                     patterns = [ "Current executable set to .*a.out.*" ])
     95 
     96         # By default, the setting interpreter.expand-regex-aliases is false.
     97         self.expect("_regexp-br product", matching=False,
     98                     substrs = [ "breakpoint set --name" ])
     99 
    100         match_object = lldbutil.run_break_set_command (self, "br s -n sum")
    101         lldbutil.check_breakpoint_result (self, match_object, symbol_name='sum', symbol_match_exact=False, num_locations=1)
    102 
    103         match_object = lldbutil.run_break_set_command (self, "br s -f main.cpp -l 32")
    104         lldbutil.check_breakpoint_result (self, match_object, file_name='main.cpp', line_number=32, num_locations=1)
    105 
    106         self.runCmd("br co a -s python 1 -o 'print frame'")
    107         self.expect("br co l 1",
    108                     substrs = [ "Breakpoint 1:",
    109                                 "Breakpoint commands:",
    110                                 "print frame" ])
    111 
    112         self.runCmd("br co del 1")
    113         self.expect("breakpoint command list 1",
    114                     startstr = "Breakpoint 1 does not have an associated command.")
    115 
    116         self.expect("br di",
    117                     startstr = 'All breakpoints disabled. (3 breakpoints)')
    118 
    119         self.expect("bre e",
    120                     startstr = "All breakpoints enabled. (3 breakpoints)")
    121 
    122         self.expect("break list",
    123                     substrs = ["1: name = 'product', locations = 1",
    124                                "2: name = 'sum', locations = 1",
    125                                "3: file = 'main.cpp', line = 32, locations = 1"])
    126         self.expect("br cl -l 32 -f main.cpp",
    127                     startstr = "1 breakpoints cleared:",
    128                     substrs = ["3: file = 'main.cpp', line = 32, locations = 1"])
    129 
    130         # Add a future to terminate the current process being debugged.
    131         #
    132         # The test framework relies on detecting either "run" or "process launch"
    133         # command to automatically kill the inferior upon tear down.
    134         # But we'll be using "pro la" command to launch the inferior.
    135         self.addTearDownHook(lambda: self.runCmd("process kill"))
    136         self.expect("pro la",
    137                     patterns = [ "Process .* launched: "])
    138 
    139         self.expect("pro st",
    140                     patterns = [ "Process .* stopped",
    141                                  "thread #1:",
    142                                  "a.out",
    143                                  "sum\(a=1238, b=78392\)",
    144                                  "at main.cpp\:25",
    145                                  "stop reason = breakpoint 2.1" ])
    146 
    147         # ARCH, if not specified, defaults to x86_64.
    148         if self.getArchitecture() in ["", 'x86_64', 'i386']:
    149             self.expect("dis -f",
    150                         startstr = "a.out`sum(int, int)",
    151                         substrs = [' mov',
    152                                    ' addl ',
    153                                    'ret'])
    154 
    155         self.expect("i d l main.cpp",
    156                     patterns = ["Line table for .*main.cpp in `a.out"])
    157 
    158         self.expect("i d se",
    159                     patterns = ["Dumping sections for [0-9]+ modules."])
    160 
    161         self.expect("i d symf",
    162                     patterns = ["Dumping debug symbols for [0-9]+ modules."])
    163 
    164         self.expect("i d symt",
    165                     patterns = ["Dumping symbol table for [0-9]+ modules."])
    166 
    167         if sys.platform.startswith("darwin"):
    168             self.expect("i li",
    169                         substrs = [ 'a.out',
    170                                     '/usr/lib/dyld',
    171                                     '/usr/lib/libSystem.B.dylib'])
    172 
    173 
    174 if __name__ == '__main__':
    175     import atexit
    176     lldb.SBDebugger.Initialize()
    177     atexit.register(lambda: lldb.SBDebugger.Terminate())
    178     unittest2.main()
    179 
    180