* h8300-tdep.c: Add H8SX registers. Drop E_NUM_REGS entirely,
[platform/upstream/binutils.git] / gdb / m3-nat.c
1 // OBSOLETE /* Interface GDB to Mach 3.0 operating systems.
2 // OBSOLETE    (Most) Mach 3.0 related routines live in this file.
3 // OBSOLETE 
4 // OBSOLETE    Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
5 // OBSOLETE    2002 Free Software Foundation, Inc.
6 // OBSOLETE 
7 // OBSOLETE    This file is part of GDB.
8 // OBSOLETE 
9 // OBSOLETE    This program is free software; you can redistribute it and/or modify
10 // OBSOLETE    it under the terms of the GNU General Public License as published by
11 // OBSOLETE    the Free Software Foundation; either version 2 of the License, or
12 // OBSOLETE    (at your option) any later version.
13 // OBSOLETE 
14 // OBSOLETE    This program is distributed in the hope that it will be useful,
15 // OBSOLETE    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // OBSOLETE    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // OBSOLETE    GNU General Public License for more details.
18 // OBSOLETE 
19 // OBSOLETE    You should have received a copy of the GNU General Public License
20 // OBSOLETE    along with this program; if not, write to the Free Software
21 // OBSOLETE    Foundation, Inc., 59 Temple Place - Suite 330,
22 // OBSOLETE    Boston, MA 02111-1307, USA.  */
23 // OBSOLETE 
24 // OBSOLETE /*
25 // OBSOLETE  * Author: Jukka Virtanen <jtv@hut.fi>
26 // OBSOLETE  *         Computing Centre
27 // OBSOLETE  *         Helsinki University of Technology
28 // OBSOLETE  *         Finland
29 // OBSOLETE  *
30 // OBSOLETE  * Thanks to my friends who helped with ideas and testing:
31 // OBSOLETE  *
32 // OBSOLETE  *      Johannes Helander, Antti Louko, Tero Mononen,
33 // OBSOLETE  *      jvh@cs.hut.fi      alo@hut.fi   tmo@cs.hut.fi
34 // OBSOLETE  *
35 // OBSOLETE  *      Tero Kivinen       and          Eamonn McManus
36 // OBSOLETE  *      kivinen@cs.hut.fi               emcmanus@gr.osf.org
37 // OBSOLETE  *      
38 // OBSOLETE  */
39 // OBSOLETE 
40 // OBSOLETE #include <stdio.h>
41 // OBSOLETE 
42 // OBSOLETE #include <mach.h>
43 // OBSOLETE #include <servers/netname.h>
44 // OBSOLETE #include <servers/machid.h>
45 // OBSOLETE #include <mach/message.h>
46 // OBSOLETE #include <mach/notify.h>
47 // OBSOLETE #include <mach_error.h>
48 // OBSOLETE #include <mach/exception.h>
49 // OBSOLETE #include <mach/vm_attributes.h>
50 // OBSOLETE 
51 // OBSOLETE #include "defs.h"
52 // OBSOLETE #include "inferior.h"
53 // OBSOLETE #include "symtab.h"
54 // OBSOLETE #include "value.h"
55 // OBSOLETE #include "language.h"
56 // OBSOLETE #include "target.h"
57 // OBSOLETE #include "gdb_wait.h"
58 // OBSOLETE #include "gdbcmd.h"
59 // OBSOLETE #include "gdbcore.h"
60 // OBSOLETE #include "regcache.h"
61 // OBSOLETE 
62 // OBSOLETE #if 0
63 // OBSOLETE #include <servers/machid_lib.h>
64 // OBSOLETE #else
65 // OBSOLETE #define     MACH_TYPE_TASK                  1
66 // OBSOLETE #define MACH_TYPE_THREAD            2
67 // OBSOLETE #endif
68 // OBSOLETE 
69 // OBSOLETE /* Included only for signal names and NSIG
70 // OBSOLETE 
71 // OBSOLETE  * note: There are many problems in signal handling with
72 // OBSOLETE  *       gdb in Mach 3.0 in general.
73 // OBSOLETE  */
74 // OBSOLETE #include <signal.h>
75 // OBSOLETE #define SIG_UNKNOWN 0               /* Exception that has no matching unix signal */
76 // OBSOLETE 
77 // OBSOLETE #include <cthreads.h>
78 // OBSOLETE 
79 // OBSOLETE /* This is what a cproc looks like.  This is here partly because
80 // OBSOLETE    cthread_internals.h is not a header we can just #include, partly with
81 // OBSOLETE    an eye towards perhaps getting this to work with cross-debugging
82 // OBSOLETE    someday.  Best solution is if CMU publishes a real interface to this
83 // OBSOLETE    stuff.  */
84 // OBSOLETE #define CPROC_NEXT_OFFSET 0
85 // OBSOLETE #define CPROC_NEXT_SIZE (TARGET_PTR_BIT / HOST_CHAR_BIT)
86 // OBSOLETE #define CPROC_INCARNATION_OFFSET (CPROC_NEXT_OFFSET + CPROC_NEXT_SIZE)
87 // OBSOLETE #define CPROC_INCARNATION_SIZE (sizeof (cthread_t))
88 // OBSOLETE #define CPROC_LIST_OFFSET (CPROC_INCARNATION_OFFSET + CPROC_INCARNATION_SIZE)
89 // OBSOLETE #define CPROC_LIST_SIZE (TARGET_PTR_BIT / HOST_CHAR_BIT)
90 // OBSOLETE #define CPROC_WAIT_OFFSET (CPROC_LIST_OFFSET + CPROC_LIST_SIZE)
91 // OBSOLETE #define CPROC_WAIT_SIZE (TARGET_PTR_BIT / HOST_CHAR_BIT)
92 // OBSOLETE #define CPROC_REPLY_OFFSET (CPROC_WAIT_OFFSET + CPROC_WAIT_SIZE)
93 // OBSOLETE #define CPROC_REPLY_SIZE (sizeof (mach_port_t))
94 // OBSOLETE #define CPROC_CONTEXT_OFFSET (CPROC_REPLY_OFFSET + CPROC_REPLY_SIZE)
95 // OBSOLETE #define CPROC_CONTEXT_SIZE (TARGET_INT_BIT / HOST_CHAR_BIT)
96 // OBSOLETE #define CPROC_LOCK_OFFSET (CPROC_CONTEXT_OFFSET + CPROC_CONTEXT_SIZE)
97 // OBSOLETE #define CPROC_LOCK_SIZE (sizeof (spin_lock_t))
98 // OBSOLETE #define CPROC_STATE_OFFSET (CPROC_LOCK_OFFSET + CPROC_LOCK_SIZE)
99 // OBSOLETE #define CPROC_STATE_SIZE (TARGET_INT_BIT / HOST_CHAR_BIT)
100 // OBSOLETE #define CPROC_WIRED_OFFSET (CPROC_STATE_OFFSET + CPROC_STATE_SIZE)
101 // OBSOLETE #define CPROC_WIRED_SIZE (sizeof (mach_port_t))
102 // OBSOLETE #define CPROC_BUSY_OFFSET (CPROC_WIRED_OFFSET + CPROC_WIRED_SIZE)
103 // OBSOLETE #define CPROC_BUSY_SIZE (TARGET_INT_BIT / HOST_CHAR_BIT)
104 // OBSOLETE #define CPROC_MSG_OFFSET (CPROC_BUSY_OFFSET + CPROC_BUSY_SIZE)
105 // OBSOLETE #define CPROC_MSG_SIZE (sizeof (mach_msg_header_t))
106 // OBSOLETE #define CPROC_BASE_OFFSET (CPROC_MSG_OFFSET + CPROC_MSG_SIZE)
107 // OBSOLETE #define CPROC_BASE_SIZE (TARGET_INT_BIT / HOST_CHAR_BIT)
108 // OBSOLETE #define CPROC_SIZE_OFFSET (CPROC_BASE_OFFSET + CPROC_BASE_SIZE)
109 // OBSOLETE #define CPROC_SIZE_SIZE (TARGET_INT_BIT / HOST_CHAR_BIT)
110 // OBSOLETE #define CPROC_SIZE (CPROC_SIZE_OFFSET + CPROC_SIZE_SIZE)
111 // OBSOLETE 
112 // OBSOLETE /* Values for the state field in the cproc.  */
113 // OBSOLETE #define CPROC_RUNNING       0
114 // OBSOLETE #define CPROC_SWITCHING 1
115 // OBSOLETE #define CPROC_BLOCKED       2
116 // OBSOLETE #define CPROC_CONDWAIT      4
117 // OBSOLETE 
118 // OBSOLETE /* For cproc and kernel thread mapping */
119 // OBSOLETE typedef struct gdb_thread
120 // OBSOLETE   {
121 // OBSOLETE     mach_port_t name;
122 // OBSOLETE     CORE_ADDR sp;
123 // OBSOLETE     CORE_ADDR pc;
124 // OBSOLETE     CORE_ADDR fp;
125 // OBSOLETE     boolean_t in_emulator;
126 // OBSOLETE     int slotid;
127 // OBSOLETE 
128 // OBSOLETE     /* This is for the mthreads list.  It points to the cproc list.
129 // OBSOLETE        Perhaps the two lists should be merged (or perhaps it was a mistake
130 // OBSOLETE        to make them both use a struct gdb_thread).  */
131 // OBSOLETE     struct gdb_thread *cproc;
132 // OBSOLETE 
133 // OBSOLETE     /* These are for the cproc list, which is linked through the next field
134 // OBSOLETE        of the struct gdb_thread.  */
135 // OBSOLETE     char raw_cproc[CPROC_SIZE];
136 // OBSOLETE     /* The cthread which is pointed to by the incarnation field from the
137 // OBSOLETE        cproc.  This points to the copy we've read into GDB.  */
138 // OBSOLETE     cthread_t cthread;
139 // OBSOLETE     /* Point back to the mthreads list.  */
140 // OBSOLETE     int reverse_map;
141 // OBSOLETE     struct gdb_thread *next;
142 // OBSOLETE   }
143 // OBSOLETE  *gdb_thread_t;
144 // OBSOLETE 
145 // OBSOLETE /* 
146 // OBSOLETE  * Actions for Mach exceptions.
147 // OBSOLETE  *
148 // OBSOLETE  * sigmap field maps the exception to corresponding Unix signal.
149 // OBSOLETE  *
150 // OBSOLETE  * I do not know how to map the exception to unix signal
151 // OBSOLETE  * if SIG_UNKNOWN is specified.
152 // OBSOLETE  */
153 // OBSOLETE 
154 // OBSOLETE struct exception_list
155 // OBSOLETE   {
156 // OBSOLETE     char *name;
157 // OBSOLETE     boolean_t forward;
158 // OBSOLETE     boolean_t print;
159 // OBSOLETE     int sigmap;
160 // OBSOLETE   }
161 // OBSOLETE exception_map[] =
162 // OBSOLETE {
163 // OBSOLETE   {
164 // OBSOLETE     "not_mach3_exception", FALSE, TRUE, SIG_UNKNOWN
165 // OBSOLETE   }
166 // OBSOLETE   ,
167 // OBSOLETE   {
168 // OBSOLETE     "EXC_BAD_ACCESS", FALSE, TRUE, SIGSEGV
169 // OBSOLETE   }
170 // OBSOLETE   ,
171 // OBSOLETE   {
172 // OBSOLETE     "EXC_BAD_INSTRUCTION", FALSE, TRUE, SIGILL
173 // OBSOLETE   }
174 // OBSOLETE   ,
175 // OBSOLETE   {
176 // OBSOLETE     "EXC_ARITHMETIC", FALSE, TRUE, SIGFPE
177 // OBSOLETE   }
178 // OBSOLETE   ,
179 // OBSOLETE   {
180 // OBSOLETE     "EXC_EMULATION", FALSE, TRUE, SIGEMT
181 // OBSOLETE   }
182 // OBSOLETE   ,                         /* ??? */
183 // OBSOLETE   {
184 // OBSOLETE     "EXC_SOFTWARE", FALSE, TRUE, SIG_UNKNOWN
185 // OBSOLETE   }
186 // OBSOLETE   ,
187 // OBSOLETE   {
188 // OBSOLETE     "EXC_BREAKPOINT", FALSE, FALSE, SIGTRAP
189 // OBSOLETE   }
190 // OBSOLETE };
191 // OBSOLETE 
192 // OBSOLETE /* Mach exception table size */
193 // OBSOLETE int max_exception = sizeof (exception_map) / sizeof (struct exception_list) - 1;
194 // OBSOLETE 
195 // OBSOLETE #define MAX_EXCEPTION max_exception
196 // OBSOLETE 
197 // OBSOLETE WAITTYPE wait_status;
198 // OBSOLETE 
199 // OBSOLETE /* If you define this, intercepted bsd server calls will be
200 // OBSOLETE  * dumped while waiting the inferior to EXEC the correct
201 // OBSOLETE  * program
202 // OBSOLETE  */
203 // OBSOLETE /* #define DUMP_SYSCALL         /* debugging interceptor */
204 // OBSOLETE 
205 // OBSOLETE /* xx_debug() outputs messages if this is nonzero.
206 // OBSOLETE  * If > 1, DUMP_SYSCALL will dump message contents.
207 // OBSOLETE  */
208 // OBSOLETE int debug_level = 0;
209 // OBSOLETE 
210 // OBSOLETE /* "Temporary" debug stuff */
211 // OBSOLETE void
212 // OBSOLETE xx_debug (char *fmt, int a, int b, int c)
213 // OBSOLETE {
214 // OBSOLETE   if (debug_level)
215 // OBSOLETE     warning (fmt, a, b, c);
216 // OBSOLETE }
217 // OBSOLETE 
218 // OBSOLETE /* This is in libmach.a */
219 // OBSOLETE extern mach_port_t name_server_port;
220 // OBSOLETE 
221 // OBSOLETE /* Set in catch_exception_raise */
222 // OBSOLETE int stop_exception, stop_code, stop_subcode;
223 // OBSOLETE int stopped_in_exception;
224 // OBSOLETE 
225 // OBSOLETE /* Thread that was the active thread when we stopped */
226 // OBSOLETE thread_t stop_thread = MACH_PORT_NULL;
227 // OBSOLETE 
228 // OBSOLETE char *hostname = "";
229 // OBSOLETE 
230 // OBSOLETE /* Set when task is attached or created */
231 // OBSOLETE boolean_t emulator_present = FALSE;
232 // OBSOLETE 
233 // OBSOLETE task_t inferior_task;
234 // OBSOLETE thread_t current_thread;
235 // OBSOLETE 
236 // OBSOLETE /* Exception ports for inferior task */
237 // OBSOLETE mach_port_t inferior_exception_port = MACH_PORT_NULL;
238 // OBSOLETE mach_port_t inferior_old_exception_port = MACH_PORT_NULL;
239 // OBSOLETE 
240 // OBSOLETE /* task exceptions and notifications */
241 // OBSOLETE mach_port_t inferior_wait_port_set = MACH_PORT_NULL;
242 // OBSOLETE mach_port_t our_notify_port = MACH_PORT_NULL;
243 // OBSOLETE 
244 // OBSOLETE /* This is "inferior_wait_port_set" when not single stepping, and
245 // OBSOLETE  *         "singlestepped_thread_port" when we are single stepping.
246 // OBSOLETE  * 
247 // OBSOLETE  * This is protected by a cleanup function: discard_single_step()
248 // OBSOLETE  */
249 // OBSOLETE mach_port_t currently_waiting_for = MACH_PORT_NULL;
250 // OBSOLETE 
251 // OBSOLETE /* A port for external messages to gdb.
252 // OBSOLETE  * External in the meaning that they do not come
253 // OBSOLETE  * from the inferior_task, but rather from external
254 // OBSOLETE  * tasks.
255 // OBSOLETE  *
256 // OBSOLETE  * As a debugging feature:
257 // OBSOLETE  * A debugger debugging another debugger can stop the
258 // OBSOLETE  * inferior debugger by the following command sequence
259 // OBSOLETE  * (without running external programs)
260 // OBSOLETE  *
261 // OBSOLETE  *    (top-gdb) set stop_inferior_gdb ()
262 // OBSOLETE  *    (top-gdb) continue
263 // OBSOLETE  */
264 // OBSOLETE mach_port_t our_message_port = MACH_PORT_NULL;
265 // OBSOLETE 
266 // OBSOLETE /* For single stepping */
267 // OBSOLETE mach_port_t thread_exception_port = MACH_PORT_NULL;
268 // OBSOLETE mach_port_t thread_saved_exception_port = MACH_PORT_NULL;
269 // OBSOLETE mach_port_t singlestepped_thread_port = MACH_PORT_NULL;
270 // OBSOLETE 
271 // OBSOLETE /* For machid calls */
272 // OBSOLETE mach_port_t mid_server = MACH_PORT_NULL;
273 // OBSOLETE mach_port_t mid_auth = MACH_PORT_NULL;
274 // OBSOLETE 
275 // OBSOLETE /* If gdb thinks the inferior task is not suspended, it
276 // OBSOLETE  * must take suspend/abort the threads when it reads the state.
277 // OBSOLETE  */
278 // OBSOLETE int must_suspend_thread = 0;
279 // OBSOLETE 
280 // OBSOLETE /* When single stepping, we switch the port that mach_really_wait() listens to.
281 // OBSOLETE  * This cleanup is a guard to prevent the port set from being left to
282 // OBSOLETE  * the singlestepped_thread_port when error() is called.
283 // OBSOLETE  *  This is nonzero only when we are single stepping.
284 // OBSOLETE  */
285 // OBSOLETE #define NULL_CLEANUP (struct cleanup *)0
286 // OBSOLETE struct cleanup *cleanup_step = NULL_CLEANUP;
287 // OBSOLETE \f
288 // OBSOLETE 
289 // OBSOLETE static struct target_ops m3_ops;
290 // OBSOLETE 
291 // OBSOLETE static void m3_kill_inferior ();
292 // OBSOLETE \f
293 // OBSOLETE #if 0
294 // OBSOLETE #define MACH_TYPE_EXCEPTION_PORT    -1
295 // OBSOLETE #endif
296 // OBSOLETE 
297 // OBSOLETE /* Chain of ports to remember requested notifications. */
298 // OBSOLETE 
299 // OBSOLETE struct port_chain
300 // OBSOLETE   {
301 // OBSOLETE     struct port_chain *next;
302 // OBSOLETE     mach_port_t port;
303 // OBSOLETE     int type;
304 // OBSOLETE     int mid;                        /* Now only valid with MACH_TYPE_THREAD and */
305 // OBSOLETE     /*  MACH_TYPE_THREAD */
306 // OBSOLETE   };
307 // OBSOLETE typedef struct port_chain *port_chain_t;
308 // OBSOLETE 
309 // OBSOLETE /* Room for chain nodes comes from pchain_obstack */
310 // OBSOLETE struct obstack pchain_obstack;
311 // OBSOLETE struct obstack *port_chain_obstack = &pchain_obstack;
312 // OBSOLETE 
313 // OBSOLETE /* For thread handling */
314 // OBSOLETE struct obstack Cproc_obstack;
315 // OBSOLETE struct obstack *cproc_obstack = &Cproc_obstack;
316 // OBSOLETE 
317 // OBSOLETE /* the list of notified ports */
318 // OBSOLETE port_chain_t notify_chain = (port_chain_t) NULL;
319 // OBSOLETE 
320 // OBSOLETE port_chain_t
321 // OBSOLETE port_chain_insert (port_chain_t list, mach_port_t name, int type)
322 // OBSOLETE {
323 // OBSOLETE   kern_return_t ret;
324 // OBSOLETE   port_chain_t new;
325 // OBSOLETE   int mid;
326 // OBSOLETE 
327 // OBSOLETE   if (!MACH_PORT_VALID (name))
328 // OBSOLETE     return list;
329 // OBSOLETE 
330 // OBSOLETE   if (type == MACH_TYPE_TASK || type == MACH_TYPE_THREAD)
331 // OBSOLETE     {
332 // OBSOLETE       if (!MACH_PORT_VALID (mid_server))
333 // OBSOLETE     {
334 // OBSOLETE       warning ("Machid server port invalid, can not map port 0x%x to MID",
335 // OBSOLETE                name);
336 // OBSOLETE       mid = name;
337 // OBSOLETE     }
338 // OBSOLETE       else
339 // OBSOLETE     {
340 // OBSOLETE       ret = machid_mach_register (mid_server, mid_auth, name, type, &mid);
341 // OBSOLETE 
342 // OBSOLETE       if (ret != KERN_SUCCESS)
343 // OBSOLETE         {
344 // OBSOLETE           warning ("Can not map name (0x%x) to MID with machid", name);
345 // OBSOLETE           mid = name;
346 // OBSOLETE         }
347 // OBSOLETE     }
348 // OBSOLETE     }
349 // OBSOLETE   else
350 // OBSOLETE     internal_error (__FILE__, __LINE__, "failed internal consistency check");
351 // OBSOLETE 
352 // OBSOLETE   new = (port_chain_t) obstack_alloc (port_chain_obstack,
353 // OBSOLETE                                   sizeof (struct port_chain));
354 // OBSOLETE   new->next = list;
355 // OBSOLETE   new->port = name;
356 // OBSOLETE   new->type = type;
357 // OBSOLETE   new->mid = mid;
358 // OBSOLETE 
359 // OBSOLETE   return new;
360 // OBSOLETE }
361 // OBSOLETE 
362 // OBSOLETE port_chain_t
363 // OBSOLETE port_chain_delete (port_chain_t list, mach_port_t elem)
364 // OBSOLETE {
365 // OBSOLETE   if (list)
366 // OBSOLETE     if (list->port == elem)
367 // OBSOLETE       list = list->next;
368 // OBSOLETE     else
369 // OBSOLETE       while (list->next)
370 // OBSOLETE     {
371 // OBSOLETE       if (list->next->port == elem)
372 // OBSOLETE         list->next = list->next->next;      /* GCd with obstack_free() */
373 // OBSOLETE       else
374 // OBSOLETE         list = list->next;
375 // OBSOLETE     }
376 // OBSOLETE   return list;
377 // OBSOLETE }
378 // OBSOLETE 
379 // OBSOLETE void
380 // OBSOLETE port_chain_destroy (struct obstack *ostack)
381 // OBSOLETE {
382 // OBSOLETE   obstack_free (ostack, 0);
383 // OBSOLETE   obstack_init (ostack);
384 // OBSOLETE }
385 // OBSOLETE 
386 // OBSOLETE port_chain_t
387 // OBSOLETE port_chain_member (port_chain_t list, mach_port_t elem)
388 // OBSOLETE {
389 // OBSOLETE   while (list)
390 // OBSOLETE     {
391 // OBSOLETE       if (list->port == elem)
392 // OBSOLETE     return list;
393 // OBSOLETE       list = list->next;
394 // OBSOLETE     }
395 // OBSOLETE   return (port_chain_t) NULL;
396 // OBSOLETE }
397 // OBSOLETE \f
398 // OBSOLETE int
399 // OBSOLETE map_port_name_to_mid (mach_port_t name, int type)
400 // OBSOLETE {
401 // OBSOLETE   port_chain_t elem;
402 // OBSOLETE 
403 // OBSOLETE   if (!MACH_PORT_VALID (name))
404 // OBSOLETE     return -1;
405 // OBSOLETE 
406 // OBSOLETE   elem = port_chain_member (notify_chain, name);
407 // OBSOLETE 
408 // OBSOLETE   if (elem && (elem->type == type))
409 // OBSOLETE     return elem->mid;
410 // OBSOLETE 
411 // OBSOLETE   if (elem)
412 // OBSOLETE     return -1;
413 // OBSOLETE 
414 // OBSOLETE   if (!MACH_PORT_VALID (mid_server))
415 // OBSOLETE     {
416 // OBSOLETE       warning ("Machid server port invalid, can not map port 0x%x to mid",
417 // OBSOLETE            name);
418 // OBSOLETE       return -1;
419 // OBSOLETE     }
420 // OBSOLETE   else
421 // OBSOLETE     {
422 // OBSOLETE       int mid;
423 // OBSOLETE       kern_return_t ret;
424 // OBSOLETE 
425 // OBSOLETE       ret = machid_mach_register (mid_server, mid_auth, name, type, &mid);
426 // OBSOLETE 
427 // OBSOLETE       if (ret != KERN_SUCCESS)
428 // OBSOLETE     {
429 // OBSOLETE       warning ("Can not map name (0x%x) to mid with machid", name);
430 // OBSOLETE       return -1;
431 // OBSOLETE     }
432 // OBSOLETE       return mid;
433 // OBSOLETE     }
434 // OBSOLETE }
435 // OBSOLETE \f
436 // OBSOLETE /* Guard for currently_waiting_for and singlestepped_thread_port */
437 // OBSOLETE static void
438 // OBSOLETE discard_single_step (thread_t thread)
439 // OBSOLETE {
440 // OBSOLETE   currently_waiting_for = inferior_wait_port_set;
441 // OBSOLETE 
442 // OBSOLETE   cleanup_step = NULL_CLEANUP;
443 // OBSOLETE   if (MACH_PORT_VALID (thread) && MACH_PORT_VALID (singlestepped_thread_port))
444 // OBSOLETE     setup_single_step (thread, FALSE);
445 // OBSOLETE }
446 // OBSOLETE 
447 // OBSOLETE setup_single_step (thread_t thread, boolean_t start_step)
448 // OBSOLETE {
449 // OBSOLETE   kern_return_t ret;
450 // OBSOLETE 
451 // OBSOLETE   if (!MACH_PORT_VALID (thread))
452 // OBSOLETE     error ("Invalid thread supplied to setup_single_step");
453 // OBSOLETE   else
454 // OBSOLETE     {
455 // OBSOLETE       mach_port_t teport;
456 // OBSOLETE 
457 // OBSOLETE       /* Get the current thread exception port */
458 // OBSOLETE       ret = thread_get_exception_port (thread, &teport);
459 // OBSOLETE       CHK ("Getting thread's exception port", ret);
460 // OBSOLETE 
461 // OBSOLETE       if (start_step)
462 // OBSOLETE     {
463 // OBSOLETE       if (MACH_PORT_VALID (singlestepped_thread_port))
464 // OBSOLETE         {
465 // OBSOLETE           warning ("Singlestepped_thread_port (0x%x) is still valid?",
466 // OBSOLETE                    singlestepped_thread_port);
467 // OBSOLETE           singlestepped_thread_port = MACH_PORT_NULL;
468 // OBSOLETE         }
469 // OBSOLETE 
470 // OBSOLETE       /* If we are already stepping this thread */
471 // OBSOLETE       if (MACH_PORT_VALID (teport) && teport == thread_exception_port)
472 // OBSOLETE         {
473 // OBSOLETE           ret = mach_port_deallocate (mach_task_self (), teport);
474 // OBSOLETE           CHK ("Could not deallocate thread exception port", ret);
475 // OBSOLETE         }
476 // OBSOLETE       else
477 // OBSOLETE         {
478 // OBSOLETE           ret = thread_set_exception_port (thread, thread_exception_port);
479 // OBSOLETE           CHK ("Setting exception port for thread", ret);
480 // OBSOLETE #if 0
481 // OBSOLETE           /* Insert thread exception port to wait port set */
482 // OBSOLETE           ret = mach_port_move_member (mach_task_self (),
483 // OBSOLETE                                        thread_exception_port,
484 // OBSOLETE                                        inferior_wait_port_set);
485 // OBSOLETE           CHK ("Moving thread exception port to inferior_wait_port_set",
486 // OBSOLETE                ret);
487 // OBSOLETE #endif
488 // OBSOLETE           thread_saved_exception_port = teport;
489 // OBSOLETE         }
490 // OBSOLETE 
491 // OBSOLETE       thread_trace (thread, TRUE);
492 // OBSOLETE 
493 // OBSOLETE       singlestepped_thread_port = thread_exception_port;
494 // OBSOLETE       currently_waiting_for = singlestepped_thread_port;
495 // OBSOLETE       cleanup_step = make_cleanup (discard_single_step, thread);
496 // OBSOLETE     }
497 // OBSOLETE       else
498 // OBSOLETE     {
499 // OBSOLETE       if (!MACH_PORT_VALID (teport))
500 // OBSOLETE         error ("Single stepped thread had an invalid exception port?");
501 // OBSOLETE 
502 // OBSOLETE       if (teport != thread_exception_port)
503 // OBSOLETE         error ("Single stepped thread had an unknown exception port?");
504 // OBSOLETE 
505 // OBSOLETE       ret = mach_port_deallocate (mach_task_self (), teport);
506 // OBSOLETE       CHK ("Couldn't deallocate thread exception port", ret);
507 // OBSOLETE #if 0
508 // OBSOLETE       /* Remove thread exception port from wait port set */
509 // OBSOLETE       ret = mach_port_move_member (mach_task_self (),
510 // OBSOLETE                                    thread_exception_port,
511 // OBSOLETE                                    MACH_PORT_NULL);
512 // OBSOLETE       CHK ("Removing thread exception port from inferior_wait_port_set",
513 // OBSOLETE            ret);
514 // OBSOLETE #endif
515 // OBSOLETE       /* Restore thread's old exception port */
516 // OBSOLETE       ret = thread_set_exception_port (thread,
517 // OBSOLETE                                        thread_saved_exception_port);
518 // OBSOLETE       CHK ("Restoring stepped thread's exception port", ret);
519 // OBSOLETE 
520 // OBSOLETE       if (MACH_PORT_VALID (thread_saved_exception_port))
521 // OBSOLETE         (void) mach_port_deallocate (mach_task_self (),
522 // OBSOLETE                                      thread_saved_exception_port);
523 // OBSOLETE 
524 // OBSOLETE       thread_trace (thread, FALSE);
525 // OBSOLETE 
526 // OBSOLETE       singlestepped_thread_port = MACH_PORT_NULL;
527 // OBSOLETE       currently_waiting_for = inferior_wait_port_set;
528 // OBSOLETE       if (cleanup_step)
529 // OBSOLETE         discard_cleanups (cleanup_step);
530 // OBSOLETE     }
531 // OBSOLETE     }
532 // OBSOLETE }
533 // OBSOLETE \f
534 // OBSOLETE static
535 // OBSOLETE request_notify (mach_port_t name, mach_msg_id_t variant, int type)
536 // OBSOLETE {
537 // OBSOLETE   kern_return_t ret;
538 // OBSOLETE   mach_port_t previous_port_dummy = MACH_PORT_NULL;
539 // OBSOLETE 
540 // OBSOLETE   if (!MACH_PORT_VALID (name))
541 // OBSOLETE     return;
542 // OBSOLETE 
543 // OBSOLETE   if (port_chain_member (notify_chain, name))
544 // OBSOLETE     return;
545 // OBSOLETE 
546 // OBSOLETE   ret = mach_port_request_notification (mach_task_self (),
547 // OBSOLETE                                     name,
548 // OBSOLETE                                     variant,
549 // OBSOLETE                                     1,
550 // OBSOLETE                                     our_notify_port,
551 // OBSOLETE                                     MACH_MSG_TYPE_MAKE_SEND_ONCE,
552 // OBSOLETE                                     &previous_port_dummy);
553 // OBSOLETE   CHK ("Serious: request_notify failed", ret);
554 // OBSOLETE 
555 // OBSOLETE   (void) mach_port_deallocate (mach_task_self (),
556 // OBSOLETE                            previous_port_dummy);
557 // OBSOLETE 
558 // OBSOLETE   notify_chain = port_chain_insert (notify_chain, name, type);
559 // OBSOLETE }
560 // OBSOLETE 
561 // OBSOLETE reverse_msg_bits (mach_msg_header_t *msgp, int type)
562 // OBSOLETE {
563 // OBSOLETE   int rbits, lbits;
564 // OBSOLETE   rbits = MACH_MSGH_BITS_REMOTE (msgp->msgh_bits);
565 // OBSOLETE   lbits = type;
566 // OBSOLETE   msgp->msgh_bits =
567 // OBSOLETE     (msgp->msgh_bits & ~MACH_MSGH_BITS_PORTS_MASK) |
568 // OBSOLETE     MACH_MSGH_BITS (lbits, rbits);
569 // OBSOLETE }
570 // OBSOLETE \f
571 // OBSOLETE /* On the third day He said:
572 // OBSOLETE 
573 // OBSOLETE    Let this be global
574 // OBSOLETE    and then it was global.
575 // OBSOLETE 
576 // OBSOLETE    When creating the inferior fork, the
577 // OBSOLETE    child code in inflow.c sets the name of the
578 // OBSOLETE    bootstrap_port in its address space to this
579 // OBSOLETE    variable.
580 // OBSOLETE 
581 // OBSOLETE    The name is transferred to our address space
582 // OBSOLETE    with mach3_read_inferior().
583 // OBSOLETE 
584 // OBSOLETE    Thou shalt not do this with
585 // OBSOLETE    task_get_bootstrap_port() in this task, since
586 // OBSOLETE    the name in the inferior task is different than
587 // OBSOLETE    the one we get.
588 // OBSOLETE 
589 // OBSOLETE    For blessed are the meek, as they shall inherit
590 // OBSOLETE    the address space.
591 // OBSOLETE  */
592 // OBSOLETE mach_port_t original_server_port_name = MACH_PORT_NULL;
593 // OBSOLETE 
594 // OBSOLETE 
595 // OBSOLETE /* Called from inferior after FORK but before EXEC */
596 // OBSOLETE static void
597 // OBSOLETE m3_trace_me (void)
598 // OBSOLETE {
599 // OBSOLETE   kern_return_t ret;
600 // OBSOLETE 
601 // OBSOLETE   /* Get the NAME of the bootstrap port in this task
602 // OBSOLETE      so that GDB can read it */
603 // OBSOLETE   ret = task_get_bootstrap_port (mach_task_self (),
604 // OBSOLETE                              &original_server_port_name);
605 // OBSOLETE   if (ret != KERN_SUCCESS)
606 // OBSOLETE     internal_error (__FILE__, __LINE__, "failed internal consistency check");
607 // OBSOLETE   ret = mach_port_deallocate (mach_task_self (),
608 // OBSOLETE                           original_server_port_name);
609 // OBSOLETE   if (ret != KERN_SUCCESS)
610 // OBSOLETE     internal_error (__FILE__, __LINE__, "failed internal consistency check");
611 // OBSOLETE 
612 // OBSOLETE   /* Suspend this task to let the parent change my ports.
613 // OBSOLETE      Resumed by the debugger */
614 // OBSOLETE   ret = task_suspend (mach_task_self ());
615 // OBSOLETE   if (ret != KERN_SUCCESS)
616 // OBSOLETE     internal_error (__FILE__, __LINE__, "failed internal consistency check");
617 // OBSOLETE }
618 // OBSOLETE \f
619 // OBSOLETE /*
620 // OBSOLETE  * Intercept system calls to Unix server.
621 // OBSOLETE  * After EXEC_COUNTER calls to exec(), return.
622 // OBSOLETE  *
623 // OBSOLETE  * Pre-assertion:  Child is suspended. (Not verified)
624 // OBSOLETE  * Post-condition: Child is suspended after EXEC_COUNTER exec() calls.
625 // OBSOLETE  */
626 // OBSOLETE 
627 // OBSOLETE void
628 // OBSOLETE intercept_exec_calls (int exec_counter)
629 // OBSOLETE {
630 // OBSOLETE   int terminal_initted = 0;
631 // OBSOLETE 
632 // OBSOLETE   struct syscall_msg_t
633 // OBSOLETE     {
634 // OBSOLETE       mach_msg_header_t header;
635 // OBSOLETE       mach_msg_type_t type;
636 // OBSOLETE       char room[2000];              /* Enuff space */
637 // OBSOLETE     };
638 // OBSOLETE 
639 // OBSOLETE   struct syscall_msg_t syscall_in, syscall_out;
640 // OBSOLETE 
641 // OBSOLETE   mach_port_t fake_server;
642 // OBSOLETE   mach_port_t original_server_send;
643 // OBSOLETE   mach_port_t original_exec_reply;
644 // OBSOLETE   mach_port_t exec_reply;
645 // OBSOLETE   mach_port_t exec_reply_send;
646 // OBSOLETE   mach_msg_type_name_t acquired;
647 // OBSOLETE   mach_port_t emulator_server_port_name;
648 // OBSOLETE   struct task_basic_info info;
649 // OBSOLETE   mach_msg_type_number_t info_count;
650 // OBSOLETE 
651 // OBSOLETE   kern_return_t ret;
652 // OBSOLETE 
653 // OBSOLETE   if (exec_counter <= 0)
654 // OBSOLETE     return;                 /* We are already set up in the correct program */
655 // OBSOLETE 
656 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
657 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
658 // OBSOLETE                         &fake_server);
659 // OBSOLETE   CHK ("create inferior_fake_server port failed", ret);
660 // OBSOLETE 
661 // OBSOLETE   /* Wait for inferior_task to suspend itself */
662 // OBSOLETE   while (1)
663 // OBSOLETE     {
664 // OBSOLETE       info_count = sizeof (info);
665 // OBSOLETE       ret = task_info (inferior_task,
666 // OBSOLETE                    TASK_BASIC_INFO,
667 // OBSOLETE                    (task_info_t) & info,
668 // OBSOLETE                    &info_count);
669 // OBSOLETE       CHK ("Task info", ret);
670 // OBSOLETE 
671 // OBSOLETE       if (info.suspend_count)
672 // OBSOLETE     break;
673 // OBSOLETE 
674 // OBSOLETE       /* Note that the definition of the parameter was undefined
675 // OBSOLETE        * at the time of this writing, so I just use an `ad hoc' value.
676 // OBSOLETE        */
677 // OBSOLETE       (void) swtch_pri (42);        /* Universal Priority Value */
678 // OBSOLETE     }
679 // OBSOLETE 
680 // OBSOLETE   /* Read the inferior's bootstrap port name */
681 // OBSOLETE   if (!mach3_read_inferior (&original_server_port_name,
682 // OBSOLETE                         &original_server_port_name,
683 // OBSOLETE                         sizeof (original_server_port_name)))
684 // OBSOLETE     error ("Can't read inferior task bootstrap port name");
685 // OBSOLETE 
686 // OBSOLETE   /* @@ BUG: If more than 1 send right GDB will FAIL!!! */
687 // OBSOLETE   /*      Should get refs, and set them back when restoring */
688 // OBSOLETE   /* Steal the original bsd server send right from inferior */
689 // OBSOLETE   ret = mach_port_extract_right (inferior_task,
690 // OBSOLETE                              original_server_port_name,
691 // OBSOLETE                              MACH_MSG_TYPE_MOVE_SEND,
692 // OBSOLETE                              &original_server_send,
693 // OBSOLETE                              &acquired);
694 // OBSOLETE   CHK ("mach_port_extract_right (bsd server send)", ret);
695 // OBSOLETE 
696 // OBSOLETE   if (acquired != MACH_MSG_TYPE_PORT_SEND)
697 // OBSOLETE     error ("Incorrect right extracted, send right to bsd server expected");
698 // OBSOLETE 
699 // OBSOLETE   ret = mach_port_insert_right (inferior_task,
700 // OBSOLETE                             original_server_port_name,
701 // OBSOLETE                             fake_server,
702 // OBSOLETE                             MACH_MSG_TYPE_MAKE_SEND);
703 // OBSOLETE   CHK ("mach_port_insert_right (fake server send)", ret);
704 // OBSOLETE 
705 // OBSOLETE   xx_debug ("inferior task bsd server ports set up \nfs %x, ospn %x, oss %x\n",
706 // OBSOLETE         fake_server,
707 // OBSOLETE         original_server_port_name, original_server_send);
708 // OBSOLETE 
709 // OBSOLETE   /* A receive right to the reply generated by unix server exec() request */
710 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
711 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
712 // OBSOLETE                         &exec_reply);
713 // OBSOLETE   CHK ("create intercepted_reply_port port failed", ret);
714 // OBSOLETE 
715 // OBSOLETE   /* Pass this send right to Unix server so it replies to us after exec() */
716 // OBSOLETE   ret = mach_port_extract_right (mach_task_self (),
717 // OBSOLETE                              exec_reply,
718 // OBSOLETE                              MACH_MSG_TYPE_MAKE_SEND_ONCE,
719 // OBSOLETE                              &exec_reply_send,
720 // OBSOLETE                              &acquired);
721 // OBSOLETE   CHK ("mach_port_extract_right (exec_reply)", ret);
722 // OBSOLETE 
723 // OBSOLETE   if (acquired != MACH_MSG_TYPE_PORT_SEND_ONCE)
724 // OBSOLETE     error ("Incorrect right extracted, send once expected for exec reply");
725 // OBSOLETE 
726 // OBSOLETE   ret = mach_port_move_member (mach_task_self (),
727 // OBSOLETE                            fake_server,
728 // OBSOLETE                            inferior_wait_port_set);
729 // OBSOLETE   CHK ("Moving fake syscall port to inferior_wait_port_set", ret);
730 // OBSOLETE 
731 // OBSOLETE   xx_debug ("syscall fake server set up, resuming inferior\n");
732 // OBSOLETE 
733 // OBSOLETE   ret = task_resume (inferior_task);
734 // OBSOLETE   CHK ("task_resume (startup)", ret);
735 // OBSOLETE 
736 // OBSOLETE   /* Read requests from the inferior.
737 // OBSOLETE      Pass directly through everything else except exec() calls.
738 // OBSOLETE    */
739 // OBSOLETE   while (exec_counter > 0)
740 // OBSOLETE     {
741 // OBSOLETE       ret = mach_msg (&syscall_in.header,   /* header */
742 // OBSOLETE                   MACH_RCV_MSG,     /* options */
743 // OBSOLETE                   0,        /* send size */
744 // OBSOLETE                   sizeof (struct syscall_msg_t),    /* receive size */
745 // OBSOLETE                   inferior_wait_port_set,   /* receive_name */
746 // OBSOLETE                   MACH_MSG_TIMEOUT_NONE,
747 // OBSOLETE                   MACH_PORT_NULL);
748 // OBSOLETE       CHK ("mach_msg (intercepted sycall)", ret);
749 // OBSOLETE 
750 // OBSOLETE #ifdef DUMP_SYSCALL
751 // OBSOLETE       print_msg (&syscall_in.header);
752 // OBSOLETE #endif
753 // OBSOLETE 
754 // OBSOLETE       /* ASSERT : msgh_local_port == fake_server */
755 // OBSOLETE 
756 // OBSOLETE       if (notify_server (&syscall_in.header, &syscall_out.header))
757 // OBSOLETE     error ("received a notify while intercepting syscalls");
758 // OBSOLETE 
759 // OBSOLETE       if (syscall_in.header.msgh_id == MIG_EXEC_SYSCALL_ID)
760 // OBSOLETE     {
761 // OBSOLETE       xx_debug ("Received EXEC SYSCALL, counter = %d\n", exec_counter);
762 // OBSOLETE       if (exec_counter == 1)
763 // OBSOLETE         {
764 // OBSOLETE           original_exec_reply = syscall_in.header.msgh_remote_port;
765 // OBSOLETE           syscall_in.header.msgh_remote_port = exec_reply_send;
766 // OBSOLETE         }
767 // OBSOLETE 
768 // OBSOLETE       if (!terminal_initted)
769 // OBSOLETE         {
770 // OBSOLETE           /* Now that the child has exec'd we know it has already set its
771 // OBSOLETE              process group.  On POSIX systems, tcsetpgrp will fail with
772 // OBSOLETE              EPERM if we try it before the child's setpgid.  */
773 // OBSOLETE 
774 // OBSOLETE           /* Set up the "saved terminal modes" of the inferior
775 // OBSOLETE              based on what modes we are starting it with.  */
776 // OBSOLETE           target_terminal_init ();
777 // OBSOLETE 
778 // OBSOLETE           /* Install inferior's terminal modes.  */
779 // OBSOLETE           target_terminal_inferior ();
780 // OBSOLETE 
781 // OBSOLETE           terminal_initted = 1;
782 // OBSOLETE         }
783 // OBSOLETE 
784 // OBSOLETE       exec_counter--;
785 // OBSOLETE     }
786 // OBSOLETE 
787 // OBSOLETE       syscall_in.header.msgh_local_port = syscall_in.header.msgh_remote_port;
788 // OBSOLETE       syscall_in.header.msgh_remote_port = original_server_send;
789 // OBSOLETE 
790 // OBSOLETE       reverse_msg_bits (&syscall_in.header, MACH_MSG_TYPE_COPY_SEND);
791 // OBSOLETE 
792 // OBSOLETE       ret = mach_msg_send (&syscall_in.header);
793 // OBSOLETE       CHK ("Forwarded syscall", ret);
794 // OBSOLETE     }
795 // OBSOLETE 
796 // OBSOLETE   ret = mach_port_move_member (mach_task_self (),
797 // OBSOLETE                            fake_server,
798 // OBSOLETE                            MACH_PORT_NULL);
799 // OBSOLETE   CHK ("Moving fake syscall out of inferior_wait_port_set", ret);
800 // OBSOLETE 
801 // OBSOLETE   ret = mach_port_move_member (mach_task_self (),
802 // OBSOLETE                            exec_reply,
803 // OBSOLETE                            inferior_wait_port_set);
804 // OBSOLETE   CHK ("Moving exec_reply to inferior_wait_port_set", ret);
805 // OBSOLETE 
806 // OBSOLETE   ret = mach_msg (&syscall_in.header,       /* header */
807 // OBSOLETE               MACH_RCV_MSG, /* options */
808 // OBSOLETE               0,            /* send size */
809 // OBSOLETE               sizeof (struct syscall_msg_t),        /* receive size */
810 // OBSOLETE               inferior_wait_port_set,       /* receive_name */
811 // OBSOLETE               MACH_MSG_TIMEOUT_NONE,
812 // OBSOLETE               MACH_PORT_NULL);
813 // OBSOLETE   CHK ("mach_msg (exec reply)", ret);
814 // OBSOLETE 
815 // OBSOLETE   ret = task_suspend (inferior_task);
816 // OBSOLETE   CHK ("Suspending inferior after last exec", ret);
817 // OBSOLETE 
818 // OBSOLETE   must_suspend_thread = 0;
819 // OBSOLETE 
820 // OBSOLETE   xx_debug ("Received exec reply from bsd server, suspended inferior task\n");
821 // OBSOLETE 
822 // OBSOLETE #ifdef DUMP_SYSCALL
823 // OBSOLETE   print_msg (&syscall_in.header);
824 // OBSOLETE #endif
825 // OBSOLETE 
826 // OBSOLETE   /* Message should appear as if it came from the unix server */
827 // OBSOLETE   syscall_in.header.msgh_local_port = MACH_PORT_NULL;
828 // OBSOLETE 
829 // OBSOLETE   /*  and go to the inferior task original reply port */
830 // OBSOLETE   syscall_in.header.msgh_remote_port = original_exec_reply;
831 // OBSOLETE 
832 // OBSOLETE   reverse_msg_bits (&syscall_in.header, MACH_MSG_TYPE_MOVE_SEND_ONCE);
833 // OBSOLETE 
834 // OBSOLETE   ret = mach_msg_send (&syscall_in.header);
835 // OBSOLETE   CHK ("Forwarding exec reply to inferior", ret);
836 // OBSOLETE 
837 // OBSOLETE   /* Garbage collect */
838 // OBSOLETE   ret = mach_port_deallocate (inferior_task,
839 // OBSOLETE                           original_server_port_name);
840 // OBSOLETE   CHK ("deallocating fake server send right", ret);
841 // OBSOLETE 
842 // OBSOLETE   ret = mach_port_insert_right (inferior_task,
843 // OBSOLETE                             original_server_port_name,
844 // OBSOLETE                             original_server_send,
845 // OBSOLETE                             MACH_MSG_TYPE_MOVE_SEND);
846 // OBSOLETE   CHK ("Restoring the original bsd server send right", ret);
847 // OBSOLETE 
848 // OBSOLETE   ret = mach_port_destroy (mach_task_self (),
849 // OBSOLETE                        fake_server);
850 // OBSOLETE   fake_server = MACH_PORT_DEAD;
851 // OBSOLETE   CHK ("mach_port_destroy (fake_server)", ret);
852 // OBSOLETE 
853 // OBSOLETE   ret = mach_port_destroy (mach_task_self (),
854 // OBSOLETE                        exec_reply);
855 // OBSOLETE   exec_reply = MACH_PORT_DEAD;
856 // OBSOLETE   CHK ("mach_port_destroy (exec_reply)", ret);
857 // OBSOLETE 
858 // OBSOLETE   xx_debug ("Done with exec call interception\n");
859 // OBSOLETE }
860 // OBSOLETE 
861 // OBSOLETE void
862 // OBSOLETE consume_send_rights (thread_array_t thread_list, int thread_count)
863 // OBSOLETE {
864 // OBSOLETE   int index;
865 // OBSOLETE 
866 // OBSOLETE   if (!thread_count)
867 // OBSOLETE     return;
868 // OBSOLETE 
869 // OBSOLETE   for (index = 0; index < thread_count; index++)
870 // OBSOLETE     {
871 // OBSOLETE       /* Since thread kill command kills threads, don't check ret */
872 // OBSOLETE       (void) mach_port_deallocate (mach_task_self (),
873 // OBSOLETE                                thread_list[index]);
874 // OBSOLETE     }
875 // OBSOLETE }
876 // OBSOLETE 
877 // OBSOLETE /* suspend/abort/resume a thread. */
878 // OBSOLETE setup_thread (mach_port_t thread, int what)
879 // OBSOLETE {
880 // OBSOLETE   kern_return_t ret;
881 // OBSOLETE 
882 // OBSOLETE   if (what)
883 // OBSOLETE     {
884 // OBSOLETE       ret = thread_suspend (thread);
885 // OBSOLETE       CHK ("setup_thread thread_suspend", ret);
886 // OBSOLETE 
887 // OBSOLETE       ret = thread_abort (thread);
888 // OBSOLETE       CHK ("setup_thread thread_abort", ret);
889 // OBSOLETE     }
890 // OBSOLETE   else
891 // OBSOLETE     {
892 // OBSOLETE       ret = thread_resume (thread);
893 // OBSOLETE       CHK ("setup_thread thread_resume", ret);
894 // OBSOLETE     }
895 // OBSOLETE }
896 // OBSOLETE 
897 // OBSOLETE int
898 // OBSOLETE map_slot_to_mid (int slot, thread_array_t threads, int thread_count)
899 // OBSOLETE {
900 // OBSOLETE   kern_return_t ret;
901 // OBSOLETE   int deallocate = 0;
902 // OBSOLETE   int index;
903 // OBSOLETE   int mid;
904 // OBSOLETE 
905 // OBSOLETE   if (!threads)
906 // OBSOLETE     {
907 // OBSOLETE       deallocate++;
908 // OBSOLETE       ret = task_threads (inferior_task, &threads, &thread_count);
909 // OBSOLETE       CHK ("Can not select a thread from a dead task", ret);
910 // OBSOLETE     }
911 // OBSOLETE 
912 // OBSOLETE   if (slot < 0 || slot >= thread_count)
913 // OBSOLETE     {
914 // OBSOLETE       if (deallocate)
915 // OBSOLETE     {
916 // OBSOLETE       consume_send_rights (threads, thread_count);
917 // OBSOLETE       (void) vm_deallocate (mach_task_self (), (vm_address_t) threads,
918 // OBSOLETE                             (thread_count * sizeof (mach_port_t)));
919 // OBSOLETE     }
920 // OBSOLETE       if (slot < 0)
921 // OBSOLETE     error ("invalid slot number");
922 // OBSOLETE       else
923 // OBSOLETE     return -(slot + 1);
924 // OBSOLETE     }
925 // OBSOLETE 
926 // OBSOLETE   mid = map_port_name_to_mid (threads[slot], MACH_TYPE_THREAD);
927 // OBSOLETE 
928 // OBSOLETE   if (deallocate)
929 // OBSOLETE     {
930 // OBSOLETE       consume_send_rights (threads, thread_count);
931 // OBSOLETE       (void) vm_deallocate (mach_task_self (), (vm_address_t) threads,
932 // OBSOLETE                         (thread_count * sizeof (mach_port_t)));
933 // OBSOLETE     }
934 // OBSOLETE 
935 // OBSOLETE   return mid;
936 // OBSOLETE }
937 // OBSOLETE 
938 // OBSOLETE static int
939 // OBSOLETE parse_thread_id (char *arg, int thread_count, int slots)
940 // OBSOLETE {
941 // OBSOLETE   kern_return_t ret;
942 // OBSOLETE   int mid;
943 // OBSOLETE   int slot;
944 // OBSOLETE   int index;
945 // OBSOLETE 
946 // OBSOLETE   if (arg == 0)
947 // OBSOLETE     return 0;
948 // OBSOLETE 
949 // OBSOLETE   while (*arg && (*arg == ' ' || *arg == '\t'))
950 // OBSOLETE     arg++;
951 // OBSOLETE 
952 // OBSOLETE   if (!*arg)
953 // OBSOLETE     return 0;
954 // OBSOLETE 
955 // OBSOLETE   /* Currently parse MID and @SLOTNUMBER */
956 // OBSOLETE   if (*arg != '@')
957 // OBSOLETE     {
958 // OBSOLETE       mid = atoi (arg);
959 // OBSOLETE       if (mid <= 0)
960 // OBSOLETE     error ("valid thread mid expected");
961 // OBSOLETE       return mid;
962 // OBSOLETE     }
963 // OBSOLETE 
964 // OBSOLETE   arg++;
965 // OBSOLETE   slot = atoi (arg);
966 // OBSOLETE 
967 // OBSOLETE   if (slot < 0)
968 // OBSOLETE     error ("invalid slot number");
969 // OBSOLETE 
970 // OBSOLETE   /* If you want slot numbers to remain slot numbers, set slots.
971 // OBSOLETE 
972 // OBSOLETE    * Well, since 0 is reserved, return the ordinal number
973 // OBSOLETE    * of the thread rather than the slot number. Awk, this
974 // OBSOLETE    * counts as a kludge.
975 // OBSOLETE    */
976 // OBSOLETE   if (slots)
977 // OBSOLETE     return -(slot + 1);
978 // OBSOLETE 
979 // OBSOLETE   if (thread_count && slot >= thread_count)
980 // OBSOLETE     return -(slot + 1);
981 // OBSOLETE 
982 // OBSOLETE   mid = map_slot_to_mid (slot);
983 // OBSOLETE 
984 // OBSOLETE   return mid;
985 // OBSOLETE }
986 // OBSOLETE 
987 // OBSOLETE /* THREAD_ID 0 is special; it selects the first kernel
988 // OBSOLETE  * thread from the list (i.e. SLOTNUMBER 0)
989 // OBSOLETE  * This is used when starting the program with 'run' or when attaching.
990 // OBSOLETE  *
991 // OBSOLETE  * If FLAG is 0 the context is not changed, and the registers, frame, etc
992 // OBSOLETE  * will continue to describe the old thread.
993 // OBSOLETE  *
994 // OBSOLETE  * If FLAG is nonzero, really select the thread.
995 // OBSOLETE  * If FLAG is 2, the THREAD_ID is a slotnumber instead of a mid.
996 // OBSOLETE  * 
997 // OBSOLETE  */
998 // OBSOLETE kern_return_t
999 // OBSOLETE select_thread (mach_port_t task, int thread_id, int flag)
1000 // OBSOLETE {
1001 // OBSOLETE   thread_array_t thread_list;
1002 // OBSOLETE   int thread_count;
1003 // OBSOLETE   kern_return_t ret;
1004 // OBSOLETE   int index;
1005 // OBSOLETE   thread_t new_thread = MACH_PORT_NULL;
1006 // OBSOLETE 
1007 // OBSOLETE   if (thread_id < 0)
1008 // OBSOLETE     error ("Can't select cprocs without kernel thread");
1009 // OBSOLETE 
1010 // OBSOLETE   ret = task_threads (task, &thread_list, &thread_count);
1011 // OBSOLETE   if (ret != KERN_SUCCESS)
1012 // OBSOLETE     {
1013 // OBSOLETE       warning ("Can not select a thread from a dead task");
1014 // OBSOLETE       m3_kill_inferior ();
1015 // OBSOLETE       return KERN_FAILURE;
1016 // OBSOLETE     }
1017 // OBSOLETE 
1018 // OBSOLETE   if (thread_count == 0)
1019 // OBSOLETE     {
1020 // OBSOLETE       /* The task can not do anything anymore, but it still
1021 // OBSOLETE        * exists as a container for memory and ports.
1022 // OBSOLETE        */
1023 // OBSOLETE       registers_changed ();
1024 // OBSOLETE       warning ("Task %d has no threads",
1025 // OBSOLETE            map_port_name_to_mid (task, MACH_TYPE_TASK));
1026 // OBSOLETE       current_thread = MACH_PORT_NULL;
1027 // OBSOLETE       (void) vm_deallocate (mach_task_self (),
1028 // OBSOLETE                         (vm_address_t) thread_list,
1029 // OBSOLETE                         (thread_count * sizeof (mach_port_t)));
1030 // OBSOLETE       return KERN_FAILURE;
1031 // OBSOLETE     }
1032 // OBSOLETE 
1033 // OBSOLETE   if (!thread_id || flag == 2)
1034 // OBSOLETE     {
1035 // OBSOLETE       /* First thread or a slotnumber */
1036 // OBSOLETE       if (!thread_id)
1037 // OBSOLETE     new_thread = thread_list[0];
1038 // OBSOLETE       else
1039 // OBSOLETE     {
1040 // OBSOLETE       if (thread_id < thread_count)
1041 // OBSOLETE         new_thread = thread_list[thread_id];
1042 // OBSOLETE       else
1043 // OBSOLETE         {
1044 // OBSOLETE           (void) vm_deallocate (mach_task_self (),
1045 // OBSOLETE                                 (vm_address_t) thread_list,
1046 // OBSOLETE                                 (thread_count * sizeof (mach_port_t)));
1047 // OBSOLETE           error ("No such thread slot number : %d", thread_id);
1048 // OBSOLETE         }
1049 // OBSOLETE     }
1050 // OBSOLETE     }
1051 // OBSOLETE   else
1052 // OBSOLETE     {
1053 // OBSOLETE       for (index = 0; index < thread_count; index++)
1054 // OBSOLETE     if (thread_id == map_port_name_to_mid (thread_list[index],
1055 // OBSOLETE                                            MACH_TYPE_THREAD))
1056 // OBSOLETE       {
1057 // OBSOLETE         new_thread = thread_list[index];
1058 // OBSOLETE         index = -1;
1059 // OBSOLETE         break;
1060 // OBSOLETE       }
1061 // OBSOLETE 
1062 // OBSOLETE       if (index != -1)
1063 // OBSOLETE     error ("No thread with mid %d", thread_id);
1064 // OBSOLETE     }
1065 // OBSOLETE 
1066 // OBSOLETE   /* Notify when the selected thread dies */
1067 // OBSOLETE   request_notify (new_thread, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_THREAD);
1068 // OBSOLETE 
1069 // OBSOLETE   ret = vm_deallocate (mach_task_self (),
1070 // OBSOLETE                    (vm_address_t) thread_list,
1071 // OBSOLETE                    (thread_count * sizeof (mach_port_t)));
1072 // OBSOLETE   CHK ("vm_deallocate", ret);
1073 // OBSOLETE 
1074 // OBSOLETE   if (!flag)
1075 // OBSOLETE     current_thread = new_thread;
1076 // OBSOLETE   else
1077 // OBSOLETE     {
1078 // OBSOLETE #if 0
1079 // OBSOLETE       if (MACH_PORT_VALID (current_thread))
1080 // OBSOLETE     {
1081 // OBSOLETE       /* Store the gdb's view of the thread we are deselecting
1082 // OBSOLETE 
1083 // OBSOLETE        * @@ I think gdb updates registers immediately when they are
1084 // OBSOLETE        * changed, so don't do this.
1085 // OBSOLETE        */
1086 // OBSOLETE       ret = thread_abort (current_thread);
1087 // OBSOLETE       CHK ("Could not abort system calls when saving state of old thread",
1088 // OBSOLETE            ret);
1089 // OBSOLETE       target_prepare_to_store ();
1090 // OBSOLETE       target_store_registers (-1);
1091 // OBSOLETE     }
1092 // OBSOLETE #endif
1093 // OBSOLETE 
1094 // OBSOLETE       registers_changed ();
1095 // OBSOLETE 
1096 // OBSOLETE       current_thread = new_thread;
1097 // OBSOLETE 
1098 // OBSOLETE       ret = thread_abort (current_thread);
1099 // OBSOLETE       CHK ("Could not abort system calls when selecting a thread", ret);
1100 // OBSOLETE 
1101 // OBSOLETE       stop_pc = read_pc ();
1102 // OBSOLETE       flush_cached_frames ();
1103 // OBSOLETE 
1104 // OBSOLETE       select_frame (get_current_frame ());
1105 // OBSOLETE     }
1106 // OBSOLETE 
1107 // OBSOLETE   return KERN_SUCCESS;
1108 // OBSOLETE }
1109 // OBSOLETE 
1110 // OBSOLETE /*
1111 // OBSOLETE  * Switch to use thread named NEW_THREAD.
1112 // OBSOLETE  * Return it's MID
1113 // OBSOLETE  */
1114 // OBSOLETE int
1115 // OBSOLETE switch_to_thread (thread_t new_thread)
1116 // OBSOLETE {
1117 // OBSOLETE   thread_t saved_thread = current_thread;
1118 // OBSOLETE   int mid;
1119 // OBSOLETE 
1120 // OBSOLETE   mid = map_port_name_to_mid (new_thread,
1121 // OBSOLETE                           MACH_TYPE_THREAD);
1122 // OBSOLETE   if (mid == -1)
1123 // OBSOLETE     warning ("Can't map thread name 0x%x to mid", new_thread);
1124 // OBSOLETE   else if (select_thread (inferior_task, mid, 1) != KERN_SUCCESS)
1125 // OBSOLETE     {
1126 // OBSOLETE       if (current_thread)
1127 // OBSOLETE     current_thread = saved_thread;
1128 // OBSOLETE       error ("Could not select thread %d", mid);
1129 // OBSOLETE     }
1130 // OBSOLETE 
1131 // OBSOLETE   return mid;
1132 // OBSOLETE }
1133 // OBSOLETE 
1134 // OBSOLETE /* Do this in gdb after doing FORK but before STARTUP_INFERIOR.
1135 // OBSOLETE  * Note that the registers are not yet valid in the inferior task.
1136 // OBSOLETE  */
1137 // OBSOLETE static int
1138 // OBSOLETE m3_trace_him (int pid)
1139 // OBSOLETE {
1140 // OBSOLETE   kern_return_t ret;
1141 // OBSOLETE 
1142 // OBSOLETE   push_target (&m3_ops);
1143 // OBSOLETE 
1144 // OBSOLETE   inferior_task = task_by_pid (pid);
1145 // OBSOLETE 
1146 // OBSOLETE   if (!MACH_PORT_VALID (inferior_task))
1147 // OBSOLETE     error ("Can not map Unix pid %d to Mach task", pid);
1148 // OBSOLETE 
1149 // OBSOLETE   /* Clean up previous notifications and create new ones */
1150 // OBSOLETE   setup_notify_port (1);
1151 // OBSOLETE 
1152 // OBSOLETE   /* When notification appears, the inferior task has died */
1153 // OBSOLETE   request_notify (inferior_task, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_TASK);
1154 // OBSOLETE 
1155 // OBSOLETE   emulator_present = have_emulator_p (inferior_task);
1156 // OBSOLETE 
1157 // OBSOLETE   /* By default, select the first thread,
1158 // OBSOLETE    * If task has no threads, gives a warning
1159 // OBSOLETE    * Does not fetch registers, since they are not yet valid.
1160 // OBSOLETE    */
1161 // OBSOLETE   select_thread (inferior_task, 0, 0);
1162 // OBSOLETE 
1163 // OBSOLETE   inferior_exception_port = MACH_PORT_NULL;
1164 // OBSOLETE 
1165 // OBSOLETE   setup_exception_port ();
1166 // OBSOLETE 
1167 // OBSOLETE   xx_debug ("Now the debugged task is created\n");
1168 // OBSOLETE 
1169 // OBSOLETE   /* One trap to exec the shell, one to exec the program being debugged.  */
1170 // OBSOLETE   intercept_exec_calls (2);
1171 // OBSOLETE 
1172 // OBSOLETE   return pid;
1173 // OBSOLETE }
1174 // OBSOLETE 
1175 // OBSOLETE setup_exception_port (void)
1176 // OBSOLETE {
1177 // OBSOLETE   kern_return_t ret;
1178 // OBSOLETE 
1179 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
1180 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
1181 // OBSOLETE                         &inferior_exception_port);
1182 // OBSOLETE   CHK ("mach_port_allocate", ret);
1183 // OBSOLETE 
1184 // OBSOLETE   /* add send right */
1185 // OBSOLETE   ret = mach_port_insert_right (mach_task_self (),
1186 // OBSOLETE                             inferior_exception_port,
1187 // OBSOLETE                             inferior_exception_port,
1188 // OBSOLETE                             MACH_MSG_TYPE_MAKE_SEND);
1189 // OBSOLETE   CHK ("mach_port_insert_right", ret);
1190 // OBSOLETE 
1191 // OBSOLETE   ret = mach_port_move_member (mach_task_self (),
1192 // OBSOLETE                            inferior_exception_port,
1193 // OBSOLETE                            inferior_wait_port_set);
1194 // OBSOLETE   CHK ("mach_port_move_member", ret);
1195 // OBSOLETE 
1196 // OBSOLETE   ret = task_get_special_port (inferior_task,
1197 // OBSOLETE                            TASK_EXCEPTION_PORT,
1198 // OBSOLETE                            &inferior_old_exception_port);
1199 // OBSOLETE   CHK ("task_get_special_port(old exc)", ret);
1200 // OBSOLETE 
1201 // OBSOLETE   ret = task_set_special_port (inferior_task,
1202 // OBSOLETE                            TASK_EXCEPTION_PORT,
1203 // OBSOLETE                            inferior_exception_port);
1204 // OBSOLETE   CHK ("task_set_special_port", ret);
1205 // OBSOLETE 
1206 // OBSOLETE   ret = mach_port_deallocate (mach_task_self (),
1207 // OBSOLETE                           inferior_exception_port);
1208 // OBSOLETE   CHK ("mack_port_deallocate", ret);
1209 // OBSOLETE 
1210 // OBSOLETE #if 0
1211 // OBSOLETE   /* When notify appears, the inferior_task's exception
1212 // OBSOLETE    * port has been destroyed.
1213 // OBSOLETE    *
1214 // OBSOLETE    * Not used, since the dead_name_notification already
1215 // OBSOLETE    * appears when task dies.
1216 // OBSOLETE    *
1217 // OBSOLETE    */
1218 // OBSOLETE   request_notify (inferior_exception_port,
1219 // OBSOLETE               MACH_NOTIFY_NO_SENDERS,
1220 // OBSOLETE               MACH_TYPE_EXCEPTION_PORT);
1221 // OBSOLETE #endif
1222 // OBSOLETE }
1223 // OBSOLETE 
1224 // OBSOLETE /* Nonzero if gdb is waiting for a message */
1225 // OBSOLETE int mach_really_waiting;
1226 // OBSOLETE 
1227 // OBSOLETE /* Wait for the inferior to stop for some reason.
1228 // OBSOLETE    - Loop on notifications until inferior_task dies.
1229 // OBSOLETE    - Loop on exceptions until stopped_in_exception comes true.
1230 // OBSOLETE    (e.g. we receive a single step trace trap)
1231 // OBSOLETE    - a message arrives to gdb's message port
1232 // OBSOLETE 
1233 // OBSOLETE    There is no other way to exit this loop.
1234 // OBSOLETE 
1235 // OBSOLETE    Returns the inferior_ptid for rest of gdb.
1236 // OBSOLETE    Side effects: Set *OURSTATUS.  */
1237 // OBSOLETE ptid_t
1238 // OBSOLETE mach_really_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
1239 // OBSOLETE {
1240 // OBSOLETE   kern_return_t ret;
1241 // OBSOLETE   int w;
1242 // OBSOLETE 
1243 // OBSOLETE   struct msg
1244 // OBSOLETE     {
1245 // OBSOLETE       mach_msg_header_t header;
1246 // OBSOLETE       mach_msg_type_t foo;
1247 // OBSOLETE       int data[8000];
1248 // OBSOLETE     }
1249 // OBSOLETE   in_msg, out_msg;
1250 // OBSOLETE 
1251 // OBSOLETE   /* Either notify (death), exception or message can stop the inferior */
1252 // OBSOLETE   stopped_in_exception = FALSE;
1253 // OBSOLETE 
1254 // OBSOLETE   while (1)
1255 // OBSOLETE     {
1256 // OBSOLETE       QUIT;
1257 // OBSOLETE 
1258 // OBSOLETE       stop_exception = stop_code = stop_subcode = -1;
1259 // OBSOLETE       stop_thread = MACH_PORT_NULL;
1260 // OBSOLETE 
1261 // OBSOLETE       mach_really_waiting = 1;
1262 // OBSOLETE       ret = mach_msg (&in_msg.header,       /* header */
1263 // OBSOLETE                   MACH_RCV_MSG,     /* options */
1264 // OBSOLETE                   0,        /* send size */
1265 // OBSOLETE                   sizeof (struct msg),      /* receive size */
1266 // OBSOLETE                   currently_waiting_for,    /* receive name */
1267 // OBSOLETE                   MACH_MSG_TIMEOUT_NONE,
1268 // OBSOLETE                   MACH_PORT_NULL);
1269 // OBSOLETE       mach_really_waiting = 0;
1270 // OBSOLETE       CHK ("mach_msg (receive)", ret);
1271 // OBSOLETE 
1272 // OBSOLETE       /* Check if we received a notify of the childs' death */
1273 // OBSOLETE       if (notify_server (&in_msg.header, &out_msg.header))
1274 // OBSOLETE     {
1275 // OBSOLETE       /* If inferior_task is null then the inferior has
1276 // OBSOLETE          gone away and we want to return to command level.
1277 // OBSOLETE          Otherwise it was just an informative message and we
1278 // OBSOLETE          need to look to see if there are any more. */
1279 // OBSOLETE       if (inferior_task != MACH_PORT_NULL)
1280 // OBSOLETE         continue;
1281 // OBSOLETE       else
1282 // OBSOLETE         {
1283 // OBSOLETE           /* Collect Unix exit status for gdb */
1284 // OBSOLETE 
1285 // OBSOLETE           wait3 (&w, WNOHANG, 0);
1286 // OBSOLETE 
1287 // OBSOLETE           /* This mess is here to check that the rest of
1288 // OBSOLETE            * gdb knows that the inferior died. It also
1289 // OBSOLETE            * tries to hack around the fact that Mach 3.0 (mk69)
1290 // OBSOLETE            * unix server (ux28) does not always know what
1291 // OBSOLETE            * has happened to it's children when mach-magic
1292 // OBSOLETE            * is applied on them.
1293 // OBSOLETE            */
1294 // OBSOLETE           if ((!WIFEXITED (w) && WIFSTOPPED (w)) ||
1295 // OBSOLETE               (WIFEXITED (w) && WEXITSTATUS (w) > 0377))
1296 // OBSOLETE             {
1297 // OBSOLETE               WSETEXIT (w, 0);
1298 // OBSOLETE               warning ("Using exit value 0 for terminated task");
1299 // OBSOLETE             }
1300 // OBSOLETE           else if (!WIFEXITED (w))
1301 // OBSOLETE             {
1302 // OBSOLETE               int sig = WTERMSIG (w);
1303 // OBSOLETE 
1304 // OBSOLETE               /* Signals cause problems. Warn the user. */
1305 // OBSOLETE               if (sig != SIGKILL)   /* Bad luck if garbage matches this */
1306 // OBSOLETE                 warning ("The terminating signal stuff may be nonsense");
1307 // OBSOLETE               else if (sig > NSIG)
1308 // OBSOLETE                 {
1309 // OBSOLETE                   WSETEXIT (w, 0);
1310 // OBSOLETE                   warning ("Using exit value 0 for terminated task");
1311 // OBSOLETE                 }
1312 // OBSOLETE             }
1313 // OBSOLETE           store_waitstatus (ourstatus, w);
1314 // OBSOLETE           return inferior_ptid;
1315 // OBSOLETE         }
1316 // OBSOLETE     }
1317 // OBSOLETE 
1318 // OBSOLETE       /* Hmm. Check for exception, as it was not a notification.
1319 // OBSOLETE          exc_server() does an upcall to catch_exception_raise()
1320 // OBSOLETE          if this rpc is an exception. Further actions are decided
1321 // OBSOLETE          there.
1322 // OBSOLETE        */
1323 // OBSOLETE       if (!exc_server (&in_msg.header, &out_msg.header))
1324 // OBSOLETE     {
1325 // OBSOLETE 
1326 // OBSOLETE       /* Not an exception, check for message.
1327 // OBSOLETE 
1328 // OBSOLETE        * Messages don't come from the inferior, or if they
1329 // OBSOLETE        * do they better be asynchronous or it will hang.
1330 // OBSOLETE        */
1331 // OBSOLETE       if (gdb_message_server (&in_msg.header))
1332 // OBSOLETE         continue;
1333 // OBSOLETE 
1334 // OBSOLETE       error ("Unrecognized message received in mach_really_wait");
1335 // OBSOLETE     }
1336 // OBSOLETE 
1337 // OBSOLETE       /* Send the reply of the exception rpc to the suspended task */
1338 // OBSOLETE       ret = mach_msg_send (&out_msg.header);
1339 // OBSOLETE       CHK ("mach_msg_send (exc reply)", ret);
1340 // OBSOLETE 
1341 // OBSOLETE       if (stopped_in_exception)
1342 // OBSOLETE     {
1343 // OBSOLETE       /* Get unix state. May be changed in mach3_exception_actions() */
1344 // OBSOLETE       wait3 (&w, WNOHANG, 0);
1345 // OBSOLETE 
1346 // OBSOLETE       mach3_exception_actions (&w, FALSE, "Task");
1347 // OBSOLETE 
1348 // OBSOLETE       store_waitstatus (ourstatus, w);
1349 // OBSOLETE       return inferior_ptid;
1350 // OBSOLETE     }
1351 // OBSOLETE     }
1352 // OBSOLETE }
1353 // OBSOLETE 
1354 // OBSOLETE /* Called by macro DO_QUIT() in utils.c(quit).
1355 // OBSOLETE  * This is called just before calling error() to return to command level
1356 // OBSOLETE  */
1357 // OBSOLETE void
1358 // OBSOLETE mach3_quit (void)
1359 // OBSOLETE {
1360 // OBSOLETE   int mid;
1361 // OBSOLETE   kern_return_t ret;
1362 // OBSOLETE 
1363 // OBSOLETE   if (mach_really_waiting)
1364 // OBSOLETE     {
1365 // OBSOLETE       ret = task_suspend (inferior_task);
1366 // OBSOLETE 
1367 // OBSOLETE       if (ret != KERN_SUCCESS)
1368 // OBSOLETE     {
1369 // OBSOLETE       warning ("Could not suspend task for interrupt: %s",
1370 // OBSOLETE                mach_error_string (ret));
1371 // OBSOLETE       mach_really_waiting = 0;
1372 // OBSOLETE       return;
1373 // OBSOLETE     }
1374 // OBSOLETE     }
1375 // OBSOLETE 
1376 // OBSOLETE   must_suspend_thread = 0;
1377 // OBSOLETE   mach_really_waiting = 0;
1378 // OBSOLETE 
1379 // OBSOLETE   mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
1380 // OBSOLETE   if (mid == -1)
1381 // OBSOLETE     {
1382 // OBSOLETE       warning ("Selecting first existing kernel thread");
1383 // OBSOLETE       mid = 0;
1384 // OBSOLETE     }
1385 // OBSOLETE 
1386 // OBSOLETE   current_thread = MACH_PORT_NULL;  /* Force setup */
1387 // OBSOLETE   select_thread (inferior_task, mid, 1);
1388 // OBSOLETE 
1389 // OBSOLETE   return;
1390 // OBSOLETE }
1391 // OBSOLETE 
1392 // OBSOLETE #if 0
1393 // OBSOLETE /* bogus bogus bogus.  It is NOT OK to quit out of target_wait.  */
1394 // OBSOLETE 
1395 // OBSOLETE /* If ^C is typed when we are waiting for a message
1396 // OBSOLETE  * and your Unix server is able to notice that we 
1397 // OBSOLETE  * should quit now.
1398 // OBSOLETE  *
1399 // OBSOLETE  * Called by REQUEST_QUIT() from utils.c(request_quit)
1400 // OBSOLETE  */
1401 // OBSOLETE void
1402 // OBSOLETE mach3_request_quit (void)
1403 // OBSOLETE {
1404 // OBSOLETE   if (mach_really_waiting)
1405 // OBSOLETE     immediate_quit = 1;
1406 // OBSOLETE }
1407 // OBSOLETE #endif
1408 // OBSOLETE 
1409 // OBSOLETE /*
1410 // OBSOLETE  * Gdb message server.
1411 // OBSOLETE  * Currently implemented is the STOP message, that causes
1412 // OBSOLETE  * gdb to return to the command level like ^C had been typed from terminal.
1413 // OBSOLETE  */
1414 // OBSOLETE int
1415 // OBSOLETE gdb_message_server (mach_msg_header_t *InP)
1416 // OBSOLETE {
1417 // OBSOLETE   kern_return_t ret;
1418 // OBSOLETE   int mid;
1419 // OBSOLETE 
1420 // OBSOLETE   if (InP->msgh_local_port == our_message_port)
1421 // OBSOLETE     {
1422 // OBSOLETE       /* A message coming to our_message_port. Check validity */
1423 // OBSOLETE       switch (InP->msgh_id)
1424 // OBSOLETE     {
1425 // OBSOLETE 
1426 // OBSOLETE     case GDB_MESSAGE_ID_STOP:
1427 // OBSOLETE       ret = task_suspend (inferior_task);
1428 // OBSOLETE       if (ret != KERN_SUCCESS)
1429 // OBSOLETE         warning ("Could not suspend task for stop message: %s",
1430 // OBSOLETE                  mach_error_string (ret));
1431 // OBSOLETE 
1432 // OBSOLETE       /* QUIT in mach_really_wait() loop. */
1433 // OBSOLETE       request_quit (0);
1434 // OBSOLETE       break;
1435 // OBSOLETE 
1436 // OBSOLETE     default:
1437 // OBSOLETE       warning ("Invalid message id %d received, ignored.",
1438 // OBSOLETE                InP->msgh_id);
1439 // OBSOLETE       break;
1440 // OBSOLETE     }
1441 // OBSOLETE 
1442 // OBSOLETE       return 1;
1443 // OBSOLETE     }
1444 // OBSOLETE 
1445 // OBSOLETE   /* Message not handled by this server */
1446 // OBSOLETE   return 0;
1447 // OBSOLETE }
1448 // OBSOLETE 
1449 // OBSOLETE /* NOTE: This is not an RPC call. It is a simpleroutine.
1450 // OBSOLETE 
1451 // OBSOLETE  * This is not called from this gdb code.
1452 // OBSOLETE  *
1453 // OBSOLETE  * It may be called by another debugger to cause this
1454 // OBSOLETE  * debugger to enter command level:
1455 // OBSOLETE  *
1456 // OBSOLETE  *            (gdb) set stop_inferior_gdb ()
1457 // OBSOLETE  *            (gdb) continue
1458 // OBSOLETE  *
1459 // OBSOLETE  * External program "stop-gdb" implements this also.
1460 // OBSOLETE  */
1461 // OBSOLETE void
1462 // OBSOLETE stop_inferior_gdb (void)
1463 // OBSOLETE {
1464 // OBSOLETE   kern_return_t ret;
1465 // OBSOLETE 
1466 // OBSOLETE   /* Code generated by mig, with minor cleanups :-)
1467 // OBSOLETE 
1468 // OBSOLETE    * simpleroutine stop_inferior_gdb (our_message_port : mach_port_t);
1469 // OBSOLETE    */
1470 // OBSOLETE 
1471 // OBSOLETE   typedef struct
1472 // OBSOLETE     {
1473 // OBSOLETE       mach_msg_header_t Head;
1474 // OBSOLETE     }
1475 // OBSOLETE   Request;
1476 // OBSOLETE 
1477 // OBSOLETE   Request Mess;
1478 // OBSOLETE 
1479 // OBSOLETE   register Request *InP = &Mess;
1480 // OBSOLETE 
1481 // OBSOLETE   InP->Head.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
1482 // OBSOLETE 
1483 // OBSOLETE   /* msgh_size passed as argument */
1484 // OBSOLETE   InP->Head.msgh_remote_port = our_message_port;
1485 // OBSOLETE   InP->Head.msgh_local_port = MACH_PORT_NULL;
1486 // OBSOLETE   InP->Head.msgh_seqno = 0;
1487 // OBSOLETE   InP->Head.msgh_id = GDB_MESSAGE_ID_STOP;
1488 // OBSOLETE 
1489 // OBSOLETE   ret = mach_msg (&InP->Head,
1490 // OBSOLETE               MACH_SEND_MSG | MACH_MSG_OPTION_NONE,
1491 // OBSOLETE               sizeof (Request),
1492 // OBSOLETE               0,
1493 // OBSOLETE               MACH_PORT_NULL,
1494 // OBSOLETE               MACH_MSG_TIMEOUT_NONE,
1495 // OBSOLETE               MACH_PORT_NULL);
1496 // OBSOLETE }
1497 // OBSOLETE 
1498 // OBSOLETE #ifdef THREAD_ALLOWED_TO_BREAK
1499 // OBSOLETE /*
1500 // OBSOLETE  * Return 1 if the MID specifies the thread that caused the
1501 // OBSOLETE  * last exception.
1502 // OBSOLETE  *  Since catch_exception_raise() selects the thread causing
1503 // OBSOLETE  * the last exception to current_thread, we just check that
1504 // OBSOLETE  * it is selected and the last exception was a breakpoint.
1505 // OBSOLETE  */
1506 // OBSOLETE int
1507 // OBSOLETE mach_thread_for_breakpoint (int mid)
1508 // OBSOLETE {
1509 // OBSOLETE   int cmid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
1510 // OBSOLETE 
1511 // OBSOLETE   if (mid < 0)
1512 // OBSOLETE     {
1513 // OBSOLETE       mid = map_slot_to_mid (-(mid + 1), 0, 0);
1514 // OBSOLETE       if (mid < 0)
1515 // OBSOLETE     return 0;               /* Don't stop, no such slot */
1516 // OBSOLETE     }
1517 // OBSOLETE 
1518 // OBSOLETE   if (!mid || cmid == -1)
1519 // OBSOLETE     return 1;                       /* stop */
1520 // OBSOLETE 
1521 // OBSOLETE   return cmid == mid && stop_exception == EXC_BREAKPOINT;
1522 // OBSOLETE }
1523 // OBSOLETE #endif /* THREAD_ALLOWED_TO_BREAK */
1524 // OBSOLETE 
1525 // OBSOLETE #ifdef THREAD_PARSE_ID
1526 // OBSOLETE /*
1527 // OBSOLETE  * Map a thread id string (MID or a @SLOTNUMBER)
1528 // OBSOLETE  * to a thread-id.
1529 // OBSOLETE  *
1530 // OBSOLETE  *   0  matches all threads.
1531 // OBSOLETE  *   Otherwise the meaning is defined only in this file.
1532 // OBSOLETE  *   (mach_thread_for_breakpoint uses it)
1533 // OBSOLETE  *
1534 // OBSOLETE  * @@ This allows non-existent MIDs to be specified.
1535 // OBSOLETE  *    It now also allows non-existent slots to be
1536 // OBSOLETE  *    specified. (Slot numbers stored are negative,
1537 // OBSOLETE  *    and the magnitude is one greater than the actual
1538 // OBSOLETE  *    slot index. (Since 0 is reserved))
1539 // OBSOLETE  */
1540 // OBSOLETE int
1541 // OBSOLETE mach_thread_parse_id (char *arg)
1542 // OBSOLETE {
1543 // OBSOLETE   int mid;
1544 // OBSOLETE   if (arg == 0)
1545 // OBSOLETE     error ("thread id expected");
1546 // OBSOLETE   mid = parse_thread_id (arg, 0, 1);
1547 // OBSOLETE 
1548 // OBSOLETE   return mid;
1549 // OBSOLETE }
1550 // OBSOLETE #endif /* THREAD_PARSE_ID */
1551 // OBSOLETE 
1552 // OBSOLETE #ifdef THREAD_OUTPUT_ID
1553 // OBSOLETE char *
1554 // OBSOLETE mach_thread_output_id (int mid)
1555 // OBSOLETE {
1556 // OBSOLETE   static char foobar[20];
1557 // OBSOLETE 
1558 // OBSOLETE   if (mid > 0)
1559 // OBSOLETE     sprintf (foobar, "mid %d", mid);
1560 // OBSOLETE   else if (mid < 0)
1561 // OBSOLETE     sprintf (foobar, "@%d", -(mid + 1));
1562 // OBSOLETE   else
1563 // OBSOLETE     sprintf (foobar, "*any thread*");
1564 // OBSOLETE 
1565 // OBSOLETE   return foobar;
1566 // OBSOLETE }
1567 // OBSOLETE #endif /* THREAD_OUTPUT_ID */
1568 // OBSOLETE 
1569 // OBSOLETE /* Called with hook PREPARE_TO_PROCEED() from infrun.c.
1570 // OBSOLETE 
1571 // OBSOLETE  * If we have switched threads and stopped at breakpoint return 1 otherwise 0.
1572 // OBSOLETE  *
1573 // OBSOLETE  *  if SELECT_IT is nonzero, reselect the thread that was active when
1574 // OBSOLETE  *  we stopped at a breakpoint.
1575 // OBSOLETE  *
1576 // OBSOLETE  * Note that this implementation is potentially redundant now that
1577 // OBSOLETE  * default_prepare_to_proceed() has been added.  
1578 // OBSOLETE  *
1579 // OBSOLETE  * FIXME This may not support switching threads after Ctrl-C
1580 // OBSOLETE  * correctly. The default implementation does support this.
1581 // OBSOLETE  */
1582 // OBSOLETE 
1583 // OBSOLETE mach3_prepare_to_proceed (int select_it)
1584 // OBSOLETE {
1585 // OBSOLETE   if (stop_thread &&
1586 // OBSOLETE       stop_thread != current_thread &&
1587 // OBSOLETE       stop_exception == EXC_BREAKPOINT)
1588 // OBSOLETE     {
1589 // OBSOLETE       int mid;
1590 // OBSOLETE 
1591 // OBSOLETE       if (!select_it)
1592 // OBSOLETE     return 1;
1593 // OBSOLETE 
1594 // OBSOLETE       mid = switch_to_thread (stop_thread);
1595 // OBSOLETE 
1596 // OBSOLETE       return 1;
1597 // OBSOLETE     }
1598 // OBSOLETE 
1599 // OBSOLETE   return 0;
1600 // OBSOLETE }
1601 // OBSOLETE 
1602 // OBSOLETE /* this stuff here is an upcall via libmach/excServer.c 
1603 // OBSOLETE    and mach_really_wait which does the actual upcall.
1604 // OBSOLETE 
1605 // OBSOLETE    The code will pass the exception to the inferior if:
1606 // OBSOLETE 
1607 // OBSOLETE    - The task that signaled is not the inferior task
1608 // OBSOLETE    (e.g. when debugging another debugger)
1609 // OBSOLETE 
1610 // OBSOLETE    - The user has explicitely requested to pass on the exceptions.
1611 // OBSOLETE    (e.g to the default unix exception handler, which maps
1612 // OBSOLETE    exceptions to signals, or the user has her own exception handler)
1613 // OBSOLETE 
1614 // OBSOLETE    - If the thread that signaled is being single-stepped and it
1615 // OBSOLETE    has set it's own exception port and the exception is not
1616 // OBSOLETE    EXC_BREAKPOINT. (Maybe this is not desirable?)
1617 // OBSOLETE  */
1618 // OBSOLETE 
1619 // OBSOLETE kern_return_t
1620 // OBSOLETE catch_exception_raise (mach_port_t port, thread_t thread, task_t task,
1621 // OBSOLETE                    int exception, int code, int subcode)
1622 // OBSOLETE {
1623 // OBSOLETE   kern_return_t ret;
1624 // OBSOLETE   boolean_t signal_thread;
1625 // OBSOLETE   int mid = map_port_name_to_mid (thread, MACH_TYPE_THREAD);
1626 // OBSOLETE 
1627 // OBSOLETE   if (!MACH_PORT_VALID (thread))
1628 // OBSOLETE     {
1629 // OBSOLETE       /* If the exception was sent and thread dies before we
1630 // OBSOLETE          receive it, THREAD will be MACH_PORT_DEAD
1631 // OBSOLETE        */
1632 // OBSOLETE 
1633 // OBSOLETE       current_thread = thread = MACH_PORT_NULL;
1634 // OBSOLETE       error ("Received exception from nonexistent thread");
1635 // OBSOLETE     }
1636 // OBSOLETE 
1637 // OBSOLETE   /* Check if the task died in transit.
1638 // OBSOLETE    * @@ Isn't the thread also invalid in such case?
1639 // OBSOLETE    */
1640 // OBSOLETE   if (!MACH_PORT_VALID (task))
1641 // OBSOLETE     {
1642 // OBSOLETE       current_thread = thread = MACH_PORT_NULL;
1643 // OBSOLETE       error ("Received exception from nonexistent task");
1644 // OBSOLETE     }
1645 // OBSOLETE 
1646 // OBSOLETE   if (exception < 0 || exception > MAX_EXCEPTION)
1647 // OBSOLETE     internal_error (__FILE__, __LINE__,
1648 // OBSOLETE                 "catch_exception_raise: unknown exception code %d thread %d",
1649 // OBSOLETE                 exception,
1650 // OBSOLETE                 mid);
1651 // OBSOLETE 
1652 // OBSOLETE   if (!MACH_PORT_VALID (inferior_task))
1653 // OBSOLETE     error ("got an exception, but inferior_task is null or dead");
1654 // OBSOLETE 
1655 // OBSOLETE   stop_exception = exception;
1656 // OBSOLETE   stop_code = code;
1657 // OBSOLETE   stop_subcode = subcode;
1658 // OBSOLETE   stop_thread = thread;
1659 // OBSOLETE 
1660 // OBSOLETE   signal_thread = exception != EXC_BREAKPOINT &&
1661 // OBSOLETE     port == singlestepped_thread_port &&
1662 // OBSOLETE     MACH_PORT_VALID (thread_saved_exception_port);
1663 // OBSOLETE 
1664 // OBSOLETE   /* If it was not our inferior or if we want to forward
1665 // OBSOLETE    * the exception to the inferior's handler, do it here
1666 // OBSOLETE    *
1667 // OBSOLETE    * Note: If you have forwarded EXC_BREAKPOINT I trust you know why.
1668 // OBSOLETE    */
1669 // OBSOLETE   if (task != inferior_task ||
1670 // OBSOLETE       signal_thread ||
1671 // OBSOLETE       exception_map[exception].forward)
1672 // OBSOLETE     {
1673 // OBSOLETE       mach_port_t eport = inferior_old_exception_port;
1674 // OBSOLETE 
1675 // OBSOLETE       if (signal_thread)
1676 // OBSOLETE     {
1677 // OBSOLETE       /*
1678 // OBSOLETE          GDB now forwards the exeption to thread's original handler,
1679 // OBSOLETE          since the user propably knows what he is doing.
1680 // OBSOLETE          Give a message, though.
1681 // OBSOLETE        */
1682 // OBSOLETE 
1683 // OBSOLETE       mach3_exception_actions ((WAITTYPE *) NULL, TRUE, "Thread");
1684 // OBSOLETE       eport = thread_saved_exception_port;
1685 // OBSOLETE     }
1686 // OBSOLETE 
1687 // OBSOLETE       /* Send the exception to the original handler */
1688 // OBSOLETE       ret = exception_raise (eport,
1689 // OBSOLETE                          thread,
1690 // OBSOLETE                          task,
1691 // OBSOLETE                          exception,
1692 // OBSOLETE                          code,
1693 // OBSOLETE                          subcode);
1694 // OBSOLETE 
1695 // OBSOLETE       (void) mach_port_deallocate (mach_task_self (), task);
1696 // OBSOLETE       (void) mach_port_deallocate (mach_task_self (), thread);
1697 // OBSOLETE 
1698 // OBSOLETE       /* If we come here, we don't want to trace any more, since we
1699 // OBSOLETE        * will never stop for tracing anyway.
1700 // OBSOLETE        */
1701 // OBSOLETE       discard_single_step (thread);
1702 // OBSOLETE 
1703 // OBSOLETE       /* Do not stop the inferior */
1704 // OBSOLETE       return ret;
1705 // OBSOLETE     }
1706 // OBSOLETE 
1707 // OBSOLETE   /* Now gdb handles the exception */
1708 // OBSOLETE   stopped_in_exception = TRUE;
1709 // OBSOLETE 
1710 // OBSOLETE   ret = task_suspend (task);
1711 // OBSOLETE   CHK ("Error suspending inferior after exception", ret);
1712 // OBSOLETE 
1713 // OBSOLETE   must_suspend_thread = 0;
1714 // OBSOLETE 
1715 // OBSOLETE   if (current_thread != thread)
1716 // OBSOLETE     {
1717 // OBSOLETE       if (MACH_PORT_VALID (singlestepped_thread_port))
1718 // OBSOLETE     /* Cleanup discards single stepping */
1719 // OBSOLETE     error ("Exception from thread %d while singlestepping thread %d",
1720 // OBSOLETE            mid,
1721 // OBSOLETE            map_port_name_to_mid (current_thread, MACH_TYPE_THREAD));
1722 // OBSOLETE 
1723 // OBSOLETE       /* Then select the thread that caused the exception */
1724 // OBSOLETE       if (select_thread (inferior_task, mid, 0) != KERN_SUCCESS)
1725 // OBSOLETE     error ("Could not select thread %d causing exception", mid);
1726 // OBSOLETE       else
1727 // OBSOLETE     warning ("Gdb selected thread %d", mid);
1728 // OBSOLETE     }
1729 // OBSOLETE 
1730 // OBSOLETE   /* If we receive an exception that is not breakpoint
1731 // OBSOLETE    * exception, we interrupt the single step and return to
1732 // OBSOLETE    * debugger. Trace condition is cleared.
1733 // OBSOLETE    */
1734 // OBSOLETE   if (MACH_PORT_VALID (singlestepped_thread_port))
1735 // OBSOLETE     {
1736 // OBSOLETE       if (stop_exception != EXC_BREAKPOINT)
1737 // OBSOLETE     warning ("Single step interrupted by exception");
1738 // OBSOLETE       else if (port == singlestepped_thread_port)
1739 // OBSOLETE     {
1740 // OBSOLETE       /* Single step exception occurred, remove trace bit
1741 // OBSOLETE        * and return to gdb.
1742 // OBSOLETE        */
1743 // OBSOLETE       if (!MACH_PORT_VALID (current_thread))
1744 // OBSOLETE         error ("Single stepped thread is not valid");
1745 // OBSOLETE 
1746 // OBSOLETE       /* Resume threads, but leave the task suspended */
1747 // OBSOLETE       resume_all_threads (0);
1748 // OBSOLETE     }
1749 // OBSOLETE       else
1750 // OBSOLETE     warning ("Breakpoint while single stepping?");
1751 // OBSOLETE 
1752 // OBSOLETE       discard_single_step (current_thread);
1753 // OBSOLETE     }
1754 // OBSOLETE 
1755 // OBSOLETE   (void) mach_port_deallocate (mach_task_self (), task);
1756 // OBSOLETE   (void) mach_port_deallocate (mach_task_self (), thread);
1757 // OBSOLETE 
1758 // OBSOLETE   return KERN_SUCCESS;
1759 // OBSOLETE }
1760 // OBSOLETE \f
1761 // OBSOLETE int
1762 // OBSOLETE port_valid (mach_port_t port, int mask)
1763 // OBSOLETE {
1764 // OBSOLETE   kern_return_t ret;
1765 // OBSOLETE   mach_port_type_t type;
1766 // OBSOLETE 
1767 // OBSOLETE   ret = mach_port_type (mach_task_self (),
1768 // OBSOLETE                     port,
1769 // OBSOLETE                     &type);
1770 // OBSOLETE   if (ret != KERN_SUCCESS || (type & mask) != mask)
1771 // OBSOLETE     return 0;
1772 // OBSOLETE   return 1;
1773 // OBSOLETE }
1774 // OBSOLETE \f
1775 // OBSOLETE /* @@ No vm read cache implemented yet */
1776 // OBSOLETE boolean_t vm_read_cache_valid = FALSE;
1777 // OBSOLETE 
1778 // OBSOLETE /*
1779 // OBSOLETE  * Read inferior task's LEN bytes from ADDR and copy it to MYADDR
1780 // OBSOLETE  * in gdb's address space.
1781 // OBSOLETE  *
1782 // OBSOLETE  * Return 0 on failure; number of bytes read otherwise.
1783 // OBSOLETE  */
1784 // OBSOLETE int
1785 // OBSOLETE mach3_read_inferior (CORE_ADDR addr, char *myaddr, int length)
1786 // OBSOLETE {
1787 // OBSOLETE   kern_return_t ret;
1788 // OBSOLETE   vm_address_t low_address = (vm_address_t) trunc_page (addr);
1789 // OBSOLETE   vm_size_t aligned_length =
1790 // OBSOLETE   (vm_size_t) round_page (addr + length) - low_address;
1791 // OBSOLETE   pointer_t copied_memory;
1792 // OBSOLETE   int copy_count;
1793 // OBSOLETE 
1794 // OBSOLETE   /* Get memory from inferior with page aligned addresses */
1795 // OBSOLETE   ret = vm_read (inferior_task,
1796 // OBSOLETE              low_address,
1797 // OBSOLETE              aligned_length,
1798 // OBSOLETE              &copied_memory,
1799 // OBSOLETE              &copy_count);
1800 // OBSOLETE   if (ret != KERN_SUCCESS)
1801 // OBSOLETE     {
1802 // OBSOLETE       /* the problem is that the inferior might be killed for whatever reason
1803 // OBSOLETE        * before we go to mach_really_wait. This is one place that ought to
1804 // OBSOLETE        * catch many of those errors.
1805 // OBSOLETE        * @@ A better fix would be to make all external events to GDB
1806 // OBSOLETE        * to arrive via a SINGLE port set. (Including user input!)
1807 // OBSOLETE        */
1808 // OBSOLETE 
1809 // OBSOLETE       if (!port_valid (inferior_task, MACH_PORT_TYPE_SEND))
1810 // OBSOLETE     {
1811 // OBSOLETE       m3_kill_inferior ();
1812 // OBSOLETE       error ("Inferior killed (task port invalid)");
1813 // OBSOLETE     }
1814 // OBSOLETE       else
1815 // OBSOLETE     {
1816 // OBSOLETE #ifdef OSF
1817 // OBSOLETE       extern int errno;
1818 // OBSOLETE       /* valprint.c gives nicer format if this does not
1819 // OBSOLETE          screw it. Eamonn seems to like this, so I enable
1820 // OBSOLETE          it if OSF is defined...
1821 // OBSOLETE        */
1822 // OBSOLETE       warning ("[read inferior %x failed: %s]",
1823 // OBSOLETE                addr, mach_error_string (ret));
1824 // OBSOLETE       errno = 0;
1825 // OBSOLETE #endif
1826 // OBSOLETE       return 0;
1827 // OBSOLETE     }
1828 // OBSOLETE     }
1829 // OBSOLETE 
1830 // OBSOLETE   memcpy (myaddr, (char *) addr - low_address + copied_memory, length);
1831 // OBSOLETE 
1832 // OBSOLETE   ret = vm_deallocate (mach_task_self (),
1833 // OBSOLETE                    copied_memory,
1834 // OBSOLETE                    copy_count);
1835 // OBSOLETE   CHK ("mach3_read_inferior vm_deallocate failed", ret);
1836 // OBSOLETE 
1837 // OBSOLETE   return length;
1838 // OBSOLETE }
1839 // OBSOLETE 
1840 // OBSOLETE #define CHK_GOTO_OUT(str,ret) \
1841 // OBSOLETE   do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
1842 // OBSOLETE 
1843 // OBSOLETE struct vm_region_list
1844 // OBSOLETE {
1845 // OBSOLETE   struct vm_region_list *next;
1846 // OBSOLETE   vm_prot_t protection;
1847 // OBSOLETE   vm_address_t start;
1848 // OBSOLETE   vm_size_t length;
1849 // OBSOLETE };
1850 // OBSOLETE 
1851 // OBSOLETE struct obstack region_obstack;
1852 // OBSOLETE 
1853 // OBSOLETE /*
1854 // OBSOLETE  * Write inferior task's LEN bytes from ADDR and copy it to MYADDR
1855 // OBSOLETE  * in gdb's address space.
1856 // OBSOLETE  */
1857 // OBSOLETE int
1858 // OBSOLETE mach3_write_inferior (CORE_ADDR addr, char *myaddr, int length)
1859 // OBSOLETE {
1860 // OBSOLETE   kern_return_t ret;
1861 // OBSOLETE   vm_address_t low_address = (vm_address_t) trunc_page (addr);
1862 // OBSOLETE   vm_size_t aligned_length =
1863 // OBSOLETE   (vm_size_t) round_page (addr + length) - low_address;
1864 // OBSOLETE   pointer_t copied_memory;
1865 // OBSOLETE   int copy_count;
1866 // OBSOLETE   int deallocate = 0;
1867 // OBSOLETE 
1868 // OBSOLETE   char *errstr = "Bug in mach3_write_inferior";
1869 // OBSOLETE 
1870 // OBSOLETE   struct vm_region_list *region_element;
1871 // OBSOLETE   struct vm_region_list *region_head = (struct vm_region_list *) NULL;
1872 // OBSOLETE 
1873 // OBSOLETE   /* Get memory from inferior with page aligned addresses */
1874 // OBSOLETE   ret = vm_read (inferior_task,
1875 // OBSOLETE              low_address,
1876 // OBSOLETE              aligned_length,
1877 // OBSOLETE              &copied_memory,
1878 // OBSOLETE              &copy_count);
1879 // OBSOLETE   CHK_GOTO_OUT ("mach3_write_inferior vm_read failed", ret);
1880 // OBSOLETE 
1881 // OBSOLETE   deallocate++;
1882 // OBSOLETE 
1883 // OBSOLETE   memcpy ((char *) addr - low_address + copied_memory, myaddr, length);
1884 // OBSOLETE 
1885 // OBSOLETE   obstack_init (&region_obstack);
1886 // OBSOLETE 
1887 // OBSOLETE   /* Do writes atomically.
1888 // OBSOLETE    * First check for holes and unwritable memory.
1889 // OBSOLETE    */
1890 // OBSOLETE   {
1891 // OBSOLETE     vm_size_t remaining_length = aligned_length;
1892 // OBSOLETE     vm_address_t region_address = low_address;
1893 // OBSOLETE 
1894 // OBSOLETE     struct vm_region_list *scan;
1895 // OBSOLETE 
1896 // OBSOLETE     while (region_address < low_address + aligned_length)
1897 // OBSOLETE       {
1898 // OBSOLETE     vm_prot_t protection;
1899 // OBSOLETE     vm_prot_t max_protection;
1900 // OBSOLETE     vm_inherit_t inheritance;
1901 // OBSOLETE     boolean_t shared;
1902 // OBSOLETE     mach_port_t object_name;
1903 // OBSOLETE     vm_offset_t offset;
1904 // OBSOLETE     vm_size_t region_length = remaining_length;
1905 // OBSOLETE     vm_address_t old_address = region_address;
1906 // OBSOLETE 
1907 // OBSOLETE     ret = vm_region (inferior_task,
1908 // OBSOLETE                      &region_address,
1909 // OBSOLETE                      &region_length,
1910 // OBSOLETE                      &protection,
1911 // OBSOLETE                      &max_protection,
1912 // OBSOLETE                      &inheritance,
1913 // OBSOLETE                      &shared,
1914 // OBSOLETE                      &object_name,
1915 // OBSOLETE                      &offset);
1916 // OBSOLETE     CHK_GOTO_OUT ("vm_region failed", ret);
1917 // OBSOLETE 
1918 // OBSOLETE     /* Check for holes in memory */
1919 // OBSOLETE     if (old_address != region_address)
1920 // OBSOLETE       {
1921 // OBSOLETE         warning ("No memory at 0x%x. Nothing written",
1922 // OBSOLETE                  old_address);
1923 // OBSOLETE         ret = KERN_SUCCESS;
1924 // OBSOLETE         length = 0;
1925 // OBSOLETE         goto out;
1926 // OBSOLETE       }
1927 // OBSOLETE 
1928 // OBSOLETE     if (!(max_protection & VM_PROT_WRITE))
1929 // OBSOLETE       {
1930 // OBSOLETE         warning ("Memory at address 0x%x is unwritable. Nothing written",
1931 // OBSOLETE                  old_address);
1932 // OBSOLETE         ret = KERN_SUCCESS;
1933 // OBSOLETE         length = 0;
1934 // OBSOLETE         goto out;
1935 // OBSOLETE       }
1936 // OBSOLETE 
1937 // OBSOLETE     /* Chain the regions for later use */
1938 // OBSOLETE     region_element =
1939 // OBSOLETE       (struct vm_region_list *)
1940 // OBSOLETE       obstack_alloc (&region_obstack, sizeof (struct vm_region_list));
1941 // OBSOLETE 
1942 // OBSOLETE     region_element->protection = protection;
1943 // OBSOLETE     region_element->start = region_address;
1944 // OBSOLETE     region_element->length = region_length;
1945 // OBSOLETE 
1946 // OBSOLETE     /* Chain the regions along with protections */
1947 // OBSOLETE     region_element->next = region_head;
1948 // OBSOLETE     region_head = region_element;
1949 // OBSOLETE 
1950 // OBSOLETE     region_address += region_length;
1951 // OBSOLETE     remaining_length = remaining_length - region_length;
1952 // OBSOLETE       }
1953 // OBSOLETE 
1954 // OBSOLETE     /* If things fail after this, we give up.
1955 // OBSOLETE      * Somebody is messing up inferior_task's mappings.
1956 // OBSOLETE      */
1957 // OBSOLETE 
1958 // OBSOLETE     /* Enable writes to the chained vm regions */
1959 // OBSOLETE     for (scan = region_head; scan; scan = scan->next)
1960 // OBSOLETE       {
1961 // OBSOLETE     boolean_t protection_changed = FALSE;
1962 // OBSOLETE 
1963 // OBSOLETE     if (!(scan->protection & VM_PROT_WRITE))
1964 // OBSOLETE       {
1965 // OBSOLETE         ret = vm_protect (inferior_task,
1966 // OBSOLETE                           scan->start,
1967 // OBSOLETE                           scan->length,
1968 // OBSOLETE                           FALSE,
1969 // OBSOLETE                           scan->protection | VM_PROT_WRITE);
1970 // OBSOLETE         CHK_GOTO_OUT ("vm_protect: enable write failed", ret);
1971 // OBSOLETE       }
1972 // OBSOLETE       }
1973 // OBSOLETE 
1974 // OBSOLETE     ret = vm_write (inferior_task,
1975 // OBSOLETE                 low_address,
1976 // OBSOLETE                 copied_memory,
1977 // OBSOLETE                 aligned_length);
1978 // OBSOLETE     CHK_GOTO_OUT ("vm_write failed", ret);
1979 // OBSOLETE 
1980 // OBSOLETE     /* Set up the original region protections, if they were changed */
1981 // OBSOLETE     for (scan = region_head; scan; scan = scan->next)
1982 // OBSOLETE       {
1983 // OBSOLETE     boolean_t protection_changed = FALSE;
1984 // OBSOLETE 
1985 // OBSOLETE     if (!(scan->protection & VM_PROT_WRITE))
1986 // OBSOLETE       {
1987 // OBSOLETE         ret = vm_protect (inferior_task,
1988 // OBSOLETE                           scan->start,
1989 // OBSOLETE                           scan->length,
1990 // OBSOLETE                           FALSE,
1991 // OBSOLETE                           scan->protection);
1992 // OBSOLETE         CHK_GOTO_OUT ("vm_protect: enable write failed", ret);
1993 // OBSOLETE       }
1994 // OBSOLETE       }
1995 // OBSOLETE   }
1996 // OBSOLETE 
1997 // OBSOLETE out:
1998 // OBSOLETE   if (deallocate)
1999 // OBSOLETE     {
2000 // OBSOLETE       obstack_free (&region_obstack, 0);
2001 // OBSOLETE 
2002 // OBSOLETE       (void) vm_deallocate (mach_task_self (),
2003 // OBSOLETE                         copied_memory,
2004 // OBSOLETE                         copy_count);
2005 // OBSOLETE     }
2006 // OBSOLETE 
2007 // OBSOLETE   if (ret != KERN_SUCCESS)
2008 // OBSOLETE     {
2009 // OBSOLETE       warning ("%s %s", errstr, mach_error_string (ret));
2010 // OBSOLETE       return 0;
2011 // OBSOLETE     }
2012 // OBSOLETE 
2013 // OBSOLETE   return length;
2014 // OBSOLETE }
2015 // OBSOLETE 
2016 // OBSOLETE /* Return 0 on failure, number of bytes handled otherwise.  TARGET is
2017 // OBSOLETE    ignored. */
2018 // OBSOLETE static int
2019 // OBSOLETE m3_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
2020 // OBSOLETE             struct target_ops *target)
2021 // OBSOLETE {
2022 // OBSOLETE   int result;
2023 // OBSOLETE 
2024 // OBSOLETE   if (write)
2025 // OBSOLETE     result = mach3_write_inferior (memaddr, myaddr, len);
2026 // OBSOLETE   else
2027 // OBSOLETE     result = mach3_read_inferior (memaddr, myaddr, len);
2028 // OBSOLETE 
2029 // OBSOLETE   return result;
2030 // OBSOLETE }
2031 // OBSOLETE \f
2032 // OBSOLETE 
2033 // OBSOLETE static char *
2034 // OBSOLETE translate_state (int state)
2035 // OBSOLETE {
2036 // OBSOLETE   switch (state)
2037 // OBSOLETE     {
2038 // OBSOLETE     case TH_STATE_RUNNING:
2039 // OBSOLETE       return ("R");
2040 // OBSOLETE     case TH_STATE_STOPPED:
2041 // OBSOLETE       return ("S");
2042 // OBSOLETE     case TH_STATE_WAITING:
2043 // OBSOLETE       return ("W");
2044 // OBSOLETE     case TH_STATE_UNINTERRUPTIBLE:
2045 // OBSOLETE       return ("U");
2046 // OBSOLETE     case TH_STATE_HALTED:
2047 // OBSOLETE       return ("H");
2048 // OBSOLETE     default:
2049 // OBSOLETE       return ("?");
2050 // OBSOLETE     }
2051 // OBSOLETE }
2052 // OBSOLETE 
2053 // OBSOLETE static char *
2054 // OBSOLETE translate_cstate (int state)
2055 // OBSOLETE {
2056 // OBSOLETE   switch (state)
2057 // OBSOLETE     {
2058 // OBSOLETE     case CPROC_RUNNING:
2059 // OBSOLETE       return "R";
2060 // OBSOLETE     case CPROC_SWITCHING:
2061 // OBSOLETE       return "S";
2062 // OBSOLETE     case CPROC_BLOCKED:
2063 // OBSOLETE       return "B";
2064 // OBSOLETE     case CPROC_CONDWAIT:
2065 // OBSOLETE       return "C";
2066 // OBSOLETE     case CPROC_CONDWAIT | CPROC_SWITCHING:
2067 // OBSOLETE       return "CS";
2068 // OBSOLETE     default:
2069 // OBSOLETE       return "?";
2070 // OBSOLETE     }
2071 // OBSOLETE }
2072 // OBSOLETE 
2073 // OBSOLETE /* type == MACH_MSG_TYPE_COPY_SEND || type == MACH_MSG_TYPE_MAKE_SEND */
2074 // OBSOLETE 
2075 // OBSOLETE mach_port_t                 /* no mach_port_name_t found in include files. */
2076 // OBSOLETE map_inferior_port_name (mach_port_t inferior_name, mach_msg_type_name_t type)
2077 // OBSOLETE {
2078 // OBSOLETE   kern_return_t ret;
2079 // OBSOLETE   mach_msg_type_name_t acquired;
2080 // OBSOLETE   mach_port_t iport;
2081 // OBSOLETE 
2082 // OBSOLETE   ret = mach_port_extract_right (inferior_task,
2083 // OBSOLETE                              inferior_name,
2084 // OBSOLETE                              type,
2085 // OBSOLETE                              &iport,
2086 // OBSOLETE                              &acquired);
2087 // OBSOLETE   CHK ("mach_port_extract_right (map_inferior_port_name)", ret);
2088 // OBSOLETE 
2089 // OBSOLETE   if (acquired != MACH_MSG_TYPE_PORT_SEND)
2090 // OBSOLETE     error ("Incorrect right extracted, (map_inferior_port_name)");
2091 // OBSOLETE 
2092 // OBSOLETE   ret = mach_port_deallocate (mach_task_self (),
2093 // OBSOLETE                           iport);
2094 // OBSOLETE   CHK ("Deallocating mapped port (map_inferior_port_name)", ret);
2095 // OBSOLETE 
2096 // OBSOLETE   return iport;
2097 // OBSOLETE }
2098 // OBSOLETE 
2099 // OBSOLETE /*
2100 // OBSOLETE  * Naming convention:
2101 // OBSOLETE  *  Always return user defined name if found.
2102 // OBSOLETE  *  _K == A kernel thread with no matching CPROC
2103 // OBSOLETE  *  _C == A cproc with no current cthread
2104 // OBSOLETE  *  _t == A cthread with no user defined name
2105 // OBSOLETE  *
2106 // OBSOLETE  * The digits that follow the _names are the SLOT number of the
2107 // OBSOLETE  * kernel thread if there is such a thing, otherwise just a negation
2108 // OBSOLETE  * of the sequential number of such cprocs.
2109 // OBSOLETE  */
2110 // OBSOLETE 
2111 // OBSOLETE static char buf[7];
2112 // OBSOLETE 
2113 // OBSOLETE static char *
2114 // OBSOLETE get_thread_name (gdb_thread_t one_cproc, int id)
2115 // OBSOLETE {
2116 // OBSOLETE   if (one_cproc)
2117 // OBSOLETE     if (one_cproc->cthread == NULL)
2118 // OBSOLETE       {
2119 // OBSOLETE     /* cproc not mapped to any cthread */
2120 // OBSOLETE     sprintf (buf, "_C%d", id);
2121 // OBSOLETE       }
2122 // OBSOLETE     else if (!one_cproc->cthread->name)
2123 // OBSOLETE       {
2124 // OBSOLETE     /* cproc and cthread, but no name */
2125 // OBSOLETE     sprintf (buf, "_t%d", id);
2126 // OBSOLETE       }
2127 // OBSOLETE     else
2128 // OBSOLETE       return (char *) (one_cproc->cthread->name);
2129 // OBSOLETE   else
2130 // OBSOLETE     {
2131 // OBSOLETE       if (id < 0)
2132 // OBSOLETE     warning ("Inconsistency in thread name id %d", id);
2133 // OBSOLETE 
2134 // OBSOLETE       /* Kernel thread without cproc */
2135 // OBSOLETE       sprintf (buf, "_K%d", id);
2136 // OBSOLETE     }
2137 // OBSOLETE 
2138 // OBSOLETE   return buf;
2139 // OBSOLETE }
2140 // OBSOLETE 
2141 // OBSOLETE int
2142 // OBSOLETE fetch_thread_info (mach_port_t task, gdb_thread_t *mthreads_out)
2143 // OBSOLETE {
2144 // OBSOLETE   kern_return_t ret;
2145 // OBSOLETE   thread_array_t th_table;
2146 // OBSOLETE   int th_count;
2147 // OBSOLETE   gdb_thread_t mthreads = NULL;
2148 // OBSOLETE   int index;
2149 // OBSOLETE 
2150 // OBSOLETE   ret = task_threads (task, &th_table, &th_count);
2151 // OBSOLETE   if (ret != KERN_SUCCESS)
2152 // OBSOLETE     {
2153 // OBSOLETE       warning ("Error getting inferior's thread list:%s",
2154 // OBSOLETE            mach_error_string (ret));
2155 // OBSOLETE       m3_kill_inferior ();
2156 // OBSOLETE       return -1;
2157 // OBSOLETE     }
2158 // OBSOLETE 
2159 // OBSOLETE   mthreads = (gdb_thread_t)
2160 // OBSOLETE     obstack_alloc
2161 // OBSOLETE     (cproc_obstack,
2162 // OBSOLETE      th_count * sizeof (struct gdb_thread));
2163 // OBSOLETE 
2164 // OBSOLETE   for (index = 0; index < th_count; index++)
2165 // OBSOLETE     {
2166 // OBSOLETE       thread_t saved_thread = MACH_PORT_NULL;
2167 // OBSOLETE       int mid;
2168 // OBSOLETE 
2169 // OBSOLETE       if (must_suspend_thread)
2170 // OBSOLETE     setup_thread (th_table[index], 1);
2171 // OBSOLETE 
2172 // OBSOLETE       if (th_table[index] != current_thread)
2173 // OBSOLETE     {
2174 // OBSOLETE       saved_thread = current_thread;
2175 // OBSOLETE 
2176 // OBSOLETE       mid = switch_to_thread (th_table[index]);
2177 // OBSOLETE     }
2178 // OBSOLETE 
2179 // OBSOLETE       mthreads[index].name = th_table[index];
2180 // OBSOLETE       mthreads[index].cproc = NULL; /* map_cprocs_to_kernel_threads() */
2181 // OBSOLETE       mthreads[index].in_emulator = FALSE;
2182 // OBSOLETE       mthreads[index].slotid = index;
2183 // OBSOLETE 
2184 // OBSOLETE       mthreads[index].sp = read_register (SP_REGNUM);
2185 // OBSOLETE       mthreads[index].fp = read_register (FP_REGNUM);
2186 // OBSOLETE       mthreads[index].pc = read_pc ();
2187 // OBSOLETE 
2188 // OBSOLETE       if (MACH_PORT_VALID (saved_thread))
2189 // OBSOLETE     mid = switch_to_thread (saved_thread);
2190 // OBSOLETE 
2191 // OBSOLETE       if (must_suspend_thread)
2192 // OBSOLETE     setup_thread (th_table[index], 0);
2193 // OBSOLETE     }
2194 // OBSOLETE 
2195 // OBSOLETE   consume_send_rights (th_table, th_count);
2196 // OBSOLETE   ret = vm_deallocate (mach_task_self (), (vm_address_t) th_table,
2197 // OBSOLETE                    (th_count * sizeof (mach_port_t)));
2198 // OBSOLETE   if (ret != KERN_SUCCESS)
2199 // OBSOLETE     {
2200 // OBSOLETE       warning ("Error trying to deallocate thread list : %s",
2201 // OBSOLETE            mach_error_string (ret));
2202 // OBSOLETE     }
2203 // OBSOLETE 
2204 // OBSOLETE   *mthreads_out = mthreads;
2205 // OBSOLETE 
2206 // OBSOLETE   return th_count;
2207 // OBSOLETE }
2208 // OBSOLETE 
2209 // OBSOLETE 
2210 // OBSOLETE /*
2211 // OBSOLETE  * Current emulator always saves the USP on top of
2212 // OBSOLETE  * emulator stack below struct emul_stack_top stuff.
2213 // OBSOLETE  */
2214 // OBSOLETE CORE_ADDR
2215 // OBSOLETE fetch_usp_from_emulator_stack (CORE_ADDR sp)
2216 // OBSOLETE {
2217 // OBSOLETE   CORE_ADDR stack_pointer;
2218 // OBSOLETE 
2219 // OBSOLETE   sp = (sp & ~(EMULATOR_STACK_SIZE - 1)) +
2220 // OBSOLETE     EMULATOR_STACK_SIZE - sizeof (struct emul_stack_top);
2221 // OBSOLETE 
2222 // OBSOLETE   if (mach3_read_inferior (sp,
2223 // OBSOLETE                        &stack_pointer,
2224 // OBSOLETE                        sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2225 // OBSOLETE     {
2226 // OBSOLETE       warning ("Can't read user sp from emulator stack address 0x%x", sp);
2227 // OBSOLETE       return 0;
2228 // OBSOLETE     }
2229 // OBSOLETE 
2230 // OBSOLETE   return stack_pointer;
2231 // OBSOLETE }
2232 // OBSOLETE 
2233 // OBSOLETE #ifdef MK67
2234 // OBSOLETE 
2235 // OBSOLETE /* get_emulation_vector() interface was changed after mk67 */
2236 // OBSOLETE #define EMUL_VECTOR_COUNT 400       /* Value does not matter too much */
2237 // OBSOLETE 
2238 // OBSOLETE #endif /* MK67 */
2239 // OBSOLETE 
2240 // OBSOLETE /* Check if the emulator exists at task's address space.
2241 // OBSOLETE  */
2242 // OBSOLETE boolean_t
2243 // OBSOLETE have_emulator_p (task_t task)
2244 // OBSOLETE {
2245 // OBSOLETE   kern_return_t ret;
2246 // OBSOLETE #ifndef EMUL_VECTOR_COUNT
2247 // OBSOLETE   vm_offset_t *emulation_vector;
2248 // OBSOLETE   int n;
2249 // OBSOLETE #else
2250 // OBSOLETE   vm_offset_t emulation_vector[EMUL_VECTOR_COUNT];
2251 // OBSOLETE   int n = EMUL_VECTOR_COUNT;
2252 // OBSOLETE #endif
2253 // OBSOLETE   int i;
2254 // OBSOLETE   int vector_start;
2255 // OBSOLETE 
2256 // OBSOLETE   ret = task_get_emulation_vector (task,
2257 // OBSOLETE                                &vector_start,
2258 // OBSOLETE #ifndef EMUL_VECTOR_COUNT
2259 // OBSOLETE                                &emulation_vector,
2260 // OBSOLETE #else
2261 // OBSOLETE                                emulation_vector,
2262 // OBSOLETE #endif
2263 // OBSOLETE                                &n);
2264 // OBSOLETE   CHK ("task_get_emulation_vector", ret);
2265 // OBSOLETE   xx_debug ("%d vectors from %d at 0x%08x\n",
2266 // OBSOLETE         n, vector_start, emulation_vector);
2267 // OBSOLETE 
2268 // OBSOLETE   for (i = 0; i < n; i++)
2269 // OBSOLETE     {
2270 // OBSOLETE       vm_offset_t entry = emulation_vector[i];
2271 // OBSOLETE 
2272 // OBSOLETE       if (EMULATOR_BASE <= entry && entry <= EMULATOR_END)
2273 // OBSOLETE     return TRUE;
2274 // OBSOLETE       else if (entry)
2275 // OBSOLETE     {
2276 // OBSOLETE       static boolean_t informed = FALSE;
2277 // OBSOLETE       if (!informed)
2278 // OBSOLETE         {
2279 // OBSOLETE           warning ("Emulation vector address 0x08%x outside emulator space",
2280 // OBSOLETE                    entry);
2281 // OBSOLETE           informed = TRUE;
2282 // OBSOLETE         }
2283 // OBSOLETE     }
2284 // OBSOLETE     }
2285 // OBSOLETE   return FALSE;
2286 // OBSOLETE }
2287 // OBSOLETE 
2288 // OBSOLETE /* Map cprocs to kernel threads and vice versa.  */
2289 // OBSOLETE 
2290 // OBSOLETE void
2291 // OBSOLETE map_cprocs_to_kernel_threads (gdb_thread_t cprocs, gdb_thread_t mthreads,
2292 // OBSOLETE                           int thread_count)
2293 // OBSOLETE {
2294 // OBSOLETE   int index;
2295 // OBSOLETE   gdb_thread_t scan;
2296 // OBSOLETE   boolean_t all_mapped = TRUE;
2297 // OBSOLETE   LONGEST stack_base;
2298 // OBSOLETE   LONGEST stack_size;
2299 // OBSOLETE 
2300 // OBSOLETE   for (scan = cprocs; scan; scan = scan->next)
2301 // OBSOLETE     {
2302 // OBSOLETE       /* Default to: no kernel thread for this cproc */
2303 // OBSOLETE       scan->reverse_map = -1;
2304 // OBSOLETE 
2305 // OBSOLETE       /* Check if the cproc is found by its stack */
2306 // OBSOLETE       for (index = 0; index < thread_count; index++)
2307 // OBSOLETE     {
2308 // OBSOLETE       stack_base =
2309 // OBSOLETE         extract_signed_integer (scan->raw_cproc + CPROC_BASE_OFFSET,
2310 // OBSOLETE                                 CPROC_BASE_SIZE);
2311 // OBSOLETE       stack_size =
2312 // OBSOLETE         extract_signed_integer (scan->raw_cproc + CPROC_SIZE_OFFSET,
2313 // OBSOLETE                                 CPROC_SIZE_SIZE);
2314 // OBSOLETE       if ((mthreads + index)->sp > stack_base &&
2315 // OBSOLETE           (mthreads + index)->sp <= stack_base + stack_size)
2316 // OBSOLETE         {
2317 // OBSOLETE           (mthreads + index)->cproc = scan;
2318 // OBSOLETE           scan->reverse_map = index;
2319 // OBSOLETE           break;
2320 // OBSOLETE         }
2321 // OBSOLETE     }
2322 // OBSOLETE       all_mapped &= (scan->reverse_map != -1);
2323 // OBSOLETE     }
2324 // OBSOLETE 
2325 // OBSOLETE   /* Check for threads that are currently in the emulator.
2326 // OBSOLETE    * If so, they have a different stack, and the still unmapped
2327 // OBSOLETE    * cprocs may well get mapped to these threads.
2328 // OBSOLETE    * 
2329 // OBSOLETE    * If:
2330 // OBSOLETE    *  - cproc stack does not match any kernel thread stack pointer
2331 // OBSOLETE    *  - there is at least one extra kernel thread
2332 // OBSOLETE    *    that has no cproc mapped above.
2333 // OBSOLETE    *  - some kernel thread stack pointer points to emulator space
2334 // OBSOLETE    *  then we find the user stack pointer saved in the emulator
2335 // OBSOLETE    *  stack, and try to map that to the cprocs.
2336 // OBSOLETE    *
2337 // OBSOLETE    * Also set in_emulator for kernel threads.
2338 // OBSOLETE    */
2339 // OBSOLETE 
2340 // OBSOLETE   if (emulator_present)
2341 // OBSOLETE     {
2342 // OBSOLETE       for (index = 0; index < thread_count; index++)
2343 // OBSOLETE     {
2344 // OBSOLETE       CORE_ADDR emul_sp;
2345 // OBSOLETE       CORE_ADDR usp;
2346 // OBSOLETE 
2347 // OBSOLETE       gdb_thread_t mthread = (mthreads + index);
2348 // OBSOLETE       emul_sp = mthread->sp;
2349 // OBSOLETE 
2350 // OBSOLETE       if (mthread->cproc == NULL &&
2351 // OBSOLETE           EMULATOR_BASE <= emul_sp && emul_sp <= EMULATOR_END)
2352 // OBSOLETE         {
2353 // OBSOLETE           mthread->in_emulator = emulator_present;
2354 // OBSOLETE 
2355 // OBSOLETE           if (!all_mapped && cprocs)
2356 // OBSOLETE             {
2357 // OBSOLETE               usp = fetch_usp_from_emulator_stack (emul_sp);
2358 // OBSOLETE 
2359 // OBSOLETE               /* @@ Could be more accurate */
2360 // OBSOLETE               if (!usp)
2361 // OBSOLETE                 error ("Zero stack pointer read from emulator?");
2362 // OBSOLETE 
2363 // OBSOLETE               /* Try to match this stack pointer to the cprocs that
2364 // OBSOLETE                * don't yet have a kernel thread.
2365 // OBSOLETE                */
2366 // OBSOLETE               for (scan = cprocs; scan; scan = scan->next)
2367 // OBSOLETE                 {
2368 // OBSOLETE 
2369 // OBSOLETE                   /* Check is this unmapped CPROC stack contains
2370 // OBSOLETE                    * the user stack pointer saved in the
2371 // OBSOLETE                    * emulator.
2372 // OBSOLETE                    */
2373 // OBSOLETE                   if (scan->reverse_map == -1)
2374 // OBSOLETE                     {
2375 // OBSOLETE                       stack_base =
2376 // OBSOLETE                         extract_signed_integer
2377 // OBSOLETE                         (scan->raw_cproc + CPROC_BASE_OFFSET,
2378 // OBSOLETE                          CPROC_BASE_SIZE);
2379 // OBSOLETE                       stack_size =
2380 // OBSOLETE                         extract_signed_integer
2381 // OBSOLETE                         (scan->raw_cproc + CPROC_SIZE_OFFSET,
2382 // OBSOLETE                          CPROC_SIZE_SIZE);
2383 // OBSOLETE                       if (usp > stack_base &&
2384 // OBSOLETE                           usp <= stack_base + stack_size)
2385 // OBSOLETE                         {
2386 // OBSOLETE                           mthread->cproc = scan;
2387 // OBSOLETE                           scan->reverse_map = index;
2388 // OBSOLETE                           break;
2389 // OBSOLETE                         }
2390 // OBSOLETE                     }
2391 // OBSOLETE                 }
2392 // OBSOLETE             }
2393 // OBSOLETE         }
2394 // OBSOLETE     }
2395 // OBSOLETE     }
2396 // OBSOLETE }
2397 // OBSOLETE \f
2398 // OBSOLETE /*
2399 // OBSOLETE  * Format of the thread_list command
2400 // OBSOLETE  *
2401 // OBSOLETE  *                   slot mid sel   name  emul ks susp  cstate wired   address
2402 // OBSOLETE  */
2403 // OBSOLETE #define TL_FORMAT "%-2.2s %5d%c %-10.10s %1.1s%s%-5.5s %-2.2s %-5.5s "
2404 // OBSOLETE 
2405 // OBSOLETE #define TL_HEADER "\n@    MID  Name        KState CState   Where\n"
2406 // OBSOLETE 
2407 // OBSOLETE void
2408 // OBSOLETE print_tl_address (struct ui_file *stream, CORE_ADDR pc)
2409 // OBSOLETE {
2410 // OBSOLETE   if (!lookup_minimal_symbol_by_pc (pc))
2411 // OBSOLETE     fprintf_filtered (stream, local_hex_format (), pc);
2412 // OBSOLETE   else
2413 // OBSOLETE     {
2414 // OBSOLETE       extern int addressprint;
2415 // OBSOLETE       extern int asm_demangle;
2416 // OBSOLETE 
2417 // OBSOLETE       int store = addressprint;
2418 // OBSOLETE       addressprint = 0;
2419 // OBSOLETE       print_address_symbolic (pc, stream, asm_demangle, "");
2420 // OBSOLETE       addressprint = store;
2421 // OBSOLETE     }
2422 // OBSOLETE }
2423 // OBSOLETE \f
2424 // OBSOLETE /* For thread names, but also for gdb_message_port external name */
2425 // OBSOLETE #define MAX_NAME_LEN 50
2426 // OBSOLETE 
2427 // OBSOLETE /* Returns the address of variable NAME or 0 if not found */
2428 // OBSOLETE CORE_ADDR
2429 // OBSOLETE lookup_address_of_variable (char *name)
2430 // OBSOLETE {
2431 // OBSOLETE   struct symbol *sym;
2432 // OBSOLETE   CORE_ADDR symaddr = 0;
2433 // OBSOLETE   struct minimal_symbol *msymbol;
2434 // OBSOLETE 
2435 // OBSOLETE   sym = lookup_symbol (name,
2436 // OBSOLETE                    (struct block *) NULL,
2437 // OBSOLETE                    VAR_DOMAIN,
2438 // OBSOLETE                    (int *) NULL,
2439 // OBSOLETE                    (struct symtab **) NULL);
2440 // OBSOLETE 
2441 // OBSOLETE   if (sym)
2442 // OBSOLETE     symaddr = SYMBOL_VALUE (sym);
2443 // OBSOLETE 
2444 // OBSOLETE   if (!symaddr)
2445 // OBSOLETE     {
2446 // OBSOLETE       msymbol = lookup_minimal_symbol (name, NULL, NULL);
2447 // OBSOLETE 
2448 // OBSOLETE       if (msymbol && msymbol->type == mst_data)
2449 // OBSOLETE     symaddr = SYMBOL_VALUE_ADDRESS (msymbol);
2450 // OBSOLETE     }
2451 // OBSOLETE 
2452 // OBSOLETE   return symaddr;
2453 // OBSOLETE }
2454 // OBSOLETE 
2455 // OBSOLETE static gdb_thread_t
2456 // OBSOLETE get_cprocs (void)
2457 // OBSOLETE {
2458 // OBSOLETE   gdb_thread_t cproc_head;
2459 // OBSOLETE   gdb_thread_t cproc_copy;
2460 // OBSOLETE   CORE_ADDR their_cprocs;
2461 // OBSOLETE   char *buf;
2462 // OBSOLETE   char *name;
2463 // OBSOLETE   cthread_t cthread;
2464 // OBSOLETE   CORE_ADDR symaddr;
2465 // OBSOLETE 
2466 // OBSOLETE   buf = alloca (TARGET_PTR_BIT / HOST_CHAR_BIT);
2467 // OBSOLETE   symaddr = lookup_address_of_variable ("cproc_list");
2468 // OBSOLETE 
2469 // OBSOLETE   if (!symaddr)
2470 // OBSOLETE     {
2471 // OBSOLETE       /* cproc_list is not in a file compiled with debugging
2472 // OBSOLETE          symbols, but don't give up yet */
2473 // OBSOLETE 
2474 // OBSOLETE       symaddr = lookup_address_of_variable ("cprocs");
2475 // OBSOLETE 
2476 // OBSOLETE       if (symaddr)
2477 // OBSOLETE     {
2478 // OBSOLETE       static int informed = 0;
2479 // OBSOLETE       if (!informed)
2480 // OBSOLETE         {
2481 // OBSOLETE           informed++;
2482 // OBSOLETE           warning ("Your program is loaded with an old threads library.");
2483 // OBSOLETE           warning ("GDB does not know the old form of threads");
2484 // OBSOLETE           warning ("so things may not work.");
2485 // OBSOLETE         }
2486 // OBSOLETE     }
2487 // OBSOLETE     }
2488 // OBSOLETE 
2489 // OBSOLETE   /* Stripped or no -lthreads loaded or "cproc_list" is in wrong segment. */
2490 // OBSOLETE   if (!symaddr)
2491 // OBSOLETE     return NULL;
2492 // OBSOLETE 
2493 // OBSOLETE   /* Get the address of the first cproc in the task */
2494 // OBSOLETE   if (!mach3_read_inferior (symaddr,
2495 // OBSOLETE                         buf,
2496 // OBSOLETE                         TARGET_PTR_BIT / HOST_CHAR_BIT))
2497 // OBSOLETE     error ("Can't read cproc master list at address (0x%x).", symaddr);
2498 // OBSOLETE   their_cprocs = extract_address (buf, TARGET_PTR_BIT / HOST_CHAR_BIT);
2499 // OBSOLETE 
2500 // OBSOLETE   /* Scan the CPROCs in the task.
2501 // OBSOLETE      CPROCs are chained with LIST field, not NEXT field, which
2502 // OBSOLETE      chains mutexes, condition variables and queues */
2503 // OBSOLETE 
2504 // OBSOLETE   cproc_head = NULL;
2505 // OBSOLETE 
2506 // OBSOLETE   while (their_cprocs != (CORE_ADDR) 0)
2507 // OBSOLETE     {
2508 // OBSOLETE       CORE_ADDR cproc_copy_incarnation;
2509 // OBSOLETE       cproc_copy = (gdb_thread_t) obstack_alloc (cproc_obstack,
2510 // OBSOLETE                                              sizeof (struct gdb_thread));
2511 // OBSOLETE 
2512 // OBSOLETE       if (!mach3_read_inferior (their_cprocs,
2513 // OBSOLETE                             &cproc_copy->raw_cproc[0],
2514 // OBSOLETE                             CPROC_SIZE))
2515 // OBSOLETE     error ("Can't read next cproc at 0x%x.", their_cprocs);
2516 // OBSOLETE 
2517 // OBSOLETE       their_cprocs =
2518 // OBSOLETE     extract_address (cproc_copy->raw_cproc + CPROC_LIST_OFFSET,
2519 // OBSOLETE                      CPROC_LIST_SIZE);
2520 // OBSOLETE       cproc_copy_incarnation =
2521 // OBSOLETE     extract_address (cproc_copy->raw_cproc + CPROC_INCARNATION_OFFSET,
2522 // OBSOLETE                      CPROC_INCARNATION_SIZE);
2523 // OBSOLETE 
2524 // OBSOLETE       if (cproc_copy_incarnation == (CORE_ADDR) 0)
2525 // OBSOLETE     cproc_copy->cthread = NULL;
2526 // OBSOLETE       else
2527 // OBSOLETE     {
2528 // OBSOLETE       /* This CPROC has an attached CTHREAD. Get its name */
2529 // OBSOLETE       cthread = (cthread_t) obstack_alloc (cproc_obstack,
2530 // OBSOLETE                                            sizeof (struct cthread));
2531 // OBSOLETE 
2532 // OBSOLETE       if (!mach3_read_inferior (cproc_copy_incarnation,
2533 // OBSOLETE                                 cthread,
2534 // OBSOLETE                                 sizeof (struct cthread)))
2535 // OBSOLETE           error ("Can't read next thread at 0x%x.",
2536 // OBSOLETE                  cproc_copy_incarnation);
2537 // OBSOLETE 
2538 // OBSOLETE       cproc_copy->cthread = cthread;
2539 // OBSOLETE 
2540 // OBSOLETE       if (cthread->name)
2541 // OBSOLETE         {
2542 // OBSOLETE           name = (char *) obstack_alloc (cproc_obstack, MAX_NAME_LEN);
2543 // OBSOLETE 
2544 // OBSOLETE           if (!mach3_read_inferior (cthread->name, name, MAX_NAME_LEN))
2545 // OBSOLETE             error ("Can't read next thread's name at 0x%x.", cthread->name);
2546 // OBSOLETE 
2547 // OBSOLETE           cthread->name = name;
2548 // OBSOLETE         }
2549 // OBSOLETE     }
2550 // OBSOLETE 
2551 // OBSOLETE       /* insert in front */
2552 // OBSOLETE       cproc_copy->next = cproc_head;
2553 // OBSOLETE       cproc_head = cproc_copy;
2554 // OBSOLETE     }
2555 // OBSOLETE   return cproc_head;
2556 // OBSOLETE }
2557 // OBSOLETE 
2558 // OBSOLETE #ifndef FETCH_CPROC_STATE
2559 // OBSOLETE /*
2560 // OBSOLETE  * Check if your machine does not grok the way this routine
2561 // OBSOLETE  * fetches the FP,PC and SP of a cproc that is not
2562 // OBSOLETE  * currently attached to any kernel thread (e.g. its cproc.context
2563 // OBSOLETE  * field points to the place in stack where the context
2564 // OBSOLETE  * is saved).
2565 // OBSOLETE  *
2566 // OBSOLETE  * If it doesn't, define your own routine.
2567 // OBSOLETE  */
2568 // OBSOLETE #define FETCH_CPROC_STATE(mth) mach3_cproc_state (mth)
2569 // OBSOLETE 
2570 // OBSOLETE int
2571 // OBSOLETE mach3_cproc_state (gdb_thread_t mthread)
2572 // OBSOLETE {
2573 // OBSOLETE   int context;
2574 // OBSOLETE 
2575 // OBSOLETE   if (!mthread || !mthread->cproc)
2576 // OBSOLETE     return -1;
2577 // OBSOLETE 
2578 // OBSOLETE   context = extract_signed_integer
2579 // OBSOLETE     (mthread->cproc->raw_cproc + CPROC_CONTEXT_OFFSET,
2580 // OBSOLETE      CPROC_CONTEXT_SIZE);
2581 // OBSOLETE   if (context == 0)
2582 // OBSOLETE     return -1;
2583 // OBSOLETE 
2584 // OBSOLETE   mthread->sp = context + MACHINE_CPROC_SP_OFFSET;
2585 // OBSOLETE 
2586 // OBSOLETE   if (mach3_read_inferior (context + MACHINE_CPROC_PC_OFFSET,
2587 // OBSOLETE                        &mthread->pc,
2588 // OBSOLETE                        sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2589 // OBSOLETE     {
2590 // OBSOLETE       warning ("Can't read cproc pc from inferior");
2591 // OBSOLETE       return -1;
2592 // OBSOLETE     }
2593 // OBSOLETE 
2594 // OBSOLETE   if (mach3_read_inferior (context + MACHINE_CPROC_FP_OFFSET,
2595 // OBSOLETE                        &mthread->fp,
2596 // OBSOLETE                        sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2597 // OBSOLETE     {
2598 // OBSOLETE       warning ("Can't read cproc fp from inferior");
2599 // OBSOLETE       return -1;
2600 // OBSOLETE     }
2601 // OBSOLETE 
2602 // OBSOLETE   return 0;
2603 // OBSOLETE }
2604 // OBSOLETE #endif /* FETCH_CPROC_STATE */
2605 // OBSOLETE \f
2606 // OBSOLETE 
2607 // OBSOLETE void
2608 // OBSOLETE thread_list_command (void)
2609 // OBSOLETE {
2610 // OBSOLETE   thread_basic_info_data_t ths;
2611 // OBSOLETE   int thread_count;
2612 // OBSOLETE   gdb_thread_t cprocs;
2613 // OBSOLETE   gdb_thread_t scan;
2614 // OBSOLETE   int index;
2615 // OBSOLETE   char *name;
2616 // OBSOLETE   char selected;
2617 // OBSOLETE   char *wired;
2618 // OBSOLETE   int infoCnt;
2619 // OBSOLETE   kern_return_t ret;
2620 // OBSOLETE   mach_port_t mid_or_port;
2621 // OBSOLETE   gdb_thread_t their_threads;
2622 // OBSOLETE   gdb_thread_t kthread;
2623 // OBSOLETE 
2624 // OBSOLETE   int neworder = 1;
2625 // OBSOLETE 
2626 // OBSOLETE   char *fmt = "There are %d kernel threads in task %d.\n";
2627 // OBSOLETE 
2628 // OBSOLETE   int tmid = map_port_name_to_mid (inferior_task, MACH_TYPE_TASK);
2629 // OBSOLETE 
2630 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
2631 // OBSOLETE 
2632 // OBSOLETE   thread_count = fetch_thread_info (inferior_task,
2633 // OBSOLETE                                 &their_threads);
2634 // OBSOLETE   if (thread_count == -1)
2635 // OBSOLETE     return;
2636 // OBSOLETE 
2637 // OBSOLETE   if (thread_count == 1)
2638 // OBSOLETE     fmt = "There is %d kernel thread in task %d.\n";
2639 // OBSOLETE 
2640 // OBSOLETE   printf_filtered (fmt, thread_count, tmid);
2641 // OBSOLETE 
2642 // OBSOLETE   puts_filtered (TL_HEADER);
2643 // OBSOLETE 
2644 // OBSOLETE   cprocs = get_cprocs ();
2645 // OBSOLETE 
2646 // OBSOLETE   map_cprocs_to_kernel_threads (cprocs, their_threads, thread_count);
2647 // OBSOLETE 
2648 // OBSOLETE   for (scan = cprocs; scan; scan = scan->next)
2649 // OBSOLETE     {
2650 // OBSOLETE       int mid;
2651 // OBSOLETE       char buf[10];
2652 // OBSOLETE       char slot[3];
2653 // OBSOLETE       int cproc_state =
2654 // OBSOLETE       extract_signed_integer
2655 // OBSOLETE       (scan->raw_cproc + CPROC_STATE_OFFSET, CPROC_STATE_SIZE);
2656 // OBSOLETE 
2657 // OBSOLETE       selected = ' ';
2658 // OBSOLETE 
2659 // OBSOLETE       /* a wired cproc? */
2660 // OBSOLETE       wired = (extract_address (scan->raw_cproc + CPROC_WIRED_OFFSET,
2661 // OBSOLETE                             CPROC_WIRED_SIZE)
2662 // OBSOLETE            ? "wired" : "");
2663 // OBSOLETE 
2664 // OBSOLETE       if (scan->reverse_map != -1)
2665 // OBSOLETE     kthread = (their_threads + scan->reverse_map);
2666 // OBSOLETE       else
2667 // OBSOLETE     kthread = NULL;
2668 // OBSOLETE 
2669 // OBSOLETE       if (kthread)
2670 // OBSOLETE     {
2671 // OBSOLETE       /* These cprocs have a kernel thread */
2672 // OBSOLETE 
2673 // OBSOLETE       mid = map_port_name_to_mid (kthread->name, MACH_TYPE_THREAD);
2674 // OBSOLETE 
2675 // OBSOLETE       infoCnt = THREAD_BASIC_INFO_COUNT;
2676 // OBSOLETE 
2677 // OBSOLETE       ret = thread_info (kthread->name,
2678 // OBSOLETE                          THREAD_BASIC_INFO,
2679 // OBSOLETE                          (thread_info_t) & ths,
2680 // OBSOLETE                          &infoCnt);
2681 // OBSOLETE 
2682 // OBSOLETE       if (ret != KERN_SUCCESS)
2683 // OBSOLETE         {
2684 // OBSOLETE           warning ("Unable to get basic info on thread %d : %s",
2685 // OBSOLETE                    mid,
2686 // OBSOLETE                    mach_error_string (ret));
2687 // OBSOLETE           continue;
2688 // OBSOLETE         }
2689 // OBSOLETE 
2690 // OBSOLETE       /* Who is the first to have more than 100 threads */
2691 // OBSOLETE       sprintf (slot, "%d", kthread->slotid % 100);
2692 // OBSOLETE 
2693 // OBSOLETE       if (kthread->name == current_thread)
2694 // OBSOLETE         selected = '*';
2695 // OBSOLETE 
2696 // OBSOLETE       if (ths.suspend_count)
2697 // OBSOLETE         sprintf (buf, "%d", ths.suspend_count);
2698 // OBSOLETE       else
2699 // OBSOLETE         buf[0] = '\000';
2700 // OBSOLETE 
2701 // OBSOLETE #if 0
2702 // OBSOLETE       if (ths.flags & TH_FLAGS_SWAPPED)
2703 // OBSOLETE         strcat (buf, "S");
2704 // OBSOLETE #endif
2705 // OBSOLETE 
2706 // OBSOLETE       if (ths.flags & TH_FLAGS_IDLE)
2707 // OBSOLETE         strcat (buf, "I");
2708 // OBSOLETE 
2709 // OBSOLETE       printf_filtered (TL_FORMAT,
2710 // OBSOLETE                        slot,
2711 // OBSOLETE                        mid,
2712 // OBSOLETE                        selected,
2713 // OBSOLETE                        get_thread_name (scan, kthread->slotid),
2714 // OBSOLETE                        kthread->in_emulator ? "E" : "",
2715 // OBSOLETE                        translate_state (ths.run_state),
2716 // OBSOLETE                        buf,
2717 // OBSOLETE                        translate_cstate (cproc_state),
2718 // OBSOLETE                        wired);
2719 // OBSOLETE       print_tl_address (gdb_stdout, kthread->pc);
2720 // OBSOLETE     }
2721 // OBSOLETE       else
2722 // OBSOLETE     {
2723 // OBSOLETE       /* These cprocs don't have a kernel thread.
2724 // OBSOLETE        * find out the calling frame with 
2725 // OBSOLETE        * FETCH_CPROC_STATE.
2726 // OBSOLETE        */
2727 // OBSOLETE 
2728 // OBSOLETE       struct gdb_thread state;
2729 // OBSOLETE 
2730 // OBSOLETE #if 0
2731 // OBSOLETE       /* jtv -> emcmanus: why do you want this here? */
2732 // OBSOLETE       if (scan->incarnation == NULL)
2733 // OBSOLETE         continue;           /* EMcM */
2734 // OBSOLETE #endif
2735 // OBSOLETE 
2736 // OBSOLETE       printf_filtered (TL_FORMAT,
2737 // OBSOLETE                        "-",
2738 // OBSOLETE                        -neworder,   /* Pseudo MID */
2739 // OBSOLETE                        selected,
2740 // OBSOLETE                        get_thread_name (scan, -neworder),
2741 // OBSOLETE                        "",
2742 // OBSOLETE                        "-", /* kernel state */
2743 // OBSOLETE                        "",
2744 // OBSOLETE                        translate_cstate (cproc_state),
2745 // OBSOLETE                        "");
2746 // OBSOLETE       state.cproc = scan;
2747 // OBSOLETE 
2748 // OBSOLETE       if (FETCH_CPROC_STATE (&state) == -1)
2749 // OBSOLETE         puts_filtered ("???");
2750 // OBSOLETE       else
2751 // OBSOLETE         print_tl_address (gdb_stdout, state.pc);
2752 // OBSOLETE 
2753 // OBSOLETE       neworder++;
2754 // OBSOLETE     }
2755 // OBSOLETE       puts_filtered ("\n");
2756 // OBSOLETE     }
2757 // OBSOLETE 
2758 // OBSOLETE   /* Scan for kernel threads without cprocs */
2759 // OBSOLETE   for (index = 0; index < thread_count; index++)
2760 // OBSOLETE     {
2761 // OBSOLETE       if (!their_threads[index].cproc)
2762 // OBSOLETE     {
2763 // OBSOLETE       int mid;
2764 // OBSOLETE 
2765 // OBSOLETE       char buf[10];
2766 // OBSOLETE       char slot[3];
2767 // OBSOLETE 
2768 // OBSOLETE       mach_port_t name = their_threads[index].name;
2769 // OBSOLETE 
2770 // OBSOLETE       mid = map_port_name_to_mid (name, MACH_TYPE_THREAD);
2771 // OBSOLETE 
2772 // OBSOLETE       infoCnt = THREAD_BASIC_INFO_COUNT;
2773 // OBSOLETE 
2774 // OBSOLETE       ret = thread_info (name,
2775 // OBSOLETE                          THREAD_BASIC_INFO,
2776 // OBSOLETE                          (thread_info_t) & ths,
2777 // OBSOLETE                          &infoCnt);
2778 // OBSOLETE 
2779 // OBSOLETE       if (ret != KERN_SUCCESS)
2780 // OBSOLETE         {
2781 // OBSOLETE           warning ("Unable to get basic info on thread %d : %s",
2782 // OBSOLETE                    mid,
2783 // OBSOLETE                    mach_error_string (ret));
2784 // OBSOLETE           continue;
2785 // OBSOLETE         }
2786 // OBSOLETE 
2787 // OBSOLETE       sprintf (slot, "%d", index % 100);
2788 // OBSOLETE 
2789 // OBSOLETE       if (name == current_thread)
2790 // OBSOLETE         selected = '*';
2791 // OBSOLETE       else
2792 // OBSOLETE         selected = ' ';
2793 // OBSOLETE 
2794 // OBSOLETE       if (ths.suspend_count)
2795 // OBSOLETE         sprintf (buf, "%d", ths.suspend_count);
2796 // OBSOLETE       else
2797 // OBSOLETE         buf[0] = '\000';
2798 // OBSOLETE 
2799 // OBSOLETE #if 0
2800 // OBSOLETE       if (ths.flags & TH_FLAGS_SWAPPED)
2801 // OBSOLETE         strcat (buf, "S");
2802 // OBSOLETE #endif
2803 // OBSOLETE 
2804 // OBSOLETE       if (ths.flags & TH_FLAGS_IDLE)
2805 // OBSOLETE         strcat (buf, "I");
2806 // OBSOLETE 
2807 // OBSOLETE       printf_filtered (TL_FORMAT,
2808 // OBSOLETE                        slot,
2809 // OBSOLETE                        mid,
2810 // OBSOLETE                        selected,
2811 // OBSOLETE                        get_thread_name (NULL, index),
2812 // OBSOLETE                        their_threads[index].in_emulator ? "E" : "",
2813 // OBSOLETE                        translate_state (ths.run_state),
2814 // OBSOLETE                        buf,
2815 // OBSOLETE                        "",  /* No cproc state */
2816 // OBSOLETE                        ""); /* Can't be wired */
2817 // OBSOLETE       print_tl_address (gdb_stdout, their_threads[index].pc);
2818 // OBSOLETE       puts_filtered ("\n");
2819 // OBSOLETE     }
2820 // OBSOLETE     }
2821 // OBSOLETE 
2822 // OBSOLETE   obstack_free (cproc_obstack, 0);
2823 // OBSOLETE   obstack_init (cproc_obstack);
2824 // OBSOLETE }
2825 // OBSOLETE \f
2826 // OBSOLETE void
2827 // OBSOLETE thread_select_command (char *args, int from_tty)
2828 // OBSOLETE {
2829 // OBSOLETE   int mid;
2830 // OBSOLETE   thread_array_t thread_list;
2831 // OBSOLETE   int thread_count;
2832 // OBSOLETE   kern_return_t ret;
2833 // OBSOLETE   int is_slot = 0;
2834 // OBSOLETE 
2835 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
2836 // OBSOLETE 
2837 // OBSOLETE   if (!args)
2838 // OBSOLETE     error_no_arg ("MID or @SLOTNUMBER to specify a thread to select");
2839 // OBSOLETE 
2840 // OBSOLETE   while (*args == ' ' || *args == '\t')
2841 // OBSOLETE     args++;
2842 // OBSOLETE 
2843 // OBSOLETE   if (*args == '@')
2844 // OBSOLETE     {
2845 // OBSOLETE       is_slot++;
2846 // OBSOLETE       args++;
2847 // OBSOLETE     }
2848 // OBSOLETE 
2849 // OBSOLETE   mid = atoi (args);
2850 // OBSOLETE 
2851 // OBSOLETE   if (mid == 0)
2852 // OBSOLETE     if (!is_slot || *args != '0')   /* Rudimentary checks */
2853 // OBSOLETE       error ("You must select threads by MID or @SLOTNUMBER");
2854 // OBSOLETE 
2855 // OBSOLETE   if (select_thread (inferior_task, mid, is_slot ? 2 : 1) != KERN_SUCCESS)
2856 // OBSOLETE     return;
2857 // OBSOLETE 
2858 // OBSOLETE   if (from_tty)
2859 // OBSOLETE     printf_filtered ("Thread %d selected\n",
2860 // OBSOLETE                  is_slot ? map_port_name_to_mid (current_thread,
2861 // OBSOLETE                                                MACH_TYPE_THREAD) : mid);
2862 // OBSOLETE }
2863 // OBSOLETE \f
2864 // OBSOLETE thread_trace (mach_port_t thread, boolean_t set)
2865 // OBSOLETE {
2866 // OBSOLETE   int flavor = TRACE_FLAVOR;
2867 // OBSOLETE   unsigned int stateCnt = TRACE_FLAVOR_SIZE;
2868 // OBSOLETE   kern_return_t ret;
2869 // OBSOLETE   thread_state_data_t state;
2870 // OBSOLETE 
2871 // OBSOLETE   if (!MACH_PORT_VALID (thread))
2872 // OBSOLETE     {
2873 // OBSOLETE       warning ("thread_trace: invalid thread");
2874 // OBSOLETE       return;
2875 // OBSOLETE     }
2876 // OBSOLETE 
2877 // OBSOLETE   if (must_suspend_thread)
2878 // OBSOLETE     setup_thread (thread, 1);
2879 // OBSOLETE 
2880 // OBSOLETE   ret = thread_get_state (thread, flavor, state, &stateCnt);
2881 // OBSOLETE   CHK ("thread_trace: error reading thread state", ret);
2882 // OBSOLETE 
2883 // OBSOLETE   if (set)
2884 // OBSOLETE     {
2885 // OBSOLETE       TRACE_SET (thread, state);
2886 // OBSOLETE     }
2887 // OBSOLETE   else
2888 // OBSOLETE     {
2889 // OBSOLETE       if (!TRACE_CLEAR (thread, state))
2890 // OBSOLETE     {
2891 // OBSOLETE       if (must_suspend_thread)
2892 // OBSOLETE         setup_thread (thread, 0);
2893 // OBSOLETE       return;
2894 // OBSOLETE     }
2895 // OBSOLETE     }
2896 // OBSOLETE 
2897 // OBSOLETE   ret = thread_set_state (thread, flavor, state, stateCnt);
2898 // OBSOLETE   CHK ("thread_trace: error writing thread state", ret);
2899 // OBSOLETE   if (must_suspend_thread)
2900 // OBSOLETE     setup_thread (thread, 0);
2901 // OBSOLETE }
2902 // OBSOLETE 
2903 // OBSOLETE #ifdef      FLUSH_INFERIOR_CACHE
2904 // OBSOLETE 
2905 // OBSOLETE /* When over-writing code on some machines the I-Cache must be flushed
2906 // OBSOLETE    explicitly, because it is not kept coherent by the lazy hardware.
2907 // OBSOLETE    This definitely includes breakpoints, for instance, or else we
2908 // OBSOLETE    end up looping in mysterious Bpt traps */
2909 // OBSOLETE 
2910 // OBSOLETE flush_inferior_icache (CORE_ADDR pc, int amount)
2911 // OBSOLETE {
2912 // OBSOLETE   vm_machine_attribute_val_t flush = MATTR_VAL_ICACHE_FLUSH;
2913 // OBSOLETE   kern_return_t ret;
2914 // OBSOLETE 
2915 // OBSOLETE   ret = vm_machine_attribute (inferior_task,
2916 // OBSOLETE                           pc,
2917 // OBSOLETE                           amount,
2918 // OBSOLETE                           MATTR_CACHE,
2919 // OBSOLETE                           &flush);
2920 // OBSOLETE   if (ret != KERN_SUCCESS)
2921 // OBSOLETE     warning ("Error flushing inferior's cache : %s",
2922 // OBSOLETE          mach_error_string (ret));
2923 // OBSOLETE }
2924 // OBSOLETE #endif /* FLUSH_INFERIOR_CACHE */
2925 // OBSOLETE \f
2926 // OBSOLETE 
2927 // OBSOLETE static
2928 // OBSOLETE suspend_all_threads (int from_tty)
2929 // OBSOLETE {
2930 // OBSOLETE   kern_return_t ret;
2931 // OBSOLETE   thread_array_t thread_list;
2932 // OBSOLETE   int thread_count, index;
2933 // OBSOLETE   int infoCnt;
2934 // OBSOLETE   thread_basic_info_data_t th_info;
2935 // OBSOLETE 
2936 // OBSOLETE 
2937 // OBSOLETE   ret = task_threads (inferior_task, &thread_list, &thread_count);
2938 // OBSOLETE   if (ret != KERN_SUCCESS)
2939 // OBSOLETE     {
2940 // OBSOLETE       warning ("Could not suspend inferior threads.");
2941 // OBSOLETE       m3_kill_inferior ();
2942 // OBSOLETE       throw_exception (RETURN_ERROR);
2943 // OBSOLETE     }
2944 // OBSOLETE 
2945 // OBSOLETE   for (index = 0; index < thread_count; index++)
2946 // OBSOLETE     {
2947 // OBSOLETE       int mid;
2948 // OBSOLETE 
2949 // OBSOLETE       mid = map_port_name_to_mid (thread_list[index],
2950 // OBSOLETE                               MACH_TYPE_THREAD);
2951 // OBSOLETE 
2952 // OBSOLETE       ret = thread_suspend (thread_list[index]);
2953 // OBSOLETE 
2954 // OBSOLETE       if (ret != KERN_SUCCESS)
2955 // OBSOLETE     warning ("Error trying to suspend thread %d : %s",
2956 // OBSOLETE              mid, mach_error_string (ret));
2957 // OBSOLETE 
2958 // OBSOLETE       if (from_tty)
2959 // OBSOLETE     {
2960 // OBSOLETE       infoCnt = THREAD_BASIC_INFO_COUNT;
2961 // OBSOLETE       ret = thread_info (thread_list[index],
2962 // OBSOLETE                          THREAD_BASIC_INFO,
2963 // OBSOLETE                          (thread_info_t) & th_info,
2964 // OBSOLETE                          &infoCnt);
2965 // OBSOLETE       CHK ("suspend can't get thread info", ret);
2966 // OBSOLETE 
2967 // OBSOLETE       warning ("Thread %d suspend count is %d",
2968 // OBSOLETE                mid, th_info.suspend_count);
2969 // OBSOLETE     }
2970 // OBSOLETE     }
2971 // OBSOLETE 
2972 // OBSOLETE   consume_send_rights (thread_list, thread_count);
2973 // OBSOLETE   ret = vm_deallocate (mach_task_self (),
2974 // OBSOLETE                    (vm_address_t) thread_list,
2975 // OBSOLETE                    (thread_count * sizeof (int)));
2976 // OBSOLETE   CHK ("Error trying to deallocate thread list", ret);
2977 // OBSOLETE }
2978 // OBSOLETE 
2979 // OBSOLETE void
2980 // OBSOLETE thread_suspend_command (char *args, int from_tty)
2981 // OBSOLETE {
2982 // OBSOLETE   kern_return_t ret;
2983 // OBSOLETE   int mid;
2984 // OBSOLETE   mach_port_t saved_thread;
2985 // OBSOLETE   int infoCnt;
2986 // OBSOLETE   thread_basic_info_data_t th_info;
2987 // OBSOLETE 
2988 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
2989 // OBSOLETE 
2990 // OBSOLETE   if (!strcasecmp (args, "all"))
2991 // OBSOLETE     {
2992 // OBSOLETE       suspend_all_threads (from_tty);
2993 // OBSOLETE       return;
2994 // OBSOLETE     }
2995 // OBSOLETE 
2996 // OBSOLETE   saved_thread = current_thread;
2997 // OBSOLETE 
2998 // OBSOLETE   mid = parse_thread_id (args, 0, 0);
2999 // OBSOLETE 
3000 // OBSOLETE   if (mid < 0)
3001 // OBSOLETE     error ("You can suspend only existing kernel threads with MID or @SLOTNUMBER");
3002 // OBSOLETE 
3003 // OBSOLETE   if (mid == 0)
3004 // OBSOLETE     mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
3005 // OBSOLETE   else if (select_thread (inferior_task, mid, 0) != KERN_SUCCESS)
3006 // OBSOLETE     {
3007 // OBSOLETE       if (current_thread)
3008 // OBSOLETE     current_thread = saved_thread;
3009 // OBSOLETE       error ("Could not select thread %d", mid);
3010 // OBSOLETE     }
3011 // OBSOLETE 
3012 // OBSOLETE   ret = thread_suspend (current_thread);
3013 // OBSOLETE   if (ret != KERN_SUCCESS)
3014 // OBSOLETE     warning ("thread_suspend failed : %s",
3015 // OBSOLETE          mach_error_string (ret));
3016 // OBSOLETE 
3017 // OBSOLETE   infoCnt = THREAD_BASIC_INFO_COUNT;
3018 // OBSOLETE   ret = thread_info (current_thread,
3019 // OBSOLETE                  THREAD_BASIC_INFO,
3020 // OBSOLETE                  (thread_info_t) & th_info,
3021 // OBSOLETE                  &infoCnt);
3022 // OBSOLETE   CHK ("suspend can't get thread info", ret);
3023 // OBSOLETE 
3024 // OBSOLETE   warning ("Thread %d suspend count is %d", mid, th_info.suspend_count);
3025 // OBSOLETE 
3026 // OBSOLETE   current_thread = saved_thread;
3027 // OBSOLETE }
3028 // OBSOLETE 
3029 // OBSOLETE resume_all_threads (int from_tty)
3030 // OBSOLETE {
3031 // OBSOLETE   kern_return_t ret;
3032 // OBSOLETE   thread_array_t thread_list;
3033 // OBSOLETE   int thread_count, index;
3034 // OBSOLETE   int mid;
3035 // OBSOLETE   int infoCnt;
3036 // OBSOLETE   thread_basic_info_data_t th_info;
3037 // OBSOLETE 
3038 // OBSOLETE   ret = task_threads (inferior_task, &thread_list, &thread_count);
3039 // OBSOLETE   if (ret != KERN_SUCCESS)
3040 // OBSOLETE     {
3041 // OBSOLETE       m3_kill_inferior ();
3042 // OBSOLETE       error ("task_threads", mach_error_string (ret));
3043 // OBSOLETE     }
3044 // OBSOLETE 
3045 // OBSOLETE   for (index = 0; index < thread_count; index++)
3046 // OBSOLETE     {
3047 // OBSOLETE       infoCnt = THREAD_BASIC_INFO_COUNT;
3048 // OBSOLETE       ret = thread_info (thread_list[index],
3049 // OBSOLETE                      THREAD_BASIC_INFO,
3050 // OBSOLETE                      (thread_info_t) & th_info,
3051 // OBSOLETE                      &infoCnt);
3052 // OBSOLETE       CHK ("resume_all can't get thread info", ret);
3053 // OBSOLETE 
3054 // OBSOLETE       mid = map_port_name_to_mid (thread_list[index],
3055 // OBSOLETE                               MACH_TYPE_THREAD);
3056 // OBSOLETE 
3057 // OBSOLETE       if (!th_info.suspend_count)
3058 // OBSOLETE     {
3059 // OBSOLETE       if (mid != -1 && from_tty)
3060 // OBSOLETE         warning ("Thread %d is not suspended", mid);
3061 // OBSOLETE       continue;
3062 // OBSOLETE     }
3063 // OBSOLETE 
3064 // OBSOLETE       ret = thread_resume (thread_list[index]);
3065 // OBSOLETE 
3066 // OBSOLETE       if (ret != KERN_SUCCESS)
3067 // OBSOLETE     warning ("Error trying to resume thread %d : %s",
3068 // OBSOLETE              mid, mach_error_string (ret));
3069 // OBSOLETE       else if (mid != -1 && from_tty)
3070 // OBSOLETE     warning ("Thread %d suspend count is %d",
3071 // OBSOLETE              mid, --th_info.suspend_count);
3072 // OBSOLETE     }
3073 // OBSOLETE 
3074 // OBSOLETE   consume_send_rights (thread_list, thread_count);
3075 // OBSOLETE   ret = vm_deallocate (mach_task_self (),
3076 // OBSOLETE                    (vm_address_t) thread_list,
3077 // OBSOLETE                    (thread_count * sizeof (int)));
3078 // OBSOLETE   CHK ("Error trying to deallocate thread list", ret);
3079 // OBSOLETE }
3080 // OBSOLETE 
3081 // OBSOLETE void
3082 // OBSOLETE thread_resume_command (char *args, int from_tty)
3083 // OBSOLETE {
3084 // OBSOLETE   int mid;
3085 // OBSOLETE   mach_port_t saved_thread;
3086 // OBSOLETE   kern_return_t ret;
3087 // OBSOLETE   thread_basic_info_data_t th_info;
3088 // OBSOLETE   int infoCnt = THREAD_BASIC_INFO_COUNT;
3089 // OBSOLETE 
3090 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
3091 // OBSOLETE 
3092 // OBSOLETE   if (!strcasecmp (args, "all"))
3093 // OBSOLETE     {
3094 // OBSOLETE       resume_all_threads (from_tty);
3095 // OBSOLETE       return;
3096 // OBSOLETE     }
3097 // OBSOLETE 
3098 // OBSOLETE   saved_thread = current_thread;
3099 // OBSOLETE 
3100 // OBSOLETE   mid = parse_thread_id (args, 0, 0);
3101 // OBSOLETE 
3102 // OBSOLETE   if (mid < 0)
3103 // OBSOLETE     error ("You can resume only existing kernel threads with MID or @SLOTNUMBER");
3104 // OBSOLETE 
3105 // OBSOLETE   if (mid == 0)
3106 // OBSOLETE     mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
3107 // OBSOLETE   else if (select_thread (inferior_task, mid, 0) != KERN_SUCCESS)
3108 // OBSOLETE     {
3109 // OBSOLETE       if (current_thread)
3110 // OBSOLETE     current_thread = saved_thread;
3111 // OBSOLETE       throw_exception (RETURN_ERROR);
3112 // OBSOLETE     }
3113 // OBSOLETE 
3114 // OBSOLETE   ret = thread_info (current_thread,
3115 // OBSOLETE                  THREAD_BASIC_INFO,
3116 // OBSOLETE                  (thread_info_t) & th_info,
3117 // OBSOLETE                  &infoCnt);
3118 // OBSOLETE   CHK ("resume can't get thread info", ret);
3119 // OBSOLETE 
3120 // OBSOLETE   if (!th_info.suspend_count)
3121 // OBSOLETE     {
3122 // OBSOLETE       warning ("Thread %d is not suspended", mid);
3123 // OBSOLETE       goto out;
3124 // OBSOLETE     }
3125 // OBSOLETE 
3126 // OBSOLETE   ret = thread_resume (current_thread);
3127 // OBSOLETE   if (ret != KERN_SUCCESS)
3128 // OBSOLETE     warning ("thread_resume failed : %s",
3129 // OBSOLETE          mach_error_string (ret));
3130 // OBSOLETE   else
3131 // OBSOLETE     {
3132 // OBSOLETE       th_info.suspend_count--;
3133 // OBSOLETE       warning ("Thread %d suspend count is %d", mid, th_info.suspend_count);
3134 // OBSOLETE     }
3135 // OBSOLETE 
3136 // OBSOLETE out:
3137 // OBSOLETE   current_thread = saved_thread;
3138 // OBSOLETE }
3139 // OBSOLETE 
3140 // OBSOLETE void
3141 // OBSOLETE thread_kill_command (char *args, int from_tty)
3142 // OBSOLETE {
3143 // OBSOLETE   int mid;
3144 // OBSOLETE   kern_return_t ret;
3145 // OBSOLETE   int thread_count;
3146 // OBSOLETE   thread_array_t thread_table;
3147 // OBSOLETE   int index;
3148 // OBSOLETE   mach_port_t thread_to_kill = MACH_PORT_NULL;
3149 // OBSOLETE 
3150 // OBSOLETE 
3151 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
3152 // OBSOLETE 
3153 // OBSOLETE   if (!args)
3154 // OBSOLETE     error_no_arg ("thread mid to kill from the inferior task");
3155 // OBSOLETE 
3156 // OBSOLETE   mid = parse_thread_id (args, 0, 0);
3157 // OBSOLETE 
3158 // OBSOLETE   if (mid < 0)
3159 // OBSOLETE     error ("You can kill only existing kernel threads with MID or @SLOTNUMBER");
3160 // OBSOLETE 
3161 // OBSOLETE   if (mid)
3162 // OBSOLETE     {
3163 // OBSOLETE       ret = machid_mach_port (mid_server, mid_auth, mid, &thread_to_kill);
3164 // OBSOLETE       CHK ("thread_kill_command: machid_mach_port map failed", ret);
3165 // OBSOLETE     }
3166 // OBSOLETE   else
3167 // OBSOLETE     mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
3168 // OBSOLETE 
3169 // OBSOLETE   /* Don't allow gdb to kill *any* thread in the system. Use mkill program for that */
3170 // OBSOLETE   ret = task_threads (inferior_task, &thread_table, &thread_count);
3171 // OBSOLETE   CHK ("Error getting inferior's thread list", ret);
3172 // OBSOLETE 
3173 // OBSOLETE   if (thread_to_kill == current_thread)
3174 // OBSOLETE     {
3175 // OBSOLETE       ret = thread_terminate (thread_to_kill);
3176 // OBSOLETE       CHK ("Thread could not be terminated", ret);
3177 // OBSOLETE 
3178 // OBSOLETE       if (select_thread (inferior_task, 0, 1) != KERN_SUCCESS)
3179 // OBSOLETE     warning ("Last thread was killed, use \"kill\" command to kill task");
3180 // OBSOLETE     }
3181 // OBSOLETE   else
3182 // OBSOLETE     for (index = 0; index < thread_count; index++)
3183 // OBSOLETE       if (thread_table[index] == thread_to_kill)
3184 // OBSOLETE     {
3185 // OBSOLETE       ret = thread_terminate (thread_to_kill);
3186 // OBSOLETE       CHK ("Thread could not be terminated", ret);
3187 // OBSOLETE     }
3188 // OBSOLETE 
3189 // OBSOLETE   if (thread_count > 1)
3190 // OBSOLETE     consume_send_rights (thread_table, thread_count);
3191 // OBSOLETE 
3192 // OBSOLETE   ret = vm_deallocate (mach_task_self (), (vm_address_t) thread_table,
3193 // OBSOLETE                    (thread_count * sizeof (mach_port_t)));
3194 // OBSOLETE   CHK ("Error trying to deallocate thread list", ret);
3195 // OBSOLETE 
3196 // OBSOLETE   warning ("Thread %d killed", mid);
3197 // OBSOLETE }
3198 // OBSOLETE \f
3199 // OBSOLETE 
3200 // OBSOLETE /* Task specific commands; add more if you like */
3201 // OBSOLETE 
3202 // OBSOLETE void
3203 // OBSOLETE task_resume_command (char *args, int from_tty)
3204 // OBSOLETE {
3205 // OBSOLETE   kern_return_t ret;
3206 // OBSOLETE   task_basic_info_data_t ta_info;
3207 // OBSOLETE   int infoCnt = TASK_BASIC_INFO_COUNT;
3208 // OBSOLETE   int mid = map_port_name_to_mid (inferior_task, MACH_TYPE_TASK);
3209 // OBSOLETE 
3210 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
3211 // OBSOLETE 
3212 // OBSOLETE   /* Would be trivial to change, but is it desirable? */
3213 // OBSOLETE   if (args)
3214 // OBSOLETE     error ("Currently gdb can resume only it's inferior task");
3215 // OBSOLETE 
3216 // OBSOLETE   ret = task_info (inferior_task,
3217 // OBSOLETE                TASK_BASIC_INFO,
3218 // OBSOLETE                (task_info_t) & ta_info,
3219 // OBSOLETE                &infoCnt);
3220 // OBSOLETE   CHK ("task_resume_command: task_info failed", ret);
3221 // OBSOLETE 
3222 // OBSOLETE   if (ta_info.suspend_count == 0)
3223 // OBSOLETE     error ("Inferior task %d is not suspended", mid);
3224 // OBSOLETE   else if (ta_info.suspend_count == 1 &&
3225 // OBSOLETE        from_tty &&
3226 // OBSOLETE     !query ("Suspend count is now 1. Do you know what you are doing? "))
3227 // OBSOLETE     error ("Task not resumed");
3228 // OBSOLETE 
3229 // OBSOLETE   ret = task_resume (inferior_task);
3230 // OBSOLETE   CHK ("task_resume_command: task_resume", ret);
3231 // OBSOLETE 
3232 // OBSOLETE   if (ta_info.suspend_count == 1)
3233 // OBSOLETE     {
3234 // OBSOLETE       warning ("Inferior task %d is no longer suspended", mid);
3235 // OBSOLETE       must_suspend_thread = 1;
3236 // OBSOLETE       /* @@ This is not complete: Registers change all the time when not
3237 // OBSOLETE          suspended! */
3238 // OBSOLETE       registers_changed ();
3239 // OBSOLETE     }
3240 // OBSOLETE   else
3241 // OBSOLETE     warning ("Inferior task %d suspend count is now %d",
3242 // OBSOLETE          mid, ta_info.suspend_count - 1);
3243 // OBSOLETE }
3244 // OBSOLETE 
3245 // OBSOLETE 
3246 // OBSOLETE void
3247 // OBSOLETE task_suspend_command (char *args, int from_tty)
3248 // OBSOLETE {
3249 // OBSOLETE   kern_return_t ret;
3250 // OBSOLETE   task_basic_info_data_t ta_info;
3251 // OBSOLETE   int infoCnt = TASK_BASIC_INFO_COUNT;
3252 // OBSOLETE   int mid = map_port_name_to_mid (inferior_task, MACH_TYPE_TASK);
3253 // OBSOLETE 
3254 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
3255 // OBSOLETE 
3256 // OBSOLETE   /* Would be trivial to change, but is it desirable? */
3257 // OBSOLETE   if (args)
3258 // OBSOLETE     error ("Currently gdb can suspend only it's inferior task");
3259 // OBSOLETE 
3260 // OBSOLETE   ret = task_suspend (inferior_task);
3261 // OBSOLETE   CHK ("task_suspend_command: task_suspend", ret);
3262 // OBSOLETE 
3263 // OBSOLETE   must_suspend_thread = 0;
3264 // OBSOLETE 
3265 // OBSOLETE   ret = task_info (inferior_task,
3266 // OBSOLETE                TASK_BASIC_INFO,
3267 // OBSOLETE                (task_info_t) & ta_info,
3268 // OBSOLETE                &infoCnt);
3269 // OBSOLETE   CHK ("task_suspend_command: task_info failed", ret);
3270 // OBSOLETE 
3271 // OBSOLETE   warning ("Inferior task %d suspend count is now %d",
3272 // OBSOLETE        mid, ta_info.suspend_count);
3273 // OBSOLETE }
3274 // OBSOLETE 
3275 // OBSOLETE static char *
3276 // OBSOLETE get_size (int bytes)
3277 // OBSOLETE {
3278 // OBSOLETE   static char size[30];
3279 // OBSOLETE   int zz = bytes / 1024;
3280 // OBSOLETE 
3281 // OBSOLETE   if (zz / 1024)
3282 // OBSOLETE     sprintf (size, "%-2.1f M", ((float) bytes) / (1024.0 * 1024.0));
3283 // OBSOLETE   else
3284 // OBSOLETE     sprintf (size, "%d K", zz);
3285 // OBSOLETE 
3286 // OBSOLETE   return size;
3287 // OBSOLETE }
3288 // OBSOLETE 
3289 // OBSOLETE /* Does this require the target task to be suspended?? I don't think so. */
3290 // OBSOLETE void
3291 // OBSOLETE task_info_command (char *args, int from_tty)
3292 // OBSOLETE {
3293 // OBSOLETE   int mid = -5;
3294 // OBSOLETE   mach_port_t task;
3295 // OBSOLETE   kern_return_t ret;
3296 // OBSOLETE   task_basic_info_data_t ta_info;
3297 // OBSOLETE   int infoCnt = TASK_BASIC_INFO_COUNT;
3298 // OBSOLETE   int page_size = round_page (1);
3299 // OBSOLETE   int thread_count = 0;
3300 // OBSOLETE 
3301 // OBSOLETE   if (MACH_PORT_VALID (inferior_task))
3302 // OBSOLETE     mid = map_port_name_to_mid (inferior_task,
3303 // OBSOLETE                             MACH_TYPE_TASK);
3304 // OBSOLETE 
3305 // OBSOLETE   task = inferior_task;
3306 // OBSOLETE 
3307 // OBSOLETE   if (args)
3308 // OBSOLETE     {
3309 // OBSOLETE       int tmid = atoi (args);
3310 // OBSOLETE 
3311 // OBSOLETE       if (tmid <= 0)
3312 // OBSOLETE     error ("Invalid mid %d for task info", tmid);
3313 // OBSOLETE 
3314 // OBSOLETE       if (tmid != mid)
3315 // OBSOLETE     {
3316 // OBSOLETE       mid = tmid;
3317 // OBSOLETE       ret = machid_mach_port (mid_server, mid_auth, tmid, &task);
3318 // OBSOLETE       CHK ("task_info_command: machid_mach_port map failed", ret);
3319 // OBSOLETE     }
3320 // OBSOLETE     }
3321 // OBSOLETE 
3322 // OBSOLETE   if (mid < 0)
3323 // OBSOLETE     error ("You have to give the task MID as an argument");
3324 // OBSOLETE 
3325 // OBSOLETE   ret = task_info (task,
3326 // OBSOLETE                TASK_BASIC_INFO,
3327 // OBSOLETE                (task_info_t) & ta_info,
3328 // OBSOLETE                &infoCnt);
3329 // OBSOLETE   CHK ("task_info_command: task_info failed", ret);
3330 // OBSOLETE 
3331 // OBSOLETE   printf_filtered ("\nTask info for task %d:\n\n", mid);
3332 // OBSOLETE   printf_filtered (" Suspend count : %d\n", ta_info.suspend_count);
3333 // OBSOLETE   printf_filtered (" Base priority : %d\n", ta_info.base_priority);
3334 // OBSOLETE   printf_filtered (" Virtual size  : %s\n", get_size (ta_info.virtual_size));
3335 // OBSOLETE   printf_filtered (" Resident size : %s\n", get_size (ta_info.resident_size));
3336 // OBSOLETE 
3337 // OBSOLETE   {
3338 // OBSOLETE     thread_array_t thread_list;
3339 // OBSOLETE 
3340 // OBSOLETE     ret = task_threads (task, &thread_list, &thread_count);
3341 // OBSOLETE     CHK ("task_info_command: task_threads", ret);
3342 // OBSOLETE 
3343 // OBSOLETE     printf_filtered (" Thread count  : %d\n", thread_count);
3344 // OBSOLETE 
3345 // OBSOLETE     consume_send_rights (thread_list, thread_count);
3346 // OBSOLETE     ret = vm_deallocate (mach_task_self (),
3347 // OBSOLETE                      (vm_address_t) thread_list,
3348 // OBSOLETE                      (thread_count * sizeof (int)));
3349 // OBSOLETE     CHK ("Error trying to deallocate thread list", ret);
3350 // OBSOLETE   }
3351 // OBSOLETE   if (have_emulator_p (task))
3352 // OBSOLETE     printf_filtered (" Emulator at   : 0x%x..0x%x\n",
3353 // OBSOLETE                  EMULATOR_BASE, EMULATOR_END);
3354 // OBSOLETE   else
3355 // OBSOLETE     printf_filtered (" No emulator.\n");
3356 // OBSOLETE 
3357 // OBSOLETE   if (thread_count && task == inferior_task)
3358 // OBSOLETE     printf_filtered ("\nUse the \"thread list\" command to see the threads\n");
3359 // OBSOLETE }
3360 // OBSOLETE \f
3361 // OBSOLETE /* You may either FORWARD the exception to the inferior, or KEEP
3362 // OBSOLETE  * it and return to GDB command level.
3363 // OBSOLETE  *
3364 // OBSOLETE  * exception mid [ forward | keep ]
3365 // OBSOLETE  */
3366 // OBSOLETE 
3367 // OBSOLETE static void
3368 // OBSOLETE exception_command (char *args, int from_tty)
3369 // OBSOLETE {
3370 // OBSOLETE   char *scan = args;
3371 // OBSOLETE   int exception;
3372 // OBSOLETE   int len;
3373 // OBSOLETE 
3374 // OBSOLETE   if (!args)
3375 // OBSOLETE     error_no_arg ("exception number action");
3376 // OBSOLETE 
3377 // OBSOLETE   while (*scan == ' ' || *scan == '\t')
3378 // OBSOLETE     scan++;
3379 // OBSOLETE 
3380 // OBSOLETE   if ('0' <= *scan && *scan <= '9')
3381 // OBSOLETE     while ('0' <= *scan && *scan <= '9')
3382 // OBSOLETE       scan++;
3383 // OBSOLETE   else
3384 // OBSOLETE     error ("exception number action");
3385 // OBSOLETE 
3386 // OBSOLETE   exception = atoi (args);
3387 // OBSOLETE   if (exception <= 0 || exception > MAX_EXCEPTION)
3388 // OBSOLETE     error ("Allowed exception numbers are in range 1..%d",
3389 // OBSOLETE        MAX_EXCEPTION);
3390 // OBSOLETE 
3391 // OBSOLETE   if (*scan != ' ' && *scan != '\t')
3392 // OBSOLETE     error ("exception number must be followed by a space");
3393 // OBSOLETE   else
3394 // OBSOLETE     while (*scan == ' ' || *scan == '\t')
3395 // OBSOLETE       scan++;
3396 // OBSOLETE 
3397 // OBSOLETE   args = scan;
3398 // OBSOLETE   len = 0;
3399 // OBSOLETE   while (*scan)
3400 // OBSOLETE     {
3401 // OBSOLETE       len++;
3402 // OBSOLETE       scan++;
3403 // OBSOLETE     }
3404 // OBSOLETE 
3405 // OBSOLETE   if (!len)
3406 // OBSOLETE     error ("exception number action");
3407 // OBSOLETE 
3408 // OBSOLETE   if (!strncasecmp (args, "forward", len))
3409 // OBSOLETE     exception_map[exception].forward = TRUE;
3410 // OBSOLETE   else if (!strncasecmp (args, "keep", len))
3411 // OBSOLETE     exception_map[exception].forward = FALSE;
3412 // OBSOLETE   else
3413 // OBSOLETE     error ("exception action is either \"keep\" or \"forward\"");
3414 // OBSOLETE }
3415 // OBSOLETE 
3416 // OBSOLETE static void
3417 // OBSOLETE print_exception_info (int exception)
3418 // OBSOLETE {
3419 // OBSOLETE   boolean_t forward = exception_map[exception].forward;
3420 // OBSOLETE 
3421 // OBSOLETE   printf_filtered ("%s\t(%d): ", exception_map[exception].name,
3422 // OBSOLETE                exception);
3423 // OBSOLETE   if (!forward)
3424 // OBSOLETE     if (exception_map[exception].sigmap != SIG_UNKNOWN)
3425 // OBSOLETE       printf_filtered ("keep and handle as signal %d\n",
3426 // OBSOLETE                    exception_map[exception].sigmap);
3427 // OBSOLETE     else
3428 // OBSOLETE       printf_filtered ("keep and handle as unknown signal %d\n",
3429 // OBSOLETE                    exception_map[exception].sigmap);
3430 // OBSOLETE   else
3431 // OBSOLETE     printf_filtered ("forward exception to inferior\n");
3432 // OBSOLETE }
3433 // OBSOLETE 
3434 // OBSOLETE void
3435 // OBSOLETE exception_info (char *args, int from_tty)
3436 // OBSOLETE {
3437 // OBSOLETE   int exception;
3438 // OBSOLETE 
3439 // OBSOLETE   if (!args)
3440 // OBSOLETE     for (exception = 1; exception <= MAX_EXCEPTION; exception++)
3441 // OBSOLETE       print_exception_info (exception);
3442 // OBSOLETE   else
3443 // OBSOLETE     {
3444 // OBSOLETE       exception = atoi (args);
3445 // OBSOLETE 
3446 // OBSOLETE       if (exception <= 0 || exception > MAX_EXCEPTION)
3447 // OBSOLETE     error ("Invalid exception number, values from 1 to %d allowed",
3448 // OBSOLETE            MAX_EXCEPTION);
3449 // OBSOLETE       print_exception_info (exception);
3450 // OBSOLETE     }
3451 // OBSOLETE }
3452 // OBSOLETE \f
3453 // OBSOLETE /* Check for actions for mach exceptions.
3454 // OBSOLETE  */
3455 // OBSOLETE mach3_exception_actions (WAITTYPE *w, boolean_t force_print_only, char *who)
3456 // OBSOLETE {
3457 // OBSOLETE   boolean_t force_print = FALSE;
3458 // OBSOLETE 
3459 // OBSOLETE 
3460 // OBSOLETE   if (force_print_only ||
3461 // OBSOLETE       exception_map[stop_exception].sigmap == SIG_UNKNOWN)
3462 // OBSOLETE     force_print = TRUE;
3463 // OBSOLETE   else
3464 // OBSOLETE     WSETSTOP (*w, exception_map[stop_exception].sigmap);
3465 // OBSOLETE 
3466 // OBSOLETE   if (exception_map[stop_exception].print || force_print)
3467 // OBSOLETE     {
3468 // OBSOLETE       target_terminal_ours ();
3469 // OBSOLETE 
3470 // OBSOLETE       printf_filtered ("\n%s received %s exception : ",
3471 // OBSOLETE                    who,
3472 // OBSOLETE                    exception_map[stop_exception].name);
3473 // OBSOLETE 
3474 // OBSOLETE       wrap_here ("   ");
3475 // OBSOLETE 
3476 // OBSOLETE       switch (stop_exception)
3477 // OBSOLETE     {
3478 // OBSOLETE     case EXC_BAD_ACCESS:
3479 // OBSOLETE       printf_filtered ("referencing address 0x%x : %s\n",
3480 // OBSOLETE                        stop_subcode,
3481 // OBSOLETE                        mach_error_string (stop_code));
3482 // OBSOLETE       break;
3483 // OBSOLETE     case EXC_BAD_INSTRUCTION:
3484 // OBSOLETE       printf_filtered
3485 // OBSOLETE         ("illegal or undefined instruction. code %d subcode %d\n",
3486 // OBSOLETE          stop_code, stop_subcode);
3487 // OBSOLETE       break;
3488 // OBSOLETE     case EXC_ARITHMETIC:
3489 // OBSOLETE       printf_filtered ("code %d\n", stop_code);
3490 // OBSOLETE       break;
3491 // OBSOLETE     case EXC_EMULATION:
3492 // OBSOLETE       printf_filtered ("code %d subcode %d\n", stop_code, stop_subcode);
3493 // OBSOLETE       break;
3494 // OBSOLETE     case EXC_SOFTWARE:
3495 // OBSOLETE       printf_filtered ("%s specific, code 0x%x\n",
3496 // OBSOLETE                        stop_code < 0xffff ? "hardware" : "os emulation",
3497 // OBSOLETE                        stop_code);
3498 // OBSOLETE       break;
3499 // OBSOLETE     case EXC_BREAKPOINT:
3500 // OBSOLETE       printf_filtered ("type %d (machine dependent)\n",
3501 // OBSOLETE                        stop_code);
3502 // OBSOLETE       break;
3503 // OBSOLETE     default:
3504 // OBSOLETE       internal_error (__FILE__, __LINE__,
3505 // OBSOLETE                       "Unknown exception");
3506 // OBSOLETE     }
3507 // OBSOLETE     }
3508 // OBSOLETE }
3509 // OBSOLETE \f
3510 // OBSOLETE setup_notify_port (int create_new)
3511 // OBSOLETE {
3512 // OBSOLETE   kern_return_t ret;
3513 // OBSOLETE 
3514 // OBSOLETE   if (MACH_PORT_VALID (our_notify_port))
3515 // OBSOLETE     {
3516 // OBSOLETE       ret = mach_port_destroy (mach_task_self (), our_notify_port);
3517 // OBSOLETE       CHK ("Could not destroy our_notify_port", ret);
3518 // OBSOLETE     }
3519 // OBSOLETE 
3520 // OBSOLETE   our_notify_port = MACH_PORT_NULL;
3521 // OBSOLETE   notify_chain = (port_chain_t) NULL;
3522 // OBSOLETE   port_chain_destroy (port_chain_obstack);
3523 // OBSOLETE 
3524 // OBSOLETE   if (create_new)
3525 // OBSOLETE     {
3526 // OBSOLETE       ret = mach_port_allocate (mach_task_self (),
3527 // OBSOLETE                             MACH_PORT_RIGHT_RECEIVE,
3528 // OBSOLETE                             &our_notify_port);
3529 // OBSOLETE       if (ret != KERN_SUCCESS)
3530 // OBSOLETE     internal_error (__FILE__, __LINE__,
3531 // OBSOLETE                     "Creating notify port %s", mach_error_string (ret));
3532 // OBSOLETE 
3533 // OBSOLETE       ret = mach_port_move_member (mach_task_self (),
3534 // OBSOLETE                                our_notify_port,
3535 // OBSOLETE                                inferior_wait_port_set);
3536 // OBSOLETE       if (ret != KERN_SUCCESS)
3537 // OBSOLETE     internal_error (__FILE__, __LINE__,
3538 // OBSOLETE                     "initial move member %s", mach_error_string (ret));
3539 // OBSOLETE     }
3540 // OBSOLETE }
3541 // OBSOLETE 
3542 // OBSOLETE /*
3543 // OBSOLETE  * Register our message port to the net name server
3544 // OBSOLETE  *
3545 // OBSOLETE  * Currently used only by the external stop-gdb program
3546 // OBSOLETE  * since ^C does not work if you would like to enter
3547 // OBSOLETE  * gdb command level while debugging your program.
3548 // OBSOLETE  *
3549 // OBSOLETE  * NOTE: If the message port is sometimes used for other
3550 // OBSOLETE  * purposes also, the NAME must not be a guessable one.
3551 // OBSOLETE  * Then, there should be a way to change it.
3552 // OBSOLETE  */
3553 // OBSOLETE 
3554 // OBSOLETE char registered_name[MAX_NAME_LEN];
3555 // OBSOLETE 
3556 // OBSOLETE void
3557 // OBSOLETE message_port_info (char *args, int from_tty)
3558 // OBSOLETE {
3559 // OBSOLETE   if (registered_name[0])
3560 // OBSOLETE     printf_filtered ("gdb's message port name: '%s'\n",
3561 // OBSOLETE                  registered_name);
3562 // OBSOLETE   else
3563 // OBSOLETE     printf_filtered ("gdb's message port is not currently registered\n");
3564 // OBSOLETE }
3565 // OBSOLETE 
3566 // OBSOLETE void
3567 // OBSOLETE gdb_register_port (char *name, mach_port_t port)
3568 // OBSOLETE {
3569 // OBSOLETE   kern_return_t ret;
3570 // OBSOLETE   static int already_signed = 0;
3571 // OBSOLETE   int len;
3572 // OBSOLETE 
3573 // OBSOLETE   if (!MACH_PORT_VALID (port) || !name || !*name)
3574 // OBSOLETE     {
3575 // OBSOLETE       warning ("Invalid registration request");
3576 // OBSOLETE       return;
3577 // OBSOLETE     }
3578 // OBSOLETE 
3579 // OBSOLETE   if (!already_signed)
3580 // OBSOLETE     {
3581 // OBSOLETE       ret = mach_port_insert_right (mach_task_self (),
3582 // OBSOLETE                                 our_message_port,
3583 // OBSOLETE                                 our_message_port,
3584 // OBSOLETE                                 MACH_MSG_TYPE_MAKE_SEND);
3585 // OBSOLETE       CHK ("Failed to create a signature to our_message_port", ret);
3586 // OBSOLETE       already_signed = 1;
3587 // OBSOLETE     }
3588 // OBSOLETE   else if (already_signed > 1)
3589 // OBSOLETE     {
3590 // OBSOLETE       ret = netname_check_out (name_server_port,
3591 // OBSOLETE                            registered_name,
3592 // OBSOLETE                            our_message_port);
3593 // OBSOLETE       CHK ("Failed to check out gdb's message port", ret);
3594 // OBSOLETE       registered_name[0] = '\000';
3595 // OBSOLETE       already_signed = 1;
3596 // OBSOLETE     }
3597 // OBSOLETE 
3598 // OBSOLETE   ret = netname_check_in (name_server_port, /* Name server port */
3599 // OBSOLETE                       name, /* Name of service */
3600 // OBSOLETE                       our_message_port,     /* Signature */
3601 // OBSOLETE                       port);        /* Creates a new send right */
3602 // OBSOLETE   CHK ("Failed to check in the port", ret);
3603 // OBSOLETE 
3604 // OBSOLETE   len = 0;
3605 // OBSOLETE   while (len < MAX_NAME_LEN && *(name + len))
3606 // OBSOLETE     {
3607 // OBSOLETE       registered_name[len] = *(name + len);
3608 // OBSOLETE       len++;
3609 // OBSOLETE     }
3610 // OBSOLETE   registered_name[len] = '\000';
3611 // OBSOLETE   already_signed = 2;
3612 // OBSOLETE }
3613 // OBSOLETE 
3614 // OBSOLETE struct cmd_list_element *cmd_thread_list;
3615 // OBSOLETE struct cmd_list_element *cmd_task_list;
3616 // OBSOLETE 
3617 // OBSOLETE /*ARGSUSED */
3618 // OBSOLETE static void
3619 // OBSOLETE thread_command (char *arg, int from_tty)
3620 // OBSOLETE {
3621 // OBSOLETE   printf_unfiltered ("\"thread\" must be followed by the name of a thread command.\n");
3622 // OBSOLETE   help_list (cmd_thread_list, "thread ", -1, gdb_stdout);
3623 // OBSOLETE }
3624 // OBSOLETE 
3625 // OBSOLETE /*ARGSUSED */
3626 // OBSOLETE static void
3627 // OBSOLETE task_command (char *arg, int from_tty)
3628 // OBSOLETE {
3629 // OBSOLETE   printf_unfiltered ("\"task\" must be followed by the name of a task command.\n");
3630 // OBSOLETE   help_list (cmd_task_list, "task ", -1, gdb_stdout);
3631 // OBSOLETE }
3632 // OBSOLETE 
3633 // OBSOLETE add_mach_specific_commands (void)
3634 // OBSOLETE {
3635 // OBSOLETE   /* Thread handling commands */
3636 // OBSOLETE 
3637 // OBSOLETE   /* FIXME: Move our thread support into the generic thread.c stuff so we
3638 // OBSOLETE      can share that code.  */
3639 // OBSOLETE   add_prefix_cmd ("mthread", class_stack, thread_command,
3640 // OBSOLETE       "Generic command for handling Mach threads in the debugged task.",
3641 // OBSOLETE               &cmd_thread_list, "thread ", 0, &cmdlist);
3642 // OBSOLETE 
3643 // OBSOLETE   add_com_alias ("th", "mthread", class_stack, 1);
3644 // OBSOLETE 
3645 // OBSOLETE   add_cmd ("select", class_stack, thread_select_command,
3646 // OBSOLETE        "Select and print MID of the selected thread",
3647 // OBSOLETE        &cmd_thread_list);
3648 // OBSOLETE   add_cmd ("list", class_stack, thread_list_command,
3649 // OBSOLETE        "List info of task's threads. Selected thread is marked with '*'",
3650 // OBSOLETE        &cmd_thread_list);
3651 // OBSOLETE   add_cmd ("suspend", class_run, thread_suspend_command,
3652 // OBSOLETE        "Suspend one or all of the threads in the selected task.",
3653 // OBSOLETE        &cmd_thread_list);
3654 // OBSOLETE   add_cmd ("resume", class_run, thread_resume_command,
3655 // OBSOLETE        "Resume one or all of the threads in the selected task.",
3656 // OBSOLETE        &cmd_thread_list);
3657 // OBSOLETE   add_cmd ("kill", class_run, thread_kill_command,
3658 // OBSOLETE        "Kill the specified thread MID from inferior task.",
3659 // OBSOLETE        &cmd_thread_list);
3660 // OBSOLETE #if 0
3661 // OBSOLETE   /* The rest of this support (condition_thread) was not merged.  It probably
3662 // OBSOLETE      should not be merged in this form, but instead added to the generic GDB
3663 // OBSOLETE      thread support.  */
3664 // OBSOLETE   add_cmd ("break", class_breakpoint, condition_thread,
3665 // OBSOLETE        "Breakpoint N will only be effective for thread MID or @SLOT\n\
3666 // OBSOLETE         If MID/@SLOT is omitted allow all threads to break at breakpoint",
3667 // OBSOLETE        &cmd_thread_list);
3668 // OBSOLETE #endif
3669 // OBSOLETE   /* Thread command shorthands (for backward compatibility) */
3670 // OBSOLETE   add_alias_cmd ("ts", "mthread select", 0, 0, &cmdlist);
3671 // OBSOLETE   add_alias_cmd ("tl", "mthread list", 0, 0, &cmdlist);
3672 // OBSOLETE 
3673 // OBSOLETE   /* task handling commands */
3674 // OBSOLETE 
3675 // OBSOLETE   add_prefix_cmd ("task", class_stack, task_command,
3676 // OBSOLETE               "Generic command for handling debugged task.",
3677 // OBSOLETE               &cmd_task_list, "task ", 0, &cmdlist);
3678 // OBSOLETE 
3679 // OBSOLETE   add_com_alias ("ta", "task", class_stack, 1);
3680 // OBSOLETE 
3681 // OBSOLETE   add_cmd ("suspend", class_run, task_suspend_command,
3682 // OBSOLETE        "Suspend the inferior task.",
3683 // OBSOLETE        &cmd_task_list);
3684 // OBSOLETE   add_cmd ("resume", class_run, task_resume_command,
3685 // OBSOLETE        "Resume the inferior task.",
3686 // OBSOLETE        &cmd_task_list);
3687 // OBSOLETE   add_cmd ("info", no_class, task_info_command,
3688 // OBSOLETE        "Print information about the specified task.",
3689 // OBSOLETE        &cmd_task_list);
3690 // OBSOLETE 
3691 // OBSOLETE   /* Print my message port name */
3692 // OBSOLETE 
3693 // OBSOLETE   add_info ("message-port", message_port_info,
3694 // OBSOLETE         "Returns the name of gdb's message port in the netnameserver");
3695 // OBSOLETE 
3696 // OBSOLETE   /* Exception commands */
3697 // OBSOLETE 
3698 // OBSOLETE   add_info ("exceptions", exception_info,
3699 // OBSOLETE         "What debugger does when program gets various exceptions.\n\
3700 // OBSOLETE Specify an exception number as argument to print info on that\n\
3701 // OBSOLETE exception only.");
3702 // OBSOLETE 
3703 // OBSOLETE   add_com ("exception", class_run, exception_command,
3704 // OBSOLETE        "Specify how to handle an exception.\n\
3705 // OBSOLETE Args are exception number followed by \"forward\" or \"keep\".\n\
3706 // OBSOLETE `Forward' means forward the exception to the program's normal exception\n\
3707 // OBSOLETE handler.\n\
3708 // OBSOLETE `Keep' means reenter debugger if this exception happens, and GDB maps\n\
3709 // OBSOLETE the exception to some signal (see info exception)\n\
3710 // OBSOLETE Normally \"keep\" is used to return to GDB on exception.");
3711 // OBSOLETE }
3712 // OBSOLETE 
3713 // OBSOLETE kern_return_t
3714 // OBSOLETE do_mach_notify_dead_name (mach_port_t notify, mach_port_t name)
3715 // OBSOLETE {
3716 // OBSOLETE   kern_return_t kr = KERN_SUCCESS;
3717 // OBSOLETE 
3718 // OBSOLETE   /* Find the thing that notified */
3719 // OBSOLETE   port_chain_t element = port_chain_member (notify_chain, name);
3720 // OBSOLETE 
3721 // OBSOLETE   /* Take name of from unreceived dead name notification list */
3722 // OBSOLETE   notify_chain = port_chain_delete (notify_chain, name);
3723 // OBSOLETE 
3724 // OBSOLETE   if (!element)
3725 // OBSOLETE     error ("Received a dead name notify from unchained port (0x%x)", name);
3726 // OBSOLETE 
3727 // OBSOLETE   switch (element->type)
3728 // OBSOLETE     {
3729 // OBSOLETE 
3730 // OBSOLETE     case MACH_TYPE_THREAD:
3731 // OBSOLETE       target_terminal_ours_for_output ();
3732 // OBSOLETE       if (name == current_thread)
3733 // OBSOLETE     {
3734 // OBSOLETE       printf_filtered ("\nCurrent thread %d died", element->mid);
3735 // OBSOLETE       current_thread = MACH_PORT_NULL;
3736 // OBSOLETE     }
3737 // OBSOLETE       else
3738 // OBSOLETE     printf_filtered ("\nThread %d died", element->mid);
3739 // OBSOLETE 
3740 // OBSOLETE       break;
3741 // OBSOLETE 
3742 // OBSOLETE     case MACH_TYPE_TASK:
3743 // OBSOLETE       target_terminal_ours_for_output ();
3744 // OBSOLETE       if (name != inferior_task)
3745 // OBSOLETE     printf_filtered ("Task %d died, but it was not the selected task",
3746 // OBSOLETE                      element->mid);
3747 // OBSOLETE       else
3748 // OBSOLETE     {
3749 // OBSOLETE       printf_filtered ("Current task %d died", element->mid);
3750 // OBSOLETE 
3751 // OBSOLETE       mach_port_destroy (mach_task_self (), name);
3752 // OBSOLETE       inferior_task = MACH_PORT_NULL;
3753 // OBSOLETE 
3754 // OBSOLETE       if (notify_chain)
3755 // OBSOLETE         warning ("There were still unreceived dead_name_notifications???");
3756 // OBSOLETE 
3757 // OBSOLETE       /* Destroy the old notifications */
3758 // OBSOLETE       setup_notify_port (0);
3759 // OBSOLETE 
3760 // OBSOLETE     }
3761 // OBSOLETE       break;
3762 // OBSOLETE 
3763 // OBSOLETE     default:
3764 // OBSOLETE       error ("Unregistered dead_name 0x%x notification received. Type is %d, mid is 0x%x",
3765 // OBSOLETE          name, element->type, element->mid);
3766 // OBSOLETE       break;
3767 // OBSOLETE     }
3768 // OBSOLETE 
3769 // OBSOLETE   return KERN_SUCCESS;
3770 // OBSOLETE }
3771 // OBSOLETE 
3772 // OBSOLETE kern_return_t
3773 // OBSOLETE do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
3774 // OBSOLETE {
3775 // OBSOLETE   warning ("do_mach_notify_msg_accepted : notify %x, name %x",
3776 // OBSOLETE        notify, name);
3777 // OBSOLETE   return KERN_SUCCESS;
3778 // OBSOLETE }
3779 // OBSOLETE 
3780 // OBSOLETE kern_return_t
3781 // OBSOLETE do_mach_notify_no_senders (mach_port_t notify, mach_port_mscount_t mscount)
3782 // OBSOLETE {
3783 // OBSOLETE   warning ("do_mach_notify_no_senders : notify %x, mscount %x",
3784 // OBSOLETE        notify, mscount);
3785 // OBSOLETE   return KERN_SUCCESS;
3786 // OBSOLETE }
3787 // OBSOLETE 
3788 // OBSOLETE kern_return_t
3789 // OBSOLETE do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
3790 // OBSOLETE {
3791 // OBSOLETE   warning ("do_mach_notify_port_deleted : notify %x, name %x",
3792 // OBSOLETE        notify, name);
3793 // OBSOLETE   return KERN_SUCCESS;
3794 // OBSOLETE }
3795 // OBSOLETE 
3796 // OBSOLETE kern_return_t
3797 // OBSOLETE do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t rights)
3798 // OBSOLETE {
3799 // OBSOLETE   warning ("do_mach_notify_port_destroyed : notify %x, rights %x",
3800 // OBSOLETE        notify, rights);
3801 // OBSOLETE   return KERN_SUCCESS;
3802 // OBSOLETE }
3803 // OBSOLETE 
3804 // OBSOLETE kern_return_t
3805 // OBSOLETE do_mach_notify_send_once (mach_port_t notify)
3806 // OBSOLETE {
3807 // OBSOLETE #ifdef DUMP_SYSCALL
3808 // OBSOLETE   /* MANY of these are generated. */
3809 // OBSOLETE   warning ("do_mach_notify_send_once : notify %x",
3810 // OBSOLETE        notify);
3811 // OBSOLETE #endif
3812 // OBSOLETE   return KERN_SUCCESS;
3813 // OBSOLETE }
3814 // OBSOLETE 
3815 // OBSOLETE /* Kills the inferior. It's gone when you call this */
3816 // OBSOLETE static void
3817 // OBSOLETE kill_inferior_fast (void)
3818 // OBSOLETE {
3819 // OBSOLETE   WAITTYPE w;
3820 // OBSOLETE 
3821 // OBSOLETE   if (PIDGET (inferior_ptid) == 0 || PIDGET (inferior_ptid) == 1)
3822 // OBSOLETE     return;
3823 // OBSOLETE 
3824 // OBSOLETE   /* kill() it, since the Unix server does not otherwise notice when
3825 // OBSOLETE    * killed with task_terminate().
3826 // OBSOLETE    */
3827 // OBSOLETE   if (PIDGET (inferior_ptid) > 0)
3828 // OBSOLETE     kill (PIDGET (inferior_ptid), SIGKILL);
3829 // OBSOLETE 
3830 // OBSOLETE   /* It's propably terminate already */
3831 // OBSOLETE   (void) task_terminate (inferior_task);
3832 // OBSOLETE 
3833 // OBSOLETE   inferior_task = MACH_PORT_NULL;
3834 // OBSOLETE   current_thread = MACH_PORT_NULL;
3835 // OBSOLETE 
3836 // OBSOLETE   wait3 (&w, WNOHANG, 0);
3837 // OBSOLETE 
3838 // OBSOLETE   setup_notify_port (0);
3839 // OBSOLETE }
3840 // OBSOLETE 
3841 // OBSOLETE static void
3842 // OBSOLETE m3_kill_inferior (void)
3843 // OBSOLETE {
3844 // OBSOLETE   kill_inferior_fast ();
3845 // OBSOLETE   target_mourn_inferior ();
3846 // OBSOLETE }
3847 // OBSOLETE 
3848 // OBSOLETE /* Clean up after the inferior dies.  */
3849 // OBSOLETE 
3850 // OBSOLETE static void
3851 // OBSOLETE m3_mourn_inferior (void)
3852 // OBSOLETE {
3853 // OBSOLETE   unpush_target (&m3_ops);
3854 // OBSOLETE   generic_mourn_inferior ();
3855 // OBSOLETE }
3856 // OBSOLETE \f
3857 // OBSOLETE 
3858 // OBSOLETE /* Fork an inferior process, and start debugging it.  */
3859 // OBSOLETE 
3860 // OBSOLETE static void
3861 // OBSOLETE m3_create_inferior (char *exec_file, char *allargs, char **env)
3862 // OBSOLETE {
3863 // OBSOLETE   fork_inferior (exec_file, allargs, env, m3_trace_me, m3_trace_him, NULL, NULL);
3864 // OBSOLETE   /* We are at the first instruction we care about.  */
3865 // OBSOLETE   /* Pedal to the metal... */
3866 // OBSOLETE   proceed ((CORE_ADDR) -1, 0, 0);
3867 // OBSOLETE }
3868 // OBSOLETE 
3869 // OBSOLETE /* Mark our target-struct as eligible for stray "run" and "attach"
3870 // OBSOLETE    commands.  */
3871 // OBSOLETE static int
3872 // OBSOLETE m3_can_run (void)
3873 // OBSOLETE {
3874 // OBSOLETE   return 1;
3875 // OBSOLETE }
3876 // OBSOLETE \f
3877 // OBSOLETE /* Mach 3.0 does not need ptrace for anything
3878 // OBSOLETE  * Make sure nobody uses it on mach.
3879 // OBSOLETE  */
3880 // OBSOLETE ptrace (int a, int b, int c, int d)
3881 // OBSOLETE {
3882 // OBSOLETE   error ("Lose, Lose! Somebody called ptrace\n");
3883 // OBSOLETE }
3884 // OBSOLETE 
3885 // OBSOLETE /* Resume execution of the inferior process.
3886 // OBSOLETE    If STEP is nonzero, single-step it.
3887 // OBSOLETE    If SIGNAL is nonzero, give it that signal.  */
3888 // OBSOLETE 
3889 // OBSOLETE void
3890 // OBSOLETE m3_resume (ptid_t ptid, int step, enum target_signal signal)
3891 // OBSOLETE {
3892 // OBSOLETE   kern_return_t ret;
3893 // OBSOLETE 
3894 // OBSOLETE   if (step)
3895 // OBSOLETE     {
3896 // OBSOLETE       thread_basic_info_data_t th_info;
3897 // OBSOLETE       unsigned int infoCnt = THREAD_BASIC_INFO_COUNT;
3898 // OBSOLETE 
3899 // OBSOLETE       /* There is no point in single stepping when current_thread
3900 // OBSOLETE        * is dead.
3901 // OBSOLETE        */
3902 // OBSOLETE       if (!MACH_PORT_VALID (current_thread))
3903 // OBSOLETE     error ("No thread selected; can not single step");
3904 // OBSOLETE 
3905 // OBSOLETE       /* If current_thread is suspended, tracing it would never return.
3906 // OBSOLETE        */
3907 // OBSOLETE       ret = thread_info (current_thread,
3908 // OBSOLETE                      THREAD_BASIC_INFO,
3909 // OBSOLETE                      (thread_info_t) & th_info,
3910 // OBSOLETE                      &infoCnt);
3911 // OBSOLETE       CHK ("child_resume: can't get thread info", ret);
3912 // OBSOLETE 
3913 // OBSOLETE       if (th_info.suspend_count)
3914 // OBSOLETE     error ("Can't trace a suspended thread. Use \"thread resume\" command to resume it");
3915 // OBSOLETE     }
3916 // OBSOLETE 
3917 // OBSOLETE   vm_read_cache_valid = FALSE;
3918 // OBSOLETE 
3919 // OBSOLETE   if (signal && PIDGET (inferior_ptid) > 0) /* Do not signal, if attached by MID */
3920 // OBSOLETE     kill (PIDGET (inferior_ptid), target_signal_to_host (signal));
3921 // OBSOLETE 
3922 // OBSOLETE   if (step)
3923 // OBSOLETE     {
3924 // OBSOLETE       suspend_all_threads (0);
3925 // OBSOLETE 
3926 // OBSOLETE       setup_single_step (current_thread, TRUE);
3927 // OBSOLETE 
3928 // OBSOLETE       ret = thread_resume (current_thread);
3929 // OBSOLETE       CHK ("thread_resume", ret);
3930 // OBSOLETE     }
3931 // OBSOLETE 
3932 // OBSOLETE   ret = task_resume (inferior_task);
3933 // OBSOLETE   if (ret == KERN_FAILURE)
3934 // OBSOLETE     warning ("Task was not suspended");
3935 // OBSOLETE   else
3936 // OBSOLETE     CHK ("Resuming task", ret);
3937 // OBSOLETE 
3938 // OBSOLETE   /* HACK HACK This is needed by the multiserver system HACK HACK */
3939 // OBSOLETE   while ((ret = task_resume (inferior_task)) == KERN_SUCCESS)
3940 // OBSOLETE     /* make sure it really runs */ ;
3941 // OBSOLETE   /* HACK HACK This is needed by the multiserver system HACK HACK */
3942 // OBSOLETE }
3943 // OBSOLETE \f
3944 // OBSOLETE #ifdef ATTACH_DETACH
3945 // OBSOLETE 
3946 // OBSOLETE /* Start debugging the process with the given task */
3947 // OBSOLETE void
3948 // OBSOLETE task_attach (task_t tid)
3949 // OBSOLETE {
3950 // OBSOLETE   kern_return_t ret;
3951 // OBSOLETE   inferior_task = tid;
3952 // OBSOLETE 
3953 // OBSOLETE   ret = task_suspend (inferior_task);
3954 // OBSOLETE   CHK ("task_attach: task_suspend", ret);
3955 // OBSOLETE 
3956 // OBSOLETE   must_suspend_thread = 0;
3957 // OBSOLETE 
3958 // OBSOLETE   setup_notify_port (1);
3959 // OBSOLETE 
3960 // OBSOLETE   request_notify (inferior_task, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_TASK);
3961 // OBSOLETE 
3962 // OBSOLETE   setup_exception_port ();
3963 // OBSOLETE 
3964 // OBSOLETE   emulator_present = have_emulator_p (inferior_task);
3965 // OBSOLETE 
3966 // OBSOLETE   attach_flag = 1;
3967 // OBSOLETE }
3968 // OBSOLETE 
3969 // OBSOLETE /* Well, we can call error also here and leave the
3970 // OBSOLETE  * target stack inconsistent. Sigh.
3971 // OBSOLETE  * Fix this sometime (the only way to fail here is that
3972 // OBSOLETE  * the task has no threads at all, which is rare, but
3973 // OBSOLETE  * possible; or if the target task has died, which is also
3974 // OBSOLETE  * possible, but unlikely, since it has been suspended.
3975 // OBSOLETE  * (Someone must have killed it))
3976 // OBSOLETE  */
3977 // OBSOLETE void
3978 // OBSOLETE attach_to_thread (void)
3979 // OBSOLETE {
3980 // OBSOLETE   if (select_thread (inferior_task, 0, 1) != KERN_SUCCESS)
3981 // OBSOLETE     error ("Could not select any threads to attach to");
3982 // OBSOLETE }
3983 // OBSOLETE 
3984 // OBSOLETE mid_attach (int mid)
3985 // OBSOLETE {
3986 // OBSOLETE   kern_return_t ret;
3987 // OBSOLETE 
3988 // OBSOLETE   ret = machid_mach_port (mid_server, mid_auth, mid, &inferior_task);
3989 // OBSOLETE   CHK ("mid_attach: machid_mach_port", ret);
3990 // OBSOLETE 
3991 // OBSOLETE   task_attach (inferior_task);
3992 // OBSOLETE 
3993 // OBSOLETE   return mid;
3994 // OBSOLETE }
3995 // OBSOLETE 
3996 // OBSOLETE /* 
3997 // OBSOLETE  * Start debugging the process whose unix process-id is PID.
3998 // OBSOLETE  * A negative "pid" value is legal and signifies a mach_id not a unix pid.
3999 // OBSOLETE  *
4000 // OBSOLETE  * Prevent (possible unwanted) dangerous operations by enabled users
4001 // OBSOLETE  * like "atta 0" or "atta foo" (equal to the previous :-) and
4002 // OBSOLETE  * "atta pidself". Anyway, the latter is allowed by specifying a MID.
4003 // OBSOLETE  */
4004 // OBSOLETE static int
4005 // OBSOLETE m3_do_attach (int pid)
4006 // OBSOLETE {
4007 // OBSOLETE   kern_return_t ret;
4008 // OBSOLETE 
4009 // OBSOLETE   if (pid == 0)
4010 // OBSOLETE     error ("MID=0, Debugging the master unix server does not compute");
4011 // OBSOLETE 
4012 // OBSOLETE   /* Foo. This assumes gdb has a unix pid */
4013 // OBSOLETE   if (pid == getpid ())
4014 // OBSOLETE     error ("I will debug myself only by mid. (Gdb would suspend itself!)");
4015 // OBSOLETE 
4016 // OBSOLETE   if (pid < 0)
4017 // OBSOLETE     {
4018 // OBSOLETE       mid_attach (-(pid));
4019 // OBSOLETE 
4020 // OBSOLETE       /* inferior_ptid will be NEGATIVE! */
4021 // OBSOLETE       inferior_ptid = pid_to_ptid (pid);
4022 // OBSOLETE 
4023 // OBSOLETE       return PIDGET (inferior_ptid);
4024 // OBSOLETE     }
4025 // OBSOLETE 
4026 // OBSOLETE   inferior_task = task_by_pid (pid);
4027 // OBSOLETE   if (!MACH_PORT_VALID (inferior_task))
4028 // OBSOLETE     error ("Cannot map Unix pid %d to Mach task port", pid);
4029 // OBSOLETE 
4030 // OBSOLETE   task_attach (inferior_task);
4031 // OBSOLETE 
4032 // OBSOLETE   inferior_ptid = pid_to_ptid (pid);
4033 // OBSOLETE 
4034 // OBSOLETE   return PIDGET (inferior_ptid);
4035 // OBSOLETE }
4036 // OBSOLETE 
4037 // OBSOLETE /* Attach to process PID, then initialize for debugging it
4038 // OBSOLETE    and wait for the trace-trap that results from attaching.  */
4039 // OBSOLETE 
4040 // OBSOLETE static void
4041 // OBSOLETE m3_attach (char *args, int from_tty)
4042 // OBSOLETE {
4043 // OBSOLETE   char *exec_file;
4044 // OBSOLETE   int pid;
4045 // OBSOLETE 
4046 // OBSOLETE   if (!args)
4047 // OBSOLETE     error_no_arg ("process-id to attach");
4048 // OBSOLETE 
4049 // OBSOLETE   pid = atoi (args);
4050 // OBSOLETE 
4051 // OBSOLETE   if (pid == getpid ())             /* Trying to masturbate? */
4052 // OBSOLETE     error ("I refuse to debug myself!");
4053 // OBSOLETE 
4054 // OBSOLETE   if (from_tty)
4055 // OBSOLETE     {
4056 // OBSOLETE       exec_file = (char *) get_exec_file (0);
4057 // OBSOLETE 
4058 // OBSOLETE       if (exec_file)
4059 // OBSOLETE     printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
4060 // OBSOLETE                        target_pid_to_str (pid_to_ptid (pid)));
4061 // OBSOLETE       else
4062 // OBSOLETE     printf_unfiltered ("Attaching to %s\n",
4063 // OBSOLETE                        target_pid_to_str (pid_to_ptid (pid)));
4064 // OBSOLETE 
4065 // OBSOLETE       gdb_flush (gdb_stdout);
4066 // OBSOLETE     }
4067 // OBSOLETE 
4068 // OBSOLETE   m3_do_attach (pid_to_ptid (pid));
4069 // OBSOLETE   inferior_ptid = pid_to_ptid (pid);
4070 // OBSOLETE   push_target (&m3_ops);
4071 // OBSOLETE }
4072 // OBSOLETE \f
4073 // OBSOLETE void
4074 // OBSOLETE deallocate_inferior_ports (void)
4075 // OBSOLETE {
4076 // OBSOLETE   kern_return_t ret;
4077 // OBSOLETE   thread_array_t thread_list;
4078 // OBSOLETE   int thread_count, index;
4079 // OBSOLETE 
4080 // OBSOLETE   if (!MACH_PORT_VALID (inferior_task))
4081 // OBSOLETE     return;
4082 // OBSOLETE 
4083 // OBSOLETE   ret = task_threads (inferior_task, &thread_list, &thread_count);
4084 // OBSOLETE   if (ret != KERN_SUCCESS)
4085 // OBSOLETE     {
4086 // OBSOLETE       warning ("deallocate_inferior_ports: task_threads",
4087 // OBSOLETE            mach_error_string (ret));
4088 // OBSOLETE       return;
4089 // OBSOLETE     }
4090 // OBSOLETE 
4091 // OBSOLETE   /* Get rid of send rights to task threads */
4092 // OBSOLETE   for (index = 0; index < thread_count; index++)
4093 // OBSOLETE     {
4094 // OBSOLETE       int rights;
4095 // OBSOLETE       ret = mach_port_get_refs (mach_task_self (),
4096 // OBSOLETE                             thread_list[index],
4097 // OBSOLETE                             MACH_PORT_RIGHT_SEND,
4098 // OBSOLETE                             &rights);
4099 // OBSOLETE       CHK ("deallocate_inferior_ports: get refs", ret);
4100 // OBSOLETE 
4101 // OBSOLETE       if (rights > 0)
4102 // OBSOLETE     {
4103 // OBSOLETE       ret = mach_port_mod_refs (mach_task_self (),
4104 // OBSOLETE                                 thread_list[index],
4105 // OBSOLETE                                 MACH_PORT_RIGHT_SEND,
4106 // OBSOLETE                                 -rights);
4107 // OBSOLETE       CHK ("deallocate_inferior_ports: mod refs", ret);
4108 // OBSOLETE     }
4109 // OBSOLETE     }
4110 // OBSOLETE 
4111 // OBSOLETE   ret = mach_port_mod_refs (mach_task_self (),
4112 // OBSOLETE                         inferior_exception_port,
4113 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
4114 // OBSOLETE                         -1);
4115 // OBSOLETE   CHK ("deallocate_inferior_ports: cannot get rid of exception port", ret);
4116 // OBSOLETE 
4117 // OBSOLETE   ret = mach_port_deallocate (mach_task_self (),
4118 // OBSOLETE                           inferior_task);
4119 // OBSOLETE   CHK ("deallocate_task_port: deallocating inferior_task", ret);
4120 // OBSOLETE 
4121 // OBSOLETE   current_thread = MACH_PORT_NULL;
4122 // OBSOLETE   inferior_task = MACH_PORT_NULL;
4123 // OBSOLETE }
4124 // OBSOLETE 
4125 // OBSOLETE /* Stop debugging the process whose number is PID
4126 // OBSOLETE    and continue it with signal number SIGNAL.
4127 // OBSOLETE    SIGNAL = 0 means just continue it.  */
4128 // OBSOLETE 
4129 // OBSOLETE static void
4130 // OBSOLETE m3_do_detach (int signal)
4131 // OBSOLETE {
4132 // OBSOLETE   kern_return_t ret;
4133 // OBSOLETE 
4134 // OBSOLETE   MACH_ERROR_NO_INFERIOR;
4135 // OBSOLETE 
4136 // OBSOLETE   if (current_thread != MACH_PORT_NULL)
4137 // OBSOLETE     {
4138 // OBSOLETE       /* Store the gdb's view of the thread we are deselecting
4139 // OBSOLETE        * before we detach.
4140 // OBSOLETE        * @@ I am really not sure if this is ever needeed.
4141 // OBSOLETE        */
4142 // OBSOLETE       target_prepare_to_store ();
4143 // OBSOLETE       target_store_registers (-1);
4144 // OBSOLETE     }
4145 // OBSOLETE 
4146 // OBSOLETE   ret = task_set_special_port (inferior_task,
4147 // OBSOLETE                            TASK_EXCEPTION_PORT,
4148 // OBSOLETE                            inferior_old_exception_port);
4149 // OBSOLETE   CHK ("task_set_special_port", ret);
4150 // OBSOLETE 
4151 // OBSOLETE   /* Discard all requested notifications */
4152 // OBSOLETE   setup_notify_port (0);
4153 // OBSOLETE 
4154 // OBSOLETE   if (remove_breakpoints ())
4155 // OBSOLETE     warning ("Could not remove breakpoints when detaching");
4156 // OBSOLETE 
4157 // OBSOLETE   if (signal && PIDGET (inferior_ptid) > 0)
4158 // OBSOLETE     kill (PIDGET (inferior_ptid), signal);
4159 // OBSOLETE 
4160 // OBSOLETE   /* the task might be dead by now */
4161 // OBSOLETE   (void) task_resume (inferior_task);
4162 // OBSOLETE 
4163 // OBSOLETE   deallocate_inferior_ports ();
4164 // OBSOLETE 
4165 // OBSOLETE   attach_flag = 0;
4166 // OBSOLETE }
4167 // OBSOLETE 
4168 // OBSOLETE /* Take a program previously attached to and detaches it.
4169 // OBSOLETE    The program resumes execution and will no longer stop
4170 // OBSOLETE    on signals, etc.  We'd better not have left any breakpoints
4171 // OBSOLETE    in the program or it'll die when it hits one.  For this
4172 // OBSOLETE    to work, it may be necessary for the process to have been
4173 // OBSOLETE    previously attached.  It *might* work if the program was
4174 // OBSOLETE    started via fork.  */
4175 // OBSOLETE 
4176 // OBSOLETE static void
4177 // OBSOLETE m3_detach (char *args, int from_tty)
4178 // OBSOLETE {
4179 // OBSOLETE   int siggnal = 0;
4180 // OBSOLETE 
4181 // OBSOLETE   if (from_tty)
4182 // OBSOLETE     {
4183 // OBSOLETE       char *exec_file = get_exec_file (0);
4184 // OBSOLETE       if (exec_file == 0)
4185 // OBSOLETE     exec_file = "";
4186 // OBSOLETE       printf_unfiltered ("Detaching from program: %s %s\n",
4187 // OBSOLETE                      exec_file, target_pid_to_str (inferior_ptid));
4188 // OBSOLETE       gdb_flush (gdb_stdout);
4189 // OBSOLETE     }
4190 // OBSOLETE   if (args)
4191 // OBSOLETE     siggnal = atoi (args);
4192 // OBSOLETE 
4193 // OBSOLETE   m3_do_detach (siggnal);
4194 // OBSOLETE   inferior_ptid = null_ptid;
4195 // OBSOLETE   unpush_target (&m3_ops);  /* Pop out of handling an inferior */
4196 // OBSOLETE }
4197 // OBSOLETE #endif /* ATTACH_DETACH */
4198 // OBSOLETE 
4199 // OBSOLETE /* Get ready to modify the registers array.  On machines which store
4200 // OBSOLETE    individual registers, this doesn't need to do anything.  On machines
4201 // OBSOLETE    which store all the registers in one fell swoop, this makes sure
4202 // OBSOLETE    that registers contains all the registers from the program being
4203 // OBSOLETE    debugged.  */
4204 // OBSOLETE 
4205 // OBSOLETE static void
4206 // OBSOLETE m3_prepare_to_store (void)
4207 // OBSOLETE {
4208 // OBSOLETE #ifdef CHILD_PREPARE_TO_STORE
4209 // OBSOLETE   CHILD_PREPARE_TO_STORE ();
4210 // OBSOLETE #endif
4211 // OBSOLETE }
4212 // OBSOLETE 
4213 // OBSOLETE /* Print status information about what we're accessing.  */
4214 // OBSOLETE 
4215 // OBSOLETE static void
4216 // OBSOLETE m3_files_info (struct target_ops *ignore)
4217 // OBSOLETE {
4218 // OBSOLETE   /* FIXME: should print MID and all that crap.  */
4219 // OBSOLETE   printf_unfiltered ("\tUsing the running image of %s %s.\n",
4220 // OBSOLETE       attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid));
4221 // OBSOLETE }
4222 // OBSOLETE 
4223 // OBSOLETE static void
4224 // OBSOLETE m3_open (char *arg, int from_tty)
4225 // OBSOLETE {
4226 // OBSOLETE   error ("Use the \"run\" command to start a Unix child process.");
4227 // OBSOLETE }
4228 // OBSOLETE 
4229 // OBSOLETE #ifdef DUMP_SYSCALL
4230 // OBSOLETE #define STR(x) #x
4231 // OBSOLETE 
4232 // OBSOLETE char *bsd1_names[] =
4233 // OBSOLETE {
4234 // OBSOLETE   "execve",
4235 // OBSOLETE   "fork",
4236 // OBSOLETE   "take_signal",
4237 // OBSOLETE   "sigreturn",
4238 // OBSOLETE   "getrusage",
4239 // OBSOLETE   "chdir",
4240 // OBSOLETE   "chroot",
4241 // OBSOLETE   "open",
4242 // OBSOLETE   "creat",
4243 // OBSOLETE   "mknod",
4244 // OBSOLETE   "link",
4245 // OBSOLETE   "symlink",
4246 // OBSOLETE   "unlink",
4247 // OBSOLETE   "access",
4248 // OBSOLETE   "stat",
4249 // OBSOLETE   "readlink",
4250 // OBSOLETE   "chmod",
4251 // OBSOLETE   "chown",
4252 // OBSOLETE   "utimes",
4253 // OBSOLETE   "truncate",
4254 // OBSOLETE   "rename",
4255 // OBSOLETE   "mkdir",
4256 // OBSOLETE   "rmdir",
4257 // OBSOLETE   "xutimes",
4258 // OBSOLETE   "mount",
4259 // OBSOLETE   "umount",
4260 // OBSOLETE   "acct",
4261 // OBSOLETE   "setquota",
4262 // OBSOLETE   "write_short",
4263 // OBSOLETE   "write_long",
4264 // OBSOLETE   "send_short",
4265 // OBSOLETE   "send_long",
4266 // OBSOLETE   "sendto_short",
4267 // OBSOLETE   "sendto_long",
4268 // OBSOLETE   "select",
4269 // OBSOLETE   "task_by_pid",
4270 // OBSOLETE   "recvfrom_short",
4271 // OBSOLETE   "recvfrom_long",
4272 // OBSOLETE   "setgroups",
4273 // OBSOLETE   "setrlimit",
4274 // OBSOLETE   "sigvec",
4275 // OBSOLETE   "sigstack",
4276 // OBSOLETE   "settimeofday",
4277 // OBSOLETE   "adjtime",
4278 // OBSOLETE   "setitimer",
4279 // OBSOLETE   "sethostname",
4280 // OBSOLETE   "bind",
4281 // OBSOLETE   "accept",
4282 // OBSOLETE   "connect",
4283 // OBSOLETE   "setsockopt",
4284 // OBSOLETE   "getsockopt",
4285 // OBSOLETE   "getsockname",
4286 // OBSOLETE   "getpeername",
4287 // OBSOLETE   "init_process",
4288 // OBSOLETE   "table_set",
4289 // OBSOLETE   "table_get",
4290 // OBSOLETE   "pioctl",
4291 // OBSOLETE   "emulator_error",
4292 // OBSOLETE   "readwrite",
4293 // OBSOLETE   "share_wakeup",
4294 // OBSOLETE   0,
4295 // OBSOLETE   "maprw_request_it",
4296 // OBSOLETE   "maprw_release_it",
4297 // OBSOLETE   "maprw_remap",
4298 // OBSOLETE   "pid_by_task",
4299 // OBSOLETE };
4300 // OBSOLETE 
4301 // OBSOLETE int bsd1_nnames = sizeof (bsd1_names) / sizeof (bsd1_names[0]);
4302 // OBSOLETE 
4303 // OBSOLETE char *
4304 // OBSOLETE name_str (int name, char *buf)
4305 // OBSOLETE {
4306 // OBSOLETE   switch (name)
4307 // OBSOLETE     {
4308 // OBSOLETE     case MACH_MSG_TYPE_BOOLEAN:
4309 // OBSOLETE       return "boolean";
4310 // OBSOLETE     case MACH_MSG_TYPE_INTEGER_16:
4311 // OBSOLETE       return "short";
4312 // OBSOLETE     case MACH_MSG_TYPE_INTEGER_32:
4313 // OBSOLETE       return "long";
4314 // OBSOLETE     case MACH_MSG_TYPE_CHAR:
4315 // OBSOLETE       return "char";
4316 // OBSOLETE     case MACH_MSG_TYPE_BYTE:
4317 // OBSOLETE       return "byte";
4318 // OBSOLETE     case MACH_MSG_TYPE_REAL:
4319 // OBSOLETE       return "real";
4320 // OBSOLETE     case MACH_MSG_TYPE_STRING:
4321 // OBSOLETE       return "string";
4322 // OBSOLETE     default:
4323 // OBSOLETE       sprintf (buf, "%d", name);
4324 // OBSOLETE       return buf;
4325 // OBSOLETE     }
4326 // OBSOLETE }
4327 // OBSOLETE 
4328 // OBSOLETE char *
4329 // OBSOLETE id_str (int id, char *buf)
4330 // OBSOLETE {
4331 // OBSOLETE   char *p;
4332 // OBSOLETE   if (id >= 101000 && id < 101000 + bsd1_nnames)
4333 // OBSOLETE     {
4334 // OBSOLETE       if (p = bsd1_names[id - 101000])
4335 // OBSOLETE     return p;
4336 // OBSOLETE     }
4337 // OBSOLETE   if (id == 102000)
4338 // OBSOLETE     return "psignal_retry";
4339 // OBSOLETE   if (id == 100000)
4340 // OBSOLETE     return "syscall";
4341 // OBSOLETE   sprintf (buf, "%d", id);
4342 // OBSOLETE   return buf;
4343 // OBSOLETE }
4344 // OBSOLETE 
4345 // OBSOLETE print_msg (mach_msg_header_t *mp)
4346 // OBSOLETE {
4347 // OBSOLETE   char *fmt_x = "%20s : 0x%08x\n";
4348 // OBSOLETE   char *fmt_d = "%20s : %10d\n";
4349 // OBSOLETE   char *fmt_s = "%20s : %s\n";
4350 // OBSOLETE   char buf[100];
4351 // OBSOLETE 
4352 // OBSOLETE   puts_filtered ("\n");
4353 // OBSOLETE #define pr(fmt,h,x) printf_filtered(fmt,STR(x),(h).x)
4354 // OBSOLETE   pr (fmt_x, (*mp), msgh_bits);
4355 // OBSOLETE   pr (fmt_d, (*mp), msgh_size);
4356 // OBSOLETE   pr (fmt_x, (*mp), msgh_remote_port);
4357 // OBSOLETE   pr (fmt_x, (*mp), msgh_local_port);
4358 // OBSOLETE   pr (fmt_d, (*mp), msgh_kind);
4359 // OBSOLETE   printf_filtered (fmt_s, STR (msgh_id), id_str (mp->msgh_id, buf));
4360 // OBSOLETE 
4361 // OBSOLETE   if (debug_level > 1)
4362 // OBSOLETE     {
4363 // OBSOLETE       char *p, *ep, *dp;
4364 // OBSOLETE       int plen;
4365 // OBSOLETE       p = (char *) mp;
4366 // OBSOLETE       ep = p + mp->msgh_size;
4367 // OBSOLETE       p += sizeof (*mp);
4368 // OBSOLETE       for (; p < ep; p += plen)
4369 // OBSOLETE     {
4370 // OBSOLETE       mach_msg_type_t *tp;
4371 // OBSOLETE       mach_msg_type_long_t *tlp;
4372 // OBSOLETE       int name, size, number;
4373 // OBSOLETE       tp = (mach_msg_type_t *) p;
4374 // OBSOLETE       if (tp->msgt_longform)
4375 // OBSOLETE         {
4376 // OBSOLETE           tlp = (mach_msg_type_long_t *) tp;
4377 // OBSOLETE           name = tlp->msgtl_name;
4378 // OBSOLETE           size = tlp->msgtl_size;
4379 // OBSOLETE           number = tlp->msgtl_number;
4380 // OBSOLETE           plen = sizeof (*tlp);
4381 // OBSOLETE         }
4382 // OBSOLETE       else
4383 // OBSOLETE         {
4384 // OBSOLETE           name = tp->msgt_name;
4385 // OBSOLETE           size = tp->msgt_size;
4386 // OBSOLETE           number = tp->msgt_number;
4387 // OBSOLETE           plen = sizeof (*tp);
4388 // OBSOLETE         }
4389 // OBSOLETE       printf_filtered ("name=%-16s size=%2d number=%7d inline=%d long=%d deal=%d\n",
4390 // OBSOLETE                     name_str (name, buf), size, number, tp->msgt_inline,
4391 // OBSOLETE                        tp->msgt_longform, tp->msgt_deallocate);
4392 // OBSOLETE       dp = p + plen;
4393 // OBSOLETE       if (tp->msgt_inline)
4394 // OBSOLETE         {
4395 // OBSOLETE           int l;
4396 // OBSOLETE           l = size * number / 8;
4397 // OBSOLETE           l = (l + sizeof (long) - 1) & ~((sizeof (long)) - 1);
4398 // OBSOLETE           plen += l;
4399 // OBSOLETE           print_data (dp, size, number);
4400 // OBSOLETE         }
4401 // OBSOLETE       else
4402 // OBSOLETE         {
4403 // OBSOLETE           plen += sizeof (int *);
4404 // OBSOLETE         }
4405 // OBSOLETE       printf_filtered ("plen=%d\n", plen);
4406 // OBSOLETE     }
4407 // OBSOLETE     }
4408 // OBSOLETE }
4409 // OBSOLETE 
4410 // OBSOLETE print_data (char *p, int size, int number)
4411 // OBSOLETE {
4412 // OBSOLETE   int *ip;
4413 // OBSOLETE   short *sp;
4414 // OBSOLETE   int i;
4415 // OBSOLETE 
4416 // OBSOLETE   switch (size)
4417 // OBSOLETE     {
4418 // OBSOLETE     case 8:
4419 // OBSOLETE       for (i = 0; i < number; i++)
4420 // OBSOLETE     {
4421 // OBSOLETE       printf_filtered (" %02x", p[i]);
4422 // OBSOLETE     }
4423 // OBSOLETE       break;
4424 // OBSOLETE     case 16:
4425 // OBSOLETE       sp = (short *) p;
4426 // OBSOLETE       for (i = 0; i < number; i++)
4427 // OBSOLETE     {
4428 // OBSOLETE       printf_filtered (" %04x", sp[i]);
4429 // OBSOLETE     }
4430 // OBSOLETE       break;
4431 // OBSOLETE     case 32:
4432 // OBSOLETE       ip = (int *) p;
4433 // OBSOLETE       for (i = 0; i < number; i++)
4434 // OBSOLETE     {
4435 // OBSOLETE       printf_filtered (" %08x", ip[i]);
4436 // OBSOLETE     }
4437 // OBSOLETE       break;
4438 // OBSOLETE     }
4439 // OBSOLETE   puts_filtered ("\n");
4440 // OBSOLETE }
4441 // OBSOLETE #endif /* DUMP_SYSCALL */
4442 // OBSOLETE 
4443 // OBSOLETE static void
4444 // OBSOLETE m3_stop (void)
4445 // OBSOLETE {
4446 // OBSOLETE   error ("to_stop target function not implemented");
4447 // OBSOLETE }
4448 // OBSOLETE 
4449 // OBSOLETE static char *
4450 // OBSOLETE m3_pid_to_exec_file (int pid)
4451 // OBSOLETE {
4452 // OBSOLETE   error ("to_pid_to_exec_file target function not implemented");
4453 // OBSOLETE   return NULL;                      /* To keep all compilers happy. */
4454 // OBSOLETE }
4455 // OBSOLETE 
4456 // OBSOLETE static void
4457 // OBSOLETE init_m3_ops (void)
4458 // OBSOLETE {
4459 // OBSOLETE   m3_ops.to_shortname = "mach";
4460 // OBSOLETE   m3_ops.to_longname = "Mach child process";
4461 // OBSOLETE   m3_ops.to_doc = "Mach child process (started by the \"run\" command).";
4462 // OBSOLETE   m3_ops.to_open = m3_open;
4463 // OBSOLETE   m3_ops.to_attach = m3_attach;
4464 // OBSOLETE   m3_ops.to_detach = m3_detach;
4465 // OBSOLETE   m3_ops.to_resume = m3_resume;
4466 // OBSOLETE   m3_ops.to_wait = mach_really_wait;
4467 // OBSOLETE   m3_ops.to_fetch_registers = fetch_inferior_registers;
4468 // OBSOLETE   m3_ops.to_store_registers = store_inferior_registers;
4469 // OBSOLETE   m3_ops.to_prepare_to_store = m3_prepare_to_store;
4470 // OBSOLETE   m3_ops.to_xfer_memory = m3_xfer_memory;
4471 // OBSOLETE   m3_ops.to_files_info = m3_files_info;
4472 // OBSOLETE   m3_ops.to_insert_breakpoint = memory_insert_breakpoint;
4473 // OBSOLETE   m3_ops.to_remove_breakpoint = memory_remove_breakpoint;
4474 // OBSOLETE   m3_ops.to_terminal_init = terminal_init_inferior;
4475 // OBSOLETE   m3_ops.to_terminal_inferior = terminal_inferior;
4476 // OBSOLETE   m3_ops.to_terminal_ours_for_output = terminal_ours_for_output;
4477 // OBSOLETE   m3_ops.to_terminal_save_ours = terminal_save_ours;
4478 // OBSOLETE   m3_ops.to_terminal_ours = terminal_ours;
4479 // OBSOLETE   m3_ops.to_terminal_info = child_terminal_info;
4480 // OBSOLETE   m3_ops.to_kill = m3_kill_inferior;
4481 // OBSOLETE   m3_ops.to_create_inferior = m3_create_inferior;
4482 // OBSOLETE   m3_ops.to_mourn_inferior = m3_mourn_inferior;
4483 // OBSOLETE   m3_ops.to_can_run = m3_can_run;
4484 // OBSOLETE   m3_ops.to_stop = m3_stop;
4485 // OBSOLETE   m3_ops.to_pid_to_exec_file = m3_pid_to_exec_file;
4486 // OBSOLETE   m3_ops.to_stratum = process_stratum;
4487 // OBSOLETE   m3_ops.to_has_all_memory = 1;
4488 // OBSOLETE   m3_ops.to_has_memory = 1;
4489 // OBSOLETE   m3_ops.to_has_stack = 1;
4490 // OBSOLETE   m3_ops.to_has_registers = 1;
4491 // OBSOLETE   m3_ops.to_has_execution = 1;
4492 // OBSOLETE   m3_ops.to_magic = OPS_MAGIC;
4493 // OBSOLETE }
4494 // OBSOLETE 
4495 // OBSOLETE void
4496 // OBSOLETE _initialize_m3_nat (void)
4497 // OBSOLETE {
4498 // OBSOLETE   kern_return_t ret;
4499 // OBSOLETE 
4500 // OBSOLETE   init_m3_ops ();
4501 // OBSOLETE   add_target (&m3_ops);
4502 // OBSOLETE 
4503 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
4504 // OBSOLETE                         MACH_PORT_RIGHT_PORT_SET,
4505 // OBSOLETE                         &inferior_wait_port_set);
4506 // OBSOLETE   if (ret != KERN_SUCCESS)
4507 // OBSOLETE     internal_error (__FILE__, __LINE__,
4508 // OBSOLETE                 "initial port set %s", mach_error_string (ret));
4509 // OBSOLETE 
4510 // OBSOLETE   /* mach_really_wait now waits for this */
4511 // OBSOLETE   currently_waiting_for = inferior_wait_port_set;
4512 // OBSOLETE 
4513 // OBSOLETE   ret = netname_look_up (name_server_port, hostname, "MachID", &mid_server);
4514 // OBSOLETE   if (ret != KERN_SUCCESS)
4515 // OBSOLETE     {
4516 // OBSOLETE       mid_server = MACH_PORT_NULL;
4517 // OBSOLETE 
4518 // OBSOLETE       warning ("initialize machid: netname_lookup_up(MachID) : %s",
4519 // OBSOLETE            mach_error_string (ret));
4520 // OBSOLETE       warning ("Some (most?) features disabled...");
4521 // OBSOLETE     }
4522 // OBSOLETE 
4523 // OBSOLETE   mid_auth = mach_privileged_host_port ();
4524 // OBSOLETE   if (mid_auth == MACH_PORT_NULL)
4525 // OBSOLETE     mid_auth = mach_task_self ();
4526 // OBSOLETE 
4527 // OBSOLETE   obstack_init (port_chain_obstack);
4528 // OBSOLETE 
4529 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
4530 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
4531 // OBSOLETE                         &thread_exception_port);
4532 // OBSOLETE   CHK ("Creating thread_exception_port for single stepping", ret);
4533 // OBSOLETE 
4534 // OBSOLETE   ret = mach_port_insert_right (mach_task_self (),
4535 // OBSOLETE                             thread_exception_port,
4536 // OBSOLETE                             thread_exception_port,
4537 // OBSOLETE                             MACH_MSG_TYPE_MAKE_SEND);
4538 // OBSOLETE   CHK ("Inserting send right to thread_exception_port", ret);
4539 // OBSOLETE 
4540 // OBSOLETE   /* Allocate message port */
4541 // OBSOLETE   ret = mach_port_allocate (mach_task_self (),
4542 // OBSOLETE                         MACH_PORT_RIGHT_RECEIVE,
4543 // OBSOLETE                         &our_message_port);
4544 // OBSOLETE   if (ret != KERN_SUCCESS)
4545 // OBSOLETE     warning ("Creating message port %s", mach_error_string (ret));
4546 // OBSOLETE   else
4547 // OBSOLETE     {
4548 // OBSOLETE       char buf[MAX_NAME_LEN];
4549 // OBSOLETE       ret = mach_port_move_member (mach_task_self (),
4550 // OBSOLETE                                our_message_port,
4551 // OBSOLETE                                inferior_wait_port_set);
4552 // OBSOLETE       if (ret != KERN_SUCCESS)
4553 // OBSOLETE     warning ("message move member %s", mach_error_string (ret));
4554 // OBSOLETE 
4555 // OBSOLETE 
4556 // OBSOLETE       /* @@@@ No way to change message port name currently */
4557 // OBSOLETE       /* Foo. This assumes gdb has a unix pid */
4558 // OBSOLETE       sprintf (buf, "gdb-%d", getpid ());
4559 // OBSOLETE       gdb_register_port (buf, our_message_port);
4560 // OBSOLETE     }
4561 // OBSOLETE 
4562 // OBSOLETE   /* Heap for thread commands */
4563 // OBSOLETE   obstack_init (cproc_obstack);
4564 // OBSOLETE 
4565 // OBSOLETE   add_mach_specific_commands ();
4566 // OBSOLETE }