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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [i386fbsd-nat.c] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Native-dependent code for FreeBSD/i386.
2
 
3
   Copyright (C) 2001, 2002, 2003, 2004, 2007, 2008
4
   Free Software Foundation, Inc.
5
 
6
   This file is part of GDB.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
 
21
#include "defs.h"
22
#include "inferior.h"
23
#include "regcache.h"
24
#include "target.h"
25
 
26
#include <sys/types.h>
27
#include <sys/ptrace.h>
28
#include <sys/sysctl.h>
29
 
30
#include "fbsd-nat.h"
31
#include "i386-tdep.h"
32
#include "i386bsd-nat.h"
33
 
34
/* Resume execution of the inferior process.  If STEP is nonzero,
35
   single-step it.  If SIGNAL is nonzero, give it that signal.  */
36
 
37
static void
38
i386fbsd_resume (ptid_t ptid, int step, enum target_signal signal)
39
{
40
  pid_t pid = ptid_get_pid (ptid);
41
  int request = PT_STEP;
42
 
43
  if (pid == -1)
44
    /* Resume all threads.  This only gets used in the non-threaded
45
       case, where "resume all threads" and "resume inferior_ptid" are
46
       the same.  */
47
    pid = ptid_get_pid (inferior_ptid);
48
 
49
  if (!step)
50
    {
51
      struct regcache *regcache = get_current_regcache ();
52
      ULONGEST eflags;
53
 
54
      /* Workaround for a bug in FreeBSD.  Make sure that the trace
55
         flag is off when doing a continue.  There is a code path
56
         through the kernel which leaves the flag set when it should
57
         have been cleared.  If a process has a signal pending (such
58
         as SIGALRM) and we do a PT_STEP, the process never really has
59
         a chance to run because the kernel needs to notify the
60
         debugger that a signal is being sent.  Therefore, the process
61
         never goes through the kernel's trap() function which would
62
         normally clear it.  */
63
 
64
      regcache_cooked_read_unsigned (regcache, I386_EFLAGS_REGNUM,
65
                                     &eflags);
66
      if (eflags & 0x0100)
67
        regcache_cooked_write_unsigned (regcache, I386_EFLAGS_REGNUM,
68
                                        eflags & ~0x0100);
69
 
70
      request = PT_CONTINUE;
71
    }
72
 
73
  /* An addres of (caddr_t) 1 tells ptrace to continue from where it
74
     was.  (If GDB wanted it to start some other way, we have already
75
     written a new PC value to the child.)  */
76
  if (ptrace (request, pid, (caddr_t) 1,
77
              target_signal_to_host (signal)) == -1)
78
    perror_with_name (("ptrace"));
79
}
80
 
81
 
82
/* Support for debugging kernel virtual memory images.  */
83
 
84
#include <sys/types.h>
85
#include <machine/pcb.h>
86
 
87
#include "bsd-kvm.h"
88
 
89
static int
90
i386fbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
91
{
92
  /* The following is true for FreeBSD 4.7:
93
 
94
     The pcb contains %eip, %ebx, %esp, %ebp, %esi, %edi and %gs.
95
     This accounts for all callee-saved registers specified by the
96
     psABI and then some.  Here %esp contains the stack pointer at the
97
     point just after the call to cpu_switch().  From this information
98
     we reconstruct the register state as it would look when we just
99
     returned from cpu_switch().  */
100
 
101
  /* The stack pointer shouldn't be zero.  */
102
  if (pcb->pcb_esp == 0)
103
    return 0;
104
 
105
  pcb->pcb_esp += 4;
106
  regcache_raw_supply (regcache, I386_EDI_REGNUM, &pcb->pcb_edi);
107
  regcache_raw_supply (regcache, I386_ESI_REGNUM, &pcb->pcb_esi);
108
  regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
109
  regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
110
  regcache_raw_supply (regcache, I386_EBX_REGNUM, &pcb->pcb_ebx);
111
  regcache_raw_supply (regcache, I386_EIP_REGNUM, &pcb->pcb_eip);
112
  regcache_raw_supply (regcache, I386_GS_REGNUM, &pcb->pcb_gs);
113
 
114
  return 1;
115
}
116
 
117
 
118
/* Prevent warning from -Wmissing-prototypes.  */
119
void _initialize_i386fbsd_nat (void);
120
 
121
void
122
_initialize_i386fbsd_nat (void)
123
{
124
  struct target_ops *t;
125
 
126
  /* Add some extra features to the common *BSD/i386 target.  */
127
  t = i386bsd_target ();
128
  t->to_resume = i386fbsd_resume;
129
  t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
130
  t->to_find_memory_regions = fbsd_find_memory_regions;
131
  t->to_make_corefile_notes = fbsd_make_corefile_notes;
132
  add_target (t);
133
 
134
  /* Support debugging kernel virtual memory images.  */
135
  bsd_kvm_add_target (i386fbsd_supply_pcb);
136
 
137
  /* FreeBSD provides a kern.ps_strings sysctl that we can use to
138
     locate the sigtramp.  That way we can still recognize a sigtramp
139
     if its location is changed in a new kernel.  Of course this is
140
     still based on the assumption that the sigtramp is placed
141
     directly under the location where the program arguments and
142
     environment can be found.  */
143
#ifdef KERN_PS_STRINGS
144
  {
145
    int mib[2];
146
    u_long ps_strings;
147
    size_t len;
148
 
149
    mib[0] = CTL_KERN;
150
    mib[1] = KERN_PS_STRINGS;
151
    len = sizeof (ps_strings);
152
    if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
153
      {
154
        i386fbsd_sigtramp_start_addr = ps_strings - 128;
155
        i386fbsd_sigtramp_end_addr = ps_strings;
156
      }
157
  }
158
#endif
159
}

powered by: WebSVN 2.1.0

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