ref: 55554976b71c0508c80fdd3531326bcce0882bbc
parent: aaabcfa788b098048d80c6e7e89cb78c408071d6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Mar 5 12:32:18 EST 2018
[nm] Add symbol type This symbol can be used by the common part to do the common work.
--- a/nm/main.c
+++ b/nm/main.c
@@ -71,9 +71,10 @@
}
void
-print(char *file, char *member, char *name, int type, unsigned long long off, long siz)
+print(char *file, char *member, struct symbol *sym)
{
char *fmt;
+ int type = sym->type;
if (uflag && type != 'U')
return;
@@ -83,7 +84,7 @@
if (Aflag)
printf((arflag) ? "%s[%s]: " : "%s: ", file, member);
if (Pflag) {
- printf("%s %c", name, type);
+ printf("%s %c", sym->name, sym->type);
if (type != 'U') {
if (radix == 8)
fmt = "%llo %llo";
@@ -91,7 +92,7 @@
fmt = "%llu %llu";
else
fmt = "%llx %llx";
- printf(fmt, off, siz);
+ printf(fmt, sym->off, sym->size);
}
} else {
if (type == 'U')
@@ -102,8 +103,8 @@
fmt = "%016.16lld";
else
fmt = "%016.16llx";
- printf(fmt, off);
- printf(" %c %s", type, name);
+ printf(fmt, sym->off);
+ printf(" %c %s", sym->type, sym->name);
}
putchar('\n');
}
--- a/nm/myro.c
+++ b/nm/myro.c
@@ -58,6 +58,7 @@
{
struct myrohdr hdr;
struct myrosym *syms = NULL, *sym;
+ struct symbol symbol;
size_t n, i;
long off;
@@ -100,13 +101,12 @@
}
qsort(syms, n, sizeof(*syms), cmp);
for (i = 0; i < n; ++i) {
- sym = &sym[i];
- print(fname,
- member,
- strings + sym->name,
- typeof(sym),
- sym->offset,
- sym->len);
+ sym = &syms[i];
+ symbol.name = strings + sym->name;
+ symbol.type = typeof(sym);
+ symbol.off = sym->offset;
+ symbol.size = sym->len;
+ print(fname, member, &symbol);
}
free_arrays:
--- a/nm/nm.h
+++ b/nm/nm.h
@@ -1,6 +1,13 @@
+struct symbol {
+ char *name;
+ int type;
+ unsigned long long off;
+ unsigned long size;
+};
+
/* main.c */
-extern void print(char *file, char *member, char *name, int type, unsigned long long off, long siz);
+extern void print(char *file, char *member, struct symbol *sym);
/* object format file */
extern void nm(char *fname, char *member, FILE *fp);