-n flag to inhibit symbol lookup in expressions.

This commit is contained in:
Kelvin Sherlock 2017-01-08 20:16:32 -05:00
parent 966a879419
commit eb993acd2a
3 changed files with 29 additions and 2 deletions

View File

@ -30,6 +30,7 @@
struct { struct {
bool _S = false; bool _S = false;
bool _g = false; bool _g = false;
bool _n = false;
} flags; } flags;
@ -285,7 +286,13 @@ bool dump_obj(const char *name, int fd)
uint8_t section = read_8(iter); uint8_t section = read_8(iter);
uint32_t offset = read_32(iter); uint32_t offset = read_32(iter);
std::string name = d.location_name(section, offset);
std::string name;
if (flags._n) {
name = d.section_name(section) + "+" + d.to_x(offset, 4, '$');
} else {
name = d.location_name(section, offset);
}
stack.emplace_back(std::move(name)); stack.emplace_back(std::move(name));
break; break;
} }
@ -636,10 +643,11 @@ void dump(const char *name) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int c; int c;
while ((c = getopt(argc, argv, "Sg")) != -1) { while ((c = getopt(argc, argv, "Sgn")) != -1) {
switch(c) { switch(c) {
case 'S': flags._S = true; break; case 'S': flags._S = true; break;
case 'g': flags._g = true; break; case 'g': flags._g = true; break;
case 'n': flags._n = true; break;
default: exit(EX_USAGE); break; default: exit(EX_USAGE); break;
} }
} }

View File

@ -374,3 +374,21 @@ std::string zrdz_disassembler::symbol_name(unsigned entry) const {
} }
return _symbols[entry].name; return _symbols[entry].name;
} }
std::string zrdz_disassembler::section_name(unsigned section) const {
std::string defname = std::string("section") + std::to_string(section);
if (section >= _sections.size()) {
warnx("Invalid section %d", section);
return defname;
}
auto &e = _sections[section];
if (!e.valid) {
warnx("Invalid section %d", section);
return defname;
}
return e.name;
}

View File

@ -39,6 +39,7 @@ public:
std::string location_name(unsigned section, uint32_t offset) const; std::string location_name(unsigned section, uint32_t offset) const;
std::string symbol_name(unsigned entry) const; std::string symbol_name(unsigned entry) const;
std::string section_name(unsigned entry) const;
protected: protected: