2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBValueList.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/SBValueList.h"
|
|
|
|
#include "lldb/API/SBValue.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/ValueObjectList.h"
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-04-23 06:57:56 +08:00
|
|
|
class ValueListImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ValueListImpl () :
|
|
|
|
m_values()
|
2013-02-08 02:23:56 +08:00
|
|
|
{
|
2013-04-23 06:57:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueListImpl (const ValueListImpl& rhs) :
|
|
|
|
m_values(rhs.m_values)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueListImpl&
|
|
|
|
operator = (const ValueListImpl& rhs)
|
|
|
|
{
|
|
|
|
if (this == &rhs)
|
2013-02-08 02:23:56 +08:00
|
|
|
return *this;
|
2013-04-23 06:57:56 +08:00
|
|
|
m_values = rhs.m_values;
|
|
|
|
return *this;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetSize ()
|
|
|
|
{
|
|
|
|
return m_values.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Append (const lldb::SBValue& sb_value)
|
|
|
|
{
|
|
|
|
m_values.push_back(sb_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Append (const ValueListImpl& list)
|
|
|
|
{
|
|
|
|
for (auto val : list.m_values)
|
|
|
|
Append (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBValue
|
|
|
|
GetValueAtIndex (uint32_t index)
|
|
|
|
{
|
|
|
|
if (index >= GetSize())
|
2013-02-08 02:23:56 +08:00
|
|
|
return lldb::SBValue();
|
2013-04-23 06:57:56 +08:00
|
|
|
return m_values[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBValue
|
|
|
|
FindValueByUID (lldb::user_id_t uid)
|
|
|
|
{
|
|
|
|
for (auto val : m_values)
|
|
|
|
{
|
|
|
|
if (val.IsValid() && val.GetID() == uid)
|
|
|
|
return val;
|
2013-02-08 02:23:56 +08:00
|
|
|
}
|
2013-04-23 06:57:56 +08:00
|
|
|
return lldb::SBValue();
|
|
|
|
}
|
2014-11-22 05:45:03 +08:00
|
|
|
|
|
|
|
lldb::SBValue
|
2014-11-22 06:23:08 +08:00
|
|
|
GetFirstValueByName (const char* name) const
|
2014-11-22 05:45:03 +08:00
|
|
|
{
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
for (auto val : m_values)
|
|
|
|
{
|
|
|
|
if (val.IsValid() && val.GetName() &&
|
|
|
|
strcmp(name,val.GetName()) == 0)
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lldb::SBValue();
|
|
|
|
}
|
2013-02-08 02:23:56 +08:00
|
|
|
|
2013-04-23 06:57:56 +08:00
|
|
|
private:
|
|
|
|
std::vector<lldb::SBValue> m_values;
|
|
|
|
};
|
2013-02-08 02:23:56 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValueList::SBValueList () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBValueList::SBValueList (const SBValueList &rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (rhs.IsValid())
|
2013-02-08 02:23:56 +08:00
|
|
|
m_opaque_ap.reset (new ValueListImpl (*rhs));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<void*>(rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
SBValueList::SBValueList (const ValueListImpl *lldb_object_ptr) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_object_ptr)
|
2013-02-08 02:23:56 +08:00
|
|
|
m_opaque_ap.reset (new ValueListImpl (*lldb_object_ptr));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
|
|
|
|
static_cast<const void*>(lldb_object_ptr),
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBValueList::~SBValueList ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBValueList::IsValid () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return (m_opaque_ap.get() != NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-12-20 04:39:44 +08:00
|
|
|
void
|
|
|
|
SBValueList::Clear()
|
|
|
|
{
|
|
|
|
m_opaque_ap.reset();
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const SBValueList &
|
|
|
|
SBValueList::operator = (const SBValueList &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2013-02-08 02:23:56 +08:00
|
|
|
m_opaque_ap.reset (new ValueListImpl (*rhs));
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
ValueListImpl *
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValueList::operator->()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
ValueListImpl &
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValueList::operator*()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
const ValueListImpl *
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValueList::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
const ValueListImpl &
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValueList::operator*() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBValueList::Append (const SBValue &val_obj)
|
|
|
|
{
|
2013-02-08 02:23:56 +08:00
|
|
|
CreateIfNeeded ();
|
|
|
|
m_opaque_ap->Append (val_obj);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
|
|
|
|
{
|
|
|
|
if (val_obj_sp)
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2013-02-08 02:23:56 +08:00
|
|
|
m_opaque_ap->Append (SBValue(val_obj_sp));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 06:09:02 +08:00
|
|
|
void
|
|
|
|
SBValueList::Append (const lldb::SBValueList& value_list)
|
|
|
|
{
|
|
|
|
if (value_list.IsValid())
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
|
|
|
m_opaque_ap->Append (*value_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBValue
|
|
|
|
SBValueList::GetValueAtIndex (uint32_t idx) const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBValue sb_value;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2013-02-08 02:23:56 +08:00
|
|
|
sb_value = m_opaque_ap->GetValueAtIndex (idx);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_value.GetDescription (sstr);
|
2010-10-27 07:49:36 +08:00
|
|
|
log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<void*>(m_opaque_ap.get()), idx,
|
|
|
|
static_cast<void*>(sb_value.GetSP().get()), sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBValueList::GetSize () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
//if (log)
|
|
|
|
// log->Printf ("SBValueList::GetSize ()");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t size = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
size = m_opaque_ap->GetSize();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBValueList::GetSize (this.ap=%p) => %d",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()), size);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBValueList::CreateIfNeeded ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get() == NULL)
|
2013-02-08 02:23:56 +08:00
|
|
|
m_opaque_ap.reset (new ValueListImpl());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBValue
|
|
|
|
SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
|
|
|
|
{
|
|
|
|
SBValue sb_value;
|
2010-12-21 04:49:23 +08:00
|
|
|
if (m_opaque_ap.get())
|
2013-02-08 02:23:56 +08:00
|
|
|
sb_value = m_opaque_ap->FindValueByUID(uid);
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_value;
|
|
|
|
}
|
|
|
|
|
2014-11-22 05:45:03 +08:00
|
|
|
SBValue
|
2014-11-22 06:23:08 +08:00
|
|
|
SBValueList::GetFirstValueByName (const char* name) const
|
2014-11-22 05:45:03 +08:00
|
|
|
{
|
|
|
|
SBValue sb_value;
|
|
|
|
if (m_opaque_ap.get())
|
2014-11-22 06:23:08 +08:00
|
|
|
sb_value = m_opaque_ap->GetFirstValueByName(name);
|
2014-11-22 05:45:03 +08:00
|
|
|
return sb_value;
|
|
|
|
}
|
|
|
|
|
2013-02-08 06:22:27 +08:00
|
|
|
void *
|
2013-02-08 06:57:46 +08:00
|
|
|
SBValueList::opaque_ptr ()
|
2010-10-27 07:49:36 +08:00
|
|
|
{
|
|
|
|
return m_opaque_ap.get();
|
|
|
|
}
|
|
|
|
|
2013-02-08 02:23:56 +08:00
|
|
|
ValueListImpl &
|
2011-06-30 06:09:02 +08:00
|
|
|
SBValueList::ref ()
|
|
|
|
{
|
|
|
|
CreateIfNeeded();
|
|
|
|
return *m_opaque_ap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|