~ubuntu-branches/ubuntu/raring/crash/raring-proposed

« back to all changes in this revision

Viewing changes to debian/gdb-6.1.back/gdb-6.1/gdb-6.1/gdb-6.1/gdb-6.1/gdb/ppc-linux-tdep.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-11-04 13:04:16 UTC
  • mfrom: (0.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20081104130416-7s1imz9huwwfzrbt
Tags: 4.0-7.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/patches/01_spu_commands.dpatch
    + Provides SPU extension support
  - debian/rules:
    + Patch support
    + Enable SPU on PPC
  - debian/control:
    + Enable LPIA builds.
    + Build depend on dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Target-dependent code for GDB, the GNU debugger.
2
 
 
3
 
   Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
4
 
   1997, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
 
   Copyright (c) 2004, 2005 Red Hat, Inc. All rights reserved.
6
 
 
7
 
   This file is part of GDB.
8
 
 
9
 
   This program is free software; you can redistribute it and/or modify
10
 
   it under the terms of the GNU General Public License as published by
11
 
   the Free Software Foundation; either version 2 of the License, or
12
 
   (at your option) any later version.
13
 
 
14
 
   This program is distributed in the hope that it will be useful,
15
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
   GNU General Public License for more details.
18
 
 
19
 
   You should have received a copy of the GNU General Public License
20
 
   along with this program; if not, write to the Free Software
21
 
   Foundation, Inc., 59 Temple Place - Suite 330,
22
 
   Boston, MA 02111-1307, USA.  */
23
 
 
24
 
#include "defs.h"
25
 
#include "frame.h"
26
 
#include "inferior.h"
27
 
#include "symtab.h"
28
 
#include "target.h"
29
 
#include "gdbcore.h"
30
 
#include "gdbcmd.h"
31
 
#include "symfile.h"
32
 
#include "objfiles.h"
33
 
#include "regcache.h"
34
 
#include "value.h"
35
 
#include "osabi.h"
36
 
 
37
 
#include "solib-svr4.h"
38
 
#include "ppc-tdep.h"
39
 
 
40
 
/* The following instructions are used in the signal trampoline code
41
 
   on GNU/Linux PPC. The kernel used to use magic syscalls 0x6666 and
42
 
   0x7777 but now uses the sigreturn syscalls.  We check for both.  */
43
 
#define INSTR_LI_R0_0x6666              0x38006666
44
 
#define INSTR_LI_R0_0x7777              0x38007777
45
 
#define INSTR_LI_R0_NR_sigreturn        0x38000077
46
 
#define INSTR_LI_R0_NR_rt_sigreturn     0x380000AC
47
 
 
48
 
#define INSTR_SC                        0x44000002
49
 
 
50
 
/* Since the *-tdep.c files are platform independent (i.e, they may be
51
 
   used to build cross platform debuggers), we can't include system
52
 
   headers.  Therefore, details concerning the sigcontext structure
53
 
   must be painstakingly rerecorded.  What's worse, if these details
54
 
   ever change in the header files, they'll have to be changed here
55
 
   as well. */
56
 
 
57
 
/* __SIGNAL_FRAMESIZE from <asm/ptrace.h> */
58
 
#define PPC_LINUX_SIGNAL_FRAMESIZE 64
59
 
 
60
 
/* From <asm/sigcontext.h>, offsetof(struct sigcontext_struct, regs) == 0x1c */
61
 
#define PPC_LINUX_REGS_PTR_OFFSET (PPC_LINUX_SIGNAL_FRAMESIZE + 0x1c)
62
 
 
63
 
/* From <asm/sigcontext.h>, 
64
 
   offsetof(struct sigcontext_struct, handler) == 0x14 */
65
 
#define PPC_LINUX_HANDLER_PTR_OFFSET (PPC_LINUX_SIGNAL_FRAMESIZE + 0x14)
66
 
 
67
 
/* From <asm/ptrace.h>, values for PT_NIP, PT_R1, and PT_LNK */
68
 
#define PPC_LINUX_PT_R0         0
69
 
#define PPC_LINUX_PT_R1         1
70
 
#define PPC_LINUX_PT_R2         2
71
 
#define PPC_LINUX_PT_R3         3
72
 
#define PPC_LINUX_PT_R4         4
73
 
#define PPC_LINUX_PT_R5         5
74
 
#define PPC_LINUX_PT_R6         6
75
 
#define PPC_LINUX_PT_R7         7
76
 
#define PPC_LINUX_PT_R8         8
77
 
#define PPC_LINUX_PT_R9         9
78
 
#define PPC_LINUX_PT_R10        10
79
 
#define PPC_LINUX_PT_R11        11
80
 
#define PPC_LINUX_PT_R12        12
81
 
#define PPC_LINUX_PT_R13        13
82
 
#define PPC_LINUX_PT_R14        14
83
 
#define PPC_LINUX_PT_R15        15
84
 
#define PPC_LINUX_PT_R16        16
85
 
#define PPC_LINUX_PT_R17        17
86
 
#define PPC_LINUX_PT_R18        18
87
 
#define PPC_LINUX_PT_R19        19
88
 
#define PPC_LINUX_PT_R20        20
89
 
#define PPC_LINUX_PT_R21        21
90
 
#define PPC_LINUX_PT_R22        22
91
 
#define PPC_LINUX_PT_R23        23
92
 
#define PPC_LINUX_PT_R24        24
93
 
#define PPC_LINUX_PT_R25        25
94
 
#define PPC_LINUX_PT_R26        26
95
 
#define PPC_LINUX_PT_R27        27
96
 
#define PPC_LINUX_PT_R28        28
97
 
#define PPC_LINUX_PT_R29        29
98
 
#define PPC_LINUX_PT_R30        30
99
 
#define PPC_LINUX_PT_R31        31
100
 
#define PPC_LINUX_PT_NIP        32
101
 
#define PPC_LINUX_PT_MSR        33
102
 
#define PPC_LINUX_PT_CTR        35
103
 
#define PPC_LINUX_PT_LNK        36
104
 
#define PPC_LINUX_PT_XER        37
105
 
#define PPC_LINUX_PT_CCR        38
106
 
#define PPC_LINUX_PT_MQ         39
107
 
#define PPC_LINUX_PT_FPR0       48      /* each FP reg occupies 2 slots in this space */
108
 
#define PPC_LINUX_PT_FPR31 (PPC_LINUX_PT_FPR0 + 2*31)
109
 
#define PPC_LINUX_PT_FPSCR (PPC_LINUX_PT_FPR0 + 2*32 + 1)
110
 
 
111
 
static int ppc_linux_at_sigtramp_return_path (CORE_ADDR pc);
112
 
 
113
 
/* Determine if pc is in a signal trampoline...
114
 
 
115
 
   Ha!  That's not what this does at all.  wait_for_inferior in
116
 
   infrun.c calls PC_IN_SIGTRAMP in order to detect entry into a
117
 
   signal trampoline just after delivery of a signal.  But on
118
 
   GNU/Linux, signal trampolines are used for the return path only.
119
 
   The kernel sets things up so that the signal handler is called
120
 
   directly.
121
 
 
122
 
   If we use in_sigtramp2() in place of in_sigtramp() (see below)
123
 
   we'll (often) end up with stop_pc in the trampoline and prev_pc in
124
 
   the (now exited) handler.  The code there will cause a temporary
125
 
   breakpoint to be set on prev_pc which is not very likely to get hit
126
 
   again.
127
 
 
128
 
   If this is confusing, think of it this way...  the code in
129
 
   wait_for_inferior() needs to be able to detect entry into a signal
130
 
   trampoline just after a signal is delivered, not after the handler
131
 
   has been run.
132
 
 
133
 
   So, we define in_sigtramp() below to return 1 if the following is
134
 
   true:
135
 
 
136
 
   1) The previous frame is a real signal trampoline.
137
 
 
138
 
   - and -
139
 
 
140
 
   2) pc is at the first or second instruction of the corresponding
141
 
   handler.
142
 
 
143
 
   Why the second instruction?  It seems that wait_for_inferior()
144
 
   never sees the first instruction when single stepping.  When a
145
 
   signal is delivered while stepping, the next instruction that
146
 
   would've been stepped over isn't, instead a signal is delivered and
147
 
   the first instruction of the handler is stepped over instead.  That
148
 
   puts us on the second instruction.  (I added the test for the
149
 
   first instruction long after the fact, just in case the observed
150
 
   behavior is ever fixed.)
151
 
 
152
 
   PC_IN_SIGTRAMP is called from blockframe.c as well in order to set
153
 
   the frame's type (if a SIGTRAMP_FRAME).  Because of our strange
154
 
   definition of in_sigtramp below, we can't rely on the frame's type
155
 
   getting set correctly from within blockframe.c.  This is why we
156
 
   take pains to set it in init_extra_frame_info().
157
 
 
158
 
   NOTE: cagney/2002-11-10: I suspect the real problem here is that
159
 
   the get_prev_frame() only initializes the frame's type after the
160
 
   call to INIT_FRAME_INFO.  get_prev_frame() should be fixed, this
161
 
   code shouldn't be working its way around a bug :-(.  */
162
 
 
163
 
int
164
 
ppc_linux_in_sigtramp (CORE_ADDR pc, char *func_name)
165
 
{
166
 
  CORE_ADDR lr;
167
 
  CORE_ADDR sp;
168
 
  CORE_ADDR tramp_sp;
169
 
  char buf[4];
170
 
  CORE_ADDR handler;
171
 
 
172
 
  lr = read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum);
173
 
  if (!ppc_linux_at_sigtramp_return_path (lr))
174
 
    return 0;
175
 
 
176
 
  sp = read_register (SP_REGNUM);
177
 
 
178
 
  if (target_read_memory (sp, buf, sizeof (buf)) != 0)
179
 
    return 0;
180
 
 
181
 
  tramp_sp = extract_unsigned_integer (buf, 4);
182
 
 
183
 
  if (target_read_memory (tramp_sp + PPC_LINUX_HANDLER_PTR_OFFSET, buf,
184
 
                          sizeof (buf)) != 0)
185
 
    return 0;
186
 
 
187
 
  handler = extract_unsigned_integer (buf, 4);
188
 
 
189
 
  return (pc == handler || pc == handler + 4);
190
 
}
191
 
 
192
 
