OSDN Git Service

2003-06-08 Andrew Cagney <cagney@redhat.com>
[pf3gnuchains/pf3gnuchains3x.git] / gdb / trad-frame.c
1 /* Traditional frame unwind support, for GDB the GNU Debugger.
2
3    Copyright 2003 Free Software Foundation, Inc.
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 "frame.h"
24 #include "trad-frame.h"
25 #include "regcache.h"
26
27 /* A traditional frame is unwound by analysing the function prologue
28    and using the information gathered to track registers.  For
29    non-optimized frames, the technique is reliable (just need to check
30    for all potential instruction sequences).  */
31
32 struct trad_frame_saved_reg *
33 trad_frame_alloc_saved_regs (struct frame_info *next_frame)
34 {
35   int regnum;
36   struct gdbarch *gdbarch = get_frame_arch (next_frame);
37   int numregs = NUM_REGS + NUM_PSEUDO_REGS;
38   struct trad_frame_saved_reg *this_saved_regs
39     = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);
40   for (regnum = 0; regnum < numregs; regnum++)
41     this_saved_regs[regnum].realnum = regnum;
42   return this_saved_regs;
43 }
44
45 void
46 trad_frame_register_value (struct trad_frame_saved_reg this_saved_regs[],
47                            int regnum, LONGEST val)
48 {
49   /* Make the REALNUM invalid, indicating that the ADDR contains the
50      register's value.  */
51   this_saved_regs[regnum].realnum = -1;
52   this_saved_regs[regnum].addr = val;
53 }
54
55 void
56 trad_frame_prev_register (struct frame_info *next_frame,
57                           struct trad_frame_saved_reg this_saved_regs[],
58                           int regnum, int *optimizedp,
59                           enum lval_type *lvalp, CORE_ADDR *addrp,
60                           int *realnump, void *bufferp)
61 {
62   struct gdbarch *gdbarch = get_frame_arch (next_frame);
63   if (this_saved_regs[regnum].realnum >= 0
64       && this_saved_regs[regnum].addr != 0)
65     {
66       /* The register was saved in memory.  */
67       *optimizedp = 0;
68       *lvalp = lval_memory;
69       *addrp = this_saved_regs[regnum].addr;
70       *realnump = -1;
71       if (bufferp != NULL)
72         {
73           /* Read the value in from memory.  */
74           get_frame_memory (next_frame, this_saved_regs[regnum].addr, bufferp,
75                             register_size (gdbarch, regnum));
76         }
77     }
78   else if (this_saved_regs[regnum].realnum >= 0
79            && this_saved_regs[regnum].addr == 0)
80     {
81       /* As the next frame to return the value of the register.  */
82       frame_register_unwind (next_frame, this_saved_regs[regnum].realnum,
83                              optimizedp, lvalp, addrp, realnump, bufferp);
84     }
85   else
86     {
87       /* The register's value is available.  */
88       *optimizedp = 0;
89       *lvalp = not_lval;
90       *addrp = 0;
91       *realnump = -1;
92       if (bufferp != NULL)
93         store_unsigned_integer (bufferp, register_size (gdbarch, regnum),
94                                 this_saved_regs[regnum].addr);
95     }
96 }