* linux-low.c (regsets_store_inferior_registers): Read the regset
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-low.c
1 /* Low level interface to ptrace, for the remote server for GDB.
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006
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 2 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, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23 #include "server.h"
24 #include "linux-low.h"
25
26 #include <sys/wait.h>
27 #include <stdio.h>
28 #include <sys/param.h>
29 #include <sys/dir.h>
30 #include <sys/ptrace.h>
31 #include <sys/user.h>
32 #include <signal.h>
33 #include <sys/ioctl.h>
34 #include <fcntl.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <errno.h>
39 #include <sys/syscall.h>
40
41 /* ``all_threads'' is keyed by the LWP ID - it should be the thread ID instead,
42 however. This requires changing the ID in place when we go from !using_threads
43 to using_threads, immediately.
44
45 ``all_processes'' is keyed by the process ID - which on Linux is (presently)
46 the same as the LWP ID. */
47
48 struct inferior_list all_processes;
49
50 /* FIXME this is a bit of a hack, and could be removed. */
51 int stopping_threads;
52
53 /* FIXME make into a target method? */
54 int using_threads;
55
56 static void linux_resume_one_process (struct inferior_list_entry *entry,
57 int step, int signal);
58 static void linux_resume (struct thread_resume *resume_info);
59 static void stop_all_processes (void);
60 static int linux_wait_for_event (struct thread_info *child);
61
62 struct pending_signals
63 {
64 int signal;
65 struct pending_signals *prev;
66 };
67
68 #define PTRACE_ARG3_TYPE long
69 #define PTRACE_XFER_TYPE long
70
71 #ifdef HAVE_LINUX_REGSETS
72 static int use_regsets_p = 1;
73 #endif
74
75 int debug_threads = 0;
76
77 #define pid_of(proc) ((proc)->head.id)
78
79 /* FIXME: Delete eventually. */
80 #define inferior_pid (pid_of (get_thread_process (current_inferior)))
81
82 /* This function should only be called if the process got a SIGTRAP.
83 The SIGTRAP could mean several things.
84
85 On i386, where decr_pc_after_break is non-zero:
86 If we were single-stepping this process using PTRACE_SINGLESTEP,
87 we will get only the one SIGTRAP (even if the instruction we
88 stepped over was a breakpoint). The value of $eip will be the
89 next instruction.
90 If we continue the process using PTRACE_CONT, we will get a
91 SIGTRAP when we hit a breakpoint. The value of $eip will be
92 the instruction after the breakpoint (i.e. needs to be
93 decremented). If we report the SIGTRAP to GDB, we must also
94 report the undecremented PC. If we cancel the SIGTRAP, we
95 must resume at the decremented PC.
96
97 (Presumably, not yet tested) On a non-decr_pc_after_break machine
98 with hardware or kernel single-step:
99 If we single-step over a breakpoint instruction, our PC will
100 point at the following instruction. If we continue and hit a
101 breakpoint instruction, our PC will point at the breakpoint
102 instruction. */
103
104 static CORE_ADDR
105 get_stop_pc (void)
106 {
107 CORE_ADDR stop_pc = (*the_low_target.get_pc) ();
108
109 if (get_thread_process (current_inferior)->stepping)
110 return stop_pc;
111 else
112 return stop_pc - the_low_target.decr_pc_after_break;
113 }
114
115 static void *
116 add_process (unsigned long pid)
117 {
118 struct process_info *process;
119
120 process = (struct process_info *) malloc (sizeof (*process));
121 memset (process, 0, sizeof (*process));
122
123 process->head.id = pid;
124
125 /* Default to tid == lwpid == pid. */
126 process->tid = pid;
127 process->lwpid = pid;
128
129 add_inferior_to_list (&all_processes, &process->head);
130
131 return process;
132 }
133
134 /* Start an inferior process and returns its pid.
135 ALLARGS is a vector of program-name and args. */
136
137 static int
138 linux_create_inferior (char *program, char **allargs)
139 {
140 void *new_process;
141 int pid;
142
143 pid = fork ();
144 if (pid < 0)
145 perror_with_name ("fork");
146
147 if (pid == 0)
148 {
149 ptrace (PTRACE_TRACEME, 0, 0, 0);
150
151 signal (__SIGRTMIN + 1, SIG_DFL);
152
153 setpgid (0, 0);
154
155 execv (program, allargs);
156
157 fprintf (stderr, "Cannot exec %s: %s.\n", program,
158 strerror (errno));
159 fflush (stderr);
160 _exit (0177);
161 }
162
163 new_process = add_process (pid);
164 add_thread (pid, new_process, pid);
165
166 return pid;
167 }
168
169 /* Attach to an inferior process. */
170
171 void
172 linux_attach_lwp (unsigned long pid, unsigned long tid)
173 {
174 struct process_info *new_process;
175
176 if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0)
177 {
178 fprintf (stderr, "Cannot attach to process %ld: %s (%d)\n", pid,
179 strerror (errno), errno);
180 fflush (stderr);
181
182 /* If we fail to attach to an LWP, just return. */
183 if (!using_threads)
184 _exit (0177);
185 return;
186 }
187
188 new_process = (struct process_info *) add_process (pid);
189 add_thread (tid, new_process, pid);
190
191 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH
192 brings it to a halt. We should ignore that SIGSTOP and resume the process
193 (unless this is the first process, in which case the flag will be cleared
194 in linux_attach).
195
196 On the other hand, if we are currently trying to stop all threads, we
197 should treat the new thread as if we had sent it a SIGSTOP. This works
198 because we are guaranteed that add_process added us to the end of the
199 list, and so the new thread has not yet reached wait_for_sigstop (but
200 will). */
201 if (! stopping_threads)
202 new_process->stop_expected = 1;
203 }
204
205 int
206 linux_attach (unsigned long pid)
207 {
208 struct process_info *process;
209
210 linux_attach_lwp (pid, pid);
211
212 /* Don't ignore the initial SIGSTOP if we just attached to this process. */
213 process = (struct process_info *) find_inferior_id (&all_processes, pid);
214 process->stop_expected = 0;
215
216 return 0;
217 }
218
219 /* Kill the inferior process. Make us have no inferior. */
220
221 static void
222 linux_kill_one_process (struct inferior_list_entry *entry)
223 {
224 struct thread_info *thread = (struct thread_info *) entry;
225 struct process_info *process = get_thread_process (thread);
226 int wstat;
227
228 /* We avoid killing the first thread here, because of a Linux kernel (at
229 least 2.6.0-test7 through 2.6.8-rc4) bug; if we kill the parent before
230 the children get a chance to be reaped, it will remain a zombie
231 forever. */
232 if (entry == all_threads.head)
233 return;
234
235 do
236 {
237 ptrace (PTRACE_KILL, pid_of (process), 0, 0);
238
239 /* Make sure it died. The loop is most likely unnecessary. */
240 wstat = linux_wait_for_event (thread);
241 } while (WIFSTOPPED (wstat));
242 }
243
244 static void
245 linux_kill (void)
246 {
247 struct thread_info *thread = (struct thread_info *) all_threads.head;
248 struct process_info *process = get_thread_process (thread);
249 int wstat;
250
251 for_each_inferior (&all_threads, linux_kill_one_process);
252
253 /* See the comment in linux_kill_one_process. We did not kill the first
254 thread in the list, so do so now. */
255 do
256 {
257 ptrace (PTRACE_KILL, pid_of (process), 0, 0);
258
259 /* Make sure it died. The loop is most likely unnecessary. */
260 wstat = linux_wait_for_event (thread);
261 } while (WIFSTOPPED (wstat));
262 }
263
264 static void
265 linux_detach_one_process (struct inferior_list_entry *entry)
266 {
267 struct thread_info *thread = (struct thread_info *) entry;
268 struct process_info *process = get_thread_process (thread);
269
270 ptrace (PTRACE_DETACH, pid_of (process), 0, 0);
271 }
272
273 static void
274 linux_detach (void)
275 {
276 for_each_inferior (&all_threads, linux_detach_one_process);
277 }
278
279 /* Return nonzero if the given thread is still alive. */
280 static int
281 linux_thread_alive (unsigned long tid)
282 {
283 if (find_inferior_id (&all_threads, tid) != NULL)
284 return 1;
285 else
286 return 0;
287 }
288
289 /* Return nonzero if this process stopped at a breakpoint which
290 no longer appears to be inserted. Also adjust the PC
291 appropriately to resume where the breakpoint used to be. */
292 static int
293 check_removed_breakpoint (struct process_info *event_child)
294 {
295 CORE_ADDR stop_pc;
296 struct thread_info *saved_inferior;
297
298 if (event_child->pending_is_breakpoint == 0)
299 return 0;
300
301 if (debug_threads)
302 fprintf (stderr, "Checking for breakpoint.\n");
303
304 saved_inferior = current_inferior;
305 current_inferior = get_process_thread (event_child);
306
307 stop_pc = get_stop_pc ();
308
309 /* If the PC has changed since we stopped, then we shouldn't do
310 anything. This happens if, for instance, GDB handled the
311 decr_pc_after_break subtraction itself. */
312 if (stop_pc != event_child->pending_stop_pc)
313 {
314 if (debug_threads)
315 fprintf (stderr, "Ignoring, PC was changed.\n");
316
317 event_child->pending_is_breakpoint = 0;
318 current_inferior = saved_inferior;
319 return 0;
320 }
321
322 /* If the breakpoint is still there, we will report hitting it. */
323 if ((*the_low_target.breakpoint_at) (stop_pc))
324 {
325 if (debug_threads)
326 fprintf (stderr, "Ignoring, breakpoint is still present.\n");
327 current_inferior = saved_inferior;
328 return 0;
329 }
330
331 if (debug_threads)
332 fprintf (stderr, "Removed breakpoint.\n");
333
334 /* For decr_pc_after_break targets, here is where we perform the
335 decrement. We go immediately from this function to resuming,
336 and can not safely call get_stop_pc () again. */
337 if (the_low_target.set_pc != NULL)
338 (*the_low_target.set_pc) (stop_pc);
339
340 /* We consumed the pending SIGTRAP. */
341 event_child->pending_is_breakpoint = 0;
342 event_child->status_pending_p = 0;
343 event_child->status_pending = 0;
344
345 current_inferior = saved_inferior;
346 return 1;
347 }
348
349 /* Return 1 if this process has an interesting status pending. This function
350 may silently resume an inferior process. */
351 static int
352 status_pending_p (struct inferior_list_entry *entry, void *dummy)
353 {
354 struct process_info *process = (struct process_info *) entry;
355
356 if (process->status_pending_p)
357 if (check_removed_breakpoint (process))
358 {
359 /* This thread was stopped at a breakpoint, and the breakpoint
360 is now gone. We were told to continue (or step...) all threads,
361 so GDB isn't trying to single-step past this breakpoint.
362 So instead of reporting the old SIGTRAP, pretend we got to
363 the breakpoint just after it was removed instead of just
364 before; resume the process. */
365 linux_resume_one_process (&process->head, 0, 0);
366 return 0;
367 }
368
369 return process->status_pending_p;
370 }
371
372 static void
373 linux_wait_for_process (struct process_info **childp, int *wstatp)
374 {
375 int ret;
376 int to_wait_for = -1;
377
378 if (*childp != NULL)
379 to_wait_for = (*childp)->lwpid;
380
381 while (1)
382 {
383 ret = waitpid (to_wait_for, wstatp, WNOHANG);
384
385 if (ret == -1)
386 {
387 if (errno != ECHILD)
388 perror_with_name ("waitpid");
389 }
390 else if (ret > 0)
391 break;
392
393 ret = waitpid (to_wait_for, wstatp, WNOHANG | __WCLONE);
394
395 if (ret == -1)
396 {
397 if (errno != ECHILD)
398 perror_with_name ("waitpid (WCLONE)");
399 }
400 else if (ret > 0)
401 break;
402
403 usleep (1000);
404 }
405
406 if (debug_threads
407 && (!WIFSTOPPED (*wstatp)
408 || (WSTOPSIG (*wstatp) != 32
409 && WSTOPSIG (*wstatp) != 33)))
410 fprintf (stderr, "Got an event from %d (%x)\n", ret, *wstatp);
411
412 if (to_wait_for == -1)
413 *childp = (struct process_info *) find_inferior_id (&all_processes, ret);
414
415 (*childp)->stopped = 1;
416 (*childp)->pending_is_breakpoint = 0;
417
418 if (debug_threads
419 && WIFSTOPPED (*wstatp))
420 {
421 current_inferior = (struct thread_info *)
422 find_inferior_id (&all_threads, (*childp)->tid);
423 /* For testing only; i386_stop_pc prints out a diagnostic. */
424 if (the_low_target.get_pc != NULL)
425 get_stop_pc ();
426 }
427 }
428
429 static int
430 linux_wait_for_event (struct thread_info *child)
431 {
432 CORE_ADDR stop_pc;
433 struct process_info *event_child;
434 int wstat;
435
436 /* Check for a process with a pending status. */
437 /* It is possible that the user changed the pending task's registers since
438 it stopped. We correctly handle the change of PC if we hit a breakpoint
439 (in check_removed_breakpoint); signals should be reported anyway. */
440 if (child == NULL)
441 {
442 event_child = (struct process_info *)
443 find_inferior (&all_processes, status_pending_p, NULL);
444 if (debug_threads && event_child)
445 fprintf (stderr, "Got a pending child %ld\n", event_child->lwpid);
446 }
447 else
448 {
449 event_child = get_thread_process (child);
450 if (event_child->status_pending_p
451 && check_removed_breakpoint (event_child))
452 event_child = NULL;
453 }
454
455 if (event_child != NULL)
456 {
457 if (event_child->status_pending_p)
458 {
459 if (debug_threads)
460 fprintf (stderr, "Got an event from pending child %ld (%04x)\n",
461 event_child->lwpid, event_child->status_pending);
462 wstat = event_child->status_pending;
463 event_child->status_pending_p = 0;
464 event_child->status_pending = 0;
465 current_inferior = get_process_thread (event_child);
466 return wstat;
467 }
468 }
469
470 /* We only enter this loop if no process has a pending wait status. Thus
471 any action taken in response to a wait status inside this loop is
472 responding as soon as we detect the status, not after any pending
473 events. */
474 while (1)
475 {
476 if (child == NULL)
477 event_child = NULL;
478 else
479 event_child = get_thread_process (child);
480
481 linux_wait_for_process (&event_child, &wstat);
482
483 if (event_child == NULL)
484 error ("event from unknown child");
485
486 current_inferior = (struct thread_info *)
487 find_inferior_id (&all_threads, event_child->tid);
488
489 if (using_threads)
490 {
491 /* Check for thread exit. */
492 if (! WIFSTOPPED (wstat))
493 {
494 if (debug_threads)
495 fprintf (stderr, "Thread %ld (LWP %ld) exiting\n",
496 event_child->tid, event_child->head.id);
497
498 /* If the last thread is exiting, just return. */
499 if (all_threads.head == all_threads.tail)
500 return wstat;
501
502 dead_thread_notify (event_child->tid);
503
504 remove_inferior (&all_processes, &event_child->head);
505 free (event_child);
506 remove_thread (current_inferior);
507 current_inferior = (struct thread_info *) all_threads.head;
508
509 /* If we were waiting for this particular child to do something...
510 well, it did something. */
511 if (child != NULL)
512 return wstat;
513
514 /* Wait for a more interesting event. */
515 continue;
516 }
517
518 if (WIFSTOPPED (wstat)
519 && WSTOPSIG (wstat) == SIGSTOP
520 && event_child->stop_expected)
521 {
522 if (debug_threads)
523 fprintf (stderr, "Expected stop.\n");
524 event_child->stop_expected = 0;
525 linux_resume_one_process (&event_child->head,
526 event_child->stepping, 0);
527 continue;
528 }
529
530 /* FIXME drow/2002-06-09: Get signal numbers from the inferior's
531 thread library? */
532 if (WIFSTOPPED (wstat)
533 && (WSTOPSIG (wstat) == __SIGRTMIN
534 || WSTOPSIG (wstat) == __SIGRTMIN + 1))
535 {
536 if (debug_threads)
537 fprintf (stderr, "Ignored signal %d for %ld (LWP %ld).\n",
538 WSTOPSIG (wstat), event_child->tid,
539 event_child->head.id);
540 linux_resume_one_process (&event_child->head,
541 event_child->stepping,
542 WSTOPSIG (wstat));
543 continue;
544 }
545 }
546
547 /* If this event was not handled above, and is not a SIGTRAP, report
548 it. */
549 if (!WIFSTOPPED (wstat) || WSTOPSIG (wstat) != SIGTRAP)
550 return wstat;
551
552 /* If this target does not support breakpoints, we simply report the
553 SIGTRAP; it's of no concern to us. */
554 if (the_low_target.get_pc == NULL)
555 return wstat;
556
557 stop_pc = get_stop_pc ();
558
559 /* bp_reinsert will only be set if we were single-stepping.
560 Notice that we will resume the process after hitting
561 a gdbserver breakpoint; single-stepping to/over one
562 is not supported (yet). */
563 if (event_child->bp_reinsert != 0)
564 {
565 if (debug_threads)
566 fprintf (stderr, "Reinserted breakpoint.\n");
567 reinsert_breakpoint (event_child->bp_reinsert);
568 event_child->bp_reinsert = 0;
569
570 /* Clear the single-stepping flag and SIGTRAP as we resume. */
571 linux_resume_one_process (&event_child->head, 0, 0);
572 continue;
573 }
574
575 if (debug_threads)
576 fprintf (stderr, "Hit a (non-reinsert) breakpoint.\n");
577
578 if (check_breakpoints (stop_pc) != 0)
579 {
580 /* We hit one of our own breakpoints. We mark it as a pending
581 breakpoint, so that check_removed_breakpoint () will do the PC
582 adjustment for us at the appropriate time. */
583 event_child->pending_is_breakpoint = 1;
584 event_child->pending_stop_pc = stop_pc;
585
586 /* Now we need to put the breakpoint back. We continue in the event
587 loop instead of simply replacing the breakpoint right away,
588 in order to not lose signals sent to the thread that hit the
589 breakpoint. Unfortunately this increases the window where another
590 thread could sneak past the removed breakpoint. For the current
591 use of server-side breakpoints (thread creation) this is
592 acceptable; but it needs to be considered before this breakpoint
593 mechanism can be used in more general ways. For some breakpoints
594 it may be necessary to stop all other threads, but that should
595 be avoided where possible.
596
597 If breakpoint_reinsert_addr is NULL, that means that we can
598 use PTRACE_SINGLESTEP on this platform. Uninsert the breakpoint,
599 mark it for reinsertion, and single-step.
600
601 Otherwise, call the target function to figure out where we need
602 our temporary breakpoint, create it, and continue executing this
603 process. */
604 if (the_low_target.breakpoint_reinsert_addr == NULL)
605 {
606 event_child->bp_reinsert = stop_pc;
607 uninsert_breakpoint (stop_pc);
608 linux_resume_one_process (&event_child->head, 1, 0);
609 }
610 else
611 {
612 reinsert_breakpoint_by_bp
613 (stop_pc, (*the_low_target.breakpoint_reinsert_addr) ());
614 linux_resume_one_process (&event_child->head, 0, 0);
615 }
616
617 continue;
618 }
619
620 /* If we were single-stepping, we definitely want to report the
621 SIGTRAP. The single-step operation has completed, so also
622 clear the stepping flag; in general this does not matter,
623 because the SIGTRAP will be reported to the client, which
624 will give us a new action for this thread, but clear it for
625 consistency anyway. It's safe to clear the stepping flag
626 because the only consumer of get_stop_pc () after this point
627 is check_removed_breakpoint, and pending_is_breakpoint is not
628 set. It might be wiser to use a step_completed flag instead. */
629 if (event_child->stepping)
630 {
631 event_child->stepping = 0;
632 return wstat;
633 }
634
635 /* A SIGTRAP that we can't explain. It may have been a breakpoint.
636 Check if it is a breakpoint, and if so mark the process information
637 accordingly. This will handle both the necessary fiddling with the
638 PC on decr_pc_after_break targets and suppressing extra threads
639 hitting a breakpoint if two hit it at once and then GDB removes it
640 after the first is reported. Arguably it would be better to report
641 multiple threads hitting breakpoints simultaneously, but the current
642 remote protocol does not allow this. */
643 if ((*the_low_target.breakpoint_at) (stop_pc))
644 {
645 event_child->pending_is_breakpoint = 1;
646 event_child->pending_stop_pc = stop_pc;
647 }
648
649 return wstat;
650 }
651
652 /* NOTREACHED */
653 return 0;
654 }
655
656 /* Wait for process, returns status. */
657
658 static unsigned char
659 linux_wait (char *status)
660 {
661 int w;
662 struct thread_info *child = NULL;
663
664 retry:
665 /* If we were only supposed to resume one thread, only wait for
666 that thread - if it's still alive. If it died, however - which
667 can happen if we're coming from the thread death case below -
668 then we need to make sure we restart the other threads. We could
669 pick a thread at random or restart all; restarting all is less
670 arbitrary. */
671 if (cont_thread != 0 && cont_thread != -1)
672 {
673 child = (struct thread_info *) find_inferior_id (&all_threads,
674 cont_thread);
675
676 /* No stepping, no signal - unless one is pending already, of course. */
677 if (child == NULL)
678 {
679 struct thread_resume resume_info;
680 resume_info.thread = -1;
681 resume_info.step = resume_info.sig = resume_info.leave_stopped = 0;
682 linux_resume (&resume_info);
683 }
684 }
685
686 enable_async_io ();
687 unblock_async_io ();
688 w = linux_wait_for_event (child);
689 stop_all_processes ();
690 disable_async_io ();
691
692 /* If we are waiting for a particular child, and it exited,
693 linux_wait_for_event will return its exit status. Similarly if
694 the last child exited. If this is not the last child, however,
695 do not report it as exited until there is a 'thread exited' response
696 available in the remote protocol. Instead, just wait for another event.
697 This should be safe, because if the thread crashed we will already
698 have reported the termination signal to GDB; that should stop any
699 in-progress stepping operations, etc.
700
701 Report the exit status of the last thread to exit. This matches
702 LinuxThreads' behavior. */
703
704 if (all_threads.head == all_threads.tail)
705 {
706 if (WIFEXITED (w))
707 {
708 fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w));
709 *status = 'W';
710 clear_inferiors ();
711 free (all_processes.head);
712 all_processes.head = all_processes.tail = NULL;
713 return ((unsigned char) WEXITSTATUS (w));
714 }
715 else if (!WIFSTOPPED (w))
716 {
717 fprintf (stderr, "\nChild terminated with signal = %x \n", WTERMSIG (w));
718 *status = 'X';
719 clear_inferiors ();
720 free (all_processes.head);
721 all_processes.head = all_processes.tail = NULL;
722 return ((unsigned char) WTERMSIG (w));
723 }
724 }
725 else
726 {
727 if (!WIFSTOPPED (w))
728 goto retry;
729 }
730
731 *status = 'T';
732 return ((unsigned char) WSTOPSIG (w));
733 }
734
735 /* Send a signal to an LWP. For LinuxThreads, kill is enough; however, if
736 thread groups are in use, we need to use tkill. */
737
738 static int
739 kill_lwp (unsigned long lwpid, int signo)
740 {
741 static int tkill_failed;
742
743 errno = 0;
744
745 #ifdef SYS_tkill
746 if (!tkill_failed)
747 {
748 int ret = syscall (SYS_tkill, lwpid, signo);
749 if (errno != ENOSYS)
750 return ret;
751 errno = 0;
752 tkill_failed = 1;
753 }
754 #endif
755
756 return kill (lwpid, signo);
757 }
758
759 static void
760 send_sigstop (struct inferior_list_entry *entry)
761 {
762 struct process_info *process = (struct process_info *) entry;
763
764 if (process->stopped)
765 return;
766
767 /* If we already have a pending stop signal for this process, don't
768 send another. */
769 if (process->stop_expected)
770 {
771 process->stop_expected = 0;
772 return;
773 }
774
775 if (debug_threads)
776 fprintf (stderr, "Sending sigstop to process %ld\n", process->head.id);
777
778 kill_lwp (process->head.id, SIGSTOP);
779 process->sigstop_sent = 1;
780 }
781
782 static void
783 wait_for_sigstop (struct inferior_list_entry *entry)
784 {
785 struct process_info *process = (struct process_info *) entry;
786 struct thread_info *saved_inferior, *thread;
787 int wstat;
788 unsigned long saved_tid;
789
790 if (process->stopped)
791 return;
792
793 saved_inferior = current_inferior;
794 saved_tid = ((struct inferior_list_entry *) saved_inferior)->id;
795 thread = (struct thread_info *) find_inferior_id (&all_threads,
796 process->tid);
797 wstat = linux_wait_for_event (thread);
798
799 /* If we stopped with a non-SIGSTOP signal, save it for later
800 and record the pending SIGSTOP. If the process exited, just
801 return. */
802 if (WIFSTOPPED (wstat)
803 && WSTOPSIG (wstat) != SIGSTOP)
804 {
805 if (debug_threads)
806 fprintf (stderr, "Stopped with non-sigstop signal\n");
807 process->status_pending_p = 1;
808 process->status_pending = wstat;
809 process->stop_expected = 1;
810 }
811
812 if (linux_thread_alive (saved_tid))
813 current_inferior = saved_inferior;
814 else
815 {
816 if (debug_threads)
817 fprintf (stderr, "Previously current thread died.\n");
818
819 /* Set a valid thread as current. */
820 set_desired_inferior (0);
821 }
822 }
823
824 static void
825 stop_all_processes (void)
826 {
827 stopping_threads = 1;
828 for_each_inferior (&all_processes, send_sigstop);
829 for_each_inferior (&all_processes, wait_for_sigstop);
830 stopping_threads = 0;
831 }
832
833 /* Resume execution of the inferior process.
834 If STEP is nonzero, single-step it.
835 If SIGNAL is nonzero, give it that signal. */
836
837 static void
838 linux_resume_one_process (struct inferior_list_entry *entry,
839 int step, int signal)
840 {
841 struct process_info *process = (struct process_info *) entry;
842 struct thread_info *saved_inferior;
843
844 if (process->stopped == 0)
845 return;
846
847 /* If we have pending signals or status, and a new signal, enqueue the
848 signal. Also enqueue the signal if we are waiting to reinsert a
849 breakpoint; it will be picked up again below. */
850 if (signal != 0
851 && (process->status_pending_p || process->pending_signals != NULL
852 || process->bp_reinsert != 0))
853 {
854 struct pending_signals *p_sig;
855 p_sig = malloc (sizeof (*p_sig));
856 p_sig->prev = process->pending_signals;
857 p_sig->signal = signal;
858 process->pending_signals = p_sig;
859 }
860
861 if (process->status_pending_p && !check_removed_breakpoint (process))
862 return;
863
864 saved_inferior = current_inferior;
865 current_inferior = get_process_thread (process);
866
867 if (debug_threads)
868 fprintf (stderr, "Resuming process %ld (%s, signal %d, stop %s)\n", inferior_pid,
869 step ? "step" : "continue", signal,
870 process->stop_expected ? "expected" : "not expected");
871
872 /* This bit needs some thinking about. If we get a signal that
873 we must report while a single-step reinsert is still pending,
874 we often end up resuming the thread. It might be better to
875 (ew) allow a stack of pending events; then we could be sure that
876 the reinsert happened right away and not lose any signals.
877
878 Making this stack would also shrink the window in which breakpoints are
879 uninserted (see comment in linux_wait_for_process) but not enough for
880 complete correctness, so it won't solve that problem. It may be
881 worthwhile just to solve this one, however. */
882 if (process->bp_reinsert != 0)
883 {
884 if (debug_threads)
885 fprintf (stderr, " pending reinsert at %08lx", (long)process->bp_reinsert);
886 if (step == 0)
887 fprintf (stderr, "BAD - reinserting but not stepping.\n");
888 step = 1;
889
890 /* Postpone any pending signal. It was enqueued above. */
891 signal = 0;
892 }
893
894 check_removed_breakpoint (process);
895
896 if (debug_threads && the_low_target.get_pc != NULL)
897 {
898 fprintf (stderr, " ");
899 (long) (*the_low_target.get_pc) ();
900 }
901
902 /* If we have pending signals, consume one unless we are trying to reinsert
903 a breakpoint. */
904 if (process->pending_signals != NULL && process->bp_reinsert == 0)
905 {
906 struct pending_signals **p_sig;
907
908 p_sig = &process->pending_signals;
909 while ((*p_sig)->prev != NULL)
910 p_sig = &(*p_sig)->prev;
911
912 signal = (*p_sig)->signal;
913 free (*p_sig);
914 *p_sig = NULL;
915 }
916
917 regcache_invalidate_one ((struct inferior_list_entry *)
918 get_process_thread (process));
919 errno = 0;
920 process->stopped = 0;
921 process->stepping = step;
922 ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, process->lwpid, 0, signal);
923
924 current_inferior = saved_inferior;
925 if (errno)
926 perror_with_name ("ptrace");
927 }
928
929 static struct thread_resume *resume_ptr;
930
931 /* This function is called once per thread. We look up the thread
932 in RESUME_PTR, and mark the thread with a pointer to the appropriate
933 resume request.
934
935 This algorithm is O(threads * resume elements), but resume elements
936 is small (and will remain small at least until GDB supports thread
937 suspension). */
938 static void
939 linux_set_resume_request (struct inferior_list_entry *entry)
940 {
941 struct process_info *process;
942 struct thread_info *thread;
943 int ndx;
944
945 thread = (struct thread_info *) entry;
946 process = get_thread_process (thread);
947
948 ndx = 0;
949 while (resume_ptr[ndx].thread != -1 && resume_ptr[ndx].thread != entry->id)
950 ndx++;
951
952 process->resume = &resume_ptr[ndx];
953 }
954
955 /* This function is called once per thread. We check the thread's resume
956 request, which will tell us whether to resume, step, or leave the thread
957 stopped; and what signal, if any, it should be sent. For threads which
958 we aren't explicitly told otherwise, we preserve the stepping flag; this
959 is used for stepping over gdbserver-placed breakpoints. */
960
961 static void
962 linux_continue_one_thread (struct inferior_list_entry *entry)
963 {
964 struct process_info *process;
965 struct thread_info *thread;
966 int step;
967
968 thread = (struct thread_info *) entry;
969 process = get_thread_process (thread);
970
971 if (process->resume->leave_stopped)
972 return;
973
974 if (process->resume->thread == -1)
975 step = process->stepping || process->resume->step;
976 else
977 step = process->resume->step;
978
979 linux_resume_one_process (&process->head, step, process->resume->sig);
980
981 process->resume = NULL;
982 }
983
984 /* This function is called once per thread. We check the thread's resume
985 request, which will tell us whether to resume, step, or leave the thread
986 stopped; and what signal, if any, it should be sent. We queue any needed
987 signals, since we won't actually resume. We already have a pending event
988 to report, so we don't need to preserve any step requests; they should
989 be re-issued if necessary. */
990
991 static void
992 linux_queue_one_thread (struct inferior_list_entry *entry)
993 {
994 struct process_info *process;
995 struct thread_info *thread;
996
997 thread = (struct thread_info *) entry;
998 process = get_thread_process (thread);
999
1000 if (process->resume->leave_stopped)
1001 return;
1002
1003 /* If we have a new signal, enqueue the signal. */
1004 if (process->resume->sig != 0)
1005 {
1006 struct pending_signals *p_sig;
1007 p_sig = malloc (sizeof (*p_sig));
1008 p_sig->prev = process->pending_signals;
1009 p_sig->signal = process->resume->sig;
1010 process->pending_signals = p_sig;
1011 }
1012
1013 process->resume = NULL;
1014 }
1015
1016 /* Set DUMMY if this process has an interesting status pending. */
1017 static int
1018 resume_status_pending_p (struct inferior_list_entry *entry, void *flag_p)
1019 {
1020 struct process_info *process = (struct process_info *) entry;
1021
1022 /* Processes which will not be resumed are not interesting, because
1023 we might not wait for them next time through linux_wait. */
1024 if (process->resume->leave_stopped)
1025 return 0;
1026
1027 /* If this thread has a removed breakpoint, we won't have any
1028 events to report later, so check now. check_removed_breakpoint
1029 may clear status_pending_p. We avoid calling check_removed_breakpoint
1030 for any thread that we are not otherwise going to resume - this
1031 lets us preserve stopped status when two threads hit a breakpoint.
1032 GDB removes the breakpoint to single-step a particular thread
1033 past it, then re-inserts it and resumes all threads. We want
1034 to report the second thread without resuming it in the interim. */
1035 if (process->status_pending_p)
1036 check_removed_breakpoint (process);
1037
1038 if (process->status_pending_p)
1039 * (int *) flag_p = 1;
1040
1041 return 0;
1042 }
1043
1044 static void
1045 linux_resume (struct thread_resume *resume_info)
1046 {
1047 int pending_flag;
1048
1049 /* Yes, the use of a global here is rather ugly. */
1050 resume_ptr = resume_info;
1051
1052 for_each_inferior (&all_threads, linux_set_resume_request);
1053
1054 /* If there is a thread which would otherwise be resumed, which
1055 has a pending status, then don't resume any threads - we can just
1056 report the pending status. Make sure to queue any signals
1057 that would otherwise be sent. */
1058 pending_flag = 0;
1059 find_inferior (&all_processes, resume_status_pending_p, &pending_flag);
1060
1061 if (debug_threads)
1062 {
1063 if (pending_flag)
1064 fprintf (stderr, "Not resuming, pending status\n");
1065 else
1066 fprintf (stderr, "Resuming, no pending status\n");
1067 }
1068
1069 if (pending_flag)
1070 for_each_inferior (&all_threads, linux_queue_one_thread);
1071 else
1072 {
1073 block_async_io ();
1074 enable_async_io ();
1075 for_each_inferior (&all_threads, linux_continue_one_thread);
1076 }
1077 }
1078
1079 #ifdef HAVE_LINUX_USRREGS
1080
1081 int
1082 register_addr (int regnum)
1083 {
1084 int addr;
1085
1086 if (regnum < 0 || regnum >= the_low_target.num_regs)
1087 error ("Invalid register number %d.", regnum);
1088
1089 addr = the_low_target.regmap[regnum];
1090
1091 return addr;
1092 }
1093
1094 /* Fetch one register. */
1095 static void
1096 fetch_register (int regno)
1097 {
1098 CORE_ADDR regaddr;
1099 int i, size;
1100 char *buf;
1101
1102 if (regno >= the_low_target.num_regs)
1103 return;
1104 if ((*the_low_target.cannot_fetch_register) (regno))
1105 return;
1106
1107 regaddr = register_addr (regno);
1108 if (regaddr == -1)
1109 return;
1110 size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1)
1111 & - sizeof (PTRACE_XFER_TYPE);
1112 buf = alloca (size);
1113 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE))
1114 {
1115 errno = 0;
1116 *(PTRACE_XFER_TYPE *) (buf + i) =
1117 ptrace (PTRACE_PEEKUSER, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, 0);
1118 regaddr += sizeof (PTRACE_XFER_TYPE);
1119 if (errno != 0)
1120 {
1121 /* Warning, not error, in case we are attached; sometimes the
1122 kernel doesn't let us at the registers. */
1123 char *err = strerror (errno);
1124 char *msg = alloca (strlen (err) + 128);
1125 sprintf (msg, "reading register %d: %s", regno, err);
1126 error (msg);
1127 goto error_exit;
1128 }
1129 }
1130 if (the_low_target.left_pad_xfer
1131 && register_size (regno) < sizeof (PTRACE_XFER_TYPE))
1132 supply_register (regno, (buf + sizeof (PTRACE_XFER_TYPE)
1133 - register_size (regno)));
1134 else
1135 supply_register (regno, buf);
1136
1137 error_exit:;
1138 }
1139
1140 /* Fetch all registers, or just one, from the child process. */
1141 static void
1142 usr_fetch_inferior_registers (int regno)
1143 {
1144 if (regno == -1 || regno == 0)
1145 for (regno = 0; regno < the_low_target.num_regs; regno++)
1146 fetch_register (regno);
1147 else
1148 fetch_register (regno);
1149 }
1150
1151 /* Store our register values back into the inferior.
1152 If REGNO is -1, do this for all registers.
1153 Otherwise, REGNO specifies which register (so we can save time). */
1154 static void
1155 usr_store_inferior_registers (int regno)
1156 {
1157 CORE_ADDR regaddr;
1158 int i, size;
1159 char *buf;
1160
1161 if (regno >= 0)
1162 {
1163 if (regno >= the_low_target.num_regs)
1164 return;
1165
1166 if ((*the_low_target.cannot_store_register) (regno) == 1)
1167 return;
1168
1169 regaddr = register_addr (regno);
1170 if (regaddr == -1)
1171 return;
1172 errno = 0;
1173 size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1)
1174 & - sizeof (PTRACE_XFER_TYPE);
1175 buf = alloca (size);
1176 memset (buf, 0, size);
1177 if (the_low_target.left_pad_xfer
1178 && register_size (regno) < sizeof (PTRACE_XFER_TYPE))
1179 collect_register (regno, (buf + sizeof (PTRACE_XFER_TYPE)
1180 - register_size (regno)));
1181 else
1182 collect_register (regno, buf);
1183 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE))
1184 {
1185 errno = 0;
1186 ptrace (PTRACE_POKEUSER, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
1187 *(PTRACE_XFER_TYPE *) (buf + i));
1188 if (errno != 0)
1189 {
1190 if ((*the_low_target.cannot_store_register) (regno) == 0)
1191 {
1192 char *err = strerror (errno);
1193 char *msg = alloca (strlen (err) + 128);
1194 sprintf (msg, "writing register %d: %s",
1195 regno, err);
1196 error (msg);
1197 return;
1198 }
1199 }
1200 regaddr += sizeof (PTRACE_XFER_TYPE);
1201 }
1202 }
1203 else
1204 for (regno = 0; regno < the_low_target.num_regs; regno++)
1205 usr_store_inferior_registers (regno);
1206 }
1207 #endif /* HAVE_LINUX_USRREGS */
1208
1209
1210
1211 #ifdef HAVE_LINUX_REGSETS
1212
1213 static int
1214 regsets_fetch_inferior_registers ()
1215 {
1216 struct regset_info *regset;
1217 int saw_general_regs = 0;
1218
1219 regset = target_regsets;
1220
1221 while (regset->size >= 0)
1222 {
1223 void *buf;
1224 int res;
1225
1226 if (regset->size == 0)
1227 {
1228 regset ++;
1229 continue;
1230 }
1231
1232 buf = malloc (regset->size);
1233 res = ptrace (regset->get_request, inferior_pid, 0, buf);
1234 if (res < 0)
1235 {
1236 if (errno == EIO)
1237 {
1238 /* If we get EIO on the first regset, do not try regsets again.
1239 If we get EIO on a later regset, disable that regset. */
1240 if (regset == target_regsets)
1241 {
1242 use_regsets_p = 0;
1243 return -1;
1244 }
1245 else
1246 {
1247 regset->size = 0;
1248 continue;
1249 }
1250 }
1251 else
1252 {
1253 char s[256];
1254 sprintf (s, "ptrace(regsets_fetch_inferior_registers) PID=%ld",
1255 inferior_pid);
1256 perror (s);
1257 }
1258 }
1259 else if (regset->type == GENERAL_REGS)
1260 saw_general_regs = 1;
1261 regset->store_function (buf);
1262 regset ++;
1263 }
1264 if (saw_general_regs)
1265 return 0;
1266 else
1267 return 1;
1268 }
1269
1270 static int
1271 regsets_store_inferior_registers ()
1272 {
1273 struct regset_info *regset;
1274 int saw_general_regs = 0;
1275
1276 regset = target_regsets;
1277
1278 while (regset->size >= 0)
1279 {
1280 void *buf;
1281 int res;
1282
1283 if (regset->size == 0)
1284 {
1285 regset ++;
1286 continue;
1287 }
1288
1289 buf = malloc (regset->size);
1290
1291 /* First fill the buffer with the current register set contents,
1292 in case there are any items in the kernel's regset that are
1293 not in gdbserver's regcache. */
1294 res = ptrace (regset->get_request, inferior_pid, 0, buf);
1295
1296 if (res == 0)
1297 {
1298 /* Then overlay our cached registers on that. */
1299 regset->fill_function (buf);
1300
1301 /* Only now do we write the register set. */
1302 res = ptrace (regset->set_request, inferior_pid, 0, buf);
1303 }
1304
1305 if (res < 0)
1306 {
1307 if (errno == EIO)
1308 {
1309 /* If we get EIO on the first regset, do not try regsets again.
1310 If we get EIO on a later regset, disable that regset. */
1311 if (regset == target_regsets)
1312 {
1313 use_regsets_p = 0;
1314 return -1;
1315 }
1316 else
1317 {
1318 regset->size = 0;
1319 continue;
1320 }
1321 }
1322 else
1323 {
1324 perror ("Warning: ptrace(regsets_store_inferior_registers)");
1325 }
1326 }
1327 else if (regset->type == GENERAL_REGS)
1328 saw_general_regs = 1;
1329 regset ++;
1330 free (buf);
1331 }
1332 if (saw_general_regs)
1333 return 0;
1334 else
1335 return 1;
1336 return 0;
1337 }
1338
1339 #endif /* HAVE_LINUX_REGSETS */
1340
1341
1342 void
1343 linux_fetch_registers (int regno)
1344 {
1345 #ifdef HAVE_LINUX_REGSETS
1346 if (use_regsets_p)
1347 {
1348 if (regsets_fetch_inferior_registers () == 0)
1349 return;
1350 }
1351 #endif
1352 #ifdef HAVE_LINUX_USRREGS
1353 usr_fetch_inferior_registers (regno);
1354 #endif
1355 }
1356
1357 void
1358 linux_store_registers (int regno)
1359 {
1360 #ifdef HAVE_LINUX_REGSETS
1361 if (use_regsets_p)
1362 {
1363 if (regsets_store_inferior_registers () == 0)
1364 return;
1365 }
1366 #endif
1367 #ifdef HAVE_LINUX_USRREGS
1368 usr_store_inferior_registers (regno);
1369 #endif
1370 }
1371
1372
1373 /* Copy LEN bytes from inferior's memory starting at MEMADDR
1374 to debugger memory starting at MYADDR. */
1375
1376 static int
1377 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1378 {
1379 register int i;
1380 /* Round starting address down to longword boundary. */
1381 register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE);
1382 /* Round ending address up; get number of longwords that makes. */
1383 register int count
1384 = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1)
1385 / sizeof (PTRACE_XFER_TYPE);
1386 /* Allocate buffer of that many longwords. */
1387 register PTRACE_XFER_TYPE *buffer
1388 = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE));
1389
1390 /* Read all the longwords */
1391 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
1392 {
1393 errno = 0;
1394 buffer[i] = ptrace (PTRACE_PEEKTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
1395 if (errno)
1396 return errno;
1397 }
1398
1399 /* Copy appropriate bytes out of the buffer. */
1400 memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), len);
1401
1402 return 0;
1403 }
1404
1405 /* Copy LEN bytes of data from debugger memory at MYADDR
1406 to inferior's memory at MEMADDR.
1407 On failure (cannot write the inferior)
1408 returns the value of errno. */
1409
1410 static int
1411 linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
1412 {
1413 register int i;
1414 /* Round starting address down to longword boundary. */
1415 register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE);
1416 /* Round ending address up; get number of longwords that makes. */
1417 register int count
1418 = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) / sizeof (PTRACE_XFER_TYPE);
1419 /* Allocate buffer of that many longwords. */
1420 register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE));
1421 extern int errno;
1422
1423 if (debug_threads)
1424 {
1425 fprintf (stderr, "Writing %02x to %08lx\n", (unsigned)myaddr[0], (long)memaddr);
1426 }
1427
1428 /* Fill start and end extra bytes of buffer with existing memory data. */
1429
1430 buffer[0] = ptrace (PTRACE_PEEKTEXT, inferior_pid,
1431 (PTRACE_ARG3_TYPE) addr, 0);
1432
1433 if (count > 1)
1434 {
1435 buffer[count - 1]
1436 = ptrace (PTRACE_PEEKTEXT, inferior_pid,
1437 (PTRACE_ARG3_TYPE) (addr + (count - 1)
1438 * sizeof (PTRACE_XFER_TYPE)),
1439 0);
1440 }
1441
1442 /* Copy data to be written over corresponding part of buffer */
1443
1444 memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), myaddr, len);
1445
1446 /* Write the entire buffer. */
1447
1448 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
1449 {
1450 errno = 0;
1451 ptrace (PTRACE_POKETEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]);
1452 if (errno)
1453 return errno;
1454 }
1455
1456 return 0;
1457 }
1458
1459 static void
1460 linux_look_up_symbols (void)
1461 {
1462 #ifdef USE_THREAD_DB
1463 if (using_threads)
1464 return;
1465
1466 using_threads = thread_db_init ();
1467 #endif
1468 }
1469
1470 static void
1471 linux_send_signal (int signum)
1472 {
1473 extern unsigned long signal_pid;
1474
1475 if (cont_thread != 0 && cont_thread != -1)
1476 {
1477 struct process_info *process;
1478
1479 process = get_thread_process (current_inferior);
1480 kill_lwp (process->lwpid, signum);
1481 }
1482 else
1483 kill_lwp (signal_pid, signum);
1484 }
1485
1486 /* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
1487 to debugger memory starting at MYADDR. */
1488
1489 static int
1490 linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
1491 {
1492 char filename[PATH_MAX];
1493 int fd, n;
1494
1495 snprintf (filename, sizeof filename, "/proc/%ld/auxv", inferior_pid);
1496
1497 fd = open (filename, O_RDONLY);
1498 if (fd < 0)
1499 return -1;
1500
1501 if (offset != (CORE_ADDR) 0
1502 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
1503 n = -1;
1504 else
1505 n = read (fd, myaddr, len);
1506
1507 close (fd);
1508
1509 return n;
1510 }
1511
1512 /* These watchpoint related wrapper functions simply pass on the function call
1513 if the target has registered a corresponding function. */
1514
1515 static int
1516 linux_insert_watchpoint (char type, CORE_ADDR addr, int len)
1517 {
1518 if (the_low_target.insert_watchpoint != NULL)
1519 return the_low_target.insert_watchpoint (type, addr, len);
1520 else
1521 /* Unsupported (see target.h). */
1522 return 1;
1523 }
1524
1525 static int
1526 linux_remove_watchpoint (char type, CORE_ADDR addr, int len)
1527 {
1528 if (the_low_target.remove_watchpoint != NULL)
1529 return the_low_target.remove_watchpoint (type, addr, len);
1530 else
1531 /* Unsupported (see target.h). */
1532 return 1;
1533 }
1534
1535 static int
1536 linux_stopped_by_watchpoint (void)
1537 {
1538 if (the_low_target.stopped_by_watchpoint != NULL)
1539 return the_low_target.stopped_by_watchpoint ();
1540 else
1541 return 0;
1542 }
1543
1544 static CORE_ADDR
1545 linux_stopped_data_address (void)
1546 {
1547 if (the_low_target.stopped_data_address != NULL)
1548 return the_low_target.stopped_data_address ();
1549 else
1550 return 0;
1551 }
1552
1553 static struct target_ops linux_target_ops = {
1554 linux_create_inferior,
1555 linux_attach,
1556 linux_kill,
1557 linux_detach,
1558 linux_thread_alive,
1559 linux_resume,
1560 linux_wait,
1561 linux_fetch_registers,
1562 linux_store_registers,
1563 linux_read_memory,
1564 linux_write_memory,
1565 linux_look_up_symbols,
1566 linux_send_signal,
1567 linux_read_auxv,
1568 linux_insert_watchpoint,
1569 linux_remove_watchpoint,
1570 linux_stopped_by_watchpoint,
1571 linux_stopped_data_address,
1572 };
1573
1574 static void
1575 linux_init_signals ()
1576 {
1577 /* FIXME drow/2002-06-09: As above, we should check with LinuxThreads
1578 to find what the cancel signal actually is. */
1579 signal (__SIGRTMIN+1, SIG_IGN);
1580 }
1581
1582 void
1583 initialize_low (void)
1584 {
1585 using_threads = 0;
1586 set_target_ops (&linux_target_ops);
1587 set_breakpoint_data (the_low_target.breakpoint,
1588 the_low_target.breakpoint_len);
1589 init_registers ();
1590 linux_init_signals ();
1591 }
This page took 0.06293 seconds and 4 git commands to generate.