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