1 /* MI Command Set - disassemble commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions (a Red Hat company).
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "mi-getopt.h"
27 #include "gdb_string.h"
31 /* The arguments to be passed on the command line and parsed here are:
35 START-ADDRESS: address to start the disassembly at.
36 END-ADDRESS: address to end the disassembly at.
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
49 MODE: 0 or 1 for disassembly only, or mixed source and disassembly,
52 mi_cmd_disassemble (char *command
, char **argv
, int argc
)
54 struct gdbarch
*gdbarch
= get_current_arch ();
57 int mixed_source_and_assembly
;
60 /* Which options have we processed ... */
67 /* ... and their corresponding value. */
68 char *file_string
= NULL
;
74 /* Options processing stuff. */
79 FILE_OPT
, LINE_OPT
, NUM_OPT
, START_OPT
, END_OPT
81 static struct mi_opt opts
[] = {
90 /* Get the options with their arguments. Keep track of what we
94 int opt
= mi_getopt ("mi_cmd_disassemble", argc
, argv
, opts
,
98 switch ((enum opt
) opt
)
101 file_string
= xstrdup (optarg
);
105 line_num
= atoi (optarg
);
109 how_many
= atoi (optarg
);
113 low
= parse_and_eval_address (optarg
);
117 high
= parse_and_eval_address (optarg
);
125 /* Allow only filename + linenum (with how_many which is not
126 required) OR start_addr + and_addr */
128 if (!((line_seen
&& file_seen
&& num_seen
&& !start_seen
&& !end_seen
)
129 || (line_seen
&& file_seen
&& !num_seen
&& !start_seen
&& !end_seen
)
130 || (!line_seen
&& !file_seen
&& !num_seen
&& start_seen
&& end_seen
)))
131 error (_("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n "
132 "howmany]] | [-s startaddr -e endaddr]) [--] mixed_mode."));
135 error (_("mi_cmd_disassemble: Usage: [-f filename -l linenum "
136 "[-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode."));
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."));
143 /* We must get the function beginning and end where line_num is
146 if (line_seen
&& file_seen
)
148 s
= lookup_symtab (file_string
);
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: "
155 "No function contains specified address"));
158 gdb_disassembly (gdbarch
, uiout
,
160 mixed_source_and_assembly
? DISASSEMBLY_SOURCE
: 0,
161 how_many
, low
, high
);