| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 2007,2011,2012 Petr Machata, Red Hat Inc. |
| 4 | * Copyright (C) 1998,2001,2004,2007,2008,2009 Juan Cespedes |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | */ |
| 21 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 22 | #include "config.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 23 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 24 | #define _GNU_SOURCE 1 |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 25 | #include <sys/ptrace.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 26 | #include <sys/types.h> |
| 27 | #include <sys/wait.h> |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 28 | #include <assert.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 29 | #include <errno.h> |
| 30 | #include <signal.h> |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 33 | #include <string.h> |
| Petr Machata | 97b2084 | 2011-11-22 16:50:36 +0100 | [diff] [blame] | 34 | #include <unistd.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 35 | |
| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 36 | #include "backend.h" |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 37 | #include "breakpoint.h" |
| 38 | #include "debug.h" |
| Petr Machata | cd97258 | 2012-01-07 03:02:07 +0100 | [diff] [blame] | 39 | #include "events.h" |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 40 | #include "proc.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 41 | |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 42 | static Event event; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 43 | |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 44 | /* A queue of events that we missed while enabling the |
| 45 | * breakpoint in one of tasks. */ |
| 46 | static Event * delayed_events = NULL; |
| 47 | static Event * end_delayed_events = NULL; |
| 48 | |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 49 | static enum callback_status |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 50 | first (Process * proc, void * data) |
| 51 | { |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 52 | return CBS_STOP; |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 55 | void |
| 56 | enque_event(Event * event) |
| 57 | { |
| 58 | debug(DEBUG_FUNCTION, "%d: queuing event %d for later", |
| 59 | event->proc->pid, event->type); |
| 60 | Event * ne = malloc(sizeof(*ne)); |
| 61 | if (ne == NULL) { |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 62 | fprintf(stderr, "event will be missed: %s\n", strerror(errno)); |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
| 66 | *ne = *event; |
| 67 | ne->next = NULL; |
| 68 | if (end_delayed_events == NULL) { |
| 69 | assert(delayed_events == NULL); |
| 70 | end_delayed_events = delayed_events = ne; |
| 71 | } |
| 72 | else { |
| 73 | assert(delayed_events != NULL); |
| 74 | end_delayed_events = end_delayed_events->next = ne; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | Event * |
| 79 | each_qd_event(enum ecb_status (*pred)(Event *, void *), void * data) |
| 80 | { |
| 81 | Event * prev = delayed_events; |
| 82 | Event * event; |
| 83 | for (event = prev; event != NULL; ) { |
| 84 | switch ((*pred)(event, data)) { |
| 85 | case ecb_cont: |
| 86 | prev = event; |
| 87 | event = event->next; |
| 88 | continue; |
| 89 | |
| 90 | case ecb_deque: |
| 91 | debug(DEBUG_FUNCTION, "dequeuing event %d for %d", |
| 92 | event->type, |
| 93 | event->proc != NULL ? event->proc->pid : -1); |
| 94 | /* |
| 95 | printf("dequeuing event %d for %d\n", event->type, |
| 96 | event->proc != NULL ? event->proc->pid : -1) ; |
| 97 | */ |
| 98 | if (end_delayed_events == event) |
| 99 | end_delayed_events = prev; |
| 100 | if (delayed_events == event) |
| 101 | delayed_events = event->next; |
| 102 | else |
| 103 | prev->next = event->next; |
| 104 | if (delayed_events == NULL) |
| 105 | end_delayed_events = NULL; |
| 106 | /* fall-through */ |
| 107 | |
| 108 | case ecb_yield: |
| 109 | return event; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | static enum ecb_status |
| 117 | event_process_not_reenabling(Event * event, void * data) |
| 118 | { |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 119 | if (event->proc == NULL |
| 120 | || event->proc->leader == NULL |
| 121 | || event->proc->leader->event_handler == NULL) |
| 122 | return ecb_deque; |
| 123 | else |
| 124 | return ecb_cont; |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static Event * |
| 128 | next_qd_event(void) |
| 129 | { |
| 130 | return each_qd_event(&event_process_not_reenabling, NULL); |
| 131 | } |
| 132 | |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 133 | int linux_in_waitpid = 0; |
| 134 | |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 135 | Event * |
| Petr Machata | 2662768 | 2011-07-08 18:15:32 +0200 | [diff] [blame] | 136 | next_event(void) |
| 137 | { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 138 | pid_t pid; |
| 139 | int status; |
| 140 | int tmp; |
| Petr Machata | ef46b3e | 2007-05-09 19:21:42 +0200 | [diff] [blame] | 141 | int stop_signal; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 142 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 143 | debug(DEBUG_FUNCTION, "next_event()"); |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 144 | Event * ev; |
| 145 | if ((ev = next_qd_event()) != NULL) { |
| 146 | event = *ev; |
| 147 | free(ev); |
| 148 | return &event; |
| 149 | } |
| 150 | |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 151 | if (!each_process(NULL, &first, NULL)) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 152 | debug(DEBUG_EVENT, "event: No more traced programs: exiting"); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 153 | exit(0); |
| 154 | } |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 155 | |
| 156 | linux_in_waitpid = 1; |
| Juan Cespedes | 6be8028 | 2009-05-28 19:06:00 +0200 | [diff] [blame] | 157 | pid = waitpid(-1, &status, __WALL); |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 158 | linux_in_waitpid = 0; |
| 159 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 160 | if (pid == -1) { |
| 161 | if (errno == ECHILD) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 162 | debug(DEBUG_EVENT, "event: No more traced programs: exiting"); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 163 | exit(0); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 164 | } else if (errno == EINTR) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 165 | debug(DEBUG_EVENT, "event: none (wait received EINTR?)"); |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 166 | event.type = EVENT_NONE; |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 167 | return &event; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 168 | } |
| 169 | perror("wait"); |
| 170 | exit(1); |
| 171 | } |
| 172 | event.proc = pid2proc(pid); |
| Juan Cespedes | 2721e6a | 2009-05-21 15:15:40 +0200 | [diff] [blame] | 173 | if (!event.proc || event.proc->state == STATE_BEING_CREATED) { |
| Petr Machata | 97b2084 | 2011-11-22 16:50:36 +0100 | [diff] [blame] | 174 | /* Work around (presumably) a bug on some kernels, |
| 175 | * where we are seeing a waitpid event even though the |
| 176 | * process is still reported to be running. Wait for |
| 177 | * the tracing stop to propagate. But don't get stuck |
| 178 | * here forever. |
| 179 | * |
| 180 | * We need the process in T, because there's a lot of |
| 181 | * ptracing going on all over the place, and these |
| 182 | * calls fail when the process is not in T. |
| 183 | * |
| 184 | * N.B. This was observed on RHEL 5 Itanium, but I'm |
| 185 | * turning this on globally, to save some poor soul |
| 186 | * down the road (which could well be me a year from |
| 187 | * now) the pain of figuring this out all over again. |
| 188 | * Petr Machata 2011-11-22. */ |
| 189 | int i = 0; |
| 190 | for (; i < 100 && process_status(pid) != ps_tracing_stop; ++i) { |
| 191 | debug(2, "waiting for %d to stop", pid); |
| 192 | usleep(10000); |
| 193 | } |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 194 | event.type = EVENT_NEW; |
| Juan Cespedes | 2721e6a | 2009-05-21 15:15:40 +0200 | [diff] [blame] | 195 | event.e_un.newpid = pid; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 196 | debug(DEBUG_EVENT, "event: NEW: pid=%d", pid); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 197 | return &event; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 198 | } |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 199 | get_arch_dep(event.proc); |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 200 | debug(3, "event from pid %u", pid); |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 201 | Process *leader = event.proc->leader; |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 202 | |
| Petr Machata | f2d2ba5 | 2011-07-09 11:03:26 +0200 | [diff] [blame] | 203 | /* The process should be stopped after the waitpid call. But |
| 204 | * when the whole thread group is terminated, we see |
| 205 | * individual tasks spontaneously transitioning from 't' to |
| 206 | * 'R' and 'Z'. Calls to ptrace fail and /proc/pid/status may |
| 207 | * not even be available anymore, so we can't check in |
| 208 | * advance. So we just drop the error checking around ptrace |
| 209 | * calls. We check for termination ex post when it fails, |
| 210 | * suppress the event, and let the event loop collect the |
| 211 | * termination in the next iteration. */ |
| 212 | #define CHECK_PROCESS_TERMINATED \ |
| 213 | do { \ |
| 214 | int errno_save = errno; \ |
| 215 | switch (process_stopped(pid)) \ |
| 216 | case 0: \ |
| 217 | case -1: { \ |
| 218 | debug(DEBUG_EVENT, \ |
| 219 | "process not stopped, is it terminating?"); \ |
| 220 | event.type = EVENT_NONE; \ |
| 221 | continue_process(event.proc->pid); \ |
| 222 | return &event; \ |
| 223 | } \ |
| 224 | errno = errno_save; \ |
| 225 | } while (0) |
| 226 | |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 227 | event.proc->instruction_pointer = (void *)(uintptr_t)-1; |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 228 | |
| Petr Machata | f2d2ba5 | 2011-07-09 11:03:26 +0200 | [diff] [blame] | 229 | /* Check for task termination now, before we have a need to |
| 230 | * call CHECK_PROCESS_TERMINATED later. That would suppress |
| 231 | * the event that we are processing. */ |
| 232 | if (WIFSIGNALED(status)) { |
| 233 | event.type = EVENT_EXIT_SIGNAL; |
| 234 | event.e_un.signum = WTERMSIG(status); |
| 235 | debug(DEBUG_EVENT, "event: EXIT_SIGNAL: pid=%d, signum=%d", pid, event.e_un.signum); |
| 236 | return &event; |
| 237 | } |
| 238 | if (WIFEXITED(status)) { |
| 239 | event.type = EVENT_EXIT; |
| 240 | event.e_un.ret_val = WEXITSTATUS(status); |
| 241 | debug(DEBUG_EVENT, "event: EXIT: pid=%d, status=%d", pid, event.e_un.ret_val); |
| 242 | return &event; |
| 243 | } |
| 244 | |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 245 | event.proc->instruction_pointer = get_instruction_pointer(event.proc); |
| 246 | if (event.proc->instruction_pointer == (void *)(uintptr_t)-1) { |
| Petr Machata | f2d2ba5 | 2011-07-09 11:03:26 +0200 | [diff] [blame] | 247 | CHECK_PROCESS_TERMINATED; |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 248 | if (errno != 0) |
| 249 | perror("get_instruction_pointer"); |
| Juan Cespedes | f0fdae9 | 1998-03-11 00:03:00 +0100 | [diff] [blame] | 250 | } |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 251 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 252 | switch (syscall_p(event.proc, status, &tmp)) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 253 | case 1: |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 254 | event.type = EVENT_SYSCALL; |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 255 | event.e_un.sysnum = tmp; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 256 | debug(DEBUG_EVENT, "event: SYSCALL: pid=%d, sysnum=%d", pid, tmp); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 257 | return &event; |
| 258 | case 2: |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 259 | event.type = EVENT_SYSRET; |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 260 | event.e_un.sysnum = tmp; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 261 | debug(DEBUG_EVENT, "event: SYSRET: pid=%d, sysnum=%d", pid, tmp); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 262 | return &event; |
| 263 | case 3: |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 264 | event.type = EVENT_ARCH_SYSCALL; |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 265 | event.e_un.sysnum = tmp; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 266 | debug(DEBUG_EVENT, "event: ARCH_SYSCALL: pid=%d, sysnum=%d", pid, tmp); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 267 | return &event; |
| 268 | case 4: |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 269 | event.type = EVENT_ARCH_SYSRET; |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 270 | event.e_un.sysnum = tmp; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 271 | debug(DEBUG_EVENT, "event: ARCH_SYSRET: pid=%d, sysnum=%d", pid, tmp); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 272 | return &event; |
| 273 | case -1: |
| Petr Machata | f2d2ba5 | 2011-07-09 11:03:26 +0200 | [diff] [blame] | 274 | CHECK_PROCESS_TERMINATED; |
| 275 | if (errno != 0) |
| 276 | perror("syscall_p"); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 277 | } |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 278 | if (WIFSTOPPED(status)) { |
| 279 | int what = status >> 16; |
| 280 | if (what == PTRACE_EVENT_VFORK |
| 281 | || what == PTRACE_EVENT_FORK |
| 282 | || what == PTRACE_EVENT_CLONE) { |
| 283 | unsigned long data; |
| 284 | event.type = what == PTRACE_EVENT_VFORK |
| 285 | ? EVENT_VFORK : EVENT_CLONE; |
| 286 | ptrace(PTRACE_GETEVENTMSG, pid, NULL, &data); |
| 287 | event.e_un.newpid = data; |
| 288 | debug(DEBUG_EVENT, "event: CLONE: pid=%d, newpid=%d", |
| 289 | pid, (int)data); |
| 290 | return &event; |
| 291 | } |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 292 | } |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 293 | if (WIFSTOPPED(status) && (status>>16 == PTRACE_EVENT_EXEC)) { |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 294 | event.type = EVENT_EXEC; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 295 | debug(DEBUG_EVENT, "event: EXEC: pid=%d", pid); |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 296 | return &event; |
| 297 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 298 | if (!WIFSTOPPED(status)) { |
| Juan Cespedes | 427b781 | 2009-07-06 23:05:30 +0200 | [diff] [blame] | 299 | /* should never happen */ |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 300 | event.type = EVENT_NONE; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 301 | debug(DEBUG_EVENT, "event: NONE: pid=%d (wait error?)", pid); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 302 | return &event; |
| 303 | } |
| Petr Machata | ef46b3e | 2007-05-09 19:21:42 +0200 | [diff] [blame] | 304 | |
| 305 | stop_signal = WSTOPSIG(status); |
| 306 | |
| 307 | /* On some targets, breakpoints are signalled not using |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 308 | SIGTRAP, but also with SIGILL, SIGSEGV or SIGEMT. SIGEMT |
| 309 | is not defined on Linux, but check for the others. |
| Petr Machata | ef46b3e | 2007-05-09 19:21:42 +0200 | [diff] [blame] | 310 | |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 311 | N.B. see comments in GDB's infrun.c for details. I've |
| 312 | actually seen this on an Itanium machine on RHEL 5, I don't |
| 313 | remember the exact kernel version anymore. ia64-sigill.s |
| 314 | in the test suite tests this. Petr Machata 2011-06-08. */ |
| 315 | void * break_address |
| 316 | = event.proc->instruction_pointer - DECR_PC_AFTER_BREAK; |
| 317 | if ((stop_signal == SIGSEGV || stop_signal == SIGILL) |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 318 | && leader != NULL |
| 319 | && address2bpstruct(leader, break_address)) |
| Petr Machata | ef46b3e | 2007-05-09 19:21:42 +0200 | [diff] [blame] | 320 | stop_signal = SIGTRAP; |
| Petr Machata | ef46b3e | 2007-05-09 19:21:42 +0200 | [diff] [blame] | 321 | |
| 322 | if (stop_signal != (SIGTRAP | event.proc->tracesysgood) |
| Juan Cespedes | 427b781 | 2009-07-06 23:05:30 +0200 | [diff] [blame] | 323 | && stop_signal != SIGTRAP) { |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 324 | event.type = EVENT_SIGNAL; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 325 | event.e_un.signum = stop_signal; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 326 | debug(DEBUG_EVENT, "event: SIGNAL: pid=%d, signum=%d", pid, stop_signal); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 327 | return &event; |
| 328 | } |
| Petr Machata | 55ed83b | 2007-05-17 16:24:15 +0200 | [diff] [blame] | 329 | |
| Juan Cespedes | 427b781 | 2009-07-06 23:05:30 +0200 | [diff] [blame] | 330 | /* last case [by exhaustion] */ |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 331 | event.type = EVENT_BREAKPOINT; |
| Juan Cespedes | 427b781 | 2009-07-06 23:05:30 +0200 | [diff] [blame] | 332 | |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 333 | event.e_un.brk_addr = break_address; |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 334 | debug(DEBUG_EVENT, "event: BREAKPOINT: pid=%d, addr=%p", pid, event.e_un.brk_addr); |
| Petr Machata | 6901b7e | 2011-07-09 11:00:33 +0200 | [diff] [blame] | 335 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 336 | return &event; |
| 337 | } |
| Petr Machata | cd97258 | 2012-01-07 03:02:07 +0100 | [diff] [blame] | 338 | |
| 339 | static enum ecb_status |
| 340 | event_for_proc(struct Event *event, void *data) |
| 341 | { |
| 342 | if (event->proc == data) |
| 343 | return ecb_deque; |
| 344 | else |
| 345 | return ecb_cont; |
| 346 | } |
| 347 | |
| 348 | void |
| 349 | delete_events_for(struct Process *proc) |
| 350 | { |
| 351 | struct Event *event; |
| 352 | while ((event = each_qd_event(&event_for_proc, proc)) != NULL) |
| 353 | free(event); |
| 354 | } |