fjricci created this revision. fjricci added reviewers: clayborg, lattner. fjricci added subscribers: sas, lldb-commits. Herald added a subscriber: kubabrecka.
Clang supports symbol rewrites via the -frewrite-map-file flag, this patch adds complementary functionality in lldb. Re-written symbols are required when, for example, two versions of the same library are linked to the same binary, and the user needs to differentiate the symbols. The SymbolRewriter implemented in this patch will use a rewrite map provided via the 'target symbols rewrite' command to lookup the original symbol names instead of the names re-written by clang. http://reviews.llvm.org/D22294 Files: include/lldb/Core/Module.h include/lldb/Core/ModuleList.h include/lldb/Symbol/SymbolRewriter.h include/lldb/Symbol/Symtab.h include/lldb/Target/Target.h include/lldb/lldb-forward.h lldb.xcodeproj/project.pbxproj packages/Python/lldbsuite/test/lang/c/symbol_rewriter/Makefile packages/Python/lldbsuite/test/lang/c/symbol_rewriter/TestSymbolRewriter.py packages/Python/lldbsuite/test/lang/c/symbol_rewriter/main.c packages/Python/lldbsuite/test/lang/c/symbol_rewriter/rewrite.map source/API/SBModule.cpp source/API/SBTarget.cpp source/Breakpoint/BreakpointResolverName.cpp source/Commands/CommandObjectSource.cpp source/Commands/CommandObjectTarget.cpp source/Core/AddressResolverName.cpp source/Core/Disassembler.cpp source/Core/Module.cpp source/Core/ModuleList.cpp source/Core/SourceManager.cpp source/Expression/IRExecutionUnit.cpp source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp source/Plugins/Process/Utility/InferiorCallPOSIX.cpp source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp source/Symbol/CMakeLists.txt source/Symbol/Symbol.cpp source/Symbol/SymbolRewriter.cpp source/Symbol/Symtab.cpp source/Target/ObjCLanguageRuntime.cpp source/Target/Target.cpp
Index: source/Target/Target.cpp =================================================================== --- source/Target/Target.cpp +++ source/Target/Target.cpp @@ -78,6 +78,7 @@ m_mutex(), m_arch(target_arch), m_images(this), + m_symbol_rewriter(), m_section_load_history(), m_breakpoint_list(false), m_internal_breakpoint_list(true), Index: source/Target/ObjCLanguageRuntime.cpp =================================================================== --- source/Target/ObjCLanguageRuntime.cpp +++ source/Target/ObjCLanguageRuntime.cpp @@ -105,6 +105,7 @@ SymbolContextList sc_list; const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name, + m_process->GetTarget().GetSymbolRewriter(), eSymbolTypeObjCClass, sc_list); Index: source/Symbol/Symtab.cpp =================================================================== --- source/Symbol/Symtab.cpp +++ source/Symbol/Symtab.cpp @@ -18,6 +18,7 @@ #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Symbol/SymbolRewriter.h" #include "lldb/Symbol/Symtab.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" @@ -806,11 +807,14 @@ } size_t -Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes) +Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, const SymbolRewriterSP rewriter, SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes) { std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer (__PRETTY_FUNCTION__, "%s", __PRETTY_FUNCTION__); + + ConstString rewrittenName = RewriteName(rewriter, name); + // Initialize all of the lookup by name indexes before converting NAME // to a uniqued string NAME_STR below. if (!m_name_indexes_computed) @@ -820,17 +824,20 @@ { // The string table did have a string that matched, but we need // to check the symbols and match the symbol_type if any was given. - AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_indexes); + AppendSymbolIndexesWithNameAndType (rewrittenName, symbol_type, symbol_indexes); } return symbol_indexes.size(); } size_t -Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes) +Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, const SymbolRewriterSP rewriter, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes) { std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer (__PRETTY_FUNCTION__, "%s", __PRETTY_FUNCTION__); + + ConstString rewrittenName = RewriteName(rewriter, name); + // Initialize all of the lookup by name indexes before converting NAME // to a uniqued string NAME_STR below. if (!m_name_indexes_computed) @@ -840,7 +847,7 @@ { // The string table did have a string that matched, but we need // to check the symbols and match the symbol_type if any was given. - AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_debug_type, symbol_visibility, symbol_indexes); + AppendSymbolIndexesWithNameAndType (rewrittenName, symbol_type, symbol_debug_type, symbol_visibility, symbol_indexes); } return symbol_indexes.size(); } @@ -855,27 +862,30 @@ } Symbol * -Symtab::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility) +Symtab::FindFirstSymbolWithNameAndType (const ConstString &name, const SymbolRewriterSP rewriter, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility) { std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer (__PRETTY_FUNCTION__, "%s", __PRETTY_FUNCTION__); + + ConstString rewrittenName = RewriteName (rewriter, name); + if (!m_name_indexes_computed) InitNameIndexes(); if (name) { std::vector<uint32_t> matching_indexes; // The string table did have a string that matched, but we need // to check the symbols and match the symbol_type if any was given. - if (AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_debug_type, symbol_visibility, matching_indexes)) + if (AppendSymbolIndexesWithNameAndType (rewrittenName, symbol_type, symbol_debug_type, symbol_visibility, matching_indexes)) { std::vector<uint32_t>::const_iterator pos, end = matching_indexes.end(); for (pos = matching_indexes.begin(); pos != end; ++pos) { Symbol *symbol = SymbolAtIndex(*pos); - if (symbol->Compare(name, symbol_type)) + if (symbol->Compare(rewrittenName, symbol_type)) return symbol; } } @@ -1138,6 +1148,7 @@ size_t Symtab::FindFunctionSymbols (const ConstString &name, + const SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list) { @@ -1152,7 +1163,7 @@ if (name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) { std::vector<uint32_t> temp_symbol_indexes; - FindAllSymbolsWithNameAndType (name, eSymbolTypeAny, temp_symbol_indexes); + FindAllSymbolsWithNameAndType (name, rewriter, eSymbolTypeAny, temp_symbol_indexes); unsigned temp_symbol_indexes_size = temp_symbol_indexes.size(); if (temp_symbol_indexes_size > 0) @@ -1260,3 +1271,14 @@ } return NULL; } + +ConstString +Symtab::RewriteName (const SymbolRewriterSP rewriter, ConstString name) +{ + if (rewriter) + { + return rewriter->Rewrite (name); + } + + return name; +} Index: source/Symbol/SymbolRewriter.cpp =================================================================== --- /dev/null +++ source/Symbol/SymbolRewriter.cpp @@ -0,0 +1,193 @@ +//===-- SymbolRewriter.cpp --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/Log.h" +#include "lldb/Symbol/SymbolRewriter.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Regex.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/YAMLParser.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_private; + +SymbolRewriter::SymbolRewriter() +{ +} + +static std::string +getString(yaml::ScalarNode *n) +{ + SmallString<32> storage; + StringRef ref; + + ref = n->getValue(storage); + + return ref.str (); +} + +void +SymbolRewriter::LoadMap(const FileSpec &path) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS)); + auto str_path = path.GetPath (); + + if (log) + { + log->Printf("loading rewrite maps from %s", str_path.c_str ()); + } + + ErrorOr<std::unique_ptr<MemoryBuffer>> mem_buffer_or_err = MemoryBuffer::getFile (str_path); + if (std::error_code err = mem_buffer_or_err.getError()) + { + report_fatal_error ("Unable to read rewrite map '" + str_path + + "': " + err.message()); + return; + } + std::unique_ptr<MemoryBuffer> mem_buffer = std::move(mem_buffer_or_err.get()); + + SourceMgr source_mgr; + yaml::Stream yaml_stream(mem_buffer->getBuffer (), source_mgr); + + for (auto &stream : yaml_stream) + { +#define PARSE_CHECK(COND, MESSAGE) \ + if (COND) \ + { \ + report_fatal_error ("Unable to parse rewrite map '" + str_path + \ + "': " + MESSAGE); \ + continue; \ + } + + auto root_map = dyn_cast<yaml::MappingNode>(stream.getRoot()); + PARSE_CHECK (!root_map, "root element is not a map") + + auto map = std::make_shared<RewriteMap> (); + m_rewrite_maps.push_back (map); + + for (auto &entry : *root_map) + { + static const std::string rewrite_type_function = "function"; + static const std::string rewrite_type_global_variable = "global variable"; + static const std::string rewrite_type_global_alias = "global alias"; + + auto key = dyn_cast<yaml::ScalarNode>(entry.getKey ()); + PARSE_CHECK(!key, "malformed rewrite entry") + + auto value = dyn_cast<yaml::MappingNode>(entry.getValue ()); + PARSE_CHECK(!value, "malformed rewrite entry") + + auto rewrite_type = getString (key); + + if (rewrite_type == rewrite_type_global_alias) + { + if (log) + log->Printf("ignoring rewrite type 'global alias' in '%s'", str_path.c_str()); + continue; + } + + PARSE_CHECK (rewrite_type != rewrite_type_function && + rewrite_type != rewrite_type_global_variable, + "'" + rewrite_type + "' is not a valid rewrite type") + + static const std::string descriptor_field_source = "source"; + static const std::string descriptor_field_target = "target"; + static const std::string descriptor_field_transform = "transform"; + static const std::string descriptor_field_naked = "naked"; + std::string source; + std::string target; + std::string transform; + std::string naked; + + for (auto &field : *value) + { + auto field_key = dyn_cast<yaml::ScalarNode> (field.getKey ()); + PARSE_CHECK(!field_key, "malformed rewrite entry") + + auto field_value = dyn_cast<yaml::ScalarNode> (field.getValue ()); + PARSE_CHECK(!field_value, "malformed rewrite entry") + + auto str_key = getString (field_key); + auto str_value = getString (field_value); + + if (str_key == descriptor_field_source) + source = str_value; + else if (str_key == descriptor_field_target) + target = str_value; + else if (str_key == descriptor_field_transform) + transform = str_value; + else if (str_key == descriptor_field_naked) + naked = str_value; + else + PARSE_CHECK (true, "'" + str_key + "' is not a valid key in a rewrite entry") + } + + PARSE_CHECK (source.size () == 0, "missing source in rewrite entry") + + if (!target.empty ()) + map->m_direct_map[ConstString(source)] = ConstString(target); + else if (!transform.empty ()) + map->m_transform_map[ConstString(source)] = ConstString(transform); + else + PARSE_CHECK (true, "target and transform are missing in rewrite entry for '" + source + "'") + } +#undef PARSE_CHECK + } + + if (log) + { + log->Printf("loaded rewrite maps from %s", str_path.c_str ()); + } +} + +ConstString +SymbolRewriter::Rewrite(const ConstString& name) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS)); + ConstString result = name; + + for (auto &map : m_rewrite_maps) + { + auto entry_it = map->m_direct_map.find(result); + if (entry_it != map->m_direct_map.end ()) + { + result = entry_it->second; + continue; + } + + for (const auto &entry : map->m_transform_map) + { + std::string error; + std::string trans; + + trans = Regex (entry.first.AsCString ()).sub (entry.second.AsCString(), + result.AsCString (), + &error); + + if (strcmp (trans.c_str (), result.AsCString ()) != 0) + { + /* Cache entry in direct rewrite map for faster lookups. */ + auto new_result = ConstString (trans.c_str ()); + map->m_direct_map[result] = new_result; + result = new_result; + break; + } + } + } + + if (log) + { + log->Printf("rewrote symbol %s to %s", name.AsCString (), result.AsCString ()); + } + + return result; +} Index: source/Symbol/Symbol.cpp =================================================================== --- source/Symbol/Symbol.cpp +++ source/Symbol/Symbol.cpp @@ -575,7 +575,7 @@ return nullptr; lldb_private::SymbolContextList sc_list; - module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny, sc_list); + module_sp->FindSymbolsWithNameAndType(reexport_name, target.GetSymbolRewriter(), eSymbolTypeAny, sc_list); const size_t num_scs = sc_list.GetSize(); if (num_scs > 0) { Index: source/Symbol/CMakeLists.txt =================================================================== --- source/Symbol/CMakeLists.txt +++ source/Symbol/CMakeLists.txt @@ -24,6 +24,7 @@ Symbol.cpp SymbolContext.cpp SymbolFile.cpp + SymbolRewriter.cpp SymbolVendor.cpp Symtab.cpp Type.cpp Index: source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp =================================================================== --- source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -301,22 +301,24 @@ static ConstString g_dispatch_queue_offsets_symbol_name ("dispatch_queue_offsets"); const Symbol *dispatch_queue_offsets_symbol = NULL; + Target &target = m_process->GetTarget(); + // libdispatch symbols were in libSystem.B.dylib up through Mac OS X 10.6 ("Snow Leopard") ModuleSpec libSystem_module_spec (FileSpec("libSystem.B.dylib", false)); - ModuleSP module_sp(m_process->GetTarget().GetImages().FindFirstModule (libSystem_module_spec)); + ModuleSP module_sp(target.GetImages().FindFirstModule (libSystem_module_spec)); if (module_sp) - dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType (g_dispatch_queue_offsets_symbol_name, eSymbolTypeData); + dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType (g_dispatch_queue_offsets_symbol_name, target.GetSymbolRewriter(), eSymbolTypeData); // libdispatch symbols are in their own dylib as of Mac OS X 10.7 ("Lion") and later if (dispatch_queue_offsets_symbol == NULL) { ModuleSpec libdispatch_module_spec (FileSpec("libdispatch.dylib", false)); - module_sp = m_process->GetTarget().GetImages().FindFirstModule (libdispatch_module_spec); + module_sp = target.GetImages().FindFirstModule (libdispatch_module_spec); if (module_sp) - dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType (g_dispatch_queue_offsets_symbol_name, eSymbolTypeData); + dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType (g_dispatch_queue_offsets_symbol_name, target.GetSymbolRewriter(), eSymbolTypeData); } if (dispatch_queue_offsets_symbol) - m_dispatch_queue_offsets_addr = dispatch_queue_offsets_symbol->GetLoadAddress(&m_process->GetTarget()); + m_dispatch_queue_offsets_addr = dispatch_queue_offsets_symbol->GetLoadAddress(&target); } void @@ -353,15 +355,17 @@ static ConstString g_libpthread_layout_offsets_symbol_name ("pthread_layout_offsets"); const Symbol *libpthread_layout_offsets_symbol = NULL; + Target &target = m_process->GetTarget(); + ModuleSpec libpthread_module_spec (FileSpec("libsystem_pthread.dylib", false)); - ModuleSP module_sp (m_process->GetTarget().GetImages().FindFirstModule (libpthread_module_spec)); + ModuleSP module_sp (target.GetImages().FindFirstModule (libpthread_module_spec)); if (module_sp) { libpthread_layout_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType - (g_libpthread_layout_offsets_symbol_name, eSymbolTypeData); + (g_libpthread_layout_offsets_symbol_name, target.GetSymbolRewriter(), eSymbolTypeData); if (libpthread_layout_offsets_symbol) { - m_libpthread_layout_offsets_addr = libpthread_layout_offsets_symbol->GetLoadAddress(&m_process->GetTarget()); + m_libpthread_layout_offsets_addr = libpthread_layout_offsets_symbol->GetLoadAddress(&target); } } } @@ -402,15 +406,17 @@ static ConstString g_libdispatch_tsd_indexes_symbol_name ("dispatch_tsd_indexes"); const Symbol *libdispatch_tsd_indexes_symbol = NULL; + Target &target = m_process->GetTarget(); + ModuleSpec libpthread_module_spec (FileSpec("libdispatch.dylib", false)); - ModuleSP module_sp (m_process->GetTarget().GetImages().FindFirstModule (libpthread_module_spec)); + ModuleSP module_sp (target.GetImages().FindFirstModule (libpthread_module_spec)); if (module_sp) { libdispatch_tsd_indexes_symbol = module_sp->FindFirstSymbolWithNameAndType - (g_libdispatch_tsd_indexes_symbol_name, eSymbolTypeData); + (g_libdispatch_tsd_indexes_symbol_name, target.GetSymbolRewriter(), eSymbolTypeData); if (libdispatch_tsd_indexes_symbol) { - m_dispatch_tsd_indexes_addr = libdispatch_tsd_indexes_symbol->GetLoadAddress(&m_process->GetTarget()); + m_dispatch_tsd_indexes_addr = libdispatch_tsd_indexes_symbol->GetLoadAddress(&target); } } } @@ -600,7 +606,7 @@ static ConstString introspection_dispatch_queue_info_version ("__introspection_dispatch_queue_info_version"); SymbolContextList sc_list; - if (m_process->GetTarget().GetImages().FindSymbolsWithNameAndType (introspection_dispatch_queue_info_version, eSymbolTypeData, sc_list) > 0) + if (target.GetImages().FindSymbolsWithNameAndType (introspection_dispatch_queue_info_version, target.GetSymbolRewriter(), eSymbolTypeData, sc_list) > 0) { SymbolContext sc; sc_list.GetContextAtIndex (0, sc); @@ -611,7 +617,7 @@ sc_list.Clear(); static ConstString introspection_dispatch_queue_info_data_offset ("__introspection_dispatch_queue_info_data_offset"); - if (m_process->GetTarget().GetImages().FindSymbolsWithNameAndType (introspection_dispatch_queue_info_data_offset, eSymbolTypeData, sc_list) > 0) + if (target.GetImages().FindSymbolsWithNameAndType (introspection_dispatch_queue_info_data_offset, target.GetSymbolRewriter(), eSymbolTypeData, sc_list) > 0) { SymbolContext sc; sc_list.GetContextAtIndex (0, sc); @@ -622,7 +628,7 @@ sc_list.Clear(); static ConstString introspection_dispatch_item_info_version ("__introspection_dispatch_item_info_version"); - if (m_process->GetTarget().GetImages().FindSymbolsWithNameAndType (introspection_dispatch_item_info_version, eSymbolTypeData, sc_list) > 0) + if (target.GetImages().FindSymbolsWithNameAndType (introspection_dispatch_item_info_version, target.GetSymbolRewriter(), eSymbolTypeData, sc_list) > 0) { SymbolContext sc; sc_list.GetContextAtIndex (0, sc); @@ -633,7 +639,7 @@ sc_list.Clear(); static ConstString introspection_dispatch_item_info_data_offset ("__introspection_dispatch_item_info_data_offset"); - if (m_process->GetTarget().GetImages().FindSymbolsWithNameAndType (introspection_dispatch_item_info_data_offset, eSymbolTypeData, sc_list) > 0) + if (target.GetImages().FindSymbolsWithNameAndType (introspection_dispatch_item_info_data_offset, target.GetSymbolRewriter(), eSymbolTypeData, sc_list) > 0) { SymbolContext sc; sc_list.GetContextAtIndex (0, sc); Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -115,6 +115,7 @@ // First we find the original symbol in the .o file's symbol table Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled), + nullptr, eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny); @@ -148,6 +149,7 @@ // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled), + nullptr, eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny); @@ -1228,7 +1230,7 @@ Symtab *symtab = module_objfile->GetSymtab(); if (symtab) { - Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(type_name, eSymbolTypeObjCClass, Symtab::eDebugAny, Symtab::eVisibilityAny); + Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(type_name, nullptr, eSymbolTypeObjCClass, Symtab::eDebugAny, Symtab::eVisibilityAny); if (objc_class_symbol) { // Get the N_SO symbol that contains the objective C class symbol as this Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3523,7 +3523,8 @@ Symtab *symtab = m_obj_file->GetSymtab (); if (symtab) { - objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, + objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, + nullptr, eSymbolTypeObjCClass, Symtab::eDebugNo, Symtab::eVisibilityAny); @@ -4461,6 +4462,7 @@ if (debug_map_symtab) { Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, + nullptr, eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityExtern); Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -4544,7 +4544,8 @@ addr_t symbol_load_addr = LLDB_INVALID_ADDRESS; lldb_private::SymbolContextList sc_list; - if (process->GetTarget().GetImages().FindSymbolsWithNameAndType(ConstString(symbol_name), eSymbolTypeAny, sc_list)) + Target &target = process->GetTarget(); + if (target.GetImages().FindSymbolsWithNameAndType(ConstString(symbol_name), target.GetSymbolRewriter(), eSymbolTypeAny, sc_list)) { const size_t num_scs = sc_list.GetSize(); for (size_t sc_idx=0; sc_idx<num_scs && symbol_load_addr == LLDB_INVALID_ADDRESS; ++sc_idx) @@ -4587,7 +4588,7 @@ case eSymbolTypeObjCMetaClass: case eSymbolTypeObjCIVar: case eSymbolTypeReExported: - symbol_load_addr = sc.symbol->GetLoadAddress(&process->GetTarget()); + symbol_load_addr = sc.symbol->GetLoadAddress(&target); break; } } Index: source/Plugins/Process/Utility/InferiorCallPOSIX.cpp =================================================================== --- source/Plugins/Process/Utility/InferiorCallPOSIX.cpp +++ source/Plugins/Process/Utility/InferiorCallPOSIX.cpp @@ -48,17 +48,20 @@ if (thread == NULL) return false; + Target &target = process->GetTarget(); + const bool append = true; const bool include_symbols = true; const bool include_inlines = false; SymbolContextList sc_list; const uint32_t count - = process->GetTarget().GetImages().FindFunctions (ConstString ("mmap"), - eFunctionNameTypeFull, - include_symbols, - include_inlines, - append, - sc_list); + = target.GetImages().FindFunctions (ConstString ("mmap"), + target.GetSymbolRewriter(), + eFunctionNameTypeFull, + include_symbols, + include_inlines, + append, + sc_list); if (count > 0) { SymbolContext sc; @@ -88,13 +91,13 @@ prot_arg |= PROT_WRITE; } - const ArchSpec arch = process->GetTarget().GetArchitecture(); - flags_arg = process->GetTarget().GetPlatform()->ConvertMmapFlagsToPlatform(arch,flags); + const ArchSpec arch = target.GetArchitecture(); + flags_arg = target.GetPlatform()->ConvertMmapFlagsToPlatform(arch,flags); AddressRange mmap_range; if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, mmap_range)) { - ClangASTContext *clang_ast_context = process->GetTarget().GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = target.GetScratchClangASTContext(); CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); lldb::addr_t args[] = { addr, length, prot_arg, flags_arg, fd, offset }; lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(), @@ -142,18 +145,21 @@ Thread *thread = process->GetThreadList().GetExpressionExecutionThread().get(); if (thread == NULL) return false; - + + Target &target = process->GetTarget(); + const bool append = true; const bool include_symbols = true; const bool include_inlines = false; SymbolContextList sc_list; const uint32_t count - = process->GetTarget().GetImages().FindFunctions (ConstString ("munmap"), - eFunctionNameTypeFull, - include_symbols, - include_inlines, - append, - sc_list); + = target.GetImages().FindFunctions (ConstString ("munmap"), + target.GetSymbolRewriter(), + eFunctionNameTypeFull, + include_symbols, + include_inlines, + append, + sc_list); if (count > 0) { SymbolContext sc; Index: source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp =================================================================== --- source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5179,7 +5179,7 @@ { SymbolContextList contexts; SymbolContext context; - if (module_sp->FindSymbolsWithNameAndType(ConstString ("start"), eSymbolTypeCode, contexts)) + if (module_sp->FindSymbolsWithNameAndType(ConstString ("start"), nullptr, eSymbolTypeCode, contexts)) { if (contexts.GetContextAtIndex(0, context)) m_entry_point_address = context.symbol->GetAddress(); Index: source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp =================================================================== --- source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp +++ source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp @@ -46,6 +46,7 @@ const Symbol* symbol = module_pointer->FindFirstSymbolWithNameAndType( ConstString("__asan_get_alloc_stack"), + target.GetSymbolRewriter(), lldb::eSymbolTypeAny); if (symbol != nullptr) Index: source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp =================================================================== --- source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -782,20 +782,22 @@ if (!module) return Searcher::eCallbackReturnContinue; + const lldb::SymbolRewriterSP rewriter = context.target_sp ? context.target_sp->GetSymbolRewriter() : nullptr; + // Is this a module containing renderscript kernels? - if (nullptr == module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData)) + if (nullptr == module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), rewriter, eSymbolTypeData)) return Searcher::eCallbackReturnContinue; // Attempt to set a breakpoint on the kernel name symbol within the module library. // If it's not found, it's likely debug info is unavailable - try to set a // breakpoint on <name>.expand. - const Symbol *kernel_sym = module->FindFirstSymbolWithNameAndType(m_kernel_name, eSymbolTypeCode); + const Symbol *kernel_sym = module->FindFirstSymbolWithNameAndType(m_kernel_name, rewriter, eSymbolTypeCode); if (!kernel_sym) { std::string kernel_name_expanded(m_kernel_name.AsCString()); kernel_name_expanded.append(".expand"); - kernel_sym = module->FindFirstSymbolWithNameAndType(ConstString(kernel_name_expanded.c_str()), eSymbolTypeCode); + kernel_sym = module->FindFirstSymbolWithNameAndType(ConstString(kernel_name_expanded.c_str()), rewriter, eSymbolTypeCode); } if (kernel_sym) @@ -834,7 +836,7 @@ if (module_sp) { // Is this a module containing renderscript kernels? - const Symbol *info_sym = module_sp->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData); + const Symbol *info_sym = module_sp->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), nullptr, eSymbolTypeData); if (info_sym) { return eModuleKindKernelObj; @@ -1364,7 +1366,7 @@ const char *symbol_name = (archByteSize == 4) ? hook_defn->symbol_name_m32 : hook_defn->symbol_name_m64; - const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(symbol_name), eSymbolTypeCode); + const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(symbol_name), target.GetSymbolRewriter(), eSymbolTypeCode); if (!sym) { if (log) @@ -2612,14 +2614,14 @@ if (!m_libRS) { m_libRS = module_sp; + Target &target = GetProcess()->GetTarget(); static ConstString gDbgPresentStr("gDebuggerPresent"); const Symbol *debug_present = - m_libRS->FindFirstSymbolWithNameAndType(gDbgPresentStr, eSymbolTypeData); + m_libRS->FindFirstSymbolWithNameAndType(gDbgPresentStr, target.GetSymbolRewriter(), eSymbolTypeData); if (debug_present) { Error error; uint32_t flag = 0x00000001U; - Target &target = GetProcess()->GetTarget(); addr_t addr = debug_present->GetLoadAddress(&target); GetProcess()->WriteMemory(addr, &flag, sizeof(flag), error); if (error.Success()) @@ -2676,7 +2678,7 @@ RSModuleDescriptor::ParseRSInfo() { assert(m_module); - const Symbol *info_sym = m_module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData); + const Symbol *info_sym = m_module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), nullptr, eSymbolTypeData); if (!info_sym) return false; @@ -3551,7 +3553,7 @@ else { strm.Printf(" - variable identified, but not found in binary"); - const Symbol *s = m_module->m_module->FindFirstSymbolWithNameAndType(m_name, eSymbolTypeData); + const Symbol *s = m_module->m_module->FindFirstSymbolWithNameAndType(m_name, nullptr, eSymbolTypeData); if (s) { strm.Printf(" (symbol exists) "); Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp =================================================================== --- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -479,6 +479,7 @@ { ConstString trampoline_name ("gdb_objc_trampolines"); const Symbol *trampoline_symbol = m_objc_module_sp->FindFirstSymbolWithNameAndType (trampoline_name, + target.GetSymbolRewriter(), eSymbolTypeData); if (trampoline_symbol != NULL) { @@ -489,6 +490,7 @@ // Next look up the "changed" symbol and set a breakpoint on that... ConstString changed_name ("gdb_objc_trampolines_changed"); const Symbol *changed_symbol = m_objc_module_sp->FindFirstSymbolWithNameAndType (changed_name, + target.GetSymbolRewriter(), eSymbolTypeCode); if (changed_symbol != NULL) { @@ -672,10 +674,11 @@ ConstString msg_forward_stret_name("_objc_msgForward_stret"); Target *target = process_sp ? &process_sp->GetTarget() : NULL; - const Symbol *class_getMethodImplementation = m_objc_module_sp->FindFirstSymbolWithNameAndType (get_impl_name, eSymbolTypeCode); - const Symbol *class_getMethodImplementation_stret = m_objc_module_sp->FindFirstSymbolWithNameAndType (get_impl_stret_name, eSymbolTypeCode); - const Symbol *msg_forward = m_objc_module_sp->FindFirstSymbolWithNameAndType (msg_forward_name, eSymbolTypeCode); - const Symbol *msg_forward_stret = m_objc_module_sp->FindFirstSymbolWithNameAndType (msg_forward_stret_name, eSymbolTypeCode); + const lldb::SymbolRewriterSP rewriter = target ? target->GetSymbolRewriter() : nullptr; + const Symbol *class_getMethodImplementation = m_objc_module_sp->FindFirstSymbolWithNameAndType (get_impl_name, rewriter, eSymbolTypeCode); + const Symbol *class_getMethodImplementation_stret = m_objc_module_sp->FindFirstSymbolWithNameAndType (get_impl_stret_name, rewriter, eSymbolTypeCode); + const Symbol *msg_forward = m_objc_module_sp->FindFirstSymbolWithNameAndType (msg_forward_name, rewriter, eSymbolTypeCode); + const Symbol *msg_forward_stret = m_objc_module_sp->FindFirstSymbolWithNameAndType (msg_forward_stret_name, rewriter, eSymbolTypeCode); if (class_getMethodImplementation) m_impl_fn_addr = class_getMethodImplementation->GetAddress().GetOpcodeLoadAddress (target); @@ -719,7 +722,7 @@ for (size_t i = 0; i != llvm::array_lengthof(g_dispatch_functions); i++) { ConstString name_const_str(g_dispatch_functions[i].name); - const Symbol *msgSend_symbol = m_objc_module_sp->FindFirstSymbolWithNameAndType (name_const_str, eSymbolTypeCode); + const Symbol *msgSend_symbol = m_objc_module_sp->FindFirstSymbolWithNameAndType (name_const_str, rewriter, eSymbolTypeCode); if (msgSend_symbol && msgSend_symbol->ValueIsAddress()) { // FixMe: Make g_dispatch_functions static table of DispatchFunctions, and have the map be address->index. Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp =================================================================== --- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -355,7 +355,7 @@ } if (!byte_size) byte_size = process->GetAddressByteSize(); - const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(name, lldb::eSymbolTypeData); + const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(name, process->GetTarget().GetSymbolRewriter(), lldb::eSymbolTypeData); if (symbol && symbol->ValueIsAddress()) { lldb::addr_t symbol_load_addr = symbol->GetAddressRef().GetLoadAddress(&process->GetTarget()); @@ -397,9 +397,11 @@ m_encoding_to_type_sp(), m_noclasses_warning_emitted(false) { + const lldb::SymbolRewriterSP rewriter = process ? process->GetTarget().GetSymbolRewriter() : nullptr; + static const ConstString g_gdb_object_getClass("gdb_object_getClass"); m_has_object_getClass = - (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL); + (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, rewriter, eSymbolTypeCode) != NULL); } bool @@ -962,7 +964,7 @@ //---------------------------------------------------------------------- SymbolContextList sc_list; Target &target = m_process->GetTarget(); - target.GetImages().FindSymbolsWithNameAndType(ivar_const_str, eSymbolTypeObjCIVar, sc_list); + target.GetImages().FindSymbolsWithNameAndType(ivar_const_str, target.GetSymbolRewriter(), eSymbolTypeObjCIVar, sc_list); addr_t ivar_offset_address = LLDB_INVALID_ADDRESS; @@ -1333,18 +1335,19 @@ if (m_isa_hash_table_ptr == LLDB_INVALID_ADDRESS) { Process *process = GetProcess(); + Target &target = process->GetTarget(); ModuleSP objc_module_sp(GetObjCModule()); if (!objc_module_sp) return LLDB_INVALID_ADDRESS; static ConstString g_gdb_objc_realized_classes("gdb_objc_realized_classes"); - const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_objc_realized_classes, lldb::eSymbolTypeAny); + const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_objc_realized_classes, target.GetSymbolRewriter(), lldb::eSymbolTypeAny); if (symbol) { - lldb::addr_t gdb_objc_realized_classes_ptr = symbol->GetLoadAddress(&process->GetTarget()); + lldb::addr_t gdb_objc_realized_classes_ptr = symbol->GetLoadAddress(&target); if (gdb_objc_realized_classes_ptr != LLDB_INVALID_ADDRESS) { Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp =================================================================== --- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp +++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp @@ -303,13 +303,12 @@ static ConstString g_objc_debug_class_hash("_objc_debug_class_hash"); - const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(g_objc_debug_class_hash, lldb::eSymbolTypeData); - if (symbol && symbol->ValueIsAddress()) + Process *process = GetProcess(); + if (process) { - Process *process = GetProcess(); - if (process) + const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(g_objc_debug_class_hash, process->GetTarget().GetSymbolRewriter(), lldb::eSymbolTypeData); + if (symbol && symbol->ValueIsAddress()) { - lldb::addr_t objc_debug_class_hash_addr = symbol->GetAddressRef().GetLoadAddress(&process->GetTarget()); if (objc_debug_class_hash_addr != LLDB_INVALID_ADDRESS) Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp =================================================================== --- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -240,13 +240,14 @@ { if (!m_PrintForDebugger_addr.get()) { - const ModuleList &modules = m_process->GetTarget().GetImages(); + Target &target = m_process->GetTarget(); + const ModuleList &modules = target.GetImages(); SymbolContextList contexts; SymbolContext context; - if ((!modules.FindSymbolsWithNameAndType(ConstString ("_NSPrintForDebugger"), eSymbolTypeCode, contexts)) && - (!modules.FindSymbolsWithNameAndType(ConstString ("_CFPrintForDebugger"), eSymbolTypeCode, contexts))) + if ((!modules.FindSymbolsWithNameAndType(ConstString ("_NSPrintForDebugger"), target.GetSymbolRewriter(), eSymbolTypeCode, contexts)) && + (!modules.FindSymbolsWithNameAndType(ConstString ("_CFPrintForDebugger"), target.GetSymbolRewriter(), eSymbolTypeCode, contexts))) return NULL; contexts.GetContextAtIndex(0, context); @@ -314,7 +315,7 @@ { const FileSpec &module_file_spec = module_sp->GetFileSpec(); static ConstString ObjCName ("libobjc.A.dylib"); - + if (module_file_spec) { if (module_file_spec.GetFilename() == ObjCName) @@ -495,8 +496,8 @@ SymbolContextList sc_list; - if (target.GetImages().FindSymbolsWithNameAndType(s_method_signature, eSymbolTypeCode, sc_list) || - target.GetImages().FindSymbolsWithNameAndType(s_arclite_method_signature, eSymbolTypeCode, sc_list)) + if (target.GetImages().FindSymbolsWithNameAndType(s_method_signature, target.GetSymbolRewriter(), eSymbolTypeCode, sc_list) || + target.GetImages().FindSymbolsWithNameAndType(s_arclite_method_signature, target.GetSymbolRewriter(), eSymbolTypeCode, sc_list)) return true; else return false; Index: source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp =================================================================== --- source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -525,8 +525,8 @@ SymbolContextList target_symbols; Target &target = m_process->GetTarget(); - if (!module_list.FindSymbolsWithNameAndType(name, symbol_type, - target_symbols)) + if (!module_list.FindSymbolsWithNameAndType(name, target.GetSymbolRewriter(), + symbol_type, target_symbols)) return LLDB_INVALID_ADDRESS; SymbolContext sym_ctx; Index: source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp =================================================================== --- source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp +++ source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp @@ -84,10 +84,10 @@ } static bool -ModuleContainsTSanRuntime(ModuleSP module_sp) +ModuleContainsTSanRuntime(ModuleSP module_sp, const lldb::SymbolRewriterSP rewriter) { static ConstString g_tsan_get_current_report("__tsan_get_current_report"); - const Symbol* symbol = module_sp->FindFirstSymbolWithNameAndType(g_tsan_get_current_report, lldb::eSymbolTypeAny); + const Symbol* symbol = module_sp->FindFirstSymbolWithNameAndType(g_tsan_get_current_report, rewriter, lldb::eSymbolTypeAny); return symbol != nullptr; } @@ -111,7 +111,9 @@ llvm::StringRef module_basename(file_spec.GetFilename().GetStringRef()); if (module_sp->IsExecutable() || module_basename.startswith("libclang_rt.tsan_")) { - if (ModuleContainsTSanRuntime(module_sp)) + ProcessSP process_sp = GetProcessSP(); + const lldb::SymbolRewriterSP rewriter = process_sp ? process_sp->GetTarget().GetSymbolRewriter() : nullptr; + if (ModuleContainsTSanRuntime(module_sp, rewriter)) { m_runtime_module_wp = module_sp; Activate(); @@ -739,7 +741,7 @@ return; ConstString symbol_name ("__tsan_on_report"); - const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType (symbol_name, eSymbolTypeCode); + const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType (symbol_name, process_sp->GetTarget().GetSymbolRewriter(), eSymbolTypeCode); if (symbol == NULL) return; Index: source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp =================================================================== --- source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp +++ source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp @@ -79,10 +79,11 @@ Deactivate(); } -bool ModuleContainsASanRuntime(Module * module) +bool ModuleContainsASanRuntime(Module * module, const lldb::SymbolRewriterSP rewriter) { const Symbol* symbol = module->FindFirstSymbolWithNameAndType( ConstString("__asan_get_alloc_stack"), + rewriter, lldb::eSymbolTypeAny); return symbol != nullptr; @@ -111,7 +112,9 @@ static RegularExpression g_asan_runtime_regex("libclang_rt.asan_(.*)_dynamic\\.dylib"); if (g_asan_runtime_regex.Execute (file_spec.GetFilename().GetCString()) || module_pointer->IsExecutable()) { - if (ModuleContainsASanRuntime(module_pointer)) + ProcessSP process_sp = GetProcessSP(); + const lldb::SymbolRewriterSP rewriter = process_sp ? process_sp->GetTarget().GetSymbolRewriter() : nullptr; + if (ModuleContainsASanRuntime(module_pointer, rewriter)) { m_runtime_module = module_pointer->shared_from_this(); Activate(); @@ -314,7 +317,7 @@ return; ConstString symbol_name ("__asan::AsanDie()"); - const Symbol *symbol = m_runtime_module->FindFirstSymbolWithNameAndType (symbol_name, eSymbolTypeCode); + const Symbol *symbol = m_runtime_module->FindFirstSymbolWithNameAndType (symbol_name, process_sp->GetTarget().GetSymbolRewriter(), eSymbolTypeCode); if (symbol == NULL) return; Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp =================================================================== --- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -525,9 +525,9 @@ SymbolContextList sc_list; if (module) - module->FindSymbolsWithNameAndType(name, symbol_type, sc_list); + module->FindSymbolsWithNameAndType(name, target.GetSymbolRewriter(), symbol_type, sc_list); else - target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list); + target.GetImages().FindSymbolsWithNameAndType(name, target.GetSymbolRewriter(), symbol_type, sc_list); const uint32_t num_matches = sc_list.GetSize(); addr_t symbol_load_addr = LLDB_INVALID_ADDRESS; @@ -637,9 +637,9 @@ SymbolContextList sc_list; if (module) - module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list); + module->FindSymbolsWithNameAndType(name, target.GetSymbolRewriter(), eSymbolTypeAny, sc_list); else - target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list); + target.GetImages().FindSymbolsWithNameAndType(name, target.GetSymbolRewriter(), eSymbolTypeAny, sc_list); const uint32_t matches = sc_list.GetSize(); for (uint32_t i=0; i<matches; ++i) @@ -1314,11 +1314,13 @@ const bool include_inlines = false; const bool append = false; + const lldb::SymbolRewriterSP rewriter = target ? target->GetSymbolRewriter() : nullptr; if (namespace_decl && module_sp) { const bool include_symbols = false; module_sp->FindFunctions(name, + rewriter, &namespace_decl, eFunctionNameTypeBase, include_symbols, @@ -1334,6 +1336,7 @@ // instance methods for eFunctionNameTypeBase. target->GetImages().FindFunctions(name, + rewriter, eFunctionNameTypeFull, include_symbols, include_inlines, Index: source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp =================================================================== --- source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -1140,7 +1140,9 @@ ms.Flush(); ConstString instance_method_name(ms.GetData()); - m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); + const lldb::SymbolRewriterSP rewriter = m_target->GetSymbolRewriter(); + + m_target->GetImages().FindFunctions(instance_method_name, rewriter, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); if (sc_list.GetSize()) break; @@ -1150,7 +1152,7 @@ ms.Flush(); ConstString class_method_name(ms.GetData()); - m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); + m_target->GetImages().FindFunctions(class_method_name, rewriter, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); if (sc_list.GetSize()) break; @@ -1160,7 +1162,7 @@ SymbolContextList candidate_sc_list; - m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list); + m_target->GetImages().FindFunctions(selector_name, rewriter, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list); for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); ci != ce; Index: source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp =================================================================== --- source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -454,7 +454,7 @@ Target &target = thread.GetProcess()->GetTarget(); const ModuleList &images = target.GetImages(); - images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols); + images.FindSymbolsWithNameAndType(sym_name, target.GetSymbolRewriter(), eSymbolTypeCode, target_symbols); size_t num_targets = target_symbols.GetSize(); if (!num_targets) return thread_plan_sp; Index: source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp =================================================================== --- source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp +++ source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp @@ -585,7 +585,7 @@ Target& target = m_process->GetTarget(); SymbolContextList list; - if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), eSymbolTypeAny, list)) + if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), target.GetSymbolRewriter(), eSymbolTypeAny, list)) return false; Address address = list[0].symbol->GetAddress(); Index: source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp =================================================================== --- source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -422,7 +422,7 @@ if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS && dyld_module_sp.get()) { static ConstString g_dyld_all_image_infos ("dyld_all_image_infos"); - const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType (g_dyld_all_image_infos, eSymbolTypeData); + const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType (g_dyld_all_image_infos, target.GetSymbolRewriter(), eSymbolTypeData); if (symbol) m_dyld_all_image_infos_addr = symbol->GetLoadAddress(&target); } @@ -1814,7 +1814,7 @@ const ModuleList &images = target_sp->GetImages(); SymbolContextList code_symbols; - images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode, code_symbols); + images.FindSymbolsWithNameAndType(trampoline_name, target_sp->GetSymbolRewriter(), eSymbolTypeCode, code_symbols); size_t num_code_symbols = code_symbols.GetSize(); if (num_code_symbols > 0) @@ -1838,7 +1838,7 @@ } SymbolContextList reexported_symbols; - images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeReExported, reexported_symbols); + images.FindSymbolsWithNameAndType(trampoline_name, target_sp->GetSymbolRewriter(), eSymbolTypeReExported, reexported_symbols); size_t num_reexported_symbols = reexported_symbols.GetSize(); if (num_reexported_symbols > 0) { @@ -1870,7 +1870,7 @@ } SymbolContextList indirect_symbols; - images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver, indirect_symbols); + images.FindSymbolsWithNameAndType(trampoline_name, target_sp->GetSymbolRewriter(), eSymbolTypeResolver, indirect_symbols); size_t num_indirect_symbols = indirect_symbols.GetSize(); if (num_indirect_symbols > 0) { @@ -2027,7 +2027,7 @@ if (module_sp) { lldb_private::SymbolContextList sc_list; - module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"), eSymbolTypeCode, sc_list); + module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"), m_process->GetTarget().GetSymbolRewriter(), eSymbolTypeCode, sc_list); SymbolContext sc; if (sc_list.GetContextAtIndex(0, sc)) { Index: source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp =================================================================== --- source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp +++ source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp @@ -329,7 +329,7 @@ Target& target = m_process->GetTarget(); SymbolContextList list; - if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), eSymbolTypeAny, list)) + if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), target.GetSymbolRewriter(), eSymbolTypeAny, list)) return false; Address address = list[0].symbol->GetAddress(); Index: source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp =================================================================== --- source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp @@ -497,7 +497,7 @@ Target &target = thread.GetProcess()->GetTarget(); const ModuleList &images = target.GetImages(); - images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols); + images.FindSymbolsWithNameAndType(sym_name, target.GetSymbolRewriter(), eSymbolTypeCode, target_symbols); size_t num_targets = target_symbols.GetSize(); if (!num_targets) return thread_plan_sp; Index: source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp =================================================================== --- source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -1024,8 +1024,10 @@ { if (!m_kext_summary_header_ptr_addr.IsValid()) { + Target &target = m_process->GetTarget(); + m_kernel.Clear(); - m_kernel.SetModule (m_process->GetTarget().GetExecutableModule()); + m_kernel.SetModule (target.GetExecutableModule()); m_kernel.SetIsKernel(true); ConstString kernel_name("mach_kernel"); @@ -1048,7 +1050,7 @@ ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile(); if (kernel_object_file) { - addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget()); + addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&target); addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress(); if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) { @@ -1080,7 +1082,7 @@ if (m_kernel.IsLoaded() && m_kernel.GetModule()) { static ConstString kext_summary_symbol ("gLoadedKextSummaries"); - const Symbol *symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData); + const Symbol *symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType (kext_summary_symbol, target.GetSymbolRewriter(), eSymbolTypeData); if (symbol) { m_kext_summary_header_ptr_addr = symbol->GetAddress(); Index: source/Expression/IRExecutionUnit.cpp =================================================================== --- source/Expression/IRExecutionUnit.cpp +++ source/Expression/IRExecutionUnit.cpp @@ -918,6 +918,7 @@ if (sc.module_sp) { sc.module_sp->FindFunctions(spec.name, + target->GetSymbolRewriter(), NULL, spec.mask, true, // include_symbols @@ -940,6 +941,7 @@ if (sc_list.GetSize() == 0 && sc.target_sp) { sc.target_sp->GetImages().FindFunctions(spec.name, + target->GetSymbolRewriter(), spec.mask, true, // include_symbols false, // include_inlines @@ -958,7 +960,7 @@ if (sc_list.GetSize() == 0 && sc.target_sp) { - sc.target_sp->GetImages().FindSymbolsWithNameAndType(spec.name, lldb::eSymbolTypeAny, sc_list); + sc.target_sp->GetImages().FindSymbolsWithNameAndType(spec.name, sc.target_sp->GetSymbolRewriter(), lldb::eSymbolTypeAny, sc_list); } if (get_external_load_address(load_address, sc_list, sc)) Index: source/Core/SourceManager.cpp =================================================================== --- source/Core/SourceManager.cpp +++ source/Core/SourceManager.cpp @@ -291,6 +291,7 @@ bool inlines_okay = true; bool append = false; size_t num_matches = executable_ptr->FindFunctions (main_name, + target_sp->GetSymbolRewriter(), NULL, lldb::eFunctionNameTypeBase, inlines_okay, Index: source/Core/ModuleList.cpp =================================================================== --- source/Core/ModuleList.cpp +++ source/Core/ModuleList.cpp @@ -331,6 +331,7 @@ size_t ModuleList::FindFunctions (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, bool include_symbols, bool include_inlines, @@ -358,6 +359,7 @@ for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindFunctions(lookup_name, + rewriter, nullptr, lookup_name_type_mask, include_symbols, @@ -393,14 +395,15 @@ collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { - (*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols, include_inlines, true, sc_list); + (*pos)->FindFunctions(name, rewriter, nullptr, name_type_mask, include_symbols, include_inlines, true, sc_list); } } return sc_list.GetSize() - old_size; } size_t ModuleList::FindFunctionSymbols (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list) { @@ -422,8 +425,9 @@ for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindFunctionSymbols (lookup_name, - lookup_name_type_mask, - sc_list); + rewriter, + lookup_name_type_mask, + sc_list); } if (match_name_after_lookup) @@ -453,7 +457,7 @@ collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { - (*pos)->FindFunctionSymbols (name, name_type_mask, sc_list); + (*pos)->FindFunctionSymbols (name, rewriter, name_type_mask, sc_list); } } @@ -531,6 +535,7 @@ size_t ModuleList::FindSymbolsWithNameAndType (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, SymbolType symbol_type, SymbolContextList &sc_list, bool append) const @@ -542,7 +547,7 @@ collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) - (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list); + (*pos)->FindSymbolsWithNameAndType (name, rewriter, symbol_type, sc_list); return sc_list.GetSize() - initial_size; } Index: source/Core/Module.cpp =================================================================== --- source/Core/Module.cpp +++ source/Core/Module.cpp @@ -736,6 +736,7 @@ size_t Module::FindFunctions (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_symbols, @@ -777,7 +778,7 @@ { Symtab *symtab = symbols->GetSymtab(); if (symtab) - symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list); + symtab->FindFunctionSymbols(lookup_name, rewriter, lookup_name_type_mask, sc_list); } } @@ -813,7 +814,7 @@ { Symtab *symtab = symbols->GetSymtab(); if (symtab) - symtab->FindFunctionSymbols(name, name_type_mask, sc_list); + symtab->FindFunctionSymbols(name, rewriter, name_type_mask, sc_list); } } } @@ -1351,7 +1352,7 @@ } const Symbol * -Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) +Module::FindFirstSymbolWithNameAndType (const ConstString &name, const lldb::SymbolRewriterSP rewriter, SymbolType symbol_type) { Timer scoped_timer(__PRETTY_FUNCTION__, "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", @@ -1362,7 +1363,7 @@ { Symtab *symtab = sym_vendor->GetSymtab(); if (symtab) - return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); + return symtab->FindFirstSymbolWithNameAndType (name, rewriter, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); } return nullptr; } @@ -1388,6 +1389,7 @@ size_t Module::FindFunctionSymbols (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list) { @@ -1400,13 +1402,13 @@ { Symtab *symtab = sym_vendor->GetSymtab(); if (symtab) - return symtab->FindFunctionSymbols (name, name_type_mask, sc_list); + return symtab->FindFunctionSymbols (name, rewriter, name_type_mask, sc_list); } return 0; } size_t -Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) +Module::FindSymbolsWithNameAndType (const ConstString &name, const lldb::SymbolRewriterSP rewriter, SymbolType symbol_type, SymbolContextList &sc_list) { // No need to protect this call using m_mutex all other method calls are // already thread safe. @@ -1423,7 +1425,7 @@ if (symtab) { std::vector<uint32_t> symbol_indexes; - symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); + symtab->FindAllSymbolsWithNameAndType (name, rewriter, symbol_type, symbol_indexes); SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); } } Index: source/Core/Disassembler.cpp =================================================================== --- source/Core/Disassembler.cpp +++ source/Core/Disassembler.cpp @@ -184,9 +184,12 @@ { const bool include_symbols = true; const bool include_inlines = true; + Target *target = exe_ctx.GetTargetPtr(); + const lldb::SymbolRewriterSP rewriter = target ? target->GetSymbolRewriter() : nullptr; if (module) { module->FindFunctions(name, + rewriter, nullptr, eFunctionNameTypeAuto, include_symbols, @@ -197,6 +200,7 @@ else if (exe_ctx.GetTargetPtr()) { exe_ctx.GetTargetPtr()->GetImages().FindFunctions (name, + rewriter, eFunctionNameTypeAuto, include_symbols, include_inlines, Index: source/Core/AddressResolverName.cpp =================================================================== --- source/Core/AddressResolverName.cpp +++ source/Core/AddressResolverName.cpp @@ -19,6 +19,7 @@ #include "lldb/Symbol/Function.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/Symbol.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -100,10 +101,13 @@ case AddressResolver::Exact: if (context.module_sp) { + const lldb::SymbolRewriterSP rewriter = context.target_sp ? context.target_sp->GetSymbolRewriter() : nullptr; context.module_sp->FindSymbolsWithNameAndType (m_func_name, + rewriter, eSymbolTypeCode, sym_list); context.module_sp->FindFunctions(m_func_name, + rewriter, nullptr, eFunctionNameTypeAuto, include_symbols, Index: source/Commands/CommandObjectTarget.cpp =================================================================== --- source/Commands/CommandObjectTarget.cpp +++ source/Commands/CommandObjectTarget.cpp @@ -45,6 +45,7 @@ #include "lldb/Symbol/LineTable.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolFile.h" +#include "lldb/Symbol/SymbolRewriter.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/UnwindPlan.h" #include "lldb/Symbol/VariableList.h" @@ -1811,7 +1812,10 @@ else { ConstString function_name (name); + Target *target = interpreter.GetExecutionContext().GetTargetPtr(); + const lldb::SymbolRewriterSP rewriter = target ? target->GetSymbolRewriter() : nullptr; num_matches = module->FindFunctions(function_name, + rewriter, nullptr, eFunctionNameTypeAuto, include_symbols, @@ -3724,7 +3728,7 @@ if (m_options.m_type == eLookupTypeFunctionOrSymbol) { ConstString function_name (m_options.m_str.c_str()); - target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list); + target->GetImages().FindFunctions (function_name, target->GetSymbolRewriter(), eFunctionNameTypeAuto, true, false, true, sc_list); } else if (m_options.m_type == eLookupTypeAddress && target) { @@ -4810,6 +4814,46 @@ OptionGroupBoolean m_current_frame_option; }; +class CommandObjectTargetSymbolsRewrite : public CommandObjectParsed +{ +public: + CommandObjectTargetSymbolsRewrite (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "target symbols rewrite", + "Add a symbol rewrite file to the target by specifying a path to a rewrite map file.", + "target symbols rewrite [<rewrite_map>]", eCommandRequiresTarget) {} + +protected: + virtual bool + DoExecute (Args& args, + CommandReturnObject &result) + { + Target *target = m_exe_ctx.GetTargetPtr(); + const char *path = args.GetArgumentAtIndex(0); + + if (!path) + { + result.AppendMessageWithFormat ("A symbol file path must be provided\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + FileSpec fspec; + fspec.SetFile (path, true); + + if (!fspec.Exists()) + { + result.AppendMessageWithFormat ("%s: File not found\n", path); + result.SetStatus (eReturnStatusFailed); + return false; + } + target->GetSymbolRewriter()->LoadMap (fspec); + + result.SetStatus (eReturnStatusSuccessFinishResult); + return true; + } +}; + #pragma mark CommandObjectTargetSymbols //------------------------------------------------------------------------- @@ -4829,6 +4873,7 @@ "target symbols <sub-command> ...") { LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter))); + LoadSubCommand ("rewrite", CommandObjectSP (new CommandObjectTargetSymbolsRewrite (interpreter))); } ~CommandObjectTargetSymbols() override = default; Index: source/Commands/CommandObjectSource.cpp =================================================================== --- source/Commands/CommandObjectSource.cpp +++ source/Commands/CommandObjectSource.cpp @@ -426,6 +426,7 @@ ModuleList module_list = (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages(); size_t num_matches = module_list.FindFunctions(name, + target->GetSymbolRewriter(), eFunctionNameTypeAuto, /*include_symbols=*/false, /*include_inlines=*/true, @@ -437,6 +438,7 @@ // symbols that line up exactly with function addresses. SymbolContextList sc_list_symbols; size_t num_symbol_matches = module_list.FindFunctionSymbols(name, + target->GetSymbolRewriter(), eFunctionNameTypeAuto, sc_list_symbols); for (size_t i = 0; i < num_symbol_matches; i++) @@ -1042,13 +1044,13 @@ ModuleSpec module_spec (module_file_spec); matching_modules.Clear(); target->GetImages().FindModules (module_spec, matching_modules); - num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + num_matches += matching_modules.FindFunctions (name, target->GetSymbolRewriter(), eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); } } } else { - num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + num_matches = target->GetImages().FindFunctions (name, target->GetSymbolRewriter(), eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); } return num_matches; } @@ -1068,13 +1070,13 @@ ModuleSpec module_spec (module_file_spec); matching_modules.Clear(); target->GetImages().FindModules (module_spec, matching_modules); - num_matches += matching_modules.FindFunctionSymbols (name, eFunctionNameTypeAuto, sc_list); + num_matches += matching_modules.FindFunctionSymbols (name, target->GetSymbolRewriter(), eFunctionNameTypeAuto, sc_list); } } } else { - num_matches = target->GetImages().FindFunctionSymbols (name, eFunctionNameTypeAuto, sc_list); + num_matches = target->GetImages().FindFunctionSymbols (name, target->GetSymbolRewriter(), eFunctionNameTypeAuto, sc_list); } return num_matches; } Index: source/Breakpoint/BreakpointResolverName.cpp =================================================================== --- source/Breakpoint/BreakpointResolverName.cpp +++ source/Breakpoint/BreakpointResolverName.cpp @@ -21,6 +21,7 @@ #include "lldb/Symbol/Function.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/Target.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" using namespace lldb; @@ -233,7 +234,9 @@ for (const LookupInfo &lookup : m_lookups) { const size_t start_func_idx = func_list.GetSize(); + const lldb::SymbolRewriterSP rewriter = context.target_sp ? context.target_sp->GetSymbolRewriter() : nullptr; context.module_sp->FindFunctions(lookup.lookup_name, + rewriter, nullptr, lookup.name_type_mask, include_symbols, Index: source/API/SBTarget.cpp =================================================================== --- source/API/SBTarget.cpp +++ source/API/SBTarget.cpp @@ -1803,6 +1803,7 @@ const bool inlines_ok = true; const bool append = true; target_sp->GetImages().FindFunctions (ConstString(name), + target_sp->GetSymbolRewriter(), name_type_mask, symbols_ok, inlines_ok, @@ -1833,7 +1834,7 @@ target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list); break; default: - target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list); + target_sp->GetImages().FindFunctions(ConstString(name), target_sp->GetSymbolRewriter(), eFunctionNameTypeAny, true, true, true, *sb_sc_list); break; } } @@ -2387,6 +2388,7 @@ { bool append = true; target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name), + target_sp->GetSymbolRewriter(), symbol_type, *sb_sc_list, append); Index: source/API/SBModule.cpp =================================================================== --- source/API/SBModule.cpp +++ source/API/SBModule.cpp @@ -376,7 +376,7 @@ ModuleSP module_sp (GetSP ()); Symtab *symtab = GetUnifiedSymbolTable (module_sp); if (symtab) - sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); + sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), nullptr, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); } return sb_symbol; } @@ -393,7 +393,7 @@ if (symtab) { std::vector<uint32_t> matching_symbol_indexes; - const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); + const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), nullptr, symbol_type, matching_symbol_indexes); if (num_matches) { SymbolContext sc; @@ -458,6 +458,7 @@ const bool symbols_ok = true; const bool inlines_ok = true; module_sp->FindFunctions (ConstString(name), + nullptr, NULL, name_type_mask, symbols_ok, Index: packages/Python/lldbsuite/test/lang/c/symbol_rewriter/rewrite.map =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/lang/c/symbol_rewriter/rewrite.map @@ -0,0 +1 @@ +function: { source: putchar, target: __my_putchar,} Index: packages/Python/lldbsuite/test/lang/c/symbol_rewriter/main.c =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/lang/c/symbol_rewriter/main.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int putchar(int c) +{ + return 12345; +} + +int main() +{ + return putchar('a'); +} Index: packages/Python/lldbsuite/test/lang/c/symbol_rewriter/TestSymbolRewriter.py =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/lang/c/symbol_rewriter/TestSymbolRewriter.py @@ -0,0 +1,51 @@ +"""Check that compiler-generated constant values work correctly""" + +from __future__ import print_function + +import os, time +import subprocess + +import lldb + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class SymbolRewriterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # We need the -frewrite-map-file clang flag to build + @expectedFailureAll(compiler="clang", compiler_version=["<", "3.7"]) + @expectedFailureAll(compiler='gcc') + @skipIfWindows + def test_and_run_command(self): + """Test the lldb symbol rewriter""" + self.build() + exe = os.path.join(os.getcwd(), "a.out") + + # Clang does not rewrite dwarf debug info, so it must be stripped + subprocess.check_call(['strip', '-g', exe]) + + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break inside the main. + lldbutil.run_break_set_by_symbol (self, "main") + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # Before adding the rewrite map, we will call the system putchar() + self.expect("expr (int)putchar('a')", substrs = ['(int) $0 = 97']) + + rewrite_map = os.path.join(os.getcwd(), "rewrite.map") + self.runCmd("target symbols rewrite " + rewrite_map) + + # After adding the rewrite map, we will call our re-written putchar() + self.expect("expr (int)putchar('a')", substrs = ['(int) $1 = 12345']) + + self.runCmd("kill") Index: packages/Python/lldbsuite/test/lang/c/symbol_rewriter/Makefile =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/lang/c/symbol_rewriter/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +CFLAGS_EXTRAS += -frewrite-map-file=rewrite.map + +include $(LEVEL)/Makefile.rules Index: lldb.xcodeproj/project.pbxproj =================================================================== --- lldb.xcodeproj/project.pbxproj +++ lldb.xcodeproj/project.pbxproj @@ -744,6 +744,7 @@ 6D9AB3DD1BB2B74E003F2289 /* TypeMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D9AB3DC1BB2B74E003F2289 /* TypeMap.cpp */; }; 6DEC6F391BD66D750091ABA6 /* TaskPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DEC6F381BD66D750091ABA6 /* TaskPool.cpp */; }; 8C26C4261C3EA5F90031DF7C /* ThreadSanitizerRuntime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C26C4241C3EA4340031DF7C /* ThreadSanitizerRuntime.cpp */; }; + 5AB29E881AD3510900C69791 /* SymbolRewriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5AB29E871AD3510900C69791 /* SymbolRewriter.cpp */; }; 8C2D6A53197A1EAF006989C9 /* MemoryHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C2D6A52197A1EAF006989C9 /* MemoryHistory.cpp */; }; 8C2D6A5E197A250F006989C9 /* MemoryHistoryASan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C2D6A5A197A1FDC006989C9 /* MemoryHistoryASan.cpp */; }; 8CCB017E19BA28A80009FD44 /* ThreadCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8CCB017A19BA283D0009FD44 /* ThreadCollection.cpp */; }; @@ -2461,6 +2462,7 @@ 4CEDAED311754F5E00E875A6 /* ThreadPlanStepUntil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadPlanStepUntil.h; path = include/lldb/Target/ThreadPlanStepUntil.h; sourceTree = "<group>"; }; 4CF52AF41428291E0051E832 /* SBFileSpecList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBFileSpecList.h; path = include/lldb/API/SBFileSpecList.h; sourceTree = "<group>"; }; 4CF52AF7142829390051E832 /* SBFileSpecList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBFileSpecList.cpp; path = source/API/SBFileSpecList.cpp; sourceTree = "<group>"; }; + 5AB29E871AD3510900C69791 /* SymbolRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SymbolRewriter.cpp; path = source/Symbol/SymbolRewriter.cpp; sourceTree = "<group>"; }; 69A01E1B1236C5D400C660B5 /* Condition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Condition.cpp; sourceTree = "<group>"; }; 69A01E1C1236C5D400C660B5 /* Host.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Host.cpp; sourceTree = "<group>"; }; 69A01E1E1236C5D400C660B5 /* Mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mutex.cpp; sourceTree = "<group>"; }; @@ -4481,6 +4483,7 @@ 6D9AB3DC1BB2B74E003F2289 /* TypeMap.cpp */, 6D99A3621BBC2F3200979793 /* ArmUnwindInfo.cpp */, 6D99A3611BBC2F1600979793 /* ArmUnwindInfo.h */, + 5AB29E871AD3510900C69791 /* SymbolRewriter.cpp */, 26BC7C5510F1B6E900F91463 /* Block.h */, 26BC7F1310F1B8EC00F91463 /* Block.cpp */, 26BC7C5610F1B6E900F91463 /* ClangASTContext.h */, @@ -6618,6 +6621,7 @@ 449ACC98197DEA0B008D175E /* FastDemangle.cpp in Sources */, 2689000513353DB600698AC0 /* BreakpointResolverName.cpp in Sources */, 6D762BEE1B1605D2006C929D /* LLDBServerUtilities.cpp in Sources */, + 5AB29E881AD3510900C69791 /* SymbolRewriter.cpp in Sources */, 2689000713353DB600698AC0 /* BreakpointSite.cpp in Sources */, 2689000913353DB600698AC0 /* BreakpointSiteList.cpp in Sources */, 26474CC918D0CB5B0073DEBA /* RegisterContextMemory.cpp in Sources */, Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -225,6 +225,7 @@ class SymbolContextSpecifier; class SymbolFile; class SymbolFileType; +class SymbolRewriter; class SymbolVendor; class Symtab; class SyntheticChildren; @@ -419,6 +420,7 @@ typedef std::shared_ptr<lldb_private::SymbolFileType> SymbolFileTypeSP; typedef std::weak_ptr<lldb_private::SymbolFileType> SymbolFileTypeWP; typedef std::shared_ptr<lldb_private::SymbolContextSpecifier> SymbolContextSpecifierSP; + typedef std::shared_ptr<lldb_private::SymbolRewriter> SymbolRewriterSP; typedef std::unique_ptr<lldb_private::SymbolVendor> SymbolVendorUP; typedef std::shared_ptr<lldb_private::SyntheticChildren> SyntheticChildrenSP; typedef std::shared_ptr<lldb_private::SyntheticChildrenFrontEnd> SyntheticChildrenFrontEndSP; Index: include/lldb/Target/Target.h =================================================================== --- include/lldb/Target/Target.h +++ include/lldb/Target/Target.h @@ -29,6 +29,7 @@ #include "lldb/Core/ModuleList.h" #include "lldb/Core/UserSettingsController.h" #include "lldb/Expression/Expression.h" +#include "lldb/Symbol/SymbolRewriter.h" #include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/ExecutionContextScope.h" #include "lldb/Target/PathMappingList.h" @@ -1134,6 +1135,17 @@ { return m_images; } + + lldb::SymbolRewriterSP + GetSymbolRewriter () + { + if (!m_symbol_rewriter) + { + m_symbol_rewriter = std::make_shared<SymbolRewriter>(); + } + + return m_symbol_rewriter; + } //------------------------------------------------------------------ /// Return whether this FileSpec corresponds to a module that should be considered for general searches. @@ -1611,6 +1623,7 @@ m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe ArchSpec m_arch; ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). + lldb::SymbolRewriterSP m_symbol_rewriter; ///< Symbol rewriter for the target. SectionLoadHistory m_section_load_history; BreakpointList m_breakpoint_list; BreakpointList m_internal_breakpoint_list; Index: include/lldb/Symbol/Symtab.h =================================================================== --- include/lldb/Symbol/Symtab.h +++ include/lldb/Symbol/Symtab.h @@ -76,14 +76,14 @@ uint32_t AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches); uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes); uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes); - size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes); - size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); + size_t FindAllSymbolsWithNameAndType (const ConstString &name, const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes); + size_t FindAllSymbolsWithNameAndType (const ConstString &name, const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); size_t FindAllSymbolsMatchingRexExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); - Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility); + Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility); Symbol * FindSymbolAtFileAddress (lldb::addr_t file_addr); Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr); void ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback); - size_t FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list); + size_t FindFunctionSymbols (const ConstString &name, const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list); void CalculateSymbolSizes (); void SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const; @@ -167,6 +167,9 @@ SymbolIndicesToSymbolContextList (std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list); + ConstString + RewriteName (const lldb::SymbolRewriterSP rewriter, ConstString name); + DISALLOW_COPY_AND_ASSIGN (Symtab); }; Index: include/lldb/Symbol/SymbolRewriter.h =================================================================== --- /dev/null +++ include/lldb/Symbol/SymbolRewriter.h @@ -0,0 +1,65 @@ +//===-- SymbolRewriter.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_SymbolRewriter_h_ +#define liblldb_SymbolRewriter_h_ + +#include "lldb/Core/ConstString.h" +#include "lldb/Host/FileSpec.h" +#include "lldb/lldb-defines.h" +#include <list> +#include <map> +#include <memory> +#include <string> + +namespace lldb_private { + +//----------------------------------------------------------------------- +/// @class SymbolRewriter SymbolRewriter.h "lldb/Symbol/SymbolRewriter.h" +/// @brief Implementation of the symbol rewrite mechanism. +//----------------------------------------------------------------------- +class SymbolRewriter +{ +private: + struct RewriteMap + { + std::map<ConstString, ConstString> m_direct_map; + std::map<ConstString, ConstString> m_transform_map; + }; + + typedef std::shared_ptr<RewriteMap> RewriteMapSP; + +public: + SymbolRewriter (); + + virtual + ~SymbolRewriter() {} + + // Load a rewrite map and add its contents to the list of rewrites. + void + LoadMap (const FileSpec &path); + + std::list<RewriteMapSP>::size_type + GetMapCount() const + { + return m_rewrite_maps.size (); + } + + ConstString + Rewrite (const ConstString &name); + +private: + std::list<RewriteMapSP> m_rewrite_maps; + + DISALLOW_COPY_AND_ASSIGN (SymbolRewriter); +}; + +} // namespace lldb_private + +#endif // liblldb_SymbolRewriter_h_ Index: include/lldb/Core/ModuleList.h =================================================================== --- include/lldb/Core/ModuleList.h +++ include/lldb/Core/ModuleList.h @@ -269,6 +269,7 @@ //------------------------------------------------------------------ size_t FindFunctions (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, bool include_symbols, bool include_inlines, @@ -280,6 +281,7 @@ //------------------------------------------------------------------ size_t FindFunctionSymbols (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list); @@ -403,6 +405,7 @@ size_t FindSymbolsWithNameAndType (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type, SymbolContextList &sc_list, bool append = false) const; Index: include/lldb/Core/Module.h =================================================================== --- include/lldb/Core/Module.h +++ include/lldb/Core/Module.h @@ -237,10 +237,12 @@ //------------------------------------------------------------------ const Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type = lldb::eSymbolTypeAny); size_t FindSymbolsWithNameAndType (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, lldb::SymbolType symbol_type, SymbolContextList &sc_list); @@ -255,6 +257,9 @@ /// @param[in] name /// The name of the symbol that we are looking for. /// + /// @param[in] rewriter + /// A symbol name rewriter. + /// /// @param[in] name_type_mask /// A mask that has one or more bitwise OR'ed values from the /// lldb::FunctionNameType enumeration type that indicate what @@ -268,6 +273,7 @@ //------------------------------------------------------------------ size_t FindFunctionSymbols (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, uint32_t name_type_mask, SymbolContextList& sc_list); @@ -330,6 +336,7 @@ //------------------------------------------------------------------ size_t FindFunctions (const ConstString &name, + const lldb::SymbolRewriterSP rewriter, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool symbols_ok, @@ -1003,7 +1010,7 @@ { return m_source_mappings; } - + //------------------------------------------------------------------ /// Finds a source file given a file spec using the module source /// path remappings (if any).
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits