1 /* Interface GDB to the GNU Hurd.
2 Copyright (C) 1992, 1995-2001, 2006-2012 Free Software Foundation,
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 3 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, see <http://www.gnu.org/licenses/>.
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 /* Defined in <hurd/process.h>, but we need forward declarations from
49 <hurd/process_request.h> as well. */
51 #include <hurd/process_request.h>
52 #include <hurd/signal.h>
53 #include <hurd/sigpreempt.h>
65 #include "gdbthread.h"
66 #include "gdb_assert.h"
67 #include "gdb_obstack.h"
70 #include "inf-child.h"
72 #include "exc_request_S.h"
74 #include "process_reply_S.h"
75 #include "msg_reply_S.h"
76 #include "exc_request_U.h"
79 static process_t proc_server
= MACH_PORT_NULL
;
81 /* If we've sent a proc_wait_request to the proc server, the pid of the
82 process we asked about. We can only ever have one outstanding. */
83 int proc_wait_pid
= 0;
85 /* The number of wait requests we've sent, and expect replies from. */
86 int proc_waits_pending
= 0;
88 int gnu_debug_flag
= 0;
92 struct inf
*make_inf ();
93 void inf_clear_wait (struct inf
*inf
);
94 void inf_cleanup (struct inf
*inf
);
95 void inf_startup (struct inf
*inf
, int pid
);
96 int inf_update_suspends (struct inf
*inf
);
97 void inf_set_pid (struct inf
*inf
, pid_t pid
);
98 void inf_validate_procs (struct inf
*inf
);
99 void inf_steal_exc_ports (struct inf
*inf
);
100 void inf_restore_exc_ports (struct inf
*inf
);
101 struct proc
*inf_tid_to_proc (struct inf
*inf
, int tid
);
102 void inf_set_threads_resume_sc (struct inf
*inf
,
103 struct proc
*run_thread
,
105 int inf_set_threads_resume_sc_for_signal_thread (struct inf
*inf
);
106 void inf_suspend (struct inf
*inf
);
107 void inf_resume (struct inf
*inf
);
108 void inf_set_step_thread (struct inf
*inf
, struct proc
*proc
);
109 void inf_detach (struct inf
*inf
);
110 void inf_attach (struct inf
*inf
, int pid
);
111 void inf_signal (struct inf
*inf
, enum gdb_signal sig
);
112 void inf_continue (struct inf
*inf
);
114 #define inf_debug(_inf, msg, args...) \
115 do { struct inf *__inf = (_inf); \
116 debug ("{inf %d %s}: " msg, __inf->pid, \
117 host_address_to_string (__inf) , ##args); } while (0)
119 void proc_abort (struct proc
*proc
, int force
);
120 struct proc
*make_proc (struct inf
*inf
, mach_port_t port
, int tid
);
121 struct proc
*_proc_free (struct proc
*proc
);
122 int proc_update_sc (struct proc
*proc
);
123 error_t
proc_get_exception_port (struct proc
*proc
, mach_port_t
* port
);
124 error_t
proc_set_exception_port (struct proc
*proc
, mach_port_t port
);
125 static mach_port_t
_proc_get_exc_port (struct proc
*proc
);
126 void proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
);
127 void proc_restore_exc_port (struct proc
*proc
);
128 int proc_trace (struct proc
*proc
, int set
);
130 /* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
131 to INF's msg port and task port respectively. If it has no msg port,
132 EIEIO is returned. INF must refer to a running process! */
133 #define INF_MSGPORT_RPC(inf, rpc_expr) \
134 HURD_MSGPORT_RPC (proc_getmsgport (proc_server, inf->pid, &msgport), \
135 (refport = inf->task->port, 0), 0, \
136 msgport ? (rpc_expr) : EIEIO)
138 /* Like INF_MSGPORT_RPC, but will also resume the signal thread to ensure
139 there's someone around to deal with the RPC (and resuspend things
140 afterwards). This effects INF's threads' resume_sc count. */
141 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
142 (inf_set_threads_resume_sc_for_signal_thread (inf) \
145 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
151 /* The state passed by an exception message. */
154 int exception
; /* The exception code. */
156 mach_port_t handler
; /* The real exception port to handle this. */
157 mach_port_t reply
; /* The reply port from the exception call. */
160 /* The results of the last wait an inf did. */
163 struct target_waitstatus status
; /* The status returned to gdb. */
164 struct exc_state exc
; /* The exception that caused us to return. */
165 struct proc
*thread
; /* The thread in question. */
166 int suppress
; /* Something trivial happened. */
169 /* The state of an inferior. */
172 /* Fields describing the current inferior. */
174 struct proc
*task
; /* The mach task. */
175 struct proc
*threads
; /* A linked list of all threads in TASK. */
177 /* True if THREADS needn't be validated by querying the task. We
178 assume that we and the task in question are the only ones
179 frobbing the thread list, so as long as we don't let any code
180 run, we don't have to worry about THREADS changing. */
181 int threads_up_to_date
;
183 pid_t pid
; /* The real system PID. */
185 struct inf_wait wait
; /* What to return from target_wait. */
187 /* One thread proc in INF may be in `single-stepping mode'. This
189 struct proc
*step_thread
;
191 /* The thread we think is the signal thread. */
192 struct proc
*signal_thread
;
194 mach_port_t event_port
; /* Where we receive various msgs. */
196 /* True if we think at least one thread in the inferior could currently be
198 unsigned int running
:1;
200 /* True if the process has stopped (in the proc server sense). Note that
201 since a proc server `stop' leaves the signal thread running, the inf can
202 be RUNNING && STOPPED... */
203 unsigned int stopped
:1;
205 /* True if the inferior has no message port. */
206 unsigned int nomsg
:1;
208 /* True if the inferior is traced. */
209 unsigned int traced
:1;
211 /* True if we shouldn't try waiting for the inferior, usually because we
212 can't for some reason. */
213 unsigned int no_wait
:1;
215 /* When starting a new inferior, we don't try to validate threads until all
216 the proper execs have been done. This is a count of how many execs we
218 unsigned pending_execs
;
220 /* Fields describing global state. */
222 /* The task suspend count used when gdb has control. This is normally 1 to
223 make things easier for us, but sometimes (like when attaching to vital
224 system servers) it may be desirable to let the task continue to run
225 (pausing individual threads as necessary). */
228 /* The task suspend count left when detaching from a task. */
231 /* The initial values used for the run_sc and pause_sc of newly discovered
232 threads -- see the definition of those fields in struct proc. */
233 int default_thread_run_sc
;
234 int default_thread_pause_sc
;
235 int default_thread_detach_sc
;
237 /* True if the process should be traced when started/attached. Newly
238 started processes *must* be traced at first to exec them properly, but
239 if this is false, tracing is turned off as soon it has done so. */
242 /* True if exceptions from the inferior process should be trapped. This
243 must be on to use breakpoints. */
249 __proc_pid (struct proc
*proc
)
251 return proc
->inf
->pid
;
255 /* Update PROC's real suspend count to match it's desired one. Returns true
256 if we think PROC is now in a runnable state. */
258 proc_update_sc (struct proc
*proc
)
262 int delta
= proc
->sc
- proc
->cur_sc
;
265 proc_debug (proc
, "sc: %d --> %d", proc
->cur_sc
, proc
->sc
);
267 if (proc
->sc
== 0 && proc
->state_changed
)
268 /* Since PROC may start running, we must write back any state changes. */
270 gdb_assert (proc_is_thread (proc
));
271 proc_debug (proc
, "storing back changed thread state");
272 err
= thread_set_state (proc
->port
, THREAD_STATE_FLAVOR
,
273 (thread_state_t
) &proc
->state
, THREAD_STATE_SIZE
);
275 proc
->state_changed
= 0;
280 while (delta
-- > 0 && !err
)
282 if (proc_is_task (proc
))
283 err
= task_suspend (proc
->port
);
285 err
= thread_suspend (proc
->port
);
290 while (delta
++ < 0 && !err
)
292 if (proc_is_task (proc
))
293 err
= task_resume (proc
->port
);
295 err
= thread_resume (proc
->port
);
299 proc
->cur_sc
= proc
->sc
;
301 /* If we got an error, then the task/thread has disappeared. */
302 running
= !err
&& proc
->sc
== 0;
304 proc_debug (proc
, "is %s", err
? "dead" : running
? "running" : "suspended");
306 proc_debug (proc
, "err = %s", safe_strerror (err
));
311 proc
->state_valid
= proc
->state_changed
= 0;
312 proc
->fetched_regs
= 0;
319 /* Thread_abort is called on PROC if needed. PROC must be a thread proc.
320 If PROC is deemed `precious', then nothing is done unless FORCE is true.
321 In particular, a thread is precious if it's running (in which case forcing
322 it includes suspending it first), or if it has an exception pending. */
324 proc_abort (struct proc
*proc
, int force
)
326 gdb_assert (proc_is_thread (proc
));
330 struct inf
*inf
= proc
->inf
;
331 int running
= (proc
->cur_sc
== 0 && inf
->task
->cur_sc
== 0);
333 if (running
&& force
)
336 inf_update_suspends (proc
->inf
);
338 warning (_("Stopped %s."), proc_string (proc
));
340 else if (proc
== inf
->wait
.thread
&& inf
->wait
.exc
.reply
&& !force
)
341 /* An exception is pending on PROC, which don't mess with. */
345 /* We only abort the thread if it's not actually running. */
347 thread_abort (proc
->port
);
348 proc_debug (proc
, "aborted");
352 proc_debug (proc
, "not aborting");
356 /* Make sure that the state field in PROC is up to date, and return a pointer
357 to it, or 0 if something is wrong. If WILL_MODIFY is true, makes sure
358 that the thread is stopped and aborted first, and sets the state_changed
359 field in PROC to true. */
361 proc_get_state (struct proc
*proc
, int will_modify
)
363 int was_aborted
= proc
->aborted
;
365 proc_debug (proc
, "updating state info%s",
366 will_modify
? " (with intention to modify)" : "");
368 proc_abort (proc
, will_modify
);
370 if (!was_aborted
&& proc
->aborted
)
371 /* PROC's state may have changed since we last fetched it. */
372 proc
->state_valid
= 0;
374 if (!proc
->state_valid
)
376 mach_msg_type_number_t state_size
= THREAD_STATE_SIZE
;
378 thread_get_state (proc
->port
, THREAD_STATE_FLAVOR
,
379 (thread_state_t
) &proc
->state
, &state_size
);
381 proc_debug (proc
, "getting thread state");
382 proc
->state_valid
= !err
;
385 if (proc
->state_valid
)
388 proc
->state_changed
= 1;
389 return (thread_state_t
) &proc
->state
;
396 /* Set PORT to PROC's exception port. */
398 proc_get_exception_port (struct proc
* proc
, mach_port_t
* port
)
400 if (proc_is_task (proc
))
401 return task_get_exception_port (proc
->port
, port
);
403 return thread_get_exception_port (proc
->port
, port
);
406 /* Set PROC's exception port to PORT. */
408 proc_set_exception_port (struct proc
* proc
, mach_port_t port
)
410 proc_debug (proc
, "setting exception port: %d", port
);
411 if (proc_is_task (proc
))
412 return task_set_exception_port (proc
->port
, port
);
414 return thread_set_exception_port (proc
->port
, port
);
417 /* Get PROC's exception port, cleaning up a bit if proc has died. */
419 _proc_get_exc_port (struct proc
*proc
)
421 mach_port_t exc_port
;
422 error_t err
= proc_get_exception_port (proc
, &exc_port
);
425 /* PROC must be dead. */
428 mach_port_deallocate (mach_task_self (), proc
->exc_port
);
429 proc
->exc_port
= MACH_PORT_NULL
;
430 if (proc
->saved_exc_port
)
431 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
432 proc
->saved_exc_port
= MACH_PORT_NULL
;
438 /* Replace PROC's exception port with EXC_PORT, unless it's already
439 been done. Stash away any existing exception port so we can
442 proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
)
444 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
450 proc_debug (proc
, "inserting exception port: %d", exc_port
);
452 if (cur_exc_port
!= exc_port
)
453 /* Put in our exception port. */
454 err
= proc_set_exception_port (proc
, exc_port
);
456 if (err
|| cur_exc_port
== proc
->exc_port
)
457 /* We previously set the exception port, and it's still set. So we
458 just keep the old saved port which is what the proc set. */
461 mach_port_deallocate (mach_task_self (), cur_exc_port
);
464 /* Keep a copy of PROC's old exception port so it can be restored. */
466 if (proc
->saved_exc_port
)
467 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
468 proc
->saved_exc_port
= cur_exc_port
;
471 proc_debug (proc
, "saved exception port: %d", proc
->saved_exc_port
);
474 proc
->exc_port
= exc_port
;
476 warning (_("Error setting exception port for %s: %s"),
477 proc_string (proc
), safe_strerror (err
));
481 /* If we previously replaced PROC's exception port, put back what we
482 found there at the time, unless *our* exception port has since been
483 overwritten, in which case who knows what's going on. */
485 proc_restore_exc_port (struct proc
*proc
)
487 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
493 proc_debug (proc
, "restoring real exception port");
495 if (proc
->exc_port
== cur_exc_port
)
496 /* Our's is still there. */
497 err
= proc_set_exception_port (proc
, proc
->saved_exc_port
);
499 if (proc
->saved_exc_port
)
500 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
501 proc
->saved_exc_port
= MACH_PORT_NULL
;
504 proc
->exc_port
= MACH_PORT_NULL
;
506 warning (_("Error setting exception port for %s: %s"),
507 proc_string (proc
), safe_strerror (err
));
512 /* Turns hardware tracing in PROC on or off when SET is true or false,
513 respectively. Returns true on success. */
515 proc_trace (struct proc
*proc
, int set
)
517 thread_state_t state
= proc_get_state (proc
, 1);
520 return 0; /* The thread must be dead. */
522 proc_debug (proc
, "tracing %s", set
? "on" : "off");
526 /* XXX We don't get the exception unless the thread has its own
527 exception port???? */
528 if (proc
->exc_port
== MACH_PORT_NULL
)
529 proc_steal_exc_port (proc
, proc
->inf
->event_port
);
530 THREAD_STATE_SET_TRACED (state
);
533 THREAD_STATE_CLEAR_TRACED (state
);
539 /* A variable from which to assign new TIDs. */
540 static int next_thread_id
= 1;
542 /* Returns a new proc structure with the given fields. Also adds a
543 notification for PORT becoming dead to be sent to INF's notify port. */
545 make_proc (struct inf
*inf
, mach_port_t port
, int tid
)
548 mach_port_t prev_port
= MACH_PORT_NULL
;
549 struct proc
*proc
= xmalloc (sizeof (struct proc
));
555 proc
->saved_exc_port
= MACH_PORT_NULL
;
556 proc
->exc_port
= MACH_PORT_NULL
;
561 /* Note that these are all the values for threads; the task simply uses the
562 corresponding field in INF directly. */
563 proc
->run_sc
= inf
->default_thread_run_sc
;
564 proc
->pause_sc
= inf
->default_thread_pause_sc
;
565 proc
->detach_sc
= inf
->default_thread_detach_sc
;
566 proc
->resume_sc
= proc
->run_sc
;
570 proc
->state_valid
= 0;
571 proc
->state_changed
= 0;
573 proc_debug (proc
, "is new");
575 /* Get notified when things die. */
577 mach_port_request_notification (mach_task_self (), port
,
578 MACH_NOTIFY_DEAD_NAME
, 1,
580 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
583 warning (_("Couldn't request notification for port %d: %s"),
584 port
, safe_strerror (err
));
587 proc_debug (proc
, "notifications to: %d", inf
->event_port
);
588 if (prev_port
!= MACH_PORT_NULL
)
589 mach_port_deallocate (mach_task_self (), prev_port
);
592 if (inf
->want_exceptions
)
594 if (proc_is_task (proc
))
595 /* Make the task exception port point to us. */
596 proc_steal_exc_port (proc
, inf
->event_port
);
598 /* Just clear thread exception ports -- they default to the
600 proc_steal_exc_port (proc
, MACH_PORT_NULL
);
606 /* Frees PROC and any resources it uses, and returns the value of PROC's
609 _proc_free (struct proc
*proc
)
611 struct inf
*inf
= proc
->inf
;
612 struct proc
*next
= proc
->next
;
614 proc_debug (proc
, "freeing...");
616 if (proc
== inf
->step_thread
)
617 /* Turn off single stepping. */
618 inf_set_step_thread (inf
, 0);
619 if (proc
== inf
->wait
.thread
)
620 inf_clear_wait (inf
);
621 if (proc
== inf
->signal_thread
)
622 inf
->signal_thread
= 0;
624 if (proc
->port
!= MACH_PORT_NULL
)
626 if (proc
->exc_port
!= MACH_PORT_NULL
)
627 /* Restore the original exception port. */
628 proc_restore_exc_port (proc
);
629 if (proc
->cur_sc
!= 0)
630 /* Resume the thread/task. */
633 proc_update_sc (proc
);
635 mach_port_deallocate (mach_task_self (), proc
->port
);
646 struct inf
*inf
= xmalloc (sizeof (struct inf
));
650 inf
->threads_up_to_date
= 0;
652 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
653 inf
->wait
.thread
= 0;
654 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
655 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
656 inf
->step_thread
= 0;
657 inf
->signal_thread
= 0;
658 inf
->event_port
= MACH_PORT_NULL
;
664 inf
->pending_execs
= 0;
667 inf
->default_thread_run_sc
= 0;
668 inf
->default_thread_pause_sc
= 0;
669 inf
->default_thread_detach_sc
= 0;
670 inf
->want_signals
= 1; /* By default */
671 inf
->want_exceptions
= 1; /* By default */
676 /* Clear INF's target wait status. */
678 inf_clear_wait (struct inf
*inf
)
680 inf_debug (inf
, "clearing wait");
681 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
682 inf
->wait
.thread
= 0;
683 inf
->wait
.suppress
= 0;
684 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
686 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.handler
);
687 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
689 if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
691 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.reply
);
692 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
698 inf_cleanup (struct inf
*inf
)
700 inf_debug (inf
, "cleanup");
702 inf_clear_wait (inf
);
704 inf_set_pid (inf
, -1);
711 inf
->pending_execs
= 0;
715 mach_port_destroy (mach_task_self (), inf
->event_port
);
716 inf
->event_port
= MACH_PORT_NULL
;
721 inf_startup (struct inf
*inf
, int pid
)
725 inf_debug (inf
, "startup: pid = %d", pid
);
729 /* Make the port on which we receive all events. */
730 err
= mach_port_allocate (mach_task_self (),
731 MACH_PORT_RIGHT_RECEIVE
, &inf
->event_port
);
733 error (_("Error allocating event port: %s"), safe_strerror (err
));
735 /* Make a send right for it, so we can easily copy it for other people. */
736 mach_port_insert_right (mach_task_self (), inf
->event_port
,
737 inf
->event_port
, MACH_MSG_TYPE_MAKE_SEND
);
738 inf_set_pid (inf
, pid
);
742 /* Close current process, if any, and attach INF to process PORT. */
744 inf_set_pid (struct inf
*inf
, pid_t pid
)
747 struct proc
*task
= inf
->task
;
749 inf_debug (inf
, "setting pid: %d", pid
);
752 task_port
= MACH_PORT_NULL
;
755 error_t err
= proc_pid2task (proc_server
, pid
, &task_port
);
758 error (_("Error getting task for pid %d: %s"),
759 pid
, safe_strerror (err
));
762 inf_debug (inf
, "setting task: %d", task_port
);
765 task_suspend (task_port
);
767 if (task
&& task
->port
!= task_port
)
770 inf_validate_procs (inf
); /* Trash all the threads. */
771 _proc_free (task
); /* And the task. */
774 if (task_port
!= MACH_PORT_NULL
)
776 inf
->task
= make_proc (inf
, task_port
, PROC_TID_TASK
);
777 inf
->threads_up_to_date
= 0;
784 /* Reflect task_suspend above. */
785 inf
->task
->sc
= inf
->task
->cur_sc
= 1;
792 /* Validates INF's stopped, nomsg and traced field from the actual
793 proc server state. Note that the traced field is only updated from
794 the proc server state if we do not have a message port. If we do
795 have a message port we'd better look at the tracemask itself. */
797 inf_validate_procinfo (struct inf
*inf
)
800 mach_msg_type_number_t noise_len
= 0;
802 mach_msg_type_number_t pi_len
= 0;
805 proc_getprocinfo (proc_server
, inf
->pid
, &info_flags
,
806 (procinfo_t
*) &pi
, &pi_len
, &noise
, &noise_len
);
810 inf
->stopped
= !!(pi
->state
& PI_STOPPED
);
811 inf
->nomsg
= !!(pi
->state
& PI_NOMSG
);
813 inf
->traced
= !!(pi
->state
& PI_TRACED
);
814 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
816 vm_deallocate (mach_task_self (), (vm_address_t
) noise
, noise_len
);
820 /* Validates INF's task suspend count. If it's higher than we expect,
821 verify with the user before `stealing' the extra count. */
823 inf_validate_task_sc (struct inf
*inf
)
826 mach_msg_type_number_t noise_len
= 0;
828 mach_msg_type_number_t pi_len
= 0;
829 int info_flags
= PI_FETCH_TASKINFO
;
830 int suspend_count
= -1;
834 err
= proc_getprocinfo (proc_server
, inf
->pid
, &info_flags
,
835 (procinfo_t
*) &pi
, &pi_len
, &noise
, &noise_len
);
838 inf
->task
->dead
= 1; /* oh well */
842 if (inf
->task
->cur_sc
< pi
->taskinfo
.suspend_count
&& suspend_count
== -1)
844 /* The proc server might have suspended the task while stopping
845 it. This happens when the task is handling a traced signal.
846 Refetch the suspend count. The proc server should be
847 finished stopping the task by now. */
848 suspend_count
= pi
->taskinfo
.suspend_count
;
852 suspend_count
= pi
->taskinfo
.suspend_count
;
854 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
856 vm_deallocate (mach_task_self (), (vm_address_t
) pi
, pi_len
);
858 if (inf
->task
->cur_sc
< suspend_count
)
862 target_terminal_ours (); /* Allow I/O. */
863 abort
= !query (_("Pid %d has an additional task suspend count of %d;"
864 " clear it? "), inf
->pid
,
865 suspend_count
- inf
->task
->cur_sc
);
866 target_terminal_inferior (); /* Give it back to the child. */
869 error (_("Additional task suspend count left untouched."));
871 inf
->task
->cur_sc
= suspend_count
;
875 /* Turns tracing for INF on or off, depending on ON, unless it already
876 is. If INF is running, the resume_sc count of INF's threads will
877 be modified, and the signal thread will briefly be run to change
880 inf_set_traced (struct inf
*inf
, int on
)
882 if (on
== inf
->traced
)
885 if (inf
->task
&& !inf
->task
->dead
)
886 /* Make it take effect immediately. */
888 sigset_t mask
= on
? ~(sigset_t
) 0 : 0;
890 INF_RESUME_MSGPORT_RPC (inf
, msg_set_init_int (msgport
, refport
,
891 INIT_TRACEMASK
, mask
));
896 warning (_("Can't modify tracing state for pid %d: %s"),
897 inf
->pid
, "No signal thread");
901 warning (_("Can't modify tracing state for pid %d: %s"),
902 inf
->pid
, safe_strerror (err
));
911 /* Makes all the real suspend count deltas of all the procs in INF
912 match the desired values. Careful to always do thread/task suspend
913 counts in the safe order. Returns true if at least one thread is
914 thought to be running. */
916 inf_update_suspends (struct inf
*inf
)
918 struct proc
*task
= inf
->task
;
920 /* We don't have to update INF->threads even though we're iterating over it
921 because we'll change a thread only if it already has an existing proc
923 inf_debug (inf
, "updating suspend counts");
928 int task_running
= (task
->sc
== 0), thread_running
= 0;
930 if (task
->sc
> task
->cur_sc
)
931 /* The task is becoming _more_ suspended; do before any threads. */
932 task_running
= proc_update_sc (task
);
934 if (inf
->pending_execs
)
935 /* When we're waiting for an exec, things may be happening behind our
936 back, so be conservative. */
939 /* Do all the thread suspend counts. */
940 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
941 thread_running
|= proc_update_sc (thread
);
943 if (task
->sc
!= task
->cur_sc
)
944 /* We didn't do the task first, because we wanted to wait for the
945 threads; do it now. */
946 task_running
= proc_update_sc (task
);
948 inf_debug (inf
, "%srunning...",
949 (thread_running
&& task_running
) ? "" : "not ");
951 inf
->running
= thread_running
&& task_running
;
953 /* Once any thread has executed some code, we can't depend on the
954 threads list any more. */
956 inf
->threads_up_to_date
= 0;
965 /* Converts a GDB pid to a struct proc. */
967 inf_tid_to_thread (struct inf
*inf
, int tid
)
969 struct proc
*thread
= inf
->threads
;
972 if (thread
->tid
== tid
)
975 thread
= thread
->next
;
979 /* Converts a thread port to a struct proc. */
981 inf_port_to_thread (struct inf
*inf
, mach_port_t port
)
983 struct proc
*thread
= inf
->threads
;
986 if (thread
->port
== port
)
989 thread
= thread
->next
;
994 /* Make INF's list of threads be consistent with reality of TASK. */
996 inf_validate_procs (struct inf
*inf
)
998 thread_array_t threads
;
999 mach_msg_type_number_t num_threads
, i
;
1000 struct proc
*task
= inf
->task
;
1002 /* If no threads are currently running, this function will guarantee that
1003 things are up to date. The exception is if there are zero threads --
1004 then it is almost certainly in an odd state, and probably some outside
1005 agent will create threads. */
1006 inf
->threads_up_to_date
= inf
->threads
? !inf
->running
: 0;
1010 error_t err
= task_threads (task
->port
, &threads
, &num_threads
);
1012 inf_debug (inf
, "fetching threads");
1014 /* TASK must be dead. */
1024 inf_debug (inf
, "no task");
1028 /* Make things normally linear. */
1029 mach_msg_type_number_t search_start
= 0;
1030 /* Which thread in PROCS corresponds to each task thread, & the task. */
1031 struct proc
*matched
[num_threads
+ 1];
1032 /* The last thread in INF->threads, so we can add to the end. */
1033 struct proc
*last
= 0;
1034 /* The current thread we're considering. */
1035 struct proc
*thread
= inf
->threads
;
1037 memset (matched
, 0, sizeof (matched
));
1041 mach_msg_type_number_t left
;
1043 for (i
= search_start
, left
= num_threads
; left
; i
++, left
--)
1045 if (i
>= num_threads
)
1046 i
-= num_threads
; /* I wrapped around. */
1047 if (thread
->port
== threads
[i
])
1048 /* We already know about this thread. */
1050 matched
[i
] = thread
;
1052 thread
= thread
->next
;
1060 proc_debug (thread
, "died!");
1061 thread
->port
= MACH_PORT_NULL
;
1062 thread
= _proc_free (thread
); /* THREAD is dead. */
1064 last
->next
= thread
;
1066 inf
->threads
= thread
;
1070 for (i
= 0; i
< num_threads
; i
++)
1073 /* Throw away the duplicate send right. */
1074 mach_port_deallocate (mach_task_self (), threads
[i
]);
1076 /* THREADS[I] is a thread we don't know about yet! */
1080 thread
= make_proc (inf
, threads
[i
], next_thread_id
++);
1082 last
->next
= thread
;
1084 inf
->threads
= thread
;
1086 proc_debug (thread
, "new thread: %d", threads
[i
]);
1088 ptid
= ptid_build (inf
->pid
, 0, thread
->tid
);
1090 /* Tell GDB's generic thread code. */
1092 if (ptid_equal (inferior_ptid
, pid_to_ptid (inf
->pid
)))
1093 /* This is the first time we're hearing about thread
1094 ids, after a fork-child. */
1095 thread_change_ptid (inferior_ptid
, ptid
);
1096 else if (inf
->pending_execs
!= 0)
1097 /* This is a shell thread. */
1098 add_thread_silent (ptid
);
1104 vm_deallocate (mach_task_self (),
1105 (vm_address_t
) threads
, (num_threads
* sizeof (thread_t
)));
1110 /* Makes sure that INF's thread list is synced with the actual process. */
1112 inf_update_procs (struct inf
*inf
)
1116 if (!inf
->threads_up_to_date
)
1117 inf_validate_procs (inf
);
1121 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1122 and others are set to their run_sc if RUN_OTHERS is true, and otherwise
1125 inf_set_threads_resume_sc (struct inf
*inf
,
1126 struct proc
*run_thread
, int run_others
)
1128 struct proc
*thread
;
1130 inf_update_procs (inf
);
1131 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1132 if (thread
== run_thread
)
1133 thread
->resume_sc
= 0;
1134 else if (run_others
)
1135 thread
->resume_sc
= thread
->run_sc
;
1137 thread
->resume_sc
= thread
->pause_sc
;
1141 /* Cause INF to continue execution immediately; individual threads may still
1142 be suspended (but their suspend counts will be updated). */
1144 inf_resume (struct inf
*inf
)
1146 struct proc
*thread
;
1148 inf_update_procs (inf
);
1150 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1151 thread
->sc
= thread
->resume_sc
;
1155 if (!inf
->pending_execs
)
1156 /* Try to make sure our task count is correct -- in the case where
1157 we're waiting for an exec though, things are too volatile, so just
1158 assume things will be reasonable (which they usually will be). */
1159 inf_validate_task_sc (inf
);
1163 inf_update_suspends (inf
);
1166 /* Cause INF to stop execution immediately; individual threads may still
1169 inf_suspend (struct inf
*inf
)
1171 struct proc
*thread
;
1173 inf_update_procs (inf
);
1175 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1176 thread
->sc
= thread
->pause_sc
;
1179 inf
->task
->sc
= inf
->pause_sc
;
1181 inf_update_suspends (inf
);
1185 /* INF has one thread PROC that is in single-stepping mode. This
1186 function changes it to be PROC, changing any old step_thread to be
1187 a normal one. A PROC of 0 clears any existing value. */
1189 inf_set_step_thread (struct inf
*inf
, struct proc
*thread
)
1191 gdb_assert (!thread
|| proc_is_thread (thread
));
1194 inf_debug (inf
, "setting step thread: %d/%d", inf
->pid
, thread
->tid
);
1196 inf_debug (inf
, "clearing step thread");
1198 if (inf
->step_thread
!= thread
)
1200 if (inf
->step_thread
&& inf
->step_thread
->port
!= MACH_PORT_NULL
)
1201 if (!proc_trace (inf
->step_thread
, 0))
1203 if (thread
&& proc_trace (thread
, 1))
1204 inf
->step_thread
= thread
;
1206 inf
->step_thread
= 0;
1211 /* Set up the thread resume_sc's so that only the signal thread is running
1212 (plus whatever other thread are set to always run). Returns true if we
1213 did so, or false if we can't find a signal thread. */
1215 inf_set_threads_resume_sc_for_signal_thread (struct inf
*inf
)
1217 if (inf
->signal_thread
)
1219 inf_set_threads_resume_sc (inf
, inf
->signal_thread
, 0);
1227 inf_update_signal_thread (struct inf
*inf
)
1229 /* XXX for now we assume that if there's a msgport, the 2nd thread is
1230 the signal thread. */
1231 inf
->signal_thread
= inf
->threads
? inf
->threads
->next
: 0;
1235 /* Detachs from INF's inferior task, letting it run once again... */
1237 inf_detach (struct inf
*inf
)
1239 struct proc
*task
= inf
->task
;
1241 inf_debug (inf
, "detaching...");
1243 inf_clear_wait (inf
);
1244 inf_set_step_thread (inf
, 0);
1248 struct proc
*thread
;
1250 inf_validate_procinfo (inf
);
1252 inf_set_traced (inf
, 0);
1258 inf_signal (inf
, GDB_SIGNAL_0
);
1261 proc_restore_exc_port (task
);
1262 task
->sc
= inf
->detach_sc
;
1264 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1266 proc_restore_exc_port (thread
);
1267 thread
->sc
= thread
->detach_sc
;
1270 inf_update_suspends (inf
);
1276 /* Attaches INF to the process with process id PID, returning it in a
1277 suspended state suitable for debugging. */
1279 inf_attach (struct inf
*inf
, int pid
)
1281 inf_debug (inf
, "attaching: %d", pid
);
1286 inf_startup (inf
, pid
);
1290 /* Makes sure that we've got our exception ports entrenched in the process. */
1292 inf_steal_exc_ports (struct inf
*inf
)
1294 struct proc
*thread
;
1296 inf_debug (inf
, "stealing exception ports");
1298 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1300 proc_steal_exc_port (inf
->task
, inf
->event_port
);
1301 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1302 proc_steal_exc_port (thread
, MACH_PORT_NULL
);
1305 /* Makes sure the process has its own exception ports. */
1307 inf_restore_exc_ports (struct inf
*inf
)
1309 struct proc
*thread
;
1311 inf_debug (inf
, "restoring exception ports");
1313 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1315 proc_restore_exc_port (inf
->task
);
1316 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1317 proc_restore_exc_port (thread
);
1321 /* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
1322 signal 0, will continue it. INF is assumed to be in a paused state, and
1323 the resume_sc's of INF's threads may be affected. */
1325 inf_signal (struct inf
*inf
, enum gdb_signal sig
)
1328 int host_sig
= gdb_signal_to_host (sig
);
1330 #define NAME gdb_signal_to_name (sig)
1332 if (host_sig
>= _NSIG
)
1333 /* A mach exception. Exceptions are encoded in the signal space by
1334 putting them after _NSIG; this assumes they're positive (and not
1335 extremely large)! */
1337 struct inf_wait
*w
= &inf
->wait
;
1339 if (w
->status
.kind
== TARGET_WAITKIND_STOPPED
1340 && w
->status
.value
.sig
== sig
1341 && w
->thread
&& !w
->thread
->aborted
)
1342 /* We're passing through the last exception we received. This is
1343 kind of bogus, because exceptions are per-thread whereas gdb
1344 treats signals as per-process. We just forward the exception to
1345 the correct handler, even it's not for the same thread as TID --
1346 i.e., we pretend it's global. */
1348 struct exc_state
*e
= &w
->exc
;
1350 inf_debug (inf
, "passing through exception:"
1351 " task = %d, thread = %d, exc = %d"
1352 ", code = %d, subcode = %d",
1353 w
->thread
->port
, inf
->task
->port
,
1354 e
->exception
, e
->code
, e
->subcode
);
1356 exception_raise_request (e
->handler
,
1357 e
->reply
, MACH_MSG_TYPE_MOVE_SEND_ONCE
,
1358 w
->thread
->port
, inf
->task
->port
,
1359 e
->exception
, e
->code
, e
->subcode
);
1362 error (_("Can't forward spontaneous exception (%s)."), NAME
);
1365 /* A Unix signal. */
1367 /* The process is stopped and expecting a signal. Just send off a
1368 request and let it get handled when we resume everything. */
1370 inf_debug (inf
, "sending %s to stopped process", NAME
);
1372 INF_MSGPORT_RPC (inf
,
1373 msg_sig_post_untraced_request (msgport
,
1375 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
1379 /* Posting an untraced signal automatically continues it.
1380 We clear this here rather than when we get the reply
1381 because we'd rather assume it's not stopped when it
1382 actually is, than the reverse. */
1386 /* It's not expecting it. We have to let just the signal thread
1387 run, and wait for it to get into a reasonable state before we
1388 can continue the rest of the process. When we finally resume the
1389 process the signal we request will be the very first thing that
1392 inf_debug (inf
, "sending %s to unstopped process"
1393 " (so resuming signal thread)", NAME
);
1395 INF_RESUME_MSGPORT_RPC (inf
,
1396 msg_sig_post_untraced (msgport
, host_sig
,
1401 /* Can't do too much... */
1402 warning (_("Can't deliver signal %s: No signal thread."), NAME
);
1404 warning (_("Delivering signal %s: %s"), NAME
, safe_strerror (err
));
1410 /* Continue INF without delivering a signal. This is meant to be used
1411 when INF does not have a message port. */
1413 inf_continue (struct inf
*inf
)
1416 error_t err
= proc_pid2proc (proc_server
, inf
->pid
, &proc
);
1420 inf_debug (inf
, "continuing process");
1422 err
= proc_mark_cont (proc
);
1425 struct proc
*thread
;
1427 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1428 thread_resume (thread
->port
);
1435 warning (_("Can't continue process: %s"), safe_strerror (err
));
1439 /* The inferior used for all gdb target ops. */
1440 struct inf
*gnu_current_inf
= 0;
1442 /* The inferior being waited for by gnu_wait. Since GDB is decidely not
1443 multi-threaded, we don't bother to lock this. */
1444 struct inf
*waiting_inf
;
1446 /* Wait for something to happen in the inferior, returning what in STATUS. */
1448 gnu_wait (struct target_ops
*ops
,
1449 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
1453 mach_msg_header_t hdr
;
1454 mach_msg_type_t type
;
1458 struct proc
*thread
;
1459 struct inf
*inf
= gnu_current_inf
;
1461 extern int exc_server (mach_msg_header_t
*, mach_msg_header_t
*);
1462 extern int msg_reply_server (mach_msg_header_t
*, mach_msg_header_t
*);
1463 extern int notify_server (mach_msg_header_t
*, mach_msg_header_t
*);
1464 extern int process_reply_server (mach_msg_header_t
*, mach_msg_header_t
*);
1466 gdb_assert (inf
->task
);
1468 if (!inf
->threads
&& !inf
->pending_execs
)
1469 /* No threads! Assume that maybe some outside agency is frobbing our
1470 task, and really look for new threads. If we can't find any, just tell
1471 the user to try again later. */
1473 inf_validate_procs (inf
);
1474 if (!inf
->threads
&& !inf
->task
->dead
)
1475 error (_("There are no threads; try again later."));
1480 inf_debug (inf
, "waiting for: %s", target_pid_to_str (ptid
));
1483 if (proc_wait_pid
!= inf
->pid
&& !inf
->no_wait
)
1484 /* Always get information on events from the proc server. */
1486 inf_debug (inf
, "requesting wait on pid %d", inf
->pid
);
1489 /* The proc server is single-threaded, and only allows a single
1490 outstanding wait request, so we have to cancel the previous one. */
1492 inf_debug (inf
, "cancelling previous wait on pid %d", proc_wait_pid
);
1493 interrupt_operation (proc_server
, 0);
1497 proc_wait_request (proc_server
, inf
->event_port
, inf
->pid
, WUNTRACED
);
1499 warning (_("wait request failed: %s"), safe_strerror (err
));
1502 inf_debug (inf
, "waits pending: %d", proc_waits_pending
);
1503 proc_wait_pid
= inf
->pid
;
1504 /* Even if proc_waits_pending was > 0 before, we still won't
1505 get any other replies, because it was either from a
1506 different INF, or a different process attached to INF --
1507 and the event port, which is the wait reply port, changes
1508 when you switch processes. */
1509 proc_waits_pending
= 1;
1513 inf_clear_wait (inf
);
1515 /* What can happen? (1) Dead name notification; (2) Exceptions arrive;
1516 (3) wait reply from the proc server. */
1518 inf_debug (inf
, "waiting for an event...");
1519 err
= mach_msg (&msg
.hdr
, MACH_RCV_MSG
| MACH_RCV_INTERRUPT
,
1520 0, sizeof (struct msg
), inf
->event_port
,
1521 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
1523 /* Re-suspend the task. */
1526 if (!inf
->task
&& inf
->pending_execs
)
1527 /* When doing an exec, it's possible that the old task wasn't reused
1528 (e.g., setuid execs). So if the task seems to have disappeared,
1529 attempt to refetch it, as the pid should still be the same. */
1530 inf_set_pid (inf
, inf
->pid
);
1532 if (err
== EMACH_RCV_INTERRUPTED
)
1533 inf_debug (inf
, "interrupted");
1535 error (_("Couldn't wait for an event: %s"), safe_strerror (err
));
1540 mach_msg_header_t hdr
;
1541 mach_msg_type_t err_type
;
1547 inf_debug (inf
, "event: msgid = %d", msg
.hdr
.msgh_id
);
1549 /* Handle what we got. */
1550 if (!notify_server (&msg
.hdr
, &reply
.hdr
)
1551 && !exc_server (&msg
.hdr
, &reply
.hdr
)
1552 && !process_reply_server (&msg
.hdr
, &reply
.hdr
)
1553 && !msg_reply_server (&msg
.hdr
, &reply
.hdr
))
1554 /* Whatever it is, it's something strange. */
1555 error (_("Got a strange event, msg id = %d."), msg
.hdr
.msgh_id
);
1558 error (_("Handling event, msgid = %d: %s"),
1559 msg
.hdr
.msgh_id
, safe_strerror (reply
.err
));
1562 if (inf
->pending_execs
)
1563 /* We're waiting for the inferior to finish execing. */
1565 struct inf_wait
*w
= &inf
->wait
;
1566 enum target_waitkind kind
= w
->status
.kind
;
1568 if (kind
== TARGET_WAITKIND_SPURIOUS
)
1569 /* Since gdb is actually counting the number of times the inferior
1570 stops, expecting one stop per exec, we only return major events
1574 inf_debug (inf
, "pending_execs = %d, ignoring minor event",
1575 inf
->pending_execs
);
1577 else if (kind
== TARGET_WAITKIND_STOPPED
1578 && w
->status
.value
.sig
== GDB_SIGNAL_TRAP
)
1579 /* Ah hah! A SIGTRAP from the inferior while starting up probably
1580 means we've succesfully completed an exec! */
1582 if (--inf
->pending_execs
== 0)
1585 #if 0 /* do we need this? */
1586 prune_threads (1); /* Get rid of the old shell
1588 renumber_threads (0); /* Give our threads reasonable
1592 inf_debug (inf
, "pending exec completed, pending_execs => %d",
1593 inf
->pending_execs
);
1595 else if (kind
== TARGET_WAITKIND_STOPPED
)
1596 /* It's possible that this signal is because of a crashed process
1597 being handled by the hurd crash server; in this case, the process
1598 will have an extra task suspend, which we need to know about.
1599 Since the code in inf_resume that normally checks for this is
1600 disabled while INF->pending_execs, we do the check here instead. */
1601 inf_validate_task_sc (inf
);
1604 if (inf
->wait
.suppress
)
1605 /* Some totally spurious event happened that we don't consider
1606 worth returning to gdb. Just keep waiting. */
1608 inf_debug (inf
, "suppressing return, rewaiting...");
1613 /* Pass back out our results. */
1614 memcpy (status
, &inf
->wait
.status
, sizeof (*status
));
1616 thread
= inf
->wait
.thread
;
1618 ptid
= ptid_build (inf
->pid
, 0, thread
->tid
);
1619 else if (ptid_equal (ptid
, minus_one_ptid
))
1620 thread
= inf_tid_to_thread (inf
, -1);
1622 thread
= inf_tid_to_thread (inf
, ptid_get_tid (ptid
));
1624 if (!thread
|| thread
->port
== MACH_PORT_NULL
)
1626 /* TID is dead; try and find a new thread. */
1627 if (inf_update_procs (inf
) && inf
->threads
)
1628 ptid
= ptid_build (inf
->pid
, 0, inf
->threads
->tid
); /* The first
1632 ptid
= inferior_ptid
; /* let wait_for_inferior handle exit case */
1636 && !ptid_equal (ptid
, minus_one_ptid
)
1637 && status
->kind
!= TARGET_WAITKIND_SPURIOUS
1638 && inf
->pause_sc
== 0 && thread
->pause_sc
== 0)
1639 /* If something actually happened to THREAD, make sure we
1643 inf_update_suspends (inf
);
1646 inf_debug (inf
, "returning ptid = %s, status = %s (%d)",
1647 target_pid_to_str (ptid
),
1648 status
->kind
== TARGET_WAITKIND_EXITED
? "EXITED"
1649 : status
->kind
== TARGET_WAITKIND_STOPPED
? "STOPPED"
1650 : status
->kind
== TARGET_WAITKIND_SIGNALLED
? "SIGNALLED"
1651 : status
->kind
== TARGET_WAITKIND_LOADED
? "LOADED"
1652 : status
->kind
== TARGET_WAITKIND_SPURIOUS
? "SPURIOUS"
1654 status
->value
.integer
);
1660 /* The rpc handler called by exc_server. */
1662 S_exception_raise_request (mach_port_t port
, mach_port_t reply_port
,
1663 thread_t thread_port
, task_t task_port
,
1664 int exception
, int code
, int subcode
)
1666 struct inf
*inf
= waiting_inf
;
1667 struct proc
*thread
= inf_port_to_thread (inf
, thread_port
);
1669 inf_debug (waiting_inf
,
1670 "thread = %d, task = %d, exc = %d, code = %d, subcode = %d",
1671 thread_port
, task_port
, exception
, code
, subcode
);
1674 /* We don't know about thread? */
1676 inf_update_procs (inf
);
1677 thread
= inf_port_to_thread (inf
, thread_port
);
1679 /* Give up, the generating thread is gone. */
1683 mach_port_deallocate (mach_task_self (), thread_port
);
1684 mach_port_deallocate (mach_task_self (), task_port
);
1686 if (!thread
->aborted
)
1687 /* THREAD hasn't been aborted since this exception happened (abortion
1688 clears any exception state), so it must be real. */
1690 /* Store away the details; this will destroy any previous info. */
1691 inf
->wait
.thread
= thread
;
1693 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1695 if (exception
== EXC_BREAKPOINT
)
1696 /* GDB likes to get SIGTRAP for breakpoints. */
1698 inf
->wait
.status
.value
.sig
= GDB_SIGNAL_TRAP
;
1699 mach_port_deallocate (mach_task_self (), reply_port
);
1702 /* Record the exception so that we can forward it later. */
1704 if (thread
->exc_port
== port
)
1706 inf_debug (waiting_inf
, "Handler is thread exception port <%d>",
1707 thread
->saved_exc_port
);
1708 inf
->wait
.exc
.handler
= thread
->saved_exc_port
;
1712 inf_debug (waiting_inf
, "Handler is task exception port <%d>",
1713 inf
->task
->saved_exc_port
);
1714 inf
->wait
.exc
.handler
= inf
->task
->saved_exc_port
;
1715 gdb_assert (inf
->task
->exc_port
== port
);
1717 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
1718 /* Add a reference to the exception handler. */
1719 mach_port_mod_refs (mach_task_self (),
1720 inf
->wait
.exc
.handler
, MACH_PORT_RIGHT_SEND
,
1723 inf
->wait
.exc
.exception
= exception
;
1724 inf
->wait
.exc
.code
= code
;
1725 inf
->wait
.exc
.subcode
= subcode
;
1726 inf
->wait
.exc
.reply
= reply_port
;
1728 /* Exceptions are encoded in the signal space by putting
1729 them after _NSIG; this assumes they're positive (and not
1730 extremely large)! */
1731 inf
->wait
.status
.value
.sig
=
1732 gdb_signal_from_host (_NSIG
+ exception
);
1736 /* A supppressed exception, which ignore. */
1738 inf
->wait
.suppress
= 1;
1739 mach_port_deallocate (mach_task_self (), reply_port
);
1746 /* Fill in INF's wait field after a task has died without giving us more
1747 detailed information. */
1749 inf_task_died_status (struct inf
*inf
)
1751 warning (_("Pid %d died with unknown exit status, using SIGKILL."),
1753 inf
->wait
.status
.kind
= TARGET_WAITKIND_SIGNALLED
;
1754 inf
->wait
.status
.value
.sig
= GDB_SIGNAL_KILL
;
1757 /* Notify server routines. The only real one is dead name notification. */
1759 do_mach_notify_dead_name (mach_port_t notify
, mach_port_t dead_port
)
1761 struct inf
*inf
= waiting_inf
;
1763 inf_debug (waiting_inf
, "port = %d", dead_port
);
1765 if (inf
->task
&& inf
->task
->port
== dead_port
)
1767 proc_debug (inf
->task
, "is dead");
1768 inf
->task
->port
= MACH_PORT_NULL
;
1769 if (proc_wait_pid
== inf
->pid
)
1770 /* We have a wait outstanding on the process, which will return more
1771 detailed information, so delay until we get that. */
1772 inf
->wait
.suppress
= 1;
1774 /* We never waited for the process (maybe it wasn't a child), so just
1775 pretend it got a SIGKILL. */
1776 inf_task_died_status (inf
);
1780 struct proc
*thread
= inf_port_to_thread (inf
, dead_port
);
1784 proc_debug (thread
, "is dead");
1785 thread
->port
= MACH_PORT_NULL
;
1788 if (inf
->task
->dead
)
1789 /* Since the task is dead, its threads are dying with it. */
1790 inf
->wait
.suppress
= 1;
1793 mach_port_deallocate (mach_task_self (), dead_port
);
1794 inf
->threads_up_to_date
= 0; /* Just in case. */
1803 warning (_("illegal rpc: %s"), fun
);
1808 do_mach_notify_no_senders (mach_port_t notify
, mach_port_mscount_t count
)
1810 return ill_rpc ("do_mach_notify_no_senders");
1814 do_mach_notify_port_deleted (mach_port_t notify
, mach_port_t name
)
1816 return ill_rpc ("do_mach_notify_port_deleted");
1820 do_mach_notify_msg_accepted (mach_port_t notify
, mach_port_t name
)
1822 return ill_rpc ("do_mach_notify_msg_accepted");
1826 do_mach_notify_port_destroyed (mach_port_t notify
, mach_port_t name
)
1828 return ill_rpc ("do_mach_notify_port_destroyed");
1832 do_mach_notify_send_once (mach_port_t notify
)
1834 return ill_rpc ("do_mach_notify_send_once");
1838 /* Process_reply server routines. We only use process_wait_reply. */
1841 S_proc_wait_reply (mach_port_t reply
, error_t err
,
1842 int status
, int sigcode
, rusage_t rusage
, pid_t pid
)
1844 struct inf
*inf
= waiting_inf
;
1846 inf_debug (inf
, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1847 err
? safe_strerror (err
) : "0", pid
, status
, sigcode
);
1849 if (err
&& proc_wait_pid
&& (!inf
->task
|| !inf
->task
->port
))
1850 /* Ack. The task has died, but the task-died notification code didn't
1851 tell anyone because it thought a more detailed reply from the
1852 procserver was forthcoming. However, we now learn that won't
1853 happen... So we have to act like the task just died, and this time,
1855 inf_task_died_status (inf
);
1857 if (--proc_waits_pending
== 0)
1858 /* PROC_WAIT_PID represents the most recent wait. We will always get
1859 replies in order because the proc server is single threaded. */
1862 inf_debug (inf
, "waits pending now: %d", proc_waits_pending
);
1868 warning (_("Can't wait for pid %d: %s"),
1869 inf
->pid
, safe_strerror (err
));
1872 /* Since we can't see the inferior's signals, don't trap them. */
1873 inf_set_traced (inf
, 0);
1876 else if (pid
== inf
->pid
)
1878 store_waitstatus (&inf
->wait
.status
, status
);
1879 if (inf
->wait
.status
.kind
== TARGET_WAITKIND_STOPPED
)
1880 /* The process has sent us a signal, and stopped itself in a sane
1881 state pending our actions. */
1883 inf_debug (inf
, "process has stopped itself");
1888 inf
->wait
.suppress
= 1; /* Something odd happened. Ignore. */
1894 S_proc_setmsgport_reply (mach_port_t reply
, error_t err
,
1895 mach_port_t old_msg_port
)
1897 return ill_rpc ("S_proc_setmsgport_reply");
1901 S_proc_getmsgport_reply (mach_port_t reply
, error_t err
, mach_port_t msg_port
)
1903 return ill_rpc ("S_proc_getmsgport_reply");
1907 /* Msg_reply server routines. We only use msg_sig_post_untraced_reply. */
1910 S_msg_sig_post_untraced_reply (mach_port_t reply
, error_t err
)
1912 struct inf
*inf
= waiting_inf
;
1915 /* EBUSY is what we get when the crash server has grabbed control of the
1916 process and doesn't like what signal we tried to send it. Just act
1917 like the process stopped (using a signal of 0 should mean that the
1918 *next* time the user continues, it will pass signal 0, which the crash
1919 server should like). */
1921 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1922 inf
->wait
.status
.value
.sig
= GDB_SIGNAL_0
;
1925 warning (_("Signal delivery failed: %s"), safe_strerror (err
));
1928 /* We only get this reply when we've posted a signal to a process which we
1929 thought was stopped, and which we expected to continue after the signal.
1930 Given that the signal has failed for some reason, it's reasonable to
1931 assume it's still stopped. */
1934 inf
->wait
.suppress
= 1;
1940 S_msg_sig_post_reply (mach_port_t reply
, error_t err
)
1942 return ill_rpc ("S_msg_sig_post_reply");
1946 /* Returns the number of messages queued for the receive right PORT. */
1947 static mach_port_msgcount_t
1948 port_msgs_queued (mach_port_t port
)
1950 struct mach_port_status status
;
1952 mach_port_get_receive_status (mach_task_self (), port
, &status
);
1957 return status
.mps_msgcount
;
1961 /* Resume execution of the inferior process.
1963 If STEP is nonzero, single-step it.
1964 If SIGNAL is nonzero, give it that signal.
1967 -1 true Single step the current thread allowing other threads to run.
1968 -1 false Continue the current thread allowing other threads to run.
1969 X true Single step the given thread, don't allow any others to run.
1970 X false Continue the given thread, do not allow any others to run.
1971 (Where X, of course, is anything except -1)
1973 Note that a resume may not `take' if there are pending exceptions/&c
1974 still unprocessed from the last resume we did (any given resume may result
1975 in multiple events returned by wait). */
1978 gnu_resume (struct target_ops
*ops
,
1979 ptid_t ptid
, int step
, enum gdb_signal sig
)
1981 struct proc
*step_thread
= 0;
1983 struct inf
*inf
= gnu_current_inf
;
1985 inf_debug (inf
, "ptid = %s, step = %d, sig = %d",
1986 target_pid_to_str (ptid
), step
, sig
);
1988 inf_validate_procinfo (inf
);
1990 if (sig
!= GDB_SIGNAL_0
|| inf
->stopped
)
1992 if (sig
== GDB_SIGNAL_0
&& inf
->nomsg
)
1995 inf_signal (inf
, sig
);
1997 else if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
1998 /* We received an exception to which we have chosen not to forward, so
1999 abort the faulting thread, which will perhaps retake it. */
2001 proc_abort (inf
->wait
.thread
, 1);
2002 warning (_("Aborting %s with unforwarded exception %s."),
2003 proc_string (inf
->wait
.thread
),
2004 gdb_signal_to_name (inf
->wait
.status
.value
.sig
));
2007 if (port_msgs_queued (inf
->event_port
))
2008 /* If there are still messages in our event queue, don't bother resuming
2009 the process, as we're just going to stop it right away anyway. */
2012 inf_update_procs (inf
);
2014 /* A specific PTID means `step only this process id'. */
2015 resume_all
= ptid_equal (ptid
, minus_one_ptid
);
2018 /* Allow all threads to run, except perhaps single-stepping one. */
2020 inf_debug (inf
, "running all threads; tid = %d", PIDGET (inferior_ptid
));
2021 ptid
= inferior_ptid
; /* What to step. */
2022 inf_set_threads_resume_sc (inf
, 0, 1);
2025 /* Just allow a single thread to run. */
2027 struct proc
*thread
= inf_tid_to_thread (inf
, ptid_get_tid (ptid
));
2030 error (_("Can't run single thread id %s: no such thread!"),
2031 target_pid_to_str (ptid
));
2032 inf_debug (inf
, "running one thread: %s", target_pid_to_str (ptid
));
2033 inf_set_threads_resume_sc (inf
, thread
, 0);
2038 step_thread
= inf_tid_to_thread (inf
, ptid_get_tid (ptid
));
2040 warning (_("Can't step thread id %s: no such thread."),
2041 target_pid_to_str (ptid
));
2043 inf_debug (inf
, "stepping thread: %s", target_pid_to_str (ptid
));
2045 if (step_thread
!= inf
->step_thread
)
2046 inf_set_step_thread (inf
, step_thread
);
2048 inf_debug (inf
, "here we go...");
2054 gnu_kill_inferior (struct target_ops
*ops
)
2056 struct proc
*task
= gnu_current_inf
->task
;
2060 proc_debug (task
, "terminating...");
2061 task_terminate (task
->port
);
2062 inf_set_pid (gnu_current_inf
, -1);
2064 target_mourn_inferior ();
2067 /* Clean up after the inferior dies. */
2069 gnu_mourn_inferior (struct target_ops
*ops
)
2071 inf_debug (gnu_current_inf
, "rip");
2072 inf_detach (gnu_current_inf
);
2073 unpush_target (ops
);
2074 generic_mourn_inferior ();
2078 /* Fork an inferior process, and start debugging it. */
2080 /* Set INFERIOR_PID to the first thread available in the child, if any. */
2082 inf_pick_first_thread (void)
2084 if (gnu_current_inf
->task
&& gnu_current_inf
->threads
)
2085 /* The first thread. */
2086 return gnu_current_inf
->threads
->tid
;
2088 /* What may be the next thread. */
2089 return next_thread_id
;
2095 if (!gnu_current_inf
)
2096 gnu_current_inf
= make_inf ();
2097 return gnu_current_inf
;
2101 gnu_create_inferior (struct target_ops
*ops
,
2102 char *exec_file
, char *allargs
, char **env
,
2105 struct inf
*inf
= cur_inf ();
2110 /* We're in the child; make this process stop as soon as it execs. */
2111 inf_debug (inf
, "tracing self");
2112 if (ptrace (PTRACE_TRACEME
) != 0)
2113 error (_("ptrace (PTRACE_TRACEME) failed!"));
2116 inf_debug (inf
, "creating inferior");
2118 pid
= fork_inferior (exec_file
, allargs
, env
, trace_me
,
2119 NULL
, NULL
, NULL
, NULL
);
2121 /* Attach to the now stopped child, which is actually a shell... */
2122 inf_debug (inf
, "attaching to child: %d", pid
);
2124 inf_attach (inf
, pid
);
2128 inf
->pending_execs
= 2;
2132 /* Now let the child run again, knowing that it will stop
2133 immediately because of the ptrace. */
2136 /* We now have thread info. */
2137 thread_change_ptid (inferior_ptid
,
2138 ptid_build (inf
->pid
, 0, inf_pick_first_thread ()));
2140 startup_inferior (inf
->pending_execs
);
2142 inf_validate_procinfo (inf
);
2143 inf_update_signal_thread (inf
);
2144 inf_set_traced (inf
, inf
->want_signals
);
2146 /* Execing the process will have trashed our exception ports; steal them
2147 back (or make sure they're restored if the user wants that). */
2148 if (inf
->want_exceptions
)
2149 inf_steal_exc_ports (inf
);
2151 inf_restore_exc_ports (inf
);
2155 /* Attach to process PID, then initialize for debugging it
2156 and wait for the trace-trap that results from attaching. */
2158 gnu_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2162 struct inf
*inf
= cur_inf ();
2163 struct inferior
*inferior
;
2165 pid
= parse_pid_to_attach (args
);
2167 if (pid
== getpid ()) /* Trying to masturbate? */
2168 error (_("I refuse to debug myself!"));
2172 exec_file
= (char *) get_exec_file (0);
2175 printf_unfiltered ("Attaching to program `%s', pid %d\n",
2178 printf_unfiltered ("Attaching to pid %d\n", pid
);
2180 gdb_flush (gdb_stdout
);
2183 inf_debug (inf
, "attaching to pid: %d", pid
);
2185 inf_attach (inf
, pid
);
2189 inferior
= current_inferior ();
2190 inferior_appeared (inferior
, pid
);
2191 inferior
->attach_flag
= 1;
2193 inf_update_procs (inf
);
2195 inferior_ptid
= ptid_build (pid
, 0, inf_pick_first_thread ());
2197 /* We have to initialize the terminal settings now, since the code
2198 below might try to restore them. */
2199 target_terminal_init ();
2201 /* If the process was stopped before we attached, make it continue the next
2202 time the user does a continue. */
2203 inf_validate_procinfo (inf
);
2205 inf_update_signal_thread (inf
);
2206 inf_set_traced (inf
, inf
->want_signals
);
2208 #if 0 /* Do we need this? */
2209 renumber_threads (0); /* Give our threads reasonable names. */
2214 /* Take a program previously attached to and detaches it.
2215 The program resumes execution and will no longer stop
2216 on signals, etc. We'd better not have left any breakpoints
2217 in the program or it'll die when it hits one. For this
2218 to work, it may be necessary for the process to have been
2219 previously attached. It *might* work if the program was
2220 started via fork. */
2222 gnu_detach (struct target_ops
*ops
, char *args
, int from_tty
)
2228 char *exec_file
= get_exec_file (0);
2231 printf_unfiltered ("Detaching from program `%s' pid %d\n",
2232 exec_file
, gnu_current_inf
->pid
);
2234 printf_unfiltered ("Detaching from pid %d\n", gnu_current_inf
->pid
);
2235 gdb_flush (gdb_stdout
);
2238 pid
= gnu_current_inf
->pid
;
2240 inf_detach (gnu_current_inf
);
2242 inferior_ptid
= null_ptid
;
2243 detach_inferior (pid
);
2245 unpush_target (ops
); /* Pop out of handling an inferior. */
2249 gnu_terminal_init_inferior (void)
2251 gdb_assert (gnu_current_inf
);
2252 terminal_init_inferior_with_pgrp (gnu_current_inf
->pid
);
2256 gnu_stop (ptid_t ptid
)
2258 error (_("to_stop target function not implemented"));
2262 gnu_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2264 inf_update_procs (gnu_current_inf
);
2265 return !!inf_tid_to_thread (gnu_current_inf
,
2266 ptid_get_tid (ptid
));
2270 /* Read inferior task's LEN bytes from ADDR and copy it to MYADDR in
2271 gdb's address space. Return 0 on failure; number of bytes read
2274 gnu_read_inferior (task_t task
, CORE_ADDR addr
, char *myaddr
, int length
)
2277 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2278 vm_size_t aligned_length
=
2279 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2283 /* Get memory from inferior with page aligned addresses. */
2284 err
= vm_read (task
, low_address
, aligned_length
, &copied
, ©_count
);
2288 err
= hurd_safe_copyin (myaddr
, (void *) (addr
- low_address
+ copied
),
2292 warning (_("Read from inferior faulted: %s"), safe_strerror (err
));
2296 err
= vm_deallocate (mach_task_self (), copied
, copy_count
);
2298 warning (_("gnu_read_inferior vm_deallocate failed: %s"),
2299 safe_strerror (err
));
2304 #define CHK_GOTO_OUT(str,ret) \
2305 do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
2307 struct vm_region_list
2309 struct vm_region_list
*next
;
2310 vm_prot_t protection
;
2315 struct obstack region_obstack
;
2317 /* Write gdb's LEN bytes from MYADDR and copy it to ADDR in inferior
2318 task's address space. */
2320 gnu_write_inferior (task_t task
, CORE_ADDR addr
, char *myaddr
, int length
)
2323 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2324 vm_size_t aligned_length
=
2325 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2330 char *errstr
= "Bug in gnu_write_inferior";
2332 struct vm_region_list
*region_element
;
2333 struct vm_region_list
*region_head
= (struct vm_region_list
*) NULL
;
2335 /* Get memory from inferior with page aligned addresses. */
2336 err
= vm_read (task
,
2341 CHK_GOTO_OUT ("gnu_write_inferior vm_read failed", err
);
2345 err
= hurd_safe_copyout ((void *) (addr
- low_address
+ copied
),
2347 CHK_GOTO_OUT ("Write to inferior faulted", err
);
2349 obstack_init (®ion_obstack
);
2351 /* Do writes atomically.
2352 First check for holes and unwritable memory. */
2354 vm_size_t remaining_length
= aligned_length
;
2355 vm_address_t region_address
= low_address
;
2357 struct vm_region_list
*scan
;
2359 while (region_address
< low_address
+ aligned_length
)
2361 vm_prot_t protection
;
2362 vm_prot_t max_protection
;
2363 vm_inherit_t inheritance
;
2365 mach_port_t object_name
;
2367 vm_size_t region_length
= remaining_length
;
2368 vm_address_t old_address
= region_address
;
2370 err
= vm_region (task
,
2379 CHK_GOTO_OUT ("vm_region failed", err
);
2381 /* Check for holes in memory. */
2382 if (old_address
!= region_address
)
2384 warning (_("No memory at 0x%x. Nothing written"),
2391 if (!(max_protection
& VM_PROT_WRITE
))
2393 warning (_("Memory at address 0x%x is unwritable. "
2401 /* Chain the regions for later use. */
2403 (struct vm_region_list
*)
2404 obstack_alloc (®ion_obstack
, sizeof (struct vm_region_list
));
2406 region_element
->protection
= protection
;
2407 region_element
->start
= region_address
;
2408 region_element
->length
= region_length
;
2410 /* Chain the regions along with protections. */
2411 region_element
->next
= region_head
;
2412 region_head
= region_element
;
2414 region_address
+= region_length
;
2415 remaining_length
= remaining_length
- region_length
;
2418 /* If things fail after this, we give up.
2419 Somebody is messing up inferior_task's mappings. */
2421 /* Enable writes to the chained vm regions. */
2422 for (scan
= region_head
; scan
; scan
= scan
->next
)
2424 if (!(scan
->protection
& VM_PROT_WRITE
))
2426 err
= vm_protect (task
,
2430 scan
->protection
| VM_PROT_WRITE
);
2431 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2435 err
= vm_write (task
,
2439 CHK_GOTO_OUT ("vm_write failed", err
);
2441 /* Set up the original region protections, if they were changed. */
2442 for (scan
= region_head
; scan
; scan
= scan
->next
)
2444 if (!(scan
->protection
& VM_PROT_WRITE
))
2446 err
= vm_protect (task
,
2451 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2459 obstack_free (®ion_obstack
, 0);
2461 (void) vm_deallocate (mach_task_self (),
2466 if (err
!= KERN_SUCCESS
)
2468 warning (_("%s: %s"), errstr
, mach_error_string (err
));
2476 /* Return 0 on failure, number of bytes handled otherwise. TARGET
2479 gnu_xfer_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
, int write
,
2480 struct mem_attrib
*attrib
,
2481 struct target_ops
*target
)
2483 task_t task
= (gnu_current_inf
2484 ? (gnu_current_inf
->task
2485 ? gnu_current_inf
->task
->port
: 0)
2488 if (task
== MACH_PORT_NULL
)
2492 inf_debug (gnu_current_inf
, "%s %s[%d] %s %s",
2493 write
? "writing" : "reading",
2494 paddress (target_gdbarch
, memaddr
), len
,
2495 write
? "<--" : "-->", host_address_to_string (myaddr
));
2497 return gnu_write_inferior (task
, memaddr
, myaddr
, len
);
2499 return gnu_read_inferior (task
, memaddr
, myaddr
, len
);
2503 /* Call FUNC on each memory region in the task. */
2505 gnu_find_memory_regions (find_memory_region_ftype func
, void *data
)
2509 vm_address_t region_address
, last_region_address
, last_region_end
;
2510 vm_prot_t last_protection
;
2512 if (gnu_current_inf
== 0 || gnu_current_inf
->task
== 0)
2514 task
= gnu_current_inf
->task
->port
;
2515 if (task
== MACH_PORT_NULL
)
2518 region_address
= last_region_address
= last_region_end
= VM_MIN_ADDRESS
;
2519 last_protection
= VM_PROT_NONE
;
2520 while (region_address
< VM_MAX_ADDRESS
)
2522 vm_prot_t protection
;
2523 vm_prot_t max_protection
;
2524 vm_inherit_t inheritance
;
2526 mach_port_t object_name
;
2528 vm_size_t region_length
= VM_MAX_ADDRESS
- region_address
;
2529 vm_address_t old_address
= region_address
;
2531 err
= vm_region (task
,
2540 if (err
== KERN_NO_SPACE
)
2542 if (err
!= KERN_SUCCESS
)
2544 warning (_("vm_region failed: %s"), mach_error_string (err
));
2548 if (protection
== last_protection
&& region_address
== last_region_end
)
2549 /* This region is contiguous with and indistinguishable from
2550 the previous one, so we just extend that one. */
2551 last_region_end
= region_address
+= region_length
;
2554 /* This region is distinct from the last one we saw, so report
2555 that previous one. */
2556 if (last_protection
!= VM_PROT_NONE
)
2557 (*func
) (last_region_address
,
2558 last_region_end
- last_region_address
,
2559 last_protection
& VM_PROT_READ
,
2560 last_protection
& VM_PROT_WRITE
,
2561 last_protection
& VM_PROT_EXECUTE
,
2562 1, /* MODIFIED is unknown, pass it as true. */
2564 last_region_address
= region_address
;
2565 last_region_end
= region_address
+= region_length
;
2566 last_protection
= protection
;
2570 /* Report the final region. */
2571 if (last_region_end
> last_region_address
&& last_protection
!= VM_PROT_NONE
)
2572 (*func
) (last_region_address
, last_region_end
- last_region_address
,
2573 last_protection
& VM_PROT_READ
,
2574 last_protection
& VM_PROT_WRITE
,
2575 last_protection
& VM_PROT_EXECUTE
,
2576 1, /* MODIFIED is unknown, pass it as true. */
2583 /* Return printable description of proc. */
2585 proc_string (struct proc
*proc
)
2587 static char tid_str
[80];
2589 if (proc_is_task (proc
))
2590 sprintf (tid_str
, "process %d", proc
->inf
->pid
);
2592 sprintf (tid_str
, "Thread %d.%d",
2593 proc
->inf
->pid
, proc
->tid
);
2598 gnu_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
2600 struct inf
*inf
= gnu_current_inf
;
2601 int tid
= ptid_get_tid (ptid
);
2602 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
2605 return proc_string (thread
);
2608 static char tid_str
[80];
2610 sprintf (tid_str
, "bogus thread id %d", tid
);
2616 /* Create a prototype generic GNU/Hurd target. The client can
2617 override it with local methods. */
2622 struct target_ops
*t
= inf_child_target ();
2624 t
->to_shortname
= "GNU";
2625 t
->to_longname
= "GNU Hurd process";
2626 t
->to_doc
= "GNU Hurd process";
2628 t
->to_attach
= gnu_attach
;
2629 t
->to_attach_no_wait
= 1;
2630 t
->to_detach
= gnu_detach
;
2631 t
->to_resume
= gnu_resume
;
2632 t
->to_wait
= gnu_wait
;
2633 t
->deprecated_xfer_memory
= gnu_xfer_memory
;
2634 t
->to_find_memory_regions
= gnu_find_memory_regions
;
2635 t
->to_terminal_init
= gnu_terminal_init_inferior
;
2636 t
->to_kill
= gnu_kill_inferior
;
2637 t
->to_create_inferior
= gnu_create_inferior
;
2638 t
->to_mourn_inferior
= gnu_mourn_inferior
;
2639 t
->to_thread_alive
= gnu_thread_alive
;
2640 t
->to_pid_to_str
= gnu_pid_to_str
;
2641 t
->to_stop
= gnu_stop
;
2647 /* User task commands. */
2649 static struct cmd_list_element
*set_task_cmd_list
= 0;
2650 static struct cmd_list_element
*show_task_cmd_list
= 0;
2651 /* User thread commands. */
2653 /* Commands with a prefix of `set/show thread'. */
2654 extern struct cmd_list_element
*thread_cmd_list
;
2655 struct cmd_list_element
*set_thread_cmd_list
= NULL
;
2656 struct cmd_list_element
*show_thread_cmd_list
= NULL
;
2658 /* Commands with a prefix of `set/show thread default'. */
2659 struct cmd_list_element
*set_thread_default_cmd_list
= NULL
;
2660 struct cmd_list_element
*show_thread_default_cmd_list
= NULL
;
2663 set_thread_cmd (char *args
, int from_tty
)
2665 printf_unfiltered ("\"set thread\" must be followed by the "
2666 "name of a thread property, or \"default\".\n");
2670 show_thread_cmd (char *args
, int from_tty
)
2672 printf_unfiltered ("\"show thread\" must be followed by the "
2673 "name of a thread property, or \"default\".\n");
2677 set_thread_default_cmd (char *args
, int from_tty
)
2679 printf_unfiltered ("\"set thread default\" must be followed "
2680 "by the name of a thread property.\n");
2684 show_thread_default_cmd (char *args
, int from_tty
)
2686 printf_unfiltered ("\"show thread default\" must be followed "
2687 "by the name of a thread property.\n");
2691 parse_int_arg (char *args
, char *cmd_prefix
)
2696 int val
= strtoul (args
, &arg_end
, 10);
2698 if (*args
&& *arg_end
== '\0')
2701 error (_("Illegal argument for \"%s\" command, should be an integer."),
2706 _parse_bool_arg (char *args
, char *t_val
, char *f_val
, char *cmd_prefix
)
2708 if (!args
|| strcmp (args
, t_val
) == 0)
2710 else if (strcmp (args
, f_val
) == 0)
2713 error (_("Illegal argument for \"%s\" command, "
2714 "should be \"%s\" or \"%s\"."),
2715 cmd_prefix
, t_val
, f_val
);
2718 #define parse_bool_arg(args, cmd_prefix) \
2719 _parse_bool_arg (args, "on", "off", cmd_prefix)
2722 check_empty (char *args
, char *cmd_prefix
)
2725 error (_("Garbage after \"%s\" command: `%s'"), cmd_prefix
, args
);
2728 /* Returns the alive thread named by INFERIOR_PID, or signals an error. */
2729 static struct proc
*
2732 struct inf
*inf
= cur_inf ();
2733 struct proc
*thread
= inf_tid_to_thread (inf
,
2734 ptid_get_tid (inferior_ptid
));
2736 error (_("No current thread."));
2740 /* Returns the current inferior, but signals an error if it has no task. */
2744 struct inf
*inf
= cur_inf ();
2747 error (_("No current process."));
2753 set_task_pause_cmd (char *args
, int from_tty
)
2755 struct inf
*inf
= cur_inf ();
2756 int old_sc
= inf
->pause_sc
;
2758 inf
->pause_sc
= parse_bool_arg (args
, "set task pause");
2760 if (old_sc
== 0 && inf
->pause_sc
!= 0)
2761 /* If the task is currently unsuspended, immediately suspend it,
2762 otherwise wait until the next time it gets control. */
2767 show_task_pause_cmd (char *args
, int from_tty
)
2769 struct inf
*inf
= cur_inf ();
2771 check_empty (args
, "show task pause");
2772 printf_unfiltered ("The inferior task %s suspended while gdb has control.\n",
2774 ? (inf
->pause_sc
== 0 ? "isn't" : "is")
2775 : (inf
->pause_sc
== 0 ? "won't be" : "will be"));
2779 set_task_detach_sc_cmd (char *args
, int from_tty
)
2781 cur_inf ()->detach_sc
= parse_int_arg (args
,
2782 "set task detach-suspend-count");
2786 show_task_detach_sc_cmd (char *args
, int from_tty
)
2788 check_empty (args
, "show task detach-suspend-count");
2789 printf_unfiltered ("The inferior task will be left with a "
2790 "suspend count of %d when detaching.\n",
2791 cur_inf ()->detach_sc
);
2796 set_thread_default_pause_cmd (char *args
, int from_tty
)
2798 struct inf
*inf
= cur_inf ();
2800 inf
->default_thread_pause_sc
=
2801 parse_bool_arg (args
, "set thread default pause") ? 0 : 1;
2805 show_thread_default_pause_cmd (char *args
, int from_tty
)
2807 struct inf
*inf
= cur_inf ();
2808 int sc
= inf
->default_thread_pause_sc
;
2810 check_empty (args
, "show thread default pause");
2811 printf_unfiltered ("New threads %s suspended while gdb has control%s.\n",
2812 sc
? "are" : "aren't",
2813 !sc
&& inf
->pause_sc
? " (but the task is)" : "");
2817 set_thread_default_run_cmd (char *args
, int from_tty
)
2819 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 ();
2830 check_empty (args
, "show thread default run");
2831 printf_unfiltered ("New threads %s allowed to run.\n",
2832 inf
->default_thread_run_sc
== 0 ? "are" : "aren't");
2836 set_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2838 cur_inf ()->default_thread_detach_sc
=
2839 parse_int_arg (args
, "set thread default detach-suspend-count");
2843 show_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2845 check_empty (args
, "show thread default detach-suspend-count");
2846 printf_unfiltered ("New threads will get a detach-suspend-count of %d.\n",
2847 cur_inf ()->default_thread_detach_sc
);
2851 /* Steal a send right called NAME in the inferior task, and make it PROC's
2852 saved exception port. */
2854 steal_exc_port (struct proc
*proc
, mach_port_t name
)
2858 mach_msg_type_name_t port_type
;
2860 if (!proc
|| !proc
->inf
->task
)
2861 error (_("No inferior task."));
2863 err
= mach_port_extract_right (proc
->inf
->task
->port
,
2864 name
, MACH_MSG_TYPE_COPY_SEND
,
2867 error (_("Couldn't extract send right %d from inferior: %s"),
2868 name
, safe_strerror (err
));
2870 if (proc
->saved_exc_port
)
2871 /* Get rid of our reference to the old one. */
2872 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
2874 proc
->saved_exc_port
= port
;
2876 if (!proc
->exc_port
)
2877 /* If PROC is a thread, we may not have set its exception port
2878 before. We can't use proc_steal_exc_port because it also sets
2881 proc
->exc_port
= proc
->inf
->event_port
;
2882 err
= proc_set_exception_port (proc
, proc
->exc_port
);
2883 error (_("Can't set exception port for %s: %s"),
2884 proc_string (proc
), safe_strerror (err
));
2889 set_task_exc_port_cmd (char *args
, int from_tty
)
2891 struct inf
*inf
= cur_inf ();
2894 error (_("No argument to \"set task exception-port\" command."));
2895 steal_exc_port (inf
->task
, parse_and_eval_address (args
));
2899 set_stopped_cmd (char *args
, int from_tty
)
2901 cur_inf ()->stopped
= _parse_bool_arg (args
, "yes", "no", "set stopped");
2905 show_stopped_cmd (char *args
, int from_tty
)
2907 struct inf
*inf
= active_inf ();
2909 check_empty (args
, "show stopped");
2910 printf_unfiltered ("The inferior process %s stopped.\n",
2911 inf
->stopped
? "is" : "isn't");
2915 set_sig_thread_cmd (char *args
, int from_tty
)
2917 struct inf
*inf
= cur_inf ();
2919 if (!args
|| (!isdigit (*args
) && strcmp (args
, "none") != 0))
2920 error (_("Illegal argument to \"set signal-thread\" command.\n"
2921 "Should be an integer thread ID, or `none'."));
2923 if (strcmp (args
, "none") == 0)
2924 inf
->signal_thread
= 0;
2927 int tid
= ptid_get_tid (thread_id_to_pid (atoi (args
)));
2930 error (_("Thread ID %s not known. "
2931 "Use the \"info threads\" command to\n"
2932 "see the IDs of currently known threads."), args
);
2933 inf
->signal_thread
= inf_tid_to_thread (inf
, tid
);
2938 show_sig_thread_cmd (char *args
, int from_tty
)
2940 struct inf
*inf
= active_inf ();
2942 check_empty (args
, "show signal-thread");
2943 if (inf
->signal_thread
)
2944 printf_unfiltered ("The signal thread is %s.\n",
2945 proc_string (inf
->signal_thread
));
2947 printf_unfiltered ("There is no signal thread.\n");
2952 set_signals_cmd (char *args
, int from_tty
)
2954 struct inf
*inf
= cur_inf ();
2956 inf
->want_signals
= parse_bool_arg (args
, "set signals");
2958 if (inf
->task
&& inf
->want_signals
!= inf
->traced
)
2959 /* Make this take effect immediately in a running process. */
2960 inf_set_traced (inf
, inf
->want_signals
);
2964 show_signals_cmd (char *args
, int from_tty
)
2966 struct inf
*inf
= cur_inf ();
2968 check_empty (args
, "show signals");
2969 printf_unfiltered ("The inferior process's signals %s intercepted.\n",
2971 ? (inf
->traced
? "are" : "aren't")
2972 : (inf
->want_signals
? "will be" : "won't be"));
2976 set_exceptions_cmd (char *args
, int from_tty
)
2978 struct inf
*inf
= cur_inf ();
2979 int val
= parse_bool_arg (args
, "set exceptions");
2981 if (inf
->task
&& inf
->want_exceptions
!= val
)
2982 /* Make this take effect immediately in a running process. */
2985 inf
->want_exceptions
= val
;
2989 show_exceptions_cmd (char *args
, int from_tty
)
2991 struct inf
*inf
= cur_inf ();
2993 check_empty (args
, "show exceptions");
2994 printf_unfiltered ("Exceptions in the inferior %s trapped.\n",
2996 ? (inf
->want_exceptions
? "are" : "aren't")
2997 : (inf
->want_exceptions
? "will be" : "won't be"));
3002 set_task_cmd (char *args
, int from_tty
)
3004 printf_unfiltered ("\"set task\" must be followed by the name"
3005 " of a task property.\n");
3009 show_task_cmd (char *args
, int from_tty
)
3011 struct inf
*inf
= cur_inf ();
3013 check_empty (args
, "show task");
3015 show_signals_cmd (0, from_tty
);
3016 show_exceptions_cmd (0, from_tty
);
3017 show_task_pause_cmd (0, from_tty
);
3019 if (inf
->pause_sc
== 0)
3020 show_thread_default_pause_cmd (0, from_tty
);
3021 show_thread_default_run_cmd (0, from_tty
);
3025 show_stopped_cmd (0, from_tty
);
3026 show_sig_thread_cmd (0, from_tty
);
3029 if (inf
->detach_sc
!= 0)
3030 show_task_detach_sc_cmd (0, from_tty
);
3031 if (inf
->default_thread_detach_sc
!= 0)
3032 show_thread_default_detach_sc_cmd (0, from_tty
);
3037 set_noninvasive_cmd (char *args
, int from_tty
)
3039 /* Invert the sense of the arg for each component. */
3040 char *inv_args
= parse_bool_arg (args
, "set noninvasive") ? "off" : "on";
3042 set_task_pause_cmd (inv_args
, from_tty
);
3043 set_signals_cmd (inv_args
, from_tty
);
3044 set_exceptions_cmd (inv_args
, from_tty
);
3049 info_port_rights (char *args
, mach_port_type_t only
)
3051 struct inf
*inf
= active_inf ();
3052 struct value
*vmark
= value_mark ();
3055 /* Explicit list of port rights. */
3059 struct value
*val
= parse_to_comma_and_eval (&args
);
3060 long right
= value_as_long (val
);
3062 print_port_info (right
, 0, inf
->task
->port
, PORTINFO_DETAILS
,
3066 error (_("%ld: %s."), right
, safe_strerror (err
));
3070 /* Print all of them. */
3073 print_task_ports_info (inf
->task
->port
, only
, PORTINFO_DETAILS
,
3076 error (_("%s."), safe_strerror (err
));
3079 value_free_to_mark (vmark
);
3083 info_send_rights_cmd (char *args
, int from_tty
)
3085 info_port_rights (args
, MACH_PORT_TYPE_SEND
);
3089 info_recv_rights_cmd (char *args
, int from_tty
)
3091 info_port_rights (args
, MACH_PORT_TYPE_RECEIVE
);
3095 info_port_sets_cmd (char *args
, int from_tty
)
3097 info_port_rights (args
, MACH_PORT_TYPE_PORT_SET
);
3101 info_dead_names_cmd (char *args
, int from_tty
)
3103 info_port_rights (args
, MACH_PORT_TYPE_DEAD_NAME
);
3107 info_port_rights_cmd (char *args
, int from_tty
)
3109 info_port_rights (args
, ~0);
3114 add_task_commands (void)
3116 add_cmd ("pause", class_run
, set_thread_default_pause_cmd
, _("\
3117 Set whether the new threads are suspended while gdb has control.\n\
3118 This property normally has no effect because the whole task is\n\
3119 suspended, however, that may be disabled with \"set task pause off\".\n\
3120 The default value is \"off\"."),
3121 &set_thread_default_cmd_list
);
3122 add_cmd ("pause", no_class
, show_thread_default_pause_cmd
, _("\
3123 Show whether new threads are suspended while gdb has control."),
3124 &show_thread_default_cmd_list
);
3126 add_cmd ("run", class_run
, set_thread_default_run_cmd
, _("\
3127 Set whether new threads are allowed to run (once gdb has noticed them)."),
3128 &set_thread_default_cmd_list
);
3129 add_cmd ("run", no_class
, show_thread_default_run_cmd
, _("\
3130 Show whether new threads are allowed to run (once gdb has noticed them)."),
3131 &show_thread_default_cmd_list
);
3133 add_cmd ("detach-suspend-count", class_run
, set_thread_default_detach_sc_cmd
,
3134 _("Set the default detach-suspend-count value for new threads."),
3135 &set_thread_default_cmd_list
);
3136 add_cmd ("detach-suspend-count", no_class
, show_thread_default_detach_sc_cmd
,
3137 _("Show the default detach-suspend-count value for new threads."),
3138 &show_thread_default_cmd_list
);
3140 add_cmd ("signals", class_run
, set_signals_cmd
, _("\
3141 Set whether the inferior process's signals will be intercepted.\n\
3142 Mach exceptions (such as breakpoint traps) are not affected."),
3144 add_alias_cmd ("sigs", "signals", class_run
, 1, &setlist
);
3145 add_cmd ("signals", no_class
, show_signals_cmd
, _("\
3146 Show whether the inferior process's signals will be intercepted."),
3148 add_alias_cmd ("sigs", "signals", no_class
, 1, &showlist
);
3150 add_cmd ("signal-thread", class_run
, set_sig_thread_cmd
, _("\
3151 Set the thread that gdb thinks is the libc signal thread.\n\
3152 This thread is run when delivering a signal to a non-stopped process."),
3154 add_alias_cmd ("sigthread", "signal-thread", class_run
, 1, &setlist
);
3155 add_cmd ("signal-thread", no_class
, show_sig_thread_cmd
, _("\
3156 Set the thread that gdb thinks is the libc signal thread."),
3158 add_alias_cmd ("sigthread", "signal-thread", no_class
, 1, &showlist
);
3160 add_cmd ("stopped", class_run
, set_stopped_cmd
, _("\
3161 Set whether gdb thinks the inferior process is stopped as with SIGSTOP.\n\
3162 Stopped process will be continued by sending them a signal."),
3164 add_cmd ("stopped", no_class
, show_stopped_cmd
, _("\
3165 Show whether gdb thinks the inferior process is stopped as with SIGSTOP."),
3168 add_cmd ("exceptions", class_run
, set_exceptions_cmd
, _("\
3169 Set whether exceptions in the inferior process will be trapped.\n\
3170 When exceptions are turned off, neither breakpoints nor single-stepping\n\
3173 /* Allow `set exc' despite conflict with `set exception-port'. */
3174 add_alias_cmd ("exc", "exceptions", class_run
, 1, &setlist
);
3175 add_cmd ("exceptions", no_class
, show_exceptions_cmd
, _("\
3176 Show whether exceptions in the inferior process will be trapped."),
3179 add_prefix_cmd ("task", no_class
, set_task_cmd
,
3180 _("Command prefix for setting task attributes."),
3181 &set_task_cmd_list
, "set task ", 0, &setlist
);
3182 add_prefix_cmd ("task", no_class
, show_task_cmd
,
3183 _("Command prefix for showing task attributes."),
3184 &show_task_cmd_list
, "show task ", 0, &showlist
);
3186 add_cmd ("pause", class_run
, set_task_pause_cmd
, _("\
3187 Set whether the task is suspended while gdb has control.\n\
3188 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3189 until the next time the program is continued.\n\
3190 When setting this to \"off\", \"set thread default pause on\" can be\n\
3191 used to pause individual threads by default instead."),
3192 &set_task_cmd_list
);
3193 add_cmd ("pause", no_class
, show_task_pause_cmd
,
3194 _("Show whether the task is suspended while gdb has control."),
3195 &show_task_cmd_list
);
3197 add_cmd ("detach-suspend-count", class_run
, set_task_detach_sc_cmd
,
3198 _("Set the suspend count will leave on the thread when detaching."),
3199 &set_task_cmd_list
);
3200 add_cmd ("detach-suspend-count", no_class
, show_task_detach_sc_cmd
,
3201 _("Show the suspend count will leave "
3202 "on the thread when detaching."),
3203 &show_task_cmd_list
);
3205 add_cmd ("exception-port", no_class
, set_task_exc_port_cmd
, _("\
3206 Set the task exception port to which we forward exceptions.\n\
3207 The argument should be the value of the send right in the task."),
3208 &set_task_cmd_list
);
3209 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_task_cmd_list
);
3210 add_alias_cmd ("exc-port", "exception-port", no_class
, 1,
3211 &set_task_cmd_list
);
3213 /* A convenient way of turning on all options require to noninvasively
3214 debug running tasks. */
3215 add_cmd ("noninvasive", no_class
, set_noninvasive_cmd
, _("\
3216 Set task options so that we interfere as little as possible.\n\
3217 This is the same as setting `task pause', `exceptions', and\n\
3218 `signals' to the opposite value."),
3221 /* Commands to show information about the task's ports. */
3222 add_cmd ("send-rights", class_info
, info_send_rights_cmd
,
3223 _("Show information about the task's send rights"),
3225 add_cmd ("receive-rights", class_info
, info_recv_rights_cmd
,
3226 _("Show information about the task's receive rights"),
3228 add_cmd ("port-rights", class_info
, info_port_rights_cmd
,
3229 _("Show information about the task's port rights"),
3231 add_cmd ("port-sets", class_info
, info_port_sets_cmd
,
3232 _("Show information about the task's port sets"),
3234 add_cmd ("dead-names", class_info
, info_dead_names_cmd
,
3235 _("Show information about the task's dead names"),
3237 add_info_alias ("ports", "port-rights", 1);
3238 add_info_alias ("port", "port-rights", 1);
3239 add_info_alias ("psets", "port-sets", 1);
3244 set_thread_pause_cmd (char *args
, int from_tty
)
3246 struct proc
*thread
= cur_thread ();
3247 int old_sc
= thread
->pause_sc
;
3249 thread
->pause_sc
= parse_bool_arg (args
, "set thread pause");
3250 if (old_sc
== 0 && thread
->pause_sc
!= 0 && thread
->inf
->pause_sc
== 0)
3251 /* If the task is currently unsuspended, immediately suspend it,
3252 otherwise wait until the next time it gets control. */
3253 inf_suspend (thread
->inf
);
3257 show_thread_pause_cmd (char *args
, int from_tty
)
3259 struct proc
*thread
= cur_thread ();
3260 int sc
= thread
->pause_sc
;
3262 check_empty (args
, "show task pause");
3263 printf_unfiltered ("Thread %s %s suspended while gdb has control%s.\n",
3264 proc_string (thread
),
3265 sc
? "is" : "isn't",
3266 !sc
&& thread
->inf
->pause_sc
? " (but the task is)" : "");
3270 set_thread_run_cmd (char *args
, int from_tty
)
3272 struct proc
*thread
= cur_thread ();
3274 thread
->run_sc
= parse_bool_arg (args
, "set thread run") ? 0 : 1;
3278 show_thread_run_cmd (char *args
, int from_tty
)
3280 struct proc
*thread
= cur_thread ();
3282 check_empty (args
, "show thread run");
3283 printf_unfiltered ("Thread %s %s allowed to run.",
3284 proc_string (thread
),
3285 thread
->run_sc
== 0 ? "is" : "isn't");
3289 set_thread_detach_sc_cmd (char *args
, int from_tty
)
3291 cur_thread ()->detach_sc
= parse_int_arg (args
,
3292 "set thread detach-suspend-count");
3296 show_thread_detach_sc_cmd (char *args
, int from_tty
)
3298 struct proc
*thread
= cur_thread ();
3300 check_empty (args
, "show thread detach-suspend-count");
3301 printf_unfiltered ("Thread %s will be left with a suspend count"
3302 " of %d when detaching.\n",
3303 proc_string (thread
),
3308 set_thread_exc_port_cmd (char *args
, int from_tty
)
3310 struct proc
*thread
= cur_thread ();
3313 error (_("No argument to \"set thread exception-port\" command."));
3314 steal_exc_port (thread
, parse_and_eval_address (args
));
3319 show_thread_cmd (char *args
, int from_tty
)
3321 struct proc
*thread
= cur_thread ();
3323 check_empty (args
, "show thread");
3324 show_thread_run_cmd (0, from_tty
);
3325 show_thread_pause_cmd (0, from_tty
);
3326 if (thread
->detach_sc
!= 0)
3327 show_thread_detach_sc_cmd (0, from_tty
);
3332 thread_takeover_sc_cmd (char *args
, int from_tty
)
3334 struct proc
*thread
= cur_thread ();
3336 thread_basic_info_data_t _info
;
3337 thread_basic_info_t info
= &_info
;
3338 mach_msg_type_number_t info_len
= THREAD_BASIC_INFO_COUNT
;
3340 thread_info (thread
->port
, THREAD_BASIC_INFO
, (int *) &info
, &info_len
);
3342 error (("%s."), safe_strerror (err
));
3343 thread
->sc
= info
->suspend_count
;
3345 printf_unfiltered ("Suspend count was %d.\n", thread
->sc
);
3347 vm_deallocate (mach_task_self (), (vm_address_t
) info
,
3348 info_len
* sizeof (int));
3353 add_thread_commands (void)
3355 add_prefix_cmd ("thread", no_class
, set_thread_cmd
,
3356 _("Command prefix for setting thread properties."),
3357 &set_thread_cmd_list
, "set thread ", 0, &setlist
);
3358 add_prefix_cmd ("default", no_class
, show_thread_cmd
,
3359 _("Command prefix for setting default thread properties."),
3360 &set_thread_default_cmd_list
, "set thread default ", 0,
3361 &set_thread_cmd_list
);
3362 add_prefix_cmd ("thread", no_class
, set_thread_default_cmd
,
3363 _("Command prefix for showing thread properties."),
3364 &show_thread_cmd_list
, "show thread ", 0, &showlist
);
3365 add_prefix_cmd ("default", no_class
, show_thread_default_cmd
,
3366 _("Command prefix for showing default thread properties."),
3367 &show_thread_default_cmd_list
, "show thread default ", 0,
3368 &show_thread_cmd_list
);
3370 add_cmd ("pause", class_run
, set_thread_pause_cmd
, _("\
3371 Set whether the current thread is suspended while gdb has control.\n\
3372 A value of \"on\" takes effect immediately, otherwise nothing happens\n\
3373 until the next time the program is continued. This property normally\n\
3374 has no effect because the whole task is suspended, however, that may\n\
3375 be disabled with \"set task pause off\".\n\
3376 The default value is \"off\"."),
3377 &set_thread_cmd_list
);
3378 add_cmd ("pause", no_class
, show_thread_pause_cmd
, _("\
3379 Show whether the current thread is suspended while gdb has control."),
3380 &show_thread_cmd_list
);
3382 add_cmd ("run", class_run
, set_thread_run_cmd
,
3383 _("Set whether the current thread is allowed to run."),
3384 &set_thread_cmd_list
);
3385 add_cmd ("run", no_class
, show_thread_run_cmd
,
3386 _("Show whether the current thread is allowed to run."),
3387 &show_thread_cmd_list
);
3389 add_cmd ("detach-suspend-count", class_run
, set_thread_detach_sc_cmd
, _("\
3390 Set the suspend count will leave on the thread when detaching.\n\
3391 Note that this is relative to suspend count when gdb noticed the thread;\n\
3392 use the `thread takeover-suspend-count' to force it to an absolute value."),
3393 &set_thread_cmd_list
);
3394 add_cmd ("detach-suspend-count", no_class
, show_thread_detach_sc_cmd
, _("\
3395 Show the suspend count will leave on the thread when detaching.\n\
3396 Note that this is relative to suspend count when gdb noticed the thread;\n\
3397 use the `thread takeover-suspend-count' to force it to an absolute value."),
3398 &show_thread_cmd_list
);
3400 add_cmd ("exception-port", no_class
, set_thread_exc_port_cmd
, _("\
3401 Set the thread exception port to which we forward exceptions.\n\
3402 This overrides the task exception port.\n\
3403 The argument should be the value of the send right in the task."),
3404 &set_thread_cmd_list
);
3405 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3406 add_alias_cmd ("exc-port", "exception-port", no_class
, 1,
3407 &set_thread_cmd_list
);
3409 add_cmd ("takeover-suspend-count", no_class
, thread_takeover_sc_cmd
, _("\
3410 Force the threads absolute suspend-count to be gdb's.\n\
3411 Prior to giving this command, gdb's thread suspend-counts are relative\n\
3412 to the thread's initial suspend-count when gdb notices the threads."),
3418 _initialize_gnu_nat (void)
3420 proc_server
= getproc ();
3422 add_task_commands ();
3423 add_thread_commands ();
3424 add_setshow_boolean_cmd ("gnu-nat", class_maintenance
,
3426 _("Set debugging output for the gnu backend."),
3427 _("Show debugging output for the gnu backend."),
3435 #ifdef FLUSH_INFERIOR_CACHE
3437 /* When over-writing code on some machines the I-Cache must be flushed
3438 explicitly, because it is not kept coherent by the lazy hardware.
3439 This definitely includes breakpoints, for instance, or else we
3440 end up looping in mysterious Bpt traps. */
3443 flush_inferior_icache (CORE_ADDR pc
, int amount
)
3445 vm_machine_attribute_val_t flush
= MATTR_VAL_ICACHE_FLUSH
;
3448 ret
= vm_machine_attribute (gnu_current_inf
->task
->port
,
3453 if (ret
!= KERN_SUCCESS
)
3454 warning (_("Error flushing inferior's cache : %s"), safe_strerror (ret
));
3456 #endif /* FLUSH_INFERIOR_CACHE */