static int
193
 
insn_is_sigreturn (unsigned long pcinsn)
194
 
{
195
 
  switch(pcinsn)
196
 
    {
197
 
    case INSTR_LI_R0_0x6666:
198
 
    case INSTR_LI_R0_0x7777:
199
 
    case INSTR_LI_R0_NR_sigreturn:
200
 
    case INSTR_LI_R0_NR_rt_sigreturn:
201
 
      return 1;
202
 
    default:
203
 
      return 0;
204
 
    }
205
 
}
206
 
 
207
 
/*
208
 
 * The signal handler trampoline is on the stack and consists of exactly
209
 
 * two instructions.  The easiest and most accurate way of determining
210
 
 * whether the pc is in one of these trampolines is by inspecting the
211
 
 * instructions.  It'd be faster though if we could find a way to do this
212
 
 * via some simple address comparisons.
213
 
 */
214
 
static int
215
 
ppc_linux_at_sigtramp_return_path (CORE_ADDR pc)
216
 
{
217
 
  char buf[12];
218
 
  unsigned long pcinsn;
219
 
  if (target_read_memory (pc - 4, buf, sizeof (buf)) != 0)
220
 
    return 0;
221
 
 
222
 
  /* extract the instruction at the pc */
223
 
  pcinsn = extract_unsigned_integer (buf + 4, 4);
224
 
 
225
 
  return (
226
 
           (insn_is_sigreturn (pcinsn)
227
 
            && extract_unsigned_integer (buf + 8, 4) == INSTR_SC)
228
 
           ||
229
 
           (pcinsn == INSTR_SC
230
 
            && insn_is_sigreturn (extract_unsigned_integer (buf, 4))));
231
 
}
232
 
 
233
 
static CORE_ADDR
234
 
ppc_linux_skip_trampoline_code (CORE_ADDR pc)
235
 
