1 /* MI Command Set - disassemble commands.
2 Copyright (C) 2000-2014 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/>. */
21 #include "arch-utils.h"
25 #include "mi-getopt.h"
30 /* 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. With source, it
42 is the number of disassembly lines only, not counting the source
47 MODE: 0 -- disassembly.
48 1 -- disassembly and source.
49 2 -- disassembly and opcodes.
50 3 -- disassembly, source and opcodes.
54 mi_cmd_disassemble (char *command
, char **argv
, int argc
)
56 struct gdbarch
*gdbarch
= get_current_arch ();
57 struct ui_out
*uiout
= current_uiout
;
60 int mode
, disasm_flags
;
63 /* Which options have we processed ... */
70 /* ... and their corresponding value. */
71 char *file_string
= NULL
;
76 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
78 /* Options processing stuff. */
83 FILE_OPT
, LINE_OPT
, NUM_OPT
, START_OPT
, END_OPT
85 static const struct mi_opt opts
[] =
95 /* Get the options with their arguments. Keep track of what we
99 int opt
= mi_getopt ("-data-disassemble", argc
, argv
, opts
,
103 switch ((enum opt
) opt
)
106 file_string
= xstrdup (oarg
);
108 make_cleanup (xfree
, file_string
);
111 line_num
= atoi (oarg
);
115 how_many
= atoi (oarg
);
119 low
= parse_and_eval_address (oarg
);
123 high
= parse_and_eval_address (oarg
);
131 /* Allow only filename + linenum (with how_many which is not
132 required) OR start_addr + end_addr. */
134 if (!((line_seen
&& file_seen
&& num_seen
&& !start_seen
&& !end_seen
)
135 || (line_seen
&& file_seen
&& !num_seen
&& !start_seen
&& !end_seen
)
136 || (!line_seen
&& !file_seen
&& !num_seen
&& start_seen
&& end_seen
)))
137 error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
138 "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
141 error (_("-data-disassemble: Usage: [-f filename -l linenum "
142 "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
144 mode
= atoi (argv
[0]);
145 if (mode
< 0 || mode
> 3)
146 error (_("-data-disassemble: Mode argument must be 0, 1, 2, or 3."));
148 /* Convert the mode into a set of disassembly flags. */
152 disasm_flags
|= DISASSEMBLY_SOURCE
;
154 disasm_flags
|= DISASSEMBLY_RAW_INSN
;
156 /* We must get the function beginning and end where line_num is
159 if (line_seen
&& file_seen
)
161 s
= lookup_symtab (file_string
);
163 error (_("-data-disassemble: Invalid filename."));
164 if (!find_line_pc (s
, line_num
, &start
))
165 error (_("-data-disassemble: Invalid line number"));
166 if (find_pc_partial_function (start
, NULL
, &low
, &high
) == 0)
167 error (_("-data-disassemble: "
168 "No function contains specified address"));
171 gdb_disassembly (gdbarch
, uiout
,
174 how_many
, low
, high
);
176 do_cleanups (cleanups
);
This page took 0.04407 seconds and 4 git commands to generate.