From 5eb99ccd3e5f7dcf4da17072503995f723f81ec9 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Fri, 24 Aug 2012 21:20:14 +0000 Subject: [PATCH] Providing an additional Python command example llvm-svn: 162600 --- lldb/www/python-reference.html | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lldb/www/python-reference.html b/lldb/www/python-reference.html index 3fa8af46e08c..e1d7f9da690b 100755 --- a/lldb/www/python-reference.html +++ b/lldb/www/python-reference.html @@ -430,6 +430,39 @@ total 365848

A template has been created in the source repository that can help you to create lldb command quickly:

cmdtemplate.py +

+ A commonly required facility is being able to create a command that does some token substitution, and then runs a different debugger command + (usually, it po'es the result of an expression evaluated on its argument). For instance, given the following program: +


+#import <Foundation/Foundation.h>
+NSString*
+ModifyString(NSString* src)
+{
+	return [src stringByAppendingString:@"foobar"];
+}
+
+int main()
+{
+	NSString* aString = @"Hello world";
+	NSString* anotherString = @"Let's be friends";
+	return 1;
+}
+		
+ you may want a pofoo X command, that equates po [ModifyString(X) capitalizedString]. + The following debugger interaction shows how to achieve that goal: +

+(lldb) script
+Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
+>>> def pofoo_funct(debugger, command, result, internal_dict):
+...	cmd = "po [ModifyString(" + command + ") capitalizedString]"
+...	lldb.debugger.HandleCommand(cmd)
+... 
+>>> ^D
+(lldb) command script add pofoo -f pofoo_funct
+(lldb) pofoo aString
+$1 = 0x000000010010aa00 Hello Worldfoobar
+(lldb) pofoo anotherString
+$2 = 0x000000010010aba0 Let's Be Friendsfoobar

Using the lldb.py module in python