{
236
 
  char buf[4];
237
 
  struct obj_section *sect;
238
 
  struct objfile *objfile;
239
 
  unsigned long insn;
240
 
  CORE_ADDR plt_start = 0;
241
 
  CORE_ADDR symtab = 0;
242
 
  CORE_ADDR strtab = 0;
243
 
  int num_slots = -1;
244
 
  int reloc_index = -1;
245
 
  CORE_ADDR plt_table;
246
 
  CORE_ADDR reloc;
247
 
  CORE_ADDR sym;
248
 
  long symidx;
249
 
  char symname[1024];
250
 
  struct minimal_symbol *msymbol;
251
 
 
252
 
  /* Find the section pc is in; return if not in .plt */
253
 
  sect = find_pc_section (pc);
254
 
  if (!sect || strcmp (sect->the_bfd_section->name, ".plt") != 0)
255
 
    return 0;
256
 
 
257
 
  objfile = sect->objfile;
258
 
 
259
 
  /* Pick up the instruction at pc.  It had better be of the
260
 
     form
261
 
     li r11, IDX
262
 
 
263
 
     where IDX is an index into the plt_table.  */
264
 
 
265
 
  if (target_read_memory (pc, buf, 4) != 0)
266
 
    return 0;
267
 
  insn = extract_unsigned_integer (buf, 4);
268
 
 
269
 
  if ((insn & 0xffff0000) != 0x39600000 /* li r11, VAL */ )
270
 
    return 0;
271
 
 
272
 
  reloc_index = (insn << 16) >> 16;
273
 
 
274
 
  /* Find the objfile that pc is in and obtain the information
275
 
     necessary for finding the symbol name. */
276
 
  for (sect = objfile->sections; sect < objfile->sections_end; ++sect)
277
 
    {
278
 
      const char *secname = sect->the_bfd_section->name;
279
 
      if (strcmp (secname, ".plt") == 0)
280
 
        plt_start = sect->addr;
281
 
      else if (strcmp (secname, ".rela.plt") == 0)
282
 
        num_slots = ((int) sect->endaddr - (int) sect->addr) / 12;
283
 
      else if (strcmp (secname, ".dynsym") == 0)
284
 
        symtab = sect->addr;
285
 
      else if (strcmp (secname, ".dynstr") == 0)
286
 
        strtab = sect->addr;
287
 
    }
288
 
 
289
 
  /* Make sure we have all the information we need. */
290
 
  if (plt_start == 0 || num_slots == -1 || symtab == 0 || strtab == 0)
291
 
    return 0;
292
 
 
293
 
  /* Compute the value of the plt table */
294
 
  plt_table = plt_start + 72 + 8 * num_slots;
295
 
 
296
 
  /* Get address of the relocation entry (Elf32_Rela) */
297
 
  if (target_read_memory (plt_table + reloc_index, buf, 4) != 0)
298
 
    return 0;
299
 
  reloc = extract_unsigned_integer (buf, 4);
300
 
 
301
 
  sect = find_pc_section (reloc);
302
 
  if (!sect)
303
 
    return 0;
304
 
 
305
 
  if (strcmp (sect->the_bfd_section->name, ".text") == 0)
306
 
    return reloc;
307
 
 
308
 
  /* Now get the r_info field which is the relocation type and symbol
309
 
     index. */
310
 
  if (target_read_memory (reloc + 4, buf, 4) != 0)
311
 
    return 0;
312
 
  symidx = extract_unsigned_integer (buf, 4);
313
 
 
314
 
  /* Shift out the relocation type leaving just the symbol index */
315
 
  /* symidx = ELF32_R_SYM(symidx); */
316
 
  symidx = symidx >> 8;
317
 
 
318
 
  /* compute the address of the symbol */
319
 
  sym = symtab + symidx * 4;
320
 
 
321
 
  /* Fetch the string table index */
322
 
  if (target_read_memory (sym, buf, 4) != 0)
323
 
    return 0;
324
 
  symidx = extract_unsigned_integer (buf, 4);
325
 
 
326
 
  /* Fetch the string; we don't know how long it is.  Is it possible
327
 
     that the following will fail because we're trying to fetch too
328
 
     much? */
329
 
  if (target_read_memory (strtab + symidx, symname, sizeof (symname)) != 0)
330
 
    return 0;
331
 
 
332
 
  /* This might not work right if we have multiple symbols with the
333
 
     same name; the only way to really get it right is to perform
334
 
     the same sort of lookup as the dynamic linker. */
335
 
  msymbol = lookup_minimal_symbol_text (symname, NULL);
336
 
  if (!msymbol)
337
 
    return 0;
338
 
 
339
 
  return SYMBOL_VALUE_ADDRESS (msymbol);
340
 
}
341
 
 
342
 
/* The rs6000 version of FRAME_SAVED_PC will almost work for us.  The
343
 
   signal handler details are different, so we'll handle those here
344
 
   and call the rs6000 version to do the rest. */
345
 
CORE_ADDR
346
 
ppc_linux_frame_saved_pc (struct frame_info *fi)
347
 
{
348
 
  if ((get_frame_type (fi) == SIGTRAMP_FRAME))
349
 
    {
350
 
      CORE_ADDR regs_addr =
351
 
        read_memory_integer (get_frame_base (fi)
352
 
                             + PPC_LINUX_REGS_PTR_OFFSET, 4);
353
 
      /* return the NIP in the regs array */
354
 
      return read_memory_integer (regs_addr + 4 * PPC_LINUX_PT_NIP, 4);
355
 
    }
356
 
  else if (get_next_frame (fi)
357
 
           && (get_frame_type (get_next_frame (fi)) == SIGTRAMP_FRAME))
358
 
    {
359
 
      CORE_ADDR regs_addr =
360
 
        read_memory_integer (get_frame_base (get_next_frame (fi))
361
 
                             + PPC_LINUX_REGS_PTR_OFFSET, 4);
362
 
      /* return LNK in the regs array */
363
 
      return read_memory_integer (regs_addr + 4 * PPC_LINUX_PT_LNK, 4);
364
 
    }
365
 
  else
366
 
    return rs6000_frame_saved_pc (fi);
367
 
}
368
 
 
369
 
void
370
 
ppc_linux_init_extra_frame_info (int fromleaf, struct frame_info *fi)
371
 
{
372
 
  rs6000_init_extra_frame_info (fromleaf, fi);
373
 
 
374
 
  if (get_next_frame (fi) != 0)
375
 
    {
376
 
      /* We're called from get_prev_frame_info; check to see if
377
 
         this is a signal frame by looking to see if the pc points
378
 
         at trampoline code */
379
 
      if (ppc_linux_at_sigtramp_return_path (get_frame_pc (fi)))
380
 
        deprecated_set_frame_type (fi, SIGTRAMP_FRAME);
381
 
      else
382
 
        /* FIXME: cagney/2002-11-10: Is this double bogus?  What
383
 
           happens if the frame has previously been marked as a dummy?  */
384
 
        deprecated_set_frame_type (fi, NORMAL_FRAME);
385
 
    }
386
 
}
387
 
 
388
 
int
389
 
ppc_linux_frameless_function_invocation (struct frame_info *fi)
390
 
{
391
 
  /* We'll find the wrong thing if we let 
392
 
     rs6000_frameless_function_invocation () search for a signal trampoline */
393
 
  if (ppc_linux_at_sigtramp_return_path (get_frame_pc (fi)))
394
 
    return 0;
395
 
  else
396
 
    return rs6000_frameless_function_invocation (fi);
397
 
}
398
 
 
399
 
void
400
 
ppc_linux_frame_init_saved_regs (struct frame_info *fi)
401
 
