From 23f8c95a4439767cf9c7dc9d7a35eb55dc78b9d0 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Mon, 24 Mar 2014 23:10:19 +0000 Subject: JITed functions can now have debug info and be debugged with debug and source info: (lldb) b puts (lldb) expr -g -i0 -- (int)puts("hello") First we will stop at the entry point of the expression before it runs, then we can step over a few times and hit the breakpoint in "puts", then we can continue and finishing stepping and fininsh the expression. Main features: - New ObjectFileJIT class that can be easily created for JIT functions - debug info can now be enabled when parsing expressions - source for any function that is run throught the JIT is now saved in LLDB process specific temp directory and cleaned up on exit - "expr -g --" allows you to single step through your expression function with source code llvm-svn: 204682 --- lldb/source/Expression/ClangFunction.cpp | 46 +++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'lldb/source/Expression/ClangFunction.cpp') diff --git a/lldb/source/Expression/ClangFunction.cpp b/lldb/source/Expression/ClangFunction.cpp index f856f726696..a7e7ac01069 100644 --- a/lldb/source/Expression/ClangFunction.cpp +++ b/lldb/source/Expression/ClangFunction.cpp @@ -22,18 +22,20 @@ #include "llvm/IR/Module.h" // Project includes -#include "lldb/Expression/ASTStructExtractor.h" -#include "lldb/Expression/ClangExpressionParser.h" -#include "lldb/Expression/ClangFunction.h" -#include "lldb/Expression/IRExecutionUnit.h" -#include "lldb/Symbol/Type.h" #include "lldb/Core/DataExtractor.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/Module.h" #include "lldb/Core/State.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectList.h" +#include "lldb/Expression/ASTStructExtractor.h" +#include "lldb/Expression/ClangExpressionParser.h" +#include "lldb/Expression/ClangFunction.h" +#include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/Function.h" +#include "lldb/Symbol/Type.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" @@ -41,7 +43,6 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallFunction.h" -#include "lldb/Core/Log.h" using namespace lldb_private; @@ -55,6 +56,9 @@ ClangFunction::ClangFunction const Address& functionAddress, const ValueList &arg_value_list ) : + m_parser(), + m_execution_unit_sp(), + m_jit_module_wp(), m_function_ptr (NULL), m_function_addr (functionAddress), m_function_return_type(return_type), @@ -87,7 +91,7 @@ ClangFunction::ClangFunction m_compiled (false), m_JITted (false) { - m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess()); + m_jit_process_wp = exe_scope.CalculateProcess(); // Can't make a ClangFunction without a process. assert (m_jit_process_wp.lock()); @@ -100,6 +104,13 @@ ClangFunction::ClangFunction //---------------------------------------------------------------------- ClangFunction::~ClangFunction() { + lldb::ProcessSP process_sp (m_jit_process_wp.lock()); + if (process_sp) + { + lldb::ModuleSP jit_module_sp (m_jit_module_wp.lock()); + if (jit_module_sp) + process_sp->GetTarget().GetImages().Remove(jit_module_sp); + } } unsigned @@ -222,7 +233,8 @@ ClangFunction::CompileFunction (Stream &errors) lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); if (jit_process_sp) { - m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this)); + const bool generate_debug_info = true; + m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, generate_debug_info)); num_errors = m_parser->Parse (errors); } @@ -263,7 +275,7 @@ ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors) Error jit_error (m_parser->PrepareForExecution (m_jit_start_addr, m_jit_end_addr, - m_execution_unit_ap, + m_execution_unit_sp, exe_ctx, can_interpret, eExecutionPolicyAlways)); @@ -271,8 +283,22 @@ ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors) if (!jit_error.Success()) return false; + if (m_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; + process->GetTarget().GetImages().Append(jit_module_sp); + } + } if (process && m_jit_start_addr) - m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); + m_jit_process_wp = process->shared_from_this(); m_JITted = true; -- cgit v1.2.3