Skip to content

Commit c4cf612

Browse files
Added parsing functions
1 parent b5c0110 commit c4cf612

File tree

2 files changed

+17
-80
lines changed

2 files changed

+17
-80
lines changed

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "ObjectFileXCOFF.h"
11-
12-
#include <algorithm>
13-
#include <cassert>
14-
#include <cstring>
15-
#include <unordered_map>
16-
1711
#include "lldb/Core/Module.h"
1812
#include "lldb/Core/ModuleSpec.h"
1913
#include "lldb/Core/PluginManager.h"
@@ -35,6 +29,10 @@
3529
#include "llvm/BinaryFormat/XCOFF.h"
3630
#include "llvm/Object/XCOFFObjectFile.h"
3731
#include "llvm/Support/MemoryBuffer.h"
32+
#include <algorithm>
33+
#include <cassert>
34+
#include <cstring>
35+
#include <unordered_map>
3836

3937
using namespace llvm;
4038
using namespace lldb;
@@ -172,77 +170,24 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp,
172170
}
173171

174172
bool ObjectFileXCOFF::ParseHeader() {
173+
174+
bool retVal = false;
175175
ModuleSP module_sp(GetModule());
176176
if (module_sp) {
177177
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
178-
lldb::offset_t offset = 0;
179178

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;
185187
}
186-
return true;
187188
}
188189

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;
246191
}
247192

248193
ByteOrder ObjectFileXCOFF::GetByteOrder() const { return eByteOrderBig; }

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
#ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_XCOFF_OBJECTFILEXCOFF_H
1111
#define LLDB_SOURCE_PLUGINS_OBJECTFILE_XCOFF_OBJECTFILEXCOFF_H
1212

13-
#include <cstdint>
14-
15-
#include <vector>
16-
1713
#include "lldb/Symbol/ObjectFile.h"
1814
#include "lldb/Utility/ArchSpec.h"
1915
#include "lldb/Utility/FileSpec.h"
2016
#include "lldb/Utility/UUID.h"
2117
#include "lldb/lldb-private.h"
2218
#include "llvm/Object/XCOFFObjectFile.h"
19+
#include <cstdint>
20+
#include <vector>
2321

2422
/// \class ObjectFileXCOFF
2523
/// Generic XCOFF object file reader.
@@ -104,12 +102,6 @@ class ObjectFileXCOFF : public lldb_private::ObjectFile {
104102

105103
typedef struct llvm::object::XCOFFAuxiliaryHeader64 xcoff_aux_header_t;
106104

107-
static bool ParseXCOFFHeader(lldb_private::DataExtractor &data,
108-
lldb::offset_t *offset_ptr,
109-
xcoff_header_t &xcoff_header);
110-
bool ParseXCOFFOptionalHeader(lldb_private::DataExtractor &data,
111-
lldb::offset_t *offset_ptr);
112-
113105
static lldb::WritableDataBufferSP
114106
MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size,
115107
uint64_t Offset);

0 commit comments

Comments
 (0)