{
402
 
  if ((get_frame_type (fi) == SIGTRAMP_FRAME))
403
 
    {
404
 
      CORE_ADDR regs_addr;
405
 
      int i;
406
 
      if (deprecated_get_frame_saved_regs (fi))
407
 
        return;
408
 
 
409
 
      frame_saved_regs_zalloc (fi);
410
 
 
411
 
      regs_addr =
412
 
        read_memory_integer (get_frame_base (fi)
413
 
                             + PPC_LINUX_REGS_PTR_OFFSET, 4);
414
 
      deprecated_get_frame_saved_regs (fi)[PC_REGNUM] = regs_addr + 4 * PPC_LINUX_PT_NIP;
415
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_ps_regnum] =
416
 
        regs_addr + 4 * PPC_LINUX_PT_MSR;
417
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_cr_regnum] =
418
 
        regs_addr + 4 * PPC_LINUX_PT_CCR;
419
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_lr_regnum] =
420
 
        regs_addr + 4 * PPC_LINUX_PT_LNK;
421
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum] =
422
 
        regs_addr + 4 * PPC_LINUX_PT_CTR;
423
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_xer_regnum] =
424
 
        regs_addr + 4 * PPC_LINUX_PT_XER;
425
 
      deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_mq_regnum] =
426
 
        regs_addr + 4 * PPC_LINUX_PT_MQ;
427
 
      for (i = 0; i < 32; i++)
428
 
        deprecated_get_frame_saved_regs (fi)[gdbarch_tdep (current_gdbarch)->ppc_gp0_regnum + i] =
429
 
          regs_addr + 4 * PPC_LINUX_PT_R0 + 4 * i;
430
 
      for (i = 0; i < 32; i++)
431
 
        deprecated_get_frame_saved_regs (fi)[FP0_REGNUM + i] = regs_addr + 4 * PPC_LINUX_PT_FPR0 + 8 * i;
432
 
    }
433
 
  else
434
 
    rs6000_frame_init_saved_regs (fi);
435
 
}
436
 
 
437
 
CORE_ADDR
438
 
ppc_linux_frame_chain (struct frame_info *thisframe)
439
 
{
440
 
  /* Kernel properly constructs the frame chain for the handler */
441
 
  if ((get_frame_type (thisframe) == SIGTRAMP_FRAME))
442
 
    return read_memory_integer (get_frame_base (thisframe), 4);
443
 
  else
444
 
    return rs6000_frame_chain (thisframe);
445
 
}
446
 
 
447
 
/* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
448
 
   in much the same fashion as memory_remove_breakpoint in mem-break.c,
449
 
   but is careful not to write back the previous contents if the code
450
 
   in question has changed in between inserting the breakpoint and
451
 
   removing it.
452
 
 
453
 
   Here is the problem that we're trying to solve...
454
 
 
455
 
   Once upon a time, before introducing this function to remove
456
 
   breakpoints from the inferior, setting a breakpoint on a shared
457
 
   library function prior to running the program would not work
458
 
   properly.  In order to understand the problem, it is first
459
 
   necessary to understand a little bit about dynamic linking on
460
 
   this platform.
461
 
 
462
 
   A call to a shared library function is accomplished via a bl
463
 
   (branch-and-link) instruction whose branch target is an entry
464
 
   in the procedure linkage table (PLT).  The PLT in the object
465
 
   file is uninitialized.  To gdb, prior to running the program, the
466
 
   entries in the PLT are all zeros.
467
 
 
468
 
   Once the program starts running, the shared libraries are loaded
469
 
   and the procedure linkage table is initialized, but the entries in
470
 
   the table are not (necessarily) resolved.  Once a function is
471
 
   actually called, the code in the PLT is hit and the function is
472
 
   resolved.  In order to better illustrate this, an example is in
473
 
   order; the following example is from the gdb testsuite.
474
 
            
475
 
        We start the program shmain.
476
 
 
477
 
            [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
478
 
            [...]
479
 
 
480
 
        We place two breakpoints, one on shr1 and the other on main.
481
 
 
482
 
            (gdb) b shr1
483
 
            Breakpoint 1 at 0x100409d4
484
 
            (gdb) b main
485
 
            Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
486
 
 
487
 
        Examine the instruction (and the immediatly following instruction)
488
 
        upon which the breakpoint was placed.  Note that the PLT entry
489
 
        for shr1 contains zeros.
490
 
 
491
 
            (gdb) x/2i 0x100409d4
492
 
            0x100409d4 <shr1>:      .long 0x0
493
 
            0x100409d8 <shr1+4>:    .long 0x0
494
 
 
495
 
        Now run 'til main.
496
 
 
497
 
            (gdb) r
498
 
            Starting program: gdb.base/shmain 
499
 
            Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
500
 
 
501
 
            Breakpoint 2, main ()
502
 
                at gdb.base/shmain.c:44
503
 
            44        g = 1;
504
 
 
505
 
        Examine the PLT again.  Note that the loading of the shared
506
 
        library has initialized the PLT to code which loads a constant
507
 
        (which I think is an index into the GOT) into r11 and then
508
 
        branchs a short distance to the code which actually does the
509
 
        resolving.
510
 
 
511
 
            (gdb) x/2i 0x100409d4
512
 
            0x100409d4 <shr1>:      li      r11,4
513
 
            0x100409d8 <shr1+4>:    b       0x10040984 <sg+4>
514
 
            (gdb) c
515
 
            Continuing.
516
 
 
517
 
            Breakpoint 1, shr1 (x=1)
518
 
                at gdb.base/shr1.c:19
519
 
            19        l = 1;
520
 
 
521
 
        Now we've hit the breakpoint at shr1.  (The breakpoint was
522
 
        reset from the PLT entry to the actual shr1 function after the
523
 
        shared library was loaded.) Note that the PLT entry has been
524
 
        resolved to contain a branch that takes us directly to shr1. 
525
 
        (The real one, not the PLT entry.)
526
 
 
527
 
            (gdb) x/2i 0x100409d4
528
 
            0x100409d4 <shr1>:      b       0xffaf76c <shr1>
529
 
            0x100409d8 <shr1+4>:    b       0x10040984 <sg+4>
530
 
 
531
 
   The thing to note here is that the PLT entry for shr1 has been
532
 
   changed twice.
533
 
 
534
 
   Now the problem should be obvious.  GDB places a breakpoint (a
535
 
   trap instruction) on the zero value of the PLT entry for shr1. 
536
 
   Later on, after the shared library had been loaded and the PLT
537
 
   initialized, GDB gets a signal indicating this fact and attempts
538
 
   (as it always does when it stops) to remove all the breakpoints.
539
 
 
540
 
   The breakpoint removal was causing the former contents (a zero
541
 
   word) to be written back to the now initialized PLT entry thus
542
 
   destroying a portion of the initialization that had occurred only a
543
 
   short time ago.  When execution continued, the zero word would be
544
 
   executed as an instruction an an illegal instruction trap was
545
 
   generated instead.  (0 is not a legal instruction.)
546
 
 
547
 
   The fix for this problem was fairly straightforward.  The function
548
 
   memory_remove_breakpoint from mem-break.c was copied to this file,
549
 
   modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
550
 
   In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
551
 
   function.
552
 
 
553
 
   The differences between ppc_linux_memory_remove_breakpoint () and
554
 
   memory_remove_breakpoint () are minor.  All that the former does
555
 
   that the latter does not is check to make sure that the breakpoint
556
 
   location actually contains a breakpoint (trap instruction) prior
557
 
   to attempting to write back the old contents.  If it does contain
558
 
   a trap instruction, we allow the old contents to be written back. 
559
 
   Otherwise, we silently do nothing.
560
 
 
561
 
   The big question is whether memory_remove_breakpoint () should be
562
 
   changed to have the same functionality.  The downside is that more
563
 
   traffic is generated for remote targets since we'll have an extra
564
 
   fetch of a memory word each time a breakpoint is removed.
565
 
 
566
 
   For the time being, we'll leave this self-modifying-code-friendly
567
 
   version in ppc-linux-tdep.c, but it ought to be migrated somewhere
568
 
   else in the event that some other platform has similar needs with
569
 
   regard to removing breakpoints in some potentially self modifying
570
 
   code.  */
