1 /* Interface GDB to the GNU Hurd
2 Copyright (C) 1992, 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 Written by Miles Bader <miles@gnu.ai.mit.edu>
8 Some code and ideas from m3-nat.c by Jukka Virtanen <jtv@hut.fi>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <sys/ptrace.h>
34 /* We include this because we don't need the access macros and they conflict
35 with gdb's definitions (ick). This is very non standard! */
36 #define _SYS_WAIT_H /* Inhibit warning from <bits/waitflags.h>. */
37 #include <bits/waitflags.h>
40 #include <mach/message.h>
41 #include <mach/notify.h>
42 #include <mach_error.h>
43 #include <mach/exception.h>
44 #include <mach/vm_attributes.h>
46 #include <hurd/process.h>
47 #include <hurd/process_request.h>
49 #include <hurd/msg_request.h>
50 #include <hurd/signal.h>
51 #include <hurd/interrupt.h>
52 #include <hurd/sigpreempt.h>
68 #include "exc_request_S.h"
70 #include "process_reply_S.h"
71 #include "msg_reply_S.h"
72 #include "exc_request_U.h"
75 static process_t proc_server
= MACH_PORT_NULL
;
77 /* If we've sent a proc_wait_request to the proc server, the pid of the
78 process we asked about. We can only ever have one outstanding. */
79 int proc_wait_pid
= 0;
81 /* The number of wait requests we've sent, and expect replies from. */
82 int proc_waits_pending
= 0;
84 int gnu_debug_flag
= 0;
88 extern struct target_ops gnu_ops
;
90 int inf_update_procs (struct inf
*inf
);
91 struct inf
*make_inf ();
92 void inf_clear_wait (struct inf
*inf
);
93 void inf_cleanup (struct inf
*inf
);
94 void inf_startup (struct inf
*inf
, int pid
);
95 int inf_update_suspends (struct inf
*inf
);
96 void inf_set_pid (struct inf
*inf
, pid_t pid
);
97 void inf_validate_procs (struct inf
*inf
);
98 void inf_steal_exc_ports (struct inf
*inf
);
99 void inf_restore_exc_ports (struct inf
*inf
);
100 struct proc
*inf_tid_to_proc (struct inf
*inf
, int tid
);
101 inline void inf_set_threads_resume_sc (struct inf
*inf
,
102 struct proc
*run_thread
,
104 inline int inf_set_threads_resume_sc_for_signal_thread (struct inf
*inf
);
105 inline void inf_suspend (struct inf
*inf
);
106 inline 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 thread_state_t
proc_get_state (struct proc
*proc
, int force
);
119 struct proc
*make_proc (struct inf
*inf
, mach_port_t port
, int tid
);
120 struct proc
*_proc_free (struct proc
*proc
);
121 int proc_update_sc (struct proc
*proc
);
122 error_t
proc_get_exception_port (struct proc
*proc
, mach_port_t
*port
);
123 error_t
proc_set_exception_port (struct proc
*proc
, mach_port_t port
);
124 static mach_port_t
_proc_get_exc_port (struct proc
*proc
);
125 void proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
);
126 void proc_restore_exc_port (struct proc
*proc
);
127 int proc_trace (struct proc
*proc
, int set
);
128 char *proc_string (struct proc
*proc
);
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); \
150 #define MIG_SERVER_DIED EMIG_SERVER_DIED /* XXX */
152 /* The state passed by an exception message. */
155 int exception
; /* The exception code */
157 mach_port_t handler
; /* The real exception port to handle this. */
158 mach_port_t reply
; /* The reply port from the exception call. */
161 /* The results of the last wait an inf did. */
164 struct target_waitstatus status
; /* The status returned to gdb. */
165 struct exc_state exc
; /* The exception that caused us to return. */
166 struct proc
*thread
; /* The thread in question. */
167 int suppress
; /* Something trivial happened. */
170 /* The state of an inferior. */
173 /* Fields describing the current inferior. */
175 struct proc
*task
; /* The mach task. */
176 struct proc
*threads
; /* A linked list of all threads in TASK. */
178 /* True if THREADS needn't be validated by querying the task. We assume that
179 we and the task in question are the only ones frobbing the thread list,
180 so as long as we don't let any code run, we don't have to worry about
182 int threads_up_to_date
;
184 pid_t pid
; /* The real system PID. */
186 struct inf_wait wait
; /* What to return from target_wait. */
188 /* One thread proc in INF may be in `single-stepping mode'. This is it. */
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. */
248 int __proc_pid (struct proc
*proc
)
250 return proc
->inf
->pid
;
253 /* Update PROC's real suspend count to match it's desired one. Returns true
254 if we think PROC is now in a runnable state. */
256 proc_update_sc (struct proc
*proc
)
260 int delta
= proc
->sc
- proc
->cur_sc
;
263 proc_debug (proc
, "sc: %d --> %d", proc
->cur_sc
, proc
->sc
);
265 if (proc
->sc
== 0 && proc
->state_changed
)
266 /* Since PROC may start running, we must write back any state changes. */
268 assert (proc_is_thread (proc
));
269 proc_debug (proc
, "storing back changed thread state");
270 err
= thread_set_state (proc
->port
, THREAD_STATE_FLAVOR
,
271 (thread_state_t
)&proc
->state
, THREAD_STATE_SIZE
);
273 proc
->state_changed
= 0;
277 while (delta
-- > 0 && !err
)
278 if (proc_is_task (proc
))
279 err
= task_suspend (proc
->port
);
281 err
= thread_suspend (proc
->port
);
283 while (delta
++ < 0 && !err
)
284 if (proc_is_task (proc
))
285 err
= task_resume (proc
->port
);
287 err
= thread_resume (proc
->port
);
290 proc
->cur_sc
= proc
->sc
;
292 /* If we got an error, then the task/thread has disappeared. */
293 running
= !err
&& proc
->sc
== 0;
295 proc_debug (proc
, "is %s", err
? "dead" : running
? "running" : "suspended");
297 proc_debug (proc
, "err = %s", strerror (err
));
302 proc
->state_valid
= proc
->state_changed
= 0;
303 proc
->fetched_regs
= 0;
309 /* Thread_abort is called on PROC if needed. PROC must be a thread proc.
310 If PROC is deemed `precious', then nothing is done unless FORCE is true.
311 In particular, a thread is precious if it's running (in which case forcing
312 it includes suspending it first), or if it has an exception pending. */
314 proc_abort (struct proc
*proc
, int force
)
316 assert (proc_is_thread (proc
));
320 struct inf
*inf
= proc
->inf
;
321 int running
= (proc
->cur_sc
== 0 && inf
->task
->cur_sc
== 0);
323 if (running
&& force
)
326 inf_update_suspends (proc
->inf
);
328 warning ("Stopped %s.", proc_string (proc
));
330 else if (proc
== inf
->wait
.thread
&& inf
->wait
.exc
.reply
&& !force
)
331 /* An exception is pending on PROC, which don't mess with. */
335 /* We only abort the thread if it's not actually running. */
337 thread_abort (proc
->port
);
338 proc_debug (proc
, "aborted");
342 proc_debug (proc
, "not aborting");
346 /* Make sure that the state field in PROC is up to date, and return a pointer
347 to it, or 0 if something is wrong. If WILL_MODIFY is true, makes sure
348 that the thread is stopped and aborted first, and sets the state_changed
349 field in PROC to true. */
351 proc_get_state (struct proc
*proc
, int will_modify
)
353 int was_aborted
= proc
->aborted
;
355 proc_debug (proc
, "updating state info%s",
356 will_modify
? " (with intention to modify)" : "");
358 proc_abort (proc
, will_modify
);
360 if (! was_aborted
&& proc
->aborted
)
361 /* PROC's state may have changed since we last fetched it. */
362 proc
->state_valid
= 0;
364 if (! proc
->state_valid
)
366 mach_msg_type_number_t state_size
= THREAD_STATE_SIZE
;
368 thread_get_state (proc
->port
, THREAD_STATE_FLAVOR
,
369 (thread_state_t
)&proc
->state
, &state_size
);
370 proc_debug (proc
, "getting thread state");
371 proc
->state_valid
= !err
;
374 if (proc
->state_valid
)
377 proc
->state_changed
= 1;
378 return (thread_state_t
)&proc
->state
;
384 /* Set PORT to PROC's exception port. */
386 proc_get_exception_port (struct proc
*proc
, mach_port_t
*port
)
388 if (proc_is_task (proc
))
389 return task_get_exception_port (proc
->port
, port
);
391 return thread_get_exception_port (proc
->port
, port
);
394 /* Set PROC's exception port to PORT. */
396 proc_set_exception_port (struct proc
*proc
, mach_port_t port
)
398 proc_debug (proc
, "setting exception port: %d", port
);
399 if (proc_is_task (proc
))
400 return task_set_exception_port (proc
->port
, port
);
402 return thread_set_exception_port (proc
->port
, port
);
405 /* Get PROC's exception port, cleaning up a bit if proc has died. */
407 _proc_get_exc_port (struct proc
*proc
)
409 mach_port_t exc_port
;
410 error_t err
= proc_get_exception_port (proc
, &exc_port
);
413 /* PROC must be dead. */
416 mach_port_deallocate (mach_task_self (), proc
->exc_port
);
417 proc
->exc_port
= MACH_PORT_NULL
;
418 if (proc
->saved_exc_port
)
419 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
420 proc
->saved_exc_port
= MACH_PORT_NULL
;
426 /* Replace PROC's exception port with EXC_PORT, unless it's already been
427 done. Stash away any existing exception port so we can restore it later. */
429 proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
)
431 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
437 proc_debug (proc
, "inserting exception port: %d", exc_port
);
439 if (cur_exc_port
!= exc_port
)
440 /* Put in our exception port. */
441 err
= proc_set_exception_port (proc
, exc_port
);
443 if (err
|| cur_exc_port
== proc
->exc_port
)
444 /* We previously set the exception port, and it's still set. So we
445 just keep the old saved port which is what the proc set. */
448 mach_port_deallocate (mach_task_self (), cur_exc_port
);
451 /* Keep a copy of PROC's old exception port so it can be restored. */
453 if (proc
->saved_exc_port
)
454 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
455 proc
->saved_exc_port
= cur_exc_port
;
458 proc_debug (proc
, "saved exception port: %d", proc
->saved_exc_port
);
461 proc
->exc_port
= exc_port
;
463 warning ("Error setting exception port for %s: %s",
464 proc_string (proc
), strerror (err
));
468 /* If we previously replaced PROC's exception port, put back what we
469 found there at the time, unless *our* exception port has since been
470 overwritten, in which case who knows what's going on. */
472 proc_restore_exc_port (struct proc
*proc
)
474 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
480 proc_debug (proc
, "restoring real exception port");
482 if (proc
->exc_port
== cur_exc_port
)
483 /* Our's is still there. */
484 err
= proc_set_exception_port (proc
, proc
->saved_exc_port
);
486 if (proc
->saved_exc_port
)
487 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
488 proc
->saved_exc_port
= MACH_PORT_NULL
;
491 proc
->exc_port
= MACH_PORT_NULL
;
493 warning ("Error setting exception port for %s: %s",
494 proc_string (proc
), strerror (err
));
498 /* Turns hardware tracing in PROC on or off when SET is true or false,
499 respectively. Returns true on success. */
501 proc_trace (struct proc
*proc
, int set
)
503 thread_state_t state
= proc_get_state (proc
, 1);
506 return 0; /* the thread must be dead. */
508 proc_debug (proc
, "tracing %s", set
? "on" : "off");
512 /* XXX We don't get the exception unless the thread has its own
513 exception port???? */
514 if (proc
->exc_port
== MACH_PORT_NULL
)
515 proc_steal_exc_port (proc
, proc
->inf
->event_port
);
516 THREAD_STATE_SET_TRACED (state
);
519 THREAD_STATE_CLEAR_TRACED (state
);
524 /* A variable from which to assign new TIDs. */
525 static int next_thread_id
= 1;
527 /* Returns a new proc structure with the given fields. Also adds a
528 notification for PORT becoming dead to be sent to INF's notify port. */
530 make_proc (struct inf
*inf
, mach_port_t port
, int tid
)
533 mach_port_t prev_port
= MACH_PORT_NULL
;
534 struct proc
*proc
= malloc (sizeof (struct proc
));
540 proc
->saved_exc_port
= MACH_PORT_NULL
;
541 proc
->exc_port
= MACH_PORT_NULL
;
546 /* Note that these are all the values for threads; the task simply uses the
547 corresponding field in INF directly. */
548 proc
->run_sc
= inf
->default_thread_run_sc
;
549 proc
->pause_sc
= inf
->default_thread_pause_sc
;
550 proc
->detach_sc
= inf
->default_thread_detach_sc
;
551 proc
->resume_sc
= proc
->run_sc
;
555 proc
->state_valid
= 0;
556 proc
->state_changed
= 0;
558 proc_debug (proc
, "is new");
560 /* Get notified when things die. */
562 mach_port_request_notification (mach_task_self(), port
,
563 MACH_NOTIFY_DEAD_NAME
, 1,
565 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
568 warning ("Couldn't request notification for port %d: %s",
569 port
, strerror (err
));
572 proc_debug (proc
, "notifications to: %d", inf
->event_port
);
573 if (prev_port
!= MACH_PORT_NULL
)
574 mach_port_deallocate (mach_task_self (), prev_port
);
577 if (inf
->want_exceptions
)
578 if (proc_is_task (proc
))
579 /* Make the task exception port point to us. */
580 proc_steal_exc_port (proc
, inf
->event_port
);
582 /* Just clear thread exception ports -- they default to the task one. */
583 proc_steal_exc_port (proc
, MACH_PORT_NULL
);
588 /* Frees PROC and any resources it uses, and returns the value of PROC's
591 _proc_free (struct proc
*proc
)
593 struct inf
*inf
= proc
->inf
;
594 struct proc
*next
= proc
->next
;
596 proc_debug (proc
, "freeing...");
598 if (proc
== inf
->step_thread
)
599 /* Turn off single stepping. */
600 inf_set_step_thread (inf
, 0);
601 if (proc
== inf
->wait
.thread
)
602 inf_clear_wait (inf
);
603 if (proc
== inf
->signal_thread
)
604 inf
->signal_thread
= 0;
606 if (proc
->port
!= MACH_PORT_NULL
)
608 if (proc
->exc_port
!= MACH_PORT_NULL
)
609 /* Restore the original exception port. */
610 proc_restore_exc_port (proc
);
611 if (proc
->cur_sc
!= 0)
612 /* Resume the thread/task. */
615 proc_update_sc (proc
);
617 mach_port_deallocate (mach_task_self (), proc
->port
);
624 struct inf
*make_inf ()
626 struct inf
*inf
= malloc (sizeof (struct inf
));
633 inf
->threads_up_to_date
= 0;
635 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
636 inf
->wait
.thread
= 0;
637 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
638 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
639 inf
->step_thread
= 0;
640 inf
->signal_thread
= 0;
641 inf
->event_port
= MACH_PORT_NULL
;
647 inf
->pending_execs
= 0;
650 inf
->default_thread_run_sc
= 0;
651 inf
->default_thread_pause_sc
= 0;
652 inf
->default_thread_detach_sc
= 0;
653 inf
->want_signals
= 1; /* By default */
654 inf
->want_exceptions
= 1; /* By default */
659 /* clear INF's target wait status. */
661 inf_clear_wait (struct inf
*inf
)
663 inf_debug (inf
, "clearing wait");
664 inf
->wait
.status
.kind
= TARGET_WAITKIND_SPURIOUS
;
665 inf
->wait
.thread
= 0;
666 inf
->wait
.suppress
= 0;
667 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
669 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.handler
);
670 inf
->wait
.exc
.handler
= MACH_PORT_NULL
;
672 if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
674 mach_port_deallocate (mach_task_self (), inf
->wait
.exc
.reply
);
675 inf
->wait
.exc
.reply
= MACH_PORT_NULL
;
680 inf_cleanup (struct inf
*inf
)
682 inf_debug (inf
, "cleanup");
684 inf_clear_wait (inf
);
686 inf_set_pid (inf
, -1);
693 inf
->pending_execs
= 0;
697 mach_port_destroy (mach_task_self (), inf
->event_port
);
698 inf
->event_port
= MACH_PORT_NULL
;
703 inf_startup (struct inf
*inf
, int pid
)
707 inf_debug (inf
, "startup: pid = %d", pid
);
711 /* Make the port on which we receive all events. */
712 err
= mach_port_allocate (mach_task_self (),
713 MACH_PORT_RIGHT_RECEIVE
, &inf
->event_port
);
715 error ("Error allocating event port: %s", strerror (err
));
717 /* Make a send right for it, so we can easily copy it for other people. */
718 mach_port_insert_right (mach_task_self (), inf
->event_port
,
719 inf
->event_port
, MACH_MSG_TYPE_MAKE_SEND
);
720 inf_set_pid (inf
, pid
);
723 /* close current process, if any, and attach INF to process PORT */
725 inf_set_pid (struct inf
*inf
, pid_t pid
)
728 struct proc
*task
= inf
->task
;
730 inf_debug (inf
, "setting pid: %d", pid
);
733 task_port
= MACH_PORT_NULL
;
736 error_t err
= proc_pid2task (proc_server
, pid
, &task_port
);
738 error ("Error getting task for pid %d: %s", pid
, strerror (err
));
741 inf_debug (inf
, "setting task: %d", task_port
);
744 task_suspend (task_port
);
746 if (task
&& task
->port
!= task_port
)
749 inf_validate_procs (inf
); /* Trash all the threads. */
750 _proc_free (task
); /* And the task. */
753 if (task_port
!= MACH_PORT_NULL
)
755 inf
->task
= make_proc (inf
, task_port
, PROC_TID_TASK
);
756 inf
->threads_up_to_date
= 0;
763 inf
->task
->sc
= inf
->task
->cur_sc
= 1; /* Reflect task_suspend above */
769 /* Validates INF's stopped, nomsg and traced field from the actual
770 proc server state. Note that the traced field is only updated from
771 the proc server state if we do not have a message port. If we do
772 have a message port we'd better look at the tracemask itself. */
774 inf_validate_procinfo (struct inf
*inf
)
777 mach_msg_type_number_t noise_len
= 0;
779 mach_msg_type_number_t pi_len
= 0;
782 proc_getprocinfo (proc_server
, inf
->pid
, &info_flags
,
783 (procinfo_t
*)&pi
, &pi_len
, &noise
, &noise_len
);
787 inf
->stopped
= !!(pi
->state
& PI_STOPPED
);
788 inf
->nomsg
= !!(pi
->state
& PI_NOMSG
);
790 inf
->traced
= !!(pi
->state
& PI_TRACED
);
791 vm_deallocate (mach_task_self (), (vm_address_t
)pi
, pi_len
);
793 vm_deallocate (mach_task_self (), (vm_address_t
)noise
, noise_len
);
797 /* Validates INF's task suspend count. If it's higher than we expect, verify
798 with the user before `stealing' the extra count. */
800 inf_validate_task_sc (struct inf
*inf
)
802 struct task_basic_info info
;
803 mach_msg_type_number_t info_len
= TASK_BASIC_INFO_COUNT
;
805 task_info (inf
->task
->port
, TASK_BASIC_INFO
, (task_info_t
)&info
, &info_len
);
808 inf
->task
->dead
= 1; /* oh well */
809 else if (inf
->task
->cur_sc
< info
.suspend_count
)
813 target_terminal_ours (); /* Allow I/O. */
815 !query ("Pid %d has an additional task suspend count of %d; clear it? ",
816 inf
->pid
, info
.suspend_count
- inf
->task
->cur_sc
);
817 target_terminal_inferior (); /* Give it back to the child. */
820 error ("Additional task suspend count left untouched.");
822 inf
->task
->cur_sc
= info
.suspend_count
;
826 /* Turns tracing for INF on or off, depending on ON, unless it already is.
827 If INF is running, the resume_sc count of INF's threads will be modified,
828 and the signal thread will briefly be run to change the trace state. */
830 inf_set_traced (struct inf
*inf
, int on
)
832 if (on
!= inf
->traced
)
833 if (inf
->task
&& !inf
->task
->dead
)
834 /* Make it take effect immediately. */
836 sigset_t mask
= on
? ~(sigset_t
)0 : 0;
838 INF_RESUME_MSGPORT_RPC (inf
, msg_set_init_int (msgport
, refport
,
839 INIT_TRACEMASK
, mask
));
843 warning ("Can't modify tracing state for pid %d: No signal thread",
848 warning ("Can't modify tracing state for pid %d: %s",
849 inf
->pid
, strerror (err
));
857 /* Makes all the real suspend count deltas of all the procs in INF match the
858 desired values. Careful to always do thread/task suspend counts in the
859 safe order. Returns true if at least one thread is thought to be running.*/
861 inf_update_suspends (struct inf
*inf
)
863 struct proc
*task
= inf
->task
;
864 /* We don't have to update INF->threads even though we're iterating over it
865 because we'll change a thread only if it already has an existing proc
868 inf_debug (inf
, "updating suspend counts");
873 int task_running
= (task
->sc
== 0), thread_running
= 0;
875 if (task
->sc
> task
->cur_sc
)
876 /* The task is becoming _more_ suspended; do before any threads. */
877 task_running
= proc_update_sc (task
);
879 if (inf
->pending_execs
)
880 /* When we're waiting for an exec, things may be happening behind our
881 back, so be conservative. */
884 /* Do all the thread suspend counts. */
885 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
886 thread_running
|= proc_update_sc (thread
);
888 if (task
->sc
!= task
->cur_sc
)
889 /* We didn't do the task first, because we wanted to wait for the
890 threads; do it now. */
891 task_running
= proc_update_sc (task
);
893 inf_debug (inf
, "%srunning...",
894 (thread_running
&& task_running
) ? "" : "not ");
896 inf
->running
= thread_running
&& task_running
;
898 /* Once any thread has executed some code, we can't depend on the
899 threads list any more. */
901 inf
->threads_up_to_date
= 0;
909 /* Converts a GDB pid to a struct proc. */
911 inf_tid_to_thread (struct inf
*inf
, int tid
)
913 struct proc
*thread
= inf
->threads
;
916 if (thread
->tid
== tid
)
919 thread
= thread
->next
;
923 /* Converts a thread port to a struct proc. */
925 inf_port_to_thread (struct inf
*inf
, mach_port_t port
)
927 struct proc
*thread
= inf
->threads
;
929 if (thread
->port
== port
)
932 thread
= thread
->next
;
936 /* Make INF's list of threads be consistent with reality of TASK. */
938 inf_validate_procs (struct inf
*inf
)
941 thread_array_t threads
;
942 unsigned num_threads
;
943 struct proc
*task
= inf
->task
;
945 /* If no threads are currently running, this function will guarantee that
946 things are up to date. The exception is if there are zero threads --
947 then it is almost certainly in an odd state, and probably some outside
948 agent will create threads. */
949 inf
->threads_up_to_date
= inf
->threads
? !inf
->running
: 0;
953 error_t err
= task_threads (task
->port
, &threads
, &num_threads
);
954 inf_debug (inf
, "fetching threads");
956 /* TASK must be dead. */
966 inf_debug (inf
, "no task");
970 unsigned search_start
= 0; /* Make things normally linear. */
971 /* Which thread in PROCS corresponds to each task thread, & the task. */
972 struct proc
*matched
[num_threads
+ 1];
973 /* The last thread in INF->threads, so we can add to the end. */
974 struct proc
*last
= 0;
975 /* The current thread we're considering. */
976 struct proc
*thread
= inf
->threads
;
978 bzero (matched
, sizeof (matched
));
984 for (i
= search_start
, left
= num_threads
; left
; i
++, left
--)
986 if (i
>= num_threads
)
987 i
-= num_threads
; /* I wrapped around. */
988 if (thread
->port
== threads
[i
])
989 /* We already know about this thread. */
993 thread
= thread
->next
;
1001 proc_debug (thread
, "died!");
1002 thread
->port
= MACH_PORT_NULL
;
1003 thread
= _proc_free (thread
); /* THREAD is dead. */
1004 (last
? last
->next
: inf
->threads
) = thread
;
1008 for (i
= 0; i
< num_threads
; i
++)
1010 /* Throw away the duplicate send right. */
1011 mach_port_deallocate (mach_task_self (), threads
[i
]);
1013 /* THREADS[I] is a thread we don't know about yet! */
1015 thread
= make_proc (inf
, threads
[i
], next_thread_id
++);
1016 (last
? last
->next
: inf
->threads
) = thread
;
1018 proc_debug (thread
, "new thread: %d", threads
[i
]);
1019 add_thread (thread
->tid
); /* Tell GDB's generic thread code. */
1022 vm_deallocate(mach_task_self(),
1023 (vm_address_t
)threads
, (num_threads
* sizeof(thread_t
)));
1027 /* Makes sure that INF's thread list is synced with the actual process. */
1029 inf_update_procs (struct inf
*inf
)
1033 if (! inf
->threads_up_to_date
)
1034 inf_validate_procs (inf
);
1038 /* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
1039 and others are set to their run_sc if RUN_OTHERS is true, and otherwise
1042 inf_set_threads_resume_sc (struct inf
*inf
,
1043 struct proc
*run_thread
, int run_others
)
1045 struct proc
*thread
;
1046 inf_update_procs (inf
);
1047 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1048 if (thread
== run_thread
)
1049 thread
->resume_sc
= 0;
1050 else if (run_others
)
1051 thread
->resume_sc
= thread
->run_sc
;
1053 thread
->resume_sc
= thread
->pause_sc
;
1056 /* Cause INF to continue execution immediately; individual threads may still
1057 be suspended (but their suspend counts will be updated). */
1059 inf_resume (struct inf
*inf
)
1061 struct proc
*thread
;
1063 inf_update_procs (inf
);
1065 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1066 thread
->sc
= thread
->resume_sc
;
1070 if (! inf
->pending_execs
)
1071 /* Try to make sure our task count is correct -- in the case where
1072 we're waiting for an exec though, things are too volatile, so just
1073 assume things will be reasonable (which they usually will be). */
1074 inf_validate_task_sc (inf
);
1078 inf_update_suspends (inf
);
1081 /* Cause INF to stop execution immediately; individual threads may still
1084 inf_suspend (struct inf
*inf
)
1086 struct proc
*thread
;
1088 inf_update_procs (inf
);
1090 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1091 thread
->sc
= thread
->pause_sc
;
1094 inf
->task
->sc
= inf
->pause_sc
;
1096 inf_update_suspends (inf
);
1099 /* INF has one thread PROC that is in single-stepping mode. This function
1100 changes it to be PROC, changing any old step_thread to be a normal one. A
1101 PROC of 0 clears any existing value. */
1103 inf_set_step_thread (struct inf
*inf
, struct proc
*thread
)
1105 assert (!thread
|| proc_is_thread (thread
));
1108 inf_debug (inf
, "setting step thread: %d/%d", inf
->pid
, thread
->tid
);
1110 inf_debug (inf
, "clearing step thread");
1112 if (inf
->step_thread
!= thread
)
1114 if (inf
->step_thread
&& inf
->step_thread
->port
!= MACH_PORT_NULL
)
1115 if (! proc_trace (inf
->step_thread
, 0))
1117 if (thread
&& proc_trace (thread
, 1))
1118 inf
->step_thread
= thread
;
1120 inf
->step_thread
= 0;
1124 /* Set up the thread resume_sc's so that only the signal thread is running
1125 (plus whatever other thread are set to always run). Returns true if we
1126 did so, or false if we can't find a signal thread. */
1128 inf_set_threads_resume_sc_for_signal_thread (struct inf
*inf
)
1130 if (inf
->signal_thread
)
1132 inf_set_threads_resume_sc (inf
, inf
->signal_thread
, 0);
1140 inf_update_signal_thread (struct inf
*inf
)
1142 /* XXX for now we assume that if there's a msgport, the 2nd thread is
1143 the signal thread. */
1144 inf
->signal_thread
= inf
->threads
? inf
->threads
->next
: 0;
1147 /* Detachs from INF's inferior task, letting it run once again... */
1149 inf_detach (struct inf
*inf
)
1151 struct proc
*task
= inf
->task
;
1153 inf_debug (inf
, "detaching...");
1155 inf_clear_wait (inf
);
1156 inf_set_step_thread (inf
, 0);
1160 struct proc
*thread
;
1162 inf_validate_procinfo (inf
);
1164 inf_set_traced (inf
, 0);
1170 inf_signal (inf
, TARGET_SIGNAL_0
);
1173 proc_restore_exc_port (task
);
1174 task
->sc
= inf
->detach_sc
;
1176 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1178 proc_restore_exc_port (thread
);
1179 thread
->sc
= thread
->detach_sc
;
1182 inf_update_suspends (inf
);
1188 /* Attaches INF to the process with process id PID, returning it in a suspended
1189 state suitable for debugging. */
1191 inf_attach (struct inf
*inf
, int pid
)
1193 inf_debug (inf
, "attaching: %d", pid
);
1198 inf_startup (inf
, pid
);
1201 /* Makes sure that we've got our exception ports entrenched in the process. */
1202 void inf_steal_exc_ports (struct inf
*inf
)
1204 struct proc
*thread
;
1206 inf_debug (inf
, "stealing exception ports");
1208 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1210 proc_steal_exc_port (inf
->task
, inf
->event_port
);
1211 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1212 proc_steal_exc_port (thread
, MACH_PORT_NULL
);
1215 /* Makes sure the process has its own exception ports. */
1216 void inf_restore_exc_ports (struct inf
*inf
)
1218 struct proc
*thread
;
1220 inf_debug (inf
, "restoring exception ports");
1222 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1224 proc_restore_exc_port (inf
->task
);
1225 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1226 proc_restore_exc_port (thread
);
1229 /* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
1230 signal 0, will continue it. INF is assumed to be in a paused state, and
1231 the resume_sc's of INF's threads may be affected. */
1233 inf_signal (struct inf
*inf
, enum target_signal sig
)
1236 int host_sig
= target_signal_to_host (sig
);
1238 #define NAME target_signal_to_name (sig)
1240 if (host_sig
>= _NSIG
)
1241 /* A mach exception. Exceptions are encoded in the signal space by
1242 putting them after _NSIG; this assumes they're positive (and not
1243 extremely large)! */
1245 struct inf_wait
*w
= &inf
->wait
;
1246 if (w
->status
.kind
== TARGET_WAITKIND_STOPPED
1247 && w
->status
.value
.sig
== sig
1248 && w
->thread
&& !w
->thread
->aborted
)
1249 /* We're passing through the last exception we received. This is
1250 kind of bogus, because exceptions are per-thread whereas gdb
1251 treats signals as per-process. We just forward the exception to
1252 the correct handler, even it's not for the same thread as TID --
1253 i.e., we pretend it's global. */
1255 struct exc_state
*e
= &w
->exc
;
1256 inf_debug (inf
, "passing through exception:"
1257 " task = %d, thread = %d, exc = %d"
1258 ", code = %d, subcode = %d",
1259 w
->thread
->port
, inf
->task
->port
,
1260 e
->exception
, e
->code
, e
->subcode
);
1262 exception_raise_request (e
->handler
,
1263 e
->reply
, MACH_MSG_TYPE_MOVE_SEND_ONCE
,
1264 w
->thread
->port
, inf
->task
->port
,
1265 e
->exception
, e
->code
, e
->subcode
);
1268 error ("Can't forward spontaneous exception (%s).", NAME
);
1271 /* A Unix signal. */
1273 /* The process is stopped and expecting a signal. Just send off a
1274 request and let it get handled when we resume everything. */
1276 inf_debug (inf
, "sending %s to stopped process", NAME
);
1278 INF_MSGPORT_RPC (inf
,
1279 msg_sig_post_untraced_request (msgport
,
1281 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
1285 /* Posting an untraced signal automatically continues it.
1286 We clear this here rather than when we get the reply
1287 because we'd rather assume it's not stopped when it
1288 actually is, than the reverse. */
1292 /* It's not expecting it. We have to let just the signal thread
1293 run, and wait for it to get into a reasonable state before we
1294 can continue the rest of the process. When we finally resume the
1295 process the signal we request will be the very first thing that
1298 inf_debug (inf
, "sending %s to unstopped process (so resuming signal thread)", NAME
);
1300 INF_RESUME_MSGPORT_RPC (inf
, msg_sig_post_untraced (msgport
,
1301 host_sig
, 0, refport
));
1305 /* Can't do too much... */
1306 warning ("Can't deliver signal %s: No signal thread.", NAME
);
1308 warning ("Delivering signal %s: %s", NAME
, strerror (err
));
1313 /* Continue INF without delivering a signal. This is meant to be used
1314 when INF does not have a message port. */
1316 inf_continue (struct inf
*inf
)
1319 error_t err
= proc_pid2proc (proc_server
, inf
->pid
, &proc
);
1323 inf_debug (inf
, "continuing process");
1325 err
= proc_mark_cont (proc
);
1328 struct proc
*thread
;
1330 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1331 thread_resume (thread
->port
);
1338 warning ("Can't continue process: %s", strerror (err
));
1341 /* The inferior used for all gdb target ops. */
1342 struct inf
*current_inferior
= 0;
1344 /* The inferior being waited for by gnu_wait. Since GDB is decidely not
1345 multi-threaded, we don't bother to lock this. */
1346 struct inf
*waiting_inf
;
1348 /* Wait for something to happen in the inferior, returning what in STATUS. */
1350 gnu_wait (int tid
, struct target_waitstatus
*status
)
1353 mach_msg_header_t hdr
;
1354 mach_msg_type_t type
;
1358 struct proc
*thread
;
1359 struct inf
*inf
= current_inferior
;
1363 if (!inf
->threads
&& !inf
->pending_execs
)
1364 /* No threads! Assume that maybe some outside agency is frobbing our
1365 task, and really look for new threads. If we can't find any, just tell
1366 the user to try again later. */
1368 inf_validate_procs (inf
);
1369 if (!inf
->threads
&& !inf
->task
->dead
)
1370 error ("There are no threads; try again later.");
1375 inf_debug (inf
, "waiting for: %d", tid
);
1378 if (proc_wait_pid
!= inf
->pid
&& !inf
->no_wait
)
1379 /* Always get information on events from the proc server. */
1381 inf_debug (inf
, "requesting wait on pid %d", inf
->pid
);
1384 /* The proc server is single-threaded, and only allows a single
1385 outstanding wait request, so we have to cancel the previous one. */
1387 inf_debug (inf
, "cancelling previous wait on pid %d", proc_wait_pid
);
1388 interrupt_operation (proc_server
, 0);
1392 proc_wait_request (proc_server
, inf
->event_port
, inf
->pid
, WUNTRACED
);
1394 warning ("wait request failed: %s", strerror (err
));
1397 inf_debug (inf
, "waits pending: %d", proc_waits_pending
);
1398 proc_wait_pid
= inf
->pid
;
1399 /* Even if proc_waits_pending was > 0 before, we still won't get
1400 any other replies, because it was either from a different INF,
1401 or a different process attached to INF -- and the event port,
1402 which is the wait reply port, changes when you switch processes.*/
1403 proc_waits_pending
= 1;
1407 inf_clear_wait (inf
);
1409 /* What can happen? (1) Dead name notification; (2) Exceptions arrive;
1410 (3) wait reply from the proc server. */
1412 inf_debug (inf
, "waiting for an event...");
1413 err
= mach_msg (&msg
.hdr
, MACH_RCV_MSG
| MACH_RCV_INTERRUPT
,
1414 0, sizeof (struct msg
), inf
->event_port
,
1415 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
1417 /* Re-suspend the task. */
1420 if (!inf
->task
&& inf
->pending_execs
)
1421 /* When doing an exec, it's possible that the old task wasn't reused
1422 (e.g., setuid execs). So if the task seems to have disappeared,
1423 attempt to refetch it, as the pid should still be the same. */
1424 inf_set_pid (inf
, inf
->pid
);
1426 if (err
== EMACH_RCV_INTERRUPTED
)
1427 inf_debug (inf
, "interrupted");
1429 error ("Couldn't wait for an event: %s", strerror (err
));
1433 mach_msg_header_t hdr
;
1434 mach_msg_type_t err_type
;
1439 inf_debug (inf
, "event: msgid = %d", msg
.hdr
.msgh_id
);
1441 /* Handle what we got. */
1442 if (! notify_server (&msg
.hdr
, &reply
.hdr
)
1443 && ! exc_server (&msg
.hdr
, &reply
.hdr
)
1444 && ! process_reply_server (&msg
.hdr
, &reply
.hdr
)
1445 && ! msg_reply_server (&msg
.hdr
, &reply
.hdr
))
1446 /* Whatever it is, it's something strange. */
1447 error ("Got a strange event, msg id = %d.", msg
.hdr
.msgh_id
);
1450 error ("Handling event, msgid = %d: %s",
1451 msg
.hdr
.msgh_id
, strerror (reply
.err
));
1454 if (inf
->pending_execs
)
1455 /* We're waiting for the inferior to finish execing. */
1457 struct inf_wait
*w
= &inf
->wait
;
1458 enum target_waitkind kind
= w
->status
.kind
;
1460 if (kind
== TARGET_WAITKIND_SPURIOUS
)
1461 /* Since gdb is actually counting the number of times the inferior
1462 stops, expecting one stop per exec, we only return major events
1466 inf_debug (inf
, "pending_execs = %d, ignoring minor event",
1467 inf
->pending_execs
);
1469 else if (kind
== TARGET_WAITKIND_STOPPED
1470 && w
->status
.value
.sig
== TARGET_SIGNAL_TRAP
)
1471 /* Ah hah! A SIGTRAP from the inferior while starting up probably
1472 means we've succesfully completed an exec! */
1474 if (--inf
->pending_execs
== 0)
1477 #if 0 /* do we need this? */
1478 prune_threads (1); /* Get rid of the old shell threads */
1479 renumber_threads (0); /* Give our threads reasonable names. */
1482 inf_debug (inf
, "pending exec completed, pending_execs => %d",
1483 inf
->pending_execs
);
1485 else if (kind
== TARGET_WAITKIND_STOPPED
)
1486 /* It's possible that this signal is because of a crashed process
1487 being handled by the hurd crash server; in this case, the process
1488 will have an extra task suspend, which we need to know about.
1489 Since the code in inf_resume that normally checks for this is
1490 disabled while INF->pending_execs, we do the check here instead. */
1491 inf_validate_task_sc (inf
);
1494 if (inf
->wait
.suppress
)
1495 /* Some totally spurious event happened that we don't consider
1496 worth returning to gdb. Just keep waiting. */
1498 inf_debug (inf
, "suppressing return, rewaiting...");
1503 /* Pass back out our results. */
1504 bcopy (&inf
->wait
.status
, status
, sizeof (*status
));
1506 thread
= inf
->wait
.thread
;
1510 thread
= inf_tid_to_thread (inf
, tid
);
1512 if (!thread
|| thread
->port
== MACH_PORT_NULL
)
1513 /* TID is dead; try and find a new thread. */
1514 if (inf_update_procs (inf
) && inf
->threads
)
1515 tid
= inf
->threads
->tid
; /* The first available thread. */
1517 tid
= inferior_pid
; /* let wait_for_inferior handle exit case */
1519 if (thread
&& tid
>= 0 && status
->kind
!= TARGET_WAITKIND_SPURIOUS
1520 && inf
->pause_sc
== 0 && thread
->pause_sc
== 0)
1521 /* If something actually happened to THREAD, make sure we suspend it. */
1524 inf_update_suspends (inf
);
1527 inf_debug (inf
, "returning tid = %d, status = %s (%d)", tid
,
1528 status
->kind
== TARGET_WAITKIND_EXITED
? "EXITED"
1529 : status
->kind
== TARGET_WAITKIND_STOPPED
? "STOPPED"
1530 : status
->kind
== TARGET_WAITKIND_SIGNALLED
? "SIGNALLED"
1531 : status
->kind
== TARGET_WAITKIND_LOADED
? "LOADED"
1532 : status
->kind
== TARGET_WAITKIND_SPURIOUS
? "SPURIOUS"
1534 status
->value
.integer
);
1539 /* The rpc handler called by exc_server. */
1541 S_exception_raise_request (mach_port_t port
, mach_port_t reply_port
,
1542 thread_t thread_port
, task_t task_port
,
1543 int exception
, int code
, int subcode
)
1545 struct inf
*inf
= waiting_inf
;
1546 struct proc
*thread
= inf_port_to_thread (inf
, thread_port
);
1548 inf_debug (waiting_inf
,
1549 "thread = %d, task = %d, exc = %d, code = %d, subcode = %d",
1550 thread_port
, task_port
, exception
, code
);
1553 /* We don't know about thread? */
1555 inf_update_procs (inf
);
1556 thread
= inf_port_to_thread (inf
, thread_port
);
1558 /* Give up, the generating thread is gone. */
1562 mach_port_deallocate (mach_task_self (), thread_port
);
1563 mach_port_deallocate (mach_task_self (), task_port
);
1565 if (! thread
->aborted
)
1566 /* THREAD hasn't been aborted since this exception happened (abortion
1567 clears any exception state), so it must be real. */
1569 /* Store away the details; this will destroy any previous info. */
1570 inf
->wait
.thread
= thread
;
1572 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1574 if (exception
== EXC_BREAKPOINT
)
1575 /* GDB likes to get SIGTRAP for breakpoints. */
1577 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_TRAP
;
1578 mach_port_deallocate (mach_task_self (), reply_port
);
1581 /* Record the exception so that we can forward it later. */
1583 if (thread
->exc_port
== port
)
1585 inf_debug (waiting_inf
, "Handler is thread exeption port <%d>",
1586 thread
->saved_exc_port
);
1587 inf
->wait
.exc
.handler
= thread
->saved_exc_port
;
1591 inf_debug (waiting_inf
, "Handler is task exeption port <%d>",
1592 inf
->task
->saved_exc_port
);
1593 inf
->wait
.exc
.handler
= inf
->task
->saved_exc_port
;
1594 assert (inf
->task
->exc_port
== port
);
1596 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
1597 /* Add a reference to the exception handler. */
1598 mach_port_mod_refs (mach_task_self (),
1599 inf
->wait
.exc
.handler
, MACH_PORT_RIGHT_SEND
,
1602 inf
->wait
.exc
.exception
= exception
;
1603 inf
->wait
.exc
.code
= code
;
1604 inf
->wait
.exc
.subcode
= subcode
;
1605 inf
->wait
.exc
.reply
= reply_port
;
1607 /* Exceptions are encoded in the signal space by putting them after
1608 _NSIG; this assumes they're positive (and not extremely large)! */
1609 inf
->wait
.status
.value
.sig
=
1610 target_signal_from_host (_NSIG
+ exception
);
1614 /* A supppressed exception, which ignore. */
1616 inf
->wait
.suppress
= 1;
1617 mach_port_deallocate (mach_task_self (), reply_port
);
1623 /* Fill in INF's wait field after a task has died without giving us more
1624 detailed information. */
1626 inf_task_died_status (struct inf
*inf
)
1628 warning ("Pid %d died with unknown exit status, using SIGKILL.", inf
->pid
);
1629 inf
->wait
.status
.kind
= TARGET_WAITKIND_SIGNALLED
;
1630 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_KILL
;
1633 /* Notify server routines. The only real one is dead name notification. */
1635 do_mach_notify_dead_name (mach_port_t notify
, mach_port_t dead_port
)
1637 struct inf
*inf
= waiting_inf
;
1639 inf_debug (waiting_inf
, "port = %d", dead_port
);
1641 if (inf
->task
&& inf
->task
->port
== dead_port
)
1643 proc_debug (inf
->task
, "is dead");
1644 inf
->task
->port
= MACH_PORT_NULL
;
1645 if (proc_wait_pid
== inf
->pid
)
1646 /* We have a wait outstanding on the process, which will return more
1647 detailed information, so delay until we get that. */
1648 inf
->wait
.suppress
= 1;
1650 /* We never waited for the process (maybe it wasn't a child), so just
1651 pretend it got a SIGKILL. */
1652 inf_task_died_status (inf
);
1656 struct proc
*thread
= inf_port_to_thread (inf
, dead_port
);
1659 proc_debug (thread
, "is dead");
1660 thread
->port
= MACH_PORT_NULL
;
1664 mach_port_deallocate (mach_task_self (), dead_port
);
1665 inf
->threads_up_to_date
= 0; /* Just in case */
1673 warning ("illegal rpc: %s", fun
);
1678 do_mach_notify_no_senders (mach_port_t notify
, mach_port_mscount_t count
)
1680 return ill_rpc (__FUNCTION__
);
1684 do_mach_notify_port_deleted (mach_port_t notify
, mach_port_t name
)
1686 return ill_rpc (__FUNCTION__
);
1690 do_mach_notify_msg_accepted (mach_port_t notify
, mach_port_t name
)
1692 return ill_rpc (__FUNCTION__
);
1696 do_mach_notify_port_destroyed (mach_port_t notify
, mach_port_t name
)
1698 return ill_rpc (__FUNCTION__
);
1702 do_mach_notify_send_once (mach_port_t notify
)
1704 return ill_rpc (__FUNCTION__
);
1707 /* Process_reply server routines. We only use process_wait_reply. */
1710 S_proc_wait_reply (mach_port_t reply
, error_t err
,
1711 int status
, int sigcode
, rusage_t rusage
, pid_t pid
)
1713 struct inf
*inf
= waiting_inf
;
1715 inf_debug (inf
, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1716 err
? strerror (err
) : "0", pid
, status
, sigcode
);
1718 if (err
&& proc_wait_pid
&& (!inf
->task
|| !inf
->task
->port
))
1719 /* Ack. The task has died, but the task-died notification code didn't
1720 tell anyone because it thought a more detailed reply from the
1721 procserver was forthcoming. However, we now learn that won't
1722 happen... So we have to act like the task just died, and this time,
1724 inf_task_died_status (inf
);
1726 if (--proc_waits_pending
== 0)
1727 /* PROC_WAIT_PID represents the most recent wait. We will always get
1728 replies in order because the proc server is single threaded. */
1731 inf_debug (inf
, "waits pending now: %d", proc_waits_pending
);
1737 warning ("Can't wait for pid %d: %s", inf
->pid
, strerror (err
));
1740 /* Since we can't see the inferior's signals, don't trap them. */
1741 inf_set_traced (inf
, 0);
1744 else if (pid
== inf
->pid
)
1746 store_waitstatus (&inf
->wait
.status
, status
);
1747 if (inf
->wait
.status
.kind
== TARGET_WAITKIND_STOPPED
)
1748 /* The process has sent us a signal, and stopped itself in a sane
1749 state pending our actions. */
1751 inf_debug (inf
, "process has stopped itself");
1756 inf
->wait
.suppress
= 1; /* Something odd happened. Ignore. */
1762 S_proc_setmsgport_reply (mach_port_t reply
, error_t err
,
1763 mach_port_t old_msg_port
)
1765 return ill_rpc (__FUNCTION__
);
1769 S_proc_getmsgport_reply (mach_port_t reply
, error_t err
, mach_port_t msg_port
)
1771 return ill_rpc (__FUNCTION__
);
1774 /* Msg_reply server routines. We only use msg_sig_post_untraced_reply. */
1777 S_msg_sig_post_untraced_reply (mach_port_t reply
, error_t err
)
1779 struct inf
*inf
= waiting_inf
;
1782 /* EBUSY is what we get when the crash server has grabbed control of the
1783 process and doesn't like what signal we tried to send it. Just act
1784 like the process stopped (using a signal of 0 should mean that the
1785 *next* time the user continues, it will pass signal 0, which the crash
1786 server should like). */
1788 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1789 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_0
;
1792 warning ("Signal delivery failed: %s", strerror (err
));
1795 /* We only get this reply when we've posted a signal to a process which we
1796 thought was stopped, and which we expected to continue after the signal.
1797 Given that the signal has failed for some reason, it's reasonable to
1798 assume it's still stopped. */
1801 inf
->wait
.suppress
= 1;
1807 S_msg_sig_post_reply (mach_port_t reply
, error_t err
)
1809 return ill_rpc (__FUNCTION__
);
1812 /* Returns the number of messages queued for the receive right PORT. */
1813 static mach_port_msgcount_t
1814 port_msgs_queued (mach_port_t port
)
1816 struct mach_port_status status
;
1818 mach_port_get_receive_status (mach_task_self (), port
, &status
);
1823 return status
.mps_msgcount
;
1826 /* Resume execution of the inferior process.
1828 If STEP is nonzero, single-step it.
1829 If SIGNAL is nonzero, give it that signal.
1832 -1 true Single step the current thread allowing other threads to run.
1833 -1 false Continue the current thread allowing other threads to run.
1834 X true Single step the given thread, don't allow any others to run.
1835 X false Continue the given thread, do not allow any others to run.
1836 (Where X, of course, is anything except -1)
1838 Note that a resume may not `take' if there are pending exceptions/&c
1839 still unprocessed from the last resume we did (any given resume may result
1840 in multiple events returned by wait).
1843 gnu_resume (int tid
, int step
, enum target_signal sig
)
1845 struct proc
*step_thread
= 0;
1846 struct inf
*inf
= current_inferior
;
1848 inf_debug (inf
, "tid = %d, step = %d, sig = %d", tid
, step
, sig
);
1850 inf_validate_procinfo (inf
);
1852 if (sig
!= TARGET_SIGNAL_0
|| inf
->stopped
)
1854 if (sig
== TARGET_SIGNAL_0
&& inf
->nomsg
)
1857 inf_signal (inf
, sig
);
1859 else if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
1860 /* We received an exception to which we have chosen not to forward, so
1861 abort the faulting thread, which will perhaps retake it. */
1863 proc_abort (inf
->wait
.thread
, 1);
1864 warning ("Aborting %s with unforwarded exception %s.",
1865 proc_string (inf
->wait
.thread
),
1866 target_signal_to_name (inf
->wait
.status
.value
.sig
));
1869 if (port_msgs_queued (inf
->event_port
))
1870 /* If there are still messages in our event queue, don't bother resuming
1871 the process, as we're just going to stop it right away anyway. */
1874 inf_update_procs (inf
);
1877 /* Allow all threads to run, except perhaps single-stepping one. */
1879 inf_debug (inf
, "running all threads; tid = %d", inferior_pid
);
1880 tid
= inferior_pid
; /* What to step. */
1881 inf_set_threads_resume_sc (inf
, 0, 1);
1884 /* Just allow a single thread to run. */
1886 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
1888 error ("Can't run single thread id %d: no such thread!");
1889 inf_debug (inf
, "running one thread: %d/%d", inf
->pid
, thread
->tid
);
1890 inf_set_threads_resume_sc (inf
, thread
, 0);
1895 step_thread
= inf_tid_to_thread (inf
, tid
);
1897 warning ("Can't step thread id %d: no such thread.", tid
);
1899 inf_debug (inf
, "stepping thread: %d/%d", inf
->pid
, step_thread
->tid
);
1901 if (step_thread
!= inf
->step_thread
)
1902 inf_set_step_thread (inf
, step_thread
);
1904 inf_debug (inf
, "here we go...");
1909 gnu_kill_inferior ()
1911 struct proc
*task
= current_inferior
->task
;
1914 proc_debug (task
, "terminating...");
1915 task_terminate (task
->port
);
1916 inf_set_pid (current_inferior
, -1);
1918 target_mourn_inferior ();
1921 /* Clean up after the inferior dies. */
1924 gnu_mourn_inferior ()
1926 inf_debug (current_inferior
, "rip");
1927 inf_detach (current_inferior
);
1928 unpush_target (&gnu_ops
);
1929 generic_mourn_inferior ();
1932 /* Fork an inferior process, and start debugging it. */
1934 /* Set INFERIOR_PID to the first thread available in the child, if any. */
1936 inf_pick_first_thread ()
1938 if (current_inferior
->task
&& current_inferior
->threads
)
1939 /* The first thread. */
1940 return current_inferior
->threads
->tid
;
1942 /* What may be the next thread. */
1943 return next_thread_id
;
1949 if (! current_inferior
)
1950 current_inferior
= make_inf ();
1951 return current_inferior
;
1955 gnu_create_inferior (exec_file
, allargs
, env
)
1960 struct inf
*inf
= cur_inf ();
1964 /* We're in the child; make this process stop as soon as it execs. */
1965 inf_debug (inf
, "tracing self");
1966 if (ptrace (PTRACE_TRACEME
) != 0)
1967 error ("ptrace (PTRACE_TRACEME) failed!");
1969 void attach_to_child (int pid
)
1971 /* Attach to the now stopped child, which is actually a shell... */
1972 inf_debug (inf
, "attaching to child: %d", pid
);
1974 inf_attach (inf
, pid
);
1977 push_target (&gnu_ops
);
1979 inf
->pending_execs
= 2;
1983 /* Now let the child run again, knowing that it will stop immediately
1984 because of the ptrace. */
1986 inferior_pid
= inf_pick_first_thread ();
1988 startup_inferior (inf
->pending_execs
);
1991 inf_debug (inf
, "creating inferior");
1993 fork_inferior (exec_file
, allargs
, env
, trace_me
, attach_to_child
,
1996 inf_validate_procinfo (inf
);
1997 inf_update_signal_thread (inf
);
1998 inf_set_traced (inf
, inf
->want_signals
);
2000 /* Execing the process will have trashed our exception ports; steal them
2001 back (or make sure they're restored if the user wants that). */
2002 if (inf
->want_exceptions
)
2003 inf_steal_exc_ports (inf
);
2005 inf_restore_exc_ports (inf
);
2008 proceed ((CORE_ADDR
) -1, 0, 0);
2011 /* Mark our target-struct as eligible for stray "run" and "attach"
2019 #ifdef ATTACH_DETACH
2021 /* Attach to process PID, then initialize for debugging it
2022 and wait for the trace-trap that results from attaching. */
2024 gnu_attach (args
, from_tty
)
2030 struct inf
*inf
= cur_inf ();
2033 error_no_arg ("PID to attach");
2037 if (pid
== getpid()) /* Trying to masturbate? */
2038 error ("I refuse to debug myself!");
2042 exec_file
= (char *) get_exec_file (0);
2045 printf_unfiltered ("Attaching to program `%s', pid %d\n",
2048 printf_unfiltered ("Attaching to pid %d\n", pid
);
2050 gdb_flush (gdb_stdout
);
2053 inf_debug (inf
, "attaching to pid: %d", pid
);
2055 inf_attach (inf
, pid
);
2056 inf_update_procs (inf
);
2058 inferior_pid
= inf_pick_first_thread ();
2061 push_target (&gnu_ops
);
2063 /* We have to initialize the terminal settings now, since the code
2064 below might try to restore them. */
2065 target_terminal_init ();
2067 /* If the process was stopped before we attached, make it continue the next
2068 time the user does a continue. */
2069 inf_validate_procinfo (inf
);
2071 inf_update_signal_thread (inf
);
2072 inf_set_traced (inf
, inf
->want_signals
);
2074 #if 0 /* Do we need this? */
2075 renumber_threads (0); /* Give our threads reasonable names. */
2079 /* Take a program previously attached to and detaches it.
2080 The program resumes execution and will no longer stop
2081 on signals, etc. We'd better not have left any breakpoints
2082 in the program or it'll die when it hits one. For this
2083 to work, it may be necessary for the process to have been
2084 previously attached. It *might* work if the program was
2085 started via fork. */
2087 gnu_detach (args
, from_tty
)
2093 char *exec_file
= get_exec_file (0);
2095 printf_unfiltered ("Detaching from program `%s' pid %d\n",
2096 exec_file
, current_inferior
->pid
);
2098 printf_unfiltered ("Detaching from pid %d\n", current_inferior
->pid
);
2099 gdb_flush (gdb_stdout
);
2102 inf_detach (current_inferior
);
2106 unpush_target (&gnu_ops
); /* Pop out of handling an inferior */
2108 #endif /* ATTACH_DETACH */
2111 gnu_terminal_init_inferior ()
2113 assert (current_inferior
);
2114 terminal_init_inferior_with_pgrp (current_inferior
->pid
);
2117 /* Get ready to modify the registers array. On machines which store
2118 individual registers, this doesn't need to do anything. On machines
2119 which store all the registers in one fell swoop, this makes sure
2120 that registers contains all the registers from the program being
2124 gnu_prepare_to_store ()
2126 #ifdef CHILD_PREPARE_TO_STORE
2127 CHILD_PREPARE_TO_STORE ();
2132 gnu_open (arg
, from_tty
)
2136 error ("Use the \"run\" command to start a Unix child process.");
2142 error ("to_stop target function not implemented");
2146 gnu_pid_to_exec_file ()
2148 error ("to_pid_to_exec_file target function not implemented");
2154 gnu_thread_alive (int tid
)
2156 inf_update_procs (current_inferior
);
2157 return !!inf_tid_to_thread (current_inferior
, tid
);
2161 * Read inferior task's LEN bytes from ADDR and copy it to MYADDR
2162 * in gdb's address space.
2164 * Return 0 on failure; number of bytes read otherwise.
2167 gnu_read_inferior (task
, addr
, myaddr
, length
)
2174 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2175 vm_size_t aligned_length
=
2176 (vm_size_t
) round_page (addr
+length
) - low_address
;
2180 /* Get memory from inferior with page aligned addresses */
2181 err
= vm_read (task
, low_address
, aligned_length
, &copied
, ©_count
);
2185 err
= hurd_safe_copyin (myaddr
, (void*)addr
- low_address
+ copied
, length
);
2188 warning ("Read from inferior faulted: %s", strerror (err
));
2192 err
= vm_deallocate (mach_task_self (), copied
, copy_count
);
2194 warning ("gnu_read_inferior vm_deallocate failed: %s", strerror (err
));
2199 #define CHK_GOTO_OUT(str,ret) \
2200 do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
2202 struct vm_region_list
{
2203 struct vm_region_list
*next
;
2204 vm_prot_t protection
;
2209 struct obstack region_obstack
;
2212 * Write gdb's LEN bytes from MYADDR and copy it to ADDR
2213 * in inferior task's address space.
2216 gnu_write_inferior (task
, addr
, myaddr
, length
)
2223 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2224 vm_size_t aligned_length
=
2225 (vm_size_t
) round_page (addr
+length
) - low_address
;
2230 char *errstr
= "Bug in gnu_write_inferior";
2232 struct vm_region_list
*region_element
;
2233 struct vm_region_list
*region_head
= (struct vm_region_list
*)NULL
;
2235 /* Get memory from inferior with page aligned addresses */
2236 err
= vm_read (task
,
2241 CHK_GOTO_OUT ("gnu_write_inferior vm_read failed", err
);
2245 err
= hurd_safe_copyout ((void*)addr
- low_address
+ copied
, myaddr
, length
);
2246 CHK_GOTO_OUT ("Write to inferior faulted", err
);
2248 obstack_init (®ion_obstack
);
2250 /* Do writes atomically.
2251 * First check for holes and unwritable memory.
2254 vm_size_t remaining_length
= aligned_length
;
2255 vm_address_t region_address
= low_address
;
2257 struct vm_region_list
*scan
;
2259 while(region_address
< low_address
+ aligned_length
)
2261 vm_prot_t protection
;
2262 vm_prot_t max_protection
;
2263 vm_inherit_t inheritance
;
2265 mach_port_t object_name
;
2267 vm_size_t region_length
= remaining_length
;
2268 vm_address_t old_address
= region_address
;
2270 err
= vm_region (task
,
2279 CHK_GOTO_OUT ("vm_region failed", err
);
2281 /* Check for holes in memory */
2282 if (old_address
!= region_address
)
2284 warning ("No memory at 0x%x. Nothing written",
2291 if (!(max_protection
& VM_PROT_WRITE
))
2293 warning ("Memory at address 0x%x is unwritable. Nothing written",
2300 /* Chain the regions for later use */
2302 (struct vm_region_list
*)
2303 obstack_alloc (®ion_obstack
, sizeof (struct vm_region_list
));
2305 region_element
->protection
= protection
;
2306 region_element
->start
= region_address
;
2307 region_element
->length
= region_length
;
2309 /* Chain the regions along with protections */
2310 region_element
->next
= region_head
;
2311 region_head
= region_element
;
2313 region_address
+= region_length
;
2314 remaining_length
= remaining_length
- region_length
;
2317 /* If things fail after this, we give up.
2318 * Somebody is messing up inferior_task's mappings.
2321 /* Enable writes to the chained vm regions */
2322 for (scan
= region_head
; scan
; scan
= scan
->next
)
2324 boolean_t protection_changed
= FALSE
;
2326 if (!(scan
->protection
& VM_PROT_WRITE
))
2328 err
= vm_protect (task
,
2332 scan
->protection
| VM_PROT_WRITE
);
2333 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2337 err
= vm_write (task
,
2341 CHK_GOTO_OUT ("vm_write failed", err
);
2343 /* Set up the original region protections, if they were changed */
2344 for (scan
= region_head
; scan
; scan
= scan
->next
)
2346 boolean_t protection_changed
= FALSE
;
2348 if (!(scan
->protection
& VM_PROT_WRITE
))
2350 err
= vm_protect (task
,
2355 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2363 obstack_free (®ion_obstack
, 0);
2365 (void) vm_deallocate (mach_task_self (),
2370 if (err
!= KERN_SUCCESS
)
2372 warning ("%s: %s", errstr
, mach_error_string (err
));
2379 /* Return 0 on failure, number of bytes handled otherwise. */
2381 gnu_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2386 struct target_ops
*target
; /* IGNORED */
2391 ? (current_inferior
->task
? current_inferior
->task
->port
: 0)
2394 if (task
== MACH_PORT_NULL
)
2398 inf_debug (current_inferior
, "%s %p[%d] %s %p",
2399 write
? "writing" : "reading", memaddr
, len
,
2400 write
? "<--" : "-->", myaddr
);
2402 return gnu_write_inferior (task
, memaddr
, myaddr
, len
);
2404 return gnu_read_inferior (task
, memaddr
, myaddr
, len
);
2408 extern void gnu_store_registers (int regno
);
2409 extern void gnu_fetch_registers (int regno
);
2411 struct target_ops gnu_ops
;
2416 gnu_ops
.to_shortname
= "GNU"; /* to_shortname */
2417 gnu_ops
.to_longname
= "GNU Hurd process"; /* to_longname */
2418 gnu_ops
.to_doc
= "GNU Hurd process"; /* to_doc */
2419 gnu_ops
.to_open
= gnu_open
; /* to_open */
2420 gnu_ops
.to_close
= 0; /* to_close */
2421 gnu_ops
.to_attach
= gnu_attach
; /* to_attach */
2422 gnu_ops
.to_post_attach
= NULL
;
2423 gnu_ops
.to_require_attach
= NULL
; /* to_require_attach */
2424 gnu_ops
.to_detach
= gnu_detach
; /* to_detach */
2425 gnu_ops
.to_require_detach
= NULL
; /* to_require_detach */
2426 gnu_ops
.to_resume
= gnu_resume
; /* to_resume */
2427 gnu_ops
.to_wait
= gnu_wait
; /* to_wait */
2428 gnu_ops
.to_post_wait
= NULL
; /* to_post_wait */
2429 gnu_ops
.to_fetch_registers
= gnu_fetch_registers
; /* to_fetch_registers */
2430 gnu_ops
.to_store_registers
= gnu_store_registers
; /* to_store_registers */
2431 gnu_ops
.to_prepare_to_store
= gnu_prepare_to_store
; /* to_prepare_to_store */
2432 gnu_ops
.to_xfer_memory
= gnu_xfer_memory
; /* to_xfer_memory */
2433 gnu_ops
.to_files_info
= 0; /* to_files_info */
2434 gnu_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
2435 gnu_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
2436 gnu_ops
.to_terminal_init
= gnu_terminal_init_inferior
;
2437 gnu_ops
.to_terminal_inferior
= terminal_inferior
;
2438 gnu_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
2439 gnu_ops
.to_terminal_ours
= terminal_ours
;
2440 gnu_ops
.to_terminal_info
= child_terminal_info
;
2441 gnu_ops
.to_kill
= gnu_kill_inferior
; /* to_kill */
2442 gnu_ops
.to_load
= 0; /* to_load */
2443 gnu_ops
.to_lookup_symbol
= 0; /* to_lookup_symbol */
2444 gnu_ops
.to_create_inferior
= gnu_create_inferior
; /* to_create_inferior */
2445 gnu_ops
.to_post_startup_inferior
= NULL
; /* to_post_startup_inferior */
2446 gnu_ops
.to_acknowledge_created_inferior
= NULL
; /* to_acknowledge_created_inferior */
2447 gnu_ops
.to_clone_and_follow_inferior
= NULL
; /* to_clone_and_follow_inferior */
2448 gnu_ops
.to_post_follow_inferior_by_clone
= NULL
; /* to_post_follow_inferior_by_clone */
2449 gnu_ops
.to_insert_fork_catchpoint
= NULL
;
2450 gnu_ops
.to_remove_fork_catchpoint
= NULL
;
2451 gnu_ops
.to_insert_vfork_catchpoint
= NULL
;
2452 gnu_ops
.to_remove_vfork_catchpoint
= NULL
;
2453 gnu_ops
.to_has_forked
= NULL
; /* to_has_forked */
2454 gnu_ops
.to_has_vforked
= NULL
; /* to_has_vforked */
2455 gnu_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2456 gnu_ops
.to_post_follow_vfork
= NULL
; /* to_post_follow_vfork */
2457 gnu_ops
.to_insert_exec_catchpoint
= NULL
;
2458 gnu_ops
.to_remove_exec_catchpoint
= NULL
;
2459 gnu_ops
.to_has_execd
= NULL
;
2460 gnu_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2461 gnu_ops
.to_has_exited
= NULL
;
2462 gnu_ops
.to_mourn_inferior
= gnu_mourn_inferior
; /* to_mourn_inferior */
2463 gnu_ops
.to_can_run
= gnu_can_run
; /* to_can_run */
2464 gnu_ops
.to_notice_signals
= 0; /* to_notice_signals */
2465 gnu_ops
.to_thread_alive
= gnu_thread_alive
;/* to_thread_alive */
2466 gnu_ops
.to_stop
= gnu_stop
; /* to_stop */
2467 gnu_ops
.to_pid_to_exec_file
= gnu_pid_to_exec_file
; /* to_pid_to_exec_file */
2468 gnu_ops
.to_core_file_to_sym_file
= NULL
;
2469 gnu_ops
.to_stratum
= process_stratum
; /* to_stratum */
2470 gnu_ops
.DONT_USE
= 0; /* to_next */
2471 gnu_ops
.to_has_all_memory
= 1; /* to_has_all_memory */
2472 gnu_ops
.to_has_memory
= 1; /* to_has_memory */
2473 gnu_ops
.to_has_stack
= 1; /* to_has_stack */
2474 gnu_ops
.to_has_registers
= 1; /* to_has_registers */
2475 gnu_ops
.to_has_execution
= 1; /* to_has_execution */
2476 gnu_ops
.to_sections
= 0; /* sections */
2477 gnu_ops
.to_sections_end
= 0; /* sections_end */
2478 gnu_ops
.to_magic
= OPS_MAGIC
; /* to_magic */
2479 } /* init_gnu_ops */
2481 /* Return printable description of proc. */
2482 char *proc_string (struct proc
*proc
)
2484 static char tid_str
[80];
2485 if (proc_is_task (proc
))
2486 sprintf (tid_str
, "process %d", proc
->inf
->pid
);
2488 sprintf (tid_str
, "thread %d.%d",
2489 proc
->inf
->pid
, pid_to_thread_id (proc
->tid
));
2494 gnu_target_pid_to_str (int tid
)
2496 struct inf
*inf
= current_inferior
;
2497 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
2500 return proc_string (thread
);
2503 static char tid_str
[80];
2504 sprintf (tid_str
, "bogus thread id %d", tid
);
2509 /* User task commands. */
2511 struct cmd_list_element
*set_task_cmd_list
= 0;
2512 struct cmd_list_element
*show_task_cmd_list
= 0;
2513 /* User thread commands. */
2515 /* Commands with a prefix of `set/show thread'. */
2516 extern struct cmd_list_element
*thread_cmd_list
;
2517 struct cmd_list_element
*set_thread_cmd_list
= NULL
;
2518 struct cmd_list_element
*show_thread_cmd_list
= NULL
;
2520 /* Commands with a prefix of `set/show thread default'. */
2521 struct cmd_list_element
*set_thread_default_cmd_list
= NULL
;
2522 struct cmd_list_element
*show_thread_default_cmd_list
= NULL
;
2525 set_thread_cmd (char *args
, int from_tty
)
2527 printf_unfiltered ("\"set thread\" must be followed by the name of a thread property, or \"default\".\n");
2531 show_thread_cmd (char *args
, int from_tty
)
2533 printf_unfiltered ("\"show thread\" must be followed by the name of a thread property, or \"default\".\n");
2537 set_thread_default_cmd (char *args
, int from_tty
)
2539 printf_unfiltered ("\"set thread default\" must be followed by the name of a thread property.\n");
2543 show_thread_default_cmd (char *args
, int from_tty
)
2545 printf_unfiltered ("\"show thread default\" must be followed by the name of a thread property.\n");
2549 parse_int_arg (char *args
, char *cmd_prefix
)
2554 int val
= strtoul (args
, &arg_end
, 10);
2555 if (*args
&& *arg_end
== '\0')
2558 error ("Illegal argument for \"%s\" command, should be an integer.", cmd_prefix
);
2562 _parse_bool_arg (char *args
, char *t_val
, char *f_val
, char *cmd_prefix
)
2564 if (!args
|| strcmp (args
, t_val
) == 0)
2566 else if (strcmp (args
, f_val
) == 0)
2569 error ("Illegal argument for \"%s\" command, should be \"%s\" or \"%s\".",
2570 cmd_prefix
, t_val
, f_val
);
2573 #define parse_bool_arg(args, cmd_prefix) \
2574 _parse_bool_arg (args, "on", "off", cmd_prefix)
2577 check_empty (char *args
, char *cmd_prefix
)
2580 error ("Garbage after \"%s\" command: `%s'", cmd_prefix
, args
);
2583 /* Returns the alive thread named by INFERIOR_PID, or signals an error. */
2584 static struct proc
*
2587 struct inf
*inf
= cur_inf ();
2588 struct proc
*thread
= inf_tid_to_thread (inf
, inferior_pid
);
2590 error ("No current thread.");
2594 /* Returns the current inferior, but signals an error if it has no task. */
2598 struct inf
*inf
= cur_inf ();
2600 error ("No current process.");
2605 set_task_pause_cmd (char *args
, int from_tty
)
2607 struct inf
*inf
= cur_inf ();
2608 int old_sc
= inf
->pause_sc
;
2610 inf
->pause_sc
= parse_bool_arg (args
, "set task pause");
2612 if (old_sc
== 0 && inf
->pause_sc
!= 0)
2613 /* If the task is currently unsuspended, immediately suspend it,
2614 otherwise wait until the next time it gets control. */
2619 show_task_pause_cmd (char *args
, int from_tty
)
2621 struct inf
*inf
= cur_inf ();
2622 check_empty (args
, "show task pause");
2623 printf_unfiltered ("The inferior task %s suspended while gdb has control.\n",
2625 ? (inf
->pause_sc
== 0 ? "isn't" : "is")
2626 : (inf
->pause_sc
== 0 ? "won't be" : "will be"));
2630 set_task_detach_sc_cmd (char *args
, int from_tty
)
2632 cur_inf ()->detach_sc
= parse_int_arg (args
, "set task detach-suspend-count");
2636 show_task_detach_sc_cmd (char *args
, int from_tty
)
2638 check_empty (args
, "show task detach-suspend-count");
2639 printf_unfiltered ("The inferior task will be left with a suspend count of %d when detaching.\n",
2640 cur_inf ()->detach_sc
);
2644 set_thread_default_pause_cmd (char *args
, int from_tty
)
2646 struct inf
*inf
= cur_inf ();
2647 inf
->default_thread_pause_sc
=
2648 parse_bool_arg (args
, "set thread default pause") ? 0 : 1;
2652 show_thread_default_pause_cmd (char *args
, int from_tty
)
2654 struct inf
*inf
= cur_inf ();
2655 int sc
= inf
->default_thread_pause_sc
;
2656 check_empty (args
, "show thread default pause");
2657 printf_unfiltered ("New threads %s suspended while gdb has control%s.\n",
2658 sc
? "are" : "aren't",
2659 !sc
&& inf
->pause_sc
? " (but the task is)" : "");
2663 set_thread_default_run_cmd (char *args
, int from_tty
)
2665 struct inf
*inf
= cur_inf ();
2666 inf
->default_thread_run_sc
=
2667 parse_bool_arg (args
, "set thread default run") ? 0 : 1;
2671 show_thread_default_run_cmd (char *args
, int from_tty
)
2673 struct inf
*inf
= cur_inf ();
2674 check_empty (args
, "show thread default run");
2675 printf_unfiltered ("New threads %s allowed to run.\n",
2676 inf
->default_thread_run_sc
== 0 ? "are" : "aren't");
2680 set_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2682 cur_inf ()->default_thread_detach_sc
=
2683 parse_int_arg (args
, "set thread default detach-suspend-count");
2687 show_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2689 check_empty (args
, "show thread default detach-suspend-count");
2690 printf_unfiltered ("New threads will get a detach-suspend-count of %d.\n",
2691 cur_inf ()->default_thread_detach_sc
);
2694 /* Steal a send right called NAME in the inferior task, and make it PROC's
2695 saved exception port. */
2697 steal_exc_port (struct proc
*proc
, mach_port_t name
)
2701 mach_msg_type_name_t port_type
;
2703 if (!proc
|| !proc
->inf
->task
)
2704 error ("No inferior task.");
2706 err
= mach_port_extract_right (proc
->inf
->task
->port
,
2707 name
, MACH_MSG_TYPE_COPY_SEND
,
2710 error ("Couldn't extract send right %d from inferior: %s",
2711 name
, strerror (err
));
2713 if (proc
->saved_exc_port
)
2714 /* Get rid of our reference to the old one. */
2715 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
2717 proc
->saved_exc_port
= port
;
2719 if (! proc
->exc_port
)
2720 /* If PROC is a thread, we may not have set its exception port before.
2721 We can't use proc_steal_exc_port because it also sets saved_exc_port. */
2723 proc
->exc_port
= proc
->inf
->event_port
;
2724 err
= proc_set_exception_port (proc
, proc
->exc_port
);
2725 error ("Can't set exception port for %s: %s",
2726 proc_string (proc
), strerror (err
));
2731 set_task_exc_port_cmd (char *args
, int from_tty
)
2733 struct inf
*inf
= cur_inf ();
2735 error ("No argument to \"set task exception-port\" command.");
2736 steal_exc_port (inf
->task
, parse_and_eval_address (args
));
2740 set_stopped_cmd (char *args
, int from_tty
)
2742 cur_inf ()->stopped
= _parse_bool_arg (args
, "yes", "no", "set stopped");
2746 show_stopped_cmd (char *args
, int from_tty
)
2748 struct inf
*inf
= active_inf ();
2749 check_empty (args
, "show stopped");
2750 printf_unfiltered ("The inferior process %s stopped.\n",
2751 inf
->stopped
? "is" : "isn't");
2755 set_sig_thread_cmd (char *args
, int from_tty
)
2758 struct inf
*inf
= cur_inf ();
2760 if (!args
|| (! isdigit (*args
) && strcmp (args
, "none") != 0))
2761 error ("Illegal argument to \"set signal-thread\" command.\n"
2762 "Should be an integer thread ID, or `none'.");
2764 if (strcmp (args
, "none") == 0)
2765 inf
->signal_thread
= 0;
2768 int tid
= thread_id_to_pid (atoi (args
));
2770 error ("Thread ID %s not known. Use the \"info threads\" command to\n"
2771 "see the IDs of currently known threads.", args
);
2772 inf
->signal_thread
= inf_tid_to_thread (inf
, tid
);
2777 show_sig_thread_cmd (char *args
, int from_tty
)
2779 struct inf
*inf
= active_inf ();
2780 check_empty (args
, "show signal-thread");
2781 if (inf
->signal_thread
)
2782 printf_unfiltered ("The signal thread is %s.\n",
2783 proc_string (inf
->signal_thread
));
2785 printf_unfiltered ("There is no signal thread.\n");
2789 set_signals_cmd (char *args
, int from_tty
)
2792 struct inf
*inf
= cur_inf ();
2794 inf
->want_signals
= parse_bool_arg (args
, "set signals");
2796 if (inf
->task
&& inf
->want_signals
!= inf
->traced
)
2797 /* Make this take effect immediately in a running process. */
2798 inf_set_traced (inf
, inf
->want_signals
);
2802 show_signals_cmd (char *args
, int from_tty
)
2804 struct inf
*inf
= cur_inf ();
2805 check_empty (args
, "show signals");
2806 printf_unfiltered ("The inferior process's signals %s intercepted.\n",
2808 ? (inf
->traced
? "are" : "aren't")
2809 : (inf
->want_signals
? "will be" : "won't be"));
2813 set_exceptions_cmd (char *args
, int from_tty
)
2815 struct inf
*inf
= cur_inf ();
2816 int val
= parse_bool_arg (args
, "set exceptions");
2818 if (inf
->task
&& inf
->want_exceptions
!= val
)
2819 /* Make this take effect immediately in a running process. */
2822 inf
->want_exceptions
= val
;
2826 show_exceptions_cmd (char *args
, int from_tty
)
2828 struct inf
*inf
= cur_inf ();
2829 check_empty (args
, "show exceptions");
2830 printf_unfiltered ("Exceptions in the inferior %s trapped.\n",
2832 ? (inf
->want_exceptions
? "are" : "aren't")
2833 : (inf
->want_exceptions
? "will be" : "won't be"));
2837 set_task_cmd (char *args
, int from_tty
)
2839 printf_unfiltered ("\"set task\" must be followed by the name of a task property.\n");
2843 show_task_cmd (char *args
, int from_tty
)
2845 struct inf
*inf
= cur_inf ();
2847 check_empty (args
, "show task");
2849 show_signals_cmd (0, from_tty
);
2850 show_exceptions_cmd (0, from_tty
);
2851 show_task_pause_cmd (0, from_tty
);
2853 if (inf
->pause_sc
== 0)
2854 show_thread_default_pause_cmd (0, from_tty
);
2855 show_thread_default_run_cmd (0, from_tty
);
2859 show_stopped_cmd (0, from_tty
);
2860 show_sig_thread_cmd (0, from_tty
);
2863 if (inf
->detach_sc
!= 0)
2864 show_task_detach_sc_cmd (0, from_tty
);
2865 if (inf
->default_thread_detach_sc
!= 0)
2866 show_thread_default_detach_sc_cmd (0, from_tty
);
2870 set_noninvasive_cmd (char *args
, int from_tty
)
2872 /* Invert the sense of the arg for each component. */
2873 char *inv_args
= parse_bool_arg (args
, "set noninvasive") ? "off" : "on";
2875 set_task_pause_cmd (inv_args
, from_tty
);
2876 set_signals_cmd (inv_args
, from_tty
);
2877 set_exceptions_cmd (inv_args
, from_tty
);
2881 info_port_rights (char *args
, mach_port_type_t only
)
2883 struct inf
*inf
= active_inf ();
2884 value_ptr vmark
= value_mark ();
2887 /* Explicit list of port rights. */
2891 value_ptr val
= parse_to_comma_and_eval (&args
);
2892 long right
= value_as_long (val
);
2894 print_port_info (right
, 0, inf
->task
->port
, PORTINFO_DETAILS
,
2897 error ("%ld: %s.", right
, strerror (err
));
2901 /* Print all of them. */
2904 print_task_ports_info (inf
->task
->port
, only
, PORTINFO_DETAILS
,
2907 error ("%s.", strerror (err
));
2910 value_free_to_mark (vmark
);
2914 info_send_rights_cmd (char *args
, int from_tty
)
2916 info_port_rights (args
, MACH_PORT_TYPE_SEND
);
2919 info_recv_rights_cmd (char *args
, int from_tty
)
2921 info_port_rights (args
, MACH_PORT_TYPE_RECEIVE
);
2924 info_port_sets_cmd (char *args
, int from_tty
)
2926 info_port_rights (args
, MACH_PORT_TYPE_PORT_SET
);
2929 info_dead_names_cmd (char *args
, int from_tty
)
2931 info_port_rights (args
, MACH_PORT_TYPE_DEAD_NAME
);
2934 info_port_rights_cmd (char *args
, int from_tty
)
2936 info_port_rights (args
, ~0);
2939 static void add_task_commands ()
2941 add_cmd ("pause", class_run
, set_thread_default_pause_cmd
,
2942 "Set whether the new threads are suspended while gdb has control.\n"
2943 "This property normally has no effect because the whole task is\n"
2944 "suspended, however, that may be disabled with \"set task pause off\".\n"
2945 "The default value is \"off\".",
2946 &set_thread_default_cmd_list
);
2947 add_cmd ("pause", no_class
, show_thread_default_pause_cmd
,
2948 "Show whether new threads are suspended while gdb has control.",
2949 &show_thread_default_cmd_list
);
2950 add_cmd ("run", class_run
, set_thread_default_run_cmd
,
2951 "Set whether new threads are allowed to run (once gdb has noticed them).",
2952 &set_thread_default_cmd_list
);
2953 add_cmd ("run", no_class
, show_thread_default_run_cmd
,
2954 "Show whether new threads are allowed to run (once gdb has noticed them).",
2955 &show_thread_default_cmd_list
);
2956 add_cmd ("detach-suspend-count", class_run
, set_thread_default_detach_sc_cmd
,
2957 "Set the default detach-suspend-count value for new threads.",
2958 &set_thread_default_cmd_list
);
2959 add_cmd ("detach-suspend-count", no_class
, show_thread_default_detach_sc_cmd
,
2960 "Show the default detach-suspend-count value for new threads.",
2961 &show_thread_default_cmd_list
);
2963 add_cmd ("signals", class_run
, set_signals_cmd
,
2964 "Set whether the inferior process's signals will be intercepted.\n"
2965 "Mach exceptions (such as breakpoint traps) are not affected.",
2967 add_alias_cmd ("sigs", "signals", class_run
, 1, &setlist
);
2968 add_cmd ("signals", no_class
, show_signals_cmd
,
2969 "Show whether the inferior process's signals will be intercepted.",
2971 add_alias_cmd ("sigs", "signals", no_class
, 1, &showlist
);
2973 add_cmd ("signal-thread", class_run
, set_sig_thread_cmd
,
2974 "Set the thread that gdb thinks is the libc signal thread.\n"
2975 "This thread is run when delivering a signal to a non-stopped process.",
2977 add_alias_cmd ("sigthread", "signal-thread", class_run
, 1, &setlist
);
2978 add_cmd ("signal-thread", no_class
, show_sig_thread_cmd
,
2979 "Set the thread that gdb thinks is the libc signal thread.",
2981 add_alias_cmd ("sigthread", "signal-thread", no_class
, 1, &showlist
);
2983 add_cmd ("stopped", class_run
, set_stopped_cmd
,
2984 "Set whether gdb thinks the inferior process is stopped as with SIGSTOP.\n"
2985 "Stopped process will be continued by sending them a signal.",
2987 add_cmd ("stopped", no_class
, show_signals_cmd
,
2988 "Show whether gdb thinks the inferior process is stopped as with SIGSTOP.",
2991 add_cmd ("exceptions", class_run
, set_exceptions_cmd
,
2992 "Set whether exceptions in the inferior process will be trapped.\n"
2993 "When exceptions are turned off, neither breakpoints nor single-stepping\n"
2996 /* Allow `set exc' despite conflict with `set exception-port'. */
2997 add_alias_cmd ("exc", "exceptions", class_run
, 1, &setlist
);
2998 add_cmd ("exceptions", no_class
, show_exceptions_cmd
,
2999 "Show whether exceptions in the inferior process will be trapped.",
3002 add_prefix_cmd ("task", no_class
, set_task_cmd
,
3003 "Command prefix for setting task attributes.",
3004 &set_task_cmd_list
, "set task ", 0, &setlist
);
3005 add_prefix_cmd ("task", no_class
, show_task_cmd
,
3006 "Command prefix for showing task attributes.",
3007 &show_task_cmd_list
, "show task ", 0, &showlist
);
3009 add_cmd ("pause", class_run
, set_task_pause_cmd
,
3010 "Set whether the task is suspended while gdb has control.\n"
3011 "A value of \"on\" takes effect immediately, otherwise nothing\n"
3012 "happens until the next time the program is continued.\n"
3013 "When setting this to \"off\", \"set thread default pause on\"\n"
3014 "can be used to pause individual threads by default instead.",
3015 &set_task_cmd_list
);
3016 add_cmd ("pause", no_class
, show_task_pause_cmd
,
3017 "Show whether the task is suspended while gdb has control.",
3018 &show_task_cmd_list
);
3019 add_cmd ("detach-suspend-count", class_run
, set_task_detach_sc_cmd
,
3020 "Set the suspend count will leave on the thread when detaching.",
3021 &set_task_cmd_list
);
3022 add_cmd ("detach-suspend-count", no_class
, show_task_detach_sc_cmd
,
3023 "Show the suspend count will leave on the thread when detaching.",
3024 &show_task_cmd_list
);
3026 add_cmd ("exception-port", no_class
, set_task_exc_port_cmd
,
3027 "Set the task exception port to which we forward exceptions.\n"
3028 "The argument should be the value of the send right in the task.",
3029 &set_task_cmd_list
);
3030 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_task_cmd_list
);
3031 add_alias_cmd ("exc-port", "exception-port", no_class
, 1, &set_task_cmd_list
);
3033 /* A convenient way of turning on all options require to noninvasively
3034 debug running tasks. */
3035 add_cmd ("noninvasive", no_class
, set_noninvasive_cmd
,
3036 "Set task options so that we interfere as little as possible.\n"
3037 "This is the same as setting `task pause', `exceptions', and"
3038 "`signals' to the opposite value.",
3041 /* Commands to show information about the task's ports. */
3042 add_cmd ("send-rights", class_info
, info_send_rights_cmd
,
3043 "Show information about the task's send rights",
3045 add_cmd ("receive-rights", class_info
, info_recv_rights_cmd
,
3046 "Show information about the task's receive rights",
3048 add_cmd ("port-rights", class_info
, info_send_rights_cmd
,
3049 "Show information about the task's port rights",
3051 add_cmd ("port-sets", class_info
, info_port_sets_cmd
,
3052 "Show information about the task's port sets",
3054 add_cmd ("dead-names", class_info
, info_dead_names_cmd
,
3055 "Show information about the task's dead names",
3057 add_info_alias ("ports", "port-rights", 1);
3058 add_info_alias ("port", "port-rights", 1);
3059 add_info_alias ("psets", "port-sets", 1);
3064 set_thread_pause_cmd (char *args
, int from_tty
)
3066 struct proc
*thread
= cur_thread ();
3067 int old_sc
= thread
->pause_sc
;
3068 thread
->pause_sc
= parse_bool_arg (args
, "set thread pause");
3069 if (old_sc
== 0 && thread
->pause_sc
!= 0 && thread
->inf
->pause_sc
== 0)
3070 /* If the task is currently unsuspended, immediately suspend it,
3071 otherwise wait until the next time it gets control. */
3072 inf_suspend (thread
->inf
);
3076 show_thread_pause_cmd (char *args
, int from_tty
)
3078 struct proc
*thread
= cur_thread ();
3079 int sc
= thread
->pause_sc
;
3080 check_empty (args
, "show task pause");
3081 printf_unfiltered ("Thread %s %s suspended while gdb has control%s.\n",
3082 proc_string (thread
),
3083 sc
? "is" : "isn't",
3084 !sc
&& thread
->inf
->pause_sc
? " (but the task is)" : "");
3088 set_thread_run_cmd (char *args
, int from_tty
)
3090 struct proc
*thread
= cur_thread ();
3091 thread
->run_sc
= parse_bool_arg (args
, "set thread run") ? 0 : 1;
3095 show_thread_run_cmd (char *args
, int from_tty
)
3097 struct proc
*thread
= cur_thread ();
3098 check_empty (args
, "show thread run");
3099 printf_unfiltered ("Thread %s %s allowed to run.",
3100 proc_string (thread
),
3101 thread
->run_sc
== 0 ? "is" : "isn't");
3105 set_thread_detach_sc_cmd (char *args
, int from_tty
)
3107 cur_thread ()->detach_sc
= parse_int_arg (args
, "set thread detach-suspend-count");
3111 show_thread_detach_sc_cmd (char *args
, int from_tty
)
3113 struct proc
*thread
= cur_thread ();
3114 check_empty (args
, "show thread detach-suspend-count");
3115 printf_unfiltered ("Thread %s will be left with a suspend count of %d when detaching.\n",
3116 proc_string (thread
),
3121 set_thread_exc_port_cmd (char *args
, int from_tty
)
3123 struct proc
*thread
= cur_thread ();
3125 error ("No argument to \"set thread exception-port\" command.");
3126 steal_exc_port (thread
, parse_and_eval_address (args
));
3131 show_thread_cmd (char *args
, int from_tty
)
3133 struct proc
*thread
= cur_thread ();
3134 check_empty (args
, "show thread");
3135 show_thread_run_cmd (0, from_tty
);
3136 show_thread_pause_cmd (0, from_tty
);
3137 if (thread
->detach_sc
!= 0)
3138 show_thread_detach_sc_cmd (0, from_tty
);
3143 thread_takeover_sc_cmd (char *args
, int from_tty
)
3145 struct proc
*thread
= cur_thread ();
3146 thread_basic_info_data_t _info
;
3147 thread_basic_info_t info
= &_info
;
3148 mach_msg_type_number_t info_len
= THREAD_BASIC_INFO_COUNT
;
3150 thread_info (thread
->port
, THREAD_BASIC_INFO
, (int *)&info
, &info_len
);
3152 error ("%s.", strerror (err
));
3153 thread
->sc
= info
->suspend_count
;
3155 printf_unfiltered ("Suspend count was %d.\n", thread
->sc
);
3157 vm_deallocate (mach_task_self (), (vm_address_t
)info
, info_len
* sizeof (int));
3160 add_thread_commands ()
3162 add_prefix_cmd ("thread", no_class
, set_thread_cmd
,
3163 "Command prefix for setting thread properties.",
3164 &set_thread_cmd_list
, "set thread ", 0, &setlist
);
3165 add_prefix_cmd ("default", no_class
, show_thread_cmd
,
3166 "Command prefix for setting default thread properties.",
3167 &set_thread_default_cmd_list
, "set thread default ", 0,
3168 &set_thread_cmd_list
);
3169 add_prefix_cmd ("thread", no_class
, set_thread_default_cmd
,
3170 "Command prefix for showing thread properties.",
3171 &show_thread_cmd_list
, "show thread ", 0, &showlist
);
3172 add_prefix_cmd ("default", no_class
, show_thread_default_cmd
,
3173 "Command prefix for showing default thread properties.",
3174 &show_thread_default_cmd_list
, "show thread default ", 0,
3175 &show_thread_cmd_list
);
3177 add_cmd ("pause", class_run
, set_thread_pause_cmd
,
3178 "Set whether the current thread is suspended while gdb has control.\n"
3179 "A value of \"on\" takes effect immediately, otherwise nothing\n"
3180 "happens until the next time the program is continued. This\n"
3181 "property normally has no effect because the whole task is suspended,\n"
3182 "however, that may be disabled with \"set task pause off\".\n"
3183 "The default value is \"off\".",
3184 &set_thread_cmd_list
);
3185 add_cmd ("pause", no_class
, show_thread_pause_cmd
,
3186 "Show whether the current thread is suspended while gdb has control.",
3187 &show_thread_cmd_list
);
3189 add_cmd ("run", class_run
, set_thread_run_cmd
,
3190 "Set whether the current thread is allowed to run.",
3191 &set_thread_cmd_list
);
3192 add_cmd ("run", no_class
, show_thread_run_cmd
,
3193 "Show whether the current thread is allowed to run.",
3194 &show_thread_cmd_list
);
3196 add_cmd ("detach-suspend-count", class_run
, set_thread_detach_sc_cmd
,
3197 "Set the suspend count will leave on the thread when detaching.\n"
3198 "Note that this is relative to suspend count when gdb noticed the thread;\n"
3199 "use the `thread takeover-suspend-count' to force it to an absolute value.",
3200 &set_thread_cmd_list
);
3201 add_cmd ("detach-suspend-count", no_class
, show_thread_detach_sc_cmd
,
3202 "Show the suspend count will leave on the thread when detaching."
3203 "Note that this is relative to suspend count when gdb noticed the thread;\n"
3204 "use the `thread takeover-suspend-count' to force it to an absolute value.",
3205 &show_thread_cmd_list
);
3207 add_cmd ("exception-port", no_class
, set_thread_exc_port_cmd
,
3208 "Set the exception port to which we forward exceptions for the\n"
3209 "current thread, overriding the task exception port.\n"
3210 "The argument should be the value of the send right in the task.",
3211 &set_thread_cmd_list
);
3212 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3213 add_alias_cmd ("exc-port", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3215 add_cmd ("takeover-suspend-count", no_class
, thread_takeover_sc_cmd
,
3216 "Force the threads absolute suspend-count to be gdb's.\n"
3217 "Prior to giving this command, gdb's thread suspend-counts are relative to\n"
3218 "the thread's initial suspend-count when gdb notices the threads.",
3223 _initialize_gnu_nat ()
3225 proc_server
= getproc ();
3227 add_target (&gnu_ops
);
3228 add_task_commands ();
3229 add_thread_commands ();
3231 add_set_cmd ("gnu-debug", class_maintenance
,
3232 var_boolean
, (char *)&gnu_debug_flag
,
3233 "Set debugging output for the gnu backend.", &maintenancelist
);
3236 #ifdef FLUSH_INFERIOR_CACHE
3238 /* When over-writing code on some machines the I-Cache must be flushed
3239 explicitly, because it is not kept coherent by the lazy hardware.
3240 This definitely includes breakpoints, for instance, or else we
3241 end up looping in mysterious Bpt traps */
3244 flush_inferior_icache(pc
, amount
)
3247 vm_machine_attribute_val_t flush
= MATTR_VAL_ICACHE_FLUSH
;
3250 ret
= vm_machine_attribute (current_inferior
->task
->port
,
3255 if (ret
!= KERN_SUCCESS
)
3256 warning ("Error flushing inferior's cache : %s", strerror (ret
));
3258 #endif FLUSH_INFERIOR_CACHE