[Lldb-commits] [lldb] r141799 - in /lldb/trunk/examples/customization: ./ pwd-cd-and-system/ pwd-cd-and-system/.lldbinit pwd-cd-and-system/README pwd-cd-and-system/utils.py

Johnny Chen johnny.chen at apple.com
Wed Oct 12 12:16:06 PDT 2011


Author: johnny
Date: Wed Oct 12 14:16:06 2011
New Revision: 141799

URL: http://llvm.org/viewvc/llvm-project?rev=141799&view=rev
Log:
Add an examples/customization directory and add a subdirectory pwd-cd-and-system
which contains the lldb init file and a utils.py Python module in order to add
the 'pwd', 'cd', and 'system' lldb commands.

Added:
    lldb/trunk/examples/customization/
    lldb/trunk/examples/customization/pwd-cd-and-system/
    lldb/trunk/examples/customization/pwd-cd-and-system/.lldbinit
    lldb/trunk/examples/customization/pwd-cd-and-system/README
    lldb/trunk/examples/customization/pwd-cd-and-system/utils.py

Added: lldb/trunk/examples/customization/pwd-cd-and-system/.lldbinit
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/customization/pwd-cd-and-system/.lldbinit?rev=141799&view=auto
==============================================================================
--- lldb/trunk/examples/customization/pwd-cd-and-system/.lldbinit (added)
+++ lldb/trunk/examples/customization/pwd-cd-and-system/.lldbinit Wed Oct 12 14:16:06 2011
@@ -0,0 +1,6 @@
+script import os, sys
+script sys.path.append(os.path.expanduser('~'))
+script import utils
+command alias pwd script print os.getcwd()
+command script add -f utils.chdir cd
+command script add -f utils.system system

Added: lldb/trunk/examples/customization/pwd-cd-and-system/README
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/customization/pwd-cd-and-system/README?rev=141799&view=auto
==============================================================================
--- lldb/trunk/examples/customization/pwd-cd-and-system/README (added)
+++ lldb/trunk/examples/customization/pwd-cd-and-system/README Wed Oct 12 14:16:06 2011
@@ -0,0 +1,41 @@
+Files in this directory:
+
+o .lldbinit:
+
+An example lldb init file that imports the utils.py module and adds the
+following commands: 'pwd', 'cd', and 'system'.
+
+o utils.py:
+
+Python module which provides implementation for the 'cd' and 'system' commands.
+
+o README:
+
+The file you are reading now.
+
+================================================================================
+The following terminal output shows an interaction with lldb using the .lldbinit
+and the utils.py files which are located in my HOME directory.  The lldb init
+file imports the utils Python module and adds the 'pwd', 'cd', and 'system'
+commands.
+
+Johnnys-MacBook-Pro:multiple_threads johnny$ pwd
+/Volumes/data/lldb/svn/trunk/test/functionalities/watchpoint/multiple_threads
+Johnnys-MacBook-Pro:multiple_threads johnny$ lldb
+(lldb) pwd
+/Volumes/data/lldb/svn/trunk/test/functionalities/watchpoint/multiple_threads
+(lldb) cd ..
+Current working directory: /Volumes/data/lldb/svn/trunk/test/functionalities/watchpoint
+(lldb) help system
+
+Execute the command (a string) in a subshell.
+Syntax: system
+(lldb) system ls -l
+total 0
+drwxr-xr-x  7 johnny  admin  238 Oct 11 17:24 hello_watchlocation
+drwxr-xr-x  7 johnny  admin  238 Oct 11 17:24 hello_watchpoint
+drwxr-xr-x  7 johnny  admin  238 Oct 11 17:24 multiple_threads
+drwxr-xr-x  7 johnny  admin  238 Oct 11 17:24 watchpoint_commands
+
+retcode: 0
+(lldb) 

Added: lldb/trunk/examples/customization/pwd-cd-and-system/utils.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/customization/pwd-cd-and-system/utils.py?rev=141799&view=auto
==============================================================================
--- lldb/trunk/examples/customization/pwd-cd-and-system/utils.py (added)
+++ lldb/trunk/examples/customization/pwd-cd-and-system/utils.py Wed Oct 12 14:16:06 2011
@@ -0,0 +1,27 @@
+"""Utility for changing directories and execution of commands in a subshell."""
+
+import os, shlex, subprocess
+
+def chdir(debugger, args, result, dict):
+    """Change the working directory, or cd to ${HOME}."""
+    dir = args.strip()
+    if dir:
+        os.chdir(args)
+    else:
+        os.chdir(os.path.expanduser('~'))
+    print "Current working directory: %s" % os.getcwd()
+
+def system(debugger, command_line, result, dict):
+    """Execute the command (a string) in a subshell."""
+    args = shlex.split(command_line)
+    process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    output, error = process.communicate()
+    retcode = process.poll()
+    if output and error:
+        print "stdout=>\n", output
+        print "stderr=>\n", error
+    elif output:
+        print output
+    elif error:
+        print error
+    print "retcode:", retcode





More information about the lldb-commits mailing list