571
 
int
572
 
ppc_linux_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
573
 
{
574
 
  const unsigned char *bp;
575
 
  int val;
576
 
  int bplen;
577
 
  char old_contents[BREAKPOINT_MAX];
578
 
 
579
 
  /* Determine appropriate breakpoint contents and size for this address.  */
580
 
  bp = BREAKPOINT_FROM_PC (&addr, &bplen);
581
 
  if (bp == NULL)
582
 
    error ("Software breakpoints not implemented for this target.");
583
 
 
584
 
  val = target_read_memory (addr, old_contents, bplen);
585
 
 
586
 
  /* If our breakpoint is no longer at the address, this means that the
587
 
     program modified the code on us, so it is wrong to put back the
588
 
     old value */
589
 
  if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
590
 
    val = target_write_memory (addr, contents_cache, bplen);
591
 
 
592
 
  return val;
593
 
}
594
 
 
595
 
/* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
596
 
   than the 32 bit SYSV R4 ABI structure return convention - all
597
 
   structures, no matter their size, are put in memory.  Vectors,
598
 
   which were added later, do get returned in a register though.  */
599
 
 
600
 
static enum return_value_convention
601
 
ppc_linux_return_value (struct gdbarch *gdbarch, struct type *valtype,
602
 
                        struct regcache *regcache, void *readbuf,
603
 
                        const void *writebuf)
604
 
{  
605
 
  if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
606
 
       || TYPE_CODE (valtype) == TYPE_CODE_UNION)
607
 
      && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
608
 
           && TYPE_VECTOR (valtype)))
609
 
    return RETURN_VALUE_STRUCT_CONVENTION;
610
 
  else
611
 
    return ppc_sysv_abi_return_value (gdbarch, valtype, regcache, readbuf,
612
 
                                      writebuf);
613
 
}
614
 
 
615
 
/* Fetch (and possibly build) an appropriate link_map_offsets
616
 
   structure for GNU/Linux PPC targets using the struct offsets
617
 
   defined in link.h (but without actual reference to that file).
618
 
 
619
 
   This makes it possible to access GNU/Linux PPC shared libraries
620
 
   from a GDB that was not built on an GNU/Linux PPC host (for cross
621
 
   debugging).  */
622
 
 
623
 
struct link_map_offsets *
624
 
ppc_linux_svr4_fetch_link_map_offsets (void)
625
 
{
626
 
  static struct link_map_offsets lmo;
627
 
  static struct link_map_offsets *lmp = NULL;
628
 
 
629
 
  if (lmp == NULL)
630
 
    {
631
 
      lmp = &lmo;
632
 
 
633
 
      lmo.r_debug_size = 8;     /* The actual size is 20 bytes, but
634
 
                                   this is all we need.  */
635
 
      lmo.r_map_offset = 4;
636
 
      lmo.r_map_size   = 4;
637
 
 
638
 
      lmo.link_map_size = 20;   /* The actual size is 560 bytes, but
639
 
                                   this is all we need.  */
640
 
      lmo.l_addr_offset = 0;
641
 
      lmo.l_addr_size   = 4;
642
 
 
643
 
      lmo.l_name_offset = 4;
644
 
      lmo.l_name_size   = 4;
645
 
 
646
 
      lmo.l_next_offset = 12;
647
 
      lmo.l_next_size   = 4;
648
 
 
649
 
      lmo.l_prev_offset = 16;
650
 
      lmo.l_prev_size   = 4;
651
 
    }
652
 
 
653
 
  return lmp;
654
 
}
655
 
 
656
 
 
657
 
/* Macros for matching instructions.  Note that, since all the
658
 
   operands are masked off before they're or-ed into the instruction,
659
 
   you can use -1 to make masks.  */
660
 
 
661
 
#define insn_d(opcd, rts, ra, d)                \
662
 
  ((((opcd) & 0x3f) << 26)                      \
663
 
   | (((rts) & 0x1f) << 21)                     \
664
 
   | (((ra) & 0x1f) << 16)                      \
665
 
   | ((d) & 0xffff))
666
 
 
667
 
#define insn_ds(opcd, rts, ra, d, xo)           \
668
 
  ((((opcd) & 0x3f) << 26)                      \
669
 
   | (((rts) & 0x1f) << 21)                     \
670
 
   | (((ra) & 0x1f) << 16)                      \
671
 
   | ((d) & 0xfffc)                             \
672
 
   | ((xo) & 0x3))
673
 
 
674
 
#define insn_xfx(opcd, rts, spr, xo)            \
675
 
  ((((opcd) & 0x3f) << 26)                      \
676
 
   | (((rts) & 0x1f) << 21)                     \
677
 
   | (((spr) & 0x1f) << 16)                     \
678
 
   | (((spr) & 0x3e0) << 6)                     \
679
 
   | (((xo) & 0x3ff) << 1))
680
 
 
681
 
/* Read a PPC instruction from memory.  PPC instructions are always
682
 
   big-endian, no matter what endianness the program is running in, so
683
 
   we can't use read_memory_integer or one of its friends here.  */
684
 
static unsigned int
685
 
read_insn (CORE_ADDR pc)
686
 
