1 /* MI Command Set - stack commands.
2 Copyright 2000 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 /* FIXME: these should go in some .h file but stack.c doesn't have a
32 corresponding .h file. These wrappers will be obsolete anyway, once
33 we pull the plug on the sanitization. */
34 extern void select_frame_command_wrapper (char *, int);
37 static void list_args_or_locals (int locals
, int values
, struct frame_info
*fi
);
39 /* Print a list of the stack frames. Args can be none, in which case
40 we want to print the whole backtrace, or a pair of numbers
41 specifying the frame numbers at which to start and stop the
42 display. If the two numbers are equal, a single frame will be
45 mi_cmd_stack_list_frames (char *command
, char **argv
, int argc
)
50 struct frame_info
*fi
;
52 if (!target_has_stack
)
53 error ("mi_cmd_stack_list_frames: No stack.");
55 if (argc
> 2 || argc
== 1)
56 error ("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]");
60 frame_low
= atoi (argv
[0]);
61 frame_high
= atoi (argv
[1]);
65 /* Called with no arguments, it means we want the whole
71 /* Let's position fi on the frame at which to start the
72 display. Could be the innermost frame if the whole stack needs
73 displaying, or if frame_low is 0. */
74 for (i
= 0, fi
= get_current_frame ();
76 i
++, fi
= get_prev_frame (fi
));
79 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
81 ui_out_list_begin (uiout
, "stack");
83 /* Now let;s print the frames up to frame_high, or until there are
84 frames in the stack. */
86 fi
&& (i
<= frame_high
|| frame_high
== -1);
87 i
++, fi
= get_prev_frame (fi
))
90 /* level == i: always print the level 'i'
91 source == LOC_AND_ADDRESS: print the location and the address
92 always, even for level 0.
93 args == 0: don't print the arguments. */
94 print_frame_info (fi
/* frame info */ ,
96 LOC_AND_ADDRESS
/* source */ ,
100 ui_out_list_end (uiout
);
102 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
108 mi_cmd_stack_info_depth (char *command
, char **argv
, int argc
)
112 struct frame_info
*fi
;
114 if (!target_has_stack
)
115 error ("mi_cmd_stack_info_depth: No stack.");
118 error ("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]");
121 frame_high
= atoi (argv
[0]);
123 /* Called with no arguments, it means we want the real depth of
127 for (i
= 0, fi
= get_current_frame ();
128 fi
&& (i
< frame_high
|| frame_high
== -1);
129 i
++, fi
= get_prev_frame (fi
))
132 ui_out_field_int (uiout
, "depth", i
);
137 /* Print a list of the locals for the current frame. With argument of
138 0, print only the names, with argument of 1 print also the
141 mi_cmd_stack_list_locals (char *command
, char **argv
, int argc
)
144 error ("mi_cmd_stack_list_locals: Usage: PRINT_VALUES");
146 list_args_or_locals (1, atoi (argv
[0]), selected_frame
);
150 /* Print a list of the arguments for the current frame. With argument
151 of 0, print only the names, with argument of 1 print also the
154 mi_cmd_stack_list_args (char *command
, char **argv
, int argc
)
159 struct frame_info
*fi
;
161 if (argc
< 1 || argc
> 3 || argc
== 2)
162 error ("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]");
166 frame_low
= atoi (argv
[1]);
167 frame_high
= atoi (argv
[2]);
171 /* Called with no arguments, it means we want args for the whole
177 /* Let's position fi on the frame at which to start the
178 display. Could be the innermost frame if the whole stack needs
179 displaying, or if frame_low is 0. */
180 for (i
= 0, fi
= get_current_frame ();
182 i
++, fi
= get_prev_frame (fi
));
185 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
187 ui_out_list_begin (uiout
, "stack-args");
189 /* Now let's print the frames up to frame_high, or until there are
190 frames in the stack. */
192 fi
&& (i
<= frame_high
|| frame_high
== -1);
193 i
++, fi
= get_prev_frame (fi
))
196 ui_out_tuple_begin (uiout
, "frame");
197 ui_out_field_int (uiout
, "level", i
);
198 list_args_or_locals (0, atoi (argv
[0]), fi
);
199 ui_out_tuple_end (uiout
);
202 ui_out_list_end (uiout
);
204 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
209 /* Print a list of the locals or the arguments for the currently
210 selected frame. If the argument passed is 0, printonly the names
211 of the variables, if an argument of 1 is passed, print the values
214 list_args_or_locals (int locals
, int values
, struct frame_info
*fi
)
220 static struct ui_stream
*stb
= NULL
;
222 stb
= ui_out_stream_new (uiout
);
224 block
= get_frame_block (fi
);
226 ui_out_list_begin (uiout
, locals
? "locals" : "args");
230 ALL_BLOCK_SYMBOLS (block
, i
, sym
)
232 switch (SYMBOL_CLASS (sym
))
235 case LOC_UNDEF
: /* catches errors */
236 case LOC_CONST
: /* constant */
237 case LOC_TYPEDEF
: /* local typedef */
238 case LOC_LABEL
: /* local label */
239 case LOC_BLOCK
: /* local function */
240 case LOC_CONST_BYTES
: /* loc. byte seq. */
241 case LOC_UNRESOLVED
: /* unresolved static */
242 case LOC_OPTIMIZED_OUT
: /* optimized out */
246 case LOC_ARG
: /* argument */
247 case LOC_REF_ARG
: /* reference arg */
248 case LOC_REGPARM
: /* register arg */
249 case LOC_REGPARM_ADDR
: /* indirect register arg */
250 case LOC_LOCAL_ARG
: /* stack arg */
251 case LOC_BASEREG_ARG
: /* basereg arg */
256 case LOC_LOCAL
: /* stack local */
257 case LOC_BASEREG
: /* basereg local */
258 case LOC_STATIC
: /* static */
259 case LOC_REGISTER
: /* register */
267 ui_out_tuple_begin (uiout
, NULL
);
268 ui_out_field_string (uiout
, "name", SYMBOL_NAME (sym
));
274 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
275 block
, VAR_NAMESPACE
,
277 (struct symtab
**) NULL
);
280 print_variable_value (sym2
, fi
, stb
->stream
);
281 ui_out_field_stream (uiout
, "value", stb
);
282 ui_out_tuple_end (uiout
);
286 if (BLOCK_FUNCTION (block
))
289 block
= BLOCK_SUPERBLOCK (block
);
291 ui_out_list_end (uiout
);
292 ui_out_stream_delete (stb
);
296 mi_cmd_stack_select_frame (char *command
, char **argv
, int argc
)
299 if (!target_has_stack
)
300 error ("mi_cmd_stack_select_frame: No stack.");
303 error ("mi_cmd_stack_select_frame: Usage: [FRAME_SPEC]");
305 /* with no args, don't change frame */
307 select_frame_command_wrapper (0, 1 /* not used */ );
309 select_frame_command_wrapper (argv
[0], 1 /* not used */ );
This page took 0.035401 seconds and 4 git commands to generate.