Rename ObjectFile::GetHeaderAddress to GetBaseAddress
authorPavel Labath <pavel@labath.sk>
Tue, 11 Dec 2018 15:21:15 +0000 (15:21 +0000)
committerPavel Labath <pavel@labath.sk>
Tue, 11 Dec 2018 15:21:15 +0000 (15:21 +0000)
Summary:
This function was named such because in the case of MachO files, the
mach header is located at this address. However all (most?) usages of
this function were not interested in that fact, but the fact that this
address is used as the base address for expressing various relative
addresses in the object file.

For other object file formats, this name is not appropriate (and it's
probably the reason why this function was not implemented in these
classes). In the ELF case the ELF header will usually end up at this
address, but this is a result of the linker optimizing the file layout
and not a requirement of the spec. For COFF files, I believe the is no
header located at this address either.

Reviewers: clayborg, jasonmolenda, amccarth, lemo, stella.stamenova

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D55422

llvm-svn: 348849

lldb/include/lldb/Symbol/ObjectFile.h
lldb/source/API/SBModule.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Symbol/CompactUnwindInfo.cpp

index 1c1e229..5e66ae4 100644 (file)
@@ -551,18 +551,16 @@ public:
   virtual lldb_private::Address GetEntryPointAddress() { return Address(); }
 
   //------------------------------------------------------------------
-  /// Returns the address that represents the header of this object file.
+  /// Returns base address of this object file.
   ///
-  /// The header address is defined as where the header for the object file is
-  /// that describes the content of the file. If the header doesn't appear in
-  /// a section that is defined in the object file, an address with no section
-  /// is returned that has the file offset set in the m_file_offset member of
-  /// the lldb_private::Address object.
-  ///
-  /// @return
-  ///     Returns the entry address for this module.
+  /// This also sometimes referred to as the "preferred load address" or the
+  /// "image base address". Addresses within object files are often expressed
+  /// relative to this base. If this address corresponds to a specific section
+  /// (usually the first byte of the first section) then the returned address
+  /// will have this section set. Otherwise, the address will just have the
+  /// offset member filled in, indicating that this represents a file address.
   //------------------------------------------------------------------
