blob: c4bf88502f41deb87d12bd8cdf4952efafb567aa [file] [log] [blame]
Sean Callanana48fe162010-08-11 03:57:18 +00001//===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Johnny Chenff7c3e92010-12-20 21:45:22 +000010#include "lldb/Expression/ClangPersistentVariables.h"
Sean Callanan82b74c82010-08-12 01:56:52 +000011#include "lldb/Core/DataExtractor.h"
Sean Callanana48fe162010-08-11 03:57:18 +000012#include "lldb/Core/Log.h"
13#include "lldb/Core/StreamString.h"
Sean Callanan82b74c82010-08-12 01:56:52 +000014#include "lldb/Core/Value.h"
Sean Callanana48fe162010-08-11 03:57:18 +000015
Greg Clayton427f2902010-12-14 02:59:59 +000016using namespace lldb;
Sean Callanana48fe162010-08-11 03:57:18 +000017using namespace lldb_private;
Sean Callanan82b74c82010-08-12 01:56:52 +000018
Sean Callanana48fe162010-08-11 03:57:18 +000019ClangPersistentVariables::ClangPersistentVariables () :
Greg Clayton427f2902010-12-14 02:59:59 +000020 ClangExpressionVariableList(),
21 m_next_persistent_variable_id (0)
Sean Callanana48fe162010-08-11 03:57:18 +000022{
Sean Callanana48fe162010-08-11 03:57:18 +000023}
Sean Callanan82b74c82010-08-12 01:56:52 +000024
Greg Clayton427f2902010-12-14 02:59:59 +000025ClangExpressionVariableSP
26ClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp)
Sean Callanan82b74c82010-08-12 01:56:52 +000027{
Greg Clayton427f2902010-12-14 02:59:59 +000028 ClangExpressionVariableSP var_sp (CreateVariable(valobj_sp));
29 return var_sp;
Sean Callanan82b74c82010-08-12 01:56:52 +000030}
Sean Callanana6223432010-08-20 01:02:30 +000031
Greg Clayton427f2902010-12-14 02:59:59 +000032ClangExpressionVariableSP
Jim Inghamfa3a16a2011-03-31 00:19:25 +000033ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope,
34 const ConstString &name,
35 const TypeFromUser& user_type,
36 lldb::ByteOrder byte_order,
37 uint32_t addr_byte_size)
Sean Callanana6223432010-08-20 01:02:30 +000038{
Greg Clayton427f2902010-12-14 02:59:59 +000039 ClangExpressionVariableSP var_sp (GetVariable(name));
Sean Callanana6223432010-08-20 01:02:30 +000040
Greg Clayton427f2902010-12-14 02:59:59 +000041 if (!var_sp)
Jim Inghamfa3a16a2011-03-31 00:19:25 +000042 var_sp = CreateVariable(exe_scope, name, user_type, byte_order, addr_byte_size);
Greg Clayton427f2902010-12-14 02:59:59 +000043
44 return var_sp;
45}
46
47
48ConstString
49ClangPersistentVariables::GetNextPersistentVariableName ()
50{
51 char name_cstr[256];
52 ::snprintf (name_cstr, sizeof(name_cstr), "$%u", m_next_persistent_variable_id++);
53 ConstString name(name_cstr);
54 return name;
55}