From 25ea6a1b8e58fd956b7cc439f027b8849441842d Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Fri, 23 May 2014 02:30:48 +0000 Subject: [PATCH] Fixed the Symbol code to resolve the callable address of the symbol itself rather than forcing clients to do it. This simplifies the logic for the expression parser a great deal. llvm-svn: 209494 --- lldb/include/lldb/Symbol/Symbol.h | 7 +++- lldb/source/Expression/ClangExpressionDeclMap.cpp | 36 +++++++---------- lldb/source/Symbol/Symbol.cpp | 47 ++++++++++++++++++++++- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h index cd10bf3..0dd04b7 100644 --- a/lldb/include/lldb/Symbol/Symbol.h +++ b/lldb/include/lldb/Symbol/Symbol.h @@ -92,6 +92,9 @@ public: return m_addr_range.GetBaseAddress(); } + lldb::addr_t + ResolveCallableAddress(Target &target) const; + const ConstString & GetName () const { @@ -135,7 +138,7 @@ public: SetReExportedSymbolSharedLibrary (const FileSpec &fspec); Symbol * - ResolveReExportedSymbol (Target &target); + ResolveReExportedSymbol (Target &target) const; uint32_t GetSiblingIndex () const; @@ -310,7 +313,7 @@ protected: ResolveReExportedSymbolInModuleSpec (Target &target, ConstString &reexport_name, lldb_private::ModuleSpec &module_spec, - lldb_private::ModuleList &seen_modules); + lldb_private::ModuleList &seen_modules) const; uint32_t m_uid; // User ID (usually the original symbol table index) uint16_t m_type_data; // data specific to m_type diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 821dae2..a285a95 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -573,37 +573,27 @@ ClangExpressionDeclMap::GetFunctionAddress SymbolContext sym_ctx; sc_list.GetContextAtIndex(i, sym_ctx); - const Address *func_so_addr = NULL; bool is_indirect_function = false; + + lldb::addr_t callable_load_addr = LLDB_INVALID_ADDRESS; + if (sym_ctx.function) - func_so_addr = &sym_ctx.function->GetAddressRange().GetBaseAddress(); - else if (sym_ctx.symbol) { - if (sym_ctx.symbol->GetType() == eSymbolTypeReExported) - { - Symbol *reexported_symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target); - if (reexported_symbol) - { - func_so_addr = &reexported_symbol->GetAddress(); - is_indirect_function = reexported_symbol->IsIndirect(); - } - } - else + const Address func_so_addr = sym_ctx.function->GetAddressRange().GetBaseAddress(); + if (func_so_addr.IsValid()) { - func_so_addr = &sym_ctx.symbol->GetAddress(); - is_indirect_function = sym_ctx.symbol->IsIndirect(); + callable_load_addr = func_so_addr.GetCallableLoadAddress(target, false); } } + else if (sym_ctx.symbol) + { + callable_load_addr = sym_ctx.symbol->ResolveCallableAddress(*target); + } - if (func_so_addr && func_so_addr->IsValid()) + if (callable_load_addr != LLDB_INVALID_ADDRESS) { - lldb::addr_t load_addr = func_so_addr->GetCallableLoadAddress (target, is_indirect_function); - - if (load_addr != LLDB_INVALID_ADDRESS) - { - func_addr = load_addr; - return true; - } + func_addr = callable_load_addr; + return true; } } return false; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 98b5a32..8805199 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -541,7 +541,7 @@ Symbol * Symbol::ResolveReExportedSymbolInModuleSpec (Target &target, ConstString &reexport_name, ModuleSpec &module_spec, - ModuleList &seen_modules) + ModuleList &seen_modules) const { ModuleSP module_sp; if (module_spec.GetFileSpec()) @@ -602,7 +602,7 @@ Symbol::ResolveReExportedSymbolInModuleSpec (Target &target, } Symbol * -Symbol::ResolveReExportedSymbol (Target &target) +Symbol::ResolveReExportedSymbol (Target &target) const { ConstString reexport_name (GetReExportedSymbolName()); if (reexport_name) @@ -618,6 +618,49 @@ Symbol::ResolveReExportedSymbol (Target &target) return nullptr; } +lldb::addr_t +Symbol::ResolveCallableAddress(Target &target) const +{ + if (GetType() == lldb::eSymbolTypeUndefined) + return LLDB_INVALID_ADDRESS; + + Address func_so_addr; + + bool is_indirect; + if (GetType() == eSymbolTypeReExported) + { + Symbol *reexported_symbol = ResolveReExportedSymbol(target); + if (reexported_symbol) + { + func_so_addr = reexported_symbol->GetAddress(); + is_indirect = reexported_symbol->IsIndirect(); + } + } + else + { + func_so_addr = GetAddress(); + is_indirect = IsIndirect(); + } + + if (func_so_addr.IsValid()) + { + if (!target.GetProcessSP() && is_indirect) + { + // can't resolve indirect symbols without calling a function... + return LLDB_INVALID_ADDRESS; + } + + lldb::addr_t load_addr = func_so_addr.GetCallableLoadAddress (&target, is_indirect); + + if (load_addr != LLDB_INVALID_ADDRESS) + { + return load_addr; + } + } + + return LLDB_INVALID_ADDRESS; +} + lldb::DisassemblerSP Symbol::GetInstructions (const ExecutionContext &exe_ctx, -- 2.7.4