Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - disassemble commands. |
b811d2c2 | 2 | Copyright (C) 2000-2020 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" | |
92df71f0 FN |
26 | #include "ui-out.h" |
27 | #include "disasm.h" | |
8f0eea0e | 28 | |
2b03b41d | 29 | /* The arguments to be passed on the command line and parsed here are |
fb40c209 AC |
30 | either: |
31 | ||
32 | START-ADDRESS: address to start the disassembly at. | |
33 | END-ADDRESS: address to end the disassembly at. | |
34 | ||
35 | or: | |
36 | ||
37 | FILENAME: The name of the file where we want disassemble from. | |
38 | LINE: The line around which we want to disassemble. It will | |
30baf67b | 39 | disassemble the function that contains that line. |
b716877b | 40 | HOW_MANY: Number of disassembly lines to display. With source, it |
fb40c209 AC |
41 | is the number of disassembly lines only, not counting the source |
42 | lines. | |
43 | ||
44 | always required: | |
45 | ||
b716877b | 46 | MODE: 0 -- disassembly. |
6ff0ba5f | 47 | 1 -- disassembly and source (with deprecated source-centric view). |
b716877b | 48 | 2 -- disassembly and opcodes. |
6ff0ba5f DE |
49 | 3 -- disassembly, source-centric and opcodes. |
50 | 4 -- disassembly, and source (with pc-centric view). | |
51 | 5 -- disassembly, source (pc-centric) and opcodes. */ | |
2b03b41d | 52 | |
ce8f13f8 | 53 | void |
9f33b8b7 | 54 | mi_cmd_disassemble (const char *command, char **argv, int argc) |
fb40c209 | 55 | { |
13274fc3 | 56 | struct gdbarch *gdbarch = get_current_arch (); |
79a45e25 | 57 | struct ui_out *uiout = current_uiout; |
fb40c209 | 58 | CORE_ADDR start; |
fb40c209 | 59 | |
9a24775b PA |
60 | int mode; |
61 | gdb_disassembly_flags disasm_flags; | |
fb40c209 AC |
62 | struct symtab *s; |
63 | ||
8e2eec62 | 64 | /* Which options have we processed ... */ |
fb40c209 AC |
65 | int file_seen = 0; |
66 | int line_seen = 0; | |
67 | int num_seen = 0; | |
68 | int start_seen = 0; | |
69 | int end_seen = 0; | |
26fb3983 | 70 | int addr_seen = 0; |
fb40c209 | 71 | |
8e2eec62 AC |
72 | /* ... and their corresponding value. */ |
73 | char *file_string = NULL; | |
74 | int line_num = -1; | |
75 | int how_many = -1; | |
76 | CORE_ADDR low = 0; | |
77 | CORE_ADDR high = 0; | |
26fb3983 | 78 | CORE_ADDR addr = 0; |
8e2eec62 | 79 | |
2b03b41d | 80 | /* Options processing stuff. */ |
81493c62 AS |
81 | int oind = 0; |
82 | char *oarg; | |
fb40c209 | 83 | enum opt |
fb40c209 | 84 | { |
26fb3983 | 85 | FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT |
27cdacdb | 86 | }; |
2b03b41d SS |
87 | static const struct mi_opt opts[] = |
88 | { | |
89 | {"f", FILE_OPT, 1}, | |
90 | {"l", LINE_OPT, 1}, | |
91 | {"n", NUM_OPT, 1}, | |
92 | {"s", START_OPT, 1}, | |
93 | {"e", END_OPT, 1}, | |
26fb3983 | 94 | {"a", ADDR_OPT, 1}, |
2b03b41d SS |
95 | { 0, 0, 0 } |
96 | }; | |
fb40c209 AC |
97 | |
98 | /* Get the options with their arguments. Keep track of what we | |
2b03b41d | 99 | encountered. */ |
fb40c209 AC |
100 | while (1) |
101 | { | |
1b05df00 | 102 | int opt = mi_getopt ("-data-disassemble", argc, argv, opts, |
81493c62 | 103 | &oind, &oarg); |
fb40c209 AC |
104 | if (opt < 0) |
105 | break; | |
106 | switch ((enum opt) opt) | |
107 | { | |
108 | case FILE_OPT: | |
9813429a | 109 | file_string = oarg; |
fb40c209 AC |
110 | file_seen = 1; |
111 | break; | |
112 | case LINE_OPT: | |
81493c62 | 113 | line_num = atoi (oarg); |
fb40c209 AC |
114 | line_seen = 1; |
115 | break; | |
116 | case NUM_OPT: | |
81493c62 | 117 | how_many = atoi (oarg); |
fb40c209 AC |
118 | num_seen = 1; |
119 | break; | |
120 | case START_OPT: | |
81493c62 | 121 | low = parse_and_eval_address (oarg); |
fb40c209 AC |
122 | start_seen = 1; |
123 | break; | |
124 | case END_OPT: | |
81493c62 | 125 | high = parse_and_eval_address (oarg); |
fb40c209 AC |
126 | end_seen = 1; |
127 | break; | |
26fb3983 JV |
128 | case ADDR_OPT: |
129 | addr = parse_and_eval_address (oarg); | |
130 | addr_seen = 1; | |
131 | break; | |
fb40c209 AC |
132 | } |
133 | } | |
81493c62 AS |
134 | argv += oind; |
135 | argc -= oind; | |
fb40c209 AC |
136 | |
137 | /* Allow only filename + linenum (with how_many which is not | |
26fb3983 JV |
138 | required) OR start_addr + end_addr OR addr. */ |
139 | ||
140 | if (!( | |
141 | ( line_seen && file_seen && !start_seen && !end_seen | |
142 | && !addr_seen) | |
fb40c209 | 143 | |
26fb3983 JV |
144 | || (!line_seen && !file_seen && !num_seen && start_seen && end_seen |
145 | && !addr_seen) | |
fb40c209 | 146 | |
26fb3983 JV |
147 | || (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen |
148 | && addr_seen)) | |
149 | || argc != 1) | |
150 | error (_("-data-disassemble: Usage: ( [-f filename -l linenum " | |
151 | "[-n howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode.")); | |
fb40c209 | 152 | |
b716877b | 153 | mode = atoi (argv[0]); |
6ff0ba5f DE |
154 | if (mode < 0 || mode > 5) |
155 | error (_("-data-disassemble: Mode argument must be in the range 0-5.")); | |
fb40c209 | 156 | |
2b03b41d | 157 | /* Convert the mode into a set of disassembly flags. */ |
b716877b | 158 | |
6ff0ba5f DE |
159 | disasm_flags = 0; /* Initialize here for -Wall. */ |
160 | switch (mode) | |
161 | { | |
162 | case 0: | |
163 | break; | |
164 | case 1: | |
165 | disasm_flags |= DISASSEMBLY_SOURCE_DEPRECATED; | |
166 | break; | |
167 | case 2: | |
168 | disasm_flags |= DISASSEMBLY_RAW_INSN; | |
169 | break; | |
170 | case 3: | |
171 | disasm_flags |= DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_RAW_INSN; | |
172 | break; | |
173 | case 4: | |
174 | disasm_flags |= DISASSEMBLY_SOURCE; | |
175 | break; | |
176 | case 5: | |
177 | disasm_flags |= DISASSEMBLY_SOURCE | DISASSEMBLY_RAW_INSN; | |
178 | break; | |
179 | default: | |
180 | gdb_assert_not_reached ("bad disassembly mode"); | |
181 | } | |
8f0eea0e | 182 | |
fb40c209 | 183 | /* We must get the function beginning and end where line_num is |
2b03b41d | 184 | contained. */ |
fb40c209 AC |
185 | |
186 | if (line_seen && file_seen) | |
187 | { | |
188 | s = lookup_symtab (file_string); | |
189 | if (s == NULL) | |
1b05df00 | 190 | error (_("-data-disassemble: Invalid filename.")); |
fb40c209 | 191 | if (!find_line_pc (s, line_num, &start)) |
1b05df00 | 192 | error (_("-data-disassemble: Invalid line number")); |
fb40c209 | 193 | if (find_pc_partial_function (start, NULL, &low, &high) == 0) |
1b05df00 | 194 | error (_("-data-disassemble: " |
9a2b4c1b | 195 | "No function contains specified address")); |
fb40c209 | 196 | } |
26fb3983 JV |
197 | else if (addr_seen) |
198 | { | |
199 | if (find_pc_partial_function (addr, NULL, &low, &high) == 0) | |
200 | error (_("-data-disassemble: " | |
201 | "No function contains specified address")); | |
202 | } | |
fb40c209 | 203 | |
13274fc3 | 204 | gdb_disassembly (gdbarch, uiout, |
b716877b | 205 | disasm_flags, |
328d0145 | 206 | how_many, low, high); |
fb40c209 | 207 | } |