You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
libcxx
libcxxabi
libunwind
lld
lldb
cmake
docs
examples
include
lit
lldb.xcodeproj
lldb.xcworkspace
packages
resources
scripts
source
API
Breakpoint
Commands
Core
DataFormatters
Expression
Host
Initialization
Interpreter
Plugins
ABI
Architecture
Disassembler
DynamicLoader
ExpressionParser
Clang
ASTDumper.cpp
ASTDumper.h
ASTResultSynthesizer.cpp
ASTResultSynthesizer.h
ASTStructExtractor.cpp
ASTStructExtractor.h
CMakeLists.txt
ClangASTSource.cpp
ClangASTSource.h
ClangDiagnostic.h
ClangExpressionDeclMap.cpp
ClangExpressionDeclMap.h
ClangExpressionHelper.h
ClangExpressionParser.cpp
ClangExpressionParser.h
ClangExpressionVariable.cpp
ClangExpressionVariable.h
ClangFunctionCaller.cpp
ClangFunctionCaller.h
ClangModulesDeclVendor.cpp
ClangModulesDeclVendor.h
ClangPersistentVariables.cpp
ClangPersistentVariables.h
ClangUserExpression.cpp
ClangUserExpression.h
ClangUtilityFunction.cpp
ClangUtilityFunction.h
IRForTarget.cpp
IRForTarget.h
Go
CMakeLists.txt
Instruction
InstrumentationRuntime
JITLoader
Language
LanguageRuntime
MemoryHistory
ObjectContainer
ObjectFile
OperatingSystem
Platform
Process
ScriptInterpreter
StructuredData
SymbolFile
SymbolVendor
SystemRuntime
UnwindAssembly
CMakeLists.txt
Symbol
Target
Utility
CMakeLists.txt
lldb.cpp
third_party
tools
unittests
utils
www
.arcconfig
.clang-format
.gitignore
CMakeLists.txt
CODE_OWNERS.txt
INSTALL.txt
LICENSE.TXT
use_lldb_suite_root.py
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
164 lines
4.8 KiB
C++
164 lines
4.8 KiB
C++
![]() |
//===-- ClangUtilityFunction.cpp ---------------------------------*- C++-*-===//
|
||
|
//
|
||
|
// The LLVM Compiler Infrastructure
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "ClangUtilityFunction.h"
|
||
|
#include "ClangExpressionDeclMap.h"
|
||
|
#include "ClangExpressionParser.h"
|
||
|
|
||
|
// C Includes
|
||
|
#include <stdio.h>
|
||
|
#if HAVE_SYS_TYPES_H
|
||
|
#include <sys/types.h>
|
||
|
#endif
|
||
|
|
||
|
// C++ Includes
|
||
|
|
||
|
#include "lldb/Core/Module.h"
|
||
|
#include "lldb/Core/StreamFile.h"
|
||
|
#include "lldb/Expression/ExpressionSourceCode.h"
|
||
|
#include "lldb/Expression/IRExecutionUnit.h"
|
||
|
#include "lldb/Host/Host.h"
|
||
|
#include "lldb/Target/ExecutionContext.h"
|
||
|
#include "lldb/Target/Target.h"
|
||
|
#include "lldb/Utility/ConstString.h"
|
||
|
#include "lldb/Utility/Log.h"
|
||
|
#include "lldb/Utility/Stream.h"
|
||
|
|
||
|
using namespace lldb_private;
|
||
|
|
||
|
//------------------------------------------------------------------
|
||
|
/// Constructor
|
||
|
///
|
||
|
/// @param[in] text
|
||
|
/// The text of the function. Must be a full translation unit.
|
||
|
///
|
||
|
/// @param[in] name
|
||
|
/// The name of the function, as used in the text.
|
||
|
//------------------------------------------------------------------
|
||
|
ClangUtilityFunction::ClangUtilityFunction(ExecutionContextScope &exe_scope,
|
||
|
const char *text, const char *name)
|
||
|
: UtilityFunction(exe_scope, text, name) {}
|
||
|
|
||
|
ClangUtilityFunction::~ClangUtilityFunction() {}
|
||
|
|
||
|
//------------------------------------------------------------------
|
||
|
/// Install the utility function into a process
|
||
|
///
|
||
|
/// @param[in] diagnostic_manager
|
||
|
/// A diagnostic manager to report errors and warnings to.
|
||
|
///
|
||
|
/// @param[in] exe_ctx
|
||
|
/// The execution context to install the utility function to.
|
||
|
///
|
||
|
/// @return
|
||
|
/// True on success (no errors); false otherwise.
|
||
|
//------------------------------------------------------------------
|
||
|
bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
|
||
|
ExecutionContext &exe_ctx) {
|
||
|
if (m_jit_start_addr != LLDB_INVALID_ADDRESS) {
|
||
|
diagnostic_manager.PutString(eDiagnosticSeverityWarning,
|
||
|
"already installed");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////
|
||
|
// Set up the target and compiler
|
||
|
//
|
||
|
|
||
|
Target *target = exe_ctx.GetTargetPtr();
|
||
|
|
||
|
if (!target) {
|
||
|
diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
Process *process = exe_ctx.GetProcessPtr();
|
||
|
|
||
|
if (!process) {
|
||
|
diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid process");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//////////////////////////
|
||
|
// Parse the expression
|
||
|
//
|
||
|
|
||
|
bool keep_result_in_memory = false;
|
||
|
|
||
|
ResetDeclMap(exe_ctx, keep_result_in_memory);
|
||
|
|
||
|
if (!DeclMap()->WillParse(exe_ctx, NULL)) {
|
||
|
diagnostic_manager.PutString(
|
||
|
eDiagnosticSeverityError,
|
||
|
"current process state is unsuitable for expression parsing");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
const bool generate_debug_info = true;
|
||
|
ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this,
|
||
|
generate_debug_info);
|
||
|
|
||
|
unsigned num_errors = parser.Parse(diagnostic_manager);
|
||
|
|
||
|
if (num_errors) {
|
||
|
ResetDeclMap();
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//////////////////////////////////
|
||
|
// JIT the output of the parser
|
||
|
//
|
||
|
|
||
|
bool can_interpret = false; // should stay that way
|
||
|
|
||
|
Status jit_error = parser.PrepareForExecution(
|
||
|
m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx,
|
||
|
can_interpret, eExecutionPolicyAlways);
|
||
|
|
||
|
if (m_jit_start_addr != LLDB_INVALID_ADDRESS) {
|
||
|
m_jit_process_wp = process->shared_from_this();
|
||
|
if (parser.GetGenerateDebugInfo()) {
|
||
|
lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
|
||
|
|
||
|
if (jit_module_sp) {
|
||
|
ConstString const_func_name(FunctionName());
|
||
|
FileSpec jit_file;
|
||
|
jit_file.GetFilename() = const_func_name;
|
||
|
jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
|
||
|
m_jit_module_wp = jit_module_sp;
|
||
|
target->GetImages().Append(jit_module_sp);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DeclMap()->DidParse();
|
||
|
|
||
|
ResetDeclMap();
|
||
|
|
||
|
if (jit_error.Success()) {
|
||
|
return true;
|
||
|
} else {
|
||
|
const char *error_cstr = jit_error.AsCString();
|
||
|
if (error_cstr && error_cstr[0]) {
|
||
|
diagnostic_manager.Printf(eDiagnosticSeverityError, "%s", error_cstr);
|
||
|
} else {
|
||
|
diagnostic_manager.PutString(eDiagnosticSeverityError,
|
||
|
"expression can't be interpreted or run");
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap(
|
||
|
ExecutionContext &exe_ctx, bool keep_result_in_memory) {
|
||
|
m_expr_decl_map_up.reset(
|
||
|
new ClangExpressionDeclMap(keep_result_in_memory, nullptr, exe_ctx));
|
||
|
}
|