| OLD | NEW |
| 1 /* Darwin support for GDB, the GNU debugger. | 1 /* Darwin support for GDB, the GNU debugger. |
| 2 Copyright (C) 2008-2012 Free Software Foundation, Inc. | 2 Copyright (C) 2008-2012 Free Software Foundation, Inc. |
| 3 | 3 |
| 4 Contributed by AdaCore. | 4 Contributed by AdaCore. |
| 5 | 5 |
| 6 This file is part of GDB. | 6 This file is part of GDB. |
| 7 | 7 |
| 8 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
| 9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
| 10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "gdbthread.h" | 32 #include "gdbthread.h" |
| 33 #include "regcache.h" | 33 #include "regcache.h" |
| 34 #include "event-top.h" | 34 #include "event-top.h" |
| 35 #include "inf-loop.h" | 35 #include "inf-loop.h" |
| 36 #include "gdb_stat.h" | 36 #include "gdb_stat.h" |
| 37 #include "exceptions.h" | 37 #include "exceptions.h" |
| 38 #include "inf-child.h" | 38 #include "inf-child.h" |
| 39 #include "value.h" | 39 #include "value.h" |
| 40 #include "arch-utils.h" | 40 #include "arch-utils.h" |
| 41 #include "bfd.h" | 41 #include "bfd.h" |
| 42 #include "bfd/mach-o.h" |
| 42 | 43 |
| 43 #include <sys/ptrace.h> | 44 #include <sys/ptrace.h> |
| 44 #include <sys/signal.h> | 45 #include <sys/signal.h> |
| 45 #include <machine/setjmp.h> | 46 #include <machine/setjmp.h> |
| 46 #include <sys/types.h> | 47 #include <sys/types.h> |
| 47 #include <unistd.h> | 48 #include <unistd.h> |
| 48 #include <signal.h> | 49 #include <signal.h> |
| 49 #include <string.h> | 50 #include <string.h> |
| 50 #include <ctype.h> | 51 #include <ctype.h> |
| 51 #include <sys/param.h> | 52 #include <sys/param.h> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 | 85 |
| 85 #define PTRACE(CMD, PID, ADDR, SIG) \ | 86 #define PTRACE(CMD, PID, ADDR, SIG) \ |
| 86 darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG)) | 87 darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG)) |
| 87 | 88 |
| 88 extern boolean_t exc_server (mach_msg_header_t *in, mach_msg_header_t *out); | 89 extern boolean_t exc_server (mach_msg_header_t *in, mach_msg_header_t *out); |
| 89 | 90 |
| 90 static void darwin_stop (ptid_t); | 91 static void darwin_stop (ptid_t); |
| 91 | 92 |
| 92 static void darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step, | 93 static void darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step, |
| 93 enum target_signal signal); | 94 enum gdb_signal signal); |
| 94 static void darwin_resume (ptid_t ptid, int step, | 95 static void darwin_resume (ptid_t ptid, int step, |
| 95 » » » enum target_signal signal); | 96 » » » enum gdb_signal signal); |
| 96 | 97 |
| 97 static ptid_t darwin_wait_to (struct target_ops *ops, ptid_t ptid, | 98 static ptid_t darwin_wait_to (struct target_ops *ops, ptid_t ptid, |
| 98 struct target_waitstatus *status, int options); | 99 struct target_waitstatus *status, int options); |
| 99 static ptid_t darwin_wait (ptid_t ptid, struct target_waitstatus *status); | 100 static ptid_t darwin_wait (ptid_t ptid, struct target_waitstatus *status); |
| 100 | 101 |
| 101 static void darwin_mourn_inferior (struct target_ops *ops); | 102 static void darwin_mourn_inferior (struct target_ops *ops); |
| 102 | 103 |
| 103 static void darwin_kill_inferior (struct target_ops *ops); | 104 static void darwin_kill_inferior (struct target_ops *ops); |
| 104 | 105 |
| 105 static void darwin_ptrace_me (void); | 106 static void darwin_ptrace_me (void); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 else if (nsignal) | 698 else if (nsignal) |
| 698 { | 699 { |
| 699 /* Note: ptrace is allowed only if the process is stopped. | 700 /* Note: ptrace is allowed only if the process is stopped. |
| 700 Directly send the signal to the thread. */ | 701 Directly send the signal to the thread. */ |
| 701 res = syscall (SYS___pthread_kill, thread->gdb_port, nsignal); | 702 res = syscall (SYS___pthread_kill, thread->gdb_port, nsignal); |
| 702 inferior_debug (4, _("darwin_resume_thread: kill 0x%x %d: %d\n"), | 703 inferior_debug (4, _("darwin_resume_thread: kill 0x%x %d: %d\n"), |
| 703 thread->gdb_port, nsignal, res); | 704 thread->gdb_port, nsignal, res); |
| 704 thread->signaled = 1; | 705 thread->signaled = 1; |
| 705 } | 706 } |
| 706 | 707 |
| 707 /* Set single step. */ | 708 /* Set or reset single step. */ |
| 708 inferior_debug (4, _("darwin_set_sstep (thread=%x, enable=%d)\n"), | 709 if (step != thread->single_step) |
| 709 thread->gdb_port, step); | 710 » { |
| 710 darwin_set_sstep (thread->gdb_port, step); | 711 » inferior_debug (4, _("darwin_set_sstep (thread=%x, enable=%d)\n"), |
| 711 thread->single_step = step; | 712 » » » thread->gdb_port, step); |
| 713 » darwin_set_sstep (thread->gdb_port, step); |
| 714 » thread->single_step = step; |
| 715 » } |
| 712 | 716 |
| 713 darwin_send_reply (inf, thread); | 717 darwin_send_reply (inf, thread); |
| 714 thread->msg_state = DARWIN_RUNNING; | 718 thread->msg_state = DARWIN_RUNNING; |
| 715 break; | 719 break; |
| 716 | 720 |
| 717 case DARWIN_RUNNING: | 721 case DARWIN_RUNNING: |
| 718 break; | 722 break; |
| 719 | 723 |
| 720 case DARWIN_STOPPED: | 724 case DARWIN_STOPPED: |
| 721 kret = thread_resume (thread->gdb_port); | 725 kret = thread_resume (thread->gdb_port); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 break; | 780 break; |
| 777 case DARWIN_RUNNING: | 781 case DARWIN_RUNNING: |
| 778 kret = thread_suspend (thread->gdb_port); | 782 kret = thread_suspend (thread->gdb_port); |
| 779 MACH_CHECK_ERROR (kret); | 783 MACH_CHECK_ERROR (kret); |
| 780 thread->msg_state = DARWIN_STOPPED; | 784 thread->msg_state = DARWIN_STOPPED; |
| 781 break; | 785 break; |
| 782 } | 786 } |
| 783 } | 787 } |
| 784 | 788 |
| 785 static void | 789 static void |
| 786 darwin_resume (ptid_t ptid, int step, enum target_signal signal) | 790 darwin_resume (ptid_t ptid, int step, enum gdb_signal signal) |
| 787 { | 791 { |
| 788 struct target_waitstatus status; | 792 struct target_waitstatus status; |
| 789 int pid; | 793 int pid; |
| 790 | 794 |
| 791 kern_return_t kret; | 795 kern_return_t kret; |
| 792 int res; | 796 int res; |
| 793 int nsignal; | 797 int nsignal; |
| 794 struct inferior *inf; | 798 struct inferior *inf; |
| 795 | 799 |
| 796 inferior_debug | 800 inferior_debug |
| 797 (2, _("darwin_resume: pid=%d, tid=0x%x, step=%d, signal=%d\n"), | 801 (2, _("darwin_resume: pid=%d, tid=0x%x, step=%d, signal=%d\n"), |
| 798 ptid_get_pid (ptid), ptid_get_tid (ptid), step, signal); | 802 ptid_get_pid (ptid), ptid_get_tid (ptid), step, signal); |
| 799 | 803 |
| 800 if (signal == TARGET_SIGNAL_0) | 804 if (signal == GDB_SIGNAL_0) |
| 801 nsignal = 0; | 805 nsignal = 0; |
| 802 else | 806 else |
| 803 nsignal = target_signal_to_host (signal); | 807 nsignal = gdb_signal_to_host (signal); |
| 804 | 808 |
| 805 /* Don't try to single step all threads. */ | 809 /* Don't try to single step all threads. */ |
| 806 if (step) | 810 if (step) |
| 807 ptid = inferior_ptid; | 811 ptid = inferior_ptid; |
| 808 | 812 |
| 809 /* minus_one_ptid is RESUME_ALL. */ | 813 /* minus_one_ptid is RESUME_ALL. */ |
| 810 if (ptid_equal (ptid, minus_one_ptid)) | 814 if (ptid_equal (ptid, minus_one_ptid)) |
| 811 { | 815 { |
| 812 struct resume_inferior_threads_param param; | 816 struct resume_inferior_threads_param param; |
| 813 | 817 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 842 darwin_resume_thread (inf, thread, step, nsignal); | 846 darwin_resume_thread (inf, thread, step, nsignal); |
| 843 } | 847 } |
| 844 | 848 |
| 845 /* Resume the task. */ | 849 /* Resume the task. */ |
| 846 darwin_resume_inferior (inf); | 850 darwin_resume_inferior (inf); |
| 847 } | 851 } |
| 848 } | 852 } |
| 849 | 853 |
| 850 static void | 854 static void |
| 851 darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step, | 855 darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step, |
| 852 enum target_signal signal) | 856 enum gdb_signal signal) |
| 853 { | 857 { |
| 854 return darwin_resume (ptid, step, signal); | 858 return darwin_resume (ptid, step, signal); |
| 855 } | 859 } |
| 856 | 860 |
| 857 static ptid_t | 861 static ptid_t |
| 858 darwin_decode_message (mach_msg_header_t *hdr, | 862 darwin_decode_message (mach_msg_header_t *hdr, |
| 859 darwin_thread_t **pthread, | 863 darwin_thread_t **pthread, |
| 860 struct inferior **pinf, | 864 struct inferior **pinf, |
| 861 struct target_waitstatus *status) | 865 struct target_waitstatus *status) |
| 862 { | 866 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 case EXC_ARITHMETIC: | 906 case EXC_ARITHMETIC: |
| 903 status->value.sig = TARGET_EXC_ARITHMETIC; | 907 status->value.sig = TARGET_EXC_ARITHMETIC; |
| 904 break; | 908 break; |
| 905 case EXC_EMULATION: | 909 case EXC_EMULATION: |
| 906 status->value.sig = TARGET_EXC_EMULATION; | 910 status->value.sig = TARGET_EXC_EMULATION; |
| 907 break; | 911 break; |
| 908 case EXC_SOFTWARE: | 912 case EXC_SOFTWARE: |
| 909 if (thread->event.ex_data[0] == EXC_SOFT_SIGNAL) | 913 if (thread->event.ex_data[0] == EXC_SOFT_SIGNAL) |
| 910 { | 914 { |
| 911 status->value.sig = | 915 status->value.sig = |
| 912 » » target_signal_from_host (thread->event.ex_data[1]); | 916 » » gdb_signal_from_host (thread->event.ex_data[1]); |
| 913 inferior_debug (5, _(" (signal %d: %s)\n"), | 917 inferior_debug (5, _(" (signal %d: %s)\n"), |
| 914 thread->event.ex_data[1], | 918 thread->event.ex_data[1], |
| 915 » » » target_signal_to_name (status->value.sig)); | 919 » » » gdb_signal_to_name (status->value.sig)); |
| 916 | 920 |
| 917 /* If the thread is stopped because it has received a signal | 921 /* If the thread is stopped because it has received a signal |
| 918 that gdb has just sent, continue. */ | 922 that gdb has just sent, continue. */ |
| 919 if (thread->signaled) | 923 if (thread->signaled) |
| 920 { | 924 { |
| 921 thread->signaled = 0; | 925 thread->signaled = 0; |
| 922 darwin_send_reply (inf, thread); | 926 darwin_send_reply (inf, thread); |
| 923 thread->msg_state = DARWIN_RUNNING; | 927 thread->msg_state = DARWIN_RUNNING; |
| 924 status->kind = TARGET_WAITKIND_IGNORE; | 928 status->kind = TARGET_WAITKIND_IGNORE; |
| 925 } | 929 } |
| 926 } | 930 } |
| 927 else | 931 else |
| 928 status->value.sig = TARGET_EXC_SOFTWARE; | 932 status->value.sig = TARGET_EXC_SOFTWARE; |
| 929 break; | 933 break; |
| 930 case EXC_BREAKPOINT: | 934 case EXC_BREAKPOINT: |
| 931 /* Many internal GDB routines expect breakpoints to be reported | 935 /* Many internal GDB routines expect breakpoints to be reported |
| 932 » as TARGET_SIGNAL_TRAP, and will report TARGET_EXC_BREAKPOINT | 936 » as GDB_SIGNAL_TRAP, and will report TARGET_EXC_BREAKPOINT |
| 933 as a spurious signal. */ | 937 as a spurious signal. */ |
| 934 » status->value.sig = TARGET_SIGNAL_TRAP; | 938 » status->value.sig = GDB_SIGNAL_TRAP; |
| 935 break; | 939 break; |
| 936 default: | 940 default: |
| 937 » status->value.sig = TARGET_SIGNAL_UNKNOWN; | 941 » status->value.sig = GDB_SIGNAL_UNKNOWN; |
| 938 break; | 942 break; |
| 939 } | 943 } |
| 940 | 944 |
| 941 return ptid_build (inf->pid, 0, thread->gdb_port); | 945 return ptid_build (inf->pid, 0, thread->gdb_port); |
| 942 } | 946 } |
| 943 | 947 |
| 944 *pinf = NULL; | 948 *pinf = NULL; |
| 945 *pthread = NULL; | 949 *pthread = NULL; |
| 946 | 950 |
| 947 inf = darwin_find_inferior_by_notify (hdr->msgh_local_port); | 951 inf = darwin_find_inferior_by_notify (hdr->msgh_local_port); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 (2, _("darwin_wait: waiting for a message pid=%d thread=%lx\n"), | 1045 (2, _("darwin_wait: waiting for a message pid=%d thread=%lx\n"), |
| 1042 ptid_get_pid (ptid), ptid_get_tid (ptid)); | 1046 ptid_get_pid (ptid), ptid_get_tid (ptid)); |
| 1043 | 1047 |
| 1044 /* Handle fake stop events at first. */ | 1048 /* Handle fake stop events at first. */ |
| 1045 if (darwin_inf_fake_stop != NULL) | 1049 if (darwin_inf_fake_stop != NULL) |
| 1046 { | 1050 { |
| 1047 inf = darwin_inf_fake_stop; | 1051 inf = darwin_inf_fake_stop; |
| 1048 darwin_inf_fake_stop = NULL; | 1052 darwin_inf_fake_stop = NULL; |
| 1049 | 1053 |
| 1050 status->kind = TARGET_WAITKIND_STOPPED; | 1054 status->kind = TARGET_WAITKIND_STOPPED; |
| 1051 status->value.sig = TARGET_SIGNAL_TRAP; | 1055 status->value.sig = GDB_SIGNAL_TRAP; |
| 1052 thread = VEC_index (darwin_thread_t, inf->private->threads, 0); | 1056 thread = VEC_index (darwin_thread_t, inf->private->threads, 0); |
| 1053 thread->msg_state = DARWIN_STOPPED; | 1057 thread->msg_state = DARWIN_STOPPED; |
| 1054 return ptid_build (inf->pid, 0, thread->gdb_port); | 1058 return ptid_build (inf->pid, 0, thread->gdb_port); |
| 1055 } | 1059 } |
| 1056 | 1060 |
| 1057 do | 1061 do |
| 1058 { | 1062 { |
| 1059 /* set_sigint_trap (); */ | 1063 /* set_sigint_trap (); */ |
| 1060 | 1064 |
| 1061 /* Wait for a message. */ | 1065 /* Wait for a message. */ |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 | 1256 |
| 1253 res = kill (inf->pid, SIGSTOP); | 1257 res = kill (inf->pid, SIGSTOP); |
| 1254 if (res != 0) | 1258 if (res != 0) |
| 1255 warning (_("cannot kill: %s"), safe_strerror (errno)); | 1259 warning (_("cannot kill: %s"), safe_strerror (errno)); |
| 1256 | 1260 |
| 1257 /* Wait until the process is really stopped. */ | 1261 /* Wait until the process is really stopped. */ |
| 1258 while (1) | 1262 while (1) |
| 1259 { | 1263 { |
| 1260 ptid = darwin_wait (inferior_ptid, &wstatus); | 1264 ptid = darwin_wait (inferior_ptid, &wstatus); |
| 1261 if (wstatus.kind == TARGET_WAITKIND_STOPPED | 1265 if (wstatus.kind == TARGET_WAITKIND_STOPPED |
| 1262 » && wstatus.value.sig == TARGET_SIGNAL_STOP) | 1266 » && wstatus.value.sig == GDB_SIGNAL_STOP) |
| 1263 break; | 1267 break; |
| 1264 } | 1268 } |
| 1265 } | 1269 } |
| 1266 | 1270 |
| 1267 static kern_return_t | 1271 static kern_return_t |
| 1268 darwin_save_exception_ports (darwin_inferior *inf) | 1272 darwin_save_exception_ports (darwin_inferior *inf) |
| 1269 { | 1273 { |
| 1270 kern_return_t kret; | 1274 kern_return_t kret; |
| 1271 | 1275 |
| 1272 inf->exception_info.count = | 1276 inf->exception_info.count = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 ptid_t ptid; | 1309 ptid_t ptid; |
| 1306 kern_return_t kret; | 1310 kern_return_t kret; |
| 1307 int status; | 1311 int status; |
| 1308 int res; | 1312 int res; |
| 1309 | 1313 |
| 1310 if (ptid_equal (inferior_ptid, null_ptid)) | 1314 if (ptid_equal (inferior_ptid, null_ptid)) |
| 1311 return; | 1315 return; |
| 1312 | 1316 |
| 1313 gdb_assert (inf != NULL); | 1317 gdb_assert (inf != NULL); |
| 1314 | 1318 |
| 1315 if (!inf->private->no_ptrace) | 1319 kret = darwin_restore_exception_ports (inf->private); |
| 1320 MACH_CHECK_ERROR (kret); |
| 1321 |
| 1322 darwin_reply_to_all_pending_messages (inf); |
| 1323 |
| 1324 res = kill (inf->pid, 9); |
| 1325 |
| 1326 if (res == 0) |
| 1316 { | 1327 { |
| 1317 darwin_stop_inferior (inf); | |
| 1318 | |
| 1319 res = PTRACE (PT_KILL, inf->pid, 0, 0); | |
| 1320 if (res != 0) | |
| 1321 warning (_("Failed to kill inferior: ptrace returned %d " | |
| 1322 "[%s] (pid=%d)"), | |
| 1323 res, safe_strerror (errno), inf->pid); | |
| 1324 | |
| 1325 darwin_reply_to_all_pending_messages (inf); | |
| 1326 | |
| 1327 darwin_resume_inferior (inf); | 1328 darwin_resume_inferior (inf); |
| 1328 | 1329 » |
| 1329 ptid = darwin_wait (inferior_ptid, &wstatus); | 1330 ptid = darwin_wait (inferior_ptid, &wstatus); |
| 1330 } | 1331 } |
| 1331 else | 1332 else if (errno != ESRCH) |
| 1332 { | 1333 warning (_("Failed to kill inferior: kill (%d, 9) returned [%s]"), |
| 1333 kret = darwin_restore_exception_ports (inf->private); | 1334 » inf->pid, safe_strerror (errno)); |
| 1334 MACH_CHECK_ERROR (kret); | |
| 1335 | |
| 1336 darwin_reply_to_all_pending_messages (inf); | |
| 1337 | |
| 1338 darwin_resume_inferior (inf); | |
| 1339 | |
| 1340 res = kill (inf->pid, 9); | |
| 1341 | |
| 1342 ptid = darwin_wait (inferior_ptid, &wstatus); | |
| 1343 } | |
| 1344 | 1335 |
| 1345 target_mourn_inferior (); | 1336 target_mourn_inferior (); |
| 1346 } | 1337 } |
| 1347 | 1338 |
| 1348 static void | 1339 static void |
| 1349 darwin_attach_pid (struct inferior *inf) | 1340 darwin_attach_pid (struct inferior *inf) |
| 1350 { | 1341 { |
| 1351 kern_return_t kret; | 1342 kern_return_t kret; |
| 1352 mach_port_t prev_port; | 1343 mach_port_t prev_port; |
| 1353 int traps_expected; | 1344 int traps_expected; |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 vm_deallocate (gdb_task, (vm_address_t) names, | 1996 vm_deallocate (gdb_task, (vm_address_t) names, |
| 2006 names_count * sizeof (mach_port_t)); | 1997 names_count * sizeof (mach_port_t)); |
| 2007 | 1998 |
| 2008 if (res) | 1999 if (res) |
| 2009 return ptid_build (ptid_get_pid (inferior_ptid), 0, res); | 2000 return ptid_build (ptid_get_pid (inferior_ptid), 0, res); |
| 2010 else | 2001 else |
| 2011 return null_ptid; | 2002 return null_ptid; |
| 2012 } | 2003 } |
| 2013 | 2004 |
| 2014 static int | 2005 static int |
error: old chunk mismatch |
None
| OLD | NEW |