Implement ObjectFilePECOFF::SetLoadAddress().

llvm-svn: 203350
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index a475234..3414e98 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -24,6 +24,8 @@
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/UUID.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/SectionLoadList.h"
+#include "lldb/Target/Target.h"
 
 #define IMAGE_DOS_SIGNATURE             0x5A4D      // MZ
 #define IMAGE_NT_SIGNATURE              0x00004550  // PE00
@@ -173,6 +175,43 @@
     return false;
 }
 
+bool
+ObjectFilePECOFF::SetLoadAddress(Target &target, addr_t value, bool value_is_offset)
+{
+    bool changed = false;
+    ModuleSP module_sp = GetModule();
+    if (module_sp)
+    {
+        size_t num_loaded_sections = 0;
+        SectionList *section_list = GetSectionList ();
+        if (section_list)
+        {
+            if (!value_is_offset)
+            {
+                value -= m_image_base;
+            }
+
+            const size_t num_sections = section_list->GetSize();
+            size_t sect_idx = 0;
+                
+            for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
+            {
+                // Iterate through the object file sections to find all
+                // of the sections that have SHF_ALLOC in their flag bits.
+                SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+                if (section_sp && !section_sp->IsThreadSpecific())
+                {
+                    if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
+                        ++num_loaded_sections;
+                }
+            }
+            changed = num_loaded_sections > 0;
+            return num_loaded_sections > 0;
+        }
+    }
+    return changed;
+}
+
 
 ByteOrder
 ObjectFilePECOFF::GetByteOrder () const
@@ -351,6 +390,9 @@
                     m_coff_header_opt.data_dirs[i].vmaddr = m_data.GetU32(offset_ptr);
                     m_coff_header_opt.data_dirs[i].vmsize = m_data.GetU32(offset_ptr);
                 }
+
+                m_file_offset = m_coff_header_opt.image_base;
+                m_image_base = m_coff_header_opt.image_base;
             }
         }
     }
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
index e480983..8d0d3b7 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -73,6 +73,9 @@
     virtual bool
     ParseHeader ();
     
+    virtual bool
+    SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset);
+
     virtual lldb::ByteOrder
     GetByteOrder () const;
     
@@ -262,6 +265,7 @@
 	coff_header_t		m_coff_header;
 	coff_opt_header_t	m_coff_header_opt;
 	SectionHeaderColl	m_sect_headers;
+    lldb::addr_t		m_image_base;
 };
 
 #endif  // #ifndef liblldb_ObjectFilePECOFF_h_