From e72d835c48454b457441b4a843d977638f9227cc Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 5 Jan 2017 14:14:22 -0500 Subject: [PATCH] bug fixes, etc. --- Makefile | 4 ++-- dumpobj.cpp | 53 ++++++------------------------------------- zrdz_disassembler.cpp | 22 ++++++++++++++++-- zrdz_disassembler.h | 2 +- 4 files changed, 30 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 96c4150..c0e88ed 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ LINK.o = $(LINK.cc) -CXXFLAGS = -std=c++11 -g +CXXFLAGS = -std=c++11 -g -Wall CCFLAGS = -g OBJS = dumpobj.o disassembler.o zrdz_disassembler.o @@ -12,7 +12,7 @@ ifeq ($(MSYSTEM),MINGW64) endif -dumpobj : $(OBJS) +wdcdumpobj : $(OBJS) disassembler.o : disassembler.cpp disassembler.h diff --git a/dumpobj.cpp b/dumpobj.cpp index 80636b1..5e2969b 100644 --- a/dumpobj.cpp +++ b/dumpobj.cpp @@ -186,9 +186,6 @@ std::vector read_symbols(const std::vector &symbol_data) { bool dump_obj(const char *name, int fd) { - static const char *kSections[] = { "PAGE0", "CODE", "KDATA", "DATA", "UDATA" }; - static const char *kTypes[] = { "S_UND", "S_ABS", "S_REL", "S_EXP", "S_REG", "S_FREG" }; - Mod_head h; ssize_t ok; @@ -275,9 +272,6 @@ bool dump_obj(const char *name, int fd) // todo -- move all this stuff to a separate function. uint8_t size = read_8(iter); - char buffer[32]; - - std::vector stack; // todo -- need to keep operation for precedence? @@ -348,25 +342,6 @@ bool dump_obj(const char *name, int fd) case REC_DEBUG: { - static const char *debugs[] = { - "D_C_FILE", - "D_C_LINE", - "D_C_SYM", - "D_C_STAG", - "D_C_ETAG", - "D_C_UTAG", - "D_C_MEMBER", - "D_C_EOS", - "D_C_FUNC", - "D_C_ENDFUNC", - "D_C_BLOCK", - "D_C_ENDBLOCK", - "D_LONGA_ON", - "D_LONGA_OFF", - "D_LONGI_ON", - "D_LONGI_OFF", - }; - d.flush(); uint16_t size = read_16(iter); @@ -404,17 +379,17 @@ bool dump_obj(const char *name, int fd) } case D_C_BLOCK: { uint16_t block = read_16(iter); - d.emit("",".block", std::to_string(line)); + d.emit("",".block", std::to_string(block)); break; } case D_C_ENDBLOCK: { - uint16_t line = read_16(iter); - d.emit("",".endblock", std::to_string(line)); + uint16_t block = read_16(iter); + d.emit("",".endblock", std::to_string(block)); break; } case D_C_FUNC: { uint16_t arg = read_16(iter); - d.emit("",".function", std::to_string(line)); + d.emit("",".function", std::to_string(arg)); break; } case D_C_ENDFUNC: { @@ -555,27 +530,13 @@ bool dump_obj(const char *name, int fd) } - d.back_matter(); + unsigned f = 0; + if (flags._S) f |= 0x01; + d.back_matter(f); if (iter != data.end() || op != REC_END) errx(EX_DATAERR, "%s records ended early", name); -#if 0 - if (flags._S) { - printf("; sections\n"); - for (auto &s : sections) { - printf("; %-20s %02x %02x %04x %04x\n", - s.name.c_str(), s.number, s.flags, s.size, s.org); - } - printf(";\n"); - - printf("; symbols\n"); - for (auto &s : symbols) { - printf("; %-20s %02x %02x %02x %08x\n", - s.name.c_str(), s.type, s.flags, s.section, s.offset); - } - } -#endif return true; } diff --git a/zrdz_disassembler.cpp b/zrdz_disassembler.cpp index 6c1fdeb..9eb6d37 100644 --- a/zrdz_disassembler.cpp +++ b/zrdz_disassembler.cpp @@ -123,7 +123,7 @@ void zrdz_disassembler::front_matter(const std::string &module) { } -void zrdz_disassembler::back_matter() { +void zrdz_disassembler::back_matter(unsigned flags) { flush(); _section = -1; @@ -148,6 +148,24 @@ void zrdz_disassembler::back_matter() { } + if (flags & 0x01) { + fputs("; sections\n", stdout); + for (const auto &e : _sections) { + if (!e.valid) continue; + printf("; %-20s %02x %02x %04x %04x\n", + e.name.c_str(), e.number, e.flags, e.size, e.org); + } + + fputs(";\n", stdout); + + fputs("; symbols\n", stdout); + for (const auto &s : _symbols) { + printf("; %-20s %02x %02x %02x %08x\n", + s.name.c_str(), s.type, s.flags, s.section, s.offset); + } + putchar('\n'); + } + emit("", "endmod"); putchar('\n'); @@ -243,7 +261,7 @@ void zrdz_disassembler::set_section(int section) { return; } auto &e = _sections[section]; - if (!e.valid) { + if (section >5 && !e.valid) { warnx("Invalid section %d", section); return; } diff --git a/zrdz_disassembler.h b/zrdz_disassembler.h index 4cd55bc..06f11bc 100644 --- a/zrdz_disassembler.h +++ b/zrdz_disassembler.h @@ -35,7 +35,7 @@ public: void set_section(int); void front_matter(const std::string &module_name); - void back_matter(); + void back_matter(unsigned flags); std::string location_name(unsigned section, uint32_t offset) const; std::string symbol_name(unsigned entry) const;