annotate objgrep/frontend.c @ 174:10c0cdc18208

objgrep-fe written, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 08:46:32 +0000
parents
children 928ed52930aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program is a front-end to objgrep. It takes an ASCII text file as
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * input that lists the modules and sections to be grepped for, and it
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * invokes objgrep via popen() for each listed section, all on the same
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * unknown binary. We collect the symbol addresses printed by objgrep
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * via our pipe, and then we sort them to produce the final report.
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 */
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdio.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <ctype.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <string.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <strings.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <unistd.h>
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #define RAM_BOUNDARY 0x800000
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 #define SYMFLAG_AMBIG 8
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #define SYMSRC_TEXTMATCH 4
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 #define SYMSRC_EXTRELOC 2
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 #define SYMSRC_INTRELOC 1
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 struct symbol {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 char *name;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 unsigned value;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int flags;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 struct symbol *next;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 };
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 struct symbol *flash_symbols, *ram_symbols;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 unsigned num_flash_symbols, num_ram_symbols;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 char *binfilename;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 enter_symbol(name, valstr, symsrc)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 char *name, *valstr;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 struct symbol *newsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 newsym = malloc(sizeof(struct symbol) + strlen(name) + 1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (!newsym) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 perror("malloc");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 newsym->name = (char *)(newsym + 1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 strcpy(newsym->name, name);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 newsym->value = strtoul(valstr, 0, 16);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 newsym->flags = symsrc;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (newsym->value < RAM_BOUNDARY) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 newsym->next = flash_symbols;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 flash_symbols = newsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 num_flash_symbols++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 } else {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 newsym->next = ram_symbols;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 ram_symbols = newsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 num_ram_symbols++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 process_section(objfile, secname)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 char *objfile, *secname;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 char cmdline[1024], linebuf[512], *cp, *fields[3];
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 FILE *f;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 int symsrc, i;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 static char headline_textmatch[] = "This source section's symbols:";
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 static char headline_extreloc[] = "Externals deduced from relocs:";
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 static char headline_intreloc[] =
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 "This module's symbols deduced from section relocs:";
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 sprintf(cmdline, "objgrep -rs %s %s %s", objfile, secname, binfilename);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 f = popen(cmdline, "r");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 if (!f) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 perror("popen");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 symsrc = 0;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 while (fgets(linebuf, sizeof linebuf, f)) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 cp = index(linebuf, '\n');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 if (!cp) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 fprintf(stderr,
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 "error: objgrep output line has no terminating newline\n");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 *cp = '\0';
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 if (!strcmp(linebuf, headline_textmatch)) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 symsrc = SYMSRC_TEXTMATCH;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 if (!strcmp(linebuf, headline_extreloc)) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 symsrc = SYMSRC_EXTRELOC;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 if (!strcmp(linebuf, headline_intreloc)) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 symsrc = SYMSRC_INTRELOC;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 cp = linebuf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 for (i = 0; ; i++) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 while (isspace(*cp))
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 cp++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 if (!*cp)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 break;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 if (i == 3) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 i++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 break;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 for (fields[i] = cp; *cp && !isspace(*cp); cp++)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 ;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 if (*cp)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 *cp++ = '\0';
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 if (i != 3)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (fields[1][0] != '=' || fields[1][1])
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 if (!symsrc) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 fprintf(stderr,
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 "error: symbol output from objgrep w/o source indication\n");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 enter_symbol(fields[0], fields[2], symsrc);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 pclose(f);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 process_list_file(listfilename)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 char *listfilename;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 FILE *f;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 char linebuf[512], *objname, *cp, *np;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 int lineno;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 f = fopen(listfilename, "r");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 if (!f) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 perror(listfilename);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 for (cp = linebuf; isspace(*cp); cp++)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 ;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 if (*cp == '\0' || *cp == '#')
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 for (objname = cp; *cp && !isspace(*cp); cp++)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 ;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 if (*cp)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 *cp++ = '\0';
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 while (isspace(*cp))
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 cp++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 if (*cp == '\0' || *cp == '#') {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 process_section(objname, ".text");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 while (*cp && *cp != '#') {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 for (np = cp; *cp && !isspace(*cp); cp++)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 ;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 if (*cp)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 *cp++ = '\0';
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 process_section(objname, np);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 while (isspace(*cp))
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 cp++;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 fclose(f);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 sort_by_value(sym1, sym2)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 struct symbol **sym1, **sym2;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 if ((*sym1)->value < (*sym2)->value)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 return(-1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 if ((*sym1)->value > (*sym2)->value)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 return(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 return(0);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 sort_by_name(sym1, sym2)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 struct symbol **sym1, **sym2;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 int i;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 i = strcmp((*sym1)->name, (*sym2)->name);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 if (i)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 return i;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 else
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 return sort_by_value(sym1, sym2);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 fill_input_array(head, buf)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 struct symbol *head, **buf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 struct symbol *sym, **p;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 p = buf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 for (sym = head; sym; sym = sym->next)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 *p = sym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 unsigned
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 dedup_symbols(inbuf, outbuf, total)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 struct symbol **inbuf, **outbuf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 unsigned total;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 struct symbol **ip, **op, **input_end, *nsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 op = outbuf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 input_end = inbuf + total;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 for (ip = inbuf; ip < input_end; ip++) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 nsym = *ip;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 if (op == outbuf || strcmp(nsym->name, op[-1]->name)) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 *op++ = nsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 if (nsym->value == op[-1]->value) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 op[-1]->flags |= nsym->flags;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 continue;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 op[-1]->flags |= SYMFLAG_AMBIG;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 nsym->flags |= SYMFLAG_AMBIG;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 *op++ = nsym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 return(op - outbuf);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 emit_final_symbols(buf, total)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 struct symbol **buf;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 unsigned total;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 struct symbol **p, **endbuf, *sym;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 endbuf = buf + total;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 for (p = buf; p < endbuf; p++) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 sym = *p;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 printf("%08X %s (", sym->value, sym->name);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 if (sym->flags & SYMSRC_TEXTMATCH)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 putchar('S');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 if (sym->flags & SYMSRC_EXTRELOC)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 putchar('R');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 if (sym->flags & SYMSRC_INTRELOC)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 putchar('r');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 if (sym->flags & SYMFLAG_AMBIG)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 fputs(", ambiguous", stdout);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 putchar(')');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 putchar('\n');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 sort_and_emit_symbols(head, total)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 struct symbol *head;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 unsigned total;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 struct symbol **input, **output;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 unsigned final_count;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 input = malloc(sizeof(void *) * total);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 if (!input) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 perror("malloc");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 fill_input_array(head, input);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 qsort(input, total, sizeof(void *), sort_by_name);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 output = malloc(sizeof(void *) * total);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 if (!output) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 perror("malloc");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 final_count = dedup_symbols(input, output, total);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 free(input);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 qsort(output, final_count, sizeof(void *), sort_by_value);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 emit_final_symbols(output, final_count);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 free(output);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 putchar('\n');
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 main(argc, argv)
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 char **argv;
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 if (argc != 3) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 fprintf(stderr, "usage: %s listfile binfile\n", argv[0]);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 exit(1);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 binfilename = argv[2];
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 process_list_file(argv[1]);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 if (flash_symbols) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 printf("Flash symbols:\n\n");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 sort_and_emit_symbols(flash_symbols, num_flash_symbols);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 if (ram_symbols) {
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 printf("RAM symbols:\n\n");
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 sort_and_emit_symbols(ram_symbols, num_ram_symbols);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 }
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 exit(0);
10c0cdc18208 objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 }