1 /* Interface GDB to the GNU Hurd.
2 Copyright 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
33 #include "gdb_string.h"
34 #include <sys/ptrace.h>
37 #include <mach_error.h>
38 #include <mach/exception.h>
39 #include <mach/message.h>
40 #include <mach/notify.h>
41 #include <mach/vm_attributes.h>
44 #include <hurd/interrupt.h>
46 #include <hurd/msg_request.h>
47 #include <hurd/process.h>
48 #include <hurd/process_request.h>
49 #include <hurd/signal.h>
50 #include <hurd/sigpreempt.h>
63 #include "gdbthread.h"
64 #include "gdb_assert.h"
68 #include "exc_request_S.h"
70 #include "process_reply_S.h"
71 #include "msg_reply_S.h"
72 #include "exc_request_U.h"
75 static process_t proc_server = MACH_PORT_NULL;
77 /* If we've sent a proc_wait_request to the proc server, the pid of the
78 process we asked about. We can only ever have one outstanding. */
79 int proc_wait_pid = 0;
81 /* The number of wait requests we've sent, and expect replies from. */
82 int proc_waits_pending = 0;
84 int gnu_debug_flag = 0;
88 extern struct target_ops gnu_ops;
90 struct inf *make_inf ();
91 void inf_clear_wait (struct inf *inf);
92 void inf_cleanup (struct inf *inf);
93 void inf_startup (struct inf *inf, int pid);
94 int inf_update_suspends (struct inf *inf);
95 void inf_set_pid (struct inf *inf, pid_t pid);
96 void inf_validate_procs (struct inf *inf);
97 void inf_steal_exc_ports (struct inf *inf);
98 void inf_restore_exc_ports (struct inf *inf);
99 struct proc *inf_tid_to_proc (struct inf *inf, int tid);
100 inline void inf_set_threads_resume_sc (struct inf *inf,
101 struct proc *run_thread,
103 inline int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
104 inline void inf_suspend (struct inf *inf);
105 inline void inf_resume (struct inf *inf);
106 void inf_set_step_thread (struct inf *inf, struct proc *proc);
107 void inf_detach (struct inf *inf);
108 void inf_attach (struct inf *inf, int pid);
109 void inf_signal (struct inf *inf, enum target_signal sig);
110 void inf_continue (struct inf *inf);
112 #define inf_debug(_inf, msg, args...) \
113 do { struct inf *__inf = (_inf); \
114 debug ("{inf %d %p}: " msg, __inf->pid, __inf , ##args); } while (0)
116 void proc_abort (struct proc *proc, int force);
117 struct proc *make_proc (struct inf *inf, mach_port_t port, int tid);
118 struct proc *_proc_free (struct proc *proc);
119 int proc_update_sc (struct proc *proc);
120 error_t proc_get_exception_port (struct proc *proc, mach_port_t * port);
121 error_t proc_set_exception_port (struct proc *proc, mach_port_t port);
122 static mach_port_t _proc_get_exc_port (struct proc *proc);
123 void proc_steal_exc_port (struct proc *proc, mach_port_t exc_port);
124 void proc_restore_exc_port (struct proc *proc);
125 int proc_trace (struct proc *proc, int set);
127 /* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
128 to INF's msg port and task port respectively. If it has no msg port,
129 EIEIO is returned. INF must refer to a running process! */
130 #define INF_MSGPORT_RPC(inf, rpc_expr) \
131 HURD_MSGPORT_RPC (proc_getmsgport (proc_server, inf->pid, &msgport), \
132 (refport = inf->task->port, 0), 0, \
133 msgport ? (rpc_expr) : EIEIO)
135 /* Like INF_MSGPORT_RPC, but will also resume the signal thread to ensure
136 there's someone around to deal with the RPC (and resuspend things
137 afterwards). This effects INF's threads' resume_sc count. */
138 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
139 (inf_set_threads_resume_sc_for_signal_thread (inf) \
142 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
148 /* The state passed by an exception message. */
151 int exception; /* The exception code */
153 mach_port_t handler; /* The real exception port to handle this. */
154 mach_port_t reply; /* The reply port from the exception call. */
157 /* The results of the last wait an inf did. */
160 struct target_waitstatus status; /* The status returned to gdb. */
161 struct exc_state exc; /* The exception that caused us to return. */
162 struct proc *thread; /* The thread in question. */
163 int suppress; /* Something trivial happened. */
166 /* The state of an inferior. */
169 /* Fields describing the current inferior. */
171 struct proc *task; /* The mach task. */
172 struct proc *threads; /* A linked list of all threads in TASK. */
174 /* True if THREADS needn't be validated by querying the task. We assume that
175 we and the task in question are the only ones frobbing the thread list,
176 so as long as we don't let any code run, we don't have to worry about
178 int threads_up_to_date;
180 pid_t pid; /* The real system PID. */
182 struct inf_wait wait; /* What to return from target_wait. */
184 /* One thread proc in INF may be in `single-stepping mode'. This is it. */
185 struct proc *step_thread;
187 /* The thread we think is the signal thread. */
188 struct proc *signal_thread;
190 mach_port_t event_port; /* Where we receive various msgs. */
192 /* True if we think at least one thread in the inferior could currently be
194 unsigned int running:1;
196 /* True if the process has stopped (in the proc server sense). Note that
197 since a proc server `stop' leaves the signal thread running, the inf can
198 be RUNNING && STOPPED... */
199 unsigned int stopped:1;
201 /* True if the inferior has no message port. */
202 unsigned int nomsg:1;
204 /* True if the inferior is traced. */
205 unsigned int traced:1;
207 /* True if we shouldn't try waiting for the inferior, usually because we
208 can't for some reason. */
209 unsigned int no_wait:1;
211 /* When starting a new inferior, we don't try to validate threads until all
212 the proper execs have been done. This is a count of how many execs we
214 unsigned pending_execs;
216 /* Fields describing global state */
218 /* The task suspend count used when gdb has control. This is normally 1 to
219 make things easier for us, but sometimes (like when attaching to vital
220 system servers) it may be desirable to let the task continue to run
221 (pausing individual threads as necessary). */
224 /* The task suspend count left when detaching from a task. */
227 /* The initial values used for the run_sc and pause_sc of newly discovered
228 threads -- see the definition of those fields in struct proc. */
229 int default_thread_run_sc;
230 int default_thread_pause_sc;
231 int default_thread_detach_sc;
233 /* True if the process should be traced when started/attached. Newly
234 started processes *must* be traced at first to exec them properly, but
235 if this is false, tracing is turned off as soon it has done so. */
238 /* True if exceptions from the inferior process should be trapped. This
239 must be on to use breakpoints. */
245 __proc_pid (struct proc *proc)
247 return proc->inf->pid;
251 /* Update PROC's real suspend count to match it's desired one. Returns true
252 if we think PROC is now in a runnable state. */
254 proc_update_sc (struct proc *proc)
258 int delta = proc->sc - proc->cur_sc;
261 proc_debug (proc, "sc: %d --> %d", proc->cur_sc, proc->sc);
263 if (proc->sc == 0 && proc->state_changed)
264 /* Since PROC may start running, we must write back any state changes. */
266 gdb_assert (proc_is_thread (proc));
267 proc_debug (proc, "storing back changed thread state");
268 err = thread_set_state (proc->port, THREAD_STATE_FLAVOR,
269 (thread_state_t) &proc->state, THREAD_STATE_SIZE);
271 proc->state_changed = 0;
276 while (delta-- > 0 && !err)
278 if (proc_is_task (proc))
279 err = task_suspend (proc->port);
281 err = thread_suspend (proc->port);
286 while (delta++ < 0 && !err)
288 if (proc_is_task (proc))
289 err = task_resume (proc->port);
291 err = thread_resume (proc->port);
295 proc->cur_sc = proc->sc;
297 /* If we got an error, then the task/thread has disappeared. */
298 running = !err && proc->sc == 0;
300 proc_debug (proc, "is %s", err ? "dead" : running ? "running" : "suspended");
302 proc_debug (proc, "err = %s", safe_strerror (err));
307 proc->state_valid = proc->state_changed = 0;
308 proc->fetched_regs = 0;
315 /* Thread_abort is called on PROC if needed. PROC must be a thread proc.
316 If PROC is deemed `precious', then nothing is done unless FORCE is true.
317 In particular, a thread is precious if it's running (in which case forcing
318 it includes suspending it first), or if it has an exception pending. */
320 proc_abort (struct proc *proc, int force)
322 gdb_assert (proc_is_thread (proc));
326 struct inf *inf = proc->inf;
327 int running = (proc->cur_sc == 0 && inf->task->cur_sc == 0);
329 if (running && force)
332 inf_update_suspends (proc->inf);
334 warning ("Stopped %s.", proc_string (proc));
336 else if (proc == inf->wait.thread && inf->wait.exc.reply && !force)
337 /* An exception is pending on PROC, which don't mess with. */
341 /* We only abort the thread if it's not actually running. */
343 thread_abort (proc->port);
344 proc_debug (proc, "aborted");
348 proc_debug (proc, "not aborting");
352 /* Make sure that the state field in PROC is up to date, and return a pointer
353 to it, or 0 if something is wrong. If WILL_MODIFY is true, makes sure
354 that the thread is stopped and aborted first, and sets the state_changed
355 field in PROC to true. */
357 proc_get_state (struct proc *proc, int will_modify)
359 int was_aborted = proc->aborted;
361 proc_debug (proc, "updating state info%s",
362 will_modify ? " (with intention to modify)" : "");
364 proc_abort (proc, will_modify);
366 if (!was_aborted && proc->aborted)
367 /* PROC's state may have changed since we last fetched it. */
368 proc->state_valid = 0;
370 if (!proc->state_valid)
372 mach_msg_type_number_t state_size = THREAD_STATE_SIZE;
374 thread_get_state (proc->port, THREAD_STATE_FLAVOR,
375 (thread_state_t) &proc->state, &state_size);
376 proc_debug (proc, "getting thread state");
377 proc->state_valid = !err;
380 if (proc->state_valid)
383 proc->state_changed = 1;
384 return (thread_state_t) &proc->state;
391 /* Set PORT to PROC's exception port. */
393 proc_get_exception_port (struct proc * proc, mach_port_t * port)
395 if (proc_is_task (proc))
396 return task_get_exception_port (proc->port, port);
398 return thread_get_exception_port (proc->port, port);
401 /* Set PROC's exception port to PORT. */
403 proc_set_exception_port (struct proc * proc, mach_port_t port)
405 proc_debug (proc, "setting exception port: %d", port);
406 if (proc_is_task (proc))
407 return task_set_exception_port (proc->port, port);
409 return thread_set_exception_port (proc->port, port);
412 /* Get PROC's exception port, cleaning up a bit if proc has died. */
414 _proc_get_exc_port (struct proc *proc)
416 mach_port_t exc_port;
417 error_t err = proc_get_exception_port (proc, &exc_port);
420 /* PROC must be dead. */
423 mach_port_deallocate (mach_task_self (), proc->exc_port);
424 proc->exc_port = MACH_PORT_NULL;
425 if (proc->saved_exc_port)
426 mach_port_deallocate (mach_task_self (), proc->saved_exc_port);
427 proc->saved_exc_port = MACH_PORT_NULL;
433 /* Replace PROC's exception port with EXC_PORT, unless it's already been
434 done. Stash away any existing exception port so we can restore it later. */
436 proc_steal_exc_port (struct proc *proc, mach_port_t exc_port)
438 mach_port_t cur_exc_port = _proc_get_exc_port (proc);
444 proc_debug (proc, "inserting exception port: %d", exc_port);
446 if (cur_exc_port != exc_port)
447 /* Put in our exception port. */
448 err = proc_set_exception_port (proc, exc_port);
450 if (err || cur_exc_port == proc->exc_port)
451 /* We previously set the exception port, and it's still set. So we
452 just keep the old saved port which is what the proc set. */
455 mach_port_deallocate (mach_task_self (), cur_exc_port);
458 /* Keep a copy of PROC's old exception port so it can be restored. */
460 if (proc->saved_exc_port)
461 mach_port_deallocate (mach_task_self (), proc->saved_exc_port);
462 proc->saved_exc_port = cur_exc_port;
465 proc_debug (proc, "saved exception port: %d", proc->saved_exc_port);
468 proc->exc_port = exc_port;
470 warning ("Error setting exception port for %s: %s",
471 proc_string (proc), safe_strerror (err));
475 /* If we previously replaced PROC's exception port, put back what we
476 found there at the time, unless *our* exception port has since been
477 overwritten, in which case who knows what's going on. */
479 proc_restore_exc_port (struct proc *proc)
481 mach_port_t cur_exc_port = _proc_get_exc_port (proc);
487 proc_debug (proc, "restoring real exception port");
489 if (proc->exc_port == cur_exc_port)
490 /* Our's is still there. */
491 err = proc_set_exception_port (proc, proc->saved_exc_port);
493 if (proc->saved_exc_port)
494 mach_port_deallocate (mach_task_self (), proc->saved_exc_port);
495 proc->saved_exc_port = MACH_PORT_NULL;
498 proc->exc_port = MACH_PORT_NULL;
500 warning ("Error setting exception port for %s: %s",
501 proc_string (proc), safe_strerror (err));
506 /* Turns hardware tracing in PROC on or off when SET is true or false,
507 respectively. Returns true on success. */
509 proc_trace (struct proc *proc, int set)
511 thread_state_t state = proc_get_state (proc, 1);
514 return 0; /* the thread must be dead. */
516 proc_debug (proc, "tracing %s", set ? "on" : "off");
520 /* XXX We don't get the exception unless the thread has its own
521 exception port???? */
522 if (proc->exc_port == MACH_PORT_NULL)
523 proc_steal_exc_port (proc, proc->inf->event_port);
524 THREAD_STATE_SET_TRACED (state);
527 THREAD_STATE_CLEAR_TRACED (state);
533 /* A variable from which to assign new TIDs. */
534 static int next_thread_id = 1;
536 /* Returns a new proc structure with the given fields. Also adds a
537 notification for PORT becoming dead to be sent to INF's notify port. */
539 make_proc (struct inf *inf, mach_port_t port, int tid)
542 mach_port_t prev_port = MACH_PORT_NULL;
543 struct proc *proc = xmalloc (sizeof (struct proc));
549 proc->saved_exc_port = MACH_PORT_NULL;
550 proc->exc_port = MACH_PORT_NULL;
555 /* Note that these are all the values for threads; the task simply uses the
556 corresponding field in INF directly. */
557 proc->run_sc = inf->default_thread_run_sc;
558 proc->pause_sc = inf->default_thread_pause_sc;
559 proc->detach_sc = inf->default_thread_detach_sc;
560 proc->resume_sc = proc->run_sc;
564 proc->state_valid = 0;
565 proc->state_changed = 0;
567 proc_debug (proc, "is new");
569 /* Get notified when things die. */
571 mach_port_request_notification (mach_task_self (), port,
572 MACH_NOTIFY_DEAD_NAME, 1,
574 MACH_MSG_TYPE_MAKE_SEND_ONCE,
577 warning ("Couldn't request notification for port %d: %s",
578 port, safe_strerror (err));
581 proc_debug (proc, "notifications to: %d", inf->event_port);
582 if (prev_port != MACH_PORT_NULL)
583 mach_port_deallocate (mach_task_self (), prev_port);
586 if (inf->want_exceptions)
588 if (proc_is_task (proc))
589 /* Make the task exception port point to us. */
590 proc_steal_exc_port (proc, inf->event_port);
592 /* Just clear thread exception ports -- they default to the
594 proc_steal_exc_port (proc, MACH_PORT_NULL);
600 /* Frees PROC and any resources it uses, and returns the value of PROC's
603 _proc_free (struct proc *proc)
605 struct inf *inf = proc->inf;
606 struct proc *next = proc->next;
608 proc_debug (proc, "freeing...");
610 if (proc == inf->step_thread)
611 /* Turn off single stepping. */
612 inf_set_step_thread (inf, 0);
613 if (proc == inf->wait.thread)
614 inf_clear_wait (inf);
615 if (proc == inf->signal_thread)
616 inf->signal_thread = 0;
618 if (proc->port != MACH_PORT_NULL)
620 if (proc->exc_port != MACH_PORT_NULL)
621 /* Restore the original exception port. */
622 proc_restore_exc_port (proc);
623 if (proc->cur_sc != 0)
624 /* Resume the thread/task. */
627 proc_update_sc (proc);
629 mach_port_deallocate (mach_task_self (), proc->port);
640 struct inf *inf = xmalloc (sizeof (struct inf));
644 inf->threads_up_to_date = 0;
646 inf->wait.status.kind = TARGET_WAITKIND_SPURIOUS;
647 inf->wait.thread = 0;
648 inf->wait.exc.handler = MACH_PORT_NULL;
649 inf->wait.exc.reply = MACH_PORT_NULL;
650 inf->step_thread = 0;
651 inf->signal_thread = 0;
652 inf->event_port = MACH_PORT_NULL;
658 inf->pending_execs = 0;
661 inf->default_thread_run_sc = 0;
662 inf->default_thread_pause_sc = 0;
663 inf->default_thread_detach_sc = 0;
664 inf->want_signals = 1; /* By default */
665 inf->want_exceptions = 1; /* By default */
670 /* Clear INF's target wait status. */
672 inf_clear_wait (struct inf *inf)
674 inf_debug (inf, "clearing wait");
675 inf->wait.status.kind = TARGET_WAITKIND_SPURIOUS;
676 inf->wait.thread = 0;
677 inf->wait.suppress = 0;
678 if (inf->wait.exc.handler != MACH_PORT_NULL)
680 mach_port_deallocate (mach_task_self (), inf->wait.exc.handler);
681 inf->wait.exc.handler = MACH_PORT_NULL;
683 if (inf->wait.exc.reply != MACH_PORT_NULL)
685 mach_port_deallocate (mach_task_self (), inf->wait.exc.reply);
686 inf->wait.exc.reply = MACH_PORT_NULL;
692 inf_cleanup (struct inf *inf)
694 inf_debug (inf, "cleanup");
696 inf_clear_wait (inf);
698 inf_set_pid (inf, -1);
705 inf->pending_execs = 0;
709 mach_port_destroy (mach_task_self (), inf->event_port);
710 inf->event_port = MACH_PORT_NULL;
715 inf_startup (struct inf *inf, int pid)
719 inf_debug (inf, "startup: pid = %d", pid);
723 /* Make the port on which we receive all events. */
724 err = mach_port_allocate (mach_task_self (),
725 MACH_PORT_RIGHT_RECEIVE, &inf->event_port);
727 error ("Error allocating event port: %s", safe_strerror (err));
729 /* Make a send right for it, so we can easily copy it for other people. */
730 mach_port_insert_right (mach_task_self (), inf->event_port,
731 inf->event_port, MACH_MSG_TYPE_MAKE_SEND);
732 inf_set_pid (inf, pid);
736 /* Close current process, if any, and attach INF to process PORT. */
738 inf_set_pid (struct inf *inf, pid_t pid)
741 struct proc *task = inf->task;
743 inf_debug (inf, "setting pid: %d", pid);
746 task_port = MACH_PORT_NULL;
749 error_t err = proc_pid2task (proc_server, pid, &task_port);
751 error ("Error getting task for pid %d: %s", pid, safe_strerror (err));
754 inf_debug (inf, "setting task: %d", task_port);
757 task_suspend (task_port);
759 if (task && task->port != task_port)
762 inf_validate_procs (inf); /* Trash all the threads. */
763 _proc_free (task); /* And the task. */
766 if (task_port != MACH_PORT_NULL)
768 inf->task = make_proc (inf, task_port, PROC_TID_TASK);
769 inf->threads_up_to_date = 0;
776 /* Reflect task_suspend above. */
777 inf->task->sc = inf->task->cur_sc = 1;
784 /* Validates INF's stopped, nomsg and traced field from the actual
785 proc server state. Note that the traced field is only updated from
786 the proc server state if we do not have a message port. If we do
787 have a message port we'd better look at the tracemask itself. */
789 inf_validate_procinfo (struct inf *inf)
792 mach_msg_type_number_t noise_len = 0;
794 mach_msg_type_number_t pi_len = 0;
797 proc_getprocinfo (proc_server, inf->pid, &info_flags,
798 (procinfo_t *) &pi, &pi_len, &noise, &noise_len);
802 inf->stopped = !!(pi->state & PI_STOPPED);
803 inf->nomsg = !!(pi->state & PI_NOMSG);
805 inf->traced = !!(pi->state & PI_TRACED);
806 vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
808 vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
812 /* Validates INF's task suspend count. If it's higher than we expect,
813 verify with the user before `stealing' the extra count. */
815 inf_validate_task_sc (struct inf *inf)
818 mach_msg_type_number_t noise_len = 0;
820 mach_msg_type_number_t pi_len = 0;
821 int info_flags = PI_FETCH_TASKINFO;
822 int suspend_count = -1;
826 err = proc_getprocinfo (proc_server, inf->pid, &info_flags,
827 (procinfo_t *) &pi, &pi_len, &noise, &noise_len);
830 inf->task->dead = 1; /* oh well */
834 if (inf->task->cur_sc < pi->taskinfo.suspend_count && suspend_count == -1)
836 /* The proc server might have suspended the task while stopping
837 it. This happens when the task is handling a traced signal.
838 Refetch the suspend count. The proc server should be
839 finished stopping the task by now. */
840 suspend_count = pi->taskinfo.suspend_count;
844 suspend_count = pi->taskinfo.suspend_count;
846 vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
848 vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
850 if (inf->task->cur_sc < suspend_count)
854 target_terminal_ours (); /* Allow I/O. */
855 abort = !query ("Pid %d has an additional task suspend count of %d;"
856 " clear it? ", inf->pid,
857 suspend_count - inf->task->cur_sc);
858 target_terminal_inferior (); /* Give it back to the child. */
861 error ("Additional task suspend count left untouched.");
863 inf->task->cur_sc = suspend_count;
867 /* Turns tracing for INF on or off, depending on ON, unless it already
868 is. If INF is running, the resume_sc count of INF's threads will
869 be modified, and the signal thread will briefly be run to change
872 inf_set_traced (struct inf *inf, int on)
874 if (on == inf->traced)
877 if (inf->task && !inf->task->dead)
878 /* Make it take effect immediately. */
880 sigset_t mask = on ? ~(sigset_t) 0 : 0;
882 INF_RESUME_MSGPORT_RPC (inf, msg_set_init_int (msgport, refport,
883 INIT_TRACEMASK, mask));
887 warning ("Can't modify tracing state for pid %d: %s",
888 inf->pid, "No signal thread");
892 warning ("Can't modify tracing state for pid %d: %s",
893 inf->pid, safe_strerror (err));
902 /* Makes all the real suspend count deltas of all the procs in INF
903 match the desired values. Careful to always do thread/task suspend
904 counts in the safe order. Returns true if at least one thread is
905 thought to be running. */
907 inf_update_suspends (struct inf *inf)
909 struct proc *task = inf->task;
910 /* We don't have to update INF->threads even though we're iterating over it
911 because we'll change a thread only if it already has an existing proc
914 inf_debug (inf, "updating suspend counts");
919 int task_running = (task->sc == 0), thread_running = 0;
921 if (task->sc > task->cur_sc)
922 /* The task is becoming _more_ suspended; do before any threads. */
923 task_running = proc_update_sc (task);
925 if (inf->pending_execs)
926 /* When we're waiting for an exec, things may be happening behind our
927 back, so be conservative. */
930 /* Do all the thread suspend counts. */
931 for (thread = inf->threads; thread; thread = thread->next)
932 thread_running |= proc_update_sc (thread);
934 if (task->sc != task->cur_sc)
935 /* We didn't do the task first, because we wanted to wait for the
936 threads; do it now. */
937 task_running = proc_update_sc (task);
939 inf_debug (inf, "%srunning...",
940 (thread_running && task_running) ? "" : "not ");
942 inf->running = thread_running && task_running;
944 /* Once any thread has executed some code, we can't depend on the
945 threads list any more. */
947 inf->threads_up_to_date = 0;
956 /* Converts a GDB pid to a struct proc. */
958 inf_tid_to_thread (struct inf *inf, int tid)
960 struct proc *thread = inf->threads;
963 if (thread->tid == tid)
966 thread = thread->next;
970 /* Converts a thread port to a struct proc. */
972 inf_port_to_thread (struct inf *inf, mach_port_t port)
974 struct proc *thread = inf->threads;
976 if (thread->port == port)
979 thread = thread->next;
984 /* Make INF's list of threads be consistent with reality of TASK. */
986 inf_validate_procs (struct inf *inf)
988 thread_array_t threads;
989 mach_msg_type_number_t num_threads, i;
990 struct proc *task = inf->task;
992 /* If no threads are currently running, this function will guarantee that
993 things are up to date. The exception is if there are zero threads --
994 then it is almost certainly in an odd state, and probably some outside
995 agent will create threads. */
996 inf->threads_up_to_date = inf->threads ? !inf->running : 0;
1000 error_t err = task_threads (task->port, &threads, &num_threads);
1001 inf_debug (inf, "fetching threads");
1003 /* TASK must be dead. */
1013 inf_debug (inf, "no task");
1017 /* Make things normally linear. */
1018 mach_msg_type_number_t search_start = 0;
1019 /* Which thread in PROCS corresponds to each task thread, & the task. */
1020 struct proc *matched[num_threads + 1];
1021 /* The last thread in INF->threads, so we can add to the end. */
1022 struct proc *last = 0;
1023 /* The current thread we're considering. */
1024 struct proc *thread = inf->threads;
1026 bzero (matched, sizeof (matched));
1030 mach_msg_type_number_t left;
1032 for (i = search_start, left = num_threads; left; i++, left--)
1034 if (i >= num_threads)
1035 i -= num_threads; /* I wrapped around. */
1036 if (thread->port == threads[i])
1037 /* We already know about this thread. */
1039 matched[i] = thread;
1041 thread = thread->next;
1049 proc_debug (thread, "died!");
1050 thread->port = MACH_PORT_NULL;
1051 thread = _proc_free (thread); /* THREAD is dead. */
1052 (last ? last->next : inf->threads) = thread;
1056 for (i = 0; i < num_threads; i++)
1059 /* Throw away the duplicate send right. */
1060 mach_port_deallocate (mach_task_self (), threads[i]);
1062 /* THREADS[I] is a thread we don't know about yet! */
1064 thread = make_proc (inf, threads[i], next_thread_id++);
1065 (last ? last->next : inf->threads) = thread;
1067 proc_debug (thread, "new thread: %d", threads[i]);
1068 add_thread (pid_to_ptid (thread->tid)); /* Tell GDB's generic thread code. */
1072 vm_deallocate (mach_task_self (),
1073 (vm_address_t) threads, (num_threads * sizeof (thread_t)));
1078 /* Makes sure that INF's thread list is synced with the actual process. */
1080 inf_update_procs (struct inf *inf)
1084 if (!inf->threads_up_to_date)
1085 inf_validate_procs (inf);
1089 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1090 and others are set to their run_sc if RUN_OTHERS is true, and otherwise
1093 inf_set_threads_resume_sc (struct inf *inf,
1094 struct proc *run_thread, int run_others)
1096 struct proc *thread;
1097 inf_update_procs (inf);
1098 for (thread = inf->threads; thread; thread = thread->next)
1099 if (thread == run_thread)
1100 thread->resume_sc = 0;
1101 else if (run_others)
1102 thread->resume_sc = thread->run_sc;
1104 thread->resume_sc = thread->pause_sc;
1108 /* Cause INF to continue execution immediately; individual threads may still
1109 be suspended (but their suspend counts will be updated). */
1111 inf_resume (struct inf *inf)
1113 struct proc *thread;
1115 inf_update_procs (inf);
1117 for (thread = inf->threads; thread; thread = thread->next)
1118 thread->sc = thread->resume_sc;
1122 if (!inf->pending_execs)
1123 /* Try to make sure our task count is correct -- in the case where
1124 we're waiting for an exec though, things are too volatile, so just
1125 assume things will be reasonable (which they usually will be). */
1126 inf_validate_task_sc (inf);
1130 inf_update_suspends (inf);
1133 /* Cause INF to stop execution immediately; individual threads may still
1136 inf_suspend (struct inf *inf)
1138 struct proc *thread;
1140 inf_update_procs (inf);
1142 for (thread = inf->threads; thread; thread = thread->next)
1143 thread->sc = thread->pause_sc;
1146 inf->task->sc = inf->pause_sc;
1148 inf_update_suspends (inf);
1152 /* INF has one thread PROC that is in single-stepping mode. This
1153 function changes it to be PROC, changing any old step_thread to be
1154 a normal one. A PROC of 0 clears any existing value. */
1156 inf_set_step_thread (struct inf *inf, struct proc *thread)
1158 gdb_assert (!thread || proc_is_thread (thread));
1161 inf_debug (inf, "setting step thread: %d/%d", inf->pid, thread->tid);
1163 inf_debug (inf, "clearing step thread");
1165 if (inf->step_thread != thread)
1167 if (inf->step_thread && inf->step_thread->port != MACH_PORT_NULL)
1168 if (!proc_trace (inf->step_thread, 0))
1170 if (thread && proc_trace (thread, 1))
1171 inf->step_thread = thread;
1173 inf->step_thread = 0;
1178 /* Set up the thread resume_sc's so that only the signal thread is running
1179 (plus whatever other thread are set to always run). Returns true if we
1180 did so, or false if we can't find a signal thread. */
1182 inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
1184 if (inf->signal_thread)
1186 inf_set_threads_resume_sc (inf, inf->signal_thread, 0);
1194 inf_update_signal_thread (struct inf *inf)
1196 /* XXX for now we assume that if there's a msgport, the 2nd thread is
1197 the signal thread. */
1198 inf->signal_thread = inf->threads ? inf->threads->next : 0;
1202 /* Detachs from INF's inferior task, letting it run once again... */
1204 inf_detach (struct inf *inf)
1206 struct proc *task = inf->task;
1208 inf_debug (inf, "detaching...");
1210 inf_clear_wait (inf);
1211 inf_set_step_thread (inf, 0);
1215 struct proc *thread;
1217 inf_validate_procinfo (inf);
1219 inf_set_traced (inf, 0);
1225 inf_signal (inf, TARGET_SIGNAL_0);
1228 proc_restore_exc_port (task);
1229 task->sc = inf->detach_sc;
1231 for (thread = inf->threads; thread; thread = thread->next)
1233 proc_restore_exc_port (thread);
1234 thread->sc = thread->detach_sc;
1237 inf_update_suspends (inf);
1243 /* Attaches INF to the process with process id PID, returning it in a
1244 suspended state suitable for debugging. */
1246 inf_attach (struct inf *inf, int pid)
1248 inf_debug (inf, "attaching: %d", pid);
1253 inf_startup (inf, pid);
1257 /* Makes sure that we've got our exception ports entrenched in the process. */
1259 inf_steal_exc_ports (struct inf *inf)
1261 struct proc *thread;
1263 inf_debug (inf, "stealing exception ports");
1265 inf_set_step_thread (inf, 0); /* The step thread is special. */
1267 proc_steal_exc_port (inf->task, inf->event_port);
1268 for (thread = inf->threads; thread; thread = thread->next)
1269 proc_steal_exc_port (thread, MACH_PORT_NULL);
1272 /* Makes sure the process has its own exception ports. */
1274 inf_restore_exc_ports (struct inf *inf)
1276 struct proc *thread;
1278 inf_debug (inf, "restoring exception ports");
1280 inf_set_step_thread (inf, 0); /* The step thread is special. */
1282 proc_restore_exc_port (inf->task);
1283 for (thread = inf->threads; thread; thread = thread->next)
1284 proc_restore_exc_port (thread);
1288 /* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
1289 signal 0, will continue it. INF is assumed to be in a paused state, and
1290 the resume_sc's of INF's threads may be affected. */
1292 inf_signal (struct inf *inf, enum target_signal sig)
1295 int host_sig = target_signal_to_host (sig);
1297 #define NAME target_signal_to_name (sig)
1299 if (host_sig >= _NSIG)
1300 /* A mach exception. Exceptions are encoded in the signal space by
1301 putting them after _NSIG; this assumes they're positive (and not
1302 extremely large)! */
1304 struct inf_wait *w = &inf->wait;
1305 if (w->status.kind == TARGET_WAITKIND_STOPPED
1306 && w->status.value.sig == sig
1307 && w->thread && !w->thread->aborted)
1308 /* We're passing through the last exception we received. This is
1309 kind of bogus, because exceptions are per-thread whereas gdb
1310 treats signals as per-process. We just forward the exception to
1311 the correct handler, even it's not for the same thread as TID --
1312 i.e., we pretend it's global. */
1314 struct exc_state *e = &w->exc;
1315 inf_debug (inf, "passing through exception:"
1316 " task = %d, thread = %d, exc = %d"
1317 ", code = %d, subcode = %d",
1318 w->thread->port, inf->task->port,
1319 e->exception, e->code, e->subcode);
1321 exception_raise_request (e->handler,
1322 e->reply, MACH_MSG_TYPE_MOVE_SEND_ONCE,
1323 w->thread->port, inf->task->port,
1324 e->exception, e->code, e->subcode);
1327 error ("Can't forward spontaneous exception (%s).", NAME);
1330 /* A Unix signal. */
1332 /* The process is stopped and expecting a signal. Just send off a
1333 request and let it get handled when we resume everything. */
1335 inf_debug (inf, "sending %s to stopped process", NAME);
1337 INF_MSGPORT_RPC (inf,
1338 msg_sig_post_untraced_request (msgport,
1340 MACH_MSG_TYPE_MAKE_SEND_ONCE,
1344 /* Posting an untraced signal automatically continues it.
1345 We clear this here rather than when we get the reply
1346 because we'd rather assume it's not stopped when it
1347 actually is, than the reverse. */
1351 /* It's not expecting it. We have to let just the signal thread
1352 run, and wait for it to get into a reasonable state before we
1353 can continue the rest of the process. When we finally resume the
1354 process the signal we request will be the very first thing that
1357 inf_debug (inf, "sending %s to unstopped process"
1358 " (so resuming signal thread)", NAME);
1360 INF_RESUME_MSGPORT_RPC (inf,
1361 msg_sig_post_untraced (msgport, host_sig,
1366 /* Can't do too much... */
1367 warning ("Can't deliver signal %s: No signal thread.", NAME);
1369 warning ("Delivering signal %s: %s", NAME, safe_strerror (err));
1375 /* Continue INF without delivering a signal. This is meant to be used
1376 when INF does not have a message port. */
1378 inf_continue (struct inf *inf)
1381 error_t err = proc_pid2proc (proc_server, inf->pid, &proc);
1385 inf_debug (inf, "continuing process");
1387 err = proc_mark_cont (proc);
1390 struct proc *thread;
1392 for (thread = inf->threads; thread; thread = thread->next)
1393 thread_resume (thread->port);
1400 warning ("Can't continue process: %s", safe_strerror (err));
1404 /* The inferior used for all gdb target ops. */
1405 struct inf *current_inferior = 0;
1407 /* The inferior being waited for by gnu_wait. Since GDB is decidely not
1408 multi-threaded, we don't bother to lock this. */
1409 struct inf *waiting_inf;
1411 /* Wait for something to happen in the inferior, returning what in STATUS. */
1413 gnu_wait (ptid_t tid, struct target_waitstatus *status)
1417 mach_msg_header_t hdr;
1418 mach_msg_type_t type;
1422 struct proc *thread;
1423 struct inf *inf = current_inferior;
1425 extern int exc_server (mach_msg_header_t *, mach_msg_header_t *);
1426 extern int msg_reply_server (mach_msg_header_t *, mach_msg_header_t *);
1427 extern int notify_server (mach_msg_header_t *, mach_msg_header_t *);
1428 extern int process_reply_server (mach_msg_header_t *, mach_msg_header_t *);
1430 gdb_assert (inf->task);
1432 if (!inf->threads && !inf->pending_execs)
1433 /* No threads! Assume that maybe some outside agency is frobbing our
1434 task, and really look for new threads. If we can't find any, just tell
1435 the user to try again later. */
1437 inf_validate_procs (inf);
1438 if (!inf->threads && !inf->task->dead)
1439 error ("There are no threads; try again later.");
1444 inf_debug (inf, "waiting for: %d", PIDGET (tid));
1447 if (proc_wait_pid != inf->pid && !inf->no_wait)
1448 /* Always get information on events from the proc server. */
1450 inf_debug (inf, "requesting wait on pid %d", inf->pid);
1453 /* The proc server is single-threaded, and only allows a single
1454 outstanding wait request, so we have to cancel the previous one. */
1456 inf_debug (inf, "cancelling previous wait on pid %d", proc_wait_pid);
1457 interrupt_operation (proc_server, 0);
1461 proc_wait_request (proc_server, inf->event_port, inf->pid, WUNTRACED);
1463 warning ("wait request failed: %s", safe_strerror (err));
1466 inf_debug (inf, "waits pending: %d", proc_waits_pending);
1467 proc_wait_pid = inf->pid;
1468 /* Even if proc_waits_pending was > 0 before, we still won't
1469 get any other replies, because it was either from a
1470 different INF, or a different process attached to INF --
1471 and the event port, which is the wait reply port, changes
1472 when you switch processes. */
1473 proc_waits_pending = 1;
1477 inf_clear_wait (inf);
1479 /* What can happen? (1) Dead name notification; (2) Exceptions arrive;
1480 (3) wait reply from the proc server. */
1482 inf_debug (inf, "waiting for an event...");
1483 err = mach_msg (&msg.hdr, MACH_RCV_MSG | MACH_RCV_INTERRUPT,
1484 0, sizeof (struct msg), inf->event_port,
1485 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
1487 /* Re-suspend the task. */
1490 if (!inf->task && inf->pending_execs)
1491 /* When doing an exec, it's possible that the old task wasn't reused
1492 (e.g., setuid execs). So if the task seems to have disappeared,
1493 attempt to refetch it, as the pid should still be the same. */
1494 inf_set_pid (inf, inf->pid);
1496 if (err == EMACH_RCV_INTERRUPTED)
1497 inf_debug (inf, "interrupted");
1499 error ("Couldn't wait for an event: %s", safe_strerror (err));
1504 mach_msg_header_t hdr;
1505 mach_msg_type_t err_type;
1511 inf_debug (inf, "event: msgid = %d", msg.hdr.msgh_id);
1513 /* Handle what we got. */
1514 if (!notify_server (&msg.hdr, &reply.hdr)
1515 && !exc_server (&msg.hdr, &reply.hdr)
1516 && !process_reply_server (&msg.hdr, &reply.hdr)
1517 && !msg_reply_server (&msg.hdr, &reply.hdr))
1518 /* Whatever it is, it's something strange. */
1519 error ("Got a strange event, msg id = %d.", msg.hdr.msgh_id);
1522 error ("Handling event, msgid = %d: %s",
1523 msg.hdr.msgh_id, safe_strerror (reply.err));
1526 if (inf->pending_execs)
1527 /* We're waiting for the inferior to finish execing. */
1529 struct inf_wait *w = &inf->wait;
1530 enum target_waitkind kind = w->status.kind;
1532 if (kind == TARGET_WAITKIND_SPURIOUS)
1533 /* Since gdb is actually counting the number of times the inferior
1534 stops, expecting one stop per exec, we only return major events
1538 inf_debug (inf, "pending_execs = %d, ignoring minor event",
1539 inf->pending_execs);
1541 else if (kind == TARGET_WAITKIND_STOPPED
1542 && w->status.value.sig == TARGET_SIGNAL_TRAP)
1543 /* Ah hah! A SIGTRAP from the inferior while starting up probably
1544 means we've succesfully completed an exec! */
1546 if (--inf->pending_execs == 0)
1549 #if 0 /* do we need this? */
1550 prune_threads (1); /* Get rid of the old shell threads */
1551 renumber_threads (0); /* Give our threads reasonable names. */
1554 inf_debug (inf, "pending exec completed, pending_execs => %d",
1555 inf->pending_execs);
1557 else if (kind == TARGET_WAITKIND_STOPPED)
1558 /* It's possible that this signal is because of a crashed process
1559 being handled by the hurd crash server; in this case, the process
1560 will have an extra task suspend, which we need to know about.
1561 Since the code in inf_resume that normally checks for this is
1562 disabled while INF->pending_execs, we do the check here instead. */
1563 inf_validate_task_sc (inf);
1566 if (inf->wait.suppress)
1567 /* Some totally spurious event happened that we don't consider
1568 worth returning to gdb. Just keep waiting. */
1570 inf_debug (inf, "suppressing return, rewaiting...");
1575 /* Pass back out our results. */
1576 bcopy (&inf->wait.status, status, sizeof (*status));
1578 thread = inf->wait.thread;
1580 tid = pid_to_ptid (thread->tid);
1582 thread = inf_tid_to_thread (inf, PIDGET (tid));
1584 if (!thread || thread->port == MACH_PORT_NULL)
1586 /* TID is dead; try and find a new thread. */
1587 if (inf_update_procs (inf) && inf->threads)
1588 tid = pid_to_ptid (inf->threads->tid); /* The first available thread. */
1590 tid = inferior_ptid; /* let wait_for_inferior handle exit case */
1593 if (thread && PIDGET (tid) >= 0 && status->kind != TARGET_WAITKIND_SPURIOUS
1594 && inf->pause_sc == 0 && thread->pause_sc == 0)
1595 /* If something actually happened to THREAD, make sure we
1599 inf_update_suspends (inf);
1602 inf_debug (inf, "returning tid = %d, status = %s (%d)", PIDGET (tid),
1603 status->kind == TARGET_WAITKIND_EXITED ? "EXITED"
1604 : status->kind == TARGET_WAITKIND_STOPPED ? "STOPPED"
1605 : status->kind == TARGET_WAITKIND_SIGNALLED ? "SIGNALLED"
1606 : status->kind == TARGET_WAITKIND_LOADED ? "LOADED"
1607 : status->kind == TARGET_WAITKIND_SPURIOUS ? "SPURIOUS"
1609 status->value.integer);
1615 /* The rpc handler called by exc_server. */
1617 S_exception_raise_request (mach_port_t port, mach_port_t reply_port,
1618 thread_t thread_port, task_t task_port,
1619 int exception, int code, int subcode)
1621 struct inf *inf = waiting_inf;
1622 struct proc *thread = inf_port_to_thread (inf, thread_port);
1624 inf_debug (waiting_inf,
1625 "thread = %d, task = %d, exc = %d, code = %d, subcode = %d",
1626 thread_port, task_port, exception, code, subcode);
1629 /* We don't know about thread? */
1631 inf_update_procs (inf);
1632 thread = inf_port_to_thread (inf, thread_port);
1634 /* Give up, the generating thread is gone. */
1638 mach_port_deallocate (mach_task_self (), thread_port);
1639 mach_port_deallocate (mach_task_self (), task_port);
1641 if (!thread->aborted)
1642 /* THREAD hasn't been aborted since this exception happened (abortion
1643 clears any exception state), so it must be real. */
1645 /* Store away the details; this will destroy any previous info. */
1646 inf->wait.thread = thread;
1648 inf->wait.status.kind = TARGET_WAITKIND_STOPPED;
1650 if (exception == EXC_BREAKPOINT)
1651 /* GDB likes to get SIGTRAP for breakpoints. */
1653 inf->wait.status.value.sig = TARGET_SIGNAL_TRAP;
1654 mach_port_deallocate (mach_task_self (), reply_port);
1657 /* Record the exception so that we can forward it later. */
1659 if (thread->exc_port == port)
1661 inf_debug (waiting_inf, "Handler is thread exception port <%d>",
1662 thread->saved_exc_port);
1663 inf->wait.exc.handler = thread->saved_exc_port;
1667 inf_debug (waiting_inf, "Handler is task exception port <%d>",
1668 inf->task->saved_exc_port);
1669 inf->wait.exc.handler = inf->task->saved_exc_port;
1670 gdb_assert (inf->task->exc_port == port);
1672 if (inf->wait.exc.handler != MACH_PORT_NULL)
1673 /* Add a reference to the exception handler. */
1674 mach_port_mod_refs (mach_task_self (),
1675 inf->wait.exc.handler, MACH_PORT_RIGHT_SEND,
1678 inf->wait.exc.exception = exception;
1679 inf->wait.exc.code = code;
1680 inf->wait.exc.subcode = subcode;
1681 inf->wait.exc.reply = reply_port;
1683 /* Exceptions are encoded in the signal space by putting them after
1684 _NSIG; this assumes they're positive (and not extremely large)! */
1685 inf->wait.status.value.sig =
1686 target_signal_from_host (_NSIG + exception);
1690 /* A supppressed exception, which ignore. */
1692 inf->wait.suppress = 1;
1693 mach_port_deallocate (mach_task_self (), reply_port);
1700 /* Fill in INF's wait field after a task has died without giving us more
1701 detailed information. */
1703 inf_task_died_status (struct inf *inf)
1705 warning ("Pid %d died with unknown exit status, using SIGKILL.", inf->pid);
1706 inf->wait.status.kind = TARGET_WAITKIND_SIGNALLED;
1707 inf->wait.status.value.sig = TARGET_SIGNAL_KILL;
1710 /* Notify server routines. The only real one is dead name notification. */
1712 do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_port)
1714 struct inf *inf = waiting_inf;
1716 inf_debug (waiting_inf, "port = %d", dead_port);
1718 if (inf->task && inf->task->port == dead_port)
1720 proc_debug (inf->task, "is dead");
1721 inf->task->port = MACH_PORT_NULL;
1722 if (proc_wait_pid == inf->pid)
1723 /* We have a wait outstanding on the process, which will return more
1724 detailed information, so delay until we get that. */
1725 inf->wait.suppress = 1;
1727 /* We never waited for the process (maybe it wasn't a child), so just
1728 pretend it got a SIGKILL. */
1729 inf_task_died_status (inf);
1733 struct proc *thread = inf_port_to_thread (inf, dead_port);
1736 proc_debug (thread, "is dead");
1737 thread->port = MACH_PORT_NULL;
1740 if (inf->task->dead)
1741 /* Since the task is dead, its threads are dying with it. */
1742 inf->wait.suppress = 1;
1745 mach_port_deallocate (mach_task_self (), dead_port);
1746 inf->threads_up_to_date = 0; /* Just in case */
1755 warning ("illegal rpc: %s", fun);
1760 do_mach_notify_no_senders (mach_port_t notify, mach_port_mscount_t count)
1762 return ill_rpc ("do_mach_notify_no_senders");
1766 do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
1768 return ill_rpc ("do_mach_notify_port_deleted");
1772 do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
1774 return ill_rpc ("do_mach_notify_msg_accepted");
1778 do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t name)
1780 return ill_rpc ("do_mach_notify_port_destroyed");
1784 do_mach_notify_send_once (mach_port_t notify)
1786 return ill_rpc ("do_mach_notify_send_once");
1790 /* Process_reply server routines. We only use process_wait_reply. */
1793 S_proc_wait_reply (mach_port_t reply, error_t err,
1794 int status, int sigcode, rusage_t rusage, pid_t pid)
1796 struct inf *inf = waiting_inf;
1798 inf_debug (inf, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1799 err ? safe_strerror (err) : "0", pid, status, sigcode);
1801 if (err && proc_wait_pid && (!inf->task || !inf->task->port))
1802 /* Ack. The task has died, but the task-died notification code didn't
1803 tell anyone because it thought a more detailed reply from the
1804 procserver was forthcoming. However, we now learn that won't
1805 happen... So we have to act like the task just died, and this time,
1807 inf_task_died_status (inf);
1809 if (--proc_waits_pending == 0)
1810 /* PROC_WAIT_PID represents the most recent wait. We will always get
1811 replies in order because the proc server is single threaded. */
1814 inf_debug (inf, "waits pending now: %d", proc_waits_pending);
1820 warning ("Can't wait for pid %d: %s", inf->pid, safe_strerror (err));
1823 /* Since we can't see the inferior's signals, don't trap them. */
1824 inf_set_traced (inf, 0);
1827 else if (pid == inf->pid)
1829 store_waitstatus (&inf->wait.status, status);
1830 if (inf->wait.status.kind == TARGET_WAITKIND_STOPPED)
1831 /* The process has sent us a signal, and stopped itself in a sane
1832 state pending our actions. */
1834 inf_debug (inf, "process has stopped itself");
1839 inf->wait.suppress = 1; /* Something odd happened. Ignore. */
1845 S_proc_setmsgport_reply (mach_port_t reply, error_t err,
1846 mach_port_t old_msg_port)
1848 return ill_rpc ("S_proc_setmsgport_reply");
1852 S_proc_getmsgport_reply (mach_port_t reply, error_t err, mach_port_t msg_port)
1854 return ill_rpc ("S_proc_getmsgport_reply");
1858 /* Msg_reply server routines. We only use msg_sig_post_untraced_reply. */
1861 S_msg_sig_post_untraced_reply (mach_port_t reply, error_t err)
1863 struct inf *inf = waiting_inf;
1866 /* EBUSY is what we get when the crash server has grabbed control of the
1867 process and doesn't like what signal we tried to send it. Just act
1868 like the process stopped (using a signal of 0 should mean that the
1869 *next* time the user continues, it will pass signal 0, which the crash
1870 server should like). */
1872 inf->wait.status.kind = TARGET_WAITKIND_STOPPED;
1873 inf->wait.status.value.sig = TARGET_SIGNAL_0;
1876 warning ("Signal delivery failed: %s", safe_strerror (err));
1879 /* We only get this reply when we've posted a signal to a process which we
1880 thought was stopped, and which we expected to continue after the signal.
1881 Given that the signal has failed for some reason, it's reasonable to
1882 assume it's still stopped. */
1885 inf->wait.suppress = 1;
1891 S_msg_sig_post_reply (mach_port_t reply, error_t err)
1893 return ill_rpc ("S_msg_sig_post_reply");
1897 /* Returns the number of messages queued for the receive right PORT. */
1898 static mach_port_msgcount_t
1899 port_msgs_queued (mach_port_t port)
1901 struct mach_port_status status;
1903 mach_port_get_receive_status (mach_task_self (), port, &status);
1908 return status.mps_msgcount;
1912 /* Resume execution of the inferior process.
1914 If STEP is nonzero, single-step it.
1915 If SIGNAL is nonzero, give it that signal.
1918 -1 true Single step the current thread allowing other threads to run.
1919 -1 false Continue the current thread allowing other threads to run.
1920 X true Single step the given thread, don't allow any others to run.
1921 X false Continue the given thread, do not allow any others to run.
1922 (Where X, of course, is anything except -1)
1924 Note that a resume may not `take' if there are pending exceptions/&c
1925 still unprocessed from the last resume we did (any given resume may result
1926 in multiple events returned by wait).
1929 gnu_resume (ptid_t tid, int step, enum target_signal sig)
1931 struct proc *step_thread = 0;
1932 struct inf *inf = current_inferior;
1934 inf_debug (inf, "tid = %d, step = %d, sig = %d", PIDGET (tid), step, sig);
1936 inf_validate_procinfo (inf);
1938 if (sig != TARGET_SIGNAL_0 || inf->stopped)
1940 if (sig == TARGET_SIGNAL_0 && inf->nomsg)
1943 inf_signal (inf, sig);
1945 else if (inf->wait.exc.reply != MACH_PORT_NULL)
1946 /* We received an exception to which we have chosen not to forward, so
1947 abort the faulting thread, which will perhaps retake it. */
1949 proc_abort (inf->wait.thread, 1);
1950 warning ("Aborting %s with unforwarded exception %s.",
1951 proc_string (inf->wait.thread),
1952 target_signal_to_name (inf->wait.status.value.sig));
1955 if (port_msgs_queued (inf->event_port))
1956 /* If there are still messages in our event queue, don't bother resuming
1957 the process, as we're just going to stop it right away anyway. */
1960 inf_update_procs (inf);
1962 if (PIDGET (tid) < 0)
1963 /* Allow all threads to run, except perhaps single-stepping one. */
1965 inf_debug (inf, "running all threads; tid = %d", PIDGET (inferior_ptid));
1966 tid = inferior_ptid; /* What to step. */
1967 inf_set_threads_resume_sc (inf, 0, 1);
1970 /* Just allow a single thread to run. */
1972 struct proc *thread = inf_tid_to_thread (inf, PIDGET (tid));
1974 error ("Can't run single thread id %d: no such thread!");
1975 inf_debug (inf, "running one thread: %d/%d", inf->pid, thread->tid);
1976 inf_set_threads_resume_sc (inf, thread, 0);
1981 step_thread = inf_tid_to_thread (inf, PIDGET (tid));
1983 warning ("Can't step thread id %d: no such thread.", PIDGET (tid));
1985 inf_debug (inf, "stepping thread: %d/%d", inf->pid, step_thread->tid);
1987 if (step_thread != inf->step_thread)
1988 inf_set_step_thread (inf, step_thread);
1990 inf_debug (inf, "here we go...");
1996 gnu_kill_inferior (void)
1998 struct proc *task = current_inferior->task;
2001 proc_debug (task, "terminating...");
2002 task_terminate (task->port);
2003 inf_set_pid (current_inferior, -1);
2005 target_mourn_inferior ();
2008 /* Clean up after the inferior dies. */
2010 gnu_mourn_inferior (void)
2012 inf_debug (current_inferior, "rip");
2013 inf_detach (current_inferior);
2014 unpush_target (&gnu_ops);
2015 generic_mourn_inferior ();
2019 /* Fork an inferior process, and start debugging it. */
2021 /* Set INFERIOR_PID to the first thread available in the child, if any. */
2023 inf_pick_first_thread (void)
2025 if (current_inferior->task && current_inferior->threads)
2026 /* The first thread. */
2027 return current_inferior->threads->tid;
2029 /* What may be the next thread. */
2030 return next_thread_id;
2036 if (!current_inferior)
2037 current_inferior = make_inf ();
2038 return current_inferior;
2042 gnu_create_inferior (char *exec_file, char *allargs, char **env)
2044 struct inf *inf = cur_inf ();
2048 /* We're in the child; make this process stop as soon as it execs. */
2049 inf_debug (inf, "tracing self");
2050 if (ptrace (PTRACE_TRACEME) != 0)
2051 error ("ptrace (PTRACE_TRACEME) failed!");
2053 void attach_to_child (int pid)
2055 /* Attach to the now stopped child, which is actually a shell... */
2056 inf_debug (inf, "attaching to child: %d", pid);
2058 inf_attach (inf, pid);
2061 push_target (&gnu_ops);
2063 inf->pending_execs = 2;
2067 /* Now let the child run again, knowing that it will stop immediately
2068 because of the ptrace. */
2070 inferior_ptid = pid_to_ptid (inf_pick_first_thread ());
2072 startup_inferior (inf->pending_execs);
2075 inf_debug (inf, "creating inferior");
2077 fork_inferior (exec_file, allargs, env, trace_me, attach_to_child,
2080 inf_validate_procinfo (inf);
2081 inf_update_signal_thread (inf);
2082 inf_set_traced (inf, inf->want_signals);
2084 /* Execing the process will have trashed our exception ports; steal them
2085 back (or make sure they're restored if the user wants that). */
2086 if (inf->want_exceptions)
2087 inf_steal_exc_ports (inf);
2089 inf_restore_exc_ports (inf);
2092 proceed ((CORE_ADDR) -1, 0, 0);
2095 /* Mark our target-struct as eligible for stray "run" and "attach"
2104 #ifdef ATTACH_DETACH
2106 /* Attach to process PID, then initialize for debugging it
2107 and wait for the trace-trap that results from attaching. */
2109 gnu_attach (char *args, int from_tty)
2113 struct inf *inf = cur_inf ();
2116 error_no_arg ("process-id to attach");
2120 if (pid == getpid ()) /* Trying to masturbate? */
2121 error ("I refuse to debug myself!");
2125 exec_file = (char *) get_exec_file (0);
2128 printf_unfiltered ("Attaching to program `%s', pid %d\n",
2131 printf_unfiltered ("Attaching to pid %d\n", pid);
2133 gdb_flush (gdb_stdout);
2136 inf_debug (inf, "attaching to pid: %d", pid);
2138 inf_attach (inf, pid);
2139 inf_update_procs (inf);
2141 inferior_ptid = pid_to_ptid (inf_pick_first_thread ());
2144 push_target (&gnu_ops);
2146 /* We have to initialize the terminal settings now, since the code
2147 below might try to restore them. */
2148 target_terminal_init ();
2150 /* If the process was stopped before we attached, make it continue the next
2151 time the user does a continue. */
2152 inf_validate_procinfo (inf);
2154 inf_update_signal_thread (inf);
2155 inf_set_traced (inf, inf->want_signals);
2157 #if 0 /* Do we need this? */
2158 renumber_threads (0); /* Give our threads reasonable names. */
2163 /* Take a program previously attached to and detaches it.
2164 The program resumes execution and will no longer stop
2165 on signals, etc. We'd better not have left any breakpoints
2166 in the program or it'll die when it hits one. For this
2167 to work, it may be necessary for the process to have been
2168 previously attached. It *might* work if the program was
2169 started via fork. */
2171 gnu_detach (char *args, int from_tty)
2175 char *exec_file = get_exec_file (0);
2177 printf_unfiltered ("Detaching from program `%s' pid %d\n",
2178 exec_file, current_inferior->pid);
2180 printf_unfiltered ("Detaching from pid %d\n", current_inferior->pid);
2181 gdb_flush (gdb_stdout);
2184 inf_detach (current_inferior);
2186 inferior_ptid = null_ptid;
2188 unpush_target (&gnu_ops); /* Pop out of handling an inferior */
2190 #endif /* ATTACH_DETACH */
2194 gnu_terminal_init_inferior (void)
2196 gdb_assert (current_inferior);
2197 terminal_init_inferior_with_pgrp (current_inferior->pid);
2200 /* Get ready to modify the registers array. On machines which store
2201 individual registers, this doesn't need to do anything. On machines
2202 which store all the registers in one fell swoop, this makes sure
2203 that registers contains all the registers from the program being
2206 gnu_prepare_to_store (void)
2208 #ifdef CHILD_PREPARE_TO_STORE
2209 CHILD_PREPARE_TO_STORE ();
2214 gnu_open (char *arg, int from_tty)
2216 error ("Use the \"run\" command to start a Unix child process.");
2222 error ("to_stop target function not implemented");
2226 gnu_pid_to_exec_file (int pid)
2228 error ("to_pid_to_exec_file target function not implemented");
2234 gnu_thread_alive (ptid_t tid)
2236 inf_update_procs (current_inferior);
2237 return !!inf_tid_to_thread (current_inferior, PIDGET (tid));
2241 /* Read inferior task's LEN bytes from ADDR and copy it to MYADDR in
2242 gdb's address space. Return 0 on failure; number of bytes read
2245 gnu_read_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
2248 vm_address_t low_address = (vm_address_t) trunc_page (addr);
2249 vm_size_t aligned_length =
2250 (vm_size_t) round_page (addr + length) - low_address;
2254 /* Get memory from inferior with page aligned addresses */
2255 err = vm_read (task, low_address, aligned_length, &copied, ©_count);
2259 err = hurd_safe_copyin (myaddr, (void *) addr - low_address + copied, length);
2262 warning ("Read from inferior faulted: %s", safe_strerror (err));
2266 err = vm_deallocate (mach_task_self (), copied, copy_count);
2268 warning ("gnu_read_inferior vm_deallocate failed: %s", safe_strerror (err));
2273 #define CHK_GOTO_OUT(str,ret) \
2274 do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
2276 struct vm_region_list
2278 struct vm_region_list *next;
2279 vm_prot_t protection;
2284 struct obstack region_obstack;
2286 /* Write gdb's LEN bytes from MYADDR and copy it to ADDR in inferior
2287 task's address space. */
2289 gnu_write_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
2292 vm_address_t low_address = (vm_address_t) trunc_page (addr);
2293 vm_size_t aligned_length =
2294 (vm_size_t) round_page (addr + length) - low_address;
2299 char *errstr = "Bug in gnu_write_inferior";
2301 struct vm_region_list *region_element;
2302 struct vm_region_list *region_head = (struct vm_region_list *) NULL;
2304 /* Get memory from inferior with page aligned addresses */
2305 err = vm_read (task,
2310 CHK_GOTO_OUT ("gnu_write_inferior vm_read failed", err);
2314 err = hurd_safe_copyout ((void *) addr - low_address + copied,
2316 CHK_GOTO_OUT ("Write to inferior faulted", err);
2318 obstack_init (®ion_obstack);
2320 /* Do writes atomically.
2321 First check for holes and unwritable memory. */
2323 vm_size_t remaining_length = aligned_length;
2324 vm_address_t region_address = low_address;
2326 struct vm_region_list *scan;
2328 while (region_address < low_address + aligned_length)
2330 vm_prot_t protection;
2331 vm_prot_t max_protection;
2332 vm_inherit_t inheritance;
2334 mach_port_t object_name;
2336 vm_size_t region_length = remaining_length;
2337 vm_address_t old_address = region_address;
2339 err = vm_region (task,
2348 CHK_GOTO_OUT ("vm_region failed", err);
2350 /* Check for holes in memory */
2351 if (old_address != region_address)
2353 warning ("No memory at 0x%x. Nothing written",
2360 if (!(max_protection & VM_PROT_WRITE))
2362 warning ("Memory at address 0x%x is unwritable. Nothing written",
2369 /* Chain the regions for later use */
2371 (struct vm_region_list *)
2372 obstack_alloc (®ion_obstack, sizeof (struct vm_region_list));
2374 region_element->protection = protection;
2375 region_element->start = region_address;
2376 region_element->length = region_length;
2378 /* Chain the regions along with protections */
2379 region_element->next = region_head;
2380 region_head = region_element;
2382 region_address += region_length;
2383 remaining_length = remaining_length - region_length;
2386 /* If things fail after this, we give up.
2387 Somebody is messing up inferior_task's mappings. */
2389 /* Enable writes to the chained vm regions */
2390 for (scan = region_head; scan; scan = scan->next)
2392 if (!(scan->protection & VM_PROT_WRITE))
2394 err = vm_protect (task,
2398 scan->protection | VM_PROT_WRITE);
2399 CHK_GOTO_OUT ("vm_protect: enable write failed", err);
2403 err = vm_write (task,
2407 CHK_GOTO_OUT ("vm_write failed", err);
2409 /* Set up the original region protections, if they were changed */
2410 for (scan = region_head; scan; scan = scan->next)
2412 if (!(scan->protection & VM_PROT_WRITE))
2414 err = vm_protect (task,
2419 CHK_GOTO_OUT ("vm_protect: enable write failed", err);
2427 obstack_free (®ion_obstack, 0);
2429 (void) vm_deallocate (mach_task_self (),
2434 if (err != KERN_SUCCESS)
2436 warning ("%s: %s", errstr, mach_error_string (err));
2444 /* Return 0 on failure, number of bytes handled otherwise. TARGET
2447 gnu_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
2448 struct mem_attrib *attrib,
2449 struct target_ops *target)
2451 task_t task = (current_inferior
2452 ? (current_inferior->task
2453 ? current_inferior->task->port : 0)
2456 if (task == MACH_PORT_NULL)
2460 inf_debug (current_inferior, "%s %p[%d] %s %p",
2461 write ? "writing" : "reading", (void *) memaddr, len,
2462 write ? "<--" : "-->", myaddr);
2464 return gnu_write_inferior (task, memaddr, myaddr, len);
2466 return gnu_read_inferior (task, memaddr, myaddr, len);
2470 /* Call FUNC on each memory region in the task. */
2472 gnu_find_memory_regions (int (*func) (CORE_ADDR,
2480 vm_address_t region_address, last_region_address, last_region_end;
2481 vm_prot_t last_protection;
2483 if (current_inferior == 0 || current_inferior->task == 0)
2485 task = current_inferior->task->port;
2486 if (task == MACH_PORT_NULL)
2489 region_address = last_region_address = last_region_end = VM_MIN_ADDRESS;
2490 last_protection = VM_PROT_NONE;
2491 while (region_address < VM_MAX_ADDRESS)
2493 vm_prot_t protection;
2494 vm_prot_t max_protection;
2495 vm_inherit_t inheritance;
2497 mach_port_t object_name;
2499 vm_size_t region_length = VM_MAX_ADDRESS - region_address;
2500 vm_address_t old_address = region_address;
2502 err = vm_region (task,
2511 if (err == KERN_NO_SPACE)
2513 if (err != KERN_SUCCESS)
2515 warning ("vm_region failed: %s", mach_error_string (err));
2519 if (protection == last_protection && region_address == last_region_end)
2520 /* This region is contiguous with and indistinguishable from
2521 the previous one, so we just extend that one. */
2522 last_region_end = region_address += region_length;
2525 /* This region is distinct from the last one we saw, so report
2526 that previous one. */
2527 if (last_protection != VM_PROT_NONE)
2528 (*func) (last_region_address,
2529 last_region_end - last_region_address,
2530 last_protection & VM_PROT_READ,
2531 last_protection & VM_PROT_WRITE,
2532 last_protection & VM_PROT_EXECUTE,
2534 last_region_address = region_address;
2535 last_region_end = region_address += region_length;
2536 last_protection = protection;
2540 /* Report the final region. */
2541 if (last_region_end > last_region_address && last_protection != VM_PROT_NONE)
2542 (*func) (last_region_address, last_region_end - last_region_address,
2543 last_protection & VM_PROT_READ,
2544 last_protection & VM_PROT_WRITE,
2545 last_protection & VM_PROT_EXECUTE,
2552 /* Return printable description of proc. */
2554 proc_string (struct proc *proc)
2556 static char tid_str[80];
2557 if (proc_is_task (proc))
2558 sprintf (tid_str, "process %d", proc->inf->pid);
2560 sprintf (tid_str, "thread %d.%d",
2561 proc->inf->pid, pid_to_thread_id (MERGEPID (proc->tid, 0)));
2566 gnu_pid_to_str (ptid_t ptid)
2568 struct inf *inf = current_inferior;
2569 int tid = PIDGET (ptid);
2570 struct proc *thread = inf_tid_to_thread (inf, tid);
2573 return proc_string (thread);
2576 static char tid_str[80];
2577 sprintf (tid_str, "bogus thread id %d", tid);
2583 extern void gnu_store_registers (int regno);
2584 extern void gnu_fetch_registers (int regno);
2586 struct target_ops gnu_ops;
2591 gnu_ops.to_shortname = "GNU"; /* to_shortname */
2592 gnu_ops.to_longname = "GNU Hurd process"; /* to_longname */
2593 gnu_ops.to_doc = "GNU Hurd process"; /* to_doc */
2594 gnu_ops.to_open = gnu_open; /* to_open */
2595 gnu_ops.to_close = 0; /* to_close */
2596 gnu_ops.to_attach = gnu_attach; /* to_attach */
2597 gnu_ops.to_post_attach = NULL;
2598 gnu_ops.to_require_attach = NULL; /* to_require_attach */
2599 gnu_ops.to_detach = gnu_detach; /* to_detach */
2600 gnu_ops.to_require_detach = NULL; /* to_require_detach */
2601 gnu_ops.to_resume = gnu_resume; /* to_resume */
2602 gnu_ops.to_wait = gnu_wait; /* to_wait */
2603 gnu_ops.to_post_wait = NULL; /* to_post_wait */
2604 gnu_ops.to_fetch_registers = gnu_fetch_registers; /* to_fetch_registers */
2605 gnu_ops.to_store_registers = gnu_store_registers; /* to_store_registers */
2606 gnu_ops.to_prepare_to_store = gnu_prepare_to_store; /* to_prepare_to_store */
2607 gnu_ops.to_xfer_memory = gnu_xfer_memory; /* to_xfer_memory */
2608 gnu_ops.to_find_memory_regions = gnu_find_memory_regions;
2609 gnu_ops.to_files_info = 0; /* to_files_info */
2610 gnu_ops.to_insert_breakpoint = memory_insert_breakpoint;
2611 gnu_ops.to_remove_breakpoint = memory_remove_breakpoint;
2612 gnu_ops.to_terminal_init = gnu_terminal_init_inferior;
2613 gnu_ops.to_terminal_inferior = terminal_inferior;
2614 gnu_ops.to_terminal_ours_for_output = terminal_ours_for_output;
2615 gnu_ops.to_terminal_save_ours = terminal_save_ours;
2616 gnu_ops.to_terminal_ours = terminal_ours;
2617 gnu_ops.to_terminal_info = child_terminal_info;
2618 gnu_ops.to_kill = gnu_kill_inferior; /* to_kill */
2619 gnu_ops.to_load = 0; /* to_load */
2620 gnu_ops.to_lookup_symbol = 0; /* to_lookup_symbol */
2621 gnu_ops.to_create_inferior = gnu_create_inferior; /* to_create_inferior */
2622 gnu_ops.to_post_startup_inferior = NULL; /* to_post_startup_inferior */
2623 /* to_acknowledge_created_inferior */
2624 gnu_ops.to_acknowledge_created_inferior = NULL;
2625 /* to_clone_and_follow_inferior */
2626 gnu_ops.to_clone_and_follow_inferior = NULL;
2627 /* to_post_follow_inferior_by_clone */
2628 gnu_ops.to_post_follow_inferior_by_clone = NULL;
2629 gnu_ops.to_insert_fork_catchpoint = NULL;
2630 gnu_ops.to_remove_fork_catchpoint = NULL;
2631 gnu_ops.to_insert_vfork_catchpoint = NULL;
2632 gnu_ops.to_remove_vfork_catchpoint = NULL;
2633 gnu_ops.to_has_forked = NULL; /* to_has_forked */
2634 gnu_ops.to_has_vforked = NULL; /* to_has_vforked */
2635 gnu_ops.to_can_follow_vfork_prior_to_exec = NULL;
2636 gnu_ops.to_post_follow_vfork = NULL; /* to_post_follow_vfork */
2637 gnu_ops.to_insert_exec_catchpoint = NULL;
2638 gnu_ops.to_remove_exec_catchpoint = NULL;
2639 gnu_ops.to_has_execd = NULL;
2640 gnu_ops.to_reported_exec_events_per_exec_call = NULL;
2641 gnu_ops.to_has_exited = NULL;
2642 gnu_ops.to_mourn_inferior = gnu_mourn_inferior; /* to_mourn_inferior */
2643 gnu_ops.to_can_run = gnu_can_run; /* to_can_run */
2644 gnu_ops.to_notice_signals = 0; /* to_notice_signals */
2645 gnu_ops.to_thread_alive = gnu_thread_alive; /* to_thread_alive */
2646 gnu_ops.to_pid_to_str = gnu_pid_to_str; /* to_pid_to_str */
2647 gnu_ops.to_stop = gnu_stop; /* to_stop */
2648 gnu_ops.to_pid_to_exec_file = gnu_pid_to_exec_file; /* to_pid_to_exec_file */
2649 gnu_ops.to_stratum = process_stratum; /* to_stratum */
2650 gnu_ops.DONT_USE = 0; /* to_next */
2651 gnu_ops.to_has_all_memory = 1; /* to_has_all_memory */
2652 gnu_ops.to_has_memory = 1; /* to_has_memory */
2653 gnu_ops.to_has_stack = 1; /* to_has_stack */
2654 gnu_ops.to_has_registers = 1; /* to_has_registers */
2655 gnu_ops.to_has_execution = 1; /* to_has_execution */
2656 gnu_ops.to_sections = 0; /* sections */
2657 gnu_ops.to_sections_end = 0; /* sections_end */
2658 gnu_ops.to_magic = OPS_MAGIC; /* to_magic */
2659 } /* init_gnu_ops */
2662 /* User task commands. */
2664 struct cmd_list_element *set_task_cmd_list = 0;
2665 struct cmd_list_element *show_task_cmd_list = 0;
2666 /* User thread commands. */
2668 /* Commands with a prefix of `set/show thread'. */
2669 extern struct cmd_list_element *thread_cmd_list;
2670 struct cmd_list_element *set_thread_cmd_list = NULL;
2671 struct cmd_list_element *show_thread_cmd_list = NULL;
2673 /* Commands with a prefix of `set/show thread default'. */
2674 struct cmd_list_element *set_thread_default_cmd_list = NULL;
2675 struct cmd_list_element *show_thread_default_cmd_list = NULL;
2678 set_thread_cmd (char *args, int from_tty)
2680 printf_unfiltered ("\"set thread\" must be followed by the name of a thread property, or \"default\".\n");
2684 show_thread_cmd (char *args, int from_tty)
2686 printf_unfiltered ("\"show thread\" must be followed by the name of a thread property, or \"default\".\n");
2690 set_thread_default_cmd (char *args, int from_tty)
2692 printf_unfiltered ("\"set thread default\" must be followed by the name of a thread property.\n");
2696 show_thread_default_cmd (char *args, int from_tty)
2698 printf_unfiltered ("\"show thread default\" must be followed by the name of a thread property.\n");
2702 parse_int_arg (char *args, char *cmd_prefix)
2707 int val = strtoul (args, &arg_end, 10);
2708 if (*args && *arg_end == '\0')
2711 error ("Illegal argument for \"%s\" command, should be an integer.", cmd_prefix);
2715 _parse_bool_arg (char *args, char *t_val, char *f_val, char *cmd_prefix)
2717 if (!args || strcmp (args, t_val) == 0)
2719 else if (strcmp (args, f_val) == 0)
2722 error ("Illegal argument for \"%s\" command, should be \"%s\" or \"%s\".",
2723 cmd_prefix, t_val, f_val);
2726 #define parse_bool_arg(args, cmd_prefix) \
2727 _parse_bool_arg (args, "on", "off", cmd_prefix)
2730 check_empty (char *args, char *cmd_prefix)
2733 error ("Garbage after \"%s\" command: `%s'", cmd_prefix, args);
2736 /* Returns the alive thread named by INFERIOR_PID, or signals an error. */
2737 static struct proc *
2740 struct inf *inf = cur_inf ();
2741 struct proc *thread = inf_tid_to_thread (inf, PIDGET (inferior_ptid));
2743 error ("No current thread.");
2747 /* Returns the current inferior, but signals an error if it has no task. */
2751 struct inf *inf = cur_inf ();
2753 error ("No current process.");
2759 set_task_pause_cmd (char *args, int from_tty)
2761 struct inf *inf = cur_inf ();
2762 int old_sc = inf->pause_sc;
2764 inf->pause_sc = parse_bool_arg (args, "set task pause");
2766 if (old_sc == 0 && inf->pause_sc != 0)
2767 /* If the task is currently unsuspended, immediately suspend it,
2768 otherwise wait until the next time it gets control. */
2773 show_task_pause_cmd (char *args, int from_tty)
2775 struct inf *inf = cur_inf ();
2776 check_empty (args, "show task pause");
2777 printf_unfiltered ("The inferior task %s suspended while gdb has control.\n",
2779 ? (inf->pause_sc == 0 ? "isn't" : "is")
2780 : (inf->pause_sc == 0 ? "won't be" : "will be"));
2784 set_task_detach_sc_cmd (char *args, int from_tty)
2786 cur_inf ()->detach_sc = parse_int_arg (args, "set task detach-suspend-count");
2790 show_task_detach_sc_cmd (char *args, int from_tty)
2792 check_empty (args, "show task detach-suspend-count");
2793 printf_unfiltered ("The inferior task will be left with a suspend count of %d when detaching.\n",
2794 cur_inf ()->detach_sc);
2799 set_thread_default_pause_cmd (char *args, int from_tty)
2801 struct inf *inf = cur_inf ();
2802 inf->default_thread_pause_sc =
2803 parse_bool_arg (args, "set thread default pause") ? 0 : 1;
2807 show_thread_default_pause_cmd (char *args, int from_tty)
2809 struct inf *inf = cur_inf ();
2810 int sc = inf->default_thread_pause_sc;
2811 check_empty (args, "show thread default pause");
2812 printf_unfiltered ("New threads %s suspended while gdb has control%s.\n",
2813 sc ? "are" : "aren't",
2814 !sc && inf->pause_sc ? " (but the task is)" : "");
2818 set_thread_default_run_cmd (char *args, int from_tty)
2820 struct inf *inf = cur_inf ();
2821 inf->default_thread_run_sc =
2822 parse_bool_arg (args, "set thread default run") ? 0 : 1;
2826 show_thread_default_run_cmd (char *args, int from_tty)
2828 struct inf *inf = cur_inf ();
2829 check_empty (args, "show thread default run");
2830 printf_unfiltered ("New threads %s allowed to run.\n",
2831 inf->default_thread_run_sc == 0 ? "are" : "aren't");
2835 set_thread_default_detach_sc_cmd (char *args, int from_tty)
2837 cur_inf ()->default_thread_detach_sc =
2838 parse_int_arg (args, "set thread default detach-suspend-count");
2842 show_thread_default_detach_sc_cmd (char *args, int from_tty)
2844 check_empty (args, "show thread default detach-suspend-count");
2845 printf_unfiltered ("New threads will get a detach-suspend-count of %d.\n",
2846 cur_inf ()->default_thread_detach_sc);
2850 /* Steal a send right called NAME in the inferior task, and make it PROC's
2851 saved exception port. */
2853 steal_exc_port (struct proc *proc, mach_port_t name)
2857 mach_msg_type_name_t port_type;
2859 if (!proc || !proc->inf->task)
2860 error ("No inferior task.");
2862 err = mach_port_extract_right (proc->inf->task->port,
2863 name, MACH_MSG_TYPE_COPY_SEND,
2866 error ("Couldn't extract send right %d from inferior: %s",
2867 name, safe_strerror (err));
2869 if (proc->saved_exc_port)
2870 /* Get rid of our reference to the old one. */
2871 mach_port_deallocate (mach_task_self (), proc->saved_exc_port);
2873 proc->saved_exc_port = port;
2875 if (!proc->exc_port)
2876 /* If PROC is a thread, we may not have set its exception port before.
2877 We can't use proc_steal_exc_port because it also sets saved_exc_port. */
2879 proc->exc_port = proc->inf->event_port;
2880 err = proc_set_exception_port (proc, proc->exc_port);
2881 error ("Can't set exception port for %s: %s",
2882 proc_string (proc), safe_strerror (err));
2887 set_task_exc_port_cmd (char *args, int from_tty)
2889 struct inf *inf = cur_inf ();
2891 error ("No argument to \"set task exception-port\" command.");
2892 steal_exc_port (inf->task, parse_and_eval_address (args));
2896 set_stopped_cmd (char *args, int from_tty)
2898 cur_inf ()->stopped = _parse_bool_arg (args, "yes", "no", "set stopped");
2902 show_stopped_cmd (char *args, int from_tty)
2904 struct inf *inf = active_inf ();
2905 check_empty (args, "show stopped");
2906 printf_unfiltered ("The inferior process %s stopped.\n",
2907 inf->stopped ? "is" : "isn't");
2911 set_sig_thread_cmd (char *args, int from_tty)
2913 struct inf *inf = cur_inf ();
2915 if (!args || (!isdigit (*args) && strcmp (args, "none") != 0))
2916 error ("Illegal argument to \"set signal-thread\" command.\n"
2917 "Should be an integer thread ID, or `none'.");
2919 if (strcmp (args, "none") == 0)
2920 inf->signal_thread = 0;
2923 int tid = PIDGET (thread_id_to_pid (atoi (args)));
2925 error ("Thread ID %s not known. Use the \"info threads\" command to\n"
2926 "see the IDs of currently known threads.", args);
2927 inf->signal_thread = inf_tid_to_thread (inf, tid);
2932 show_sig_thread_cmd (char *args, int from_tty)
2934 struct inf *inf = active_inf ();
2935 check_empty (args, "show signal-thread");
2936 if (inf->signal_thread)
2937 printf_unfiltered ("The signal thread is %s.\n",
2938 proc_string (inf->signal_thread));
2940 printf_unfiltered ("There is no signal thread.\n");
2945 set_signals_cmd (char *args, int from_tty)
2947 struct inf *inf = cur_inf ();
2949 inf->want_signals = parse_bool_arg (args, "set signals");
2951 if (inf->task && inf->want_signals != inf->traced)
2952 /* Make this take effect immediately in a running process. */
2953 inf_set_traced (inf, inf->want_signals);
2957 show_signals_cmd (char *args, int from_tty)
2959 struct inf *inf = cur_inf ();
2960 check_empty (args, "show signals");
2961 printf_unfiltered ("The inferior process's signals %s intercepted.\n",
2963 ? (inf->traced ? "are" : "aren't")
2964 : (inf->want_signals ? "will be" : "won't be"));
2968 set_exceptions_cmd (char *args, int from_tty)
2970 struct inf *inf = cur_inf ();
2971 int val = parse_bool_arg (args, "set exceptions");
2973 if (inf->task && inf->want_exceptions != val)
2974 /* Make this take effect immediately in a running process. */
2977 inf->want_exceptions = val;
2981 show_exceptions_cmd (char *args, int from_tty)
2983 struct inf *inf = cur_inf ();
2984 check_empty (args, "show exceptions");
2985 printf_unfiltered ("Exceptions in the inferior %s trapped.\n",
2987 ? (inf->want_exceptions ? "are" : "aren't")
2988 : (inf->want_exceptions ? "will be" : "won't be"));
2993 set_task_cmd (char *args, int from_tty)
2995 printf_unfiltered ("\"set task\" must be followed by the name"
2996 " of a task property.\n");
3000 show_task_cmd (char *args, int from_tty)
3002 struct inf *inf = cur_inf ();
3004 check_empty (args, "show task");
3006 show_signals_cmd (0, from_tty);
3007 show_exceptions_cmd (0, from_tty);
3008 show_task_pause_cmd (0, from_tty);
3010 if (inf->pause_sc == 0)
3011 show_thread_default_pause_cmd (0, from_tty);
3012 show_thread_default_run_cmd (0, from_tty);
3016 show_stopped_cmd (0, from_tty);
3017 show_sig_thread_cmd (0, from_tty);
3020 if (inf->detach_sc != 0)
3021 show_task_detach_sc_cmd (0, from_tty);
3022 if (inf->default_thread_detach_sc != 0)
3023 show_thread_default_detach_sc_cmd (0, from_tty);
3028 set_noninvasive_cmd (char *args, int from_tty)
3030 /* Invert the sense of the arg for each component. */
3031 char *inv_args = parse_bool_arg (args, "set noninvasive") ? "off" : "on";
3033 set_task_pause_cmd (inv_args, from_tty);
3034 set_signals_cmd (inv_args, from_tty);
3035 set_exceptions_cmd (inv_args, from_tty);
3040 info_port_rights (char *args, mach_port_type_t only)
3042 struct inf *inf = active_inf ();
3043 struct value *vmark = value_mark ();
3046 /* Explicit list of port rights. */
3050 struct value *val = parse_to_comma_and_eval (&args);
3051 long right = value_as_long (val);
3053 print_port_info (right, 0, inf->task->port, PORTINFO_DETAILS,
3056 error ("%ld: %s.", right, safe_strerror (err));
3060 /* Print all of them. */
3063 print_task_ports_info (inf->task->port, only, PORTINFO_DETAILS,
3066 error ("%s.", safe_strerror (err));
3069 value_free_to_mark (vmark);
3073 info_send_rights_cmd (char *args, int from_tty)
3075 info_port_rights (args, MACH_PORT_TYPE_SEND);
3079 info_recv_rights_cmd (char *args, int from_tty)
3081 info_port_rights (args, MACH_PORT_TYPE_RECEIVE);
3085 info_port_sets_cmd (char *args, int from_tty)
3087 info_port_rights (args, MACH_PORT_TYPE_PORT_SET);
3091 info_dead_names_cmd (char *args, int from_tty)
3093 info_port_rights (args, MACH_PORT_TYPE_DEAD_NAME);
3097 info_port_rights_cmd (char *args, int from_tty)
3099 info_port_rights (args, ~0);
3104 add_task_commands (void)
3106 add_cmd ("pause", class_run, set_thread_default_pause_cmd,
3107 "Set whether the new threads are suspended while gdb has control.\n\
3108 This property normally has no effect because the whole task is\n\
3109 suspended, however, that may be disabled with \"set task pause off\".\n\
3110 The default value is \"off\".",
3111 &set_thread_default_cmd_list);
3112 add_cmd ("pause", no_class, show_thread_default_pause_cmd,
3113 "Show whether new threads are suspended while gdb has control.",
3114 &show_thread_default_cmd_list);
3116 add_cmd ("run", class_run, set_thread_default_run_cmd,
3117 "Set whether new threads are allowed to run \
3118 (once gdb has noticed them).",
3119 &set_thread_default_cmd_list);
3120 add_cmd ("run", no_class, show_thread_default_run_cmd,
3121 "Show whether new threads are allowed to run \
3122 (once gdb has noticed them).",
3123 &show_thread_default_cmd_list);
3125 add_cmd ("detach-suspend-count", class_run, set_thread_default_detach_sc_cmd,
3126 "Set the default detach-suspend-count value for new threads.",
3127 &set_thread_default_cmd_list);
3128 add_cmd ("detach-suspend-count", no_class, show_thread_default_detach_sc_cmd,
3129 "Show the default detach-suspend-count value for new threads.",
3130 &show_thread_default_cmd_list);
3132 add_cmd ("signals", class_run, set_signals_cmd,
3133 "Set whether the inferior process's signals will be intercepted.\n\
3134 Mach exceptions (such as breakpoint traps) are not affected.",
3136 add_alias_cmd ("sigs", "signals", class_run, 1, &setlist);
3137 add_cmd ("signals", no_class, show_signals_cmd,
3138 "Show whether the inferior process's signals will be intercepted.",
3140 add_alias_cmd ("sigs", "signals", no_class, 1, &showlist);
3142 add_cmd ("signal-thread", class_run, set_sig_thread_cmd,
3143 "Set the thread that gdb thinks is the libc signal thread.\n\
3144 This thread is run when delivering a signal to a non-stopped process.",
3146 add_alias_cmd ("sigthread", "signal-thread", class_run, 1, &setlist);
3147 add_cmd ("signal-thread", no_class, show_sig_thread_cmd,
3148 "Set the thread that gdb thinks is the libc signal thread.",
3150 add_alias_cmd ("sigthread", "signal-thread", no_class, 1, &showlist);
3152 add_cmd ("stopped", class_run, set_stopped_cmd,
3153 "Set whether gdb thinks the inferior process is stopped \
3155 Stopped process will be continued by sending them a signal.",
3157 add_cmd ("stopped", no_class, show_signals_cmd,
3158 "Show whether gdb thinks the inferior process is stopped \
3162 add_cmd ("exceptions", class_run, set_exceptions_cmd,
3163 "Set whether exceptions in the inferior process will be trapped.\n\
3164 When exceptions are turned off, neither breakpoints nor single-stepping\n\
3167 /* Allow `set exc' despite conflict with `set exception-port'. */
3168 add_alias_cmd ("exc", "exceptions", class_run, 1, &setlist);
3169 add_cmd ("exceptions", no_class, show_exceptions_cmd,
3170 "Show whether exceptions in the inferior process will be trapped.",
3173 add_prefix_cmd ("task", no_class, set_task_cmd,
3174 "Command prefix for setting task attributes.",
3175 &set_task_cmd_list, "set task ", 0, &setlist);
3176 add_prefix_cmd ("task", no_class, show_task_cmd,
3177 "Command prefix for showing task attributes.",
3178 &show_task_cmd_list, "show task ", 0, &showlist);
3180 add_cmd ("pause", class_run, set_task_pause_cmd,
3181 "Set whether the task is suspended while gdb has control.\n\
3182 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3183 until the next time the program is continued.\n\
3184 When setting this to \"off\", \"set thread default pause on\" can be\n\
3185 used to pause individual threads by default instead.",
3186 &set_task_cmd_list);
3187 add_cmd ("pause", no_class, show_task_pause_cmd,
3188 "Show whether the task is suspended while gdb has control.",
3189 &show_task_cmd_list);
3191 add_cmd ("detach-suspend-count", class_run, set_task_detach_sc_cmd,
3192 "Set the suspend count will leave on the thread when detaching.",
3193 &set_task_cmd_list);
3194 add_cmd ("detach-suspend-count", no_class, show_task_detach_sc_cmd,
3195 "Show the suspend count will leave on the thread when detaching.",
3196 &show_task_cmd_list);
3198 add_cmd ("exception-port", no_class, set_task_exc_port_cmd,
3199 "Set the task exception port to which we forward exceptions.\n\
3200 The argument should be the value of the send right in the task.",
3201 &set_task_cmd_list);
3202 add_alias_cmd ("excp", "exception-port", no_class, 1, &set_task_cmd_list);
3203 add_alias_cmd ("exc-port", "exception-port", no_class, 1,
3204 &set_task_cmd_list);
3206 /* A convenient way of turning on all options require to noninvasively
3207 debug running tasks. */
3208 add_cmd ("noninvasive", no_class, set_noninvasive_cmd,
3209 "Set task options so that we interfere as little as possible.\n\
3210 This is the same as setting `task pause', `exceptions', and\n\
3211 `signals' to the opposite value.",
3214 /* Commands to show information about the task's ports. */
3215 add_cmd ("send-rights", class_info, info_send_rights_cmd,
3216 "Show information about the task's send rights",
3218 add_cmd ("receive-rights", class_info, info_recv_rights_cmd,
3219 "Show information about the task's receive rights",
3221 add_cmd ("port-rights", class_info, info_port_rights_cmd,
3222 "Show information about the task's port rights",
3224 add_cmd ("port-sets", class_info, info_port_sets_cmd,
3225 "Show information about the task's port sets",
3227 add_cmd ("dead-names", class_info, info_dead_names_cmd,
3228 "Show information about the task's dead names",
3230 add_info_alias ("ports", "port-rights", 1);
3231 add_info_alias ("port", "port-rights", 1);
3232 add_info_alias ("psets", "port-sets", 1);
3237 set_thread_pause_cmd (char *args, int from_tty)
3239 struct proc *thread = cur_thread ();
3240 int old_sc = thread->pause_sc;
3241 thread->pause_sc = parse_bool_arg (args, "set thread pause");
3242 if (old_sc == 0 && thread->pause_sc != 0 && thread->inf->pause_sc == 0)
3243 /* If the task is currently unsuspended, immediately suspend it,
3244 otherwise wait until the next time it gets control. */
3245 inf_suspend (thread->inf);
3249 show_thread_pause_cmd (char *args, int from_tty)
3251 struct proc *thread = cur_thread ();
3252 int sc = thread->pause_sc;
3253 check_empty (args, "show task pause");
3254 printf_unfiltered ("Thread %s %s suspended while gdb has control%s.\n",
3255 proc_string (thread),
3256 sc ? "is" : "isn't",
3257 !sc && thread->inf->pause_sc ? " (but the task is)" : "");
3261 set_thread_run_cmd (char *args, int from_tty)
3263 struct proc *thread = cur_thread ();
3264 thread->run_sc = parse_bool_arg (args, "set thread run") ? 0 : 1;
3268 show_thread_run_cmd (char *args, int from_tty)
3270 struct proc *thread = cur_thread ();
3271 check_empty (args, "show thread run");
3272 printf_unfiltered ("Thread %s %s allowed to run.",
3273 proc_string (thread),
3274 thread->run_sc == 0 ? "is" : "isn't");
3278 set_thread_detach_sc_cmd (char *args, int from_tty)
3280 cur_thread ()->detach_sc = parse_int_arg (args,
3281 "set thread detach-suspend-count");
3285 show_thread_detach_sc_cmd (char *args, int from_tty)
3287 struct proc *thread = cur_thread ();
3288 check_empty (args, "show thread detach-suspend-count");
3289 printf_unfiltered ("Thread %s will be left with a suspend count"
3290 " of %d when detaching.\n",
3291 proc_string (thread),
3296 set_thread_exc_port_cmd (char *args, int from_tty)
3298 struct proc *thread = cur_thread ();
3300 error ("No argument to \"set thread exception-port\" command.");
3301 steal_exc_port (thread, parse_and_eval_address (args));
3306 show_thread_cmd (char *args, int from_tty)
3308 struct proc *thread = cur_thread ();
3309 check_empty (args, "show thread");
3310 show_thread_run_cmd (0, from_tty);
3311 show_thread_pause_cmd (0, from_tty);
3312 if (thread->detach_sc != 0)
3313 show_thread_detach_sc_cmd (0, from_tty);
3318 thread_takeover_sc_cmd (char *args, int from_tty)
3320 struct proc *thread = cur_thread ();
3321 thread_basic_info_data_t _info;
3322 thread_basic_info_t info = &_info;
3323 mach_msg_type_number_t info_len = THREAD_BASIC_INFO_COUNT;
3325 thread_info (thread->port, THREAD_BASIC_INFO, (int *) &info, &info_len);
3327 error ("%s.", safe_strerror (err));
3328 thread->sc = info->suspend_count;
3330 printf_unfiltered ("Suspend count was %d.\n", thread->sc);
3332 vm_deallocate (mach_task_self (), (vm_address_t) info,
3333 info_len * sizeof (int));
3338 add_thread_commands (void)
3340 add_prefix_cmd ("thread", no_class, set_thread_cmd,
3341 "Command prefix for setting thread properties.",
3342 &set_thread_cmd_list, "set thread ", 0, &setlist);
3343 add_prefix_cmd ("default", no_class, show_thread_cmd,
3344 "Command prefix for setting default thread properties.",
3345 &set_thread_default_cmd_list, "set thread default ", 0,
3346 &set_thread_cmd_list);
3347 add_prefix_cmd ("thread", no_class, set_thread_default_cmd,
3348 "Command prefix for showing thread properties.",
3349 &show_thread_cmd_list, "show thread ", 0, &showlist);
3350 add_prefix_cmd ("default", no_class, show_thread_default_cmd,
3351 "Command prefix for showing default thread properties.",
3352 &show_thread_default_cmd_list, "show thread default ", 0,
3353 &show_thread_cmd_list);
3355 add_cmd ("pause", class_run, set_thread_pause_cmd,
3356 "Set whether the current thread is suspended \
3357 while gdb has control.\n\
3358 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3359 until the next time the program is continued. This property normally\n\
3360 has no effect because the whole task is suspended, however, that may\n\
3361 be disabled with \"set task pause off\".\n\
3362 The default value is \"off\".",
3363 &set_thread_cmd_list);
3364 add_cmd ("pause", no_class, show_thread_pause_cmd,
3365 "Show whether the current thread is suspended \
3366 while gdb has control.",
3367 &show_thread_cmd_list);
3369 add_cmd ("run", class_run, set_thread_run_cmd,
3370 "Set whether the current thread is allowed to run.",
3371 &set_thread_cmd_list);
3372 add_cmd ("run", no_class, show_thread_run_cmd,
3373 "Show whether the current thread is allowed to run.",
3374 &show_thread_cmd_list);
3376 add_cmd ("detach-suspend-count", class_run, set_thread_detach_sc_cmd,
3377 "Set the suspend count will leave on the thread when detaching.\n\
3378 Note that this is relative to suspend count when gdb noticed the thread;\n\
3379 use the `thread takeover-suspend-count' to force it to an absolute value.",
3380 &set_thread_cmd_list);
3381 add_cmd ("detach-suspend-count", no_class, show_thread_detach_sc_cmd,
3382 "Show the suspend count will leave on the thread when detaching.\n\
3383 Note that this is relative to suspend count when gdb noticed the thread;\n\
3384 use the `thread takeover-suspend-count' to force it to an absolute value.",
3385 &show_thread_cmd_list);
3387 add_cmd ("exception-port", no_class, set_thread_exc_port_cmd,
3388 "Set the thread exception port to which we forward exceptions.\n\
3389 This overrides the task exception port.\n\
3390 The argument should be the value of the send right in the task.",
3391 &set_thread_cmd_list);
3392 add_alias_cmd ("excp", "exception-port", no_class, 1, &set_thread_cmd_list);
3393 add_alias_cmd ("exc-port", "exception-port", no_class, 1,
3394 &set_thread_cmd_list);
3396 add_cmd ("takeover-suspend-count", no_class, thread_takeover_sc_cmd,
3397 "Force the threads absolute suspend-count to be gdb's.\n\
3398 Prior to giving this command, gdb's thread suspend-counts are relative\n\
3399 to the thread's initial suspend-count when gdb notices the threads.",
3405 _initialize_gnu_nat (void)
3407 proc_server = getproc ();
3410 add_target (&gnu_ops);
3412 add_task_commands ();
3413 add_thread_commands ();
3414 add_set_cmd ("gnu-debug", class_maintenance,
3415 var_boolean, (char *) &gnu_debug_flag,
3416 "Set debugging output for the gnu backend.", &maintenancelist);
3419 #ifdef FLUSH_INFERIOR_CACHE
3421 /* When over-writing code on some machines the I-Cache must be flushed
3422 explicitly, because it is not kept coherent by the lazy hardware.
3423 This definitely includes breakpoints, for instance, or else we
3424 end up looping in mysterious Bpt traps */
3427 flush_inferior_icache (CORE_ADDR pc, int amount)
3429 vm_machine_attribute_val_t flush = MATTR_VAL_ICACHE_FLUSH;
3432 ret = vm_machine_attribute (current_inferior->task->port,
3437 if (ret != KERN_SUCCESS)
3438 warning ("Error flushing inferior's cache : %s", safe_strerror (ret));
3440 #endif /* FLUSH_INFERIOR_CACHE */