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,
23 Boston, MA 02111-1307, USA.
33 #include <sys/ptrace.h>
35 /* We include this because we don't need the access macros and they conflict
36 with gdb's definitions (ick). This is very non standard! */
37 #define _SYS_WAIT_H /* Inhibit warning from <bits/waitflags.h>. */
38 #include <bits/waitflags.h>
41 #include <mach/message.h>
42 #include <mach/notify.h>
43 #include <mach_error.h>
44 #include <mach/exception.h>
45 #include <mach/vm_attributes.h>
47 #include <hurd/process.h>
48 #include <hurd/process_request.h>
50 #include <hurd/msg_request.h>
51 #include <hurd/signal.h>
52 #include <hurd/interrupt.h>
53 #include <hurd/sigpreempt.h>
69 #include "exc_request_S.h"
71 #include "process_reply_S.h"
72 #include "msg_reply_S.h"
73 #include "exc_request_U.h"
76 static process_t proc_server
= MACH_PORT_NULL
;
78 /* If we've sent a proc_wait_request to the proc server, the pid of the
79 process we asked about. We can only ever have one outstanding. */
80 int proc_wait_pid
= 0;
82 /* The number of wait requests we've sent, and expect replies from. */
83 int proc_waits_pending
= 0;
85 int gnu_debug_flag
= 0;
89 extern struct target_ops gnu_ops
;
91 struct inf
*make_inf ();
92 void inf_clear_wait (struct inf
*inf
);
93 void inf_cleanup (struct inf
*inf
);
94 void inf_startup (struct inf
*inf
, int pid
);
95 int inf_update_suspends (struct inf
*inf
);
96 void inf_set_pid (struct inf
*inf
, pid_t pid
);
97 void inf_validate_procs (struct inf
*inf
);
98 void inf_steal_exc_ports (struct inf
*inf
);
99 void inf_restore_exc_ports (struct inf
*inf
);
100 struct proc
*inf_tid_to_proc (struct inf
*inf
, int tid
);
101 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 struct proc
*make_proc (struct inf
*inf
, mach_port_t port
, int tid
);
119 struct proc
*_proc_free (struct proc
*proc
);
120 int proc_update_sc (struct proc
*proc
);
121 error_t
proc_get_exception_port (struct proc
*proc
, mach_port_t
* port
);
122 error_t
proc_set_exception_port (struct proc
*proc
, mach_port_t port
);
123 static mach_port_t
_proc_get_exc_port (struct proc
*proc
);
124 void proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
);
125 void proc_restore_exc_port (struct proc
*proc
);
126 int proc_trace (struct proc
*proc
, int set
);
128 /* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
129 to INF's msg port and task port respectively. If it has no msg port,
130 EIEIO is returned. INF must refer to a running process! */
131 #define INF_MSGPORT_RPC(inf, rpc_expr) \
132 HURD_MSGPORT_RPC (proc_getmsgport (proc_server, inf->pid, &msgport), \
133 (refport = inf->task->port, 0), 0, \
134 msgport ? (rpc_expr) : EIEIO)
136 /* Like INF_MSGPORT_RPC, but will also resume the signal thread to ensure
137 there's someone around to deal with the RPC (and resuspend things
138 afterwards). This effects INF's threads' resume_sc count. */
139 #define INF_RESUME_MSGPORT_RPC(inf, rpc_expr) \
140 (inf_set_threads_resume_sc_for_signal_thread (inf) \
143 __e = INF_MSGPORT_RPC (inf, rpc_expr); \
148 #define MIG_SERVER_DIED EMIG_SERVER_DIED /* XXX */
150 /* The state passed by an exception message. */
153 int exception
; /* The exception code */
155 mach_port_t handler
; /* The real exception port to handle this. */
156 mach_port_t reply
; /* The reply port from the exception call. */
159 /* The results of the last wait an inf did. */
162 struct target_waitstatus status
; /* The status returned to gdb. */
163 struct exc_state exc
; /* The exception that caused us to return. */
164 struct proc
*thread
; /* The thread in question. */
165 int suppress
; /* Something trivial happened. */
168 /* The state of an inferior. */
171 /* Fields describing the current inferior. */
173 struct proc
*task
; /* The mach task. */
174 struct proc
*threads
; /* A linked list of all threads in TASK. */
176 /* True if THREADS needn't be validated by querying the task. We assume that
177 we and the task in question are the only ones frobbing the thread list,
178 so as long as we don't let any code run, we don't have to worry about
180 int threads_up_to_date
;
182 pid_t pid
; /* The real system PID. */
184 struct inf_wait wait
; /* What to return from target_wait. */
186 /* One thread proc in INF may be in `single-stepping mode'. This is it. */
187 struct proc
*step_thread
;
189 /* The thread we think is the signal thread. */
190 struct proc
*signal_thread
;
192 mach_port_t event_port
; /* Where we receive various msgs. */
194 /* True if we think at least one thread in the inferior could currently be
196 unsigned int running
:1;
198 /* True if the process has stopped (in the proc server sense). Note that
199 since a proc server `stop' leaves the signal thread running, the inf can
200 be RUNNING && STOPPED... */
201 unsigned int stopped
:1;
203 /* True if the inferior has no message port. */
204 unsigned int nomsg
:1;
206 /* True if the inferior is traced. */
207 unsigned int traced
:1;
209 /* True if we shouldn't try waiting for the inferior, usually because we
210 can't for some reason. */
211 unsigned int no_wait
:1;
213 /* When starting a new inferior, we don't try to validate threads until all
214 the proper execs have been done. This is a count of how many execs we
216 unsigned pending_execs
;
218 /* Fields describing global state */
220 /* The task suspend count used when gdb has control. This is normally 1 to
221 make things easier for us, but sometimes (like when attaching to vital
222 system servers) it may be desirable to let the task continue to run
223 (pausing individual threads as necessary). */
226 /* The task suspend count left when detaching from a task. */
229 /* The initial values used for the run_sc and pause_sc of newly discovered
230 threads -- see the definition of those fields in struct proc. */
231 int default_thread_run_sc
;
232 int default_thread_pause_sc
;
233 int default_thread_detach_sc
;
235 /* True if the process should be traced when started/attached. Newly
236 started processes *must* be traced at first to exec them properly, but
237 if this is false, tracing is turned off as soon it has done so. */
240 /* True if exceptions from the inferior process should be trapped. This
241 must be on to use breakpoints. */
247 __proc_pid (struct proc
*proc
)
249 return proc
->inf
->pid
;
252 /* Update PROC's real suspend count to match it's desired one. Returns true
253 if we think PROC is now in a runnable state. */
255 proc_update_sc (struct proc
*proc
)
259 int delta
= proc
->sc
- proc
->cur_sc
;
262 proc_debug (proc
, "sc: %d --> %d", proc
->cur_sc
, proc
->sc
);
264 if (proc
->sc
== 0 && proc
->state_changed
)
265 /* Since PROC may start running, we must write back any state changes. */
267 assert (proc_is_thread (proc
));
268 proc_debug (proc
, "storing back changed thread state");
269 err
= thread_set_state (proc
->port
, THREAD_STATE_FLAVOR
,
270 (thread_state_t
) & proc
->state
, THREAD_STATE_SIZE
);
272 proc
->state_changed
= 0;
276 while (delta
-- > 0 && !err
)
277 if (proc_is_task (proc
))
278 err
= task_suspend (proc
->port
);
280 err
= thread_suspend (proc
->port
);
282 while (delta
++ < 0 && !err
)
283 if (proc_is_task (proc
))
284 err
= task_resume (proc
->port
);
286 err
= thread_resume (proc
->port
);
289 proc
->cur_sc
= proc
->sc
;
291 /* If we got an error, then the task/thread has disappeared. */
292 running
= !err
&& proc
->sc
== 0;
294 proc_debug (proc
, "is %s", err
? "dead" : running
? "running" : "suspended");
296 proc_debug (proc
, "err = %s", strerror (err
));
301 proc
->state_valid
= proc
->state_changed
= 0;
302 proc
->fetched_regs
= 0;
308 /* Thread_abort is called on PROC if needed. PROC must be a thread proc.
309 If PROC is deemed `precious', then nothing is done unless FORCE is true.
310 In particular, a thread is precious if it's running (in which case forcing
311 it includes suspending it first), or if it has an exception pending. */
313 proc_abort (struct proc
*proc
, int force
)
315 assert (proc_is_thread (proc
));
319 struct inf
*inf
= proc
->inf
;
320 int running
= (proc
->cur_sc
== 0 && inf
->task
->cur_sc
== 0);
322 if (running
&& force
)
325 inf_update_suspends (proc
->inf
);
327 warning ("Stopped %s.", proc_string (proc
));
329 else if (proc
== inf
->wait
.thread
&& inf
->wait
.exc
.reply
&& !force
)
330 /* An exception is pending on PROC, which don't mess with. */
334 /* We only abort the thread if it's not actually running. */
336 thread_abort (proc
->port
);
337 proc_debug (proc
, "aborted");
341 proc_debug (proc
, "not aborting");
345 /* Make sure that the state field in PROC is up to date, and return a pointer
346 to it, or 0 if something is wrong. If WILL_MODIFY is true, makes sure
347 that the thread is stopped and aborted first, and sets the state_changed
348 field in PROC to true. */
350 proc_get_state (struct proc
*proc
, int will_modify
)
352 int was_aborted
= proc
->aborted
;
354 proc_debug (proc
, "updating state info%s",
355 will_modify
? " (with intention to modify)" : "");
357 proc_abort (proc
, will_modify
);
359 if (!was_aborted
&& proc
->aborted
)
360 /* PROC's state may have changed since we last fetched it. */
361 proc
->state_valid
= 0;
363 if (!proc
->state_valid
)
365 mach_msg_type_number_t state_size
= THREAD_STATE_SIZE
;
367 thread_get_state (proc
->port
, THREAD_STATE_FLAVOR
,
368 (thread_state_t
) & proc
->state
, &state_size
);
369 proc_debug (proc
, "getting thread state");
370 proc
->state_valid
= !err
;
373 if (proc
->state_valid
)
376 proc
->state_changed
= 1;
377 return (thread_state_t
) & proc
->state
;
383 /* Set PORT to PROC's exception port. */
385 proc_get_exception_port (struct proc
* proc
, mach_port_t
* port
)
387 if (proc_is_task (proc
))
388 return task_get_exception_port (proc
->port
, port
);
390 return thread_get_exception_port (proc
->port
, port
);
393 /* Set PROC's exception port to PORT. */
395 proc_set_exception_port (struct proc
* proc
, mach_port_t port
)
397 proc_debug (proc
, "setting exception port: %d", port
);
398 if (proc_is_task (proc
))
399 return task_set_exception_port (proc
->port
, port
);
401 return thread_set_exception_port (proc
->port
, port
);
404 /* Get PROC's exception port, cleaning up a bit if proc has died. */
406 _proc_get_exc_port (struct proc
*proc
)
408 mach_port_t exc_port
;
409 error_t err
= proc_get_exception_port (proc
, &exc_port
);
412 /* PROC must be dead. */
415 mach_port_deallocate (mach_task_self (), proc
->exc_port
);
416 proc
->exc_port
= MACH_PORT_NULL
;
417 if (proc
->saved_exc_port
)
418 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
419 proc
->saved_exc_port
= MACH_PORT_NULL
;
425 /* Replace PROC's exception port with EXC_PORT, unless it's already been
426 done. Stash away any existing exception port so we can restore it later. */
428 proc_steal_exc_port (struct proc
*proc
, mach_port_t exc_port
)
430 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
436 proc_debug (proc
, "inserting exception port: %d", exc_port
);
438 if (cur_exc_port
!= exc_port
)
439 /* Put in our exception port. */
440 err
= proc_set_exception_port (proc
, exc_port
);
442 if (err
|| cur_exc_port
== proc
->exc_port
)
443 /* We previously set the exception port, and it's still set. So we
444 just keep the old saved port which is what the proc set. */
447 mach_port_deallocate (mach_task_self (), cur_exc_port
);
450 /* Keep a copy of PROC's old exception port so it can be restored. */
452 if (proc
->saved_exc_port
)
453 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
454 proc
->saved_exc_port
= cur_exc_port
;
457 proc_debug (proc
, "saved exception port: %d", proc
->saved_exc_port
);
460 proc
->exc_port
= exc_port
;
462 warning ("Error setting exception port for %s: %s",
463 proc_string (proc
), strerror (err
));
467 /* If we previously replaced PROC's exception port, put back what we
468 found there at the time, unless *our* exception port has since been
469 overwritten, in which case who knows what's going on. */
471 proc_restore_exc_port (struct proc
*proc
)
473 mach_port_t cur_exc_port
= _proc_get_exc_port (proc
);
479 proc_debug (proc
, "restoring real exception port");
481 if (proc
->exc_port
== cur_exc_port
)
482 /* Our's is still there. */
483 err
= proc_set_exception_port (proc
, proc
->saved_exc_port
);
485 if (proc
->saved_exc_port
)
486 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
487 proc
->saved_exc_port
= MACH_PORT_NULL
;
490 proc
->exc_port
= MACH_PORT_NULL
;
492 warning ("Error setting exception port for %s: %s",
493 proc_string (proc
), strerror (err
));
497 /* Turns hardware tracing in PROC on or off when SET is true or false,
498 respectively. Returns true on success. */
500 proc_trace (struct proc
*proc
, int set
)
502 thread_state_t state
= proc_get_state (proc
, 1);
505 return 0; /* the thread must be dead. */
507 proc_debug (proc
, "tracing %s", set
? "on" : "off");
511 /* XXX We don't get the exception unless the thread has its own
512 exception port???? */
513 if (proc
->exc_port
== MACH_PORT_NULL
)
514 proc_steal_exc_port (proc
, proc
->inf
->event_port
);
515 THREAD_STATE_SET_TRACED (state
);
518 THREAD_STATE_CLEAR_TRACED (state
);
523 /* A variable from which to assign new TIDs. */
524 static int next_thread_id
= 1;
526 /* Returns a new proc structure with the given fields. Also adds a
527 notification for PORT becoming dead to be sent to INF's notify port. */
529 make_proc (struct inf
*inf
, mach_port_t port
, int tid
)
532 mach_port_t prev_port
= MACH_PORT_NULL
;
533 struct proc
*proc
= malloc (sizeof (struct proc
));
539 proc
->saved_exc_port
= MACH_PORT_NULL
;
540 proc
->exc_port
= MACH_PORT_NULL
;
545 /* Note that these are all the values for threads; the task simply uses the
546 corresponding field in INF directly. */
547 proc
->run_sc
= inf
->default_thread_run_sc
;
548 proc
->pause_sc
= inf
->default_thread_pause_sc
;
549 proc
->detach_sc
= inf
->default_thread_detach_sc
;
550 proc
->resume_sc
= proc
->run_sc
;
554 proc
->state_valid
= 0;
555 proc
->state_changed
= 0;
557 proc_debug (proc
, "is new");
559 /* Get notified when things die. */
561 mach_port_request_notification (mach_task_self (), port
,
562 MACH_NOTIFY_DEAD_NAME
, 1,
564 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
567 warning ("Couldn't request notification for port %d: %s",
568 port
, strerror (err
));
571 proc_debug (proc
, "notifications to: %d", inf
->event_port
);
572 if (prev_port
!= MACH_PORT_NULL
)
573 mach_port_deallocate (mach_task_self (), prev_port
);
576 if (inf
->want_exceptions
)
577 if (proc_is_task (proc
))
578 /* Make the task exception port point to us. */
579 proc_steal_exc_port (proc
, inf
->event_port
);
581 /* Just clear thread exception ports -- they default to the task one. */
582 proc_steal_exc_port (proc
, MACH_PORT_NULL
);
587 /* Frees PROC and any resources it uses, and returns the value of PROC's
590 _proc_free (struct proc
*proc
)
592 struct inf
*inf
= proc
->inf
;
593 struct proc
*next
= proc
->next
;
595 proc_debug (proc
, "freeing...");
597 if (proc
== inf
->step_thread
)
598 /* Turn off single stepping. */
599 inf_set_step_thread (inf
, 0);
600 if (proc
== inf
->wait
.thread
)
601 inf_clear_wait (inf
);
602 if (proc
== inf
->signal_thread
)
603 inf
->signal_thread
= 0;
605 if (proc
->port
!= MACH_PORT_NULL
)
607 if (proc
->exc_port
!= MACH_PORT_NULL
)
608 /* Restore the original exception port. */
609 proc_restore_exc_port (proc
);
610 if (proc
->cur_sc
!= 0)
611 /* Resume the thread/task. */
614 proc_update_sc (proc
);
616 mach_port_deallocate (mach_task_self (), proc
->port
);
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. */
1203 inf_steal_exc_ports (struct inf
*inf
)
1205 struct proc
*thread
;
1207 inf_debug (inf
, "stealing exception ports");
1209 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1211 proc_steal_exc_port (inf
->task
, inf
->event_port
);
1212 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1213 proc_steal_exc_port (thread
, MACH_PORT_NULL
);
1216 /* Makes sure the process has its own exception ports. */
1218 inf_restore_exc_ports (struct inf
*inf
)
1220 struct proc
*thread
;
1222 inf_debug (inf
, "restoring exception ports");
1224 inf_set_step_thread (inf
, 0); /* The step thread is special. */
1226 proc_restore_exc_port (inf
->task
);
1227 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1228 proc_restore_exc_port (thread
);
1231 /* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
1232 signal 0, will continue it. INF is assumed to be in a paused state, and
1233 the resume_sc's of INF's threads may be affected. */
1235 inf_signal (struct inf
*inf
, enum target_signal sig
)
1238 int host_sig
= target_signal_to_host (sig
);
1240 #define NAME target_signal_to_name (sig)
1242 if (host_sig
>= _NSIG
)
1243 /* A mach exception. Exceptions are encoded in the signal space by
1244 putting them after _NSIG; this assumes they're positive (and not
1245 extremely large)! */
1247 struct inf_wait
*w
= &inf
->wait
;
1248 if (w
->status
.kind
== TARGET_WAITKIND_STOPPED
1249 && w
->status
.value
.sig
== sig
1250 && w
->thread
&& !w
->thread
->aborted
)
1251 /* We're passing through the last exception we received. This is
1252 kind of bogus, because exceptions are per-thread whereas gdb
1253 treats signals as per-process. We just forward the exception to
1254 the correct handler, even it's not for the same thread as TID --
1255 i.e., we pretend it's global. */
1257 struct exc_state
*e
= &w
->exc
;
1258 inf_debug (inf
, "passing through exception:"
1259 " task = %d, thread = %d, exc = %d"
1260 ", code = %d, subcode = %d",
1261 w
->thread
->port
, inf
->task
->port
,
1262 e
->exception
, e
->code
, e
->subcode
);
1264 exception_raise_request (e
->handler
,
1265 e
->reply
, MACH_MSG_TYPE_MOVE_SEND_ONCE
,
1266 w
->thread
->port
, inf
->task
->port
,
1267 e
->exception
, e
->code
, e
->subcode
);
1270 error ("Can't forward spontaneous exception (%s).", NAME
);
1273 /* A Unix signal. */
1275 /* The process is stopped and expecting a signal. Just send off a
1276 request and let it get handled when we resume everything. */
1278 inf_debug (inf
, "sending %s to stopped process", NAME
);
1280 INF_MSGPORT_RPC (inf
,
1281 msg_sig_post_untraced_request (msgport
,
1283 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
1287 /* Posting an untraced signal automatically continues it.
1288 We clear this here rather than when we get the reply
1289 because we'd rather assume it's not stopped when it
1290 actually is, than the reverse. */
1294 /* It's not expecting it. We have to let just the signal thread
1295 run, and wait for it to get into a reasonable state before we
1296 can continue the rest of the process. When we finally resume the
1297 process the signal we request will be the very first thing that
1300 inf_debug (inf
, "sending %s to unstopped process (so resuming signal thread)", NAME
);
1302 INF_RESUME_MSGPORT_RPC (inf
, msg_sig_post_untraced (msgport
,
1303 host_sig
, 0, refport
));
1307 /* Can't do too much... */
1308 warning ("Can't deliver signal %s: No signal thread.", NAME
);
1310 warning ("Delivering signal %s: %s", NAME
, strerror (err
));
1315 /* Continue INF without delivering a signal. This is meant to be used
1316 when INF does not have a message port. */
1318 inf_continue (struct inf
*inf
)
1321 error_t err
= proc_pid2proc (proc_server
, inf
->pid
, &proc
);
1325 inf_debug (inf
, "continuing process");
1327 err
= proc_mark_cont (proc
);
1330 struct proc
*thread
;
1332 for (thread
= inf
->threads
; thread
; thread
= thread
->next
)
1333 thread_resume (thread
->port
);
1340 warning ("Can't continue process: %s", strerror (err
));
1343 /* The inferior used for all gdb target ops. */
1344 struct inf
*current_inferior
= 0;
1346 /* The inferior being waited for by gnu_wait. Since GDB is decidely not
1347 multi-threaded, we don't bother to lock this. */
1348 struct inf
*waiting_inf
;
1350 /* Wait for something to happen in the inferior, returning what in STATUS. */
1352 gnu_wait (int tid
, struct target_waitstatus
*status
)
1356 mach_msg_header_t hdr
;
1357 mach_msg_type_t type
;
1362 struct proc
*thread
;
1363 struct inf
*inf
= current_inferior
;
1367 if (!inf
->threads
&& !inf
->pending_execs
)
1368 /* No threads! Assume that maybe some outside agency is frobbing our
1369 task, and really look for new threads. If we can't find any, just tell
1370 the user to try again later. */
1372 inf_validate_procs (inf
);
1373 if (!inf
->threads
&& !inf
->task
->dead
)
1374 error ("There are no threads; try again later.");
1379 inf_debug (inf
, "waiting for: %d", tid
);
1382 if (proc_wait_pid
!= inf
->pid
&& !inf
->no_wait
)
1383 /* Always get information on events from the proc server. */
1385 inf_debug (inf
, "requesting wait on pid %d", inf
->pid
);
1388 /* The proc server is single-threaded, and only allows a single
1389 outstanding wait request, so we have to cancel the previous one. */
1391 inf_debug (inf
, "cancelling previous wait on pid %d", proc_wait_pid
);
1392 interrupt_operation (proc_server
, 0);
1396 proc_wait_request (proc_server
, inf
->event_port
, inf
->pid
, WUNTRACED
);
1398 warning ("wait request failed: %s", strerror (err
));
1401 inf_debug (inf
, "waits pending: %d", proc_waits_pending
);
1402 proc_wait_pid
= inf
->pid
;
1403 /* Even if proc_waits_pending was > 0 before, we still won't get
1404 any other replies, because it was either from a different INF,
1405 or a different process attached to INF -- and the event port,
1406 which is the wait reply port, changes when you switch processes. */
1407 proc_waits_pending
= 1;
1411 inf_clear_wait (inf
);
1413 /* What can happen? (1) Dead name notification; (2) Exceptions arrive;
1414 (3) wait reply from the proc server. */
1416 inf_debug (inf
, "waiting for an event...");
1417 err
= mach_msg (&msg
.hdr
, MACH_RCV_MSG
| MACH_RCV_INTERRUPT
,
1418 0, sizeof (struct msg
), inf
->event_port
,
1419 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
1421 /* Re-suspend the task. */
1424 if (!inf
->task
&& inf
->pending_execs
)
1425 /* When doing an exec, it's possible that the old task wasn't reused
1426 (e.g., setuid execs). So if the task seems to have disappeared,
1427 attempt to refetch it, as the pid should still be the same. */
1428 inf_set_pid (inf
, inf
->pid
);
1430 if (err
== EMACH_RCV_INTERRUPTED
)
1431 inf_debug (inf
, "interrupted");
1433 error ("Couldn't wait for an event: %s", strerror (err
));
1438 mach_msg_header_t hdr
;
1439 mach_msg_type_t err_type
;
1445 inf_debug (inf
, "event: msgid = %d", msg
.hdr
.msgh_id
);
1447 /* Handle what we got. */
1448 if (!notify_server (&msg
.hdr
, &reply
.hdr
)
1449 && !exc_server (&msg
.hdr
, &reply
.hdr
)
1450 && !process_reply_server (&msg
.hdr
, &reply
.hdr
)
1451 && !msg_reply_server (&msg
.hdr
, &reply
.hdr
))
1452 /* Whatever it is, it's something strange. */
1453 error ("Got a strange event, msg id = %d.", msg
.hdr
.msgh_id
);
1456 error ("Handling event, msgid = %d: %s",
1457 msg
.hdr
.msgh_id
, strerror (reply
.err
));
1460 if (inf
->pending_execs
)
1461 /* We're waiting for the inferior to finish execing. */
1463 struct inf_wait
*w
= &inf
->wait
;
1464 enum target_waitkind kind
= w
->status
.kind
;
1466 if (kind
== TARGET_WAITKIND_SPURIOUS
)
1467 /* Since gdb is actually counting the number of times the inferior
1468 stops, expecting one stop per exec, we only return major events
1472 inf_debug (inf
, "pending_execs = %d, ignoring minor event",
1473 inf
->pending_execs
);
1475 else if (kind
== TARGET_WAITKIND_STOPPED
1476 && w
->status
.value
.sig
== TARGET_SIGNAL_TRAP
)
1477 /* Ah hah! A SIGTRAP from the inferior while starting up probably
1478 means we've succesfully completed an exec! */
1480 if (--inf
->pending_execs
== 0)
1483 #if 0 /* do we need this? */
1484 prune_threads (1); /* Get rid of the old shell threads */
1485 renumber_threads (0); /* Give our threads reasonable names. */
1488 inf_debug (inf
, "pending exec completed, pending_execs => %d",
1489 inf
->pending_execs
);
1491 else if (kind
== TARGET_WAITKIND_STOPPED
)
1492 /* It's possible that this signal is because of a crashed process
1493 being handled by the hurd crash server; in this case, the process
1494 will have an extra task suspend, which we need to know about.
1495 Since the code in inf_resume that normally checks for this is
1496 disabled while INF->pending_execs, we do the check here instead. */
1497 inf_validate_task_sc (inf
);
1500 if (inf
->wait
.suppress
)
1501 /* Some totally spurious event happened that we don't consider
1502 worth returning to gdb. Just keep waiting. */
1504 inf_debug (inf
, "suppressing return, rewaiting...");
1509 /* Pass back out our results. */
1510 bcopy (&inf
->wait
.status
, status
, sizeof (*status
));
1512 thread
= inf
->wait
.thread
;
1516 thread
= inf_tid_to_thread (inf
, tid
);
1518 if (!thread
|| thread
->port
== MACH_PORT_NULL
)
1519 /* TID is dead; try and find a new thread. */
1520 if (inf_update_procs (inf
) && inf
->threads
)
1521 tid
= inf
->threads
->tid
; /* The first available thread. */
1523 tid
= inferior_pid
; /* let wait_for_inferior handle exit case */
1525 if (thread
&& tid
>= 0 && status
->kind
!= TARGET_WAITKIND_SPURIOUS
1526 && inf
->pause_sc
== 0 && thread
->pause_sc
== 0)
1527 /* If something actually happened to THREAD, make sure we suspend it. */
1530 inf_update_suspends (inf
);
1533 inf_debug (inf
, "returning tid = %d, status = %s (%d)", tid
,
1534 status
->kind
== TARGET_WAITKIND_EXITED
? "EXITED"
1535 : status
->kind
== TARGET_WAITKIND_STOPPED
? "STOPPED"
1536 : status
->kind
== TARGET_WAITKIND_SIGNALLED
? "SIGNALLED"
1537 : status
->kind
== TARGET_WAITKIND_LOADED
? "LOADED"
1538 : status
->kind
== TARGET_WAITKIND_SPURIOUS
? "SPURIOUS"
1540 status
->value
.integer
);
1545 /* The rpc handler called by exc_server. */
1547 S_exception_raise_request (mach_port_t port
, mach_port_t reply_port
,
1548 thread_t thread_port
, task_t task_port
,
1549 int exception
, int code
, int subcode
)
1551 struct inf
*inf
= waiting_inf
;
1552 struct proc
*thread
= inf_port_to_thread (inf
, thread_port
);
1554 inf_debug (waiting_inf
,
1555 "thread = %d, task = %d, exc = %d, code = %d, subcode = %d",
1556 thread_port
, task_port
, exception
, code
);
1559 /* We don't know about thread? */
1561 inf_update_procs (inf
);
1562 thread
= inf_port_to_thread (inf
, thread_port
);
1564 /* Give up, the generating thread is gone. */
1568 mach_port_deallocate (mach_task_self (), thread_port
);
1569 mach_port_deallocate (mach_task_self (), task_port
);
1571 if (!thread
->aborted
)
1572 /* THREAD hasn't been aborted since this exception happened (abortion
1573 clears any exception state), so it must be real. */
1575 /* Store away the details; this will destroy any previous info. */
1576 inf
->wait
.thread
= thread
;
1578 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1580 if (exception
== EXC_BREAKPOINT
)
1581 /* GDB likes to get SIGTRAP for breakpoints. */
1583 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_TRAP
;
1584 mach_port_deallocate (mach_task_self (), reply_port
);
1587 /* Record the exception so that we can forward it later. */
1589 if (thread
->exc_port
== port
)
1591 inf_debug (waiting_inf
, "Handler is thread exeption port <%d>",
1592 thread
->saved_exc_port
);
1593 inf
->wait
.exc
.handler
= thread
->saved_exc_port
;
1597 inf_debug (waiting_inf
, "Handler is task exeption port <%d>",
1598 inf
->task
->saved_exc_port
);
1599 inf
->wait
.exc
.handler
= inf
->task
->saved_exc_port
;
1600 assert (inf
->task
->exc_port
== port
);
1602 if (inf
->wait
.exc
.handler
!= MACH_PORT_NULL
)
1603 /* Add a reference to the exception handler. */
1604 mach_port_mod_refs (mach_task_self (),
1605 inf
->wait
.exc
.handler
, MACH_PORT_RIGHT_SEND
,
1608 inf
->wait
.exc
.exception
= exception
;
1609 inf
->wait
.exc
.code
= code
;
1610 inf
->wait
.exc
.subcode
= subcode
;
1611 inf
->wait
.exc
.reply
= reply_port
;
1613 /* Exceptions are encoded in the signal space by putting them after
1614 _NSIG; this assumes they're positive (and not extremely large)! */
1615 inf
->wait
.status
.value
.sig
=
1616 target_signal_from_host (_NSIG
+ exception
);
1620 /* A supppressed exception, which ignore. */
1622 inf
->wait
.suppress
= 1;
1623 mach_port_deallocate (mach_task_self (), reply_port
);
1629 /* Fill in INF's wait field after a task has died without giving us more
1630 detailed information. */
1632 inf_task_died_status (struct inf
*inf
)
1634 warning ("Pid %d died with unknown exit status, using SIGKILL.", inf
->pid
);
1635 inf
->wait
.status
.kind
= TARGET_WAITKIND_SIGNALLED
;
1636 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_KILL
;
1639 /* Notify server routines. The only real one is dead name notification. */
1641 do_mach_notify_dead_name (mach_port_t notify
, mach_port_t dead_port
)
1643 struct inf
*inf
= waiting_inf
;
1645 inf_debug (waiting_inf
, "port = %d", dead_port
);
1647 if (inf
->task
&& inf
->task
->port
== dead_port
)
1649 proc_debug (inf
->task
, "is dead");
1650 inf
->task
->port
= MACH_PORT_NULL
;
1651 if (proc_wait_pid
== inf
->pid
)
1652 /* We have a wait outstanding on the process, which will return more
1653 detailed information, so delay until we get that. */
1654 inf
->wait
.suppress
= 1;
1656 /* We never waited for the process (maybe it wasn't a child), so just
1657 pretend it got a SIGKILL. */
1658 inf_task_died_status (inf
);
1662 struct proc
*thread
= inf_port_to_thread (inf
, dead_port
);
1665 proc_debug (thread
, "is dead");
1666 thread
->port
= MACH_PORT_NULL
;
1670 mach_port_deallocate (mach_task_self (), dead_port
);
1671 inf
->threads_up_to_date
= 0; /* Just in case */
1679 warning ("illegal rpc: %s", fun
);
1684 do_mach_notify_no_senders (mach_port_t notify
, mach_port_mscount_t count
)
1686 return ill_rpc (__FUNCTION__
);
1690 do_mach_notify_port_deleted (mach_port_t notify
, mach_port_t name
)
1692 return ill_rpc (__FUNCTION__
);
1696 do_mach_notify_msg_accepted (mach_port_t notify
, mach_port_t name
)
1698 return ill_rpc (__FUNCTION__
);
1702 do_mach_notify_port_destroyed (mach_port_t notify
, mach_port_t name
)
1704 return ill_rpc (__FUNCTION__
);
1708 do_mach_notify_send_once (mach_port_t notify
)
1710 return ill_rpc (__FUNCTION__
);
1713 /* Process_reply server routines. We only use process_wait_reply. */
1716 S_proc_wait_reply (mach_port_t reply
, error_t err
,
1717 int status
, int sigcode
, rusage_t rusage
, pid_t pid
)
1719 struct inf
*inf
= waiting_inf
;
1721 inf_debug (inf
, "err = %s, pid = %d, status = 0x%x, sigcode = %d",
1722 err
? strerror (err
) : "0", pid
, status
, sigcode
);
1724 if (err
&& proc_wait_pid
&& (!inf
->task
|| !inf
->task
->port
))
1725 /* Ack. The task has died, but the task-died notification code didn't
1726 tell anyone because it thought a more detailed reply from the
1727 procserver was forthcoming. However, we now learn that won't
1728 happen... So we have to act like the task just died, and this time,
1730 inf_task_died_status (inf
);
1732 if (--proc_waits_pending
== 0)
1733 /* PROC_WAIT_PID represents the most recent wait. We will always get
1734 replies in order because the proc server is single threaded. */
1737 inf_debug (inf
, "waits pending now: %d", proc_waits_pending
);
1743 warning ("Can't wait for pid %d: %s", inf
->pid
, strerror (err
));
1746 /* Since we can't see the inferior's signals, don't trap them. */
1747 inf_set_traced (inf
, 0);
1750 else if (pid
== inf
->pid
)
1752 store_waitstatus (&inf
->wait
.status
, status
);
1753 if (inf
->wait
.status
.kind
== TARGET_WAITKIND_STOPPED
)
1754 /* The process has sent us a signal, and stopped itself in a sane
1755 state pending our actions. */
1757 inf_debug (inf
, "process has stopped itself");
1762 inf
->wait
.suppress
= 1; /* Something odd happened. Ignore. */
1768 S_proc_setmsgport_reply (mach_port_t reply
, error_t err
,
1769 mach_port_t old_msg_port
)
1771 return ill_rpc (__FUNCTION__
);
1775 S_proc_getmsgport_reply (mach_port_t reply
, error_t err
, mach_port_t msg_port
)
1777 return ill_rpc (__FUNCTION__
);
1780 /* Msg_reply server routines. We only use msg_sig_post_untraced_reply. */
1783 S_msg_sig_post_untraced_reply (mach_port_t reply
, error_t err
)
1785 struct inf
*inf
= waiting_inf
;
1788 /* EBUSY is what we get when the crash server has grabbed control of the
1789 process and doesn't like what signal we tried to send it. Just act
1790 like the process stopped (using a signal of 0 should mean that the
1791 *next* time the user continues, it will pass signal 0, which the crash
1792 server should like). */
1794 inf
->wait
.status
.kind
= TARGET_WAITKIND_STOPPED
;
1795 inf
->wait
.status
.value
.sig
= TARGET_SIGNAL_0
;
1798 warning ("Signal delivery failed: %s", strerror (err
));
1801 /* We only get this reply when we've posted a signal to a process which we
1802 thought was stopped, and which we expected to continue after the signal.
1803 Given that the signal has failed for some reason, it's reasonable to
1804 assume it's still stopped. */
1807 inf
->wait
.suppress
= 1;
1813 S_msg_sig_post_reply (mach_port_t reply
, error_t err
)
1815 return ill_rpc (__FUNCTION__
);
1818 /* Returns the number of messages queued for the receive right PORT. */
1819 static mach_port_msgcount_t
1820 port_msgs_queued (mach_port_t port
)
1822 struct mach_port_status status
;
1824 mach_port_get_receive_status (mach_task_self (), port
, &status
);
1829 return status
.mps_msgcount
;
1832 /* Resume execution of the inferior process.
1834 If STEP is nonzero, single-step it.
1835 If SIGNAL is nonzero, give it that signal.
1838 -1 true Single step the current thread allowing other threads to run.
1839 -1 false Continue the current thread allowing other threads to run.
1840 X true Single step the given thread, don't allow any others to run.
1841 X false Continue the given thread, do not allow any others to run.
1842 (Where X, of course, is anything except -1)
1844 Note that a resume may not `take' if there are pending exceptions/&c
1845 still unprocessed from the last resume we did (any given resume may result
1846 in multiple events returned by wait).
1849 gnu_resume (int tid
, int step
, enum target_signal sig
)
1851 struct proc
*step_thread
= 0;
1852 struct inf
*inf
= current_inferior
;
1854 inf_debug (inf
, "tid = %d, step = %d, sig = %d", tid
, step
, sig
);
1856 inf_validate_procinfo (inf
);
1858 if (sig
!= TARGET_SIGNAL_0
|| inf
->stopped
)
1860 if (sig
== TARGET_SIGNAL_0
&& inf
->nomsg
)
1863 inf_signal (inf
, sig
);
1865 else if (inf
->wait
.exc
.reply
!= MACH_PORT_NULL
)
1866 /* We received an exception to which we have chosen not to forward, so
1867 abort the faulting thread, which will perhaps retake it. */
1869 proc_abort (inf
->wait
.thread
, 1);
1870 warning ("Aborting %s with unforwarded exception %s.",
1871 proc_string (inf
->wait
.thread
),
1872 target_signal_to_name (inf
->wait
.status
.value
.sig
));
1875 if (port_msgs_queued (inf
->event_port
))
1876 /* If there are still messages in our event queue, don't bother resuming
1877 the process, as we're just going to stop it right away anyway. */
1880 inf_update_procs (inf
);
1883 /* Allow all threads to run, except perhaps single-stepping one. */
1885 inf_debug (inf
, "running all threads; tid = %d", inferior_pid
);
1886 tid
= inferior_pid
; /* What to step. */
1887 inf_set_threads_resume_sc (inf
, 0, 1);
1890 /* Just allow a single thread to run. */
1892 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
1894 error ("Can't run single thread id %d: no such thread!");
1895 inf_debug (inf
, "running one thread: %d/%d", inf
->pid
, thread
->tid
);
1896 inf_set_threads_resume_sc (inf
, thread
, 0);
1901 step_thread
= inf_tid_to_thread (inf
, tid
);
1903 warning ("Can't step thread id %d: no such thread.", tid
);
1905 inf_debug (inf
, "stepping thread: %d/%d", inf
->pid
, step_thread
->tid
);
1907 if (step_thread
!= inf
->step_thread
)
1908 inf_set_step_thread (inf
, step_thread
);
1910 inf_debug (inf
, "here we go...");
1915 gnu_kill_inferior ()
1917 struct proc
*task
= current_inferior
->task
;
1920 proc_debug (task
, "terminating...");
1921 task_terminate (task
->port
);
1922 inf_set_pid (current_inferior
, -1);
1924 target_mourn_inferior ();
1927 /* Clean up after the inferior dies. */
1930 gnu_mourn_inferior ()
1932 inf_debug (current_inferior
, "rip");
1933 inf_detach (current_inferior
);
1934 unpush_target (&gnu_ops
);
1935 generic_mourn_inferior ();
1938 /* Fork an inferior process, and start debugging it. */
1940 /* Set INFERIOR_PID to the first thread available in the child, if any. */
1942 inf_pick_first_thread ()
1944 if (current_inferior
->task
&& current_inferior
->threads
)
1945 /* The first thread. */
1946 return current_inferior
->threads
->tid
;
1948 /* What may be the next thread. */
1949 return next_thread_id
;
1955 if (!current_inferior
)
1956 current_inferior
= make_inf ();
1957 return current_inferior
;
1961 gnu_create_inferior (exec_file
, allargs
, env
)
1966 struct inf
*inf
= cur_inf ();
1970 /* We're in the child; make this process stop as soon as it execs. */
1971 inf_debug (inf
, "tracing self");
1972 if (ptrace (PTRACE_TRACEME
) != 0)
1973 error ("ptrace (PTRACE_TRACEME) failed!");
1975 void attach_to_child (int pid
)
1977 /* Attach to the now stopped child, which is actually a shell... */
1978 inf_debug (inf
, "attaching to child: %d", pid
);
1980 inf_attach (inf
, pid
);
1983 push_target (&gnu_ops
);
1985 inf
->pending_execs
= 2;
1989 /* Now let the child run again, knowing that it will stop immediately
1990 because of the ptrace. */
1992 inferior_pid
= inf_pick_first_thread ();
1994 startup_inferior (inf
->pending_execs
);
1997 inf_debug (inf
, "creating inferior");
1999 fork_inferior (exec_file
, allargs
, env
, trace_me
, attach_to_child
,
2002 inf_validate_procinfo (inf
);
2003 inf_update_signal_thread (inf
);
2004 inf_set_traced (inf
, inf
->want_signals
);
2006 /* Execing the process will have trashed our exception ports; steal them
2007 back (or make sure they're restored if the user wants that). */
2008 if (inf
->want_exceptions
)
2009 inf_steal_exc_ports (inf
);
2011 inf_restore_exc_ports (inf
);
2014 proceed ((CORE_ADDR
) -1, 0, 0);
2017 /* Mark our target-struct as eligible for stray "run" and "attach"
2025 #ifdef ATTACH_DETACH
2027 /* Attach to process PID, then initialize for debugging it
2028 and wait for the trace-trap that results from attaching. */
2030 gnu_attach (args
, from_tty
)
2036 struct inf
*inf
= cur_inf ();
2039 error_no_arg ("PID to attach");
2043 if (pid
== getpid ()) /* Trying to masturbate? */
2044 error ("I refuse to debug myself!");
2048 exec_file
= (char *) get_exec_file (0);
2051 printf_unfiltered ("Attaching to program `%s', pid %d\n",
2054 printf_unfiltered ("Attaching to pid %d\n", pid
);
2056 gdb_flush (gdb_stdout
);
2059 inf_debug (inf
, "attaching to pid: %d", pid
);
2061 inf_attach (inf
, pid
);
2062 inf_update_procs (inf
);
2064 inferior_pid
= inf_pick_first_thread ();
2067 push_target (&gnu_ops
);
2069 /* We have to initialize the terminal settings now, since the code
2070 below might try to restore them. */
2071 target_terminal_init ();
2073 /* If the process was stopped before we attached, make it continue the next
2074 time the user does a continue. */
2075 inf_validate_procinfo (inf
);
2077 inf_update_signal_thread (inf
);
2078 inf_set_traced (inf
, inf
->want_signals
);
2080 #if 0 /* Do we need this? */
2081 renumber_threads (0); /* Give our threads reasonable names. */
2085 /* Take a program previously attached to and detaches it.
2086 The program resumes execution and will no longer stop
2087 on signals, etc. We'd better not have left any breakpoints
2088 in the program or it'll die when it hits one. For this
2089 to work, it may be necessary for the process to have been
2090 previously attached. It *might* work if the program was
2091 started via fork. */
2093 gnu_detach (args
, from_tty
)
2099 char *exec_file
= get_exec_file (0);
2101 printf_unfiltered ("Detaching from program `%s' pid %d\n",
2102 exec_file
, current_inferior
->pid
);
2104 printf_unfiltered ("Detaching from pid %d\n", current_inferior
->pid
);
2105 gdb_flush (gdb_stdout
);
2108 inf_detach (current_inferior
);
2112 unpush_target (&gnu_ops
); /* Pop out of handling an inferior */
2114 #endif /* ATTACH_DETACH */
2117 gnu_terminal_init_inferior ()
2119 assert (current_inferior
);
2120 terminal_init_inferior_with_pgrp (current_inferior
->pid
);
2123 /* Get ready to modify the registers array. On machines which store
2124 individual registers, this doesn't need to do anything. On machines
2125 which store all the registers in one fell swoop, this makes sure
2126 that registers contains all the registers from the program being
2130 gnu_prepare_to_store ()
2132 #ifdef CHILD_PREPARE_TO_STORE
2133 CHILD_PREPARE_TO_STORE ();
2138 gnu_open (arg
, from_tty
)
2142 error ("Use the \"run\" command to start a Unix child process.");
2148 error ("to_stop target function not implemented");
2152 gnu_pid_to_exec_file ()
2154 error ("to_pid_to_exec_file target function not implemented");
2160 gnu_thread_alive (int tid
)
2162 inf_update_procs (current_inferior
);
2163 return !!inf_tid_to_thread (current_inferior
, tid
);
2167 * Read inferior task's LEN bytes from ADDR and copy it to MYADDR
2168 * in gdb's address space.
2170 * Return 0 on failure; number of bytes read otherwise.
2173 gnu_read_inferior (task
, addr
, myaddr
, length
)
2180 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2181 vm_size_t aligned_length
=
2182 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2186 /* Get memory from inferior with page aligned addresses */
2187 err
= vm_read (task
, low_address
, aligned_length
, &copied
, ©_count
);
2191 err
= hurd_safe_copyin (myaddr
, (void *) addr
- low_address
+ copied
, length
);
2194 warning ("Read from inferior faulted: %s", strerror (err
));
2198 err
= vm_deallocate (mach_task_self (), copied
, copy_count
);
2200 warning ("gnu_read_inferior vm_deallocate failed: %s", strerror (err
));
2205 #define CHK_GOTO_OUT(str,ret) \
2206 do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
2208 struct vm_region_list
2210 struct vm_region_list
*next
;
2211 vm_prot_t protection
;
2216 struct obstack region_obstack
;
2219 * Write gdb's LEN bytes from MYADDR and copy it to ADDR
2220 * in inferior task's address space.
2223 gnu_write_inferior (task
, addr
, myaddr
, length
)
2230 vm_address_t low_address
= (vm_address_t
) trunc_page (addr
);
2231 vm_size_t aligned_length
=
2232 (vm_size_t
) round_page (addr
+ length
) - low_address
;
2237 char *errstr
= "Bug in gnu_write_inferior";
2239 struct vm_region_list
*region_element
;
2240 struct vm_region_list
*region_head
= (struct vm_region_list
*) NULL
;
2242 /* Get memory from inferior with page aligned addresses */
2243 err
= vm_read (task
,
2248 CHK_GOTO_OUT ("gnu_write_inferior vm_read failed", err
);
2252 err
= hurd_safe_copyout ((void *) addr
- low_address
+ copied
, myaddr
, length
);
2253 CHK_GOTO_OUT ("Write to inferior faulted", err
);
2255 obstack_init (®ion_obstack
);
2257 /* Do writes atomically.
2258 * First check for holes and unwritable memory.
2261 vm_size_t remaining_length
= aligned_length
;
2262 vm_address_t region_address
= low_address
;
2264 struct vm_region_list
*scan
;
2266 while (region_address
< low_address
+ aligned_length
)
2268 vm_prot_t protection
;
2269 vm_prot_t max_protection
;
2270 vm_inherit_t inheritance
;
2272 mach_port_t object_name
;
2274 vm_size_t region_length
= remaining_length
;
2275 vm_address_t old_address
= region_address
;
2277 err
= vm_region (task
,
2286 CHK_GOTO_OUT ("vm_region failed", err
);
2288 /* Check for holes in memory */
2289 if (old_address
!= region_address
)
2291 warning ("No memory at 0x%x. Nothing written",
2298 if (!(max_protection
& VM_PROT_WRITE
))
2300 warning ("Memory at address 0x%x is unwritable. Nothing written",
2307 /* Chain the regions for later use */
2309 (struct vm_region_list
*)
2310 obstack_alloc (®ion_obstack
, sizeof (struct vm_region_list
));
2312 region_element
->protection
= protection
;
2313 region_element
->start
= region_address
;
2314 region_element
->length
= region_length
;
2316 /* Chain the regions along with protections */
2317 region_element
->next
= region_head
;
2318 region_head
= region_element
;
2320 region_address
+= region_length
;
2321 remaining_length
= remaining_length
- region_length
;
2324 /* If things fail after this, we give up.
2325 * Somebody is messing up inferior_task's mappings.
2328 /* Enable writes to the chained vm regions */
2329 for (scan
= region_head
; scan
; scan
= scan
->next
)
2331 boolean_t protection_changed
= FALSE
;
2333 if (!(scan
->protection
& VM_PROT_WRITE
))
2335 err
= vm_protect (task
,
2339 scan
->protection
| VM_PROT_WRITE
);
2340 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2344 err
= vm_write (task
,
2348 CHK_GOTO_OUT ("vm_write failed", err
);
2350 /* Set up the original region protections, if they were changed */
2351 for (scan
= region_head
; scan
; scan
= scan
->next
)
2353 boolean_t protection_changed
= FALSE
;
2355 if (!(scan
->protection
& VM_PROT_WRITE
))
2357 err
= vm_protect (task
,
2362 CHK_GOTO_OUT ("vm_protect: enable write failed", err
);
2370 obstack_free (®ion_obstack
, 0);
2372 (void) vm_deallocate (mach_task_self (),
2377 if (err
!= KERN_SUCCESS
)
2379 warning ("%s: %s", errstr
, mach_error_string (err
));
2386 /* Return 0 on failure, number of bytes handled otherwise. */
2388 gnu_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2393 struct target_ops
*target
; /* IGNORED */
2398 ? (current_inferior
->task
? current_inferior
->task
->port
: 0)
2401 if (task
== MACH_PORT_NULL
)
2405 inf_debug (current_inferior
, "%s %p[%d] %s %p",
2406 write
? "writing" : "reading", memaddr
, len
,
2407 write
? "<--" : "-->", myaddr
);
2409 return gnu_write_inferior (task
, memaddr
, myaddr
, len
);
2411 return gnu_read_inferior (task
, memaddr
, myaddr
, len
);
2415 /* Return printable description of proc. */
2417 proc_string (struct proc
*proc
)
2419 static char tid_str
[80];
2420 if (proc_is_task (proc
))
2421 sprintf (tid_str
, "process %d", proc
->inf
->pid
);
2423 sprintf (tid_str
, "thread %d.%d",
2424 proc
->inf
->pid
, pid_to_thread_id (proc
->tid
));
2429 gnu_pid_to_str (int tid
)
2431 struct inf
*inf
= current_inferior
;
2432 struct proc
*thread
= inf_tid_to_thread (inf
, tid
);
2435 return proc_string (thread
);
2438 static char tid_str
[80];
2439 sprintf (tid_str
, "bogus thread id %d", tid
);
2444 extern void gnu_store_registers (int regno
);
2445 extern void gnu_fetch_registers (int regno
);
2447 struct target_ops gnu_ops
;
2452 gnu_ops
.to_shortname
= "GNU"; /* to_shortname */
2453 gnu_ops
.to_longname
= "GNU Hurd process"; /* to_longname */
2454 gnu_ops
.to_doc
= "GNU Hurd process"; /* to_doc */
2455 gnu_ops
.to_open
= gnu_open
; /* to_open */
2456 gnu_ops
.to_close
= 0; /* to_close */
2457 gnu_ops
.to_attach
= gnu_attach
; /* to_attach */
2458 gnu_ops
.to_post_attach
= NULL
;
2459 gnu_ops
.to_require_attach
= NULL
; /* to_require_attach */
2460 gnu_ops
.to_detach
= gnu_detach
; /* to_detach */
2461 gnu_ops
.to_require_detach
= NULL
; /* to_require_detach */
2462 gnu_ops
.to_resume
= gnu_resume
; /* to_resume */
2463 gnu_ops
.to_wait
= gnu_wait
; /* to_wait */
2464 gnu_ops
.to_post_wait
= NULL
; /* to_post_wait */
2465 gnu_ops
.to_fetch_registers
= gnu_fetch_registers
; /* to_fetch_registers */
2466 gnu_ops
.to_store_registers
= gnu_store_registers
; /* to_store_registers */
2467 gnu_ops
.to_prepare_to_store
= gnu_prepare_to_store
; /* to_prepare_to_store */
2468 gnu_ops
.to_xfer_memory
= gnu_xfer_memory
; /* to_xfer_memory */
2469 gnu_ops
.to_files_info
= 0; /* to_files_info */
2470 gnu_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
2471 gnu_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
2472 gnu_ops
.to_terminal_init
= gnu_terminal_init_inferior
;
2473 gnu_ops
.to_terminal_inferior
= terminal_inferior
;
2474 gnu_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
2475 gnu_ops
.to_terminal_ours
= terminal_ours
;
2476 gnu_ops
.to_terminal_info
= child_terminal_info
;
2477 gnu_ops
.to_kill
= gnu_kill_inferior
; /* to_kill */
2478 gnu_ops
.to_load
= 0; /* to_load */
2479 gnu_ops
.to_lookup_symbol
= 0; /* to_lookup_symbol */
2480 gnu_ops
.to_create_inferior
= gnu_create_inferior
; /* to_create_inferior */
2481 gnu_ops
.to_post_startup_inferior
= NULL
; /* to_post_startup_inferior */
2482 gnu_ops
.to_acknowledge_created_inferior
= NULL
; /* to_acknowledge_created_inferior */
2483 gnu_ops
.to_clone_and_follow_inferior
= NULL
; /* to_clone_and_follow_inferior */
2484 gnu_ops
.to_post_follow_inferior_by_clone
= NULL
; /* to_post_follow_inferior_by_clone */
2485 gnu_ops
.to_insert_fork_catchpoint
= NULL
;
2486 gnu_ops
.to_remove_fork_catchpoint
= NULL
;
2487 gnu_ops
.to_insert_vfork_catchpoint
= NULL
;
2488 gnu_ops
.to_remove_vfork_catchpoint
= NULL
;
2489 gnu_ops
.to_has_forked
= NULL
; /* to_has_forked */
2490 gnu_ops
.to_has_vforked
= NULL
; /* to_has_vforked */
2491 gnu_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
2492 gnu_ops
.to_post_follow_vfork
= NULL
; /* to_post_follow_vfork */
2493 gnu_ops
.to_insert_exec_catchpoint
= NULL
;
2494 gnu_ops
.to_remove_exec_catchpoint
= NULL
;
2495 gnu_ops
.to_has_execd
= NULL
;
2496 gnu_ops
.to_reported_exec_events_per_exec_call
= NULL
;
2497 gnu_ops
.to_has_exited
= NULL
;
2498 gnu_ops
.to_mourn_inferior
= gnu_mourn_inferior
; /* to_mourn_inferior */
2499 gnu_ops
.to_can_run
= gnu_can_run
; /* to_can_run */
2500 gnu_ops
.to_notice_signals
= 0; /* to_notice_signals */
2501 gnu_ops
.to_thread_alive
= gnu_thread_alive
; /* to_thread_alive */
2502 gnu_ops
.to_pid_to_str
= gnu_pid_to_str
; /* to_pid_to_str */
2503 gnu_ops
.to_stop
= gnu_stop
; /* to_stop */
2504 gnu_ops
.to_pid_to_exec_file
= gnu_pid_to_exec_file
; /* to_pid_to_exec_file */
2505 gnu_ops
.to_core_file_to_sym_file
= NULL
;
2506 gnu_ops
.to_stratum
= process_stratum
; /* to_stratum */
2507 gnu_ops
.DONT_USE
= 0; /* to_next */
2508 gnu_ops
.to_has_all_memory
= 1; /* to_has_all_memory */
2509 gnu_ops
.to_has_memory
= 1; /* to_has_memory */
2510 gnu_ops
.to_has_stack
= 1; /* to_has_stack */
2511 gnu_ops
.to_has_registers
= 1; /* to_has_registers */
2512 gnu_ops
.to_has_execution
= 1; /* to_has_execution */
2513 gnu_ops
.to_sections
= 0; /* sections */
2514 gnu_ops
.to_sections_end
= 0; /* sections_end */
2515 gnu_ops
.to_magic
= OPS_MAGIC
; /* to_magic */
2516 } /* init_gnu_ops */
2518 /* User task commands. */
2520 struct cmd_list_element
*set_task_cmd_list
= 0;
2521 struct cmd_list_element
*show_task_cmd_list
= 0;
2522 /* User thread commands. */
2524 /* Commands with a prefix of `set/show thread'. */
2525 extern struct cmd_list_element
*thread_cmd_list
;
2526 struct cmd_list_element
*set_thread_cmd_list
= NULL
;
2527 struct cmd_list_element
*show_thread_cmd_list
= NULL
;
2529 /* Commands with a prefix of `set/show thread default'. */
2530 struct cmd_list_element
*set_thread_default_cmd_list
= NULL
;
2531 struct cmd_list_element
*show_thread_default_cmd_list
= NULL
;
2534 set_thread_cmd (char *args
, int from_tty
)
2536 printf_unfiltered ("\"set thread\" must be followed by the name of a thread property, or \"default\".\n");
2540 show_thread_cmd (char *args
, int from_tty
)
2542 printf_unfiltered ("\"show thread\" must be followed by the name of a thread property, or \"default\".\n");
2546 set_thread_default_cmd (char *args
, int from_tty
)
2548 printf_unfiltered ("\"set thread default\" must be followed by the name of a thread property.\n");
2552 show_thread_default_cmd (char *args
, int from_tty
)
2554 printf_unfiltered ("\"show thread default\" must be followed by the name of a thread property.\n");
2558 parse_int_arg (char *args
, char *cmd_prefix
)
2563 int val
= strtoul (args
, &arg_end
, 10);
2564 if (*args
&& *arg_end
== '\0')
2567 error ("Illegal argument for \"%s\" command, should be an integer.", cmd_prefix
);
2571 _parse_bool_arg (char *args
, char *t_val
, char *f_val
, char *cmd_prefix
)
2573 if (!args
|| strcmp (args
, t_val
) == 0)
2575 else if (strcmp (args
, f_val
) == 0)
2578 error ("Illegal argument for \"%s\" command, should be \"%s\" or \"%s\".",
2579 cmd_prefix
, t_val
, f_val
);
2582 #define parse_bool_arg(args, cmd_prefix) \
2583 _parse_bool_arg (args, "on", "off", cmd_prefix)
2586 check_empty (char *args
, char *cmd_prefix
)
2589 error ("Garbage after \"%s\" command: `%s'", cmd_prefix
, args
);
2592 /* Returns the alive thread named by INFERIOR_PID, or signals an error. */
2593 static struct proc
*
2596 struct inf
*inf
= cur_inf ();
2597 struct proc
*thread
= inf_tid_to_thread (inf
, inferior_pid
);
2599 error ("No current thread.");
2603 /* Returns the current inferior, but signals an error if it has no task. */
2607 struct inf
*inf
= cur_inf ();
2609 error ("No current process.");
2614 set_task_pause_cmd (char *args
, int from_tty
)
2616 struct inf
*inf
= cur_inf ();
2617 int old_sc
= inf
->pause_sc
;
2619 inf
->pause_sc
= parse_bool_arg (args
, "set task pause");
2621 if (old_sc
== 0 && inf
->pause_sc
!= 0)
2622 /* If the task is currently unsuspended, immediately suspend it,
2623 otherwise wait until the next time it gets control. */
2628 show_task_pause_cmd (char *args
, int from_tty
)
2630 struct inf
*inf
= cur_inf ();
2631 check_empty (args
, "show task pause");
2632 printf_unfiltered ("The inferior task %s suspended while gdb has control.\n",
2634 ? (inf
->pause_sc
== 0 ? "isn't" : "is")
2635 : (inf
->pause_sc
== 0 ? "won't be" : "will be"));
2639 set_task_detach_sc_cmd (char *args
, int from_tty
)
2641 cur_inf ()->detach_sc
= parse_int_arg (args
, "set task detach-suspend-count");
2645 show_task_detach_sc_cmd (char *args
, int from_tty
)
2647 check_empty (args
, "show task detach-suspend-count");
2648 printf_unfiltered ("The inferior task will be left with a suspend count of %d when detaching.\n",
2649 cur_inf ()->detach_sc
);
2653 set_thread_default_pause_cmd (char *args
, int from_tty
)
2655 struct inf
*inf
= cur_inf ();
2656 inf
->default_thread_pause_sc
=
2657 parse_bool_arg (args
, "set thread default pause") ? 0 : 1;
2661 show_thread_default_pause_cmd (char *args
, int from_tty
)
2663 struct inf
*inf
= cur_inf ();
2664 int sc
= inf
->default_thread_pause_sc
;
2665 check_empty (args
, "show thread default pause");
2666 printf_unfiltered ("New threads %s suspended while gdb has control%s.\n",
2667 sc
? "are" : "aren't",
2668 !sc
&& inf
->pause_sc
? " (but the task is)" : "");
2672 set_thread_default_run_cmd (char *args
, int from_tty
)
2674 struct inf
*inf
= cur_inf ();
2675 inf
->default_thread_run_sc
=
2676 parse_bool_arg (args
, "set thread default run") ? 0 : 1;
2680 show_thread_default_run_cmd (char *args
, int from_tty
)
2682 struct inf
*inf
= cur_inf ();
2683 check_empty (args
, "show thread default run");
2684 printf_unfiltered ("New threads %s allowed to run.\n",
2685 inf
->default_thread_run_sc
== 0 ? "are" : "aren't");
2689 set_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2691 cur_inf ()->default_thread_detach_sc
=
2692 parse_int_arg (args
, "set thread default detach-suspend-count");
2696 show_thread_default_detach_sc_cmd (char *args
, int from_tty
)
2698 check_empty (args
, "show thread default detach-suspend-count");
2699 printf_unfiltered ("New threads will get a detach-suspend-count of %d.\n",
2700 cur_inf ()->default_thread_detach_sc
);
2703 /* Steal a send right called NAME in the inferior task, and make it PROC's
2704 saved exception port. */
2706 steal_exc_port (struct proc
*proc
, mach_port_t name
)
2710 mach_msg_type_name_t port_type
;
2712 if (!proc
|| !proc
->inf
->task
)
2713 error ("No inferior task.");
2715 err
= mach_port_extract_right (proc
->inf
->task
->port
,
2716 name
, MACH_MSG_TYPE_COPY_SEND
,
2719 error ("Couldn't extract send right %d from inferior: %s",
2720 name
, strerror (err
));
2722 if (proc
->saved_exc_port
)
2723 /* Get rid of our reference to the old one. */
2724 mach_port_deallocate (mach_task_self (), proc
->saved_exc_port
);
2726 proc
->saved_exc_port
= port
;
2728 if (!proc
->exc_port
)
2729 /* If PROC is a thread, we may not have set its exception port before.
2730 We can't use proc_steal_exc_port because it also sets saved_exc_port. */
2732 proc
->exc_port
= proc
->inf
->event_port
;
2733 err
= proc_set_exception_port (proc
, proc
->exc_port
);
2734 error ("Can't set exception port for %s: %s",
2735 proc_string (proc
), strerror (err
));
2740 set_task_exc_port_cmd (char *args
, int from_tty
)
2742 struct inf
*inf
= cur_inf ();
2744 error ("No argument to \"set task exception-port\" command.");
2745 steal_exc_port (inf
->task
, parse_and_eval_address (args
));
2749 set_stopped_cmd (char *args
, int from_tty
)
2751 cur_inf ()->stopped
= _parse_bool_arg (args
, "yes", "no", "set stopped");
2755 show_stopped_cmd (char *args
, int from_tty
)
2757 struct inf
*inf
= active_inf ();
2758 check_empty (args
, "show stopped");
2759 printf_unfiltered ("The inferior process %s stopped.\n",
2760 inf
->stopped
? "is" : "isn't");
2764 set_sig_thread_cmd (char *args
, int from_tty
)
2767 struct inf
*inf
= cur_inf ();
2769 if (!args
|| (!isdigit (*args
) && strcmp (args
, "none") != 0))
2770 error ("Illegal argument to \"set signal-thread\" command.\n"
2771 "Should be an integer thread ID, or `none'.");
2773 if (strcmp (args
, "none") == 0)
2774 inf
->signal_thread
= 0;
2777 int tid
= thread_id_to_pid (atoi (args
));
2779 error ("Thread ID %s not known. Use the \"info threads\" command to\n"
2780 "see the IDs of currently known threads.", args
);
2781 inf
->signal_thread
= inf_tid_to_thread (inf
, tid
);
2786 show_sig_thread_cmd (char *args
, int from_tty
)
2788 struct inf
*inf
= active_inf ();
2789 check_empty (args
, "show signal-thread");
2790 if (inf
->signal_thread
)
2791 printf_unfiltered ("The signal thread is %s.\n",
2792 proc_string (inf
->signal_thread
));
2794 printf_unfiltered ("There is no signal thread.\n");
2798 set_signals_cmd (char *args
, int from_tty
)
2801 struct inf
*inf
= cur_inf ();
2803 inf
->want_signals
= parse_bool_arg (args
, "set signals");
2805 if (inf
->task
&& inf
->want_signals
!= inf
->traced
)
2806 /* Make this take effect immediately in a running process. */
2807 inf_set_traced (inf
, inf
->want_signals
);
2811 show_signals_cmd (char *args
, int from_tty
)
2813 struct inf
*inf
= cur_inf ();
2814 check_empty (args
, "show signals");
2815 printf_unfiltered ("The inferior process's signals %s intercepted.\n",
2817 ? (inf
->traced
? "are" : "aren't")
2818 : (inf
->want_signals
? "will be" : "won't be"));
2822 set_exceptions_cmd (char *args
, int from_tty
)
2824 struct inf
*inf
= cur_inf ();
2825 int val
= parse_bool_arg (args
, "set exceptions");
2827 if (inf
->task
&& inf
->want_exceptions
!= val
)
2828 /* Make this take effect immediately in a running process. */
2831 inf
->want_exceptions
= val
;
2835 show_exceptions_cmd (char *args
, int from_tty
)
2837 struct inf
*inf
= cur_inf ();
2838 check_empty (args
, "show exceptions");
2839 printf_unfiltered ("Exceptions in the inferior %s trapped.\n",
2841 ? (inf
->want_exceptions
? "are" : "aren't")
2842 : (inf
->want_exceptions
? "will be" : "won't be"));
2846 set_task_cmd (char *args
, int from_tty
)
2848 printf_unfiltered ("\"set task\" must be followed by the name of a task property.\n");
2852 show_task_cmd (char *args
, int from_tty
)
2854 struct inf
*inf
= cur_inf ();
2856 check_empty (args
, "show task");
2858 show_signals_cmd (0, from_tty
);
2859 show_exceptions_cmd (0, from_tty
);
2860 show_task_pause_cmd (0, from_tty
);
2862 if (inf
->pause_sc
== 0)
2863 show_thread_default_pause_cmd (0, from_tty
);
2864 show_thread_default_run_cmd (0, from_tty
);
2868 show_stopped_cmd (0, from_tty
);
2869 show_sig_thread_cmd (0, from_tty
);
2872 if (inf
->detach_sc
!= 0)
2873 show_task_detach_sc_cmd (0, from_tty
);
2874 if (inf
->default_thread_detach_sc
!= 0)
2875 show_thread_default_detach_sc_cmd (0, from_tty
);
2879 set_noninvasive_cmd (char *args
, int from_tty
)
2881 /* Invert the sense of the arg for each component. */
2882 char *inv_args
= parse_bool_arg (args
, "set noninvasive") ? "off" : "on";
2884 set_task_pause_cmd (inv_args
, from_tty
);
2885 set_signals_cmd (inv_args
, from_tty
);
2886 set_exceptions_cmd (inv_args
, from_tty
);
2890 info_port_rights (char *args
, mach_port_type_t only
)
2892 struct inf
*inf
= active_inf ();
2893 value_ptr vmark
= value_mark ();
2896 /* Explicit list of port rights. */
2900 value_ptr val
= parse_to_comma_and_eval (&args
);
2901 long right
= value_as_long (val
);
2903 print_port_info (right
, 0, inf
->task
->port
, PORTINFO_DETAILS
,
2906 error ("%ld: %s.", right
, strerror (err
));
2910 /* Print all of them. */
2913 print_task_ports_info (inf
->task
->port
, only
, PORTINFO_DETAILS
,
2916 error ("%s.", strerror (err
));
2919 value_free_to_mark (vmark
);
2923 info_send_rights_cmd (char *args
, int from_tty
)
2925 info_port_rights (args
, MACH_PORT_TYPE_SEND
);
2928 info_recv_rights_cmd (char *args
, int from_tty
)
2930 info_port_rights (args
, MACH_PORT_TYPE_RECEIVE
);
2933 info_port_sets_cmd (char *args
, int from_tty
)
2935 info_port_rights (args
, MACH_PORT_TYPE_PORT_SET
);
2938 info_dead_names_cmd (char *args
, int from_tty
)
2940 info_port_rights (args
, MACH_PORT_TYPE_DEAD_NAME
);
2943 info_port_rights_cmd (char *args
, int from_tty
)
2945 info_port_rights (args
, ~0);
2949 add_task_commands ()
2951 add_cmd ("pause", class_run
, set_thread_default_pause_cmd
,
2952 "Set whether the new threads are suspended while gdb has control.\n"
2953 "This property normally has no effect because the whole task is\n"
2954 "suspended, however, that may be disabled with \"set task pause off\".\n"
2955 "The default value is \"off\".",
2956 &set_thread_default_cmd_list
);
2957 add_cmd ("pause", no_class
, show_thread_default_pause_cmd
,
2958 "Show whether new threads are suspended while gdb has control.",
2959 &show_thread_default_cmd_list
);
2960 add_cmd ("run", class_run
, set_thread_default_run_cmd
,
2961 "Set whether new threads are allowed to run (once gdb has noticed them).",
2962 &set_thread_default_cmd_list
);
2963 add_cmd ("run", no_class
, show_thread_default_run_cmd
,
2964 "Show whether new threads are allowed to run (once gdb has noticed them).",
2965 &show_thread_default_cmd_list
);
2966 add_cmd ("detach-suspend-count", class_run
, set_thread_default_detach_sc_cmd
,
2967 "Set the default detach-suspend-count value for new threads.",
2968 &set_thread_default_cmd_list
);
2969 add_cmd ("detach-suspend-count", no_class
, show_thread_default_detach_sc_cmd
,
2970 "Show the default detach-suspend-count value for new threads.",
2971 &show_thread_default_cmd_list
);
2973 add_cmd ("signals", class_run
, set_signals_cmd
,
2974 "Set whether the inferior process's signals will be intercepted.\n"
2975 "Mach exceptions (such as breakpoint traps) are not affected.",
2977 add_alias_cmd ("sigs", "signals", class_run
, 1, &setlist
);
2978 add_cmd ("signals", no_class
, show_signals_cmd
,
2979 "Show whether the inferior process's signals will be intercepted.",
2981 add_alias_cmd ("sigs", "signals", no_class
, 1, &showlist
);
2983 add_cmd ("signal-thread", class_run
, set_sig_thread_cmd
,
2984 "Set the thread that gdb thinks is the libc signal thread.\n"
2985 "This thread is run when delivering a signal to a non-stopped process.",
2987 add_alias_cmd ("sigthread", "signal-thread", class_run
, 1, &setlist
);
2988 add_cmd ("signal-thread", no_class
, show_sig_thread_cmd
,
2989 "Set the thread that gdb thinks is the libc signal thread.",
2991 add_alias_cmd ("sigthread", "signal-thread", no_class
, 1, &showlist
);
2993 add_cmd ("stopped", class_run
, set_stopped_cmd
,
2994 "Set whether gdb thinks the inferior process is stopped as with SIGSTOP.\n"
2995 "Stopped process will be continued by sending them a signal.",
2997 add_cmd ("stopped", no_class
, show_signals_cmd
,
2998 "Show whether gdb thinks the inferior process is stopped as with SIGSTOP.",
3001 add_cmd ("exceptions", class_run
, set_exceptions_cmd
,
3002 "Set whether exceptions in the inferior process will be trapped.\n"
3003 "When exceptions are turned off, neither breakpoints nor single-stepping\n"
3006 /* Allow `set exc' despite conflict with `set exception-port'. */
3007 add_alias_cmd ("exc", "exceptions", class_run
, 1, &setlist
);
3008 add_cmd ("exceptions", no_class
, show_exceptions_cmd
,
3009 "Show whether exceptions in the inferior process will be trapped.",
3012 add_prefix_cmd ("task", no_class
, set_task_cmd
,
3013 "Command prefix for setting task attributes.",
3014 &set_task_cmd_list
, "set task ", 0, &setlist
);
3015 add_prefix_cmd ("task", no_class
, show_task_cmd
,
3016 "Command prefix for showing task attributes.",
3017 &show_task_cmd_list
, "show task ", 0, &showlist
);
3019 add_cmd ("pause", class_run
, set_task_pause_cmd
,
3020 "Set whether the task is suspended while gdb has control.\n"
3021 "A value of \"on\" takes effect immediately, otherwise nothing\n"
3022 "happens until the next time the program is continued.\n"
3023 "When setting this to \"off\", \"set thread default pause on\"\n"
3024 "can be used to pause individual threads by default instead.",
3025 &set_task_cmd_list
);
3026 add_cmd ("pause", no_class
, show_task_pause_cmd
,
3027 "Show whether the task is suspended while gdb has control.",
3028 &show_task_cmd_list
);
3029 add_cmd ("detach-suspend-count", class_run
, set_task_detach_sc_cmd
,
3030 "Set the suspend count will leave on the thread when detaching.",
3031 &set_task_cmd_list
);
3032 add_cmd ("detach-suspend-count", no_class
, show_task_detach_sc_cmd
,
3033 "Show the suspend count will leave on the thread when detaching.",
3034 &show_task_cmd_list
);
3036 add_cmd ("exception-port", no_class
, set_task_exc_port_cmd
,
3037 "Set the task exception port to which we forward exceptions.\n"
3038 "The argument should be the value of the send right in the task.",
3039 &set_task_cmd_list
);
3040 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_task_cmd_list
);
3041 add_alias_cmd ("exc-port", "exception-port", no_class
, 1, &set_task_cmd_list
);
3043 /* A convenient way of turning on all options require to noninvasively
3044 debug running tasks. */
3045 add_cmd ("noninvasive", no_class
, set_noninvasive_cmd
,
3046 "Set task options so that we interfere as little as possible.\n"
3047 "This is the same as setting `task pause', `exceptions', and"
3048 "`signals' to the opposite value.",
3051 /* Commands to show information about the task's ports. */
3052 add_cmd ("send-rights", class_info
, info_send_rights_cmd
,
3053 "Show information about the task's send rights",
3055 add_cmd ("receive-rights", class_info
, info_recv_rights_cmd
,
3056 "Show information about the task's receive rights",
3058 add_cmd ("port-rights", class_info
, info_send_rights_cmd
,
3059 "Show information about the task's port rights",
3061 add_cmd ("port-sets", class_info
, info_port_sets_cmd
,
3062 "Show information about the task's port sets",
3064 add_cmd ("dead-names", class_info
, info_dead_names_cmd
,
3065 "Show information about the task's dead names",
3067 add_info_alias ("ports", "port-rights", 1);
3068 add_info_alias ("port", "port-rights", 1);
3069 add_info_alias ("psets", "port-sets", 1);
3074 set_thread_pause_cmd (char *args
, int from_tty
)
3076 struct proc
*thread
= cur_thread ();
3077 int old_sc
= thread
->pause_sc
;
3078 thread
->pause_sc
= parse_bool_arg (args
, "set thread pause");
3079 if (old_sc
== 0 && thread
->pause_sc
!= 0 && thread
->inf
->pause_sc
== 0)
3080 /* If the task is currently unsuspended, immediately suspend it,
3081 otherwise wait until the next time it gets control. */
3082 inf_suspend (thread
->inf
);
3086 show_thread_pause_cmd (char *args
, int from_tty
)
3088 struct proc
*thread
= cur_thread ();
3089 int sc
= thread
->pause_sc
;
3090 check_empty (args
, "show task pause");
3091 printf_unfiltered ("Thread %s %s suspended while gdb has control%s.\n",
3092 proc_string (thread
),
3093 sc
? "is" : "isn't",
3094 !sc
&& thread
->inf
->pause_sc
? " (but the task is)" : "");
3098 set_thread_run_cmd (char *args
, int from_tty
)
3100 struct proc
*thread
= cur_thread ();
3101 thread
->run_sc
= parse_bool_arg (args
, "set thread run") ? 0 : 1;
3105 show_thread_run_cmd (char *args
, int from_tty
)
3107 struct proc
*thread
= cur_thread ();
3108 check_empty (args
, "show thread run");
3109 printf_unfiltered ("Thread %s %s allowed to run.",
3110 proc_string (thread
),
3111 thread
->run_sc
== 0 ? "is" : "isn't");
3115 set_thread_detach_sc_cmd (char *args
, int from_tty
)
3117 cur_thread ()->detach_sc
= parse_int_arg (args
, "set thread detach-suspend-count");
3121 show_thread_detach_sc_cmd (char *args
, int from_tty
)
3123 struct proc
*thread
= cur_thread ();
3124 check_empty (args
, "show thread detach-suspend-count");
3125 printf_unfiltered ("Thread %s will be left with a suspend count of %d when detaching.\n",
3126 proc_string (thread
),
3131 set_thread_exc_port_cmd (char *args
, int from_tty
)
3133 struct proc
*thread
= cur_thread ();
3135 error ("No argument to \"set thread exception-port\" command.");
3136 steal_exc_port (thread
, parse_and_eval_address (args
));
3141 show_thread_cmd (char *args
, int from_tty
)
3143 struct proc
*thread
= cur_thread ();
3144 check_empty (args
, "show thread");
3145 show_thread_run_cmd (0, from_tty
);
3146 show_thread_pause_cmd (0, from_tty
);
3147 if (thread
->detach_sc
!= 0)
3148 show_thread_detach_sc_cmd (0, from_tty
);
3153 thread_takeover_sc_cmd (char *args
, int from_tty
)
3155 struct proc
*thread
= cur_thread ();
3156 thread_basic_info_data_t _info
;
3157 thread_basic_info_t info
= &_info
;
3158 mach_msg_type_number_t info_len
= THREAD_BASIC_INFO_COUNT
;
3160 thread_info (thread
->port
, THREAD_BASIC_INFO
, (int *) &info
, &info_len
);
3162 error ("%s.", strerror (err
));
3163 thread
->sc
= info
->suspend_count
;
3165 printf_unfiltered ("Suspend count was %d.\n", thread
->sc
);
3167 vm_deallocate (mach_task_self (), (vm_address_t
) info
, info_len
* sizeof (int));
3170 add_thread_commands ()
3172 add_prefix_cmd ("thread", no_class
, set_thread_cmd
,
3173 "Command prefix for setting thread properties.",
3174 &set_thread_cmd_list
, "set thread ", 0, &setlist
);
3175 add_prefix_cmd ("default", no_class
, show_thread_cmd
,
3176 "Command prefix for setting default thread properties.",
3177 &set_thread_default_cmd_list
, "set thread default ", 0,
3178 &set_thread_cmd_list
);
3179 add_prefix_cmd ("thread", no_class
, set_thread_default_cmd
,
3180 "Command prefix for showing thread properties.",
3181 &show_thread_cmd_list
, "show thread ", 0, &showlist
);
3182 add_prefix_cmd ("default", no_class
, show_thread_default_cmd
,
3183 "Command prefix for showing default thread properties.",
3184 &show_thread_default_cmd_list
, "show thread default ", 0,
3185 &show_thread_cmd_list
);
3187 add_cmd ("pause", class_run
, set_thread_pause_cmd
,
3188 "Set whether the current thread is suspended while gdb has control.\n"
3189 "A value of \"on\" takes effect immediately, otherwise nothing\n"
3190 "happens until the next time the program is continued. This\n"
3191 "property normally has no effect because the whole task is suspended,\n"
3192 "however, that may be disabled with \"set task pause off\".\n"
3193 "The default value is \"off\".",
3194 &set_thread_cmd_list
);
3195 add_cmd ("pause", no_class
, show_thread_pause_cmd
,
3196 "Show whether the current thread is suspended while gdb has control.",
3197 &show_thread_cmd_list
);
3199 add_cmd ("run", class_run
, set_thread_run_cmd
,
3200 "Set whether the current thread is allowed to run.",
3201 &set_thread_cmd_list
);
3202 add_cmd ("run", no_class
, show_thread_run_cmd
,
3203 "Show whether the current thread is allowed to run.",
3204 &show_thread_cmd_list
);
3206 add_cmd ("detach-suspend-count", class_run
, set_thread_detach_sc_cmd
,
3207 "Set the suspend count will leave on the thread when detaching.\n"
3208 "Note that this is relative to suspend count when gdb noticed the thread;\n"
3209 "use the `thread takeover-suspend-count' to force it to an absolute value.",
3210 &set_thread_cmd_list
);
3211 add_cmd ("detach-suspend-count", no_class
, show_thread_detach_sc_cmd
,
3212 "Show the suspend count will leave on the thread when detaching."
3213 "Note that this is relative to suspend count when gdb noticed the thread;\n"
3214 "use the `thread takeover-suspend-count' to force it to an absolute value.",
3215 &show_thread_cmd_list
);
3217 add_cmd ("exception-port", no_class
, set_thread_exc_port_cmd
,
3218 "Set the exception port to which we forward exceptions for the\n"
3219 "current thread, overriding the task exception port.\n"
3220 "The argument should be the value of the send right in the task.",
3221 &set_thread_cmd_list
);
3222 add_alias_cmd ("excp", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3223 add_alias_cmd ("exc-port", "exception-port", no_class
, 1, &set_thread_cmd_list
);
3225 add_cmd ("takeover-suspend-count", no_class
, thread_takeover_sc_cmd
,
3226 "Force the threads absolute suspend-count to be gdb's.\n"
3227 "Prior to giving this command, gdb's thread suspend-counts are relative to\n"
3228 "the thread's initial suspend-count when gdb notices the threads.",
3233 _initialize_gnu_nat ()
3235 proc_server
= getproc ();
3237 add_target (&gnu_ops
);
3238 add_task_commands ();
3239 add_thread_commands ();
3241 add_set_cmd ("gnu-debug", class_maintenance
,
3242 var_boolean
, (char *) &gnu_debug_flag
,
3243 "Set debugging output for the gnu backend.", &maintenancelist
);
3246 #ifdef FLUSH_INFERIOR_CACHE
3248 /* When over-writing code on some machines the I-Cache must be flushed
3249 explicitly, because it is not kept coherent by the lazy hardware.
3250 This definitely includes breakpoints, for instance, or else we
3251 end up looping in mysterious Bpt traps */
3254 flush_inferior_icache (pc
, amount
)
3257 vm_machine_attribute_val_t flush
= MATTR_VAL_ICACHE_FLUSH
;
3260 ret
= vm_machine_attribute (current_inferior
->task
->port
,
3265 if (ret
!= KERN_SUCCESS
)
3266 warning ("Error flushing inferior's cache : %s", strerror (ret
));
3268 #endif /* FLUSH_INFERIOR_CACHE */