Lines Matching defs:inf

91 struct inf *make_inf ();
92 void inf_clear_wait (struct inf *inf);
93 void inf_cleanup (struct inf *inf);
94 void inf_startup (struct inf *inf, int pid);
95 int inf_update_suspends (struct inf *inf);
96 void inf_set_pid (struct inf *inf, pid_t pid);
97 void inf_validate_procs (struct inf *inf);
98 void inf_steal_exc_ports (struct inf *inf);
99 void inf_restore_exc_ports (struct inf *inf);
100 struct proc *inf_tid_to_proc (struct inf *inf, int tid);
101 void inf_set_threads_resume_sc (struct inf *inf,
104 int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
105 void inf_suspend (struct inf *inf);
106 void inf_resume (struct inf *inf);
107 void inf_set_step_thread (struct inf *inf, struct proc *proc);
108 void inf_detach (struct inf *inf);
109 void inf_attach (struct inf *inf, int pid);
110 void inf_signal (struct inf *inf, enum target_signal sig);
111 void inf_continue (struct inf *inf);
114 do { struct inf *__inf = (_inf); \
115 debug ("{inf %d %p}: " msg, __inf->pid, __inf , ##args); } while (0)
118 struct proc *make_proc (struct inf *inf, mach_port_t port, int tid);
131 #define INF_MSGPORT_RPC(inf, rpc_expr) \
132 HURD_MSGPORT_RPC (proc_getmsgport (proc_server, inf->pid, &msgport), \
133 (refport = inf->task->port, 0), 0, \
139 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
140 (inf_set_threads_resume_sc_for_signal_thread (inf) \
142 inf_resume (inf); \
143 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
144 inf_suspend (inf); \
159 /* The results of the last wait an inf did. */
169 struct inf
199 since a proc server `stop' leaves the signal thread running, the inf can
249 return proc->inf->pid;
330 struct inf *inf = proc->inf;
331 int running = (proc->cur_sc == 0 && inf->task->cur_sc == 0);
336 inf_update_suspends (proc->inf);
340 else if (proc == inf->wait.thread && inf->wait.exc.reply && !force)
529 proc_steal_exc_port (proc, proc->inf->event_port);
546 make_proc (struct inf *inf, mach_port_t port, int tid)
554 proc->inf = inf;
564 proc->run_sc = inf->default_thread_run_sc;
565 proc->pause_sc = inf->default_thread_pause_sc;
566 proc->detach_sc = inf->default_thread_detach_sc;
580 inf->event_port,
588 proc_debug (proc, "notifications to: %d", inf->event_port);
593 if (inf->want_exceptions)
597 proc_steal_exc_port (proc, inf->event_port);
612 struct inf *inf = proc->inf;
617 if (proc == inf->step_thread)
619 inf_set_step_thread (inf, 0);
620 if (proc == inf->wait.thread)
621 inf_clear_wait (inf);
622 if (proc == inf->signal_thread)
623 inf->signal_thread = 0;
645 struct inf *
648 struct inf *inf = xmalloc (sizeof (struct inf));
650 inf->task = 0;
651 inf->threads = 0;
652 inf->threads_up_to_date = 0;
653 inf->pid = 0;
654 inf->wait.status.kind = TARGET_WAITKIND_SPURIOUS;
655 inf->wait.thread = 0;
656 inf->wait.exc.handler = MACH_PORT_NULL;
657 inf->wait.exc.reply = MACH_PORT_NULL;
658 inf->step_thread = 0;
659 inf->signal_thread = 0;
660 inf->event_port = MACH_PORT_NULL;
661 inf->running = 0;
662 inf->stopped = 0;
663 inf->nomsg = 1;
664 inf->traced = 0;
665 inf->no_wait = 0;
666 inf->pending_execs = 0;
667 inf->pause_sc = 1;
668 inf->detach_sc = 0;
669 inf->default_thread_run_sc = 0;
670 inf->default_thread_pause_sc = 0;
671 inf->default_thread_detach_sc = 0;
672 inf->want_signals = 1; /* By default */
673 inf->want_exceptions = 1; /* By default */
675 return inf;
680 inf_clear_wait (struct inf *inf)
682 inf_debug (inf, "clearing wait");
683 inf->wait.status.kind = TARGET_WAITKIND_SPURIOUS;
684 inf->wait.thread = 0;
685 inf->wait.suppress = 0;
686 if (inf->wait.exc.handler != MACH_PORT_NULL)
688 mach_port_deallocate (mach_task_self (), inf->wait.exc.handler);
689 inf->wait.exc.handler = MACH_PORT_NULL;
691 if (inf->wait.exc.reply != MACH_PORT_NULL)
693 mach_port_deallocate (mach_task_self (), inf->wait.exc.reply);
694 inf->wait.exc.reply = MACH_PORT_NULL;
701 inf_cleanup (struct inf *inf)
703 inf_debug (inf, "cleanup");
705 inf_clear_wait (inf);
707 inf_set_pid (inf, -1);
708 inf->pid = 0;
709 inf->running = 0;
710 inf->stopped = 0;
711 inf->nomsg = 1;
712 inf->traced = 0;
713 inf->no_wait = 0;
714 inf->pending_execs = 0;
716 if (inf->event_port)
718 mach_port_destroy (mach_task_self (), inf->event_port);
719 inf->event_port = MACH_PORT_NULL;
724 inf_startup (struct inf *inf, int pid)
728 inf_debug (inf, "startup: pid = %d", pid);
730 inf_cleanup (inf);
734 MACH_PORT_RIGHT_RECEIVE, &inf->event_port);
739 mach_port_insert_right (mach_task_self (), inf->event_port,
740 inf->event_port, MACH_MSG_TYPE_MAKE_SEND);
741 inf_set_pid (inf, pid);
748 inf_set_pid (struct inf *inf, pid_t pid)
751 struct proc *task = inf->task;
753 inf_debug (inf, "setting pid: %d", pid);
764 inf_debug (inf, "setting task: %d", task_port);
766 if (inf->pause_sc)
771 inf->task = 0;
772 inf_validate_procs (inf); /* Trash all the threads. */
778 inf->task = make_proc (inf, task_port, PROC_TID_TASK);
779 inf->threads_up_to_date = 0;
782 if (inf->task)
784 inf->pid = pid;
785 if (inf->pause_sc)
787 inf->task->sc = inf->task->cur_sc = 1;
790 inf->pid = -1;
800 inf_validate_procinfo (struct inf *inf)
808 proc_getprocinfo (proc_server, inf->pid, &info_flags,
813 inf->stopped = !!(pi->state & PI_STOPPED);
814 inf->nomsg = !!(pi->state & PI_NOMSG);
815 if (inf->nomsg)
816 inf->traced = !!(pi->state & PI_TRACED);
826 inf_validate_task_sc (struct inf *inf)
837 err = proc_getprocinfo (proc_server, inf->pid, &info_flags,
841 inf->task->dead = 1; /* oh well */
845 if (inf->task->cur_sc < pi->taskinfo.suspend_count && suspend_count == -1)
861 if (inf->task->cur_sc < suspend_count)
867 " clear it? ", inf->pid,
868 suspend_count - inf->task->cur_sc);
874 inf->task->cur_sc = suspend_count;
883 inf_set_traced (struct inf *inf, int on)
885 if (on == inf->traced)
888 if (inf->task && !inf->task->dead)
893 INF_RESUME_MSGPORT_RPC (inf, msg_set_init_int (msgport, refport,
899 inf->pid, "No signal thread");
900 inf->traced = on;
904 inf->pid, safe_strerror (err));
906 inf->traced = on;
909 inf->traced = on;
919 inf_update_suspends (struct inf *inf)
921 struct proc *task = inf->task;
926 inf_debug (inf, "updating suspend counts");
937 if (inf->pending_execs)
943 for (thread = inf->threads; thread; thread = thread->next)
951 inf_debug (inf, "%srunning...",
954 inf->running = thread_running && task_running;
958 if (inf->running)
959 inf->threads_up_to_date = 0;
961 return inf->running;
971 inf_tid_to_thread (struct inf *inf, int tid)
973 struct proc *thread = inf->threads;
985 inf_port_to_thread (struct inf *inf, mach_port_t port)
987 struct proc *thread = inf->threads;
1000 inf_validate_procs (struct inf *inf)
1004 struct proc *task = inf->task;
1010 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;
1066 (last ? last->next : inf->threads) = thread;
1078 thread = make_proc (inf, threads[i], next_thread_id++);
1079 (last ? last->next : inf->threads) = thread;
1095 inf_update_procs (struct inf *inf)
1097 if (!inf->task)
1099 if (!inf->threads_up_to_date)
1100 inf_validate_procs (inf);
1101 return !!inf->task;
1104 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1108 inf_set_threads_resume_sc (struct inf *inf,
1112 inf_update_procs (inf);
1113 for (thread = inf->threads; thread; thread = thread->next)
1127 inf_resume (struct inf *inf)
1131 inf_update_procs (inf);
1133 for (thread = inf->threads; thread; thread = thread->next)
1136 if (inf->task)
1138 if (!inf->pending_execs)
1142 inf_validate_task_sc (inf);
1143 inf->task->sc = 0;
1146 inf_update_suspends (inf);
1152 inf_suspend (struct inf *inf)
1156 inf_update_procs (inf);
1158 for (thread = inf->threads; thread; thread = thread->next)
1161 if (inf->task)
1162 inf->task->sc = inf->pause_sc;
1164 inf_update_suspends (inf);
1173 inf_set_step_thread (struct inf *inf, struct proc *thread)
1178 inf_debug (inf, "setting step thread: %d/%d", inf->pid, thread->tid);
1180 inf_debug (inf, "clearing step thread");
1182 if (inf->step_thread != thread)
1184 if (inf->step_thread && inf->step_thread->port != MACH_PORT_NULL)
1185 if (!proc_trace (inf->step_thread, 0))
1188 inf->step_thread = thread;
1190 inf->step_thread = 0;
1200 inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
1202 if (inf->signal_thread)
1204 inf_set_threads_resume_sc (inf, inf->signal_thread, 0);
1212 inf_update_signal_thread (struct inf *inf)
1216 inf->signal_thread = inf->threads ? inf->threads->next : 0;
1223 inf_detach (struct inf *inf)
1225 struct proc *task = inf->task;
1227 inf_debug (inf, "detaching...");
1229 inf_clear_wait (inf);
1230 inf_set_step_thread (inf, 0);
1236 inf_validate_procinfo (inf);
1238 inf_set_traced (inf, 0);
1239 if (inf->stopped)
1241 if (inf->nomsg)
1242 inf_continue (inf);
1244 inf_signal (inf, TARGET_SIGNAL_0);
1248 task->sc = inf->detach_sc;
1250 for (thread = inf->threads; thread; thread = thread->next)
1256 inf_update_suspends (inf);
1259 inf_cleanup (inf);
1265 inf_attach (struct inf *inf, int pid)
1267 inf_debug (inf, "attaching: %d", pid);
1269 if (inf->pid)
1270 inf_detach (inf);
1272 inf_startup (inf, pid);
1279 inf_steal_exc_ports (struct inf *inf)
1283 inf_debug (inf, "stealing exception ports");
1285 inf_set_step_thread (inf, 0); /* The step thread is special. */
1287 proc_steal_exc_port (inf->task, inf->event_port);
1288 for (thread = inf->threads; thread; thread = thread->next)
1294 inf_restore_exc_ports (struct inf *inf)
1298 inf_debug (inf, "restoring exception ports");
1300 inf_set_step_thread (inf, 0); /* The step thread is special. */
1302 proc_restore_exc_port (inf->task);
1303 for (thread = inf->threads; thread; thread = thread->next)
1313 inf_signal (struct inf *inf, enum target_signal sig)
1325 struct inf_wait *w = &inf->wait;
1336 inf_debug (inf, "passing through exception:"
1339 w->thread->port, inf->task->port,
1344 w->thread->port, inf->task->port,
1352 if (inf->stopped)
1356 inf_debug (inf, "sending %s to stopped process", NAME);
1358 INF_MSGPORT_RPC (inf,
1360 inf->event_port,
1369 inf->stopped = 0;
1378 inf_debug (inf, "sending %s to unstopped process"
1381 INF_RESUME_MSGPORT_RPC (inf,
1400 inf_continue (struct inf *inf)
1403 error_t err = proc_pid2proc (proc_server, inf->pid, &proc);
1407 inf_debug (inf, "continuing process");
1414 for (thread = inf->threads; thread; thread = thread->next)
1417 inf->stopped = 0;
1428 struct inf *current_inferior = 0;
1432 struct inf *waiting_inf;
1446 struct inf *inf = current_inferior;
1453 gdb_assert (inf->task);
1455 if (!inf->threads && !inf->pending_execs)
1460 inf_validate_procs (inf);
1461 if (!inf->threads && !inf->task->dead)
1465 waiting_inf = inf;
1467 inf_debug (inf, "waiting for: %d", PIDGET (tid));
1470 if (proc_wait_pid != inf->pid && !inf->no_wait)
1473 inf_debug (inf, "requesting wait on pid %d", inf->pid);
1479 inf_debug (inf, "cancelling previous wait on pid %d", proc_wait_pid);
1484 proc_wait_request (proc_server, inf->event_port, inf->pid, WUNTRACED);
1489 inf_debug (inf, "waits pending: %d", proc_waits_pending);
1490 proc_wait_pid = inf->pid;
1500 inf_clear_wait (inf);
1505 inf_debug (inf, "waiting for an event...");
1507 0, sizeof (struct msg), inf->event_port,
1511 inf_suspend (inf);
1513 if (!inf->task && inf->pending_execs)
1517 inf_set_pid (inf, inf->pid);
1520 inf_debug (inf, "interrupted");
1534 inf_debug (inf, "event: msgid = %d", msg.hdr.msgh_id);
1549 if (inf->pending_execs)
1552 struct inf_wait *w = &inf->wait;
1561 inf_debug (inf, "pending_execs = %d, ignoring minor event",
1562 inf->pending_execs);
1569 if (--inf->pending_execs == 0)
1577 inf_debug (inf, "pending exec completed, pending_execs => %d",
1578 inf->pending_execs);
1586 inf_validate_task_sc (inf);
1589 if (inf->wait.suppress)
1593 inf_debug (inf, "suppressing return, rewaiting...");
1594 inf_resume (inf);
1599 bcopy (&inf->wait.status, status, sizeof (*status));
1601 thread = inf->wait.thread;
1605 thread = inf_tid_to_thread (inf, PIDGET (tid));
1610 if (inf_update_procs (inf) && inf->threads)
1611 tid = pid_to_ptid (inf->threads->tid); /* The first available thread. */
1617 && inf->pause_sc == 0 && thread->pause_sc == 0)
1622 inf_update_suspends (inf);
1625 inf_debug (inf, "returning tid = %d, status = %s (%d)", PIDGET (tid),
1645 struct inf *inf = waiting_inf;
1646 struct proc *thread = inf_port_to_thread (inf, thread_port);
1655 inf_update_procs (inf);
1656 thread = inf_port_to_thread (inf, thread_port);
1670 inf->wait.thread = thread;
1672 inf->wait.status.kind = TARGET_WAITKIND_STOPPED;
1677 inf->wait.status.value.sig = TARGET_SIGNAL_TRAP;
1687 inf->wait.exc.handler = thread->saved_exc_port;
1692 inf->task->saved_exc_port);
1693 inf->wait.exc.handler = inf->task->saved_exc_port;
1694 gdb_assert (inf->task->exc_port == port);
1696 if (inf->wait.exc.handler != MACH_PORT_NULL)
1699 inf->wait.exc.handler, MACH_PORT_RIGHT_SEND,
1702 inf->wait.exc.exception = exception;
1703 inf->wait.exc.code = code;
1704 inf->wait.exc.subcode = subcode;
1705 inf->wait.exc.reply = reply_port;
1709 inf->wait.status.value.sig =
1716 inf->wait.suppress = 1;
1728 inf_task_died_status (struct inf *inf)
1730 warning ("Pid %d died with unknown exit status, using SIGKILL.", inf->pid);
1731 inf->wait.status.kind = TARGET_WAITKIND_SIGNALLED;
1732 inf->wait.status.value.sig = TARGET_SIGNAL_KILL;
1739 struct inf *inf = waiting_inf;
1743 if (inf->task && inf->task->port == dead_port)
1745 proc_debug (inf->task, "is dead");
1746 inf->task->port = MACH_PORT_NULL;
1747 if (proc_wait_pid == inf->pid)
1750 inf->wait.suppress = 1;
1754 inf_task_died_status (inf);
1758 struct proc *thread = inf_port_to_thread (inf, dead_port);
1765 if (inf->task->dead)
1767 inf->wait.suppress = 1;
1771 inf->threads_up_to_date = 0; /* Just in case */
1823 struct inf *inf = waiting_inf;
1825 inf_debug (inf, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1828 if (err && proc_wait_pid && (!inf->task || !inf->task->port))
1834 inf_task_died_status (inf);
1841 inf_debug (inf, "waits pending now: %d", proc_waits_pending);
1847 warning ("Can't wait for pid %d: %s", inf->pid, safe_strerror (err));
1848 inf->no_wait = 1;
1851 inf_set_traced (inf, 0);
1854 else if (pid == inf->pid)
1856 store_waitstatus (&inf->wait.status, status);
1857 if (inf->wait.status.kind == TARGET_WAITKIND_STOPPED)
1861 inf_debug (inf, "process has stopped itself");
1862 inf->stopped = 1;
1866 inf->wait.suppress = 1; /* Something odd happened. Ignore. */
1891 struct inf *inf = waiting_inf;
1900 inf->wait.status.kind = TARGET_WAITKIND_STOPPED;
1901 inf->wait.status.value.sig = TARGET_SIGNAL_0;
1911 inf->stopped = 1;
1913 inf->wait.suppress = 1;
1962 struct inf *inf = current_inferior;
1964 inf_debug (inf, "tid = %d, step = %d, sig = %d", PIDGET (tid), step, sig);
1966 inf_validate_procinfo (inf);
1968 if (sig != TARGET_SIGNAL_0 || inf->stopped)
1970 if (sig == TARGET_SIGNAL_0 && inf->nomsg)
1971 inf_continue (inf);
1973 inf_signal (inf, sig);
1975 else if (inf->wait.exc.reply != MACH_PORT_NULL)
1979 proc_abort (inf->wait.thread, 1);
1981 proc_string (inf->wait.thread),
1982 target_signal_to_name (inf->wait.status.value.sig));
1985 if (port_msgs_queued (inf->event_port))
1990 inf_update_procs (inf);
1995 inf_debug (inf, "running all threads; tid = %d", PIDGET (inferior_ptid));
1997 inf_set_threads_resume_sc (inf, 0, 1);
2002 struct proc *thread = inf_tid_to_thread (inf, PIDGET (tid));
2005 inf_debug (inf, "running one thread: %d/%d", inf->pid, thread->tid);
2006 inf_set_threads_resume_sc (inf, thread, 0);
2011 step_thread = inf_tid_to_thread (inf, PIDGET (tid));
2015 inf_debug (inf, "stepping thread: %d/%d", inf->pid, step_thread->tid);
2017 if (step_thread != inf->step_thread)
2018 inf_set_step_thread (inf, step_thread);
2020 inf_debug (inf, "here we go...");
2021 inf_resume (inf);
2065 static struct inf *
2076 struct inf *inf = cur_inf ();
2081 inf_debug (inf, "tracing self");
2088 inf_debug (inf, "attaching to child: %d", pid);
2090 inf_attach (inf, pid);
2095 inf->pending_execs = 2;
2096 inf->nomsg = 1;
2097 inf->traced = 1;
2101 inf_resume (inf);
2104 startup_inferior (inf->pending_execs);
2107 inf_debug (inf, "creating inferior");
2112 inf_validate_procinfo (inf);
2113 inf_update_signal_thread (inf);
2114 inf_set_traced (inf, inf->want_signals);
2118 if (inf->want_exceptions)
2119 inf_steal_exc_ports (inf);
2121 inf_restore_exc_ports (inf);
2146 struct inf *inf = cur_inf ();
2169 inf_debug (inf, "attaching to pid: %d", pid);
2171 inf_attach (inf, pid);
2172 inf_update_procs (inf);
2185 inf_validate_procinfo (inf);
2187 inf_update_signal_thread (inf);
2188 inf_set_traced (inf, inf->want_signals);
2596 sprintf (tid_str, "process %d", proc->inf->pid);
2599 proc->inf->pid, pid_to_thread_id (MERGEPID (proc->tid, 0)));
2606 struct inf *inf = current_inferior;
2608 struct proc *thread = inf_tid_to_thread (inf, tid);
2748 struct inf *inf = cur_inf ();
2749 struct proc *thread = inf_tid_to_thread (inf, PIDGET (inferior_ptid));
2756 static struct inf *
2759 struct inf *inf = cur_inf ();
2760 if (!inf->task)
2762 return inf;
2770 struct inf *inf = cur_inf ();
2771 int old_sc = inf->pause_sc;
2773 inf->pause_sc = parse_bool_arg (args, "set task pause");
2775 if (old_sc == 0 && inf->pause_sc != 0)
2778 inf_suspend (inf);
2784 struct inf *inf = cur_inf ();
2787 inf->task
2788 ? (inf->pause_sc == 0 ? "isn't" : "is")
2789 : (inf->pause_sc == 0 ? "won't be" : "will be"));
2811 struct inf *inf = cur_inf ();
2812 inf->default_thread_pause_sc =
2819 struct inf *inf = cur_inf ();
2820 int sc = inf->default_thread_pause_sc;
2824 !sc && inf->pause_sc ? " (but the task is)" : "");
2830 struct inf *inf = cur_inf ();
2831 inf->default_thread_run_sc =
2838 struct inf *inf = cur_inf ();
2841 inf->default_thread_run_sc == 0 ? "are" : "aren't");
2870 if (!proc || !proc->inf->task)
2873 err = mach_port_extract_right (proc->inf->task->port,
2890 proc->exc_port = proc->inf->event_port;
2900 struct inf *inf = cur_inf ();
2903 steal_exc_port (inf->task, parse_and_eval_address (args));
2915 struct inf *inf = active_inf ();
2918 inf->stopped ? "is" : "isn't");
2924 struct inf *inf = cur_inf ();
2931 inf->signal_thread = 0;
2938 inf->signal_thread = inf_tid_to_thread (inf, tid);
2945 struct inf *inf = active_inf ();
2947 if (inf->signal_thread)
2949 proc_string (inf->signal_thread));
2959 struct inf *inf = cur_inf ();
2961 inf->want_signals = parse_bool_arg (args, "set signals");
2963 if (inf->task && inf->want_signals != inf->traced)
2965 inf_set_traced (inf, inf->want_signals);
2971 struct inf *inf = cur_inf ();
2974 inf->task
2975 ? (inf->traced ? "are" : "aren't")
2976 : (inf->want_signals ? "will be" : "won't be"));
2982 struct inf *inf = cur_inf ();
2985 if (inf->task && inf->want_exceptions != val)
2989 inf->want_exceptions = val;
2995 struct inf *inf = cur_inf ();
2998 inf->task
2999 ? (inf->want_exceptions ? "are" : "aren't")
3000 : (inf->want_exceptions ? "will be" : "won't be"));
3015 struct inf *inf = cur_inf ();
3023 if (inf->pause_sc == 0)
3027 if (inf->task)
3033 if (inf->detach_sc != 0)
3035 if (inf->default_thread_detach_sc != 0)
3057 struct inf *inf = active_inf ();
3068 print_port_info (right, 0, inf->task->port, PORTINFO_DETAILS,
3078 print_task_ports_info (inf->task->port, only, PORTINFO_DETAILS,
3259 if (old_sc == 0 && thread->pause_sc != 0 && thread->inf->pause_sc == 0)
3262 inf_suspend (thread->inf);
3274 !sc && thread->inf->pause_sc ? " (but the task is)" : "");