1 /* GNU/Linux native-dependent code common to multiple platforms.
2 Copyright (C) 2003, 2004 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
26 #include "gdb_assert.h"
27 #ifdef HAVE_TKILL_SYSCALL
29 #include <sys/syscall.h>
31 #include <sys/ptrace.h>
32 #include "linux-nat.h"
33 #include "gdbthread.h"
37 /* If the system headers did not provide the constants, hard-code the normal
39 #ifndef PTRACE_EVENT_FORK
41 #define PTRACE_SETOPTIONS 0x4200
42 #define PTRACE_GETEVENTMSG 0x4201
44 /* options set using PTRACE_SETOPTIONS */
45 #define PTRACE_O_TRACESYSGOOD 0x00000001
46 #define PTRACE_O_TRACEFORK 0x00000002
47 #define PTRACE_O_TRACEVFORK 0x00000004
48 #define PTRACE_O_TRACECLONE 0x00000008
49 #define PTRACE_O_TRACEEXEC 0x00000010
50 #define PTRACE_O_TRACEVFORKDONE 0x00000020
51 #define PTRACE_O_TRACEEXIT 0x00000040
53 /* Wait extended result codes for the above trace options. */
54 #define PTRACE_EVENT_FORK 1
55 #define PTRACE_EVENT_VFORK 2
56 #define PTRACE_EVENT_CLONE 3
57 #define PTRACE_EVENT_EXEC 4
58 #define PTRACE_EVENT_VFORKDONE 5
59 #define PTRACE_EVENT_EXIT 6
61 #endif /* PTRACE_EVENT_FORK */
63 /* We can't always assume that this flag is available, but all systems
64 with the ptrace event handlers also have __WALL, so it's safe to use
67 #define __WALL 0x40000000 /* Wait for any child. */
70 static int debug_linux_nat
;
72 extern struct target_ops child_ops
;
74 static int linux_parent_pid
;
76 struct simple_pid_list
79 struct simple_pid_list
*next
;
81 struct simple_pid_list
*stopped_pids
;
83 /* This variable is a tri-state flag: -1 for unknown, 0 if PTRACE_O_TRACEFORK
84 can not be used, 1 if it can. */
86 static int linux_supports_tracefork_flag
= -1;
88 /* If we have PTRACE_O_TRACEFORK, this flag indicates whether we also have
89 PTRACE_O_TRACEVFORKDONE. */
91 static int linux_supports_tracevforkdone_flag
= -1;
94 /* Trivial list manipulation functions to keep track of a list of
95 new stopped processes. */
97 add_to_pid_list (struct simple_pid_list
**listp
, int pid
)
99 struct simple_pid_list
*new_pid
= xmalloc (sizeof (struct simple_pid_list
));
101 new_pid
->next
= *listp
;
106 pull_pid_from_list (struct simple_pid_list
**listp
, int pid
)
108 struct simple_pid_list
**p
;
110 for (p
= listp
; *p
!= NULL
; p
= &(*p
)->next
)
111 if ((*p
)->pid
== pid
)
113 struct simple_pid_list
*next
= (*p
)->next
;
122 linux_record_stopped_pid (int pid
)
124 add_to_pid_list (&stopped_pids
, pid
);
128 /* A helper function for linux_test_for_tracefork, called after fork (). */
131 linux_tracefork_child (void)
135 ptrace (PTRACE_TRACEME
, 0, 0, 0);
136 kill (getpid (), SIGSTOP
);
141 /* Determine if PTRACE_O_TRACEFORK can be used to follow fork events. We
142 create a child process, attach to it, use PTRACE_SETOPTIONS to enable
143 fork tracing, and let it fork. If the process exits, we assume that
144 we can't use TRACEFORK; if we get the fork notification, and we can
145 extract the new child's PID, then we assume that we can. */
148 linux_test_for_tracefork (void)
150 int child_pid
, ret
, status
;
155 perror_with_name ("linux_test_for_tracefork: fork");
158 linux_tracefork_child ();
160 ret
= waitpid (child_pid
, &status
, 0);
162 perror_with_name ("linux_test_for_tracefork: waitpid");
163 else if (ret
!= child_pid
)
164 error ("linux_test_for_tracefork: waitpid: unexpected result %d.", ret
);
165 if (! WIFSTOPPED (status
))
166 error ("linux_test_for_tracefork: waitpid: unexpected status %d.", status
);
168 linux_supports_tracefork_flag
= 0;
170 ret
= ptrace (PTRACE_SETOPTIONS
, child_pid
, 0, PTRACE_O_TRACEFORK
);
173 ptrace (PTRACE_KILL
, child_pid
, 0, 0);
174 waitpid (child_pid
, &status
, 0);
178 /* Check whether PTRACE_O_TRACEVFORKDONE is available. */
179 ret
= ptrace (PTRACE_SETOPTIONS
, child_pid
, 0,
180 PTRACE_O_TRACEFORK
| PTRACE_O_TRACEVFORKDONE
);
181 linux_supports_tracevforkdone_flag
= (ret
== 0);
183 ptrace (PTRACE_CONT
, child_pid
, 0, 0);
184 ret
= waitpid (child_pid
, &status
, 0);
185 if (ret
== child_pid
&& WIFSTOPPED (status
)
186 && status
>> 16 == PTRACE_EVENT_FORK
)
189 ret
= ptrace (PTRACE_GETEVENTMSG
, child_pid
, 0, &second_pid
);
190 if (ret
== 0 && second_pid
!= 0)
194 linux_supports_tracefork_flag
= 1;
195 waitpid (second_pid
, &second_status
, 0);
196 ptrace (PTRACE_DETACH
, second_pid
, 0, 0);
200 if (WIFSTOPPED (status
))
202 ptrace (PTRACE_DETACH
, child_pid
, 0, 0);
203 waitpid (child_pid
, &status
, 0);
207 /* Return non-zero iff we have tracefork functionality available.
208 This function also sets linux_supports_tracefork_flag. */
211 linux_supports_tracefork (void)
213 if (linux_supports_tracefork_flag
== -1)
214 linux_test_for_tracefork ();
215 return linux_supports_tracefork_flag
;
219 linux_supports_tracevforkdone (void)
221 if (linux_supports_tracefork_flag
== -1)
222 linux_test_for_tracefork ();
223 return linux_supports_tracevforkdone_flag
;
228 linux_enable_event_reporting (ptid_t ptid
)
230 int pid
= ptid_get_pid (ptid
);
233 if (! linux_supports_tracefork ())
236 options
= PTRACE_O_TRACEFORK
| PTRACE_O_TRACEVFORK
| PTRACE_O_TRACEEXEC
237 | PTRACE_O_TRACECLONE
;
238 if (linux_supports_tracevforkdone ())
239 options
|= PTRACE_O_TRACEVFORKDONE
;
241 /* Do not enable PTRACE_O_TRACEEXIT until GDB is more prepared to support
242 read-only process state. */
244 ptrace (PTRACE_SETOPTIONS
, pid
, 0, options
);
248 child_post_attach (int pid
)
250 linux_enable_event_reporting (pid_to_ptid (pid
));
254 linux_child_post_startup_inferior (ptid_t ptid
)
256 linux_enable_event_reporting (ptid
);
259 #ifndef LINUX_CHILD_POST_STARTUP_INFERIOR
261 child_post_startup_inferior (ptid_t ptid
)
263 linux_child_post_startup_inferior (ptid
);
268 child_follow_fork (int follow_child
)
271 struct target_waitstatus last_status
;
273 int parent_pid
, child_pid
;
275 get_last_target_status (&last_ptid
, &last_status
);
276 has_vforked
= (last_status
.kind
== TARGET_WAITKIND_VFORKED
);
277 parent_pid
= ptid_get_pid (last_ptid
);
278 child_pid
= last_status
.value
.related_pid
;
282 /* We're already attached to the parent, by default. */
284 /* Before detaching from the child, remove all breakpoints from
285 it. (This won't actually modify the breakpoint list, but will
286 physically remove the breakpoints from the child.) */
287 /* If we vforked this will remove the breakpoints from the parent
288 also, but they'll be reinserted below. */
289 detach_breakpoints (child_pid
);
291 fprintf_filtered (gdb_stdout
,
292 "Detaching after fork from child process %d.\n",
295 ptrace (PTRACE_DETACH
, child_pid
, 0, 0);
299 if (linux_supports_tracevforkdone ())
303 ptrace (PTRACE_CONT
, parent_pid
, 0, 0);
304 waitpid (parent_pid
, &status
, __WALL
);
305 if ((status
>> 16) != PTRACE_EVENT_VFORKDONE
)
306 warning ("Unexpected waitpid result %06x when waiting for "
307 "vfork-done", status
);
311 /* We can't insert breakpoints until the child has
312 finished with the shared memory region. We need to
313 wait until that happens. Ideal would be to just
315 - ptrace (PTRACE_SYSCALL, parent_pid, 0, 0);
316 - waitpid (parent_pid, &status, __WALL);
317 However, most architectures can't handle a syscall
318 being traced on the way out if it wasn't traced on
321 We might also think to loop, continuing the child
322 until it exits or gets a SIGTRAP. One problem is
323 that the child might call ptrace with PTRACE_TRACEME.
325 There's no simple and reliable way to figure out when
326 the vforked child will be done with its copy of the
327 shared memory. We could step it out of the syscall,
328 two instructions, let it go, and then single-step the
329 parent once. When we have hardware single-step, this
330 would work; with software single-step it could still
331 be made to work but we'd have to be able to insert
332 single-step breakpoints in the child, and we'd have
333 to insert -just- the single-step breakpoint in the
334 parent. Very awkward.
336 In the end, the best we can do is to make sure it
337 runs for a little while. Hopefully it will be out of
338 range of any breakpoints we reinsert. Usually this
339 is only the single-step breakpoint at vfork's return
345 /* Since we vforked, breakpoints were removed in the parent
346 too. Put them back. */
347 reattach_breakpoints (parent_pid
);
352 char child_pid_spelling
[40];
354 /* Needed to keep the breakpoint lists in sync. */
356 detach_breakpoints (child_pid
);
358 /* Before detaching from the parent, remove all breakpoints from it. */
359 remove_breakpoints ();
361 fprintf_filtered (gdb_stdout
,
362 "Attaching after fork to child process %d.\n",
365 /* If we're vforking, we may want to hold on to the parent until
366 the child exits or execs. At exec time we can remove the old
367 breakpoints from the parent and detach it; at exit time we
368 could do the same (or even, sneakily, resume debugging it - the
369 child's exec has failed, or something similar).
371 This doesn't clean up "properly", because we can't call
372 target_detach, but that's OK; if the current target is "child",
373 then it doesn't need any further cleanups, and lin_lwp will
374 generally not encounter vfork (vfork is defined to fork
377 The holding part is very easy if we have VFORKDONE events;
378 but keeping track of both processes is beyond GDB at the
379 moment. So we don't expose the parent to the rest of GDB.
380 Instead we quietly hold onto it until such time as we can
384 linux_parent_pid
= parent_pid
;
386 target_detach (NULL
, 0);
388 inferior_ptid
= pid_to_ptid (child_pid
);
389 push_target (&child_ops
);
391 /* Reset breakpoints in the child as appropriate. */
392 follow_inferior_reset_breakpoints ();
399 linux_handle_extended_wait (int pid
, int status
,
400 struct target_waitstatus
*ourstatus
)
402 int event
= status
>> 16;
404 if (event
== PTRACE_EVENT_FORK
|| event
== PTRACE_EVENT_VFORK
405 || event
== PTRACE_EVENT_CLONE
)
407 unsigned long new_pid
;
410 ptrace (PTRACE_GETEVENTMSG
, pid
, 0, &new_pid
);
412 /* If we haven't already seen the new PID stop, wait for it now. */
413 if (! pull_pid_from_list (&stopped_pids
, new_pid
))
415 /* The new child has a pending SIGSTOP. We can't affect it until it
416 hits the SIGSTOP, but we're already attached. */
418 ret
= waitpid (new_pid
, &status
,
419 (event
== PTRACE_EVENT_CLONE
) ? __WCLONE
: 0);
420 } while (ret
== -1 && errno
== EINTR
);
422 perror_with_name ("waiting for new child");
423 else if (ret
!= new_pid
)
424 internal_error (__FILE__
, __LINE__
,
425 "wait returned unexpected PID %d", ret
);
426 else if (!WIFSTOPPED (status
) || WSTOPSIG (status
) != SIGSTOP
)
427 internal_error (__FILE__
, __LINE__
,
428 "wait returned unexpected status 0x%x", status
);
431 if (event
== PTRACE_EVENT_FORK
)
432 ourstatus
->kind
= TARGET_WAITKIND_FORKED
;
433 else if (event
== PTRACE_EVENT_VFORK
)
434 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
436 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
438 ourstatus
->value
.related_pid
= new_pid
;
439 return inferior_ptid
;
442 if (event
== PTRACE_EVENT_EXEC
)
444 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
445 ourstatus
->value
.execd_pathname
446 = xstrdup (child_pid_to_exec_file (pid
));
448 if (linux_parent_pid
)
450 detach_breakpoints (linux_parent_pid
);
451 ptrace (PTRACE_DETACH
, linux_parent_pid
, 0, 0);
453 linux_parent_pid
= 0;
456 return inferior_ptid
;
459 internal_error (__FILE__
, __LINE__
,
460 "unknown ptrace event %d", event
);
465 child_insert_fork_catchpoint (int pid
)
467 if (! linux_supports_tracefork ())
468 error ("Your system does not support fork catchpoints.");
474 child_insert_vfork_catchpoint (int pid
)
476 if (!linux_supports_tracefork ())
477 error ("Your system does not support vfork catchpoints.");
483 child_insert_exec_catchpoint (int pid
)
485 if (!linux_supports_tracefork ())
486 error ("Your system does not support exec catchpoints.");
495 int pid
= PIDGET (inferior_ptid
);
496 struct target_waitstatus last
;
503 /* If we're stopped while forking and we haven't followed yet, kill the
504 other task. We need to do this first because the parent will be
505 sleeping if this is a vfork. */
507 get_last_target_status (&last_ptid
, &last
);
509 if (last
.kind
== TARGET_WAITKIND_FORKED
510 || last
.kind
== TARGET_WAITKIND_VFORKED
)
512 ptrace (PT_KILL
, last
.value
.related_pid
, 0, 0);
513 ptrace_wait (null_ptid
, &status
);
516 /* Kill the current process. */
517 ptrace (PT_KILL
, pid
, 0, 0);
518 ret
= ptrace_wait (null_ptid
, &status
);
520 /* We might get a SIGCHLD instead of an exit status. This is
521 aggravated by the first kill above - a child has just died. */
523 while (ret
== pid
&& WIFSTOPPED (status
))
525 ptrace (PT_KILL
, pid
, 0, 0);
526 ret
= ptrace_wait (null_ptid
, &status
);
529 target_mourn_inferior ();
532 /* On GNU/Linux there are no real LWP's. The closest thing to LWP's
533 are processes sharing the same VM space. A multi-threaded process
534 is basically a group of such processes. However, such a grouping
535 is almost entirely a user-space issue; the kernel doesn't enforce
536 such a grouping at all (this might change in the future). In
537 general, we'll rely on the threads library (i.e. the GNU/Linux
538 Threads library) to provide such a grouping.
540 It is perfectly well possible to write a multi-threaded application
541 without the assistance of a threads library, by using the clone
542 system call directly. This module should be able to give some
543 rudimentary support for debugging such applications if developers
544 specify the CLONE_PTRACE flag in the clone system call, and are
545 using the Linux kernel 2.4 or above.
547 Note that there are some peculiarities in GNU/Linux that affect
550 - In general one should specify the __WCLONE flag to waitpid in
551 order to make it report events for any of the cloned processes
552 (and leave it out for the initial process). However, if a cloned
553 process has exited the exit status is only reported if the
554 __WCLONE flag is absent. Linux kernel 2.4 has a __WALL flag, but
555 we cannot use it since GDB must work on older systems too.
557 - When a traced, cloned process exits and is waited for by the
558 debugger, the kernel reassigns it to the original parent and
559 keeps it around as a "zombie". Somehow, the GNU/Linux Threads
560 library doesn't notice this, which leads to the "zombie problem":
561 When debugged a multi-threaded process that spawns a lot of
562 threads will run out of processes, even if the threads exit,
563 because the "zombies" stay around. */
565 /* List of known LWPs. */
566 static struct lwp_info
*lwp_list
;
568 /* Number of LWPs in the list. */
571 /* Non-zero if we're running in "threaded" mode. */
575 #define GET_LWP(ptid) ptid_get_lwp (ptid)
576 #define GET_PID(ptid) ptid_get_pid (ptid)
577 #define is_lwp(ptid) (GET_LWP (ptid) != 0)
578 #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
580 /* If the last reported event was a SIGTRAP, this variable is set to
581 the process id of the LWP/thread that got it. */
585 /* This module's target-specific operations. */
586 static struct target_ops linux_nat_ops
;
588 /* The standard child operations. */
589 extern struct target_ops child_ops
;
591 /* Since we cannot wait (in linux_nat_wait) for the initial process and
592 any cloned processes with a single call to waitpid, we have to use
593 the WNOHANG flag and call waitpid in a loop. To optimize
594 things a bit we use `sigsuspend' to wake us up when a process has
595 something to report (it will send us a SIGCHLD if it has). To make
596 this work we have to juggle with the signal mask. We save the
597 original signal mask such that we can restore it before creating a
598 new process in order to avoid blocking certain signals in the
599 inferior. We then block SIGCHLD during the waitpid/sigsuspend
602 /* Original signal mask. */
603 static sigset_t normal_mask
;
605 /* Signal mask for use with sigsuspend in linux_nat_wait, initialized in
606 _initialize_linux_nat. */
607 static sigset_t suspend_mask
;
609 /* Signals to block to make that sigsuspend work. */
610 static sigset_t blocked_mask
;
613 /* Prototypes for local functions. */
614 static int stop_wait_callback (struct lwp_info
*lp
, void *data
);
615 static int linux_nat_thread_alive (ptid_t ptid
);
617 /* Convert wait status STATUS to a string. Used for printing debug
621 status_to_str (int status
)
625 if (WIFSTOPPED (status
))
626 snprintf (buf
, sizeof (buf
), "%s (stopped)",
627 strsignal (WSTOPSIG (status
)));
628 else if (WIFSIGNALED (status
))
629 snprintf (buf
, sizeof (buf
), "%s (terminated)",
630 strsignal (WSTOPSIG (status
)));
632 snprintf (buf
, sizeof (buf
), "%d (exited)", WEXITSTATUS (status
));
637 /* Initialize the list of LWPs. Note that this module, contrary to
638 what GDB's generic threads layer does for its thread list,
639 re-initializes the LWP lists whenever we mourn or detach (which
640 doesn't involve mourning) the inferior. */
645 struct lwp_info
*lp
, *lpnext
;
647 for (lp
= lwp_list
; lp
; lp
= lpnext
)
658 /* Add the LWP specified by PID to the list. If this causes the
659 number of LWPs to become larger than one, go into "threaded" mode.
660 Return a pointer to the structure describing the new LWP. */
662 static struct lwp_info
*
663 add_lwp (ptid_t ptid
)
667 gdb_assert (is_lwp (ptid
));
669 lp
= (struct lwp_info
*) xmalloc (sizeof (struct lwp_info
));
671 memset (lp
, 0, sizeof (struct lwp_info
));
673 lp
->waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
685 /* Remove the LWP specified by PID from the list. */
688 delete_lwp (ptid_t ptid
)
690 struct lwp_info
*lp
, *lpprev
;
694 for (lp
= lwp_list
; lp
; lpprev
= lp
, lp
= lp
->next
)
695 if (ptid_equal (lp
->ptid
, ptid
))
701 /* We don't go back to "non-threaded" mode if the number of threads
702 becomes less than two. */
706 lpprev
->next
= lp
->next
;
713 /* Return a pointer to the structure describing the LWP corresponding
714 to PID. If no corresponding LWP could be found, return NULL. */
716 static struct lwp_info
*
717 find_lwp_pid (ptid_t ptid
)
723 lwp
= GET_LWP (ptid
);
725 lwp
= GET_PID (ptid
);
727 for (lp
= lwp_list
; lp
; lp
= lp
->next
)
728 if (lwp
== GET_LWP (lp
->ptid
))
734 /* Call CALLBACK with its second argument set to DATA for every LWP in
735 the list. If CALLBACK returns 1 for a particular LWP, return a
736 pointer to the structure describing that LWP immediately.
737 Otherwise return NULL. */
740 iterate_over_lwps (int (*callback
) (struct lwp_info
*, void *), void *data
)
742 struct lwp_info
*lp
, *lpnext
;
744 for (lp
= lwp_list
; lp
; lp
= lpnext
)
747 if ((*callback
) (lp
, data
))
754 /* Attach to the LWP specified by PID. If VERBOSE is non-zero, print
755 a message telling the user that a new LWP has been added to the
759 lin_lwp_attach_lwp (ptid_t ptid
, int verbose
)
761 struct lwp_info
*lp
, *found_lp
;
763 gdb_assert (is_lwp (ptid
));
765 /* Make sure SIGCHLD is blocked. We don't want SIGCHLD events
766 to interrupt either the ptrace() or waitpid() calls below. */
767 if (!sigismember (&blocked_mask
, SIGCHLD
))
769 sigaddset (&blocked_mask
, SIGCHLD
);
770 sigprocmask (SIG_BLOCK
, &blocked_mask
, NULL
);
774 printf_filtered ("[New %s]\n", target_pid_to_str (ptid
));
776 found_lp
= lp
= find_lwp_pid (ptid
);
780 /* We assume that we're already attached to any LWP that has an id
781 equal to the overall process id, and to any LWP that is already
782 in our list of LWPs. If we're not seeing exit events from threads
783 and we've had PID wraparound since we last tried to stop all threads,
784 this assumption might be wrong; fortunately, this is very unlikely
786 if (GET_LWP (ptid
) != GET_PID (ptid
) && found_lp
== NULL
)
791 if (ptrace (PTRACE_ATTACH
, GET_LWP (ptid
), 0, 0) < 0)
792 error ("Can't attach %s: %s", target_pid_to_str (ptid
),
793 safe_strerror (errno
));
796 fprintf_unfiltered (gdb_stdlog
,
797 "LLAL: PTRACE_ATTACH %s, 0, 0 (OK)\n",
798 target_pid_to_str (ptid
));
800 pid
= waitpid (GET_LWP (ptid
), &status
, 0);
801 if (pid
== -1 && errno
== ECHILD
)
803 /* Try again with __WCLONE to check cloned processes. */
804 pid
= waitpid (GET_LWP (ptid
), &status
, __WCLONE
);
808 gdb_assert (pid
== GET_LWP (ptid
)
809 && WIFSTOPPED (status
) && WSTOPSIG (status
));
811 child_post_attach (pid
);
817 fprintf_unfiltered (gdb_stdlog
,
818 "LLAL: waitpid %s received %s\n",
819 target_pid_to_str (ptid
),
820 status_to_str (status
));
825 /* We assume that the LWP representing the original process is
826 already stopped. Mark it as stopped in the data structure
827 that the linux ptrace layer uses to keep track of threads.
828 Note that this won't have already been done since the main
829 thread will have, we assume, been stopped by an attach from a
836 linux_nat_attach (char *args
, int from_tty
)
842 /* FIXME: We should probably accept a list of process id's, and
843 attach all of them. */
844 child_ops
.to_attach (args
, from_tty
);
846 /* Add the initial process as the first LWP to the list. */
847 lp
= add_lwp (BUILD_LWP (GET_PID (inferior_ptid
), GET_PID (inferior_ptid
)));
849 /* Make sure the initial process is stopped. The user-level threads
850 layer might want to poke around in the inferior, and that won't
851 work if things haven't stabilized yet. */
852 pid
= waitpid (GET_PID (inferior_ptid
), &status
, 0);
853 if (pid
== -1 && errno
== ECHILD
)
855 warning ("%s is a cloned process", target_pid_to_str (inferior_ptid
));
857 /* Try again with __WCLONE to check cloned processes. */
858 pid
= waitpid (GET_PID (inferior_ptid
), &status
, __WCLONE
);
862 gdb_assert (pid
== GET_PID (inferior_ptid
)
863 && WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGSTOP
);
867 /* Fake the SIGSTOP that core GDB expects. */
868 lp
->status
= W_STOPCODE (SIGSTOP
);
872 fprintf_unfiltered (gdb_stdlog
,
873 "LLA: waitpid %ld, faking SIGSTOP\n", (long) pid
);
878 detach_callback (struct lwp_info
*lp
, void *data
)
880 gdb_assert (lp
->status
== 0 || WIFSTOPPED (lp
->status
));
882 if (debug_linux_nat
&& lp
->status
)
883 fprintf_unfiltered (gdb_stdlog
, "DC: Pending %s for %s on detach.\n",
884 strsignal (WSTOPSIG (lp
->status
)),
885 target_pid_to_str (lp
->ptid
));
887 while (lp
->signalled
&& lp
->stopped
)
890 if (ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0,
891 WSTOPSIG (lp
->status
)) < 0)
892 error ("Can't continue %s: %s", target_pid_to_str (lp
->ptid
),
893 safe_strerror (errno
));
896 fprintf_unfiltered (gdb_stdlog
,
897 "DC: PTRACE_CONTINUE (%s, 0, %s) (OK)\n",
898 target_pid_to_str (lp
->ptid
),
899 status_to_str (lp
->status
));
904 /* FIXME drow/2003-08-26: There was a call to stop_wait_callback
905 here. But since lp->signalled was cleared above,
906 stop_wait_callback didn't do anything; the process was left
907 running. Shouldn't we be waiting for it to stop?
908 I've removed the call, since stop_wait_callback now does do
909 something when called with lp->signalled == 0. */
911 gdb_assert (lp
->status
== 0 || WIFSTOPPED (lp
->status
));
914 /* We don't actually detach from the LWP that has an id equal to the
915 overall process id just yet. */
916 if (GET_LWP (lp
->ptid
) != GET_PID (lp
->ptid
))
919 if (ptrace (PTRACE_DETACH
, GET_LWP (lp
->ptid
), 0,
920 WSTOPSIG (lp
->status
)) < 0)
921 error ("Can't detach %s: %s", target_pid_to_str (lp
->ptid
),
922 safe_strerror (errno
));
925 fprintf_unfiltered (gdb_stdlog
,
926 "PTRACE_DETACH (%s, %s, 0) (OK)\n",
927 target_pid_to_str (lp
->ptid
),
928 strsignal (WSTOPSIG (lp
->status
)));
930 delete_lwp (lp
->ptid
);
937 linux_nat_detach (char *args
, int from_tty
)
939 iterate_over_lwps (detach_callback
, NULL
);
941 /* Only the initial process should be left right now. */
942 gdb_assert (num_lwps
== 1);
944 trap_ptid
= null_ptid
;
946 /* Destroy LWP info; it's no longer valid. */
949 /* Restore the original signal mask. */
950 sigprocmask (SIG_SETMASK
, &normal_mask
, NULL
);
951 sigemptyset (&blocked_mask
);
953 inferior_ptid
= pid_to_ptid (GET_PID (inferior_ptid
));
954 child_ops
.to_detach (args
, from_tty
);
960 resume_callback (struct lwp_info
*lp
, void *data
)
962 if (lp
->stopped
&& lp
->status
== 0)
964 struct thread_info
*tp
;
966 child_resume (pid_to_ptid (GET_LWP (lp
->ptid
)), 0, TARGET_SIGNAL_0
);
968 fprintf_unfiltered (gdb_stdlog
,
969 "RC: PTRACE_CONT %s, 0, 0 (resume sibling)\n",
970 target_pid_to_str (lp
->ptid
));
979 resume_clear_callback (struct lwp_info
*lp
, void *data
)
986 resume_set_callback (struct lwp_info
*lp
, void *data
)
993 linux_nat_resume (ptid_t ptid
, int step
, enum target_signal signo
)
998 /* A specific PTID means `step only this process id'. */
999 resume_all
= (PIDGET (ptid
) == -1);
1002 iterate_over_lwps (resume_set_callback
, NULL
);
1004 iterate_over_lwps (resume_clear_callback
, NULL
);
1006 /* If PID is -1, it's the current inferior that should be
1007 handled specially. */
1008 if (PIDGET (ptid
) == -1)
1009 ptid
= inferior_ptid
;
1011 lp
= find_lwp_pid (ptid
);
1014 ptid
= pid_to_ptid (GET_LWP (lp
->ptid
));
1016 /* Remember if we're stepping. */
1019 /* Mark this LWP as resumed. */
1022 /* If we have a pending wait status for this thread, there is no
1023 point in resuming the process. */
1026 /* FIXME: What should we do if we are supposed to continue
1027 this thread with a signal? */
1028 gdb_assert (signo
== TARGET_SIGNAL_0
);
1032 /* Mark LWP as not stopped to prevent it from being continued by
1038 iterate_over_lwps (resume_callback
, NULL
);
1040 child_resume (ptid
, step
, signo
);
1041 if (debug_linux_nat
)
1042 fprintf_unfiltered (gdb_stdlog
,
1043 "LLR: %s %s, %s (resume event thread)\n",
1044 step
? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
1045 target_pid_to_str (ptid
),
1046 signo
? strsignal (signo
) : "0");
1049 /* Issue kill to specified lwp. */
1051 static int tkill_failed
;
1054 kill_lwp (int lwpid
, int signo
)
1058 /* Use tkill, if possible, in case we are using nptl threads. If tkill
1059 fails, then we are not using nptl threads and we should be using kill. */
1061 #ifdef HAVE_TKILL_SYSCALL
1064 int ret
= syscall (__NR_tkill
, lwpid
, signo
);
1065 if (errno
!= ENOSYS
)
1072 return kill (lwpid
, signo
);
1075 /* Handle a GNU/Linux extended wait response. Most of the work we
1076 just pass off to linux_handle_extended_wait, but if it reports a
1077 clone event we need to add the new LWP to our list (and not report
1078 the trap to higher layers). This function returns non-zero if
1079 the event should be ignored and we should wait again. */
1082 linux_nat_handle_extended (struct lwp_info
*lp
, int status
)
1084 linux_handle_extended_wait (GET_LWP (lp
->ptid
), status
,
1087 /* TARGET_WAITKIND_SPURIOUS is used to indicate clone events. */
1088 if (lp
->waitstatus
.kind
== TARGET_WAITKIND_SPURIOUS
)
1090 struct lwp_info
*new_lp
;
1091 new_lp
= add_lwp (BUILD_LWP (lp
->waitstatus
.value
.related_pid
,
1092 GET_PID (inferior_ptid
)));
1094 new_lp
->stopped
= 1;
1096 lp
->waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
1098 if (debug_linux_nat
)
1099 fprintf_unfiltered (gdb_stdlog
,
1100 "LLHE: Got clone event from LWP %ld, resuming\n",
1101 GET_LWP (lp
->ptid
));
1102 ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0, 0);
1110 /* Wait for LP to stop. Returns the wait status, or 0 if the LWP has
1114 wait_lwp (struct lwp_info
*lp
)
1118 int thread_dead
= 0;
1120 gdb_assert (!lp
->stopped
);
1121 gdb_assert (lp
->status
== 0);
1123 pid
= waitpid (GET_LWP (lp
->ptid
), &status
, 0);
1124 if (pid
== -1 && errno
== ECHILD
)
1126 pid
= waitpid (GET_LWP (lp
->ptid
), &status
, __WCLONE
);
1127 if (pid
== -1 && errno
== ECHILD
)
1129 /* The thread has previously exited. We need to delete it
1130 now because, for some vendor 2.4 kernels with NPTL
1131 support backported, there won't be an exit event unless
1132 it is the main thread. 2.6 kernels will report an exit
1133 event for each thread that exits, as expected. */
1135 if (debug_linux_nat
)
1136 fprintf_unfiltered (gdb_stdlog
, "WL: %s vanished.\n",
1137 target_pid_to_str (lp
->ptid
));
1143 gdb_assert (pid
== GET_LWP (lp
->ptid
));
1145 if (debug_linux_nat
)
1147 fprintf_unfiltered (gdb_stdlog
,
1148 "WL: waitpid %s received %s\n",
1149 target_pid_to_str (lp
->ptid
),
1150 status_to_str (status
));
1154 /* Check if the thread has exited. */
1155 if (WIFEXITED (status
) || WIFSIGNALED (status
))
1158 if (debug_linux_nat
)
1159 fprintf_unfiltered (gdb_stdlog
, "WL: %s exited.\n",
1160 target_pid_to_str (lp
->ptid
));
1165 if (in_thread_list (lp
->ptid
))
1167 /* Core GDB cannot deal with us deleting the current thread. */
1168 if (!ptid_equal (lp
->ptid
, inferior_ptid
))
1169 delete_thread (lp
->ptid
);
1170 printf_unfiltered ("[%s exited]\n",
1171 target_pid_to_str (lp
->ptid
));
1174 delete_lwp (lp
->ptid
);
1178 gdb_assert (WIFSTOPPED (status
));
1180 /* Handle GNU/Linux's extended waitstatus for trace events. */
1181 if (WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGTRAP
&& status
>> 16 != 0)
1183 if (debug_linux_nat
)
1184 fprintf_unfiltered (gdb_stdlog
,
1185 "WL: Handling extended status 0x%06x\n",
1187 if (linux_nat_handle_extended (lp
, status
))
1188 return wait_lwp (lp
);
1194 /* Send a SIGSTOP to LP. */
1197 stop_callback (struct lwp_info
*lp
, void *data
)
1199 if (!lp
->stopped
&& !lp
->signalled
)
1203 if (debug_linux_nat
)
1205 fprintf_unfiltered (gdb_stdlog
,
1206 "SC: kill %s **<SIGSTOP>**\n",
1207 target_pid_to_str (lp
->ptid
));
1210 ret
= kill_lwp (GET_LWP (lp
->ptid
), SIGSTOP
);
1211 if (debug_linux_nat
)
1213 fprintf_unfiltered (gdb_stdlog
,
1214 "SC: lwp kill %d %s\n",
1216 errno
? safe_strerror (errno
) : "ERRNO-OK");
1220 gdb_assert (lp
->status
== 0);
1226 /* Wait until LP is stopped. If DATA is non-null it is interpreted as
1227 a pointer to a set of signals to be flushed immediately. */
1230 stop_wait_callback (struct lwp_info
*lp
, void *data
)
1232 sigset_t
*flush_mask
= data
;
1238 status
= wait_lwp (lp
);
1242 /* Ignore any signals in FLUSH_MASK. */
1243 if (flush_mask
&& sigismember (flush_mask
, WSTOPSIG (status
)))
1252 ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0, 0);
1253 if (debug_linux_nat
)
1254 fprintf_unfiltered (gdb_stdlog
,
1255 "PTRACE_CONT %s, 0, 0 (%s)\n",
1256 target_pid_to_str (lp
->ptid
),
1257 errno
? safe_strerror (errno
) : "OK");
1259 return stop_wait_callback (lp
, flush_mask
);
1262 if (WSTOPSIG (status
) != SIGSTOP
)
1264 if (WSTOPSIG (status
) == SIGTRAP
)
1266 /* If a LWP other than the LWP that we're reporting an
1267 event for has hit a GDB breakpoint (as opposed to
1268 some random trap signal), then just arrange for it to
1269 hit it again later. We don't keep the SIGTRAP status
1270 and don't forward the SIGTRAP signal to the LWP. We
1271 will handle the current event, eventually we will
1272 resume all LWPs, and this one will get its breakpoint
1275 If we do not do this, then we run the risk that the
1276 user will delete or disable the breakpoint, but the
1277 thread will have already tripped on it. */
1279 /* Now resume this LWP and get the SIGSTOP event. */
1281 ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0, 0);
1282 if (debug_linux_nat
)
1284 fprintf_unfiltered (gdb_stdlog
,
1285 "PTRACE_CONT %s, 0, 0 (%s)\n",
1286 target_pid_to_str (lp
->ptid
),
1287 errno
? safe_strerror (errno
) : "OK");
1289 fprintf_unfiltered (gdb_stdlog
,
1290 "SWC: Candidate SIGTRAP event in %s\n",
1291 target_pid_to_str (lp
->ptid
));
1293 /* Hold the SIGTRAP for handling by linux_nat_wait. */
1294 stop_wait_callback (lp
, data
);
1295 /* If there's another event, throw it back into the queue. */
1298 if (debug_linux_nat
)
1300 fprintf_unfiltered (gdb_stdlog
,
1301 "SWC: kill %s, %s\n",
1302 target_pid_to_str (lp
->ptid
),
1303 status_to_str ((int) status
));
1305 kill_lwp (GET_LWP (lp
->ptid
), WSTOPSIG (lp
->status
));
1307 /* Save the sigtrap event. */
1308 lp
->status
= status
;
1313 /* The thread was stopped with a signal other than
1314 SIGSTOP, and didn't accidentally trip a breakpoint. */
1316 if (debug_linux_nat
)
1318 fprintf_unfiltered (gdb_stdlog
,
1319 "SWC: Pending event %s in %s\n",
1320 status_to_str ((int) status
),
1321 target_pid_to_str (lp
->ptid
));
1323 /* Now resume this LWP and get the SIGSTOP event. */
1325 ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0, 0);
1326 if (debug_linux_nat
)
1327 fprintf_unfiltered (gdb_stdlog
,
1328 "SWC: PTRACE_CONT %s, 0, 0 (%s)\n",
1329 target_pid_to_str (lp
->ptid
),
1330 errno
? safe_strerror (errno
) : "OK");
1332 /* Hold this event/waitstatus while we check to see if
1333 there are any more (we still want to get that SIGSTOP). */
1334 stop_wait_callback (lp
, data
);
1335 /* If the lp->status field is still empty, use it to hold
1336 this event. If not, then this event must be returned
1337 to the event queue of the LWP. */
1338 if (lp
->status
== 0)
1339 lp
->status
= status
;
1342 if (debug_linux_nat
)
1344 fprintf_unfiltered (gdb_stdlog
,
1345 "SWC: kill %s, %s\n",
1346 target_pid_to_str (lp
->ptid
),
1347 status_to_str ((int) status
));
1349 kill_lwp (GET_LWP (lp
->ptid
), WSTOPSIG (status
));
1356 /* We caught the SIGSTOP that we intended to catch, so
1357 there's no SIGSTOP pending. */
1366 /* Check whether PID has any pending signals in FLUSH_MASK. If so set
1367 the appropriate bits in PENDING, and return 1 - otherwise return 0. */
1370 linux_nat_has_pending (int pid
, sigset_t
*pending
, sigset_t
*flush_mask
)
1372 sigset_t blocked
, ignored
;
1375 linux_proc_pending_signals (pid
, pending
, &blocked
, &ignored
);
1380 for (i
= 1; i
< NSIG
; i
++)
1381 if (sigismember (pending
, i
))
1382 if (!sigismember (flush_mask
, i
)
1383 || sigismember (&blocked
, i
)
1384 || sigismember (&ignored
, i
))
1385 sigdelset (pending
, i
);
1387 if (sigisemptyset (pending
))
1393 /* DATA is interpreted as a mask of signals to flush. If LP has
1394 signals pending, and they are all in the flush mask, then arrange
1395 to flush them. LP should be stopped, as should all other threads
1396 it might share a signal queue with. */
1399 flush_callback (struct lwp_info
*lp
, void *data
)
1401 sigset_t
*flush_mask
= data
;
1402 sigset_t pending
, intersection
, blocked
, ignored
;
1405 /* Normally, when an LWP exits, it is removed from the LWP list. The
1406 last LWP isn't removed till later, however. So if there is only
1407 one LWP on the list, make sure it's alive. */
1408 if (lwp_list
== lp
&& lp
->next
== NULL
)
1409 if (!linux_nat_thread_alive (lp
->ptid
))
1412 /* Just because the LWP is stopped doesn't mean that new signals
1413 can't arrive from outside, so this function must be careful of
1414 race conditions. However, because all threads are stopped, we
1415 can assume that the pending mask will not shrink unless we resume
1416 the LWP, and that it will then get another signal. We can't
1417 control which one, however. */
1421 if (debug_linux_nat
)
1422 printf_unfiltered ("FC: LP has pending status %06x\n", lp
->status
);
1423 if (WIFSTOPPED (lp
->status
) && sigismember (flush_mask
, WSTOPSIG (lp
->status
)))
1427 while (linux_nat_has_pending (GET_LWP (lp
->ptid
), &pending
, flush_mask
))
1432 ret
= ptrace (PTRACE_CONT
, GET_LWP (lp
->ptid
), 0, 0);
1433 if (debug_linux_nat
)
1434 fprintf_unfiltered (gdb_stderr
,
1435 "FC: Sent PTRACE_CONT, ret %d %d\n", ret
, errno
);
1438 stop_wait_callback (lp
, flush_mask
);
1439 if (debug_linux_nat
)
1440 fprintf_unfiltered (gdb_stderr
,
1441 "FC: Wait finished; saved status is %d\n",
1448 /* Return non-zero if LP has a wait status pending. */
1451 status_callback (struct lwp_info
*lp
, void *data
)
1453 /* Only report a pending wait status if we pretend that this has
1454 indeed been resumed. */
1455 return (lp
->status
!= 0 && lp
->resumed
);
1458 /* Return non-zero if LP isn't stopped. */
1461 running_callback (struct lwp_info
*lp
, void *data
)
1463 return (lp
->stopped
== 0 || (lp
->status
!= 0 && lp
->resumed
));
1466 /* Count the LWP's that have had events. */
1469 count_events_callback (struct lwp_info
*lp
, void *data
)
1473 gdb_assert (count
!= NULL
);
1475 /* Count only LWPs that have a SIGTRAP event pending. */
1477 && WIFSTOPPED (lp
->status
) && WSTOPSIG (lp
->status
) == SIGTRAP
)
1483 /* Select the LWP (if any) that is currently being single-stepped. */
1486 select_singlestep_lwp_callback (struct lwp_info
*lp
, void *data
)
1488 if (lp
->step
&& lp
->status
!= 0)
1494 /* Select the Nth LWP that has had a SIGTRAP event. */
1497 select_event_lwp_callback (struct lwp_info
*lp
, void *data
)
1499 int *selector
= data
;
1501 gdb_assert (selector
!= NULL
);
1503 /* Select only LWPs that have a SIGTRAP event pending. */
1505 && WIFSTOPPED (lp
->status
) && WSTOPSIG (lp
->status
) == SIGTRAP
)
1506 if ((*selector
)-- == 0)
1513 cancel_breakpoints_callback (struct lwp_info
*lp
, void *data
)
1515 struct lwp_info
*event_lp
= data
;
1517 /* Leave the LWP that has been elected to receive a SIGTRAP alone. */
1521 /* If a LWP other than the LWP that we're reporting an event for has
1522 hit a GDB breakpoint (as opposed to some random trap signal),
1523 then just arrange for it to hit it again later. We don't keep
1524 the SIGTRAP status and don't forward the SIGTRAP signal to the
1525 LWP. We will handle the current event, eventually we will resume
1526 all LWPs, and this one will get its breakpoint trap again.
1528 If we do not do this, then we run the risk that the user will
1529 delete or disable the breakpoint, but the LWP will have already
1533 && WIFSTOPPED (lp
->status
) && WSTOPSIG (lp
->status
) == SIGTRAP
1534 && breakpoint_inserted_here_p (read_pc_pid (lp
->ptid
) -
1535 DECR_PC_AFTER_BREAK
))
1537 if (debug_linux_nat
)
1538 fprintf_unfiltered (gdb_stdlog
,
1539 "CBC: Push back breakpoint for %s\n",
1540 target_pid_to_str (lp
->ptid
));
1542 /* Back up the PC if necessary. */
1543 if (DECR_PC_AFTER_BREAK
)
1544 write_pc_pid (read_pc_pid (lp
->ptid
) - DECR_PC_AFTER_BREAK
, lp
->ptid
);
1546 /* Throw away the SIGTRAP. */
1553 /* Select one LWP out of those that have events pending. */
1556 select_event_lwp (struct lwp_info
**orig_lp
, int *status
)
1559 int random_selector
;
1560 struct lwp_info
*event_lp
;
1562 /* Record the wait status for the origional LWP. */
1563 (*orig_lp
)->status
= *status
;
1565 /* Give preference to any LWP that is being single-stepped. */
1566 event_lp
= iterate_over_lwps (select_singlestep_lwp_callback
, NULL
);
1567 if (event_lp
!= NULL
)
1569 if (debug_linux_nat
)
1570 fprintf_unfiltered (gdb_stdlog
,
1571 "SEL: Select single-step %s\n",
1572 target_pid_to_str (event_lp
->ptid
));
1576 /* No single-stepping LWP. Select one at random, out of those
1577 which have had SIGTRAP events. */
1579 /* First see how many SIGTRAP events we have. */
1580 iterate_over_lwps (count_events_callback
, &num_events
);
1582 /* Now randomly pick a LWP out of those that have had a SIGTRAP. */
1583 random_selector
= (int)
1584 ((num_events
* (double) rand ()) / (RAND_MAX
+ 1.0));
1586 if (debug_linux_nat
&& num_events
> 1)
1587 fprintf_unfiltered (gdb_stdlog
,
1588 "SEL: Found %d SIGTRAP events, selecting #%d\n",
1589 num_events
, random_selector
);
1591 event_lp
= iterate_over_lwps (select_event_lwp_callback
,
1595 if (event_lp
!= NULL
)
1597 /* Switch the event LWP. */
1598 *orig_lp
= event_lp
;
1599 *status
= event_lp
->status
;
1602 /* Flush the wait status for the event LWP. */
1603 (*orig_lp
)->status
= 0;
1606 /* Return non-zero if LP has been resumed. */
1609 resumed_callback (struct lwp_info
*lp
, void *data
)
1616 /* We need to override child_wait to support attaching to cloned
1617 processes, since a normal wait (as done by the default version)
1618 ignores those processes. */
1620 /* Wait for child PTID to do something. Return id of the child,
1621 minus_one_ptid in case of error; store status into *OURSTATUS. */
1624 child_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
1630 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
1634 set_sigint_trap (); /* Causes SIGINT to be passed on to the
1635 attached process. */
1638 pid
= waitpid (GET_PID (ptid
), &status
, 0);
1639 if (pid
== -1 && errno
== ECHILD
)
1640 /* Try again with __WCLONE to check cloned processes. */
1641 pid
= waitpid (GET_PID (ptid
), &status
, __WCLONE
);
1643 if (debug_linux_nat
)
1645 fprintf_unfiltered (gdb_stdlog
,
1646 "CW: waitpid %ld received %s\n",
1647 (long) pid
, status_to_str (status
));
1652 /* Make sure we don't report an event for the exit of the
1653 original program, if we've detached from it. */
1654 if (pid
!= -1 && !WIFSTOPPED (status
) && pid
!= GET_PID (inferior_ptid
))
1660 /* Check for stop events reported by a process we didn't already
1661 know about - in this case, anything other than inferior_ptid.
1663 If we're expecting to receive stopped processes after fork,
1664 vfork, and clone events, then we'll just add the new one to
1665 our list and go back to waiting for the event to be reported
1666 - the stopped process might be returned from waitpid before
1667 or after the event is. If we want to handle debugging of
1668 CLONE_PTRACE processes we need to do more here, i.e. switch
1669 to multi-threaded mode. */
1670 if (pid
!= -1 && WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGSTOP
1671 && pid
!= GET_PID (inferior_ptid
))
1673 linux_record_stopped_pid (pid
);
1678 /* Handle GNU/Linux's extended waitstatus for trace events. */
1679 if (pid
!= -1 && WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGTRAP
1680 && status
>> 16 != 0)
1682 linux_handle_extended_wait (pid
, status
, ourstatus
);
1684 /* If we see a clone event, detach the child, and don't
1685 report the event. It would be nice to offer some way to
1686 switch into a non-thread-db based threaded mode at this
1688 if (ourstatus
->kind
== TARGET_WAITKIND_SPURIOUS
)
1690 ptrace (PTRACE_DETACH
, ourstatus
->value
.related_pid
, 0, 0);
1691 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
1692 ptrace (PTRACE_CONT
, pid
, 0, 0);
1698 clear_sigio_trap ();
1699 clear_sigint_trap ();
1701 while (pid
== -1 && save_errno
== EINTR
);
1705 warning ("Child process unexpectedly missing: %s",
1706 safe_strerror (errno
));
1708 /* Claim it exited with unknown signal. */
1709 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1710 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
1711 return minus_one_ptid
;
1714 if (ourstatus
->kind
== TARGET_WAITKIND_IGNORE
)
1715 store_waitstatus (ourstatus
, status
);
1717 return pid_to_ptid (pid
);
1722 /* Stop an active thread, verify it still exists, then resume it. */
1725 stop_and_resume_callback (struct lwp_info
*lp
, void *data
)
1727 struct lwp_info
*ptr
;
1729 if (!lp
->stopped
&& !lp
->signalled
)
1731 stop_callback (lp
, NULL
);
1732 stop_wait_callback (lp
, NULL
);
1733 /* Resume if the lwp still exists. */
1734 for (ptr
= lwp_list
; ptr
; ptr
= ptr
->next
)
1737 resume_callback (lp
, NULL
);
1738 resume_set_callback (lp
, NULL
);
1745 linux_nat_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
1747 struct lwp_info
*lp
= NULL
;
1750 pid_t pid
= PIDGET (ptid
);
1751 sigset_t flush_mask
;
1753 sigemptyset (&flush_mask
);
1755 /* Make sure SIGCHLD is blocked. */
1756 if (!sigismember (&blocked_mask
, SIGCHLD
))
1758 sigaddset (&blocked_mask
, SIGCHLD
);
1759 sigprocmask (SIG_BLOCK
, &blocked_mask
, NULL
);
1764 /* Make sure there is at least one LWP that has been resumed, at
1765 least if there are any LWPs at all. */
1766 gdb_assert (num_lwps
== 0 || iterate_over_lwps (resumed_callback
, NULL
));
1768 /* First check if there is a LWP with a wait status pending. */
1771 /* Any LWP that's been resumed will do. */
1772 lp
= iterate_over_lwps (status_callback
, NULL
);
1775 status
= lp
->status
;
1778 if (debug_linux_nat
&& status
)
1779 fprintf_unfiltered (gdb_stdlog
,
1780 "LLW: Using pending wait status %s for %s.\n",
1781 status_to_str (status
),
1782 target_pid_to_str (lp
->ptid
));
1785 /* But if we don't fine one, we'll have to wait, and check both
1786 cloned and uncloned processes. We start with the cloned
1788 options
= __WCLONE
| WNOHANG
;
1790 else if (is_lwp (ptid
))
1792 if (debug_linux_nat
)
1793 fprintf_unfiltered (gdb_stdlog
,
1794 "LLW: Waiting for specific LWP %s.\n",
1795 target_pid_to_str (ptid
));
1797 /* We have a specific LWP to check. */
1798 lp
= find_lwp_pid (ptid
);
1800 status
= lp
->status
;
1803 if (debug_linux_nat
&& status
)
1804 fprintf_unfiltered (gdb_stdlog
,
1805 "LLW: Using pending wait status %s for %s.\n",
1806 status_to_str (status
),
1807 target_pid_to_str (lp
->ptid
));
1809 /* If we have to wait, take into account whether PID is a cloned
1810 process or not. And we have to convert it to something that
1811 the layer beneath us can understand. */
1812 options
= lp
->cloned
? __WCLONE
: 0;
1813 pid
= GET_LWP (ptid
);
1816 if (status
&& lp
->signalled
)
1818 /* A pending SIGSTOP may interfere with the normal stream of
1819 events. In a typical case where interference is a problem,
1820 we have a SIGSTOP signal pending for LWP A while
1821 single-stepping it, encounter an event in LWP B, and take the
1822 pending SIGSTOP while trying to stop LWP A. After processing
1823 the event in LWP B, LWP A is continued, and we'll never see
1824 the SIGTRAP associated with the last time we were
1825 single-stepping LWP A. */
1827 /* Resume the thread. It should halt immediately returning the
1829 registers_changed ();
1830 child_resume (pid_to_ptid (GET_LWP (lp
->ptid
)), lp
->step
,
1832 if (debug_linux_nat
)
1833 fprintf_unfiltered (gdb_stdlog
,
1834 "LLW: %s %s, 0, 0 (expect SIGSTOP)\n",
1835 lp
->step
? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
1836 target_pid_to_str (lp
->ptid
));
1838 gdb_assert (lp
->resumed
);
1840 /* This should catch the pending SIGSTOP. */
1841 stop_wait_callback (lp
, NULL
);
1844 set_sigint_trap (); /* Causes SIGINT to be passed on to the
1845 attached process. */
1852 lwpid
= waitpid (pid
, &status
, options
);
1855 gdb_assert (pid
== -1 || lwpid
== pid
);
1857 if (debug_linux_nat
)
1859 fprintf_unfiltered (gdb_stdlog
,
1860 "LLW: waitpid %ld received %s\n",
1861 (long) lwpid
, status_to_str (status
));
1864 lp
= find_lwp_pid (pid_to_ptid (lwpid
));
1866 /* Check for stop events reported by a process we didn't
1867 already know about - anything not already in our LWP
1870 If we're expecting to receive stopped processes after
1871 fork, vfork, and clone events, then we'll just add the
1872 new one to our list and go back to waiting for the event
1873 to be reported - the stopped process might be returned
1874 from waitpid before or after the event is. */
1875 if (WIFSTOPPED (status
) && !lp
)
1877 linux_record_stopped_pid (lwpid
);
1882 /* Make sure we don't report an event for the exit of an LWP not in
1883 our list, i.e. not part of the current process. This can happen
1884 if we detach from a program we original forked and then it
1886 if (!WIFSTOPPED (status
) && !lp
)
1892 /* NOTE drow/2003-06-17: This code seems to be meant for debugging
1893 CLONE_PTRACE processes which do not use the thread library -
1894 otherwise we wouldn't find the new LWP this way. That doesn't
1895 currently work, and the following code is currently unreachable
1896 due to the two blocks above. If it's fixed some day, this code
1897 should be broken out into a function so that we can also pick up
1898 LWPs from the new interface. */
1901 lp
= add_lwp (BUILD_LWP (lwpid
, GET_PID (inferior_ptid
)));
1902 if (options
& __WCLONE
)
1907 gdb_assert (WIFSTOPPED (status
)
1908 && WSTOPSIG (status
) == SIGSTOP
);
1911 if (!in_thread_list (inferior_ptid
))
1913 inferior_ptid
= BUILD_LWP (GET_PID (inferior_ptid
),
1914 GET_PID (inferior_ptid
));
1915 add_thread (inferior_ptid
);
1918 add_thread (lp
->ptid
);
1919 printf_unfiltered ("[New %s]\n",
1920 target_pid_to_str (lp
->ptid
));
1924 /* Handle GNU/Linux's extended waitstatus for trace events. */
1925 if (WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGTRAP
&& status
>> 16 != 0)
1927 if (debug_linux_nat
)
1928 fprintf_unfiltered (gdb_stdlog
,
1929 "LLW: Handling extended status 0x%06x\n",
1931 if (linux_nat_handle_extended (lp
, status
))
1938 /* Check if the thread has exited. */
1939 if ((WIFEXITED (status
) || WIFSIGNALED (status
)) && num_lwps
> 1)
1941 if (in_thread_list (lp
->ptid
))
1943 /* Core GDB cannot deal with us deleting the current
1945 if (!ptid_equal (lp
->ptid
, inferior_ptid
))
1946 delete_thread (lp
->ptid
);
1947 printf_unfiltered ("[%s exited]\n",
1948 target_pid_to_str (lp
->ptid
));
1951 /* If this is the main thread, we must stop all threads and
1952 verify if they are still alive. This is because in the nptl
1953 thread model, there is no signal issued for exiting LWPs
1954 other than the main thread. We only get the main thread
1955 exit signal once all child threads have already exited.
1956 If we stop all the threads and use the stop_wait_callback
1957 to check if they have exited we can determine whether this
1958 signal should be ignored or whether it means the end of the
1959 debugged application, regardless of which threading model
1961 if (GET_PID (lp
->ptid
) == GET_LWP (lp
->ptid
))
1964 iterate_over_lwps (stop_and_resume_callback
, NULL
);
1967 if (debug_linux_nat
)
1968 fprintf_unfiltered (gdb_stdlog
,
1969 "LLW: %s exited.\n",
1970 target_pid_to_str (lp
->ptid
));
1972 delete_lwp (lp
->ptid
);
1974 /* If there is at least one more LWP, then the exit signal
1975 was not the end of the debugged application and should be
1979 /* Make sure there is at least one thread running. */
1980 gdb_assert (iterate_over_lwps (running_callback
, NULL
));
1982 /* Discard the event. */
1988 /* Check if the current LWP has previously exited. In the nptl
1989 thread model, LWPs other than the main thread do not issue
1990 signals when they exit so we must check whenever the thread
1991 has stopped. A similar check is made in stop_wait_callback(). */
1992 if (num_lwps
> 1 && !linux_nat_thread_alive (lp
->ptid
))
1994 if (in_thread_list (lp
->ptid
))
1996 /* Core GDB cannot deal with us deleting the current
1998 if (!ptid_equal (lp
->ptid
, inferior_ptid
))
1999 delete_thread (lp
->ptid
);
2000 printf_unfiltered ("[%s exited]\n",
2001 target_pid_to_str (lp
->ptid
));
2003 if (debug_linux_nat
)
2004 fprintf_unfiltered (gdb_stdlog
,
2005 "LLW: %s exited.\n",
2006 target_pid_to_str (lp
->ptid
));
2008 delete_lwp (lp
->ptid
);
2010 /* Make sure there is at least one thread running. */
2011 gdb_assert (iterate_over_lwps (running_callback
, NULL
));
2013 /* Discard the event. */
2018 /* Make sure we don't report a SIGSTOP that we sent
2019 ourselves in an attempt to stop an LWP. */
2021 && WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGSTOP
)
2023 if (debug_linux_nat
)
2024 fprintf_unfiltered (gdb_stdlog
,
2025 "LLW: Delayed SIGSTOP caught for %s.\n",
2026 target_pid_to_str (lp
->ptid
));
2028 /* This is a delayed SIGSTOP. */
2031 registers_changed ();
2032 child_resume (pid_to_ptid (GET_LWP (lp
->ptid
)), lp
->step
,
2034 if (debug_linux_nat
)
2035 fprintf_unfiltered (gdb_stdlog
,
2036 "LLW: %s %s, 0, 0 (discard SIGSTOP)\n",
2038 "PTRACE_SINGLESTEP" : "PTRACE_CONT",
2039 target_pid_to_str (lp
->ptid
));
2042 gdb_assert (lp
->resumed
);
2044 /* Discard the event. */
2054 /* Alternate between checking cloned and uncloned processes. */
2055 options
^= __WCLONE
;
2057 /* And suspend every time we have checked both. */
2058 if (options
& __WCLONE
)
2059 sigsuspend (&suspend_mask
);
2062 /* We shouldn't end up here unless we want to try again. */
2063 gdb_assert (status
== 0);
2066 clear_sigio_trap ();
2067 clear_sigint_trap ();
2071 /* Don't report signals that GDB isn't interested in, such as
2072 signals that are neither printed nor stopped upon. Stopping all
2073 threads can be a bit time-consuming so if we want decent
2074 performance with heavily multi-threaded programs, especially when
2075 they're using a high frequency timer, we'd better avoid it if we
2078 if (WIFSTOPPED (status
))
2080 int signo
= target_signal_from_host (WSTOPSIG (status
));
2082 if (signal_stop_state (signo
) == 0
2083 && signal_print_state (signo
) == 0
2084 && signal_pass_state (signo
) == 1)
2086 /* FIMXE: kettenis/2001-06-06: Should we resume all threads
2087 here? It is not clear we should. GDB may not expect
2088 other threads to run. On the other hand, not resuming
2089 newly attached threads may cause an unwanted delay in
2090 getting them running. */
2091 registers_changed ();
2092 child_resume (pid_to_ptid (GET_LWP (lp
->ptid
)), lp
->step
, signo
);
2093 if (debug_linux_nat
)
2094 fprintf_unfiltered (gdb_stdlog
,
2095 "LLW: %s %s, %s (preempt 'handle')\n",
2097 "PTRACE_SINGLESTEP" : "PTRACE_CONT",
2098 target_pid_to_str (lp
->ptid
),
2099 signo
? strsignal (signo
) : "0");
2105 if (signo
== TARGET_SIGNAL_INT
&& signal_pass_state (signo
) == 0)
2107 /* If ^C/BREAK is typed at the tty/console, SIGINT gets
2108 forwarded to the entire process group, that is, all LWP's
2109 will receive it. Since we only want to report it once,
2110 we try to flush it from all LWPs except this one. */
2111 sigaddset (&flush_mask
, SIGINT
);
2115 /* This LWP is stopped now. */
2118 if (debug_linux_nat
)
2119 fprintf_unfiltered (gdb_stdlog
, "LLW: Candidate event %s in %s.\n",
2120 status_to_str (status
), target_pid_to_str (lp
->ptid
));
2122 /* Now stop all other LWP's ... */
2123 iterate_over_lwps (stop_callback
, NULL
);
2125 /* ... and wait until all of them have reported back that they're no
2127 iterate_over_lwps (stop_wait_callback
, &flush_mask
);
2128 iterate_over_lwps (flush_callback
, &flush_mask
);
2130 /* If we're not waiting for a specific LWP, choose an event LWP from
2131 among those that have had events. Giving equal priority to all
2132 LWPs that have had events helps prevent starvation. */
2134 select_event_lwp (&lp
, &status
);
2136 /* Now that we've selected our final event LWP, cancel any
2137 breakpoints in other LWPs that have hit a GDB breakpoint. See
2138 the comment in cancel_breakpoints_callback to find out why. */
2139 iterate_over_lwps (cancel_breakpoints_callback
, lp
);
2141 /* If we're not running in "threaded" mode, we'll report the bare
2144 if (WIFSTOPPED (status
) && WSTOPSIG (status
) == SIGTRAP
)
2146 trap_ptid
= (threaded
? lp
->ptid
: pid_to_ptid (GET_LWP (lp
->ptid
)));
2147 if (debug_linux_nat
)
2148 fprintf_unfiltered (gdb_stdlog
,
2149 "LLW: trap_ptid is %s.\n",
2150 target_pid_to_str (trap_ptid
));
2153 trap_ptid
= null_ptid
;
2155 if (lp
->waitstatus
.kind
!= TARGET_WAITKIND_IGNORE
)
2157 *ourstatus
= lp
->waitstatus
;
2158 lp
->waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
2161 store_waitstatus (ourstatus
, status
);
2163 return (threaded
? lp
->ptid
: pid_to_ptid (GET_LWP (lp
->ptid
)));
2167 kill_callback (struct lwp_info
*lp
, void *data
)
2170 ptrace (PTRACE_KILL
, GET_LWP (lp
->ptid
), 0, 0);
2171 if (debug_linux_nat
)
2172 fprintf_unfiltered (gdb_stdlog
,
2173 "KC: PTRACE_KILL %s, 0, 0 (%s)\n",
2174 target_pid_to_str (lp
->ptid
),
2175 errno
? safe_strerror (errno
) : "OK");
2181 kill_wait_callback (struct lwp_info
*lp
, void *data
)
2185 /* We must make sure that there are no pending events (delayed
2186 SIGSTOPs, pending SIGTRAPs, etc.) to make sure the current
2187 program doesn't interfere with any following debugging session. */
2189 /* For cloned processes we must check both with __WCLONE and
2190 without, since the exit status of a cloned process isn't reported
2196 pid
= waitpid (GET_LWP (lp
->ptid
), NULL
, __WCLONE
);
2197 if (pid
!= (pid_t
) -1 && debug_linux_nat
)
2199 fprintf_unfiltered (gdb_stdlog
,
2200 "KWC: wait %s received unknown.\n",
2201 target_pid_to_str (lp
->ptid
));
2204 while (pid
== GET_LWP (lp
->ptid
));
2206 gdb_assert (pid
== -1 && errno
== ECHILD
);
2211 pid
= waitpid (GET_LWP (lp
->ptid
), NULL
, 0);
2212 if (pid
!= (pid_t
) -1 && debug_linux_nat
)
2214 fprintf_unfiltered (gdb_stdlog
,
2215 "KWC: wait %s received unk.\n",
2216 target_pid_to_str (lp
->ptid
));
2219 while (pid
== GET_LWP (lp
->ptid
));
2221 gdb_assert (pid
== -1 && errno
== ECHILD
);
2226 linux_nat_kill (void)
2228 /* Kill all LWP's ... */
2229 iterate_over_lwps (kill_callback
, NULL
);
2231 /* ... and wait until we've flushed all events. */
2232 iterate_over_lwps (kill_wait_callback
, NULL
);
2234 target_mourn_inferior ();
2238 linux_nat_create_inferior (char *exec_file
, char *allargs
, char **env
,
2241 child_ops
.to_create_inferior (exec_file
, allargs
, env
, from_tty
);
2245 linux_nat_mourn_inferior (void)
2247 trap_ptid
= null_ptid
;
2249 /* Destroy LWP info; it's no longer valid. */
2252 /* Restore the original signal mask. */
2253 sigprocmask (SIG_SETMASK
, &normal_mask
, NULL
);
2254 sigemptyset (&blocked_mask
);
2256 child_ops
.to_mourn_inferior ();
2260 linux_nat_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
2261 struct mem_attrib
*attrib
, struct target_ops
*target
)
2263 struct cleanup
*old_chain
= save_inferior_ptid ();
2266 if (is_lwp (inferior_ptid
))
2267 inferior_ptid
= pid_to_ptid (GET_LWP (inferior_ptid
));
2269 xfer
= linux_proc_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, target
);
2271 xfer
= child_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, target
);
2273 do_cleanups (old_chain
);
2278 linux_nat_thread_alive (ptid_t ptid
)
2280 gdb_assert (is_lwp (ptid
));
2283 ptrace (PTRACE_PEEKUSER
, GET_LWP (ptid
), 0, 0);
2284 if (debug_linux_nat
)
2285 fprintf_unfiltered (gdb_stdlog
,
2286 "LLTA: PTRACE_PEEKUSER %s, 0, 0 (%s)\n",
2287 target_pid_to_str (ptid
),
2288 errno
? safe_strerror (errno
) : "OK");
2296 linux_nat_pid_to_str (ptid_t ptid
)
2298 static char buf
[64];
2302 snprintf (buf
, sizeof (buf
), "LWP %ld", GET_LWP (ptid
));
2306 return normal_pid_to_str (ptid
);
2310 init_linux_nat_ops (void)
2313 linux_nat_ops
.to_open
= linux_nat_open
;
2315 linux_nat_ops
.to_shortname
= "lwp-layer";
2316 linux_nat_ops
.to_longname
= "lwp-layer";
2317 linux_nat_ops
.to_doc
= "Low level threads support (LWP layer)";
2318 linux_nat_ops
.to_attach
= linux_nat_attach
;
2319 linux_nat_ops
.to_detach
= linux_nat_detach
;
2320 linux_nat_ops
.to_resume
= linux_nat_resume
;
2321 linux_nat_ops
.to_wait
= linux_nat_wait
;
2322 /* fetch_inferior_registers and store_inferior_registers will
2323 honor the LWP id, so we can use them directly. */
2324 linux_nat_ops
.to_fetch_registers
= fetch_inferior_registers
;
2325 linux_nat_ops
.to_store_registers
= store_inferior_registers
;
2326 linux_nat_ops
.to_xfer_memory
= linux_nat_xfer_memory
;
2327 linux_nat_ops
.to_kill
= linux_nat_kill
;
2328 linux_nat_ops
.to_create_inferior
= linux_nat_create_inferior
;
2329 linux_nat_ops
.to_mourn_inferior
= linux_nat_mourn_inferior
;
2330 linux_nat_ops
.to_thread_alive
= linux_nat_thread_alive
;
2331 linux_nat_ops
.to_pid_to_str
= linux_nat_pid_to_str
;
2332 linux_nat_ops
.to_post_startup_inferior
= child_post_startup_inferior
;
2333 linux_nat_ops
.to_post_attach
= child_post_attach
;
2334 linux_nat_ops
.to_insert_fork_catchpoint
= child_insert_fork_catchpoint
;
2335 linux_nat_ops
.to_insert_vfork_catchpoint
= child_insert_vfork_catchpoint
;
2336 linux_nat_ops
.to_insert_exec_catchpoint
= child_insert_exec_catchpoint
;
2338 linux_nat_ops
.to_stratum
= thread_stratum
;
2339 linux_nat_ops
.to_has_thread_control
= tc_schedlock
;
2340 linux_nat_ops
.to_magic
= OPS_MAGIC
;
2344 sigchld_handler (int signo
)
2346 /* Do nothing. The only reason for this handler is that it allows
2347 us to use sigsuspend in linux_nat_wait above to wait for the
2348 arrival of a SIGCHLD. */
2352 _initialize_linux_nat (void)
2354 struct sigaction action
;
2356 extern void thread_db_init (struct target_ops
*);
2358 init_linux_nat_ops ();
2359 add_target (&linux_nat_ops
);
2360 thread_db_init (&linux_nat_ops
);
2362 /* Save the original signal mask. */
2363 sigprocmask (SIG_SETMASK
, NULL
, &normal_mask
);
2365 action
.sa_handler
= sigchld_handler
;
2366 sigemptyset (&action
.sa_mask
);
2367 action
.sa_flags
= 0;
2368 sigaction (SIGCHLD
, &action
, NULL
);
2370 /* Make sure we don't block SIGCHLD during a sigsuspend. */
2371 sigprocmask (SIG_SETMASK
, NULL
, &suspend_mask
);
2372 sigdelset (&suspend_mask
, SIGCHLD
);
2374 sigemptyset (&blocked_mask
);
2376 deprecated_add_show_from_set
2377 (add_set_cmd ("lin-lwp", no_class
, var_zinteger
,
2378 (char *) &debug_linux_nat
,
2379 "Set debugging of GNU/Linux lwp module.\n\
2380 Enables printf debugging output.\n", &setdebuglist
), &showdebuglist
);
2384 /* FIXME: kettenis/2000-08-26: The stuff on this page is specific to
2385 the GNU/Linux Threads library and therefore doesn't really belong
2388 /* Read variable NAME in the target and return its value if found.
2389 Otherwise return zero. It is assumed that the type of the variable
2393 get_signo (const char *name
)
2395 struct minimal_symbol
*ms
;
2398 ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
2402 if (target_read_memory (SYMBOL_VALUE_ADDRESS (ms
), (char *) &signo
,
2403 sizeof (signo
)) != 0)
2409 /* Return the set of signals used by the threads library in *SET. */
2412 lin_thread_get_thread_signals (sigset_t
*set
)
2414 struct sigaction action
;
2415 int restart
, cancel
;
2419 restart
= get_signo ("__pthread_sig_restart");
2423 cancel
= get_signo ("__pthread_sig_cancel");
2427 sigaddset (set
, restart
);
2428 sigaddset (set
, cancel
);
2430 /* The GNU/Linux Threads library makes terminating threads send a
2431 special "cancel" signal instead of SIGCHLD. Make sure we catch
2432 those (to prevent them from terminating GDB itself, which is
2433 likely to be their default action) and treat them the same way as
2436 action
.sa_handler
= sigchld_handler
;
2437 sigemptyset (&action
.sa_mask
);
2438 action
.sa_flags
= 0;
2439 sigaction (cancel
, &action
, NULL
);
2441 /* We block the "cancel" signal throughout this code ... */
2442 sigaddset (&blocked_mask
, cancel
);
2443 sigprocmask (SIG_BLOCK
, &blocked_mask
, NULL
);
2445 /* ... except during a sigsuspend. */
2446 sigdelset (&suspend_mask
, cancel
);