def run_abbrevs2(self): exe = os.path.join(os.getcwd(), "a.out") self.expect("file " + exe, patterns=["Current executable set to .*a.out.*"]) # br s -> breakpoint set 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) self.runCmd("settings set interpreter.expand-regex-aliases true") self.addTearDownHook(lambda: self.runCmd( "settings set interpreter.expand-regex-aliases false")) # disp -> display self.expect("disp a", startstr="target stop-hook add -o") self.expect("disp b", startstr="target stop-hook add -o") # di/dis -> disassemble self.expect("help di", substrs=["disassemble"]) self.expect("help dis", substrs=["disassemble"]) # ta st a -> target stop-hook add self.expect("help ta st a", substrs=["target stop-hook add"]) # fr v -> frame variable self.expect("help fr v", substrs=["frame variable"]) # ta st li -> target stop-hook list self.expect("ta st li", substrs=["Hook: 1", "Hook: 2"])
def regexp_break_command(self): """Test the super consie "b" command, which is analias for _regexp-break.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) break_results = lldbutil.run_break_set_command(self, "b %d" % self.line) lldbutil.check_breakpoint_result(self, break_results, file_name='main.c', line_number=self.line, num_locations=1) break_results = lldbutil.run_break_set_command( self, "b %s:%d" % (self.source, self.line)) lldbutil.check_breakpoint_result(self, break_results, file_name='main.c', line_number=self.line, num_locations=1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint'])
def disassemble_breakpoint (self): exe = os.path.join (os.getcwd(), "a.out") self.expect("file " + exe, patterns = [ "Current executable set to .*a.out.*" ]) 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) self.expect("run", patterns = [ "Process .* launched: "]) self.runCmd("dis -f") disassembly = self.res.GetOutput() # ARCH, if not specified, defaults to x86_64. if self.getArchitecture() in ["", 'x86_64', 'i386']: breakpoint_opcodes = ["int3"] instructions = [' mov', ' addl ', 'ret'] elif self.getArchitecture() in ["arm", "aarch64"]: breakpoint_opcodes = ["brk", "udf"] instructions = [' add ', ' ldr ', ' str '] else: # TODO please add your arch here self.fail('unimplemented for arch = "{arch}"'.format(arch=self.getArchitecture())) # make sure that the software breakpoint has been removed for op in breakpoint_opcodes: self.assertFalse(op in disassembly) # make sure a few reasonable assembly instructions are here self.expect(disassembly, exe=False, startstr = "a.out`sum", substrs = instructions)
def disassemble_breakpoint (self): exe = os.path.join (os.getcwd(), "a.out") self.expect("file " + exe, patterns = [ "Current executable set to .*a.out.*" ]) 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) self.expect("run", patterns = [ "Process .* launched: "]) self.runCmd("dis -f") disassembly = self.res.GetOutput() # ARCH, if not specified, defaults to x86_64. if self.getArchitecture() in ["", 'x86_64', 'i386']: # make sure that the software breakpoint has been removed self.assertFalse("int3" in disassembly) # make sure a few reasonable assembly instructions are here self.expect(disassembly, exe=False, startstr = "a.out`sum(int, int)", substrs = [' mov', ' addl ', 'ret']) else: # TODO please add your arch here self.fail('unimplemented for arch = "{arch}"'.format(arch=self.getArchitecture()))
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:]. symbol_name = "+[NSString stringWithFormat:]" break_results = lldbutil.run_break_set_command (self, "_regexp-break %s"%(symbol_name)) lldbutil.check_breakpoint_result (self, break_results, symbol_name=symbol_name, num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol (self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector (self, 'description', num_expected_locations=1) # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command (self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='-[NSAutoreleasePool release]', num_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")
def test_break(self): """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'.""" self.build() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Stop at +[NSString stringWithFormat:]. break_results = lldbutil.run_break_set_command(self, "_regexp-break +[NSString stringWithFormat:]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='+[NSString stringWithFormat:]', num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol (self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector (self, 'description', num_expected_locations=1, module_name='a.out') # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command(self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='-[NSAutoreleasePool release]', num_locations=1) self.runCmd("run", RUN_SUCCEEDED) # First stop is +[NSString stringWithFormat:]. self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]", substrs = ["Foundation`+[NSString stringWithFormat:]"]) self.runCmd("process continue") # Second stop is still +[NSString stringWithFormat:]. self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]", substrs = ["Foundation`+[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:]"]) self.runCmd("process continue") # Followed by -[MyString description]. self.expect("thread backtrace", "Stop at -[MyString description]", substrs = ["a.out`-[MyString description]"]) self.runCmd("process continue") # Followed by the same -[MyString description]. self.expect("thread backtrace", "Stop at -[MyString description]", substrs = ["a.out`-[MyString description]"]) self.runCmd("process continue") # Followed by -[NSAutoreleasePool release]. self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]", substrs = ["Foundation`-[NSAutoreleasePool release]"])
def break_on_objc_methods(self): """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Stop at +[NSString stringWithFormat:]. break_results = lldbutil.run_break_set_command(self, "_regexp-break +[NSString stringWithFormat:]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='+[NSString stringWithFormat:]', num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol (self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector (self, 'description', num_expected_locations=1) # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command(self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='-[NSAutoreleasePool release]', num_locations=1) self.runCmd("run", RUN_SUCCEEDED) # First stop is +[NSString stringWithFormat:]. self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]", substrs = ["Foundation`+[NSString stringWithFormat:]"]) self.runCmd("process continue") # Second stop is still +[NSString stringWithFormat:]. self.expect("thread backtrace", "Stop at +[NSString stringWithFormat:]", substrs = ["Foundation`+[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:]"]) self.runCmd("process continue") # Followed by -[MyString description]. self.expect("thread backtrace", "Stop at -[MyString description]", substrs = ["a.out`-[MyString description]"]) self.runCmd("process continue") # Followed by the same -[MyString description]. self.expect("thread backtrace", "Stop at -[MyString description]", substrs = ["a.out`-[MyString description]"]) self.runCmd("process continue") # Followed by -[NSAutoreleasePool release]. self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]", substrs = ["Foundation`-[NSAutoreleasePool release]"])
def regexp_break_command(self): """Test the super consie "b" command, which is analias for _regexp-break.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) break_results = lldbutil.run_break_set_command (self, "b %d" % self.line) lldbutil.check_breakpoint_result (self, break_results, file_name='main.c', line_number=self.line, num_locations=1) break_results = lldbutil.run_break_set_command (self, "b %s:%d" % (self.source, self.line)) lldbutil.check_breakpoint_result (self, break_results, file_name='main.c', line_number=self.line, num_locations=1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint'])
def run_abbrevs2 (self): exe = os.path.join (os.getcwd(), "a.out") self.expect("file " + exe, patterns = [ "Current executable set to .*a.out.*" ]) # br s -> breakpoint set 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) self.runCmd("settings set interpreter.expand-regex-aliases true") self.addTearDownHook( lambda: self.runCmd("settings set interpreter.expand-regex-aliases false")) # disp -> display self.expect("disp a", startstr = "target stop-hook add -o") self.expect("disp b", startstr = "target stop-hook add -o") # di/dis -> disassemble self.expect("help di", substrs = ["disassemble"]) self.expect("help dis", substrs = ["disassemble"]) # ta st a -> target stop-hook add self.expect("help ta st a", substrs = ["target stop-hook add"]) # fr v -> frame variable self.expect("help fr v", substrs = ["frame variable"]) # ta st li -> target stop-hook list self.expect("ta st li", substrs = ["Hook: 1", "Hook: 2"])
def alias_tests (self): exe = os.path.join (os.getcwd(), "a.out") self.expect("file " + exe, patterns = [ "Current executable set to .*a.out" ]) def cleanup(): self.runCmd('command unalias hello', check=False) self.runCmd('command unalias python', check=False) self.runCmd('command unalias pp', check=False) self.runCmd('command unalias alias', check=False) self.runCmd('command unalias unalias', check=False) self.runCmd('command unalias myrun', check=False) self.runCmd('command unalias bp', check=False) self.runCmd('command unalias bpa', check=False) self.runCmd('command unalias bpi', check=False) self.runCmd('command unalias bfl', check=False) self.runCmd('command unalias exprf', check=False) self.runCmd('command unalias exprf2', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd (r'''command alias hello expr (int) printf ("\n\nHello, anybody!\n\n")''') self.runCmd ("command alias python script") # We don't want to display the stdout if not in TraceOn() mode. if not self.TraceOn(): self.HideStdout() self.runCmd (r'''python print "\n\n\nWhoopee!\n\n\n"''') # self.expect (r'''python print "\n\n\nWhoopee!\n\n\n"''', # substrs = [ "Whoopee!" ]) self.runCmd (r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') # self.expect (r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''', # substrs = [ "hello" ]) self.runCmd (r'''command alias pp python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') self.runCmd ("pp") # self.expect ("pp", # substrs = [ "hello" ]) self.runCmd ("command alias alias command alias") self.runCmd ("command alias unalias command unalias") self.runCmd ("alias myrun process launch -t %1 --") self.runCmd ("alias bp breakpoint") self.expect ("alias bpa bp add", COMMAND_FAILED_AS_EXPECTED, error = True, substrs = [ "'add' is not a valid sub-command of 'bp'" ]) self.runCmd ("alias bpa bp command add") self.runCmd ("alias bpi bp list") break_results = lldbutil.run_break_set_command (self, "bp set -n foo") lldbutil.check_breakpoint_result (self, break_results, num_locations=1, symbol_name='foo', symbol_match_exact=False) break_results = lldbutil.run_break_set_command (self, "bp set -n sum") lldbutil.check_breakpoint_result (self, break_results, num_locations=1, symbol_name='sum', symbol_match_exact=False) self.runCmd ("alias bfl bp set -f %1 -l %2") break_results = lldbutil.run_break_set_command (self, "bfl main.cpp 32") lldbutil.check_breakpoint_result (self, break_results, num_locations=1, file_name='main.cpp', line_number=32) self.expect ("bpi", startstr = "Current breakpoints:", substrs = [ "1: name = 'foo', locations = 1", "2: name = 'sum', locations = 1", "3: file = 'main.cpp', line = 32, locations = 1" ]) self.runCmd ("bpa -s python 1 -o 'print frame; print bp_loc'") self.runCmd ("bpa -s command 2 -o 'frame variable b'") self.expect ("bpi -f", substrs = [ "Current breakpoints:", "1: name = 'foo', locations = 1", "print frame; print bp_loc", "2: name = 'sum', locations = 1", "frame variable b" ]) self.expect ("help run", substrs = [ "'run' is an abbreviation for 'process launch -c /bin/bash --'" ]) self.expect ("help -a run", substrs = [ "'run' is an abbreviation for 'process launch -c /bin/bash --'" ]) self.expect ("help -a", substrs = [ 'run', 'process launch -c /bin/bash' ]) self.expect ("help", matching=False, substrs = [ "'run'", 'process launch -c /bin/bash' ]) self.expect ("run", patterns = [ "Process .* launched: .*a.out" ]) self.expect (r'''expression (int) printf("\x68\x65\x6c\x6c\x6f\n")''', substrs = [ "(int) $", "= 6" ]) self.expect ("hello", substrs = [ "(int) $", "= 19" ]) self.expect ("expr -f x -- 68", substrs = [ "(int) $", "= 0x00000044" ]) self.runCmd ("alias exprf expr -f %1") self.runCmd ("alias exprf2 expr --raw -f %1 --") self.expect ("exprf x -- 1234", substrs = [ "(int) $", "= 0x000004d2" ]) self.expect ('exprf2 c "Hi there!"', substrs = [ "[0] = 'H'", "[1] = 'i'", "[2] = ' '", "[3] = 't'", "[4] = 'h'", "[5] = 'e'", "[6] = 'r'", "[7] = 'e'", "[8] = '!'", "[9] = '\\0'" ]) self.expect ("exprf x 1234", COMMAND_FAILED_AS_EXPECTED, error = True, substrs = [ "use of undeclared identifier 'f'", "1 errors parsing expression" ])
def running_abbreviations (self): exe = os.path.join (os.getcwd(), "a.out") self.expect("fil " + 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 = [' push', ' mov', ' addl ', 'ret'], patterns = ['(leave|popq|popl)']) 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/libstdc++', '/usr/lib/libSystem.B.dylib'])
def alias_tests(self): exe = os.path.join(os.getcwd(), "a.out") self.expect("file " + exe, patterns=["Current executable set to .*a.out"]) def cleanup(): self.runCmd('command unalias hello', check=False) self.runCmd('command unalias python', check=False) self.runCmd('command unalias pp', check=False) self.runCmd('command unalias alias', check=False) self.runCmd('command unalias unalias', check=False) self.runCmd('command unalias myrun', check=False) self.runCmd('command unalias bp', check=False) self.runCmd('command unalias bpa', check=False) self.runCmd('command unalias bpi', check=False) self.runCmd('command unalias bfl', check=False) self.runCmd('command unalias exprf', check=False) self.runCmd('command unalias exprf2', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd( r'''command alias hello expr (int) printf ("\n\nHello, anybody!\n\n")''' ) self.runCmd("command alias python script") # We don't want to display the stdout if not in TraceOn() mode. if not self.TraceOn(): self.HideStdout() self.runCmd(r'''python print "\n\n\nWhoopee!\n\n\n"''') # self.expect (r'''python print "\n\n\nWhoopee!\n\n\n"''', # substrs = [ "Whoopee!" ]) self.runCmd(r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') # self.expect (r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''', # substrs = [ "hello" ]) self.runCmd( r'''command alias pp python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') self.runCmd("pp") # self.expect ("pp", # substrs = [ "hello" ]) self.runCmd("command alias alias command alias") self.runCmd("command alias unalias command unalias") self.runCmd("alias myrun process launch -t %1 --") self.runCmd("alias bp breakpoint") self.expect("alias bpa bp add", COMMAND_FAILED_AS_EXPECTED, error=True, substrs=["'add' is not a valid sub-command of 'bp'"]) self.runCmd("alias bpa bp command add") self.runCmd("alias bpi bp list") break_results = lldbutil.run_break_set_command(self, "bp set -n foo") lldbutil.check_breakpoint_result(self, break_results, num_locations=1, symbol_name='foo', symbol_match_exact=False) break_results = lldbutil.run_break_set_command(self, "bp set -n sum") lldbutil.check_breakpoint_result(self, break_results, num_locations=1, symbol_name='sum', symbol_match_exact=False) self.runCmd("alias bfl bp set -f %1 -l %2") break_results = lldbutil.run_break_set_command(self, "bfl main.cpp 32") lldbutil.check_breakpoint_result(self, break_results, num_locations=1, file_name='main.cpp', line_number=32) self.expect("bpi", startstr="Current breakpoints:", substrs=[ "1: name = 'foo', locations = 1", "2: name = 'sum', locations = 1", "3: file = 'main.cpp', line = 32, locations = 1" ]) self.runCmd("bpa -s python 1 -o 'print frame; print bp_loc'") self.runCmd("bpa -s command 2 -o 'frame variable b'") self.expect("bpi -f", substrs=[ "Current breakpoints:", "1: name = 'foo', locations = 1", "print frame; print bp_loc", "2: name = 'sum', locations = 1", "frame variable b" ]) self.expect( "help run", substrs=[ "'run' is an abbreviation for 'process launch -c /bin/sh --'" ]) self.expect( "help -a run", substrs=[ "'run' is an abbreviation for 'process launch -c /bin/sh --'" ]) self.expect("help", substrs=['run', 'process launch -c /bin/sh']) self.expect("help -a", matching=False, substrs=["'run'", 'process launch -c /bin/sh']) self.expect("run", patterns=["Process .* launched: .*a.out"]) self.expect(r'''expression (int) printf("\x68\x65\x6c\x6c\x6f\n")''', substrs=["(int) $", "= 6"]) self.expect("hello", substrs=["(int) $", "= 19"]) self.expect("expr -f x -- 68", substrs=["(int) $", "= 0x00000044"]) self.runCmd("alias exprf expr -f %1") self.runCmd("alias exprf2 expr --raw -f %1 --") self.expect("exprf x -- 1234", substrs=["(int) $", "= 0x000004d2"]) self.expect('exprf2 c "Hi there!"', substrs=[ "[0] = 'H'", "[1] = 'i'", "[2] = ' '", "[3] = 't'", "[4] = 'h'", "[5] = 'e'", "[6] = 'r'", "[7] = 'e'", "[8] = '!'", "[9] = '\\0'" ]) self.expect("exprf x 1234", COMMAND_FAILED_AS_EXPECTED, error=True, substrs=["1 errors parsing expression"])
def running_abbreviations(self): exe = os.path.join(os.getcwd(), "a.out") self.expect("fil " + 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=[' push', ' mov', ' addl ', 'ret'], patterns=['(leave|popq|popl)']) 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/libstdc++', '/usr/lib/libSystem.B.dylib' ])
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.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. self.runCmd("dis -f") disassembly = self.res.GetOutput() if self.getArchitecture() in ["", 'x86_64', 'i386']: # hey! we shouldn't have a software breakpoint in here self.assertFalse("int3" in disassembly) self.expect(disassembly, exe=False, startstr = "a.out`sum(int, int)", substrs = [' mov', ' addl ', 'ret']) else: self.fail('unimplemented for arch = "{arch}"'.format(arch=self.getArchitecture())) 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 self.platformIsDarwin(): self.expect("i li", substrs = [ 'a.out', '/usr/lib/dyld', '/usr/lib/libSystem.B.dylib'])
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:]. symbol_name = "+[NSString stringWithFormat:]" break_results = lldbutil.run_break_set_command( self, "_regexp-break %s" % (symbol_name)) lldbutil.check_breakpoint_result(self, break_results, symbol_name=symbol_name, num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol(self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector(self, 'description', num_expected_locations=1, module_name='a.out') # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command( self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result( self, break_results, symbol_name='-[NSAutoreleasePool release]', num_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")
def do_simple_disasm(self): """Do a bunch of simple disassemble commands.""" # Create a target by the debugger. target = self.dbg.CreateTarget("a.out") self.assertTrue(target, VALID_TARGET) print target for module in target.modules: print module # Stop at +[NSString stringWithFormat:]. symbol_name = "+[NSString stringWithFormat:]" break_results = lldbutil.run_break_set_command (self, "_regexp-break %s"%(symbol_name)) lldbutil.check_breakpoint_result (self, break_results, symbol_name=symbol_name, num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol (self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector (self, 'description', num_expected_locations=1, module_name='a.out') # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command (self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='-[NSAutoreleasePool release]', num_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")
def test_simple_disasm(self): """Test the lldb 'disassemble' command""" self.build() # Create a target by the debugger. target = self.dbg.CreateTarget("a.out") self.assertTrue(target, VALID_TARGET) print target for module in target.modules: print module # Stop at +[NSString stringWithFormat:]. symbol_name = "+[NSString stringWithFormat:]" break_results = lldbutil.run_break_set_command (self, "_regexp-break %s"%(symbol_name)) lldbutil.check_breakpoint_result (self, break_results, symbol_name=symbol_name, num_locations=1) # Stop at -[MyString initWithNSString:]. lldbutil.run_break_set_by_symbol (self, '-[MyString initWithNSString:]', num_expected_locations=1, sym_exact=True) # Stop at the "description" selector. lldbutil.run_break_set_by_selector (self, 'description', num_expected_locations=1, module_name='a.out') # Stop at -[NSAutoreleasePool release]. break_results = lldbutil.run_break_set_command (self, "_regexp-break -[NSAutoreleasePool release]") lldbutil.check_breakpoint_result (self, break_results, symbol_name='-[NSAutoreleasePool release]', num_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")