old-cross-binutils/gdb/mi/mi-cmd-stack.c
Andrew Cagney 8a3fe4f86c 2005-02-10 Andrew Cagney <cagney@gnu.org>
Mark up all error and warning messages.
	* ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update.
	* bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update.
	* core-aout.c, core-regset.c, corefile.c, corelow.c: Update.
	* cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update.
	* dbxread.c, demangle.c, doublest.c, dsrec.c: Update.
	* dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update.
	* dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update.
	* event-top.c, exec.c, expprint.c, f-lang.c: Update.
	* f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update.
	* frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update.
	* gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update.
	* hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update.
	* hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update.
	* hpread.c, hpux-thread.c, i386-linux-nat.c: Update.
	* i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update.
	* i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update.
	* ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update.
	* infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
	* inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update.
	* kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update.
	* linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update.
	* m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update.
	* m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update.
	* maint.c, mdebugread.c, mem-break.c, memattr.c: Update.
	* mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update.
	* nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update.
	* observer.c, ocd.c, p-lang.c, p-typeprint.c: Update.
	* p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update.
	* ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update.
	* remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update.
	* remote-rdp.c, remote-sim.c, remote-st.c: Update.
	* remote-utils.c, remote-utils.h, remote.c: Update.
	* rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update.
	* ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update.
	* sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update.
	* solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update.
	* solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update.
	* somread.c, somsolib.c, source.c, stabsread.c: Update.
	* stack.c, std-regs.c, symfile-mem.c, symfile.c: Update.
	* symmisc.c, symtab.c, target.c, thread.c, top.c: Update.
	* tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update.
	* uw-thread.c, valarith.c, valops.c, valprint.c: Update.
	* value.c, varobj.c, version.in, win32-nat.c, wince.c: Update.
	* xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update.
	* cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update.
	* cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update.
	* mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update.
	* mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update.
	* mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update.
	* tui/tui-win.c: Update.
2005-02-11 04:06:14 +00:00

344 lines
10 KiB
C

