labath created this revision.
labath added reviewers: clayborg, jasonmolenda, amccarth, lemo, 
stella.stamenova.

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.


https://reviews.llvm.org/D55422

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

Index: source/Symbol/CompactUnwindInfo.cpp
===================================================================
--- source/Symbol/CompactUnwindInfo.cpp
+++ source/Symbol/CompactUnwindInfo.cpp
@@ -204,7 +204,7 @@
         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 @@
     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 @@
       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 @@
           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 @@
       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 @@
           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);
           }
         }
       }
Index: source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
===================================================================
--- source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -104,7 +104,7 @@
 
   lldb_private::Address GetEntryPointAddress() override;
 
-  lldb_private::Address GetHeaderAddress() override;
+  lldb_private::Address GetBaseAddress() override;
 
   uint32_t GetNumThreadContexts() override;
 
Index: source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===================================================================
--- source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1674,7 +1674,7 @@
   } 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 @@
   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: source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
===================================================================
--- source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
+++ source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
@@ -89,7 +89,7 @@
 
   lldb_private::Address GetEntryPointAddress() override;
 
-  lldb_private::Address GetHeaderAddress() override;
+  lldb_private::Address GetBaseAddress() override;
 
   ObjectFile::Type CalculateType() override;
 
Index: source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
===================================================================
--- source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
+++ source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
@@ -184,7 +184,7 @@
   return Address();
 }
 
-lldb_private::Address ObjectFileJIT::GetHeaderAddress() { return Address(); }
+lldb_private::Address ObjectFileJIT::GetBaseAddress() { return Address(); }
 
 ObjectFile::Type ObjectFileJIT::CalculateType() { return eTypeJIT; }
 
Index: source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
===================================================================
--- source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -211,13 +211,13 @@
       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 @@
       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 @@
         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: source/Commands/CommandObjectTarget.cpp
===================================================================
--- source/Commands/CommandObjectTarget.cpp
+++ source/Commands/CommandObjectTarget.cpp
@@ -2969,8 +2969,8 @@
   { 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 @@
 
           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 @@
                     // 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: source/API/SBModule.cpp
===================================================================
--- source/API/SBModule.cpp
+++ source/API/SBModule.cpp
@@ -587,7 +587,7 @@
   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: include/lldb/Symbol/ObjectFile.h
===================================================================
--- include/lldb/Symbol/ObjectFile.h
+++ include/lldb/Symbol/ObjectFile.h
@@ -551,18 +551,16 @@
   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.
   //------------------------------------------------------------------
-  virtual lldb_private::Address GetHeaderAddress() {
+  virtual lldb_private::Address GetBaseAddress() {
     return Address(m_memory_addr);
   }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to