1 // OBSOLETE /* Interface GDB to Mach 3.0 operating systems.
2 // OBSOLETE (Most) Mach 3.0 related routines live in this file.
4 // OBSOLETE Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
5 // OBSOLETE 2002 Free Software Foundation, Inc.
7 // OBSOLETE This file is part of GDB.
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.
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.
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. */
26 // OBSOLETE * Computing Centre
27 // OBSOLETE * Helsinki University of Technology
30 // OBSOLETE * Thanks to my friends who helped with ideas and testing:
32 // OBSOLETE * Johannes Helander, Antti Louko, Tero Mononen,
35 // OBSOLETE * Tero Kivinen and Eamonn McManus
40 // OBSOLETE #include <stdio.h>
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>
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"
63 // OBSOLETE #include <servers/machid_lib.h>
65 // OBSOLETE #define MACH_TYPE_TASK 1
66 // OBSOLETE #define MACH_TYPE_THREAD 2
69 // OBSOLETE /* Included only for signal names and NSIG
71 // OBSOLETE * note: There are many problems in signal handling with
72 // OBSOLETE * gdb in Mach 3.0 in general.
74 // OBSOLETE #include <signal.h>
75 // OBSOLETE #define SIG_UNKNOWN 0 /* Exception that has no matching unix signal */
77 // OBSOLETE #include <cthreads.h>
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
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)
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
118 // OBSOLETE /* For cproc and kernel thread mapping */
119 // OBSOLETE typedef struct gdb_thread
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;
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;
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;
143 // OBSOLETE *gdb_thread_t;
146 // OBSOLETE * Actions for Mach exceptions.
148 // OBSOLETE * sigmap field maps the exception to corresponding Unix signal.
150 // OBSOLETE * I do not know how to map the exception to unix signal
151 // OBSOLETE * if SIG_UNKNOWN is specified.
154 // OBSOLETE struct exception_list
156 // OBSOLETE char *name;
157 // OBSOLETE boolean_t forward;
158 // OBSOLETE boolean_t print;
159 // OBSOLETE int sigmap;
161 // OBSOLETE exception_map[] =
164 // OBSOLETE "not_mach3_exception", FALSE, TRUE, SIG_UNKNOWN
168 // OBSOLETE "EXC_BAD_ACCESS", FALSE, TRUE, SIGSEGV
172 // OBSOLETE "EXC_BAD_INSTRUCTION", FALSE, TRUE, SIGILL
176 // OBSOLETE "EXC_ARITHMETIC", FALSE, TRUE, SIGFPE
180 // OBSOLETE "EXC_EMULATION", FALSE, TRUE, SIGEMT
182 // OBSOLETE , /* ??? */
184 // OBSOLETE "EXC_SOFTWARE", FALSE, TRUE, SIG_UNKNOWN
188 // OBSOLETE "EXC_BREAKPOINT", FALSE, FALSE, SIGTRAP
192 // OBSOLETE /* Mach exception table size */
193 // OBSOLETE int max_exception = sizeof (exception_map) / sizeof (struct exception_list) - 1;
195 // OBSOLETE #define MAX_EXCEPTION max_exception
197 // OBSOLETE WAITTYPE wait_status;
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
203 // OBSOLETE /* #define DUMP_SYSCALL /* debugging interceptor */
205 // OBSOLETE /* xx_debug() outputs messages if this is nonzero.
206 // OBSOLETE * If > 1, DUMP_SYSCALL will dump message contents.
208 // OBSOLETE int debug_level = 0;
210 // OBSOLETE /* "Temporary" debug stuff */
212 // OBSOLETE xx_debug (char *fmt, int a, int b, int c)
214 // OBSOLETE if (debug_level)
215 // OBSOLETE warning (fmt, a, b, c);
218 // OBSOLETE /* This is in libmach.a */
219 // OBSOLETE extern mach_port_t name_server_port;
221 // OBSOLETE /* Set in catch_exception_raise */
222 // OBSOLETE int stop_exception, stop_code, stop_subcode;
223 // OBSOLETE int stopped_in_exception;
225 // OBSOLETE /* Thread that was the active thread when we stopped */
226 // OBSOLETE thread_t stop_thread = MACH_PORT_NULL;
228 // OBSOLETE char *hostname = "";
230 // OBSOLETE /* Set when task is attached or created */
231 // OBSOLETE boolean_t emulator_present = FALSE;
233 // OBSOLETE task_t inferior_task;
234 // OBSOLETE thread_t current_thread;
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;
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;
244 // OBSOLETE /* This is "inferior_wait_port_set" when not single stepping, and
245 // OBSOLETE * "singlestepped_thread_port" when we are single stepping.
247 // OBSOLETE * This is protected by a cleanup function: discard_single_step()
249 // OBSOLETE mach_port_t currently_waiting_for = MACH_PORT_NULL;
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
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)
261 // OBSOLETE * (top-gdb) set stop_inferior_gdb ()
262 // OBSOLETE * (top-gdb) continue
264 // OBSOLETE mach_port_t our_message_port = MACH_PORT_NULL;
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;
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;
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.
278 // OBSOLETE int must_suspend_thread = 0;
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.
285 // OBSOLETE #define NULL_CLEANUP (struct cleanup *)0
286 // OBSOLETE struct cleanup *cleanup_step = NULL_CLEANUP;
289 // OBSOLETE static struct target_ops m3_ops;
291 // OBSOLETE static void m3_kill_inferior ();
294 // OBSOLETE #define MACH_TYPE_EXCEPTION_PORT -1
297 // OBSOLETE /* Chain of ports to remember requested notifications. */
299 // OBSOLETE struct port_chain
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 */
307 // OBSOLETE typedef struct port_chain *port_chain_t;
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;
313 // OBSOLETE /* For thread handling */
314 // OBSOLETE struct obstack Cproc_obstack;
315 // OBSOLETE struct obstack *cproc_obstack = &Cproc_obstack;
317 // OBSOLETE /* the list of notified ports */
318 // OBSOLETE port_chain_t notify_chain = (port_chain_t) NULL;
320 // OBSOLETE port_chain_t
321 // OBSOLETE port_chain_insert (port_chain_t list, mach_port_t name, int type)
323 // OBSOLETE kern_return_t ret;
324 // OBSOLETE port_chain_t new;
327 // OBSOLETE if (!MACH_PORT_VALID (name))
328 // OBSOLETE return list;
330 // OBSOLETE if (type == MACH_TYPE_TASK || type == MACH_TYPE_THREAD)
332 // OBSOLETE if (!MACH_PORT_VALID (mid_server))
334 // OBSOLETE warning ("Machid server port invalid, can not map port 0x%x to MID",
336 // OBSOLETE mid = name;
340 // OBSOLETE ret = machid_mach_register (mid_server, mid_auth, name, type, &mid);
342 // OBSOLETE if (ret != KERN_SUCCESS)
344 // OBSOLETE warning ("Can not map name (0x%x) to MID with machid", name);
345 // OBSOLETE mid = name;
350 // OBSOLETE internal_error (__FILE__, __LINE__, "failed internal consistency check");
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;
359 // OBSOLETE return new;
362 // OBSOLETE port_chain_t
363 // OBSOLETE port_chain_delete (port_chain_t list, mach_port_t elem)
365 // OBSOLETE if (list)
366 // OBSOLETE if (list->port == elem)
367 // OBSOLETE list = list->next;
369 // OBSOLETE while (list->next)
371 // OBSOLETE if (list->next->port == elem)
372 // OBSOLETE list->next = list->next->next; /* GCd with obstack_free() */
374 // OBSOLETE list = list->next;
376 // OBSOLETE return list;
380 // OBSOLETE port_chain_destroy (struct obstack *ostack)
382 // OBSOLETE obstack_free (ostack, 0);
383 // OBSOLETE obstack_init (ostack);
386 // OBSOLETE port_chain_t
387 // OBSOLETE port_chain_member (port_chain_t list, mach_port_t elem)
389 // OBSOLETE while (list)
391 // OBSOLETE if (list->port == elem)
392 // OBSOLETE return list;
393 // OBSOLETE list = list->next;
395 // OBSOLETE return (port_chain_t) NULL;
399 // OBSOLETE map_port_name_to_mid (mach_port_t name, int type)
401 // OBSOLETE port_chain_t elem;
403 // OBSOLETE if (!MACH_PORT_VALID (name))
404 // OBSOLETE return -1;
406 // OBSOLETE elem = port_chain_member (notify_chain, name);
408 // OBSOLETE if (elem && (elem->type == type))
409 // OBSOLETE return elem->mid;
411 // OBSOLETE if (elem)
412 // OBSOLETE return -1;
414 // OBSOLETE if (!MACH_PORT_VALID (mid_server))
416 // OBSOLETE warning ("Machid server port invalid, can not map port 0x%x to mid",
418 // OBSOLETE return -1;
423 // OBSOLETE kern_return_t ret;
425 // OBSOLETE ret = machid_mach_register (mid_server, mid_auth, name, type, &mid);
427 // OBSOLETE if (ret != KERN_SUCCESS)
429 // OBSOLETE warning ("Can not map name (0x%x) to mid with machid", name);
430 // OBSOLETE return -1;
432 // OBSOLETE return mid;
436 // OBSOLETE /* Guard for currently_waiting_for and singlestepped_thread_port */
437 // OBSOLETE static void
438 // OBSOLETE discard_single_step (thread_t thread)
440 // OBSOLETE currently_waiting_for = inferior_wait_port_set;
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);
447 // OBSOLETE setup_single_step (thread_t thread, boolean_t start_step)
449 // OBSOLETE kern_return_t ret;
451 // OBSOLETE if (!MACH_PORT_VALID (thread))
452 // OBSOLETE error ("Invalid thread supplied to setup_single_step");
455 // OBSOLETE mach_port_t teport;
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);
461 // OBSOLETE if (start_step)
463 // OBSOLETE if (MACH_PORT_VALID (singlestepped_thread_port))
465 // OBSOLETE warning ("Singlestepped_thread_port (0x%x) is still valid?",
466 // OBSOLETE singlestepped_thread_port);
467 // OBSOLETE singlestepped_thread_port = MACH_PORT_NULL;
470 // OBSOLETE /* If we are already stepping this thread */
471 // OBSOLETE if (MACH_PORT_VALID (teport) && teport == thread_exception_port)
473 // OBSOLETE ret = mach_port_deallocate (mach_task_self (), teport);
474 // OBSOLETE CHK ("Could not deallocate thread exception port", ret);
478 // OBSOLETE ret = thread_set_exception_port (thread, thread_exception_port);
479 // OBSOLETE CHK ("Setting exception port for thread", ret);
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",
488 // OBSOLETE thread_saved_exception_port = teport;
491 // OBSOLETE thread_trace (thread, TRUE);
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);
499 // OBSOLETE if (!MACH_PORT_VALID (teport))
500 // OBSOLETE error ("Single stepped thread had an invalid exception port?");
502 // OBSOLETE if (teport != thread_exception_port)
503 // OBSOLETE error ("Single stepped thread had an unknown exception port?");
505 // OBSOLETE ret = mach_port_deallocate (mach_task_self (), teport);
506 // OBSOLETE CHK ("Couldn't deallocate thread exception port", ret);
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",
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);
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);
524 // OBSOLETE thread_trace (thread, FALSE);
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);
535 // OBSOLETE request_notify (mach_port_t name, mach_msg_id_t variant, int type)
537 // OBSOLETE kern_return_t ret;
538 // OBSOLETE mach_port_t previous_port_dummy = MACH_PORT_NULL;
540 // OBSOLETE if (!MACH_PORT_VALID (name))
543 // OBSOLETE if (port_chain_member (notify_chain, name))
546 // OBSOLETE ret = mach_port_request_notification (mach_task_self (),
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);
555 // OBSOLETE (void) mach_port_deallocate (mach_task_self (),
556 // OBSOLETE previous_port_dummy);
558 // OBSOLETE notify_chain = port_chain_insert (notify_chain, name, type);
561 // OBSOLETE reverse_msg_bits (mach_msg_header_t *msgp, int type)
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);
571 // OBSOLETE /* On the third day He said:
573 // OBSOLETE Let this be global
574 // OBSOLETE and then it was global.
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.
581 // OBSOLETE The name is transferred to our address space
582 // OBSOLETE with mach3_read_inferior().
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.
589 // OBSOLETE For blessed are the meek, as they shall inherit
590 // OBSOLETE the address space.
592 // OBSOLETE mach_port_t original_server_port_name = MACH_PORT_NULL;
595 // OBSOLETE /* Called from inferior after FORK but before EXEC */
596 // OBSOLETE static void
597 // OBSOLETE m3_trace_me (void)
599 // OBSOLETE kern_return_t ret;
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");
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");
620 // OBSOLETE * Intercept system calls to Unix server.
621 // OBSOLETE * After EXEC_COUNTER calls to exec(), return.
623 // OBSOLETE * Pre-assertion: Child is suspended. (Not verified)
624 // OBSOLETE * Post-condition: Child is suspended after EXEC_COUNTER exec() calls.
628 // OBSOLETE intercept_exec_calls (int exec_counter)
630 // OBSOLETE int terminal_initted = 0;
632 // OBSOLETE struct syscall_msg_t
634 // OBSOLETE mach_msg_header_t header;
635 // OBSOLETE mach_msg_type_t type;
636 // OBSOLETE char room[2000]; /* Enuff space */
639 // OBSOLETE struct syscall_msg_t syscall_in, syscall_out;
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;
651 // OBSOLETE kern_return_t ret;
653 // OBSOLETE if (exec_counter <= 0)
654 // OBSOLETE return; /* We are already set up in the correct program */
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);
661 // OBSOLETE /* Wait for inferior_task to suspend itself */
662 // OBSOLETE while (1)
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);
671 // OBSOLETE if (info.suspend_count)
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.
677 // OBSOLETE (void) swtch_pri (42); /* Universal Priority Value */
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");
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);
696 // OBSOLETE if (acquired != MACH_MSG_TYPE_PORT_SEND)
697 // OBSOLETE error ("Incorrect right extracted, send right to bsd server expected");
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);
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);
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);
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);
723 // OBSOLETE if (acquired != MACH_MSG_TYPE_PORT_SEND_ONCE)
724 // OBSOLETE error ("Incorrect right extracted, send once expected for exec reply");
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);
731 // OBSOLETE xx_debug ("syscall fake server set up, resuming inferior\n");
733 // OBSOLETE ret = task_resume (inferior_task);
734 // OBSOLETE CHK ("task_resume (startup)", ret);
736 // OBSOLETE /* Read requests from the inferior.
737 // OBSOLETE Pass directly through everything else except exec() calls.
739 // OBSOLETE while (exec_counter > 0)
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);
750 // OBSOLETE #ifdef DUMP_SYSCALL
751 // OBSOLETE print_msg (&syscall_in.header);
754 // OBSOLETE /* ASSERT : msgh_local_port == fake_server */
756 // OBSOLETE if (notify_server (&syscall_in.header, &syscall_out.header))
757 // OBSOLETE error ("received a notify while intercepting syscalls");
759 // OBSOLETE if (syscall_in.header.msgh_id == MIG_EXEC_SYSCALL_ID)
761 // OBSOLETE xx_debug ("Received EXEC SYSCALL, counter = %d\n", exec_counter);
762 // OBSOLETE if (exec_counter == 1)
764 // OBSOLETE original_exec_reply = syscall_in.header.msgh_remote_port;
765 // OBSOLETE syscall_in.header.msgh_remote_port = exec_reply_send;
768 // OBSOLETE if (!terminal_initted)
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. */
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 ();
778 // OBSOLETE /* Install inferior's terminal modes. */
779 // OBSOLETE target_terminal_inferior ();
781 // OBSOLETE terminal_initted = 1;
784 // OBSOLETE exec_counter--;
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;
790 // OBSOLETE reverse_msg_bits (&syscall_in.header, MACH_MSG_TYPE_COPY_SEND);
792 // OBSOLETE ret = mach_msg_send (&syscall_in.header);
793 // OBSOLETE CHK ("Forwarded syscall", ret);
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);
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);
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);
815 // OBSOLETE ret = task_suspend (inferior_task);
816 // OBSOLETE CHK ("Suspending inferior after last exec", ret);
818 // OBSOLETE must_suspend_thread = 0;
820 // OBSOLETE xx_debug ("Received exec reply from bsd server, suspended inferior task\n");
822 // OBSOLETE #ifdef DUMP_SYSCALL
823 // OBSOLETE print_msg (&syscall_in.header);
826 // OBSOLETE /* Message should appear as if it came from the unix server */
827 // OBSOLETE syscall_in.header.msgh_local_port = MACH_PORT_NULL;
829 // OBSOLETE /* and go to the inferior task original reply port */
830 // OBSOLETE syscall_in.header.msgh_remote_port = original_exec_reply;
832 // OBSOLETE reverse_msg_bits (&syscall_in.header, MACH_MSG_TYPE_MOVE_SEND_ONCE);
834 // OBSOLETE ret = mach_msg_send (&syscall_in.header);
835 // OBSOLETE CHK ("Forwarding exec reply to inferior", ret);
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);
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);
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);
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);
858 // OBSOLETE xx_debug ("Done with exec call interception\n");
862 // OBSOLETE consume_send_rights (thread_array_t thread_list, int thread_count)
864 // OBSOLETE int index;
866 // OBSOLETE if (!thread_count)
869 // OBSOLETE for (index = 0; index < thread_count; index++)
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]);
877 // OBSOLETE /* suspend/abort/resume a thread. */
878 // OBSOLETE setup_thread (mach_port_t thread, int what)
880 // OBSOLETE kern_return_t ret;
882 // OBSOLETE if (what)
884 // OBSOLETE ret = thread_suspend (thread);
885 // OBSOLETE CHK ("setup_thread thread_suspend", ret);
887 // OBSOLETE ret = thread_abort (thread);
888 // OBSOLETE CHK ("setup_thread thread_abort", ret);
892 // OBSOLETE ret = thread_resume (thread);
893 // OBSOLETE CHK ("setup_thread thread_resume", ret);
898 // OBSOLETE map_slot_to_mid (int slot, thread_array_t threads, int thread_count)
900 // OBSOLETE kern_return_t ret;
901 // OBSOLETE int deallocate = 0;
902 // OBSOLETE int index;
905 // OBSOLETE if (!threads)
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);
912 // OBSOLETE if (slot < 0 || slot >= thread_count)
914 // OBSOLETE if (deallocate)
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)));
920 // OBSOLETE if (slot < 0)
921 // OBSOLETE error ("invalid slot number");
923 // OBSOLETE return -(slot + 1);
926 // OBSOLETE mid = map_port_name_to_mid (threads[slot], MACH_TYPE_THREAD);
928 // OBSOLETE if (deallocate)
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)));
935 // OBSOLETE return mid;
938 // OBSOLETE static int
939 // OBSOLETE parse_thread_id (char *arg, int thread_count, int slots)
941 // OBSOLETE kern_return_t ret;
943 // OBSOLETE int slot;
944 // OBSOLETE int index;
946 // OBSOLETE if (arg == 0)
947 // OBSOLETE return 0;
949 // OBSOLETE while (*arg && (*arg == ' ' || *arg == '\t'))
952 // OBSOLETE if (!*arg)
953 // OBSOLETE return 0;
955 // OBSOLETE /* Currently parse MID and @SLOTNUMBER */
956 // OBSOLETE if (*arg != '@')
958 // OBSOLETE mid = atoi (arg);
959 // OBSOLETE if (mid <= 0)
960 // OBSOLETE error ("valid thread mid expected");
961 // OBSOLETE return mid;
965 // OBSOLETE slot = atoi (arg);
967 // OBSOLETE if (slot < 0)
968 // OBSOLETE error ("invalid slot number");
970 // OBSOLETE /* If you want slot numbers to remain slot numbers, set slots.
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.
976 // OBSOLETE if (slots)
977 // OBSOLETE return -(slot + 1);
979 // OBSOLETE if (thread_count && slot >= thread_count)
980 // OBSOLETE return -(slot + 1);
982 // OBSOLETE mid = map_slot_to_mid (slot);
984 // OBSOLETE return mid;
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.
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.
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.
998 // OBSOLETE kern_return_t
999 // OBSOLETE select_thread (mach_port_t task, int thread_id, int flag)
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;
1007 // OBSOLETE if (thread_id < 0)
1008 // OBSOLETE error ("Can't select cprocs without kernel thread");
1010 // OBSOLETE ret = task_threads (task, &thread_list, &thread_count);
1011 // OBSOLETE if (ret != KERN_SUCCESS)
1013 // OBSOLETE warning ("Can not select a thread from a dead task");
1014 // OBSOLETE m3_kill_inferior ();
1015 // OBSOLETE return KERN_FAILURE;
1018 // OBSOLETE if (thread_count == 0)
1020 // OBSOLETE /* The task can not do anything anymore, but it still
1021 // OBSOLETE * exists as a container for memory and ports.
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;
1033 // OBSOLETE if (!thread_id || flag == 2)
1035 // OBSOLETE /* First thread or a slotnumber */
1036 // OBSOLETE if (!thread_id)
1037 // OBSOLETE new_thread = thread_list[0];
1040 // OBSOLETE if (thread_id < thread_count)
1041 // OBSOLETE new_thread = thread_list[thread_id];
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);
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))
1057 // OBSOLETE new_thread = thread_list[index];
1058 // OBSOLETE index = -1;
1062 // OBSOLETE if (index != -1)
1063 // OBSOLETE error ("No thread with mid %d", thread_id);
1066 // OBSOLETE /* Notify when the selected thread dies */
1067 // OBSOLETE request_notify (new_thread, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_THREAD);
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);
1074 // OBSOLETE if (!flag)
1075 // OBSOLETE current_thread = new_thread;
1079 // OBSOLETE if (MACH_PORT_VALID (current_thread))
1081 // OBSOLETE /* Store the gdb's view of the thread we are deselecting
1083 // OBSOLETE * @@ I think gdb updates registers immediately when they are
1084 // OBSOLETE * changed, so don't do this.
1086 // OBSOLETE ret = thread_abort (current_thread);
1087 // OBSOLETE CHK ("Could not abort system calls when saving state of old thread",
1089 // OBSOLETE target_prepare_to_store ();
1090 // OBSOLETE target_store_registers (-1);
1094 // OBSOLETE registers_changed ();
1096 // OBSOLETE current_thread = new_thread;
1098 // OBSOLETE ret = thread_abort (current_thread);
1099 // OBSOLETE CHK ("Could not abort system calls when selecting a thread", ret);
1101 // OBSOLETE stop_pc = read_pc ();
1102 // OBSOLETE flush_cached_frames ();
1104 // OBSOLETE select_frame (get_current_frame ());
1107 // OBSOLETE return KERN_SUCCESS;
1111 // OBSOLETE * Switch to use thread named NEW_THREAD.
1112 // OBSOLETE * Return it's MID
1115 // OBSOLETE switch_to_thread (thread_t new_thread)
1117 // OBSOLETE thread_t saved_thread = current_thread;
1118 // OBSOLETE int mid;
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)
1126 // OBSOLETE if (current_thread)
1127 // OBSOLETE current_thread = saved_thread;
1128 // OBSOLETE error ("Could not select thread %d", mid);
1131 // OBSOLETE return mid;
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.
1137 // OBSOLETE static int
1138 // OBSOLETE m3_trace_him (int pid)
1140 // OBSOLETE kern_return_t ret;
1142 // OBSOLETE push_target (&m3_ops);
1144 // OBSOLETE inferior_task = task_by_pid (pid);
1146 // OBSOLETE if (!MACH_PORT_VALID (inferior_task))
1147 // OBSOLETE error ("Can not map Unix pid %d to Mach task", pid);
1149 // OBSOLETE /* Clean up previous notifications and create new ones */
1150 // OBSOLETE setup_notify_port (1);
1152 // OBSOLETE /* When notification appears, the inferior task has died */
1153 // OBSOLETE request_notify (inferior_task, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_TASK);
1155 // OBSOLETE emulator_present = have_emulator_p (inferior_task);
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.
1161 // OBSOLETE select_thread (inferior_task, 0, 0);
1163 // OBSOLETE inferior_exception_port = MACH_PORT_NULL;
1165 // OBSOLETE setup_exception_port ();
1167 // OBSOLETE xx_debug ("Now the debugged task is created\n");
1169 // OBSOLETE /* One trap to exec the shell, one to exec the program being debugged. */
1170 // OBSOLETE intercept_exec_calls (2);
1172 // OBSOLETE return pid;
1175 // OBSOLETE setup_exception_port (void)
1177 // OBSOLETE kern_return_t ret;
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);
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);
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);
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);
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);
1206 // OBSOLETE ret = mach_port_deallocate (mach_task_self (),
1207 // OBSOLETE inferior_exception_port);
1208 // OBSOLETE CHK ("mack_port_deallocate", ret);
1211 // OBSOLETE /* When notify appears, the inferior_task's exception
1212 // OBSOLETE * port has been destroyed.
1214 // OBSOLETE * Not used, since the dead_name_notification already
1215 // OBSOLETE * appears when task dies.
1218 // OBSOLETE request_notify (inferior_exception_port,
1219 // OBSOLETE MACH_NOTIFY_NO_SENDERS,
1220 // OBSOLETE MACH_TYPE_EXCEPTION_PORT);
1224 // OBSOLETE /* Nonzero if gdb is waiting for a message */
1225 // OBSOLETE int mach_really_waiting;
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
1233 // OBSOLETE There is no other way to exit this loop.
1235 // OBSOLETE Returns the inferior_ptid for rest of gdb.
1236 // OBSOLETE Side effects: Set *OURSTATUS. */
1238 // OBSOLETE mach_really_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
1240 // OBSOLETE kern_return_t ret;
1243 // OBSOLETE struct msg
1245 // OBSOLETE mach_msg_header_t header;
1246 // OBSOLETE mach_msg_type_t foo;
1247 // OBSOLETE int data[8000];
1249 // OBSOLETE in_msg, out_msg;
1251 // OBSOLETE /* Either notify (death), exception or message can stop the inferior */
1252 // OBSOLETE stopped_in_exception = FALSE;
1254 // OBSOLETE while (1)
1258 // OBSOLETE stop_exception = stop_code = stop_subcode = -1;
1259 // OBSOLETE stop_thread = MACH_PORT_NULL;
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);
1272 // OBSOLETE /* Check if we received a notify of the childs' death */
1273 // OBSOLETE if (notify_server (&in_msg.header, &out_msg.header))
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;
1283 // OBSOLETE /* Collect Unix exit status for gdb */
1285 // OBSOLETE wait3 (&w, WNOHANG, 0);
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.
1294 // OBSOLETE if ((!WIFEXITED (w) && WIFSTOPPED (w)) ||
1295 // OBSOLETE (WIFEXITED (w) && WEXITSTATUS (w) > 0377))
1297 // OBSOLETE WSETEXIT (w, 0);
1298 // OBSOLETE warning ("Using exit value 0 for terminated task");
1300 // OBSOLETE else if (!WIFEXITED (w))
1302 // OBSOLETE int sig = WTERMSIG (w);
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)
1309 // OBSOLETE WSETEXIT (w, 0);
1310 // OBSOLETE warning ("Using exit value 0 for terminated task");
1313 // OBSOLETE store_waitstatus (ourstatus, w);
1314 // OBSOLETE return inferior_ptid;
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
1323 // OBSOLETE if (!exc_server (&in_msg.header, &out_msg.header))
1326 // OBSOLETE /* Not an exception, check for message.
1328 // OBSOLETE * Messages don't come from the inferior, or if they
1329 // OBSOLETE * do they better be asynchronous or it will hang.
1331 // OBSOLETE if (gdb_message_server (&in_msg.header))
1332 // OBSOLETE continue;
1334 // OBSOLETE error ("Unrecognized message received in mach_really_wait");
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);
1341 // OBSOLETE if (stopped_in_exception)
1343 // OBSOLETE /* Get unix state. May be changed in mach3_exception_actions() */
1344 // OBSOLETE wait3 (&w, WNOHANG, 0);
1346 // OBSOLETE mach3_exception_actions (&w, FALSE, "Task");
1348 // OBSOLETE store_waitstatus (ourstatus, w);
1349 // OBSOLETE return inferior_ptid;
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
1358 // OBSOLETE mach3_quit (void)
1360 // OBSOLETE int mid;
1361 // OBSOLETE kern_return_t ret;
1363 // OBSOLETE if (mach_really_waiting)
1365 // OBSOLETE ret = task_suspend (inferior_task);
1367 // OBSOLETE if (ret != KERN_SUCCESS)
1369 // OBSOLETE warning ("Could not suspend task for interrupt: %s",
1370 // OBSOLETE mach_error_string (ret));
1371 // OBSOLETE mach_really_waiting = 0;
1376 // OBSOLETE must_suspend_thread = 0;
1377 // OBSOLETE mach_really_waiting = 0;
1379 // OBSOLETE mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
1380 // OBSOLETE if (mid == -1)
1382 // OBSOLETE warning ("Selecting first existing kernel thread");
1383 // OBSOLETE mid = 0;
1386 // OBSOLETE current_thread = MACH_PORT_NULL; /* Force setup */
1387 // OBSOLETE select_thread (inferior_task, mid, 1);
1393 // OBSOLETE /* bogus bogus bogus. It is NOT OK to quit out of target_wait. */
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.
1399 // OBSOLETE * Called by REQUEST_QUIT() from utils.c(request_quit)
1402 // OBSOLETE mach3_request_quit (void)
1404 // OBSOLETE if (mach_really_waiting)
1405 // OBSOLETE immediate_quit = 1;
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.
1415 // OBSOLETE gdb_message_server (mach_msg_header_t *InP)
1417 // OBSOLETE kern_return_t ret;
1418 // OBSOLETE int mid;
1420 // OBSOLETE if (InP->msgh_local_port == our_message_port)
1422 // OBSOLETE /* A message coming to our_message_port. Check validity */
1423 // OBSOLETE switch (InP->msgh_id)
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));
1432 // OBSOLETE /* QUIT in mach_really_wait() loop. */
1433 // OBSOLETE request_quit (0);
1436 // OBSOLETE default:
1437 // OBSOLETE warning ("Invalid message id %d received, ignored.",
1438 // OBSOLETE InP->msgh_id);
1442 // OBSOLETE return 1;
1445 // OBSOLETE /* Message not handled by this server */
1446 // OBSOLETE return 0;
1449 // OBSOLETE /* NOTE: This is not an RPC call. It is a simpleroutine.
1451 // OBSOLETE * This is not called from this gdb code.
1453 // OBSOLETE * It may be called by another debugger to cause this
1454 // OBSOLETE * debugger to enter command level:
1456 // OBSOLETE * (gdb) set stop_inferior_gdb ()
1457 // OBSOLETE * (gdb) continue
1459 // OBSOLETE * External program "stop-gdb" implements this also.
1462 // OBSOLETE stop_inferior_gdb (void)
1464 // OBSOLETE kern_return_t ret;
1466 // OBSOLETE /* Code generated by mig, with minor cleanups :-)
1468 // OBSOLETE * simpleroutine stop_inferior_gdb (our_message_port : mach_port_t);
1471 // OBSOLETE typedef struct
1473 // OBSOLETE mach_msg_header_t Head;
1475 // OBSOLETE Request;
1477 // OBSOLETE Request Mess;
1479 // OBSOLETE register Request *InP = &Mess;
1481 // OBSOLETE InP->Head.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
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;
1489 // OBSOLETE ret = mach_msg (&InP->Head,
1490 // OBSOLETE MACH_SEND_MSG | MACH_MSG_OPTION_NONE,
1491 // OBSOLETE sizeof (Request),
1493 // OBSOLETE MACH_PORT_NULL,
1494 // OBSOLETE MACH_MSG_TIMEOUT_NONE,
1495 // OBSOLETE MACH_PORT_NULL);
1498 // OBSOLETE #ifdef THREAD_ALLOWED_TO_BREAK
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.
1507 // OBSOLETE mach_thread_for_breakpoint (int mid)
1509 // OBSOLETE int cmid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
1511 // OBSOLETE if (mid < 0)
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 */
1518 // OBSOLETE if (!mid || cmid == -1)
1519 // OBSOLETE return 1; /* stop */
1521 // OBSOLETE return cmid == mid && stop_exception == EXC_BREAKPOINT;
1523 // OBSOLETE #endif /* THREAD_ALLOWED_TO_BREAK */
1525 // OBSOLETE #ifdef THREAD_PARSE_ID
1527 // OBSOLETE * Map a thread id string (MID or a @SLOTNUMBER)
1528 // OBSOLETE * to a thread-id.
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)
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))
1541 // OBSOLETE mach_thread_parse_id (char *arg)
1543 // OBSOLETE int mid;
1544 // OBSOLETE if (arg == 0)
1545 // OBSOLETE error ("thread id expected");
1546 // OBSOLETE mid = parse_thread_id (arg, 0, 1);
1548 // OBSOLETE return mid;
1550 // OBSOLETE #endif /* THREAD_PARSE_ID */
1552 // OBSOLETE #ifdef THREAD_OUTPUT_ID
1554 // OBSOLETE mach_thread_output_id (int mid)
1556 // OBSOLETE static char foobar[20];
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));
1563 // OBSOLETE sprintf (foobar, "*any thread*");
1565 // OBSOLETE return foobar;
1567 // OBSOLETE #endif /* THREAD_OUTPUT_ID */
1569 // OBSOLETE /* Called with hook PREPARE_TO_PROCEED() from infrun.c.
1571 // OBSOLETE * If we have switched threads and stopped at breakpoint return 1 otherwise 0.
1573 // OBSOLETE * if SELECT_IT is nonzero, reselect the thread that was active when
1574 // OBSOLETE * we stopped at a breakpoint.
1576 // OBSOLETE * Note that this implementation is potentially redundant now that
1577 // OBSOLETE * default_prepare_to_proceed() has been added.
1579 // OBSOLETE * FIXME This may not support switching threads after Ctrl-C
1580 // OBSOLETE * correctly. The default implementation does support this.
1583 // OBSOLETE mach3_prepare_to_proceed (int select_it)
1585 // OBSOLETE if (stop_thread &&
1586 // OBSOLETE stop_thread != current_thread &&
1587 // OBSOLETE stop_exception == EXC_BREAKPOINT)
1589 // OBSOLETE int mid;
1591 // OBSOLETE if (!select_it)
1592 // OBSOLETE return 1;
1594 // OBSOLETE mid = switch_to_thread (stop_thread);
1596 // OBSOLETE return 1;
1599 // OBSOLETE return 0;
1602 // OBSOLETE /* this stuff here is an upcall via libmach/excServer.c
1603 // OBSOLETE and mach_really_wait which does the actual upcall.
1605 // OBSOLETE The code will pass the exception to the inferior if:
1607 // OBSOLETE - The task that signaled is not the inferior task
1608 // OBSOLETE (e.g. when debugging another debugger)
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)
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?)
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)
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);
1627 // OBSOLETE if (!MACH_PORT_VALID (thread))
1629 // OBSOLETE /* If the exception was sent and thread dies before we
1630 // OBSOLETE receive it, THREAD will be MACH_PORT_DEAD
1633 // OBSOLETE current_thread = thread = MACH_PORT_NULL;
1634 // OBSOLETE error ("Received exception from nonexistent thread");
1637 // OBSOLETE /* Check if the task died in transit.
1638 // OBSOLETE * @@ Isn't the thread also invalid in such case?
1640 // OBSOLETE if (!MACH_PORT_VALID (task))
1642 // OBSOLETE current_thread = thread = MACH_PORT_NULL;
1643 // OBSOLETE error ("Received exception from nonexistent task");
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,
1652 // OBSOLETE if (!MACH_PORT_VALID (inferior_task))
1653 // OBSOLETE error ("got an exception, but inferior_task is null or dead");
1655 // OBSOLETE stop_exception = exception;
1656 // OBSOLETE stop_code = code;
1657 // OBSOLETE stop_subcode = subcode;
1658 // OBSOLETE stop_thread = thread;
1660 // OBSOLETE signal_thread = exception != EXC_BREAKPOINT &&
1661 // OBSOLETE port == singlestepped_thread_port &&
1662 // OBSOLETE MACH_PORT_VALID (thread_saved_exception_port);
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
1667 // OBSOLETE * Note: If you have forwarded EXC_BREAKPOINT I trust you know why.
1669 // OBSOLETE if (task != inferior_task ||
1670 // OBSOLETE signal_thread ||
1671 // OBSOLETE exception_map[exception].forward)
1673 // OBSOLETE mach_port_t eport = inferior_old_exception_port;
1675 // OBSOLETE if (signal_thread)
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.
1683 // OBSOLETE mach3_exception_actions ((WAITTYPE *) NULL, TRUE, "Thread");
1684 // OBSOLETE eport = thread_saved_exception_port;
1687 // OBSOLETE /* Send the exception to the original handler */
1688 // OBSOLETE ret = exception_raise (eport,
1691 // OBSOLETE exception,
1693 // OBSOLETE subcode);
1695 // OBSOLETE (void) mach_port_deallocate (mach_task_self (), task);
1696 // OBSOLETE (void) mach_port_deallocate (mach_task_self (), thread);
1698 // OBSOLETE /* If we come here, we don't want to trace any more, since we
1699 // OBSOLETE * will never stop for tracing anyway.
1701 // OBSOLETE discard_single_step (thread);
1703 // OBSOLETE /* Do not stop the inferior */
1704 // OBSOLETE return ret;
1707 // OBSOLETE /* Now gdb handles the exception */
1708 // OBSOLETE stopped_in_exception = TRUE;
1710 // OBSOLETE ret = task_suspend (task);
1711 // OBSOLETE CHK ("Error suspending inferior after exception", ret);
1713 // OBSOLETE must_suspend_thread = 0;
1715 // OBSOLETE if (current_thread != thread)
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",
1721 // OBSOLETE map_port_name_to_mid (current_thread, MACH_TYPE_THREAD));
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);
1727 // OBSOLETE warning ("Gdb selected thread %d", mid);
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.
1734 // OBSOLETE if (MACH_PORT_VALID (singlestepped_thread_port))
1736 // OBSOLETE if (stop_exception != EXC_BREAKPOINT)
1737 // OBSOLETE warning ("Single step interrupted by exception");
1738 // OBSOLETE else if (port == singlestepped_thread_port)
1740 // OBSOLETE /* Single step exception occurred, remove trace bit
1741 // OBSOLETE * and return to gdb.
1743 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
1744 // OBSOLETE error ("Single stepped thread is not valid");
1746 // OBSOLETE /* Resume threads, but leave the task suspended */
1747 // OBSOLETE resume_all_threads (0);
1750 // OBSOLETE warning ("Breakpoint while single stepping?");
1752 // OBSOLETE discard_single_step (current_thread);
1755 // OBSOLETE (void) mach_port_deallocate (mach_task_self (), task);
1756 // OBSOLETE (void) mach_port_deallocate (mach_task_self (), thread);
1758 // OBSOLETE return KERN_SUCCESS;
1762 // OBSOLETE port_valid (mach_port_t port, int mask)
1764 // OBSOLETE kern_return_t ret;
1765 // OBSOLETE mach_port_type_t type;
1767 // OBSOLETE ret = mach_port_type (mach_task_self (),
1770 // OBSOLETE if (ret != KERN_SUCCESS || (type & mask) != mask)
1771 // OBSOLETE return 0;
1772 // OBSOLETE return 1;
1775 // OBSOLETE /* @@ No vm read cache implemented yet */
1776 // OBSOLETE boolean_t vm_read_cache_valid = FALSE;
1779 // OBSOLETE * Read inferior task's LEN bytes from ADDR and copy it to MYADDR
1780 // OBSOLETE * in gdb's address space.
1782 // OBSOLETE * Return 0 on failure; number of bytes read otherwise.
1785 // OBSOLETE mach3_read_inferior (CORE_ADDR addr, char *myaddr, int length)
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;
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 ©_count);
1800 // OBSOLETE if (ret != KERN_SUCCESS)
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!)
1809 // OBSOLETE if (!port_valid (inferior_task, MACH_PORT_TYPE_SEND))
1811 // OBSOLETE m3_kill_inferior ();
1812 // OBSOLETE error ("Inferior killed (task port invalid)");
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...
1822 // OBSOLETE warning ("[read inferior %x failed: %s]",
1823 // OBSOLETE addr, mach_error_string (ret));
1824 // OBSOLETE errno = 0;
1826 // OBSOLETE return 0;
1830 // OBSOLETE memcpy (myaddr, (char *) addr - low_address + copied_memory, length);
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);
1837 // OBSOLETE return length;
1840 // OBSOLETE #define CHK_GOTO_OUT(str,ret) \
1841 // OBSOLETE do if (ret != KERN_SUCCESS) { errstr = #str; goto out; } while(0)
1843 // OBSOLETE struct vm_region_list
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;
1851 // OBSOLETE struct obstack region_obstack;
1854 // OBSOLETE * Write inferior task's LEN bytes from ADDR and copy it to MYADDR
1855 // OBSOLETE * in gdb's address space.
1858 // OBSOLETE mach3_write_inferior (CORE_ADDR addr, char *myaddr, int length)
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;
1868 // OBSOLETE char *errstr = "Bug in mach3_write_inferior";
1870 // OBSOLETE struct vm_region_list *region_element;
1871 // OBSOLETE struct vm_region_list *region_head = (struct vm_region_list *) NULL;
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 ©_count);
1879 // OBSOLETE CHK_GOTO_OUT ("mach3_write_inferior vm_read failed", ret);
1881 // OBSOLETE deallocate++;
1883 // OBSOLETE memcpy ((char *) addr - low_address + copied_memory, myaddr, length);
1885 // OBSOLETE obstack_init (®ion_obstack);
1887 // OBSOLETE /* Do writes atomically.
1888 // OBSOLETE * First check for holes and unwritable memory.
1891 // OBSOLETE vm_size_t remaining_length = aligned_length;
1892 // OBSOLETE vm_address_t region_address = low_address;
1894 // OBSOLETE struct vm_region_list *scan;
1896 // OBSOLETE while (region_address < low_address + aligned_length)
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;
1907 // OBSOLETE ret = vm_region (inferior_task,
1908 // OBSOLETE ®ion_address,
1909 // OBSOLETE ®ion_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);
1918 // OBSOLETE /* Check for holes in memory */
1919 // OBSOLETE if (old_address != region_address)
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;
1928 // OBSOLETE if (!(max_protection & VM_PROT_WRITE))
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;
1937 // OBSOLETE /* Chain the regions for later use */
1938 // OBSOLETE region_element =
1939 // OBSOLETE (struct vm_region_list *)
1940 // OBSOLETE obstack_alloc (®ion_obstack, sizeof (struct vm_region_list));
1942 // OBSOLETE region_element->protection = protection;
1943 // OBSOLETE region_element->start = region_address;
1944 // OBSOLETE region_element->length = region_length;
1946 // OBSOLETE /* Chain the regions along with protections */
1947 // OBSOLETE region_element->next = region_head;
1948 // OBSOLETE region_head = region_element;
1950 // OBSOLETE region_address += region_length;
1951 // OBSOLETE remaining_length = remaining_length - region_length;
1954 // OBSOLETE /* If things fail after this, we give up.
1955 // OBSOLETE * Somebody is messing up inferior_task's mappings.
1958 // OBSOLETE /* Enable writes to the chained vm regions */
1959 // OBSOLETE for (scan = region_head; scan; scan = scan->next)
1961 // OBSOLETE boolean_t protection_changed = FALSE;
1963 // OBSOLETE if (!(scan->protection & VM_PROT_WRITE))
1965 // OBSOLETE ret = vm_protect (inferior_task,
1966 // OBSOLETE scan->start,
1967 // OBSOLETE scan->length,
1969 // OBSOLETE scan->protection | VM_PROT_WRITE);
1970 // OBSOLETE CHK_GOTO_OUT ("vm_protect: enable write failed", ret);
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);
1980 // OBSOLETE /* Set up the original region protections, if they were changed */
1981 // OBSOLETE for (scan = region_head; scan; scan = scan->next)
1983 // OBSOLETE boolean_t protection_changed = FALSE;
1985 // OBSOLETE if (!(scan->protection & VM_PROT_WRITE))
1987 // OBSOLETE ret = vm_protect (inferior_task,
1988 // OBSOLETE scan->start,
1989 // OBSOLETE scan->length,
1991 // OBSOLETE scan->protection);
1992 // OBSOLETE CHK_GOTO_OUT ("vm_protect: enable write failed", ret);
1998 // OBSOLETE if (deallocate)
2000 // OBSOLETE obstack_free (®ion_obstack, 0);
2002 // OBSOLETE (void) vm_deallocate (mach_task_self (),
2003 // OBSOLETE copied_memory,
2004 // OBSOLETE copy_count);
2007 // OBSOLETE if (ret != KERN_SUCCESS)
2009 // OBSOLETE warning ("%s %s", errstr, mach_error_string (ret));
2010 // OBSOLETE return 0;
2013 // OBSOLETE return length;
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)
2022 // OBSOLETE int result;
2024 // OBSOLETE if (write)
2025 // OBSOLETE result = mach3_write_inferior (memaddr, myaddr, len);
2027 // OBSOLETE result = mach3_read_inferior (memaddr, myaddr, len);
2029 // OBSOLETE return result;
2033 // OBSOLETE static char *
2034 // OBSOLETE translate_state (int state)
2036 // OBSOLETE switch (state)
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 ("?");
2053 // OBSOLETE static char *
2054 // OBSOLETE translate_cstate (int state)
2056 // OBSOLETE switch (state)
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 "?";
2073 // OBSOLETE /* type == MACH_MSG_TYPE_COPY_SEND || type == MACH_MSG_TYPE_MAKE_SEND */
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)
2078 // OBSOLETE kern_return_t ret;
2079 // OBSOLETE mach_msg_type_name_t acquired;
2080 // OBSOLETE mach_port_t iport;
2082 // OBSOLETE ret = mach_port_extract_right (inferior_task,
2083 // OBSOLETE inferior_name,
2086 // OBSOLETE &acquired);
2087 // OBSOLETE CHK ("mach_port_extract_right (map_inferior_port_name)", ret);
2089 // OBSOLETE if (acquired != MACH_MSG_TYPE_PORT_SEND)
2090 // OBSOLETE error ("Incorrect right extracted, (map_inferior_port_name)");
2092 // OBSOLETE ret = mach_port_deallocate (mach_task_self (),
2094 // OBSOLETE CHK ("Deallocating mapped port (map_inferior_port_name)", ret);
2096 // OBSOLETE return iport;
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
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.
2111 // OBSOLETE static char buf[7];
2113 // OBSOLETE static char *
2114 // OBSOLETE get_thread_name (gdb_thread_t one_cproc, int id)
2116 // OBSOLETE if (one_cproc)
2117 // OBSOLETE if (one_cproc->cthread == NULL)
2119 // OBSOLETE /* cproc not mapped to any cthread */
2120 // OBSOLETE sprintf (buf, "_C%d", id);
2122 // OBSOLETE else if (!one_cproc->cthread->name)
2124 // OBSOLETE /* cproc and cthread, but no name */
2125 // OBSOLETE sprintf (buf, "_t%d", id);
2128 // OBSOLETE return (char *) (one_cproc->cthread->name);
2131 // OBSOLETE if (id < 0)
2132 // OBSOLETE warning ("Inconsistency in thread name id %d", id);
2134 // OBSOLETE /* Kernel thread without cproc */
2135 // OBSOLETE sprintf (buf, "_K%d", id);
2138 // OBSOLETE return buf;
2142 // OBSOLETE fetch_thread_info (mach_port_t task, gdb_thread_t *mthreads_out)
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;
2150 // OBSOLETE ret = task_threads (task, &th_table, &th_count);
2151 // OBSOLETE if (ret != KERN_SUCCESS)
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;
2159 // OBSOLETE mthreads = (gdb_thread_t)
2160 // OBSOLETE obstack_alloc
2161 // OBSOLETE (cproc_obstack,
2162 // OBSOLETE th_count * sizeof (struct gdb_thread));
2164 // OBSOLETE for (index = 0; index < th_count; index++)
2166 // OBSOLETE thread_t saved_thread = MACH_PORT_NULL;
2167 // OBSOLETE int mid;
2169 // OBSOLETE if (must_suspend_thread)
2170 // OBSOLETE setup_thread (th_table[index], 1);
2172 // OBSOLETE if (th_table[index] != current_thread)
2174 // OBSOLETE saved_thread = current_thread;
2176 // OBSOLETE mid = switch_to_thread (th_table[index]);
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;
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 ();
2188 // OBSOLETE if (MACH_PORT_VALID (saved_thread))
2189 // OBSOLETE mid = switch_to_thread (saved_thread);
2191 // OBSOLETE if (must_suspend_thread)
2192 // OBSOLETE setup_thread (th_table[index], 0);
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)
2200 // OBSOLETE warning ("Error trying to deallocate thread list : %s",
2201 // OBSOLETE mach_error_string (ret));
2204 // OBSOLETE *mthreads_out = mthreads;
2206 // OBSOLETE return th_count;
2211 // OBSOLETE * Current emulator always saves the USP on top of
2212 // OBSOLETE * emulator stack below struct emul_stack_top stuff.
2214 // OBSOLETE CORE_ADDR
2215 // OBSOLETE fetch_usp_from_emulator_stack (CORE_ADDR sp)
2217 // OBSOLETE CORE_ADDR stack_pointer;
2219 // OBSOLETE sp = (sp & ~(EMULATOR_STACK_SIZE - 1)) +
2220 // OBSOLETE EMULATOR_STACK_SIZE - sizeof (struct emul_stack_top);
2222 // OBSOLETE if (mach3_read_inferior (sp,
2223 // OBSOLETE &stack_pointer,
2224 // OBSOLETE sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2226 // OBSOLETE warning ("Can't read user sp from emulator stack address 0x%x", sp);
2227 // OBSOLETE return 0;
2230 // OBSOLETE return stack_pointer;
2233 // OBSOLETE #ifdef MK67
2235 // OBSOLETE /* get_emulation_vector() interface was changed after mk67 */
2236 // OBSOLETE #define EMUL_VECTOR_COUNT 400 /* Value does not matter too much */
2238 // OBSOLETE #endif /* MK67 */
2240 // OBSOLETE /* Check if the emulator exists at task's address space.
2242 // OBSOLETE boolean_t
2243 // OBSOLETE have_emulator_p (task_t task)
2245 // OBSOLETE kern_return_t ret;
2246 // OBSOLETE #ifndef EMUL_VECTOR_COUNT
2247 // OBSOLETE vm_offset_t *emulation_vector;
2250 // OBSOLETE vm_offset_t emulation_vector[EMUL_VECTOR_COUNT];
2251 // OBSOLETE int n = EMUL_VECTOR_COUNT;
2254 // OBSOLETE int vector_start;
2256 // OBSOLETE ret = task_get_emulation_vector (task,
2257 // OBSOLETE &vector_start,
2258 // OBSOLETE #ifndef EMUL_VECTOR_COUNT
2259 // OBSOLETE &emulation_vector,
2261 // OBSOLETE emulation_vector,
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);
2268 // OBSOLETE for (i = 0; i < n; i++)
2270 // OBSOLETE vm_offset_t entry = emulation_vector[i];
2272 // OBSOLETE if (EMULATOR_BASE <= entry && entry <= EMULATOR_END)
2273 // OBSOLETE return TRUE;
2274 // OBSOLETE else if (entry)
2276 // OBSOLETE static boolean_t informed = FALSE;
2277 // OBSOLETE if (!informed)
2279 // OBSOLETE warning ("Emulation vector address 0x08%x outside emulator space",
2281 // OBSOLETE informed = TRUE;
2285 // OBSOLETE return FALSE;
2288 // OBSOLETE /* Map cprocs to kernel threads and vice versa. */
2291 // OBSOLETE map_cprocs_to_kernel_threads (gdb_thread_t cprocs, gdb_thread_t mthreads,
2292 // OBSOLETE int thread_count)
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;
2300 // OBSOLETE for (scan = cprocs; scan; scan = scan->next)
2302 // OBSOLETE /* Default to: no kernel thread for this cproc */
2303 // OBSOLETE scan->reverse_map = -1;
2305 // OBSOLETE /* Check if the cproc is found by its stack */
2306 // OBSOLETE for (index = 0; index < thread_count; index++)
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)
2317 // OBSOLETE (mthreads + index)->cproc = scan;
2318 // OBSOLETE scan->reverse_map = index;
2322 // OBSOLETE all_mapped &= (scan->reverse_map != -1);
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.
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.
2337 // OBSOLETE * Also set in_emulator for kernel threads.
2340 // OBSOLETE if (emulator_present)
2342 // OBSOLETE for (index = 0; index < thread_count; index++)
2344 // OBSOLETE CORE_ADDR emul_sp;
2345 // OBSOLETE CORE_ADDR usp;
2347 // OBSOLETE gdb_thread_t mthread = (mthreads + index);
2348 // OBSOLETE emul_sp = mthread->sp;
2350 // OBSOLETE if (mthread->cproc == NULL &&
2351 // OBSOLETE EMULATOR_BASE <= emul_sp && emul_sp <= EMULATOR_END)
2353 // OBSOLETE mthread->in_emulator = emulator_present;
2355 // OBSOLETE if (!all_mapped && cprocs)
2357 // OBSOLETE usp = fetch_usp_from_emulator_stack (emul_sp);
2359 // OBSOLETE /* @@ Could be more accurate */
2360 // OBSOLETE if (!usp)
2361 // OBSOLETE error ("Zero stack pointer read from emulator?");
2363 // OBSOLETE /* Try to match this stack pointer to the cprocs that
2364 // OBSOLETE * don't yet have a kernel thread.
2366 // OBSOLETE for (scan = cprocs; scan; scan = scan->next)
2369 // OBSOLETE /* Check is this unmapped CPROC stack contains
2370 // OBSOLETE * the user stack pointer saved in the
2371 // OBSOLETE * emulator.
2373 // OBSOLETE if (scan->reverse_map == -1)
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)
2386 // OBSOLETE mthread->cproc = scan;
2387 // OBSOLETE scan->reverse_map = index;
2399 // OBSOLETE * Format of the thread_list command
2401 // OBSOLETE * slot mid sel name emul ks susp cstate wired address
2403 // OBSOLETE #define TL_FORMAT "%-2.2s %5d%c %-10.10s %1.1s%s%-5.5s %-2.2s %-5.5s "
2405 // OBSOLETE #define TL_HEADER "\n@ MID Name KState CState Where\n"
2408 // OBSOLETE print_tl_address (struct ui_file *stream, CORE_ADDR pc)
2410 // OBSOLETE if (!lookup_minimal_symbol_by_pc (pc))
2411 // OBSOLETE fprintf_filtered (stream, local_hex_format (), pc);
2414 // OBSOLETE extern int addressprint;
2415 // OBSOLETE extern int asm_demangle;
2417 // OBSOLETE int store = addressprint;
2418 // OBSOLETE addressprint = 0;
2419 // OBSOLETE print_address_symbolic (pc, stream, asm_demangle, "");
2420 // OBSOLETE addressprint = store;
2424 // OBSOLETE /* For thread names, but also for gdb_message_port external name */
2425 // OBSOLETE #define MAX_NAME_LEN 50
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)
2431 // OBSOLETE struct symbol *sym;
2432 // OBSOLETE CORE_ADDR symaddr = 0;
2433 // OBSOLETE struct minimal_symbol *msymbol;
2435 // OBSOLETE sym = lookup_symbol (name,
2436 // OBSOLETE (struct block *) NULL,
2437 // OBSOLETE VAR_NAMESPACE,
2438 // OBSOLETE (int *) NULL,
2439 // OBSOLETE (struct symtab **) NULL);
2441 // OBSOLETE if (sym)
2442 // OBSOLETE symaddr = SYMBOL_VALUE (sym);
2444 // OBSOLETE if (!symaddr)
2446 // OBSOLETE msymbol = lookup_minimal_symbol (name, NULL, NULL);
2448 // OBSOLETE if (msymbol && msymbol->type == mst_data)
2449 // OBSOLETE symaddr = SYMBOL_VALUE_ADDRESS (msymbol);
2452 // OBSOLETE return symaddr;
2455 // OBSOLETE static gdb_thread_t
2456 // OBSOLETE get_cprocs (void)
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;
2466 // OBSOLETE buf = alloca (TARGET_PTR_BIT / HOST_CHAR_BIT);
2467 // OBSOLETE symaddr = lookup_address_of_variable ("cproc_list");
2469 // OBSOLETE if (!symaddr)
2471 // OBSOLETE /* cproc_list is not in a file compiled with debugging
2472 // OBSOLETE symbols, but don't give up yet */
2474 // OBSOLETE symaddr = lookup_address_of_variable ("cprocs");
2476 // OBSOLETE if (symaddr)
2478 // OBSOLETE static int informed = 0;
2479 // OBSOLETE if (!informed)
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.");
2489 // OBSOLETE /* Stripped or no -lthreads loaded or "cproc_list" is in wrong segment. */
2490 // OBSOLETE if (!symaddr)
2491 // OBSOLETE return NULL;
2493 // OBSOLETE /* Get the address of the first cproc in the task */
2494 // OBSOLETE if (!mach3_read_inferior (symaddr,
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);
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 */
2504 // OBSOLETE cproc_head = NULL;
2506 // OBSOLETE while (their_cprocs != (CORE_ADDR) 0)
2508 // OBSOLETE CORE_ADDR cproc_copy_incarnation;
2509 // OBSOLETE cproc_copy = (gdb_thread_t) obstack_alloc (cproc_obstack,
2510 // OBSOLETE sizeof (struct gdb_thread));
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);
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);
2524 // OBSOLETE if (cproc_copy_incarnation == (CORE_ADDR) 0)
2525 // OBSOLETE cproc_copy->cthread = NULL;
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));
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);
2538 // OBSOLETE cproc_copy->cthread = cthread;
2540 // OBSOLETE if (cthread->name)
2542 // OBSOLETE name = (char *) obstack_alloc (cproc_obstack, MAX_NAME_LEN);
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);
2547 // OBSOLETE cthread->name = name;
2551 // OBSOLETE /* insert in front */
2552 // OBSOLETE cproc_copy->next = cproc_head;
2553 // OBSOLETE cproc_head = cproc_copy;
2555 // OBSOLETE return cproc_head;
2558 // OBSOLETE #ifndef FETCH_CPROC_STATE
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).
2566 // OBSOLETE * If it doesn't, define your own routine.
2568 // OBSOLETE #define FETCH_CPROC_STATE(mth) mach3_cproc_state (mth)
2571 // OBSOLETE mach3_cproc_state (gdb_thread_t mthread)
2573 // OBSOLETE int context;
2575 // OBSOLETE if (!mthread || !mthread->cproc)
2576 // OBSOLETE return -1;
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;
2584 // OBSOLETE mthread->sp = context + MACHINE_CPROC_SP_OFFSET;
2586 // OBSOLETE if (mach3_read_inferior (context + MACHINE_CPROC_PC_OFFSET,
2587 // OBSOLETE &mthread->pc,
2588 // OBSOLETE sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2590 // OBSOLETE warning ("Can't read cproc pc from inferior");
2591 // OBSOLETE return -1;
2594 // OBSOLETE if (mach3_read_inferior (context + MACHINE_CPROC_FP_OFFSET,
2595 // OBSOLETE &mthread->fp,
2596 // OBSOLETE sizeof (CORE_ADDR)) != sizeof (CORE_ADDR))
2598 // OBSOLETE warning ("Can't read cproc fp from inferior");
2599 // OBSOLETE return -1;
2602 // OBSOLETE return 0;
2604 // OBSOLETE #endif /* FETCH_CPROC_STATE */
2608 // OBSOLETE thread_list_command (void)
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;
2624 // OBSOLETE int neworder = 1;
2626 // OBSOLETE char *fmt = "There are %d kernel threads in task %d.\n";
2628 // OBSOLETE int tmid = map_port_name_to_mid (inferior_task, MACH_TYPE_TASK);
2630 // OBSOLETE MACH_ERROR_NO_INFERIOR;
2632 // OBSOLETE thread_count = fetch_thread_info (inferior_task,
2633 // OBSOLETE &their_threads);
2634 // OBSOLETE if (thread_count == -1)
2637 // OBSOLETE if (thread_count == 1)
2638 // OBSOLETE fmt = "There is %d kernel thread in task %d.\n";
2640 // OBSOLETE printf_filtered (fmt, thread_count, tmid);
2642 // OBSOLETE puts_filtered (TL_HEADER);
2644 // OBSOLETE cprocs = get_cprocs ();
2646 // OBSOLETE map_cprocs_to_kernel_threads (cprocs, their_threads, thread_count);
2648 // OBSOLETE for (scan = cprocs; scan; scan = scan->next)
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);
2657 // OBSOLETE selected = ' ';
2659 // OBSOLETE /* a wired cproc? */
2660 // OBSOLETE wired = (extract_address (scan->raw_cproc + CPROC_WIRED_OFFSET,
2661 // OBSOLETE CPROC_WIRED_SIZE)
2662 // OBSOLETE ? "wired" : "");
2664 // OBSOLETE if (scan->reverse_map != -1)
2665 // OBSOLETE kthread = (their_threads + scan->reverse_map);
2667 // OBSOLETE kthread = NULL;
2669 // OBSOLETE if (kthread)
2671 // OBSOLETE /* These cprocs have a kernel thread */
2673 // OBSOLETE mid = map_port_name_to_mid (kthread->name, MACH_TYPE_THREAD);
2675 // OBSOLETE infoCnt = THREAD_BASIC_INFO_COUNT;
2677 // OBSOLETE ret = thread_info (kthread->name,
2678 // OBSOLETE THREAD_BASIC_INFO,
2679 // OBSOLETE (thread_info_t) & ths,
2680 // OBSOLETE &infoCnt);
2682 // OBSOLETE if (ret != KERN_SUCCESS)
2684 // OBSOLETE warning ("Unable to get basic info on thread %d : %s",
2686 // OBSOLETE mach_error_string (ret));
2687 // OBSOLETE continue;
2690 // OBSOLETE /* Who is the first to have more than 100 threads */
2691 // OBSOLETE sprintf (slot, "%d", kthread->slotid % 100);
2693 // OBSOLETE if (kthread->name == current_thread)
2694 // OBSOLETE selected = '*';
2696 // OBSOLETE if (ths.suspend_count)
2697 // OBSOLETE sprintf (buf, "%d", ths.suspend_count);
2699 // OBSOLETE buf[0] = '\000';
2702 // OBSOLETE if (ths.flags & TH_FLAGS_SWAPPED)
2703 // OBSOLETE strcat (buf, "S");
2706 // OBSOLETE if (ths.flags & TH_FLAGS_IDLE)
2707 // OBSOLETE strcat (buf, "I");
2709 // OBSOLETE printf_filtered (TL_FORMAT,
2712 // OBSOLETE selected,
2713 // OBSOLETE get_thread_name (scan, kthread->slotid),
2714 // OBSOLETE kthread->in_emulator ? "E" : "",
2715 // OBSOLETE translate_state (ths.run_state),
2717 // OBSOLETE translate_cstate (cproc_state),
2719 // OBSOLETE print_tl_address (gdb_stdout, kthread->pc);
2723 // OBSOLETE /* These cprocs don't have a kernel thread.
2724 // OBSOLETE * find out the calling frame with
2725 // OBSOLETE * FETCH_CPROC_STATE.
2728 // OBSOLETE struct gdb_thread state;
2731 // OBSOLETE /* jtv -> emcmanus: why do you want this here? */
2732 // OBSOLETE if (scan->incarnation == NULL)
2733 // OBSOLETE continue; /* EMcM */
2736 // OBSOLETE printf_filtered (TL_FORMAT,
2738 // OBSOLETE -neworder, /* Pseudo MID */
2739 // OBSOLETE selected,
2740 // OBSOLETE get_thread_name (scan, -neworder),
2742 // OBSOLETE "-", /* kernel state */
2744 // OBSOLETE translate_cstate (cproc_state),
2746 // OBSOLETE state.cproc = scan;
2748 // OBSOLETE if (FETCH_CPROC_STATE (&state) == -1)
2749 // OBSOLETE puts_filtered ("???");
2751 // OBSOLETE print_tl_address (gdb_stdout, state.pc);
2753 // OBSOLETE neworder++;
2755 // OBSOLETE puts_filtered ("\n");
2758 // OBSOLETE /* Scan for kernel threads without cprocs */
2759 // OBSOLETE for (index = 0; index < thread_count; index++)
2761 // OBSOLETE if (!their_threads[index].cproc)
2763 // OBSOLETE int mid;
2765 // OBSOLETE char buf[10];
2766 // OBSOLETE char slot[3];
2768 // OBSOLETE mach_port_t name = their_threads[index].name;
2770 // OBSOLETE mid = map_port_name_to_mid (name, MACH_TYPE_THREAD);
2772 // OBSOLETE infoCnt = THREAD_BASIC_INFO_COUNT;
2774 // OBSOLETE ret = thread_info (name,
2775 // OBSOLETE THREAD_BASIC_INFO,
2776 // OBSOLETE (thread_info_t) & ths,
2777 // OBSOLETE &infoCnt);
2779 // OBSOLETE if (ret != KERN_SUCCESS)
2781 // OBSOLETE warning ("Unable to get basic info on thread %d : %s",
2783 // OBSOLETE mach_error_string (ret));
2784 // OBSOLETE continue;
2787 // OBSOLETE sprintf (slot, "%d", index % 100);
2789 // OBSOLETE if (name == current_thread)
2790 // OBSOLETE selected = '*';
2792 // OBSOLETE selected = ' ';
2794 // OBSOLETE if (ths.suspend_count)
2795 // OBSOLETE sprintf (buf, "%d", ths.suspend_count);
2797 // OBSOLETE buf[0] = '\000';
2800 // OBSOLETE if (ths.flags & TH_FLAGS_SWAPPED)
2801 // OBSOLETE strcat (buf, "S");
2804 // OBSOLETE if (ths.flags & TH_FLAGS_IDLE)
2805 // OBSOLETE strcat (buf, "I");
2807 // OBSOLETE printf_filtered (TL_FORMAT,
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),
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");
2822 // OBSOLETE obstack_free (cproc_obstack, 0);
2823 // OBSOLETE obstack_init (cproc_obstack);
2827 // OBSOLETE thread_select_command (char *args, int from_tty)
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;
2835 // OBSOLETE MACH_ERROR_NO_INFERIOR;
2837 // OBSOLETE if (!args)
2838 // OBSOLETE error_no_arg ("MID or @SLOTNUMBER to specify a thread to select");
2840 // OBSOLETE while (*args == ' ' || *args == '\t')
2843 // OBSOLETE if (*args == '@')
2845 // OBSOLETE is_slot++;
2849 // OBSOLETE mid = atoi (args);
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");
2855 // OBSOLETE if (select_thread (inferior_task, mid, is_slot ? 2 : 1) != KERN_SUCCESS)
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);
2864 // OBSOLETE thread_trace (mach_port_t thread, boolean_t set)
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;
2871 // OBSOLETE if (!MACH_PORT_VALID (thread))
2873 // OBSOLETE warning ("thread_trace: invalid thread");
2877 // OBSOLETE if (must_suspend_thread)
2878 // OBSOLETE setup_thread (thread, 1);
2880 // OBSOLETE ret = thread_get_state (thread, flavor, state, &stateCnt);
2881 // OBSOLETE CHK ("thread_trace: error reading thread state", ret);
2883 // OBSOLETE if (set)
2885 // OBSOLETE TRACE_SET (thread, state);
2889 // OBSOLETE if (!TRACE_CLEAR (thread, state))
2891 // OBSOLETE if (must_suspend_thread)
2892 // OBSOLETE setup_thread (thread, 0);
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);
2903 // OBSOLETE #ifdef FLUSH_INFERIOR_CACHE
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 */
2910 // OBSOLETE flush_inferior_icache (CORE_ADDR pc, int amount)
2912 // OBSOLETE vm_machine_attribute_val_t flush = MATTR_VAL_ICACHE_FLUSH;
2913 // OBSOLETE kern_return_t ret;
2915 // OBSOLETE ret = vm_machine_attribute (inferior_task,
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));
2924 // OBSOLETE #endif /* FLUSH_INFERIOR_CACHE */
2928 // OBSOLETE suspend_all_threads (int from_tty)
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;
2937 // OBSOLETE ret = task_threads (inferior_task, &thread_list, &thread_count);
2938 // OBSOLETE if (ret != KERN_SUCCESS)
2940 // OBSOLETE warning ("Could not suspend inferior threads.");
2941 // OBSOLETE m3_kill_inferior ();
2942 // OBSOLETE throw_exception (RETURN_ERROR);
2945 // OBSOLETE for (index = 0; index < thread_count; index++)
2947 // OBSOLETE int mid;
2949 // OBSOLETE mid = map_port_name_to_mid (thread_list[index],
2950 // OBSOLETE MACH_TYPE_THREAD);
2952 // OBSOLETE ret = thread_suspend (thread_list[index]);
2954 // OBSOLETE if (ret != KERN_SUCCESS)
2955 // OBSOLETE warning ("Error trying to suspend thread %d : %s",
2956 // OBSOLETE mid, mach_error_string (ret));
2958 // OBSOLETE if (from_tty)
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);
2967 // OBSOLETE warning ("Thread %d suspend count is %d",
2968 // OBSOLETE mid, th_info.suspend_count);
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);
2980 // OBSOLETE thread_suspend_command (char *args, int from_tty)
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;
2988 // OBSOLETE MACH_ERROR_NO_INFERIOR;
2990 // OBSOLETE if (!strcasecmp (args, "all"))
2992 // OBSOLETE suspend_all_threads (from_tty);
2996 // OBSOLETE saved_thread = current_thread;
2998 // OBSOLETE mid = parse_thread_id (args, 0, 0);
3000 // OBSOLETE if (mid < 0)
3001 // OBSOLETE error ("You can suspend only existing kernel threads with MID or @SLOTNUMBER");
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)
3007 // OBSOLETE if (current_thread)
3008 // OBSOLETE current_thread = saved_thread;
3009 // OBSOLETE error ("Could not select thread %d", mid);
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));
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);
3024 // OBSOLETE warning ("Thread %d suspend count is %d", mid, th_info.suspend_count);
3026 // OBSOLETE current_thread = saved_thread;
3029 // OBSOLETE resume_all_threads (int from_tty)
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;
3038 // OBSOLETE ret = task_threads (inferior_task, &thread_list, &thread_count);
3039 // OBSOLETE if (ret != KERN_SUCCESS)
3041 // OBSOLETE m3_kill_inferior ();
3042 // OBSOLETE error ("task_threads", mach_error_string (ret));
3045 // OBSOLETE for (index = 0; index < thread_count; index++)
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);
3054 // OBSOLETE mid = map_port_name_to_mid (thread_list[index],
3055 // OBSOLETE MACH_TYPE_THREAD);
3057 // OBSOLETE if (!th_info.suspend_count)
3059 // OBSOLETE if (mid != -1 && from_tty)
3060 // OBSOLETE warning ("Thread %d is not suspended", mid);
3061 // OBSOLETE continue;
3064 // OBSOLETE ret = thread_resume (thread_list[index]);
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);
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);
3082 // OBSOLETE thread_resume_command (char *args, int from_tty)
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;
3090 // OBSOLETE MACH_ERROR_NO_INFERIOR;
3092 // OBSOLETE if (!strcasecmp (args, "all"))
3094 // OBSOLETE resume_all_threads (from_tty);
3098 // OBSOLETE saved_thread = current_thread;
3100 // OBSOLETE mid = parse_thread_id (args, 0, 0);
3102 // OBSOLETE if (mid < 0)
3103 // OBSOLETE error ("You can resume only existing kernel threads with MID or @SLOTNUMBER");
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)
3109 // OBSOLETE if (current_thread)
3110 // OBSOLETE current_thread = saved_thread;
3111 // OBSOLETE throw_exception (RETURN_ERROR);
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);
3120 // OBSOLETE if (!th_info.suspend_count)
3122 // OBSOLETE warning ("Thread %d is not suspended", mid);
3123 // OBSOLETE goto out;
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));
3132 // OBSOLETE th_info.suspend_count--;
3133 // OBSOLETE warning ("Thread %d suspend count is %d", mid, th_info.suspend_count);
3137 // OBSOLETE current_thread = saved_thread;
3141 // OBSOLETE thread_kill_command (char *args, int from_tty)
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;
3151 // OBSOLETE MACH_ERROR_NO_INFERIOR;
3153 // OBSOLETE if (!args)
3154 // OBSOLETE error_no_arg ("thread mid to kill from the inferior task");
3156 // OBSOLETE mid = parse_thread_id (args, 0, 0);
3158 // OBSOLETE if (mid < 0)
3159 // OBSOLETE error ("You can kill only existing kernel threads with MID or @SLOTNUMBER");
3161 // OBSOLETE if (mid)
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);
3167 // OBSOLETE mid = map_port_name_to_mid (current_thread, MACH_TYPE_THREAD);
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);
3173 // OBSOLETE if (thread_to_kill == current_thread)
3175 // OBSOLETE ret = thread_terminate (thread_to_kill);
3176 // OBSOLETE CHK ("Thread could not be terminated", ret);
3178 // OBSOLETE if (select_thread (inferior_task, 0, 1) != KERN_SUCCESS)
3179 // OBSOLETE warning ("Last thread was killed, use \"kill\" command to kill task");
3182 // OBSOLETE for (index = 0; index < thread_count; index++)
3183 // OBSOLETE if (thread_table[index] == thread_to_kill)
3185 // OBSOLETE ret = thread_terminate (thread_to_kill);
3186 // OBSOLETE CHK ("Thread could not be terminated", ret);
3189 // OBSOLETE if (thread_count > 1)
3190 // OBSOLETE consume_send_rights (thread_table, thread_count);
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);
3196 // OBSOLETE warning ("Thread %d killed", mid);
3200 // OBSOLETE /* Task specific commands; add more if you like */
3203 // OBSOLETE task_resume_command (char *args, int from_tty)
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);
3210 // OBSOLETE MACH_ERROR_NO_INFERIOR;
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");
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);
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");
3229 // OBSOLETE ret = task_resume (inferior_task);
3230 // OBSOLETE CHK ("task_resume_command: task_resume", ret);
3232 // OBSOLETE if (ta_info.suspend_count == 1)
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 ();
3241 // OBSOLETE warning ("Inferior task %d suspend count is now %d",
3242 // OBSOLETE mid, ta_info.suspend_count - 1);
3247 // OBSOLETE task_suspend_command (char *args, int from_tty)
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);
3254 // OBSOLETE MACH_ERROR_NO_INFERIOR;
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");
3260 // OBSOLETE ret = task_suspend (inferior_task);
3261 // OBSOLETE CHK ("task_suspend_command: task_suspend", ret);
3263 // OBSOLETE must_suspend_thread = 0;
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);
3271 // OBSOLETE warning ("Inferior task %d suspend count is now %d",
3272 // OBSOLETE mid, ta_info.suspend_count);
3275 // OBSOLETE static char *
3276 // OBSOLETE get_size (int bytes)
3278 // OBSOLETE static char size[30];
3279 // OBSOLETE int zz = bytes / 1024;
3281 // OBSOLETE if (zz / 1024)
3282 // OBSOLETE sprintf (size, "%-2.1f M", ((float) bytes) / (1024.0 * 1024.0));
3284 // OBSOLETE sprintf (size, "%d K", zz);
3286 // OBSOLETE return size;
3289 // OBSOLETE /* Does this require the target task to be suspended?? I don't think so. */
3291 // OBSOLETE task_info_command (char *args, int from_tty)
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;
3301 // OBSOLETE if (MACH_PORT_VALID (inferior_task))
3302 // OBSOLETE mid = map_port_name_to_mid (inferior_task,
3303 // OBSOLETE MACH_TYPE_TASK);
3305 // OBSOLETE task = inferior_task;
3307 // OBSOLETE if (args)
3309 // OBSOLETE int tmid = atoi (args);
3311 // OBSOLETE if (tmid <= 0)
3312 // OBSOLETE error ("Invalid mid %d for task info", tmid);
3314 // OBSOLETE if (tmid != mid)
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);
3322 // OBSOLETE if (mid < 0)
3323 // OBSOLETE error ("You have to give the task MID as an argument");
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);
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));
3338 // OBSOLETE thread_array_t thread_list;
3340 // OBSOLETE ret = task_threads (task, &thread_list, &thread_count);
3341 // OBSOLETE CHK ("task_info_command: task_threads", ret);
3343 // OBSOLETE printf_filtered (" Thread count : %d\n", thread_count);
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);
3351 // OBSOLETE if (have_emulator_p (task))
3352 // OBSOLETE printf_filtered (" Emulator at : 0x%x..0x%x\n",
3353 // OBSOLETE EMULATOR_BASE, EMULATOR_END);
3355 // OBSOLETE printf_filtered (" No emulator.\n");
3357 // OBSOLETE if (thread_count && task == inferior_task)
3358 // OBSOLETE printf_filtered ("\nUse the \"thread list\" command to see the threads\n");
3361 // OBSOLETE /* You may either FORWARD the exception to the inferior, or KEEP
3362 // OBSOLETE * it and return to GDB command level.
3364 // OBSOLETE * exception mid [ forward | keep ]
3367 // OBSOLETE static void
3368 // OBSOLETE exception_command (char *args, int from_tty)
3370 // OBSOLETE char *scan = args;
3371 // OBSOLETE int exception;
3372 // OBSOLETE int len;
3374 // OBSOLETE if (!args)
3375 // OBSOLETE error_no_arg ("exception number action");
3377 // OBSOLETE while (*scan == ' ' || *scan == '\t')
3380 // OBSOLETE if ('0' <= *scan && *scan <= '9')
3381 // OBSOLETE while ('0' <= *scan && *scan <= '9')
3384 // OBSOLETE error ("exception number action");
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);
3391 // OBSOLETE if (*scan != ' ' && *scan != '\t')
3392 // OBSOLETE error ("exception number must be followed by a space");
3394 // OBSOLETE while (*scan == ' ' || *scan == '\t')
3397 // OBSOLETE args = scan;
3398 // OBSOLETE len = 0;
3399 // OBSOLETE while (*scan)
3405 // OBSOLETE if (!len)
3406 // OBSOLETE error ("exception number action");
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;
3413 // OBSOLETE error ("exception action is either \"keep\" or \"forward\"");
3416 // OBSOLETE static void
3417 // OBSOLETE print_exception_info (int exception)
3419 // OBSOLETE boolean_t forward = exception_map[exception].forward;
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);
3428 // OBSOLETE printf_filtered ("keep and handle as unknown signal %d\n",
3429 // OBSOLETE exception_map[exception].sigmap);
3431 // OBSOLETE printf_filtered ("forward exception to inferior\n");
3435 // OBSOLETE exception_info (char *args, int from_tty)
3437 // OBSOLETE int exception;
3439 // OBSOLETE if (!args)
3440 // OBSOLETE for (exception = 1; exception <= MAX_EXCEPTION; exception++)
3441 // OBSOLETE print_exception_info (exception);
3444 // OBSOLETE exception = atoi (args);
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);
3453 // OBSOLETE /* Check for actions for mach exceptions.
3455 // OBSOLETE mach3_exception_actions (WAITTYPE *w, boolean_t force_print_only, char *who)
3457 // OBSOLETE boolean_t force_print = FALSE;
3460 // OBSOLETE if (force_print_only ||
3461 // OBSOLETE exception_map[stop_exception].sigmap == SIG_UNKNOWN)
3462 // OBSOLETE force_print = TRUE;
3464 // OBSOLETE WSETSTOP (*w, exception_map[stop_exception].sigmap);
3466 // OBSOLETE if (exception_map[stop_exception].print || force_print)
3468 // OBSOLETE target_terminal_ours ();
3470 // OBSOLETE printf_filtered ("\n%s received %s exception : ",
3472 // OBSOLETE exception_map[stop_exception].name);
3474 // OBSOLETE wrap_here (" ");
3476 // OBSOLETE switch (stop_exception)
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));
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);
3488 // OBSOLETE case EXC_ARITHMETIC:
3489 // OBSOLETE printf_filtered ("code %d\n", stop_code);
3491 // OBSOLETE case EXC_EMULATION:
3492 // OBSOLETE printf_filtered ("code %d subcode %d\n", stop_code, stop_subcode);
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);
3499 // OBSOLETE case EXC_BREAKPOINT:
3500 // OBSOLETE printf_filtered ("type %d (machine dependent)\n",
3501 // OBSOLETE stop_code);
3503 // OBSOLETE default:
3504 // OBSOLETE internal_error (__FILE__, __LINE__,
3505 // OBSOLETE "Unknown exception");
3510 // OBSOLETE setup_notify_port (int create_new)
3512 // OBSOLETE kern_return_t ret;
3514 // OBSOLETE if (MACH_PORT_VALID (our_notify_port))
3516 // OBSOLETE ret = mach_port_destroy (mach_task_self (), our_notify_port);
3517 // OBSOLETE CHK ("Could not destroy our_notify_port", ret);
3520 // OBSOLETE our_notify_port = MACH_PORT_NULL;
3521 // OBSOLETE notify_chain = (port_chain_t) NULL;
3522 // OBSOLETE port_chain_destroy (port_chain_obstack);
3524 // OBSOLETE if (create_new)
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));
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));
3543 // OBSOLETE * Register our message port to the net name server
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.
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.
3554 // OBSOLETE char registered_name[MAX_NAME_LEN];
3557 // OBSOLETE message_port_info (char *args, int from_tty)
3559 // OBSOLETE if (registered_name[0])
3560 // OBSOLETE printf_filtered ("gdb's message port name: '%s'\n",
3561 // OBSOLETE registered_name);
3563 // OBSOLETE printf_filtered ("gdb's message port is not currently registered\n");
3567 // OBSOLETE gdb_register_port (char *name, mach_port_t port)
3569 // OBSOLETE kern_return_t ret;
3570 // OBSOLETE static int already_signed = 0;
3571 // OBSOLETE int len;
3573 // OBSOLETE if (!MACH_PORT_VALID (port) || !name || !*name)
3575 // OBSOLETE warning ("Invalid registration request");
3579 // OBSOLETE if (!already_signed)
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;
3588 // OBSOLETE else if (already_signed > 1)
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;
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);
3604 // OBSOLETE len = 0;
3605 // OBSOLETE while (len < MAX_NAME_LEN && *(name + len))
3607 // OBSOLETE registered_name[len] = *(name + len);
3610 // OBSOLETE registered_name[len] = '\000';
3611 // OBSOLETE already_signed = 2;
3614 // OBSOLETE struct cmd_list_element *cmd_thread_list;
3615 // OBSOLETE struct cmd_list_element *cmd_task_list;
3617 // OBSOLETE /*ARGSUSED */
3618 // OBSOLETE static void
3619 // OBSOLETE thread_command (char *arg, int from_tty)
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);
3625 // OBSOLETE /*ARGSUSED */
3626 // OBSOLETE static void
3627 // OBSOLETE task_command (char *arg, int from_tty)
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);
3633 // OBSOLETE add_mach_specific_commands (void)
3635 // OBSOLETE /* Thread handling commands */
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);
3643 // OBSOLETE add_com_alias ("th", "mthread", class_stack, 1);
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);
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);
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);
3673 // OBSOLETE /* task handling commands */
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);
3679 // OBSOLETE add_com_alias ("ta", "task", class_stack, 1);
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);
3691 // OBSOLETE /* Print my message port name */
3693 // OBSOLETE add_info ("message-port", message_port_info,
3694 // OBSOLETE "Returns the name of gdb's message port in the netnameserver");
3696 // OBSOLETE /* Exception commands */
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.");
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.");
3713 // OBSOLETE kern_return_t
3714 // OBSOLETE do_mach_notify_dead_name (mach_port_t notify, mach_port_t name)
3716 // OBSOLETE kern_return_t kr = KERN_SUCCESS;
3718 // OBSOLETE /* Find the thing that notified */
3719 // OBSOLETE port_chain_t element = port_chain_member (notify_chain, name);
3721 // OBSOLETE /* Take name of from unreceived dead name notification list */
3722 // OBSOLETE notify_chain = port_chain_delete (notify_chain, name);
3724 // OBSOLETE if (!element)
3725 // OBSOLETE error ("Received a dead name notify from unchained port (0x%x)", name);
3727 // OBSOLETE switch (element->type)
3730 // OBSOLETE case MACH_TYPE_THREAD:
3731 // OBSOLETE target_terminal_ours_for_output ();
3732 // OBSOLETE if (name == current_thread)
3734 // OBSOLETE printf_filtered ("\nCurrent thread %d died", element->mid);
3735 // OBSOLETE current_thread = MACH_PORT_NULL;
3738 // OBSOLETE printf_filtered ("\nThread %d died", element->mid);
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);
3749 // OBSOLETE printf_filtered ("Current task %d died", element->mid);
3751 // OBSOLETE mach_port_destroy (mach_task_self (), name);
3752 // OBSOLETE inferior_task = MACH_PORT_NULL;
3754 // OBSOLETE if (notify_chain)
3755 // OBSOLETE warning ("There were still unreceived dead_name_notifications???");
3757 // OBSOLETE /* Destroy the old notifications */
3758 // OBSOLETE setup_notify_port (0);
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);
3769 // OBSOLETE return KERN_SUCCESS;
3772 // OBSOLETE kern_return_t
3773 // OBSOLETE do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
3775 // OBSOLETE warning ("do_mach_notify_msg_accepted : notify %x, name %x",
3776 // OBSOLETE notify, name);
3777 // OBSOLETE return KERN_SUCCESS;
3780 // OBSOLETE kern_return_t
3781 // OBSOLETE do_mach_notify_no_senders (mach_port_t notify, mach_port_mscount_t mscount)
3783 // OBSOLETE warning ("do_mach_notify_no_senders : notify %x, mscount %x",
3784 // OBSOLETE notify, mscount);
3785 // OBSOLETE return KERN_SUCCESS;
3788 // OBSOLETE kern_return_t
3789 // OBSOLETE do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
3791 // OBSOLETE warning ("do_mach_notify_port_deleted : notify %x, name %x",
3792 // OBSOLETE notify, name);
3793 // OBSOLETE return KERN_SUCCESS;
3796 // OBSOLETE kern_return_t
3797 // OBSOLETE do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t rights)
3799 // OBSOLETE warning ("do_mach_notify_port_destroyed : notify %x, rights %x",
3800 // OBSOLETE notify, rights);
3801 // OBSOLETE return KERN_SUCCESS;
3804 // OBSOLETE kern_return_t
3805 // OBSOLETE do_mach_notify_send_once (mach_port_t notify)
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);
3812 // OBSOLETE return KERN_SUCCESS;
3815 // OBSOLETE /* Kills the inferior. It's gone when you call this */
3816 // OBSOLETE static void
3817 // OBSOLETE kill_inferior_fast (void)
3819 // OBSOLETE WAITTYPE w;
3821 // OBSOLETE if (PIDGET (inferior_ptid) == 0 || PIDGET (inferior_ptid) == 1)
3824 // OBSOLETE /* kill() it, since the Unix server does not otherwise notice when
3825 // OBSOLETE * killed with task_terminate().
3827 // OBSOLETE if (PIDGET (inferior_ptid) > 0)
3828 // OBSOLETE kill (PIDGET (inferior_ptid), SIGKILL);
3830 // OBSOLETE /* It's propably terminate already */
3831 // OBSOLETE (void) task_terminate (inferior_task);
3833 // OBSOLETE inferior_task = MACH_PORT_NULL;
3834 // OBSOLETE current_thread = MACH_PORT_NULL;
3836 // OBSOLETE wait3 (&w, WNOHANG, 0);
3838 // OBSOLETE setup_notify_port (0);
3841 // OBSOLETE static void
3842 // OBSOLETE m3_kill_inferior (void)
3844 // OBSOLETE kill_inferior_fast ();
3845 // OBSOLETE target_mourn_inferior ();
3848 // OBSOLETE /* Clean up after the inferior dies. */
3850 // OBSOLETE static void
3851 // OBSOLETE m3_mourn_inferior (void)
3853 // OBSOLETE unpush_target (&m3_ops);
3854 // OBSOLETE generic_mourn_inferior ();
3858 // OBSOLETE /* Fork an inferior process, and start debugging it. */
3860 // OBSOLETE static void
3861 // OBSOLETE m3_create_inferior (char *exec_file, char *allargs, char **env)
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);
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)
3874 // OBSOLETE return 1;
3877 // OBSOLETE /* Mach 3.0 does not need ptrace for anything
3878 // OBSOLETE * Make sure nobody uses it on mach.
3880 // OBSOLETE ptrace (int a, int b, int c, int d)
3882 // OBSOLETE error ("Lose, Lose! Somebody called ptrace\n");
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. */
3890 // OBSOLETE m3_resume (ptid_t ptid, int step, enum target_signal signal)
3892 // OBSOLETE kern_return_t ret;
3894 // OBSOLETE if (step)
3896 // OBSOLETE thread_basic_info_data_t th_info;
3897 // OBSOLETE unsigned int infoCnt = THREAD_BASIC_INFO_COUNT;
3899 // OBSOLETE /* There is no point in single stepping when current_thread
3900 // OBSOLETE * is dead.
3902 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
3903 // OBSOLETE error ("No thread selected; can not single step");
3905 // OBSOLETE /* If current_thread is suspended, tracing it would never return.
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);
3913 // OBSOLETE if (th_info.suspend_count)
3914 // OBSOLETE error ("Can't trace a suspended thread. Use \"thread resume\" command to resume it");
3917 // OBSOLETE vm_read_cache_valid = FALSE;
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));
3922 // OBSOLETE if (step)
3924 // OBSOLETE suspend_all_threads (0);
3926 // OBSOLETE setup_single_step (current_thread, TRUE);
3928 // OBSOLETE ret = thread_resume (current_thread);
3929 // OBSOLETE CHK ("thread_resume", ret);
3932 // OBSOLETE ret = task_resume (inferior_task);
3933 // OBSOLETE if (ret == KERN_FAILURE)
3934 // OBSOLETE warning ("Task was not suspended");
3936 // OBSOLETE CHK ("Resuming task", ret);
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 */
3944 // OBSOLETE #ifdef ATTACH_DETACH
3946 // OBSOLETE /* Start debugging the process with the given task */
3948 // OBSOLETE task_attach (task_t tid)
3950 // OBSOLETE kern_return_t ret;
3951 // OBSOLETE inferior_task = tid;
3953 // OBSOLETE ret = task_suspend (inferior_task);
3954 // OBSOLETE CHK ("task_attach: task_suspend", ret);
3956 // OBSOLETE must_suspend_thread = 0;
3958 // OBSOLETE setup_notify_port (1);
3960 // OBSOLETE request_notify (inferior_task, MACH_NOTIFY_DEAD_NAME, MACH_TYPE_TASK);
3962 // OBSOLETE setup_exception_port ();
3964 // OBSOLETE emulator_present = have_emulator_p (inferior_task);
3966 // OBSOLETE attach_flag = 1;
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))
3978 // OBSOLETE attach_to_thread (void)
3980 // OBSOLETE if (select_thread (inferior_task, 0, 1) != KERN_SUCCESS)
3981 // OBSOLETE error ("Could not select any threads to attach to");
3984 // OBSOLETE mid_attach (int mid)
3986 // OBSOLETE kern_return_t ret;
3988 // OBSOLETE ret = machid_mach_port (mid_server, mid_auth, mid, &inferior_task);
3989 // OBSOLETE CHK ("mid_attach: machid_mach_port", ret);
3991 // OBSOLETE task_attach (inferior_task);
3993 // OBSOLETE return mid;
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.
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.
4004 // OBSOLETE static int
4005 // OBSOLETE m3_do_attach (int pid)
4007 // OBSOLETE kern_return_t ret;
4009 // OBSOLETE if (pid == 0)
4010 // OBSOLETE error ("MID=0, Debugging the master unix server does not compute");
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!)");
4016 // OBSOLETE if (pid < 0)
4018 // OBSOLETE mid_attach (-(pid));
4020 // OBSOLETE /* inferior_ptid will be NEGATIVE! */
4021 // OBSOLETE inferior_ptid = pid_to_ptid (pid);
4023 // OBSOLETE return PIDGET (inferior_ptid);
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);
4030 // OBSOLETE task_attach (inferior_task);
4032 // OBSOLETE inferior_ptid = pid_to_ptid (pid);
4034 // OBSOLETE return PIDGET (inferior_ptid);
4037 // OBSOLETE /* Attach to process PID, then initialize for debugging it
4038 // OBSOLETE and wait for the trace-trap that results from attaching. */
4040 // OBSOLETE static void
4041 // OBSOLETE m3_attach (char *args, int from_tty)
4043 // OBSOLETE char *exec_file;
4044 // OBSOLETE int pid;
4046 // OBSOLETE if (!args)
4047 // OBSOLETE error_no_arg ("process-id to attach");
4049 // OBSOLETE pid = atoi (args);
4051 // OBSOLETE if (pid == getpid ()) /* Trying to masturbate? */
4052 // OBSOLETE error ("I refuse to debug myself!");
4054 // OBSOLETE if (from_tty)
4056 // OBSOLETE exec_file = (char *) get_exec_file (0);
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)));
4062 // OBSOLETE printf_unfiltered ("Attaching to %s\n",
4063 // OBSOLETE target_pid_to_str (pid_to_ptid (pid)));
4065 // OBSOLETE gdb_flush (gdb_stdout);
4068 // OBSOLETE m3_do_attach (pid_to_ptid (pid));
4069 // OBSOLETE inferior_ptid = pid_to_ptid (pid);
4070 // OBSOLETE push_target (&m3_ops);
4074 // OBSOLETE deallocate_inferior_ports (void)
4076 // OBSOLETE kern_return_t ret;
4077 // OBSOLETE thread_array_t thread_list;
4078 // OBSOLETE int thread_count, index;
4080 // OBSOLETE if (!MACH_PORT_VALID (inferior_task))
4083 // OBSOLETE ret = task_threads (inferior_task, &thread_list, &thread_count);
4084 // OBSOLETE if (ret != KERN_SUCCESS)
4086 // OBSOLETE warning ("deallocate_inferior_ports: task_threads",
4087 // OBSOLETE mach_error_string (ret));
4091 // OBSOLETE /* Get rid of send rights to task threads */
4092 // OBSOLETE for (index = 0; index < thread_count; index++)
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);
4101 // OBSOLETE if (rights > 0)
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);
4111 // OBSOLETE ret = mach_port_mod_refs (mach_task_self (),
4112 // OBSOLETE inferior_exception_port,
4113 // OBSOLETE MACH_PORT_RIGHT_RECEIVE,
4115 // OBSOLETE CHK ("deallocate_inferior_ports: cannot get rid of exception port", ret);
4117 // OBSOLETE ret = mach_port_deallocate (mach_task_self (),
4118 // OBSOLETE inferior_task);
4119 // OBSOLETE CHK ("deallocate_task_port: deallocating inferior_task", ret);
4121 // OBSOLETE current_thread = MACH_PORT_NULL;
4122 // OBSOLETE inferior_task = MACH_PORT_NULL;
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. */
4129 // OBSOLETE static void
4130 // OBSOLETE m3_do_detach (int signal)
4132 // OBSOLETE kern_return_t ret;
4134 // OBSOLETE MACH_ERROR_NO_INFERIOR;
4136 // OBSOLETE if (current_thread != MACH_PORT_NULL)
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.
4142 // OBSOLETE target_prepare_to_store ();
4143 // OBSOLETE target_store_registers (-1);
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);
4151 // OBSOLETE /* Discard all requested notifications */
4152 // OBSOLETE setup_notify_port (0);
4154 // OBSOLETE if (remove_breakpoints ())
4155 // OBSOLETE warning ("Could not remove breakpoints when detaching");
4157 // OBSOLETE if (signal && PIDGET (inferior_ptid) > 0)
4158 // OBSOLETE kill (PIDGET (inferior_ptid), signal);
4160 // OBSOLETE /* the task might be dead by now */
4161 // OBSOLETE (void) task_resume (inferior_task);
4163 // OBSOLETE deallocate_inferior_ports ();
4165 // OBSOLETE attach_flag = 0;
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. */
4176 // OBSOLETE static void
4177 // OBSOLETE m3_detach (char *args, int from_tty)
4179 // OBSOLETE int siggnal = 0;
4181 // OBSOLETE if (from_tty)
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);
4190 // OBSOLETE if (args)
4191 // OBSOLETE siggnal = atoi (args);
4193 // OBSOLETE m3_do_detach (siggnal);
4194 // OBSOLETE inferior_ptid = null_ptid;
4195 // OBSOLETE unpush_target (&m3_ops); /* Pop out of handling an inferior */
4197 // OBSOLETE #endif /* ATTACH_DETACH */
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. */
4205 // OBSOLETE static void
4206 // OBSOLETE m3_prepare_to_store (void)
4208 // OBSOLETE #ifdef CHILD_PREPARE_TO_STORE
4209 // OBSOLETE CHILD_PREPARE_TO_STORE ();
4213 // OBSOLETE /* Print status information about what we're accessing. */
4215 // OBSOLETE static void
4216 // OBSOLETE m3_files_info (struct target_ops *ignore)
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));
4223 // OBSOLETE static void
4224 // OBSOLETE m3_open (char *arg, int from_tty)
4226 // OBSOLETE error ("Use the \"run\" command to start a Unix child process.");
4229 // OBSOLETE #ifdef DUMP_SYSCALL
4230 // OBSOLETE #define STR(x) #x
4232 // OBSOLETE char *bsd1_names[] =
4234 // OBSOLETE "execve",
4236 // OBSOLETE "take_signal",
4237 // OBSOLETE "sigreturn",
4238 // OBSOLETE "getrusage",
4239 // OBSOLETE "chdir",
4240 // OBSOLETE "chroot",
4242 // OBSOLETE "creat",
4243 // OBSOLETE "mknod",
4245 // OBSOLETE "symlink",
4246 // OBSOLETE "unlink",
4247 // OBSOLETE "access",
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",
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",
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",
4295 // OBSOLETE "maprw_request_it",
4296 // OBSOLETE "maprw_release_it",
4297 // OBSOLETE "maprw_remap",
4298 // OBSOLETE "pid_by_task",
4301 // OBSOLETE int bsd1_nnames = sizeof (bsd1_names) / sizeof (bsd1_names[0]);
4304 // OBSOLETE name_str (int name, char *buf)
4306 // OBSOLETE switch (name)
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;
4329 // OBSOLETE id_str (int id, char *buf)
4331 // OBSOLETE char *p;
4332 // OBSOLETE if (id >= 101000 && id < 101000 + bsd1_nnames)
4334 // OBSOLETE if (p = bsd1_names[id - 101000])
4335 // OBSOLETE return p;
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;
4345 // OBSOLETE print_msg (mach_msg_header_t *mp)
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];
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));
4361 // OBSOLETE if (debug_level > 1)
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)
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)
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);
4384 // OBSOLETE name = tp->msgt_name;
4385 // OBSOLETE size = tp->msgt_size;
4386 // OBSOLETE number = tp->msgt_number;
4387 // OBSOLETE plen = sizeof (*tp);
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)
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);
4403 // OBSOLETE plen += sizeof (int *);
4405 // OBSOLETE printf_filtered ("plen=%d\n", plen);
4410 // OBSOLETE print_data (char *p, int size, int number)
4412 // OBSOLETE int *ip;
4413 // OBSOLETE short *sp;
4416 // OBSOLETE switch (size)
4419 // OBSOLETE for (i = 0; i < number; i++)
4421 // OBSOLETE printf_filtered (" %02x", p[i]);
4424 // OBSOLETE case 16:
4425 // OBSOLETE sp = (short *) p;
4426 // OBSOLETE for (i = 0; i < number; i++)
4428 // OBSOLETE printf_filtered (" %04x", sp[i]);
4431 // OBSOLETE case 32:
4432 // OBSOLETE ip = (int *) p;
4433 // OBSOLETE for (i = 0; i < number; i++)
4435 // OBSOLETE printf_filtered (" %08x", ip[i]);
4439 // OBSOLETE puts_filtered ("\n");
4441 // OBSOLETE #endif /* DUMP_SYSCALL */
4443 // OBSOLETE static void
4444 // OBSOLETE m3_stop (void)
4446 // OBSOLETE error ("to_stop target function not implemented");
4449 // OBSOLETE static char *
4450 // OBSOLETE m3_pid_to_exec_file (int pid)
4452 // OBSOLETE error ("to_pid_to_exec_file target function not implemented");
4453 // OBSOLETE return NULL; /* To keep all compilers happy. */
4456 // OBSOLETE static void
4457 // OBSOLETE init_m3_ops (void)
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;
4496 // OBSOLETE _initialize_m3_nat (void)
4498 // OBSOLETE kern_return_t ret;
4500 // OBSOLETE init_m3_ops ();
4501 // OBSOLETE add_target (&m3_ops);
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));
4510 // OBSOLETE /* mach_really_wait now waits for this */
4511 // OBSOLETE currently_waiting_for = inferior_wait_port_set;
4513 // OBSOLETE ret = netname_look_up (name_server_port, hostname, "MachID", &mid_server);
4514 // OBSOLETE if (ret != KERN_SUCCESS)
4516 // OBSOLETE mid_server = MACH_PORT_NULL;
4518 // OBSOLETE warning ("initialize machid: netname_lookup_up(MachID) : %s",
4519 // OBSOLETE mach_error_string (ret));
4520 // OBSOLETE warning ("Some (most?) features disabled...");
4523 // OBSOLETE mid_auth = mach_privileged_host_port ();
4524 // OBSOLETE if (mid_auth == MACH_PORT_NULL)
4525 // OBSOLETE mid_auth = mach_task_self ();
4527 // OBSOLETE obstack_init (port_chain_obstack);
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);
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);
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));
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));
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);
4562 // OBSOLETE /* Heap for thread commands */
4563 // OBSOLETE obstack_init (cproc_obstack);
4565 // OBSOLETE add_mach_specific_commands ();