|
8 | 8 | //===----------------------------------------------------------------------===// |
9 | 9 |
|
10 | 10 | #include "ObjectFileXCOFF.h" |
11 | | - |
12 | | -#include <algorithm> |
13 | | -#include <cassert> |
14 | | -#include <cstring> |
15 | | -#include <unordered_map> |
16 | | - |
17 | 11 | #include "lldb/Core/Module.h" |
18 | 12 | #include "lldb/Core/ModuleSpec.h" |
19 | 13 | #include "lldb/Core/PluginManager.h" |
|
35 | 29 | #include "llvm/BinaryFormat/XCOFF.h" |
36 | 30 | #include "llvm/Object/XCOFFObjectFile.h" |
37 | 31 | #include "llvm/Support/MemoryBuffer.h" |
| 32 | +#include <algorithm> |
| 33 | +#include <cassert> |
| 34 | +#include <cstring> |
| 35 | +#include <unordered_map> |
38 | 36 |
|
39 | 37 | using namespace llvm; |
40 | 38 | using namespace lldb; |
@@ -172,77 +170,24 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, |
172 | 170 | } |
173 | 171 |
|
174 | 172 | bool ObjectFileXCOFF::ParseHeader() { |
| 173 | + |
| 174 | + bool retVal = false; |
175 | 175 | ModuleSP module_sp(GetModule()); |
176 | 176 | if (module_sp) { |
177 | 177 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
178 | | - lldb::offset_t offset = 0; |
179 | 178 |
|
180 | | - m_data.SetByteOrder(eByteOrderBig); |
181 | | - if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { |
182 | | - m_data.SetAddressByteSize(GetAddressByteSize()); |
183 | | - if (m_xcoff_header.AuxHeaderSize > 0) |
184 | | - ParseXCOFFOptionalHeader(m_data, &offset); |
| 179 | + const auto *fileHeaderPtr = m_binary->fileHeader64(); |
| 180 | + m_xcoff_header = *fileHeaderPtr; |
| 181 | + if (m_xcoff_header.Magic != 0) { |
| 182 | + if (m_xcoff_header.AuxHeaderSize > 0) { |
| 183 | + const auto *fileAuxHeader = m_binary->auxiliaryHeader64(); |
| 184 | + m_xcoff_aux_header = *fileAuxHeader; |
| 185 | + } |
| 186 | + retVal = true; |
185 | 187 | } |
186 | | - return true; |
187 | 188 | } |
188 | 189 |
|
189 | | - return false; |
190 | | -} |
191 | | - |
192 | | -bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, |
193 | | - lldb::offset_t *offset_ptr, |
194 | | - xcoff_header_t &xcoff_header) { |
195 | | - |
196 | | - // FIXME: data.ValidOffsetForDataOfSize |
197 | | - xcoff_header.Magic = data.GetU16(offset_ptr); |
198 | | - xcoff_header.NumberOfSections = data.GetU16(offset_ptr); |
199 | | - xcoff_header.TimeStamp = data.GetU32(offset_ptr); |
200 | | - xcoff_header.SymbolTableOffset = data.GetU64(offset_ptr); |
201 | | - xcoff_header.AuxHeaderSize = data.GetU16(offset_ptr); |
202 | | - xcoff_header.Flags = data.GetU16(offset_ptr); |
203 | | - xcoff_header.NumberOfSymTableEntries = data.GetU32(offset_ptr); |
204 | | - return true; |
205 | | -} |
206 | | - |
207 | | -bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( |
208 | | - lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { |
209 | | - lldb::offset_t init_offset = *offset_ptr; |
210 | | - |
211 | | - // FIXME: data.ValidOffsetForDataOfSize |
212 | | - m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); |
213 | | - m_xcoff_aux_header.Version = data.GetU16(offset_ptr); |
214 | | - m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); |
215 | | - m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); |
216 | | - m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); |
217 | | - m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); |
218 | | - m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); |
219 | | - m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); |
220 | | - m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); |
221 | | - m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); |
222 | | - m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); |
223 | | - m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); |
224 | | - m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); |
225 | | - m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); |
226 | | - m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); |
227 | | - m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); |
228 | | - m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); |
229 | | - m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); |
230 | | - m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); |
231 | | - m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); |
232 | | - m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); |
233 | | - m_xcoff_aux_header.TextSize = data.GetU64(offset_ptr); |
234 | | - m_xcoff_aux_header.InitDataSize = data.GetU64(offset_ptr); |
235 | | - m_xcoff_aux_header.BssDataSize = data.GetU64(offset_ptr); |
236 | | - m_xcoff_aux_header.EntryPointAddr = data.GetU64(offset_ptr); |
237 | | - m_xcoff_aux_header.MaxStackSize = data.GetU64(offset_ptr); |
238 | | - m_xcoff_aux_header.MaxDataSize = data.GetU64(offset_ptr); |
239 | | - m_xcoff_aux_header.SecNumOfTData = data.GetU16(offset_ptr); |
240 | | - m_xcoff_aux_header.SecNumOfTBSS = data.GetU16(offset_ptr); |
241 | | - m_xcoff_aux_header.XCOFF64Flag = data.GetU16(offset_ptr); |
242 | | - lldb::offset_t last_offset = *offset_ptr; |
243 | | - if ((last_offset - init_offset) < m_xcoff_header.AuxHeaderSize) |
244 | | - *offset_ptr += (m_xcoff_header.AuxHeaderSize - (last_offset - init_offset)); |
245 | | - return true; |
| 190 | + return retVal; |
246 | 191 | } |
247 | 192 |
|
248 | 193 | ByteOrder ObjectFileXCOFF::GetByteOrder() const { return eByteOrderBig; } |
|
0 commit comments