]>
Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - disassemble commands. |
0fb0cc75 JB |
2 | Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009 |
3 | Free Software Foundation, Inc. | |
ab91fdd5 | 4 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
fb40c209 AC |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb40c209 AC |
20 | |
21 | #include "defs.h" | |
13274fc3 | 22 | #include "arch-utils.h" |
fb40c209 AC |
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. */ | |
ce8f13f8 | 51 | void |
fb40c209 AC |
52 | mi_cmd_disassemble (char *command, char **argv, int argc) |
53 | { | |
13274fc3 | 54 | struct gdbarch *gdbarch = get_current_arch (); |
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}, | |
d5d6fca5 | 87 | { 0, 0, 0 } |
fb40c209 AC |
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)) | |
8a3fe4f8 | 140 | error (_("mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.")); |
fb40c209 | 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) | |
8a3fe4f8 | 150 | error (_("mi_cmd_disassemble: Invalid filename.")); |
fb40c209 | 151 | if (!find_line_pc (s, line_num, &start)) |
8a3fe4f8 | 152 | error (_("mi_cmd_disassemble: Invalid line number")); |
fb40c209 | 153 | if (find_pc_partial_function (start, NULL, &low, &high) == 0) |
8a3fe4f8 | 154 | error (_("mi_cmd_disassemble: No function contains specified address")); |
fb40c209 AC |
155 | } |
156 | ||
13274fc3 | 157 | gdb_disassembly (gdbarch, uiout, |
92df71f0 | 158 | file_string, |
e6158f16 | 159 | DISASSEMBLY_SOURCE, how_many, low, high); |
92df71f0 | 160 | |
fb40c209 | 161 | } |