* ldlang.c (dprint_statement): Stop printing at end of list.
[deliverable/binutils-gdb.git] / gdb / lynx-nat.c
CommitLineData
d3225ea0 1/* Native-dependent code for LynxOS.
658821b9 2 Copyright 1993, 1994 Free Software Foundation, Inc.
d3225ea0
SG
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
d3225ea0
SG
19
20#include "defs.h"
21#include "frame.h"
22#include "inferior.h"
23#include "target.h"
3730a0ed 24#include "gdbcore.h"
d3225ea0
SG
25
26#include <sys/ptrace.h>
658821b9 27#include <sys/wait.h>
d575ddc0 28#include <sys/fpp.h>
d3225ea0
SG
29
30static unsigned long registers_addr PARAMS ((int pid));
31
32#define X(ENTRY)(offsetof(struct econtext, ENTRY))
33
34#ifdef I386
35/* Mappings from tm-i386v.h */
36
37static int regmap[] =
38{
39 X(eax),
40 X(ecx),
41 X(edx),
42 X(ebx),
43 X(esp), /* sp */
44 X(ebp), /* fp */
45 X(esi),
46 X(edi),
47 X(eip), /* pc */
48 X(flags), /* ps */
49 X(cs),
50 X(ss),
51 X(ds),
52 X(es),
53 X(ecode), /* Lynx doesn't give us either fs or gs, so */
54 X(fault), /* we just substitute these two in the hopes
55 that they are useful. */
56};
790a14a8 57#endif /* I386 */
d3225ea0
SG
58
59#ifdef M68K
60/* Mappings from tm-m68k.h */
61
62static int regmap[] =
63{
64 X(regs[0]), /* d0 */
65 X(regs[1]), /* d1 */
66 X(regs[2]), /* d2 */
67 X(regs[3]), /* d3 */
68 X(regs[4]), /* d4 */
69 X(regs[5]), /* d5 */
70 X(regs[6]), /* d6 */
71 X(regs[7]), /* d7 */
72 X(regs[8]), /* a0 */
73 X(regs[9]), /* a1 */
74 X(regs[10]), /* a2 */
75 X(regs[11]), /* a3 */
76 X(regs[12]), /* a4 */
77 X(regs[13]), /* a5 */
78 X(regs[14]), /* fp */
79 offsetof (st_t, usp) - offsetof (st_t, ec), /* sp */
80 X(status), /* ps */
81 X(pc),
82
83 X(fregs[0*3]), /* fp0 */
84 X(fregs[1*3]), /* fp1 */
85 X(fregs[2*3]), /* fp2 */
86 X(fregs[3*3]), /* fp3 */
87 X(fregs[4*3]), /* fp4 */
88 X(fregs[5*3]), /* fp5 */
89 X(fregs[6*3]), /* fp6 */
90 X(fregs[7*3]), /* fp7 */
91
92 X(fcregs[0]), /* fpcontrol */
93 X(fcregs[1]), /* fpstatus */
94 X(fcregs[2]), /* fpiaddr */
95 X(ssw), /* fpcode */
96 X(fault), /* fpflags */
97};
790a14a8
SG
98#endif /* M68K */
99
100#ifdef SPARC
101/* Mappings from tm-sparc.h */
102
103#define FX(ENTRY)(offsetof(struct fcontext, ENTRY))
104
105static int regmap[] =
106{
107 -1, /* g0 */
108 X(g1),
109 X(g2),
110 X(g3),
111 X(g4),
112 -1, /* g5->g7 aren't saved by Lynx */
113 -1,
114 -1,
115
116 X(o[0]),
117 X(o[1]),
118 X(o[2]),
119 X(o[3]),
120 X(o[4]),
121 X(o[5]),
122 X(o[6]), /* sp */
123 X(o[7]), /* ra */
124
125 -1,-1,-1,-1,-1,-1,-1,-1, /* l0 -> l7 */
126
127 -1,-1,-1,-1,-1,-1,-1,-1, /* i0 -> i7 */
128
129 FX(f.fregs[0]), /* f0 */
130 FX(f.fregs[1]),
131 FX(f.fregs[2]),
132 FX(f.fregs[3]),
133 FX(f.fregs[4]),
134 FX(f.fregs[5]),
135 FX(f.fregs[6]),
136 FX(f.fregs[7]),
137 FX(f.fregs[8]),
138 FX(f.fregs[9]),
139 FX(f.fregs[10]),
140 FX(f.fregs[11]),
141 FX(f.fregs[12]),
142 FX(f.fregs[13]),
143 FX(f.fregs[14]),
144 FX(f.fregs[15]),
145 FX(f.fregs[16]),
146 FX(f.fregs[17]),
147 FX(f.fregs[18]),
148 FX(f.fregs[19]),
149 FX(f.fregs[20]),
150 FX(f.fregs[21]),
151 FX(f.fregs[22]),
152 FX(f.fregs[23]),
153 FX(f.fregs[24]),
154 FX(f.fregs[25]),
155 FX(f.fregs[26]),
156 FX(f.fregs[27]),
157 FX(f.fregs[28]),
158 FX(f.fregs[29]),
159 FX(f.fregs[30]),
160 FX(f.fregs[31]),
161
162 X(y),
163 X(psr),
164 X(wim),
165 X(tbr),
166 X(pc),
167 X(npc),
168 FX(fsr), /* fpsr */
169 -1, /* cpsr */
170};
171#endif /* SPARC */
d3225ea0 172
d87d7b10 173#ifdef rs6000
d575ddc0
SG
174
175static int regmap[] =
176{
d87d7b10
SG
177 X(iregs[0]), /* r0 */
178 X(iregs[1]),
179 X(iregs[2]),
180 X(iregs[3]),
181 X(iregs[4]),
182 X(iregs[5]),
183 X(iregs[6]),
184 X(iregs[7]),
185 X(iregs[8]),
186 X(iregs[9]),
187 X(iregs[10]),
188 X(iregs[11]),
189 X(iregs[12]),
190 X(iregs[13]),
191 X(iregs[14]),
192 X(iregs[15]),
193 X(iregs[16]),
194 X(iregs[17]),
195 X(iregs[18]),
196 X(iregs[19]),
197 X(iregs[20]),
198 X(iregs[21]),
199 X(iregs[22]),
200 X(iregs[23]),
201 X(iregs[24]),
202 X(iregs[25]),
203 X(iregs[26]),
204 X(iregs[27]),
205 X(iregs[28]),
206 X(iregs[29]),
207 X(iregs[30]),
208 X(iregs[31]),
209
210 X(fregs[0]), /* f0 */
211 X(fregs[1]),
212 X(fregs[2]),
213 X(fregs[3]),
214 X(fregs[4]),
215 X(fregs[5]),
216 X(fregs[6]),
217 X(fregs[7]),
218 X(fregs[8]),
219 X(fregs[9]),
220 X(fregs[10]),
221 X(fregs[11]),
222 X(fregs[12]),
223 X(fregs[13]),
224 X(fregs[14]),
225 X(fregs[15]),
226 X(fregs[16]),
227 X(fregs[17]),
228 X(fregs[18]),
229 X(fregs[19]),
230 X(fregs[20]),
231 X(fregs[21]),
232 X(fregs[22]),
233 X(fregs[23]),
234 X(fregs[24]),
235 X(fregs[25]),
236 X(fregs[26]),
237 X(fregs[27]),
238 X(fregs[28]),
239 X(fregs[29]),
240 X(fregs[30]),
241 X(fregs[31]),
242
243 X(srr0), /* IAR (PC) */
244 X(srr1), /* MSR (PS) */
245 X(cr), /* CR */
246 X(lr), /* LR */
247 X(ctr), /* CTR */
248 X(xer), /* XER */
249 X(mq) /* MQ */
d575ddc0 250};
d87d7b10
SG
251
252#endif /* rs6000 */
d575ddc0
SG
253
254#ifdef SPARC
255
256/* This routine handles some oddball cases for Sparc registers and LynxOS.
257 In partucular, it causes refs to G0, g5->7, and all fp regs to return zero.
258 It also handles knows where to find the I & L regs on the stack. */
259
260void
261fetch_inferior_registers (regno)
262 int regno;
263{
264 int whatregs = 0;
265
266#define WHATREGS_FLOAT 1
267#define WHATREGS_GEN 2
268#define WHATREGS_STACK 4
269
270 if (regno == -1)
271 whatregs = WHATREGS_FLOAT | WHATREGS_GEN | WHATREGS_STACK;
272 else if (regno >= L0_REGNUM && regno <= I7_REGNUM)
273 whatregs = WHATREGS_STACK;
274 else if (regno >= FP0_REGNUM && regno < FP0_REGNUM + 32)
275 whatregs = WHATREGS_FLOAT;
276 else
277 whatregs = WHATREGS_GEN;
278
279 if (whatregs & WHATREGS_GEN)
280 {
281 struct econtext ec; /* general regs */
282 char buf[MAX_REGISTER_RAW_SIZE];
283 int retval;
284 int i;
285
286 errno = 0;
287 retval = ptrace (PTRACE_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &ec,
288 0);
289 if (errno)
d87d7b10 290 perror_with_name ("ptrace(PTRACE_GETREGS)");
d575ddc0
SG
291
292 memset (buf, 0, REGISTER_RAW_SIZE (G0_REGNUM));
293 supply_register (G0_REGNUM, buf);
294 supply_register (TBR_REGNUM, (char *)&ec.tbr);
295
296 memcpy (&registers[REGISTER_BYTE (G1_REGNUM)], &ec.g1,
297 4 * REGISTER_RAW_SIZE (G1_REGNUM));
298 for (i = G1_REGNUM; i <= G1_REGNUM + 3; i++)
299 register_valid[i] = 1;
300
301 supply_register (PS_REGNUM, (char *)&ec.psr);
302 supply_register (Y_REGNUM, (char *)&ec.y);
303 supply_register (PC_REGNUM, (char *)&ec.pc);
304 supply_register (NPC_REGNUM, (char *)&ec.npc);
305 supply_register (WIM_REGNUM, (char *)&ec.wim);
306
307 memcpy (&registers[REGISTER_BYTE (O0_REGNUM)], ec.o,
308 8 * REGISTER_RAW_SIZE (O0_REGNUM));
309 for (i = O0_REGNUM; i <= O0_REGNUM + 7; i++)
310 register_valid[i] = 1;
311 }
312
313 if (whatregs & WHATREGS_STACK)
314 {
315 CORE_ADDR sp;
316 int i;
317
318 sp = read_register (SP_REGNUM);
319
8bf94f44
SG
320 target_xfer_memory (sp + FRAME_SAVED_I0,
321 &registers[REGISTER_BYTE(I0_REGNUM)],
d575ddc0
SG
322 8 * REGISTER_RAW_SIZE (I0_REGNUM), 0);
323 for (i = I0_REGNUM; i <= I7_REGNUM; i++)
324 register_valid[i] = 1;
325
8bf94f44
SG
326 target_xfer_memory (sp + FRAME_SAVED_L0,
327 &registers[REGISTER_BYTE(L0_REGNUM)],
d575ddc0
SG
328 8 * REGISTER_RAW_SIZE (L0_REGNUM), 0);
329 for (i = L0_REGNUM; i <= L0_REGNUM + 7; i++)
330 register_valid[i] = 1;
331 }
332
333 if (whatregs & WHATREGS_FLOAT)
334 {
335 struct fcontext fc; /* fp regs */
336 int retval;
337 int i;
338
339 errno = 0;
340 retval = ptrace (PTRACE_GETFPREGS, inferior_pid, (PTRACE_ARG3_TYPE) &fc,
341 0);
342 if (errno)
d87d7b10 343 perror_with_name ("ptrace(PTRACE_GETFPREGS)");
d575ddc0
SG
344
345 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], fc.f.fregs,
346 32 * REGISTER_RAW_SIZE (FP0_REGNUM));
347 for (i = FP0_REGNUM; i <= FP0_REGNUM + 31; i++)
348 register_valid[i] = 1;
349
350 supply_register (FPS_REGNUM, (char *)&fc.fsr);
351 }
352}
353
354/* This routine handles storing of the I & L regs for the Sparc. The trick
355 here is that they actually live on the stack. The really tricky part is
356 that when changing the stack pointer, the I & L regs must be written to
357 where the new SP points, otherwise the regs will be incorrect when the
358 process is started up again. We assume that the I & L regs are valid at
359 this point. */
360
361void
362store_inferior_registers (regno)
363 int regno;
364{
365 int whatregs = 0;
366
367 if (regno == -1)
368 whatregs = WHATREGS_FLOAT | WHATREGS_GEN | WHATREGS_STACK;
369 else if (regno >= L0_REGNUM && regno <= I7_REGNUM)
370 whatregs = WHATREGS_STACK;
371 else if (regno >= FP0_REGNUM && regno < FP0_REGNUM + 32)
372 whatregs = WHATREGS_FLOAT;
373 else if (regno == SP_REGNUM)
374 whatregs = WHATREGS_STACK | WHATREGS_GEN;
375 else
376 whatregs = WHATREGS_GEN;
377
378 if (whatregs & WHATREGS_GEN)
379 {
380 struct econtext ec; /* general regs */
381 int retval;
382
383 ec.tbr = read_register (TBR_REGNUM);
384 memcpy (&ec.g1, &registers[REGISTER_BYTE (G1_REGNUM)],
385 4 * REGISTER_RAW_SIZE (G1_REGNUM));
386
387 ec.psr = read_register (PS_REGNUM);
388 ec.y = read_register (Y_REGNUM);
389 ec.pc = read_register (PC_REGNUM);
390 ec.npc = read_register (NPC_REGNUM);
391 ec.wim = read_register (WIM_REGNUM);
392
393 memcpy (ec.o, &registers[REGISTER_BYTE (O0_REGNUM)],
394 8 * REGISTER_RAW_SIZE (O0_REGNUM));
395
396 errno = 0;
397 retval = ptrace (PTRACE_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &ec,
398 0);
399 if (errno)
d87d7b10 400 perror_with_name ("ptrace(PTRACE_SETREGS)");
d575ddc0
SG
401 }
402
403 if (whatregs & WHATREGS_STACK)
404 {
405 int regoffset;
406 CORE_ADDR sp;
407
408 sp = read_register (SP_REGNUM);
409
410 if (regno == -1 || regno == SP_REGNUM)
411 {
412 if (!register_valid[L0_REGNUM+5])
413 abort();
8bf94f44
SG
414 target_xfer_memory (sp + FRAME_SAVED_I0,
415 &registers[REGISTER_BYTE (I0_REGNUM)],
d575ddc0 416 8 * REGISTER_RAW_SIZE (I0_REGNUM), 1);
8bf94f44
SG
417
418 target_xfer_memory (sp + FRAME_SAVED_L0,
419 &registers[REGISTER_BYTE (L0_REGNUM)],
d575ddc0
SG
420 8 * REGISTER_RAW_SIZE (L0_REGNUM), 1);
421 }
422 else if (regno >= L0_REGNUM && regno <= I7_REGNUM)
423 {
424 if (!register_valid[regno])
425 abort();
426 if (regno >= L0_REGNUM && regno <= L0_REGNUM + 7)
427 regoffset = REGISTER_BYTE (regno) - REGISTER_BYTE (L0_REGNUM)
8bf94f44 428 + FRAME_SAVED_L0;
d575ddc0 429 else
8bf94f44
SG
430 regoffset = REGISTER_BYTE (regno) - REGISTER_BYTE (I0_REGNUM)
431 + FRAME_SAVED_I0;
d575ddc0
SG
432 target_xfer_memory (sp + regoffset, &registers[REGISTER_BYTE (regno)],
433 REGISTER_RAW_SIZE (regno), 1);
434 }
435 }
436
437 if (whatregs & WHATREGS_FLOAT)
438 {
439 struct fcontext fc; /* fp regs */
440 int retval;
441
442/* We read fcontext first so that we can get good values for fq_t... */
443 errno = 0;
444 retval = ptrace (PTRACE_GETFPREGS, inferior_pid, (PTRACE_ARG3_TYPE) &fc,
445 0);
446 if (errno)
d87d7b10 447 perror_with_name ("ptrace(PTRACE_GETFPREGS)");
d575ddc0
SG
448
449 memcpy (fc.f.fregs, &registers[REGISTER_BYTE (FP0_REGNUM)],
450 32 * REGISTER_RAW_SIZE (FP0_REGNUM));
451
452 fc.fsr = read_register (FPS_REGNUM);
453
454 errno = 0;
455 retval = ptrace (PTRACE_SETFPREGS, inferior_pid, (PTRACE_ARG3_TYPE) &fc,
456 0);
457 if (errno)
d87d7b10 458 perror_with_name ("ptrace(PTRACE_SETFPREGS)");
d575ddc0
SG
459 }
460}
e90445c9 461#endif /* SPARC */
d575ddc0 462
d87d7b10 463#if defined (I386) || defined (M68K) || defined (rs6000)
d575ddc0 464
d3225ea0
SG
465/* Return the offset relative to the start of the per-thread data to the
466 saved context block. */
467
468static unsigned long
469registers_addr(pid)
470 int pid;
471{
472 CORE_ADDR stblock;
473 int ecpoff = offsetof(st_t, ecp);
474 CORE_ADDR ecp;
475
476 errno = 0;
477 stblock = (CORE_ADDR) ptrace (PTRACE_THREADUSER, pid, (PTRACE_ARG3_TYPE)0,
478 0);
479 if (errno)
d87d7b10 480 perror_with_name ("ptrace(PTRACE_THREADUSER)");
d3225ea0
SG
481
482 ecp = (CORE_ADDR) ptrace (PTRACE_PEEKTHREAD, pid, (PTRACE_ARG3_TYPE)ecpoff,
483 0);
484 if (errno)
d87d7b10 485 perror_with_name ("ptrace(PTRACE_PEEKTHREAD)");
d3225ea0
SG
486
487 return ecp - stblock;
488}
489
490/* Fetch one or more registers from the inferior. REGNO == -1 to get
491 them all. We actually fetch more than requested, when convenient,
492 marking them as valid so we won't fetch them again. */
493
494void
495fetch_inferior_registers (regno)
496 int regno;
497{
498 int reglo, reghi;
499 int i;
500 unsigned long ecp;
501
502 if (regno == -1)
503 {
504 reglo = 0;
505 reghi = NUM_REGS - 1;
506 }
507 else
508 reglo = reghi = regno;
509
510 ecp = registers_addr (inferior_pid);
511
e90445c9 512 for (regno = reglo; regno <= reghi; regno++)
d3225ea0
SG
513 {
514 char buf[MAX_REGISTER_RAW_SIZE];
515 int ptrace_fun = PTRACE_PEEKTHREAD;
516
d87d7b10 517#ifdef M68K
d3225ea0
SG
518 ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD;
519#endif
520
521 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
522 {
523 unsigned int reg;
524
525 errno = 0;
526 reg = ptrace (ptrace_fun, inferior_pid,
527 (PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), 0);
528 if (errno)
d87d7b10 529 perror_with_name ("ptrace(PTRACE_PEEKUSP)");
d3225ea0
SG
530
531 *(int *)&buf[i] = reg;
532 }
533 supply_register (regno, buf);
534 }
535}
536
537/* Store our register values back into the inferior.
538 If REGNO is -1, do this for all registers.
539 Otherwise, REGNO specifies which register (so we can save time). */
540
aa175216
SS
541/* Registers we shouldn't try to store. */
542#if !defined (CANNOT_STORE_REGISTER)
543#define CANNOT_STORE_REGISTER(regno) 0
544#endif
545
d3225ea0
SG
546void
547store_inferior_registers (regno)
548 int regno;
549{
550 int reglo, reghi;
551 int i;
552 unsigned long ecp;
553
554 if (regno == -1)
555 {
556 reglo = 0;
557 reghi = NUM_REGS - 1;
558 }
559 else
560 reglo = reghi = regno;
561
562 ecp = registers_addr (inferior_pid);
563
e90445c9 564 for (regno = reglo; regno <= reghi; regno++)
d3225ea0
SG
565 {
566 int ptrace_fun = PTRACE_POKEUSER;
567
d87d7b10
SG
568 if (CANNOT_STORE_REGISTER (regno))
569 continue;
570
571#ifdef M68K
d3225ea0
SG
572 ptrace_fun = regno == SP_REGNUM ? PTRACE_POKEUSP : PTRACE_POKEUSER;
573#endif
574
575 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
576 {
577 unsigned int reg;
578
579 reg = *(unsigned int *)&registers[REGISTER_BYTE (regno) + i];
580
581 errno = 0;
582 ptrace (ptrace_fun, inferior_pid,
583 (PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), reg);
584 if (errno)
d87d7b10 585 perror_with_name ("ptrace(PTRACE_POKEUSP)");
d3225ea0
SG
586 }
587 }
588}
d87d7b10 589#endif /* defined (I386) || defined (M68K) || defined (rs6000) */
d3225ea0
SG
590
591/* Wait for child to do something. Return pid of child, or -1 in case
67ac9759 592 of error; store status through argument pointer OURSTATUS. */
d3225ea0
SG
593
594int
2919ae5a 595child_wait (pid, ourstatus)
d3225ea0 596 int pid;
67ac9759 597 struct target_waitstatus *ourstatus;
d3225ea0
SG
598{
599 int save_errno;
600 int thread;
320f93f7 601 union wait status;
d3225ea0
SG
602
603 while (1)
604 {
605 int sig;
606
1e75b5f5 607 set_sigint_trap(); /* Causes SIGINT to be passed on to the
d3225ea0 608 attached process. */
d575ddc0 609 pid = wait (&status);
d575ddc0 610
d3225ea0
SG
611 save_errno = errno;
612
1e75b5f5 613 clear_sigint_trap();
d3225ea0
SG
614
615 if (pid == -1)
616 {
617 if (save_errno == EINTR)
618 continue;
619 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing: %s.\n",
620 safe_strerror (save_errno));
67ac9759
JK
621 /* Claim it exited with unknown signal. */
622 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
623 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
d3225ea0
SG
624 return -1;
625 }
626
627 if (pid != PIDGET (inferior_pid)) /* Some other process?!? */
628 continue;
629
320f93f7 630 thread = status.w_tid; /* Get thread id from status */
d3225ea0
SG
631
632 /* Initial thread value can only be acquired via wait, so we have to
633 resort to this hack. */
634
5c54124b 635 if (TIDGET (inferior_pid) == 0 && thread != 0)
d3225ea0
SG
636 {
637 inferior_pid = BUILDPID (inferior_pid, thread);
638 add_thread (inferior_pid);
639 }
640
641 pid = BUILDPID (pid, thread);
642
5c54124b
JL
643 /* We've become a single threaded process again. */
644 if (thread == 0)
645 inferior_pid = pid;
646
647 /* Check for thread creation. */
320f93f7
SG
648 if (WIFSTOPPED(status)
649 && WSTOPSIG(status) == SIGTRAP
650 && !in_thread_list (pid))
651 {
652 int realsig;
653
6adffcd8 654 realsig = ptrace (PTRACE_GETTRACESIG, pid, (PTRACE_ARG3_TYPE)0, 0);
320f93f7
SG
655
656 if (realsig == SIGNEWTHREAD)
657 {
1657d50b
JL
658 /* It's a new thread notification. Nothing to do here since
659 the machine independent code in wait_for_inferior will
660 add the thread to the thread list and restart the thread
661 when pid != inferior_pid and pid is not in the thread
662 list. We don't even want to much with realsig -- the
663 code in wait_for_inferior expects SIGTRAP. */
664 ;
320f93f7 665 }
1657d50b
JL
666 else
667 error ("Signal for unknown thread was not SIGNEWTHREAD");
320f93f7
SG
668 }
669
b3393912
JL
670 /* Check for thread termination. */
671 else if (WIFSTOPPED(status)
672 && WSTOPSIG(status) == SIGTRAP
673 && in_thread_list (pid))
674 {
675 int realsig;
676
677 realsig = ptrace (PTRACE_GETTRACESIG, pid, (PTRACE_ARG3_TYPE)0, 0);
678
679 if (realsig == SIGTHREADEXIT)
680 {
681 ptrace (PTRACE_CONT, PIDGET (pid), (PTRACE_ARG3_TYPE)0, 0);
682 continue;
683 }
684 }
685
60e86a67
ILT
686#ifdef SPARC
687 /* SPARC Lynx uses an byte reversed wait status; we must use the
688 host macros to access it. These lines just a copy of
689 store_waitstatus. We can't use CHILD_SPECIAL_WAITSTATUS
690 because target.c can't include the Lynx <sys/wait.h>. */
691 if (WIFEXITED (status))
692 {
693 ourstatus->kind = TARGET_WAITKIND_EXITED;
694 ourstatus->value.integer = WEXITSTATUS (status);
695 }
696 else if (!WIFSTOPPED (status))
697 {
698 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
699 ourstatus->value.sig =
700 target_signal_from_host (WTERMSIG (status));
701 }
702 else
703 {
704 ourstatus->kind = TARGET_WAITKIND_STOPPED;
705 ourstatus->value.sig =
706 target_signal_from_host (WSTOPSIG (status));
707 }
708#else
320f93f7 709 store_waitstatus (ourstatus, status.w_status);
60e86a67 710#endif
67ac9759 711
d3225ea0
SG
712 return pid;
713 }
714}
715
f8c90568
JL
716/* Return nonzero if the given thread is still alive. */
717int
718child_thread_alive (pid)
719 int pid;
720{
721 /* Arggh. Apparently pthread_kill only works for threads within
722 the process that calls pthread_kill.
723
724 We want to avoid the lynx signal extensions as they simply don't
725 map well to the generic gdb interface we want to keep.
726
727 All we want to do is determine if a particular thread is alive;
728 it appears as if we can just make a harmless thread specific
729 ptrace call to do that. */
730 return (ptrace (PTRACE_THREADUSER, pid, 0, 0) != -1);
731}
732
2e6784a8
SG
733/* Resume execution of the inferior process.
734 If STEP is nonzero, single-step it.
735 If SIGNAL is nonzero, give it that signal. */
736
737void
738child_resume (pid, step, signal)
739 int pid;
740 int step;
741 enum target_signal signal;
742{
320f93f7
SG
743 int func;
744
2e6784a8
SG
745 errno = 0;
746
48f4903f
JL
747 /* If pid == -1, then we want to step/continue all threads, else
748 we only want to step/continue a single thread. */
2e6784a8 749 if (pid == -1)
320f93f7 750 {
320f93f7 751 pid = inferior_pid;
48f4903f 752 func = step ? PTRACE_SINGLESTEP : PTRACE_CONT;
320f93f7 753 }
48f4903f
JL
754 else
755 func = step ? PTRACE_SINGLESTEP_ONE : PTRACE_CONT_ONE;
320f93f7 756
2e6784a8
SG
757
758 /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where
759 it was. (If GDB wanted it to start some other way, we have already
760 written a new PC value to the child.)
761
762 If this system does not support PT_STEP, a higher level function will
763 have called single_step() to transmute the step request into a
764 continue request (by setting breakpoints on all possible successor
765 instructions), so we don't have to worry about that here. */
766
320f93f7 767 ptrace (func, pid, (PTRACE_ARG3_TYPE) 1, target_signal_to_host (signal));
2e6784a8
SG
768
769 if (errno)
770 perror_with_name ("ptrace");
771}
772
d3225ea0
SG
773/* Convert a Lynx process ID to a string. Returns the string in a static
774 buffer. */
775
776char *
777lynx_pid_to_str (pid)
778 int pid;
779{
780 static char buf[40];
781
782 sprintf (buf, "process %d thread %d", PIDGET (pid), TIDGET (pid));
783
784 return buf;
785}
786
787/* Extract the register values out of the core file and store
788 them where `read_register' will find them.
789
790 CORE_REG_SECT points to the register values themselves, read into memory.
791 CORE_REG_SIZE is the size of that area.
792 WHICH says which set of registers we are handling (0 = int, 2 = float
793 on machines where they are discontiguous).
794 REG_ADDR is the offset from u.u_ar0 to the register values relative to
795 core_reg_sect. This is used with old-fashioned core files to
796 locate the registers in a large upage-plus-stack ".reg" section.
797 Original upage address X is at location core_reg_sect+x+reg_addr.
798 */
799
a1df8e78 800static void
d3225ea0
SG
801fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
802 char *core_reg_sect;
803 unsigned core_reg_size;
804 int which;
805 unsigned reg_addr;
806{
807 struct st_entry s;
808 unsigned int regno;
809
810 for (regno = 0; regno < NUM_REGS; regno++)
60e86a67
ILT
811 if (regmap[regno] != -1)
812 supply_register (regno, core_reg_sect + offsetof (st_t, ec)
813 + regmap[regno]);
e90445c9
SG
814
815#ifdef SPARC
816/* Fetching this register causes all of the I & L regs to be read from the
817 stack and validated. */
818
819 fetch_inferior_registers (I0_REGNUM);
820#endif
d3225ea0 821}
a1df8e78
FF
822
823\f
824/* Register that we are able to handle lynx core file formats.
825 FIXME: is this really bfd_target_unknown_flavour? */
826
827static struct core_fns lynx_core_fns =
828{
829 bfd_target_unknown_flavour,
830 fetch_core_registers,
831 NULL
832};
833
834void
835_initialize_core_lynx ()
836{
837 add_core_fns (&lynx_core_fns);
838}
This page took 0.162581 seconds and 4 git commands to generate.