Added a user-settable variable, 'target.expr-prefix',
which holds the name of a file whose contents are
prefixed to each expression. For example, if the file
~/lldb.prefix.header contains:
typedef unsigned short my_type;
then you can do this:
(lldb) settings set target.expr-prefix '~/lldb.prefix.header'
(lldb) expr sizeof(my_type)
(unsigned long) $0 = 2
When the variable is changed, the corresponding file
is loaded and its contents are fetched into a string
that is stored along with the target. This string
is then passed to each expression and inserted into
it during parsing, like this:
typedef unsigned short my_type;
void
$__lldb_expr(void *$__lldb_arg)
{
sizeof(my_type);
}
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@117627 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index 60f3e75..bd67bbd 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -35,8 +35,10 @@
using namespace lldb_private;
-ClangUserExpression::ClangUserExpression (const char *expr) :
+ClangUserExpression::ClangUserExpression (const char *expr,
+ const char *expr_prefix) :
m_expr_text(expr),
+ m_expr_prefix(expr_prefix),
m_transformed_text(),
m_jit_addr(LLDB_INVALID_ADDRESS),
m_cplusplus(false),
@@ -129,12 +131,14 @@
if (m_cplusplus)
{
- m_transformed_stream.Printf("typedef unsigned short unichar; \n"
+ m_transformed_stream.Printf("%s \n"
+ "typedef unsigned short unichar; \n"
"void \n"
"$__lldb_class::%s(void *$__lldb_arg) \n"
"{ \n"
" %s; \n"
"} \n",
+ m_expr_prefix.c_str(),
FunctionName(),
m_expr_text.c_str());
@@ -142,12 +146,14 @@
}
else
{
- m_transformed_stream.Printf("typedef unsigned short unichar;\n"
+ m_transformed_stream.Printf("%s \n"
+ "typedef unsigned short unichar;\n"
"void \n"
"%s(void *$__lldb_arg) \n"
"{ \n"
" %s; \n"
"} \n",
+ m_expr_prefix.c_str(),
FunctionName(),
m_expr_text.c_str());
}
@@ -425,11 +431,13 @@
lldb::ValueObjectSP
-ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr)
+ClangUserExpression::Evaluate (ExecutionContext &exe_ctx,
+ const char *expr_cstr,
+ const char *expr_prefix)
{
Error error;
lldb::ValueObjectSP result_valobj_sp;
- ClangUserExpression user_expression (expr_cstr);
+ ClangUserExpression user_expression (expr_cstr, expr_prefix);
StreamString error_stream;