Added a ClangUtilityFunction class that allows the
debugger to insert self-contained functions for use by
expressions (mainly for error-checking).
In order to support detecting whether a crash occurred
in one of these helpers -- currently our preferred way
of reporting that an error-check failed -- added a bit
of support for getting the extent of a JITted function
in addition to just its base.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@112324 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 05c237a..7c4cc6a 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -369,7 +369,9 @@
}
Error
-ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr, ExecutionContext &exe_ctx)
+ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr,
+ lldb::addr_t &func_end,
+ ExecutionContext &exe_ctx)
{
Error err;
@@ -507,7 +509,10 @@
(*pos).m_remote_addr = m_jit_mm->GetRemoteAddressForLocal ((*pos).m_local_addr);
if (!(*pos).m_name.compare(m_expr.FunctionName()))
+ {
+ func_end = m_jit_mm->GetRemoteRangeForLocal ((*pos).m_local_addr).second;
func_addr = (*pos).m_remote_addr;
+ }
}
err.Clear();
diff --git a/source/Expression/ClangFunction.cpp b/source/Expression/ClangFunction.cpp
index be107ca..3044d51 100644
--- a/source/Expression/ClangFunction.cpp
+++ b/source/Expression/ClangFunction.cpp
@@ -227,7 +227,9 @@
if (m_JITted)
return true;
- Error jit_error = m_parser->MakeJIT(m_wrapper_function_addr, exe_ctx);
+ lldb::addr_t wrapper_function_end;
+
+ Error jit_error = m_parser->MakeJIT(m_wrapper_function_addr, wrapper_function_end, exe_ctx);
if (!jit_error.Success())
return false;
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index afd94bb..d8841d3 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -45,6 +45,10 @@
m_transformed_text = m_transformed_stream.GetData();
}
+ClangUserExpression::~ClangUserExpression ()
+{
+}
+
clang::ASTConsumer *
ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough)
{
@@ -123,7 +127,9 @@
m_dwarf_opcodes.reset();
- Error jit_error = parser.MakeJIT (m_jit_addr, exe_ctx);
+ lldb::addr_t jit_end;
+
+ Error jit_error = parser.MakeJIT (m_jit_addr, jit_end, exe_ctx);
if (jit_error.Success())
{
diff --git a/source/Expression/ClangUtilityFunction.cpp b/source/Expression/ClangUtilityFunction.cpp
new file mode 100644
index 0000000..3acd3f2
--- /dev/null
+++ b/source/Expression/ClangUtilityFunction.cpp
@@ -0,0 +1,116 @@
+//===-- ClangUserExpression.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+// C++ Includes
+
+#include "lldb/Core/ConstString.h"
+#include "lldb/Core/Stream.h"
+#include "lldb/Expression/ClangExpressionParser.h"
+#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Target.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 (const char *text,
+ const char *name) :
+ m_function_text(text),
+ m_function_name(name)
+{
+}
+
+//------------------------------------------------------------------
+/// Install the utility function into a process
+///
+/// @param[in] error_stream
+/// A stream to print parse 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 (Stream &error_stream,
+ ExecutionContext &exe_ctx)
+{
+ ////////////////////////////////////
+ // Set up the target and compiler
+ //
+
+ Target *target = exe_ctx.target;
+
+ if (!target)
+ {
+ error_stream.PutCString ("error: invalid target\n");
+ return false;
+ }
+
+ ConstString target_triple;
+
+ target->GetTargetTriple (target_triple);
+
+ if (!target_triple)
+ target_triple = Host::GetTargetTriple ();
+
+ if (!target_triple)
+ {
+ error_stream.PutCString ("error: invalid target triple\n");
+ return false;
+ }
+
+ //////////////////////////
+ // Parse the expression
+ //
+
+ ClangExpressionParser parser(target_triple.GetCString(), *this);
+
+ unsigned num_errors = parser.Parse (error_stream);
+
+ if (num_errors)
+ {
+ error_stream.Printf ("error: %d errors parsing expression\n", num_errors);
+ return false;
+ }
+
+ //////////////////////////////////
+ // JIT the output of the parser
+ //
+
+ Error jit_error = parser.MakeJIT (m_jit_begin, m_jit_end, exe_ctx);
+
+ if (jit_error.Success())
+ {
+ return true;
+ }
+ else
+ {
+ error_stream.Printf ("error: expression can't be interpreted or run\n", num_errors);
+ return false;
+ }
+}
+
+