-  virtual lldb_private::Address GetHeaderAddress() {
+  virtual lldb_private::Address GetBaseAddress() {
     return Address(m_memory_addr);
   }
 
index 9c029c5..183eae1 100644 (file)
@@ -587,7 +587,7 @@ lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const {
   if (module_sp) {
     ObjectFile *objfile_ptr = module_sp->GetObjectFile();
     if (objfile_ptr)
-      sb_addr.ref() = objfile_ptr->GetHeaderAddress();
+      sb_addr.ref() = objfile_ptr->GetBaseAddress();
   }
   return sb_addr;
 }
index 4eddc0f..4a4d0d2 100644 (file)
@@ -2969,8 +2969,8 @@ static constexpr OptionDefinition g_target_modules_list_options[] = {
   { LLDB_OPT_SET_1, false, "address",        'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddressOrExpression, "Display the image at this address." },
   { LLDB_OPT_SET_1, false, "arch",           'A', OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeWidth,               "Display the architecture when listing images." },
   { LLDB_OPT_SET_1, false, "triple",         't', OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeWidth,               "Display the triple when listing images." },
-  { LLDB_OPT_SET_1, false, "header",         'h', OptionParser::eNoArgument,       nullptr, {}, 0, eArgTypeNone,                "Display the image header address as a load address if debugging, a file address otherwise." },
-  { LLDB_OPT_SET_1, false, "offset",         'o', OptionParser::eNoArgument,       nullptr, {}, 0, eArgTypeNone,                "Display the image header address offset from the header file address (the slide amount)." },
+  { LLDB_OPT_SET_1, false, "header",         'h', OptionParser::eNoArgument,       nullptr, {}, 0, eArgTypeNone,                "Display the image base address as a load address if debugging, a file address otherwise." },
+  { LLDB_OPT_SET_1, false, "offset",         'o', OptionParser::eNoArgument,       nullptr, {}, 0, eArgTypeNone,                "Display the image load address offset from the base file address (the slide amount)." },
   { LLDB_OPT_SET_1, false, "uuid",           'u', OptionParser::eNoArgument,       nullptr, {}, 0, eArgTypeNone,                "Display the UUID when listing images." },
   { LLDB_OPT_SET_1, false, "fullpath",       'f', OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeWidth,               "Display the fullpath to the image object file." },
   { LLDB_OPT_SET_1, false, "directory",      'd', OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeWidth,               "Display the directory with optional width for the image object file." },
@@ -3229,13 +3229,13 @@ protected:
 
           ObjectFile *objfile = module->GetObjectFile();
           if (objfile) {
-            Address header_addr(objfile->GetHeaderAddress());
-            if (header_addr.IsValid()) {
+            Address base_addr(objfile->GetBaseAddress());
+            if (base_addr.IsValid()) {
               if (target && !target->GetSectionLoadList().IsEmpty()) {
-                lldb::addr_t header_load_addr =
-                    header_addr.GetLoadAddress(target);
-                if (header_load_addr == LLDB_INVALID_ADDRESS) {
-                  header_addr.Dump(&strm, target,
+                lldb::addr_t load_addr =
+                    base_addr.GetLoadAddress(target);
+                if (load_addr == LLDB_INVALID_ADDRESS) {
+                  base_addr.Dump(&strm, target,
                                    Address::DumpStyleModuleWithFileAddress,
                                    Address::DumpStyleFileAddress);
                 } else {
@@ -3243,18 +3243,18 @@ protected:
                     // Show the offset of slide for the image
                     strm.Printf(
                         "0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width,
-                        header_load_addr - header_addr.GetFileAddress());
+                        load_addr - base_addr.GetFileAddress());
                   } else {
                     // Show the load address of the image
                     strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
-                                addr_nibble_width, header_load_addr);
+                                addr_nibble_width, load_addr);
                   }
                 }
                 break;
               }
               // The address was valid, but the image isn't loaded, output the
               // address in an appropriate format
-              header_addr.Dump(&strm, target, Address::DumpStyleFileAddress);
+              base_addr.Dump(&strm, target, Address::DumpStyleFileAddress);
               break;
             }
           }
index 862e489..551f038 100644 (file)
@@ -211,13 +211,13 @@ DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr(Process *process) {
       exe_objfile->GetStrata() != ObjectFile::eStrataKernel)
     return LLDB_INVALID_ADDRESS;
 
-  if (!exe_objfile->GetHeaderAddress().IsValid())
+  if (!exe_objfile->GetBaseAddress().IsValid())
     return LLDB_INVALID_ADDRESS;
 
   if (CheckForKernelImageAtAddress(
-          exe_objfile->GetHeaderAddress().GetFileAddress(), process) ==
+          exe_objfile->GetBaseAddress().GetFileAddress(), process) ==
       exe_module->GetUUID())
-    return exe_objfile->GetHeaderAddress().GetFileAddress();
+    return exe_objfile->GetBaseAddress().GetFileAddress();
 
   return LLDB_INVALID_ADDRESS;
 }
