Skip to content

Commit 9cfc80c

Browse files
committed
feat: objdump outputs section by offset
1 parent b9c3dd3 commit 9cfc80c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

include/fle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class FLEWriter {
157157

158158
private:
159159
std::string current_section;
160-
nlohmann::ordered_json result;
160+
json result;
161161
std::vector<std::string> current_lines;
162162
};
163163

src/base/objdump.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "fle.hpp"
2+
#include <algorithm>
23
#include <iomanip>
34
#include <iostream>
45
#include <sstream>
@@ -21,8 +22,19 @@ void FLE_objdump(const FLEObject& obj, FLEWriter& writer)
2122
}
2223
}
2324

24-
// 写入所有段的内容
25+
std::vector<std::tuple<std::string, size_t, FLESection>> sections;
2526
for (const auto& [name, section] : obj.sections) {
27+
auto shdr = std::find_if(obj.shdrs.begin(), obj.shdrs.end(), [name](const auto& shdr) {
28+
return shdr.name == name;
29+
});
30+
sections.push_back({ name, shdr->offset, section });
31+
}
32+
std::sort(sections.begin(), sections.end(), [](const auto& a, const auto& b) {
33+
return std::get<1>(a) < std::get<1>(b);
34+
});
35+
36+
// 写入所有段的内容
37+
for (const auto& [name, _, section] : sections) {
2638
writer.begin_section(name);
2739

2840
// 收集所有断点(符号和重定位的位置)

0 commit comments

Comments
 (0)