1 /* MI Command Set - disassemble commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "mi-getopt.h"
25 #include "gdb_string.h"
29 /* The arguments to be passed on the command line and parsed here are:
33 START-ADDRESS: address to start the disassembly at.
34 END-ADDRESS: address to end the disassembly at.
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.
41 HOW_MANY: Number of disassembly lines to display. In mixed mode, it
42 is the number of disassembly lines only, not counting the source
47 MODE: 0 or 1 for disassembly only, or mixed source and disassembly,
50 mi_cmd_disassemble (char *command
, char **argv
, int argc
)
54 int mixed_source_and_assembly
;
57 /* Which options have we processed ... */
64 /* ... and their corresponding value. */
65 char *file_string
= NULL
;
71 /* Options processing stuff. */
76 FILE_OPT
, LINE_OPT
, NUM_OPT
, START_OPT
, END_OPT
78 static struct mi_opt opts
[] = {
87 /* Get the options with their arguments. Keep track of what we
91 int opt
= mi_getopt ("mi_cmd_disassemble", argc
, argv
, opts
,
95 switch ((enum opt
) opt
)
98 file_string
= xstrdup (optarg
);
102 line_num
= atoi (optarg
);
106 how_many
= atoi (optarg
);
110 low
= parse_and_eval_address (optarg
);
114 high
= parse_and_eval_address (optarg
);
122 /* Allow only filename + linenum (with how_many which is not
123 required) OR start_addr + and_addr */
125 if (!((line_seen
&& file_seen
&& num_seen
&& !start_seen
&& !end_seen
)
126 || (line_seen
&& file_seen
&& !num_seen
&& !start_seen
&& !end_seen
)
127 || (!line_seen
&& !file_seen
&& !num_seen
&& start_seen
&& end_seen
)))
129 ("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n howmany]] | [-s startaddr -e endaddr]) [--] mixed_mode.");
133 ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode.");
135 mixed_source_and_assembly
= atoi (argv
[0]);
136 if ((mixed_source_and_assembly
!= 0) && (mixed_source_and_assembly
!= 1))
137 error (_("mi_cmd_disassemble: Mixed_mode argument must be 0 or 1."));
140 /* We must get the function beginning and end where line_num is
143 if (line_seen
&& file_seen
)
145 s
= lookup_symtab (file_string
);
147 error (_("mi_cmd_disassemble: Invalid filename."));
148 if (!find_line_pc (s
, line_num
, &start
))
149 error (_("mi_cmd_disassemble: Invalid line number"));
150 if (find_pc_partial_function (start
, NULL
, &low
, &high
) == 0)
151 error (_("mi_cmd_disassemble: No function contains specified address"));
154 gdb_disassembly (uiout
,
157 mixed_source_and_assembly
, how_many
, low
, high
);