GDB (xrefs)
/tmp/gdb-8.1/gdb/linux-fork.c
Go to the documentation of this file.
1 /* GNU/Linux native-dependent code for debugging multiple forks.
2 
3  Copyright (C) 2005-2018 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 "arch-utils.h"
22 #include "inferior.h"
23 #include "infrun.h"
24 #include "regcache.h"
25 #include "gdbcmd.h"
26 #include "infcall.h"
27 #include "objfiles.h"
28 #include "linux-fork.h"
29 #include "linux-nat.h"
30 #include "gdbthread.h"
31 #include "source.h"
32 
33 #include "nat/gdb_ptrace.h"
34 #include "gdb_wait.h"
35 #include <dirent.h>
36 #include <ctype.h>
37 
39 static int highest_fork_num;
40 
41 /* Fork list data structure: */
42 struct fork_info
43 {
44  struct fork_info *next;
47  int num; /* Convenient handle (GDB fork id). */
48  struct regcache *savedregs; /* Convenient for info fork, saves
49  having to actually switch contexts. */
50  int clobber_regs; /* True if we should restore saved regs. */
51  off_t *filepos; /* Set of open file descriptors' offsets. */
52  int maxfd;
53 };
54 
55 /* Fork list methods: */
56 
57 int
59 {
60  return (fork_list != NULL);
61 }
62 
63 /* Return the last fork in the list. */
64 
65 static struct fork_info *
67 {
68  struct fork_info *last;
69 
70  if (fork_list == NULL)
71  return NULL;
72 
73  for (last = fork_list; last->next != NULL; last = last->next)
74  ;
75  return last;
76 }
77 
78 /* Add a fork to the internal fork list. */
79 
80 struct fork_info *
81 add_fork (pid_t pid)
82 {
83  struct fork_info *fp;
84 
85  if (fork_list == NULL && pid != ptid_get_pid (inferior_ptid))
86  {
87  /* Special case -- if this is the first fork in the list
88  (the list is hitherto empty), and if this new fork is
89  NOT the current inferior_ptid, then add inferior_ptid
90  first, as a special zeroeth fork id. */
91  highest_fork_num = -1;
92  add_fork (ptid_get_pid (inferior_ptid)); /* safe recursion */
93  }
94 
95  fp = XCNEW (struct fork_info);
96  fp->ptid = ptid_build (pid, pid, 0);
97  fp->num = ++highest_fork_num;
98 
99  if (fork_list == NULL)
100  fork_list = fp;
101  else
102  {
103  struct fork_info *last = find_last_fork ();
104 
105  last->next = fp;
106  }
107 
108  return fp;
109 }
110 
111 static void
112 free_fork (struct fork_info *fp)
113 {
114  /* Notes on step-resume breakpoints: since this is a concern for
115  threads, let's convince ourselves that it's not a concern for
116  forks. There are two ways for a fork_info to be created. First,
117  by the checkpoint command, in which case we're at a gdb prompt
118  and there can't be any step-resume breakpoint. Second, by a fork
119  in the user program, in which case we *may* have stepped into the
120  fork call, but regardless of whether we follow the parent or the
121  child, we will return to the same place and the step-resume
122  breakpoint, if any, will take care of itself as usual. And
123  unlike threads, we do not save a private copy of the step-resume
124  breakpoint -- so we're OK. */
125 
126  if (fp)
127  {
128  if (fp->savedregs)
129  delete fp->savedregs;
130  if (fp->filepos)
131  xfree (fp->filepos);
132  xfree (fp);
133  }
134 }
135 
136 static void
138 {
139  struct fork_info *fp, *fpprev;
140 
141  fpprev = NULL;
142 
144 
145  for (fp = fork_list; fp; fpprev = fp, fp = fp->next)
146  if (ptid_equal (fp->ptid, ptid))
147  break;
148 
149  if (!fp)
150  return;
151 
152  if (fpprev)
153  fpprev->next = fp->next;
154  else
155  fork_list = fp->next;
156 
157  free_fork (fp);
158 
159  /* Special case: if there is now only one process in the list,
160  and if it is (hopefully!) the current inferior_ptid, then
161  remove it, leaving the list empty -- we're now down to the
162  default case of debugging a single process. */
163  if (fork_list != NULL && fork_list->next == NULL &&
165  {
166  /* Last fork -- delete from list and handle as solo process
167  (should be a safe recursion). */
169  }
170 }
171 
172 /* Find a fork_info by matching PTID. */
173 static struct fork_info *
175 {
176  struct fork_info *fp;
177 
178  for (fp = fork_list; fp; fp = fp->next)
179  if (ptid_equal (fp->ptid, ptid))
180  return fp;
181 
182  return NULL;
183 }
184 
185 /* Find a fork_info by matching ID. */
186 static struct fork_info *
188 {
189  struct fork_info *fp;
190 
191  for (fp = fork_list; fp; fp = fp->next)
192  if (fp->num == num)
193  return fp;
194 
195  return NULL;
196 }
197 
198 /* Find a fork_info by matching pid. */
199 extern struct fork_info *
201 {
202  struct fork_info *fp;
203 
204  for (fp = fork_list; fp; fp = fp->next)
205  if (pid == ptid_get_pid (fp->ptid))
206  return fp;
207 
208  return NULL;
209 }
210 
211 static ptid_t
213 {
214  struct fork_info *fork = find_fork_id (num);
215  if (fork)
216  return fork->ptid;
217  else
218  return pid_to_ptid (-1);
219 }
220 
221 static void
223 {
224  struct fork_info *fp, *fpnext;
225 
226  if (!fork_list)
227  return;
228 
229  for (fp = fork_list; fp; fp = fpnext)
230  {
231  fpnext = fp->next;
232  free_fork (fp);
233  }
234 
235  fork_list = NULL;
236 }
237 
238 /* Fork list <-> gdb interface. */
239 
240 /* Utility function for fork_load/fork_save.
241  Calls lseek in the (current) inferior process. */
242 
243 static off_t
244 call_lseek (int fd, off_t offset, int whence)
245 {
246  char exp[80];
247 
248  snprintf (&exp[0], sizeof (exp), "(long) lseek (%d, %ld, %d)",
249  fd, (long) offset, whence);
250  return (off_t) parse_and_eval_long (&exp[0]);
251 }
252 
253 /* Load infrun state for the fork PTID. */
254 
255 static void
257 {
258  extern void nullify_last_target_wait_ptid ();
259  int i;
260 
262 
263  if (fp->savedregs && fp->clobber_regs)
265 
268 
271 
272  /* Now restore the file positions of open file descriptors. */
273  if (fp->filepos)
274  {
275  for (i = 0; i <= fp->maxfd; i++)
276  if (fp->filepos[i] != (off_t) -1)
277  call_lseek (i, fp->filepos[i], SEEK_SET);
278  /* NOTE: I can get away with using SEEK_SET and SEEK_CUR because
279  this is native-only. If it ever has to be cross, we'll have
280  to rethink this. */
281  }
282 }
283 
284 /* Save infrun state for the fork PTID.
285  Exported for use by linux child_follow_fork. */
286 
287 static void
289 {
290  char path[PATH_MAX];
291  struct dirent *de;
292  DIR *d;
293 
294  if (fp->savedregs)
295  delete fp->savedregs;
296 
298  fp->clobber_regs = clobber_regs;
299 
300  if (clobber_regs)
301  {
302  /* Now save the 'state' (file position) of all open file descriptors.
303  Unfortunately fork does not take care of that for us... */
304  snprintf (path, PATH_MAX, "/proc/%ld/fd",
305  (long) ptid_get_pid (fp->ptid));
306  if ((d = opendir (path)) != NULL)
307  {
308  long tmp;
309 
310  fp->maxfd = 0;
311  while ((de = readdir (d)) != NULL)
312  {
313  /* Count open file descriptors (actually find highest
314  numbered). */
315  tmp = strtol (&de->d_name[0], NULL, 10);
316  if (fp->maxfd < tmp)
317  fp->maxfd = tmp;
318  }
319  /* Allocate array of file positions. */
320  fp->filepos = XRESIZEVEC (off_t, fp->filepos, fp->maxfd + 1);
321 
322  /* Initialize to -1 (invalid). */
323  for (tmp = 0; tmp <= fp->maxfd; tmp++)
324  fp->filepos[tmp] = -1;
325 
326  /* Now find actual file positions. */
327  rewinddir (d);
328  while ((de = readdir (d)) != NULL)
329  if (isdigit (de->d_name[0]))
330  {
331  tmp = strtol (&de->d_name[0], NULL, 10);
332  fp->filepos[tmp] = call_lseek (tmp, 0, SEEK_CUR);
333  }
334  closedir (d);
335  }
336  }
337 }
338 
339 /* Kill 'em all, let God sort 'em out... */
340 
341 void
343 {
344  /* Walk list and kill every pid. No need to treat the
345  current inferior_ptid as special (we do not return a
346  status for it) -- however any process may be a child
347  or a parent, so may get a SIGCHLD from a previously
348  killed child. Wait them all out. */
349  struct fork_info *fp;
350  pid_t pid, ret;
351  int status;
352 
353  for (fp = fork_list; fp; fp = fp->next)
354  {
355  pid = ptid_get_pid (fp->ptid);
356  do {
357  /* Use SIGKILL instead of PTRACE_KILL because the former works even
358  if the thread is running, while the later doesn't. */
359  kill (pid, SIGKILL);
360  ret = waitpid (pid, &status, 0);
361  /* We might get a SIGCHLD instead of an exit status. This is
362  aggravated by the first kill above - a child has just
363  died. MVS comment cut-and-pasted from linux-nat. */
364  } while (ret == pid && WIFSTOPPED (status));
365  }
366  init_fork_list (); /* Clear list, prepare to start fresh. */
367 }
368 
369 /* The current inferior_ptid has exited, but there are other viable
370  forks to debug. Delete the exiting one and context-switch to the
371  first available. */
372 
373 void
375 {
376  struct fork_info *last;
377  int status;
378 
379  /* Wait just one more time to collect the inferior's exit status.
380  Do not check whether this succeeds though, since we may be
381  dealing with a process that we attached to. Such a process will
382  only report its exit status to its original parent. */
383  waitpid (ptid_get_pid (inferior_ptid), &status, 0);
384 
385  /* OK, presumably inferior_ptid is the one who has exited.
386  We need to delete that one from the fork_list, and switch
387  to the next available fork. */
389 
390  /* There should still be a fork - if there's only one left,
391  delete_fork won't remove it, because we haven't updated
392  inferior_ptid yet. */
394 
395  last = find_last_fork ();
396  fork_load_infrun_state (last);
397  printf_filtered (_("[Switching to %s]\n"),
399 
400  /* If there's only one fork, switch back to non-fork mode. */
401  if (fork_list->next == NULL)
403 }
404 
405 /* The current inferior_ptid is being detached, but there are other
406  viable forks to debug. Detach and delete it and context-switch to
407  the first available. */
408 
409 void
410 linux_fork_detach (const char *args, int from_tty)
411 {
412  /* OK, inferior_ptid is the one we are detaching from. We need to
413  delete it from the fork_list, and switch to the next available
414  fork. */
415 
416  if (ptrace (PTRACE_DETACH, ptid_get_pid (inferior_ptid), 0, 0))
417  error (_("Unable to detach %s"), target_pid_to_str (inferior_ptid));
418 
420 
421  /* There should still be a fork - if there's only one left,
422  delete_fork won't remove it, because we haven't updated
423  inferior_ptid yet. */
425 
427 
428  if (from_tty)
429  printf_filtered (_("[Switching to %s]\n"),
431 
432  /* If there's only one fork, switch back to non-fork mode. */
433  if (fork_list->next == NULL)
435 }
436 
437 static void
439 {
440  struct fork_info *oldfp = (struct fork_info *) fp;
441 
442  if (oldfp)
443  {
444  /* Switch back to inferior_ptid. */
446  fork_load_infrun_state (oldfp);
448  }
449 }
450 
451 static int
453 {
454  struct objfile *waitpid_objf;
455  struct value *waitpid_fn = NULL;
456  struct value *argv[4], *retv;
457  struct gdbarch *gdbarch = get_current_arch ();
458  struct fork_info *oldfp = NULL, *newfp = NULL;
459  struct cleanup *old_cleanup;
460  int ret = -1;
461 
462  if (!ptid_equal (pptid, inferior_ptid))
463  {
464  /* Switch to pptid. */
465  oldfp = find_fork_ptid (inferior_ptid);
466  gdb_assert (oldfp != NULL);
467  newfp = find_fork_ptid (pptid);
468  gdb_assert (newfp != NULL);
469  fork_save_infrun_state (oldfp, 1);
471  fork_load_infrun_state (newfp);
473  }
474 
475  old_cleanup = make_cleanup (inferior_call_waitpid_cleanup, oldfp);
476 
477  /* Get the waitpid_fn. */
478  if (lookup_minimal_symbol ("waitpid", NULL, NULL).minsym != NULL)
479  waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);
480  if (!waitpid_fn
481  && lookup_minimal_symbol ("_waitpid", NULL, NULL).minsym != NULL)
482  waitpid_fn = find_function_in_inferior ("_waitpid", &waitpid_objf);
483  if (!waitpid_fn)
484  goto out;
485 
486  /* Get the argv. */
487  argv[0] = value_from_longest (builtin_type (gdbarch)->builtin_int, pid);
488  argv[1] = value_from_pointer (builtin_type (gdbarch)->builtin_data_ptr, 0);
489  argv[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
490  argv[3] = 0;
491 
492  retv = call_function_by_hand (waitpid_fn, NULL, 3, argv);
493  if (value_as_long (retv) < 0)
494  goto out;
495 
496  ret = 0;
497 
498 out:
499  do_cleanups (old_cleanup);
500  return ret;
501 }
502 
503 /* Fork list <-> user interface. */
504 
505 static void
506 delete_checkpoint_command (const char *args, int from_tty)
507 {
508  ptid_t ptid, pptid;
509  struct fork_info *fi;
510 
511  if (!args || !*args)
512  error (_("Requires argument (checkpoint id to delete)"));
513 
516  error (_("No such checkpoint id, %s"), args);
517 
519  error (_("\
520 Please switch to another checkpoint before deleting the current one"));
521 
522  if (ptrace (PTRACE_KILL, ptid_get_pid (ptid), 0, 0))
523  error (_("Unable to kill pid %s"), target_pid_to_str (ptid));
524 
525  fi = find_fork_ptid (ptid);
526  gdb_assert (fi);
527  pptid = fi->parent_ptid;
528 
529  if (from_tty)
530  printf_filtered (_("Killed %s\n"), target_pid_to_str (ptid));
531 
532  delete_fork (ptid);
533 
534  /* If fi->parent_ptid is not a part of lwp but it's a part of checkpoint
535  list, waitpid the ptid.
536  If fi->parent_ptid is a part of lwp and it is stoped, waitpid the
537  ptid. */
538  if ((!find_thread_ptid (pptid) && find_fork_ptid (pptid))
539  || (find_thread_ptid (pptid) && is_stopped (pptid)))
540  {
541  if (inferior_call_waitpid (pptid, ptid_get_pid (ptid)))
542  warning (_("Unable to wait pid %s"), target_pid_to_str (ptid));
543  }
544 }
545 
546 static void
547 detach_checkpoint_command (const char *args, int from_tty)
548 {
549  ptid_t ptid;
550 
551  if (!args || !*args)
552  error (_("Requires argument (checkpoint id to detach)"));
553 
556  error (_("No such checkpoint id, %s"), args);
557 
559  error (_("\
560 Please switch to another checkpoint before detaching the current one"));
561 
562  if (ptrace (PTRACE_DETACH, ptid_get_pid (ptid), 0, 0))
563  error (_("Unable to detach %s"), target_pid_to_str (ptid));
564 
565  if (from_tty)
566  printf_filtered (_("Detached %s\n"), target_pid_to_str (ptid));
567 
568  delete_fork (ptid);
569 }
570 
571 /* Print information about currently known checkpoints. */
572 
573 static void
574 info_checkpoints_command (const char *arg, int from_tty)
575 {
576  struct gdbarch *gdbarch = get_current_arch ();
577  struct symtab_and_line sal;
578  struct fork_info *fp;
579  ULONGEST pc;
580  int requested = -1;
581  struct fork_info *printed = NULL;
582 
583  if (arg && *arg)
584  requested = (int) parse_and_eval_long (arg);
585 
586  for (fp = fork_list; fp; fp = fp->next)
587  {
588  if (requested > 0 && fp->num != requested)
589  continue;
590 
591  printed = fp;
592  if (ptid_equal (fp->ptid, inferior_ptid))
593  {
594  printf_filtered ("* ");
596  }
597  else
598  {
599  printf_filtered (" ");
600  pc = regcache_read_pc (fp->savedregs);
601  }
602  printf_filtered ("%d %s", fp->num, target_pid_to_str (fp->ptid));
603  if (fp->num == 0)
604  printf_filtered (_(" (main process)"));
605  printf_filtered (_(" at "));
607 
608  sal = find_pc_line (pc, 0);
609  if (sal.symtab)
610  printf_filtered (_(", file %s"),
612  if (sal.line)
613  printf_filtered (_(", line %d"), sal.line);
614  if (!sal.symtab && !sal.line)
615  {
616  struct bound_minimal_symbol msym;
617 
618  msym = lookup_minimal_symbol_by_pc (pc);
619  if (msym.minsym)
620  printf_filtered (", <%s>", MSYMBOL_LINKAGE_NAME (msym.minsym));
621  }
622 
623  putchar_filtered ('\n');
624  }
625  if (printed == NULL)
626  {
627  if (requested > 0)
628  printf_filtered (_("No checkpoint number %d.\n"), requested);
629  else
630  printf_filtered (_("No checkpoints.\n"));
631  }
632 }
633 
634 /* The PID of the process we're checkpointing. */
635 static int checkpointing_pid = 0;
636 
637 int
639 {
640  return (checkpointing_pid == pid);
641 }
642 
643 /* Callback for iterate over threads. Used to check whether
644  the current inferior is multi-threaded. Returns true as soon
645  as it sees the second thread of the current inferior. */
646 
647 static int
648 inf_has_multiple_thread_cb (struct thread_info *tp, void *data)
649 {
650  int *count_p = (int *) data;
651 
652  if (current_inferior ()->pid == ptid_get_pid (tp->ptid))
653  (*count_p)++;
654 
655  /* Stop the iteration if multiple threads have been detected. */
656  return *count_p > 1;
657 }
658 
659 /* Return true if the current inferior is multi-threaded. */
660 
661 static int
663 {
664  int count = 0;
665 
667  return (count > 1);
668 }
669 
670 static void
671 checkpoint_command (const char *args, int from_tty)
672 {
673  struct objfile *fork_objf;
674  struct gdbarch *gdbarch;
675  struct target_waitstatus last_target_waitstatus;
676  ptid_t last_target_ptid;
677  struct value *fork_fn = NULL, *ret;
678  struct fork_info *fp;
679  pid_t retpid;
680 
681  if (!target_has_execution)
682  error (_("The program is not being run."));
683 
684  /* Ensure that the inferior is not multithreaded. */
687  error (_("checkpoint: can't checkpoint multiple threads."));
688 
689  /* Make the inferior fork, record its (and gdb's) state. */
690 
691  if (lookup_minimal_symbol ("fork", NULL, NULL).minsym != NULL)
692  fork_fn = find_function_in_inferior ("fork", &fork_objf);
693  if (!fork_fn)
694  if (lookup_minimal_symbol ("_fork", NULL, NULL).minsym != NULL)
695  fork_fn = find_function_in_inferior ("fork", &fork_objf);
696  if (!fork_fn)
697  error (_("checkpoint: can't find fork function in inferior."));
698 
699  gdbarch = get_objfile_arch (fork_objf);
700  ret = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
701 
702  /* Tell linux-nat.c that we're checkpointing this inferior. */
703  {
704  scoped_restore save_pid
706 
707  ret = call_function_by_hand (fork_fn, NULL, 0, &ret);
708  }
709 
710  if (!ret) /* Probably can't happen. */
711  error (_("checkpoint: call_function_by_hand returned null."));
712 
713  retpid = value_as_long (ret);
714  get_last_target_status (&last_target_ptid, &last_target_waitstatus);
715 
716  fp = find_fork_pid (retpid);
717 
718  if (from_tty)
719  {
720  int parent_pid;
721 
722  printf_filtered (_("checkpoint %d: fork returned pid %ld.\n"),
723  fp != NULL ? fp->num : -1, (long) retpid);
724  if (info_verbose)
725  {
726  parent_pid = ptid_get_lwp (last_target_ptid);
727  if (parent_pid == 0)
728  parent_pid = ptid_get_pid (last_target_ptid);
729  printf_filtered (_(" gdb says parent = %ld.\n"),
730  (long) parent_pid);
731  }
732  }
733 
734  if (!fp)
735  error (_("Failed to find new fork"));
736  fork_save_infrun_state (fp, 1);
737  fp->parent_ptid = last_target_ptid;
738 }
739 
740 static void
741 linux_fork_context (struct fork_info *newfp, int from_tty)
742 {
743  /* Now we attempt to switch processes. */
744  struct fork_info *oldfp;
745 
746  gdb_assert (newfp != NULL);
747 
748  oldfp = find_fork_ptid (inferior_ptid);
749  gdb_assert (oldfp != NULL);
750 
751  fork_save_infrun_state (oldfp, 1);
753  fork_load_infrun_state (newfp);
755 
756  printf_filtered (_("Switching to %s\n"),
758 
760 }
761 
762 /* Switch inferior process (checkpoint) context, by checkpoint id. */
763 static void
764 restart_command (const char *args, int from_tty)
765 {
766  struct fork_info *fp;
767 
768  if (!args || !*args)
769  error (_("Requires argument (checkpoint id to restart)"));
770 
771  if ((fp = find_fork_id (parse_and_eval_long (args))) == NULL)
772  error (_("Not found: checkpoint id %s"), args);
773 
774  linux_fork_context (fp, from_tty);
775 }
776 
777 void
779 {
780  init_fork_list ();
781 
782  /* Checkpoint command: create a fork of the inferior process
783  and set it aside for later debugging. */
784 
785  add_com ("checkpoint", class_obscure, checkpoint_command, _("\
786 Fork a duplicate process (experimental)."));
787 
788  /* Restart command: restore the context of a specified checkpoint
789  process. */
790 
791  add_com ("restart", class_obscure, restart_command, _("\
792 restart <n>: restore program context from a checkpoint.\n\
793 Argument 'n' is checkpoint ID, as displayed by 'info checkpoints'."));
794 
795  /* Delete checkpoint command: kill the process and remove it from
796  the fork list. */
797 
799 Delete a checkpoint (experimental)."),
800  &deletelist);
801 
802  /* Detach checkpoint command: release the process to run independently,
803  and remove it from the fork list. */
804 
806 Detach from a checkpoint (experimental)."),
807  &detachlist);
808 
809  /* Info checkpoints command: list all forks/checkpoints
810  currently under gdb's control. */
811 
812  add_info ("checkpoints", info_checkpoints_command,
813  _("IDs of currently known checkpoints."));
814 }
void get_last_target_status(ptid_t *ptidp, struct target_waitstatus *status)
Definition: infrun.c:4037
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition: source.c:1168
struct thread_info * find_thread_ptid(ptid_t ptid)
Definition: thread.c:514
struct fork_info * next
Definition: linux-fork.c:44
struct frame_info * get_selected_frame(const char *message)
Definition: frame.c:1638
#define MSYMBOL_LINKAGE_NAME(symbol)
Definition: symtab.h:707
ptid_t ptid
Definition: linux-fork.c:45
int maxfd
Definition: linux-fork.c:52
void insert_breakpoints(void)
Definition: breakpoint.c:2845
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
int linux_fork_checkpointing_p(int pid)
Definition: linux-fork.c:638
void xfree(void *)
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:1824
LONGEST value_as_long(struct value *val)
Definition: value.c:2749
void warning(const char *fmt,...)
Definition: errors.c:26
struct cmd_list_element * add_info(const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:886
void linux_fork_killall(void)
Definition: linux-fork.c:342
struct regcache * savedregs
Definition: linux-fork.c:48
int pid
Definition: inferior.h:328
int info_verbose
Definition: top.c:1791
struct cmd_list_element * deletelist
Definition: cli-cmds.c:99
static ptid_t fork_id_to_ptid(int num)
Definition: linux-fork.c:212
void nullify_last_target_wait_ptid(void)
Definition: infrun.c:4044
void linux_fork_mourn_inferior(void)
Definition: linux-fork.c:374
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
static void checkpoint_command(const char *args, int from_tty)
Definition: linux-fork.c:671
#define _(String)
Definition: gdb_locale.h:35
static void fork_load_infrun_state(struct fork_info *fp)
Definition: linux-fork.c:256
struct regcache * get_current_regcache(void)
Definition: regcache.c:446
PTRACE_TYPE_RET ptrace()
void printf_filtered(const char *format,...)
Definition: utils.c:2045
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
static int highest_fork_num
Definition: linux-fork.c:39
ptid_t ptid_build(int pid, long lwp, long tid)
Definition: ptid.c:31
struct regcache * regcache_dup(struct regcache *src)
Definition: regcache.c:353
static void detach_checkpoint_command(const char *args, int from_tty)
Definition: linux-fork.c:547
static void delete_checkpoint_command(const char *args, int from_tty)
Definition: linux-fork.c:506
scoped_restore_tmpl< T > make_scoped_restore(T *var)
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition: thread.c:551
int is_stopped(ptid_t ptid)
Definition: thread.c:963
static struct fork_info * find_fork_ptid(ptid_t ptid)
Definition: linux-fork.c:174
void _initialize_linux_fork(void)
Definition: linux-fork.c:778
int clobber_regs
Definition: linux-fork.c:50
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
Definition: symtab.c:3288
struct fork_info * add_fork(pid_t pid)
Definition: linux-fork.c:81
void linux_fork_detach(const char *args, int from_tty)
Definition: linux-fork.c:410
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
Definition: valops.c:127
Definition: ptid.h:35
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1811
ptid_t pid_to_ptid(int pid)
Definition: ptid.c:39
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:116
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
Definition: objfiles.c:445
static struct fork_info * find_last_fork(void)
Definition: linux-fork.c:66
static off_t call_lseek(int fd, off_t offset, int whence)
Definition: linux-fork.c:244
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:798
void regcache_cpy(struct regcache *dst, struct regcache *src)
Definition: regcache.c:342
struct value * value_from_longest(struct type *type, LONGEST num)
Definition: value.c:3534
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition: gnu-nat.c:1822
static int inf_has_multiple_thread_cb(struct thread_info *tp, void *data)
Definition: linux-fork.c:648
struct fork_info * fork_list
Definition: linux-fork.c:38
ptid_t ptid
Definition: gdbthread.h:219
#define target_has_execution
Definition: target.h:1756
int putchar_filtered(int c)
Definition: utils.c:1829
int forks_exist_p(void)
Definition: linux-fork.c:58
static void info_checkpoints_command(const char *arg, int from_tty)
Definition: linux-fork.c:574
#define XRESIZEVEC(T, P, N)
Definition: poison.h:169
struct symtab * symtab
Definition: symtab.h:1751
long ptid_get_lwp(const ptid_t &ptid)
Definition: ptid.c:55
#define gdb_assert(expr)
Definition: gdb_assert.h:32
Definition: value.c:169
static void init_fork_list(void)
Definition: linux-fork.c:222
void print_stack_frame(struct frame_info *, int print_level, enum print_what print_what, int set_current_sal)
Definition: stack.c:165
#define WIFSTOPPED(w)
Definition: gdb_wait.h:62
struct cmd_list_element * detachlist
Definition: cli-cmds.c:103
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
Definition: value.c:3560
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
Definition: minsyms.c:928
static int inf_has_multiple_threads(void)
Definition: linux-fork.c:662
#define SEEK_SET
Definition: defs.h:93
#define XCNEW(T)
Definition: poison.h:121
void update_thread_list(void)
Definition: thread.c:2000
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition: regcache.c:1229
ptid_t inferior_ptid
Definition: infcmd.c:94
int remove_breakpoints(void)
Definition: breakpoint.c:3038
const char * target_pid_to_str(ptid_t ptid)
Definition: target.c:2194
int offset
Definition: agent.c:65
void registers_changed(void)
Definition: regcache.c:522
CORE_ADDR stop_pc
Definition: infcmd.c:98
static void linux_fork_context(struct fork_info *newfp, int from_tty)
Definition: linux-fork.c:741
static void delete_fork(ptid_t ptid)
Definition: linux-fork.c:137
int ptid_equal(const ptid_t &ptid1, const ptid_t &ptid2)
Definition: ptid.c:71
struct inferior * current_inferior(void)
Definition: inferior.c:58
unsigned long long ULONGEST
Definition: common-types.h:53
static void free_fork(struct fork_info *fp)
Definition: linux-fork.c:112
struct value * call_function_by_hand(struct value *function, type *default_return_type, int nargs, struct value **args)
Definition: infcall.c:690
static void restart_command(const char *args, int from_tty)
Definition: linux-fork.c:764
#define SEEK_CUR
Definition: defs.h:96
ptid_t parent_ptid
Definition: linux-fork.c:46
static int checkpointing_pid
Definition: linux-fork.c:635
void linux_nat_switch_fork(ptid_t new_ptid)
Definition: linux-nat.c:1016
struct fork_info * find_fork_pid(pid_t pid)
Definition: linux-fork.c:200
argv
Definition: __init__.py:63
static struct fork_info * find_fork_id(int num)
Definition: linux-fork.c:187
void reinit_frame_cache(void)
Definition: frame.c:1809
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:902
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:311
static void fork_save_infrun_state(struct fork_info *fp, int clobber_regs)
Definition: linux-fork.c:288
static void inferior_call_waitpid_cleanup(void *fp)
Definition: linux-fork.c:438
void error(const char *fmt,...)
Definition: errors.c:38
ptid_t minus_one_ptid
Definition: ptid.c:26
static int inferior_call_waitpid(ptid_t pptid, int pid)
Definition: linux-fork.c:452
off_t * filepos
Definition: linux-fork.c:51
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:174
void linux_nat_forget_process(pid_t pid)
Definition: linux-nat.c:4916
#define gdb_stdout
Definition: utils.h:340
LONGEST parse_and_eval_long(const char *exp)
Definition: eval.c:111