Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - disassemble commands. |
46fe1613 | 2 | Copyright 2000, 2001, 2002 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 | |
9 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "target.h" | |
24 | #include "value.h" | |
25 | #include "mi-cmds.h" | |
26 | #include "mi-getopt.h" | |
5f8a3188 | 27 | #include "gdb_string.h" |
92df71f0 FN |
28 | #include "ui-out.h" |
29 | #include "disasm.h" | |
8f0eea0e | 30 | |
fb40c209 AC |
31 | /* The arguments to be passed on the command line and parsed here are: |
32 | ||
33 | either: | |
34 | ||
35 | START-ADDRESS: address to start the disassembly at. | |
36 | END-ADDRESS: address to end the disassembly at. | |
37 | ||
38 | or: | |
39 | ||
40 | FILENAME: The name of the file where we want disassemble from. | |
41 | LINE: The line around which we want to disassemble. It will | |
42 | disassemble the function that contins that line. | |
43 | HOW_MANY: Number of disassembly lines to display. In mixed mode, it | |
44 | is the number of disassembly lines only, not counting the source | |
45 | lines. | |
46 | ||
47 | always required: | |
48 | ||
49 | MODE: 0 or 1 for disassembly only, or mixed source and disassembly, | |
50 | respectively. */ | |
fb40c209 AC |
51 | enum mi_cmd_result |
52 | mi_cmd_disassemble (char *command, char **argv, int argc) | |
53 | { | |
8f0eea0e | 54 | enum mi_cmd_result retval; |
fb40c209 | 55 | CORE_ADDR start; |
fb40c209 | 56 | |
fb40c209 | 57 | int mixed_source_and_assembly; |
fb40c209 AC |
58 | struct symtab *s; |
59 | ||
8e2eec62 | 60 | /* Which options have we processed ... */ |
fb40c209 AC |
61 | int file_seen = 0; |
62 | int line_seen = 0; | |
63 | int num_seen = 0; | |
64 | int start_seen = 0; | |
65 | int end_seen = 0; | |
66 | ||
8e2eec62 AC |
67 | /* ... and their corresponding value. */ |
68 | char *file_string = NULL; | |
69 | int line_num = -1; | |
70 | int how_many = -1; | |
71 | CORE_ADDR low = 0; | |
72 | CORE_ADDR high = 0; | |
73 | ||
fb40c209 AC |
74 | /* Options processing stuff. */ |
75 | int optind = 0; | |
76 | char *optarg; | |
77 | enum opt | |
fb40c209 | 78 | { |
27cdacdb EZ |
79 | FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT |
80 | }; | |
81 | static struct mi_opt opts[] = { | |
fb40c209 AC |
82 | {"f", FILE_OPT, 1}, |
83 | {"l", LINE_OPT, 1}, | |
84 | {"n", NUM_OPT, 1}, | |
85 | {"s", START_OPT, 1}, | |
86 | {"e", END_OPT, 1}, | |
87 | 0 | |
88 | }; | |
89 | ||
90 | /* Get the options with their arguments. Keep track of what we | |
91 | encountered. */ | |
92 | while (1) | |
93 | { | |
94 | int opt = mi_getopt ("mi_cmd_disassemble", argc, argv, opts, | |
95 | &optind, &optarg); | |
96 | if (opt < 0) | |
97 | break; | |
98 | switch ((enum opt) opt) | |
99 | { | |
100 | case FILE_OPT: | |
101 | file_string = xstrdup (optarg); | |
102 | file_seen = 1; | |
103 | break; | |
104 | case LINE_OPT: | |
105 | line_num = atoi (optarg); | |
106 | line_seen = 1; | |
107 | break; | |
108 | case NUM_OPT: | |
109 | how_many = atoi (optarg); | |
110 | num_seen = 1; | |
111 | break; | |
112 | case START_OPT: | |
113 | low = parse_and_eval_address (optarg); | |
114 | start_seen = 1; | |
115 | break; | |
116 | case END_OPT: | |
117 | high = parse_and_eval_address (optarg); | |
118 | end_seen = 1; | |
119 | break; | |
120 | } | |
121 | } | |
122 | argv += optind; | |
123 | argc -= optind; | |
124 | ||
125 | /* Allow only filename + linenum (with how_many which is not | |
126 | required) OR start_addr + and_addr */ | |
127 | ||
128 | if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen) | |
129 | || (line_seen && file_seen && !num_seen && !start_seen && !end_seen) | |
27cdacdb EZ |
130 | || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))) |
131 | error | |
132 | ("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n howmany]] | [-s startaddr -e endaddr]) [--] mixed_mode."); | |
fb40c209 AC |
133 | |
134 | if (argc != 1) | |
27cdacdb EZ |
135 | error |
136 | ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode."); | |
fb40c209 AC |
137 | |
138 | mixed_source_and_assembly = atoi (argv[0]); | |
139 | if ((mixed_source_and_assembly != 0) && (mixed_source_and_assembly != 1)) | |
140 | error ("mi_cmd_disassemble: Mixed_mode argument must be 0 or 1."); | |
141 | ||
8f0eea0e | 142 | |
fb40c209 AC |
143 | /* We must get the function beginning and end where line_num is |
144 | contained. */ | |
145 | ||
146 | if (line_seen && file_seen) | |
147 | { | |
148 | s = lookup_symtab (file_string); | |
149 | if (s == NULL) | |
150 | error ("mi_cmd_disassemble: Invalid filename."); | |
151 | if (!find_line_pc (s, line_num, &start)) | |
152 | error ("mi_cmd_disassemble: Invalid line number"); | |
153 | if (find_pc_partial_function (start, NULL, &low, &high) == 0) | |
154 | error ("mi_cmd_disassemble: No function contains specified address"); | |
155 | } | |
156 | ||
92df71f0 FN |
157 | gdb_disassembly (uiout, |
158 | file_string, | |
159 | line_num, | |
160 | mixed_source_and_assembly, how_many, low, high); | |
161 | ||
162 | return MI_CMD_DONE; | |
fb40c209 | 163 | } |