OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [VER_5_3/] [gdb-5.3/] [gdb/] [mi/] [mi-cmd-stack.c] - Blame information for rev 1782

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
/* MI Command Set - stack commands.
2
   Copyright 2000, 2002 Free Software Foundation, Inc.
3
   Contributed by Cygnus Solutions (a Red Hat company).
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
9
   the Free Software Foundation; either version 2 of the License, or
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
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.  */
21
 
22
#include "defs.h"
23
#include "target.h"
24
#include "frame.h"
25
#include "value.h"
26
#include "mi-cmds.h"
27
#include "ui-out.h"
28
#include "symtab.h"
29
 
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);
34
 
35
static void list_args_or_locals (int locals, int values, struct frame_info *fi);
36
 
37
/* Print a list of the stack frames. Args can be none, in which case
38
   we want to print the whole backtrace, or a pair of numbers
39
   specifying the frame numbers at which to start and stop the
40
   display. If the two numbers are equal, a single frame will be
41
   displayed. */
42
enum mi_cmd_result
43
mi_cmd_stack_list_frames (char *command, char **argv, int argc)
44
{
45
  int frame_low;
46
  int frame_high;
47
  int i;
48
  struct frame_info *fi;
49
 
50
  if (!target_has_stack)
51
    error ("mi_cmd_stack_list_frames: No stack.");
52
 
53
  if (argc > 2 || argc == 1)
54
    error ("mi_cmd_stack_list_frames: Usage: [FRAME_LOW FRAME_HIGH]");
55
 
56
  if (argc == 2)
57
    {
58
      frame_low = atoi (argv[0]);
59
      frame_high = atoi (argv[1]);
60
    }
61
  else
62
    {
63
      /* Called with no arguments, it means we want the whole
64
         backtrace. */
65
      frame_low = -1;
66
      frame_high = -1;
67
    }
68
 
69
  /* Let's position fi on the frame at which to start the
70
     display. Could be the innermost frame if the whole stack needs
71
     displaying, or if frame_low is 0. */
72
  for (i = 0, fi = get_current_frame ();
73
       fi && i < frame_low;
74
       i++, fi = get_prev_frame (fi));
75
 
76
  if (fi == NULL)
77
    error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
78
 
79
  ui_out_list_begin (uiout, "stack");
80
 
81
  /* Now let;s print the frames up to frame_high, or until there are
82
     frames in the stack. */
83
  for (;
84
       fi && (i <= frame_high || frame_high == -1);
85
       i++, fi = get_prev_frame (fi))
86
    {
87
      QUIT;
88
      /* level == i: always print the level 'i'
89
         source == LOC_AND_ADDRESS: print the location and the address
90
         always, even for level 0.
91
         args == 0: don't print the arguments. */
92
      print_frame_info (fi /* frame info */ ,
93
                        i /* level */ ,
94
                        LOC_AND_ADDRESS /* source */ ,
95
 
96
    }
97
 
98
  ui_out_list_end (uiout);
99
  if (i < frame_high)
100
    error ("mi_cmd_stack_list_frames: Not enough frames in stack.");
101
 
102
  return MI_CMD_DONE;
103
}
104
 
105
enum mi_cmd_result
106
mi_cmd_stack_info_depth (char *command, char **argv, int argc)
107
{
108
  int frame_high;
109
  int i;
110
  struct frame_info *fi;
111
 
112
  if (!target_has_stack)
113
    error ("mi_cmd_stack_info_depth: No stack.");
114
 
115
  if (argc > 1)
116
    error ("mi_cmd_stack_info_depth: Usage: [MAX_DEPTH]");
117
 
118
  if (argc == 1)
119
    frame_high = atoi (argv[0]);
120
  else
121
    /* Called with no arguments, it means we want the real depth of
122
       the stack. */
123
    frame_high = -1;
124
 
125
  for (i = 0, fi = get_current_frame ();
126
       fi && (i < frame_high || frame_high == -1);
127
       i++, fi = get_prev_frame (fi))
128
    QUIT;
129
 
130
  ui_out_field_int (uiout, "depth", i);
131
 
132
  return MI_CMD_DONE;
133
}
134
 
135
/* Print a list of the locals for the current frame. With argument of
136
   0, print only the names, with argument of 1 print also the
137
   values. */
138
enum mi_cmd_result
139
mi_cmd_stack_list_locals (char *command, char **argv, int argc)
140
{
141
  if (argc != 1)
142
    error ("mi_cmd_stack_list_locals: Usage: PRINT_VALUES");
143
 
144
  list_args_or_locals (1, atoi (argv[0]), selected_frame);
145
  return MI_CMD_DONE;
146
}
147
 
148
/* Print a list of the arguments for the current frame. With argument
149
   of 0, print only the names, with argument of 1 print also the
150
   values. */
151
enum mi_cmd_result
152
mi_cmd_stack_list_args (char *command, char **argv, int argc)
153
{
154
  int frame_low;
155
  int frame_high;
156
  int i;
157
  struct frame_info *fi;
158
 
159
  if (argc < 1 || argc > 3 || argc == 2)
160
    error ("mi_cmd_stack_list_args: Usage: PRINT_VALUES [FRAME_LOW FRAME_HIGH]");
161
 
162
  if (argc == 3)
163
    {
164
      frame_low = atoi (argv[1]);
165
      frame_high = atoi (argv[2]);
166
    }
167
  else
168
    {
169
      /* Called with no arguments, it means we want args for the whole
170
         backtrace. */
171
      frame_low = -1;
172
      frame_high = -1;
173
    }
174
 
175
  /* Let's position fi on the frame at which to start the
176
     display. Could be the innermost frame if the whole stack needs
177
     displaying, or if frame_low is 0. */
178
  for (i = 0, fi = get_current_frame ();
179
       fi && i < frame_low;
180
       i++, fi = get_prev_frame (fi));
181
 
182
  if (fi == NULL)
183
    error ("mi_cmd_stack_list_args: Not enough frames in stack.");
184
 
185
  ui_out_list_begin (uiout, "stack-args");
186
 
187
  /* Now let's print the frames up to frame_high, or until there are
188
     frames in the stack. */
189
  for (;
190
       fi && (i <= frame_high || frame_high == -1);
191
       i++, fi = get_prev_frame (fi))
192
    {
193
      QUIT;
194
      ui_out_tuple_begin (uiout, "frame");
195
      ui_out_field_int (uiout, "level", i);
196
      list_args_or_locals (0, atoi (argv[0]), fi);
197
      ui_out_tuple_end (uiout);
198
    }
199
 
200
  ui_out_list_end (uiout);
201
  if (i < frame_high)
202
    error ("mi_cmd_stack_list_args: Not enough frames in stack.");
203
 
204
  return MI_CMD_DONE;
205
}
206
 
207
/* Print a list of the locals or the arguments for the currently
208
   selected frame.  If the argument passed is 0, printonly the names
209
   of the variables, if an argument of 1 is passed, print the values
210
   as well. */
211
static void
212
list_args_or_locals (int locals, int values, struct frame_info *fi)
213
{
214
  struct block *block;
215
  struct symbol *sym;
216
  int i, nsyms;
217
  static struct ui_stream *stb = NULL;
218
 
219
  stb = ui_out_stream_new (uiout);
220
 
221
  block = get_frame_block (fi, 0);
222
 
223
  ui_out_list_begin (uiout, locals ? "locals" : "args");
224
 
225
  while (block != 0)
226
    {
227
      ALL_BLOCK_SYMBOLS (block, i, sym)
228
        {
229
          int print_me = 0;
230
 
231
          switch (SYMBOL_CLASS (sym))
232
            {
233
            default:
234
            case LOC_UNDEF:     /* catches errors        */
235
            case LOC_CONST:     /* constant              */
236
            case LOC_TYPEDEF:   /* local typedef         */
237
            case LOC_LABEL:     /* local label           */
238
            case LOC_BLOCK:     /* local function        */
239
            case LOC_CONST_BYTES:       /* loc. byte seq.        */
240
            case LOC_UNRESOLVED:        /* unresolved static     */
241
            case LOC_OPTIMIZED_OUT:     /* optimized out         */
242
              print_me = 0;
243
              break;
244
 
245
            case LOC_ARG:       /* argument              */
246
            case LOC_REF_ARG:   /* reference arg         */
247
            case LOC_REGPARM:   /* register arg          */
248
            case LOC_REGPARM_ADDR:      /* indirect register arg */
249
            case LOC_LOCAL_ARG: /* stack arg             */
250
            case LOC_BASEREG_ARG:       /* basereg arg           */
251
              if (!locals)
252
                print_me = 1;
253
              break;
254
 
255
            case LOC_LOCAL:     /* stack local           */
256
            case LOC_BASEREG:   /* basereg local         */
257
            case LOC_STATIC:    /* static                */
258
            case LOC_REGISTER:  /* register              */
259
              if (locals)
260
                print_me = 1;
261
              break;
262
            }
263
          if (print_me)
264
            {
265
              if (values)
266
                ui_out_tuple_begin (uiout, NULL);
267
              ui_out_field_string (uiout, "name", SYMBOL_NAME (sym));
268
 
269
              if (values)
270
                {
271
                  struct symbol *sym2;
272
                  if (!locals)
273
                    sym2 = lookup_symbol (SYMBOL_NAME (sym),
274
                                          block, VAR_NAMESPACE,
275
                                          (int *) NULL,
276
                                          (struct symtab **) NULL);
277
                  else
278
                    sym2 = sym;
279
                  print_variable_value (sym2, fi, stb->stream);
280
                  ui_out_field_stream (uiout, "value", stb);
281
                  ui_out_tuple_end (uiout);
282
                }
283
            }
284
        }
285
      if (BLOCK_FUNCTION (block))
286
        break;
287
      else
288
        block = BLOCK_SUPERBLOCK (block);
289
    }
290
  ui_out_list_end (uiout);
291
  ui_out_stream_delete (stb);
292
}
293
 
294
enum mi_cmd_result
295
mi_cmd_stack_select_frame (char *command, char **argv, int argc)
296
{
297
  if (!target_has_stack)
298
    error ("mi_cmd_stack_select_frame: No stack.");
299
 
300
  if (argc > 1)
301
    error ("mi_cmd_stack_select_frame: Usage: [FRAME_SPEC]");
302
 
303
  /* with no args, don't change frame */
304
  if (argc == 0)
305
    select_frame_command_wrapper (0, 1 /* not used */ );
306
  else
307
    select_frame_command_wrapper (argv[0], 1 /* not used */ );
308
  return MI_CMD_DONE;
309
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.