Author: jmolenda
Date: Thu Aug 15 22:20:42 2013
New Revision: 188532

URL: http://llvm.org/viewvc/llvm-project?rev=188532&view=rev
Log:
Add a new Section::SetFileAddress method to change a Section's file
address.

When loading a dSYM, and the file addresses of the dSYM Sections are
different than the executable binary Sections' file addresses, the
debug info won't be remapped to the actual load addresses correctly.
This only happens with binaries on the in-memory shared cache binaries
where their File addresses have been set to their actual load address
(outside an offset value) whereas the original executable and dSYM
have 0-based File addresses.

I think this patch will not be activated for other cases -- this is
the only case we know of where the dSYM and the executable's File
addresses differ -- but if this causes other problems we can restrict
it more carefully.

<rdar://problem/12335086> 


Modified:
    lldb/trunk/include/lldb/Core/Section.h
    lldb/trunk/source/Core/Section.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/include/lldb/Core/Section.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=188532&r1=188531&r2=188532&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Section.h (original)
+++ lldb/trunk/include/lldb/Core/Section.h Thu Aug 15 22:20:42 2013
@@ -193,6 +193,9 @@ public:
     lldb::addr_t
     GetFileAddress () const;
 
+    bool
+    SetFileAddress (lldb::addr_t file_addr);
+
     lldb::addr_t
     GetOffset () const;
 

Modified: lldb/trunk/source/Core/Section.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=188532&r1=188531&r2=188532&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Thu Aug 15 22:20:42 2013
@@ -98,6 +98,24 @@ Section::GetFileAddress () const
     return m_file_addr;
 }
 
+bool
+Section::SetFileAddress (lldb::addr_t file_addr)
+{
+    SectionSP parent_sp (GetParent ());
+    if (parent_sp)
+    {
+        if (m_file_addr >= file_addr)
+            return parent_sp->SetFileAddress (m_file_addr - file_addr);
+        return false;
+    }
+    else
+    {
+        // This section has no parent, so m_file_addr is the file base address
+        m_file_addr = file_addr;
+        return true;
+    }
+}
+
 lldb::addr_t
 Section::GetOffset () const
 {

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=188532&r1=188531&r2=188532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Aug 15 
22:20:42 2013
@@ -1035,11 +1035,11 @@ ObjectFileMachO::CreateSections (Section
                             // is null out the SectionList vector and if a 
process has been set up, dump a message
                             // to stdout.  The most common case here is core 
file debugging with a truncated file.
                             const char *lc_segment_name = load_cmd.cmd == 
LoadCommandSegment64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
-                            GetModule()->ReportError("is a corrupt mach-o 
file: load command %u %s has a fileoff (0x%" PRIx64 ") that extends beyond the 
end of the file (0x%" PRIx64 ")",
-                                                     i,
-                                                     lc_segment_name,
-                                                     load_cmd.fileoff,
-                                                     m_length);
+                            module_sp->ReportError("is a corrupt mach-o file: 
load command %u %s has a fileoff (0x%" PRIx64 ") that extends beyond the end of 
the file (0x%" PRIx64 ")",
+                                                   i,
+                                                   lc_segment_name,
+                                                   load_cmd.fileoff,
+                                                   m_length);
                             
                             load_cmd.fileoff = 0;
                             load_cmd.filesize = 0;
@@ -1053,11 +1053,11 @@ ObjectFileMachO::CreateSections (Section
                             // is null out the SectionList vector and if a 
process has been set up, dump a message
                             // to stdout.  The most common case here is core 
file debugging with a truncated file.
                             const char *lc_segment_name = load_cmd.cmd == 
LoadCommandSegment64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
-                            GetModule()->ReportError("is a corrupt mach-o 
file: load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends 
beyond the end of the file (0x%" PRIx64 "), the segment will be truncated",
-                                                     i,
-                                                     lc_segment_name,
-                                                     load_cmd.fileoff + 
load_cmd.filesize,
-                                                     m_length);
+                            module_sp->ReportError("is a corrupt mach-o file: 
load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends beyond 
the end of the file (0x%" PRIx64 "), the segment will be truncated",
+                                                   i,
+                                                   lc_segment_name,
+                                                   load_cmd.fileoff + 
load_cmd.filesize,
+                                                   m_length);
                             
                             // Tuncase the length
                             load_cmd.filesize = m_length - load_cmd.fileoff;
@@ -1095,6 +1095,20 @@ ObjectFileMachO::CreateSections (Section
                         }
                         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())
+                                {
+                                    // 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 in the new symbol 
file will still be unslid.
+                                    // Since everything is stored as section 
offset, this shouldn't
+                                    // cause any problems.
+                                    
unified_section_sp->SetFileAddress(load_cmd.vmaddr);
+                                }
+                            }
                             m_sections_ap->AddSection(unified_section_sp);
                         }
 


_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to