[Lldb-commits] [lldb] r113660 - in /lldb/trunk: include/lldb/API/SBValue.h include/lldb/Core/ValueObject.h include/lldb/Target/ObjCObjectPrinter.h source/API/SBValue.cpp source/Commands/CommandObjectFrame.cpp source/Core/ValueObject.cpp source/Target/ObjCObjectPrinter.cpp

Jim Ingham jingham at apple.com
Fri Sep 10 16:12:17 PDT 2010


Author: jingham
Date: Fri Sep 10 18:12:17 2010
New Revision: 113660

URL: http://llvm.org/viewvc/llvm-project?rev=113660&view=rev
Log:
Move the "Object Description" into the ValueObject, and the add an API to
SBValue to access it.  For now this is just the result of ObjC NSPrintForDebugger,
but could be extended.  Also store the results of the ObjC Object Printer in a
Stream, not a ConstString.

Modified:
    lldb/trunk/include/lldb/API/SBValue.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Target/ObjCObjectPrinter.h
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Target/ObjCObjectPrinter.cpp

Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Fri Sep 10 18:12:17 2010
@@ -49,6 +49,9 @@
 
     const char *
     GetSummary (const lldb::SBFrame &frame);
+    
+    const char *
+    GetObjectDescription (const lldb::SBFrame &frame);
 
     const char *
     GetLocation (const lldb::SBFrame &frame);

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Fri Sep 10 18:12:17 2010
@@ -140,6 +140,10 @@
 
     const char *
     GetSummaryAsCString (ExecutionContextScope *exe_scope);
+    
+    const char *
+    GetObjectDescription (ExecutionContextScope *exe_scope);
+
 
     lldb::user_id_t
     GetUpdateID() const;
@@ -190,6 +194,8 @@
     std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
     std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
     std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
+    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
+                                              // in that the summary is consed up by us, the object_desc_string is builtin.
     std::vector<lldb::ValueObjectSP> m_children;
     std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children;
     bool                m_value_is_valid:1,

Modified: lldb/trunk/include/lldb/Target/ObjCObjectPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCObjectPrinter.h?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCObjectPrinter.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCObjectPrinter.h Fri Sep 10 18:12:17 2010
@@ -31,7 +31,7 @@
         ~ObjCObjectPrinter ();
         
         bool
-        PrintObject (ConstString &str, Value &object_ptr, ExecutionContext &exe_ctx);
+        PrintObject (Stream &str, Value &object_ptr, ExecutionContext &exe_ctx);
     protected:
         Process                 &m_process;
         std::auto_ptr<Address>  m_PrintForDebugger_addr;

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Fri Sep 10 18:12:17 2010
@@ -176,6 +176,15 @@
     return value_string;
 }
 
+const char *
+SBValue::GetObjectDescription (const SBFrame &frame)
+{
+    const char *value_string = NULL;
+    if ( m_opaque_sp)
+        value_string = m_opaque_sp->GetObjectDescription (frame.get());
+    return value_string;
+}
+
 bool
 SBValue::GetValueDidChange (const SBFrame &frame)
 {

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Fri Sep 10 18:12:17 2010
@@ -444,41 +444,11 @@
                 
                 if (use_objc)
                 {
-                    if (!ClangASTContext::IsPointerType (valobj->GetOpaqueClangQualType()))
-                        return;
-                    
-                    if (!valobj->GetValueIsValid())
-                        return;
-                    
-                    Process *process = exe_scope->CalculateProcess();
-                    
-                    if (!process)
-                        return;
-                    
-                    Scalar scalar;
-                    
-                    if (!ClangASTType::GetValueAsScalar (valobj->GetClangAST(),
-                                                        valobj->GetOpaqueClangQualType(),
-                                                        valobj->GetDataExtractor(),
-                                                        0,
-                                                        valobj->GetByteSize(),
-                                                        scalar))
-                        return;
-                                        
-                    ConstString po_output;
-                    
-                    ExecutionContext exe_ctx;
-                    exe_scope->Calculate(exe_ctx);
-                    
-                    Value val(scalar);
-                    val.SetContext(Value::eContextTypeOpaqueClangQualType, 
-                                   ClangASTContext::GetVoidPtrType(valobj->GetClangAST(), false));
-                    
-                    if (!process->GetObjCObjectPrinter().PrintObject(po_output, val, exe_ctx))
-                        return;
-                    
-                    s.Printf("\n%s\n", po_output.GetCString());
-                                        
+                    const char *object_desc = valobj->GetObjectDescription(exe_scope);
+                    if (object_desc)
+                        s.Printf("\n%s\n", object_desc);
+                    else
+                        s.Printf ("No description available.\n");
                     return;
                 }
 

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri Sep 10 18:12:17 2010
@@ -24,6 +24,7 @@
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/Type.h"
 
+#include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/Thread.h"
@@ -48,6 +49,7 @@
     m_old_value_str (),
     m_location_str (),
     m_summary_str (),
+    m_object_desc_str (),
     m_children (),
     m_synthetic_children (),
     m_value_is_valid (false),
@@ -96,6 +98,7 @@
                 }
                 m_location_str.clear();
                 m_summary_str.clear();
