1 /* Interface GDB to the GNU Hurd.
2 Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2006
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 Written by Miles Bader <miles@gnu.ai.mit.edu>
9 Some code and ideas from m3-nat.c by Jukka Virtanen <jtv@hut.fi>
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., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, 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"
65 #include "gdb_obstack.h"
69 #include "exc_request_S.h"
71 #include "process_reply_S.h"
72 #include "msg_reply_S.h"
73 #include "exc_request_U.h"
76 static process_t proc_server
= MACH_PORT_NULL
;
78 /* If we've sent a proc_wait_request to the proc server, the pid of the
79 process we asked about. We can only ever have one outstanding. */
80 int proc_wait_pid
= 0;
82 /* The number of wait requests we've sent, and expect replies from. */
83 int proc_waits_pending
= 0;
85 int gnu_debug_flag
= 0;
89 extern struct target_ops gnu_ops
;
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
,
102 struct proc
*run_thread
,
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
);
113 #define inf_debug(_inf, msg, args...) \
114 do { struct inf *__inf = (_inf); \
115 debug ("{inf %d %p}: " msg, __inf->pid, __inf , ##args); } while (0)
117 void proc_abort (struct proc
*proc
, int force
);
118 struct proc
*make_proc (struct inf
*inf
, mach_port_t port
, int tid
);
119 struct proc
*_proc_free (struct proc
*proc
);
120 int proc_update_sc (struct proc
*proc
);
121 error_t
proc_get_exception_port (struct proc
*proc
, mach_port_t
* port
);
122 error_t
proc_set_exception_port (struct proc
*proc
, mach_port_t port
);
123 static mach_port_t
_proc_get_exc_port (struct proc
*proc
);
124 void proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
);
125 void proc_restore_exc_port (struct proc
*proc
);
126 int proc_trace (struct proc
*proc
, int set
);
128 /* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
129 to INF's msg port and task port respectively. If it has no msg port,
130 EIEIO is returned. INF must refer to a running process! */
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, \
134 msgport ? (rpc_expr) : EIEIO)
136 /* Like INF_MSGPORT_RPC, but will also resume the signal thread to ensure
137 there's someone around to deal with the RPC (and resuspend things
138 afterwards). This effects INF's threads' resume_sc count. */
139 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
140 (inf_set_threads_resume_sc_for_signal_thread (inf) \
143 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
149 /* The state passed by an exception message. */
152 int exception
; /* The exception code */
154 mach_port_t handler
; /* The real exception port to handle this. */
155 mach_port_t reply
; /* The reply port from the exception call. */
158 /* The results of the last wait an inf did. */
161 struct target_waitstatus status
; /* The status returned to gdb. */
162 struct exc_state exc
; /* The exception that caused us to return. */
163 struct proc
*thread
; /* The thread in question. */
164 int suppress
; /* Something trivial happened. */
167 /* The state of an inferior. */
170 /* Fields describing the current inferior. */
172 struct proc
*task
; /* The mach task. */
173 struct proc
*threads
; /* A linked list of all threads in TASK. */
175 /* True if THREADS needn't be validated by querying the task. We assume that
176 we and the task in question are the only ones frobbing the thread list,
177 so as long as we don't let any code run, we don't have to worry about
179 int threads_up_to_date
;
181 pid_t pid
; /* The real system PID. */
183 struct inf_wait wait
; /* What to return from target_wait. */
185 /* One thread proc in INF may be in `single-stepping mode'. This is it. */
186 struct proc
*step_thread
;
188 /* The thread we think is the signal thread. */
189 struct proc
*signal_thread
;
191 mach_port_t event_port
; /* Where we receive various msgs. */
193 /* True if we think at least one thread in the inferior could currently be
195 unsigned int running
:1;
197 /* True if the process has stopped (in the proc server sense). Note that
198 since a proc server `stop' leaves the signal thread running, the inf can
199 be RUNNING && STOPPED... */
200 unsigned int stopped
:1;
202 /* True if the inferior has no message port. */
203 unsigned int nomsg
:1;
205 /* True if the inferior is traced. */
206 unsigned int traced
:1;
208 /* True if we shouldn't try waiting for the inferior, usually because we
209 can't for some reason. */
210 unsigned int no_wait
:1;
212 /* When starting a new inferior, we don't try to validate threads until all
213 the proper execs have been done. This is a count of how many execs we
215 unsigned pending_execs
;
217 /* Fields describing global state */
219 /* The task suspend count used when gdb has control. This is normally 1 to
220 make things easier for us, but sometimes (like when attaching to vital
221 system servers) it may be desirable to let the task continue to run
222 (pausing individual threads as necessary). */
225 /* The task suspend count left when detaching from a task. */
228 /* The initial values used for the run_sc and pause_sc of newly discovered
229 threads -- see the definition of those fields in struct proc. */
230 int default_thread_run_sc
;
231 int default_thread_pause_sc
;
232 int default_thread_detach_sc
;
234 /* True if the process should be traced when started/attached. Newly
235 started processes *must* be traced at first to exec them properly, but
236 if this is false, tracing is turned off as soon it has done so. */
239 /* True if exceptions from the inferior process should be trapped. This
240 must be on to use breakpoints. */
246 __proc_pid (struct proc
*proc
)
248 return proc
->inf
->pid
;
252 /* Update PROC's real suspend count to match it's desired one. Returns true
253 if we think PROC is now in a runnable state. */
255 proc_update_sc (struct proc
*proc
)
259 int delta
= proc
->sc
- proc
->cur_sc
;
262 proc_debug (proc
, "sc: %d --> %d", proc
->cur_sc
, proc
->sc
);
264 if (proc
->sc
== 0 && proc
->state_changed
)
265 /* Since PROC may start running, we must write back any state changes. */
267 gdb_assert (proc_is_thread (proc
));
268 proc_debug (proc
, "storing back changed thread state");
269 err
= thread_set_state (proc
->port
, THREAD_STATE_FLAVOR
,
270 (thread_state_t
) &proc
->state
, THREAD_STATE_SIZE
);
272 proc
->state_changed
= 0;
277 while (delta
-- > 0 && !err
)
279 if (proc_is_task (proc
))
280 err
= task_suspend (proc
->port
);
282 err
= thread_suspend (proc
->port
);
287 while (delta
++ < 0 && !err
)
289 if (proc_is_task (proc
))
290 err
= task_resume (proc
->port
);
292 err
= thread_resume (proc
->port
);
296 proc
->cur_sc
= proc
->sc
;
298 /* If we got an error, then the task/thread has disappeared. */
299 running
= !err
&& proc
->sc
== 0;
301 proc_debug (proc
, "is %s", err
? "dead" : running
? "running" : "suspended");
303 proc_debug (proc
, "err = %s", safe_strerror (err
));
308 proc
->state_valid
= proc
->state_changed
= 0;
309 proc
->fetched_regs
= 0;
316 /* Thread_abort is called on PROC if needed. PROC must be a thread proc.
317 If PROC is deemed `precious', then nothing is done unless FORCE is true.
318 In particular, a thread is precious if it's running (in which case forcing
319 it includes suspending it first), or if it has an exception pending. */
321 proc_abort (struct proc
*proc
, int force
)
323 gdb_assert (proc_is_thread (proc
));
327 struct inf
*inf
= proc
->inf
;
328 int running
= (proc
->cur_sc
== 0 && inf
->task
->cur_sc
== 0);
330 if (running
&& force
)
333 inf_update_suspends (proc
->inf
);
335 warning (_("Stopped %s."), proc_string (proc
));
337 else if (proc
== inf
->wait
.thread
&& inf
->wait
.exc
.reply
&& !force
)
338 /* An exception is pending on PROC, which don't mess with. */
342 /* We only abort the thread if it's not actually running. */
344 thread_abort (proc
->port
);
345 proc_debug (proc
, "aborted");
349 proc_debug (proc
, "not aborting");
353 /* Make sure that the state field in PROC is up to date, and return a pointer
354 to it, or 0 if something is wrong. If WILL_MODIFY is true, makes sure
355 that the thread is stopped and aborted first, and sets the state_changed
356 field in PROC to true. */
358 proc_get_state (struct proc
*proc
, int will_modify
)
360 int was_aborted
= proc
->aborted
;
362 proc_debug (proc
, "updating state info%s",
363 will_modify
? " (with intention to modify)" : "");
365 proc_abort (proc
, will_modify
);
367 if (!was_aborted
&& proc
->aborted
)
368 /* PROC's state may have changed since we last fetched it. */
369 proc
->state_valid
= 0;
371 if (!proc
->state_valid
)
373 mach_msg_type_number_t state_size
= THREAD_STATE_SIZE
;
375 thread_get_state (proc
->port
, THREAD_STATE_FLAVOR
,
376 (thread_state_t
) &proc
->state
, &state_size
);
377 proc_debug (proc
, "getting thread state");
378 proc
->state_valid
= !err
;
381 if (proc
->state_valid
)
384 proc
->state_changed
= 1;
385 return (thread_state_t
) &proc
->state
;
392 /* Set PORT to PROC's exception port. */
394 proc_get_exception_port (struct proc
* proc
, mach_port_t
* port
)
396 if (proc_is_task (proc
))
397 return task_get_exception_port (proc
->port
, port
);
399 return thread_get_exception_port (proc
->port
, port
);
402 /* Set PROC's exception port to PORT. */
404 proc_set_exception_port (struct proc
* proc
, mach_port_t port
)
406 proc_debug (proc
, "setting exception port: %d", port
);
407 if (proc_is_task (proc
))
408 return task_set_exception_port (proc
->port
, port
);
410 return thread_set_exception_port (proc
->port
, port
);
413 /* Get PROC's exception port, cleaning up a bit if proc has died. */
415 _proc_get_exc_port (struct proc
*proc
)
417 mach_port_t exc_port
;
418 error_t err
= proc_get_exception_port (proc
, &exc_port
);
421 /* PROC must be dead. */
424 mach_port_deallocate (mach_task_self (), proc
->exc_port
);
425 proc
->exc_port
= MACH_PORT_NULL
;
426 if (proc
->saved_exc_port
)
427 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
428 proc
->saved_exc_port
= MACH_PORT_NULL
;
434 /* Replace PROC's exception port with EXC_PORT, unless it's already been
435 done. Stash away any existing exception port so we can restore it later. */
437 proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
)
439 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
445 proc_debug (proc
, "inserting exception port: %d", exc_port
);
447 if (cur_exc_port
!= exc_port
)
448 /* Put in our exception port. */
449 err
= proc_set_exception_port (proc
, exc_port
);
451 if (err
|| cur_exc_port
== proc
->exc_port
)
452 /* We previously set the exception port, and it's still set. So we
453 just keep the old saved port which is what the proc set. */
456 mach_port_deallocate (mach_task_self (), cur_exc_port
);
459 /* Keep a copy of PROC's old exception port so it can be restored. */
461 if (proc
->saved_exc_port
)
462 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
463 proc
->saved_exc_port
= cur_exc_port
;
466 proc_debug (proc
, "saved exception port: %d", proc
->saved_exc_port
);
469 proc
->exc_port
= exc_port
;
471 warning (_("Error setting exception port for %s: %s"),
472 proc_string (proc
), safe_strerror (err
));
476 /* If we previously replaced PROC's exception port, put back what we
477 found there at the time, unless *our* exception port has since been
478 overwritten, in which case who knows what's going on. */
480 proc_restore_exc_port (struct proc
*proc
)
482 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
488 proc_debug (proc
, "restoring real exception port");
490 if (proc
->exc_port
== cur_exc_port
)
491 /* Our's is still there. */
492 err
= proc_set_exception_port (proc
, proc
->saved_exc_port
);
494 if (proc
->saved_exc_port
)
495 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
496 proc
->saved_exc_port
= MACH_PORT_NULL
;
499 proc
->exc_port
= MACH_PORT_NULL
;
501 warning (_("Error setting exception port for %s: %s"),
502 proc_string (proc
), safe_strerror (err
));
507 /* Turns hardware tracing in PROC on or off when SET is true or false,
508 respectively. Returns true on success. */
510 proc_trace (struct proc
*proc
, int set
)
512 thread_state_t state
= proc_get_state (proc
, 1);
515 return 0; /* the thread must be dead. */
517 proc_debug (proc
, "tracing %s", set
? "on" : "off");
521 /* XXX We don't get the exception unless the thread has its own
522 exception port???? */
523 if (proc
->exc_port
== MACH_PORT_NULL
)
524 proc_steal_exc_port (proc
, proc
->inf
->event_port
);
525 THREAD_STATE_SET_TRACED (state
);
528 THREAD_STATE_CLEAR_TRACED (state
);
534 /* A variable from which to assign new TIDs. */
535 static int next_thread_id
= 1;
537 /* Returns a new proc structure with the given fields. Also adds a
538 notification for PORT becoming dead to be sent to INF's notify port. */
540 make_proc (struct inf
*inf
, mach_port_t port
, int tid
)
543 mach_port_t prev_port
= MACH_PORT_NULL
;
544 struct proc
*proc
= xmalloc (sizeof (struct proc
));
550 proc
->saved_exc_port
= MACH_PORT_NULL
;
551 proc
->exc_port
= MACH_PORT_NULL
;
556 /* Note that these are all the values for threads; the task simply uses the
557 corresponding field in INF directly. */
558 proc
->run_sc
= inf
->default_thread_run_sc
;
559 proc
->pause_sc
= inf
->default_thread_pause_sc
;
560 proc
->detach_sc
= inf
->default_thread_detach_sc
;
561 proc
->resume_sc
= proc
->run_sc
;
565 proc
->state_valid
= 0;
566 proc
->state_changed
= 0;
568 proc_debug (proc
, "is new");
570 /* Get notified when things die. */
572 mach_port_request_notification (mach_task_self (), port
,
573 MACH_NOTIFY_DEAD_NAME
, 1,
575 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
578 warning (_("Couldn't request notification for port %d: %s"),
579 port
, safe_strerror (err
));
582 proc_debug (proc
, "notifications to: %d", inf
->event_port
);
583 if (prev_port
!= MACH_PORT_NULL
)
584 mach_port_deallocate (mach_task_self (), prev_port
);
587 if (inf
->want_exceptions
)
589 if (proc_is_task (proc
))
590 /* Make the task exception port point to us. */
591 proc_steal_exc_port (proc
, inf
->event_port
);
593 /* Just clear thread exception ports -- they default to the
595 proc_steal_exc_port (proc
, MACH_PORT_NULL
);
601 /* Frees PROC and any resources it uses, and returns the value of PROC's
604 _proc_free (struct proc
*proc
)
606 struct inf
*inf
= proc
->inf
;
607 struct proc
*next
= proc
->next
;
609 proc_debug (proc
, "freeing...");
611 if (proc
== inf
->step_thread
)
612 /* Turn off single stepping. */
613 inf_set_step_thread (inf
, 0);
614 if (proc
== inf
->wait
.thread
)
615 inf_clear_wait (inf
);
616 if (proc
== inf
->signal_thread
)
617 inf
->signal_thread
= 0;
619 if (proc
->port
!= MACH_PORT_NULL
)
621 if (proc
->exc_port
!= MACH_PORT_NULL
)
622 /* Restore the original exception port. */
623 proc_restore_exc_port (proc
);
624 if (proc
->cur_sc
!= 0)
625 /* Resume the thread/task. */
628 proc_update_sc (proc
);
630 mach_port_deallocate (mach_task_self (), proc
->port
);
641 struct inf
*inf
= xmalloc (sizeof (struct inf
));
645 inf
->threads_up_to_date
= 0;
647 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
648 inf
->wait
.thread
= 0;
649 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
650 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
651 inf
->step_thread
= 0;
652 inf
->signal_thread
= 0;
653 inf
->event_port
= MACH_PORT_NULL
;
659 inf
->pending_execs
= 0;
662 inf
->default_thread_run_sc
= 0;
663 inf
->default_thread_pause_sc
= 0;
664 inf
->default_thread_detach_sc
= 0;
665 inf
->want_signals
= 1; /* By default */
666 inf
->want_exceptions
= 1; /* By default */
671 /* Clear INF's target wait status. */
673 inf_clear_wait (struct inf
*inf
)
675 inf_debug (inf
, "clearing wait");
676 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
677 inf
->wait
.thread
= 0;
678 inf
->wait
.suppress
= 0;
679 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
681 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.handler
);
682 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
684 if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
686 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.reply
);
687 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
693 inf_cleanup (struct inf
*inf
)
695 inf_debug (inf
, "cleanup");
697 inf_clear_wait (inf
);
699 inf_set_pid (inf
, -1);
706 inf
->pending_execs
= 0;
710 mach_port_destroy (mach_task_self (), inf
->event_port
);
711 inf
->event_port
= MACH_PORT_NULL
;
716 inf_startup (struct inf
*inf
, int pid
)
720 inf_debug (inf
, "startup: pid = %d", pid
);
724 /* Make the port on which we receive all events. */
725 err
= mach_port_allocate (mach_task_self (),
726 MACH_PORT_RIGHT_RECEIVE
, &inf
->event_port
);
728 error (_("Error allocating event port: %s"), safe_strerror (err
));
730 /* Make a send right for it, so we can easily copy it for other people. */
731 mach_port_insert_right (mach_task_self (), inf
->event_port
,
732 inf
->event_port
, MACH_MSG_TYPE_MAKE_SEND
);
733 inf_set_pid (inf
, pid
);
737 /* Close current process, if any, and attach INF to process PORT. */
739 inf_set_pid (struct inf
*inf
, pid_t pid
)
742 struct proc
*task
= inf
->task
;
744 inf_debug (inf
, "setting pid: %d", pid
);
747 task_port
= MACH_PORT_NULL
;
750 error_t err
= proc_pid2task (proc_server
, pid
, &task_port
);
752 error (_("Error getting task for pid %d: %s"), pid
, safe_strerror (err
));
755 inf_debug (inf
, "setting task: %d", task_port
);
758 task_suspend (task_port
);
760 if (task
&& task
->port
!= task_port
)
763 inf_validate_procs (inf
); /* Trash all the threads. */
764 _proc_free (task
); /* And the task. */
767 if (task_port
!= MACH_PORT_NULL
)
769 inf
->task
= make_proc (inf
, task_port
, PROC_TID_TASK
);
770 inf
->threads_up_to_date
= 0;
777 /* Reflect task_suspend above. */
778 inf
->task
->sc
= inf
->task
->cur_sc
= 1;
785 /* Validates INF's stopped, nomsg and traced field from the actual
786 proc server state. Note that the traced field is only updated from
787 the proc server state if we do not have a message port. If we do
788 have a message port we'd better look at the tracemask itself. */
790 inf_validate_procinfo (struct inf
*inf
)
793 mach_msg_type_number_t noise_len
= 0;
795 mach_msg_type_number_t pi_len
= 0;
798 proc_getprocinfo (proc_server
, inf
->pid
, &info_flags
,
799 (procinfo_t
*) &pi
, &pi_len
, &noise
, &noise_len
);
803 inf
->stopped
= !!(pi
->state
& PI_STOPPED
);
804 inf
->nomsg
= !!(pi
->state
& PI_NOMSG
);
806 inf
->traced
= !!(pi
->state
& PI_TRACED
);
807 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
809 vm_deallocate (mach_task_self (), (vm_address_t
) noise
, noise_len
);
813 /* Validates INF's task suspend count. If it's higher than we expect,
814 verify with the user before `stealing' the extra count. */
816 inf_validate_task_sc (struct inf
*inf
)
819 mach_msg_type_number_t noise_len
= 0;
821 mach_msg_type_number_t pi_len
= 0;
822 int info_flags
= PI_FETCH_TASKINFO
;
823 int suspend_count
= -1;
827 err
= proc_getprocinfo (proc_server
, inf
->pid
, &info_flags
,
828 (procinfo_t
*) &pi
, &pi_len
, &noise
, &noise_len
);
831 inf
->task
->dead
= 1; /* oh well */
835 if (inf
->task
->cur_sc
< pi
->taskinfo
.suspend_count
&& suspend_count
== -1)
837 /* The proc server might have suspended the task while stopping
838 it. This happens when the task is handling a traced signal.
839 Refetch the suspend count. The proc server should be
840 finished stopping the task by now. */
841 suspend_count
= pi
->taskinfo
.suspend_count
;
845 suspend_count
= pi
->taskinfo
.suspend_count
;
847 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
849 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
851 if (inf
->task
->cur_sc
< suspend_count
)
855 target_terminal_ours (); /* Allow I/O. */
856 abort
= !query ("Pid %d has an additional task suspend count of %d;"
857 " clear it? ", inf
->pid
,
858 suspend_count
- inf
->task
->cur_sc
);
859 target_terminal_inferior (); /* Give it back to the child. */
862 error (_("Additional task suspend count left untouched."));
864 inf
->task
->cur_sc
= suspend_count
;
868 /* Turns tracing for INF on or off, depending on ON, unless it already
869 is. If INF is running, the resume_sc count of INF's threads will
870 be modified, and the signal thread will briefly be run to change
873 inf_set_traced (struct inf
*inf
, int on
)
875 if (on
== inf
->traced
)
878 if (inf
->task
&& !inf
->task
->dead
)
879 /* Make it take effect immediately. */
881 sigset_t mask
= on
? ~(sigset_t
) 0 : 0;
883 INF_RESUME_MSGPORT_RPC (inf
, msg_set_init_int (msgport
, refport
,
884 INIT_TRACEMASK
, mask
));
888 warning (_("Can't modify tracing state for pid %d: %s"),
889 inf
->pid
, "No signal thread");
893 warning (_("Can't modify tracing state for pid %d: %s"),
894 inf
->pid
, safe_strerror (err
));
903 /* Makes all the real suspend count deltas of all the procs in INF
904 match the desired values. Careful to always do thread/task suspend
905 counts in the safe order. Returns true if at least one thread is
906 thought to be running. */
908 inf_update_suspends (struct inf
*inf
)
910 struct proc
*task
= inf
->task
;
911 /* We don't have to update INF->threads even though we're iterating over it
912 because we'll change a thread only if it already has an existing proc
915 inf_debug (inf
, "updating suspend counts");
920 int task_running
= (task
->sc
== 0), thread_running
= 0;
922 if (task
->sc
> task
->cur_sc
)
923 /* The task is becoming _more_ suspended; do before any threads. */
924 task_running
= proc_update_sc (task
);
926 if (inf
->pending_execs
)
927 /* When we're waiting for an exec, things may be happening behind our
928 back, so be conservative. */
931 /* Do all the thread suspend counts. */
932 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
933 thread_running
|= proc_update_sc (thread
);
935 if (task
->sc
!= task
->cur_sc
)
936 /* We didn't do the task first, because we wanted to wait for the
937 threads; do it now. */
938 task_running
= proc_update_sc (task
);
940 inf_debug (inf
, "%srunning...",
941 (thread_running
&& task_running
) ? "" : "not ");
943 inf
->running
= thread_running
&& task_running
;
945 /* Once any thread has executed some code, we can't depend on the
946 threads list any more. */
948 inf
->threads_up_to_date
= 0;
957 /* Converts a GDB pid to a struct proc. */
959 inf_tid_to_thread (struct inf
*inf
, int tid
)
961 struct proc
*thread
= inf
->threads
;
964 if (thread
->tid
== tid
)
967 thread
= thread
->next
;
971 /* Converts a thread port to a struct proc. */
973 inf_port_to_thread (struct inf
*inf
, mach_port_t port
)
975 struct proc
*thread
= inf
->threads
;
977 if (thread
->port
== port
)
980 thread
= thread
->next
;
985 /* Make INF's list of threads be consistent with reality of TASK. */
987 inf_validate_procs (struct inf
*inf
)
989 thread_array_t threads
;
990 mach_msg_type_number_t num_threads
, i
;
991 struct proc
*task
= inf
->task
;
993 /* If no threads are currently running, this function will guarantee that
994 things are up to date. The exception is if there are zero threads --
995 then it is almost certainly in an odd state, and probably some outside
996 agent will create threads. */
997 inf
->threads_up_to_date
= inf
->threads
? !inf
->running
: 0;
1001 error_t err
= task_threads (task
->port
, &threads
, &num_threads
);
1002 inf_debug (inf
, "fetching threads");
1004 /* TASK must be dead. */
1014 inf_debug (inf
, "no task");
1018 /* Make things normally linear. */
1019 mach_msg_type_number_t search_start
= 0;
1020 /* Which thread in PROCS corresponds to each task thread, & the task. */
1021 struct proc
*matched
[num_threads
+ 1];
1022 /* The last thread in INF->threads, so we can add to the end. */
1023 struct proc
*last
= 0;
1024 /* The current thread we're considering. */
1025 struct proc
*thread
= inf
->threads
;
1027 memset (matched
, 0, sizeof (matched
));
1031 mach_msg_type_number_t left
;
1033 for (i
= search_start
, left
= num_threads
; left
; i
++, left
--)
1035 if (i
>= num_threads
)
1036 i
-= num_threads
; /* I wrapped around. */
1037 if (thread
->port
== threads
[i
])
1038 /* We already know about this thread. */
1040 matched
[i
] = thread
;
1042 thread
= thread
->next
;
1050 proc_debug (thread
, "died!");
1051 thread
->port
= MACH_PORT_NULL
;
1052 thread
= _proc_free (thread
); /* THREAD is dead. */
1054 last
->next
= thread
;
1056 inf
->threads
= thread
;
1060 for (i
= 0; i
< num_threads
; i
++)
1063 /* Throw away the duplicate send right. */
1064 mach_port_deallocate (mach_task_self (), threads
[i
]);
1066 /* THREADS[I] is a thread we don't know about yet! */
1068 thread
= make_proc (inf
, threads
[i
], next_thread_id
++);
1070 last
->next
= thread
;
1072 inf
->threads
= thread
;
1074 proc_debug (thread
, "new thread: %d", threads
[i
]);
1075 add_thread (pid_to_ptid (thread
->tid
)); /* Tell GDB's generic thread code. */
1079 vm_deallocate (mach_task_self (),
1080 (vm_address_t
) threads
, (num_threads
* sizeof (thread_t
)));
1085 /* Makes sure that INF's thread list is synced with the actual process. */
1087 inf_update_procs (struct inf
*inf
)
1091 if (!inf
->threads_up_to_date
)
1092 inf_validate_procs (inf
);
1096 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1097 and others are set to their run_sc if RUN_OTHERS is true, and otherwise
1100 inf_set_threads_resume_sc (struct inf
*inf
,
1101 struct proc
*run_thread
, int run_others
)
1103 struct proc
*thread
;
1104 inf_update_procs (inf
);
1105 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1106 if (thread
== run_thread
)
1107 thread
->resume_sc
= 0;
1108 else if (run_others
)
1109 thread
->resume_sc
= thread
->run_sc
;
1111 thread
->resume_sc
= thread
->pause_sc
;
1115 /* Cause INF to continue execution immediately; individual threads may still
1116 be suspended (but their suspend counts will be updated). */
1118 inf_resume (struct inf
*inf
)
1120 struct proc
*thread
;
1122 inf_update_procs (inf
);
1124 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1125 thread
->sc
= thread
->resume_sc
;
1129 if (!inf
->pending_execs
)
1130 /* Try to make sure our task count is correct -- in the case where
1131 we're waiting for an exec though, things are too volatile, so just
1132 assume things will be reasonable (which they usually will be). */
1133 inf_validate_task_sc (inf
);
1137 inf_update_suspends (inf
);
1140 /* Cause INF to stop execution immediately; individual threads may still
1143 inf_suspend (struct inf
*inf
)
1145 struct proc
*thread
;
1147 inf_update_procs (inf
);
1149 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1150 thread
->sc
= thread
->pause_sc
;
1153 inf
->task
->sc
= inf
->pause_sc
;
1155 inf_update_suspends (inf
);
1159 /* INF has one thread PROC that is in single-stepping mode. This
1160 function changes it to be PROC, changing any old step_thread to be
1161 a normal one. A PROC of 0 clears any existing value. */
1163 inf_set_step_thread (struct inf
*inf
, struct proc
*thread
)
1165 gdb_assert (!thread
|| proc_is_thread (thread
));
1168 inf_debug (inf
, "setting step thread: %d/%d", inf
->pid
, thread
->tid
);
1170 inf_debug (inf
, "clearing step thread");
1172 if (inf
->step_thread
!= thread
)
1174 if (inf
->step_thread
&& inf
->step_thread
->port
!= MACH_PORT_NULL
)
1175 if (!proc_trace (inf
->step_thread
, 0))
1177 if (thread
&& proc_trace (thread
, 1))
1178 inf
->step_thread
= thread
;
1180 inf
->step_thread
= 0;
1185 /* Set up the thread resume_sc's so that only the signal thread is running
1186 (plus whatever other thread are set to always run). Returns true if we
1187 did so, or false if we can't find a signal thread. */
1189 inf_set_threads_resume_sc_for_signal_thread (struct inf
*inf
)
1191 if (inf
->signal_thread
)
1193 inf_set_threads_resume_sc (inf
, inf
->signal_thread
, 0);
1201 inf_update_signal_thread (struct inf
*inf
)
1203 /* XXX for now we assume that if there's a msgport, the 2nd thread is
1204 the signal thread. */
1205 inf
->signal_thread
= inf
->threads
? inf
->threads
->next
: 0;
1209 /* Detachs from INF's inferior task, letting it run once again... */
1211 inf_detach (struct inf
*inf
)
1213 struct proc
*task
= inf
->task
;
1215 inf_debug (inf
, "detaching...");
1217 inf_clear_wait (inf
);
1218 inf_set_step_thread (inf
, 0);
1222 struct proc
*thread
;
1224 inf_validate_procinfo (inf
);
1226 inf_set_traced (inf
, 0);
1232 inf_signal (inf
, TARGET_SIGNAL_0
);
1235 proc_restore_exc_port (task
);
1236 task
->sc
= inf
->detach_sc
;
1238 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1240 proc_restore_exc_port (thread
);
1241 thread
->sc
= thread
->detach_sc
;
1244 inf_update_suspends (inf
);
1250 /* Attaches INF to the process with process id PID, returning it in a
1251 suspended state suitable for debugging. */
1253 inf_attach (struct inf
*inf
, int pid
)
1255 inf_debug (inf
, "attaching: %d", pid
);
1260 inf_startup (inf
, pid
);
1264 /* Makes sure that we've got our exception ports entrenched in the process. */
1266 inf_steal_exc_ports (struct inf
*inf
)
1268 struct proc
*thread
;
1270 inf_debug (inf
, "stealing exception ports");
1272 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1274 proc_steal_exc_port (inf
->task
, inf
->event_port
);
1275 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1276 proc_steal_exc_port (thread
, MACH_PORT_NULL
);
1279 /* Makes sure the process has its own exception ports. */
1281 inf_restore_exc_ports (struct inf
*inf
)
1283 struct proc
*thread
;
1285 inf_debug (inf
, "restoring exception ports");
1287 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1289 proc_restore_exc_port (inf
->task
);
1290 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1291 proc_restore_exc_port (thread
);
1295 /* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
1296 signal 0, will continue it. INF is assumed to be in a paused state, and
1297 the resume_sc's of INF's threads may be affected. */
1299 inf_signal (struct inf
*inf
, enum target_signal sig
)
1302 int host_sig
= target_signal_to_host (sig
);
1304 #define NAME target_signal_to_name (sig)
1306 if (host_sig
>= _NSIG
)
1307 /* A mach exception. Exceptions are encoded in the signal space by
1308 putting them after _NSIG; this assumes they're positive (and not
1309 extremely large)! */
1311 struct inf_wait
*w
= &inf
->wait
;
1312 if (w
->status
.kind
== TARGET_WAITKIND_STOPPED
1313 && w
->status
.value
.sig
== sig
1314 && w
->thread
&& !w
->thread
->aborted
)
1315 /* We're passing through the last exception we received. This is
1316 kind of bogus, because exceptions are per-thread whereas gdb
1317 treats signals as per-process. We just forward the exception to
1318 the correct handler, even it's not for the same thread as TID --
1319 i.e., we pretend it's global. */
1321 struct exc_state
*e
= &w
->exc
;
1322 inf_debug (inf
, "passing through exception:"
1323 " task = %d, thread = %d, exc = %d"
1324 ", code = %d, subcode = %d",
1325 w
->thread
->port
, inf
->task
->port
,
1326 e
->exception
, e
->code
, e
->subcode
);
1328 exception_raise_request (e
->handler
,
1329 e
->reply
, MACH_MSG_TYPE_MOVE_SEND_ONCE
,
1330 w
->thread
->port
, inf
->task
->port
,
1331 e
->exception
, e
->code
, e
->subcode
);
1334 error (_("Can't forward spontaneous exception (%s)."), NAME
);
1337 /* A Unix signal. */
1339 /* The process is stopped and expecting a signal. Just send off a
1340 request and let it get handled when we resume everything. */
1342 inf_debug (inf
, "sending %s to stopped process", NAME
);
1344 INF_MSGPORT_RPC (inf
,
1345 msg_sig_post_untraced_request (msgport
,
1347 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
1351 /* Posting an untraced signal automatically continues it.
1352 We clear this here rather than when we get the reply
1353 because we'd rather assume it's not stopped when it
1354 actually is, than the reverse. */
1358 /* It's not expecting it. We have to let just the signal thread
1359 run, and wait for it to get into a reasonable state before we
1360 can continue the rest of the process. When we finally resume the
1361 process the signal we request will be the very first thing that
1364 inf_debug (inf
, "sending %s to unstopped process"
1365 " (so resuming signal thread)", NAME
);
1367 INF_RESUME_MSGPORT_RPC (inf
,
1368 msg_sig_post_untraced (msgport
, host_sig
,
1373 /* Can't do too much... */
1374 warning (_("Can't deliver signal %s: No signal thread."), NAME
);
1376 warning (_("Delivering signal %s: %s"), NAME
, safe_strerror (err
));
1382 /* Continue INF without delivering a signal. This is meant to be used
1383 when INF does not have a message port. */
1385 inf_continue (struct inf
*inf
)
1388 error_t err
= proc_pid2proc (proc_server
, inf
->pid
, &proc
);
1392 inf_debug (inf
, "continuing process");
1394 err
= proc_mark_cont (proc
);
1397 struct proc
*thread
;
1399 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1400 thread_resume (thread
->port
);
1407 warning (_("Can't continue process: %s"), safe_strerror (err
));
1411 /* The inferior used for all gdb target ops. */
1412 struct inf
*current_inferior
= 0;
1414 /* The inferior being waited for by gnu_wait. Since GDB is decidely not
1415 multi-threaded, we don't bother to lock this. */
1416 struct inf
*waiting_inf
;
1418 /* Wait for something to happen in the inferior, returning what in STATUS. */
1420 gnu_wait (ptid_t tid
, struct target_waitstatus
*status
)
1424 mach_msg_header_t hdr
;
1425 mach_msg_type_t type
;
1429 struct proc
*thread
;
1430 struct inf
*inf
= current_inferior
;
1432 extern int exc_server (mach_msg_header_t
*, mach_msg_header_t
*);
1433 extern int msg_reply_server (mach_msg_header_t
*, mach_msg_header_t
*);
1434 extern int notify_server (mach_msg_header_t
*, mach_msg_header_t
*);
1435 extern int process_reply_server (mach_msg_header_t
*, mach_msg_header_t
*);
1437 gdb_assert (inf
->task
);
1439 if (!inf
->threads
&& !inf
->pending_execs
)
1440 /* No threads! Assume that maybe some outside agency is frobbing our
1441 task, and really look for new threads. If we can't find any, just tell
1442 the user to try again later. */
1444 inf_validate_procs (inf
);
1445 if (!inf
->threads
&& !inf
->task
->dead
)
1446 error (_("There are no threads; try again later."));
1451 inf_debug (inf
, "waiting for: %d", PIDGET (tid
));
1454 if (proc_wait_pid
!= inf
->pid
&& !inf
->no_wait
)
1455 /* Always get information on events from the proc server. */
1457 inf_debug (inf
, "requesting wait on pid %d", inf
->pid
);
1460 /* The proc server is single-threaded, and only allows a single
1461 outstanding wait request, so we have to cancel the previous one. */
1463 inf_debug (inf
, "cancelling previous wait on pid %d", proc_wait_pid
);
1464 interrupt_operation (proc_server
, 0);
1468 proc_wait_request (proc_server
, inf
->event_port
, inf
->pid
, WUNTRACED
);
1470 warning (_("wait request failed: %s"), safe_strerror (err
));
1473 inf_debug (inf
, "waits pending: %d", proc_waits_pending
);
1474 proc_wait_pid
= inf
->pid
;
1475 /* Even if proc_waits_pending was > 0 before, we still won't
1476 get any other replies, because it was either from a
1477 different INF, or a different process attached to INF --
1478 and the event port, which is the wait reply port, changes
1479 when you switch processes. */
1480 proc_waits_pending
= 1;
1484 inf_clear_wait (inf
);
1486 /* What can happen? (1) Dead name notification; (2) Exceptions arrive;
1487 (3) wait reply from the proc server. */
1489 inf_debug (inf
, "waiting for an event...");
1490 err
= mach_msg (&msg
.hdr
, MACH_RCV_MSG
| MACH_RCV_INTERRUPT
,
1491 0, sizeof (struct msg
), inf
->event_port
,
1492 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
1494 /* Re-suspend the task. */
1497 if (!inf
->task
&& inf
->pending_execs
)
1498 /* When doing an exec, it's possible that the old task wasn't reused
1499 (e.g., setuid execs). So if the task seems to have disappeared,
1500 attempt to refetch it, as the pid should still be the same. */
1501 inf_set_pid (inf
, inf
->pid
);
1503 if (err
== EMACH_RCV_INTERRUPTED
)
1504 inf_debug (inf
, "interrupted");
1506 error (_("Couldn't wait for an event: %s"), safe_strerror (err
));
1511 mach_msg_header_t hdr
;
1512 mach_msg_type_t err_type
;
1518 inf_debug (inf
, "event: msgid = %d", msg
.hdr
.msgh_id
);
1520 /* Handle what we got. */
1521 if (!notify_server (&msg
.hdr
, &reply
.hdr
)
1522 && !exc_server (&msg
.hdr
, &reply
.hdr
)
1523 && !process_reply_server (&msg
.hdr
, &reply
.hdr
)
1524 && !msg_reply_server (&msg
.hdr
, &reply
.hdr
))
1525 /* Whatever it is, it's something strange. */
1526 error (_("Got a strange event, msg id = %d."), msg
.hdr
.msgh_id
);
1529 error (_("Handling event, msgid = %d: %s"),
1530 msg
.hdr
.msgh_id
, safe_strerror (reply
.err
));
1533 if (inf
->pending_execs
)
1534 /* We're waiting for the inferior to finish execing. */
1536 struct inf_wait
*w
= &inf
->wait
;
1537 enum target_waitkind kind
= w
->status
.kind
;
1539 if (kind
== TARGET_WAITKIND_SPURIOUS
)
1540 /* Since gdb is actually counting the number of times the inferior
1541 stops, expecting one stop per exec, we only return major events
1545 inf_debug (inf
, "pending_execs = %d, ignoring minor event",
1546 inf
->pending_execs
);
1548 else if (kind
== TARGET_WAITKIND_STOPPED
1549 && w
->status
.value
.sig
== TARGET_SIGNAL_TRAP
)
1550 /* Ah hah! A SIGTRAP from the inferior while starting up probably
1551 means we've succesfully completed an exec! */
1553 if (--inf
->pending_execs
== 0)
1556 #if 0 /* do we need this? */
1557 prune_threads (1); /* Get rid of the old shell threads */
1558 renumber_threads (0); /* Give our threads reasonable names. */
1561 inf_debug (inf
, "pending exec completed, pending_execs => %d",
1562 inf
->pending_execs
);
1564 else if (kind
== TARGET_WAITKIND_STOPPED
)
1565 /* It's possible that this signal is because of a crashed process
1566 being handled by the hurd crash server; in this case, the process
1567 will have an extra task suspend, which we need to know about.
1568 Since the code in inf_resume that normally checks for this is
1569 disabled while INF->pending_execs, we do the check here instead. */
1570 inf_validate_task_sc (inf
);
1573 if (inf
->wait
.suppress
)
1574 /* Some totally spurious event happened that we don't consider
1575 worth returning to gdb. Just keep waiting. */
1577 inf_debug (inf
, "suppressing return, rewaiting...");
1582 /* Pass back out our results. */
1583 memcpy (status
, &inf
->wait
.status
, sizeof (*status
));
1585 thread
= inf
->wait
.thread
;
1587 tid
= pid_to_ptid (thread
->tid
);
1589 thread
= inf_tid_to_thread (inf
, PIDGET (tid
));
1591 if (!thread
|| thread
->port
== MACH_PORT_NULL
)
1593 /* TID is dead; try and find a new thread. */
1594 if (inf_update_procs (inf
) && inf
->threads
)
1595 tid
= pid_to_ptid (inf
->threads
->tid
); /* The first available thread. */
1597 tid
= inferior_ptid
; /* let wait_for_inferior handle exit case */
1600 if (thread
&& PIDGET (tid
) >= 0 && status
->kind
!= TARGET_WAITKIND_SPURIOUS
1601 && inf
->pause_sc
== 0 && thread
->pause_sc
== 0)
1602 /* If something actually happened to THREAD, make sure we
1606 inf_update_suspends (inf
);
1609 inf_debug (inf
, "returning tid = %d, status = %s (%d)", PIDGET (tid
),
1610 status
->kind
== TARGET_WAITKIND_EXITED
? "EXITED"
1611 : status
->kind
== TARGET_WAITKIND_STOPPED
? "STOPPED"
1612 : status
->kind
== TARGET_WAITKIND_SIGNALLED
? "SIGNALLED"
1613 : status
->kind
== TARGET_WAITKIND_LOADED
? "LOADED"
1614 : status
->kind
== TARGET_WAITKIND_SPURIOUS
? "SPURIOUS"
1616 status
->value
.integer
);
1622 /* The rpc handler called by exc_server. */
1624 S_exception_raise_request (mach_port_t port
, mach_port_t reply_port
,
1625 thread_t thread_port
, task_t task_port
,
1626 int exception
, int code
, int subcode
)
1628 struct inf
*inf
= waiting_inf
;
1629 struct proc
*thread
= inf_port_to_thread (inf
, thread_port
);
1631 inf_debug (waiting_inf
,
1632 "thread = %d, task = %d, exc = %d, code = %d, subcode = %d",
1633 thread_port
, task_port
, exception
, code
, subcode
);
1636 /* We don't know about thread? */
1638 inf_update_procs (inf
);
1639 thread
= inf_port_to_thread (inf
, thread_port
);
1641 /* Give up, the generating thread is gone. */
1645 mach_port_deallocate (mach_task_self (), thread_port
);
1646 mach_port_deallocate (mach_task_self (), task_port
);
1648 if (!thread
->aborted
)
1649 /* THREAD hasn't been aborted since this exception happened (abortion
1650 clears any exception state), so it must be real. */
1652 /* Store away the details; this will destroy any previous info. */
1653 inf
->wait
.thread
= thread
;
1655 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1657 if (exception
== EXC_BREAKPOINT
)
1658 /* GDB likes to get SIGTRAP for breakpoints. */
1660 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_TRAP
;
1661 mach_port_deallocate (mach_task_self (), reply_port
);
1664 /* Record the exception so that we can forward it later. */
1666 if (thread
->exc_port
== port
)
1668 inf_debug (waiting_inf
, "Handler is thread exception port <%d>",
1669 thread
->saved_exc_port
);
1670 inf
->wait
.exc
.handler
= thread
->saved_exc_port
;
1674 inf_debug (waiting_inf
, "Handler is task exception port <%d>",
1675 inf
->task
->saved_exc_port
);
1676 inf
->wait
.exc
.handler
= inf
->task
->saved_exc_port
;
1677 gdb_assert (inf
->task
->exc_port
== port
);
1679 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
1680 /* Add a reference to the exception handler. */
1681 mach_port_mod_refs (mach_task_self (),
1682 inf
->wait
.exc
.handler
, MACH_PORT_RIGHT_SEND
,
1685 inf
->wait
.exc
.exception
= exception
;
1686 inf
->wait
.exc
.code
= code
;
1687 inf
->wait
.exc
.subcode
= subcode
;
1688 inf
->wait
.exc
.reply
= reply_port
;
1690 /* Exceptions are encoded in the signal space by putting them after
1691 _NSIG; this assumes they're positive (and not extremely large)! */
1692 inf
->wait
.status
.value
.sig
=
1693 target_signal_from_host (_NSIG
+ exception
);
1697 /* A supppressed exception, which ignore. */
1699 inf
->wait
.suppress
= 1;
1700 mach_port_deallocate (mach_task_self (), reply_port
);
1707 /* Fill in INF's wait field after a task has died without giving us more
1708 detailed information. */
1710 inf_task_died_status (struct inf
*inf
)
1712 warning (_("Pid %d died with unknown exit status, using SIGKILL."), inf
->pid
);
1713 inf
->wait
.status
.kind
= TARGET_WAITKIND_SIGNALLED
;
1714 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_KILL
;
1717 /* Notify server routines. The only real one is dead name notification. */
1719 do_mach_notify_dead_name (mach_port_t notify
, mach_port_t dead_port
)
1721 struct inf
*inf
= waiting_inf
;
1723 inf_debug (waiting_inf
, "port = %d", dead_port
);
1725 if (inf
->task
&& inf
->task
->port
== dead_port
)
1727 proc_debug (inf
->task
, "is dead");
1728 inf
->task
->port
= MACH_PORT_NULL
;
1729 if (proc_wait_pid
== inf
->pid
)
1730 /* We have a wait outstanding on the process, which will return more
1731 detailed information, so delay until we get that. */
1732 inf
->wait
.suppress
= 1;
1734 /* We never waited for the process (maybe it wasn't a child), so just
1735 pretend it got a SIGKILL. */
1736 inf_task_died_status (inf
);
1740 struct proc
*thread
= inf_port_to_thread (inf
, dead_port
);
1743 proc_debug (thread
, "is dead");
1744 thread
->port
= MACH_PORT_NULL
;
1747 if (inf
->task
->dead
)
1748 /* Since the task is dead, its threads are dying with it. */
1749 inf
->wait
.suppress
= 1;
1752 mach_port_deallocate (mach_task_self (), dead_port
);
1753 inf
->threads_up_to_date
= 0; /* Just in case */
1762 warning (_("illegal rpc: %s"), fun
);
1767 do_mach_notify_no_senders (mach_port_t notify
, mach_port_mscount_t count
)
1769 return ill_rpc ("do_mach_notify_no_senders");
1773 do_mach_notify_port_deleted (mach_port_t notify
, mach_port_t name
)
1775 return ill_rpc ("do_mach_notify_port_deleted");
1779 do_mach_notify_msg_accepted (mach_port_t notify
, mach_port_t name
)
1781 return ill_rpc ("do_mach_notify_msg_accepted");
1785 do_mach_notify_port_destroyed (mach_port_t notify
, mach_port_t name
)
1787 return ill_rpc ("do_mach_notify_port_destroyed");
1791 do_mach_notify_send_once (mach_port_t notify
)
1793 return ill_rpc ("do_mach_notify_send_once");
1797 /* Process_reply server routines. We only use process_wait_reply. */
1800 S_proc_wait_reply (mach_port_t reply
, error_t err
,
1801 int status
, int sigcode
, rusage_t rusage
, pid_t pid
)
1803 struct inf
*inf
= waiting_inf
;
1805 inf_debug (inf
, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1806 err
? safe_strerror (err
) : "0", pid
, status
, sigcode
);
1808 if (err
&& proc_wait_pid
&& (!inf
->task
|| !inf
->task
->port
))
1809 /* Ack. The task has died, but the task-died notification code didn't
1810 tell anyone because it thought a more detailed reply from the
1811 procserver was forthcoming. However, we now learn that won't
1812 happen... So we have to act like the task just died, and this time,
1814 inf_task_died_status (inf
);
1816 if (--proc_waits_pending
== 0)
1817 /* PROC_WAIT_PID represents the most recent wait. We will always get
1818 replies in order because the proc server is single threaded. */
1821 inf_debug (inf
, "waits pending now: %d", proc_waits_pending
);
1827 warning (_("Can't wait for pid %d: %s"), inf
->pid
, safe_strerror (err
));
1830 /* Since we can't see the inferior's signals, don't trap them. */
1831 inf_set_traced (inf
, 0);
1834 else if (pid
== inf
->pid
)
1836 store_waitstatus (&inf
->wait
.status
, status
);
1837 if (inf
->wait
.status
.kind
== TARGET_WAITKIND_STOPPED
)
1838 /* The process has sent us a signal, and stopped itself in a sane
1839 state pending our actions. */
1841 inf_debug (inf
, "process has stopped itself");
1846 inf
->wait
.suppress
= 1; /* Something odd happened. Ignore. */
1852 S_proc_setmsgport_reply (mach_port_t reply
, error_t err
,
1853 mach_port_t old_msg_port
)
1855 return ill_rpc ("S_proc_setmsgport_reply");
1859 S_proc_getmsgport_reply (mach_port_t reply
, error_t err
, mach_port_t msg_port
)
1861 return ill_rpc ("S_proc_getmsgport_reply");
1865 /* Msg_reply server routines. We only use msg_sig_post_untraced_reply. */
1868 S_msg_sig_post_untraced_reply (mach_port_t reply
, error_t err
)
1870 struct inf
*inf
= waiting_inf
;
1873 /* EBUSY is what we get when the crash server has grabbed control of the
1874 process and doesn't like what signal we tried to send it. Just act
1875 like the process stopped (using a signal of 0 should mean that the
1876 *next* time the user continues, it will pass signal 0, which the crash
1877 server should like). */
1879 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1880 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_0
;
1883 warning (_("Signal delivery failed: %s"), safe_strerror (err
));
1886 /* We only get this reply when we've posted a signal to a process which we
1887 thought was stopped, and which we expected to continue after the signal.
1888 Given that the signal has failed for some reason, it's reasonable to
1889 assume it's still stopped. */
1892 inf
->wait
.suppress
= 1;
1898 S_msg_sig_post_reply (mach_port_t reply
, error_t err
)
1900 return ill_rpc ("S_msg_sig_post_reply");
1904 /* Returns the number of messages queued for the receive right PORT. */
1905 static mach_port_msgcount_t
1906 port_msgs_queued (mach_port_t port
)
1908 struct mach_port_status status
;
1910 mach_port_get_receive_status (mach_task_self (), port
, &status
);
1915 return status
.mps_msgcount
;
1919 /* Resume execution of the inferior process.
1921 If STEP is nonzero, single-step it.
1922 If SIGNAL is nonzero, give it that signal.
1925 -1 true Single step the current thread allowing other threads to run.
1926 -1 false Continue the current thread allowing other threads to run.
1927 X true Single step the given thread, don't allow any others to run.
1928 X false Continue the given thread, do not allow any others to run.
1929 (Where X, of course, is anything except -1)
1931 Note that a resume may not `take' if there are pending exceptions/&c
1932 still unprocessed from the last resume we did (any given resume may result
1933 in multiple events returned by wait).
1936 gnu_resume (ptid_t tid
, int step
, enum target_signal sig
)
1938 struct proc
*step_thread
= 0;
1939 struct inf
*inf
= current_inferior
;
1941 inf_debug (inf
, "tid = %d, step = %d, sig = %d", PIDGET (tid
), step
, sig
);
1943 inf_validate_procinfo (inf
);
1945 if (sig
!= TARGET_SIGNAL_0
|| inf
->stopped
)
1947 if (sig
== TARGET_SIGNAL_0
&& inf
->nomsg
)
1950 inf_signal (inf
, sig
);
1952 else if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
1953 /* We received an exception to which we have chosen not to forward, so
1954 abort the faulting thread, which will perhaps retake it. */
1956 proc_abort (inf
->wait
.thread
, 1);
1957 warning (_("Aborting %s with unforwarded exception %s."),
1958 proc_string (inf
->wait
.thread
),
1959 target_signal_to_name (inf
->wait
.status
.value
.sig
));
1962 if (port_msgs_queued (inf
->event_port
))
1963 /* If there are still messages in our event queue, don't bother resuming
1964 the process, as we're just going to stop it right away anyway. */
1967 inf_update_procs (inf
);
1969 if (PIDGET (tid
) < 0)
1970 /* Allow all threads to run, except perhaps single-stepping one. */
1972 inf_debug (inf
, "running all threads; tid = %d", PIDGET (inferior_ptid
));
1973 tid
= inferior_ptid
; /* What to step. */
1974 inf_set_threads_resume_sc (inf
, 0, 1);
1977 /* Just allow a single thread to run. */
1979 struct proc
*thread
= inf_tid_to_thread (inf
, PIDGET (tid
));
1981 error (_("Can't run single thread id %d: no such thread!"));
1982 inf_debug (inf
, "running one thread: %d/%d", inf
->pid
, thread
->tid
);
1983 inf_set_threads_resume_sc (inf
, thread
, 0);
1988 step_thread
= inf_tid_to_thread (inf
, PIDGET (tid
));
1990 warning (_("Can't step thread id %d: no such thread."), PIDGET (tid
));
1992 inf_debug (inf
, "stepping thread: %d/%d", inf
->pid
, step_thread
->tid
);
1994 if (step_thread
!= inf
->step_thread
)
1995 inf_set_step_thread (inf
, step_thread
);
1997 inf_debug (inf
, "here we go...");
2003 gnu_kill_inferior (void)
2005 struct proc
*task
= current_inferior
->task
;
2008 proc_debug (task
, "terminating...");
2009 task_terminate (task
->port
);
2010 inf_set_pid (current_inferior
, -1);
2012 target_mourn_inferior ();
2015 /* Clean up after the inferior dies. */
2017 gnu_mourn_inferior (void)
2019 inf_debug (current_inferior
, "rip");
2020 inf_detach (current_inferior
);
2021 unpush_target (&gnu_ops
);
2022 generic_mourn_inferior ();
2026 /* Fork an inferior process, and start debugging it. */
2028 /* Set INFERIOR_PID to the first thread available in the child, if any. */
2030 inf_pick_first_thread (void)
2032 if (current_inferior
->task
&& current_inferior
->threads
)
2033 /* The first thread. */
2034 return current_inferior
->threads
->tid
;
2036 /* What may be the next thread. */
2037 return next_thread_id
;
2043 if (!current_inferior
)
2044 current_inferior
= make_inf ();
2045 return current_inferior
;
2049 gnu_create_inferior (char *exec_file
, char *allargs
, char **env
,
2052 struct inf
*inf
= cur_inf ();
2056 /* We're in the child; make this process stop as soon as it execs. */
2057 inf_debug (inf
, "tracing self");
2058 if (ptrace (PTRACE_TRACEME
) != 0)
2059 error (_("ptrace (PTRACE_TRACEME) failed!"));
2061 void attach_to_child (int pid
)
2063 /* Attach to the now stopped child, which is actually a shell... */
2064 inf_debug (inf
, "attaching to child: %d", pid
);
2066 inf_attach (inf
, pid
);
2069 push_target (&gnu_ops
);
2071 inf
->pending_execs
= 2;
2075 /* Now let the child run again, knowing that it will stop immediately
2076 because of the ptrace. */
2078 inferior_ptid
= pid_to_ptid (inf_pick_first_thread ());
2080 startup_inferior (inf
->pending_execs
);
2083 inf_debug (inf
, "creating inferior");
2085 fork_inferior (exec_file
, allargs
, env
, trace_me
, attach_to_child
,
2088 inf_validate_procinfo (inf
);
2089 inf_update_signal_thread (inf
);
2090 inf_set_traced (inf
, inf
->want_signals
);
2092 /* Execing the process will have trashed our exception ports; steal them
2093 back (or make sure they're restored if the user wants that). */
2094 if (inf
->want_exceptions
)
2095 inf_steal_exc_ports (inf
);
2097 inf_restore_exc_ports (inf
);
2100 /* Mark our target-struct as eligible for stray "run" and "attach"
2109 /* Attach to process PID, then initialize for debugging it
2110 and wait for the trace-trap that results from attaching. */
2112 gnu_attach (char *args
, int from_tty
)
2116 struct inf
*inf
= cur_inf ();
2119 error_no_arg (_("process-id to attach"));
2123 if (pid
== getpid ()) /* Trying to masturbate? */
2124 error (_("I refuse to debug myself!"));
2128 exec_file
= (char *) get_exec_file (0);
2131 printf_unfiltered ("Attaching to program `%s', pid %d\n",
2134 printf_unfiltered ("Attaching to pid %d\n", pid
);
2136 gdb_flush (gdb_stdout
);
2139 inf_debug (inf
, "attaching to pid: %d", pid
);
2141 inf_attach (inf
, pid
);
2142 inf_update_procs (inf
);
2144 inferior_ptid
= pid_to_ptid (inf_pick_first_thread ());
2147 push_target (&gnu_ops
);
2149 /* We have to initialize the terminal settings now, since the code
2150 below might try to restore them. */
2151 target_terminal_init ();
2153 /* If the process was stopped before we attached, make it continue the next
2154 time the user does a continue. */
2155 inf_validate_procinfo (inf
);
2157 inf_update_signal_thread (inf
);
2158 inf_set_traced (inf
, inf
->want_signals
);
2160 #if 0 /* Do we need this? */
2161 renumber_threads (0); /* Give our threads reasonable names. */
2166 /* Take a program previously attached to and detaches it.
2167 The program resumes execution and will no longer stop
2168 on signals, etc. We'd better not have left any breakpoints
2169 in the program or it'll die when it hits one. For this
2170 to work, it may be necessary for the process to have been
2171 previously attached. It *might* work if the program was
2172 started via fork. */
2174 gnu_detach (char *args
, int from_tty
)
2178 char *exec_file
= get_exec_file (0);
2180 printf_unfiltered ("Detaching from program `%s' pid %d\n",
2181 exec_file
, current_inferior
->pid
);
2183 printf_unfiltered ("Detaching from pid %d\n", current_inferior
->pid
);
2184 gdb_flush (gdb_stdout
);
2187 inf_detach (current_inferior
);
2189 inferior_ptid
= null_ptid
;
2191 unpush_target (&gnu_ops
); /* Pop out of handling an inferior */
2195 gnu_terminal_init_inferior (void)
2197 gdb_assert (current_inferior
);
2198 terminal_init_inferior_with_pgrp (current_inferior
->pid
);
2201 /* Get ready to modify the registers array. On machines which store
2202 individual registers, this doesn't need to do anything. On machines
2203 which store all the registers in one fell swoop, this makes sure
2204 that registers contains all the registers from the program being
2207 gnu_prepare_to_store (void)
2209 #ifdef CHILD_PREPARE_TO_STORE
2210 CHILD_PREPARE_TO_STORE ();
2215 gnu_open (char *arg
, int from_tty
)
2217 error (_("Use the \"run\" command to start a Unix child process."));
2223 error (_("to_stop target function not implemented"));
2227 gnu_pid_to_exec_file (int pid
)
2229 error (_("to_pid_to_exec_file target function not implemented"));
2235 gnu_thread_alive (ptid_t tid
)
2237 inf_update_procs (current_inferior
);
2238 return !!inf_tid_to_thread (current_inferior
, PIDGET (tid
));
2242 /* Read inferior task's LEN bytes from ADDR and copy it to MYADDR in
2243 gdb's address space. Return 0 on failure; number of bytes read
2246 gnu_read_inferior (task_t task
, CORE_ADDR addr
, char *myaddr
, int length
)
2249 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2250 vm_size_t aligned_length
=
2251 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2255 /* Get memory from inferior with page aligned addresses */
2256 err
= vm_read (task
, low_address
, aligned_length
, &copied
, ©_count
);
2260 err
= hurd_safe_copyin (myaddr
, (void *) addr
- low_address
+ copied
, length
);
2263 warning (_("Read from inferior faulted: %s"), safe_strerror (err
));
2267 err
= vm_deallocate (mach_task_self (), copied
, copy_count
);
2269 warning (_("gnu_read_inferior vm_deallocate failed: %s"), safe_strerror (err
));
2274 #define CHK_GOTO_OUT(str,ret) \
2275 do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
2277 struct vm_region_list
2279 struct vm_region_list
*next
;
2280 vm_prot_t protection
;
2285 struct obstack region_obstack
;
2287 /* Write gdb's LEN bytes from MYADDR and copy it to ADDR in inferior
2288 task's address space. */
2290 gnu_write_inferior (task_t task
, CORE_ADDR addr
, char *myaddr
, int length
)
2293 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2294 vm_size_t aligned_length
=
2295 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2300 char *errstr
= "Bug in gnu_write_inferior";
2302 struct vm_region_list
*region_element
;
2303 struct vm_region_list
*region_head
= (struct vm_region_list
*) NULL
;
2305 /* Get memory from inferior with page aligned addresses */
2306 err
= vm_read (task
,
2311 CHK_GOTO_OUT ("gnu_write_inferior vm_read failed", err
);
2315 err
= hurd_safe_copyout ((void *) addr
- low_address
+ copied
,
2317 CHK_GOTO_OUT ("Write to inferior faulted", err
);
2319 obstack_init (®ion_obstack
);
2321 /* Do writes atomically.
2322 First check for holes and unwritable memory. */
2324 vm_size_t remaining_length
= aligned_length
;
2325 vm_address_t region_address
= low_address
;
2327 struct vm_region_list
*scan
;
2329 while (region_address
< low_address
+ aligned_length
)
2331 vm_prot_t protection
;
2332 vm_prot_t max_protection
;
2333 vm_inherit_t inheritance
;
2335 mach_port_t object_name
;
2337 vm_size_t region_length
= remaining_length
;
2338 vm_address_t old_address
= region_address
;
2340 err
= vm_region (task
,
2349 CHK_GOTO_OUT ("vm_region failed", err
);
2351 /* Check for holes in memory */
2352 if (old_address
!= region_address
)
2354 warning (_("No memory at 0x%x. Nothing written"),
2361 if (!(max_protection
& VM_PROT_WRITE
))
2363 warning (_("Memory at address 0x%x is unwritable. Nothing written"),
2370 /* Chain the regions for later use */
2372 (struct vm_region_list
*)
2373 obstack_alloc (®ion_obstack
, sizeof (struct vm_region_list
));
2375 region_element
->protection
= protection
;
2376 region_element
->start
= region_address
;
2377 region_element
->length
= region_length
;
2379 /* Chain the regions along with protections */
2380 region_element
->next
= region_head
;
2381 region_head
= region_element
;
2383 region_address
+= region_length
;
2384 remaining_length
= remaining_length
- region_length
;
2387 /* If things fail after this, we give up.
2388 Somebody is messing up inferior_task's mappings. */
2390 /* Enable writes to the chained vm regions */
2391 for (scan
= region_head
; scan
; scan
= scan
->next
)
2393 if (!(scan
->protection
& VM_PROT_WRITE
))
2395 err
= vm_protect (task
,
2399 scan
->protection
| VM_PROT_WRITE
);
2400 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2404 err
= vm_write (task
,
2408 CHK_GOTO_OUT ("vm_write failed", err
);
2410 /* Set up the original region protections, if they were changed */
2411 for (scan
= region_head
; scan
; scan
= scan
->next
)
2413 if (!(scan
->protection
& VM_PROT_WRITE
))
2415 err
= vm_protect (task
,
2420 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2428 obstack_free (®ion_obstack
, 0);
2430 (void) vm_deallocate (mach_task_self (),
2435 if (err
!= KERN_SUCCESS
)
2437 warning (_("%s: %s"), errstr
, mach_error_string (err
));
2445 /* Return 0 on failure, number of bytes handled otherwise. TARGET
2448 gnu_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
2449 struct mem_attrib
*attrib
,
2450 struct target_ops
*target
)
2452 task_t task
= (current_inferior
2453 ? (current_inferior
->task
2454 ? current_inferior
->task
->port
: 0)
2457 if (task
== MACH_PORT_NULL
)
2461 inf_debug (current_inferior
, "%s %p[%d] %s %p",
2462 write
? "writing" : "reading", (void *) memaddr
, len
,
2463 write
? "<--" : "-->", myaddr
);
2465 return gnu_write_inferior (task
, memaddr
, myaddr
, len
);
2467 return gnu_read_inferior (task
, memaddr
, myaddr
, len
);
2471 /* Call FUNC on each memory region in the task. */
2473 gnu_find_memory_regions (int (*func
) (CORE_ADDR
,
2481 vm_address_t region_address
, last_region_address
, last_region_end
;
2482 vm_prot_t last_protection
;
2484 if (current_inferior
== 0 || current_inferior
->task
== 0)
2486 task
= current_inferior
->task
->port
;
2487 if (task
== MACH_PORT_NULL
)
2490 region_address
= last_region_address
= last_region_end
= VM_MIN_ADDRESS
;
2491 last_protection
= VM_PROT_NONE
;
2492 while (region_address
< VM_MAX_ADDRESS
)
2494 vm_prot_t protection
;
2495 vm_prot_t max_protection
;
2496 vm_inherit_t inheritance
;
2498 mach_port_t object_name
;
2500 vm_size_t region_length
= VM_MAX_ADDRESS
- region_address
;
2501 vm_address_t old_address
= region_address
;
2503 err
= vm_region (task
,
2512 if (err
== KERN_NO_SPACE
)
2514 if (err
!= KERN_SUCCESS
)
2516 warning (_("vm_region failed: %s"), mach_error_string (err
));
2520 if (protection
== last_protection
&& region_address
== last_region_end
)
2521 /* This region is contiguous with and indistinguishable from
2522 the previous one, so we just extend that one. */
2523 last_region_end
= region_address
+= region_length
;
2526 /* This region is distinct from the last one we saw, so report
2527 that previous one. */
2528 if (last_protection
!= VM_PROT_NONE
)
2529 (*func
) (last_region_address
,
2530 last_region_end
- last_region_address
,
2531 last_protection
& VM_PROT_READ
,
2532 last_protection
& VM_PROT_WRITE
,
2533 last_protection
& VM_PROT_EXECUTE
,
2535 last_region_address
= region_address
;
2536 last_region_end
= region_address
+= region_length
;
2537 last_protection
= protection
;
2541 /* Report the final region. */
2542 if (last_region_end
> last_region_address
&& last_protection
!= VM_PROT_NONE
)
2543 (*func
) (last_region_address
, last_region_end
- last_region_address
,
2544 last_protection
& VM_PROT_READ
,
2545 last_protection
& VM_PROT_WRITE
,
2546 last_protection
& VM_PROT_EXECUTE
,
2553 /* Return printable description of proc. */
2555 proc_string (struct proc
*proc
)
2557 static char tid_str
[80];
2558 if (proc_is_task (proc
))
2559 sprintf (tid_str
, "process %d", proc
->inf
->pid
);
2561 sprintf (tid_str
, "thread %d.%d",
2562 proc
->inf
->pid
, pid_to_thread_id (MERGEPID (proc
->tid
, 0)));
2567 gnu_pid_to_str (ptid_t ptid
)
2569 struct inf
*inf
= current_inferior
;
2570 int tid
= PIDGET (ptid
);
2571 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
2574 return proc_string (thread
);
2577 static char tid_str
[80];
2578 sprintf (tid_str
, "bogus thread id %d", tid
);
2584 extern void gnu_store_registers (int regno
);
2585 extern void gnu_fetch_registers (int regno
);
2587 struct target_ops gnu_ops
;
2592 gnu_ops
.to_shortname
= "GNU"; /* to_shortname */
2593 gnu_ops
.to_longname
= "GNU Hurd process"; /* to_longname */
2594 gnu_ops
.to_doc
= "GNU Hurd process"; /* to_doc */
2595 gnu_ops
.to_open
= gnu_open
; /* to_open */
2596 gnu_ops
.to_attach
= gnu_attach
; /* to_attach */
2597 gnu_ops
.to_detach
= gnu_detach
; /* to_detach */
2598 gnu_ops
.to_resume
= gnu_resume
; /* to_resume */
2599 gnu_ops
.to_wait
= gnu_wait
; /* to_wait */
2600 gnu_ops
.to_fetch_registers
= gnu_fetch_registers
; /* to_fetch_registers */
2601 gnu_ops
.to_store_registers
= gnu_store_registers
; /* to_store_registers */
2602 gnu_ops
.to_prepare_to_store
= gnu_prepare_to_store
; /* to_prepare_to_store */
2603 gnu_ops
.deprecated_xfer_memory
= gnu_xfer_memory
;
2604 gnu_ops
.to_find_memory_regions
= gnu_find_memory_regions
;
2605 gnu_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
2606 gnu_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
2607 gnu_ops
.to_terminal_init
= gnu_terminal_init_inferior
;
2608 gnu_ops
.to_terminal_inferior
= terminal_inferior
;
2609 gnu_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
2610 gnu_ops
.to_terminal_save_ours
= terminal_save_ours
;
2611 gnu_ops
.to_terminal_ours
= terminal_ours
;
2612 gnu_ops
.to_terminal_info
= child_terminal_info
;
2613 gnu_ops
.to_kill
= gnu_kill_inferior
; /* to_kill */
2614 gnu_ops
.to_create_inferior
= gnu_create_inferior
; /* to_create_inferior */
2615 gnu_ops
.to_mourn_inferior
= gnu_mourn_inferior
; /* to_mourn_inferior */
2616 gnu_ops
.to_can_run
= gnu_can_run
; /* to_can_run */
2617 gnu_ops
.to_thread_alive
= gnu_thread_alive
; /* to_thread_alive */
2618 gnu_ops
.to_pid_to_str
= gnu_pid_to_str
; /* to_pid_to_str */
2619 gnu_ops
.to_stop
= gnu_stop
; /* to_stop */
2620 gnu_ops
.to_pid_to_exec_file
= gnu_pid_to_exec_file
; /* to_pid_to_exec_file */
2621 gnu_ops
.to_stratum
= process_stratum
; /* to_stratum */
2622 gnu_ops
.to_has_all_memory
= 1; /* to_has_all_memory */
2623 gnu_ops
.to_has_memory
= 1; /* to_has_memory */
2624 gnu_ops
.to_has_stack
= 1; /* to_has_stack */
2625 gnu_ops
.to_has_registers
= 1; /* to_has_registers */
2626 gnu_ops
.to_has_execution
= 1; /* to_has_execution */
2627 gnu_ops
.to_magic
= OPS_MAGIC
; /* to_magic */
2628 } /* init_gnu_ops */
2631 /* User task commands. */
2633 struct cmd_list_element
*set_task_cmd_list
= 0;
2634 struct cmd_list_element
*show_task_cmd_list
= 0;
2635 /* User thread commands. */
2637 /* Commands with a prefix of `set/show thread'. */
2638 extern struct cmd_list_element
*thread_cmd_list
;
2639 struct cmd_list_element
*set_thread_cmd_list
= NULL
;
2640 struct cmd_list_element
*show_thread_cmd_list
= NULL
;
2642 /* Commands with a prefix of `set/show thread default'. */
2643 struct cmd_list_element
*set_thread_default_cmd_list
= NULL
;
2644 struct cmd_list_element
*show_thread_default_cmd_list
= NULL
;
2647 set_thread_cmd (char *args
, int from_tty
)
2649 printf_unfiltered ("\"set thread\" must be followed by the name of a thread property, or \"default\".\n");
2653 show_thread_cmd (char *args
, int from_tty
)
2655 printf_unfiltered ("\"show thread\" must be followed by the name of a thread property, or \"default\".\n");
2659 set_thread_default_cmd (char *args
, int from_tty
)
2661 printf_unfiltered ("\"set thread default\" must be followed by the name of a thread property.\n");
2665 show_thread_default_cmd (char *args
, int from_tty
)
2667 printf_unfiltered ("\"show thread default\" must be followed by the name of a thread property.\n");
2671 parse_int_arg (char *args
, char *cmd_prefix
)
2676 int val
= strtoul (args
, &arg_end
, 10);
2677 if (*args
&& *arg_end
== '\0')
2680 error (_("Illegal argument for \"%s\" command, should be an integer."), cmd_prefix
);
2684 _parse_bool_arg (char *args
, char *t_val
, char *f_val
, char *cmd_prefix
)
2686 if (!args
|| strcmp (args
, t_val
) == 0)
2688 else if (strcmp (args
, f_val
) == 0)
2691 error (_("Illegal argument for \"%s\" command, should be \"%s\" or \"%s\"."),
2692 cmd_prefix
, t_val
, f_val
);
2695 #define parse_bool_arg(args, cmd_prefix) \
2696 _parse_bool_arg (args, "on", "off", cmd_prefix)
2699 check_empty (char *args
, char *cmd_prefix
)
2702 error (_("Garbage after \"%s\" command: `%s'"), cmd_prefix
, args
);
2705 /* Returns the alive thread named by INFERIOR_PID, or signals an error. */
2706 static struct proc
*
2709 struct inf
*inf
= cur_inf ();
2710 struct proc
*thread
= inf_tid_to_thread (inf
, PIDGET (inferior_ptid
));
2712 error (_("No current thread."));
2716 /* Returns the current inferior, but signals an error if it has no task. */
2720 struct inf
*inf
= cur_inf ();
2722 error (_("No current process."));
2728 set_task_pause_cmd (char *args
, int from_tty
)
2730 struct inf
*inf
= cur_inf ();
2731 int old_sc
= inf
->pause_sc
;
2733 inf
->pause_sc
= parse_bool_arg (args
, "set task pause");
2735 if (old_sc
== 0 && inf
->pause_sc
!= 0)
2736 /* If the task is currently unsuspended, immediately suspend it,
2737 otherwise wait until the next time it gets control. */
2742 show_task_pause_cmd (char *args
, int from_tty
)
2744 struct inf
*inf
= cur_inf ();
2745 check_empty (args
, "show task pause");
2746 printf_unfiltered ("The inferior task %s suspended while gdb has control.\n",
2748 ? (inf
->pause_sc
== 0 ? "isn't" : "is")
2749 : (inf
->pause_sc
== 0 ? "won't be" : "will be"));
2753 set_task_detach_sc_cmd (char *args
, int from_tty
)
2755 cur_inf ()->detach_sc
= parse_int_arg (args
, "set task detach-suspend-count");
2759 show_task_detach_sc_cmd (char *args
, int from_tty
)
2761 check_empty (args
, "show task detach-suspend-count");
2762 printf_unfiltered ("The inferior task will be left with a suspend count of %d when detaching.\n",
2763 cur_inf ()->detach_sc
);
2768 set_thread_default_pause_cmd (char *args
, int from_tty
)
2770 struct inf
*inf
= cur_inf ();
2771 inf
->default_thread_pause_sc
=
2772 parse_bool_arg (args
, "set thread default pause") ? 0 : 1;
2776 show_thread_default_pause_cmd (char *args
, int from_tty
)
2778 struct inf
*inf
= cur_inf ();
2779 int sc
= inf
->default_thread_pause_sc
;
2780 check_empty (args
, "show thread default pause");
2781 printf_unfiltered ("New threads %s suspended while gdb has control%s.\n",
2782 sc
? "are" : "aren't",
2783 !sc
&& inf
->pause_sc
? " (but the task is)" : "");
2787 set_thread_default_run_cmd (char *args
, int from_tty
)
2789 struct inf
*inf
= cur_inf ();
2790 inf
->default_thread_run_sc
=
2791 parse_bool_arg (args
, "set thread default run") ? 0 : 1;
2795 show_thread_default_run_cmd (char *args
, int from_tty
)
2797 struct inf
*inf
= cur_inf ();
2798 check_empty (args
, "show thread default run");
2799 printf_unfiltered ("New threads %s allowed to run.\n",
2800 inf
->default_thread_run_sc
== 0 ? "are" : "aren't");
2804 set_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2806 cur_inf ()->default_thread_detach_sc
=
2807 parse_int_arg (args
, "set thread default detach-suspend-count");
2811 show_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2813 check_empty (args
, "show thread default detach-suspend-count");
2814 printf_unfiltered ("New threads will get a detach-suspend-count of %d.\n",
2815 cur_inf ()->default_thread_detach_sc
);
2819 /* Steal a send right called NAME in the inferior task, and make it PROC's
2820 saved exception port. */
2822 steal_exc_port (struct proc
*proc
, mach_port_t name
)
2826 mach_msg_type_name_t port_type
;
2828 if (!proc
|| !proc
->inf
->task
)
2829 error (_("No inferior task."));
2831 err
= mach_port_extract_right (proc
->inf
->task
->port
,
2832 name
, MACH_MSG_TYPE_COPY_SEND
,
2835 error (_("Couldn't extract send right %d from inferior: %s"),
2836 name
, safe_strerror (err
));
2838 if (proc
->saved_exc_port
)
2839 /* Get rid of our reference to the old one. */
2840 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
2842 proc
->saved_exc_port
= port
;
2844 if (!proc
->exc_port
)
2845 /* If PROC is a thread, we may not have set its exception port before.
2846 We can't use proc_steal_exc_port because it also sets saved_exc_port. */
2848 proc
->exc_port
= proc
->inf
->event_port
;
2849 err
= proc_set_exception_port (proc
, proc
->exc_port
);
2850 error (_("Can't set exception port for %s: %s"),
2851 proc_string (proc
), safe_strerror (err
));
2856 set_task_exc_port_cmd (char *args
, int from_tty
)
2858 struct inf
*inf
= cur_inf ();
2860 error (_("No argument to \"set task exception-port\" command."));
2861 steal_exc_port (inf
->task
, parse_and_eval_address (args
));
2865 set_stopped_cmd (char *args
, int from_tty
)
2867 cur_inf ()->stopped
= _parse_bool_arg (args
, "yes", "no", "set stopped");
2871 show_stopped_cmd (char *args
, int from_tty
)
2873 struct inf
*inf
= active_inf ();
2874 check_empty (args
, "show stopped");
2875 printf_unfiltered ("The inferior process %s stopped.\n",
2876 inf
->stopped
? "is" : "isn't");
2880 set_sig_thread_cmd (char *args
, int from_tty
)
2882 struct inf
*inf
= cur_inf ();
2884 if (!args
|| (!isdigit (*args
) && strcmp (args
, "none") != 0))
2885 error (_("Illegal argument to \"set signal-thread\" command.\n"
2886 "Should be an integer thread ID, or `none'."));
2888 if (strcmp (args
, "none") == 0)
2889 inf
->signal_thread
= 0;
2892 int tid
= PIDGET (thread_id_to_pid (atoi (args
)));
2894 error (_("Thread ID %s not known. Use the \"info threads\" command to\n"
2895 "see the IDs of currently known threads."), args
);
2896 inf
->signal_thread
= inf_tid_to_thread (inf
, tid
);
2901 show_sig_thread_cmd (char *args
, int from_tty
)
2903 struct inf
*inf
= active_inf ();
2904 check_empty (args
, "show signal-thread");
2905 if (inf
->signal_thread
)
2906 printf_unfiltered ("The signal thread is %s.\n",
2907 proc_string (inf
->signal_thread
));
2909 printf_unfiltered ("There is no signal thread.\n");
2914 set_signals_cmd (char *args
, int from_tty
)
2916 struct inf
*inf
= cur_inf ();
2918 inf
->want_signals
= parse_bool_arg (args
, "set signals");
2920 if (inf
->task
&& inf
->want_signals
!= inf
->traced
)
2921 /* Make this take effect immediately in a running process. */
2922 inf_set_traced (inf
, inf
->want_signals
);
2926 show_signals_cmd (char *args
, int from_tty
)
2928 struct inf
*inf
= cur_inf ();
2929 check_empty (args
, "show signals");
2930 printf_unfiltered ("The inferior process's signals %s intercepted.\n",
2932 ? (inf
->traced
? "are" : "aren't")
2933 : (inf
->want_signals
? "will be" : "won't be"));
2937 set_exceptions_cmd (char *args
, int from_tty
)
2939 struct inf
*inf
= cur_inf ();
2940 int val
= parse_bool_arg (args
, "set exceptions");
2942 if (inf
->task
&& inf
->want_exceptions
!= val
)
2943 /* Make this take effect immediately in a running process. */
2946 inf
->want_exceptions
= val
;
2950 show_exceptions_cmd (char *args
, int from_tty
)
2952 struct inf
*inf
= cur_inf ();
2953 check_empty (args
, "show exceptions");
2954 printf_unfiltered ("Exceptions in the inferior %s trapped.\n",
2956 ? (inf
->want_exceptions
? "are" : "aren't")
2957 : (inf
->want_exceptions
? "will be" : "won't be"));
2962 set_task_cmd (char *args
, int from_tty
)
2964 printf_unfiltered ("\"set task\" must be followed by the name"
2965 " of a task property.\n");
2969 show_task_cmd (char *args
, int from_tty
)
2971 struct inf
*inf
= cur_inf ();
2973 check_empty (args
, "show task");
2975 show_signals_cmd (0, from_tty
);
2976 show_exceptions_cmd (0, from_tty
);
2977 show_task_pause_cmd (0, from_tty
);
2979 if (inf
->pause_sc
== 0)
2980 show_thread_default_pause_cmd (0, from_tty
);
2981 show_thread_default_run_cmd (0, from_tty
);
2985 show_stopped_cmd (0, from_tty
);
2986 show_sig_thread_cmd (0, from_tty
);
2989 if (inf
->detach_sc
!= 0)
2990 show_task_detach_sc_cmd (0, from_tty
);
2991 if (inf
->default_thread_detach_sc
!= 0)
2992 show_thread_default_detach_sc_cmd (0, from_tty
);
2997 set_noninvasive_cmd (char *args
, int from_tty
)
2999 /* Invert the sense of the arg for each component. */
3000 char *inv_args
= parse_bool_arg (args
, "set noninvasive") ? "off" : "on";
3002 set_task_pause_cmd (inv_args
, from_tty
);
3003 set_signals_cmd (inv_args
, from_tty
);
3004 set_exceptions_cmd (inv_args
, from_tty
);
3009 info_port_rights (char *args
, mach_port_type_t only
)
3011 struct inf
*inf
= active_inf ();
3012 struct value
*vmark
= value_mark ();
3015 /* Explicit list of port rights. */
3019 struct value
*val
= parse_to_comma_and_eval (&args
);
3020 long right
= value_as_long (val
);
3022 print_port_info (right
, 0, inf
->task
->port
, PORTINFO_DETAILS
,
3025 error (_("%ld: %s."), right
, safe_strerror (err
));
3029 /* Print all of them. */
3032 print_task_ports_info (inf
->task
->port
, only
, PORTINFO_DETAILS
,
3035 error (_("%s."), safe_strerror (err
));
3038 value_free_to_mark (vmark
);
3042 info_send_rights_cmd (char *args
, int from_tty
)
3044 info_port_rights (args
, MACH_PORT_TYPE_SEND
);
3048 info_recv_rights_cmd (char *args
, int from_tty
)
3050 info_port_rights (args
, MACH_PORT_TYPE_RECEIVE
);
3054 info_port_sets_cmd (char *args
, int from_tty
)
3056 info_port_rights (args
, MACH_PORT_TYPE_PORT_SET
);
3060 info_dead_names_cmd (char *args
, int from_tty
)
3062 info_port_rights (args
, MACH_PORT_TYPE_DEAD_NAME
);
3066 info_port_rights_cmd (char *args
, int from_tty
)
3068 info_port_rights (args
, ~0);
3073 add_task_commands (void)
3075 add_cmd ("pause", class_run
, set_thread_default_pause_cmd
, _("\
3076 Set whether the new threads are suspended while gdb has control.\n\
3077 This property normally has no effect because the whole task is\n\
3078 suspended, however, that may be disabled with \"set task pause off\".\n\
3079 The default value is \"off\"."),
3080 &set_thread_default_cmd_list
);
3081 add_cmd ("pause", no_class
, show_thread_default_pause_cmd
, _("\
3082 Show whether new threads are suspended while gdb has control."),
3083 &show_thread_default_cmd_list
);
3085 add_cmd ("run", class_run
, set_thread_default_run_cmd
, _("\
3086 Set whether new threads are allowed to run (once gdb has noticed them)."),
3087 &set_thread_default_cmd_list
);
3088 add_cmd ("run", no_class
, show_thread_default_run_cmd
, _("\
3089 Show whether new threads are allowed to run (once gdb has noticed them)."),
3090 &show_thread_default_cmd_list
);
3092 add_cmd ("detach-suspend-count", class_run
, set_thread_default_detach_sc_cmd
,
3093 _("Set the default detach-suspend-count value for new threads."),
3094 &set_thread_default_cmd_list
);
3095 add_cmd ("detach-suspend-count", no_class
, show_thread_default_detach_sc_cmd
,
3096 _("Show the default detach-suspend-count value for new threads."),
3097 &show_thread_default_cmd_list
);
3099 add_cmd ("signals", class_run
, set_signals_cmd
, _("\
3100 Set whether the inferior process's signals will be intercepted.\n\
3101 Mach exceptions (such as breakpoint traps) are not affected."),
3103 add_alias_cmd ("sigs", "signals", class_run
, 1, &setlist
);
3104 add_cmd ("signals", no_class
, show_signals_cmd
, _("\
3105 Show whether the inferior process's signals will be intercepted."),
3107 add_alias_cmd ("sigs", "signals", no_class
, 1, &showlist
);
3109 add_cmd ("signal-thread", class_run
, set_sig_thread_cmd
, _("\
3110 Set the thread that gdb thinks is the libc signal thread.\n\
3111 This thread is run when delivering a signal to a non-stopped process."),
3113 add_alias_cmd ("sigthread", "signal-thread", class_run
, 1, &setlist
);
3114 add_cmd ("signal-thread", no_class
, show_sig_thread_cmd
, _("\
3115 Set the thread that gdb thinks is the libc signal thread."),
3117 add_alias_cmd ("sigthread", "signal-thread", no_class
, 1, &showlist
);
3119 add_cmd ("stopped", class_run
, set_stopped_cmd
, _("\
3120 Set whether gdb thinks the inferior process is stopped as with SIGSTOP.\n\
3121 Stopped process will be continued by sending them a signal."),
3123 add_cmd ("stopped", no_class
, show_signals_cmd
, _("\
3124 Show whether gdb thinks the inferior process is stopped as with SIGSTOP."),
3127 add_cmd ("exceptions", class_run
, set_exceptions_cmd
, _("\
3128 Set whether exceptions in the inferior process will be trapped.\n\
3129 When exceptions are turned off, neither breakpoints nor single-stepping\n\
3132 /* Allow `set exc' despite conflict with `set exception-port'. */
3133 add_alias_cmd ("exc", "exceptions", class_run
, 1, &setlist
);
3134 add_cmd ("exceptions", no_class
, show_exceptions_cmd
, _("\
3135 Show whether exceptions in the inferior process will be trapped."),
3138 add_prefix_cmd ("task", no_class
, set_task_cmd
,
3139 _("Command prefix for setting task attributes."),
3140 &set_task_cmd_list
, "set task ", 0, &setlist
);
3141 add_prefix_cmd ("task", no_class
, show_task_cmd
,
3142 _("Command prefix for showing task attributes."),
3143 &show_task_cmd_list
, "show task ", 0, &showlist
);
3145 add_cmd ("pause", class_run
, set_task_pause_cmd
, _("\
3146 Set whether the task is suspended while gdb has control.\n\
3147 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3148 until the next time the program is continued.\n\
3149 When setting this to \"off\", \"set thread default pause on\" can be\n\
3150 used to pause individual threads by default instead."),
3151 &set_task_cmd_list
);
3152 add_cmd ("pause", no_class
, show_task_pause_cmd
,
3153 _("Show whether the task is suspended while gdb has control."),
3154 &show_task_cmd_list
);
3156 add_cmd ("detach-suspend-count", class_run
, set_task_detach_sc_cmd
,
3157 _("Set the suspend count will leave on the thread when detaching."),
3158 &set_task_cmd_list
);
3159 add_cmd ("detach-suspend-count", no_class
, show_task_detach_sc_cmd
,
3160 _("Show the suspend count will leave on the thread when detaching."),
3161 &show_task_cmd_list
);
3163 add_cmd ("exception-port", no_class
, set_task_exc_port_cmd
, _("\
3164 Set the task exception port to which we forward exceptions.\n\
3165 The argument should be the value of the send right in the task."),
3166 &set_task_cmd_list
);
3167 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_task_cmd_list
);
3168 add_alias_cmd ("exc-port", "exception-port", no_class
, 1,
3169 &set_task_cmd_list
);
3171 /* A convenient way of turning on all options require to noninvasively
3172 debug running tasks. */
3173 add_cmd ("noninvasive", no_class
, set_noninvasive_cmd
, _("\
3174 Set task options so that we interfere as little as possible.\n\
3175 This is the same as setting `task pause', `exceptions', and\n\
3176 `signals' to the opposite value."),
3179 /* Commands to show information about the task's ports. */
3180 add_cmd ("send-rights", class_info
, info_send_rights_cmd
,
3181 _("Show information about the task's send rights"),
3183 add_cmd ("receive-rights", class_info
, info_recv_rights_cmd
,
3184 _("Show information about the task's receive rights"),
3186 add_cmd ("port-rights", class_info
, info_port_rights_cmd
,
3187 _("Show information about the task's port rights"),
3189 add_cmd ("port-sets", class_info
, info_port_sets_cmd
,
3190 _("Show information about the task's port sets"),
3192 add_cmd ("dead-names", class_info
, info_dead_names_cmd
,
3193 _("Show information about the task's dead names"),
3195 add_info_alias ("ports", "port-rights", 1);
3196 add_info_alias ("port", "port-rights", 1);
3197 add_info_alias ("psets", "port-sets", 1);
3202 set_thread_pause_cmd (char *args
, int from_tty
)
3204 struct proc
*thread
= cur_thread ();
3205 int old_sc
= thread
->pause_sc
;
3206 thread
->pause_sc
= parse_bool_arg (args
, "set thread pause");
3207 if (old_sc
== 0 && thread
->pause_sc
!= 0 && thread
->inf
->pause_sc
== 0)
3208 /* If the task is currently unsuspended, immediately suspend it,
3209 otherwise wait until the next time it gets control. */
3210 inf_suspend (thread
->inf
);
3214 show_thread_pause_cmd (char *args
, int from_tty
)
3216 struct proc
*thread
= cur_thread ();
3217 int sc
= thread
->pause_sc
;
3218 check_empty (args
, "show task pause");
3219 printf_unfiltered ("Thread %s %s suspended while gdb has control%s.\n",
3220 proc_string (thread
),
3221 sc
? "is" : "isn't",
3222 !sc
&& thread
->inf
->pause_sc
? " (but the task is)" : "");
3226 set_thread_run_cmd (char *args
, int from_tty
)
3228 struct proc
*thread
= cur_thread ();
3229 thread
->run_sc
= parse_bool_arg (args
, "set thread run") ? 0 : 1;
3233 show_thread_run_cmd (char *args
, int from_tty
)
3235 struct proc
*thread
= cur_thread ();
3236 check_empty (args
, "show thread run");
3237 printf_unfiltered ("Thread %s %s allowed to run.",
3238 proc_string (thread
),
3239 thread
->run_sc
== 0 ? "is" : "isn't");
3243 set_thread_detach_sc_cmd (char *args
, int from_tty
)
3245 cur_thread ()->detach_sc
= parse_int_arg (args
,
3246 "set thread detach-suspend-count");
3250 show_thread_detach_sc_cmd (char *args
, int from_tty
)
3252 struct proc
*thread
= cur_thread ();
3253 check_empty (args
, "show thread detach-suspend-count");
3254 printf_unfiltered ("Thread %s will be left with a suspend count"
3255 " of %d when detaching.\n",
3256 proc_string (thread
),
3261 set_thread_exc_port_cmd (char *args
, int from_tty
)
3263 struct proc
*thread
= cur_thread ();
3265 error (_("No argument to \"set thread exception-port\" command."));
3266 steal_exc_port (thread
, parse_and_eval_address (args
));
3271 show_thread_cmd (char *args
, int from_tty
)
3273 struct proc
*thread
= cur_thread ();
3274 check_empty (args
, "show thread");
3275 show_thread_run_cmd (0, from_tty
);
3276 show_thread_pause_cmd (0, from_tty
);
3277 if (thread
->detach_sc
!= 0)
3278 show_thread_detach_sc_cmd (0, from_tty
);
3283 thread_takeover_sc_cmd (char *args
, int from_tty
)
3285 struct proc
*thread
= cur_thread ();
3286 thread_basic_info_data_t _info
;
3287 thread_basic_info_t info
= &_info
;
3288 mach_msg_type_number_t info_len
= THREAD_BASIC_INFO_COUNT
;
3290 thread_info (thread
->port
, THREAD_BASIC_INFO
, (int *) &info
, &info_len
);
3292 error (("%s."), safe_strerror (err
));
3293 thread
->sc
= info
->suspend_count
;
3295 printf_unfiltered ("Suspend count was %d.\n", thread
->sc
);
3297 vm_deallocate (mach_task_self (), (vm_address_t
) info
,
3298 info_len
* sizeof (int));
3303 add_thread_commands (void)
3305 add_prefix_cmd ("thread", no_class
, set_thread_cmd
,
3306 _("Command prefix for setting thread properties."),
3307 &set_thread_cmd_list
, "set thread ", 0, &setlist
);
3308 add_prefix_cmd ("default", no_class
, show_thread_cmd
,
3309 _("Command prefix for setting default thread properties."),
3310 &set_thread_default_cmd_list
, "set thread default ", 0,
3311 &set_thread_cmd_list
);
3312 add_prefix_cmd ("thread", no_class
, set_thread_default_cmd
,
3313 _("Command prefix for showing thread properties."),
3314 &show_thread_cmd_list
, "show thread ", 0, &showlist
);
3315 add_prefix_cmd ("default", no_class
, show_thread_default_cmd
,
3316 _("Command prefix for showing default thread properties."),
3317 &show_thread_default_cmd_list
, "show thread default ", 0,
3318 &show_thread_cmd_list
);
3320 add_cmd ("pause", class_run
, set_thread_pause_cmd
, _("\
3321 Set whether the current thread is suspended while gdb has control.\n\
3322 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3323 until the next time the program is continued. This property normally\n\
3324 has no effect because the whole task is suspended, however, that may\n\
3325 be disabled with \"set task pause off\".\n\
3326 The default value is \"off\"."),
3327 &set_thread_cmd_list
);
3328 add_cmd ("pause", no_class
, show_thread_pause_cmd
, _("\
3329 Show whether the current thread is suspended while gdb has control."),
3330 &show_thread_cmd_list
);
3332 add_cmd ("run", class_run
, set_thread_run_cmd
,
3333 _("Set whether the current thread is allowed to run."),
3334 &set_thread_cmd_list
);
3335 add_cmd ("run", no_class
, show_thread_run_cmd
,
3336 _("Show whether the current thread is allowed to run."),
3337 &show_thread_cmd_list
);
3339 add_cmd ("detach-suspend-count", class_run
, set_thread_detach_sc_cmd
, _("\
3340 Set the suspend count will leave on the thread when detaching.\n\
3341 Note that this is relative to suspend count when gdb noticed the thread;\n\
3342 use the `thread takeover-suspend-count' to force it to an absolute value."),
3343 &set_thread_cmd_list
);
3344 add_cmd ("detach-suspend-count", no_class
, show_thread_detach_sc_cmd
, _("\
3345 Show the suspend count will leave on the thread when detaching.\n\
3346 Note that this is relative to suspend count when gdb noticed the thread;\n\
3347 use the `thread takeover-suspend-count' to force it to an absolute value."),
3348 &show_thread_cmd_list
);
3350 add_cmd ("exception-port", no_class
, set_thread_exc_port_cmd
, _("\
3351 Set the thread exception port to which we forward exceptions.\n\
3352 This overrides the task exception port.\n\
3353 The argument should be the value of the send right in the task."),
3354 &set_thread_cmd_list
);
3355 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3356 add_alias_cmd ("exc-port", "exception-port", no_class
, 1,
3357 &set_thread_cmd_list
);
3359 add_cmd ("takeover-suspend-count", no_class
, thread_takeover_sc_cmd
, _("\
3360 Force the threads absolute suspend-count to be gdb's.\n\
3361 Prior to giving this command, gdb's thread suspend-counts are relative\n\
3362 to the thread's initial suspend-count when gdb notices the threads."),
3368 _initialize_gnu_nat (void)
3370 proc_server
= getproc ();
3373 add_target (&gnu_ops
);
3375 add_task_commands ();
3376 add_thread_commands ();
3377 deprecated_add_set_cmd ("gnu-debug", class_maintenance
,
3378 var_boolean
, (char *) &gnu_debug_flag
,
3379 "Set debugging output for the gnu backend.",
3383 #ifdef FLUSH_INFERIOR_CACHE
3385 /* When over-writing code on some machines the I-Cache must be flushed
3386 explicitly, because it is not kept coherent by the lazy hardware.
3387 This definitely includes breakpoints, for instance, or else we
3388 end up looping in mysterious Bpt traps */
3391 flush_inferior_icache (CORE_ADDR pc
, int amount
)
3393 vm_machine_attribute_val_t flush
= MATTR_VAL_ICACHE_FLUSH
;
3396 ret
= vm_machine_attribute (current_inferior
->task
->port
,
3401 if (ret
!= KERN_SUCCESS
)
3402 warning (_("Error flushing inferior's cache : %s"), safe_strerror (ret
));
3404 #endif /* FLUSH_INFERIOR_CACHE */