diff leo-obj/tool/disasm.c @ 152:fcf1ef773a57

tiobjd disasm: implemented -l option to show line markers
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 01 May 2014 01:01:58 +0000
parents 6fe08feee018
children 71e25510f5af
line wrap: on
line diff
--- a/leo-obj/tool/disasm.c	Thu May 01 00:23:18 2014 +0000
+++ b/leo-obj/tool/disasm.c	Thu May 01 01:01:58 2014 +0000
@@ -15,7 +15,7 @@
 extern char *storage_class_to_string();
 
 int auto_xlat_section_relocs = 1;
-int disasm_richsym;
+int disasm_richsym, disasm_lineno;
 extern int richsym_print_bitsize;
 
 static void
@@ -181,10 +181,19 @@
 	struct hint *hint = sec->hints;
 	u_char *asciz_end;
 	unsigned asciz_len;
+	unsigned *lineno_arr;
+	unsigned lineno_cur, lineno_total;
 
 	if (sec->nreloc)
 		get_relocs_of_sec(sec);
+	if (disasm_lineno && sec->nlineent)
+		get_lineno_addrs(sec, &lineno_arr, &lineno_total);
+	else {
+		lineno_arr = 0;
+		lineno_total = 0;
+	}
 	symnum = relnum = 0;
+	lineno_cur = 0;
 	for (pos = 0; pos < sec->size; pos += incr) {
 		headroom = sec->size - pos;
 		while (symnum < sec->nsymbols) {
@@ -221,6 +230,15 @@
 			gothint = 0;
 		if (gothint && pos == hint->pos && hint->linebrk)
 			putchar('\n');
+		if (lineno_cur < lineno_total) {
+			if (pos >= lineno_arr[lineno_cur]) {
+				puts("; line");
+				lineno_cur++;
+			} else {
+				if (lineno_arr[lineno_cur] - pos < headroom)
+					headroom = lineno_arr[lineno_cur] - pos;
+			}
+		}
 		printf("%8x:\t", pos);
 		if (gothint && hint->type) {
 			if (rel) {
@@ -351,6 +369,8 @@
 	}
 	if (linebrk)
 		printf("%8x:\t<end of section>\n", sec->size);
+	if (lineno_arr)
+		free(lineno_arr);
 }
 
 void
@@ -414,7 +434,7 @@
 	unsigned secnum;
 	int c;
 
-	while ((c = getopt(argc, argv, "bgh:s")) != EOF)
+	while ((c = getopt(argc, argv, "bgh:ls")) != EOF)
 		switch (c) {
 		case 'b':
 			richsym_print_bitsize++;
@@ -425,6 +445,9 @@
 		case 'h':
 			hintsfile = optarg;
 			continue;
+		case 'l':
+			disasm_lineno++;
+			continue;
 		case 's':
 			auto_xlat_section_relocs = 0;
 			continue;