[Lldb-commits] [lldb] r182483 - Implement attach by name in LLDB Vim plugin using ":Lattach <process-name>"

Daniel Malea daniel.malea at intel.com
Wed May 22 09:04:28 PDT 2013


Author: dmalea
Date: Wed May 22 11:04:28 2013
New Revision: 182483

URL: http://llvm.org/viewvc/llvm-project?rev=182483&view=rev
Log:
Implement attach by name in LLDB Vim plugin using ":Lattach <process-name>"

patch by Arthur Evstifeev


Modified:
    lldb/trunk/utils/vim-lldb/plugin/lldb.vim
    lldb/trunk/utils/vim-lldb/python-vim-lldb/lldb_controller.py

Modified: lldb/trunk/utils/vim-lldb/plugin/lldb.vim
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/vim-lldb/plugin/lldb.vim?rev=182483&r1=182482&r2=182483&view=diff
==============================================================================
--- lldb/trunk/utils/vim-lldb/plugin/lldb.vim (original)
+++ lldb/trunk/utils/vim-lldb/plugin/lldb.vim Wed May 22 11:04:28 2013
@@ -47,6 +47,8 @@ function! s:InitLldbPlugin()
   " Launching convenience commands (no autocompletion)
   command -nargs=* Lstart                                                python ctrl.doLaunch(True,  '<args>')
   command -nargs=* Lrun                                                  python ctrl.doLaunch(False, '<args>')
+  command -nargs=1 Lattach                                               python ctrl.doAttach('<args>')
+  command -nargs=0 Ldetach                                               python ctrl.doDetach()
 
   " Regexp-commands: because vim's command mode does not support '_' or '-'
   " characters in command names, we omit them when creating the :L<cmd>

Modified: lldb/trunk/utils/vim-lldb/python-vim-lldb/lldb_controller.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/vim-lldb/python-vim-lldb/lldb_controller.py?rev=182483&r1=182482&r2=182483&view=diff
==============================================================================
--- lldb/trunk/utils/vim-lldb/python-vim-lldb/lldb_controller.py (original)
+++ lldb/trunk/utils/vim-lldb/python-vim-lldb/lldb_controller.py Wed May 22 11:04:28 2013
@@ -141,6 +141,33 @@ class LLDBController(object):
     else:
       self.doLaunch('-s' not in args, "")
 
+  def doAttach(self, process_name):
+    """ Handle process attach.  """
+    error = lldb.SBError()
+    
+    self.processListener = lldb.SBListener("process_event_listener")
+    self.target = self.dbg.CreateTarget('')
+    self.process = self.target.AttachToProcessWithName(self.processListener, process_name, False, error)
+    if not error.Success():
+      sys.stderr.write("Error during attach: " + str(error))
+      return
+
+    self.ui.activate()
+
+    # attach succeeded, store pid and add some event listeners
+    self.pid = self.process.GetProcessID()
+    self.process.GetBroadcaster().AddListener(self.processListener, lldb.SBProcess.eBroadcastBitStateChanged)
+    self.doContinue()
+
+    print "Attached to %s (pid=%d)" % (process_name, self.pid)
+
+  def doDetach(self):
+    if self.process is not None and self.process.IsValid():
+      pid = self.process.GetProcessID()
+      state = state_type_to_str(self.process.GetState())
+      self.process.Detach()
+      self.processPendingEvents(self.eventDelayLaunch)
+
   def doLaunch(self, stop_at_entry, args):
     """ Handle process launch.  """
     error = lldb.SBError()





More information about the lldb-commits mailing list