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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [core-sol2.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* Machine independent support for Solaris 2 core files for GDB.
2
   Copyright 1994, 1995, 1996, 1998, 1999, 2000, 2001
3
   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
 
23
/* Solaris comes with two flavours of core files, cores generated by
24
   an ELF executable and cores generated by programs that were
25
   run under BCP (the part of Solaris which allows it to run SunOS4
26
   a.out files).
27
   This file combines the core register fetching from core-regset.c
28
   and sparc-nat.c to be able to read both flavours.  */
29
 
30
/* for Sparc64 cross Sparc32 */
31
#define _SYSCALL32
32
#include "defs.h"
33
 
34
#if defined (__sparcv9)
35
/* Fails to get included by the Solaris system header files.  */
36
# include <v9/sys/privregs.h>
37
#endif
38
 
39
#include <time.h>
40
#include <sys/types.h>
41
#include <sys/regset.h>
42
#include <sys/procfs.h>
43
#include <fcntl.h>
44
#include <errno.h>
45
#include "gdb_string.h"
46
#include "regcache.h"
47
 
48
#include "inferior.h"
49
#include "target.h"
50
#include "command.h"
51
#include "gdbcore.h"
52
 
53
/* Prototypes for supply_gregset etc. */
54
#include "gregset.h"
55
 
56
static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
57
 
58
/* Fetch registers from core file data pointed to by CORE_REG_SECT.  When
59
   WHICH is 0, the the general register set is fetched; when WHICH is
60
   2, the floating point registers are fetched.  CORE_REG_SIZE is used
61
   to validate the size of the data pointed to by CORE_REG_SECT.  REG_ADDR
62
   is unused. */
63
 
64
static void
65
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
66
                      CORE_ADDR reg_addr)
67
{
68
  int i;
69
 
70
  if (which == 0)
71
    {
72
      prgregset_t prgregset;
73
 
74
      if (core_reg_size == sizeof (prgregset_t))
75
        {
76
          memcpy ((char *) &prgregset, core_reg_sect, sizeof (prgregset));
77
          supply_gregset (&prgregset);
78
        }
79
#if defined (HAVE_PRGREGSET32_T)
80
      /* 32-bit corefile, 64-bit debugger.  */
81
      else if (core_reg_size == sizeof (prgregset32_t))
82
        {
83
          prgreg32_t *core_gregs;
84
 
85
          /* Can't use memcpy here, because the core file contains
86
             32-bit regs; supply_register expects 64-bit regs.  */
87
          core_gregs = (prgreg32_t *) core_reg_sect;
88
          for (i = 0; i < NPRGREG; i++)
89
            prgregset[i] = core_gregs[i];
90
 
91
          supply_gregset (&prgregset);
92
        }
93
#endif /* HAVE_PRGREGSET32_T */
94
      else if (core_reg_size == sizeof (struct regs))
95
        {
96
          struct regs *gregs = (struct regs *) core_reg_sect;
97
 
98
          /* G0 *always* holds 0.  */
99
          *(int *) &registers[REGISTER_BYTE (0)] = 0;
100
 
101
          /* The globals and output registers.  */
102
          memcpy (&registers[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1,
103
                  15 * REGISTER_RAW_SIZE (G1_REGNUM));
104
          *(int *) &registers[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
105
          *(int *) &registers[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
106
          *(int *) &registers[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc;
107
          *(int *) &registers[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
108
 
109
          /* My best guess at where to get the locals and input
110
             registers is exactly where they usually are, right above
111
             the stack pointer.  If the core dump was caused by a bus error
112
             from blowing away the stack pointer (as is possible) then this
113
             won't work, but it's worth the try. */
114
          {
115
            int sp;
116
 
117
            sp = *(int *) &registers[REGISTER_BYTE (SP_REGNUM)];
118
            if (0 != target_read_memory (sp,
119
                                      &registers[REGISTER_BYTE (L0_REGNUM)],
120
                                         16 * REGISTER_RAW_SIZE (L0_REGNUM)))
121
              {
122
                warning ("couldn't read input and local registers from core file\n");
123
              }
124
          }
125
        }
126
      else
127
        {
128
          warning ("wrong size gregset struct in core file");
129
        }
130
    }
131
  else if (which == 2)
132
    {
133
      prfpregset_t prfpregset;
134
 
135
      if (core_reg_size == sizeof (prfpregset_t))
136
        {
137
          memcpy ((char *) &prfpregset, core_reg_sect, sizeof (prfpregset));
138
          supply_fpregset (&prfpregset);
139
        }
140
#if defined (HAVE_PRFPREGSET32_T)
141
      /* 32-bit corefile, 64-bit debugger.  */
142
      else if (core_reg_size == sizeof (prfpregset32_t))
143
        {
144
          prfpregset32_t *core_fpregset;
145
 
146
          /* Can't use memcpy here, because the core file contains
147
             32-bit regs; supply_fpregset expects 64-bit regs.  */
148
 
149
          core_fpregset = (prfpregset32_t *) core_reg_sect;
150
          for (i = 0; i < 16; i++)
151
            prfpregset.pr_fr.pr_dregs[i] = core_fpregset->pr_fr.pr_dregs[i];
152
          while (i < 32)
153
            prfpregset.pr_fr.pr_dregs[i++] = 0;
154
 
155
          prfpregset.pr_fsr         = core_fpregset->pr_fsr;
156
          prfpregset.pr_qcnt        = core_fpregset->pr_qcnt;
157
          prfpregset.pr_q_entrysize = core_fpregset->pr_q_entrysize;
158
          prfpregset.pr_en          = core_fpregset->pr_en;
159
          /* We will not use the pr_q array.  */
160
 
161
          supply_fpregset (&prfpregset);
162
        }
163
#endif /* HAVE_PRFPREGSET32_T */
164
      else if (core_reg_size >= sizeof (struct fpu))
165
        {
166
          struct fpu *fpuregs = (struct fpu *) core_reg_sect;
167
 
168
          memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &fpuregs->fpu_fr,
169
                  sizeof (fpuregs->fpu_fr));
170
          memcpy (&registers[REGISTER_BYTE (FPS_REGNUM)], &fpuregs->fpu_fsr,
171
                  sizeof (FPU_FSR_TYPE));
172
        }
173
      else
174
        {
175
          warning ("wrong size fpregset struct in core file");
176
        }
177
    }
178
}
179
 
180
 
181
/* Register that we are able to handle solaris core file formats. */
182
 
183
static struct core_fns solaris_core_fns =
184
{
185
  bfd_target_elf_flavour,               /* core_flavour */
186
  default_check_format,                 /* check_format */
187
  default_core_sniffer,                 /* core_sniffer */
188
  fetch_core_registers,                 /* core_read_registers */
189
  NULL                                  /* next */
190
};
191
 
192
void
193
_initialize_core_solaris (void)
194
{
195
  add_core_fns (&solaris_core_fns);
196
}

powered by: WebSVN 2.1.0

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