Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - disassemble commands. |
ecd75fc8 | 2 | Copyright (C) 2000-2014 Free Software Foundation, Inc. |
ab91fdd5 | 3 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
fb40c209 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb40c209 AC |
19 | |
20 | #include "defs.h" | |
13274fc3 | 21 | #include "arch-utils.h" |
fb40c209 AC |
22 | #include "target.h" |
23 | #include "value.h" | |
24 | #include "mi-cmds.h" | |
25 | #include "mi-getopt.h" | |
0e9f083f | 26 | #include <string.h> |
92df71f0 FN |
27 | #include "ui-out.h" |
28 | #include "disasm.h" | |
8f0eea0e | 29 | |
2b03b41d | 30 | /* The arguments to be passed on the command line and parsed here are |
fb40c209 AC |
31 | either: |
32 | ||
33 | START-ADDRESS: address to start the disassembly at. | |
34 | END-ADDRESS: address to end the disassembly at. | |
35 | ||
36 | or: | |
37 | ||
38 | FILENAME: The name of the file where we want disassemble from. | |
39 | LINE: The line around which we want to disassemble. It will | |
40 | disassemble the function that contins that line. | |
b716877b | 41 | HOW_MANY: Number of disassembly lines to display. With source, it |
fb40c209 AC |
42 | is the number of disassembly lines only, not counting the source |
43 | lines. | |
44 | ||
45 | always required: | |
46 | ||
b716877b AB |
47 | MODE: 0 -- disassembly. |
48 | 1 -- disassembly and source. | |
49 | 2 -- disassembly and opcodes. | |
50 | 3 -- disassembly, source and opcodes. | |
51 | */ | |
2b03b41d | 52 | |
ce8f13f8 | 53 | void |
fb40c209 AC |
54 | mi_cmd_disassemble (char *command, char **argv, int argc) |
55 | { | |
13274fc3 | 56 | struct gdbarch *gdbarch = get_current_arch (); |
79a45e25 | 57 | struct ui_out *uiout = current_uiout; |
fb40c209 | 58 | CORE_ADDR start; |
fb40c209 | 59 | |
b716877b | 60 | int mode, disasm_flags; |
fb40c209 AC |
61 | struct symtab *s; |
62 | ||
8e2eec62 | 63 | /* Which options have we processed ... */ |
fb40c209 AC |
64 | int file_seen = 0; |
65 | int line_seen = 0; | |
66 | int num_seen = 0; | |
67 | int start_seen = 0; | |
68 | int end_seen = 0; | |
69 | ||
8e2eec62 AC |
70 | /* ... and their corresponding value. */ |
71 | char *file_string = NULL; | |
72 | int line_num = -1; | |
73 | int how_many = -1; | |
74 | CORE_ADDR low = 0; | |
75 | CORE_ADDR high = 0; | |
85c9d6a6 | 76 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
8e2eec62 | 77 | |
2b03b41d | 78 | /* Options processing stuff. */ |
81493c62 AS |
79 | int oind = 0; |
80 | char *oarg; | |
fb40c209 | 81 | enum opt |
fb40c209 | 82 | { |
27cdacdb EZ |
83 | FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT |
84 | }; | |
2b03b41d SS |
85 | static const struct mi_opt opts[] = |
86 | { | |
87 | {"f", FILE_OPT, 1}, | |
88 | {"l", LINE_OPT, 1}, | |
89 | {"n", NUM_OPT, 1}, | |
90 | {"s", START_OPT, 1}, | |
91 | {"e", END_OPT, 1}, | |
92 | { 0, 0, 0 } | |
93 | }; | |
fb40c209 AC |
94 | |
95 | /* Get the options with their arguments. Keep track of what we | |
2b03b41d | 96 | encountered. */ |
fb40c209 AC |
97 | while (1) |
98 | { | |
1b05df00 | 99 | int opt = mi_getopt ("-data-disassemble", argc, argv, opts, |
81493c62 | 100 | &oind, &oarg); |
fb40c209 AC |
101 | if (opt < 0) |
102 | break; | |
103 | switch ((enum opt) opt) | |
104 | { | |
105 | case FILE_OPT: | |
81493c62 | 106 | file_string = xstrdup (oarg); |
fb40c209 | 107 | file_seen = 1; |
85c9d6a6 | 108 | make_cleanup (xfree, file_string); |
fb40c209 AC |
109 | break; |
110 | case LINE_OPT: | |
81493c62 | 111 | line_num = atoi (oarg); |
fb40c209 AC |
112 | line_seen = 1; |
113 | break; | |
114 | case NUM_OPT: | |
81493c62 | 115 | how_many = atoi (oarg); |
fb40c209 AC |
116 | num_seen = 1; |
117 | break; | |
118 | case START_OPT: | |
81493c62 | 119 | low = parse_and_eval_address (oarg); |
fb40c209 AC |
120 | start_seen = 1; |
121 | break; | |
122 | case END_OPT: | |
81493c62 | 123 | high = parse_and_eval_address (oarg); |
fb40c209 AC |
124 | end_seen = 1; |
125 | break; | |
126 | } | |
127 | } | |
81493c62 AS |
128 | argv += oind; |
129 | argc -= oind; | |
fb40c209 AC |
130 | |
131 | /* Allow only filename + linenum (with how_many which is not | |
2b03b41d | 132 | required) OR start_addr + end_addr. */ |
fb40c209 AC |
133 | |
134 | if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen) | |
135 | || (line_seen && file_seen && !num_seen && !start_seen && !end_seen) | |
27cdacdb | 136 | || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))) |
1b05df00 | 137 | error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n " |
b716877b | 138 | "howmany]] | [-s startaddr -e endaddr]) [--] mode.")); |
fb40c209 AC |
139 | |
140 | if (argc != 1) | |
1b05df00 | 141 | error (_("-data-disassemble: Usage: [-f filename -l linenum " |
b716877b | 142 | "[-n howmany]] [-s startaddr -e endaddr] [--] mode.")); |
fb40c209 | 143 | |
b716877b AB |
144 | mode = atoi (argv[0]); |
145 | if (mode < 0 || mode > 3) | |
1b05df00 | 146 | error (_("-data-disassemble: Mode argument must be 0, 1, 2, or 3.")); |
fb40c209 | 147 | |
2b03b41d | 148 | /* Convert the mode into a set of disassembly flags. */ |
b716877b AB |
149 | |
150 | disasm_flags = 0; | |
151 | if (mode & 0x1) | |
152 | disasm_flags |= DISASSEMBLY_SOURCE; | |
153 | if (mode & 0x2) | |
154 | disasm_flags |= DISASSEMBLY_RAW_INSN; | |
8f0eea0e | 155 | |
fb40c209 | 156 | /* We must get the function beginning and end where line_num is |
2b03b41d | 157 | contained. */ |
fb40c209 AC |
158 | |
159 | if (line_seen && file_seen) | |
160 | { | |
161 | s = lookup_symtab (file_string); | |
162 | if (s == NULL) | |
1b05df00 | 163 | error (_("-data-disassemble: Invalid filename.")); |
fb40c209 | 164 | if (!find_line_pc (s, line_num, &start)) |
1b05df00 | 165 | error (_("-data-disassemble: Invalid line number")); |
fb40c209 | 166 | if (find_pc_partial_function (start, NULL, &low, &high) == 0) |
1b05df00 | 167 | error (_("-data-disassemble: " |
9a2b4c1b | 168 | "No function contains specified address")); |
fb40c209 AC |
169 | } |
170 | ||
13274fc3 | 171 | gdb_disassembly (gdbarch, uiout, |
92df71f0 | 172 | file_string, |
b716877b | 173 | disasm_flags, |
328d0145 | 174 | how_many, low, high); |
85c9d6a6 MS |
175 | |
176 | do_cleanups (cleanups); | |
fb40c209 | 177 | } |