annotate leo-obj/tool/main.c @ 155:15743b40e03a

tiobjd ctypes: print more useful hex byte offsets for struct fields
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 02 May 2014 23:41:44 +0000
parents 25d3ead621f8
children 069b79b36228
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * tiobjd main() function and command dispatch
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "globals.h"
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 75
diff changeset
12 extern int cmd_basics();
145
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 143
diff changeset
13 extern int cmd_ctypes();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 110
diff changeset
14 extern int cmd_disasm();
143
fbdb7686a9e9 tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
15 extern int cmd_ln();
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 79
diff changeset
16 extern int cmd_nm();
79
8f4996bff904 tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
17 extern int cmd_profile();
82
c20dc315a9d4 tiobjd: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
18 extern int cmd_rawrel();
110
e650fdc743fe tiobjd: higher-level reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 82
diff changeset
19 extern int cmd_reloc();
71
c15cd3d695c0 tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 70
diff changeset
20 extern int cmd_sechdr();
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 75
diff changeset
21 extern int cmd_symtab();
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 extern int dump_filehdr_info();
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 static struct cmdtab {
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 char *cmd;
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int (*func)();
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 } cmdtab[] = {
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 75
diff changeset
28 {"basics", cmd_basics},
145
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 143
diff changeset
29 {"ctypes", cmd_ctypes},
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 110
diff changeset
30 {"disasm", cmd_disasm},
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 75
diff changeset
31 {"dumpsym", cmd_symtab}, /* backward compat */
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 {"hdr", dump_filehdr_info},
143
fbdb7686a9e9 tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
33 {"ln", cmd_ln},
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 79
diff changeset
34 {"nm", cmd_nm},
79
8f4996bff904 tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
35 {"profile", cmd_profile},
82
c20dc315a9d4 tiobjd: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
36 {"rawrel", cmd_rawrel},
110
e650fdc743fe tiobjd: higher-level reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 82
diff changeset
37 {"reloc", cmd_reloc},
71
c15cd3d695c0 tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 70
diff changeset
38 {"sechdr", cmd_sechdr},
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 75
diff changeset
39 {"symtab", cmd_symtab},
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 {0, 0}
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 };
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 main(argc, argv)
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 char **argv;
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 {
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 struct cmdtab *tp;
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
48 if (argc < 3) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
49 fprintf(stderr, "usage: %s <objfile> <op> [args]\n", argv[0]);
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 exit(1);
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 }
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 objfilename = argv[1];
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 mmap_objfile();
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 initial_parse_hdr();
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 for (tp = cmdtab; tp->cmd; tp++)
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (!strcmp(tp->cmd, argv[2]))
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 break;
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (!tp->func) {
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 fprintf(stderr, "\"%s\": unknown or unimplemented command\n",
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 argv[2]);
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 exit(1);
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
63 return tp->func(argc - 2, argv + 2);
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 }