def run(self): self.setup() if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False LLDBLayoutManager.lldb_toggle_output_view(self.window, show=True) exe = LLDBPlugin.search_for_executable() sm = SettingsManager.getSM() arch = sm.get_default('arch', lldb.LLDB_ARCH_DEFAULT) if exe: args = map(str, sm.get_default('args', [])) debug(debugPlugin, 'Launching program: ' + exe + ' (' + arch + '), with args: ' + str(args)) t = driver_instance().debugger.CreateTargetWithFileAndArch(str(exe), str(arch)) driver_instance().debugger.SetSelectedTarget(t) sublime.status_message('Setting default breakpoints.') create_default_bps_for_target(t) sublime.status_message('Launching program (%s): %s %s' % (arch, exe, args)) if t.LaunchSimple(args, None, os.getcwd()): sublime.status_message('Program successfully launched.') else: sublime.error_message('Program failed to launch.')
def ensure_lldb_is_running(cls, w=None): """Returns True if lldb is running (we don't care if we started it or not). Returns False on error""" # Ensure we reflect any changes to saved settings (including project settings) # reload_settings() if not w and window_ref(): w = window_ref() else: # We're redefining the default window. set_window_ref(w) if driver_instance() is None: sm = SettingsManager.getSM() clear_view_on_startup = sm.get_default('i/o.view.clear_on_startup', True) if clear_view_on_startup: LLDBLayoutManager.clear_view(lldb_out_view()) if not cls.start_debugging(w): return False set_ui_updater(LLDBUIUpdater()) g = cls.lldb_greeting() if lldb_out_view().size() > 0: g = '\n\n' + cls.lldb_greeting() lldb_view_write(g) lldb_view_write('cwd: ' + os.getcwd() + '\n') w.set_view_index(lldb_out_view(), 1, 0) cls.debug_prologue(driver_instance()) return True return True
def start_debugging(cls, w): global _is_debugging if _is_debugging: cls.cleanup(window_ref()) cls.initialize_plugin() # Check for error conditions before starting the debugger global _did_not_find_debugserver, _macosx_is_too_old, _os_not_supported if _did_not_find_debugserver: sublime.error_message("Couldn't find the debugserver binary.\n" + \ 'Is XCode.app or the command line tools installed?') return False if _macosx_is_too_old: sublime.error_message('Your Mac OS X version is not supported.\n' + \ 'Supported versions: Lion and more recent\n\n' + \ 'If you think it should be supported, please contact the author.') return False if _os_not_supported: sublime.error_message('Your operating system is not supported by this plugin yet.\n' + \ 'If there is a stable version of lldb for your operating system and you would ' + \ 'like to have the plugin support it, please contact the author.') return False _is_debugging = True # Really start the debugger cls.initialize_lldb(w) driver_instance().debugger.SetInputFileHandle(sys.__stdin__, False) # We may also need to change the width upon window resize # debugger.SetTerminalWidth() return True
def run(self): self.setup() if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False LLDBLayoutManager.lldb_toggle_output_view(self.window, show=True) exe = LLDBPlugin.search_for_executable() sm = SettingsManager.getSM() arch = sm.get_default('arch', lldb.LLDB_ARCH_DEFAULT) if exe: args = map(str, sm.get_default('args', [])) debug( debugPlugin, 'Launching program: ' + exe + ' (' + arch + '), with args: ' + str(args)) t = driver_instance().debugger.CreateTargetWithFileAndArch( str(exe), str(arch)) driver_instance().debugger.SetSelectedTarget(t) sublime.status_message('Setting default breakpoints.') create_default_bps_for_target(t) sublime.status_message('Launching program (%s): %s %s' % (arch, exe, args)) if t.LaunchSimple(args, None, os.getcwd()): sublime.status_message('Program successfully launched.') else: sublime.error_message('Program failed to launch.')
def updated_content(self): debug(debugViews, 'Updating content for: %s' % repr(self)) # Reset the PC line number self.__pc_line = 0 thread = self.__thread if not thread.IsValid(): return 'Invalid thread. Has it finished its work?' target = thread.GetProcess().GetTarget() pc = thread.GetSelectedFrame().GetPCAddress() function = pc.GetFunction() symbol = pc.GetSymbol() if function.IsValid(): name = function.GetName() start_addr = function.GetStartAddress().GetLoadAddress(target) elif symbol.IsValid(): name = symbol.GetName() start_addr = symbol.GetStartAddress().GetLoadAddress(target) else: name = pc.GetModule().GetFileSpec().GetFilename() start_addr = pc.GetLoadAddress(target) instrs = driver_instance().disassemble_frame(thread.GetSelectedFrame()) if not instrs: return 'Error getting instructions for thread 0x%x: No instructions available.' % thread.GetThreadID( ) pc = driver_instance().get_PC() def get_max_sizes(accum, next): return (max(accum[0], len(next[1])), max(accum[1], len(next[2]))) (max_mnemonic, max_operands) = reduce(get_max_sizes, instrs, (0, 0)) format_str = '%.10s: %*s %*s%s\n' max_mnemonic, max_operands = (int(max_mnemonic), int(max_operands)) result = '%s @ 0x%s:\n' % (name, start_addr) n_instrs = 0 for i in instrs: n_instrs += 1 if len(i) == 3: (addr, mnemonic, ops) = i comment_str = '' elif len(i) == 4: (addr, mnemonic, ops, comment) = i comment_str = '\t; ' + comment else: assert False if pc == addr: self.__pc_line = n_instrs result += format_str % (hex(addr), max_mnemonic, mnemonic, max_operands, ops, comment_str) return result
def updated_content(self): debug(debugViews, 'Updating content for: %s' % repr(self)) # Reset the PC line number self.__pc_line = 0 thread = self.__thread if not thread.IsValid(): return 'Invalid thread. Has it finished its work?' target = thread.GetProcess().GetTarget() pc = thread.GetSelectedFrame().GetPCAddress() function = pc.GetFunction() symbol = pc.GetSymbol() if function.IsValid(): name = function.GetName() start_addr = function.GetStartAddress().GetLoadAddress(target) elif symbol.IsValid(): name = symbol.GetName() start_addr = symbol.GetStartAddress().GetLoadAddress(target) else: name = pc.GetModule().GetFileSpec().GetFilename() start_addr = pc.GetLoadAddress(target) instrs = driver_instance().disassemble_frame(thread.GetSelectedFrame()) if not instrs: return 'Error getting instructions for thread 0x%x: No instructions available.' % thread.GetThreadID() pc = driver_instance().get_PC() def get_max_sizes(accum, next): return (max(accum[0], len(next[1])), max(accum[1], len(next[2]))) (max_mnemonic, max_operands) = reduce(get_max_sizes, instrs, (0, 0)) format_str = '%.10s: %*s %*s%s\n' max_mnemonic, max_operands = (int(max_mnemonic), int(max_operands)) result = '%s @ 0x%s:\n' % (name, start_addr) n_instrs = 0 for i in instrs: n_instrs += 1 if len(i) == 3: (addr, mnemonic, ops) = i comment_str = '' elif len(i) == 4: (addr, mnemonic, ops, comment) = i comment_str = '\t; ' + comment else: assert False if pc == addr: self.__pc_line = n_instrs result += format_str % (hex(addr), max_mnemonic, mnemonic, max_operands, ops, comment_str) return result
def run(self, debugger=None): if debugger is None: debugger = driver_instance().debugger if debugger: target = debugger.GetSelectedTarget() if not target: return False proc = target.GetProcess() if not proc: return False proc.Stop() driver_instance().maybe_get_input()
def run(self, debugger=None): if debugger is None: debugger = driver_instance().debugger if debugger: # FIXME: DispatchEndOfFile should work, but we're working around it. debugger.DispatchInput('\x04')
def run(self, process=None): if process is None: process = driver_instance().current_process() if process: delegate = self.ViewMemoryDelegate(self, process) delegate.show_on_window(self.window, 'Address to inspect')
def run(self, target=None): self.setup() if len(disabled_bps()) > 0: for bp in disabled_bps(): if bp: bp.SetEnabled(True) set_disabled_bps([]) msg = 'Breakpoints disabled.' else: # bps are enabled. Disable them if target is None: target = driver_instance().current_target() if target: assert (len(disabled_bps()) == 0) for bp in target.breakpoint_iter(): if bp and bp.IsEnabled(): disabled_bps().append(bp) bp.SetEnabled(False) msg = 'Breakpoints enabled.' self.status_message(msg)
def run(self, target=None): self.setup() if target is None: target = driver_instance().debugger.GetSelectedTarget() if not target: sublime.error_message('No selected target.') return bp_list = [] for bp in target.breakpoint_iter(): # We're going to have to parse the description to know which kind # of breakpoint we have, since lldb doesn't reify that information. bp_list.append(self.parse_description(lldbutil.get_description(bp))) string = ', '.join(bp_list) v = self.window.get_output_panel('breakpoint list') LLDBLayoutManager.clear_view(v) v.set_read_only(False) edit = v.begin_edit('bp-list-view-clear') v.replace(edit, sublime.Region(0, v.size()), string) v.end_edit(edit) v.set_read_only(True) self.window.run_command('show_panel', {"panel": 'output.breakpoint list'})
def run(self, thread=None): self.setup() if thread is None: thread = driver_instance().current_thread() if thread: thread.StepInto(lldb.eOnlyThisThread)
def run(self, thread=None): self.setup() if thread is None: thread = driver_instance().current_thread() if thread: thread.StepInstruction(False)
def run(self, thread=None): self.setup() if thread is None: thread = driver_instance().current_thread() if thread: thread.StepOut()
def run(self, target=None): self.setup() if target is None: target = driver_instance().debugger.GetSelectedTarget() if not target: sublime.error_message('No selected target.') return bp_list = [] for bp in target.breakpoint_iter(): # We're going to have to parse the description to know which kind # of breakpoint we have, since lldb doesn't reify that information. bp_list.append(self.parse_description( lldbutil.get_description(bp))) string = ', '.join(bp_list) v = self.window.get_output_panel('breakpoint list') LLDBLayoutManager.clear_view(v) v.set_read_only(False) edit = v.begin_edit('bp-list-view-clear') v.replace(edit, sublime.Region(0, v.size()), string) v.end_edit(edit) v.set_read_only(True) self.window.run_command('show_panel', {"panel": 'output.breakpoint list'})
def run(self, target=None): self.setup() if target is None: target = driver_instance().current_target() result = '' if target: for i in xrange(0, target.GetNumModules()): debug(debugPlugin | debugVerbose, lldbutil.get_description(target.GetModuleAtIndex(i))) result += lldbutil.get_description(target.GetModuleAtIndex(i)) + '\n' # Re-use a view, if we already have one. v = None for _v in self.window.views(): if _v.name() == self._shared_libraries_view_name: v = _v break if v is None: v = self.window.new_file() v.set_name(self._shared_libraries_view_name) LLDBLayoutManager.clear_view(v) v.set_scratch(True) v.set_read_only(False) edit = v.begin_edit('lldb-shared-libraries-list') v.insert(edit, 0, result) v.end_edit(edit) v.set_read_only(True)
def run(self, target=None): self.setup() if target is None: target = driver_instance().current_target() result = '' if target: for i in xrange(0, target.GetNumModules()): debug(debugPlugin | debugVerbose, lldbutil.get_description(target.GetModuleAtIndex(i))) result += lldbutil.get_description( target.GetModuleAtIndex(i)) + '\n' # Re-use a view, if we already have one. v = None for _v in self.window.views(): if _v.name() == self._shared_libraries_view_name: v = _v break if v is None: v = self.window.new_file() v.set_name(self._shared_libraries_view_name) LLDBLayoutManager.clear_view(v) v.set_scratch(True) v.set_read_only(False) edit = v.begin_edit('lldb-shared-libraries-list') v.insert(edit, 0, result) v.end_edit(edit) v.set_read_only(True)
def on_done(self, string): if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False LLDBLayoutManager.lldb_toggle_output_view(self.window, show=True) driver = driver_instance() if driver: invalidListener = lldb.SBListener() error = lldb.SBError() target = driver.debugger.CreateTargetWithFileAndArch( None, None) sublime.status_message('Connecting to debugserver at: %s' % string) process = target.ConnectRemote(invalidListener, str(string), None, error) debug(debugPlugin, process) if error.Fail(): sublime.error_message("Connect failed: %s" % error.GetCString()) else: driver.debugger.SetSelectedTarget(target) sublime.status_message('Connected to debugserver.')
def run(self, target=None): self.setup() if len(disabled_bps()) > 0: for bp in disabled_bps(): if bp: bp.SetEnabled(True) set_disabled_bps([]) msg = 'Breakpoints disabled.' else: # bps are enabled. Disable them if target is None: target = driver_instance().current_target() if target: assert(len(disabled_bps()) == 0) for bp in target.breakpoint_iter(): if bp and bp.IsEnabled(): disabled_bps().append(bp) bp.SetEnabled(False) msg = 'Breakpoints enabled.' self.status_message(msg)
def run(self): self.setup() driver = driver_instance() if driver: sublime.status_message('Stopping the debugger.') LLDBPlugin.cleanup(self.window) sublime.status_message('Debugging session stopped.') else: sublime.error_message('Nothing to stop. Debugger not running.')
def run(self, target=None): self.setup() if target is None: target = driver_instance().current_target() if target: delegate = self.BreakAtSymbolDelegate(self, target) delegate.show_on_window(self.window, 'Symbol to break at')
def cleanup(cls, w=None): global _is_debugging _is_debugging = False set_disabled_bps([]) ui_updater().stop() driver = driver_instance() if driver: driver.stop() set_driver_instance(None) lldb_view_send('\nDebugging session ended.\n')
def run(self): self.setup() LLDBLayoutManager.lldb_toggle_output_view(self.window, show=True) if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False # lldb wasn't started by us. show the input panel if possible if not driver_instance().maybe_get_input(): sublime.error_message('Unable to send commands to the debugger.')
def run(self, target=None): self.setup() if target is None: target = driver_instance().current_target() v = self.window.active_view() if target and v: file = v.file_name() (line, col) = v.rowcol(v.sel()[0].begin()) if target.BreakpointCreateByLocation(str(file), line + 1): sublime.status_message('Breakpoint set at %s:%d' % (file, line)) else: sublime.error_message('Couldn\'t set breakpoint at %s:%d' % (file, line))
def run(self, process=None): self.setup() driver = driver_instance() if driver: if process is None: target = driver.debugger.GetSelectedTarget() if target: process = target.GetProcess() if process: process.Continue() # TODO: Decide what to do in case of errors. # e.g: Warn about no running program, etc. else: sublime.error_message('Nothing to continue. Debugger not running.')
def run(self, process=None): self.setup() driver = driver_instance() if driver: if process is None: target = driver.debugger.GetSelectedTarget() if target: process = target.GetProcess() if process: delegate = self.SendSignalDelegate(self, process) delegate.show_on_window(self.window, 'Signal number') # TODO: check what happens. From our standpoint, it seems the process terminated successfully. # on the lldb CLI interface, we see the signal. else: sublime.error_message('No running process.')
def run(self, thread=None): self.setup() if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False if thread is None: thread = driver_instance().current_thread() if not thread: return False base_disasm_view = get_lldb_output_view(self.window, lldb_disassembly_view_name(thread.GetThreadID())) if isinstance(base_disasm_view, LLDBThreadDisassemblyView): disasm_view = base_disasm_view else: disasm_view = LLDBThreadDisassemblyView(base_disasm_view, thread) disasm_view.full_update() self.window.focus_view(disasm_view.base_view())
def run(self, thread=None): self.setup() if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False if thread is None: thread = driver_instance().current_thread() if not thread: return False base_disasm_view = get_lldb_output_view( self.window, lldb_disassembly_view_name(thread.GetThreadID())) if isinstance(base_disasm_view, LLDBThreadDisassemblyView): disasm_view = base_disasm_view else: disasm_view = LLDBThreadDisassemblyView(base_disasm_view, thread) disasm_view.full_update() self.window.focus_view(disasm_view.base_view())
def on_done(self, string): if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False LLDBLayoutManager.lldb_toggle_output_view(self.window, show=True) driver = driver_instance() if driver: invalidListener = lldb.SBListener() error = lldb.SBError() target = driver.debugger.CreateTargetWithFileAndArch(None, None) sublime.status_message('Connecting to debugserver at: %s' % string) process = target.ConnectRemote(invalidListener, str(string), None, error) debug(debugPlugin, process) if error.Fail(): sublime.error_message("Connect failed: %s" % error.GetCString()) else: driver.debugger.SetSelectedTarget(target) sublime.status_message('Connected to debugserver.')
def is_enabled(self): driver = driver_instance() if driver and driver.current_target(): return not driver.process_is_stopped() return False
def is_enabled(self): driver = driver_instance() return driver is not None and driver.current_target()
def is_enabled(self): driver = driver_instance() return driver is not None and driver.debugger.GetSelectedTarget()
def is_enabled(self): driver = driver_instance() if driver: target = driver.debugger.GetSelectedTarget() return target and target.GetProcess()
def on_done(self, string): if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False driver = driver_instance() if driver: # Check if we have a previously running program target = driver.debugger.GetSelectedTarget() if not target: target = driver.debugger.CreateTarget('') if not target: sublime.error_message('Error attaching to process') driver.debugger.SetSelectedTarget(target) old_exec_module = target.GetExecutable() old_triple = target.GetTriple() # attach_info = lldb.SBAttachInfo() # If the user didn't specify anything, attach to the program from # the current target, if it exists # if string is '': # if old_exec_module: # attach_info.SetExecutable(old_exec_module) # else: # # Bail out # sublime.error_message('No process name/ID specified and no current target.') # return # else: error = lldb.SBError() sm = SettingsManager.getSM() wait_for_launch = sm.get_default('attach.wait_for_launch', False) try: pid = int(string) # attach_info.SetProcessID(pid) debug(debugPlugin, 'Attaching to pid: %d' % pid) sublime.status_message('Attaching to pid: %d' % pid) process = target.AttachToProcessWithID(lldb.SBListener(), pid, error) except ValueError: # We have a process name, not a pid. # pid = lldb.LLDB_INVALID_PROCESS_ID # attach_info.SetExecutable(str(string)) name = str(string) if string != '' else old_exec_module debug(debugPlugin, 'Attaching to process: %s (wait=%s)' % (name, str(wait_for_launch))) sublime.status_message('Attaching to process: %s (wait=%s)' % (name, wait_for_launch)) process = target.AttachToProcessWithName(lldb.SBListener(), name, wait_for_launch, error) # attach_info.SetWaitForLaunch(wait_for_launch) # error = lldb.SBError() # debug(debugPlugin, attach_info) # process = target.Attach(attach_info, error) debug(debugPlugin, process) if error.Fail(): sublime.error_message("Attach failed: %s" % error.GetCString()) new_exec_module = target.GetExecutable() if new_exec_module != old_exec_module: debug(debugPlugin, 'Executable module changed from "%s" to "%s".' % \ (old_exec_module, new_exec_module)) new_triple = target.GetTriple() if new_triple != old_triple: debug(debugPlugin, 'Target triple changed from "%s" to "%s".' % (old_triple, new_triple)) # How can we setup the default breakpoints? # We *could* start a new thread with a listener, just for that... else: sublime.error_message('Couldn\'t get a debugging session.')
def is_enabled(self): driver = driver_instance() if driver: return driver.process_is_stopped() return False
def on_done(self, string): if LLDBPlugin.ensure_lldb_is_running(self.window): sublime.status_message('Debugging session started.') else: sublime.error_message('Couldn\'t get a debugging session.') return False driver = driver_instance() if driver: # Check if we have a previously running program target = driver.debugger.GetSelectedTarget() if not target: target = driver.debugger.CreateTarget('') if not target: sublime.error_message('Error attaching to process') driver.debugger.SetSelectedTarget(target) old_exec_module = target.GetExecutable() old_triple = target.GetTriple() # attach_info = lldb.SBAttachInfo() # If the user didn't specify anything, attach to the program from # the current target, if it exists # if string is '': # if old_exec_module: # attach_info.SetExecutable(old_exec_module) # else: # # Bail out # sublime.error_message('No process name/ID specified and no current target.') # return # else: error = lldb.SBError() sm = SettingsManager.getSM() wait_for_launch = sm.get_default('attach.wait_for_launch', False) try: pid = int(string) # attach_info.SetProcessID(pid) debug(debugPlugin, 'Attaching to pid: %d' % pid) sublime.status_message('Attaching to pid: %d' % pid) process = target.AttachToProcessWithID( lldb.SBListener(), pid, error) except ValueError: # We have a process name, not a pid. # pid = lldb.LLDB_INVALID_PROCESS_ID # attach_info.SetExecutable(str(string)) name = str(string) if string != '' else old_exec_module debug( debugPlugin, 'Attaching to process: %s (wait=%s)' % (name, str(wait_for_launch))) sublime.status_message( 'Attaching to process: %s (wait=%s)' % (name, wait_for_launch)) process = target.AttachToProcessWithName( lldb.SBListener(), name, wait_for_launch, error) # attach_info.SetWaitForLaunch(wait_for_launch) # error = lldb.SBError() # debug(debugPlugin, attach_info) # process = target.Attach(attach_info, error) debug(debugPlugin, process) if error.Fail(): sublime.error_message("Attach failed: %s" % error.GetCString()) new_exec_module = target.GetExecutable() if new_exec_module != old_exec_module: debug(debugPlugin, 'Executable module changed from "%s" to "%s".' % \ (old_exec_module, new_exec_module)) new_triple = target.GetTriple() if new_triple != old_triple: debug( debugPlugin, 'Target triple changed from "%s" to "%s".' % (old_triple, new_triple)) # How can we setup the default breakpoints? # We *could* start a new thread with a listener, just for that... else: sublime.error_message('Couldn\'t get a debugging session.')
def is_enabled(self): driver = driver_instance() return driver is not None