[Lldb-commits] [lldb] r137801 - in /lldb/trunk: include/lldb/Interpreter/CommandObject.h include/lldb/Interpreter/ScriptInterpreter.h include/lldb/Interpreter/ScriptInterpreterPython.h source/Commands/CommandObjectCommands.cpp source/Interpreter/CommandObject.cpp source/Interpreter/ScriptInterpreterPython.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp test/functionalities/alias/TestAliases.py test/functionalities/alias/welcome.py

Enrico Granata granata.enrico at gmail.com
Tue Aug 16 18:30:04 PDT 2011


Author: enrico
Date: Tue Aug 16 20:30:04 2011
New Revision: 137801

URL: http://llvm.org/viewvc/llvm-project?rev=137801&view=rev
Log:
When defining a scripted command, it is possible to provide a docstring and that will be used as the help text for the command
 If no docstring is provided, a default help text is created
LLDB will refuse to create scripted commands if the scripting language is anything but Python
Some additional comments in AppleObjCRuntimeV2.cpp to describe the memory layout expected by the dynamic type lookup code

Modified:
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/test/functionalities/alias/TestAliases.py
    lldb/trunk/test/functionalities/alias/welcome.py

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Tue Aug 16 20:30:04 2011
@@ -112,6 +112,9 @@
     SetHelpLong (const char * str);
 
     void
+    SetHelpLong (std::string str);
+
+    void
     SetSyntax (const char *str);
 
     virtual void

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Tue Aug 16 20:30:04 2011
@@ -191,6 +191,12 @@
     {
         return false;
     }
+    
+    virtual std::string
+    GetDocumentationForItem(const char* item)
+    {
+        return std::string("");
+    }
 
     const char *
     GetScriptInterpreterPtyName ();

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Tue Aug 16 20:30:04 2011
@@ -109,6 +109,9 @@
     static std::string
     CallPythonScriptFunction (const char *python_function_name,
                               lldb::ValueObjectSP valobj);
+    
+    virtual std::string
+    GetDocumentationForItem(const char* item);
 
     void
     CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue Aug 16 20:30:04 2011
@@ -24,6 +24,8 @@
 #include "lldb/Interpreter/CommandObjectRegexCommand.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/Options.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Interpreter/ScriptInterpreterPython.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -1155,6 +1157,13 @@
                    NULL),
     m_function_name(funct)
     {
+        ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
+        if (scripter)
+        {
+            std::string docstring = scripter->GetDocumentationForItem(funct.c_str());
+            if (!docstring.empty())
+                SetHelpLong(docstring);
+        }
     }
     
     virtual
@@ -1427,6 +1436,14 @@
      CommandReturnObject &result
      )
     {
+        
+        if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython)
+        {
+            result.AppendError ("only scripting language supported for scripted commands is currently Python");
+            result.SetStatus (eReturnStatusFailed);
+            return false;
+        }
+        
         size_t argc = args.GetArgumentCount();
         
         if (argc != 1)

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Tue Aug 16 20:30:04 2011
@@ -129,6 +129,12 @@
 }
 
 void
+CommandObject::SetHelpLong (std::string str)
+{
+    m_cmd_help_long = str;
+}
+
+void
 CommandObject::SetSyntax (const char *cstr)
 {
     m_cmd_syntax = cstr;

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Tue Aug 16 20:30:04 2011
@@ -763,13 +763,13 @@
                 case eCharPtr: // "char *"
                 {
                     const char format[3] = "s#";
-                    success = PyArg_Parse (py_return, format, (char **) &ret_value);
+                    success = PyArg_Parse (py_return, format, (char **) ret_value);
                     break;
                 }
                 case eCharStrOrNone: // char* or NULL if py_return == Py_None
                 {
                     const char format[3] = "z";
-                    success = PyArg_Parse (py_return, format, (char **) &ret_value);
+                    success = PyArg_Parse (py_return, format, (char **) ret_value);
                     break;
                 }
                 case eBool:
@@ -1972,6 +1972,26 @@
     
 }
 
+// in Python, a special attribute __doc__ contains the docstring
+// for an object (function, method, class, ...) if any is defined
+// Otherwise, the attribute's value is None
+std::string
+ScriptInterpreterPython::GetDocumentationForItem(const char* item)
+{
+    std::string command(item);
+    command += ".__doc__";
+    
+    char* result_ptr = NULL; // Python is going to point this to valid data if ExecuteOneLineWithReturn returns successfully
+    
+    if (ExecuteOneLineWithReturn (command.c_str(),
+                                 ScriptInterpreter::eCharStrOrNone,
+                                 &result_ptr) && result_ptr)
+    {
+        return std::string(result_ptr);
+    }
+    else
+        return std::string("");
+}
 
 void
 ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Tue Aug 16 20:30:04 2011
