GDB (xrefs)
Loading...
Searching...
No Matches
linux-nat.c
Go to the documentation of this file.
1/* GNU/Linux native-dependent code common to multiple platforms.
2
3 Copyright (C) 2001-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "inferior.h"
22#include "infrun.h"
23#include "target.h"
24#include "nat/linux-nat.h"
25#include "nat/linux-waitpid.h"
26#include "gdbsupport/gdb_wait.h"
27#include <unistd.h>
28#include <sys/syscall.h>
29#include "nat/gdb_ptrace.h"
30#include "linux-nat.h"
31#include "nat/linux-ptrace.h"
32#include "nat/linux-procfs.h"
34#include "linux-fork.h"
35#include "gdbthread.h"
36#include "gdbcmd.h"
37#include "regcache.h"
38#include "regset.h"
39#include "inf-child.h"
40#include "inf-ptrace.h"
41#include "auxv.h"
42#include <sys/procfs.h>
43#include "elf-bfd.h"
44#include "gregset.h"
45#include "gdbcore.h"
46#include <ctype.h>
47#include <sys/stat.h>
48#include <fcntl.h>
49#include "inf-loop.h"
50#include "gdbsupport/event-loop.h"
51#include "event-top.h"
52#include <pwd.h>
53#include <sys/types.h>
54#include <dirent.h>
55#include "xml-support.h"
56#include <sys/vfs.h>
57#include "solib.h"
58#include "nat/linux-osdata.h"
59#include "linux-tdep.h"
60#include "symfile.h"
61#include "gdbsupport/agent.h"
62#include "tracepoint.h"
63#include "target-descriptions.h"
64#include "gdbsupport/filestuff.h"
65#include "objfiles.h"
67#include "gdbsupport/block-signals.h"
68#include "gdbsupport/fileio.h"
69#include "gdbsupport/scope-exit.h"
70#include "gdbsupport/gdb-sigmask.h"
71#include "gdbsupport/common-debug.h"
72#include <unordered_map>
73
74/* This comment documents high-level logic of this file.
75
76Waiting for events in sync mode
77===============================
78
79When waiting for an event in a specific thread, we just use waitpid,
80passing the specific pid, and not passing WNOHANG.
81
82When waiting for an event in all threads, waitpid is not quite good:
83
84- If the thread group leader exits while other threads in the thread
85 group still exist, waitpid(TGID, ...) hangs. That waitpid won't
86 return an exit status until the other threads in the group are
87 reaped.
88
89- When a non-leader thread execs, that thread just vanishes without
90 reporting an exit (so we'd hang if we waited for it explicitly in
91 that case). The exec event is instead reported to the TGID pid.
92
93The solution is to always use -1 and WNOHANG, together with
94sigsuspend.
95
96First, we use non-blocking waitpid to check for events. If nothing is
97found, we use sigsuspend to wait for SIGCHLD. When SIGCHLD arrives,
98it means something happened to a child process. As soon as we know
99there's an event, we get back to calling nonblocking waitpid.
100
101Note that SIGCHLD should be blocked between waitpid and sigsuspend
102calls, so that we don't miss a signal. If SIGCHLD arrives in between,
103when it's blocked, the signal becomes pending and sigsuspend
104immediately notices it and returns.
105
106Waiting for events in async mode (TARGET_WNOHANG)
107=================================================
108
109In async mode, GDB should always be ready to handle both user input
110and target events, so neither blocking waitpid nor sigsuspend are
111viable options. Instead, we should asynchronously notify the GDB main
112event loop whenever there's an unprocessed event from the target. We
113detect asynchronous target events by handling SIGCHLD signals. To
114notify the event loop about target events, an event pipe is used
115--- the pipe is registered as waitable event source in the event loop,
116the event loop select/poll's on the read end of this pipe (as well on
117other event sources, e.g., stdin), and the SIGCHLD handler marks the
118event pipe to raise an event. This is more portable than relying on
119pselect/ppoll, since on kernels that lack those syscalls, libc
120emulates them with select/poll+sigprocmask, and that is racy
121(a.k.a. plain broken).
122
123Obviously, if we fail to notify the event loop if there's a target
124event, it's bad. OTOH, if we notify the event loop when there's no
125event from the target, linux_nat_wait will detect that there's no real
126event to report, and return event of type TARGET_WAITKIND_IGNORE.
127This is mostly harmless, but it will waste time and is better avoided.
128
129The main design point is that every time GDB is outside linux-nat.c,
130we have a SIGCHLD handler installed that is called when something
131happens to the target and notifies the GDB event loop. Whenever GDB
132core decides to handle the event, and calls into linux-nat.c, we
133process things as in sync mode, except that the we never block in
134sigsuspend.
135
136While processing an event, we may end up momentarily blocked in
137waitpid calls. Those waitpid calls, while blocking, are guarantied to
138return quickly. E.g., in all-stop mode, before reporting to the core
139that an LWP hit a breakpoint, all LWPs are stopped by sending them
140SIGSTOP, and synchronously waiting for the SIGSTOP to be reported.
141Note that this is different from blocking indefinitely waiting for the
142next event --- here, we're already handling an event.
143
144Use of signals
145==============
146
147We stop threads by sending a SIGSTOP. The use of SIGSTOP instead of another
148signal is not entirely significant; we just need for a signal to be delivered,
149so that we can intercept it. SIGSTOP's advantage is that it can not be
150blocked. A disadvantage is that it is not a real-time signal, so it can only
151be queued once; we do not keep track of other sources of SIGSTOP.
152
153Two other signals that can't be blocked are SIGCONT and SIGKILL. But we can't
154use them, because they have special behavior when the signal is generated -
155not when it is delivered. SIGCONT resumes the entire thread group and SIGKILL
156kills the entire thread group.
157
158A delivered SIGSTOP would stop the entire thread group, not just the thread we
159tkill'd. But we never let the SIGSTOP be delivered; we always intercept and
160cancel it (by PTRACE_CONT without passing SIGSTOP).
161
162We could use a real-time signal instead. This would solve those problems; we
163could use PTRACE_GETSIGINFO to locate the specific stop signals sent by GDB.
164But we would still have to have some support for SIGSTOP, since PTRACE_ATTACH
165generates it, and there are races with trying to find a signal that is not
166blocked.
167
168Exec events
169===========
170
171The case of a thread group (process) with 3 or more threads, and a
172thread other than the leader execs is worth detailing:
173
174On an exec, the Linux kernel destroys all threads except the execing
175one in the thread group, and resets the execing thread's tid to the
176tgid. No exit notification is sent for the execing thread -- from the
177ptracer's perspective, it appears as though the execing thread just
178vanishes. Until we reap all other threads except the leader and the
179execing thread, the leader will be zombie, and the execing thread will
180be in `D (disc sleep)' state. As soon as all other threads are
181reaped, the execing thread changes its tid to the tgid, and the
182previous (zombie) leader vanishes, giving place to the "new"
183leader. */
184
185#ifndef O_LARGEFILE
186#define O_LARGEFILE 0
187#endif
188
190
191/* Does the current host support PTRACE_GETREGSET? */
192enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
193
194/* When true, print debug messages relating to the linux native target. */
195
196static bool debug_linux_nat;
197
198/* Implement 'show debug linux-nat'. */
199
200static void
201show_debug_linux_nat (struct ui_file *file, int from_tty,
202 struct cmd_list_element *c, const char *value)
203{
204 gdb_printf (file, _("Debugging of GNU/Linux native targets is %s.\n"),
205 value);
206}
207
208/* Print a linux-nat debug statement. */
209
210#define linux_nat_debug_printf(fmt, ...) \
211 debug_prefixed_printf_cond (debug_linux_nat, "linux-nat", fmt, ##__VA_ARGS__)
212
213/* Print "linux-nat" enter/exit debug statements. */
214
215#define LINUX_NAT_SCOPED_DEBUG_ENTER_EXIT \
216 scoped_debug_enter_exit (debug_linux_nat, "linux-nat")
217
219{
220 int pid;
223};
225
226/* Whether target_thread_events is in effect. */
228
229static int kill_lwp (int lwpid, int signo);
230
231static int stop_callback (struct lwp_info *lp);
232
233static void block_child_signals (sigset_t *prev_mask);
234static void restore_child_signals_mask (sigset_t *prev_mask);
235
236struct lwp_info;
237static struct lwp_info *add_lwp (ptid_t ptid);
238static void purge_lwp_list (int pid);
239static void delete_lwp (ptid_t ptid);
240static struct lwp_info *find_lwp_pid (ptid_t ptid);
241
242static int lwp_status_pending_p (struct lwp_info *lp);
243
244static void save_stop_reason (struct lwp_info *lp);
245
246static bool proc_mem_file_is_writable ();
247static void close_proc_mem_file (pid_t pid);
248static void open_proc_mem_file (ptid_t ptid);
249
250/* Return TRUE if LWP is the leader thread of the process. */
251
252static bool
254{
255 return lp->ptid.pid () == lp->ptid.lwp ();
256}
257
258/* Convert an LWP's pending status to a std::string. */
259
260static std::string
262{
263 gdb_assert (lwp_status_pending_p (lp));
264
266 return lp->waitstatus.to_string ();
267 else
268 return status_to_str (lp->status);
269}
270
271
272/* LWP accessors. */
273
274/* See nat/linux-nat.h. */
275
276ptid_t
278{
279 return lwp->ptid;
280}
281
282/* See nat/linux-nat.h. */
283
284void
286 struct arch_lwp_info *info)
287{
288 lwp->arch_private = info;
289}
290
291/* See nat/linux-nat.h. */
292
293struct arch_lwp_info *
295{
296 return lwp->arch_private;
297}
298
299/* See nat/linux-nat.h. */
300
301int
303{
304 return lwp->stopped;
305}
306
307/* See nat/linux-nat.h. */
308
311{
312 return lwp->stop_reason;
313}
314
315/* See nat/linux-nat.h. */
316
317int
319{
320 return lwp->step;
321}
322
323
324/* Trivial list manipulation functions to keep track of a list of
325 new stopped processes. */
326static void
327add_to_pid_list (struct simple_pid_list **listp, int pid, int status)
328{
329 struct simple_pid_list *new_pid = XNEW (struct simple_pid_list);
330
331 new_pid->pid = pid;
332 new_pid->status = status;
333 new_pid->next = *listp;
334 *listp = new_pid;
335}
336
337static int
338pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp)
339{
340 struct simple_pid_list **p;
341
342 for (p = listp; *p != NULL; p = &(*p)->next)
343 if ((*p)->pid == pid)
344 {
345 struct simple_pid_list *next = (*p)->next;
346
347 *statusp = (*p)->status;
348 xfree (*p);
349 *p = next;
350 return 1;
351 }
352 return 0;
353}
354
355/* Return the ptrace options that we want to try to enable. */
356
357static int
359{
360 int options = 0;
361
362 if (!attached)
363 options |= PTRACE_O_EXITKILL;
364
365 options |= (PTRACE_O_TRACESYSGOOD
370
371 return options;
372}
373
374/* Initialize ptrace and procfs warnings and check for supported
375 ptrace features given PID.
376
377 ATTACHED should be nonzero iff we attached to the inferior. */
378
379static void
380linux_init_ptrace_procfs (pid_t pid, int attached)
381{
382 int options = linux_nat_ptrace_options (attached);
383
388}
389
392
393void
398
399/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
400
401void
403{
404 linux_init_ptrace_procfs (ptid.pid (), 0);
405}
406
407/* Return the number of known LWPs in the tgid given by PID. */
408
409static int
411{
412 int count = 0;
413
414 for (const lwp_info *lp ATTRIBUTE_UNUSED : all_lwps ())
415 if (lp->ptid.pid () == pid)
416 count++;
417
418 return count;
419}
420
421/* Deleter for lwp_info unique_ptr specialisation. */
422
424{
425 void operator() (struct lwp_info *lwp) const
426 {
427 delete_lwp (lwp->ptid);
428 }
429};
430
431/* A unique_ptr specialisation for lwp_info. */
432
433typedef std::unique_ptr<struct lwp_info, lwp_deleter> lwp_info_up;
434
435/* Target hook for follow_fork. */
436
437void
438linux_nat_target::follow_fork (inferior *child_inf, ptid_t child_ptid,
439 target_waitkind fork_kind, bool follow_child,
440 bool detach_fork)
441{
442 inf_ptrace_target::follow_fork (child_inf, child_ptid, fork_kind,
443 follow_child, detach_fork);
444
445 if (!follow_child)
446 {
447 bool has_vforked = fork_kind == TARGET_WAITKIND_VFORKED;
448 ptid_t parent_ptid = inferior_ptid;
449 int parent_pid = parent_ptid.lwp ();
450 int child_pid = child_ptid.lwp ();
451
452 /* We're already attached to the parent, by default. */
453 lwp_info *child_lp = add_lwp (child_ptid);
454 child_lp->stopped = 1;
455 child_lp->last_resume_kind = resume_stop;
456
457 /* Detach new forked process? */
458 if (detach_fork)
459 {
460 int child_stop_signal = 0;
461 bool detach_child = true;
462
463 /* Move CHILD_LP into a unique_ptr and clear the source pointer
464 to prevent us doing anything stupid with it. */
465 lwp_info_up child_lp_ptr (child_lp);
466 child_lp = nullptr;
467
468 linux_target->low_prepare_to_resume (child_lp_ptr.get ());
469
470 /* When debugging an inferior in an architecture that supports
471 hardware single stepping on a kernel without commit
472 6580807da14c423f0d0a708108e6df6ebc8bc83d, the vfork child
473 process starts with the TIF_SINGLESTEP/X86_EFLAGS_TF bits
474 set if the parent process had them set.
475 To work around this, single step the child process
476 once before detaching to clear the flags. */
477
478 /* Note that we consult the parent's architecture instead of
479 the child's because there's no inferior for the child at
480 this point. */
482 (parent_ptid)))
483 {
484 int status;
485
487 if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0)
488 perror_with_name (_("Couldn't do single step"));
489 if (my_waitpid (child_pid, &status, 0) < 0)
490 perror_with_name (_("Couldn't wait vfork process"));
491 else
492 {
493 detach_child = WIFSTOPPED (status);
494 child_stop_signal = WSTOPSIG (status);
495 }
496 }
497
498 if (detach_child)
499 {
500 int signo = child_stop_signal;
501
502 if (signo != 0
503 && !signal_pass_state (gdb_signal_from_host (signo)))
504 signo = 0;
505 ptrace (PTRACE_DETACH, child_pid, 0, signo);
506
507 close_proc_mem_file (child_pid);
508 }
509 }
510
511 if (has_vforked)
512 {
513 lwp_info *parent_lp = find_lwp_pid (parent_ptid);
514 linux_nat_debug_printf ("waiting for VFORK_DONE on %d", parent_pid);
515 parent_lp->stopped = 1;
516
517 /* We'll handle the VFORK_DONE event like any other
518 event, in target_wait. */
519 }
520 }
521 else
522 {
523 struct lwp_info *child_lp;
524
525 child_lp = add_lwp (child_ptid);
526 child_lp->stopped = 1;
527 child_lp->last_resume_kind = resume_stop;
528 }
529}
530
531
532int
534{
535 return 0;
536}
537
538int
540{
541 return 0;
542}
543
544int
546{
547 return 0;
548}
549
550int
552{
553 return 0;
554}
555
556int
558{
559 return 0;
560}
561
562int
564{
565 return 0;
566}
567
568int
569linux_nat_target::set_syscall_catchpoint (int pid, bool needed, int any_count,
570 gdb::array_view<const int> syscall_counts)
571{
572 /* On GNU/Linux, we ignore the arguments. It means that we only
573 enable the syscall catchpoints, but do not disable them.
574
575 Also, we do not use the `syscall_counts' information because we do not
576 filter system calls here. We let GDB do the logic for us. */
577 return 0;
578}
579
580/* List of known LWPs, keyed by LWP PID. This speeds up the common
581 case of mapping a PID returned from the kernel to our corresponding
582 lwp_info data structure. */
583static htab_t lwp_lwpid_htab;
584
585/* Calculate a hash from a lwp_info's LWP PID. */
586
587static hashval_t
588lwp_info_hash (const void *ap)
589{
590 const struct lwp_info *lp = (struct lwp_info *) ap;
591 pid_t pid = lp->ptid.lwp ();
592
593 return iterative_hash_object (pid, 0);
594}
595
596/* Equality function for the lwp_info hash table. Compares the LWP's
597 PID. */
598
599static int
600lwp_lwpid_htab_eq (const void *a, const void *b)
601{
602 const struct lwp_info *entry = (const struct lwp_info *) a;
603 const struct lwp_info *element = (const struct lwp_info *) b;
604
605 return entry->ptid.lwp () == element->ptid.lwp ();
606}
607
608/* Create the lwp_lwpid_htab hash table. */
609
610static void
612{
613 lwp_lwpid_htab = htab_create (100, lwp_info_hash, lwp_lwpid_htab_eq, NULL);
614}
615
616/* Add LP to the hash table. */
617
618static void
620{
621 void **slot;
622
623 slot = htab_find_slot (lwp_lwpid_htab, lp, INSERT);
624 gdb_assert (slot != NULL && *slot == NULL);
625 *slot = lp;
626}
627
628/* Head of doubly-linked list of known LWPs. Sorted by reverse
629 creation order. This order is assumed in some cases. E.g.,
630 reaping status after killing alls lwps of a process: the leader LWP
631 must be reaped last. */
632
633static intrusive_list<lwp_info> lwp_list;
634
635/* See linux-nat.h. */
636
639{
640 return lwp_info_range (lwp_list.begin ());
641}
642
643/* See linux-nat.h. */
644
647{
648 return lwp_info_safe_range (lwp_list.begin ());
649}
650
651/* Add LP to sorted-by-reverse-creation-order doubly-linked list. */
652
653static void
655{
656 lwp_list.push_front (*lp);
657}
658
659/* Remove LP from sorted-by-reverse-creation-order doubly-linked
660 list. */
661
662static void
664{
665 /* Remove from sorted-by-creation-order list. */
666 lwp_list.erase (lwp_list.iterator_to (*lp));
667}
668
669
670
671/* Signal mask for use with sigsuspend in linux_nat_wait, initialized in
672 _initialize_linux_nat. */
673static sigset_t suspend_mask;
674
675/* Signals to block to make that sigsuspend work. */
676static sigset_t blocked_mask;
677
678/* SIGCHLD action. */
679static struct sigaction sigchld_action;
680
681/* Block child signals (SIGCHLD and linux threads signals), and store
682 the previous mask in PREV_MASK. */
683
684static void
685block_child_signals (sigset_t *prev_mask)
686{
687 /* Make sure SIGCHLD is blocked. */
688 if (!sigismember (&blocked_mask, SIGCHLD))
689 sigaddset (&blocked_mask, SIGCHLD);
690
691 gdb_sigmask (SIG_BLOCK, &blocked_mask, prev_mask);
692}
693
694/* Restore child signals mask, previously returned by
695 block_child_signals. */
696
697static void
698restore_child_signals_mask (sigset_t *prev_mask)
699{
700 gdb_sigmask (SIG_SETMASK, prev_mask, NULL);
701}
702
703/* Mask of signals to pass directly to the inferior. */
704static sigset_t pass_mask;
705
706/* Update signals to pass to the inferior. */
707void
709 (gdb::array_view<const unsigned char> pass_signals)
710{
711 int signo;
712
713 sigemptyset (&pass_mask);
714
715 for (signo = 1; signo < NSIG; signo++)
716 {
717 int target_signo = gdb_signal_from_host (signo);
718 if (target_signo < pass_signals.size () && pass_signals[target_signo])
719 sigaddset (&pass_mask, signo);
720 }
721}
722
723
724
725/* Prototypes for local functions. */
726static int stop_wait_callback (struct lwp_info *lp);
727static int resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid);
728static int check_ptrace_stopped_lwp_gone (struct lwp_info *lp);
729
730
731
732/* Destroy and free LP. */
733
735{
736 /* Let the arch specific bits release arch_lwp_info. */
738}
739
740/* Traversal function for purge_lwp_list. */
741
742static int
743lwp_lwpid_htab_remove_pid (void **slot, void *info)
744{
745 struct lwp_info *lp = (struct lwp_info *) *slot;
746 int pid = *(int *) info;
747
748 if (lp->ptid.pid () == pid)
749 {
750 htab_clear_slot (lwp_lwpid_htab, slot);
751 lwp_list_remove (lp);
752 delete lp;
753 }
754
755 return 1;
756}
757
758/* Remove all LWPs belong to PID from the lwp list. */
759
760static void
762{
763 htab_traverse_noresize (lwp_lwpid_htab, lwp_lwpid_htab_remove_pid, &pid);
764}
765
766/* Add the LWP specified by PTID to the list. PTID is the first LWP
767 in the process. Return a pointer to the structure describing the
768 new LWP.
769
770 This differs from add_lwp in that we don't let the arch specific
771 bits know about this new thread. Current clients of this callback
772 take the opportunity to install watchpoints in the new thread, and
773 we shouldn't do that for the first thread. If we're spawning a
774 child ("run"), the thread executes the shell wrapper first, and we
775 shouldn't touch it until it execs the program we want to debug.
776 For "attach", it'd be okay to call the callback, but it's not
777 necessary, because watchpoints can't yet have been inserted into
778 the inferior. */
779
780static struct lwp_info *
782{
783 gdb_assert (ptid.lwp_p ());
784
785 lwp_info *lp = new lwp_info (ptid);
786
787
788 /* Add to sorted-by-reverse-creation-order list. */
789 lwp_list_add (lp);
790
791 /* Add to keyed-by-pid htab. */
793
794 return lp;
795}
796
797/* Add the LWP specified by PID to the list. Return a pointer to the
798 structure describing the new LWP. The LWP should already be
799 stopped. */
800
801static struct lwp_info *
802add_lwp (ptid_t ptid)
803{
804 struct lwp_info *lp;
805
806 lp = add_initial_lwp (ptid);
807
808 /* Let the arch specific bits know about this new thread. Current
809 clients of this callback take the opportunity to install
810 watchpoints in the new thread. We don't do this for the first
811 thread though. See add_initial_lwp. */
813
814 return lp;
815}
816
817/* Remove the LWP specified by PID from the list. */
818
819static void
821{
823
824 void **slot = htab_find_slot (lwp_lwpid_htab, &dummy, NO_INSERT);
825 if (slot == NULL)
826 return;
827
828 lwp_info *lp = *(struct lwp_info **) slot;
829 gdb_assert (lp != NULL);
830
831 htab_clear_slot (lwp_lwpid_htab, slot);
832
833 /* Remove from sorted-by-creation-order list. */
834 lwp_list_remove (lp);
835
836 /* Release. */
837 delete lp;
838}
839
840/* Return a pointer to the structure describing the LWP corresponding
841 to PID. If no corresponding LWP could be found, return NULL. */
842
843static struct lwp_info *
845{
846 int lwp;
847
848 if (ptid.lwp_p ())
849 lwp = ptid.lwp ();
850 else
851 lwp = ptid.pid ();
852
853 lwp_info dummy (ptid_t (0, lwp));
854 return (struct lwp_info *) htab_find (lwp_lwpid_htab, &dummy);
855}
856
857/* See nat/linux-nat.h. */
858
859struct lwp_info *
860iterate_over_lwps (ptid_t filter,
861 gdb::function_view<iterate_over_lwps_ftype> callback)
862{
863 for (lwp_info *lp : all_lwps_safe ())
864 {
865 if (lp->ptid.matches (filter))
866 {
867 if (callback (lp) != 0)
868 return lp;
869 }
870 }
871
872 return NULL;
873}
874
875/* Update our internal state when changing from one checkpoint to
876 another indicated by NEW_PTID. We can only switch single-threaded
877 applications, so we only create one new LWP, and the previous list
878 is discarded. */
879
880void
881linux_nat_switch_fork (ptid_t new_ptid)
882{
883 struct lwp_info *lp;
884
886
887 lp = add_lwp (new_ptid);
888 lp->stopped = 1;
889
890 /* This changes the thread's ptid while preserving the gdb thread
891 num. Also changes the inferior pid, while preserving the
892 inferior num. */
894
895 /* We've just told GDB core that the thread changed target id, but,
896 in fact, it really is a different thread, with different register
897 contents. */
899}
900
901/* Handle the exit of a single thread LP. */
902
903static void
904exit_lwp (struct lwp_info *lp)
905{
906 struct thread_info *th = linux_target->find_thread (lp->ptid);
907
908 if (th)
909 delete_thread (th);
910
911 delete_lwp (lp->ptid);
912}
913
914/* Wait for the LWP specified by LP, which we have just attached to.
915 Returns a wait status for that LWP, to cache. */
916
917static int
918linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
919{
920 pid_t new_pid, pid = ptid.lwp ();
921 int status;
922
924 {
925 linux_nat_debug_printf ("Attaching to a stopped process");
926
927 /* The process is definitely stopped. It is in a job control
928 stop, unless the kernel predates the TASK_STOPPED /
929 TASK_TRACED distinction, in which case it might be in a
930 ptrace stop. Make sure it is in a ptrace stop; from there we
931 can kill it, signal it, et cetera.
932
933 First make sure there is a pending SIGSTOP. Since we are
934 already attached, the process can not transition from stopped
935 to running without a PTRACE_CONT; so we know this signal will
936 go into the queue. The SIGSTOP generated by PTRACE_ATTACH is
937 probably already in the queue (unless this kernel is old
938 enough to use TASK_STOPPED for ptrace stops); but since SIGSTOP
939 is not an RT signal, it can only be queued once. */
940 kill_lwp (pid, SIGSTOP);
941
942 /* Finally, resume the stopped process. This will deliver the SIGSTOP
943 (or a higher priority signal, just like normal PTRACE_ATTACH). */
944 ptrace (PTRACE_CONT, pid, 0, 0);
945 }
946
947 /* Make sure the initial process is stopped. The user-level threads
948 layer might want to poke around in the inferior, and that won't
949 work if things haven't stabilized yet. */
950 new_pid = my_waitpid (pid, &status, __WALL);
951 gdb_assert (pid == new_pid);
952
953 if (!WIFSTOPPED (status))
954 {
955 /* The pid we tried to attach has apparently just exited. */
956 linux_nat_debug_printf ("Failed to stop %d: %s", pid,
957 status_to_str (status).c_str ());
958 return status;
959 }
960
961 if (WSTOPSIG (status) != SIGSTOP)
962 {
963 *signalled = 1;
964 linux_nat_debug_printf ("Received %s after attaching",
965 status_to_str (status).c_str ());
966 }
967
968 return status;
969}
970
971void
973 const std::string &allargs,
974 char **env, int from_tty)
975{
978
979 /* The fork_child mechanism is synchronous and calls target_wait, so
980 we have to mask the async mode. */
981
982 /* Make sure we report all signals during startup. */
983 pass_signals ({});
984
985 inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
986
988}
989
990/* Callback for linux_proc_attach_tgid_threads. Attach to PTID if not
991 already attached. Returns true if a new LWP is found, false
992 otherwise. */
993
994static int
996{
997 struct lwp_info *lp;
998
999 /* Ignore LWPs we're already attached to. */
1000 lp = find_lwp_pid (ptid);
1001 if (lp == NULL)
1002 {
1003 int lwpid = ptid.lwp ();
1004
1005 if (ptrace (PTRACE_ATTACH, lwpid, 0, 0) < 0)
1006 {
1007 int err = errno;
1008
1009 /* Be quiet if we simply raced with the thread exiting.
1010 EPERM is returned if the thread's task still exists, and
1011 is marked as exited or zombie, as well as other
1012 conditions, so in that case, confirm the status in
1013 /proc/PID/status. */
1014 if (err == ESRCH
1015 || (err == EPERM && linux_proc_pid_is_gone (lwpid)))
1016 {
1018 ("Cannot attach to lwp %d: thread is gone (%d: %s)",
1019 lwpid, err, safe_strerror (err));
1020
1021 }
1022 else
1023 {
1024 std::string reason
1026
1027 warning (_("Cannot attach to lwp %d: %s"),
1028 lwpid, reason.c_str ());
1029 }
1030 }
1031 else
1032 {
1033 linux_nat_debug_printf ("PTRACE_ATTACH %s, 0, 0 (OK)",
1034 ptid.to_string ().c_str ());
1035
1036 lp = add_lwp (ptid);
1037
1038 /* The next time we wait for this LWP we'll see a SIGSTOP as
1039 PTRACE_ATTACH brings it to a halt. */
1040 lp->signalled = 1;
1041
1042 /* We need to wait for a stop before being able to make the
1043 next ptrace call on this LWP. */
1044 lp->must_set_ptrace_flags = 1;
1045
1046 /* So that wait collects the SIGSTOP. */
1047 lp->resumed = 1;
1048
1049 /* Also add the LWP to gdb's thread list, in case a
1050 matching libthread_db is not found (or the process uses
1051 raw clone). */
1053 set_running (linux_target, lp->ptid, true);
1054 set_executing (linux_target, lp->ptid, true);
1055 }
1056
1057 return 1;
1058 }
1059 return 0;
1060}
1061
1062void
1063linux_nat_target::attach (const char *args, int from_tty)
1064{
1065 struct lwp_info *lp;
1066 int status;
1067 ptid_t ptid;
1068
1069 /* Make sure we report all signals during attach. */
1070 pass_signals ({});
1071
1072 try
1073 {
1074 inf_ptrace_target::attach (args, from_tty);
1075 }
1076 catch (const gdb_exception_error &ex)
1077 {
1078 pid_t pid = parse_pid_to_attach (args);
1079 std::string reason = linux_ptrace_attach_fail_reason (pid);
1080
1081 if (!reason.empty ())
1082 throw_error (ex.error, "warning: %s\n%s", reason.c_str (),
1083 ex.what ());
1084 else
1085 throw_error (ex.error, "%s", ex.what ());
1086 }
1087
1088 /* The ptrace base target adds the main thread with (pid,0,0)
1089 format. Decorate it with lwp info. */
1090 ptid = ptid_t (inferior_ptid.pid (),
1091 inferior_ptid.pid ());
1093
1094 /* Add the initial process as the first LWP to the list. */
1095 lp = add_initial_lwp (ptid);
1096
1098 if (!WIFSTOPPED (status))
1099 {
1100 if (WIFEXITED (status))
1101 {
1102 int exit_code = WEXITSTATUS (status);
1103
1106 if (exit_code == 0)
1107 error (_("Unable to attach: program exited normally."));
1108 else
1109 error (_("Unable to attach: program exited with code %d."),
1110 exit_code);
1111 }
1112 else if (WIFSIGNALED (status))
1113 {
1114 enum gdb_signal signo;
1115
1118
1119 signo = gdb_signal_from_host (WTERMSIG (status));
1120 error (_("Unable to attach: program terminated with signal "
1121 "%s, %s."),
1122 gdb_signal_to_name (signo),
1123 gdb_signal_to_string (signo));
1124 }
1125
1126 internal_error (_("unexpected status %d for PID %ld"),
1127 status, (long) ptid.lwp ());
1128 }
1129
1130 lp->stopped = 1;
1131
1133
1134 /* Save the wait status to report later. */
1135 lp->resumed = 1;
1136 linux_nat_debug_printf ("waitpid %ld, saving status %s",
1137 (long) lp->ptid.pid (),
1138 status_to_str (status).c_str ());
1139
1140 lp->status = status;
1141
1142 /* We must attach to every LWP. If /proc is mounted, use that to
1143 find them now. The inferior may be using raw clone instead of
1144 using pthreads. But even if it is using pthreads, thread_db
1145 walks structures in the inferior's address space to find the list
1146 of threads/LWPs, and those structures may well be corrupted.
1147 Note that once thread_db is loaded, we'll still use it to list
1148 threads and associate pthread info with each LWP. */
1151}
1152
1153/* Ptrace-detach the thread with pid PID. */
1154
1155static void
1156detach_one_pid (int pid, int signo)
1157{
1158 if (ptrace (PTRACE_DETACH, pid, 0, signo) < 0)
1159 {
1160 int save_errno = errno;
1161
1162 /* We know the thread exists, so ESRCH must mean the lwp is
1163 zombie. This can happen if one of the already-detached
1164 threads exits the whole thread group. In that case we're
1165 still attached, and must reap the lwp. */
1166 if (save_errno == ESRCH)
1167 {
1168 int ret, status;
1169
1170 ret = my_waitpid (pid, &status, __WALL);
1171 if (ret == -1)
1172 {
1173 warning (_("Couldn't reap LWP %d while detaching: %s"),
1174 pid, safe_strerror (errno));
1175 }
1176 else if (!WIFEXITED (status) && !WIFSIGNALED (status))
1177 {
1178 warning (_("Reaping LWP %d while detaching "
1179 "returned unexpected status 0x%x"),
1180 pid, status);
1181 }
1182 }
1183 else
1184 error (_("Can't detach %d: %s"),
1185 pid, safe_strerror (save_errno));
1186 }
1187 else
1188 linux_nat_debug_printf ("PTRACE_DETACH (%d, %s, 0) (OK)",
1189 pid, strsignal (signo));
1190}
1191
1192/* Get pending signal of THREAD as a host signal number, for detaching
1193 purposes. This is the signal the thread last stopped for, which we
1194 need to deliver to the thread when detaching, otherwise, it'd be
1195 suppressed/lost. */
1196
1197static int
1199{
1200 enum gdb_signal signo = GDB_SIGNAL_0;
1201
1202 /* If we paused threads momentarily, we may have stored pending
1203 events in lp->status or lp->waitstatus (see stop_wait_callback),
1204 and GDB core hasn't seen any signal for those threads.
1205 Otherwise, the last signal reported to the core is found in the
1206 thread object's stop_signal.
1207
1208 There's a corner case that isn't handled here at present. Only
1209 if the thread stopped with a TARGET_WAITKIND_STOPPED does
1210 stop_signal make sense as a real signal to pass to the inferior.
1211 Some catchpoint related events, like
1212 TARGET_WAITKIND_(V)FORK|EXEC|SYSCALL, have their stop_signal set
1213 to GDB_SIGNAL_SIGTRAP when the catchpoint triggers. But,
1214 those traps are debug API (ptrace in our case) related and
1215 induced; the inferior wouldn't see them if it wasn't being
1216 traced. Hence, we should never pass them to the inferior, even
1217 when set to pass state. Since this corner case isn't handled by
1218 infrun.c when proceeding with a signal, for consistency, neither
1219 do we handle it here (or elsewhere in the file we check for
1220 signal pass state). Normally SIGTRAP isn't set to pass state, so
1221 this is really a corner case. */
1222
1224 signo = GDB_SIGNAL_0; /* a pending ptrace event, not a real signal. */
1225 else if (lp->status)
1226 signo = gdb_signal_from_host (WSTOPSIG (lp->status));
1227 else
1228 {
1230
1231 if (target_is_non_stop_p () && !tp->executing ())
1232 {
1233 if (tp->has_pending_waitstatus ())
1234 {
1235 /* If the thread has a pending event, and it was stopped with a
1236 signal, use that signal to resume it. If it has a pending
1237 event of another kind, it was not stopped with a signal, so
1238 resume it without a signal. */
1240 signo = tp->pending_waitstatus ().sig ();
1241 else
1242 signo = GDB_SIGNAL_0;
1243 }
1244 else
1245 signo = tp->stop_signal ();
1246 }
1247 else if (!target_is_non_stop_p ())
1248 {
1249 ptid_t last_ptid;
1250 process_stratum_target *last_target;
1251
1252 get_last_target_status (&last_target, &last_ptid, nullptr);
1253
1254 if (last_target == linux_target
1255 && lp->ptid.lwp () == last_ptid.lwp ())
1256 signo = tp->stop_signal ();
1257 }
1258 }
1259
1260 if (signo == GDB_SIGNAL_0)
1261 {
1262 linux_nat_debug_printf ("lwp %s has no pending signal",
1263 lp->ptid.to_string ().c_str ());
1264 }
1265 else if (!signal_pass_state (signo))
1266 {
1268 ("lwp %s had signal %s but it is in no pass state",
1269 lp->ptid.to_string ().c_str (), gdb_signal_to_string (signo));
1270 }
1271 else
1272 {
1273 linux_nat_debug_printf ("lwp %s has pending signal %s",
1274 lp->ptid.to_string ().c_str (),
1275 gdb_signal_to_string (signo));
1276
1277 return gdb_signal_to_host (signo);
1278 }
1279
1280 return 0;
1281}
1282
1283/* Detach from LP. If SIGNO_P is non-NULL, then it points to the
1284 signal number that should be passed to the LWP when detaching.
1285 Otherwise pass any pending signal the LWP may have, if any. */
1286
1287static void
1288detach_one_lwp (struct lwp_info *lp, int *signo_p)
1289{
1291
1292 linux_nat_debug_printf ("lwp %s (stopped = %d)",
1293 lp->ptid.to_string ().c_str (), lp->stopped);
1294
1295 int lwpid = lp->ptid.lwp ();
1296 int signo;
1297
1298 gdb_assert (lp->status == 0 || WIFSTOPPED (lp->status));
1299
1300 /* If the lwp/thread we are about to detach has a pending fork event,
1301 there is a process GDB is attached to that the core of GDB doesn't know
1302 about. Detach from it. */
1303
1304 /* Check in lwp_info::status. */
1305 if (WIFSTOPPED (lp->status) && linux_is_extended_waitstatus (lp->status))
1306 {
1307 int event = linux_ptrace_get_extended_event (lp->status);
1308
1309 if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK)
1310 {
1311 unsigned long child_pid;
1312 int ret = ptrace (PTRACE_GETEVENTMSG, lp->ptid.lwp (), 0, &child_pid);
1313 if (ret == 0)
1314 detach_one_pid (child_pid, 0);
1315 else
1316 perror_warning_with_name (_("Failed to detach fork child"));
1317 }
1318 }
1319
1320 /* Check in lwp_info::waitstatus. */
1323 detach_one_pid (lp->waitstatus.child_ptid ().pid (), 0);
1324
1325
1326 /* Check in thread_info::pending_waitstatus. */
1328 if (tp->has_pending_waitstatus ())
1329 {
1330 const target_waitstatus &ws = tp->pending_waitstatus ();
1331
1332 if (ws.kind () == TARGET_WAITKIND_VFORKED
1333 || ws.kind () == TARGET_WAITKIND_FORKED)
1334 detach_one_pid (ws.child_ptid ().pid (), 0);
1335 }
1336
1337 /* Check in thread_info::pending_follow. */
1340 detach_one_pid (tp->pending_follow.child_ptid ().pid (), 0);
1341
1342 if (lp->status != 0)
1343 linux_nat_debug_printf ("Pending %s for %s on detach.",
1344 strsignal (WSTOPSIG (lp->status)),
1345 lp->ptid.to_string ().c_str ());
1346
1347 /* If there is a pending SIGSTOP, get rid of it. */
1348 if (lp->signalled)
1349 {
1350 linux_nat_debug_printf ("Sending SIGCONT to %s",
1351 lp->ptid.to_string ().c_str ());
1352
1353 kill_lwp (lwpid, SIGCONT);
1354 lp->signalled = 0;
1355 }
1356
1357 if (signo_p == NULL)
1358 {
1359 /* Pass on any pending signal for this LWP. */
1360 signo = get_detach_signal (lp);
1361 }
1362 else
1363 signo = *signo_p;
1364
1365 linux_nat_debug_printf ("preparing to resume lwp %s (stopped = %d)",
1366 lp->ptid.to_string ().c_str (),
1367 lp->stopped);
1368
1369 /* Preparing to resume may try to write registers, and fail if the
1370 lwp is zombie. If that happens, ignore the error. We'll handle
1371 it below, when detach fails with ESRCH. */
1372 try
1373 {
1375 }
1376 catch (const gdb_exception_error &ex)
1377 {
1379 throw;
1380 }
1381
1382 detach_one_pid (lwpid, signo);
1383
1384 delete_lwp (lp->ptid);
1385}
1386
1387static int
1389{
1390 /* We don't actually detach from the thread group leader just yet.
1391 If the thread group exits, we must reap the zombie clone lwps
1392 before we're able to reap the leader. */
1393 if (lp->ptid.lwp () != lp->ptid.pid ())
1394 detach_one_lwp (lp, NULL);
1395 return 0;
1396}
1397
1398void
1400{
1402
1403 struct lwp_info *main_lwp;
1404 int pid = inf->pid;
1405
1406 /* Don't unregister from the event loop, as there may be other
1407 inferiors running. */
1408
1409 /* Stop all threads before detaching. ptrace requires that the
1410 thread is stopped to successfully detach. */
1412 /* ... and wait until all of them have reported back that
1413 they're no longer running. */
1415
1416 /* We can now safely remove breakpoints. We don't this in earlier
1417 in common code because this target doesn't currently support
1418 writing memory while the inferior is running. */
1420
1422
1423 /* Only the initial process should be left right now. */
1424 gdb_assert (num_lwps (pid) == 1);
1425
1426 main_lwp = find_lwp_pid (ptid_t (pid));
1427
1428 if (forks_exist_p ())
1429 {
1430 /* Multi-fork case. The current inferior_ptid is being detached
1431 from, but there are other viable forks to debug. Detach from
1432 the current fork, and context-switch to the first
1433 available. */
1434 linux_fork_detach (from_tty);
1435 }
1436 else
1437 {
1438 target_announce_detach (from_tty);
1439
1440 /* Pass on any pending signal for the last LWP. */
1441 int signo = get_detach_signal (main_lwp);
1442
1443 detach_one_lwp (main_lwp, &signo);
1444
1446 }
1447
1449}
1450
1451/* Resume execution of the inferior process. If STEP is nonzero,
1452 single-step it. If SIGNAL is nonzero, give it that signal. */
1453
1454static void
1456 enum gdb_signal signo)
1457{
1458 lp->step = step;
1459
1460 /* stop_pc doubles as the PC the LWP had when it was last resumed.
1461 We only presently need that if the LWP is stepped though (to
1462 handle the case of stepping a breakpoint instruction). */
1463 if (step)
1464 {
1466
1468 }
1469 else
1470 lp->stop_pc = 0;
1471
1473 linux_target->low_resume (lp->ptid, step, signo);
1474
1475 /* Successfully resumed. Clear state that no longer makes sense,
1476 and mark the LWP as running. Must not do this before resuming
1477 otherwise if that fails other code will be confused. E.g., we'd
1478 later try to stop the LWP and hang forever waiting for a stop
1479 status. Note that we must not throw after this is cleared,
1480 otherwise handle_zombie_lwp_error would get confused. */
1481 lp->stopped = 0;
1482 lp->core = -1;
1485}
1486
1487/* Called when we try to resume a stopped LWP and that errors out. If
1488 the LWP is no longer in ptrace-stopped state (meaning it's zombie,
1489 or about to become), discard the error, clear any pending status
1490 the LWP may have, and return true (we'll collect the exit status
1491 soon enough). Otherwise, return false. */
1492
1493static int
1495{
1496 /* If we get an error after resuming the LWP successfully, we'd
1497 confuse !T state for the LWP being gone. */
1498 gdb_assert (lp->stopped);
1499
1500 /* We can't just check whether the LWP is in 'Z (Zombie)' state,
1501 because even if ptrace failed with ESRCH, the tracee may be "not
1502 yet fully dead", but already refusing ptrace requests. In that
1503 case the tracee has 'R (Running)' state for a little bit
1504 (observed in Linux 3.18). See also the note on ESRCH in the
1505 ptrace(2) man page. Instead, check whether the LWP has any state
1506 other than ptrace-stopped. */
1507
1508 /* Don't assume anything if /proc/PID/status can't be read. */
1509 if (linux_proc_pid_is_trace_stopped_nowarn (lp->ptid.lwp ()) == 0)
1510 {
1512 lp->status = 0;
1513 lp->waitstatus.set_ignore ();
1514 return 1;
1515 }
1516 return 0;
1517}
1518
1519/* Like linux_resume_one_lwp_throw, but no error is thrown if the LWP
1520 disappears while we try to resume it. */
1521
1522static void
1523linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
1524{
1525 try
1526 {
1527 linux_resume_one_lwp_throw (lp, step, signo);
1528 }
1529 catch (const gdb_exception_error &ex)
1530 {
1532 throw;
1533 }
1534}
1535
1536/* Resume LP. */
1537
1538static void
1539resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
1540{
1541 if (lp->stopped)
1542 {
1544
1545 if (inf->vfork_child != NULL)
1546 {
1547 linux_nat_debug_printf ("Not resuming sibling %s (vfork parent)",
1548 lp->ptid.to_string ().c_str ());
1549 }
1550 else if (!lwp_status_pending_p (lp))
1551 {
1552 linux_nat_debug_printf ("Resuming sibling %s, %s, %s",
1553 lp->ptid.to_string ().c_str (),
1554 (signo != GDB_SIGNAL_0
1555 ? strsignal (gdb_signal_to_host (signo))
1556 : "0"),
1557 step ? "step" : "resume");
1558
1559 linux_resume_one_lwp (lp, step, signo);
1560 }
1561 else
1562 {
1563 linux_nat_debug_printf ("Not resuming sibling %s (has pending)",
1564 lp->ptid.to_string ().c_str ());
1565 }
1566 }
1567 else
1568 linux_nat_debug_printf ("Not resuming sibling %s (not stopped)",
1569 lp->ptid.to_string ().c_str ());
1570}
1571
1572/* Callback for iterate_over_lwps. If LWP is EXCEPT, do nothing.
1573 Resume LWP with the last stop signal, if it is in pass state. */
1574
1575static int
1576linux_nat_resume_callback (struct lwp_info *lp, struct lwp_info *except)
1577{
1578 enum gdb_signal signo = GDB_SIGNAL_0;
1579
1580 if (lp == except)
1581 return 0;
1582
1583 if (lp->stopped)
1584 {
1585 struct thread_info *thread;
1586
1587 thread = linux_target->find_thread (lp->ptid);
1588 if (thread != NULL)
1589 {
1590 signo = thread->stop_signal ();
1591 thread->set_stop_signal (GDB_SIGNAL_0);
1592 }
1593 }
1594
1595 resume_lwp (lp, 0, signo);
1596 return 0;
1597}
1598
1599static int
1601{
1602 lp->resumed = 0;
1604 return 0;
1605}
1606
1607static int
1609{
1610 lp->resumed = 1;
1612 return 0;
1613}
1614
1615void
1616linux_nat_target::resume (ptid_t scope_ptid, int step, enum gdb_signal signo)
1617{
1618 struct lwp_info *lp;
1619
1620 linux_nat_debug_printf ("Preparing to %s %s, %s, inferior_ptid %s",
1621 step ? "step" : "resume",
1622 scope_ptid.to_string ().c_str (),
1623 (signo != GDB_SIGNAL_0
1624 ? strsignal (gdb_signal_to_host (signo)) : "0"),
1625 inferior_ptid.to_string ().c_str ());
1626
1627 /* Mark the lwps we're resuming as resumed and update their
1628 last_resume_kind to resume_continue. */
1630
1632 gdb_assert (lp != NULL);
1633
1634 /* Remember if we're stepping. */
1636
1637 /* If we have a pending wait status for this thread, there is no
1638 point in resuming the process. But first make sure that
1639 linux_nat_wait won't preemptively handle the event - we
1640 should never take this short-circuit if we are going to
1641 leave LP running, since we have skipped resuming all the
1642 other threads. This bit of code needs to be synchronized
1643 with linux_nat_wait. */
1644
1645 if (lp->status && WIFSTOPPED (lp->status))
1646 {
1647 if (!lp->step
1648 && WSTOPSIG (lp->status)
1649 && sigismember (&pass_mask, WSTOPSIG (lp->status)))
1650 {
1652 ("Not short circuiting for ignored status 0x%x", lp->status);
1653
1654 /* FIXME: What should we do if we are supposed to continue
1655 this thread with a signal? */
1656 gdb_assert (signo == GDB_SIGNAL_0);
1657 signo = gdb_signal_from_host (WSTOPSIG (lp->status));
1658 lp->status = 0;
1659 }
1660 }
1661
1662 if (lwp_status_pending_p (lp))
1663 {
1664 /* FIXME: What should we do if we are supposed to continue
1665 this thread with a signal? */
1666 gdb_assert (signo == GDB_SIGNAL_0);
1667
1668 linux_nat_debug_printf ("Short circuiting for status %s",
1669 pending_status_str (lp).c_str ());
1670
1671 if (target_can_async_p ())
1672 {
1673 target_async (true);
1674 /* Tell the event loop we have something to process. */
1675 async_file_mark ();
1676 }
1677 return;
1678 }
1679
1680 /* No use iterating unless we're resuming other threads. */
1681 if (scope_ptid != lp->ptid)
1682 iterate_over_lwps (scope_ptid, [=] (struct lwp_info *info)
1683 {
1684 return linux_nat_resume_callback (info, lp);
1685 });
1686
1687 linux_nat_debug_printf ("%s %s, %s (resume event thread)",
1688 step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
1689 lp->ptid.to_string ().c_str (),
1690 (signo != GDB_SIGNAL_0
1691 ? strsignal (gdb_signal_to_host (signo)) : "0"));
1692
1693 linux_resume_one_lwp (lp, step, signo);
1694}
1695
1696/* Send a signal to an LWP. */
1697
1698static int
1699kill_lwp (int lwpid, int signo)
1700{
1701 int ret;
1702
1703 errno = 0;
1704 ret = syscall (__NR_tkill, lwpid, signo);
1705 if (errno == ENOSYS)
1706 {
1707 /* If tkill fails, then we are not using nptl threads, a
1708 configuration we no longer support. */
1709 perror_with_name (("tkill"));
1710 }
1711 return ret;
1712}
1713
1714/* Handle a GNU/Linux syscall trap wait response. If we see a syscall
1715 event, check if the core is interested in it: if not, ignore the
1716 event, and keep waiting; otherwise, we need to toggle the LWP's
1717 syscall entry/exit status, since the ptrace event itself doesn't
1718 indicate it, and report the trap to higher layers. */
1719
1720static int
1721linux_handle_syscall_trap (struct lwp_info *lp, int stopping)
1722{
1723 struct target_waitstatus *ourstatus = &lp->waitstatus;
1725 thread_info *thread = linux_target->find_thread (lp->ptid);
1726 int syscall_number = (int) gdbarch_get_syscall_number (gdbarch, thread);
1727
1728 if (stopping)
1729 {
1730 /* If we're stopping threads, there's a SIGSTOP pending, which
1731 makes it so that the LWP reports an immediate syscall return,
1732 followed by the SIGSTOP. Skip seeing that "return" using
1733 PTRACE_CONT directly, and let stop_wait_callback collect the
1734 SIGSTOP. Later when the thread is resumed, a new syscall
1735 entry event. If we didn't do this (and returned 0), we'd
1736 leave a syscall entry pending, and our caller, by using
1737 PTRACE_CONT to collect the SIGSTOP, skips the syscall return
1738 itself. Later, when the user re-resumes this LWP, we'd see
1739 another syscall entry event and we'd mistake it for a return.
1740
1741 If stop_wait_callback didn't force the SIGSTOP out of the LWP
1742 (leaving immediately with LWP->signalled set, without issuing
1743 a PTRACE_CONT), it would still be problematic to leave this
1744 syscall enter pending, as later when the thread is resumed,
1745 it would then see the same syscall exit mentioned above,
1746 followed by the delayed SIGSTOP, while the syscall didn't
1747 actually get to execute. It seems it would be even more
1748 confusing to the user. */
1749
1751 ("ignoring syscall %d for LWP %ld (stopping threads), resuming with "
1752 "PTRACE_CONT for SIGSTOP", syscall_number, lp->ptid.lwp ());
1753
1755 ptrace (PTRACE_CONT, lp->ptid.lwp (), 0, 0);
1756 lp->stopped = 0;
1757 return 1;
1758 }
1759
1760 /* Always update the entry/return state, even if this particular
1761 syscall isn't interesting to the core now. In async mode,
1762 the user could install a new catchpoint for this syscall
1763 between syscall enter/return, and we'll need to know to
1764 report a syscall return if that happens. */
1768
1769 if (catch_syscall_enabled ())
1770 {
1771 if (catching_syscall_number (syscall_number))
1772 {
1773 /* Alright, an event to report. */
1775 ourstatus->set_syscall_entry (syscall_number);
1777 ourstatus->set_syscall_return (syscall_number);
1778 else
1779 gdb_assert_not_reached ("unexpected syscall state");
1780
1782 ("stopping for %s of syscall %d for LWP %ld",
1784 ? "entry" : "return"), syscall_number, lp->ptid.lwp ());
1785
1786 return 0;
1787 }
1788
1790 ("ignoring %s of syscall %d for LWP %ld",
1792 ? "entry" : "return"), syscall_number, lp->ptid.lwp ());
1793 }
1794 else
1795 {
1796 /* If we had been syscall tracing, and hence used PT_SYSCALL
1797 before on this LWP, it could happen that the user removes all
1798 syscall catchpoints before we get to process this event.
1799 There are two noteworthy issues here:
1800
1801 - When stopped at a syscall entry event, resuming with
1802 PT_STEP still resumes executing the syscall and reports a
1803 syscall return.
1804
1805 - Only PT_SYSCALL catches syscall enters. If we last
1806 single-stepped this thread, then this event can't be a
1807 syscall enter. If we last single-stepped this thread, this
1808 has to be a syscall exit.
1809
1810 The points above mean that the next resume, be it PT_STEP or
1811 PT_CONTINUE, can not trigger a syscall trace event. */
1813 ("caught syscall event with no syscall catchpoints. %d for LWP %ld, "
1814 "ignoring", syscall_number, lp->ptid.lwp ());
1816 }
1817
1818 /* The core isn't interested in this event. For efficiency, avoid
1819 stopping all threads only to have the core resume them all again.
1820 Since we're not stopping threads, if we're still syscall tracing
1821 and not stepping, we can't use PTRACE_CONT here, as we'd miss any
1822 subsequent syscall. Simply resume using the inf-ptrace layer,
1823 which knows when to use PT_SYSCALL or PT_CONTINUE. */
1824
1825 linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
1826 return 1;
1827}
1828
1829/* Handle a GNU/Linux extended wait response. If we see a clone
1830 event, we need to add the new LWP to our list (and not report the
1831 trap to higher layers). This function returns non-zero if the
1832 event should be ignored and we should wait again. If STOPPING is
1833 true, the new LWP remains stopped, otherwise it is continued. */
1834
1835static int
1837{
1838 int pid = lp->ptid.lwp ();
1839 struct target_waitstatus *ourstatus = &lp->waitstatus;
1841
1842 /* All extended events we currently use are mid-syscall. Only
1843 PTRACE_EVENT_STOP is delivered more like a signal-stop, but
1844 you have to be using PTRACE_SEIZE to get that. */
1846
1847 if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK
1848 || event == PTRACE_EVENT_CLONE)
1849 {
1850 unsigned long new_pid;
1851 int ret;
1852
1853 ptrace (PTRACE_GETEVENTMSG, pid, 0, &new_pid);
1854
1855 /* If we haven't already seen the new PID stop, wait for it now. */
1856 if (! pull_pid_from_list (&stopped_pids, new_pid, &status))
1857 {
1858 /* The new child has a pending SIGSTOP. We can't affect it until it
1859 hits the SIGSTOP, but we're already attached. */
1860 ret = my_waitpid (new_pid, &status, __WALL);
1861 if (ret == -1)
1862 perror_with_name (_("waiting for new child"));
1863 else if (ret != new_pid)
1864 internal_error (_("wait returned unexpected PID %d"), ret);
1865 else if (!WIFSTOPPED (status))
1866 internal_error (_("wait returned unexpected status 0x%x"), status);
1867 }
1868
1869 ptid_t child_ptid (new_pid, new_pid);
1870
1871 if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK)
1872 {
1874
1875 /* The arch-specific native code may need to know about new
1876 forks even if those end up never mapped to an
1877 inferior. */
1878 linux_target->low_new_fork (lp, new_pid);
1879 }
1880 else if (event == PTRACE_EVENT_CLONE)
1881 {
1882 linux_target->low_new_clone (lp, new_pid);
1883 }
1884
1885 if (event == PTRACE_EVENT_FORK
1886 && linux_fork_checkpointing_p (lp->ptid.pid ()))
1887 {
1888 /* Handle checkpointing by linux-fork.c here as a special
1889 case. We don't want the follow-fork-mode or 'catch fork'
1890 to interfere with this. */
1891
1892 /* This won't actually modify the breakpoint list, but will
1893 physically remove the breakpoints from the child. */
1894 detach_breakpoints (ptid_t (new_pid, new_pid));
1895
1896 /* Retain child fork in ptrace (stopped) state. */
1897 if (!find_fork_pid (new_pid))
1898 add_fork (new_pid);
1899
1900 /* Report as spurious, so that infrun doesn't want to follow
1901 this fork. We're actually doing an infcall in
1902 linux-fork.c. */
1903 ourstatus->set_spurious ();
1904
1905 /* Report the stop to the core. */
1906 return 0;
1907 }
1908
1909 if (event == PTRACE_EVENT_FORK)
1910 ourstatus->set_forked (child_ptid);
1911 else if (event == PTRACE_EVENT_VFORK)
1912 ourstatus->set_vforked (child_ptid);
1913 else if (event == PTRACE_EVENT_CLONE)
1914 {
1915 struct lwp_info *new_lp;
1916
1917 ourstatus->set_ignore ();
1918
1920 ("Got clone event from LWP %d, new child is LWP %ld", pid, new_pid);
1921
1922 new_lp = add_lwp (ptid_t (lp->ptid.pid (), new_pid));
1923 new_lp->stopped = 1;
1924 new_lp->resumed = 1;
1925
1926 /* If the thread_db layer is active, let it record the user
1927 level thread id and status, and add the thread to GDB's
1928 list. */
1929 if (!thread_db_notice_clone (lp->ptid, new_lp->ptid))
1930 {
1931 /* The process is not using thread_db. Add the LWP to
1932 GDB's list. */
1933 add_thread (linux_target, new_lp->ptid);
1934 }
1935
1936 /* Even if we're stopping the thread for some reason
1937 internal to this module, from the perspective of infrun
1938 and the user/frontend, this new thread is running until
1939 it next reports a stop. */
1940 set_running (linux_target, new_lp->ptid, true);
1941 set_executing (linux_target, new_lp->ptid, true);
1942
1943 if (WSTOPSIG (status) != SIGSTOP)
1944 {
1945 /* This can happen if someone starts sending signals to
1946 the new thread before it gets a chance to run, which
1947 have a lower number than SIGSTOP (e.g. SIGUSR1).
1948 This is an unlikely case, and harder to handle for
1949 fork / vfork than for clone, so we do not try - but
1950 we handle it for clone events here. */
1951
1952 new_lp->signalled = 1;
1953
1954 /* We created NEW_LP so it cannot yet contain STATUS. */
1955 gdb_assert (new_lp->status == 0);
1956
1957 /* Save the wait status to report later. */
1959 ("waitpid of new LWP %ld, saving status %s",
1960 (long) new_lp->ptid.lwp (), status_to_str (status).c_str ());
1961 new_lp->status = status;
1962 }
1963 else if (report_thread_events)
1964 {
1965 new_lp->waitstatus.set_thread_created ();
1966 new_lp->status = status;
1967 }
1968
1969 return 1;
1970 }
1971
1972 return 0;
1973 }
1974
1975 if (event == PTRACE_EVENT_EXEC)
1976 {
1977 linux_nat_debug_printf ("Got exec event from LWP %ld", lp->ptid.lwp ());
1978
1979 /* Close the previous /proc/PID/mem file for this inferior,
1980 which was using the address space which is now gone.
1981 Reading/writing from this file would return 0/EOF. */
1982 close_proc_mem_file (lp->ptid.pid ());
1983
1984 /* Open a new file for the new address space. */
1986
1987 ourstatus->set_execd
1988 (make_unique_xstrdup (linux_proc_pid_to_exec_file (pid)));
1989
1990 /* The thread that execed must have been resumed, but, when a
1991 thread execs, it changes its tid to the tgid, and the old
1992 tgid thread might have not been resumed. */
1993 lp->resumed = 1;
1994 return 0;
1995 }
1996
1997 if (event == PTRACE_EVENT_VFORK_DONE)
1998 {
2000 ("Got PTRACE_EVENT_VFORK_DONE from LWP %ld",
2001 lp->ptid.lwp ());
2002 ourstatus->set_vfork_done ();
2003 return 0;
2004 }
2005
2006 internal_error (_("unknown ptrace event %d"), event);
2007}
2008
2009/* Suspend waiting for a signal. We're mostly interested in
2010 SIGCHLD/SIGINT. */
2011
2012static void
2014{
2015 linux_nat_debug_printf ("about to sigsuspend");
2016 sigsuspend (&suspend_mask);
2017
2018 /* If the quit flag is set, it means that the user pressed Ctrl-C
2019 and we're debugging a process that is running on a separate
2020 terminal, so we must forward the Ctrl-C to the inferior. (If the
2021 inferior is sharing GDB's terminal, then the Ctrl-C reaches the
2022 inferior directly.) We must do this here because functions that
2023 need to block waiting for a signal loop forever until there's an
2024 event to report before returning back to the event loop. */
2026 {
2027 if (check_quit_flag ())
2029 }
2030}
2031
2032/* Wait for LP to stop. Returns the wait status, or 0 if the LWP has
2033 exited. */
2034
2035static int
2036wait_lwp (struct lwp_info *lp)
2037{
2038 pid_t pid;
2039 int status = 0;
2040 int thread_dead = 0;
2041 sigset_t prev_mask;
2042
2043 gdb_assert (!lp->stopped);
2044 gdb_assert (lp->status == 0);
2045
2046 /* Make sure SIGCHLD is blocked for sigsuspend avoiding a race below. */
2047 block_child_signals (&prev_mask);
2048
2049 for (;;)
2050 {
2051 pid = my_waitpid (lp->ptid.lwp (), &status, __WALL | WNOHANG);
2052 if (pid == -1 && errno == ECHILD)
2053 {
2054 /* The thread has previously exited. We need to delete it
2055 now because if this was a non-leader thread execing, we
2056 won't get an exit event. See comments on exec events at
2057 the top of the file. */
2058 thread_dead = 1;
2059 linux_nat_debug_printf ("%s vanished.",
2060 lp->ptid.to_string ().c_str ());
2061 }
2062 if (pid != 0)
2063 break;
2064
2065 /* Bugs 10970, 12702.
2066 Thread group leader may have exited in which case we'll lock up in
2067 waitpid if there are other threads, even if they are all zombies too.
2068 Basically, we're not supposed to use waitpid this way.
2069 tkill(pid,0) cannot be used here as it gets ESRCH for both
2070 for zombie and running processes.
2071
2072 As a workaround, check if we're waiting for the thread group leader and
2073 if it's a zombie, and avoid calling waitpid if it is.
2074
2075 This is racy, what if the tgl becomes a zombie right after we check?
2076 Therefore always use WNOHANG with sigsuspend - it is equivalent to
2077 waiting waitpid but linux_proc_pid_is_zombie is safe this way. */
2078
2079 if (lp->ptid.pid () == lp->ptid.lwp ()
2080 && linux_proc_pid_is_zombie (lp->ptid.lwp ()))
2081 {
2082 thread_dead = 1;
2083 linux_nat_debug_printf ("Thread group leader %s vanished.",
2084 lp->ptid.to_string ().c_str ());
2085 break;
2086 }
2087
2088 /* Wait for next SIGCHLD and try again. This may let SIGCHLD handlers
2089 get invoked despite our caller had them intentionally blocked by
2090 block_child_signals. This is sensitive only to the loop of
2091 linux_nat_wait_1 and there if we get called my_waitpid gets called
2092 again before it gets to sigsuspend so we can safely let the handlers
2093 get executed here. */
2094 wait_for_signal ();
2095 }
2096
2097 restore_child_signals_mask (&prev_mask);
2098
2099 if (!thread_dead)
2100 {
2101 gdb_assert (pid == lp->ptid.lwp ());
2102
2103 linux_nat_debug_printf ("waitpid %s received %s",
2104 lp->ptid.to_string ().c_str (),
2105 status_to_str (status).c_str ());
2106
2107 /* Check if the thread has exited. */
2108 if (WIFEXITED (status) || WIFSIGNALED (status))
2109 {
2111 || lp->ptid.pid () == lp->ptid.lwp ())
2112 {
2113 linux_nat_debug_printf ("LWP %d exited.", lp->ptid.pid ());
2114
2115 /* If this is the leader exiting, it means the whole
2116 process is gone. Store the status to report to the
2117 core. Store it in lp->waitstatus, because lp->status
2118 would be ambiguous (W_EXITCODE(0,0) == 0). */
2120 return 0;
2121 }
2122
2123 thread_dead = 1;
2124 linux_nat_debug_printf ("%s exited.",
2125 lp->ptid.to_string ().c_str ());
2126 }
2127 }
2128
2129 if (thread_dead)
2130 {
2131 exit_lwp (lp);
2132 return 0;
2133 }
2134
2135 gdb_assert (WIFSTOPPED (status));
2136 lp->stopped = 1;
2137
2138 if (lp->must_set_ptrace_flags)
2139 {
2141 int options = linux_nat_ptrace_options (inf->attach_flag);
2142
2143 linux_enable_event_reporting (lp->ptid.lwp (), options);
2144 lp->must_set_ptrace_flags = 0;
2145 }
2146
2147 /* Handle GNU/Linux's syscall SIGTRAPs. */
2148 if (WIFSTOPPED (status) && WSTOPSIG (status) == SYSCALL_SIGTRAP)
2149 {
2150 /* No longer need the sysgood bit. The ptrace event ends up
2151 recorded in lp->waitstatus if we care for it. We can carry
2152 on handling the event like a regular SIGTRAP from here
2153 on. */
2154 status = W_STOPCODE (SIGTRAP);
2155 if (linux_handle_syscall_trap (lp, 1))
2156 return wait_lwp (lp);
2157 }
2158 else
2159 {
2160 /* Almost all other ptrace-stops are known to be outside of system
2161 calls, with further exceptions in linux_handle_extended_wait. */
2163 }
2164
2165 /* Handle GNU/Linux's extended waitstatus for trace events. */
2166 if (WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP
2168 {
2169 linux_nat_debug_printf ("Handling extended status 0x%06x", status);
2171 return 0;
2172 }
2173
2174 return status;
2175}
2176
2177/* Send a SIGSTOP to LP. */
2178
2179static int
2181{
2182 if (!lp->stopped && !lp->signalled)
2183 {
2184 int ret;
2185
2186 linux_nat_debug_printf ("kill %s **<SIGSTOP>**",
2187 lp->ptid.to_string ().c_str ());
2188
2189 errno = 0;
2190 ret = kill_lwp (lp->ptid.lwp (), SIGSTOP);
2191 linux_nat_debug_printf ("lwp kill %d %s", ret,
2192 errno ? safe_strerror (errno) : "ERRNO-OK");
2193
2194 lp->signalled = 1;
2195 gdb_assert (lp->status == 0);
2196 }
2197
2198 return 0;
2199}
2200
2201/* Request a stop on LWP. */
2202
2203void
2205{
2206 stop_callback (lwp);
2207}
2208
2209/* See linux-nat.h */
2210
2211void
2213{
2214 /* Stop all LWP's ... */
2215 iterate_over_lwps (minus_one_ptid, stop_callback);
2216
2217 /* ... and wait until all of them have reported back that
2218 they're no longer running. */
2219 iterate_over_lwps (minus_one_ptid, stop_wait_callback);
2220}
2221
2222/* See linux-nat.h */
2223
2224void
2226{
2227 iterate_over_lwps (minus_one_ptid,
2228 [] (struct lwp_info *info)
2229 {
2230 return resume_stopped_resumed_lwps (info, minus_one_ptid);
2231 });
2232}
2233
2234/* Return non-zero if LWP PID has a pending SIGINT. */
2235
2236static int
2238{
2239 sigset_t pending, blocked, ignored;
2240
2241 linux_proc_pending_signals (pid, &pending, &blocked, &ignored);
2242
2243 if (sigismember (&pending, SIGINT)
2244 && !sigismember (&ignored, SIGINT))
2245 return 1;
2246
2247 return 0;
2248}
2249
2250/* Set a flag in LP indicating that we should ignore its next SIGINT. */
2251
2252static int
2254{
2255 /* If a thread has a pending SIGINT, consume it; otherwise, set a
2256 flag to consume the next one. */
2257 if (lp->stopped && lp->status != 0 && WIFSTOPPED (lp->status)
2258 && WSTOPSIG (lp->status) == SIGINT)
2259 lp->status = 0;
2260 else
2261 lp->ignore_sigint = 1;
2262
2263 return 0;
2264}
2265
2266/* If LP does not have a SIGINT pending, then clear the ignore_sigint flag.
2267 This function is called after we know the LWP has stopped; if the LWP
2268 stopped before the expected SIGINT was delivered, then it will never have
2269 arrived. Also, if the signal was delivered to a shared queue and consumed
2270 by a different thread, it will never be delivered to this LWP. */
2271
2272static void
2274{
2275 if (!lp->ignore_sigint)
2276 return;
2277
2278 if (!linux_nat_has_pending_sigint (lp->ptid.lwp ()))
2279 {
2280 linux_nat_debug_printf ("Clearing bogus flag for %s",
2281 lp->ptid.to_string ().c_str ());
2282 lp->ignore_sigint = 0;
2283 }
2284}
2285
2286/* Fetch the possible triggered data watchpoint info and store it in
2287 LP.
2288
2289 On some archs, like x86, that use debug registers to set
2290 watchpoints, it's possible that the way to know which watched
2291 address trapped, is to check the register that is used to select
2292 which address to watch. Problem is, between setting the watchpoint
2293 and reading back which data address trapped, the user may change
2294 the set of watchpoints, and, as a consequence, GDB changes the
2295 debug registers in the inferior. To avoid reading back a stale
2296 stopped-data-address when that happens, we cache in LP the fact
2297 that a watchpoint trapped, and the corresponding data address, as
2298 soon as we see LP stop with a SIGTRAP. If GDB changes the debug
2299 registers meanwhile, we have the cached data we can rely on. */
2300
2301static int
2303{
2304 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
2305 inferior_ptid = lp->ptid;
2306
2308 {
2312 }
2313
2315}
2316
2317/* Returns true if the LWP had stopped for a watchpoint. */
2318
2319bool
2321{
2322 struct lwp_info *lp = find_lwp_pid (inferior_ptid);
2323
2324 gdb_assert (lp != NULL);
2325
2327}
2328
2329bool
2331{
2332 struct lwp_info *lp = find_lwp_pid (inferior_ptid);
2333
2334 gdb_assert (lp != NULL);
2335
2336 *addr_p = lp->stopped_data_address;
2337
2338 return lp->stopped_data_address_p;
2339}
2340
2341/* Commonly any breakpoint / watchpoint generate only SIGTRAP. */
2342
2343bool
2345{
2346 return WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP;
2347}
2348
2349/* Wait until LP is stopped. */
2350
2351static int
2353{
2355
2356 /* If this is a vfork parent, bail out, it is not going to report
2357 any SIGSTOP until the vfork is done with. */
2358 if (inf->vfork_child != NULL)
2359 return 0;
2360
2361 if (!lp->stopped)
2362 {
2363 int status;
2364
2365 status = wait_lwp (lp);
2366 if (status == 0)
2367 return 0;
2368
2369 if (lp->ignore_sigint && WIFSTOPPED (status)
2370 && WSTOPSIG (status) == SIGINT)
2371 {
2372 lp->ignore_sigint = 0;
2373
2374 errno = 0;
2375 ptrace (PTRACE_CONT, lp->ptid.lwp (), 0, 0);
2376 lp->stopped = 0;
2378 ("PTRACE_CONT %s, 0, 0 (%s) (discarding SIGINT)",
2379 lp->ptid.to_string ().c_str (),
2380 errno ? safe_strerror (errno) : "OK");
2381
2382 return stop_wait_callback (lp);
2383 }
2384
2386
2387 if (WSTOPSIG (status) != SIGSTOP)
2388 {
2389 /* The thread was stopped with a signal other than SIGSTOP. */
2390
2391 linux_nat_debug_printf ("Pending event %s in %s",
2392 status_to_str ((int) status).c_str (),
2393 lp->ptid.to_string ().c_str ());
2394
2395 /* Save the sigtrap event. */
2396 lp->status = status;
2397 gdb_assert (lp->signalled);
2398 save_stop_reason (lp);
2399 }
2400 else
2401 {
2402 /* We caught the SIGSTOP that we intended to catch. */
2403
2404 linux_nat_debug_printf ("Expected SIGSTOP caught for %s.",
2405 lp->ptid.to_string ().c_str ());
2406
2407 lp->signalled = 0;
2408
2409 /* If we are waiting for this stop so we can report the thread
2410 stopped then we need to record this status. Otherwise, we can
2411 now discard this stop event. */
2412 if (lp->last_resume_kind == resume_stop)
2413 {
2414 lp->status = status;
2415 save_stop_reason (lp);
2416 }
2417 }
2418 }
2419
2420 return 0;
2421}
2422
2423/* Return non-zero if LP has a wait status pending. Discard the
2424 pending event and resume the LWP if the event that originally
2425 caused the stop became uninteresting. */
2426
2427static int
2429{
2430 /* Only report a pending wait status if we pretend that this has
2431 indeed been resumed. */
2432 if (!lp->resumed)
2433 return 0;
2434
2435 if (!lwp_status_pending_p (lp))
2436 return 0;
2437
2440 {
2442 CORE_ADDR pc;
2443 int discard = 0;
2444
2446
2447 if (pc != lp->stop_pc)
2448 {
2449 linux_nat_debug_printf ("PC of %s changed. was=%s, now=%s",
2450 lp->ptid.to_string ().c_str (),
2452 paddress (target_gdbarch (), pc));
2453 discard = 1;
2454 }
2455
2456#if !USE_SIGTRAP_SIGINFO
2457 else if (!breakpoint_inserted_here_p (regcache->aspace (), pc))
2458 {
2459 linux_nat_debug_printf ("previous breakpoint of %s, at %s gone",
2460 lp->ptid.to_string ().c_str (),
2461 paddress (target_gdbarch (), lp->stop_pc));
2462
2463 discard = 1;
2464 }
2465#endif
2466
2467 if (discard)
2468 {
2469 linux_nat_debug_printf ("pending event of %s cancelled.",
2470 lp->ptid.to_string ().c_str ());
2471
2472 lp->status = 0;
2473 linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
2474 return 0;
2475 }
2476 }
2477
2478 return 1;
2479}
2480
2481/* Count the LWP's that have had events. */
2482
2483static int
2484count_events_callback (struct lwp_info *lp, int *count)
2485{
2486 gdb_assert (count != NULL);
2487
2488 /* Select only resumed LWPs that have an event pending. */
2489 if (lp->resumed && lwp_status_pending_p (lp))
2490 (*count)++;
2491
2492 return 0;
2493}
2494
2495/* Select the LWP (if any) that is currently being single-stepped. */
2496
2497static int
2499{
2500 if (lp->last_resume_kind == resume_step
2501 && lp->status != 0)
2502 return 1;
2503 else
2504 return 0;
2505}
2506
2507/* Returns true if LP has a status pending. */
2508
2509static int
2511{
2512 /* We check for lp->waitstatus in addition to lp->status, because we
2513 can have pending process exits recorded in lp->status and
2514 W_EXITCODE(0,0) happens to be 0. */
2515 return lp->status != 0 || lp->waitstatus.kind () != TARGET_WAITKIND_IGNORE;
2516}
2517
2518/* Select the Nth LWP that has had an event. */
2519
2520static int
2522{
2523 gdb_assert (selector != NULL);
2524
2525 /* Select only resumed LWPs that have an event pending. */
2526 if (lp->resumed && lwp_status_pending_p (lp))
2527 if ((*selector)-- == 0)
2528 return 1;
2529
2530 return 0;
2531}
2532
2533/* Called when the LWP stopped for a signal/trap. If it stopped for a
2534 trap check what caused it (breakpoint, watchpoint, trace, etc.),
2535 and save the result in the LWP's stop_reason field. If it stopped
2536 for a breakpoint, decrement the PC if necessary on the lwp's
2537 architecture. */
2538
2539static void
2541{
2542 struct regcache *regcache;
2543 struct gdbarch *gdbarch;
2544 CORE_ADDR pc;
2545 CORE_ADDR sw_bp_pc;
2546#if USE_SIGTRAP_SIGINFO
2547 siginfo_t siginfo;
2548#endif
2549
2550 gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
2551 gdb_assert (lp->status != 0);
2552
2554 return;
2555
2557 if (inf->starting_up)
2558 return;
2559
2561 gdbarch = regcache->arch ();
2562
2564 sw_bp_pc = pc - gdbarch_decr_pc_after_break (gdbarch);
2565
2566#if USE_SIGTRAP_SIGINFO
2567 if (linux_nat_get_siginfo (lp->ptid, &siginfo))
2568 {
2569 if (siginfo.si_signo == SIGTRAP)
2570 {
2571 if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)
2572 && GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
2573 {
2574 /* The si_code is ambiguous on this arch -- check debug
2575 registers. */
2578 }
2579 else if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
2580 {
2581 /* If we determine the LWP stopped for a SW breakpoint,
2582 trust it. Particularly don't check watchpoint
2583 registers, because, at least on s390, we'd find
2584 stopped-by-watchpoint as long as there's a watchpoint
2585 set. */
2587 }
2588 else if (GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
2589 {
2590 /* This can indicate either a hardware breakpoint or
2591 hardware watchpoint. Check debug registers. */
2594 }
2595 else if (siginfo.si_code == TRAP_TRACE)
2596 {
2597 linux_nat_debug_printf ("%s stopped by trace",
2598 lp->ptid.to_string ().c_str ());
2599
2600 /* We may have single stepped an instruction that
2601 triggered a watchpoint. In that case, on some
2602 architectures (such as x86), instead of TRAP_HWBKPT,
2603 si_code indicates TRAP_TRACE, and we need to check
2604 the debug registers separately. */
2606 }
2607 }
2608 }
2609#else
2610 if ((!lp->step || lp->stop_pc == sw_bp_pc)
2612 sw_bp_pc))
2613 {
2614 /* The LWP was either continued, or stepped a software
2615 breakpoint instruction. */
2617 }
2618
2621
2624#endif
2625
2627 {
2628 linux_nat_debug_printf ("%s stopped by software breakpoint",
2629 lp->ptid.to_string ().c_str ());
2630
2631 /* Back up the PC if necessary. */
2632 if (pc != sw_bp_pc)
2633 regcache_write_pc (regcache, sw_bp_pc);
2634
2635 /* Update this so we record the correct stop PC below. */
2636 pc = sw_bp_pc;
2637 }
2639 {
2640 linux_nat_debug_printf ("%s stopped by hardware breakpoint",
2641 lp->ptid.to_string ().c_str ());
2642 }
2644 {
2645 linux_nat_debug_printf ("%s stopped by hardware watchpoint",
2646 lp->ptid.to_string ().c_str ());
2647 }
2648
2649 lp->stop_pc = pc;
2650}
2651
2652
2653/* Returns true if the LWP had stopped for a software breakpoint. */
2654
2655bool
2657{
2658 struct lwp_info *lp = find_lwp_pid (inferior_ptid);
2659
2660 gdb_assert (lp != NULL);
2661
2663}
2664
2665/* Implement the supports_stopped_by_sw_breakpoint method. */
2666
2667bool
2672
2673/* Returns true if the LWP had stopped for a hardware
2674 breakpoint/watchpoint. */
2675
2676bool
2678{
2679 struct lwp_info *lp = find_lwp_pid (inferior_ptid);
2680
2681 gdb_assert (lp != NULL);
2682
2684}
2685
2686/* Implement the supports_stopped_by_hw_breakpoint method. */
2687
2688bool
2693
2694/* Select one LWP out of those that have events pending. */
2695
2696static void
2697select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
2698{
2699 int num_events = 0;
2700 int random_selector;
2701 struct lwp_info *event_lp = NULL;
2702
2703 /* Record the wait status for the original LWP. */
2704 (*orig_lp)->status = *status;
2705
2706 /* In all-stop, give preference to the LWP that is being
2707 single-stepped. There will be at most one, and it will be the
2708 LWP that the core is most interested in. If we didn't do this,
2709 then we'd have to handle pending step SIGTRAPs somehow in case
2710 the core later continues the previously-stepped thread, as
2711 otherwise we'd report the pending SIGTRAP then, and the core, not
2712 having stepped the thread, wouldn't understand what the trap was
2713 for, and therefore would report it to the user as a random
2714 signal. */
2715 if (!target_is_non_stop_p ())
2716 {
2718 if (event_lp != NULL)
2719 {
2720 linux_nat_debug_printf ("Select single-step %s",
2721 event_lp->ptid.to_string ().c_str ());
2722 }
2723 }
2724
2725 if (event_lp == NULL)
2726 {
2727 /* Pick one at random, out of those which have had events. */
2728
2729 /* First see how many events we have. */
2730 iterate_over_lwps (filter,
2731 [&] (struct lwp_info *info)
2732 {
2733 return count_events_callback (info, &num_events);
2734 });
2735 gdb_assert (num_events > 0);
2736
2737 /* Now randomly pick a LWP out of those that have had
2738 events. */
2739 random_selector = (int)
2740 ((num_events * (double) rand ()) / (RAND_MAX + 1.0));
2741
2742 if (num_events > 1)
2743 linux_nat_debug_printf ("Found %d events, selecting #%d",
2744 num_events, random_selector);
2745
2746 event_lp
2748 (filter,
2749 [&] (struct lwp_info *info)
2750 {
2751 return select_event_lwp_callback (info,
2752 &random_selector);
2753 }));
2754 }
2755
2756 if (event_lp != NULL)
2757 {
2758 /* Switch the event LWP. */
2759 *orig_lp = event_lp;
2760 *status = event_lp->status;
2761 }
2762
2763 /* Flush the wait status for the event LWP. */
2764 (*orig_lp)->status = 0;
2765}
2766
2767/* Return non-zero if LP has been resumed. */
2768
2769static int
2771{
2772 return lp->resumed;
2773}
2774
2775/* Check if we should go on and pass this event to common code.
2776
2777 If so, save the status to the lwp_info structure associated to LWPID. */
2778
2779static void
2781{
2782 struct lwp_info *lp;
2784
2785 lp = find_lwp_pid (ptid_t (lwpid));
2786
2787 /* Check for events reported by anything not in our LWP list. */
2788 if (lp == nullptr)
2789 {
2790 if (WIFSTOPPED (status))
2791 {
2792 if (WSTOPSIG (status) == SIGTRAP && event == PTRACE_EVENT_EXEC)
2793 {
2794 /* A non-leader thread exec'ed after we've seen the
2795 leader zombie, and removed it from our lists (in
2796 check_zombie_leaders). The non-leader thread changes
2797 its tid to the tgid. */
2799 ("Re-adding thread group leader LWP %d after exec.",
2800 lwpid);
2801
2802 lp = add_lwp (ptid_t (lwpid, lwpid));
2803 lp->stopped = 1;
2804 lp->resumed = 1;
2806 }
2807 else
2808 {
2809 /* A process we are controlling has forked and the new
2810 child's stop was reported to us by the kernel. Save
2811 its PID and go back to waiting for the fork event to
2812 be reported - the stopped process might be returned
2813 from waitpid before or after the fork event is. */
2815 ("Saving LWP %d status %s in stopped_pids list",
2816 lwpid, status_to_str (status).c_str ());
2818 }
2819 }
2820 else
2821 {
2822 /* Don't report an event for the exit of an LWP not in our
2823 list, i.e. not part of any inferior we're debugging.
2824 This can happen if we detach from a program we originally
2825 forked and then it exits. However, note that we may have
2826 earlier deleted a leader of an inferior we're debugging,
2827 in check_zombie_leaders. Re-add it back here if so. */
2829 {
2830 if (inf->pid == lwpid)
2831 {
2833 ("Re-adding thread group leader LWP %d after exit.",
2834 lwpid);
2835
2836 lp = add_lwp (ptid_t (lwpid, lwpid));
2837 lp->resumed = 1;
2839 break;
2840 }
2841 }
2842 }
2843
2844 if (lp == nullptr)
2845 return;
2846 }
2847
2848 /* This LWP is stopped now. (And if dead, this prevents it from
2849 ever being continued.) */
2850 lp->stopped = 1;
2851
2852 if (WIFSTOPPED (status) && lp->must_set_ptrace_flags)
2853 {
2855 int options = linux_nat_ptrace_options (inf->attach_flag);
2856
2857 linux_enable_event_reporting (lp->ptid.lwp (), options);
2858 lp->must_set_ptrace_flags = 0;
2859 }
2860
2861 /* Handle GNU/Linux's syscall SIGTRAPs. */
2862 if (WIFSTOPPED (status) && WSTOPSIG (status) == SYSCALL_SIGTRAP)
2863 {
2864 /* No longer need the sysgood bit. The ptrace event ends up
2865 recorded in lp->waitstatus if we care for it. We can carry
2866 on handling the event like a regular SIGTRAP from here
2867 on. */
2868 status = W_STOPCODE (SIGTRAP);
2869 if (linux_handle_syscall_trap (lp, 0))
2870 return;
2871 }
2872 else
2873 {
2874 /* Almost all other ptrace-stops are known to be outside of system
2875 calls, with further exceptions in linux_handle_extended_wait. */
2877 }
2878
2879 /* Handle GNU/Linux's extended waitstatus for trace events. */
2880 if (WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP
2882 {
2883 linux_nat_debug_printf ("Handling extended status 0x%06x", status);
2884
2886 return;
2887 }
2888
2889 /* Check if the thread has exited. */
2890 if (WIFEXITED (status) || WIFSIGNALED (status))
2891 {
2892 if (!report_thread_events && !is_leader (lp))
2893 {
2894 linux_nat_debug_printf ("%s exited.",
2895 lp->ptid.to_string ().c_str ());
2896
2897 /* If this was not the leader exiting, then the exit signal
2898 was not the end of the debugged application and should be
2899 ignored. */
2900 exit_lwp (lp);
2901 return;
2902 }
2903
2904 /* Note that even if the leader was ptrace-stopped, it can still
2905 exit, if e.g., some other thread brings down the whole
2906 process (calls `exit'). So don't assert that the lwp is
2907 resumed. */
2908 linux_nat_debug_printf ("LWP %ld exited (resumed=%d)",
2909 lp->ptid.lwp (), lp->resumed);
2910
2911 /* Dead LWP's aren't expected to reported a pending sigstop. */
2912 lp->signalled = 0;
2913
2914 /* Store the pending event in the waitstatus, because
2915 W_EXITCODE(0,0) == 0. */
2917 return;
2918 }
2919
2920 /* Make sure we don't report a SIGSTOP that we sent ourselves in
2921 an attempt to stop an LWP. */
2922 if (lp->signalled
2923 && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP)
2924 {
2925 lp->signalled = 0;
2926
2927 if (lp->last_resume_kind == resume_stop)
2928 {
2929 linux_nat_debug_printf ("resume_stop SIGSTOP caught for %s.",
2930 lp->ptid.to_string ().c_str ());
2931 }
2932 else
2933 {
2934 /* This is a delayed SIGSTOP. Filter out the event. */
2935
2937 ("%s %s, 0, 0 (discard delayed SIGSTOP)",
2938 lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
2939 lp->ptid.to_string ().c_str ());
2940
2941 linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
2942 gdb_assert (lp->resumed);
2943 return;
2944 }
2945 }
2946
2947 /* Make sure we don't report a SIGINT that we have already displayed
2948 for another thread. */
2949 if (lp->ignore_sigint
2950 && WIFSTOPPED (status) && WSTOPSIG (status) == SIGINT)
2951 {
2952 linux_nat_debug_printf ("Delayed SIGINT caught for %s.",
2953 lp->ptid.to_string ().c_str ());
2954
2955 /* This is a delayed SIGINT. */
2956 lp->ignore_sigint = 0;
2957
2958 linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
2959 linux_nat_debug_printf ("%s %s, 0, 0 (discard SIGINT)",
2960 lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
2961 lp->ptid.to_string ().c_str ());
2962 gdb_assert (lp->resumed);
2963
2964 /* Discard the event. */
2965 return;
2966 }
2967
2968 /* Don't report signals that GDB isn't interested in, such as
2969 signals that are neither printed nor stopped upon. Stopping all
2970 threads can be a bit time-consuming, so if we want decent
2971 performance with heavily multi-threaded programs, especially when
2972 they're using a high frequency timer, we'd better avoid it if we
2973 can. */
2974 if (WIFSTOPPED (status))
2975 {
2976 enum gdb_signal signo = gdb_signal_from_host (WSTOPSIG (status));
2977
2978 if (!target_is_non_stop_p ())
2979 {
2980 /* Only do the below in all-stop, as we currently use SIGSTOP
2981 to implement target_stop (see linux_nat_stop) in
2982 non-stop. */
2983 if (signo == GDB_SIGNAL_INT && signal_pass_state (signo) == 0)
2984 {
2985 /* If ^C/BREAK is typed at the tty/console, SIGINT gets
2986 forwarded to the entire process group, that is, all LWPs
2987 will receive it - unless they're using CLONE_THREAD to
2988 share signals. Since we only want to report it once, we
2989 mark it as ignored for all LWPs except this one. */
2990 iterate_over_lwps (ptid_t (lp->ptid.pid ()), set_ignore_sigint);
2991 lp->ignore_sigint = 0;
2992 }
2993 else
2995 }
2996
2997 /* When using hardware single-step, we need to report every signal.
2998 Otherwise, signals in pass_mask may be short-circuited
2999 except signals that might be caused by a breakpoint, or SIGSTOP
3000 if we sent the SIGSTOP and are waiting for it to arrive. */
3001 if (!lp->step
3002 && WSTOPSIG (status) && sigismember (&pass_mask, WSTOPSIG (status))
3003 && (WSTOPSIG (status) != SIGSTOP
3006 {
3007 linux_resume_one_lwp (lp, lp->step, signo);
3009 ("%s %s, %s (preempt 'handle')",
3010 lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
3011 lp->ptid.to_string ().c_str (),
3012 (signo != GDB_SIGNAL_0
3013 ? strsignal (gdb_signal_to_host (signo)) : "0"));
3014 return;
3015 }
3016 }
3017
3018 /* An interesting event. */
3019 gdb_assert (lp);
3020 lp->status = status;
3021 save_stop_reason (lp);
3022}
3023
3024/* Detect zombie thread group leaders, and "exit" them. We can't reap
3025 their exits until all other threads in the group have exited. */
3026
3027static void
3029{
3030 for (inferior *inf : all_inferiors ())
3031 {
3032 struct lwp_info *leader_lp;
3033
3034 if (inf->pid == 0)
3035 continue;
3036
3037 leader_lp = find_lwp_pid (ptid_t (inf->pid));
3038 if (leader_lp != NULL
3039 /* Check if there are other threads in the group, as we may
3040 have raced with the inferior simply exiting. Note this
3041 isn't a watertight check. If the inferior is
3042 multi-threaded and is exiting, it may be we see the
3043 leader as zombie before we reap all the non-leader
3044 threads. See comments below. */
3045 && num_lwps (inf->pid) > 1
3047 {
3048 /* A zombie leader in a multi-threaded program can mean one
3049 of three things:
3050
3051 #1 - Only the leader exited, not the whole program, e.g.,
3052 with pthread_exit. Since we can't reap the leader's exit
3053 status until all other threads are gone and reaped too,
3054 we want to delete the zombie leader right away, as it
3055 can't be debugged, we can't read its registers, etc.
3056 This is the main reason we check for zombie leaders
3057 disappearing.
3058
3059 #2 - The whole thread-group/process exited (a group exit,
3060 via e.g. exit(3), and there is (or will be shortly) an
3061 exit reported for each thread in the process, and then
3062 finally an exit for the leader once the non-leaders are
3063 reaped.
3064
3065 #3 - There are 3 or more threads in the group, and a
3066 thread other than the leader exec'd. See comments on
3067 exec events at the top of the file.
3068
3069 Ideally we would never delete the leader for case #2.
3070 Instead, we want to collect the exit status of each
3071 non-leader thread, and then finally collect the exit
3072 status of the leader as normal and use its exit code as
3073 whole-process exit code. Unfortunately, there's no
3074 race-free way to distinguish cases #1 and #2. We can't
3075 assume the exit events for the non-leaders threads are
3076 already pending in the kernel, nor can we assume the
3077 non-leader threads are in zombie state already. Between
3078 the leader becoming zombie and the non-leaders exiting
3079 and becoming zombie themselves, there's a small time
3080 window, so such a check would be racy. Temporarily
3081 pausing all threads and checking to see if all threads
3082 exit or not before re-resuming them would work in the
3083 case that all threads are running right now, but it
3084 wouldn't work if some thread is currently already
3085 ptrace-stopped, e.g., due to scheduler-locking.
3086
3087 So what we do is we delete the leader anyhow, and then
3088 later on when we see its exit status, we re-add it back.
3089 We also make sure that we only report a whole-process
3090 exit when we see the leader exiting, as opposed to when
3091 the last LWP in the LWP list exits, which can be a
3092 non-leader if we deleted the leader here. */
3093 linux_nat_debug_printf ("Thread group leader %d zombie "
3094 "(it exited, or another thread execd), "
3095 "deleting it.",
3096 inf->pid);
3097 exit_lwp (leader_lp);
3098 }
3099 }
3100}
3101
3102/* Convenience function that is called when the kernel reports an exit
3103 event. This decides whether to report the event to GDB as a
3104 process exit event, a thread exit event, or to suppress the
3105 event. */
3106
3107static ptid_t
3108filter_exit_event (struct lwp_info *event_child,
3109 struct target_waitstatus *ourstatus)
3110{
3111 ptid_t ptid = event_child->ptid;
3112
3113 if (!is_leader (event_child))
3114 {
3116 ourstatus->set_thread_exited (0);
3117 else
3118 ourstatus->set_ignore ();
3119
3120 exit_lwp (event_child);
3121 }
3122
3123 return ptid;
3124}
3125
3126static ptid_t
3127linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
3128 target_wait_flags target_options)
3129{
3131
3132 sigset_t prev_mask;
3134 struct lwp_info *lp;
3135 int status;
3136
3137 /* The first time we get here after starting a new inferior, we may
3138 not have added it to the LWP list yet - this is the earliest
3139 moment at which we know its PID. */
3140 if (ptid.is_pid () && find_lwp_pid (ptid) == nullptr)
3141 {
3142 ptid_t lwp_ptid (ptid.pid (), ptid.pid ());
3143
3144 /* Upgrade the main thread's ptid. */
3146 lp = add_initial_lwp (lwp_ptid);
3147 lp->resumed = 1;
3148 }
3149
3150 /* Make sure SIGCHLD is blocked until the sigsuspend below. */
3151 block_child_signals (&prev_mask);
3152
3153 /* First check if there is a LWP with a wait status pending. */
3155 if (lp != NULL)
3156 {
3157 linux_nat_debug_printf ("Using pending wait status %s for %s.",
3158 pending_status_str (lp).c_str (),
3159 lp->ptid.to_string ().c_str ());
3160 }
3161
3162 /* But if we don't find a pending event, we'll have to wait. Always
3163 pull all events out of the kernel. We'll randomly select an
3164 event LWP out of all that have events, to prevent starvation. */
3165
3166 while (lp == NULL)
3167 {
3168 pid_t lwpid;
3169
3170 /* Always use -1 and WNOHANG, due to couple of a kernel/ptrace
3171 quirks:
3172
3173 - If the thread group leader exits while other threads in the
3174 thread group still exist, waitpid(TGID, ...) hangs. That
3175 waitpid won't return an exit status until the other threads
3176 in the group are reaped.
3177
3178 - When a non-leader thread execs, that thread just vanishes
3179 without reporting an exit (so we'd hang if we waited for it
3180 explicitly in that case). The exec event is reported to
3181 the TGID pid. */
3182
3183 errno = 0;
3184 lwpid = my_waitpid (-1, &status, __WALL | WNOHANG);
3185
3186 linux_nat_debug_printf ("waitpid(-1, ...) returned %d, %s",
3187 lwpid,
3188 errno ? safe_strerror (errno) : "ERRNO-OK");
3189
3190 if (lwpid > 0)
3191 {
3192 linux_nat_debug_printf ("waitpid %ld received %s",
3193 (long) lwpid,
3194 status_to_str (status).c_str ());
3195
3197 /* Retry until nothing comes out of waitpid. A single
3198 SIGCHLD can indicate more than one child stopped. */
3199 continue;
3200 }
3201
3202 /* Now that we've pulled all events out of the kernel, resume
3203 LWPs that don't have an interesting event to report. */
3204 iterate_over_lwps (minus_one_ptid,
3205 [] (struct lwp_info *info)
3206 {
3207 return resume_stopped_resumed_lwps (info, minus_one_ptid);
3208 });
3209
3210 /* ... and find an LWP with a status to report to the core, if
3211 any. */
3213 if (lp != NULL)
3214 break;
3215
3216 /* Check for zombie thread group leaders. Those can't be reaped
3217 until all other threads in the thread group are. */
3219
3220 /* If there are no resumed children left, bail. We'd be stuck
3221 forever in the sigsuspend call below otherwise. */
3223 {
3224 linux_nat_debug_printf ("exit (no resumed LWP)");
3225
3226 ourstatus->set_no_resumed ();
3227
3228 restore_child_signals_mask (&prev_mask);
3229 return minus_one_ptid;
3230 }
3231
3232 /* No interesting event to report to the core. */
3233
3234 if (target_options & TARGET_WNOHANG)
3235 {
3236 linux_nat_debug_printf ("no interesting events found");
3237
3238 ourstatus->set_ignore ();
3239 restore_child_signals_mask (&prev_mask);
3240 return minus_one_ptid;
3241 }
3242
3243 /* We shouldn't end up here unless we want to try again. */
3244 gdb_assert (lp == NULL);
3245
3246 /* Block until we get an event reported with SIGCHLD. */
3247 wait_for_signal ();
3248 }
3249
3250 gdb_assert (lp);
3251
3252 status = lp->status;
3253 lp->status = 0;
3254
3255 if (!target_is_non_stop_p ())
3256 {
3257 /* Now stop all other LWP's ... */
3258 iterate_over_lwps (minus_one_ptid, stop_callback);
3259
3260 /* ... and wait until all of them have reported back that
3261 they're no longer running. */
3262 iterate_over_lwps (minus_one_ptid, stop_wait_callback);
3263 }
3264
3265 /* If we're not waiting for a specific LWP, choose an event LWP from
3266 among those that have had events. Giving equal priority to all
3267 LWPs that have had events helps prevent starvation. */
3268 if (ptid == minus_one_ptid || ptid.is_pid ())
3269 select_event_lwp (ptid, &lp, &status);
3270
3271 gdb_assert (lp != NULL);
3272
3273 /* Now that we've selected our final event LWP, un-adjust its PC if
3274 it was a software breakpoint, and we can't reliably support the
3275 "stopped by software breakpoint" stop reason. */
3278 {
3280 struct gdbarch *gdbarch = regcache->arch ();
3281 int decr_pc = gdbarch_decr_pc_after_break (gdbarch);
3282
3283 if (decr_pc != 0)
3284 {
3285 CORE_ADDR pc;
3286
3288 regcache_write_pc (regcache, pc + decr_pc);
3289 }
3290 }
3291
3292 /* We'll need this to determine whether to report a SIGSTOP as
3293 GDB_SIGNAL_0. Need to take a copy because resume_clear_callback
3294 clears it. */
3295 last_resume_kind = lp->last_resume_kind;
3296
3297 if (!target_is_non_stop_p ())
3298 {
3299 /* In all-stop, from the core's perspective, all LWPs are now
3300 stopped until a new resume action is sent over. */
3301 iterate_over_lwps (minus_one_ptid, resume_clear_callback);
3302 }
3303 else
3304 {
3306 }
3307
3309 {
3310 linux_nat_debug_printf ("trap ptid is %s.",
3311 lp->ptid.to_string ().c_str ());
3312 }
3313
3315 {
3316 *ourstatus = lp->waitstatus;
3317 lp->waitstatus.set_ignore ();
3318 }
3319 else
3320 *ourstatus = host_status_to_waitstatus (status);
3321
3322 linux_nat_debug_printf ("event found");
3323
3324 restore_child_signals_mask (&prev_mask);
3325
3326 if (last_resume_kind == resume_stop
3327 && ourstatus->kind () == TARGET_WAITKIND_STOPPED
3328 && WSTOPSIG (status) == SIGSTOP)
3329 {
3330 /* A thread that has been requested to stop by GDB with
3331 target_stop, and it stopped cleanly, so report as SIG0. The
3332 use of SIGSTOP is an implementation detail. */
3333 ourstatus->set_stopped (GDB_SIGNAL_0);
3334 }
3335
3336 if (ourstatus->kind () == TARGET_WAITKIND_EXITED
3337 || ourstatus->kind () == TARGET_WAITKIND_SIGNALLED)
3338 lp->core = -1;
3339 else
3341
3342 if (ourstatus->kind () == TARGET_WAITKIND_EXITED)
3343 return filter_exit_event (lp, ourstatus);
3344
3345 return lp->ptid;
3346}
3347
3348/* Resume LWPs that are currently stopped without any pending status
3349 to report, but are resumed from the core's perspective. */
3350
3351static int
3352resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid)
3353{
3355
3356 if (!lp->stopped)
3357 {
3358 linux_nat_debug_printf ("NOT resuming LWP %s, not stopped",
3359 lp->ptid.to_string ().c_str ());
3360 }
3361 else if (!lp->resumed)
3362 {
3363 linux_nat_debug_printf ("NOT resuming LWP %s, not resumed",
3364 lp->ptid.to_string ().c_str ());
3365 }
3366 else if (lwp_status_pending_p (lp))
3367 {
3368 linux_nat_debug_printf ("NOT resuming LWP %s, has pending status",
3369 lp->ptid.to_string ().c_str ());
3370 }
3371 else if (inf->vfork_child != nullptr)
3372 {
3373 linux_nat_debug_printf ("NOT resuming LWP %s (vfork parent)",
3374 lp->ptid.to_string ().c_str ());
3375 }
3376 else
3377 {
3379 struct gdbarch *gdbarch = regcache->arch ();
3380
3381 try
3382 {
3383 CORE_ADDR pc = regcache_read_pc (regcache);
3384 int leave_stopped = 0;
3385
3386 /* Don't bother if there's a breakpoint at PC that we'd hit
3387 immediately, and we're not waiting for this LWP. */
3388 if (!lp->ptid.matches (wait_ptid))
3389 {
3391 leave_stopped = 1;
3392 }
3393
3394 if (!leave_stopped)
3395 {
3397 ("resuming stopped-resumed LWP %s at %s: step=%d",
3398 lp->ptid.to_string ().c_str (), paddress (gdbarch, pc),
3399 lp->step);
3400
3401 linux_resume_one_lwp_throw (lp, lp->step, GDB_SIGNAL_0);
3402 }
3403 }
3404 catch (const gdb_exception_error &ex)
3405 {
3407 throw;
3408 }
3409 }
3410
3411 return 0;
3412}
3413
3414ptid_t
3415linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
3416 target_wait_flags target_options)
3417{
3419
3420 ptid_t event_ptid;
3421
3422 linux_nat_debug_printf ("[%s], [%s]", ptid.to_string ().c_str (),
3423 target_options_to_string (target_options).c_str ());
3424
3425 /* Flush the async file first. */
3426 if (target_is_async_p ())
3428
3429 /* Resume LWPs that are currently stopped without any pending status
3430 to report, but are resumed from the core's perspective. LWPs get
3431 in this state if we find them stopping at a time we're not
3432 interested in reporting the event (target_wait on a
3433 specific_process, for example, see linux_nat_wait_1), and
3434 meanwhile the event became uninteresting. Don't bother resuming
3435 LWPs we're not going to wait for if they'd stop immediately. */
3436 if (target_is_non_stop_p ())
3437 iterate_over_lwps (minus_one_ptid,
3438 [=] (struct lwp_info *info)
3439 {
3440 return resume_stopped_resumed_lwps (info, ptid);
3441 });
3442
3443 event_ptid = linux_nat_wait_1 (ptid, ourstatus, target_options);
3444
3445 /* If we requested any event, and something came out, assume there
3446 may be more. If we requested a specific lwp or process, also
3447 assume there may be more. */
3448 if (target_is_async_p ()
3449 && ((ourstatus->kind () != TARGET_WAITKIND_IGNORE
3450 && ourstatus->kind () != TARGET_WAITKIND_NO_RESUMED)
3451 || ptid != minus_one_ptid))
3452 async_file_mark ();
3453
3454 return event_ptid;
3455}
3456
3457/* Kill one LWP. */
3458
3459static void
3461{
3462 /* PTRACE_KILL may resume the inferior. Send SIGKILL first. */
3463
3464 errno = 0;
3465 kill_lwp (pid, SIGKILL);
3466
3467 if (debug_linux_nat)
3468 {
3469 int save_errno = errno;
3470
3472 ("kill (SIGKILL) %ld, 0, 0 (%s)", (long) pid,
3473 save_errno != 0 ? safe_strerror (save_errno) : "OK");
3474 }
3475
3476 /* Some kernels ignore even SIGKILL for processes under ptrace. */
3477
3478 errno = 0;
3479 ptrace (PTRACE_KILL, pid, 0, 0);
3480 if (debug_linux_nat)
3481 {
3482 int save_errno = errno;
3483
3485 ("PTRACE_KILL %ld, 0, 0 (%s)", (long) pid,
3486 save_errno ? safe_strerror (save_errno) : "OK");
3487 }
3488}
3489
3490/* Wait for an LWP to die. */
3491
3492static void
3494{
3495 pid_t res;
3496
3497 /* We must make sure that there are no pending events (delayed
3498 SIGSTOPs, pending SIGTRAPs, etc.) to make sure the current
3499 program doesn't interfere with any following debugging session. */
3500
3501 do
3502 {
3503 res = my_waitpid (pid, NULL, __WALL);
3504 if (res != (pid_t) -1)
3505 {
3506 linux_nat_debug_printf ("wait %ld received unknown.", (long) pid);
3507
3508 /* The Linux kernel sometimes fails to kill a thread
3509 completely after PTRACE_KILL; that goes from the stop
3510 point in do_fork out to the one in get_signal_to_deliver
3511 and waits again. So kill it again. */
3512 kill_one_lwp (pid);
3513 }
3514 }
3515 while (res == pid);
3516
3517 gdb_assert (res == -1 && errno == ECHILD);
3518}
3519
3520/* Callback for iterate_over_lwps. */
3521
3522static int
3524{
3525 kill_one_lwp (lp->ptid.lwp ());
3526 return 0;
3527}
3528
3529/* Callback for iterate_over_lwps. */
3530
3531static int
3533{
3534 kill_wait_one_lwp (lp->ptid.lwp ());
3535 return 0;
3536}
3537
3538/* Kill the fork children of any threads of inferior INF that are
3539 stopped at a fork event. */
3540
3541static void
3543{
3544 for (thread_info *thread : inf->non_exited_threads ())
3545 {
3546 struct target_waitstatus *ws = &thread->pending_follow;
3547
3548 if (ws->kind () == TARGET_WAITKIND_FORKED
3549 || ws->kind () == TARGET_WAITKIND_VFORKED)
3550 {
3551 ptid_t child_ptid = ws->child_ptid ();
3552 int child_pid = child_ptid.pid ();
3553 int child_lwp = child_ptid.lwp ();
3554
3555 kill_one_lwp (child_lwp);
3556 kill_wait_one_lwp (child_lwp);
3557
3558 /* Let the arch-specific native code know this process is
3559 gone. */
3560 linux_target->low_forget_process (child_pid);
3561 }
3562 }
3563}
3564
3565void
3567{
3568 /* If we're stopped while forking and we haven't followed yet,
3569 kill the other task. We need to do this first because the
3570 parent will be sleeping if this is a vfork. */
3572
3573 if (forks_exist_p ())
3575 else
3576 {
3577 ptid_t ptid = ptid_t (inferior_ptid.pid ());
3578
3579 /* Stop all threads before killing them, since ptrace requires
3580 that the thread is stopped to successfully PTRACE_KILL. */
3582 /* ... and wait until all of them have reported back that
3583 they're no longer running. */
3585
3586 /* Kill all LWP's ... */
3588
3589 /* ... and wait until we've flushed all events. */
3591 }
3592
3594}
3595
3596void
3598{
3600
3601 int pid = inferior_ptid.pid ();
3602
3604
3606
3607 if (! forks_exist_p ())
3608 /* Normal case, no other forks available. */
3610 else
3611 /* Multi-fork case. The current inferior_ptid has exited, but
3612 there are other viable forks to debug. Delete the exiting
3613 one and context-switch to the first available. */
3615
3616 /* Let the arch-specific native code know this process is gone. */
3618}
3619
3620/* Convert a native/host siginfo object, into/from the siginfo in the
3621 layout of the inferiors' architecture. */
3622
3623static void
3624siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
3625{
3626 /* If the low target didn't do anything, then just do a straight
3627 memcpy. */
3628 if (!linux_target->low_siginfo_fixup (siginfo, inf_siginfo, direction))
3629 {
3630 if (direction == 1)
3631 memcpy (siginfo, inf_siginfo, sizeof (siginfo_t));
3632 else
3633 memcpy (inf_siginfo, siginfo, sizeof (siginfo_t));
3634 }
3635}
3636
3637static enum target_xfer_status
3638linux_xfer_siginfo (ptid_t ptid, enum target_object object,
3639 const char *annex, gdb_byte *readbuf,
3640 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
3641 ULONGEST *xfered_len)
3642{
3643 siginfo_t siginfo;
3644 gdb_byte inf_siginfo[sizeof (siginfo_t)];
3645
3646 gdb_assert (object == TARGET_OBJECT_SIGNAL_INFO);
3647 gdb_assert (readbuf || writebuf);
3648
3649 if (offset > sizeof (siginfo))
3650 return TARGET_XFER_E_IO;
3651
3652 if (!linux_nat_get_siginfo (ptid, &siginfo))
3653 return TARGET_XFER_E_IO;
3654
3655 /* When GDB is built as a 64-bit application, ptrace writes into
3656 SIGINFO an object with 64-bit layout. Since debugging a 32-bit
3657 inferior with a 64-bit GDB should look the same as debugging it
3658 with a 32-bit GDB, we need to convert it. GDB core always sees
3659 the converted layout, so any read/write will have to be done
3660 post-conversion. */
3661 siginfo_fixup (&siginfo, inf_siginfo, 0);
3662
3663 if (offset + len > sizeof (siginfo))
3664 len = sizeof (siginfo) - offset;
3665
3666 if (readbuf != NULL)
3667 memcpy (readbuf, inf_siginfo + offset, len);
3668 else
3669 {
3670 memcpy (inf_siginfo + offset, writebuf, len);
3671
3672 /* Convert back to ptrace layout before flushing it out. */
3673 siginfo_fixup (&siginfo, inf_siginfo, 1);
3674
3675 int pid = get_ptrace_pid (ptid);
3676 errno = 0;
3677 ptrace (PTRACE_SETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo);
3678 if (errno != 0)
3679 return TARGET_XFER_E_IO;
3680 }
3681
3682 *xfered_len = len;
3683 return TARGET_XFER_OK;
3684}
3685
3686static enum target_xfer_status
3688 const char *annex, gdb_byte *readbuf,
3689 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
3690 ULONGEST *xfered_len);
3691
3692static enum target_xfer_status
3693linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
3694 const gdb_byte *writebuf, ULONGEST offset,
3695 LONGEST len, ULONGEST *xfered_len);
3696
3699 const char *annex, gdb_byte *readbuf,
3700 const gdb_byte *writebuf,
3701 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
3702{
3703 if (object == TARGET_OBJECT_SIGNAL_INFO)
3704 return linux_xfer_siginfo (inferior_ptid, object, annex, readbuf, writebuf,
3705 offset, len, xfered_len);
3706
3707 /* The target is connected but no live inferior is selected. Pass
3708 this request down to a lower stratum (e.g., the executable
3709 file). */
3710 if (object == TARGET_OBJECT_MEMORY && inferior_ptid == null_ptid)
3711 return TARGET_XFER_EOF;
3712
3713 if (object == TARGET_OBJECT_AUXV)
3714 return memory_xfer_auxv (this, object, annex, readbuf, writebuf,
3715 offset, len, xfered_len);
3716
3717 if (object == TARGET_OBJECT_OSDATA)
3718 return linux_nat_xfer_osdata (object, annex, readbuf, writebuf,
3719 offset, len, xfered_len);
3720
3721 if (object == TARGET_OBJECT_MEMORY)
3722 {
3723 /* GDB calculates all addresses in the largest possible address
3724 width. The address width must be masked before its final use
3725 by linux_proc_xfer_partial.
3726
3727 Compare ADDR_BIT first to avoid a compiler warning on shift overflow. */
3728 int addr_bit = gdbarch_addr_bit (target_gdbarch ());
3729
3730 if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT))
3731 offset &= ((ULONGEST) 1 << addr_bit) - 1;
3732
3733 /* If /proc/pid/mem is writable, don't fallback to ptrace. If
3734 the write via /proc/pid/mem fails because the inferior execed
3735 (and we haven't seen the exec event yet), a subsequent ptrace
3736 poke would incorrectly write memory to the post-exec address
3737 space, while the core was trying to write to the pre-exec
3738 address space. */
3740 return linux_proc_xfer_memory_partial (inferior_ptid.pid (), readbuf,
3741 writebuf, offset, len,
3742 xfered_len);
3743 }
3744
3745 return inf_ptrace_target::xfer_partial (object, annex, readbuf, writebuf,
3746 offset, len, xfered_len);
3747}
3748
3749bool
3751{
3752 /* As long as a PTID is in lwp list, consider it alive. */
3753 return find_lwp_pid (ptid) != NULL;
3754}
3755
3756/* Implement the to_update_thread_list target method for this
3757 target. */
3758
3759void
3761{
3762 /* We add/delete threads from the list as clone/exit events are
3763 processed, so just try deleting exited threads still in the
3764 thread list. */
3766
3767 /* Update the processor core that each lwp/thread was last seen
3768 running on. */
3769 for (lwp_info *lwp : all_lwps ())
3770 {
3771 /* Avoid accessing /proc if the thread hasn't run since we last
3772 time we fetched the thread's core. Accessing /proc becomes
3773 noticeably expensive when we have thousands of LWPs. */
3774 if (lwp->core == -1)
3775 lwp->core = linux_common_core_of_thread (lwp->ptid);
3776 }
3777}
3778
3779std::string
3781{
3782 if (ptid.lwp_p ()
3783 && (ptid.pid () != ptid.lwp ()
3784 || num_lwps (ptid.pid ()) > 1))
3785 return string_printf ("LWP %ld", ptid.lwp ());
3786
3787 return normal_pid_to_str (ptid);
3788}
3789
3790const char *
3792{
3793 return linux_proc_tid_get_name (thr->ptid);
3794}
3795
3796/* Accepts an integer PID; Returns a string representing a file that
3797 can be opened to get the symbols for the child process. */
3798
3799const char *
3804
3805/* Object representing an /proc/PID/mem open file. We keep one such
3806 file open per inferior.
3807
3808 It might be tempting to think about only ever opening one file at
3809 most for all inferiors, closing/reopening the file as we access
3810 memory of different inferiors, to minimize number of file
3811 descriptors open, which can otherwise run into resource limits.
3812 However, that does not work correctly -- if the inferior execs and
3813 we haven't processed the exec event yet, and, we opened a
3814 /proc/PID/mem file, we will get a mem file accessing the post-exec
3815 address space, thinking we're opening it for the pre-exec address
3816 space. That is dangerous as we can poke memory (e.g. clearing
3817 breakpoints) in the post-exec memory by mistake, corrupting the
3818 inferior. For that reason, we open the mem file as early as
3819 possible, right after spawning, forking or attaching to the
3820 inferior, when the inferior is stopped and thus before it has a
3821 chance of execing.
3822
3823 Note that after opening the file, even if the thread we opened it
3824 for subsequently exits, the open file is still usable for accessing
3825 memory. It's only when the whole process exits or execs that the
3826 file becomes invalid, at which point reads/writes return EOF. */
3827
3829{
3830public:
3831 proc_mem_file (ptid_t ptid, int fd)
3832 : m_ptid (ptid), m_fd (fd)
3833 {
3834 gdb_assert (m_fd != -1);
3835 }
3836
3838 {
3839 linux_nat_debug_printf ("closing fd %d for /proc/%d/task/%ld/mem",
3840 m_fd, m_ptid.pid (), m_ptid.lwp ());
3841 close (m_fd);
3842 }
3843
3845
3846 int fd ()
3847 {
3848 return m_fd;
3849 }
3850
3851private:
3852 /* The LWP this file was opened for. Just for debugging
3853 purposes. */
3854 ptid_t m_ptid;
3855
3856 /* The file descriptor. */
3857 int m_fd = -1;
3858};
3859
3860/* The map between an inferior process id, and the open /proc/PID/mem
3861 file. This is stored in a map instead of in a per-inferior
3862 structure because we need to be able to access memory of processes
3863 which don't have a corresponding struct inferior object. E.g.,
3864 with "detach-on-fork on" (the default), and "follow-fork parent"
3865 (also default), we don't create an inferior for the fork child, but
3866 we still need to remove breakpoints from the fork child's
3867 memory. */
3868static std::unordered_map<int, proc_mem_file> proc_mem_file_map;
3869
3870/* Close the /proc/PID/mem file for PID. */
3871
3872static void
3874{
3875 proc_mem_file_map.erase (pid);
3876}
3877
3878/* Open the /proc/PID/mem file for the process (thread group) of PTID.
3879 We actually open /proc/PID/task/LWP/mem, as that's the LWP we know
3880 exists and is stopped right now. We prefer the
3881 /proc/PID/task/LWP/mem form over /proc/LWP/mem to avoid tid-reuse
3882 races, just in case this is ever called on an already-waited
3883 LWP. */
3884
3885static void
3887{
3888 auto iter = proc_mem_file_map.find (ptid.pid ());
3889 gdb_assert (iter == proc_mem_file_map.end ());
3890
3891 char filename[64];
3892 xsnprintf (filename, sizeof filename,
3893 "/proc/%d/task/%ld/mem", ptid.pid (), ptid.lwp ());
3894
3895 int fd = gdb_open_cloexec (filename, O_RDWR | O_LARGEFILE, 0).release ();
3896
3897 if (fd == -1)
3898 {
3899 warning (_("opening /proc/PID/mem file for lwp %d.%ld failed: %s (%d)"),
3900 ptid.pid (), ptid.lwp (),
3901 safe_strerror (errno), errno);
3902 return;
3903 }
3904
3905 proc_mem_file_map.emplace (std::piecewise_construct,
3906 std::forward_as_tuple (ptid.pid ()),
3907 std::forward_as_tuple (ptid, fd));
3908
3909 linux_nat_debug_printf ("opened fd %d for lwp %d.%ld",
3910 fd, ptid.pid (), ptid.lwp ());
3911}
3912
3913/* Helper for linux_proc_xfer_memory_partial and
3914 proc_mem_file_is_writable. FD is the already opened /proc/pid/mem
3915 file, and PID is the pid of the corresponding process. The rest of
3916 the arguments are like linux_proc_xfer_memory_partial's. */
3917
3918static enum target_xfer_status
3920 gdb_byte *readbuf, const gdb_byte *writebuf,
3921 ULONGEST offset, LONGEST len,
3922 ULONGEST *xfered_len)
3923{
3924 ssize_t ret;
3925
3926 gdb_assert (fd != -1);
3927
3928 /* Use pread64/pwrite64 if available, since they save a syscall and
3929 can handle 64-bit offsets even on 32-bit platforms (for instance,
3930 SPARC debugging a SPARC64 application). But only use them if the
3931 offset isn't so high that when cast to off_t it'd be negative, as
3932 seen on SPARC64. pread64/pwrite64 outright reject such offsets.
3933 lseek does not. */
3934#ifdef HAVE_PREAD64
3935 if ((off_t) offset >= 0)
3936 ret = (readbuf != nullptr
3937 ? pread64 (fd, readbuf, len, offset)
3938 : pwrite64 (fd, writebuf, len, offset));
3939 else
3940#endif
3941 {
3942 ret = lseek (fd, offset, SEEK_SET);
3943 if (ret != -1)
3944 ret = (readbuf != nullptr
3945 ? read (fd, readbuf, len)
3946 : write (fd, writebuf, len));
3947 }
3948
3949 if (ret == -1)
3950 {
3951 linux_nat_debug_printf ("accessing fd %d for pid %d failed: %s (%d)",
3952 fd, pid, safe_strerror (errno), errno);
3953 return TARGET_XFER_E_IO;
3954 }
3955 else if (ret == 0)
3956 {
3957 /* EOF means the address space is gone, the whole process exited
3958 or execed. */
3959 linux_nat_debug_printf ("accessing fd %d for pid %d got EOF",
3960 fd, pid);
3961 return TARGET_XFER_EOF;
3962 }
3963 else
3964 {
3965 *xfered_len = ret;
3966 return TARGET_XFER_OK;
3967 }
3968}
3969
3970/* Implement the to_xfer_partial target method using /proc/PID/mem.
3971 Because we can use a single read/write call, this can be much more
3972 efficient than banging away at PTRACE_PEEKTEXT. Also, unlike
3973 PTRACE_PEEKTEXT/PTRACE_POKETEXT, this works with running
3974 threads. */
3975
3976static enum target_xfer_status
3977linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
3978 const gdb_byte *writebuf, ULONGEST offset,
3979 LONGEST len, ULONGEST *xfered_len)
3980{
3981 auto iter = proc_mem_file_map.find (pid);
3982 if (iter == proc_mem_file_map.end ())
3983 return TARGET_XFER_EOF;
3984
3985 int fd = iter->second.fd ();
3986
3987 return linux_proc_xfer_memory_partial_fd (fd, pid, readbuf, writebuf, offset,
3988 len, xfered_len);
3989}
3990
3991/* Check whether /proc/pid/mem is writable in the current kernel, and
3992 return true if so. It wasn't writable before Linux 2.6.39, but
3993 there's no way to know whether the feature was backported to older
3994 kernels. So we check to see if it works. The result is cached,
3995 and this is guaranteed to be called once early during inferior
3996 startup, so that any warning is printed out consistently between
3997 GDB invocations. Note we don't call it during GDB startup instead
3998 though, because then we might warn with e.g. just "gdb --version"
3999 on sandboxed systems. See PR gdb/29907. */
4000
4001static bool
4003{
4004 static gdb::optional<bool> writable;
4005
4006 if (writable.has_value ())
4007 return *writable;
4008
4009 writable.emplace (false);
4010
4011 /* We check whether /proc/pid/mem is writable by trying to write to
4012 one of our variables via /proc/self/mem. */
4013
4014 int fd = gdb_open_cloexec ("/proc/self/mem", O_RDWR | O_LARGEFILE, 0).release ();
4015
4016 if (fd == -1)
4017 {
4018 warning (_("opening /proc/self/mem file failed: %s (%d)"),
4019 safe_strerror (errno), errno);
4020 return *writable;
4021 }
4022
4023 SCOPE_EXIT { close (fd); };
4024
4025 /* This is the variable we try to write to. Note OFFSET below. */
4026 volatile gdb_byte test_var = 0;
4027
4028 gdb_byte writebuf[] = {0x55};
4029 ULONGEST offset = (uintptr_t) &test_var;
4030 ULONGEST xfered_len;
4031
4032 enum target_xfer_status res
4033 = linux_proc_xfer_memory_partial_fd (fd, getpid (), nullptr, writebuf,
4034 offset, 1, &xfered_len);
4035
4036 if (res == TARGET_XFER_OK)
4037 {
4038 gdb_assert (xfered_len == 1);
4039 gdb_assert (test_var == 0x55);
4040 /* Success. */
4041 *writable = true;
4042 }
4043
4044 return *writable;
4045}
4046
4047/* Parse LINE as a signal set and add its set bits to SIGS. */
4048
4049static void
4050add_line_to_sigset (const char *line, sigset_t *sigs)
4051{
4052 int len = strlen (line) - 1;
4053 const char *p;
4054 int signum;
4055
4056 if (line[len] != '\n')
4057 error (_("Could not parse signal set: %s"), line);
4058
4059 p = line;
4060 signum = len * 4;
4061 while (len-- > 0)
4062 {
4063 int digit;
4064
4065 if (*p >= '0' && *p <= '9')
4066 digit = *p - '0';
4067 else if (*p >= 'a' && *p <= 'f')
4068 digit = *p - 'a' + 10;
4069 else
4070 error (_("Could not parse signal set: %s"), line);
4071
4072 signum -= 4;
4073
4074 if (digit & 1)
4075 sigaddset (sigs, signum + 1);
4076 if (digit & 2)
4077 sigaddset (sigs, signum + 2);
4078 if (digit & 4)
4079 sigaddset (sigs, signum + 3);
4080 if (digit & 8)
4081 sigaddset (sigs, signum + 4);
4082
4083 p++;
4084 }
4085}
4086
4087/* Find process PID's pending signals from /proc/pid/status and set
4088 SIGS to match. */
4089
4090void
4092 sigset_t *blocked, sigset_t *ignored)
4093{
4094 char buffer[PATH_MAX], fname[PATH_MAX];
4095
4096 sigemptyset (pending);
4097 sigemptyset (blocked);
4098 sigemptyset (ignored);
4099 xsnprintf (fname, sizeof fname, "/proc/%d/status", pid);
4100 gdb_file_up procfile = gdb_fopen_cloexec (fname, "r");
4101 if (procfile == NULL)
4102 error (_("Could not open %s"), fname);
4103
4104 while (fgets (buffer, PATH_MAX, procfile.get ()) != NULL)
4105 {
4106 /* Normal queued signals are on the SigPnd line in the status
4107 file. However, 2.6 kernels also have a "shared" pending
4108 queue for delivering signals to a thread group, so check for
4109 a ShdPnd line also.
4110
4111 Unfortunately some Red Hat kernels include the shared pending
4112 queue but not the ShdPnd status field. */
4113
4114 if (startswith (buffer, "SigPnd:\t"))
4115 add_line_to_sigset (buffer + 8, pending);
4116 else if (startswith (buffer, "ShdPnd:\t"))
4117 add_line_to_sigset (buffer + 8, pending);
4118 else if (startswith (buffer, "SigBlk:\t"))
4119 add_line_to_sigset (buffer + 8, blocked);
4120 else if (startswith (buffer, "SigIgn:\t"))
4121 add_line_to_sigset (buffer + 8, ignored);
4122 }
4123}
4124
4125static enum target_xfer_status
4127 const char *annex, gdb_byte *readbuf,
4128 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
4129 ULONGEST *xfered_len)
4130{
4131 gdb_assert (object == TARGET_OBJECT_OSDATA);
4132
4133 *xfered_len = linux_common_xfer_osdata (annex, readbuf, offset, len);
4134 if (*xfered_len == 0)
4135 return TARGET_XFER_EOF;
4136 else
4137 return TARGET_XFER_OK;
4138}
4139
4140std::vector<static_tracepoint_marker>
4142{
4143 char s[IPA_CMD_BUF_SIZE];
4144 int pid = inferior_ptid.pid ();
4145 std::vector<static_tracepoint_marker> markers;
4146 const char *p = s;
4147 ptid_t ptid = ptid_t (pid, 0);
4149
4150 /* Pause all */
4151 target_stop (ptid);
4152
4153 strcpy (s, "qTfSTM");
4154 agent_run_command (pid, s, strlen (s) + 1);
4155
4156 /* Unpause all. */
4157 SCOPE_EXIT { target_continue_no_signal (ptid); };
4158
4159 while (*p++ == 'm')
4160 {
4161 do
4162 {
4164
4165 if (strid == NULL || marker.str_id == strid)
4166 markers.push_back (std::move (marker));
4167 }
4168 while (*p++ == ','); /* comma-separated list */
4169
4170 strcpy (s, "qTsSTM");
4171 agent_run_command (pid, s, strlen (s) + 1);
4172 p = s;
4173 }
4174
4175 return markers;
4176}
4177
4178/* target_can_async_p implementation. */
4179
4180bool
4182{
4183 /* This flag should be checked in the common target.c code. */
4184 gdb_assert (target_async_permitted);
4185
4186 /* Otherwise, this targets is always able to support async mode. */
4187 return true;
4188}
4189
4190bool
4192{
4193 return true;
4194}
4195
4196/* to_always_non_stop_p implementation. */
4197
4198bool
4200{
4201 return true;
4202}
4203
4204bool
4206{
4207 return true;
4208}
4209
4210bool
4215
4216/* SIGCHLD handler that serves two purposes: In non-stop/async mode,
4217 so we notice when any child changes state, and notify the
4218 event-loop; it allows us to use sigsuspend in linux_nat_wait_1
4219 above to wait for the arrival of a SIGCHLD. */
4220
4221static void
4223{
4224 int old_errno = errno;
4225
4226 if (debug_linux_nat)
4227 gdb_stdlog->write_async_safe ("sigchld\n", sizeof ("sigchld\n") - 1);
4228
4229 if (signo == SIGCHLD)
4230 {
4231 /* Let the event loop know that there are events to handle. */
4233 }
4234
4235 errno = old_errno;
4236}
4237
4238/* Callback registered with the target events file descriptor. */
4239
4240static void
4241handle_target_event (int error, gdb_client_data client_data)
4242{
4244}
4245
4246/* target_async implementation. */
4247
4248void
4250{
4251 if (enable == is_async_p ())
4252 return;
4253
4254 /* Block child signals while we create/destroy the pipe, as their
4255 handler writes to it. */
4256 gdb::block_signals blocker;
4257
4258 if (enable)
4259 {
4260 if (!async_file_open ())
4261 internal_error ("creating event pipe failed.");
4262
4263 add_file_handler (async_wait_fd (), handle_target_event, NULL,
4264 "linux-nat");
4265
4266 /* There may be pending events to handle. Tell the event loop
4267 to poll them. */
4268 async_file_mark ();
4269 }
4270 else
4271 {
4272 delete_file_handler (async_wait_fd ());
4274 }
4275}
4276
4277/* Stop an LWP, and push a GDB_SIGNAL_0 stop status if no other
4278 event came out. */
4279
4280static int
4282{
4283 if (!lwp->stopped)
4284 {
4285 linux_nat_debug_printf ("running -> suspending %s",
4286 lwp->ptid.to_string ().c_str ());
4287
4288
4289 if (lwp->last_resume_kind == resume_stop)
4290 {
4291 linux_nat_debug_printf ("already stopping LWP %ld at GDB's request",
4292 lwp->ptid.lwp ());
4293 return 0;
4294 }
4295
4296 stop_callback (lwp);
4298 }
4299 else
4300 {
4301 /* Already known to be stopped; do nothing. */
4302
4303 if (debug_linux_nat)
4304 {
4306 linux_nat_debug_printf ("already stopped/stop_requested %s",
4307 lwp->ptid.to_string ().c_str ());
4308 else
4309 linux_nat_debug_printf ("already stopped/no stop_requested yet %s",
4310 lwp->ptid.to_string ().c_str ());
4311 }
4312 }
4313 return 0;
4314}
4315
4316void
4322
4323/* When requests are passed down from the linux-nat layer to the
4324 single threaded inf-ptrace layer, ptids of (lwpid,0,0) form are
4325 used. The address space pointer is stored in the inferior object,
4326 but the common code that is passed such ptid can't tell whether
4327 lwpid is a "main" process id or not (it assumes so). We reverse
4328 look up the "main" process id from the lwp here. */
4329
4330struct address_space *
4332{
4333 struct lwp_info *lwp;
4334 struct inferior *inf;
4335 int pid;
4336
4337 if (ptid.lwp () == 0)
4338 {
4339 /* An (lwpid,0,0) ptid. Look up the lwp object to get at the
4340 tgid. */
4341 lwp = find_lwp_pid (ptid);
4342 pid = lwp->ptid.pid ();
4343 }
4344 else
4345 {
4346 /* A (pid,lwpid,0) ptid. */
4347 pid = ptid.pid ();
4348 }
4349
4350 inf = find_inferior_pid (this, pid);
4351 gdb_assert (inf != NULL);
4352 return inf->aspace;
4353}
4354
4355/* Return the cached value of the processor core for thread PTID. */
4356
4357int
4359{
4360 struct lwp_info *info = find_lwp_pid (ptid);
4361
4362 if (info)
4363 return info->core;
4364 return -1;
4365}
4366
4367/* Implementation of to_filesystem_is_local. */
4368
4369bool
4371{
4372 struct inferior *inf = current_inferior ();
4373
4374 if (inf->fake_pid_p || inf->pid == 0)
4375 return true;
4376
4377 return linux_ns_same (inf->pid, LINUX_NS_MNT);
4378}
4379
4380/* Convert the INF argument passed to a to_fileio_* method
4381 to a process ID suitable for passing to its corresponding
4382 linux_mntns_* function. If INF is non-NULL then the
4383 caller is requesting the filesystem seen by INF. If INF
4384 is NULL then the caller is requesting the filesystem seen
4385 by the GDB. We fall back to GDB's filesystem in the case
4386 that INF is non-NULL but its PID is unknown. */
4387
4388static pid_t
4390{
4391 if (inf == NULL || inf->fake_pid_p || inf->pid == 0)
4392 return getpid ();
4393 else
4394 return inf->pid;
4395}
4396
4397/* Implementation of to_fileio_open. */
4398
4399int
4400linux_nat_target::fileio_open (struct inferior *inf, const char *filename,
4401 int flags, int mode, int warn_if_slow,
4402 fileio_error *target_errno)
4403{
4404 int nat_flags;
4405 mode_t nat_mode;
4406 int fd;
4407
4408 if (fileio_to_host_openflags (flags, &nat_flags) == -1
4409 || fileio_to_host_mode (mode, &nat_mode) == -1)
4410 {
4411 *target_errno = FILEIO_EINVAL;
4412 return -1;
4413 }
4414
4416 filename, nat_flags, nat_mode);
4417 if (fd == -1)
4418 *target_errno = host_to_fileio_error (errno);
4419
4420 return fd;
4421}
4422
4423/* Implementation of to_fileio_readlink. */
4424
4425gdb::optional<std::string>
4426linux_nat_target::fileio_readlink (struct inferior *inf, const char *filename,
4427 fileio_error *target_errno)
4428{
4429 char buf[PATH_MAX];
4430 int len;
4431
4433 filename, buf, sizeof (buf));
4434 if (len < 0)
4435 {
4436 *target_errno = host_to_fileio_error (errno);
4437 return {};
4438 }
4439
4440 return std::string (buf, len);
4441}
4442
4443/* Implementation of to_fileio_unlink. */
4444
4445int
4446linux_nat_target::fileio_unlink (struct inferior *inf, const char *filename,
4447 fileio_error *target_errno)
4448{
4449 int ret;
4450
4452 filename);
4453 if (ret == -1)
4454 *target_errno = host_to_fileio_error (errno);
4455
4456 return ret;
4457}
4458
4459/* Implementation of the to_thread_events method. */
4460
4461void
4466
4468{
4469 /* We don't change the stratum; this target will sit at
4470 process_stratum and thread_db will set at thread_stratum. This
4471 is a little strange, since this is a multi-threaded-capable
4472 target, but we want to be on the stack below thread_db, and we
4473 also want to be used for single-threaded processes. */
4474}
4475
4476/* See linux-nat.h. */
4477
4478bool
4479linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo)
4480{
4481 int pid = get_ptrace_pid (ptid);
4482 return ptrace (PTRACE_GETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, siginfo) == 0;
4483}
4484
4485/* See nat/linux-nat.h. */
4486
4487ptid_t
4489{
4490 gdb_assert (inferior_ptid.lwp_p ());
4491 return inferior_ptid;
4492}
4493
4494void _initialize_linux_nat ();
4495void
4497{
4499 &debug_linux_nat, _("\
4500Set debugging of GNU/Linux native target."), _(" \
4501Show debugging of GNU/Linux native target."), _(" \
4502When on, print debug messages relating to the GNU/Linux native target."),
4503 nullptr,
4506
4507 add_setshow_boolean_cmd ("linux-namespaces", class_maintenance,
4509Set debugging of GNU/Linux namespaces module."), _("\
4510Show debugging of GNU/Linux namespaces module."), _("\
4511Enables printf debugging output."),
4512 NULL,
4513 NULL,
4515
4516 /* Install a SIGCHLD handler. */
4517 sigchld_action.sa_handler = sigchld_handler;
4518 sigemptyset (&sigchld_action.sa_mask);
4519 sigchld_action.sa_flags = SA_RESTART;
4520
4521 /* Make it the default. */
4522 sigaction (SIGCHLD, &sigchld_action, NULL);
4523
4524 /* Make sure we don't block SIGCHLD during a sigsuspend. */
4525 gdb_sigmask (SIG_SETMASK, NULL, &suspend_mask);
4526 sigdelset (&suspend_mask, SIGCHLD);
4527
4528 sigemptyset (&blocked_mask);
4529
4531}
4532
4533
4534/* FIXME: kettenis/2000-08-26: The stuff on this page is specific to
4535 the GNU/Linux Threads library and therefore doesn't really belong
4536 here. */
4537
4538/* NPTL reserves the first two RT signals, but does not provide any
4539 way for the debugger to query the signal numbers - fortunately
4540 they don't change. */
4542
4543/* See linux-nat.h. */
4544
4545unsigned int
4547{
4548 return sizeof (lin_thread_signals) / sizeof (lin_thread_signals[0]);
4549}
4550
4551/* See linux-nat.h. */
4552
4553int
4555{
4556 gdb_assert (i < lin_thread_get_thread_signal_num ());
4557 return lin_thread_signals[i];
4558}
void xfree(void *)
static void handle_target_event(gdb_client_data client_data)
struct gdbarch * target_gdbarch(void)
target_xfer_partial_ftype memory_xfer_auxv
int catch_syscall_enabled(void)
bool catching_syscall_number(int syscall_number)
int software_breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
int detach_breakpoints(ptid_t ptid)
void remove_breakpoints_inf(inferior *inf)
int hardware_breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
int breakpoint_inserted_here_p(const address_space *aspace, CORE_ADDR pc)
const target_info & info() const override
Definition inf-child.c:49
gdb::optional< std::string > fileio_readlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition linux-nat.c:4426
struct address_space * thread_address_space(ptid_t) override
Definition linux-nat.c:4331
void kill() override
Definition linux-nat.c:3566
void post_startup_inferior(ptid_t) override
Definition linux-nat.c:402
int core_of_thread(ptid_t ptid) override
Definition linux-nat.c:4358
bool always_non_stop_p() override
Definition linux-nat.c:4199
virtual void low_prepare_to_resume(struct lwp_info *)
Definition linux-nat.h:171
bool thread_alive(ptid_t ptid) override
Definition linux-nat.c:3750
bool supports_stopped_by_sw_breakpoint() override
Definition linux-nat.c:2668
void attach(const char *, int) override
Definition linux-nat.c:1063
void post_attach(int) override
Definition linux-nat.c:394
virtual bool low_status_is_event(int status)
Definition linux-nat.c:2344
~linux_nat_target() override=0
Definition linux-nat.c:390
void resume(ptid_t, int, enum gdb_signal) override
Definition linux-nat.c:1616
int insert_exec_catchpoint(int) override
Definition linux-nat.c:557
virtual void low_new_thread(struct lwp_info *)
Definition linux-nat.h:148
std::string pid_to_str(ptid_t) override
Definition linux-nat.c:3780
const char * pid_to_exec_file(int pid) override
Definition linux-nat.c:3800
bool can_async_p() override
Definition linux-nat.c:4181
int fileio_open(struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, fileio_error *target_errno) override
Definition linux-nat.c:4400
int fileio_unlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition linux-nat.c:4446
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
Definition linux-nat.c:3415
virtual void low_resume(ptid_t ptid, int step, enum gdb_signal sig)
Definition linux-nat.h:138
virtual void low_forget_process(pid_t pid)
Definition linux-nat.h:167
virtual void low_delete_thread(struct arch_lwp_info *lp)
Definition linux-nat.h:152
bool supports_stopped_by_hw_breakpoint() override
Definition linux-nat.c:2689
bool supports_disable_randomization() override
Definition linux-nat.c:4211
void detach(inferior *, int) override
Definition linux-nat.c:1399
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition linux-nat.c:3698
bool stopped_by_sw_breakpoint() override
Definition linux-nat.c:2656
virtual bool low_stopped_data_address(CORE_ADDR *addr_p)
Definition linux-nat.h:144
int insert_fork_catchpoint(int) override
Definition linux-nat.c:533
virtual void low_new_clone(struct lwp_info *parent, pid_t child_lwp)
Definition linux-nat.h:162
bool stopped_by_hw_breakpoint() override
Definition linux-nat.c:2677
bool stopped_by_watchpoint() override
Definition linux-nat.c:2320
virtual void low_new_fork(struct lwp_info *parent, pid_t child_pid)
Definition linux-nat.h:158
int remove_exec_catchpoint(int) override
Definition linux-nat.c:563
const char * thread_name(struct thread_info *) override
Definition linux-nat.c:3791
virtual bool low_stopped_by_watchpoint()
Definition linux-nat.h:141
void follow_fork(inferior *, ptid_t, target_waitkind, bool, bool) override
Definition linux-nat.c:438
int insert_vfork_catchpoint(int) override
Definition linux-nat.c:545
bool filesystem_is_local() override
Definition linux-nat.c:4370
int remove_fork_catchpoint(int) override
Definition linux-nat.c:539
void update_thread_list() override
Definition linux-nat.c:3760
void thread_events(int) override
Definition linux-nat.c:4462
bool supports_multi_process() override
Definition linux-nat.c:4205
int set_syscall_catchpoint(int pid, bool needed, int any_count, gdb::array_view< const int > syscall_counts) override
Definition linux-nat.c:569
std::vector< static_tracepoint_marker > static_tracepoint_markers_by_strid(const char *id) override
Definition linux-nat.c:4141
void create_inferior(const char *, const std::string &, char **, int) override
Definition linux-nat.c:972
void async(bool) override
Definition linux-nat.c:4249
int remove_vfork_catchpoint(int) override
Definition linux-nat.c:551
virtual bool low_siginfo_fixup(siginfo_t *ptrace, gdb_byte *inf, int direction)
Definition linux-nat.h:179
void mourn_inferior() override
Definition linux-nat.c:3597
bool stopped_data_address(CORE_ADDR *) override
Definition linux-nat.c:2330
bool supports_non_stop() override
Definition linux-nat.c:4191
void pass_signals(gdb::array_view< const unsigned char >) override
Definition linux-nat.c:709
DISABLE_COPY_AND_ASSIGN(proc_mem_file)
proc_mem_file(ptid_t ptid, int fd)
Definition linux-nat.c:3831
void follow_fork(inferior *child_inf, ptid_t child_ptid, target_waitkind fork_kind, bool follow_child, bool detach_on_fork) override
thread_info * find_thread(ptid_t ptid)
friend class regcache
Definition regcache.h:269
gdbarch * arch() const
Definition regcache.c:231
const address_space * aspace() const
Definition regcache.h:343
static bool is_ours()
Definition target.h:189
static void ours()
Definition target.c:1070
ptid_t ptid
Definition gdbthread.h:259
gdb_signal stop_signal() const
Definition gdbthread.h:424
bool has_pending_waitstatus() const
Definition gdbthread.h:394
struct target_waitstatus pending_follow
Definition gdbthread.h:516
const target_waitstatus & pending_waitstatus() const
Definition gdbthread.h:403
bool executing() const
Definition gdbthread.h:319
int stop_requested
Definition gdbthread.h:519
void set_stop_signal(gdb_signal sig)
Definition gdbthread.h:431
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
@ class_maintenance
Definition command.h:65
#define SEEK_SET
Definition defs.h:101
int check_quit_flag(void)
Definition extension.c:857
ssize_t read(int fd, void *buf, size_t count)
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1739
LONGEST gdbarch_get_syscall_number(struct gdbarch *gdbarch, thread_info *thread)
Definition gdbarch.c:4499
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
Definition gdbarch.c:2903
bool gdbarch_software_single_step_p(struct gdbarch *gdbarch)
Definition gdbarch.c:3288
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:336
void delete_thread(thread_info *thread)
Definition thread.c:527
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
Definition thread.c:908
void set_running(process_stratum_target *targ, ptid_t ptid, bool running)
Definition thread.c:891
void thread_change_ptid(process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid)
Definition thread.c:811
void delete_exited_threads(void)
Definition thread.c:753
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition gnu-nat.c:1789
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1791
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
unsigned dummy
Definition go32-nat.c:8
unsigned short selector
Definition go32-nat.c:1
target_waitstatus host_status_to_waitstatus(int hoststatus)
Definition inf-child.c:57
void inferior_event_handler(enum inferior_event_type event_type)
Definition inf-loop.c:37
pid_t get_ptrace_pid(ptid_t ptid)
Definition inf-ptrace.c:238
ptid_t inferior_ptid
Definition infcmd.c:74
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
Definition inferior.c:406
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
Definition inferior.c:389
struct inferior * current_inferior(void)
Definition inferior.c:55
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:821
static bool detach_fork
Definition infrun.c:185
bool disable_randomization
Definition infrun.c:197
int signal_pass_state(int signo)
Definition infrun.c:9097
void get_last_target_status(process_stratum_target **target, ptid_t *ptid, target_waitstatus *status)
Definition infrun.c:4621
int linux_fork_checkpointing_p(int pid)
Definition linux-fork.c:627
void linux_fork_killall(void)
Definition linux-fork.c:295
void add_fork(pid_t pid)
Definition linux-fork.c:119
void linux_fork_mourn_inferior(void)
Definition linux-fork.c:328
int forks_exist_p(void)
Definition linux-fork.c:92
struct fork_info * find_fork_pid(pid_t pid)
Definition linux-fork.c:178
void linux_fork_detach(int from_tty)
Definition linux-fork.c:364
int linux_ns_same(pid_t pid, enum linux_ns_type type)
ssize_t linux_mntns_readlink(pid_t pid, const char *filename, char *buf, size_t bufsiz)
bool debug_linux_namespaces
int linux_mntns_open_cloexec(pid_t pid, const char *filename, int flags, mode_t mode)
int linux_mntns_unlink(pid_t pid, const char *filename)
@ LINUX_NS_MNT
ptid_t ptid_of_lwp(struct lwp_info *lwp)
Definition linux-nat.c:277
static void detach_one_pid(int pid, int signo)
Definition linux-nat.c:1156
static void check_zombie_leaders(void)
Definition linux-nat.c:3028
void linux_stop_lwp(struct lwp_info *lwp)
Definition linux-nat.c:2204
#define O_LARGEFILE
Definition linux-nat.c:186
static int linux_handle_syscall_trap(struct lwp_info *lp, int stopping)
Definition linux-nat.c:1721
static int resume_stopped_resumed_lwps(struct lwp_info *lp, const ptid_t wait_ptid)
Definition linux-nat.c:3352
void linux_unstop_all_lwps(void)
Definition linux-nat.c:2225
int lin_thread_get_thread_signal(unsigned int i)
Definition linux-nat.c:4554
static int lwp_lwpid_htab_remove_pid(void **slot, void *info)
Definition linux-nat.c:743
static void purge_lwp_list(int pid)
Definition linux-nat.c:761
static void linux_nat_filter_event(int lwpid, int status)
Definition linux-nat.c:2780
static struct lwp_info * find_lwp_pid(ptid_t ptid)
Definition linux-nat.c:844
static void detach_one_lwp(struct lwp_info *lp, int *signo_p)
Definition linux-nat.c:1288
static int get_detach_signal(struct lwp_info *lp)
Definition linux-nat.c:1198
static void exit_lwp(struct lwp_info *lp)
Definition linux-nat.c:904
static int lwp_status_pending_p(struct lwp_info *lp)
Definition linux-nat.c:2510
static void kill_one_lwp(pid_t pid)
Definition linux-nat.c:3460
static void lwp_lwpid_htab_add_lwp(struct lwp_info *lp)
Definition linux-nat.c:619
static enum target_xfer_status linux_proc_xfer_memory_partial(int pid, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
Definition linux-nat.c:3977
std::unique_ptr< struct lwp_info, lwp_deleter > lwp_info_up
Definition linux-nat.c:433
static void sigchld_handler(int signo)
Definition linux-nat.c:4222
static bool is_leader(lwp_info *lp)
Definition linux-nat.c:253
static void lwp_list_add(struct lwp_info *lp)
Definition linux-nat.c:654
#define linux_nat_debug_printf(fmt,...)
Definition linux-nat.c:210
static int kill_callback(struct lwp_info *lp)
Definition linux-nat.c:3523
lwp_info_range all_lwps()
Definition linux-nat.c:638
void linux_proc_pending_signals(int pid, sigset_t *pending, sigset_t *blocked, sigset_t *ignored)
Definition linux-nat.c:4091
static int stop_callback(struct lwp_info *lp)
Definition linux-nat.c:2180
static void siginfo_fixup(siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
Definition linux-nat.c:3624
static ptid_t linux_nat_wait_1(ptid_t ptid, struct target_waitstatus *ourstatus, target_wait_flags target_options)
Definition linux-nat.c:3127
static int attach_proc_task_lwp_callback(ptid_t ptid)
Definition linux-nat.c:995
static int status_callback(struct lwp_info *lp)
Definition linux-nat.c:2428
static std::string pending_status_str(lwp_info *lp)
Definition linux-nat.c:261
bool linux_nat_get_siginfo(ptid_t ptid, siginfo_t *siginfo)
Definition linux-nat.c:4479
static int set_ignore_sigint(struct lwp_info *lp)
Definition linux-nat.c:2253
void _initialize_linux_nat()
Definition linux-nat.c:4496
static struct simple_pid_list * stopped_pids
Definition linux-nat.c:224
static int select_event_lwp_callback(struct lwp_info *lp, int *selector)
Definition linux-nat.c:2521
static int lwp_lwpid_htab_eq(const void *a, const void *b)
Definition linux-nat.c:600
static void add_to_pid_list(struct simple_pid_list **listp, int pid, int status)
Definition linux-nat.c:327
static void linux_resume_one_lwp_throw(struct lwp_info *lp, int step, enum gdb_signal signo)
Definition linux-nat.c:1455
ptid_t current_lwp_ptid(void)
Definition linux-nat.c:4488
static int resume_set_callback(struct lwp_info *lp)
Definition linux-nat.c:1608
static void maybe_clear_ignore_sigint(struct lwp_info *lp)
Definition linux-nat.c:2273
lwp_info_safe_range all_lwps_safe()
Definition linux-nat.c:646
static int check_stopped_by_watchpoint(struct lwp_info *lp)
Definition linux-nat.c:2302
static void open_proc_mem_file(ptid_t ptid)
Definition linux-nat.c:3886
static void resume_lwp(struct lwp_info *lp, int step, enum gdb_signal signo)
Definition linux-nat.c:1539
static struct lwp_info * add_initial_lwp(ptid_t ptid)
Definition linux-nat.c:781
static void wait_for_signal()
Definition linux-nat.c:2013
static int detach_callback(struct lwp_info *lp)
Definition linux-nat.c:1388
static enum target_xfer_status linux_nat_xfer_osdata(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
Definition linux-nat.c:4126
static void kill_unfollowed_fork_children(struct inferior *inf)
Definition linux-nat.c:3542
static int linux_nat_post_attach_wait(ptid_t ptid, int *signalled)
Definition linux-nat.c:918
static int kill_wait_callback(struct lwp_info *lp)
Definition linux-nat.c:3532
static void lwp_lwpid_htab_create(void)
Definition linux-nat.c:611
static pid_t linux_nat_fileio_pid_of(struct inferior *inf)
Definition linux-nat.c:4389
static void add_line_to_sigset(const char *line, sigset_t *sigs)
Definition linux-nat.c:4050
static int linux_handle_extended_wait(struct lwp_info *lp, int status)
Definition linux-nat.c:1836
static struct lwp_info * add_lwp(ptid_t ptid)
Definition linux-nat.c:802
static int wait_lwp(struct lwp_info *lp)
Definition linux-nat.c:2036
static int linux_nat_resume_callback(struct lwp_info *lp, struct lwp_info *except)
Definition linux-nat.c:1576
void lwp_set_arch_private_info(struct lwp_info *lwp, struct arch_lwp_info *info)
Definition linux-nat.c:285
static int linux_nat_has_pending_sigint(int pid)
Definition linux-nat.c:2237
static htab_t lwp_lwpid_htab
Definition linux-nat.c:583
static int select_singlestep_lwp_callback(struct lwp_info *lp)
Definition linux-nat.c:2498
static void linux_init_ptrace_procfs(pid_t pid, int attached)
Definition linux-nat.c:380
static void select_event_lwp(ptid_t filter, struct lwp_info **orig_lp, int *status)
Definition linux-nat.c:2697
struct arch_lwp_info * lwp_arch_private_info(struct lwp_info *lwp)
Definition linux-nat.c:294
static int count_events_callback(struct lwp_info *lp, int *count)
Definition linux-nat.c:2484
static sigset_t pass_mask
Definition linux-nat.c:704
static int pull_pid_from_list(struct simple_pid_list **listp, int pid, int *statusp)
Definition linux-nat.c:338
static void lwp_list_remove(struct lwp_info *lp)
Definition linux-nat.c:663
static int report_thread_events
Definition linux-nat.c:227
static int linux_nat_stop_lwp(struct lwp_info *lwp)
Definition linux-nat.c:4281
static bool debug_linux_nat
Definition linux-nat.c:196
static void linux_resume_one_lwp(struct lwp_info *lp, int step, enum gdb_signal signo)
Definition linux-nat.c:1523
static void restore_child_signals_mask(sigset_t *prev_mask)
Definition linux-nat.c:698
unsigned int lin_thread_get_thread_signal_num(void)
Definition linux-nat.c:4546
static std::unordered_map< int, proc_mem_file > proc_mem_file_map
Definition linux-nat.c:3868
static void delete_lwp(ptid_t ptid)
Definition linux-nat.c:820
static int linux_nat_ptrace_options(int attached)
Definition linux-nat.c:358
static int resume_clear_callback(struct lwp_info *lp)
Definition linux-nat.c:1600
struct lwp_info * iterate_over_lwps(ptid_t filter, gdb::function_view< iterate_over_lwps_ftype > callback)
Definition linux-nat.c:860
struct linux_nat_target * linux_target
Definition linux-nat.c:189
void linux_stop_and_wait_all_lwps(void)
Definition linux-nat.c:2212
static enum target_xfer_status linux_xfer_siginfo(ptid_t ptid, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
Definition linux-nat.c:3638
static int num_lwps(int pid)
Definition linux-nat.c:410
static void handle_target_event(int error, gdb_client_data client_data)
Definition linux-nat.c:4241
static ptid_t filter_exit_event(struct lwp_info *event_child, struct target_waitstatus *ourstatus)
Definition linux-nat.c:3108
enum tribool have_ptrace_getregset
Definition linux-nat.c:192
static int lin_thread_signals[]
Definition linux-nat.c:4541
static bool proc_mem_file_is_writable()
Definition linux-nat.c:4002
static void save_stop_reason(struct lwp_info *lp)
Definition linux-nat.c:2540
int lwp_is_stepping(struct lwp_info *lwp)
Definition linux-nat.c:318
static void close_proc_mem_file(pid_t pid)
Definition linux-nat.c:3873
static enum target_xfer_status linux_proc_xfer_memory_partial_fd(int fd, int pid, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
Definition linux-nat.c:3919
static int kill_lwp(int lwpid, int signo)
Definition linux-nat.c:1699
static int stop_wait_callback(struct lwp_info *lp)
Definition linux-nat.c:2352
#define LINUX_NAT_SCOPED_DEBUG_ENTER_EXIT
Definition linux-nat.c:215
static intrusive_list< lwp_info > lwp_list
Definition linux-nat.c:633
void linux_nat_switch_fork(ptid_t new_ptid)
Definition linux-nat.c:881
static hashval_t lwp_info_hash(const void *ap)
Definition linux-nat.c:588
static sigset_t suspend_mask
Definition linux-nat.c:673
static sigset_t blocked_mask
Definition linux-nat.c:676
static int resumed_callback(struct lwp_info *lp)
Definition linux-nat.c:2770
static int check_ptrace_stopped_lwp_gone(struct lwp_info *lp)
Definition linux-nat.c:1494
static void block_child_signals(sigset_t *prev_mask)
Definition linux-nat.c:685
static void kill_wait_one_lwp(pid_t pid)
Definition linux-nat.c:3493
static void show_debug_linux_nat(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition linux-nat.c:201
int lwp_is_stopped(struct lwp_info *lwp)
Definition linux-nat.c:302
static struct sigaction sigchld_action
Definition linux-nat.c:679
enum target_stop_reason lwp_stop_reason(struct lwp_info *lwp)
Definition linux-nat.c:310
lwp_info_range all_lwps()
Definition linux-nat.c:638
int thread_db_notice_clone(ptid_t parent, ptid_t child)
linux_nat_target * linux_target
Definition linux-nat.c:189
iterator_range< lwp_info_iterator > lwp_info_range
Definition linux-nat.h:288
basic_safe_range< lwp_info_range > lwp_info_safe_range
Definition linux-nat.h:289
LONGEST linux_common_xfer_osdata(const char *annex, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
int linux_common_core_of_thread(ptid_t ptid)
int linux_proc_pid_is_gone(pid_t pid)
const char * linux_proc_pid_to_exec_file(int pid)
void linux_proc_init_warnings()
int linux_proc_pid_is_trace_stopped_nowarn(pid_t pid)
int linux_proc_pid_is_zombie(pid_t pid)
void linux_proc_attach_tgid_threads(pid_t pid, linux_proc_attach_lwp_func attach_lwp)
const char * linux_proc_tid_get_name(ptid_t ptid)
int linux_proc_pid_is_stopped(pid_t pid)
int linux_is_extended_waitstatus(int wstat)
void linux_enable_event_reporting(pid_t pid, int options)
int linux_ptrace_get_extended_event(int wstat)
int linux_wstatus_maybe_breakpoint(int wstat)
void linux_ptrace_init_warnings(void)
void linux_disable_event_reporting(pid_t pid)
std::string linux_ptrace_attach_fail_reason_string(ptid_t ptid, int err)
std::string linux_ptrace_attach_fail_reason(pid_t pid)
#define PTRACE_O_TRACEEXEC
#define PTRACE_GETSIGINFO
#define USE_SIGTRAP_SIGINFO
#define PTRACE_O_TRACEFORK
#define PTRACE_TYPE_ARG3
#define GDB_ARCH_IS_TRAP_HWBKPT(X)
#define PTRACE_EVENT_VFORK_DONE
#define GDB_ARCH_IS_TRAP_BRKPT(X)
#define PTRACE_GETEVENTMSG
#define PTRACE_EVENT_FORK
#define PTRACE_EVENT_CLONE
#define __WALL
#define PTRACE_O_EXITKILL
#define PTRACE_SETSIGINFO
#define PTRACE_EVENT_VFORK
#define PTRACE_O_TRACEVFORK
#define PTRACE_EVENT_EXEC
#define PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEVFORKDONE
int my_waitpid(int pid, int *status, int flags)
std::string status_to_str(int status)
#define SYSCALL_SIGTRAP
Definition linux-nat.h:37
#define __SIGRTMIN
Definition linux-nat.h:31
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition regcache.c:1333
void registers_changed_ptid(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:497
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
Definition regcache.c:1377
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
void registers_changed(void)
Definition regcache.c:580
resume_kind
Definition resume.h:26
@ resume_step
Definition resume.h:31
@ resume_continue
Definition resume.h:28
@ resume_stop
Definition resume.h:34
#define enable()
Definition ser-go32.c:239
void create_inferior(const char *, const std::string &, char **, int) override
Definition inf-ptrace.c:75
void async_file_flush()
Definition inf-ptrace.h:83
void async_file_mark()
Definition inf-ptrace.h:85
void detach_success(inferior *inf)
Definition inf-ptrace.c:208
void async_file_close()
Definition inf-ptrace.h:81
int async_wait_fd() override
Definition inf-ptrace.h:66
bool is_async_p() override
Definition inf-ptrace.h:63
void mourn_inferior() override
Definition inf-ptrace.c:115
void attach(const char *, int) override
Definition inf-ptrace.c:132
bool async_file_open()
Definition inf-ptrace.h:79
static void async_file_mark_if_open()
Definition inf-ptrace.h:71
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition inf-ptrace.c:424
Definition gnu-nat.c:153
pid_t pid
Definition gnu-nat.c:165
void operator()(struct lwp_info *lwp) const
Definition linux-nat.c:425
ptid_t ptid
Definition linux-nat.h:211
struct target_waitstatus waitstatus
Definition linux-nat.h:269
int resumed
Definition linux-nat.h:230
CORE_ADDR stop_pc
Definition linux-nat.h:245
CORE_ADDR stopped_data_address
Definition linux-nat.h:260
int signalled
Definition linux-nat.h:219
int stopped
Definition linux-nat.h:222
target_stop_reason stop_reason
Definition linux-nat.h:252
int must_set_ptrace_flags
Definition linux-nat.h:215
int status
Definition linux-nat.h:238
int stopped_data_address_p
Definition linux-nat.h:259
int ignore_sigint
Definition linux-nat.h:263
resume_kind last_resume_kind
Definition linux-nat.h:233
struct arch_lwp_info * arch_private
Definition linux-nat.h:282
lwp_info(ptid_t ptid)
Definition linux-nat.h:201
enum target_waitkind syscall_state
Definition linux-nat.h:276
struct simple_pid_list * next
Definition linux-nat.c:222
virtual gdb::array_view< const_gdb_byte > virtual thread_info_to_thread_handle(struct thread_info *) TARGET_DEFAULT_RETURN(gdb voi stop)(ptid_t) TARGET_DEFAULT_IGNORE()
Definition target.h:689
target_waitstatus & set_spurious()
Definition waitstatus.h:300
target_waitstatus & set_syscall_return(int syscall_number)
Definition waitstatus.h:292
target_waitstatus & set_no_resumed()
Definition waitstatus.h:321
target_waitstatus & set_vfork_done()
Definition waitstatus.h:277
target_waitstatus & set_forked(ptid_t child_ptid)
Definition waitstatus.h:253
target_waitstatus & set_execd(gdb::unique_xmalloc_ptr< char > execd_pathname)
Definition waitstatus.h:269
target_waitstatus & set_stopped(gdb_signal sig)
Definition waitstatus.h:230
enum gdb_signal sig
Definition waitstatus.h:414
target_waitstatus & set_vforked(ptid_t child_ptid)
Definition waitstatus.h:261
target_waitstatus & set_thread_exited(int exit_status)
Definition waitstatus.h:335
target_waitstatus & set_syscall_entry(int syscall_number)
Definition waitstatus.h:284
target_waitstatus & set_ignore()
Definition waitstatus.h:307
target_waitkind kind() const
Definition waitstatus.h:345
std::string to_string() const
Definition waitstatus.c:26
target_waitstatus & set_thread_created()
Definition waitstatus.h:328
Definition value.h:130
void target_announce_detach(int from_tty)
Definition target.c:3622
bool target_is_async_p()
Definition target.c:402
void target_async(bool enable)
Definition target.c:4337
bool target_async_permitted
Definition target.c:4356
bool target_can_async_p()
Definition target.c:384
gdbarch * target_thread_architecture(ptid_t ptid)
Definition target.c:434
void target_stop(ptid_t ptid)
Definition target.c:3782
std::string target_options_to_string(target_wait_flags target_options)
Definition target.c:3912
bool target_is_non_stop_p()
Definition target.c:4394
std::string normal_pid_to_str(ptid_t ptid)
Definition target.c:3693
void target_continue_no_signal(ptid_t ptid)
Definition target.c:3870
void target_pass_ctrlc(void)
Definition target.c:3812
void target_mourn_inferior(ptid_t ptid)
Definition target.c:2758
@ INF_REG_EVENT
Definition target.h:134
target_xfer_status
Definition target.h:219
@ TARGET_XFER_E_IO
Definition target.h:232
@ TARGET_XFER_EOF
Definition target.h:224
@ TARGET_XFER_OK
Definition target.h:221
target_object
Definition target.h:143
@ TARGET_OBJECT_AUXV
Definition target.h:162
@ TARGET_OBJECT_OSDATA
Definition target.h:184
@ TARGET_OBJECT_SIGNAL_INFO
Definition target.h:187
@ TARGET_OBJECT_MEMORY
Definition target.h:147
void parse_static_tracepoint_marker_definition(const char *line, const char **pp, static_tracepoint_marker *marker)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
void perror_warning_with_name(const char *string)
Definition utils.c:616
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
int parse_pid_to_attach(const char *args)
Definition utils.c:3331
#define gdb_stdlog
Definition utils.h:190
@ TARGET_WNOHANG
Definition wait.h:32
target_waitkind
Definition waitstatus.h:30
@ TARGET_WAITKIND_NO_RESUMED
Definition waitstatus.h:96
@ TARGET_WAITKIND_SIGNALLED
Definition waitstatus.h:40
@ TARGET_WAITKIND_STOPPED
Definition waitstatus.h:36
@ TARGET_WAITKIND_EXITED
Definition waitstatus.h:32
@ TARGET_WAITKIND_SYSCALL_RETURN
Definition waitstatus.h:73
@ TARGET_WAITKIND_SYSCALL_ENTRY
Definition waitstatus.h:72
@ TARGET_WAITKIND_FORKED
Definition waitstatus.h:49
@ TARGET_WAITKIND_VFORKED
Definition waitstatus.h:53
@ TARGET_WAITKIND_IGNORE
Definition waitstatus.h:89
target_stop_reason
Definition waitstatus.h:428
@ TARGET_STOPPED_BY_SW_BREAKPOINT
Definition waitstatus.h:434
@ TARGET_STOPPED_BY_WATCHPOINT
Definition waitstatus.h:440
@ TARGET_STOPPED_BY_HW_BREAKPOINT
Definition waitstatus.h:437
@ TARGET_STOPPED_BY_NO_REASON
Definition waitstatus.h:431