* stabsread.c (get_substring): Declare second arg as int.
[deliverable/binutils-gdb.git] / gdb / lynx-nat.c
1 /* Native-dependent code for LynxOS.
2 Copyright 1993, 1994 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "target.h"
24 #include "gdbcore.h"
25
26 #include <sys/ptrace.h>
27 #include <sys/wait.h>
28 #include <sys/fpp.h>
29
30 static 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
37 static 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 };
57 #endif /* I386 */
58
59 #ifdef M68K
60 /* Mappings from tm-m68k.h */
61
62 static 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 };
98 #endif /* M68K */
99
100 #ifdef SPARC
101 /* Mappings from tm-sparc.h */
102
103 #define FX(ENTRY)(offsetof(struct fcontext, ENTRY))
104
105 static 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 */
172
173 #ifdef rs6000
174
175 static int regmap[] =
176 {
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 */
250 };
251
252 #endif /* rs6000 */
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
260 void
261 fetch_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)
290 perror_with_name ("ptrace(PTRACE_GETREGS)");
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
320 target_xfer_memory (sp + FRAME_SAVED_I0,
321 &registers[REGISTER_BYTE(I0_REGNUM)],
322 8 * REGISTER_RAW_SIZE (I0_REGNUM), 0);
323 for (i = I0_REGNUM; i <= I7_REGNUM; i++)
324 register_valid[i] = 1;
325
326 target_xfer_memory (sp + FRAME_SAVED_L0,
327 &registers[REGISTER_BYTE(L0_REGNUM)],
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)
343 perror_with_name ("ptrace(PTRACE_GETFPREGS)");
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
361 void
362 store_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)
400 perror_with_name ("ptrace(PTRACE_SETREGS)");
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();
414 target_xfer_memory (sp + FRAME_SAVED_I0,
415 &registers[REGISTER_BYTE (I0_REGNUM)],
416 8 * REGISTER_RAW_SIZE (I0_REGNUM), 1);
417
418 target_xfer_memory (sp + FRAME_SAVED_L0,
419 &registers[REGISTER_BYTE (L0_REGNUM)],
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)
428 + FRAME_SAVED_L0;
429 else
430 regoffset = REGISTER_BYTE (regno) - REGISTER_BYTE (I0_REGNUM)
431 + FRAME_SAVED_I0;
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)
447 perror_with_name ("ptrace(PTRACE_GETFPREGS)");
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)
458 perror_with_name ("ptrace(PTRACE_SETFPREGS)");
459 }
460 }
461 #endif /* SPARC */
462
463 #if defined (I386) || defined (M68K) || defined (rs6000)
464
465 /* Return the offset relative to the start of the per-thread data to the
466 saved context block. */
467
468 static unsigned long
469 registers_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)
480 perror_with_name ("ptrace(PTRACE_THREADUSER)");
481
482 ecp = (CORE_ADDR) ptrace (PTRACE_PEEKTHREAD, pid, (PTRACE_ARG3_TYPE)ecpoff,
483 0);
484 if (errno)
485 perror_with_name ("ptrace(PTRACE_PEEKTHREAD)");
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
494 void
495 fetch_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
512 for (regno = reglo; regno <= reghi; regno++)
513 {
514 char buf[MAX_REGISTER_RAW_SIZE];
515 int ptrace_fun = PTRACE_PEEKTHREAD;
516
517 #ifdef M68K
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)
529 perror_with_name ("ptrace(PTRACE_PEEKUSP)");
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
541 /* Registers we shouldn't try to store. */
542 #if !defined (CANNOT_STORE_REGISTER)
543 #define CANNOT_STORE_REGISTER(regno) 0
544 #endif
545
546 void
547 store_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
564 for (regno = reglo; regno <= reghi; regno++)
565 {
566 int ptrace_fun = PTRACE_POKEUSER;
567
568 if (CANNOT_STORE_REGISTER (regno))
569 continue;
570
571 #ifdef M68K
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)
585 perror_with_name ("ptrace(PTRACE_POKEUSP)");
586 }
587 }
588 }
589 #endif /* defined (I386) || defined (M68K) || defined (rs6000) */
590
591 /* Wait for child to do something. Return pid of child, or -1 in case
592 of error; store status through argument pointer OURSTATUS. */
593
594 int
595 child_wait (pid, ourstatus)
596 int pid;
597 struct target_waitstatus *ourstatus;
598 {
599 int save_errno;
600 int thread;
601 union wait status;
602
603 while (1)
604 {
605 int sig;
606
607 set_sigint_trap(); /* Causes SIGINT to be passed on to the
608 attached process. */
609 pid = wait (&status);
610
611 save_errno = errno;
612
613 clear_sigint_trap();
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));
621 /* Claim it exited with unknown signal. */
622 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
623 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
624 return -1;
625 }
626
627 if (pid != PIDGET (inferior_pid)) /* Some other process?!? */
628 continue;
629
630 thread = status.w_tid; /* Get thread id from status */
631
632 /* Initial thread value can only be acquired via wait, so we have to
633 resort to this hack. */
634
635 if (TIDGET (inferior_pid) == 0 && thread != 0)
636 {
637 inferior_pid = BUILDPID (inferior_pid, thread);
638 add_thread (inferior_pid);
639 }
640
641 pid = BUILDPID (pid, thread);
642
643 /* We've become a single threaded process again. */
644 if (thread == 0)
645 inferior_pid = pid;
646
647 /* Check for thread creation. */
648 if (WIFSTOPPED(status)
649 && WSTOPSIG(status) == SIGTRAP
650 && !in_thread_list (pid))
651 {
652 int realsig;
653
654 realsig = ptrace (PTRACE_GETTRACESIG, pid, (PTRACE_ARG3_TYPE)0, 0);
655
656 if (realsig == SIGNEWTHREAD)
657 {
658 /* It's a new thread notification. We don't want to much with
659 realsig -- the code in wait_for_inferior expects SIGTRAP. */
660 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
661 ourstatus->value.sig = TARGET_SIGNAL_0;
662 return pid;
663 }
664 else
665 error ("Signal for unknown thread was not SIGNEWTHREAD");
666 }
667
668 /* Check for thread termination. */
669 else if (WIFSTOPPED(status)
670 && WSTOPSIG(status) == SIGTRAP
671 && in_thread_list (pid))
672 {
673 int realsig;
674
675 realsig = ptrace (PTRACE_GETTRACESIG, pid, (PTRACE_ARG3_TYPE)0, 0);
676
677 if (realsig == SIGTHREADEXIT)
678 {
679 ptrace (PTRACE_CONT, PIDGET (pid), (PTRACE_ARG3_TYPE)0, 0);
680 continue;
681 }
682 }
683
684 #ifdef SPARC
685 /* SPARC Lynx uses an byte reversed wait status; we must use the
686 host macros to access it. These lines just a copy of
687 store_waitstatus. We can't use CHILD_SPECIAL_WAITSTATUS
688 because target.c can't include the Lynx <sys/wait.h>. */
689 if (WIFEXITED (status))
690 {
691 ourstatus->kind = TARGET_WAITKIND_EXITED;
692 ourstatus->value.integer = WEXITSTATUS (status);
693 }
694 else if (!WIFSTOPPED (status))
695 {
696 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
697 ourstatus->value.sig =
698 target_signal_from_host (WTERMSIG (status));
699 }
700 else
701 {
702 ourstatus->kind = TARGET_WAITKIND_STOPPED;
703 ourstatus->value.sig =
704 target_signal_from_host (WSTOPSIG (status));
705 }
706 #else
707 store_waitstatus (ourstatus, status.w_status);
708 #endif
709
710 return pid;
711 }
712 }
713
714 /* Return nonzero if the given thread is still alive. */
715 int
716 child_thread_alive (pid)
717 int pid;
718 {
719 /* Arggh. Apparently pthread_kill only works for threads within
720 the process that calls pthread_kill.
721
722 We want to avoid the lynx signal extensions as they simply don't
723 map well to the generic gdb interface we want to keep.
724
725 All we want to do is determine if a particular thread is alive;
726 it appears as if we can just make a harmless thread specific
727 ptrace call to do that. */
728 return (ptrace (PTRACE_THREADUSER, pid, 0, 0) != -1);
729 }
730
731 /* Resume execution of the inferior process.
732 If STEP is nonzero, single-step it.
733 If SIGNAL is nonzero, give it that signal. */
734
735 void
736 child_resume (pid, step, signal)
737 int pid;
738 int step;
739 enum target_signal signal;
740 {
741 int func;
742
743 errno = 0;
744
745 /* If pid == -1, then we want to step/continue all threads, else
746 we only want to step/continue a single thread. */
747 if (pid == -1)
748 {
749 pid = inferior_pid;
750 func = step ? PTRACE_SINGLESTEP : PTRACE_CONT;
751 }
752 else
753 func = step ? PTRACE_SINGLESTEP_ONE : PTRACE_CONT_ONE;
754
755
756 /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where
757 it was. (If GDB wanted it to start some other way, we have already
758 written a new PC value to the child.)
759
760 If this system does not support PT_STEP, a higher level function will
761 have called single_step() to transmute the step request into a
762 continue request (by setting breakpoints on all possible successor
763 instructions), so we don't have to worry about that here. */
764
765 ptrace (func, pid, (PTRACE_ARG3_TYPE) 1, target_signal_to_host (signal));
766
767 if (errno)
768 perror_with_name ("ptrace");
769 }
770
771 /* Convert a Lynx process ID to a string. Returns the string in a static
772 buffer. */
773
774 char *
775 lynx_pid_to_str (pid)
776 int pid;
777 {
778 static char buf[40];
779
780 sprintf (buf, "process %d thread %d", PIDGET (pid), TIDGET (pid));
781
782 return buf;
783 }
784
785 /* Extract the register values out of the core file and store
786 them where `read_register' will find them.
787
788 CORE_REG_SECT points to the register values themselves, read into memory.
789 CORE_REG_SIZE is the size of that area.
790 WHICH says which set of registers we are handling (0 = int, 2 = float
791 on machines where they are discontiguous).
792 REG_ADDR is the offset from u.u_ar0 to the register values relative to
793 core_reg_sect. This is used with old-fashioned core files to
794 locate the registers in a large upage-plus-stack ".reg" section.
795 Original upage address X is at location core_reg_sect+x+reg_addr.
796 */
797
798 static void
799 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
800 char *core_reg_sect;
801 unsigned core_reg_size;
802 int which;
803 unsigned reg_addr;
804 {
805 struct st_entry s;
806 unsigned int regno;
807
808 for (regno = 0; regno < NUM_REGS; regno++)
809 if (regmap[regno] != -1)
810 supply_register (regno, core_reg_sect + offsetof (st_t, ec)
811 + regmap[regno]);
812
813 #ifdef SPARC
814 /* Fetching this register causes all of the I & L regs to be read from the
815 stack and validated. */
816
817 fetch_inferior_registers (I0_REGNUM);
818 #endif
819 }
820
821 \f
822 /* Register that we are able to handle lynx core file formats.
823 FIXME: is this really bfd_target_unknown_flavour? */
824
825 static struct core_fns lynx_core_fns =
826 {
827 bfd_target_unknown_flavour,
828 fetch_core_registers,
829 NULL
830 };
831
832 void
833 _initialize_core_lynx ()
834 {
835 add_core_fns (&lynx_core_fns);
836 }
This page took 0.046848 seconds and 4 git commands to generate.