+                m_object_desc_str.clear();
 
                 const bool value_was_valid = GetValueIsValid();
                 SetValueDidChange (false);
@@ -499,6 +502,48 @@
     return m_summary_str.c_str();
 }
 
+const char *
+ValueObject::GetObjectDescription (ExecutionContextScope *exe_scope)
+{
+    if (!m_object_desc_str.empty())
+        return m_object_desc_str.c_str();
+        
+    if (!ClangASTContext::IsPointerType (GetOpaqueClangQualType()))
+        return NULL;
+    
+    if (!GetValueIsValid())
+        return NULL;
+    
+    Process *process = exe_scope->CalculateProcess();
+    
+    if (!process)
+        return NULL;
+    
+    Scalar scalar;
+    
+    if (!ClangASTType::GetValueAsScalar (GetClangAST(),
+                                        GetOpaqueClangQualType(),
+                                        GetDataExtractor(),
+                                        0,
+                                        GetByteSize(),
+                                        scalar))
+        return NULL;
+                        
+    ExecutionContext exe_ctx;
+    exe_scope->Calculate(exe_ctx);
+    
+    Value val(scalar);
+    val.SetContext(Value::eContextTypeOpaqueClangQualType, 
+                   ClangASTContext::GetVoidPtrType(GetClangAST(), false));
+                   
+    StreamString s;
+    // FIXME: Check the runtime this object belongs to and get the appropriate object printer for the object kind.
+    if (process->GetObjCObjectPrinter().PrintObject(s, val, exe_ctx))
+    {
+        m_object_desc_str.append (s.GetData());
+    }
+    return m_object_desc_str.c_str();
+}
 
 const char *
 ValueObject::GetValueAsCString (ExecutionContextScope *exe_scope)

Modified: lldb/trunk/source/Target/ObjCObjectPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCObjectPrinter.cpp?rev=113660&r1=113659&r2=113660&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCObjectPrinter.cpp (original)
+++ lldb/trunk/source/Target/ObjCObjectPrinter.cpp Fri Sep 10 18:12:17 2010
@@ -38,7 +38,7 @@
 }
 
 bool
-ObjCObjectPrinter::PrintObject (ConstString &str, Value &object_ptr, ExecutionContext &exe_ctx)
+ObjCObjectPrinter::PrintObject (Stream &str, Value &object_ptr, ExecutionContext &exe_ctx)
 {
     if (!exe_ctx.process)
         return false;
@@ -64,8 +64,14 @@
     lldb::addr_t wrapper_struct_addr = LLDB_INVALID_ADDRESS;
     func.InsertFunction(exe_ctx, wrapper_struct_addr, error_stream);
     // FIXME: Check result of ExecuteFunction.
-    func.ExecuteFunction(exe_ctx, &wrapper_struct_addr, error_stream, true, 1000, true, ret);
-        
+    ClangFunction::ExecutionResults results 
+        = func.ExecuteFunction(exe_ctx, &wrapper_struct_addr, error_stream, true, 1000, true, ret);
+    if (results != ClangFunction::eExecutionCompleted)
+    {
+        str.Printf("Error evaluating Print Object function: %d.\n", results);
+        return false;
+    }
+       
     addr_t result_ptr = ret.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
     
     // poor man's strcpy
@@ -86,7 +92,7 @@
     
     if (!desc.empty())
     {
-        str.SetCString(&desc.front());
+        str.PutCString(&desc.front());
         return true;
     }
     return false;





More information about the lldb-commits mailing list