2010-08-11 11:57:18 +08:00
|
|
|
//===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-12-21 05:45:22 +08:00
|
|
|
#include "lldb/Expression/ClangPersistentVariables.h"
|
2010-08-12 09:56:52 +08:00
|
|
|
#include "lldb/Core/DataExtractor.h"
|
2010-08-11 11:57:18 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
2010-08-12 09:56:52 +08:00
|
|
|
#include "lldb/Core/Value.h"
|
2010-08-11 11:57:18 +08:00
|
|
|
|
2011-08-24 05:20:51 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
using namespace lldb;
|
2010-08-11 11:57:18 +08:00
|
|
|
using namespace lldb_private;
|
2010-08-12 09:56:52 +08:00
|
|
|
|
2010-08-11 11:57:18 +08:00
|
|
|
ClangPersistentVariables::ClangPersistentVariables () :
|
2010-12-14 10:59:59 +08:00
|
|
|
ClangExpressionVariableList(),
|
|
|
|
m_next_persistent_variable_id (0)
|
2010-08-11 11:57:18 +08:00
|
|
|
{
|
|
|
|
}
|
2010-08-12 09:56:52 +08:00
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
ClangExpressionVariableSP
|
|
|
|
ClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp)
|
2010-08-12 09:56:52 +08:00
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
ClangExpressionVariableSP var_sp (CreateVariable(valobj_sp));
|
|
|
|
return var_sp;
|
2010-08-12 09:56:52 +08:00
|
|
|
}
|
2010-08-20 09:02:30 +08:00
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
ClangExpressionVariableSP
|
2011-03-31 08:19:25 +08:00
|
|
|
ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope,
|
|
|
|
const ConstString &name,
|
|
|
|
const TypeFromUser& user_type,
|
|
|
|
lldb::ByteOrder byte_order,
|
|
|
|
uint32_t addr_byte_size)
|
2010-08-20 09:02:30 +08:00
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
ClangExpressionVariableSP var_sp (GetVariable(name));
|
2010-08-20 09:02:30 +08:00
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
if (!var_sp)
|
2011-03-31 08:19:25 +08:00
|
|
|
var_sp = CreateVariable(exe_scope, name, user_type, byte_order, addr_byte_size);
|
2010-12-14 10:59:59 +08:00
|
|
|
|
|
|
|
return var_sp;
|
|
|
|
}
|
|
|
|
|
2012-02-04 16:49:35 +08:00
|
|
|
void
|
|
|
|
ClangPersistentVariables::RemovePersistentVariable (lldb::ClangExpressionVariableSP variable)
|
|
|
|
{
|
|
|
|
RemoveVariable(variable);
|
|
|
|
|
|
|
|
const char *name = variable->GetName().AsCString();
|
|
|
|
|
|
|
|
if (*name != '$')
|
|
|
|
return;
|
|
|
|
name++;
|
|
|
|
|
|
|
|
if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1)
|
|
|
|
m_next_persistent_variable_id--;
|
|
|
|
}
|
2010-12-14 10:59:59 +08:00
|
|
|
|
|
|
|
ConstString
|
|
|
|
ClangPersistentVariables::GetNextPersistentVariableName ()
|
|
|
|
{
|
|
|
|
char name_cstr[256];
|
|
|
|
::snprintf (name_cstr, sizeof(name_cstr), "$%u", m_next_persistent_variable_id++);
|
|
|
|
ConstString name(name_cstr);
|
|
|
|
return name;
|
|
|
|
}
|
2011-08-24 05:20:51 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ClangPersistentVariables::RegisterPersistentType (const ConstString &name,
|
|
|
|
clang::TypeDecl *type_decl)
|
|
|
|
{
|
|
|
|
m_persistent_types.insert(std::pair<const char*, clang::TypeDecl*>(name.GetCString(), type_decl));
|
|
|
|
}
|
|
|
|
|
|
|
|
clang::TypeDecl *
|
|
|
|
ClangPersistentVariables::GetPersistentType (const ConstString &name)
|
|
|
|
{
|
|
|
|
PersistentTypeMap::const_iterator i = m_persistent_types.find(name.GetCString());
|
|
|
|
|
|
|
|
if (i == m_persistent_types.end())
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return i->second;
|
|
|
|
}
|