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