Files
clang-p2996/lldb/source/API/SBValue.cpp
Caroline Tice ceb6b1393d First pass at adding logging capabilities for the API functions. At the moment
it logs the function calls, their arguments and the return values.  This is not
complete or polished, but I am committing it now, at the request of someone who
really wants to use it, even though it's not really done.  It currently does not
attempt to log all the functions, just the most important ones.  I will be 
making further adjustments to the API logging code over the next few days/weeks.
(Suggestions for improvements are welcome).


Update the Python build scripts to re-build the swig C++ file whenever 
the python-extensions.swig file is modified.

Correct the help for 'log enable' command (give it the correct number & type of
arguments).

llvm-svn: 117349
2010-10-26 03:11:13 +00:00

334 lines
6.7 KiB
C++

//===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBValue.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBDebugger.h"
using namespace lldb;
using namespace lldb_private;
SBValue::SBValue () :
m_opaque_sp ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
if (log)
log->Printf ("SBValue::SBValue () ==> this = %p", this);
}
SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
m_opaque_sp (value_sp)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
if (log)
{
SBStream sstr;
GetDescription (sstr);
log->Printf ("SBValue::SBValue (const lldb::ValueObjectSP &value_sp) value_sp.get() = %p ==> this = %p (%s)",
value_sp.get(), this, sstr.GetData());
}
}
SBValue::~SBValue()
{
}
bool
SBValue::IsValid () const
{
return (m_opaque_sp.get() != NULL);
}
SBError
SBValue::GetError()
{
SBError sb_error;
if (m_opaque_sp.get())
sb_error.SetError(m_opaque_sp->GetError());
return sb_error;
}
const char *
SBValue::GetName()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBValue::GetName ()");
if (IsValid())
{
if (log)
log->Printf ("SBValue::GetName ==> %s", m_opaque_sp->GetName().AsCString());
return m_opaque_sp->GetName().AsCString();
}
else
{
if (log)
log->Printf ("SBValue::GetName ==> NULL");
return NULL;
}
}
const char *
SBValue::GetTypeName ()
{
if (IsValid())
return m_opaque_sp->GetTypeName().AsCString();
else
return NULL;
}
size_t
SBValue::GetByteSize ()
{
size_t result = 0;
if (IsValid())
result = m_opaque_sp->GetByteSize();
return result;
}
bool
SBValue::IsInScope (const SBFrame &frame)
{
bool result = false;
if (IsValid())
result = m_opaque_sp->IsInScope (frame.get());
return result;
}
const char *
SBValue::GetValue (const SBFrame &frame)
{
const char *value_string = NULL;
if ( m_opaque_sp)
value_string = m_opaque_sp->GetValueAsCString (frame.get());
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)
{
if (IsValid())
return m_opaque_sp->GetValueDidChange (frame.get());
return false;
}
const char *
SBValue::GetSummary (const SBFrame &frame)
{
const char *value_string = NULL;
if ( m_opaque_sp)
value_string = m_opaque_sp->GetSummaryAsCString(frame.get());
return value_string;
}
const char *
SBValue::GetLocation (const SBFrame &frame)
{
const char *value_string = NULL;
if (IsValid())
value_string = m_opaque_sp->GetLocationAsCString(frame.get());
return value_string;
}
bool
SBValue::SetValueFromCString (const SBFrame &frame, const char *value_str)
{
bool success = false;
if (IsValid())
success = m_opaque_sp->SetValueFromCString (frame.get(), value_str);
return success;
}
SBValue
SBValue::GetChildAtIndex (uint32_t idx)
{
lldb::ValueObjectSP child_sp;
if (IsValid())
{
child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
}
SBValue sb_value (child_sp);
return sb_value;
}
uint32_t
SBValue::GetIndexOfChildWithName (const char *name)
{
if (IsValid())
return m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
return UINT32_MAX;
}
SBValue
SBValue::GetChildMemberWithName (const char *name)
{
lldb::ValueObjectSP child_sp;
const ConstString str_name (name);
if (IsValid())
{
child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
}
SBValue sb_value (child_sp);
return sb_value;
}
uint32_t
SBValue::GetNumChildren ()
{
uint32_t num_children = 0;
if (IsValid())
{
num_children = m_opaque_sp->GetNumChildren();
}
return num_children;
}
bool
SBValue::ValueIsStale ()
{
bool result = true;
if (IsValid())
{
result = m_opaque_sp->GetValueIsValid();
}
return result;
}
SBValue
SBValue::Dereference ()
{
if (IsValid())
{
if (m_opaque_sp->IsPointerType())
{
return GetChildAtIndex(0);
}
}
return *this;
}
bool
SBValue::TypeIsPtrType ()
{
bool is_ptr_type = false;
if (IsValid())
{
is_ptr_type = m_opaque_sp->IsPointerType();
}
return is_ptr_type;
}
void *
SBValue::GetOpaqueType()
{
if (m_opaque_sp)
return m_opaque_sp->GetClangType();
return NULL;
}
// Mimic shared pointer...
lldb_private::ValueObject *
SBValue::get() const
{
return m_opaque_sp.get();
}
lldb_private::ValueObject *
SBValue::operator->() const
{
return m_opaque_sp.get();
}
lldb::ValueObjectSP &
SBValue::operator*()
{
return m_opaque_sp;
}
const lldb::ValueObjectSP &
SBValue::operator*() const
{
return m_opaque_sp;
}
bool
SBValue::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
const char *name = GetName();
const char *type_name = GetTypeName ();
size_t byte_size = GetByteSize ();
uint32_t num_children = GetNumChildren ();
bool is_stale = ValueIsStale ();
description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
(type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
if (num_children > 0)
description.Printf (", num_children: %d", num_children);
if (is_stale)
description.Printf (" [value is stale]");
}
else
description.Printf ("No value");
return true;
}