1 //===-- Address.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/Address.h"
14 #include "llvm/ADT/Triple.h"
16 // Other libraries and framework includes
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/Section.h"
20 #include "lldb/Symbol/Block.h"
21 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Symbol/Variable.h"
23 #include "lldb/Symbol/VariableList.h"
24 #include "lldb/Target/ExecutionContext.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Target/SectionLoadList.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Symbol/SymbolVendor.h"
31 using namespace lldb_private;
34 ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
36 if (exe_scope == nullptr)
39 TargetSP target_sp (exe_scope->CalculateTarget());
43 bool prefer_file_cache = false;
44 return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error);
50 GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &address, ByteOrder& byte_order, uint32_t& addr_size)
52 byte_order = eByteOrderInvalid;
54 if (exe_scope == nullptr)
57 TargetSP target_sp (exe_scope->CalculateTarget());
60 byte_order = target_sp->GetArchitecture().GetByteOrder();
61 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
64 if (byte_order == eByteOrderInvalid || addr_size == 0)
66 ModuleSP module_sp (address.GetModule());
69 byte_order = module_sp->GetArchitecture().GetByteOrder();
70 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
73 return byte_order != eByteOrderInvalid && addr_size != 0;
77 ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
80 if (exe_scope == nullptr || byte_size > sizeof(uint64_t))
87 success = ReadBytes (exe_scope, address, &buf, byte_size) == byte_size;
90 ByteOrder byte_order = eByteOrderInvalid;
91 uint32_t addr_size = 0;
92 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
94 DataExtractor data (&buf, sizeof(buf), byte_order, addr_size);
95 lldb::offset_t offset = 0;
96 uval64 = data.GetU64(&offset);
105 ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
107 if (exe_scope == nullptr)
110 bool success = false;
111 addr_t deref_addr = ReadUIntMax64 (exe_scope, address, pointer_size, success);
114 ExecutionContext exe_ctx;
115 exe_scope->CalculateExecutionContext(exe_ctx);
116 // If we have any sections that are loaded, try and resolve using the
118 Target *target = exe_ctx.GetTargetPtr();
119 if (target && !target->GetSectionLoadList().IsEmpty())
121 if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr))
126 // If we were not running, yet able to read an integer, we must
128 ModuleSP module_sp (address.GetModule());
131 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
135 // We couldn't make "deref_addr" into a section offset value, but we were
136 // able to read the address, so we return a section offset address with
137 // no section and "deref_addr" as the offset (address).
138 deref_so_addr.SetRawAddress(deref_addr);
145 DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
147 if (exe_scope == nullptr || byte_size == 0)
149 std::vector<uint8_t> buf(byte_size, 0);
151 if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size())
153 ByteOrder byte_order = eByteOrderInvalid;
154 uint32_t addr_size = 0;
155 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
157 DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
160 0, // Start offset in "data"
161 eFormatHex, // Print as characters
162 buf.size(), // Size of item
164 UINT32_MAX, // num per line
165 LLDB_INVALID_ADDRESS,// base address
166 0, // bitfield bit size
167 0); // bitfield bit offset
176 ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
178 if (exe_scope == nullptr)
180 const size_t k_buf_len = 256;
181 char buf[k_buf_len+1];
182 buf[k_buf_len] = '\0'; // NULL terminate
184 // Byte order and address size don't matter for C string dumping..
185 DataExtractor data (buf, sizeof(buf), endian::InlHostByteOrder(), 4);
186 size_t total_len = 0;
188 Address curr_address(address);
190 while ((bytes_read = ReadBytes (exe_scope, curr_address, buf, k_buf_len)) > 0)
192 size_t len = strlen(buf);
195 if (len > bytes_read)
199 0, // Start offset in "data"
200 eFormatChar, // Print as characters
201 1, // Size of item (1 byte for a char!)
202 len, // How many bytes to print?
203 UINT32_MAX, // num per line
204 LLDB_INVALID_ADDRESS,// base address
205 0, // bitfield bit size
207 0); // bitfield bit offset
209 total_len += bytes_read;
213 curr_address.SetOffset (curr_address.GetOffset() + bytes_read);
219 Address::Address (lldb::addr_t abs_addr) :
225 Address::Address (addr_t address, const SectionList *section_list) :
227 m_offset (LLDB_INVALID_ADDRESS)
229 ResolveAddressUsingFileSections(address, section_list);
233 Address::operator= (const Address& rhs)
237 m_section_wp = rhs.m_section_wp;
238 m_offset = rhs.m_offset.load();
244 Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list)
248 SectionSP section_sp (section_list->FindSectionContainingFileAddress(file_addr));
249 m_section_wp = section_sp;
252 assert( section_sp->ContainsFileAddress(file_addr) );
253 m_offset = file_addr - section_sp->GetFileAddress();
254 return true; // Successfully transformed addr into a section offset address
257 m_offset = file_addr;
258 return false; // Failed to resolve this address to a section offset value
262 Address::GetModule () const
264 lldb::ModuleSP module_sp;
265 SectionSP section_sp (GetSection());
267 module_sp = section_sp->GetModule();
272 Address::GetFileAddress () const
274 SectionSP section_sp (GetSection());
277 addr_t sect_file_addr = section_sp->GetFileAddress();
278 if (sect_file_addr == LLDB_INVALID_ADDRESS)
280 // Section isn't resolved, we can't return a valid file address
281 return LLDB_INVALID_ADDRESS;
283 // We have a valid file range, so we can return the file based
284 // address by adding the file base address to our offset
285 return sect_file_addr + m_offset;
287 else if (SectionWasDeletedPrivate())
289 // Used to have a valid section but it got deleted so the
290 // offset doesn't mean anything without the section
291 return LLDB_INVALID_ADDRESS;
293 // No section, we just return the offset since it is the value in this case
298 Address::GetLoadAddress (Target *target) const
300 SectionSP section_sp (GetSection());
305 addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target);
307 if (sect_load_addr != LLDB_INVALID_ADDRESS)
309 // We have a valid file range, so we can return the file based
310 // address by adding the file base address to our offset
311 return sect_load_addr + m_offset;
315 else if (SectionWasDeletedPrivate())
317 // Used to have a valid section but it got deleted so the
318 // offset doesn't mean anything without the section
319 return LLDB_INVALID_ADDRESS;
323 // We don't have a section so the offset is the load address
326 // The section isn't resolved or an invalid target was passed in
327 // so we can't return a valid load address.
328 return LLDB_INVALID_ADDRESS;
332 Address::GetCallableLoadAddress (Target *target, bool is_indirect) const
334 addr_t code_addr = LLDB_INVALID_ADDRESS;
336 if (is_indirect && target)
338 ProcessSP processSP = target->GetProcessSP();
342 code_addr = processSP->ResolveIndirectFunction(this, error);
343 if (!error.Success())
344 code_addr = LLDB_INVALID_ADDRESS;
349 code_addr = GetLoadAddress (target);
352 if (code_addr == LLDB_INVALID_ADDRESS)
356 return target->GetCallableLoadAddress (code_addr, GetAddressClass());
361 Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target)
363 if (SetLoadAddress (load_addr, target))
366 m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
373 Address::GetOpcodeLoadAddress (Target *target, AddressClass addr_class) const
375 addr_t code_addr = GetLoadAddress (target);
376 if (code_addr != LLDB_INVALID_ADDRESS)
378 if (addr_class == eAddressClassInvalid)
379 addr_class = GetAddressClass();
380 code_addr = target->GetOpcodeLoadAddress (code_addr, addr_class);
386 Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target, AddressClass addr_class)
388 if (SetLoadAddress (load_addr, target))
392 if (addr_class == eAddressClassInvalid)
393 addr_class = GetAddressClass();
394 m_offset = target->GetOpcodeLoadAddress (m_offset, addr_class);
402 Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
404 // If the section was nullptr, only load address is going to work unless we are
405 // trying to deref a pointer
406 SectionSP section_sp (GetSection());
407 if (!section_sp && style != DumpStyleResolvedPointerDescription)
408 style = DumpStyleLoadAddress;
410 ExecutionContext exe_ctx (exe_scope);
411 Target *target = exe_ctx.GetTargetPtr();
412 // If addr_byte_size is UINT32_MAX, then determine the correct address
413 // byte size for the process or default to the size of addr_t
414 if (addr_size == UINT32_MAX)
417 addr_size = target->GetArchitecture().GetAddressByteSize ();
419 addr_size = sizeof(addr_t);
425 case DumpStyleInvalid:
428 case DumpStyleSectionNameOffset:
431 section_sp->DumpName(s);
432 s->Printf (" + %" PRIu64, m_offset.load());
436 s->Address(m_offset, addr_size);
440 case DumpStyleSectionPointerOffset:
441 s->Printf("(Section *)%p + ", static_cast<void*>(section_sp.get()));
442 s->Address(m_offset, addr_size);
445 case DumpStyleModuleWithFileAddress:
448 ModuleSP module_sp = section_sp->GetModule();
450 s->Printf("%s[", module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"));
452 s->Printf("%s[","<Unknown>");
455 case DumpStyleFileAddress:
457 addr_t file_addr = GetFileAddress();
458 if (file_addr == LLDB_INVALID_ADDRESS)
460 if (fallback_style != DumpStyleInvalid)
461 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
464 s->Address (file_addr, addr_size);
465 if (style == DumpStyleModuleWithFileAddress && section_sp)
470 case DumpStyleLoadAddress:
472 addr_t load_addr = GetLoadAddress (target);
476 * Display address in compressed form for MIPS16 or microMIPS
477 * if the address belongs to eAddressClassCodeAlternateISA.
481 const llvm::Triple::ArchType llvm_arch = target->GetArchitecture().GetMachine();
482 if (llvm_arch == llvm::Triple::mips || llvm_arch == llvm::Triple::mipsel
483 || llvm_arch == llvm::Triple::mips64 || llvm_arch == llvm::Triple::mips64el)
484 load_addr = GetCallableLoadAddress (target);
487 if (load_addr == LLDB_INVALID_ADDRESS)
489 if (fallback_style != DumpStyleInvalid)
490 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
493 s->Address (load_addr, addr_size);
497 case DumpStyleResolvedDescription:
498 case DumpStyleResolvedDescriptionNoModule:
499 case DumpStyleResolvedDescriptionNoFunctionArguments:
500 case DumpStyleNoFunctionName:
501 if (IsSectionOffset())
503 uint32_t pointer_size = 4;
504 ModuleSP module_sp (GetModule());
506 pointer_size = target->GetArchitecture().GetAddressByteSize();
508 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
510 bool showed_info = false;
513 SectionType sect_type = section_sp->GetType();
516 case eSectionTypeData:
519 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
522 Symtab *symtab = sym_vendor->GetSymtab();
525 const addr_t file_Addr = GetFileAddress();
526 Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
529 const char *symbol_name = symbol->GetName().AsCString();
532 s->PutCString(symbol_name);
533 addr_t delta = file_Addr - symbol->GetAddressRef().GetFileAddress();
535 s->Printf(" + %" PRIu64, delta);
544 case eSectionTypeDataCString:
545 // Read the C string from memory and display it
547 ReadCStringFromMemory (exe_scope, *this, s);
550 case eSectionTypeDataCStringPointers:
551 if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
554 s->PutCString("(char *)");
555 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
559 ReadCStringFromMemory(exe_scope, so_addr, s);
563 case eSectionTypeDataObjCMessageRefs:
564 if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
566 if (target && so_addr.IsSectionOffset())
568 SymbolContext func_sc;
569 target->GetImages().ResolveSymbolContextForAddress(so_addr,
570 eSymbolContextEverything,
572 if (func_sc.function != nullptr || func_sc.symbol != nullptr)
576 s->PutCString ("(objc_msgref *) -> { (func*)");
577 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
579 s->PutCString ("{ ");
581 Address cstr_addr(*this);
582 cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
583 func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false, true, true);
584 if (ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr))
587 s->PutCString("), (char *)");
588 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
593 ReadCStringFromMemory (exe_scope, so_addr, s);
596 s->PutCString(") }");
605 case eSectionTypeDataObjCCFStrings:
607 Address cfstring_data_addr(*this);
608 cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
609 if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
612 s->PutCString("(CFString *) ");
613 cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
614 s->PutCString(" -> @");
618 if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
624 case eSectionTypeData4:
625 // Read the 4 byte data and display it
627 s->PutCString("(uint32_t) ");
628 DumpUInt (exe_scope, *this, 4, s);
631 case eSectionTypeData8:
632 // Read the 8 byte data and display it
634 s->PutCString("(uint64_t) ");
635 DumpUInt (exe_scope, *this, 8, s);
638 case eSectionTypeData16:
639 // Read the 16 byte data and display it
641 s->PutCString("(uint128_t) ");
642 DumpUInt (exe_scope, *this, 16, s);
645 case eSectionTypeDataPointers:
646 // Read the pointer data and display it
647 if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
649 s->PutCString ("(void *)");
650 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
653 if (so_addr.IsSectionOffset())
655 SymbolContext pointer_sc;
658 target->GetImages().ResolveSymbolContextForAddress(so_addr,
659 eSymbolContextEverything,
661 if (pointer_sc.function != nullptr || pointer_sc.symbol != nullptr)
664 pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false, true, true);
681 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
682 if (sc.function || sc.symbol)
684 bool show_stop_context = true;
685 const bool show_module = (style == DumpStyleResolvedDescription);
686 const bool show_fullpaths = false;
687 const bool show_inlined_frames = true;
688 const bool show_function_arguments = (style != DumpStyleResolvedDescriptionNoFunctionArguments);
689 const bool show_function_name = (style != DumpStyleNoFunctionName);
690 if (sc.function == nullptr && sc.symbol != nullptr)
692 // If we have just a symbol make sure it is in the right section
693 if (sc.symbol->ValueIsAddress())
695 if (sc.symbol->GetAddressRef().GetSection() != GetSection())
697 // don't show the module if the symbol is a trampoline symbol
698 show_stop_context = false;
702 if (show_stop_context)
704 // We have a function or a symbol from the same
705 // sections as this address.
706 sc.DumpStopContext (s,
712 show_function_arguments,
717 // We found a symbol but it was in a different
718 // section so it isn't the symbol we should be
719 // showing, just show the section name + offset
720 Dump (s, exe_scope, DumpStyleSectionNameOffset);
728 if (fallback_style != DumpStyleInvalid)
729 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
734 case DumpStyleDetailedSymbolContext:
735 if (IsSectionOffset())
737 ModuleSP module_sp (GetModule());
741 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything | eSymbolContextVariable, sc);
744 // If we have just a symbol make sure it is in the same section
745 // as our address. If it isn't, then we might have just found
746 // the last symbol that came before the address that we are
747 // looking up that has nothing to do with our address lookup.
748 if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddressRef().GetSection() != GetSection())
751 sc.GetDescription(s, eDescriptionLevelBrief, target);
755 bool can_create = true;
756 bool get_parent_variables = true;
757 bool stop_if_block_is_inlined_function = false;
758 VariableList variable_list;
759 sc.block->AppendVariables (can_create,
760 get_parent_variables,
761 stop_if_block_is_inlined_function,
762 [](Variable*) { return true; },
765 const size_t num_variables = variable_list.GetSize();
766 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
768 Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
769 if (var && var->LocationIsValidForAddress (*this))
772 s->Printf (" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"",
774 var->GetName().GetCString());
775 Type *type = var->GetType();
777 s->Printf(", type = \"%s\"", type->GetName().GetCString());
779 s->PutCString(", type = <unknown>");
780 s->PutCString(", location = ");
781 var->DumpLocationForAddress(s, *this);
782 s->PutCString(", decl = ");
783 var->GetDeclaration().DumpStopContext(s, false);
792 if (fallback_style != DumpStyleInvalid)
793 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
798 case DumpStyleResolvedPointerDescription:
800 Process *process = exe_ctx.GetProcessPtr();
803 addr_t load_addr = GetLoadAddress (target);
804 if (load_addr != LLDB_INVALID_ADDRESS)
807 addr_t dereferenced_load_addr = process->ReadPointerFromMemory(load_addr, memory_error);
808 if (dereferenced_load_addr != LLDB_INVALID_ADDRESS)
810 Address dereferenced_addr;
811 if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr, target))
814 if (dereferenced_addr.Dump (&strm, exe_scope, DumpStyleResolvedDescription, DumpStyleInvalid, addr_size))
816 s->Address (dereferenced_load_addr, addr_size, " -> ", " ");
817 s->Write(strm.GetData(), strm.GetSize());
824 if (fallback_style != DumpStyleInvalid)
825 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
835 Address::SectionWasDeleted() const
839 return SectionWasDeletedPrivate();
843 Address::SectionWasDeletedPrivate() const
845 lldb::SectionWP empty_section_wp;
847 // If either call to "std::weak_ptr::owner_before(...) value returns true, this
848 // indicates that m_section_wp once contained (possibly still does) a reference
849 // to a valid shared pointer. This helps us know if we had a valid reference to
850 // a section which is now invalid because the module it was in was unloaded/deleted,
851 // or if the address doesn't have a valid reference to a section.
852 return empty_section_wp.owner_before(m_section_wp) || m_section_wp.owner_before(empty_section_wp);
856 Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
859 // Absolute addresses don't have enough information to reconstruct even their target.
861 SectionSP section_sp (GetSection());
864 ModuleSP module_sp (section_sp->GetModule());
867 sc->module_sp = module_sp;
869 return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
876 Address::CalculateSymbolContextModule () const
878 SectionSP section_sp (GetSection());
880 return section_sp->GetModule();
885 Address::CalculateSymbolContextCompileUnit () const
887 SectionSP section_sp (GetSection());
891 sc.module_sp = section_sp->GetModule();
894 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc);
902 Address::CalculateSymbolContextFunction () const
904 SectionSP section_sp (GetSection());
908 sc.module_sp = section_sp->GetModule();
911 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc);
919 Address::CalculateSymbolContextBlock () const
921 SectionSP section_sp (GetSection());
925 sc.module_sp = section_sp->GetModule();
928 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc);
936 Address::CalculateSymbolContextSymbol () const
938 SectionSP section_sp (GetSection());
942 sc.module_sp = section_sp->GetModule();
945 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
953 Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
955 SectionSP section_sp (GetSection());
959 sc.module_sp = section_sp->GetModule();
962 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
963 if (sc.line_entry.IsValid())
965 line_entry = sc.line_entry;
975 Address::CompareFileAddress (const Address& a, const Address& b)
977 addr_t a_file_addr = a.GetFileAddress();
978 addr_t b_file_addr = b.GetFileAddress();
979 if (a_file_addr < b_file_addr)
981 if (a_file_addr > b_file_addr)
987 Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
989 assert(target != nullptr);
990 addr_t a_load_addr = a.GetLoadAddress (target);
991 addr_t b_load_addr = b.GetLoadAddress (target);
992 if (a_load_addr < b_load_addr)
994 if (a_load_addr > b_load_addr)
1000 Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
1002 ModuleSP a_module_sp (a.GetModule());
1003 ModuleSP b_module_sp (b.GetModule());
1004 Module *a_module = a_module_sp.get();
1005 Module *b_module = b_module_sp.get();
1006 if (a_module < b_module)
1008 if (a_module > b_module)
1010 // Modules are the same, just compare the file address since they should
1012 addr_t a_file_addr = a.GetFileAddress();
1013 addr_t b_file_addr = b.GetFileAddress();
1014 if (a_file_addr < b_file_addr)
1016 if (a_file_addr > b_file_addr)
1022 Address::MemorySize () const
1024 // Noting special for the memory size of a single Address object,
1025 // it is just the size of itself.
1026 return sizeof(Address);
1029 //----------------------------------------------------------------------
1030 // NOTE: Be careful using this operator. It can correctly compare two
1031 // addresses from the same Module correctly. It can't compare two
1032 // addresses from different modules in any meaningful way, but it will
1033 // compare the module pointers.
1035 // To sum things up:
1036 // - works great for addresses within the same module
1037 // - it works for addresses across multiple modules, but don't expect the
1038 // address results to make much sense
1040 // This basically lets Address objects be used in ordered collection
1042 //----------------------------------------------------------------------
1045 lldb_private::operator< (const Address& lhs, const Address& rhs)
1047 ModuleSP lhs_module_sp (lhs.GetModule());
1048 ModuleSP rhs_module_sp (rhs.GetModule());
1049 Module *lhs_module = lhs_module_sp.get();
1050 Module *rhs_module = rhs_module_sp.get();
1051 if (lhs_module == rhs_module)
1053 // Addresses are in the same module, just compare the file addresses
1054 return lhs.GetFileAddress() < rhs.GetFileAddress();
1058 // The addresses are from different modules, just use the module
1059 // pointer value to get consistent ordering
1060 return lhs_module < rhs_module;
1065 lldb_private::operator> (const Address& lhs, const Address& rhs)
1067 ModuleSP lhs_module_sp (lhs.GetModule());
1068 ModuleSP rhs_module_sp (rhs.GetModule());
1069 Module *lhs_module = lhs_module_sp.get();
1070 Module *rhs_module = rhs_module_sp.get();
1071 if (lhs_module == rhs_module)
1073 // Addresses are in the same module, just compare the file addresses
1074 return lhs.GetFileAddress() > rhs.GetFileAddress();
1078 // The addresses are from different modules, just use the module
1079 // pointer value to get consistent ordering
1080 return lhs_module > rhs_module;
1084 // The operator == checks for exact equality only (same section, same offset)
1086 lldb_private::operator== (const Address& a, const Address& rhs)
1088 return a.GetOffset() == rhs.GetOffset() &&
1089 a.GetSection() == rhs.GetSection();
1092 // The operator != checks for exact inequality only (differing section, or
1093 // different offset)
1095 lldb_private::operator!= (const Address& a, const Address& rhs)
1097 return a.GetOffset() != rhs.GetOffset() ||
1098 a.GetSection() != rhs.GetSection();
1102 Address::GetAddressClass () const
1104 ModuleSP module_sp (GetModule());
1107 ObjectFile *obj_file = module_sp->GetObjectFile();
1110 // Give the symbol vendor a chance to add to the unified section list.
1111 module_sp->GetSymbolVendor();
1112 return obj_file->GetAddressClass (GetFileAddress());
1115 return eAddressClassUnknown;
1119 Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
1121 if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
1123 m_section_wp.reset();
1124 m_offset = load_addr;