1 /* MI Command Set - stack commands.
2 Copyright (C) 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. */
30 /* FIXME: these should go in some .h file but stack.c doesn't have a
31 corresponding .h file. These wrappers will be obsolete anyway, once
32 we pull the plug on the sanitization. */
33 extern void select_frame_command_wrapper (char *, int);
36 static void list_args_or_locals (int locals
, int values
, struct frame_info
*fi
);
38 /* Print a list of the stack frames. Args can be none, in which case
39 we want to print the whole backtrace, or a pair of numbers
40 specifying the frame numbers at which to start and stop the
41 display. If the two numbers are equal, a single frame will be
44 mi_cmd_stack_list_frames (char *command
, char **argv
, int argc
)
49 struct frame_info
*fi
;
51 if (!target_has_stack
)
52 error ("mi_cmd_stack_list_frames: No stack.");
54 if (argc
> 2 || argc
== 1)
55 error ("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]");
59 frame_low
= atoi (argv
[0]);
60 frame_high
= atoi (argv
[1]);
64 /* Called with no arguments, it means we want the whole
70 /* Let's position fi on the frame at which to start the
71 display. Could be the innermost frame if the whole stack needs
72 displaying, or if frame_low is 0. */
73 for (i
= 0, fi
= get_current_frame ();
75 i
++, fi
= get_prev_frame (fi
));
78 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
80 ui_out_list_begin (uiout
, "stack");
82 /* Now let;s print the frames up to frame_high, or until there are
83 frames in the stack. */
85 fi
&& (i
<= frame_high
|| frame_high
== -1);
86 i
++, fi
= get_prev_frame (fi
))
89 /* level == i: always print the level 'i'
90 source == LOC_AND_ADDRESS: print the location and the address
91 always, even for level 0.
92 args == 0: don't print the arguments. */
93 print_frame_info (fi
/* frame info */ ,
95 LOC_AND_ADDRESS
/* source */ ,
99 ui_out_list_end (uiout
);
101 error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
107 mi_cmd_stack_info_depth (char *command
, char **argv
, int argc
)
111 struct frame_info
*fi
;
113 if (!target_has_stack
)
114 error ("mi_cmd_stack_info_depth: No stack.");
117 error ("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]");
120 frame_high
= atoi (argv
[0]);
122 /* Called with no arguments, it means we want the real depth of
126 for (i
= 0, fi
= get_current_frame ();
127 fi
&& (i
< frame_high
|| frame_high
== -1);
128 i
++, fi
= get_prev_frame (fi
))
131 ui_out_field_int (uiout
, "depth", i
);
136 /* Print a list of the locals for the current frame. With argument of
137 0, print only the names, with argument of 1 print also the
140 mi_cmd_stack_list_locals (char *command
, char **argv
, int argc
)
143 error ("mi_cmd_stack_list_locals: Usage: PRINT_VALUES");
145 list_args_or_locals (1, atoi (argv
[0]), selected_frame
);
149 /* Print a list of the arguments for the current frame. With argument
150 of 0, print only the names, with argument of 1 print also the
153 mi_cmd_stack_list_args (char *command
, char **argv
, int argc
)
158 struct frame_info
*fi
;
160 if (argc
< 1 || argc
> 3 || argc
== 2)
161 error ("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]");
165 frame_low
= atoi (argv
[1]);
166 frame_high
= atoi (argv
[2]);
170 /* Called with no arguments, it means we want args for the whole
176 /* Let's position fi on the frame at which to start the
177 display. Could be the innermost frame if the whole stack needs
178 displaying, or if frame_low is 0. */
179 for (i
= 0, fi
= get_current_frame ();
181 i
++, fi
= get_prev_frame (fi
));
184 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
186 ui_out_list_begin (uiout
, "stack-args");
188 /* Now let's print the frames up to frame_high, or until there are
189 frames in the stack. */
191 fi
&& (i
<= frame_high
|| frame_high
== -1);
192 i
++, fi
= get_prev_frame (fi
))
195 ui_out_list_begin (uiout
, "frame");
196 ui_out_field_int (uiout
, "level", i
);
197 list_args_or_locals (0, atoi (argv
[0]), fi
);
198 ui_out_list_end (uiout
);
201 ui_out_list_end (uiout
);
203 error ("mi_cmd_stack_list_args: Not enough frames in stack.");
208 /* Print a list of the locals or the arguments for the currently
209 selected frame. If the argument passed is 0, printonly the names
210 of the variables, if an argument of 1 is passed, print the values
213 list_args_or_locals (int locals
, int values
, struct frame_info
*fi
)
219 static struct ui_stream
*stb
= NULL
;
221 stb
= ui_out_stream_new (uiout
);
223 block
= get_frame_block (fi
);
225 ui_out_list_begin (uiout
, locals
? "locals" : "args");
229 nsyms
= BLOCK_NSYMS (block
);
230 for (i
= 0; i
< nsyms
; i
++)
232 sym
= BLOCK_SYM (block
, i
);
233 switch (SYMBOL_CLASS (sym
))
236 case LOC_UNDEF
: /* catches errors */
237 case LOC_CONST
: /* constant */
238 case LOC_TYPEDEF
: /* local typedef */
239 case LOC_LABEL
: /* local label */
240 case LOC_BLOCK
: /* local function */
241 case LOC_CONST_BYTES
: /* loc. byte seq. */
242 case LOC_UNRESOLVED
: /* unresolved static */
243 case LOC_OPTIMIZED_OUT
: /* optimized out */
247 case LOC_ARG
: /* argument */
248 case LOC_REF_ARG
: /* reference arg */
249 case LOC_REGPARM
: /* register arg */
250 case LOC_REGPARM_ADDR
: /* indirect register arg */
251 case LOC_LOCAL_ARG
: /* stack arg */
252 case LOC_BASEREG_ARG
: /* basereg arg */
257 case LOC_LOCAL
: /* stack local */
258 case LOC_BASEREG
: /* basereg local */
259 case LOC_STATIC
: /* static */
260 case LOC_REGISTER
: /* register */
268 ui_out_list_begin (uiout
, NULL
);
269 ui_out_field_string (uiout
, "name", SYMBOL_NAME (sym
));
275 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
276 block
, VAR_NAMESPACE
,
278 (struct symtab
**) NULL
);
281 print_variable_value (sym2
, fi
, stb
->stream
);
282 ui_out_field_stream (uiout
, "value", stb
);
283 ui_out_list_end (uiout
);
287 if (BLOCK_FUNCTION (block
))
290 block
= BLOCK_SUPERBLOCK (block
);
292 ui_out_list_end (uiout
);
293 ui_out_stream_delete (stb
);
297 mi_cmd_stack_select_frame (char *command
, char **argv
, int argc
)
300 if (!target_has_stack
)
301 error ("mi_cmd_stack_select_frame: No stack.");
304 error ("mi_cmd_stack_select_frame: Usage: [FRAME_SPEC]");
306 /* with no args, don't change frame */
308 select_frame_command_wrapper (0, 1 /* not used */ );
310 select_frame_command_wrapper (argv
[0], 1 /* not used */ );
This page took 0.035574 seconds and 4 git commands to generate.