1 /* Native-dependent code for Intel 386 running LynxOS.
2 Copyright 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <sys/ptrace.h>
26 #include "/usr/include/sys/wait.h"
28 /* these values indicate the offset of the named register in the econtext
46 /* Currently these are not being used. So set them to 0 */
51 /* this table must line up with REGISTER_NAMES in m-i386.h */
52 static unsigned int regmap
[] =
60 /* Return the address in the core dump or inferior of register REGNO.
61 BLOCKEND is the address of the econtext structure */
64 register_addr (regno
, blockend
)
67 if (regno
< 0 || regno
>= NUM_REGS
)
68 error ("Invalid register number %d.", regno
);
70 return (blockend
+ regmap
[regno
] * sizeof (long));
73 /* Fetch one register. */
76 fetch_register (regno
, offset
, bpid
)
81 char buf
[MAX_REGISTER_RAW_SIZE
];
82 char mess
[128]; /* For messages */
85 regaddr
= register_addr (regno
, offset
);
86 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
89 *(int *) &buf
[i
] = ptrace (PTRACE_PEEKTHREAD
, bpid
,
90 (PTRACE_ARG3_TYPE
) regaddr
, 0);
91 regaddr
+= sizeof (int);
94 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
95 perror_with_name (mess
);
98 supply_register (regno
, buf
);
101 /* Store our register values back into the inferior.
102 If REGNO is -1, do this for all registers.
103 Otherwise, REGNO specifies which register (so we can save time). */
106 store_register (regno
, offset
, bpid
)
110 unsigned int regaddr
;
112 extern char registers
[];
115 regaddr
= register_addr (regno
, offset
);
116 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
119 ptrace (PTRACE_POKEUSER
, bpid
, (PTRACE_ARG3_TYPE
) regaddr
,
120 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
123 sprintf (mess
, "writing register number %d(%d)", regno
, i
);
124 perror_with_name (mess
);
126 regaddr
+= sizeof(int);
130 /* return an offset for use with register_addr() */
137 unsigned int specpage_off
, offset
= (char *) &s
.ecp
- (char *) &s
;
140 specpage_off
= ptrace (PTRACE_THREADUSER
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
142 perror_with_name ("ptrace");
144 offset
= ptrace (PTRACE_PEEKTHREAD
, pid
, (PTRACE_ARG3_TYPE
) offset
, 0)
147 perror_with_name ("ptrace");
151 /* Fetch all registers, or just one, from the child process. */
154 fetch_inferior_registers (regno
)
157 unsigned int offset
= fetch_offset (inferior_pid
);
161 for (regno
= 0; regno
< NUM_REGS
; regno
++)
162 fetch_register (regno
, offset
, inferior_pid
);
165 fetch_register (regno
, offset
, inferior_pid
);
168 /* Store all registers, or just one, to the child process. */
171 store_inferior_registers (regno
)
174 unsigned int offset
= fetch_offset (inferior_pid
);
178 for (regno
= 0; regno
< NUM_REGS
; regno
++)
179 store_register (regno
, offset
, inferior_pid
);
182 store_register (regno
, offset
, inferior_pid
);
185 /* Wait for child to do something. Return pid of child, or -1 in case
186 of error; store status through argument pointer STATUS. */
189 child_wait (pid
, status
)
201 set_sigint_trap(); /* Causes SIGINT to be passed on to the
211 if (save_errno
== EINTR
)
213 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
214 safe_strerror (save_errno
));
215 *status
= 42; /* Claim it exited with signal 42 */
219 if (pid
!= PIDGET (inferior_pid
)) /* Some other process?!? */
222 /* thread = WIFTID (*status);*/
223 thread
= *status
>> 16;
225 /* Initial thread value can only be acquired via wait, so we have to
226 resort to this hack. */
228 if (TIDGET (inferior_pid
) == 0)
230 inferior_pid
= BUILDPID (inferior_pid
, thread
);
231 add_thread (inferior_pid
);
234 pid
= BUILDPID (pid
, thread
);
240 /* Convert a Lynx process ID to a string. Returns the string in a static
244 i386lynx_pid_to_str (pid
)
249 sprintf (buf
, "process %d thread %d", PIDGET (pid
), TIDGET (pid
));
254 /* Extract the register values out of the core file and store
255 them where `read_register' will find them.
257 CORE_REG_SECT points to the register values themselves, read into memory.
258 CORE_REG_SIZE is the size of that area.
259 WHICH says which set of registers we are handling (0 = int, 2 = float
260 on machines where they are discontiguous).
261 REG_ADDR is the offset from u.u_ar0 to the register values relative to
262 core_reg_sect. This is used with old-fashioned core files to
263 locate the registers in a large upage-plus-stack ".reg" section.
264 Original upage address X is at location core_reg_sect+x+reg_addr.
268 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
270 unsigned core_reg_size
;
275 unsigned int regno
, addr
;
277 for (regno
= 0; regno
< NUM_REGS
; regno
++)
279 addr
= register_addr (regno
, (char *) &s
.ec
- (char *) &s
);
280 supply_register (regno
, core_reg_sect
+ addr
);
This page took 0.037495 seconds and 4 git commands to generate.