{
687
 
  unsigned char buf[4];
688
 
 
689
 
  read_memory (pc, buf, 4);
690
 
  return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
691
 
}
692
 
 
693
 
 
694
 
/* An instruction to match.  */
695
 
struct insn_pattern
696
 
{
697
 
  unsigned int mask;            /* mask the insn with this... */
698
 
  unsigned int data;            /* ...and see if it matches this. */
699
 
  int optional;                 /* If non-zero, this insn may be absent.  */
700
 
};
701
 
 
702
 
/* Return non-zero if the instructions at PC match the series
703
 
   described in PATTERN, or zero otherwise.  PATTERN is an array of
704
 
   'struct insn_pattern' objects, terminated by an entry whose mask is
705
 
   zero.
706
 
 
707
 
   When the match is successful, fill INSN[i] with what PATTERN[i]
708
 
   matched.  If PATTERN[i] is optional, and the instruction wasn't
709
 
   present, set INSN[i] to 0 (which is not a valid PPC instruction).
710
 
   INSN should have as many elements as PATTERN.  Note that, if
711
 
   PATTERN contains optional instructions which aren't present in
712
 
   memory, then INSN will have holes, so INSN[i] isn't necessarily the
713
 
   i'th instruction in memory.  */
714
 
static int
715
 
insns_match_pattern (CORE_ADDR pc,
716
 
                     struct insn_pattern *pattern,
717
 
                     unsigned int *insn)
718
 
{
719
 
  int i;
720
 
 
721
 
  for (i = 0; pattern[i].mask; i++)
722
 
    {
723
 
      insn[i] = read_insn (pc);
724
 
      if ((insn[i] & pattern[i].mask) == pattern[i].data)
725
 
        pc += 4;
726
 
      else if (pattern[i].optional)
727
 
        insn[i] = 0;
728
 
      else
729
 
        return 0;
730
 
    }
731
 
 
732
 
  return 1;
733
 
}
734
 
 
735
 
 
736
 
/* Return the 'd' field of the d-form instruction INSN, properly
737
 
   sign-extended.  */
738
 
static CORE_ADDR
739
 
insn_d_field (unsigned int insn)
740
 
{
741
 
  return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
742
 
}
743
 
 
744
 
 
745
 
/* Return the 'ds' field of the ds-form instruction INSN, with the two
746
 
   zero bits concatenated at the right, and properly
747
 
   sign-extended.  */
748
 
static CORE_ADDR
749
 
insn_ds_field (unsigned int insn)
750
 
{
751
 
  return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
752
 
}
753
 
 
754
 
 
755
 
/* If DESC is the address of a 64-bit PowerPC GNU/Linux function
756
 
   descriptor, return the descriptor's entry point.  */
757
 
static CORE_ADDR
758
 
ppc64_desc_entry_point (CORE_ADDR desc)
759
 
{
760
 
  /* The first word of the descriptor is the entry point.  */
761
 
  return (CORE_ADDR) read_memory_unsigned_integer (desc, 8);
762
 
}
763
 
 
764
 
 
765
 
/* Pattern for the standard linkage function.  These are built by
766
 
   build_plt_stub in elf64-ppc.c, whose GLINK argument is always
767
 
   zero.  */
768
 
