diff options
author | Greg Clayton <gclayton@apple.com> | 2015-06-25 21:46:34 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2015-06-25 21:46:34 +0000 |
commit | 358cf1ea302ebc9c2f307aa710c22821a4ab670a (patch) | |
tree | 6107730cfdba431365534feddc2af4c36d12facc /lldb/source/Plugins | |
parent | aed187c76e884dcb96e55312c16e1335580a2ed9 (diff) | |
download | bcm5719-llvm-358cf1ea302ebc9c2f307aa710c22821a4ab670a.tar.gz bcm5719-llvm-358cf1ea302ebc9c2f307aa710c22821a4ab670a.zip |
Resubmitting 240466 after fixing the linux test suite failures.
A few extras were fixed
- Symbol::GetAddress() now returns an Address object, not a reference. There were places where people were accessing the address of a symbol when the symbol's value wasn't an address symbol. On MacOSX, undefined symbols have a value zero and some places where using the symbol's address and getting an absolute address of zero (since an Address object with no section and an m_offset whose value isn't LLDB_INVALID_ADDRESS is considered an absolute address). So fixing this required some changes to make sure people were getting what they expected.
- Since some places want to access the address as a reference, I added a few new functions to symbol:
Address &Symbol::GetAddressRef();
const Address &Symbol::GetAddressRef() const;
Linux test suite passes just fine now.
<rdar://problem/21494354>
llvm-svn: 240702
Diffstat (limited to 'lldb/source/Plugins')
21 files changed, 579 insertions, 284 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp index 061283ba121..87dadd72f88 100644 --- a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp @@ -64,7 +64,7 @@ static lldb::addr_t findSymbolAddress( Process *proc, ConstString findName ) if ( ConstString::Compare( findName, symName ) == 0 ) { - Address addr = sym->GetAddress( ); + Address addr = sym->GetAddressObj( ); return addr.GetLoadAddress( & proc->GetTarget() ); } } diff --git a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp index 61f9b3d441c..5b9c39d2555 100644 --- a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp +++ b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp @@ -332,7 +332,7 @@ HexagonDYLDRendezvous::FindMetadata(const char *name, PThreadField field, uint32 if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), eSymbolTypeAny, list)) return false; - Address address = list[0].symbol->GetAddress(); + Address address = list[0].symbol->GetAddressObj(); addr_t addr = address.GetLoadAddress (&target); if (addr == LLDB_INVALID_ADDRESS) return false; diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 80fe2531845..33a375f9ac9 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -407,7 +407,7 @@ DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb:: static ConstString g_dyld_all_image_infos ("dyld_all_image_infos"); const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType (g_dyld_all_image_infos, eSymbolTypeData); if (symbol) - m_dyld_all_image_infos_addr = symbol->GetAddress().GetLoadAddress(&target); + m_dyld_all_image_infos_addr = symbol->GetLoadAddress(&target); } // Update all image infos @@ -1370,7 +1370,7 @@ DynamicLoaderMacOSXDYLD::AlwaysRelyOnEHUnwindInfo (SymbolContext &sym_ctx) ModuleSP module_sp; if (sym_ctx.symbol) { - module_sp = sym_ctx.symbol->GetAddress().GetModule(); + module_sp = sym_ctx.symbol->GetAddressRef().GetModule(); } if (module_sp.get() == NULL && sym_ctx.function) { @@ -1649,12 +1649,13 @@ DynamicLoaderMacOSXDYLD::GetStepThroughTrampolinePlan (Thread &thread, bool stop Symbol *actual_symbol = context.symbol->ResolveReExportedSymbol(*target_sp.get()); if (actual_symbol) { - if (actual_symbol->GetAddress().IsValid()) + const Address actual_symbol_addr = actual_symbol->GetAddress(); + if (actual_symbol_addr.IsValid()) { - addresses.push_back(actual_symbol->GetAddress()); + addresses.push_back(actual_symbol_addr); if (log) { - lldb::addr_t load_addr = actual_symbol->GetAddress().GetLoadAddress(target_sp.get()); + lldb::addr_t load_addr = actual_symbol_addr.GetLoadAddress(target_sp.get()); log->Printf ("Found a re-exported symbol: %s at 0x%" PRIx64 ".", actual_symbol->GetName().GetCString(), load_addr); } @@ -1720,7 +1721,8 @@ DynamicLoaderMacOSXDYLD::GetStepThroughTrampolinePlan (Thread &thread, bool stop if (symbol && symbol->IsIndirect()) { Error error; - addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(&symbol->GetAddress(), error); + Address symbol_address = symbol->GetAddress(); + addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(&symbol_address, error); if (error.Success()) { load_addrs.push_back(resolved_addr); diff --git a/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp index 54c6834518a..9b72ceb71bd 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp @@ -287,11 +287,11 @@ AddressSanitizerRuntime::Activate() if (symbol == NULL) return; - if (!symbol->GetAddress().IsValid()) + if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return; Target &target = m_process->GetTarget(); - addr_t symbol_address = symbol->GetAddress().GetOpcodeLoadAddress(&target); + addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(&target); if (symbol_address == LLDB_INVALID_ADDRESS) return; diff --git a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp b/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp index b9c71ad1ba4..8e454e712fe 100644 --- a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ b/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -436,10 +436,10 @@ JITLoaderGDB::GetSymbolAddress(ModuleList &module_list, const ConstString &name, SymbolContext sym_ctx; target_symbols.GetContextAtIndex(0, sym_ctx); - const Address *jit_descriptor_addr = &sym_ctx.symbol->GetAddress(); - if (!jit_descriptor_addr || !jit_descriptor_addr->IsValid()) + const Address jit_descriptor_addr = sym_ctx.symbol->GetAddress(); + if (!jit_descriptor_addr.IsValid()) return LLDB_INVALID_ADDRESS; - const addr_t jit_addr = jit_descriptor_addr->GetLoadAddress(&target); + const addr_t jit_addr = jit_descriptor_addr.GetLoadAddress(&target); return jit_addr; } diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp index 792886f1bcf..9f0f6aa3c48 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp @@ -299,13 +299,13 @@ AppleObjCRuntimeV1::GetISAHashTablePointer () 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) + if (symbol && symbol->ValueIsAddress()) { Process *process = GetProcess(); if (process) { - lldb::addr_t objc_debug_class_hash_addr = symbol->GetAddress().GetLoadAddress(&process->GetTarget()); + lldb::addr_t objc_debug_class_hash_addr = symbol->GetAddressRef().GetLoadAddress(&process->GetTarget()); if (objc_debug_class_hash_addr != LLDB_INVALID_ADDRESS) { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 02d9350ba90..54a253c8200 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -321,9 +321,9 @@ ExtractRuntimeGlobalSymbol (Process* process, if (!byte_size) byte_size = process->GetAddressByteSize(); const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(name, lldb::eSymbolTypeData); - if (symbol) + if (symbol && symbol->ValueIsAddress()) { - lldb::addr_t symbol_load_addr = symbol->GetAddress().GetLoadAddress(&process->GetTarget()); + lldb::addr_t symbol_load_addr = symbol->GetAddressRef().GetLoadAddress(&process->GetTarget()); if (symbol_load_addr != LLDB_INVALID_ADDRESS) { if (read_value) @@ -815,7 +815,7 @@ AppleObjCRuntimeV2::GetByteOffsetForIvar (ClangASTType &parent_ast_type, const c if (sc_list.GetSize() == 1 && sc_list.GetContextAtIndex(0, ivar_offset_symbol)) { if (ivar_offset_symbol.symbol) - ivar_offset_address = ivar_offset_symbol.symbol->GetAddress().GetLoadAddress (&target); + ivar_offset_address = ivar_offset_symbol.symbol->GetLoadAddress (&target); } //---------------------------------------------------------------------- @@ -1191,7 +1191,7 @@ AppleObjCRuntimeV2::GetISAHashTablePointer () const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_objc_realized_classes, lldb::eSymbolTypeAny); if (symbol) { - lldb::addr_t gdb_objc_realized_classes_ptr = symbol->GetAddress().GetLoadAddress(&process->GetTarget()); + lldb::addr_t gdb_objc_realized_classes_ptr = symbol->GetLoadAddress(&process->GetTarget()); if (gdb_objc_realized_classes_ptr != LLDB_INVALID_ADDRESS) { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index dd2d0e035d9..5d82f16722e 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -471,10 +471,7 @@ AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols () eSymbolTypeData); if (trampoline_symbol != NULL) { - if (!trampoline_symbol->GetAddress().IsValid()) - return false; - - m_trampoline_header = trampoline_symbol->GetAddress().GetLoadAddress(&target); + m_trampoline_header = trampoline_symbol->GetLoadAddress(&target); if (m_trampoline_header == LLDB_INVALID_ADDRESS) return false; @@ -484,10 +481,11 @@ AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols () eSymbolTypeCode); if (changed_symbol != NULL) { - if (!changed_symbol->GetAddress().IsValid()) + const Address changed_symbol_addr = changed_symbol->GetAddress(); + if (!changed_symbol_addr.IsValid()) return false; - lldb::addr_t changed_addr = changed_symbol->GetAddress().GetOpcodeLoadAddress (&target); + lldb::addr_t changed_addr = changed_symbol_addr.GetOpcodeLoadAddress (&target); if (changed_addr != LLDB_INVALID_ADDRESS) { BreakpointSP trampolines_changed_bp_sp = target.CreateBreakpoint (changed_addr, true, false); @@ -703,13 +701,13 @@ AppleObjCTrampolineHandler::AppleObjCTrampolineHandler (const ProcessSP &process { ConstString name_const_str(g_dispatch_functions[i].name); const Symbol *msgSend_symbol = m_objc_module_sp->FindFirstSymbolWithNameAndType (name_const_str, eSymbolTypeCode); - if (msgSend_symbol) + if (msgSend_symbol && msgSend_symbol->ValueIsAddress()) { // FixMe: Make g_dispatch_functions static table of DispatchFunctions, and have the map be address->index. // Problem is we also need to lookup the dispatch function. For now we could have a side table of stret & non-stret // dispatch functions. If that's as complex as it gets, we're fine. - lldb::addr_t sym_addr = msgSend_symbol->GetAddress().GetOpcodeLoadAddress(target); + lldb::addr_t sym_addr = msgSend_symbol->GetAddressRef().GetOpcodeLoadAddress(target); m_msgSend_map.insert(std::pair<lldb::addr_t, int>(sym_addr, i)); } diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index da36b19f321..2490cf31409 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -422,7 +422,7 @@ RenderScriptRuntime::LoadRuntimeHooks(lldb::ModuleSP module, ModuleKind kind) const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(hook_defn->symbol_name), eSymbolTypeCode); - addr_t addr = sym->GetAddress().GetLoadAddress(&target); + addr_t addr = sym->GetLoadAddress(&target); if (addr == LLDB_INVALID_ADDRESS) { if(log) @@ -542,7 +542,7 @@ RenderScriptRuntime::LoadModule(const lldb::ModuleSP &module_sp) Error error; uint32_t flag = 0x00000001U; Target &target = GetProcess()->GetTarget(); - addr_t addr = debug_present->GetAddress().GetLoadAddress(&target); + addr_t addr = debug_present->GetLoadAddress(&target); GetProcess()->WriteMemory(addr, &flag, sizeof(flag), error); if(error.Success()) { @@ -597,7 +597,7 @@ RSModuleDescriptor::ParseRSInfo() const Symbol *info_sym = m_module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData); if (info_sym) { - const addr_t addr = info_sym->GetAddress().GetFileAddress(); + const addr_t addr = info_sym->GetAddressRef().GetFileAddress(); const addr_t size = info_sym->GetByteSize(); const FileSpec fs = m_module->GetFileSpec(); @@ -809,7 +809,7 @@ RenderScriptRuntime::AttemptBreakpointAtKernelName(Stream &strm, const char* nam } } - addr_t bp_addr = kernel_sym->GetAddress().GetLoadAddress(&GetProcess()->GetTarget()); + addr_t bp_addr = kernel_sym->GetLoadAddress(&GetProcess()->GetTarget()); if (bp_addr == LLDB_INVALID_ADDRESS) { error.SetErrorStringWithFormat("Could not locate load address for symbols of kernel '%s'.", name); diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index bdc13e73260..1ceaa2c3761 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2381,7 +2381,7 @@ ObjectFileELF::RelocateSection(Symtab* symtab, const ELFHeader *hdr, const ELFSe symbol = symtab->FindSymbolByID(reloc_symbol(rel)); if (symbol) { - addr_t value = symbol->GetAddress().GetFileAddress(); + addr_t value = symbol->GetAddressRef().GetFileAddress(); DataBufferSP& data_buffer_sp = debug_data.GetSharedDataBuffer(); uint64_t* dst = reinterpret_cast<uint64_t*>(data_buffer_sp->GetBytes() + rel_section->GetFileOffset() + ELFRelocation::RelocOffset64(rel)); *dst = value + ELFRelocation::RelocAddend64(rel); @@ -2394,7 +2394,7 @@ ObjectFileELF::RelocateSection(Symtab* symtab, const ELFHeader *hdr, const ELFSe symbol = symtab->FindSymbolByID(reloc_symbol(rel)); if (symbol) { - addr_t value = symbol->GetAddress().GetFileAddress(); + addr_t value = symbol->GetAddressRef().GetFileAddress(); value += ELFRelocation::RelocAddend32(rel); assert((reloc_type(rel) == R_X86_64_32 && (value <= UINT32_MAX)) || (reloc_type(rel) == R_X86_64_32S && diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index c61f871cdbd..511d73d2226 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -1271,7 +1271,7 @@ ObjectFileMachO::GetAddressClass (lldb::addr_t file_addr) { if (symbol->ValueIsAddress()) { - SectionSP section_sp (symbol->GetAddress().GetSection()); + SectionSP section_sp (symbol->GetAddressRef().GetSection()); if (section_sp) { const lldb::SectionType section_type = section_sp->GetType(); @@ -3521,8 +3521,8 @@ ObjectFileMachO::ParseSymtab () m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx; // Copy the address, because often the N_GSYM address has an invalid address of zero // when the global is a common symbol - sym[GSYM_sym_idx].GetAddress().SetSection (symbol_section); - sym[GSYM_sym_idx].GetAddress().SetOffset (symbol_value); + sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section); + sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value); // We just need the flags from the linker symbol, so put these flags // into the N_GSYM flags to avoid duplicate symbols in the symbol table sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); @@ -3537,8 +3537,8 @@ ObjectFileMachO::ParseSymtab () sym[sym_idx].SetType (type); if (set_value) { - sym[sym_idx].GetAddress().SetSection (symbol_section); - sym[sym_idx].GetAddress().SetOffset (symbol_value); + sym[sym_idx].GetAddressRef().SetSection (symbol_section); + sym[sym_idx].GetAddressRef().SetOffset (symbol_value); } sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); @@ -4364,8 +4364,8 @@ ObjectFileMachO::ParseSymtab () m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx; // Copy the address, because often the N_GSYM address has an invalid address of zero // when the global is a common symbol - sym[GSYM_sym_idx].GetAddress().SetSection (symbol_section); - sym[GSYM_sym_idx].GetAddress().SetOffset (symbol_value); + sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section); + sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value); // We just need the flags from the linker symbol, so put these flags // into the N_GSYM flags to avoid duplicate symbols in the symbol table sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); @@ -4380,8 +4380,8 @@ ObjectFileMachO::ParseSymtab () sym[sym_idx].SetType (type); if (set_value) { - sym[sym_idx].GetAddress().SetSection (symbol_section); - sym[sym_idx].GetAddress().SetOffset (symbol_value); + sym[sym_idx].GetAddressRef().SetSection (symbol_section); + sym[sym_idx].GetAddressRef().SetOffset (symbol_value); } sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); @@ -4475,7 +4475,7 @@ ObjectFileMachO::ParseSymtab () sym[sym_idx].GetMangled().SetDemangledName(ConstString(synthetic_function_symbol)); sym[sym_idx].SetType (eSymbolTypeCode); sym[sym_idx].SetIsSynthetic (true); - sym[sym_idx].GetAddress() = symbol_addr; + sym[sym_idx].GetAddressRef() = symbol_addr; if (symbol_flags) sym[sym_idx].SetFlags (symbol_flags); if (symbol_byte_size) @@ -4559,7 +4559,7 @@ ObjectFileMachO::ParseSymtab () else stub_symbol->SetType (eSymbolTypeResolver); stub_symbol->SetExternal (false); - stub_symbol->GetAddress() = so_addr; + stub_symbol->GetAddressRef() = so_addr; stub_symbol->SetByteSize (symbol_stub_byte_size); } else @@ -4578,7 +4578,7 @@ ObjectFileMachO::ParseSymtab () else sym[sym_idx].SetType (eSymbolTypeResolver); sym[sym_idx].SetIsSynthetic (true); - sym[sym_idx].GetAddress() = so_addr; + sym[sym_idx].GetAddressRef() = so_addr; sym[sym_idx].SetByteSize (symbol_stub_byte_size); ++sym_idx; } diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index 5f7935e1275..8189f10bd30 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -574,7 +574,7 @@ ObjectFilePECOFF::GetSymtab() if ((int16_t)symbol.sect >= 1) { Address symbol_addr(sect_list->GetSectionAtIndex(symbol.sect-1), symbol.value); - symbols[i].GetAddress() = symbol_addr; + symbols[i].GetAddressRef() = symbol_addr; } if (symbol.naux > 0) @@ -633,7 +633,7 @@ ObjectFilePECOFF::GetSymtab() Address symbol_addr(m_coff_header_opt.image_base + function_rva, sect_list); symbols[i].GetMangled().SetValue(ConstString(symbol_name.c_str())); - symbols[i].GetAddress() = symbol_addr; + symbols[i].GetAddressRef() = symbol_addr; symbols[i].SetType(lldb::eSymbolTypeCode); symbols[i].SetDebug(true); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index f487ae94192..167198950fa 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -100,6 +100,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient() : m_supports_QEnvironment (true), m_supports_QEnvironmentHexEncoded (true), m_supports_qSymbol (true), + m_supports_jThreadsInfo (true), m_curr_pid (LLDB_INVALID_PROCESS_ID), m_curr_tid (LLDB_INVALID_THREAD_ID), m_curr_tid_run (LLDB_INVALID_THREAD_ID), @@ -604,6 +605,32 @@ GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid) return m_supports_p; } +StructuredData::ObjectSP +GDBRemoteCommunicationClient::GetThreadsInfo() +{ + // Get information on all threads at one using the "jThreadsInfo" packet + StructuredData::ObjectSP object_sp; + + if (m_supports_jThreadsInfo) + { + StringExtractorGDBRemote response; + m_supports_jThreadExtendedInfo = eLazyBoolNo; + if (SendPacketAndWaitForResponse("jThreadsInfo", response, false) == PacketResult::Success) + { + if (response.IsUnsupportedResponse()) + { + m_supports_jThreadsInfo = false; + } + else if (!response.Empty()) + { + object_sp = StructuredData::ParseJSON (response.GetStringRef()); + } + } + } + return object_sp; +} + + bool GDBRemoteCommunicationClient::GetThreadExtendedInfoSupported () { @@ -4296,11 +4323,52 @@ GDBRemoteCommunicationClient::ServeSymbolLookups(lldb_private::Process *process) lldb_private::SymbolContextList sc_list; if (process->GetTarget().GetImages().FindSymbolsWithNameAndType(ConstString(symbol_name), eSymbolTypeAny, sc_list)) { - SymbolContext sc; - if (sc_list.GetContextAtIndex(0, sc)) + 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) { - if (sc.symbol) - symbol_load_addr = sc.symbol->GetAddress().GetLoadAddress(&process->GetTarget()); + SymbolContext sc; + if (sc_list.GetContextAtIndex(sc_idx, sc)) + { + if (sc.symbol) + { + switch (sc.symbol->GetType()) + { + case eSymbolTypeInvalid: + case eSymbolTypeAbsolute: + case eSymbolTypeUndefined: + case eSymbolTypeSourceFile: + case eSymbolTypeHeaderFile: + case eSymbolTypeObjectFile: + case eSymbolTypeCommonBlock: + case eSymbolTypeBlock: + case eSymbolTypeLocal: + case eSymbolTypeParam: + case eSymbolTypeVariable: + case eSymbolTypeVariableType: + case eSymbolTypeLineEntry: + case eSymbolTypeLineHeader: + case eSymbolTypeScopeBegin: + case eSymbolTypeScopeEnd: + case eSymbolTypeAdditional: + case eSymbolTypeCompiler: + case eSymbolTypeInstrumentation: + case eSymbolTypeTrampoline: + break; + + case eSymbolTypeCode: + case eSymbolTypeResolver: + case eSymbolTypeData: + case eSymbolTypeRuntime: + case eSymbolTypeException: + case eSymbolTypeObjCClass: + case eSymbolTypeObjCMetaClass: + case eSymbolTypeObjCIVar: + case eSymbolTypeReExported: + symbol_load_addr = sc.symbol->GetLoadAddress(&process->GetTarget()); + break; + } + } + } } } // This is the normal path where our symbol lookup was successful and we want diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 07a3bd93321..28983b7574b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -17,6 +17,7 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/ArchSpec.h" +#include "lldb/Core/StructuredData.h" #include "lldb/Target/Process.h" #include "GDBRemoteCommunication.h" @@ -542,6 +543,9 @@ public: bool AvoidGPackets(ProcessGDBRemote *process); + StructuredData::ObjectSP + GetThreadsInfo(); + bool GetThreadExtendedInfoSupported(); @@ -624,7 +628,8 @@ protected: m_supports_z4:1, m_supports_QEnvironment:1, m_supports_QEnvironmentHexEncoded:1, - m_supports_qSymbol:1; + m_supports_qSymbol:1, + m_supports_jThreadsInfo:1; lldb::pid_t m_curr_pid; lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 2b7ff2427b9..a7e4d8c95e4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -378,6 +378,7 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : m_async_broadcaster (NULL, "lldb.process.gdb-remote.async-broadcaster"), m_async_thread_state_mutex(Mutex::eMutexTypeRecursive), m_thread_ids (), + m_threads_info_sp (), m_continue_c_tids (), m_continue_C_tids (), m_continue_s_tids (), @@ -1795,6 +1796,362 @@ ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new return true; } +bool +ProcessGDBRemote::CalculateThreadStopInfo (ThreadGDBRemote *thread) +{ + // See if we got thread stop infos for all threads via the "jThreadsInfo" packet + if (m_threads_info_sp) + { + StructuredData::Array *thread_infos = m_threads_info_sp->GetAsArray(); + if (thread_infos) + { + lldb::tid_t tid; + const size_t n = thread_infos->GetSize(); + for (size_t i=0; i<n; ++i) + { + StructuredData::Dictionary *thread_dict = thread_infos->GetItemAtIndex(i)->GetAsDictionary(); + if (thread_dict) + { + if (thread_dict->GetValueForKeyAsInteger<lldb::tid_t>("tid", tid, LLDB_INVALID_THREAD_ID)) + { + if (tid == thread->GetID()) + return SetThreadStopInfo(thread_dict); + } + } + } + } + } + + // Fall back to using the qThreadStopInfo packet + StringExtractorGDBRemote stop_packet; + if (GetGDBRemote().GetThreadStopInfo(thread->GetProtocolID(), stop_packet)) + return SetThreadStopInfo (stop_packet) == eStateStopped; + return false; +} + + +ThreadSP +ProcessGDBRemote::SetThreadStopInfo (lldb::tid_t tid, + ExpeditedRegisterMap &expedited_register_map, + uint8_t signo, + const std::string &thread_name, + const std::string &reason, + const std::string &description, + uint32_t exc_type, + const std::vector<addr_t> &exc_data, + addr_t thread_dispatch_qaddr) +{ + ThreadSP thread_sp; + if (tid != LLDB_INVALID_THREAD_ID) + { + // Scope for "locker" below + { + // m_thread_list_real does have its own mutex, but we need to + // hold onto the mutex between the call to m_thread_list_real.FindThreadByID(...) + // and the m_thread_list_real.AddThread(...) so it doesn't change on us + Mutex::Locker locker (m_thread_list_real.GetMutex ()); + thread_sp = m_thread_list_real.FindThreadByProtocolID(tid, false); + + if (!thread_sp) + { + // Create the thread if we need to + thread_sp.reset (new ThreadGDBRemote (*this, tid)); + m_thread_list_real.AddThread(thread_sp); + } + } + + if (thread_sp) + { + ThreadGDBRemote *gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); + gdb_thread->GetRegisterContext()->InvalidateIfNeeded(true); + + for (const auto &pair : expedited_register_map) + { + StringExtractor reg_value_extractor; + reg_value_extractor.GetStringRef() = pair.second; + gdb_thread->PrivateSetRegisterValue (pair.first, reg_value_extractor); + } + + // Clear the stop info just in case we don't set it to anything + thread_sp->SetStopInfo (StopInfoSP()); + thread_sp->SetName (thread_name.empty() ? NULL : thread_name.c_str()); + + gdb_thread->SetThreadDispatchQAddr (thread_dispatch_qaddr); + if (exc_type != 0) + { + const size_t exc_data_size = exc_data.size(); + + thread_sp->SetStopInfo (StopInfoMachException::CreateStopReasonWithMachException (*thread_sp, + exc_type, + exc_data_size, + exc_data_size >= 1 ? exc_data[0] : 0, + exc_data_size >= 2 ? exc_data[1] : 0, + exc_data_size >= 3 ? exc_data[2] : 0)); + } + else + { + bool handled = false; + bool did_exec = false; + if (!reason.empty()) + { + if (reason.compare("trace") == 0) + { + thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); + handled = true; + } + else if (reason.compare("breakpoint") == 0) + { + addr_t pc = thread_sp->GetRegisterContext()->GetPC(); + lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); + if (bp_site_sp) + { + // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, + // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that + // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. + handled = true; + if (bp_site_sp->ValidForThisThread (thread_sp.get())) + { + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); + } + else + { + StopInfoSP invalid_stop_info_sp; + thread_sp->SetStopInfo (invalid_stop_info_sp); + } + } + } + else if (reason.compare("trap") == 0) + { + // Let the trap just use the standard signal stop reason below... + } + else if (reason.compare("watchpoint") == 0) + { + StringExtractor desc_extractor(description.c_str()); + addr_t wp_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS); + uint32_t wp_index = desc_extractor.GetU32(LLDB_INVALID_INDEX32); + watch_id_t watch_id = LLDB_INVALID_WATCH_ID; + if (wp_addr != LLDB_INVALID_ADDRESS) + { + WatchpointSP wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_addr); + if (wp_sp) + { + wp_sp->SetHardwareIndex(wp_index); + watch_id = wp_sp->GetID(); + } + } + if (watch_id == LLDB_INVALID_WATCH_ID) + { + Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_WATCHPOINTS)); + if (log) log->Printf ("failed to find watchpoint"); + } + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithWatchpointID (*thread_sp, watch_id)); + handled = true; + } + else if (reason.compare("exception") == 0) + { + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException(*thread_sp, description.c_str())); + handled = true; + } + else if (reason.compare("exec") == 0) + { + did_exec = true; + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithExec(*thread_sp)); + handled = true; + } + } + + if (!handled && signo && did_exec == false) + { + if (signo == SIGTRAP) + { + // Currently we are going to assume SIGTRAP means we are either + // hitting a breakpoint or hardware single stepping. + handled = true; + addr_t pc = thread_sp->GetRegisterContext()->GetPC() + m_breakpoint_pc_offset; + lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); + + if (bp_site_sp) + { + // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, + // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that + // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. + if (bp_site_sp->ValidForThisThread (thread_sp.get())) + { + if(m_breakpoint_pc_offset != 0) + thread_sp->GetRegisterContext()->SetPC(pc); + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); + } + else + { + StopInfoSP invalid_stop_info_sp; + thread_sp->SetStopInfo (invalid_stop_info_sp); + } + } + else + { + // If we were stepping then assume the stop was the result of the trace. If we were + // not stepping then report the SIGTRAP. + // FIXME: We are still missing the case where we single step over a trap instruction. + if (thread_sp->GetTemporaryResumeState() == eStateStepping) + thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); + else + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal(*thread_sp, signo, description.c_str())); + } + } + if (!handled) + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal (*thread_sp, signo, description.c_str())); + } + + if (!description.empty()) + { + lldb::StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); + if (stop_info_sp) + { + const char *stop_info_desc = stop_info_sp->GetDescription(); + if (!stop_info_desc || !stop_info_desc[0]) + stop_info_sp->SetDescription (description.c_str()); + } + else + { + thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException (*thread_sp, description.c_str())); + } + } + } + } + } + return thread_sp; +} + +StateType +ProcessGDBRemote::SetThreadStopInfo (StructuredData::Dictionary *thread_dict) +{ + static ConstString g_key_tid("tid"); + static ConstString g_key_name("name"); + static ConstString g_key_reason("reason"); + static ConstString g_key_metype("metype"); + static ConstString g_key_medata("medata"); + static ConstString g_key_qaddr("qaddr"); + static ConstString g_key_registers("registers"); + static ConstString g_key_memory("memory"); + static ConstString g_key_address("address"); + static ConstString g_key_bytes("bytes"); + static ConstString g_key_description("description"); + + // Stop with signal and thread info + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; + uint8_t signo = 0; + std::string value; + std::string thread_name; + std::string reason; + std::string description; + uint32_t exc_type = 0; + std::vector<addr_t> exc_data; + addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; + ExpeditedRegisterMap expedited_register_map; + // Iterate through all of the thread dictionary key/value pairs from the structured data dictionary + + thread_dict->ForEach([this, &tid, &expedited_register_map, &thread_name, &signo, &reason, &description, &exc_type, &exc_data, &thread_dispatch_qaddr](ConstString key, StructuredData::Object* object) -> bool + { + if (key == g_key_tid) + { + // thread in big endian hex + tid = object->GetIntegerValue(LLDB_INVALID_THREAD_ID); + } + else if (key == g_key_metype) + { + // exception type in big endian hex + exc_type = object->GetIntegerValue(0); + } + else if (key == g_key_medata) + { + // exception data in big endian hex + StructuredData::Array *array = object->GetAsArray(); + if (array) + { + array->ForEach([&exc_data](StructuredData::Object* object) -> bool { + exc_data.push_back(object->GetIntegerValue()); + return true; // Keep iterating through all array items + }); + } + } + else if (key == g_key_name) + { + thread_name = std::move(object->GetStringValue()); + } + else if (key == g_key_qaddr) + { + thread_dispatch_qaddr = object->GetIntegerValue(LLDB_INVALID_ADDRESS); + } + else if (key == g_key_reason) + { + reason = std::move(object->GetStringValue()); + } + else if (key == g_key_description) + { + description = std::move(object->GetStringValue()); + } + else if (key == g_key_registers) + { + StructuredData::Dictionary *registers_dict = object->GetAsDictionary(); + + if (registers_dict) + { + registers_dict->ForEach([&expedited_register_map](ConstString key, StructuredData::Object* object) -> bool { + const uint32_t reg = StringConvert::ToUInt32 (key.GetCString(), UINT32_MAX, 10); + if (reg != UINT32_MAX) + expedited_register_map[reg] = std::move(object->GetStringValue()); + return true; // Keep iterating through all array items + }); + } + } + else if (key == g_key_memory) + { + StructuredData::Array *array = object->GetAsArray(); + if (array) + { + array->ForEach([this](StructuredData::Object* object) -> bool { + StructuredData::Dictionary *mem_cache_dict = object->GetAsDictionary(); + if (mem_cache_dict) + { + lldb::addr_t mem_cache_addr = LLDB_INVALID_ADDRESS; + if (mem_cache_dict->GetValueForKeyAsInteger<lldb::addr_t>("address", mem_cache_addr)) + { + if (mem_cache_addr != LLDB_INVALID_ADDRESS) + { + StringExtractor bytes; + if (mem_cache_dict->GetValueForKeyAsString("bytes", bytes.GetStringRef())) + { + bytes.SetFilePos(0); + + const size_t byte_size = bytes.GetStringRef().size()/2; + DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); + if (bytes_copied == byte_size) + m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); + } + } + } + } + return true; // Keep iterating through all array items + }); + } + + } + return true; // Keep iterating through all dictionary key/value pairs + }); + + SetThreadStopInfo (tid, + expedited_register_map, + signo, + thread_name, + reason, + description, + exc_type, + exc_data, + thread_dispatch_qaddr); + + return eStateExited; +} StateType ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) @@ -1825,8 +2182,9 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) BuildDynamicRegisterInfo (true); } // Stop with signal and thread info + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; const uint8_t signo = stop_packet.GetHexU8(); - std::string name; + std::string key; std::string value; std::string thread_name; std::string reason; @@ -1838,48 +2196,25 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) std::string queue_name; QueueKind queue_kind = eQueueKindUnknown; uint64_t queue_serial = 0; - ThreadSP thread_sp; - ThreadGDBRemote *gdb_thread = NULL; - - while (stop_packet.GetNameColonValue(name, value)) + ExpeditedRegisterMap expedited_register_map; + while (stop_packet.GetNameColonValue(key, value)) { - if (name.compare("metype") == 0) + if (key.compare("metype") == 0) { // exception type in big endian hex exc_type = StringConvert::ToUInt32 (value.c_str(), 0, 16); } - else if (name.compare("medata") == 0) + else if (key.compare("medata") == 0) { // exception data in big endian hex exc_data.push_back(StringConvert::ToUInt64 (value.c_str(), 0, 16)); } - else if (name.compare("thread") == 0) + else if (key.compare("thread") == 0) { // thread in big endian hex - lldb::tid_t tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); - // m_thread_list_real does have its own mutex, but we need to - // hold onto the mutex between the call to m_thread_list_real.FindThreadByID(...) - // and the m_thread_list_real.AddThread(...) so it doesn't change on us - Mutex::Locker locker (m_thread_list_real.GetMutex ()); - thread_sp = m_thread_list_real.FindThreadByProtocolID(tid, false); - - if (!thread_sp) - { - // Create the thread if we need to - thread_sp.reset (new ThreadGDBRemote (*this, tid)); - Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_THREAD)); - if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) - log->Printf ("ProcessGDBRemote::%s Adding new thread: %p for thread ID: 0x%" PRIx64 ".\n", - __FUNCTION__, - static_cast<void*>(thread_sp.get()), - thread_sp->GetID()); - - m_thread_list_real.AddThread(thread_sp); - } - gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); - + tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); } - else if (name.compare("threads") == 0) + else if (key.compare("threads") == 0) { Mutex::Locker locker(m_thread_list_real.GetMutex()); m_thread_ids.clear(); @@ -1901,7 +2236,7 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) if (tid != LLDB_INVALID_THREAD_ID) m_thread_ids.push_back (tid); } - else if (name.compare("hexname") == 0) + else if (key.compare("hexname") == 0) { StringExtractor name_extractor; // Swap "value" over into "name_extractor" @@ -1910,15 +2245,15 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) name_extractor.GetHexByteString (value); thread_name.swap (value); } - else if (name.compare("name") == 0) + else if (key.compare("name") == 0) { thread_name.swap (value); } - else if (name.compare("qaddr") == 0) + else if (key.compare("qaddr") == 0) { thread_dispatch_qaddr = StringConvert::ToUInt64 (value.c_str(), 0, 16); } - else if (name.compare("qname") == 0) + else if (key.compare("qname") == 0) { queue_vars_valid = true; StringExtractor name_extractor; @@ -1928,7 +2263,7 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) name_extractor.GetHexByteString (value); queue_name.swap (value); } - else if (name.compare("qkind") == 0) + else if (key.compare("qkind") == 0) { queue_vars_valid = true; if (value == "serial") @@ -1936,16 +2271,16 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) else if (value == "concurrent") queue_kind = eQueueKindConcurrent; } - else if (name.compare("qserial") == 0) + else if (key.compare("qserial") == 0) { queue_vars_valid = true; queue_serial = StringConvert::ToUInt64 (value.c_str(), 0, 0); } - else if (name.compare("reason") == 0) + else if (key.compare("reason") == 0) { reason.swap(value); } - else if (name.compare("description") == 0) + else if (key.compare("description") == 0) { StringExtractor desc_extractor; // Swap "value" over into "name_extractor" @@ -1954,34 +2289,57 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) desc_extractor.GetHexByteString (value); description.swap(value); } - else if (name.size() == 2 && ::isxdigit(name[0]) && ::isxdigit(name[1])) + else if (key.compare("memory") == 0) { - // We have a register number that contains an expedited - // register value. Lets supply this register to our thread - // so it won't have to go and read it. - if (gdb_thread) + // Expedited memory. GDB servers can choose to send back expedited memory + // that can populate the L1 memory cache in the process so that things like + // the frame pointer backchain can be expedited. This will help stack + // backtracing be more efficient by not having to send as many memory read + // requests down the remote GDB server. + + // Key/value pair format: memory:<addr>=<bytes>; + // <addr> is a number whose base will be interpreted by the prefix: + // "0x[0-9a-fA-F]+" for hex + // "0[0-7]+" for octal + // "[1-9]+" for decimal + // <bytes> is native endian ASCII hex bytes just like the register values + llvm::StringRef value_ref(value); + std::pair<llvm::StringRef, llvm::StringRef> pair; + pair = value_ref.split('='); + if (!pair.first.empty() && !pair.second.empty()) { - uint32_t reg = StringConvert::ToUInt32 (name.c_str(), UINT32_MAX, 16); - - if (reg != UINT32_MAX) + std::string addr_str(pair.first.str()); + const lldb::addr_t mem_cache_addr = StringConvert::ToUInt64(addr_str.c_str(), LLDB_INVALID_ADDRESS, 0); + if (mem_cache_addr != LLDB_INVALID_ADDRESS) { - StringExtractor reg_value_extractor; - // Swap "value" over into "reg_value_extractor" - reg_value_extractor.GetStringRef().swap(value); - if (!gdb_thread->PrivateSetRegisterValue (reg, reg_value_extractor)) - { - Host::SetCrashDescriptionWithFormat("Setting thread register '%s' (decoded to %u (0x%x)) with value '%s' for stop packet: '%s'", - name.c_str(), - reg, - reg, - reg_value_extractor.GetStringRef().c_str(), - stop_packet.GetStringRef().c_str()); - } + StringExtractor bytes; + bytes.GetStringRef() = std::move(pair.second.str()); + const size_t byte_size = bytes.GetStringRef().size()/2; + DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); + if (bytes_copied == byte_size) + m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); } } } + else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) + { + uint32_t reg = StringConvert::ToUInt32 (key.c_str(), UINT32_MAX, 16); + if (reg != UINT32_MAX) + expedited_register_map[reg] = std::move(value); + } } + ThreadSP thread_sp = SetThreadStopInfo (tid, + expedited_register_map, + signo, + thread_name, + reason, + description, + exc_type, + exc_data, + thread_dispatch_qaddr); + // If the response is old style 'S' packet which does not provide us with thread information // then update the thread list and choose the first one. if (!thread_sp) @@ -1992,164 +2350,9 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) { Mutex::Locker locker (m_thread_list_real.GetMutex ()); thread_sp = m_thread_list_real.FindThreadByProtocolID (m_thread_ids.front (), false); - if (thread_sp) - gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get ()); } } - if (thread_sp) - { - // Clear the stop info just in case we don't set it to anything - thread_sp->SetStopInfo (StopInfoSP()); - - gdb_thread->SetThreadDispatchQAddr (thread_dispatch_qaddr); - if (queue_vars_valid) - gdb_thread->SetQueueInfo(std::move(queue_name), queue_kind, queue_serial); - else - gdb_thread->ClearQueueInfo(); - - gdb_thread->SetName (thread_name.empty() ? NULL : thread_name.c_str()); - if (exc_type != 0) - { - const size_t exc_data_size = exc_data.size(); - - thread_sp->SetStopInfo (StopInfoMachException::CreateStopReasonWithMachException (*thread_sp, - exc_type, - exc_data_size, - exc_data_size >= 1 ? exc_data[0] : 0, - exc_data_size >= 2 ? exc_data[1] : 0, - exc_data_size >= 3 ? exc_data[2] : 0)); - } - else - { - bool handled = false; - bool did_exec = false; - if (!reason.empty()) - { - if (reason.compare("trace") == 0) - { - thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); - handled = true; - } - else if (reason.compare("breakpoint") == 0) - { - addr_t pc = thread_sp->GetRegisterContext()->GetPC(); - lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); - if (bp_site_sp) - { - // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, - // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that - // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. - handled = true; - if (bp_site_sp->ValidForThisThread (thread_sp.get())) - { - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); - } - else - { - StopInfoSP invalid_stop_info_sp; - thread_sp->SetStopInfo (invalid_stop_info_sp); - } - } - } - else if (reason.compare("trap") == 0) - { - // Let the trap just use the standard signal stop reason below... - } - else if (reason.compare("watchpoint") == 0) - { - StringExtractor desc_extractor(description.c_str()); - addr_t wp_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS); - uint32_t wp_index = desc_extractor.GetU32(LLDB_INVALID_INDEX32); - watch_id_t watch_id = LLDB_INVALID_WATCH_ID; - if (wp_addr != LLDB_INVALID_ADDRESS) - { - WatchpointSP wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_addr); - if (wp_sp) - { - wp_sp->SetHardwareIndex(wp_index); - watch_id = wp_sp->GetID(); - } - } - if (watch_id == LLDB_INVALID_WATCH_ID) - { - Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_WATCHPOINTS)); - if (log) log->Printf ("failed to find watchpoint"); - } - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithWatchpointID (*thread_sp, watch_id)); - handled = true; - } - else if (reason.compare("exception") == 0) - { - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException(*thread_sp, description.c_str())); - handled = true; - } - else if (reason.compare("exec") == 0) - { - did_exec = true; - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithExec(*thread_sp)); - handled = true; - } - } - - if (!handled && signo && did_exec == false) - { - if (signo == SIGTRAP) - { - // Currently we are going to assume SIGTRAP means we are either - // hitting a breakpoint or hardware single stepping. - handled = true; - addr_t pc = thread_sp->GetRegisterContext()->GetPC() + m_breakpoint_pc_offset; - lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); - - if (bp_site_sp) - { - // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, - // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that - // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. - if (bp_site_sp->ValidForThisThread (thread_sp.get())) - { - if(m_breakpoint_pc_offset != 0) - thread_sp->GetRegisterContext()->SetPC(pc); - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); - } - else - { - StopInfoSP invalid_stop_info_sp; - thread_sp->SetStopInfo (invalid_stop_info_sp); - } - } - else - { - // If we were stepping then assume the stop was the result of the trace. If we were - // not stepping then report the SIGTRAP. - // FIXME: We are still missing the case where we single step over a trap instruction. - if (thread_sp->GetTemporaryResumeState() == eStateStepping) - thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); - else - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal(*thread_sp, signo, description.c_str())); - } - } - if (!handled) - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal (*thread_sp, signo, description.c_str())); - } - - if (!description.empty()) - { - lldb::StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); - if (stop_info_sp) - { - const char *stop_info_desc = stop_info_sp->GetDescription(); - if (!stop_info_desc || !stop_info_desc[0]) - stop_info_sp->SetDescription (description.c_str()); - } - else - { - thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException (*thread_sp, description.c_str())); - } - } - } - } return eStateStopped; } break; @@ -2206,6 +2409,11 @@ ProcessGDBRemote::RefreshStateAfterStop () m_initial_tid = LLDB_INVALID_THREAD_ID; } + // Fetch the threads via an efficient packet that gets stop infos for all threads + // only if we have more than one thread + if (m_thread_ids.size() > 1) + m_threads_info_sp = m_gdb_comm.GetThreadsInfo(); + // Let all threads recover from stopping and do any clean up based // on the previous thread state (if any). m_thread_list_real.RefreshStateAfterStop(); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 16e47dfcba6..d810d9ce2f1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -326,6 +326,9 @@ protected: void GetMaxMemorySize(); + bool + CalculateThreadStopInfo (ThreadGDBRemote *thread); + //------------------------------------------------------------------ /// Broadcaster event bits definitions. //------------------------------------------------------------------ @@ -348,7 +351,9 @@ protected: typedef std::vector<lldb::tid_t> tid_collection; typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection; typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; + typedef std::map<uint32_t, std::string> ExpeditedRegisterMap; tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping + StructuredData::ObjectSP m_threads_info_sp; // Stop info for all threads if "jThreadsInfo" packet is supported tid_collection m_continue_c_tids; // 'c' for continue tid_sig_collection m_continue_C_tids; // 'C' for continue with signal tid_collection m_continue_s_tids; // 's' for step @@ -385,6 +390,20 @@ protected: lldb::StateType SetThreadStopInfo (StringExtractor& stop_packet); + lldb::StateType + SetThreadStopInfo (StructuredData::Dictionary *thread_dict); + + lldb::ThreadSP + SetThreadStopInfo (lldb::tid_t tid, + ExpeditedRegisterMap &expedited_register_map, + uint8_t signo, + const std::string &thread_name, + const std::string &reason, + const std::string &description, + uint32_t exc_type, + const std::vector<lldb::addr_t> &exc_data, + lldb::addr_t thread_dispatch_qaddr); + void HandleStopReplySequence (); diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index e58121b1978..59c701d75a6 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -317,12 +317,7 @@ ThreadGDBRemote::CalculateStopInfo () { ProcessSP process_sp (GetProcess()); if (process_sp) - { - StringExtractorGDBRemote stop_packet; - ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get()); - if (gdb_process->GetGDBRemote().GetThreadStopInfo(GetProtocolID(), stop_packet)) - return gdb_process->SetThreadStopInfo (stop_packet) == eStateStopped; - } + return static_cast<ProcessGDBRemote *>(process_sp.get())->CalculateThreadStopInfo(this); return false; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 4d3d22a6211..dafd389449a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -7620,7 +7620,7 @@ SymbolFileDWARF::ParseVariableDIE { if (exe_symbol->ValueIsAddress()) { - const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); + const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress(); if (exe_file_addr != LLDB_INVALID_ADDRESS) { if (location.Update_DW_OP_addr (exe_file_addr)) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index d5d60aed03e..5579a23ce71 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -121,8 +121,8 @@ SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(SymbolFileDWARFDebugMa { // Add the inverse OSO file address to debug map entry mapping exe_symfile->AddOSOFileRange (this, - exe_symbol->GetAddress().GetFileAddress(), - oso_fun_symbol->GetAddress().GetFileAddress(), + exe_symbol->GetAddressRef().GetFileAddress(), + oso_fun_symbol->GetAddressRef().GetFileAddress(), std::min<addr_t>(exe_symbol->GetByteSize(), oso_fun_symbol->GetByteSize())); } @@ -155,8 +155,8 @@ SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(SymbolFileDWARFDebugMa { // Add the inverse OSO file address to debug map entry mapping exe_symfile->AddOSOFileRange (this, - exe_symbol->GetAddress().GetFileAddress(), - oso_gsym_symbol->GetAddress().GetFileAddress(), + exe_symbol->GetAddressRef().GetFileAddress(), + oso_gsym_symbol->GetAddressRef().GetFileAddress(), std::min<addr_t>(exe_symbol->GetByteSize(), oso_gsym_symbol->GetByteSize())); } } @@ -374,7 +374,7 @@ SymbolFileDWARFDebugMap::InitOSO() for (uint32_t sym_idx : m_func_indexes) { const Symbol *symbol = symtab->SymbolAtIndex(sym_idx); - lldb::addr_t file_addr = symbol->GetAddress().GetFileAddress(); + lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress(); lldb::addr_t byte_size = symbol->GetByteSize(); DebugMap::Entry debug_map_entry(file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS)); m_debug_map.Append(debug_map_entry); @@ -382,7 +382,7 @@ SymbolFileDWARFDebugMap::InitOSO() for (uint32_t sym_idx : m_glob_indexes) { const Symbol *symbol = symtab->SymbolAtIndex(sym_idx); - lldb::addr_t file_addr = symbol->GetAddress().GetFileAddress(); + lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress(); lldb::addr_t byte_size = symbol->GetByteSize(); DebugMap::Entry debug_map_entry(file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS)); m_debug_map.Append(debug_map_entry); @@ -405,7 +405,7 @@ SymbolFileDWARFDebugMap::InitOSO() m_compile_unit_infos[i].so_file.SetFile(so_symbol->GetName().AsCString(), false); m_compile_unit_infos[i].oso_path = oso_symbol->GetName(); TimeValue oso_mod_time; - oso_mod_time.OffsetWithSeconds(oso_symbol->GetAddress().GetOffset()); + oso_mod_time.OffsetWithSeconds(oso_symbol->GetIntegerValue(0)); m_compile_unit_infos[i].oso_mod_time = oso_mod_time; uint32_t sibling_idx = so_symbol->GetSiblingIndex(); // The sibling index can't be less that or equal to the current index "i" diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp index 8eb3e3a09c8..64c88ab716b 100644 --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp @@ -225,7 +225,7 @@ SymbolFileSymtab::ParseCompileUnitFunctions (const SymbolContext &sc) next_symbol = symtab->SymbolAtIndex(m_code_indexes[idx + 1]); if (next_symbol) { - func_range.SetByteSize(next_symbol->GetAddress().GetOffset() - curr_symbol->GetAddress().GetOffset()); + func_range.SetByteSize(next_symbol->GetAddressRef().GetOffset() - curr_symbol->GetAddressRef().GetOffset()); } } diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index 9b18eadbf1d..67f9c59cadf 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -316,7 +316,7 @@ SystemRuntimeMacOSX::ReadLibdispatchOffsetsAddress () dispatch_queue_offsets_symbol = module_sp->FindFirstSymbolWithNameAndType (g_dispatch_queue_offsets_symbol_name, eSymbolTypeData); } if (dispatch_queue_offsets_symbol) - m_dispatch_queue_offsets_addr = dispatch_queue_offsets_symbol->GetAddress().GetLoadAddress(&m_process->GetTarget()); + m_dispatch_queue_offsets_addr = dispatch_queue_offsets_symbol->GetLoadAddress(&m_process->GetTarget()); } void @@ -361,7 +361,7 @@ SystemRuntimeMacOSX::ReadLibpthreadOffsetsAddress () (g_libpthread_layout_offsets_symbol_name, eSymbolTypeData); if (libpthread_layout_offsets_symbol) { - m_libpthread_layout_offsets_addr = libpthread_layout_offsets_symbol->GetAddress().GetLoadAddress(&m_process->GetTarget()); + m_libpthread_layout_offsets_addr = libpthread_layout_offsets_symbol->GetLoadAddress(&m_process->GetTarget()); } } } @@ -410,7 +410,7 @@ SystemRuntimeMacOSX::ReadLibdispatchTSDIndexesAddress () (g_libdispatch_tsd_indexes_symbol_name, eSymbolTypeData); if (libdispatch_tsd_indexes_symbol) { - m_dispatch_tsd_indexes_addr = libdispatch_tsd_indexes_symbol->GetAddress().GetLoadAddress(&m_process->GetTarget()); + m_dispatch_tsd_indexes_addr = libdispatch_tsd_indexes_symbol->GetLoadAddress(&m_process->GetTarget()); } } } |