@@ -931,7 +931,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
       ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
       if (kernel_object_file) {
         addr_t file_address =
-            kernel_object_file->GetHeaderAddress().GetFileAddress();
+            kernel_object_file->GetBaseAddress().GetFileAddress();
         if (m_load_address != LLDB_INVALID_ADDRESS &&
             file_address != LLDB_INVALID_ADDRESS) {
           s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
@@ -1005,10 +1005,10 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
         ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile();
         if (kernel_object_file) {
           addr_t load_address =
-              kernel_object_file->GetHeaderAddress().GetLoadAddress(
+              kernel_object_file->GetBaseAddress().GetLoadAddress(
                   &m_process->GetTarget());
           addr_t file_address =
-              kernel_object_file->GetHeaderAddress().GetFileAddress();
+              kernel_object_file->GetBaseAddress().GetFileAddress();
           if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) {
             m_kernel.SetLoadAddress(load_address);
             if (load_address != file_address) {
index af04032..53eb820 100644 (file)
@@ -184,7 +184,7 @@ lldb_private::Address ObjectFileJIT::GetEntryPointAddress() {
   return Address();
 }
 
-lldb_private::Address ObjectFileJIT::GetHeaderAddress() { return Address(); }
+lldb_private::Address ObjectFileJIT::GetBaseAddress() { return Address(); }
 
 ObjectFile::Type ObjectFileJIT::CalculateType() { return eTypeJIT; }
 
index 6ff1ecb..ec01f1f 100644 (file)
@@ -89,7 +89,7 @@ public:
 
   lldb_private::Address GetEntryPointAddress() override;
 
-  lldb_private::Address GetHeaderAddress() override;
+  lldb_private::Address GetBaseAddress() override;
 
   ObjectFile::Type CalculateType() override;
 
index dafbb64..e6b9c52 100644 (file)
@@ -1674,7 +1674,7 @@ void ObjectFileMachO::ProcessSegmentCommand(const load_command &load_cmd_,
   } else if (unified_section_sp) {
     if (is_dsym && unified_section_sp->GetFileAddress() != load_cmd.vmaddr) {
       // Check to see if the module was read from memory?
-      if (module_sp->GetObjectFile()->GetHeaderAddress().IsValid()) {
+      if (module_sp->GetObjectFile()->GetBaseAddress().IsValid()) {
         // We have a module that is in memory and needs to have its file
         // address adjusted. We need to do this because when we load a file
         // from memory, its addresses will be slid already, yet the addresses
@@ -5339,7 +5339,7 @@ lldb_private::Address ObjectFileMachO::GetEntryPointAddress() {
   return m_entry_point_address;
 }
 
-lldb_private::Address ObjectFileMachO::GetHeaderAddress() {
+lldb_private::Address ObjectFileMachO::GetBaseAddress() {
   lldb_private::Address header_addr;
   SectionList *section_list = GetSectionList();
   if (section_list) {
index 50a930a..02546a5 100644 (file)
@@ -104,7 +104,7 @@ public:
 
   lldb_private::Address GetEntryPointAddress() override;
 
-  lldb_private::Address GetHeaderAddress() override;
+  lldb_private::Address GetBaseAddress() override;
 
   uint32_t GetNumThreadContexts() override;
 
index 7dda877..8710470 100644 (file)
@@ -204,7 +204,7 @@ bool CompactUnwindInfo::GetUnwindPlan(Target &target, Address addr,
         if (sl) {
           addr_t func_range_start_file_addr =
               function_info.valid_range_offset_start +
-              m_objfile.GetHeaderAddress().GetFileAddress();
+              m_objfile.GetBaseAddress().GetFileAddress();
           AddressRange func_range(func_range_start_file_addr,
                                   function_info.valid_range_offset_end -
                                       function_info.valid_range_offset_start,
@@ -513,7 +513,7 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
     return false;
 
   addr_t function_offset =
-      address.GetFileAddress() - m_objfile.GetHeaderAddress().GetFileAddress();
+      address.GetFileAddress() - m_objfile.GetBaseAddress().GetFileAddress();
 
   UnwindIndex key;
   key.function_offset = function_offset;
@@ -578,10 +578,10 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
       if (sl) {
         uint32_t lsda_offset = GetLSDAForFunctionOffset(
             lsda_array_start, lsda_array_count, function_offset);
-        addr_t objfile_header_file_address =
-            m_objfile.GetHeaderAddress().GetFileAddress();
+        addr_t objfile_base_address =
+            m_objfile.GetBaseAddress().GetFileAddress();
         unwind_info.lsda_address.ResolveAddressUsingFileSections(
-            objfile_header_file_address + lsda_offset, sl);
+            objfile_base_address + lsda_offset, sl);
       }
     }
     if (unwind_info.encoding & UNWIND_PERSONALITY_MASK) {
@@ -596,10 +596,10 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
           SectionList *sl = m_objfile.GetSectionList();
           if (sl) {
             uint32_t personality_offset = m_unwindinfo_data.GetU32(&offset);
-            addr_t objfile_header_file_address =
-                m_objfile.GetHeaderAddress().GetFileAddress();
+            addr_t objfile_base_address =
+                m_objfile.GetBaseAddress().GetFileAddress();
             unwind_info.personality_ptr_address.ResolveAddressUsingFileSections(
-                objfile_header_file_address + personality_offset, sl);
+                objfile_base_address + personality_offset, sl);
           }
         }
       }
@@ -662,10 +662,10 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
       if (sl) {
         uint32_t lsda_offset = GetLSDAForFunctionOffset(
             lsda_array_start, lsda_array_count, function_offset);
-        addr_t objfile_header_file_address =
-            m_objfile.GetHeaderAddress().GetFileAddress();
+        addr_t objfile_base_address =
+            m_objfile.GetBaseAddress().GetFileAddress();
         unwind_info.lsda_address.ResolveAddressUsingFileSections(
-            objfile_header_file_address + lsda_offset, sl);
+            objfile_base_address + lsda_offset, sl);
       }
     }
     if (unwind_info.encoding & UNWIND_PERSONALITY_MASK) {
@@ -680,10 +680,10 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
           SectionList *sl = m_objfile.GetSectionList();
           if (sl) {
             uint32_t personality_offset = m_unwindinfo_data.GetU32(&offset);
-            addr_t objfile_header_file_address =
-                m_objfile.GetHeaderAddress().GetFileAddress();
+            addr_t objfile_base_address =
+                m_objfile.GetBaseAddress().GetFileAddress();
             unwind_info.personality_ptr_address.ResolveAddressUsingFileSections(
-                objfile_header_file_address + personality_offset, sl);
+                objfile_base_address + personality_offset, sl);
           }
         }
       }