summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/ASTResultSynthesizer.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2011-01-13 08:53:35 +0000
committerSean Callanan <scallanan@apple.com>2011-01-13 08:53:35 +0000
commit92adcac9ec01e0751db8d775b12ece52625b8804 (patch)
treeb4726e59e8eda9ef4cf12f228d23ab1fdb292919 /lldb/source/Expression/ASTResultSynthesizer.cpp
parent02cde7ffa49a637366e0d7f05122c582cc90d011 (diff)
downloadbcm5719-llvm-92adcac9ec01e0751db8d775b12ece52625b8804.tar.gz
bcm5719-llvm-92adcac9ec01e0751db8d775b12ece52625b8804.zip
Implemented a major overhaul of the way variables are handled
by LLDB. Instead of being materialized into the input structure passed to the expression, variables are left in place and pointers to them are materialzied into the structure. Variables not resident in memory (notably, registers) get temporary memory regions allocated for them. Persistent variables are the most complex part of this, because they are made in various ways and there are different expectations about their lifetime. Persistent variables now have flags indicating their status and what the expectations for longevity are. They can be marked as residing in target memory permanently -- this is the default for result variables from expressions entered on the command line and for explicitly declared persistent variables (but more on that below). Other result variables have their memory freed. Some major improvements resulting from this include being able to properly take the address of variables, better and cleaner support for functions that return references, and cleaner C++ support in general. One problem that remains is the problem of explicitly declared persistent variables; I have not yet implemented the code that makes references to them into indirect references, so currently materialization and dematerialization of these variables is broken. llvm-svn: 123371
Diffstat (limited to 'lldb/source/Expression/ASTResultSynthesizer.cpp')
-rw-r--r--lldb/source/Expression/ASTResultSynthesizer.cpp100
1 files changed, 86 insertions, 14 deletions
diff --git a/lldb/source/Expression/ASTResultSynthesizer.cpp b/lldb/source/Expression/ASTResultSynthesizer.cpp
index 36f78b3120f..99e24728108 100644
--- a/lldb/source/Expression/ASTResultSynthesizer.cpp
+++ b/lldb/source/Expression/ASTResultSynthesizer.cpp
@@ -246,6 +246,49 @@ ASTResultSynthesizer::SynthesizeBodyResult (CompoundStmt *Body,
// No auxiliary variable necessary; expression returns void
return true;
+ // is_lvalue is used to record whether the expression returns an assignable Lvalue or an
+ // Rvalue. This is relevant because they are handled differently.
+ //
+ // For Lvalues
+ //
+ // - In AST result synthesis (here!) the expression E is transformed into an initialization
+ // T *$__lldb_expr_result_ptr = &E.
+ //
+ // - In structure allocation, a pointer-sized slot is allocated in the struct that is to be
+ // passed into the expression.
+ //
+ // - In IR transformations, reads and writes to $__lldb_expr_result_ptr are redirected at
+ // an entry in the struct ($__lldb_arg) passed into the expression. (Other persistent
+ // variables are treated similarly, having been materialized as references, but in those
+ // cases the value of the reference itself is never modified.)
+ //
+ // - During materialization, $0 (the result persistent variable) is ignored.
+ //
+ // - During dematerialization, $0 is marked up as a load address with value equal to the
+ // contents of the structure entry.
+ //
+ // For Rvalues
+ //
+ // - In AST result synthesis the expression E is transformed into an initialization
+ // static T $__lldb_expr_result = E.
+ //
+ // - In structure allocation, a pointer-sized slot is allocated in the struct that is to be
+ // passed into the expression.
+ //
+ // - In IR transformations, an instruction is inserted at the beginning of the function to
+ // dereference the pointer resident in the slot. Reads and writes to $__lldb_expr_result
+ // are redirected at that dereferenced version. Guard variables for the static variable
+ // are excised.
+ //
+ // - During materialization, $0 (the result persistent variable) is populated with the location
+ // of a newly-allocated area of memory.
+ //
+ // - During dematerialization, $0 is ignored.
+
+ bool is_lvalue =
+ (last_expr->getValueKind() == VK_LValue || last_expr->getValueKind() == VK_XValue) &&
+ (last_expr->getObjectKind() == OK_Ordinary);
+
QualType expr_qual_type = last_expr->getType();
clang::Type *expr_type = expr_qual_type.getTypePtr();
@@ -259,22 +302,51 @@ ASTResultSynthesizer::SynthesizeBodyResult (CompoundStmt *Body,
{
std::string s = expr_qual_type.getAsString();
- log->Printf("Last statement's type: %s", s.c_str());
+ log->Printf("Last statement is an %s with type: %s", (is_lvalue ? "lvalue" : "rvalue"), s.c_str());
}
- IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
+ clang::VarDecl *result_decl;
+
+ if (is_lvalue)
+ {
+ IdentifierInfo &result_ptr_id = Ctx.Idents.get("$__lldb_expr_result_ptr");
- clang::VarDecl *result_decl = VarDecl::Create(Ctx,
- DC,
- SourceLocation(),
- &result_id,
- expr_qual_type,
- NULL,
- SC_Static,
- SC_Static);
-
- if (!result_decl)
- return false;
+ QualType ptr_qual_type = Ctx.getPointerType(expr_qual_type);
+
+ result_decl = VarDecl::Create(Ctx,
+ DC,
+ SourceLocation(),
+ &result_ptr_id,
+ ptr_qual_type,
+ NULL,
+ SC_Static,
+ SC_Static);
+
+ if (!result_decl)
+ return false;
+
+ ExprResult address_of_expr = m_sema->CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, last_expr);
+
+ m_sema->AddInitializerToDecl(result_decl, address_of_expr.take());
+ }
+ else
+ {
+ IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
+
+ result_decl = VarDecl::Create(Ctx,
+ DC,
+ SourceLocation(),
+ &result_id,
+ expr_qual_type,
+ NULL,
+ SC_Static,
+ SC_Static);
+
+ if (!result_decl)
+ return false;
+
+ m_sema->AddInitializerToDecl(result_decl, last_expr);
+ }
DC->addDecl(result_decl);
@@ -282,7 +354,7 @@ ASTResultSynthesizer::SynthesizeBodyResult (CompoundStmt *Body,
// call AddInitializerToDecl
//
- m_sema->AddInitializerToDecl(result_decl, last_expr);
+ //m_sema->AddInitializerToDecl(result_decl, last_expr);
/////////////////////////////////
// call ConvertDeclToDeclGroup
OpenPOWER on IntegriCloud