static struct insn_pattern ppc64_standard_linkage[] =
769
 
  {
770
 
    /* addis r12, r2, <any> */
771
 
    { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
772
 
 
773
 
    /* std r2, 40(r1) */
774
 
    { -1, insn_ds (62, 2, 1, 40, 0), 0 },
775
 
 
776
 
    /* ld r11, <any>(r12) */
777
 
    { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
778
 
 
779
 
    /* addis r12, r12, 1 <optional> */
780
 
    { insn_d (-1, -1, -1, -1), insn_d (15, 12, 2, 1), 1 },
781
 
 
782
 
    /* ld r2, <any>(r12) */
783
 
    { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
784
 
 
785
 
    /* addis r12, r12, 1 <optional> */
786
 
    { insn_d (-1, -1, -1, -1), insn_d (15, 12, 2, 1), 1 },
787
 
 
788
 
    /* mtctr r11 */
789
 
    { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467),
790
 
      0 },
791
 
 
792
 
    /* ld r11, <any>(r12) */
793
 
    { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
794
 
      
795
 
    /* bctr */
796
 
    { -1, 0x4e800420, 0 },
797
 
 
798
 
    { 0, 0, 0 }
799
 
  };
800
 
#define PPC64_STANDARD_LINKAGE_LEN \
801
 
  (sizeof (ppc64_standard_linkage) / sizeof (ppc64_standard_linkage[0]))
802
 
 
803
 
 
804
 
/* Recognize a 64-bit PowerPC GNU/Linux linkage function --- what GDB
805
 
   calls a "solib trampoline".  */
806
 
static int
807
 
ppc64_in_solib_call_trampoline (CORE_ADDR pc, char *name)
808
 
{
809
 
  /* Detecting solib call trampolines on PPC64 GNU/Linux is a pain.
810
 
 
811
 
     It's not specifically solib call trampolines that are the issue.
812
 
     Any call from one function to another function that uses a
813
 
     different TOC requires a trampoline, to save the caller's TOC
814
 
     pointer and then load the callee's TOC.  An executable or shared
815
 
     library may have more than one TOC, so even intra-object calls
816
 
     may require a trampoline.  Since executable and shared libraries
817
 
     will all have their own distinct TOCs, every inter-object call is
818
 
     also an inter-TOC call, and requires a trampoline --- so "solib
819
 
     call trampolines" are just a special case.
820
 
 
821
 
     The 64-bit PowerPC GNU/Linux ABI calls these call trampolines
822
 
     "linkage functions".  Since they need to be near the functions
823
 
     that call them, they all appear in .text, not in any special
824
 
     section.  The .plt section just contains an array of function
825
 
     descriptors, from which the linkage functions load the callee's
826
 
     entry point, TOC value, and environment pointer.  So
827
 
     in_plt_section is useless.  The linkage functions don't have any
828
 
     special linker symbols to name them, either.
829
 
 
830
 
     The only way I can see to recognize them is to actually look at
831
 
     their code.  They're generated by ppc_build_one_stub and some
832
 
     other functions in bfd/elf64-ppc.c, so that should show us all
833
 
     the instruction sequences we need to recognize.  */
834
 
  unsigned int insn[PPC64_STANDARD_LINKAGE_LEN];
835
 
 
836
 
  return insns_match_pattern (pc, ppc64_standard_linkage, insn);
837
 
}
838
 
 
839
 
 
840
 
/* When the dynamic linker is doing lazy symbol resolution, the first
841
 
   call to a function in another object will go like this:
842
 
 
843
 
   - The user's function calls the linkage function:
844
 
 
845
 
     100007c4:  4b ff fc d5     bl      10000498
846
 
     100007c8:  e8 41 00 28     ld      r2,40(r1)
847
 
 
848
 
   - The linkage function loads the entry point (and other stuff) from
849
 
     the function descriptor in the PLT, and jumps to it:
850
 
 
851
 
     10000498:  3d 82 00 00     addis   r12,r2,0
852
 
     1000049c:  f8 41 00 28     std     r2,40(r1)
853
 
     100004a0:  e9 6c 80 98     ld      r11,-32616(r12)
854
 
     100004a4:  e8 4c 80 a0     ld      r2,-32608(r12)
855
 
     100004a8:  7d 69 03 a6     mtctr   r11
856
 
     100004ac:  e9 6c 80 a8     ld      r11,-32600(r12)
857
 
     100004b0:  4e 80 04 20     bctr
858
 
 
859
 
   - But since this is the first time that PLT entry has been used, it
860
 
     sends control to its glink entry.  That loads the number of the
861
 
     PLT entry and jumps to the common glink0 code:
862
 
 
863
 
     10000c98:  38 00 00 00     li      r0,0
864
 
     10000c9c:  4b ff ff dc     b       10000c78
865
 
 
866
 
   - The common glink0 code then transfers control to the dynamic
867
 
     linker's fixup code:
868
 
 
869
 
     10000c78:  e8 41 00 28     ld      r2,40(r1)
870
 
     10000c7c:  3d 82 00 00     addis   r12,r2,0
871
 
     10000c80:  e9 6c 80 80     ld      r11,-32640(r12)
872
 
     10000c84:  e8 4c 80 88     ld      r2,-32632(r12)
873
 
     10000c88:  7d 69 03 a6     mtctr   r11
874
 
     10000c8c:  e9 6c 80 90     ld      r11,-32624(r12)
875
 
     10000c90:  4e 80 04 20     bctr
876
 
 
877
 
   Eventually, this code will figure out how to skip all of this,
878
 
   including the dynamic linker.  At the moment, we just get through
879
 
   the linkage function.  */
880
 
 
881
 
/* If the current thread is about to execute a series of instructions
882
 
   at PC matching the ppc64_standard_linkage pattern, and INSN is the result
883
 
   from that pattern match, return the code address to which the
884
 
   standard linkage function will send them.  (This doesn't deal with
885
 
   dynamic linker lazy symbol resolution stubs.)  */
886
 
static CORE_ADDR
887
 
ppc64_standard_linkage_target (CORE_ADDR pc, unsigned int *insn)
888
 
{
889
 
  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
890
 
 
891
 
  /* The address of the function descriptor this linkage function
892
 
     references.  */
893
 
  CORE_ADDR desc
894
 
    = ((CORE_ADDR) read_register (tdep->ppc_gp0_regnum + 2)
895
 
       + (insn_d_field (insn[0]) << 16)
896
 
       + insn_ds_field (insn[2]));
897
 
 
898
 
  /* The first word of the descriptor is the entry point.  Return that.  */
899
 
  return ppc64_desc_entry_point (desc);
900
 
}
901
 
 
902
 
 
903
 
/* Given that we've begun executing a call trampoline at PC, return
904
 
   the entry point of the function the trampoline will go to.  */
905
 
static CORE_ADDR
906
 
ppc64_skip_trampoline_code (CORE_ADDR pc)
907
 
{
908
 
  unsigned int ppc64_standard_linkage_insn[PPC64_STANDARD_LINKAGE_LEN];
909
 
 
910
 
  if (insns_match_pattern (pc, ppc64_standard_linkage,
911
 
                           ppc64_standard_linkage_insn))
912
 
    return ppc64_standard_linkage_target (pc, ppc64_standard_linkage_insn);
913
 
  else
914
 
    return 0;
915
 
}
916
 
 
917
 
 
918
 
/* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG) on PPC64
919
 
   GNU/Linux.
920
 
 
921
 
   Usually a function pointer's representation is simply the address
922
 
   of the function. On GNU/Linux on the 64-bit PowerPC however, a
923
 
   function pointer is represented by a pointer to a TOC entry. This
924
 
   TOC entry contains three words, the first word is the address of
925
 
   the function, the second word is the TOC pointer (r2), and the
926
 
   third word is the static chain value.  Throughout GDB it is
927
 
   currently assumed that a function pointer contains the address of
928
 
   the function, which is not easy to fix.  In addition, the
929
 
   conversion of a function address to a function pointer would
930
 
   require allocation of a TOC entry in the inferior's memory space,
931
 
   with all its drawbacks.  To be able to call C++ virtual methods in
932
 
   the inferior (which are called via function pointers),
933
 
   find_function_addr uses this function to get the function address
934
 
   from a function pointer.  */
935
 
 
936
 
/* If ADDR points at what is clearly a function descriptor, transform
937
 
   it into the address of the corresponding function.  Be
938
 
   conservative, otherwize GDB will do the transformation on any
939
 
   random addresses such as occures when there is no symbol table.  */
940
 
 
941
 
static CORE_ADDR
942
 
ppc64_linux_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
943
 
                                        CORE_ADDR addr,
944
 
                                        struct target_ops *targ)
945
 
{
946
 
  struct section_table *s = target_section_by_addr (targ, addr);
947
 
 
948
 
  /* Check if ADDR points to a function descriptor.  */
949
 
  if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
950
 
    return get_target_memory_unsigned (targ, addr, 8);
951
 
 
952
 
  return addr;
953
 
}
954
 
 
955
 
#ifdef CRASH_MERGE
956
 
enum {
957
 
  PPC_ELF_NGREG = 48,
958
 
  PPC_ELF_NFPREG = 33,
959
 
  PPC_ELF_NVRREG = 33
960
 
};
961
 
 
962
 
enum {
963
 
  ELF_GREGSET_SIZE = (PPC_ELF_NGREG * 4),
964
 
  ELF_FPREGSET_SIZE = (PPC_ELF_NFPREG * 8)
965
 
};
966
 
#else
967
 
enum {
968
 
  ELF_NGREG = 48,
969
 
  ELF_NFPREG = 33,
970
 
  ELF_NVRREG = 33
971
 
};
972
 
 
973
 
enum {
974
 
  ELF_GREGSET_SIZE = (ELF_NGREG * 4),
975
 
  ELF_FPREGSET_SIZE = (ELF_NFPREG * 8)
976
 
};
977
 
#endif
978
 
 
979
 
void
980
 
ppc_linux_supply_gregset (char *buf)
981
 
{
982
 
  int regi;
983
 
  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
984
 
 
985
 
  for (regi = 0; regi < 32; regi++)
986
 
    supply_register (regi, buf + 4 * regi);
987
 
 
988
 
  supply_register (PC_REGNUM, buf + 4 * PPC_LINUX_PT_NIP);
989
 
  supply_register (tdep->ppc_lr_regnum, buf + 4 * PPC_LINUX_PT_LNK);
990
 
  supply_register (tdep->ppc_cr_regnum, buf + 4 * PPC_LINUX_PT_CCR);
991
 
  supply_register (tdep->ppc_xer_regnum, buf + 4 * PPC_LINUX_PT_XER);
992
 
  supply_register (tdep->ppc_ctr_regnum, buf + 4 * PPC_LINUX_PT_CTR);
993
 
  if (tdep->ppc_mq_regnum != -1)
994
 
    supply_register (tdep->ppc_mq_regnum, buf + 4 * PPC_LINUX_PT_MQ);
995
 
  supply_register (tdep->ppc_ps_regnum, buf + 4 * PPC_LINUX_PT_MSR);
996
 
}
997
 
 
998
 
void
999
 
ppc_linux_supply_fpregset (char *buf)
1000
 
{
1001
 
  int regi;
1002
 
  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
1003
 
 
1004
 
  for (regi = 0; regi < 32; regi++)
1005
 
    supply_register (FP0_REGNUM + regi, buf + 8 * regi);
1006
 
 
1007
 
  /* The FPSCR is stored in the low order word of the last doubleword in the
1008
 
     fpregset.  */
1009
 
  supply_register (tdep->ppc_fpscr_regnum, buf + 8 * 32 + 4);
1010
 
}
1011
 
 
1012
 
/*
1013
 
  Use a local version of this function to get the correct types for regsets.
1014
 
*/
1015
 
 
1016
 
static void
1017
 
fetch_core_registers (char *core_reg_sect,
1018
 
                      unsigned core_reg_size,
1019
 
                      int which,
1020
 
                      CORE_ADDR reg_addr)
1021
 
{
1022
 
  if (which == 0)
1023
 
    {
1024
 
      if (core_reg_size == ELF_GREGSET_SIZE)
1025
 
        ppc_linux_supply_gregset (core_reg_sect);
1026
 
      else
1027
 
        warning ("wrong size gregset struct in core file");
1028
 
    }
1029
 
  else if (which == 2)
1030
 
    {
1031
 
      if (core_reg_size == ELF_FPREGSET_SIZE)
1032
 
        ppc_linux_supply_fpregset (core_reg_sect);
1033
 
      else
1034
 
        warning ("wrong size fpregset struct in core file");
1035
 
    }
1036
 
}
1037
 
 
1038
 
/* Register that we are able to handle ELF file formats using standard
1039
 
   procfs "regset" structures.  */
1040
 
 
1041
 
static struct core_fns ppc_linux_regset_core_fns =
1042
 
{
1043
 
  bfd_target_elf_flavour,       /* core_flavour */
1044
 
  default_check_format,         /* check_format */
1045
 
  default_core_sniffer,         /* core_sniffer */
1046
 
  fetch_core_registers,         /* core_read_registers */
1047
 
  NULL                          /* next */
1048
 
};
1049
 
 
1050
 
static void
1051
 
ppc_linux_init_abi (struct gdbarch_info info,
1052
 
                    struct gdbarch *gdbarch)
1053
 
{
1054
 
  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1055
 
 
1056
 
  if (tdep->wordsize == 4)
1057
 
    {
1058
 
      /* Until November 2001, gcc did not comply with the 32 bit SysV
1059
 
         R4 ABI requirement that structures less than or equal to 8
1060
 
         bytes should be returned in registers.  Instead GCC was using
1061
 
         the the AIX/PowerOpen ABI - everything returned in memory
1062
 
         (well ignoring vectors that is).  When this was corrected, it
1063
 
         wasn't fixed for GNU/Linux native platform.  Use the
1064
 
         PowerOpen struct convention.  */
1065
 
      set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1066
 
 
1067
 
      /* Note: kevinb/2002-04-12: See note in rs6000_gdbarch_init regarding
1068
 
         *_push_arguments().  The same remarks hold for the methods below.  */
1069
 
      set_gdbarch_deprecated_frameless_function_invocation (gdbarch, ppc_linux_frameless_function_invocation);
1070
 
      set_gdbarch_deprecated_frame_chain (gdbarch, ppc_linux_frame_chain);
1071
 
      set_gdbarch_deprecated_frame_saved_pc (gdbarch, ppc_linux_frame_saved_pc);
1072
 
 
1073
 
      set_gdbarch_deprecated_frame_init_saved_regs (gdbarch,
1074
 
                                         ppc_linux_frame_init_saved_regs);
1075
 
      set_gdbarch_deprecated_init_extra_frame_info (gdbarch,
1076
 
                                         ppc_linux_init_extra_frame_info);
1077
 
 
1078
 
      set_gdbarch_memory_remove_breakpoint (gdbarch,
1079
 
                                            ppc_linux_memory_remove_breakpoint);
1080
 
      /* Shared library handling.  */
1081
 
      set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section);
1082
 
      set_gdbarch_skip_trampoline_code (gdbarch,
1083
 
                                        ppc_linux_skip_trampoline_code);
1084
 
      set_solib_svr4_fetch_link_map_offsets
1085
 
        (gdbarch, ppc_linux_svr4_fetch_link_map_offsets);
1086
 
    }
1087
 
  
1088
 
  if (tdep->wordsize == 8)
1089
 
    {
1090
 
      /* Handle PPC64 GNU/Linux function pointers (which are really
1091
 
         function descriptors).  */
1092
 
      set_gdbarch_convert_from_func_ptr_addr
1093
 
        (gdbarch, ppc64_linux_convert_from_func_ptr_addr);
1094
 
 
1095
 
      set_gdbarch_in_solib_call_trampoline
1096
 
        (gdbarch, ppc64_in_solib_call_trampoline);
1097
 
      set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1098
 
 
1099
 
      /* PPC64 malloc's entry-point is called ".malloc".  */
1100
 
      set_gdbarch_name_of_malloc (gdbarch, ".malloc");
1101
 
    }
1102
 
}
1103
 
 
1104
 
void
1105
 
_initialize_ppc_linux_tdep (void)
1106
 
{
1107
 
  /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1108
 
     64-bit PowerPC, and the older rs6k.  */
1109
 
  gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1110
 
                         ppc_linux_init_abi);
1111
 
  gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1112
 
                         ppc_linux_init_abi);
1113
 
  gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1114
 
                         ppc_linux_init_abi);
1115
 
  add_core_fns (&ppc_linux_regset_core_fns);
1116
 
}