This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] nm.c code rearrangement
- From: Elias Athanasopoulos <eathan at otenet dot gr>
- To: binutils at sources dot redhat dot com
- Date: Sat, 28 Sep 2002 14:31:12 +0300
- Subject: [PATCH] nm.c code rearrangement
Hi,
This patch rearranges a little the code of nm.c, in order nm to be
aesthitic correct with the -fsysv output:
[anteater@neutrino binutils]$ ./nm-new -l -fs ~/test/foo.o
Symbols from /home/anteater/test/foo.o:
Name Value Class Type Size Line Section
another_one |00000004| C | OBJECT|00000004| |*COM*
a_symbol |00000004| C | OBJECT|00000004| |*COM*
bar | | U | NOTYPE| |/tmp/cc4jJh9R.s:12|*UND*
gcc2_compiled. |00000000| t | NOTYPE| |/tmp/cc4jJh9R.s:9|.text
main |00000000| T | FUNC|00000012|/tmp/cc4jJh9R.s:9|.text
Elias
ChangeLog
2002-09-28 Elias Athanasopoulos <eathan@otenet.gr>
* nm.c (extended_symbol_info): Add filename, lineno for line
numbers information.
(get_line_info): New function. Place the line numbers counting
code here.
(print_symbol): Remove line numbers counting code and call
get_line_info.
(print_symbol_info_bsd): Print line number information.
(print_symbol_info_sysv): Likewise.
(print_symbol_info_posix): Likewise.
--- nm.c.orig Sat Sep 28 12:43:03 2002
+++ nm.c Sat Sep 28 14:15:42 2002
@@ -57,7 +57,8 @@
symbol_info *sinfo;
bfd_vma ssize;
elf_symbol_type *elfinfo;
- /* FIXME: We should add more fields for Type, Line, Section. */
+ const char *filename;
+ unsigned int lineno;
};
#define SYM_NAME(sym) (sym->sinfo->name)
#define SYM_VALUE(sym) (sym->sinfo->value)
@@ -67,6 +68,8 @@
#define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other)
#define SYM_SIZE(sym) \
(sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize)
+#define SYM_FILENAME(sym) (sym->filename)
+#define SYM_LINENO(sym) (sym->lineno)
static void usage PARAMS ((FILE *, int));
static void set_print_radix PARAMS ((char *));
@@ -109,7 +112,7 @@
static void print_symbol_info_posix PARAMS ((struct extended_symbol_info *, bfd *));
static void get_relocs PARAMS ((bfd *, asection *, PTR));
static const char * get_symbol_type PARAMS ((unsigned int));
-
+static void get_line_info PARAMS ((bfd *, asymbol *, const char **, unsigned int *));
/* Support for different output formats. */
struct output_fns
{
@@ -1197,15 +1200,27 @@
info.elfinfo = (elf_symbol_type *) sym;
else
info.elfinfo = NULL;
+ if (line_numbers) {
+ info.filename = NULL;
+ info.lineno = 0;
+ get_line_info (abfd, sym, &(info.filename), &(info.lineno));
+ }
(*format->print_symbol_info) (&info, abfd);
}
- if (line_numbers)
- {
+ putchar ('\n');
+}
+
+static void
+get_line_info (abfd, sym, filename, lineno)
+ bfd *abfd;
+ asymbol *sym;
+ const char **filename;
+ unsigned int *lineno;
+{
static asymbol **syms;
static long symcount;
- const char *filename, *functionname;
- unsigned int lineno;
+ const char *functionname;
/* We need to get the canonical symbols in order to call
bfd_find_nearest_line. This is inefficient, but, then, you
@@ -1287,12 +1302,11 @@
&& strcmp (symname,
bfd_asymbol_name (*r->sym_ptr_ptr)) == 0
&& bfd_find_nearest_line (abfd, secs[i], syms,
- r->address, &filename,
- &functionname, &lineno)
+ r->address, filename,
+ &functionname, lineno)
&& filename != NULL)
{
- /* We only print the first one we find. */
- printf ("\t%s:%u", filename, lineno);
+ /* We only get the first one we find. */
i = seccount;
break;
}
@@ -1302,17 +1316,14 @@
else if (bfd_get_section (sym)->owner == abfd)
{
if (bfd_find_nearest_line (abfd, bfd_get_section (sym), syms,
- sym->value, &filename, &functionname,
- &lineno)
+ sym->value, filename, &functionname,
+ lineno)
&& filename != NULL
&& lineno != 0)
{
- printf ("\t%s:%u", filename, lineno);
- }
+ return;
}
}
-
- putchar ('\n');
}
/* The following 3 groups of functions are called unconditionally,
@@ -1523,6 +1534,8 @@
printf (" %5s", SYM_STAB_NAME (info));
}
print_symname (" %s", SYM_NAME (info), abfd);
+ if (SYM_FILENAME (info) && SYM_LINENO (info))
+ printf ("\t%s:%u", SYM_FILENAME (info), SYM_LINENO (info));
}
static void
@@ -1569,11 +1582,12 @@
else
printf (" ");
}
-
- if (info->elfinfo)
- printf("| |%s", info->elfinfo->symbol.section->name);
+ if (SYM_FILENAME (info) && SYM_LINENO (info))
+ printf ("|%s:%u|", SYM_FILENAME (info), SYM_LINENO (info));
else
- printf("| |");
+ printf ("| |");
+ if (info->elfinfo)
+ printf ("%s", info->elfinfo->symbol.section->name);
}
}
@@ -1594,6 +1608,8 @@
if (SYM_SIZE (info))
print_value (abfd, SYM_SIZE (info));
}
+ if (SYM_FILENAME (info) && SYM_LINENO (info))
+ printf ("\t%s:%u", SYM_FILENAME (info), SYM_LINENO (info));
}
static void