40 #include "bfd/mach-o.h"
42 #include <sys/ptrace.h>
43 #include <sys/signal.h>
45 #include <sys/types.h>
49 #include <sys/sysctl.h>
52 #include <sys/syscall.h>
55 #include <mach/mach_error.h>
56 #include <mach/mach_vm.h>
57 #include <mach/mach_init.h>
58 #include <mach/vm_map.h>
59 #include <mach/task.h>
60 #include <mach/mach_port.h>
61 #include <mach/thread_act.h>
62 #include <mach/port.h>
83 #define PTRACE(CMD, PID, ADDR, SIG) \
84 darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG))
89 enum gdb_signal signal);
91 enum gdb_signal signal);
106 char *allargs,
char **env,
int from_tty);
115 mach_msg_header_t *hdr, integer_t
code);
142 #define PAGE_TRUNC(x) ((x) & ~(mach_page_size - 1))
143 #define PAGE_ROUND(x) PAGE_TRUNC((x) + mach_page_size - 1)
153 static const unsigned char info_plist[]
155 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
156 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
157 " \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
158 "<plist version=\"1.0\">\n"
160 " <key>CFBundleIdentifier</key>\n"
161 " <string>org.gnu.gdb</string>\n"
162 " <key>CFBundleName</key>\n"
163 " <string>gdb</string>\n"
164 " <key>CFBundleVersion</key>\n"
165 " <string>1.0</string>\n"
166 " <key>SecTaskAccess</key>\n"
168 " <string>allowed</string>\n"
169 " <string>debug</string>\n"
182 if (darwin_debug_flag < level)
193 unsigned int line,
const char *
func)
195 if (ret == KERN_SUCCESS)
198 func =
_(
"[UNKNOWN]");
200 warning (
_(
"Mach error at \"%s:%u\" in function \"%s\": %s (0x%lx)"),
201 file, line, func, mach_error_string (ret), (
unsigned long) ret);
207 static char unknown_exception_buf[32];
212 return "EXC_BAD_ACCESS";
213 case EXC_BAD_INSTRUCTION:
214 return "EXC_BAD_INSTRUCTION";
216 return "EXC_ARITHMETIC";
218 return "EXC_EMULATION";
220 return "EXC_SOFTWARE";
222 return "EXC_BREAKPOINT";
224 return "EXC_SYSCALL";
225 case EXC_MACH_SYSCALL:
226 return "EXC_MACH_SYSCALL";
228 return "EXC_RPC_ALERT";
232 snprintf (unknown_exception_buf, 32,
_(
"unknown (%d)"), i);
233 return unknown_exception_buf;
253 ret =
ptrace (request, pid, (caddr_t) arg3, arg4);
254 if (ret == -1 && errno == 0)
258 name, pid, arg3, arg4, ret,
268 return (
int)(tl - tr);
277 unsigned int new_nbr;
278 unsigned int old_nbr;
279 unsigned int new_ix, old_ix;
284 kret = task_threads (darwin_inf->
task, &thread_list, &new_nbr);
286 if (kret != KERN_SUCCESS)
293 if (darwin_inf->threads)
299 if (old_nbr == new_nbr)
301 for (i = 0; i < new_nbr; i++)
308 for (i = 0; i < new_nbr; i++)
310 kret = mach_port_deallocate (mach_task_self (), thread_list[i]);
315 kret = vm_deallocate (gdb_task, (vm_address_t) thread_list,
316 new_nbr *
sizeof (
int));
325 for (new_ix = 0, old_ix = 0; new_ix < new_nbr || old_ix < old_nbr;)
327 thread_t new_id = (new_ix < new_nbr) ?
328 thread_list[new_ix] : THREAD_NULL;
334 (12,
_(
" new_ix:%d/%d, old_ix:%d/%d, new_id:0x%x old_id:0x%x\n"),
335 new_ix, new_nbr, old_ix, old_nbr, new_id, old_id);
337 if (old_id == new_id)
345 kret = mach_port_deallocate (gdb_task, new_id);
350 if (new_ix < new_nbr && new_id == MACH_PORT_DEAD)
358 if (new_ix < new_nbr && (old_ix == old_nbr || new_id < old_id))
369 if (!(old_nbr == 0 && new_ix == 0))
381 if (old_ix < old_nbr && (new_ix == new_nbr || new_id > old_id))
385 kret = mach_port_deallocate (gdb_task, old_id);
393 if (darwin_inf->threads)
395 darwin_inf->threads = thread_vec;
398 kret = vm_deallocate (gdb_task, (vm_address_t) thread_list,
399 new_nbr *
sizeof (
int));
406 return inf->
priv->
task == *(task_t*)port_ptr;
453 kret = task_suspend (inf->
priv->
task);
469 kret = task_resume (inf->
priv->
task);
506 const unsigned char *data;
507 const unsigned int *ldata;
511 data = (
unsigned char *)(hdr + 1);
512 size = hdr->msgh_size -
sizeof (mach_msg_header_t);
514 if (hdr->msgh_bits & MACH_MSGH_BITS_COMPLEX)
516 mach_msg_body_t *bod = (mach_msg_body_t*)data;
517 mach_msg_port_descriptor_t *desc =
518 (mach_msg_port_descriptor_t *)(bod + 1);
522 bod->msgh_descriptor_count);
523 data +=
sizeof (mach_msg_body_t);
524 size -=
sizeof (mach_msg_body_t);
525 for (k = 0; k < bod->msgh_descriptor_count; k++)
526 switch (desc[k].
type)
528 case MACH_MSG_PORT_DESCRIPTOR:
530 (
_(
" descr %d: type=%u (port) name=0x%x, dispo=%d\n"),
531 k, desc[k].type, desc[k].
name, desc[k].disposition);
538 data += bod->msgh_descriptor_count
539 *
sizeof (mach_msg_port_descriptor_t);
540 size -= bod->msgh_descriptor_count
541 *
sizeof (mach_msg_port_descriptor_t);
542 ndr = (NDR_record_t *)(desc + bod->msgh_descriptor_count);
544 (
_(
"NDR: mig=%02x if=%02x encod=%02x "
545 "int=%02x char=%02x float=%02x\n"),
546 ndr->mig_vers, ndr->if_vers, ndr->mig_encoding,
547 ndr->int_rep, ndr->char_rep, ndr->float_rep);
548 data +=
sizeof (NDR_record_t);
549 size -=
sizeof (NDR_record_t);
553 ldata = (
const unsigned int *)data;
554 for (i = 0; i < size /
sizeof (
unsigned int); i++)
565 mach_msg_body_t *bod = (mach_msg_body_t*)(hdr + 1);
566 mach_msg_port_descriptor_t *desc = (mach_msg_port_descriptor_t *)(bod + 1);
577 if (hdr->msgh_local_port != darwin_ex_port)
581 if (!(hdr->msgh_bits & MACH_MSGH_BITS_COMPLEX))
585 if (hdr->msgh_size < (sizeof (*hdr) +
sizeof (*bod) + 2 *
sizeof (*desc)
586 +
sizeof (*ndr) + 2 *
sizeof (integer_t))
587 || bod->msgh_descriptor_count != 2
588 || desc[0].type != MACH_MSG_PORT_DESCRIPTOR
589 || desc[0].disposition != MACH_MSG_TYPE_MOVE_SEND
590 || desc[1].type != MACH_MSG_PORT_DESCRIPTOR
591 || desc[1].disposition != MACH_MSG_TYPE_MOVE_SEND)
595 ndr = (NDR_record_t *)(desc + 2);
596 if (ndr->mig_vers != NDR_PROTOCOL_2_0
597 || ndr->if_vers != NDR_PROTOCOL_2_0
598 || ndr->mig_encoding != NDR_record.mig_encoding
599 || ndr->int_rep != NDR_record.int_rep
600 || ndr->char_rep != NDR_record.char_rep
601 || ndr->float_rep != NDR_record.float_rep)
605 data = (integer_t *)(ndr + 1);
607 task_port = desc[1].
name;
608 thread_port = desc[0].name;
612 kret = mach_port_deallocate (mach_task_self (), task_port);
624 mig_reply_error_t reply;
627 kret = mach_port_deallocate (mach_task_self (), thread_port);
632 kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
633 reply.Head.msgh_size, 0,
634 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
648 kret = mach_port_deallocate (mach_task_self (), thread_port);
667 if (hdr->msgh_size < (sizeof (*hdr) +
sizeof (*bod) + 2 *
sizeof (*desc)
668 +
sizeof (*ndr) + 2 *
sizeof (integer_t)
669 + data[1] *
sizeof (integer_t)))
671 for (i = 0; i < data[1]; i++)
683 mach_msg_header_t *rh = &reply->Head;
685 rh->msgh_bits = MACH_MSGH_BITS (MACH_MSGH_BITS_REMOTE (hdr->msgh_bits), 0);
686 rh->msgh_remote_port = hdr->msgh_remote_port;
687 rh->msgh_size = (mach_msg_size_t)
sizeof (mig_reply_error_t);
688 rh->msgh_local_port = MACH_PORT_NULL;
689 rh->msgh_id = hdr->msgh_id + 100;
691 reply->NDR = NDR_record;
692 reply->RetCode =
code;
699 mig_reply_error_t reply;
703 kret = mach_msg (&reply.Head, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
704 reply.Head.msgh_size, 0,
705 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
714 int step,
int nsignal)
720 (3,
_(
"darwin_resume_thread: state=%d, thread=0x%x, step=%d nsignal=%d\n"),
731 (
void *)(uintptr_t)thread->
gdb_port, nsignal);
762 kret = thread_resume (thread->
gdb_port);
819 kret = thread_suspend (thread->
gdb_port);
838 (2,
_(
"darwin_resume: pid=%d, tid=0x%x, step=%d, signal=%d\n"),
841 if (signal == GDB_SIGNAL_0)
893 enum gdb_signal signal)
908 if (hdr->msgh_id == 2401)
919 (
_(
"darwin_wait: ill-formatted message (id=0x%x)\n"), hdr->msgh_id);
943 status->
value.
sig = GDB_EXC_BAD_ACCESS;
945 case EXC_BAD_INSTRUCTION:
946 status->
value.
sig = GDB_EXC_BAD_INSTRUCTION;
949 status->
value.
sig = GDB_EXC_ARITHMETIC;
952 status->
value.
sig = GDB_EXC_EMULATION;
974 status->
value.
sig = GDB_EXC_SOFTWARE;
980 status->
value.
sig = GDB_SIGNAL_TRAP;
983 status->
value.
sig = GDB_SIGNAL_UNKNOWN;
989 else if (hdr->msgh_id == 0x48)
1003 res = wait4 (inf->
pid, &wstatus, 0, NULL);
1004 if (res < 0 || res != inf->
pid)
1026 wait4 (inf->
pid, &wstatus, 0, NULL);
1041 warning (
_(
"darwin: got unknown message, id: 0x%x"), hdr->msgh_id);
1082 mach_msg_header_t hdr;
1085 mach_msg_header_t *hdr = &msgin.hdr;
1091 (2,
_(
"darwin_wait: waiting for a message pid=%d thread=%lx\n"),
1095 if (darwin_inf_fake_stop != NULL)
1098 darwin_inf_fake_stop = NULL;
1101 status->
value.
sig = GDB_SIGNAL_TRAP;
1112 kret = mach_msg (&msgin.hdr, MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0,
1113 sizeof (msgin.data), darwin_port_set, 0, MACH_PORT_NULL);
1117 if (kret == MACH_RCV_INTERRUPTED)
1123 if (kret != MACH_MSG_SUCCESS)
1131 if (darwin_debug_flag > 10)
1153 kret = mach_msg (&msgin.hdr,
1154 MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0,
1155 sizeof (msgin.data), darwin_port_set, 1, MACH_PORT_NULL);
1157 if (kret == MACH_RCV_TIMED_OUT)
1159 if (kret != MACH_MSG_SUCCESS)
1162 (5,
_(
"darwin_wait: mach_msg(pending) ret=0x%x\n"), kret);
1167 if (darwin_debug_flag > 10)
1172 if (inf != NULL && thread != NULL
1184 (3,
_(
"darwin_wait: thread 0x%x hit a non-gdb breakpoint\n"),
1207 kill (inf->
pid, SIGINT);
1219 if (inf->
priv->threads)
1227 kret = mach_port_deallocate (gdb_task, t->
gdb_port);
1231 inf->
priv->threads = NULL;
1234 kret = mach_port_move_member (gdb_task,
1238 kret = mach_port_request_notification (gdb_task, inf->
priv->
task,
1239 MACH_NOTIFY_DEAD_NAME, 0,
1241 MACH_MSG_TYPE_MAKE_SEND_ONCE,
1247 if (kret == KERN_SUCCESS)
1249 kret = mach_port_deallocate (gdb_task, prev);
1260 kret = mach_port_deallocate
1266 kret = mach_port_deallocate (gdb_task, inf->
priv->
task);
1308 res = kill (inf->
pid, SIGSTOP);
1317 && wstatus.
value.
sig == GDB_SIGNAL_STOP)
1322 static kern_return_t
1330 kret = task_get_exception_ports
1337 static kern_return_t
1345 kret = task_set_exception_ports
1348 if (kret != KERN_SUCCESS)
1352 return KERN_SUCCESS;
1375 res = kill (inf->
pid, 9);
1383 else if (errno != ESRCH)
1384 warning (
_(
"Failed to kill inferior: kill (%d, 9) returned [%s]"),
1394 mach_port_t prev_port;
1396 mach_port_t prev_not;
1397 exception_mask_t mask;
1401 kret = task_for_pid (gdb_task, inf->
pid, &inf->
priv->
task);
1402 if (kret != KERN_SUCCESS)
1409 waitpid (inf->
pid, &status, 0);
1412 error (
_(
"Unable to find Mach task port for process-id %d: %s (0x%lx).\n"
1413 " (please check gdb is codesigned - see taskgated(8))"),
1414 inf->
pid, mach_error_string (kret), (
unsigned long) kret);
1420 if (darwin_ex_port == MACH_PORT_NULL)
1423 kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE,
1425 if (kret != KERN_SUCCESS)
1426 error (
_(
"Unable to create exception port, mach_port_allocate "
1430 kret = mach_port_insert_right (gdb_task, darwin_ex_port, darwin_ex_port,
1431 MACH_MSG_TYPE_MAKE_SEND);
1432 if (kret != KERN_SUCCESS)
1433 error (
_(
"Unable to create exception port, mach_port_insert_right "
1438 kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_PORT_SET,
1440 if (kret != KERN_SUCCESS)
1441 error (
_(
"Unable to create port set, mach_port_allocate "
1445 kret = mach_port_move_member (gdb_task, darwin_ex_port, darwin_port_set);
1446 if (kret != KERN_SUCCESS)
1447 error (
_(
"Unable to move exception port into new port set, "
1448 "mach_port_move_member\n"
1454 kret = mach_port_allocate (gdb_task, MACH_PORT_RIGHT_RECEIVE,
1456 if (kret != KERN_SUCCESS)
1457 error (
_(
"Unable to create notification port, mach_port_allocate "
1461 kret = mach_port_move_member (gdb_task,
1463 if (kret != KERN_SUCCESS)
1464 error (
_(
"Unable to move notification port into new port set, "
1465 "mach_port_move_member\n"
1469 kret = mach_port_request_notification (gdb_task, inf->
priv->
task,
1470 MACH_NOTIFY_DEAD_NAME, 0,
1472 MACH_MSG_TYPE_MAKE_SEND_ONCE,
1474 if (kret != KERN_SUCCESS)
1475 error (
_(
"Termination notification request failed, "
1476 "mach_port_request_notification\n"
1479 if (prev_not != MACH_PORT_NULL)
1485 A task termination request was registered before the debugger registered\n\
1486 its own. This is unexpected, but should otherwise not have any actual\n\
1487 impact on the debugging session."));
1491 if (kret != KERN_SUCCESS)
1492 error (
_(
"Unable to save exception ports, task_get_exception_ports"
1497 if (enable_mach_exceptions)
1498 mask = EXC_MASK_ALL;
1500 mask = EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT;
1501 kret = task_set_exception_ports (inf->
priv->
task, mask, darwin_ex_port,
1502 EXCEPTION_DEFAULT, THREAD_STATE_NONE);
1503 if (kret != KERN_SUCCESS)
1504 error (
_(
"Unable to set exception ports, task_set_exception_ports"
1534 static int ptrace_fds[2];
1543 close (ptrace_fds[1]);
1546 res =
read (ptrace_fds[0], &c, 1);
1548 error (
_(
"unable to read from pipe, read returned: %d"), res);
1549 close (ptrace_fds[0]);
1552 setegid (getgid ());
1558 PTRACE (PT_SIGEXC, 0, 0, 0);
1565 if (pipe (ptrace_fds) != 0)
1581 mach_port_t prev_port;
1588 close (ptrace_fds[0]);
1589 close (ptrace_fds[1]);
1602 posix_spawnattr_t attr;
1606 res = posix_spawnattr_init (&attr);
1610 (
gdb_stderr,
"Cannot initialize attribute for posix_spawn\n");
1615 ps_flags = POSIX_SPAWN_SETEXEC;
1619 #ifndef _POSIX_SPAWN_DISABLE_ASLR
1620 #define _POSIX_SPAWN_DISABLE_ASLR 0x0100
1623 res = posix_spawnattr_setflags (&attr, ps_flags);
1630 posix_spawnp (NULL, argv[0], NULL, &attr, argv, env);
1635 char *allargs,
char **env,
int from_tty)
1660 darwin_inf_fake_stop =
inf;
1669 kret = thread_suspend (thread->
gdb_port);
1687 if (pid == getpid ())
1688 error (
_(
"I refuse to debug myself!"));
1704 if (pid == 0 || kill (pid, 0) < 0)
1705 error (
_(
"Can't attach to process %d: %s (%d)"),
1764 res =
PTRACE (PT_DETACH, inf->
pid, 0, 0);
1789 static char buf[80];
1794 snprintf (buf,
sizeof (buf),
_(
"Thread 0x%lx of process %u"),
1819 mach_vm_address_t
offset = addr & (mach_page_size - 1);
1820 mach_vm_address_t low_address = (mach_vm_address_t) (addr - offset);
1821 mach_vm_size_t aligned_length = (mach_vm_size_t)
PAGE_ROUND (offset + length);
1823 mach_msg_type_number_t copy_count;
1824 mach_vm_size_t remaining_length;
1825 mach_vm_address_t region_address;
1826 mach_vm_size_t region_length;
1828 inferior_debug (8,
_(
"darwin_read_write_inferior(task=0x%x, %s, len=%s)\n"),
1832 kret = mach_vm_read (task, low_address, aligned_length,
1833 &copied, ©_count);
1834 if (kret != KERN_SUCCESS)
1837 (1,
_(
"darwin_read_write_inferior: mach_vm_read failed at %s: %s"),
1843 memcpy (rdaddr, (
char *)copied + offset, length);
1848 memcpy ((
char *)copied + offset, wraddr, length);
1852 for (region_address = low_address, remaining_length = aligned_length;
1853 region_address < low_address + aligned_length;
1854 region_address += region_length, remaining_length -= region_length)
1856 vm_region_submap_short_info_data_64_t info;
1857 mach_vm_address_t region_start = region_address;
1858 mach_msg_type_number_t count;
1859 natural_t region_depth;
1861 region_depth = 100000;
1862 count = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64;
1863 kret = mach_vm_region_recurse
1864 (task, ®ion_start, ®ion_length, ®ion_depth,
1865 (vm_region_recurse_info_t) &info, &count);
1867 if (kret != KERN_SUCCESS)
1870 "mach_vm_region_recurse failed at %s: %s\n"),
1872 mach_error_string (kret));
1877 (9,
_(
"darwin_read_write_inferior: "
1878 "mach_vm_region_recurse addr=%s, start=%s, len=%s\n"),
1884 if (region_start > region_address)
1886 warning (
_(
"No memory at %s (vs %s+0x%x). Nothing written"),
1889 (
unsigned)region_length);
1895 region_length -= (region_address - region_start);
1897 if (!(info.max_protection & VM_PROT_WRITE))
1899 kret = mach_vm_protect
1900 (task, region_address, region_length,
1901 TRUE, info.max_protection | VM_PROT_WRITE | VM_PROT_COPY);
1902 if (kret != KERN_SUCCESS)
1904 warning (
_(
"darwin_read_write_inf: "
1905 "mach_vm_protect max failed at %s: %s"),
1907 mach_error_string (kret));
1913 if (!(info.protection & VM_PROT_WRITE))
1915 kret = mach_vm_protect (task, region_address, region_length,
1916 FALSE, info.protection | VM_PROT_WRITE);
1917 if (kret != KERN_SUCCESS)
1919 warning (
_(
"darwin_read_write_inf: "
1920 "mach_vm_protect failed at %s (len=0x%lx): %s"),
1922 (
unsigned long)region_length, mach_error_string (kret));
1929 kret = mach_vm_write (task, low_address, copied, aligned_length);
1931 if (kret != KERN_SUCCESS)
1933 warning (
_(
"darwin_read_write_inferior: mach_vm_write failed: %s"),
1934 mach_error_string (kret));
1938 mach_vm_deallocate (mach_task_self (), copied, copy_count);
1946 #ifdef TASK_DYLD_INFO_COUNT
1952 struct task_dyld_info task_dyld_info;
1953 mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
1954 int sz = TASK_DYLD_INFO_COUNT *
sizeof (natural_t);
1960 kret = task_info (task, TASK_DYLD_INFO, (task_info_t) &task_dyld_info, &count);
1962 if (kret != KERN_SUCCESS)
1965 if (addr + length > sz)
1967 memcpy (rdaddr, (
char *)&task_dyld_info + addr, length);
1984 (8,
_(
"darwin_xfer_partial(%s, %s, rbuf=%s, wbuf=%s) pid=%u\n"),
1994 readbuf, writebuf, len);
2005 #ifdef TASK_DYLD_INFO_COUNT
2007 if (writebuf != NULL || readbuf == NULL)
2012 return darwin_read_dyld_info (inf->
priv->
task, offset, readbuf, len,
2028 exception_mask_t mask;
2031 if (enable_mach_exceptions)
2032 mask = EXC_MASK_ALL;
2036 mask = EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT;
2038 kret = task_set_exception_ports (inf->
priv->
task, mask, darwin_ex_port,
2039 EXCEPTION_DEFAULT, THREAD_STATE_NONE);
2047 static char path[PATH_MAX];
2050 res = proc_pidinfo (pid, PROC_PIDPATHINFO, 0, path, PATH_MAX);
2065 mach_port_name_array_t names;
2066 mach_msg_type_number_t names_count;
2067 mach_port_type_array_t types;
2068 mach_msg_type_number_t types_count;
2081 kret = mach_port_names (inf->
priv->
task, &names, &names_count, &types,
2084 if (kret != KERN_SUCCESS)
2090 for (i = 0; i < names_count; i++)
2092 mach_port_t local_name;
2093 mach_msg_type_name_t local_type;
2097 kret = mach_port_extract_right (inf->
priv->
task, names[i],
2098 MACH_MSG_TYPE_COPY_SEND,
2099 &local_name, &local_type);
2100 if (kret != KERN_SUCCESS)
2102 mach_port_deallocate (gdb_task, local_name);
2110 if (names[i] == lwp)
2115 vm_deallocate (gdb_task, (vm_address_t) names,
2116 names_count *
sizeof (mach_port_t));
2138 gdb_task = mach_task_self ();
2139 darwin_host_self = mach_host_self ();
2142 kret = host_page_size (darwin_host_self, &mach_page_size);
2143 if (kret != KERN_SUCCESS)
2145 mach_page_size = 0x1000;
2173 inferior_debug (2,
_(
"GDB task: 0x%lx, pid: %d\n"), mach_task_self (),
2177 &darwin_debug_flag,
_(
"\
2178 Set if printing inferior communication debugging statements."),
_(
"\
2179 Show if printing inferior communication debugging statements."), NULL,
2184 &enable_mach_exceptions,
_(
"\
2185 Set if mach exceptions are caught."),
_(
"\
2186 Show if mach exceptions are caught."),
_(
"\
2187 When this mode is on, all low level exceptions are reported before being\n\
2188 reported by the kernel."),
static ptid_t darwin_decode_message(mach_msg_header_t *hdr, darwin_thread_t **pthread, struct inferior **pinf, struct target_waitstatus *status)
void add_target(struct target_ops *t)
static struct target_ops * darwin_ops
ssize_t read(int fd, void *buf, size_t count)
static void darwin_dump_message(mach_msg_header_t *hdr, int disp_body)
struct private_thread_info * priv
static void darwin_resume_to(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal signal)
struct thread_info * find_thread_ptid(ptid_t ptid)
static struct inferior * darwin_inf_fake_stop
thread_state_flavor_t flavors[EXC_TYPES_COUNT]
#define PTRACE(CMD, PID, ADDR, SIG)
initialize_file_ftype _initialize_darwin_inferior
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void darwin_resume_inferior_threads(struct inferior *inf, int step, int nsignal)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
static enum target_xfer_status darwin_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static int darwin_suspend_inferior_it(struct inferior *inf, void *arg)
struct regcache * get_thread_regcache(ptid_t ptid)
void delete_thread(ptid_t)
static darwin_thread_t * darwin_find_thread(struct inferior *inf, thread_t thread)
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
static int darwin_read_write_inferior(task_t task, CORE_ADDR addr, gdb_byte *rdaddr, const gdb_byte *wraddr, ULONGEST length)
void warning(const char *fmt,...)
char *(* to_pid_to_str)(struct target_ops *, ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
struct type ** const(pascal_builtin_types[])
void darwin_set_sstep(thread_t thread, int enable)
void push_target(struct target_ops *t)
static void darwin_reply_to_all_pending_messages(struct inferior *inf)
struct ui_file * gdb_stdout
struct thread_info * add_thread_with_info(ptid_t ptid, struct private_thread_info *)
static int darwin_supports_multi_process(struct target_ops *self)
exception_mask_t masks[EXC_TYPES_COUNT]
static struct inferior * darwin_find_inferior_by_task(task_t port)
static void darwin_resume_inferior(struct inferior *inf)
exception_behavior_t behaviors[EXC_TYPES_COUNT]
static void darwin_execvp(const char *file, char *const argv[], char *const env[])
static int find_inferior_task_it(struct inferior *inf, void *port_ptr)
#define VEC_safe_push(T, V, O)
struct inferior * find_inferior_ptid(ptid_t ptid)
static kern_return_t darwin_save_exception_ports(darwin_inferior *inf)
struct inferior * iterate_over_inferiors(int(*callback)(struct inferior *, void *), void *data)
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_NORETURN(noprocess())
char * target_pid_to_str(ptid_t ptid)
static void darwin_pre_ptrace(void)
static void darwin_resume(ptid_t ptid, int step, enum gdb_signal signal)
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
static void darwin_stop_inferior(struct inferior *inf)
static ptid_t darwin_get_ada_task_ptid(struct target_ops *self, long lwp, long thread)
static ptid_t darwin_wait(ptid_t ptid, struct target_waitstatus *status)
mach_port_t darwin_ex_port
mach_port_t ports[EXC_TYPES_COUNT]
#define MACH_CHECK_ERROR(ret)
int breakpoint_inserted_here_p(struct address_space *aspace, CORE_ADDR pc)
ptid_t ptid_build(int pid, long lwp, long tid)
static int find_inferior_notify_it(struct inferior *inf, void *port_ptr)
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
static void darwin_setup_fake_stop_event(struct inferior *inf)
struct cmd_list_element * setlist
#define VEC_iterate(T, V, I, P)
static void darwin_encode_reply(mig_reply_error_t *reply, mach_msg_header_t *hdr, integer_t code)
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
void unmark_fd_no_cloexec(int fd)
static struct inferior * darwin_find_inferior_by_notify(mach_port_t port)
void initialize_file_ftype(void)
void startup_inferior(int ntraps)
mach_port_t darwin_host_self
static void darwin_stop(struct target_ops *self, ptid_t)
static void darwin_init_thread_list(struct inferior *inf)
static int darwin_thread_alive(struct target_ops *ops, ptid_t tpid)
darwin_exception_info exception_info
static int enable_mach_exceptions
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
enum darwin_msg_state msg_state
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
void(* to_resume)(struct target_ops *, ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
mach_msg_type_number_t data_count
struct cmd_list_element * showlist
#define gdb_assert_not_reached(message)
static void darwin_detach(struct target_ops *ops, const char *args, int from_tty)
ptid_t pid_to_ptid(int pid)
union target_waitstatus::@161 value
char * pulongest(ULONGEST u)
static char * darwin_pid_to_exec_file(struct target_ops *self, int pid)
int gdb_signal_to_host(enum gdb_signal)
enum gdb_signal gdb_signal_from_host(int)
#define VEC_index(T, V, I)
static kern_return_t darwin_restore_exception_ports(darwin_inferior *inf)
void target_mourn_inferior(void)
void thread_change_ptid(ptid_t old_ptid, ptid_t new_ptid)
static int darwin_resume_inferior_it(struct inferior *inf, void *arg)
static int darwin_decode_exception_message(mach_msg_header_t *hdr, struct inferior **pinf, darwin_thread_t **pthread)
int fork_inferior(char *exec_file_arg, char *allargs, char **env, void(*traceme_fun)(void), void(*init_trace_fun)(int), void(*pre_trace_fun)(void), char *shell_file_arg, void(*exec_fun)(const char *file, char *const *argv, char *const *env))
struct thread_info * add_thread_silent(ptid_t ptid)
const char * gdb_signal_to_name(enum gdb_signal)
unsigned int pending_messages
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
void printf_unfiltered(const char *format,...)
struct cmd_list_element * setdebuglist
static const unsigned char info_plist[] __attribute__((section("__TEXT,__info_plist"), used))
void(* to_detach)(struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE()
void inf_child_mourn_inferior(struct target_ops *ops)
static int cancel_breakpoint(ptid_t ptid)
char *(* to_pid_to_exec_file)(struct target_ops *, int pid) TARGET_DEFAULT_RETURN(NULL)
int target_is_pushed(struct target_ops *t)
static void darwin_ptrace_me(void)
char * normal_pid_to_str(ptid_t ptid)
static void inferior_debug(int level, const char *fmt,...) ATTRIBUTE_PRINTF(2
int ptid_get_pid(ptid_t ptid)
void vprintf_unfiltered(const char *format, va_list args)
static void darwin_suspend_inferior_threads(struct inferior *inf)
static void darwin_files_info(struct target_ops *ops)
void mach_check_error(kern_return_t ret, const char *file, unsigned int line, const char *func)
const char const char int
struct target_ops * inf_child_target(void)
static void darwin_attach_pid(struct inferior *inf)
long ptid_get_tid(ptid_t ptid)
void(* to_mourn_inferior)(struct target_ops *) TARGET_DEFAULT_FUNC(default_mourn_inferior)
mach_port_t darwin_port_set
static const char * unparse_exception_type(unsigned int i)
static void darwin_mourn_inferior(struct target_ops *ops)
void(* to_stop)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
static int darwin_resume_inferior_threads_it(struct inferior *inf, void *param)
#define START_INFERIOR_TRAPS_EXPECTED
enum target_waitkind kind
void(* to_kill)(struct target_ops *) TARGET_DEFAULT_NORETURN(noprocess())
struct ui_file * gdb_stderr
CORE_ADDR regcache_read_pc(struct regcache *regcache)
struct darwin_exception_msg event
char * safe_strerror(int)
const char * host_address_to_string(const void *addr)
static vm_size_t mach_page_size
static void darwin_create_inferior(struct target_ops *ops, char *exec_file, char *allargs, char **env, int from_tty)
void(* to_create_inferior)(struct target_ops *, char *, char *, char **, int)
unsigned char single_step
int parse_pid_to_attach(const char *args)
static void darwin_check_new_threads(struct inferior *inf)
struct address_space * get_regcache_aspace(const struct regcache *regcache)
struct thread_info * thread_list
struct inferior * current_inferior(void)
static void darwin_ptrace_him(int pid)
char * get_exec_file(int err)
unsigned long long ULONGEST
static void ATTRIBUTE_PRINTF(6, 0)
static void darwin_send_reply(struct inferior *inf, darwin_thread_t *thread)
void darwin_check_osabi(darwin_inferior *inf, thread_t thread)
const char * core_addr_to_string(const CORE_ADDR addr)
struct cmd_list_element * showdebuglist
struct private_inferior * priv
static void darwin_resume_thread(struct inferior *inf, darwin_thread_t *thread, int step, int nsignal)
static ptid_t darwin_wait_to(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
#define _POSIX_SPAWN_DISABLE_ASLR
int(* to_thread_alive)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(0)
static void darwin_kill_inferior(struct target_ops *ops)
void(* to_attach)(struct target_ops *ops, const char *, int)
void mark_fd_no_cloexec(int fd)
static unsigned int darwin_debug_flag
void gdb_flush(struct ui_file *file)
static void darwin_suspend_inferior(struct inferior *inf)
static int darwin_ptrace(const char *name, int request, int pid, PTRACE_TYPE_ARG3 arg3, int arg4)
ptid_t(* to_get_ada_task_ptid)(struct target_ops *, long lwp, long thread) TARGET_DEFAULT_FUNC(default_get_ada_task_ptid)
mach_msg_type_number_t count
static void set_enable_mach_exceptions(char *args, int from_tty, struct cmd_list_element *c)
void error(const char *fmt,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void darwin_complete_target(struct target_ops *target)
static int cmp_thread_t(const void *l, const void *r)
void inferior_appeared(struct inferior *inf, int pid)
void(* to_load)(struct target_ops *, const char *, int) TARGET_DEFAULT_NORETURN(tcomplain())
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int(* to_supports_multi_process)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
static void darwin_attach(struct target_ops *ops, const char *args, int from_tty)
const ULONGEST const LONGEST len
static char * darwin_pid_to_str(struct target_ops *ops, ptid_t tpid)