/* MI Command Set - stack commands.
Copyright 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Cygnus Solutions (a Red Hat company).
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "defs.h"
#include "target.h"
#include "frame.h"
#include "value.h"
#include "mi-cmds.h"
#include "ui-out.h"
#include "symtab.h"
#include "block.h"
#include "stack.h"
#include "dictionary.h"
#include "gdb_string.h"
static void list_args_or_locals (int locals, int values, struct frame_info *fi);
/* Print a list of the stack frames. Args can be none, in which case
we want to print the whole backtrace, or a pair of numbers
specifying the frame numbers at which to start and stop the
display. If the two numbers are equal, a single frame will be
displayed. */
enum mi_cmd_result
mi_cmd_stack_list_frames (char *command, char **argv, int argc)
{
int frame_low;
int frame_high;
int i;
struct cleanup *cleanup_stack;
struct frame_info *fi;
if (!target_has_stack)
error (_("mi_cmd_stack_list_frames: No stack."));
if (argc > 2 || argc == 1)
error (_("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]"));
if (argc == 2)
{
frame_low = atoi (argv[0]);
frame_high = atoi (argv[1]);
}
else
{
/* Called with no arguments, it means we want the whole
backtrace. */
frame_low = -1;
frame_high = -1;
}
/* Let's position fi on the frame at which to start the
display. Could be the innermost frame if the whole stack needs
displaying, or if frame_low is 0. */
for (i = 0, fi = get_current_frame ();
fi && i < frame_low;
i++, fi = get_prev_frame (fi));
if (fi == NULL)
error (_("mi_cmd_stack_list_frames: Not enough frames in stack."));
cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "stack");
/* Now let;s print the frames up to frame_high, or until there are
frames in the stack. */
for (;
fi && (i <= frame_high || frame_high == -1);
i++, fi = get_prev_frame (fi))
{
QUIT;
/* Print the location and the address always, even for level 0.
args == 0: don't print the arguments. */
print_frame_info (fi, 1, LOC_AND_ADDRESS, 0 /* args */ );
}
do_cleanups (cleanup_stack);
if (i < frame_high)
error (_("mi_cmd_stack_list_frames: Not enough frames in stack."));
return MI_CMD_DONE;
}
enum mi_cmd_result
mi_cmd_stack_info_depth (char *command, char **argv, int argc)
{
int frame_high;
int i;
struct frame_info *fi;
if (!target_has_stack)
error (_("mi_cmd_stack_info_depth: No stack."));
if (argc > 1)
error (_("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]"));
if (argc == 1)
frame_high = atoi (argv[0]);
else
/* Called with no arguments, it means we want the real depth of
the stack. */
frame_high = -1;
for (i = 0, fi = get_current_frame ();
fi && (i < frame_high || frame_high == -1);
i++, fi = get_prev_frame (fi))
QUIT;
ui_out_field_int (uiout, "depth", i);
return MI_CMD_DONE;
}
/* Print a list of the locals for the current frame. With argument of
0, print only the names, with argument of 1 print also the
values. */
enum mi_cmd_result
mi_cmd_stack_list_locals (char *command, char **argv, int argc)
{
struct frame_info *frame;
enum print_values print_values;
if (argc != 1)
error (_("mi_cmd_stack_list_locals: Usage: PRINT_VALUES"));
frame = get_selected_frame (NULL);
if (strcmp (argv[0], "0") == 0
|| strcmp (argv[0], "--no-values") == 0)
print_values = PRINT_NO_VALUES;
else if (strcmp (argv[0], "1") == 0
|| strcmp (argv[0], "--all-values") == 0)
print_values = PRINT_ALL_VALUES;
else if (strcmp (argv[0], "2") == 0
|| strcmp (argv[0], "--simple-values") == 0)
print_values = PRINT_SIMPLE_VALUES;
else
error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\", 2 or \"--simple-values\""));
list_args_or_locals (1, print_values, frame);
return MI_CMD_DONE;
}
/* Print a list of the arguments for the current frame. With argument
of 0, print only the names, with argument of 1 print also the
values. */
enum mi_cmd_result
mi_cmd_stack_list_args (char *command, char **argv, int argc)
{
int frame_low;
int frame_high;
int i;
struct frame_info *fi;
struct cleanup *cleanup_stack_args;
if (argc < 1 || argc > 3 || argc == 2)
error (_("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]"));
if (argc == 3)
{
frame_low = atoi (argv[1]);
frame_high = atoi (argv[2]);
}
else
{
/* Called with no arguments, it means we want args for the whole
backtrace. */
frame_low = -1;
frame_high = -1;
}
/* Let's position fi on the frame at which to start the
display. Could be the innermost frame if the whole stack needs
displaying, or if frame_low is 0. */
for (i = 0, fi = get_current_frame ();
fi && i < frame_low;
i++, fi = get_prev_frame (fi));
if (fi == NULL)
error (_("mi_cmd_stack_list_args: Not enough frames in stack."));
cleanup_stack_args = make_cleanup_ui_out_list_begin_end (uiout, "stack-args");
/* Now let's print the frames up to frame_high, or until there are
frames in the stack. */
for (;
fi && (i <= frame_high || frame_high == -1);
i++, fi = get_prev_frame (fi))
{
struct cleanup *cleanup_frame;
QUIT;
cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
ui_out_field_int (uiout, "level", i);
list_args_or_locals (0, atoi (argv[0]), fi);
do_cleanups (cleanup_frame);
}
do_cleanups (cleanup_stack_args);
if (i < frame_high)
error (_("mi_cmd_stack_list_args: Not enough frames in stack."));
return MI_CMD_DONE;
}
/* Print a list of the locals or the arguments for the currently
selected frame. If the argument passed is 0, printonly the names
of the variables, if an argument of 1 is passed, print the values
as well. */
static void
list_args_or_locals (int locals, int values, struct frame_info *fi)
{
struct block *block;
struct symbol *sym;
struct dict_iterator iter;
int nsyms;
struct cleanup *cleanup_list;
static struct ui_stream *stb = NULL;
struct type *type;
stb = ui_out_stream_new (uiout);
block = get_frame_block (fi, 0);
cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, locals ? "locals" : "args");
while (block != 0)
{
ALL_BLOCK_SYMBOLS (block, iter, sym)
{
int print_me = 0;
switch (SYMBOL_CLASS (sym))
{
default:
case LOC_UNDEF: /* catches errors */
case LOC_CONST: /* constant */
case LOC_TYPEDEF: /* local typedef */
case LOC_LABEL: /* local label */
case LOC_BLOCK: /* local function */
case LOC_CONST_BYTES: /* loc. byte seq. */
case LOC_UNRESOLVED: /* unresolved static */
case LOC_OPTIMIZED_OUT: /* optimized out */
print_me = 0;
break;
case LOC_ARG: /* argument */
case LOC_REF_ARG: /* reference arg */
case LOC_REGPARM: /* register arg */
case LOC_REGPARM_ADDR: /* indirect register arg */
case LOC_LOCAL_ARG: /* stack arg */
case LOC_BASEREG_ARG: /* basereg arg */
case LOC_COMPUTED_ARG: /* arg with computed location */
if (!locals)
print_me = 1;
break;
case LOC_LOCAL: /* stack local */
case LOC_BASEREG: /* basereg local */
case LOC_STATIC: /* static */
case LOC_REGISTER: /* register */
case LOC_COMPUTED: /* computed location */
if (locals)
print_me = 1;
break;
}
if (print_me)
{
struct cleanup *cleanup_tuple = NULL;
struct symbol *sym2;
if (values != PRINT_NO_VALUES)
cleanup_tuple =
make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
ui_out_field_string (uiout, "name", SYMBOL_PRINT_NAME (sym));
if (!locals)
sym2 = lookup_symbol (SYMBOL_NATURAL_NAME (sym),
block, VAR_DOMAIN,
(int *) NULL,
(struct symtab **) NULL);
else
sym2 = sym;
switch (values)
{
case PRINT_SIMPLE_VALUES:
type = check_typedef (sym2->type);
type_print (sym2->type, "", stb->stream, -1);
ui_out_field_stream (uiout, "type", stb);
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
{
print_variable_value (sym2, fi, stb->stream);
ui_out_field_stream (uiout, "value", stb);
}
do_cleanups (cleanup_tuple);
break;
case PRINT_ALL_VALUES:
print_variable_value (sym2, fi, stb->stream);
ui_out_field_stream (uiout, "value", stb);
do_cleanups (cleanup_tuple);
break;
}
}
}
if (BLOCK_FUNCTION (block))
break;
else
block = BLOCK_SUPERBLOCK (block);
}
do_cleanups (cleanup_list);
ui_out_stream_delete (stb);
}
enum mi_cmd_result
mi_cmd_stack_select_frame (char *command, char **argv, int argc)
{
if (!target_has_stack)
error (_("mi_cmd_stack_select_frame: No stack."));
if (argc > 1)
error (_("mi_cmd_stack_select_frame: Usage: [FRAME_SPEC]"));
/* with no args, don't change frame */
if (argc == 0)
select_frame_command (0, 1 /* not used */ );
else
select_frame_command (argv[0], 1 /* not used */ );
return MI_CMD_DONE;
}