1 /* Native-dependent code for Lynx running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1993
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include <sys/ptrace.h>
27 #include "/usr/include/sys/wait.h"
29 /* these values indicate the offset of the named register in the econtext
47 /* Currently these are not being used. So set them to 0 */
52 /* this table must line up with REGISTER_NAMES in m-i386.h */
53 static unsigned int regmap
[] =
61 /* Return the address in the core dump or inferior of register REGNO.
62 BLOCKEND is the address of the econtext structure */
65 register_addr (regno
, blockend
)
68 if (regno
< 0 || regno
>= NUM_REGS
)
69 error ("Invalid register number %d.", regno
);
71 return (blockend
+ regmap
[regno
] * sizeof (long));
74 /* Fetch one register. */
77 fetch_register (regno
, offset
, bpid
)
82 char buf
[MAX_REGISTER_RAW_SIZE
];
83 char mess
[128]; /* For messages */
86 regaddr
= register_addr (regno
, offset
);
87 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
90 *(int *) &buf
[i
] = ptrace (PTRACE_PEEKTHREAD
, bpid
,
91 (PTRACE_ARG3_TYPE
) regaddr
, 0);
92 regaddr
+= sizeof (int);
95 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
96 perror_with_name (mess
);
99 supply_register (regno
, buf
);
102 /* Store our register values back into the inferior.
103 If REGNO is -1, do this for all registers.
104 Otherwise, REGNO specifies which register (so we can save time). */
107 store_register (regno
, offset
, bpid
)
111 unsigned int regaddr
;
113 extern char registers
[];
116 regaddr
= register_addr (regno
, offset
);
117 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
120 ptrace (PTRACE_POKEUSER
, bpid
, (PTRACE_ARG3_TYPE
) regaddr
,
121 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
124 sprintf (mess
, "writing register number %d(%d)", regno
, i
);
125 perror_with_name (mess
);
127 regaddr
+= sizeof(int);
131 /* return an offset for use with register_addr() */
138 unsigned int specpage_off
, offset
= (char *) &s
.ecp
- (char *) &s
;
141 specpage_off
= ptrace (PTRACE_THREADUSER
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
143 perror_with_name ("ptrace");
145 offset
= ptrace (PTRACE_PEEKTHREAD
, pid
, (PTRACE_ARG3_TYPE
) offset
, 0)
148 perror_with_name ("ptrace");
152 /* Fetch all registers, or just one, from the child process. */
155 fetch_inferior_registers (regno
)
158 unsigned int offset
= fetch_offset (inferior_pid
);
162 for (regno
= 0; regno
< NUM_REGS
; regno
++)
163 fetch_register (regno
, offset
, inferior_pid
);
166 fetch_register (regno
, offset
, inferior_pid
);
169 /* Store all registers, or just one, to the child process. */
172 store_inferior_registers (regno
)
175 unsigned int offset
= fetch_offset (inferior_pid
);
179 for (regno
= 0; regno
< NUM_REGS
; regno
++)
180 store_register (regno
, offset
, inferior_pid
);
183 store_register (regno
, offset
, inferior_pid
);
186 /* Wait for child to do something. Return pid of child, or -1 in case
187 of error; store status through argument pointer STATUS. */
202 set_sigint_trap(); /* Causes SIGINT to be passed on to the
212 if (save_errno
== EINTR
)
214 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
215 safe_strerror (save_errno
));
216 *status
= 42; /* Claim it exited with signal 42 */
220 if (pid
!= PIDGET (inferior_pid
)) /* Some other process?!? */
223 /* thread = WIFTID (*status);*/
224 thread
= *status
>> 16;
226 /* Initial thread value can only be acquired via wait, so we have to
227 resort to this hack. */
229 if (TIDGET (inferior_pid
) == 0)
231 inferior_pid
= BUILDPID (inferior_pid
, thread
);
232 add_thread (inferior_pid
);
235 pid
= BUILDPID (pid
, thread
);
241 /* Convert a Lynx process ID to a string. Returns the string in a static
245 i386lynx_pid_to_str (pid
)
250 sprintf (buf
, "process %d thread %d", PIDGET (pid
), TIDGET (pid
));
255 /* Extract the register values out of the core file and store
256 them where `read_register' will find them.
258 CORE_REG_SECT points to the register values themselves, read into memory.
259 CORE_REG_SIZE is the size of that area.
260 WHICH says which set of registers we are handling (0 = int, 2 = float
261 on machines where they are discontiguous).
262 REG_ADDR is the offset from u.u_ar0 to the register values relative to
263 core_reg_sect. This is used with old-fashioned core files to
264 locate the registers in a large upage-plus-stack ".reg" section.
265 Original upage address X is at location core_reg_sect+x+reg_addr.
269 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
271 unsigned core_reg_size
;
276 unsigned int regno
, addr
;
278 for (regno
= 0; regno
< NUM_REGS
; regno
++)
280 addr
= register_addr (regno
, (char *) &s
.ec
- (char *) &s
);
281 supply_register (regno
, core_reg_sect
+ addr
);
This page took 0.034552 seconds and 4 git commands to generate.