diff options
Diffstat (limited to 'lldb/source/Core')
-rw-r--r-- | lldb/source/Core/Address.cpp | 208 | ||||
-rw-r--r-- | lldb/source/Core/AddressRange.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Core/DataExtractor.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Core/Disassembler.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Core/ModuleChild.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Core/Section.cpp | 246 | ||||
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 16 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectChild.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectDynamicValue.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectMemory.cpp | 8 | ||||
-rw-r--r-- | lldb/source/Core/ValueObjectVariable.cpp | 12 |
13 files changed, 295 insertions, 279 deletions
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index 5ce845f88ae..75eb742fdfe 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -55,11 +55,11 @@ GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &add if (byte_order == eByteOrderInvalid || addr_size == 0) { - Module *module = address.GetModulePtr(); - if (module) + ModuleSP module_sp (address.GetModule()); + if (module_sp) { - byte_order = module->GetArchitecture().GetByteOrder(); - addr_size = module->GetArchitecture().GetAddressByteSize(); + byte_order = module_sp->GetArchitecture().GetByteOrder(); + addr_size = module_sp->GetArchitecture().GetAddressByteSize(); } } return byte_order != eByteOrderInvalid && addr_size != 0; @@ -118,17 +118,17 @@ ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t { // If we were not running, yet able to read an integer, we must // have a module - Module *module = address.GetModulePtr(); - assert (module); - if (module->ResolveFileAddress(deref_addr, deref_so_addr)) + ModuleSP module_sp (address.GetModule()); + + assert (module_sp); + if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr)) return true; } // We couldn't make "deref_addr" into a section offset value, but we were // able to read the address, so we return a section offset address with // no section and "deref_addr" as the offset (address). - deref_so_addr.SetSection(NULL); - deref_so_addr.SetOffset(deref_addr); + deref_so_addr.SetRawAddress(deref_addr); return true; } return false; @@ -210,11 +210,17 @@ ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, return total_len; } -Address::Address (addr_t address, const SectionList * sections) : - m_section (NULL), +Address::Address (lldb::addr_t abs_addr) : + m_section_wp (), + m_offset (abs_addr) +{ +} + +Address::Address (addr_t address, const SectionList *section_list) : + m_section_wp (), m_offset (LLDB_INVALID_ADDRESS) { - ResolveAddressUsingFileSections(address, sections); + ResolveAddressUsingFileSections(address, section_list); } const Address& @@ -222,58 +228,47 @@ Address::operator= (const Address& rhs) { if (this != &rhs) { - m_section = rhs.m_section; + m_section_wp = rhs.m_section_wp; m_offset = rhs.m_offset; } return *this; } bool -Address::ResolveAddressUsingFileSections (addr_t addr, const SectionList *sections) +Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list) { - if (sections) - m_section = sections->FindSectionContainingFileAddress(addr).get(); - else - m_section = NULL; - - if (m_section != NULL) + if (section_list) { - assert( m_section->ContainsFileAddress(addr) ); - m_offset = addr - m_section->GetFileAddress(); - return true; // Successfully transformed addr into a section offset address + SectionSP section_sp (section_list->FindSectionContainingFileAddress(file_addr)); + m_section_wp = section_sp; + if (section_sp) + { + assert( section_sp->ContainsFileAddress(file_addr) ); + m_offset = file_addr - section_sp->GetFileAddress(); + return true; // Successfully transformed addr into a section offset address + } } - - m_offset = addr; + m_offset = file_addr; return false; // Failed to resolve this address to a section offset value } -Module * -Address::GetModulePtr () const -{ - if (m_section) - return m_section->GetModule(); - return NULL; -} - ModuleSP -Address::GetModuleSP () const +Address::GetModule () const { lldb::ModuleSP module_sp; - if (m_section) - { - Module *module = m_section->GetModule(); - if (module) - module_sp = module->shared_from_this(); - } + SectionSP section_sp (GetSection()); + if (section_sp) + module_sp = section_sp->GetModule(); return module_sp; } addr_t Address::GetFileAddress () const { - if (m_section != NULL) + SectionSP section_sp (GetSection()); + if (section_sp) { - addr_t sect_file_addr = m_section->GetFileAddress(); + addr_t sect_file_addr = section_sp->GetFileAddress(); if (sect_file_addr == LLDB_INVALID_ADDRESS) { // Section isn't resolved, we can't return a valid file address @@ -290,7 +285,8 @@ Address::GetFileAddress () const addr_t Address::GetLoadAddress (Target *target) const { - if (m_section == NULL) + SectionSP section_sp (GetSection()); + if (!section_sp) { // No section, we just return the offset since it is the value in this case return m_offset; @@ -298,7 +294,7 @@ Address::GetLoadAddress (Target *target) const if (target) { - addr_t sect_load_addr = m_section->GetLoadBaseAddress (target); + addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target); if (sect_load_addr != LLDB_INVALID_ADDRESS) { @@ -359,7 +355,8 @@ bool Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const { // If the section was NULL, only load address is going to work. - if (m_section == NULL) + SectionSP section_sp (GetSection()); + if (!section_sp) style = DumpStyleLoadAddress; ExecutionContext exe_ctx (exe_scope); @@ -381,9 +378,9 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum return false; case DumpStyleSectionNameOffset: - if (m_section != NULL) + if (section_sp) { - m_section->DumpName(s); + section_sp->DumpName(s); s->Printf (" + %llu", m_offset); } else @@ -393,13 +390,13 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum break; case DumpStyleSectionPointerOffset: - s->Printf("(Section *)%p + ", m_section); + s->Printf("(Section *)%p + ", section_sp.get()); s->Address(m_offset, addr_size); break; case DumpStyleModuleWithFileAddress: - if (m_section) - s->Printf("%s[", m_section->GetModule()->GetFileSpec().GetFilename().AsCString()); + if (section_sp) + s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString()); // Fall through case DumpStyleFileAddress: { @@ -411,7 +408,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum return false; } s->Address (file_addr, addr_size); - if (style == DumpStyleModuleWithFileAddress && m_section) + if (style == DumpStyleModuleWithFileAddress && section_sp) s->PutChar(']'); } break; @@ -442,23 +439,22 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum } uint32_t pointer_size = 4; - Module *module = GetModulePtr(); + ModuleSP module_sp (GetModule()); if (target) pointer_size = target->GetArchitecture().GetAddressByteSize(); - else if (module) - pointer_size = module->GetArchitecture().GetAddressByteSize(); + else if (module_sp) + pointer_size = module_sp->GetArchitecture().GetAddressByteSize(); bool showed_info = false; - const Section *section = GetSection(); - if (section) + if (section_sp) { - SectionType sect_type = section->GetType(); + SectionType sect_type = section_sp->GetType(); switch (sect_type) { case eSectionTypeData: - if (module) + if (module_sp) { - ObjectFile *objfile = module->GetObjectFile(); + ObjectFile *objfile = module_sp->GetObjectFile(); if (objfile) { Symtab *symtab = objfile->GetSymtab(); @@ -623,10 +619,10 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum if (!showed_info) { - if (module) + if (module_sp) { SymbolContext sc; - module->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); + module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); if (sc.function || sc.symbol) { bool show_stop_context = true; @@ -678,11 +674,11 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum case DumpStyleDetailedSymbolContext: if (IsSectionOffset()) { - Module *module = GetModulePtr(); - if (module) + ModuleSP module_sp (GetModule()); + if (module_sp) { SymbolContext sc; - module->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); + module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); if (sc.symbol) { // If we have just a symbol make sure it is in the same section @@ -741,12 +737,14 @@ Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) cons { sc->Clear(); // Absolute addresses don't have enough information to reconstruct even their target. - if (m_section) + + SectionSP section_sp (GetSection()); + if (section_sp) { - Module *address_module = m_section->GetModule(); - if (address_module) + ModuleSP module_sp (section_sp->GetModule()); + if (module_sp) { - sc->module_sp = address_module->shared_from_this(); + sc->module_sp = module_sp; if (sc->module_sp) return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc); } @@ -754,21 +752,23 @@ Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) cons return 0; } -Module * +ModuleSP Address::CalculateSymbolContextModule () const { - if (m_section) - return m_section->GetModule(); - return NULL; + SectionSP section_sp (GetSection()); + if (section_sp) + return section_sp->GetModule(); + return ModuleSP(); } CompileUnit * Address::CalculateSymbolContextCompileUnit () const { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->shared_from_this(); + sc.module_sp = section_sp->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc); @@ -781,10 +781,11 @@ Address::CalculateSymbolContextCompileUnit () const Function * Address::CalculateSymbolContextFunction () const { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->shared_from_this(); + sc.module_sp = section_sp->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc); @@ -797,10 +798,11 @@ Address::CalculateSymbolContextFunction () const Block * Address::CalculateSymbolContextBlock () const { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->shared_from_this(); + sc.module_sp = section_sp->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc); @@ -813,10 +815,11 @@ Address::CalculateSymbolContextBlock () const Symbol * Address::CalculateSymbolContextSymbol () const { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->shared_from_this(); + sc.module_sp = section_sp->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc); @@ -829,10 +832,11 @@ Address::CalculateSymbolContextSymbol () const bool Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->shared_from_this(); + sc.module_sp = section_sp->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc); @@ -876,8 +880,10 @@ Address::CompareLoadAddress (const Address& a, const Address& b, Target *target) int Address::CompareModulePointerAndOffset (const Address& a, const Address& b) { - Module *a_module = a.GetModulePtr (); - Module *b_module = b.GetModulePtr (); + ModuleSP a_module_sp (a.GetModule()); + ModuleSP b_module_sp (b.GetModule()); + Module *a_module = a_module_sp.get(); + Module *b_module = b_module_sp.get(); if (a_module < b_module) return -1; if (a_module > b_module) @@ -921,8 +927,10 @@ Address::MemorySize () const bool lldb_private::operator< (const Address& lhs, const Address& rhs) { - Module *lhs_module = lhs.GetModulePtr(); - Module *rhs_module = rhs.GetModulePtr(); + ModuleSP lhs_module_sp (lhs.GetModule()); + ModuleSP rhs_module_sp (rhs.GetModule()); + Module *lhs_module = lhs_module_sp.get(); + Module *rhs_module = rhs_module_sp.get(); if (lhs_module == rhs_module) { // Addresses are in the same module, just compare the file addresses @@ -939,8 +947,10 @@ lldb_private::operator< (const Address& lhs, const Address& rhs) bool lldb_private::operator> (const Address& lhs, const Address& rhs) { - Module *lhs_module = lhs.GetModulePtr(); - Module *rhs_module = rhs.GetModulePtr(); + ModuleSP lhs_module_sp (lhs.GetModule()); + ModuleSP rhs_module_sp (rhs.GetModule()); + Module *lhs_module = lhs_module_sp.get(); + Module *rhs_module = rhs_module_sp.get(); if (lhs_module == rhs_module) { // Addresses are in the same module, just compare the file addresses @@ -974,20 +984,22 @@ lldb_private::operator!= (const Address& a, const Address& rhs) bool Address::IsLinkedAddress () const { - return m_section && m_section->GetLinkedSection(); + SectionSP section_sp (GetSection()); + return section_sp && section_sp->GetLinkedSection(); } void Address::ResolveLinkedAddress () { - if (m_section) + SectionSP section_sp (GetSection()); + if (section_sp) { - const Section *linked_section = m_section->GetLinkedSection(); - if (linked_section) + SectionSP linked_section_sp (section_sp->GetLinkedSection()); + if (linked_section_sp) { - m_offset += m_section->GetLinkedOffset(); - m_section = linked_section; + m_offset += section_sp->GetLinkedOffset(); + m_section_wp = linked_section_sp; } } } @@ -995,10 +1007,10 @@ Address::ResolveLinkedAddress () AddressClass Address::GetAddressClass () const { - Module *module = GetModulePtr(); - if (module) + ModuleSP module_sp (GetModule()); + if (module_sp) { - ObjectFile *obj_file = module->GetObjectFile(); + ObjectFile *obj_file = module_sp->GetObjectFile(); if (obj_file) return obj_file->GetAddressClass (GetFileAddress()); } @@ -1010,7 +1022,7 @@ Address::SetLoadAddress (lldb::addr_t load_addr, Target *target) { if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this)) return true; - m_section = NULL; + m_section_wp.reset(); m_offset = load_addr; return false; } diff --git a/lldb/source/Core/AddressRange.cpp b/lldb/source/Core/AddressRange.cpp index 700de90806c..20050221914 100644 --- a/lldb/source/Core/AddressRange.cpp +++ b/lldb/source/Core/AddressRange.cpp @@ -28,7 +28,7 @@ AddressRange::AddressRange (addr_t file_addr, addr_t byte_size, const SectionLis { } -AddressRange::AddressRange (const Section* section, addr_t offset, addr_t byte_size) : +AddressRange::AddressRange (const lldb::SectionSP §ion, addr_t offset, addr_t byte_size) : m_base_addr(section, offset), m_byte_size(byte_size) { @@ -177,9 +177,9 @@ AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style, Address: { if (show_module) { - Module *module = GetBaseAddress().GetModulePtr(); - if (module) - s->Printf("%s", module->GetFileSpec().GetFilename().AsCString()); + ModuleSP module_sp (GetBaseAddress().GetModule()); + if (module_sp) + s->Printf("%s", module_sp->GetFileSpec().GetFilename().AsCString()); } s->AddressRange(vmaddr, vmaddr + GetByteSize(), addr_size); return true; @@ -196,7 +196,7 @@ AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style, Address: void AddressRange::DumpDebug (Stream *s) const { - s->Printf("%p: AddressRange section = %p, offset = 0x%16.16llx, byte_size = 0x%16.16llx\n", this, m_base_addr.GetSection(), m_base_addr.GetOffset(), GetByteSize()); + s->Printf("%p: AddressRange section = %p, offset = 0x%16.16llx, byte_size = 0x%16.16llx\n", this, m_base_addr.GetSection().get(), m_base_addr.GetOffset(), GetByteSize()); } // //bool diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp index b88b5384deb..0b409451d99 100644 --- a/lldb/source/Core/DataExtractor.cpp +++ b/lldb/source/Core/DataExtractor.cpp @@ -1366,8 +1366,7 @@ DataExtractor::Dump (Stream *s, lldb_private::Address so_addr; if (!target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { - so_addr.SetOffset(addr); - so_addr.SetSection(NULL); + so_addr.SetRawAddress(addr); } size_t bytes_consumed = disassembler_sp->DecodeInstructions (so_addr, *this, start_offset, item_count, false); diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index ce4f708fef3..2be02f96ac0 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -386,10 +386,10 @@ Disassembler::PrintInstructions prev_sc = sc; - Module *module = addr.GetModulePtr(); - if (module) + ModuleSP module_sp (addr.GetModule()); + if (module_sp) { - uint32_t resolved_mask = module->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); + uint32_t resolved_mask = module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); if (resolved_mask) { if (num_mixed_context_lines) diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 707b651c194..eb8d35c2188 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -122,6 +122,7 @@ Module::Module(const FileSpec& file_spec, const lldb::ProcessSP &process_sp, lld m_uuid (), m_file (file_spec), m_platform_file(), + m_symfile_spec (), m_object_name (), m_object_offset (), m_objfile_sp (), @@ -158,7 +159,7 @@ Module::Module(const FileSpec& file_spec, const lldb::ProcessSP &process_sp, lld if (bytes_read == 512) { data_sp.reset (data_ap.release()); - m_objfile_sp = ObjectFile::FindPlugin(this, process_sp, header_addr, data_sp); + m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp); if (m_objfile_sp) { // Once we get the object file, update our module with the object file's @@ -170,13 +171,17 @@ Module::Module(const FileSpec& file_spec, const lldb::ProcessSP &process_sp, lld } } -Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) : +Module::Module(const FileSpec& file_spec, + const ArchSpec& arch, + const ConstString *object_name, + off_t object_offset) : m_mutex (Mutex::eMutexTypeRecursive), m_mod_time (file_spec.GetModificationTime()), m_arch (arch), m_uuid (), m_file (file_spec), m_platform_file(), + m_symfile_spec (), m_object_name (), m_object_offset (object_offset), m_objfile_sp (), @@ -320,10 +325,10 @@ Module::CalculateSymbolContext(SymbolContext* sc) sc->module_sp = shared_from_this(); } -Module * +ModuleSP Module::CalculateSymbolContextModule () { - return this; + return shared_from_this(); } void @@ -380,10 +385,10 @@ Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve sc.Clear(); // Get the section from the section/offset address. - const Section *section = so_addr.GetSection(); + SectionSP section_sp (so_addr.GetSection()); // Make sure the section matches this module before we try and match anything - if (section && section->GetModule() == this) + if (section_sp && section_sp->GetModule().get() == this) { // If the section offset based address resolved itself, then this // is the right module. @@ -667,7 +672,7 @@ Module::GetSymbolVendor (bool can_create) if (obj_file != NULL) { Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); - m_symfile_ap.reset(SymbolVendor::FindPlugin(this)); + m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this())); m_did_load_symbol_vendor = true; } } @@ -890,7 +895,11 @@ Module::GetObjectFile() Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); DataBufferSP file_data_sp; - m_objfile_sp = ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize(), file_data_sp); + m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(), + &m_file, + m_object_offset, + m_file.GetByteSize(), + file_data_sp); if (m_objfile_sp) { // Once we get the object file, update our module with the object file's diff --git a/lldb/source/Core/ModuleChild.cpp b/lldb/source/Core/ModuleChild.cpp index f38fb4f6c36..9637fc3aedd 100644 --- a/lldb/source/Core/ModuleChild.cpp +++ b/lldb/source/Core/ModuleChild.cpp @@ -11,13 +11,13 @@ using namespace lldb_private; -ModuleChild::ModuleChild (Module* module) : - m_module(module) +ModuleChild::ModuleChild (const lldb::ModuleSP &module_sp) : + m_module_wp (module_sp) { } ModuleChild::ModuleChild (const ModuleChild& rhs) : - m_module(rhs.m_module) + m_module_wp(rhs.m_module_wp) { } @@ -29,24 +29,18 @@ const ModuleChild& ModuleChild::operator= (const ModuleChild& rhs) { if (this != &rhs) - m_module = rhs.m_module; + m_module_wp = rhs.m_module_wp; return *this; } -Module * -ModuleChild::GetModule () -{ - return m_module; -} - -Module * +lldb::ModuleSP ModuleChild::GetModule () const { - return m_module; + return m_module_wp.lock(); } void -ModuleChild::SetModule (Module *module) +ModuleChild::SetModule (const lldb::ModuleSP &module_sp) { - m_module = module; + m_module_wp = module_sp; } diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index f1715758e59..2325bde0bc0 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -586,12 +586,12 @@ ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t res { // The address is already section offset so it has a module uint32_t resolved_flags = 0; - Module *module = so_addr.GetModulePtr(); - if (module) + ModuleSP module_sp (so_addr.GetModule()); + if (module_sp) { - resolved_flags = module->ResolveSymbolContextForAddress (so_addr, - resolve_scope, - sc); + resolved_flags = module_sp->ResolveSymbolContextForAddress (so_addr, + resolve_scope, + sc); } else { diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp index dd2556a49d3..f1f4dc11271 100644 --- a/lldb/source/Core/Section.cpp +++ b/lldb/source/Core/Section.cpp @@ -15,23 +15,19 @@ using namespace lldb; using namespace lldb_private; -Section::Section -( - Section *parent, - Module* module, - user_id_t sect_id, - const ConstString &name, - SectionType sect_type, - addr_t file_addr, - addr_t byte_size, - uint64_t file_offset, - uint64_t file_size, - uint32_t flags -) : - ModuleChild (module), +Section::Section (const ModuleSP &module_sp, + user_id_t sect_id, + const ConstString &name, + SectionType sect_type, + addr_t file_addr, + addr_t byte_size, + uint64_t file_offset, + uint64_t file_size, + uint32_t flags) : + ModuleChild (module_sp), UserID (sect_id), Flags (flags), - m_parent (parent), + m_parent_wp (), m_name (name), m_type (sect_type), m_file_addr (file_addr), @@ -40,73 +36,92 @@ Section::Section m_file_size (file_size), m_children (), m_fake (false), - m_linked_section(NULL), + m_linked_section_wp(), m_linked_offset (0) { -} - -Section::~Section() -{ -} - - -// Get a valid shared pointer to this section object -SectionSP -Section::GetSharedPointer() const +// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16llx, addr=[0x%16.16llx - 0x%16.16llx), file [0x%16.16llx - 0x%16.16llx), flags = 0x%8.8x, name = %s\n", +// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString()); +} + +Section::Section (const lldb::SectionSP &parent_section_sp, + const ModuleSP &module_sp, + user_id_t sect_id, + const ConstString &name, + SectionType sect_type, + addr_t file_addr, + addr_t byte_size, + uint64_t file_offset, + uint64_t file_size, + uint32_t flags) : + ModuleChild (module_sp), + UserID (sect_id), + Flags (flags), + m_parent_wp (), + m_name (name), + m_type (sect_type), + m_file_addr (file_addr), + m_byte_size (byte_size), + m_file_offset (file_offset), + m_file_size (file_size), + m_children (), + m_fake (false), + m_linked_section_wp(), + m_linked_offset (0) { - SectionSP this_sp; - if (m_parent) - this_sp = m_parent->GetChildren().GetSharedPointer (this, false); - else - { - ObjectFile *objfile = m_module->GetObjectFile(); - if (objfile) - { - SectionList *section_list = objfile->GetSectionList(); - if (section_list) - this_sp = section_list->GetSharedPointer (this, false); - } - } - return this_sp; +// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16llx, addr=[0x%16.16llx - 0x%16.16llx), file [0x%16.16llx - 0x%16.16llx), flags = 0x%8.8x, name = %s.%s\n", +// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, parent_section_sp->GetName().GetCString(), name.GetCString()); + if (parent_section_sp) + m_parent_wp = parent_section_sp; } - - -ConstString& -Section::GetName() +Section::~Section() { - if (m_linked_section) - return const_cast<Section *>(m_linked_section)->GetName(); - return m_name; +// printf ("Section::~Section(%p)\n", this); } const ConstString& Section::GetName() const { - if (m_linked_section) - return m_linked_section->GetName(); + SectionSP linked_section_sp (m_linked_section_wp.lock()); + if (linked_section_sp) + return linked_section_sp->GetName(); return m_name; } addr_t Section::GetFileAddress () const { - if (m_parent) + SectionSP parent_sp (GetParent ()); + if (parent_sp) { // This section has a parent which means m_file_addr is an offset into // the parent section, so the file address for this section is the file // address of the parent plus the offset - return m_parent->GetFileAddress() + m_file_addr; + return parent_sp->GetFileAddress() + m_file_addr; } // This section has no parent, so m_file_addr is the file base address return m_file_addr; } +lldb::addr_t +Section::GetOffset () const +{ + // This section has a parent which means m_file_addr is an offset. + SectionSP parent_sp (GetParent ()); + if (parent_sp) + return m_file_addr; + + // This section has no parent, so there is no offset to be had + return 0; +} + + addr_t Section::GetLinkedFileAddress () const { - if (m_linked_section) - return m_linked_section->GetFileAddress() + m_linked_offset; + SectionSP linked_section_sp (m_linked_section_wp.lock()); + if (linked_section_sp) + return linked_section_sp->GetFileAddress() + m_linked_offset; return LLDB_INVALID_ADDRESS; } @@ -115,22 +130,26 @@ addr_t Section::GetLoadBaseAddress (Target *target) const { addr_t load_base_addr = LLDB_INVALID_ADDRESS; - if (m_linked_section) + SectionSP linked_section_sp (m_linked_section_wp.lock()); + if (linked_section_sp) { - load_base_addr = m_linked_section->GetLoadBaseAddress(target); + load_base_addr = linked_section_sp->GetLoadBaseAddress(target); if (load_base_addr != LLDB_INVALID_ADDRESS) load_base_addr += m_linked_offset; } else - if (m_parent) - { - load_base_addr = m_parent->GetLoadBaseAddress (target); - if (load_base_addr != LLDB_INVALID_ADDRESS) - load_base_addr += GetOffset(); - } - else { - load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (this); + SectionSP parent_sp (GetParent ()); + if (parent_sp) + { + load_base_addr = parent_sp->GetLoadBaseAddress (target); + if (load_base_addr != LLDB_INVALID_ADDRESS) + load_base_addr += GetOffset(); + } + else + { + load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (this); + } } return load_base_addr; @@ -151,15 +170,16 @@ Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const return child_section->ResolveContainedAddress (offset - child_offset, so_addr); } } - if (m_linked_section) + SectionSP linked_section_sp (m_linked_section_wp.lock()); + if (linked_section_sp) { so_addr.SetOffset(m_linked_offset + offset); - so_addr.SetSection(m_linked_section); + so_addr.SetSection(linked_section_sp); } else { so_addr.SetOffset(offset); - so_addr.SetSection(this); + so_addr.SetSection(const_cast<Section *>(this)->shared_from_this()); } return true; } @@ -200,9 +220,9 @@ Section::Compare (const Section& a, const Section& b) if (&a == &b) return 0; - const Module* a_module = a.GetModule(); - const Module* b_module = b.GetModule(); - if (a_module == b_module) + const ModuleSP a_module_sp = a.GetModule(); + const ModuleSP b_module_sp = b.GetModule(); + if (a_module_sp == b_module_sp) { user_id_t a_sect_uid = a.GetID(); user_id_t b_sect_uid = b.GetID(); @@ -215,7 +235,7 @@ Section::Compare (const Section& a, const Section& b) else { // The modules are different, just compare the module pointers - if (a_module < b_module) + if (a_module_sp.get() < b_module_sp.get()) return -1; else return 1; // We already know the modules aren't equal @@ -232,11 +252,12 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const bool resolved = true; addr_t addr = LLDB_INVALID_ADDRESS; + SectionSP linked_section_sp (m_linked_section_wp.lock()); if (GetByteSize() == 0) s->Printf("%39s", ""); else { - if (target && m_linked_section == NULL) + if (target && linked_section_sp.get() == NULL) addr = GetLoadBaseAddress (target); if (addr == LLDB_INVALID_ADDRESS) @@ -256,13 +277,13 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const s->EOL(); - if (m_linked_section) + if (linked_section_sp) { addr = LLDB_INVALID_ADDRESS; resolved = true; if (target) { - addr = m_linked_section->GetLoadBaseAddress(target); + addr = linked_section_sp->GetLoadBaseAddress(target); if (addr != LLDB_INVALID_ADDRESS) addr += m_linked_offset; } @@ -271,7 +292,7 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const { if (target) resolved = false; - addr = m_linked_section->GetFileAddress() + m_linked_offset; + addr = linked_section_sp->GetFileAddress() + m_linked_offset; } int indent = 26 + s->GetIndentLevel(); @@ -281,7 +302,7 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const indent = 3 * (sizeof(uint32_t) * 2 + 2 + 1) + 1; s->Printf("%c%*.*s", resolved ? ' ' : '*', indent, indent, ""); - m_linked_section->DumpName(s); + linked_section_sp->DumpName(s); s->Printf(" + 0x%llx\n", m_linked_offset); } @@ -292,17 +313,22 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const void Section::DumpName (Stream *s) const { - if (m_parent == NULL) + SectionSP parent_sp (GetParent ()); + if (parent_sp) { - // The top most section prints the module basename - const char *module_basename = m_module->GetFileSpec().GetFilename().AsCString(); - if (module_basename && module_basename[0]) - s->Printf("%s.", module_basename); + parent_sp->DumpName (s); + s->PutChar('.'); } else { - m_parent->DumpName (s); - s->PutChar('.'); + // The top most section prints the module basename + ModuleSP module_sp (GetModule()); + if (module_sp) + { + const char *module_basename = module_sp->GetFileSpec().GetFilename().AsCString(); + if (module_basename && module_basename[0]) + s->Printf("%s.", module_basename); + } } m_name.Dump(s); } @@ -312,8 +338,9 @@ Section::IsDescendant (const Section *section) { if (this == section) return true; - if (m_parent) - return m_parent->IsDescendant (section); + SectionSP parent_sp (GetParent ()); + if (parent_sp) + return parent_sp->IsDescendant (section); return false; } @@ -336,11 +363,11 @@ Section::Slide (addr_t slide_amount, bool slide_children) } void -Section::SetLinkedLocation (const Section *linked_section, uint64_t linked_offset) +Section::SetLinkedLocation (const lldb::SectionSP &linked_section_sp, uint64_t linked_offset) { - if (linked_section) - m_module = linked_section->GetModule(); - m_linked_section = linked_section; + if (linked_section_sp) + m_module_wp = linked_section_sp->GetModule(); + m_linked_section_wp = linked_section_sp; m_linked_offset = linked_offset; } @@ -357,10 +384,11 @@ SectionList::~SectionList () } uint32_t -SectionList::AddSection (SectionSP& sect_sp) +SectionList::AddSection (const lldb::SectionSP& section_sp) { + assert (section_sp.get()); uint32_t section_index = m_sections.size(); - m_sections.push_back(sect_sp); + m_sections.push_back(section_sp); return section_index; } @@ -382,7 +410,7 @@ SectionList::FindSectionIndex (const Section* sect) } uint32_t -SectionList::AddUniqueSection (SectionSP& sect_sp) +SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp) { uint32_t sect_idx = FindSectionIndex (sect_sp.get()); if (sect_idx == UINT32_MAX) @@ -392,7 +420,7 @@ SectionList::AddUniqueSection (SectionSP& sect_sp) bool -SectionList::ReplaceSection (user_id_t sect_id, SectionSP& sect_sp, uint32_t depth) +SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth) { iterator sect_iter, end = m_sections.end(); for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter) @@ -441,19 +469,21 @@ SectionList::FindSectionByName (const ConstString §ion_dstr) const { SectionSP sect_sp; // Check if we have a valid section string - if (section_dstr) + if (section_dstr && !m_sections.empty()) { const_iterator sect_iter; const_iterator end = m_sections.end(); for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter) { - if ((*sect_iter)->GetName() == section_dstr) + Section *child_section = sect_iter->get(); + assert (child_section); + if (child_section->GetName() == section_dstr) { sect_sp = *sect_iter; } else { - sect_sp = (*sect_iter)->GetChildren().FindSectionByName(section_dstr); + sect_sp = child_section->GetChildren().FindSectionByName(section_dstr); } } } @@ -508,32 +538,6 @@ SectionList::FindSectionByType (SectionType sect_type, bool check_children, uint } SectionSP -SectionList::GetSharedPointer (const Section *section, bool check_children) const -{ - SectionSP sect_sp; - if (section) - { - const_iterator sect_iter; - const_iterator end = m_sections.end(); - for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter) - { - if (sect_iter->get() == section) - { - sect_sp = *sect_iter; - break; - } - else if (check_children) - { - sect_sp = (*sect_iter)->GetChildren().GetSharedPointer (section, true); - } - } - } - return sect_sp; -} - - - -SectionSP SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const { SectionSP sect_sp; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 15885eb691f..7c8cd7f62ed 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -817,11 +817,11 @@ ValueObject::GetPointeeData (DataExtractor& data, { case eAddressTypeFile: { - Module* module = GetModule(); - if (module) + ModuleSP module_sp (GetModule()); + if (module_sp) { Address so_addr; - module->ResolveFileAddress(addr, so_addr); + module_sp->ResolveFileAddress(addr, so_addr); ExecutionContext exe_ctx (GetExecutionContextRef()); Target* target = exe_ctx.GetTargetPtr(); if (target) @@ -873,7 +873,7 @@ ValueObject::GetData (DataExtractor& data) { UpdateValueIfNeeded(false); ExecutionContext exe_ctx (GetExecutionContextRef()); - Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule()); + Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get()); if (error.Fail()) return 0; data.SetAddressByteSize(m_data.GetAddressByteSize()); @@ -956,7 +956,7 @@ ValueObject::ReadPointedString (Stream& s, } if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS) { - Address cstr_so_addr (NULL, cstr_address); + Address cstr_so_addr (cstr_address); DataExtractor data; size_t bytes_read = 0; if (cstr_len > 0 && honor_array) @@ -3383,7 +3383,7 @@ ValueObject::CreateConstantValue (const ConstString &name) data.SetByteOrder (m_data.GetByteOrder()); data.SetAddressByteSize(m_data.GetAddressByteSize()); - m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get()); valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), ast, @@ -3543,7 +3543,7 @@ ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) if (ptr_value != LLDB_INVALID_ADDRESS) { - Address ptr_addr (NULL, ptr_value); + Address ptr_addr (ptr_value); ExecutionContext exe_ctx (GetExecutionContextRef()); valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), name, @@ -3562,7 +3562,7 @@ ValueObject::CastPointerType (const char *name, TypeSP &type_sp) if (ptr_value != LLDB_INVALID_ADDRESS) { - Address ptr_addr (NULL, ptr_value); + Address ptr_addr (ptr_value); ExecutionContext exe_ctx (GetExecutionContextRef()); valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), name, diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp index 91522ba4b72..0cb0d6e9eac 100644 --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -190,7 +190,7 @@ ValueObjectChild::UpdateValue () if (m_error.Success()) { ExecutionContext exe_ctx (GetExecutionContextRef().Lock()); - m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST (), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST (), m_data, 0, GetModule().get()); } } else diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp index b336a7fa274..2e9f06728f4 100644 --- a/lldb/source/Core/ValueObjectDynamicValue.cpp +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp @@ -118,7 +118,7 @@ ValueObjectCast::UpdateValue () SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } ExecutionContext exe_ctx (GetExecutionContextRef()); - m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); SetValueDidChange (m_parent->GetValueDidChange()); return true; } @@ -287,7 +287,7 @@ ValueObjectDynamicValue::UpdateValue () if (m_type_sp) SetValueDidChange(true); m_value = m_parent->GetValue(); - m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); return m_error.Success(); } @@ -336,7 +336,7 @@ ValueObjectDynamicValue::UpdateValue () { // The variable value is in the Scalar value inside the m_value. // We can point our m_data right to it. - m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); if (m_error.Success()) { if (ClangASTContext::IsAggregateType (GetClangType())) diff --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp index 970cd267fdd..960895fa66e 100644 --- a/lldb/source/Core/ValueObjectMemory.cpp +++ b/lldb/source/Core/ValueObjectMemory.cpp @@ -209,7 +209,7 @@ ValueObjectMemory::UpdateValue () case Value::eValueTypeScalar: // The variable value is in the Scalar value inside the m_value. // We can point our m_data right to it. - m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); break; case Value::eValueTypeFileAddress: @@ -251,7 +251,7 @@ ValueObjectMemory::UpdateValue () else value.SetContext(Value::eContextTypeClangType, m_clang_type.GetOpaqueQualType()); - m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); } break; } @@ -272,10 +272,10 @@ ValueObjectMemory::IsInScope () } -Module * +lldb::ModuleSP ValueObjectMemory::GetModule() { - return m_address.GetModulePtr(); + return m_address.GetModule(); } diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp index 653b3cb58e8..f5c5d0132da 100644 --- a/lldb/source/Core/ValueObjectVariable.cpp +++ b/lldb/source/Core/ValueObjectVariable.cpp @@ -180,7 +180,7 @@ ValueObjectVariable::UpdateValue () case Value::eValueTypeScalar: // The variable value is in the Scalar value inside the m_value. // We can point our m_data right to it. - m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); break; case Value::eValueTypeFileAddress: @@ -233,7 +233,7 @@ ValueObjectVariable::UpdateValue () // so it can extract read its value into m_data appropriately Value value(m_value); value.SetContext(Value::eContextTypeVariable, variable); - m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule().get()); } break; } @@ -272,7 +272,7 @@ ValueObjectVariable::IsInScope () } -Module * +lldb::ModuleSP ValueObjectVariable::GetModule() { if (m_variable_sp) @@ -280,12 +280,10 @@ ValueObjectVariable::GetModule() SymbolContextScope *sc_scope = m_variable_sp->GetSymbolContextScope(); if (sc_scope) { - SymbolContext sc; - sc_scope->CalculateSymbolContext (&sc); - return sc.module_sp.get(); + return sc_scope->CalculateSymbolContextModule(); } } - return NULL; + return lldb::ModuleSP(); } SymbolContextScope * |