diff leo-obj/tool/ln.c @ 211:71e25510f5af

tiobjd disasm -ll: show the actual line numbers
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 26 Mar 2016 22:03:08 +0000
parents fcf1ef773a57
children
line wrap: on
line diff
--- a/leo-obj/tool/ln.c	Sat Mar 05 02:51:04 2016 +0000
+++ b/leo-obj/tool/ln.c	Sat Mar 26 22:03:08 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Dumping of line number records
+ * Making use of line number records
  */
 
 #include <sys/types.h>
@@ -32,24 +32,51 @@
 	exit(0);
 }
 
-get_lineno_addrs(sec, arr_rtn, count_rtn)
+static unsigned
+get_lineno_base(func_symidx)
+	unsigned func_symidx;
+{
+	struct internal_syment *func_sym, *bf_sym;
+
+	if (func_symidx >= nsymtab)
+		return 0;
+	func_sym = symtab[func_symidx];
+	if (!func_sym->aux)
+		return 0;
+	if (func_symidx + 2 >= nsymtab)
+		return 0;
+	bf_sym = symtab[func_symidx + 2];
+	if (!bf_sym->aux)
+		return 0;
+	return get_u16(bf_sym->aux + 4);
+}
+
+get_lineno_array(sec, arr_rtn, count_rtn, actual_numbers)
 	struct internal_scnhdr *sec;
-	unsigned **arr_rtn, *count_rtn;
+	struct internal_lineno **arr_rtn;
+	unsigned *count_rtn;
 {
-	unsigned *array, cur, last;
+	struct internal_lineno *array;
+	unsigned cur, last;
 	unsigned n, m;
+	unsigned base, incr;
 	u_char *rec;
 
-	array = malloc(sizeof(unsigned) * sec->nlineent);
+	array = malloc(sizeof(struct internal_lineno) * sec->nlineent);
 	if (!array) {
 		perror("malloc");
 		exit(1);
 	}
 	m = 0;
 	rec = filemap + sec->line_offset;
+	base = 0;
 	for (n = 0; n < sec->nlineent; n++, rec += 6) {
-		if (!get_u16(rec + 4))
+		incr = get_u16(rec + 4);
+		if (!incr) {
+			if (actual_numbers)
+				base = get_lineno_base(get_u32(rec));
 			continue;
+		}
 		cur = get_u32(rec);
 		if (m) {
 			if (cur < last) {
@@ -58,10 +85,19 @@
 					sec->name);
 				exit(1);
 			}
-			if (cur == last)
+			if (cur == last && !actual_numbers)
 				continue;
 		}
-		array[m++] = cur;
+		if (actual_numbers) {
+			if (!base) {
+				fprintf(stderr,
+					"error: no line # base in section %s\n",
+					sec->name);
+				exit(1);
+			}
+			array[m].lineno = base + incr - 1;
+		}
+		array[m++].location = cur;
 		last = cur;
 	}
 	*arr_rtn = array;