Go to the documentation of this file.
16 #include <sys/types.h>
35 bool enable_debugging)
40 std::move(name), enable_debugging) {
43 if (enable_debugging) {
45 llvm::SmallString<128> result_path;
46 llvm::sys::fs::createTemporaryFile(
"lldb",
"expr", temp_fd, result_path);
49 text =
"#line 1 \"" +
std::string(result_path) +
"\"\n" + text;
50 size_t bytes_written = text.size();
51 file.
Write(text.c_str(), bytes_written);
52 if (bytes_written == text.size()) {
106 bool keep_result_in_memory =
false;
110 if (!
DeclMap()->WillParse(exe_ctx,
nullptr)) {
113 "current process state is unsuitable for expression parsing");
117 const bool generate_debug_info =
true;
119 generate_debug_info);
121 unsigned num_errors = parser.
Parse(diagnostic_manager);
133 bool can_interpret =
false;
148 jit_module_sp->SetFileSpecAndObjectName(jit_file,
ConstString());
162 const char *error_cstr = jit_error.
AsCString();
163 if (error_cstr && error_cstr[0]) {
167 "expression can't be interpreted or run");
175 std::shared_ptr<ClangASTImporter> ast_importer;
176 auto *state = exe_ctx.
GetTargetSP()->GetPersistentExpressionStateForLanguage(
179 auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
180 ast_importer = persistent_vars->GetClangASTImporter();
183 keep_result_in_memory,
nullptr, exe_ctx.
GetTargetSP(), ast_importer,
lldb::ModuleWP m_jit_module_wp
Process * GetProcessPtr() const
Returns a pointer to the process object.
static const char * g_expression_suffix
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
ClangUtilityFunction(ExecutionContextScope &exe_scope, std::string text, std::string name, bool enable_debugging)
Constructor.
static const char * g_expression_prefix
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
@ eDiagnosticSeverityWarning
const ModuleList & GetImages() const
Get accessor for the images for this process.
Status Close() override
Flush any buffers and release any resources owned by the file.
bool Success() const
Test for success condition.
@ eDiagnosticSeverityError
bool GetGenerateDebugInfo() const
Status PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end, lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy) override
Ready an already-parsed expression for execution, possibly evaluating it statically.
lldb::addr_t m_jit_end_addr
The address of the JITted function within the JIT allocation.
unsigned Parse(DiagnosticManager &diagnostic_manager)
Parse a single expression and convert it to IR using Clang.
~ClangUtilityFunction() override
std::shared_ptr< IRExecutionUnit > m_execution_unit_sp
string(SUBSTRING ${p} 10 -1 pStripped) if($
bool Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override
Install the utility function into a process.
ClangExpressionDeclMap * DeclMap()
ExecutionContextScope * GetBestExecutionContextScope() const
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
std::string m_function_text
The text of the function. Must be a well-formed translation unit.
#define LLDB_INVALID_ADDRESS
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
@ eLanguageTypeC
Non-standardized C, such as K&R.
A class that represents a running process on the host machine.
Status Write(const void *buf, size_t &num_bytes) override
Write bytes from buf to a file at the current file position.
const char * FunctionName() override
Return the function name that should be used for executing the expression.
std::unique_ptr< ClangExpressionDeclMap > m_expr_decl_map_up
ConstString & GetFilename()
Filename string get accessor.
void DidParse()
Disable the state needed for parsing and IR transformation.
Target * GetTargetPtr() const
Returns a pointer to the target object.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
size_t Printf(DiagnosticSeverity severity, const char *format,...) __attribute__((format(printf
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.