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.

llvm-svn: 113660
This commit is contained in:
Jim Ingham 2010-09-10 23:12:17 +00:00
parent cc766a20d3
commit 53c47f1e2f
7 changed files with 79 additions and 40 deletions

View File

@ -49,6 +49,9 @@ public:
const char *
GetSummary (const lldb::SBFrame &frame);
const char *
GetObjectDescription (const lldb::SBFrame &frame);
const char *
GetLocation (const lldb::SBFrame &frame);

View File

@ -140,6 +140,10 @@ public:
const char *
GetSummaryAsCString (ExecutionContextScope *exe_scope);
const char *
GetObjectDescription (ExecutionContextScope *exe_scope);
lldb::user_id_t
GetUpdateID() const;
@ -190,6 +194,8 @@ protected:
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,

View File

@ -31,7 +31,7 @@ namespace lldb_private {
~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;

View File

@ -176,6 +176,15 @@ SBValue::GetValue (const SBFrame &frame)
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)
{

View File

@ -444,41 +444,11 @@ public:
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;
}

View File

@ -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 @@ ValueObject::ValueObject () :
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 @@ ValueObject::UpdateValueIfNeeded (ExecutionContextScope *exe_scope)
}
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 @@ ValueObject::GetSummaryAsCString (ExecutionContextScope *exe_scope)
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)

View File

@ -38,7 +38,7 @@ ObjCObjectPrinter::~ObjCObjectPrinter ()
}
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 @@ ObjCObjectPrinter::PrintObject (ConstString &str, Value &object_ptr, ExecutionCo
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 @@ ObjCObjectPrinter::PrintObject (ConstString &str, Value &object_ptr, ExecutionCo
if (!desc.empty())
{
str.SetCString(&desc.front());
str.PutCString(&desc.front());
return true;
}
return false;