commit da7a1e321a20363b1b3ddd37bdbdb63fa69ac89a
parent 87c10daec10a697c280b9e65162a6bc66b98a972
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 28 Nov 2017 22:24:33 +0100
[objdump] Print symbols in one line format
It helps to scripts
Diffstat:
2 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/inc/myro.h b/inc/myro.h
@@ -53,6 +53,13 @@ enum myrosecflg {
MYROSEC_ABS = 1 << 5,
};
+enum myrosymflg {
+ MYROSYM_DEDUP = 1 << 0,
+ MYROSYM_COMMON = 1 << 1,
+ MYROSYM_EXTERN = 1 << 2,
+ MYROSYM_UNDEF = 1 << 3,
+};
+
extern int wrmyrohdr(FILE *fp, struct myrohdr *hdr);
extern int wrmyrosec(FILE *fp, struct myrosect *sect);
extern int wrmyrosym(FILE *fp, struct myrosym *sym);
diff --git a/objdump/main.c b/objdump/main.c
@@ -124,29 +124,47 @@ printsections(struct myrohdr *hdr, FILE *fp)
return 0;
}
+static char *
+symflags(struct myrosym *sym)
+{
+ static char flags[10];
+ char *s = flags + sizeof(flags);
+
+ if (sym->flags & MYROSYM_DEDUP)
+ *--s = 'D';
+ if (sym->flags & MYROSYM_COMMON)
+ *--s = 'C';
+ if (sym->flags & MYROSYM_EXTERN)
+ *--s = 'G';
+ if (sym->flags & MYROSYM_UNDEF)
+ *s-- = 'U';
+ return s;
+}
+
static int
printsymbols(struct myrohdr *hdr, FILE *fp)
{
unsigned long long n, i;
struct myrosym sym;
- puts("symbols:");
+ printf("symbols:\n"
+ "[Nr]\t%s\t%-16s\t%s\t%s\t%s\n",
+ "Name",
+ "Value",
+ "Section",
+ "Flags",
+ "Type");
n = hdr->symsize / MYROSYM_SIZ;
for (i = 0; i < n; ++i) {
if (rdmyrosym(fp, &sym) < 0)
return -1;
- printf("\tname: %lu (\"%s\")\n"
- "\ttype: %lu (\"%s\")\n"
- "\tsection: %u\n"
- "\tflags: %x\n"
- "\toffset: %llu\n"
- "\tlength: %llu\n\n",
- sym.name, getstring(sym.name),
- sym.type, getstring(sym.type),
- sym.section,
- sym.flags,
+ printf("[%2u]\t%s\t%016X\t%u\t%s\t%s\n",
+ i,
+ getstring(sym.name),
sym.offset,
- sym.len);
+ sym.section,
+ symflags(&sym),
+ getstring(sym.type));
}
return 0;
}