Lines Matching refs:inf

76 #include "inf-child.h"
106 static struct inf *make_inf ();
109 do { struct inf *__inf = (_inf); \
110 debug ("{inf %d %s}: " msg, __inf->pid, \
116 #define INF_MSGPORT_RPC(inf, rpc_expr) \
117 HURD_MSGPORT_RPC (proc_getmsgport (proc_server, inf->pid, &msgport), \
118 (refport = inf->task->port, 0), 0, \
124 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
125 (inf_set_threads_resume_sc_for_signal_thread (inf) \
127 inf_resume (inf); \
128 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
129 inf_suspend (inf); \
144 /* The results of the last wait an inf did. */
154 struct inf
185 since a proc server `stop' leaves the signal thread running, the inf can
235 return proc->inf->pid;
316 struct inf *inf = proc->inf;
317 int running = (proc->cur_sc == 0 && inf->task->cur_sc == 0);
322 inf_update_suspends (proc->inf);
326 else if (proc == inf->wait.thread && inf->wait.exc.reply && !force)
517 proc_steal_exc_port (proc, proc->inf->event_port);
534 gnu_nat_target::make_proc (struct inf *inf, mach_port_t port, int tid)
542 proc->inf = inf;
552 proc->run_sc = inf->default_thread_run_sc;
553 proc->pause_sc = inf->default_thread_pause_sc;
554 proc->detach_sc = inf->default_thread_detach_sc;
568 inf->event_port,
576 proc_debug (proc, "notifications to: %lu", inf->event_port);
581 if (inf->want_exceptions)
585 proc_steal_exc_port (proc, inf->event_port);
600 struct inf *inf = proc->inf;
605 if (proc == inf->step_thread)
607 inf_set_step_thread (inf, 0);
608 if (proc == inf->wait.thread)
609 inf_clear_wait (inf);
610 if (proc == inf->signal_thread)
611 inf->signal_thread = 0;
633 static struct inf *
636 struct inf *inf = new struct inf;
638 inf->task = 0;
639 inf->threads = 0;
640 inf->threads_up_to_date = 0;
641 inf->pid = 0;
642 inf->wait.status.set_spurious ();
643 inf->wait.thread = 0;
644 inf->wait.exc.handler = MACH_PORT_NULL;
645 inf->wait.exc.reply = MACH_PORT_NULL;
646 inf->step_thread = 0;
647 inf->signal_thread = 0;
648 inf->event_port = MACH_PORT_NULL;
649 inf->running = 0;
650 inf->stopped = 0;
651 inf->nomsg = 1;
652 inf->traced = 0;
653 inf->no_wait = 0;
654 inf->pending_execs = 0;
655 inf->pause_sc = 1;
656 inf->detach_sc = 0;
657 inf->default_thread_run_sc = 0;
658 inf->default_thread_pause_sc = 0;
659 inf->default_thread_detach_sc = 0;
660 inf->want_signals = 1; /* By default */
661 inf->want_exceptions = 1; /* By default */
663 return inf;
668 gnu_nat_target::inf_clear_wait (struct inf *inf)
670 inf_debug (inf, "clearing wait");
671 inf->wait.status.set_spurious ();
672 inf->wait.thread = 0;
673 inf->wait.suppress = 0;
674 if (inf->wait.exc.handler != MACH_PORT_NULL)
676 mach_port_deallocate (mach_task_self (), inf->wait.exc.handler);
677 inf->wait.exc.handler = MACH_PORT_NULL;
679 if (inf->wait.exc.reply != MACH_PORT_NULL)
681 mach_port_deallocate (mach_task_self (), inf->wait.exc.reply);
682 inf->wait.exc.reply = MACH_PORT_NULL;
689 gnu_nat_target::inf_cleanup (struct inf *inf)
691 inf_debug (inf, "cleanup");
693 inf_clear_wait (inf);
695 inf_set_pid (inf, -1);
696 inf->pid = 0;
697 inf->running = 0;
698 inf->stopped = 0;
699 inf->nomsg = 1;
700 inf->traced = 0;
701 inf->no_wait = 0;
702 inf->pending_execs = 0;
704 if (inf->event_port)
706 mach_port_destroy (mach_task_self (), inf->event_port);
707 inf->event_port = MACH_PORT_NULL;
712 gnu_nat_target::inf_startup (struct inf *inf, int pid)
716 inf_debug (inf, "startup: pid = %d", pid);
718 inf_cleanup (inf);
722 MACH_PORT_RIGHT_RECEIVE, &inf->event_port);
727 mach_port_insert_right (mach_task_self (), inf->event_port,
728 inf->event_port, MACH_MSG_TYPE_MAKE_SEND);
729 inf_set_pid (inf, pid);
736 gnu_nat_target::inf_set_pid (struct inf *inf, pid_t pid)
739 struct proc *task = inf->task;
741 inf_debug (inf, "setting pid: %d", pid);
754 inf_debug (inf, "setting task: %lu", task_port);
756 if (inf->pause_sc)
761 inf->task = 0;
762 inf_validate_procs (inf); /* Trash all the threads. */
768 inf->task = make_proc (inf, task_port, PROC_TID_TASK);
769 inf->threads_up_to_date = 0;
772 if (inf->task)
774 inf->pid = pid;
775 if (inf->pause_sc)
777 inf->task->sc = inf->task->cur_sc = 1;
780 inf->pid = -1;
790 gnu_nat_target::inf_validate_procinfo (struct inf *inf)
798 proc_getprocinfo (proc_server, inf->pid, &info_flags,
803 inf->stopped = !!(pi->state & PI_STOPPED);
804 inf->nomsg = !!(pi->state & PI_NOMSG);
805 if (inf->nomsg)
806 inf->traced = !!(pi->state & PI_TRACED);
817 gnu_nat_target::inf_validate_task_sc (struct inf *inf)
828 err = proc_getprocinfo (proc_server, inf->pid, &info_flags,
832 inf->task->dead = 1; /* oh well */
836 if (inf->task->cur_sc < pi->taskinfo.suspend_count && suspend_count == -1)
853 if (inf->task->cur_sc < suspend_count)
856 " clear it? "), inf->pid,
857 suspend_count - inf->task->cur_sc))
860 inf->task->cur_sc = suspend_count;
869 gnu_nat_target::inf_set_traced (struct inf *inf, int on)
871 if (on == inf->traced)
874 if (inf->task && !inf->task->dead)
879 INF_RESUME_MSGPORT_RPC (inf, msg_set_init_int (msgport, refport,
886 inf->pid, "No signal thread");
887 inf->traced = on;
891 inf->pid, safe_strerror (err));
893 inf->traced = on;
896 inf->traced = on;
906 gnu_nat_target::inf_update_suspends (struct inf *inf)
908 struct proc *task = inf->task;
913 inf_debug (inf, "updating suspend counts");
924 if (inf->pending_execs)
930 for (thread = inf->threads; thread; thread = thread->next)
938 inf_debug (inf, "%srunning...",
941 inf->running = thread_running && task_running;
945 if (inf->running)
946 inf->threads_up_to_date = 0;
948 return inf->running;
958 inf_tid_to_thread (struct inf *inf, int tid)
960 struct proc *thread = inf->threads;
972 inf_port_to_thread (struct inf *inf, mach_port_t port)
974 struct proc *thread = inf->threads;
987 inf_threads (struct inf *inf, inf_threads_ftype *f, void *arg)
991 for (thread = inf->threads; thread; thread = thread->next)
999 gnu_nat_target::inf_validate_procs (struct inf *inf)
1003 struct proc *task = inf->task;
1009 inf->threads_up_to_date = inf->threads ? !inf->running : 0;
1015 inf_debug (inf, "fetching threads");
1027 inf_debug (inf, "no task");
1038 struct proc *thread = inf->threads;
1069 inf->threads = thread;
1083 thread = make_proc (inf, threads[i], next_thread_id++);
1087 inf->threads = thread;
1091 ptid = ptid_t (inf->pid, thread->tid, 0);
1095 if (inferior_ptid == ptid_t (inf->pid))
1099 else if (inf->pending_execs != 0)
1116 inf_update_procs (struct inf *inf)
1118 if (!inf->task)
1120 if (!inf->threads_up_to_date)
1121 gnu_target->inf_validate_procs (inf);
1122 return !!inf->task;
1125 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1129 gnu_nat_target::inf_set_threads_resume_sc (struct inf *inf,
1134 inf_update_procs (inf);
1135 for (thread = inf->threads; thread; thread = thread->next)
1149 gnu_nat_target::inf_resume (struct inf *inf)
1153 inf_update_procs (inf);
1155 for (thread = inf->threads; thread; thread = thread->next)
1158 if (inf->task)
1160 if (!inf->pending_execs)
1164 inf_validate_task_sc (inf);
1165 inf->task->sc = 0;
1168 inf_update_suspends (inf);
1174 gnu_nat_target::inf_suspend (struct inf *inf)
1178 inf_update_procs (inf);
1180 for (thread = inf->threads; thread; thread = thread->next)
1183 if (inf->task)
1184 inf->task->sc = inf->pause_sc;
1186 inf_update_suspends (inf);
1195 gnu_nat_target::inf_set_step_thread (struct inf *inf, struct proc *thread)
1200 inf_debug (inf, "setting step thread: %d/%d", inf->pid, thread->tid);
1202 inf_debug (inf, "clearing step thread");
1204 if (inf->step_thread != thread)
1206 if (inf->step_thread && inf->step_thread->port != MACH_PORT_NULL)
1207 if (!proc_trace (inf->step_thread, 0))
1210 inf->step_thread = thread;
1212 inf->step_thread = 0;
1222 gnu_nat_target::inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
1224 if (inf->signal_thread)
1226 inf_set_threads_resume_sc (inf, inf->signal_thread, 0);
1234 inf_update_signal_thread (struct inf *inf)
1238 inf->signal_thread = inf->threads ? inf->threads->next : 0;
1245 gnu_nat_target::inf_detach (struct inf *inf)
1247 struct proc *task = inf->task;
1249 inf_debug (inf, "detaching...");
1251 inf_clear_wait (inf);
1252 inf_set_step_thread (inf, 0);
1258 inf_validate_procinfo (inf);
1260 inf_set_traced (inf, 0);
1261 if (inf->stopped)
1263 if (inf->nomsg)
1264 inf_continue (inf);
1266 inf_signal (inf, GDB_SIGNAL_0);
1270 task->sc = inf->detach_sc;
1272 for (thread = inf->threads; thread; thread = thread->next)
1278 inf_update_suspends (inf);
1281 inf_cleanup (inf);
1287 gnu_nat_target::inf_attach (struct inf *inf, int pid)
1289 inf_debug (inf, "attaching: %d", pid);
1291 if (inf->pid)
1292 inf_detach (inf);
1294 inf_startup (inf, pid);
1301 gnu_nat_target::inf_steal_exc_ports (struct inf *inf)
1305 inf_debug (inf, "stealing exception ports");
1307 inf_set_step_thread (inf, 0); /* The step thread is special. */
1309 proc_steal_exc_port (inf->task, inf->event_port);
1310 for (thread = inf->threads; thread; thread = thread->next)
1316 gnu_nat_target::inf_restore_exc_ports (struct inf *inf)
1320 inf_debug (inf, "restoring exception ports");
1322 inf_set_step_thread (inf, 0); /* The step thread is special. */
1324 proc_restore_exc_port (inf->task);
1325 for (thread = inf->threads; thread; thread = thread->next)
1335 gnu_nat_target::inf_signal (struct inf *inf, enum gdb_signal sig)
1347 struct inf_wait *w = &inf->wait;
1360 inf_debug (inf, "passing through exception:"
1363 w->thread->port, inf->task->port,
1368 w->thread->port, inf->task->port,
1376 if (inf->stopped)
1380 inf_debug (inf, "sending %s to stopped process", NAME);
1382 INF_MSGPORT_RPC (inf,
1384 inf->event_port,
1393 inf->stopped = 0;
1402 inf_debug (inf, "sending %s to unstopped process"
1405 INF_RESUME_MSGPORT_RPC (inf,
1424 gnu_nat_target::inf_continue (struct inf *inf)
1427 kern_return_t err = proc_pid2proc (proc_server, inf->pid, &proc);
1431 inf_debug (inf, "continuing process");
1438 for (thread = inf->threads; thread; thread = thread->next)
1441 inf->stopped = 0;
1452 struct inf *gnu_current_inf = 0;
1456 static struct inf *waiting_inf;
1472 struct inf *inf = gnu_current_inf;
1474 gdb_assert (inf->task);
1476 if (!inf->threads && !inf->pending_execs)
1481 inf_validate_procs (inf);
1482 if (!inf->threads && !inf->task->dead)
1486 waiting_inf = inf;
1488 inf_debug (inf, "waiting for: %s", ptid.to_string ().c_str ());
1491 if (proc_wait_pid != inf->pid && !inf->no_wait)
1494 inf_debug (inf, "requesting wait on pid %d", inf->pid);
1500 inf_debug (inf, "cancelling previous wait on pid %d", proc_wait_pid);
1505 proc_wait_request (proc_server, inf->event_port, inf->pid, WUNTRACED);
1510 inf_debug (inf, "waits pending: %d", proc_waits_pending);
1511 proc_wait_pid = inf->pid;
1521 inf_clear_wait (inf);
1526 inf_debug (inf, "waiting for an event...");
1528 0, sizeof (struct msg), inf->event_port,
1532 inf_suspend (inf);
1534 if (!inf->task && inf->pending_execs)
1538 inf_set_pid (inf, inf->pid);
1541 inf_debug (inf, "interrupted");
1555 inf_debug (inf, "event: msgid = %d", msg.hdr.msgh_id);
1570 if (inf->pending_execs)
1573 struct inf_wait *w = &inf->wait;
1582 inf_debug (inf, "pending_execs, ignoring minor event");
1589 inf_debug (inf, "one pending exec completed");
1597 inf_validate_task_sc (inf);
1600 if (inf->wait.suppress)
1604 inf_debug (inf, "suppressing return, rewaiting...");
1605 inf_resume (inf);
1610 *status = inf->wait.status;
1612 thread = inf->wait.thread;
1614 ptid = ptid_t (inf->pid, thread->tid, 0);
1616 thread = inf_tid_to_thread (inf, -1);
1618 thread = inf_tid_to_thread (inf, ptid.lwp ());
1623 if (inf_update_procs (inf) && inf->threads)
1624 ptid = ptid_t (inf->pid, inf->threads->tid, 0); /* The first
1630 ptid = ptid_t (inf->pid);
1637 && inf->pause_sc == 0 && thread->pause_sc == 0)
1642 inf_update_suspends (inf);
1645 inf_debug (inf, "returning ptid = %s, %s",
1660 struct inf *inf = waiting_inf;
1661 struct proc *thread = inf_port_to_thread (inf, thread_port);
1670 inf_update_procs (inf);
1671 thread = inf_port_to_thread (inf, thread_port);
1685 inf->wait.thread = thread;
1690 inf->wait.status.set_stopped (GDB_SIGNAL_TRAP);
1700 inf->wait.exc.handler = thread->saved_exc_port;
1705 inf->task->saved_exc_port);
1706 inf->wait.exc.handler = inf->task->saved_exc_port;
1707 gdb_assert (inf->task->exc_port == port);
1709 if (inf->wait.exc.handler != MACH_PORT_NULL)
1712 inf->wait.exc.handler, MACH_PORT_RIGHT_SEND,
1715 inf->wait.exc.exception = exception;
1716 inf->wait.exc.code = code;
1717 inf->wait.exc.subcode = subcode;
1718 inf->wait.exc.reply = reply_port;
1723 inf->wait.status.set_stopped
1730 inf->wait.suppress = 1;
1742 inf_task_died_status (struct inf *inf)
1745 inf->pid);
1746 inf->wait.status.set_signalled (GDB_SIGNAL_KILL);
1753 struct inf *inf = waiting_inf;
1757 if (inf->task && inf->task->port == dead_port)
1759 proc_debug (inf->task, "is dead");
1760 inf->task->port = MACH_PORT_NULL;
1761 if (proc_wait_pid == inf->pid)
1764 inf->wait.suppress = 1;
1768 inf_task_died_status (inf);
1772 struct proc *thread = inf_port_to_thread (inf, dead_port);
1780 if (inf->task->dead)
1782 inf->wait.suppress = 1;
1786 inf->threads_up_to_date = 0; /* Just in case. */
1819 struct inf *inf = waiting_inf;
1821 inf_debug (inf, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1824 if (err && proc_wait_pid && (!inf->task || !inf->task->port))
1830 inf_task_died_status (inf);
1837 inf_debug (inf, "waits pending now: %d", proc_waits_pending);
1844 inf->pid, safe_strerror (err));
1845 inf->no_wait = 1;
1848 gnu_target->inf_set_traced (inf, 0);
1851 else if (pid == inf->pid)
1853 inf->wait.status = host_status_to_waitstatus (status);
1854 if (inf->wait.status.kind () == TARGET_WAITKIND_STOPPED)
1858 inf_debug (inf, "process has stopped itself");
1859 inf->stopped = 1;
1863 inf->wait.suppress = 1; /* Something odd happened. Ignore. */
1937 struct inf *inf = waiting_inf;
1945 inf->wait.status.set_stopped (GDB_SIGNAL_0);
1954 inf->stopped = 1;
1956 inf->wait.suppress = 1;
2002 struct inf *inf = gnu_current_inf;
2004 inf_debug (inf, "ptid = %s, step = %d, sig = %d",
2007 inf_validate_procinfo (inf);
2009 if (sig != GDB_SIGNAL_0 || inf->stopped)
2011 if (sig == GDB_SIGNAL_0 && inf->nomsg)
2012 inf_continue (inf);
2014 inf_signal (inf, sig);
2016 else if (inf->wait.exc.reply != MACH_PORT_NULL)
2020 proc_abort (inf->wait.thread, 1);
2022 proc_string (inf->wait.thread),
2023 gdb_signal_to_name (inf->wait.status.sig ()));
2026 if (port_msgs_queued (inf->event_port))
2031 inf_update_procs (inf);
2039 inf_debug (inf, "running all threads; tid = %d",
2042 inf_set_threads_resume_sc (inf, 0, 1);
2047 struct proc *thread = inf_tid_to_thread (inf, ptid.lwp ());
2052 inf_debug (inf, "running one thread: %s",
2054 inf_set_threads_resume_sc (inf, thread, 0);
2059 step_thread = inf_tid_to_thread (inf, ptid.lwp ());
2064 inf_debug (inf, "stepping thread: %s",
2067 if (step_thread != inf->step_thread)
2068 inf_set_step_thread (inf, step_thread);
2070 inf_debug (inf, "here we go...");
2071 inf_resume (inf);
2115 static struct inf *
2127 struct inf *inf = cur_inf ();
2128 inf_debug (inf, "tracing self");
2139 struct inf *inf = cur_inf ();
2143 inf_debug (inf, "creating inferior");
2158 inf_debug (inf, "attaching to child: %d", pid);
2160 inf_attach (inf, pid);
2162 inf->pending_execs = 1;
2163 inf->nomsg = 1;
2164 inf->traced = 1;
2168 inf_resume (inf);
2172 ptid_t (inf->pid, inf_pick_first_thread (), 0));
2176 inf->pending_execs = 0;
2180 inf_validate_procinfo (inf);
2181 inf_update_signal_thread (inf);
2182 inf_set_traced (inf, inf->want_signals);
2186 if (inf->want_exceptions)
2187 inf_steal_exc_ports (inf);
2189 inf_restore_exc_ports (inf);
2200 struct inf *inf = cur_inf ();
2210 inf_debug (inf, "attaching to pid: %d", pid);
2212 inf_attach (inf, pid);
2220 inf_update_procs (inf);
2232 inf_validate_procinfo (inf);
2234 inf_update_signal_thread (inf);
2235 inf_set_traced (inf, inf->want_signals);
2252 gnu_nat_target::detach (inferior *inf, int from_tty)
2259 detach_inferior (inf);
2692 xsnprintf (tid_str, sizeof (tid_str), "process %d", proc->inf->pid);
2695 proc->inf->pid, proc->tid);
2702 struct inf *inf = gnu_current_inf;
2704 struct proc *thread = inf_tid_to_thread (inf, tid);
2772 struct inf *inf = cur_inf ();
2773 struct proc *thread = inf_tid_to_thread (inf,
2781 static struct inf *
2784 struct inf *inf = cur_inf ();
2786 if (!inf->task)
2788 return inf;
2796 struct inf *inf = cur_inf ();
2797 int old_sc = inf->pause_sc;
2799 inf->pause_sc = arg;
2801 if (old_sc == 0 && inf->pause_sc != 0)
2804 gnu_target->inf_suspend (inf);
2816 struct inf *inf = cur_inf ();
2820 inf->task
2821 ? (inf->pause_sc == 0 ? "isn't" : "is")
2822 : (inf->pause_sc == 0 ? "won't be" : "will be"));
2846 struct inf *inf = cur_inf ();
2848 inf->default_thread_pause_sc =
2855 struct inf *inf = cur_inf ();
2856 int sc = inf->default_thread_pause_sc;
2861 !sc && inf->pause_sc ? " (but the task is)" : "");
2867 struct inf *inf = cur_inf ();
2869 inf->default_thread_run_sc =
2876 struct inf *inf = cur_inf ();
2880 inf->default_thread_run_sc == 0 ? "are" : "aren't");
2909 if (!proc || !proc->inf->task)
2912 err = mach_port_extract_right (proc->inf->task->port,
2930 proc->exc_port = proc->inf->event_port;
2940 struct inf *inf = cur_inf ();
2944 gnu_target->steal_exc_port (inf->task, parse_and_eval_address (args));
2956 struct inf *inf = active_inf ();
2960 inf->stopped ? "is" : "isn't");
2966 struct inf *inf = cur_inf ();
2973 inf->signal_thread = 0;
2977 inf->signal_thread = inf_tid_to_thread (inf, tp->ptid.lwp ());
2984 struct inf *inf = active_inf ();
2987 if (inf->signal_thread)
2989 proc_string (inf->signal_thread));
2999 struct inf *inf = cur_inf ();
3001 inf->want_signals = arg;
3003 if (inf->task && inf->want_signals != inf->traced)
3005 gnu_target->inf_set_traced (inf, inf->want_signals);
3017 struct inf *inf = cur_inf ();
3021 inf->task
3022 ? (inf->traced ? "are" : "aren't")
3023 : (inf->want_signals ? "will be" : "won't be"));
3029 struct inf *inf = cur_inf ();
3034 inf->want_exceptions = arg;
3046 struct inf *inf = cur_inf ();
3050 inf->task
3051 ? (inf->want_exceptions ? "are" : "aren't")
3052 : (inf->want_exceptions ? "will be" : "won't be"));
3067 struct inf *inf = cur_inf ();
3075 if (inf->pause_sc == 0)
3079 if (inf->task)
3085 if (inf->detach_sc != 0)
3087 if (inf->default_thread_detach_sc != 0)
3109 struct inf *inf = active_inf ();
3120 print_port_info (right, 0, inf->task->port, PORTINFO_DETAILS,
3131 print_task_ports_info (inf->task->port, only, PORTINFO_DETAILS,
3314 if (old_sc == 0 && thread->pause_sc != 0 && thread->inf->pause_sc == 0)
3317 gnu_target->inf_suspend (thread->inf);
3330 !sc && thread->inf->pause_sc ? " (but the task is)" : "");