summaryrefslogtreecommitdiffstats
path: root/contrib/gdb/gdb/i386bsd-tdep.c
blob: a01ed6b89e6fe4faa61bbd9107da18f27dfbdbad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Target-dependent code for i386 BSD's.
   Copyright 2001 Free Software Foundation, Inc.

   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 "frame.h"
#include "gdbcore.h"
#include "regcache.h"

/* Support for signal handlers.  */

/* Range in which to find the signaltramp routine, traditionally found
   on the use stack, just below the user area.  Initialized to values
   that work for NetBSD and FreeBSD.  */

CORE_ADDR i386bsd_sigtramp_start = 0xbfbfdf20;
CORE_ADDR i386bsd_sigtramp_end = 0xbfbfdff0;

/* Return whether PC is in a BSD sigtramp routine.  */

int
i386bsd_in_sigtramp (CORE_ADDR pc, char *name)
{
  return (pc >= i386bsd_sigtramp_start && pc < i386bsd_sigtramp_end);
}

/* Offset in the sigcontext structure of the program counter.
   Initialized to the value from 4.4 BSD Lite.  */
int i386bsd_sigcontext_pc_offset = 20;

/* Assuming FRAME is for a BSD sigtramp routine, return the address of
   the associated sigcontext structure.  */

static CORE_ADDR
i386bsd_sigcontext_addr (struct frame_info *frame)
{
  if (frame->next)
    /* If this isn't the top frame, the next frame must be for the
       signal handler itself.  A pointer to the sigcontext structure
       is passed as the third argument to the signal handler.  */
    return read_memory_unsigned_integer (frame->next->frame + 16, 4);

  /* This is the top frame.  We'll have to find the address of the
     sigcontext structure by looking at the stack pointer.  */
  return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
}

/* Assuming FRAME is for a BSD sigtramp routine, return the saved
   program counter.  */

static CORE_ADDR
i386bsd_sigtramp_saved_pc (struct frame_info *frame)
{
  CORE_ADDR addr;
  addr = i386bsd_sigcontext_addr (frame);
  return read_memory_unsigned_integer (addr + i386bsd_sigcontext_pc_offset, 4);
}

/* Return the saved program counter for FRAME.  */

CORE_ADDR
i386bsd_frame_saved_pc (struct frame_info *frame)
{
  if (frame->signal_handler_caller)
    return i386bsd_sigtramp_saved_pc (frame);

  return read_memory_unsigned_integer (frame->frame + 4, 4);
}
OpenPOWER on IntegriCloud