[PATCH] Use /usr/bin/nm -D

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use "nm -D" to retrieve also the symbols of crash when compiled without -g
(or stripped after compilation and debuginfo extraction).


Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>


1 file changed, 60 insertions(+), 38 deletions(-)
symbols.c |   98 +++++++++++++++++++++++++++++++++++++------------------------


Use "nm -D" to retrieve also the symbols of crash when compiled without -g
(or stripped after compilation and debuginfo extraction).


Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>

diff --git a/symbols.c b/symbols.c
--- a/symbols.c
+++ b/symbols.c
@@ -9036,21 +9036,68 @@
         exit(1);
 }
 
-
-/*
- *  Dump a trace leading to the improper datatype usage.
- */
-void
-dump_trace(ulong *retaddr)
-{
+static int
+print_symbol_nm(ulong lookfor, const char *thisfile, int only_dynamic)
+{
+	const char *dynamic_nm_args = "/usr/bin/nm -DBn %s";
+	const char *normal_nm_args  = "/usr/bin/nm -Bn %s 2>/dev/null";
 	int i, c;
-	char *thisfile;
-	char *arglist[MAXARGS];
-	char buf[BUFSIZE];
-	FILE *pipe;
-	ulong vaddr, lookfor;
 	ulong last_vaddr;
 	char symbol[BUFSIZE];
+	char *arglist[MAXARGS];
+	FILE *pipe;
+	ulong vaddr;
+	char buf[BUFSIZE];
+
+	sprintf(buf, only_dynamic ? dynamic_nm_args : normal_nm_args, thisfile);
+	if (!(pipe = popen(buf, "r"))) {
+		perror("pipe");
+		return FALSE;
+	}
+
+	last_vaddr = 0;
+	BZERO(symbol, BUFSIZE);
+
+	while (fgets(buf, 80, pipe)) {
+		c = parse_line(strip_linefeeds(buf), arglist);
+		if (c != 3)
+			continue;
+		vaddr = htol(arglist[0], FAULT_ON_ERROR, NULL);
+		if (vaddr > lookfor) {
+			fprintf(stderr, "%s  %lx: %s+%ld\n",
+				i == 0 ? "\n" : "", 
+				lookfor, symbol, 
+				lookfor-last_vaddr);
+			pclose(pipe);
+			return TRUE;
+		}
+		strcpy(symbol, arglist[2]);
+		last_vaddr = vaddr;
+	}
+
+	pclose(pipe);
+	return FALSE;
+}
+
+static void
+print_symbol(ulong lookfor, const char *thisfile)
+{
+	int success;
+
+	success = print_symbol_nm(lookfor, thisfile, FALSE);
+	if (!success)
+		print_symbol_nm(lookfor, thisfile, TRUE);
+}
+
+/*
+ *  Dump a trace leading to the improper datatype usage.
+ */
+void
+dump_trace(ulong *retaddr)
+{
+	int i;
+	char *thisfile;
+	ulong lookfor;
 
 	fflush(fp);
 	fflush(stdout);
@@ -9077,32 +9124,7 @@
 		if (!(lookfor = retaddr[i]))
 			continue;
 
-		sprintf(buf, "/usr/bin/nm -Bn %s", thisfile);
-	        if (!(pipe = popen(buf, "r"))) {
-			perror("pipe");
-			break;
-		}
-
-		last_vaddr = 0;
-		BZERO(symbol, BUFSIZE);
-
-	        while (fgets(buf, 80, pipe)) {
-			c = parse_line(strip_linefeeds(buf), arglist);
-			if (c != 3)
-				continue;
-			vaddr = htol(arglist[0], FAULT_ON_ERROR, NULL);
-			if (vaddr > lookfor) {
-				fprintf(stderr, "%s  %lx: %s+%ld\n",
-					i == 0 ? "\n" : "", 
-					lookfor, symbol, 
-					lookfor-last_vaddr);
-				break;
-			}
-			strcpy(symbol, arglist[2]);
-			last_vaddr = vaddr;
-		}
-
-		pclose(pipe);
+		print_symbol(lookfor, thisfile);
 	}
 
 	fprintf(stderr, "\n");
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux