mirror of
https://github.com/intel/llvm.git
synced 2026-01-17 23:45:25 +08:00
expression parser. You can use a persistent
type like this:
(lldb) expr struct $foo { int a; int b; };
(lldb) struct $foo i; i.a = 2; i.b = 3; i
($foo) $0 = {
(int) a = 2
(int) b = 3
}
typedefs work similarly.
This patch affects the following files:
test/expression_command/persistent_types/*
A test case for persistent types,
in particular structs and typedefs.
ClangForward.h
Added TypeDecl, needed to declare some
functions in ASTResultSynthesizer.h
ClangPersistentVariables.[h,cpp]
Added a list of persistent types to the
persistent variable store.
ASTResultSynthesizer.[h,cpp]
Made the AST result synthesizer iterate
across TypeDecls in the expression, and
record any persistent types found. Also
made a minor documentation fix.
ClangUserExpression.[h,cpp]
Extended the user expression class to
keep the state needed to report the
persistent variable store for the target
to the AST result synthesizers.
Also introduced a new error code for
expressions that executed normally but
did not return a result.
CommandObjectExpression.cpp
Improved output for expressions (like
declarations of new persistent types) that
don't return a result. This is no longer
treated as an error.
llvm-svn: 138383
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
//===-- ClangPersistentVariables.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/Expression/ClangPersistentVariables.h"
|
|
#include "lldb/Core/DataExtractor.h"
|
|
#include "lldb/Core/Log.h"
|
|
#include "lldb/Core/StreamString.h"
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
ClangPersistentVariables::ClangPersistentVariables () :
|
|
ClangExpressionVariableList(),
|
|
m_next_persistent_variable_id (0)
|
|
{
|
|
}
|
|
|
|
ClangExpressionVariableSP
|
|
ClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp)
|
|
{
|
|
ClangExpressionVariableSP var_sp (CreateVariable(valobj_sp));
|
|
return var_sp;
|
|
}
|
|
|
|
ClangExpressionVariableSP
|
|
ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope,
|
|
const ConstString &name,
|
|
const TypeFromUser& user_type,
|
|
lldb::ByteOrder byte_order,
|
|
uint32_t addr_byte_size)
|
|
{
|
|
ClangExpressionVariableSP var_sp (GetVariable(name));
|
|
|
|
if (!var_sp)
|
|
var_sp = CreateVariable(exe_scope, name, user_type, byte_order, addr_byte_size);
|
|
|
|
return var_sp;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|