diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 36 | ||||
-rw-r--r-- | lldb/source/Expression/ASTResultSynthesizer.cpp | 56 | ||||
-rw-r--r-- | lldb/source/Expression/ClangExpressionDeclMap.cpp | 36 | ||||
-rw-r--r-- | lldb/source/Expression/ClangExpressionParser.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Expression/ClangPersistentVariables.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Expression/ClangUserExpression.cpp | 16 |
6 files changed, 146 insertions, 19 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index ca5ca1520f1..694c904391e 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -347,24 +347,34 @@ CommandObjectExpression::EvaluateExpression } else { - const char *error_cstr = result_valobj_sp->GetError().AsCString(); - if (error_cstr && error_cstr[0]) + if (result_valobj_sp->GetError().GetError() == ClangUserExpression::kNoResult) { - int error_cstr_len = strlen (error_cstr); - const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n'; - if (strstr(error_cstr, "error:") != error_cstr) - error_stream->PutCString ("error: "); - error_stream->Write(error_cstr, error_cstr_len); - if (!ends_with_newline) - error_stream->EOL(); + error_stream->PutCString("<no result>\n"); + + if (result) + result->SetStatus (eReturnStatusSuccessFinishResult); } else { - error_stream->PutCString ("error: unknown error\n"); + const char *error_cstr = result_valobj_sp->GetError().AsCString(); + if (error_cstr && error_cstr[0]) + { + int error_cstr_len = strlen (error_cstr); + const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n'; + if (strstr(error_cstr, "error:") != error_cstr) + error_stream->PutCString ("error: "); + error_stream->Write(error_cstr, error_cstr_len); + if (!ends_with_newline) + error_stream->EOL(); + } + else + { + error_stream->PutCString ("error: unknown error\n"); + } + + if (result) + result->SetStatus (eReturnStatusFailed); } - - if (result) - result->SetStatus (eReturnStatusFailed); } } } diff --git a/lldb/source/Expression/ASTResultSynthesizer.cpp b/lldb/source/Expression/ASTResultSynthesizer.cpp index 1125d6272f9..b2b593bbed9 100644 --- a/lldb/source/Expression/ASTResultSynthesizer.cpp +++ b/lldb/source/Expression/ASTResultSynthesizer.cpp @@ -19,19 +19,25 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" #include "lldb/Core/Log.h" +#include "lldb/Expression/ClangPersistentVariables.h" #include "lldb/Expression/ASTResultSynthesizer.h" +#include "lldb/Symbol/ClangASTContext.h" using namespace llvm; using namespace clang; using namespace lldb_private; ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough, - TypeFromUser desired_type) : + TypeFromUser desired_type, + ASTContext &scratch_ast_context, + ClangPersistentVariables &persistent_vars) : m_ast_context (NULL), m_passthrough (passthrough), m_passthrough_sema (NULL), m_sema (NULL), - m_desired_type (desired_type) + m_desired_type (desired_type), + m_scratch_ast_context (scratch_ast_context), + m_persistent_vars (persistent_vars) { if (!m_passthrough) return; @@ -87,6 +93,7 @@ ASTResultSynthesizer::TransformTopLevelDecl(Decl* D) if (m_ast_context && !method_decl->getSelector().getAsString().compare("$__lldb_expr:")) { + RecordPersistentTypes(method_decl); SynthesizeObjCMethodResult(method_decl); } } @@ -95,6 +102,7 @@ ASTResultSynthesizer::TransformTopLevelDecl(Decl* D) if (m_ast_context && !function_decl->getNameInfo().getAsString().compare("$__lldb_expr")) { + RecordPersistentTypes(function_decl); SynthesizeFunctionResult(function_decl); } } @@ -397,9 +405,51 @@ ASTResultSynthesizer::HandleTranslationUnit(ASTContext &Ctx) m_passthrough->HandleTranslationUnit(Ctx); } +void +ASTResultSynthesizer::RecordPersistentTypes(DeclContext *FunDeclCtx) +{ + typedef DeclContext::specific_decl_iterator<TypeDecl> TypeDeclIterator; + + for (TypeDeclIterator i = TypeDeclIterator(FunDeclCtx->decls_begin()), + e = TypeDeclIterator(FunDeclCtx->decls_end()); + i != e; + ++i) + { + MaybeRecordPersistentType(*i); + } +} + void -ASTResultSynthesizer::HandleTagDeclDefinition(TagDecl *D) +ASTResultSynthesizer::MaybeRecordPersistentType(TypeDecl *D) { + if (!D->getIdentifier()) + return; + + StringRef name = D->getName(); + + if (name.size() == 0 || name[0] != '$') + return; + + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + ConstString name_cs(name.str().c_str()); + + if (log) + log->Printf ("Recording persistent type %s\n", name_cs.GetCString()); + + Decl *D_scratch = ClangASTContext::CopyDecl(&m_scratch_ast_context, + m_ast_context, + D); + + TypeDecl *TD_scratch = dyn_cast<TypeDecl>(D_scratch); + + if (TD_scratch) + m_persistent_vars.RegisterPersistentType(name_cs, TD_scratch); +} + +void +ASTResultSynthesizer::HandleTagDeclDefinition(TagDecl *D) +{ if (m_passthrough) m_passthrough->HandleTagDeclDefinition(D); } diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 08e7724d0fc..75387a9d33c 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -1945,6 +1945,42 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString return; } + do + { + if (!m_parser_vars->m_exe_ctx->target) + break; + + ClangASTContext *scratch_clang_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext(); + + if (!scratch_clang_ast_context) + break; + + ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); + + if (!scratch_ast_context) + break; + + TypeDecl *ptype_type_decl = m_parser_vars->m_persistent_vars->GetPersistentType(name); + + if (!ptype_type_decl) + break; + + Decl *parser_ptype_decl = ClangASTContext::CopyDecl(context.GetASTContext(), scratch_ast_context, ptype_type_decl); + + if (!parser_ptype_decl) + break; + + TypeDecl *parser_ptype_type_decl = dyn_cast<TypeDecl>(parser_ptype_decl); + + if (!parser_ptype_type_decl) + break; + + if (log) + log->Printf("Found persistent type %s", name.GetCString()); + + context.AddNamedDecl(parser_ptype_type_decl); + } while (0); + ClangExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariable(name)); if (pvar_sp) diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index 14d8a70ebb6..81c03f36c52 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -234,6 +234,7 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, m_compiler->getLangOpts().ThreadsafeStatics = false; m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access m_compiler->getLangOpts().DollarIdents = true; // $ indicates a persistent variable name + //m_compiler->getLangOpts().DebuggerSupport = true; // Features specifically for debugger clients // Set CodeGen options m_compiler->getCodeGenOpts().EmitDeclMetadata = true; diff --git a/lldb/source/Expression/ClangPersistentVariables.cpp b/lldb/source/Expression/ClangPersistentVariables.cpp index c4bf88502f4..3da9dc8c365 100644 --- a/lldb/source/Expression/ClangPersistentVariables.cpp +++ b/lldb/source/Expression/ClangPersistentVariables.cpp @@ -13,6 +13,8 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/Value.h" +#include "llvm/ADT/StringMap.h" + using namespace lldb; using namespace lldb_private; @@ -53,3 +55,21 @@ ClangPersistentVariables::GetNextPersistentVariableName () ConstString name(name_cstr); return name; } + +void +ClangPersistentVariables::RegisterPersistentType (const ConstString &name, + clang::TypeDecl *type_decl) +{ + m_persistent_types.insert(std::pair<const char*, clang::TypeDecl*>(name.GetCString(), type_decl)); +} + +clang::TypeDecl * +ClangPersistentVariables::GetPersistentType (const ConstString &name) +{ + PersistentTypeMap::const_iterator i = m_persistent_types.find(name.GetCString()); + + if (i == m_persistent_types.end()) + return NULL; + else + return i->second; +} diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp index 9cd84894854..f0a6359eea0 100644 --- a/lldb/source/Expression/ClangUserExpression.cpp +++ b/lldb/source/Expression/ClangUserExpression.cpp @@ -53,7 +53,8 @@ ClangUserExpression::ClangUserExpression (const char *expr, m_objectivec (false), m_needs_object_ptr (false), m_const_object (false), - m_const_result () + m_const_result (), + m_target (NULL) { } @@ -64,8 +65,15 @@ ClangUserExpression::~ClangUserExpression () clang::ASTConsumer * ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough) { + ClangASTContext *clang_ast_context = m_target->GetScratchClangASTContext(); + + if (!clang_ast_context) + return NULL; + return new ASTResultSynthesizer(passthrough, - m_desired_type); + m_desired_type, + *m_target->GetScratchClangASTContext()->getASTContext(), + m_target->GetPersistentVariables()); } void @@ -88,6 +96,8 @@ ClangUserExpression::ScanContext(ExecutionContext &exe_ctx) if (!decl_context) return; + + m_target = exe_ctx.target; if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_context)) { @@ -718,7 +728,7 @@ ClangUserExpression::EvaluateWithError (ExecutionContext &exe_ctx, if (log) log->Printf("== [ClangUserExpression::Evaluate] Execution completed normally with no result =="); - error.SetErrorString ("Expression did not return a result"); + error.SetError(ClangUserExpression::kNoResult, lldb::eErrorTypeGeneric); } } } |