@@ -568,9 +568,9 @@
 
 // tagged pointers are marked by having their least-significant bit
 // set. this makes them "invalid" as pointers because they violate
-// the alignment requirements. this way, we can always know when
-// we are dealing with a tagged pointer, and use the lookup approach
-// that the runtime would
+// the alignment requirements. of course, this detection algorithm
+// is not accurate (it might become better by incorporating further
+// knowledge about the internals of tagged pointers)
 bool
 AppleObjCRuntimeV2::IsTaggedPointer(lldb::addr_t ptr)
 {
@@ -578,6 +578,9 @@
 }
 
 
+// this code relies on the assumption that an Objective-C object always starts
+// with an ISA at offset 0. an ISA is effectively a pointer to an instance of
+// struct class_t in the ObjCv2 runtime
 lldb_private::ObjCLanguageRuntime::ObjCISA
 AppleObjCRuntimeV2::GetISA(ValueObject& valobj)
 {
@@ -587,8 +590,8 @@
     {
         // when using the expression parser, an additional layer of "frozen data"
         // can be created, which is basically a byte-exact copy of the data returned
-        // by the expression, but in host memory. because Python code might need to read
-        // into the object memory in non-obvious ways, we need to hand it the target version
+        // by the expression, but in host memory. because this code reads memory without
+        // taking the debug-info-provided object layout, we need to hand it the target version
         // of the expression output
         lldb::addr_t tgt_address = valobj.GetValueAsUnsigned();
         ValueObjectSP target_object = ValueObjectConstResult::Create (valobj.GetExecutionContextScope(),
@@ -647,9 +650,20 @@
     
     uint8_t pointer_size = m_process->GetAddressByteSize();
     Error error;
+    
+    /*
+     struct class_t *isa;
+     struct class_t *superclass;
+     Cache cache;
+     IMP *vtable;
+-->     uintptr_t data_NEVER_USE;
+     WARNING: this data_NEVER_USE pointer might one day contain flags in the least-significant bits
+     currently, rdar://problem/8955342 prevents the runtime from doing so
+     it presently is just a pointer to a class_rw_t
+     */
+    
     lldb::addr_t rw_pointer = isa + (4 * pointer_size);
     //printf("rw_pointer: %llx\n", rw_pointer);
-    
     uint64_t data_pointer =  m_process->ReadUnsignedIntegerFromMemory(rw_pointer,
                                                                       pointer_size,
                                                                       0,
@@ -657,6 +671,12 @@
     if (error.Fail())
         return ConstString("unknown");
     
+    /*
+     uint32_t flags;
+     uint32_t version;
+     
+-->     const class_ro_t *ro;
+     */
     data_pointer += 8;
     //printf("data_pointer: %llx\n", data_pointer);
     uint64_t ro_pointer = m_process->ReadUnsignedIntegerFromMemory(data_pointer,
@@ -666,6 +686,18 @@
     if (error.Fail())
         return ConstString("unknown");
     
+    /*
+     uint32_t flags;
+     uint32_t instanceStart;
+     uint32_t instanceSize;
+     #ifdef __LP64__
+     uint32_t reserved;
+     #endif
+     
+     const uint8_t * ivarLayout;
+     
+-->     const char * name;
+     */
     ro_pointer += 12;
     if (pointer_size == 8)
         ro_pointer += 4;
@@ -722,6 +754,10 @@
     
     uint8_t pointer_size = m_process->GetAddressByteSize();
     Error error;
+    /*
+     struct class_t *isa;
+-->     struct class_t *superclass;
+     */
     lldb::addr_t parent_pointer = isa + pointer_size;
     //printf("rw_pointer: %llx\n", rw_pointer);
     

Modified: lldb/trunk/test/functionalities/alias/TestAliases.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/alias/TestAliases.py?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/alias/TestAliases.py (original)
+++ lldb/trunk/test/functionalities/alias/TestAliases.py Tue Aug 16 20:30:04 2011
@@ -134,6 +134,10 @@
 
         self.expect('welcome Enrico',
             substrs = ['Hello Enrico, welcome to LLDB']);
+                
+        self.expect("help welcome",
+                    substrs = ['Just a docstring for welcome_impl',
+                               'A command that says hello to LLDB users'])
 
         self.runCmd("command script delete welcome");
 

Modified: lldb/trunk/test/functionalities/alias/welcome.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/alias/welcome.py?rev=137801&r1=137800&r2=137801&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/alias/welcome.py (original)
+++ lldb/trunk/test/functionalities/alias/welcome.py Tue Aug 16 20:30:04 2011
@@ -1,6 +1,10 @@
 import sys
 
 def welcome_impl(debugger, args, result, dict):
+    """
+        Just a docstring for welcome_impl
+        A command that says hello to LLDB users
+    """
     result.Printf('Hello ' + args + ', welcome to LLDB');
     return None;
 





More information about the lldb-commits mailing list