[llvm] [llvm-objdump] print out xcoff file header and load section header for xcoff object file with option private-headers (PR #96350)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 00:44:09 PDT 2024
================
@@ -30,10 +32,131 @@ using namespace llvm::support;
namespace {
class XCOFFDumper : public objdump::Dumper {
+ const XCOFFObjectFile &Obj;
+ unsigned Width;
+
public:
- XCOFFDumper(const object::XCOFFObjectFile &O) : Dumper(O) {}
- void printPrivateHeaders() override {}
+ XCOFFDumper(const object::XCOFFObjectFile &O) : Dumper(O), Obj(O) {}
+
+private:
+ void printPrivateHeaders() override;
+ void printFileHeader();
+ void printAuxiliaryHeader() {};
+ void printLoaderSectionHeader();
+ FormattedString formatName(StringRef Name);
+ void printHex(StringRef Name, uint64_t Value);
+ void printNumber(StringRef Name, uint64_t Value);
+ void printStrHex(StringRef Name, StringRef Str, uint64_t Value);
+ void setWidth(unsigned W) { Width = W; };
};
+
+void XCOFFDumper::printPrivateHeaders() {
+ printFileHeader();
+ printAuxiliaryHeader();
+ printLoaderSectionHeader();
+}
+
+FormattedString XCOFFDumper::formatName(StringRef Name) {
+ return FormattedString(Name, Width, FormattedString::JustifyLeft);
+}
+
+void XCOFFDumper::printHex(StringRef Name, uint64_t Value) {
+ outs() << formatName(Name) << format_hex(Value, 0) << "\n";
+}
+
+void XCOFFDumper::printNumber(StringRef Name, uint64_t Value) {
+ outs() << formatName(Name) << format_decimal(Value, 0) << "\n";
+}
+
+void XCOFFDumper::printStrHex(StringRef Name, StringRef Str, uint64_t Value) {
+ outs() << formatName(Name) << Str << " (" << format_decimal(Value, 0) << ")"
+ << "\n";
+}
+
+void XCOFFDumper::printFileHeader() {
+ setWidth(20);
+ outs() << "\n---File Header:\n";
+ printHex("Magic:", Obj.getMagic());
+ printNumber("NumberOfSections:", Obj.getNumberOfSections());
+
+ int32_t TimeStamp = Obj.getTimeStamp();
+ // Negative timestamp values are reserved for future use.
+ if (TimeStamp > 0) {
+ // This handling of the time stamp assumes that the host system's time_t is
----------------
jh7370 wrote:
This comment hasn't been reflowed properly. Same for various other comments. clang-format won't attempt to reflow a comment that has been prematurely wrapped by hand. Instead, I suggest putting your comments all on one line and then allowing clang-format to reflow everything correctly.
https://github.com/llvm/llvm-project/pull/96350
More information about the llvm-commits
mailing list