OLD | NEW |
1 /* Low level interface to ptrace, for the remote server for GDB. | 1 /* Low level interface to ptrace, for the remote server for GDB. |
2 Copyright (C) 1995-1996, 1998-2012 Free Software Foundation, Inc. | 2 Copyright (C) 1995-2013 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GDB. | 4 This file is part of GDB. |
5 | 5 |
6 This program is free software; you can redistribute it and/or modify | 6 This program is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation; either version 3 of the License, or | 8 the Free Software Foundation; either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 This program is distributed in the hope that it will be useful, | 11 This program is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
18 | 18 |
19 #include "server.h" | 19 #include "server.h" |
20 #include "linux-low.h" | 20 #include "linux-low.h" |
21 #include "linux-osdata.h" | 21 #include "linux-osdata.h" |
22 #include "agent.h" | 22 #include "agent.h" |
23 | 23 |
24 #include <sys/wait.h> | 24 #include "nat/linux-nat.h" |
| 25 #include "nat/linux-waitpid.h" |
| 26 #include "gdb_wait.h" |
25 #include <stdio.h> | 27 #include <stdio.h> |
26 #include <sys/param.h> | |
27 #include <sys/ptrace.h> | 28 #include <sys/ptrace.h> |
28 #include "linux-ptrace.h" | 29 #include "linux-ptrace.h" |
29 #include "linux-procfs.h" | 30 #include "linux-procfs.h" |
30 #include <signal.h> | 31 #include <signal.h> |
31 #include <sys/ioctl.h> | 32 #include <sys/ioctl.h> |
32 #include <fcntl.h> | 33 #include <fcntl.h> |
33 #include <string.h> | 34 #include <string.h> |
34 #include <stdlib.h> | 35 #include <stdlib.h> |
35 #include <unistd.h> | 36 #include <unistd.h> |
36 #include <errno.h> | 37 #include <errno.h> |
37 #include <sys/syscall.h> | 38 #include <sys/syscall.h> |
38 #include <sched.h> | 39 #include <sched.h> |
39 #include <ctype.h> | 40 #include <ctype.h> |
40 #include <pwd.h> | 41 #include <pwd.h> |
41 #include <sys/types.h> | 42 #include <sys/types.h> |
42 #include <dirent.h> | 43 #include <dirent.h> |
43 #include <sys/stat.h> | 44 #include <sys/stat.h> |
44 #include <sys/vfs.h> | 45 #include <sys/vfs.h> |
45 #include <sys/uio.h> | 46 #include <sys/uio.h> |
| 47 #include "filestuff.h" |
| 48 #include "tracepoint.h" |
| 49 #include "hostio.h" |
46 #ifndef ELFMAG0 | 50 #ifndef ELFMAG0 |
47 /* Don't include <linux/elf.h> here. If it got included by gdb_proc_service.h | 51 /* Don't include <linux/elf.h> here. If it got included by gdb_proc_service.h |
48 then ELFMAG0 will have been defined. If it didn't get included by | 52 then ELFMAG0 will have been defined. If it didn't get included by |
49 gdb_proc_service.h then including it will likely introduce a duplicate | 53 gdb_proc_service.h then including it will likely introduce a duplicate |
50 definition of elf_fpregset_t. */ | 54 definition of elf_fpregset_t. */ |
51 #include <elf.h> | 55 #include <elf.h> |
52 #endif | 56 #endif |
53 | 57 |
54 #ifndef SPUFS_MAGIC | 58 #ifndef SPUFS_MAGIC |
55 #define SPUFS_MAGIC 0x23c9b64e | 59 #define SPUFS_MAGIC 0x23c9b64e |
(...skipping 13 matching lines...) Expand all Loading... |
69 #ifndef W_STOPCODE | 73 #ifndef W_STOPCODE |
70 #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) | 74 #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) |
71 #endif | 75 #endif |
72 | 76 |
73 /* This is the kernel's hard limit. Not to be confused with | 77 /* This is the kernel's hard limit. Not to be confused with |
74 SIGRTMIN. */ | 78 SIGRTMIN. */ |
75 #ifndef __SIGRTMIN | 79 #ifndef __SIGRTMIN |
76 #define __SIGRTMIN 32 | 80 #define __SIGRTMIN 32 |
77 #endif | 81 #endif |
78 | 82 |
79 #ifdef __UCLIBC__ | 83 /* Some targets did not define these ptrace constants from the start, |
80 #if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_HAS_MMU__)) | 84 so gdbserver defines them locally here. In the future, these may |
81 /* PTRACE_TEXT_ADDR and friends. */ | 85 be removed after they are added to asm/ptrace.h. */ |
82 #include <asm/ptrace.h> | 86 #if !(defined(PT_TEXT_ADDR) \ |
83 #define HAS_NOMMU | 87 || defined(PT_DATA_ADDR) \ |
| 88 || defined(PT_TEXT_END_ADDR)) |
| 89 #if defined(__mcoldfire__) |
| 90 /* These are still undefined in 3.10 kernels. */ |
| 91 #define PT_TEXT_ADDR 49*4 |
| 92 #define PT_DATA_ADDR 50*4 |
| 93 #define PT_TEXT_END_ADDR 51*4 |
| 94 /* BFIN already defines these since at least 2.6.32 kernels. */ |
| 95 #elif defined(BFIN) |
| 96 #define PT_TEXT_ADDR 220 |
| 97 #define PT_TEXT_END_ADDR 224 |
| 98 #define PT_DATA_ADDR 228 |
| 99 /* These are still undefined in 3.10 kernels. */ |
| 100 #elif defined(__TMS320C6X__) |
| 101 #define PT_TEXT_ADDR (0x10000*4) |
| 102 #define PT_DATA_ADDR (0x10004*4) |
| 103 #define PT_TEXT_END_ADDR (0x10008*4) |
84 #endif | 104 #endif |
85 #endif | 105 #endif |
86 | 106 |
| 107 #ifdef HAVE_LINUX_BTRACE |
| 108 # include "linux-btrace.h" |
| 109 #endif |
| 110 |
87 #ifndef HAVE_ELF32_AUXV_T | 111 #ifndef HAVE_ELF32_AUXV_T |
88 /* Copied from glibc's elf.h. */ | 112 /* Copied from glibc's elf.h. */ |
89 typedef struct | 113 typedef struct |
90 { | 114 { |
91 uint32_t a_type; /* Entry type */ | 115 uint32_t a_type; /* Entry type */ |
92 union | 116 union |
93 { | 117 { |
94 uint32_t a_val; /* Integer value */ | 118 uint32_t a_val; /* Integer value */ |
95 /* We use to have pointer elements added here. We cannot do that, | 119 /* We use to have pointer elements added here. We cannot do that, |
96 though, since it does not work when using 32-bit definitions | 120 though, since it does not work when using 32-bit definitions |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 /* This is set while stop_all_lwps is in effect. */ | 213 /* This is set while stop_all_lwps is in effect. */ |
190 enum stopping_threads_kind stopping_threads = NOT_STOPPING_THREADS; | 214 enum stopping_threads_kind stopping_threads = NOT_STOPPING_THREADS; |
191 | 215 |
192 /* FIXME make into a target method? */ | 216 /* FIXME make into a target method? */ |
193 int using_threads = 1; | 217 int using_threads = 1; |
194 | 218 |
195 /* True if we're presently stabilizing threads (moving them out of | 219 /* True if we're presently stabilizing threads (moving them out of |
196 jump pads). */ | 220 jump pads). */ |
197 static int stabilizing_threads; | 221 static int stabilizing_threads; |
198 | 222 |
199 /* This flag is true iff we've just created or attached to our first | |
200 inferior but it has not stopped yet. As soon as it does, we need | |
201 to call the low target's arch_setup callback. Doing this only on | |
202 the first inferior avoids reinializing the architecture on every | |
203 inferior, and avoids messing with the register caches of the | |
204 already running inferiors. NOTE: this assumes all inferiors under | |
205 control of gdbserver have the same architecture. */ | |
206 static int new_inferior; | |
207 | |
208 static void linux_resume_one_lwp (struct lwp_info *lwp, | 223 static void linux_resume_one_lwp (struct lwp_info *lwp, |
209 int step, int signal, siginfo_t *info); | 224 int step, int signal, siginfo_t *info); |
210 static void linux_resume (struct thread_resume *resume_info, size_t n); | 225 static void linux_resume (struct thread_resume *resume_info, size_t n); |
211 static void stop_all_lwps (int suspend, struct lwp_info *except); | 226 static void stop_all_lwps (int suspend, struct lwp_info *except); |
212 static void unstop_all_lwps (int unsuspend, struct lwp_info *except); | 227 static void unstop_all_lwps (int unsuspend, struct lwp_info *except); |
213 static int linux_wait_for_event (ptid_t ptid, int *wstat, int options); | 228 static int linux_wait_for_event (ptid_t ptid, int *wstat, int options); |
214 static void *add_lwp (ptid_t ptid); | 229 static void *add_lwp (ptid_t ptid); |
215 static int linux_stopped_by_watchpoint (void); | 230 static int linux_stopped_by_watchpoint (void); |
216 static void mark_lwp_dead (struct lwp_info *lwp, int wstat); | 231 static void mark_lwp_dead (struct lwp_info *lwp, int wstat); |
217 static void proceed_all_lwps (void); | 232 static void proceed_all_lwps (void); |
218 static int finish_step_over (struct lwp_info *lwp); | 233 static int finish_step_over (struct lwp_info *lwp); |
219 static CORE_ADDR get_stop_pc (struct lwp_info *lwp); | 234 static CORE_ADDR get_stop_pc (struct lwp_info *lwp); |
220 static int kill_lwp (unsigned long lwpid, int signo); | 235 static int kill_lwp (unsigned long lwpid, int signo); |
221 static void linux_enable_event_reporting (int pid); | |
222 | 236 |
223 /* True if the low target can hardware single-step. Such targets | 237 /* True if the low target can hardware single-step. Such targets |
224 don't need a BREAKPOINT_REINSERT_ADDR callback. */ | 238 don't need a BREAKPOINT_REINSERT_ADDR callback. */ |
225 | 239 |
226 static int | 240 static int |
227 can_hardware_single_step (void) | 241 can_hardware_single_step (void) |
228 { | 242 { |
229 return (the_low_target.breakpoint_reinsert_addr == NULL); | 243 return (the_low_target.breakpoint_reinsert_addr == NULL); |
230 } | 244 } |
231 | 245 |
232 /* True if the low target supports memory breakpoints. If so, we'll | 246 /* True if the low target supports memory breakpoints. If so, we'll |
233 have a GET_PC implementation. */ | 247 have a GET_PC implementation. */ |
234 | 248 |
235 static int | 249 static int |
236 supports_breakpoints (void) | 250 supports_breakpoints (void) |
237 { | 251 { |
238 return (the_low_target.get_pc != NULL); | 252 return (the_low_target.get_pc != NULL); |
239 } | 253 } |
240 | 254 |
241 /* Returns true if this target can support fast tracepoints. This | 255 /* Returns true if this target can support fast tracepoints. This |
242 does not mean that the in-process agent has been loaded in the | 256 does not mean that the in-process agent has been loaded in the |
243 inferior. */ | 257 inferior. */ |
244 | 258 |
245 static int | 259 static int |
246 supports_fast_tracepoints (void) | 260 supports_fast_tracepoints (void) |
247 { | 261 { |
248 return the_low_target.install_fast_tracepoint_jump_pad != NULL; | 262 return the_low_target.install_fast_tracepoint_jump_pad != NULL; |
249 } | 263 } |
250 | 264 |
| 265 /* True if LWP is stopped in its stepping range. */ |
| 266 |
| 267 static int |
| 268 lwp_in_step_range (struct lwp_info *lwp) |
| 269 { |
| 270 CORE_ADDR pc = lwp->stop_pc; |
| 271 |
| 272 return (pc >= lwp->step_range_start && pc < lwp->step_range_end); |
| 273 } |
| 274 |
251 struct pending_signals | 275 struct pending_signals |
252 { | 276 { |
253 int signal; | 277 int signal; |
254 siginfo_t info; | 278 siginfo_t info; |
255 struct pending_signals *prev; | 279 struct pending_signals *prev; |
256 }; | 280 }; |
257 | 281 |
258 #ifdef HAVE_LINUX_REGSETS | |
259 static char *disabled_regsets; | |
260 static int num_regsets; | |
261 #endif | |
262 | |
263 /* The read/write ends of the pipe registered as waitable file in the | 282 /* The read/write ends of the pipe registered as waitable file in the |
264 event loop. */ | 283 event loop. */ |
265 static int linux_event_pipe[2] = { -1, -1 }; | 284 static int linux_event_pipe[2] = { -1, -1 }; |
266 | 285 |
267 /* True if we're currently in async mode. */ | 286 /* True if we're currently in async mode. */ |
268 #define target_is_async_p() (linux_event_pipe[0] != -1) | 287 #define target_is_async_p() (linux_event_pipe[0] != -1) |
269 | 288 |
270 static void send_sigstop (struct lwp_info *lwp); | 289 static void send_sigstop (struct lwp_info *lwp); |
271 static void wait_for_sigstop (struct inferior_list_entry *entry); | 290 static void wait_for_sigstop (struct inferior_list_entry *entry); |
272 | 291 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 330 |
312 return elf_64_header_p (&header, machine); | 331 return elf_64_header_p (&header, machine); |
313 } | 332 } |
314 | 333 |
315 /* Accepts an integer PID; Returns true if the executable PID is | 334 /* Accepts an integer PID; Returns true if the executable PID is |
316 running is a 64-bit ELF file.. */ | 335 running is a 64-bit ELF file.. */ |
317 | 336 |
318 int | 337 int |
319 linux_pid_exe_is_elf_64_file (int pid, unsigned int *machine) | 338 linux_pid_exe_is_elf_64_file (int pid, unsigned int *machine) |
320 { | 339 { |
321 char file[MAXPATHLEN]; | 340 char file[PATH_MAX]; |
322 | 341 |
323 sprintf (file, "/proc/%d/exe", pid); | 342 sprintf (file, "/proc/%d/exe", pid); |
324 return elf_64_file_p (file, machine); | 343 return elf_64_file_p (file, machine); |
325 } | 344 } |
326 | 345 |
327 static void | 346 static void |
328 delete_lwp (struct lwp_info *lwp) | 347 delete_lwp (struct lwp_info *lwp) |
329 { | 348 { |
330 remove_thread (get_lwp_thread (lwp)); | 349 remove_thread (get_lwp_thread (lwp)); |
331 remove_inferior (&all_lwps, &lwp->head); | 350 remove_inferior (&all_lwps, &lwp->head); |
332 free (lwp->arch_private); | 351 free (lwp->arch_private); |
333 free (lwp); | 352 free (lwp); |
334 } | 353 } |
335 | 354 |
336 /* Add a process to the common process list, and set its private | 355 /* Add a process to the common process list, and set its private |
337 data. */ | 356 data. */ |
338 | 357 |
339 static struct process_info * | 358 static struct process_info * |
340 linux_add_process (int pid, int attached) | 359 linux_add_process (int pid, int attached) |
341 { | 360 { |
342 struct process_info *proc; | 361 struct process_info *proc; |
343 | 362 |
344 /* Is this the first process? If so, then set the arch. */ | |
345 if (all_processes.head == NULL) | |
346 new_inferior = 1; | |
347 | |
348 proc = add_process (pid, attached); | 363 proc = add_process (pid, attached); |
349 proc->private = xcalloc (1, sizeof (*proc->private)); | 364 proc->private = xcalloc (1, sizeof (*proc->private)); |
350 | 365 |
| 366 /* Set the arch when the first LWP stops. */ |
| 367 proc->private->new_inferior = 1; |
| 368 |
351 if (the_low_target.new_process != NULL) | 369 if (the_low_target.new_process != NULL) |
352 proc->private->arch_private = the_low_target.new_process (); | 370 proc->private->arch_private = the_low_target.new_process (); |
353 | 371 |
354 return proc; | 372 return proc; |
355 } | 373 } |
356 | 374 |
357 /* Wrapper function for waitpid which handles EINTR, and emulates | |
358 __WALL for systems where that is not available. */ | |
359 | |
360 static int | |
361 my_waitpid (int pid, int *status, int flags) | |
362 { | |
363 int ret, out_errno; | |
364 | |
365 if (debug_threads) | |
366 fprintf (stderr, "my_waitpid (%d, 0x%x)\n", pid, flags); | |
367 | |
368 if (flags & __WALL) | |
369 { | |
370 sigset_t block_mask, org_mask, wake_mask; | |
371 int wnohang; | |
372 | |
373 wnohang = (flags & WNOHANG) != 0; | |
374 flags &= ~(__WALL | __WCLONE); | |
375 flags |= WNOHANG; | |
376 | |
377 /* Block all signals while here. This avoids knowing about | |
378 LinuxThread's signals. */ | |
379 sigfillset (&block_mask); | |
380 sigprocmask (SIG_BLOCK, &block_mask, &org_mask); | |
381 | |
382 /* ... except during the sigsuspend below. */ | |
383 sigemptyset (&wake_mask); | |
384 | |
385 while (1) | |
386 { | |
387 /* Since all signals are blocked, there's no need to check | |
388 for EINTR here. */ | |
389 ret = waitpid (pid, status, flags); | |
390 out_errno = errno; | |
391 | |
392 if (ret == -1 && out_errno != ECHILD) | |
393 break; | |
394 else if (ret > 0) | |
395 break; | |
396 | |
397 if (flags & __WCLONE) | |
398 { | |
399 /* We've tried both flavors now. If WNOHANG is set, | |
400 there's nothing else to do, just bail out. */ | |
401 if (wnohang) | |
402 break; | |
403 | |
404 if (debug_threads) | |
405 fprintf (stderr, "blocking\n"); | |
406 | |
407 /* Block waiting for signals. */ | |
408 sigsuspend (&wake_mask); | |
409 } | |
410 | |
411 flags ^= __WCLONE; | |
412 } | |
413 | |
414 sigprocmask (SIG_SETMASK, &org_mask, NULL); | |
415 } | |
416 else | |
417 { | |
418 do | |
419 ret = waitpid (pid, status, flags); | |
420 while (ret == -1 && errno == EINTR); | |
421 out_errno = errno; | |
422 } | |
423 | |
424 if (debug_threads) | |
425 fprintf (stderr, "my_waitpid (%d, 0x%x): status(%x), %d\n", | |
426 pid, flags, status ? *status : -1, ret); | |
427 | |
428 errno = out_errno; | |
429 return ret; | |
430 } | |
431 | |
432 /* Handle a GNU/Linux extended wait response. If we see a clone | 375 /* Handle a GNU/Linux extended wait response. If we see a clone |
433 event, we need to add the new LWP to our list (and not report the | 376 event, we need to add the new LWP to our list (and not report the |
434 trap to higher layers). */ | 377 trap to higher layers). */ |
435 | 378 |
436 static void | 379 static void |
437 handle_extended_wait (struct lwp_info *event_child, int wstat) | 380 handle_extended_wait (struct lwp_info *event_child, int wstat) |
438 { | 381 { |
439 int event = wstat >> 16; | 382 int event = wstat >> 16; |
440 struct lwp_info *new_lwp; | 383 struct lwp_info *new_lwp; |
441 | 384 |
442 if (event == PTRACE_EVENT_CLONE) | 385 if (event == PTRACE_EVENT_CLONE) |
443 { | 386 { |
444 ptid_t ptid; | 387 ptid_t ptid; |
445 unsigned long new_pid; | 388 unsigned long new_pid; |
446 int ret, status; | 389 int ret, status; |
447 | 390 |
448 ptrace (PTRACE_GETEVENTMSG, lwpid_of (event_child), 0, &new_pid); | 391 ptrace (PTRACE_GETEVENTMSG, lwpid_of (event_child), (PTRACE_TYPE_ARG3) 0, |
| 392 » &new_pid); |
449 | 393 |
450 /* If we haven't already seen the new PID stop, wait for it now. */ | 394 /* If we haven't already seen the new PID stop, wait for it now. */ |
451 if (!pull_pid_from_list (&stopped_pids, new_pid, &status)) | 395 if (!pull_pid_from_list (&stopped_pids, new_pid, &status)) |
452 { | 396 { |
453 /* The new child has a pending SIGSTOP. We can't affect it until it | 397 /* The new child has a pending SIGSTOP. We can't affect it until it |
454 hits the SIGSTOP, but we're already attached. */ | 398 hits the SIGSTOP, but we're already attached. */ |
455 | 399 |
456 ret = my_waitpid (new_pid, &status, __WALL); | 400 ret = my_waitpid (new_pid, &status, __WALL); |
457 | 401 |
458 if (ret == -1) | 402 if (ret == -1) |
459 perror_with_name ("waiting for new child"); | 403 perror_with_name ("waiting for new child"); |
460 else if (ret != new_pid) | 404 else if (ret != new_pid) |
461 warning ("wait returned unexpected PID %d", ret); | 405 warning ("wait returned unexpected PID %d", ret); |
462 else if (!WIFSTOPPED (status)) | 406 else if (!WIFSTOPPED (status)) |
463 warning ("wait returned unexpected status 0x%x", status); | 407 warning ("wait returned unexpected status 0x%x", status); |
464 } | 408 } |
465 | 409 |
466 linux_enable_event_reporting (new_pid); | |
467 | |
468 ptid = ptid_build (pid_of (event_child), new_pid, 0); | 410 ptid = ptid_build (pid_of (event_child), new_pid, 0); |
469 new_lwp = (struct lwp_info *) add_lwp (ptid); | 411 new_lwp = (struct lwp_info *) add_lwp (ptid); |
470 add_thread (ptid, new_lwp); | 412 add_thread (ptid, new_lwp); |
471 | 413 |
472 /* Either we're going to immediately resume the new thread | 414 /* Either we're going to immediately resume the new thread |
473 or leave it stopped. linux_resume_one_lwp is a nop if it | 415 or leave it stopped. linux_resume_one_lwp is a nop if it |
474 thinks the thread is currently running, so set this first | 416 thinks the thread is currently running, so set this first |
475 before calling linux_resume_one_lwp. */ | 417 before calling linux_resume_one_lwp. */ |
476 new_lwp->stopped = 1; | 418 new_lwp->stopped = 1; |
477 | 419 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 #if defined(__UCLIBC__) && defined(HAS_NOMMU) | 576 #if defined(__UCLIBC__) && defined(HAS_NOMMU) |
635 pid = vfork (); | 577 pid = vfork (); |
636 #else | 578 #else |
637 pid = fork (); | 579 pid = fork (); |
638 #endif | 580 #endif |
639 if (pid < 0) | 581 if (pid < 0) |
640 perror_with_name ("fork"); | 582 perror_with_name ("fork"); |
641 | 583 |
642 if (pid == 0) | 584 if (pid == 0) |
643 { | 585 { |
644 ptrace (PTRACE_TRACEME, 0, 0, 0); | 586 close_most_fds (); |
| 587 ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0); |
645 | 588 |
646 #ifndef __ANDROID__ /* Bionic doesn't use SIGRTMIN the way glibc does. */ | 589 #ifndef __ANDROID__ /* Bionic doesn't use SIGRTMIN the way glibc does. */ |
647 signal (__SIGRTMIN + 1, SIG_DFL); | 590 signal (__SIGRTMIN + 1, SIG_DFL); |
648 #endif | 591 #endif |
649 | 592 |
650 setpgid (0, 0); | 593 setpgid (0, 0); |
651 | 594 |
652 /* If gdbserver is connected to gdb via stdio, redirect the inferior's | 595 /* If gdbserver is connected to gdb via stdio, redirect the inferior's |
653 stdout to stderr so that inferior i/o doesn't corrupt the connection. | 596 stdout to stderr so that inferior i/o doesn't corrupt the connection. |
654 Also, redirect stdin to /dev/null. */ | 597 Also, redirect stdin to /dev/null. */ |
655 if (remote_connection_is_stdio ()) | 598 if (remote_connection_is_stdio ()) |
656 { | 599 { |
657 close (0); | 600 close (0); |
658 open ("/dev/null", O_RDONLY); | 601 open ("/dev/null", O_RDONLY); |
659 dup2 (2, 1); | 602 dup2 (2, 1); |
660 if (write (2, "stdin/stdout redirected\n", | 603 if (write (2, "stdin/stdout redirected\n", |
661 sizeof ("stdin/stdout redirected\n") - 1) < 0) | 604 sizeof ("stdin/stdout redirected\n") - 1) < 0) |
662 » /* Errors ignored. */; | 605 » { |
| 606 » /* Errors ignored. */; |
| 607 » } |
663 } | 608 } |
664 | 609 |
665 execv (program, allargs); | 610 execv (program, allargs); |
666 if (errno == ENOENT) | 611 if (errno == ENOENT) |
667 execvp (program, allargs); | 612 execvp (program, allargs); |
668 | 613 |
669 fprintf (stderr, "Cannot exec %s: %s.\n", program, | 614 fprintf (stderr, "Cannot exec %s: %s.\n", program, |
670 strerror (errno)); | 615 strerror (errno)); |
671 fflush (stderr); | 616 fflush (stderr); |
672 _exit (0177); | 617 _exit (0177); |
(...skipping 21 matching lines...) Expand all Loading... |
694 } | 639 } |
695 | 640 |
696 /* Attach to an inferior process. */ | 641 /* Attach to an inferior process. */ |
697 | 642 |
698 static void | 643 static void |
699 linux_attach_lwp_1 (unsigned long lwpid, int initial) | 644 linux_attach_lwp_1 (unsigned long lwpid, int initial) |
700 { | 645 { |
701 ptid_t ptid; | 646 ptid_t ptid; |
702 struct lwp_info *new_lwp; | 647 struct lwp_info *new_lwp; |
703 | 648 |
704 if (ptrace (PTRACE_ATTACH, lwpid, 0, 0) != 0) | 649 if (ptrace (PTRACE_ATTACH, lwpid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0) |
| 650 != 0) |
705 { | 651 { |
706 struct buffer buffer; | 652 struct buffer buffer; |
707 | 653 |
708 if (!initial) | 654 if (!initial) |
709 { | 655 { |
710 /* If we fail to attach to an LWP, just warn. */ | 656 /* If we fail to attach to an LWP, just warn. */ |
711 fprintf (stderr, "Cannot attach to lwp %ld: %s (%d)\n", lwpid, | 657 fprintf (stderr, "Cannot attach to lwp %ld: %s (%d)\n", lwpid, |
712 strerror (errno), errno); | 658 strerror (errno), errno); |
713 fflush (stderr); | 659 fflush (stderr); |
714 return; | 660 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 to running without a PTRACE_CONT; so we know this signal will | 706 to running without a PTRACE_CONT; so we know this signal will |
761 go into the queue. The SIGSTOP generated by PTRACE_ATTACH is | 707 go into the queue. The SIGSTOP generated by PTRACE_ATTACH is |
762 probably already in the queue (unless this kernel is old | 708 probably already in the queue (unless this kernel is old |
763 enough to use TASK_STOPPED for ptrace stops); but since | 709 enough to use TASK_STOPPED for ptrace stops); but since |
764 SIGSTOP is not an RT signal, it can only be queued once. */ | 710 SIGSTOP is not an RT signal, it can only be queued once. */ |
765 kill_lwp (lwpid, SIGSTOP); | 711 kill_lwp (lwpid, SIGSTOP); |
766 | 712 |
767 /* Finally, resume the stopped process. This will deliver the | 713 /* Finally, resume the stopped process. This will deliver the |
768 SIGSTOP (or a higher priority signal, just like normal | 714 SIGSTOP (or a higher priority signal, just like normal |
769 PTRACE_ATTACH), which we'll catch later on. */ | 715 PTRACE_ATTACH), which we'll catch later on. */ |
770 ptrace (PTRACE_CONT, lwpid, 0, 0); | 716 ptrace (PTRACE_CONT, lwpid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0); |
771 } | 717 } |
772 | 718 |
773 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH | 719 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH |
774 brings it to a halt. | 720 brings it to a halt. |
775 | 721 |
776 There are several cases to consider here: | 722 There are several cases to consider here: |
777 | 723 |
778 1) gdbserver has already attached to the process and is being notified | 724 1) gdbserver has already attached to the process and is being notified |
779 of a new thread that is being created. | 725 of a new thread that is being created. |
780 In this case we should ignore that SIGSTOP and resume the | 726 In this case we should ignore that SIGSTOP and resume the |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 | 897 |
952 errno = 0; | 898 errno = 0; |
953 kill (pid, SIGKILL); | 899 kill (pid, SIGKILL); |
954 if (debug_threads) | 900 if (debug_threads) |
955 fprintf (stderr, | 901 fprintf (stderr, |
956 "LKL: kill (SIGKILL) %s, 0, 0 (%s)\n", | 902 "LKL: kill (SIGKILL) %s, 0, 0 (%s)\n", |
957 target_pid_to_str (ptid_of (lwp)), | 903 target_pid_to_str (ptid_of (lwp)), |
958 errno ? strerror (errno) : "OK"); | 904 errno ? strerror (errno) : "OK"); |
959 | 905 |
960 errno = 0; | 906 errno = 0; |
961 ptrace (PTRACE_KILL, pid, 0, 0); | 907 ptrace (PTRACE_KILL, pid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0); |
962 if (debug_threads) | 908 if (debug_threads) |
963 fprintf (stderr, | 909 fprintf (stderr, |
964 "LKL: PTRACE_KILL %s, 0, 0 (%s)\n", | 910 "LKL: PTRACE_KILL %s, 0, 0 (%s)\n", |
965 target_pid_to_str (ptid_of (lwp)), | 911 target_pid_to_str (ptid_of (lwp)), |
966 errno ? strerror (errno) : "OK"); | 912 errno ? strerror (errno) : "OK"); |
967 } | 913 } |
968 | 914 |
969 /* Callback for `find_inferior'. Kills an lwp of a given process, | 915 /* Callback for `find_inferior'. Kills an lwp of a given process, |
970 except the leader. */ | 916 except the leader. */ |
971 | 917 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 if (debug_threads) | 1102 if (debug_threads) |
1157 fprintf (stderr, | 1103 fprintf (stderr, |
1158 "Sending SIGCONT to %s\n", | 1104 "Sending SIGCONT to %s\n", |
1159 target_pid_to_str (ptid_of (lwp))); | 1105 target_pid_to_str (ptid_of (lwp))); |
1160 | 1106 |
1161 kill_lwp (lwpid_of (lwp), SIGCONT); | 1107 kill_lwp (lwpid_of (lwp), SIGCONT); |
1162 lwp->stop_expected = 0; | 1108 lwp->stop_expected = 0; |
1163 } | 1109 } |
1164 | 1110 |
1165 /* Flush any pending changes to the process's registers. */ | 1111 /* Flush any pending changes to the process's registers. */ |
1166 regcache_invalidate_one ((struct inferior_list_entry *) | 1112 regcache_invalidate_thread (get_lwp_thread (lwp)); |
1167 » » » get_lwp_thread (lwp)); | |
1168 | 1113 |
1169 /* Pass on any pending signal for this thread. */ | 1114 /* Pass on any pending signal for this thread. */ |
1170 sig = get_detach_signal (thread); | 1115 sig = get_detach_signal (thread); |
1171 | 1116 |
1172 /* Finally, let it resume. */ | 1117 /* Finally, let it resume. */ |
1173 if (the_low_target.prepare_to_resume != NULL) | 1118 if (the_low_target.prepare_to_resume != NULL) |
1174 the_low_target.prepare_to_resume (lwp); | 1119 the_low_target.prepare_to_resume (lwp); |
1175 if (ptrace (PTRACE_DETACH, lwpid_of (lwp), 0, | 1120 if (ptrace (PTRACE_DETACH, lwpid_of (lwp), (PTRACE_TYPE_ARG3) 0, |
1176 » (PTRACE_ARG4_TYPE) (long) sig) < 0) | 1121 » (PTRACE_TYPE_ARG4) (long) sig) < 0) |
1177 error (_("Can't detach %s: %s"), | 1122 error (_("Can't detach %s: %s"), |
1178 target_pid_to_str (ptid_of (lwp)), | 1123 target_pid_to_str (ptid_of (lwp)), |
1179 strerror (errno)); | 1124 strerror (errno)); |
1180 | 1125 |
1181 delete_lwp (lwp); | 1126 delete_lwp (lwp); |
1182 return 0; | 1127 return 0; |
1183 } | 1128 } |
1184 | 1129 |
1185 static int | 1130 static int |
1186 linux_detach (int pid) | 1131 linux_detach (int pid) |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 add_to_pid_list (&stopped_pids, ret, *wstatp); | 1310 add_to_pid_list (&stopped_pids, ret, *wstatp); |
1366 goto retry; | 1311 goto retry; |
1367 } | 1312 } |
1368 else if (child == NULL) | 1313 else if (child == NULL) |
1369 goto retry; | 1314 goto retry; |
1370 | 1315 |
1371 child->stopped = 1; | 1316 child->stopped = 1; |
1372 | 1317 |
1373 child->last_status = *wstatp; | 1318 child->last_status = *wstatp; |
1374 | 1319 |
1375 /* Architecture-specific setup after inferior is running. | 1320 if (WIFSTOPPED (*wstatp)) |
1376 This needs to happen after we have attached to the inferior | |
1377 and it is stopped for the first time, but before we access | |
1378 any inferior registers. */ | |
1379 if (new_inferior) | |
1380 { | 1321 { |
1381 the_low_target.arch_setup (); | 1322 struct process_info *proc; |
1382 #ifdef HAVE_LINUX_REGSETS | 1323 |
1383 memset (disabled_regsets, 0, num_regsets); | 1324 /* Architecture-specific setup after inferior is running. This |
1384 #endif | 1325 » needs to happen after we have attached to the inferior and it |
1385 new_inferior = 0; | 1326 » is stopped for the first time, but before we access any |
| 1327 » inferior registers. */ |
| 1328 proc = find_process_pid (pid_of (child)); |
| 1329 if (proc->private->new_inferior) |
| 1330 » { |
| 1331 » struct thread_info *saved_inferior; |
| 1332 |
| 1333 » saved_inferior = current_inferior; |
| 1334 » current_inferior = get_lwp_thread (child); |
| 1335 |
| 1336 » the_low_target.arch_setup (); |
| 1337 |
| 1338 » current_inferior = saved_inferior; |
| 1339 |
| 1340 » proc->private->new_inferior = 0; |
| 1341 » } |
1386 } | 1342 } |
1387 | 1343 |
1388 /* Fetch the possibly triggered data watchpoint info and store it in | 1344 /* Fetch the possibly triggered data watchpoint info and store it in |
1389 CHILD. | 1345 CHILD. |
1390 | 1346 |
1391 On some archs, like x86, that use debug registers to set | 1347 On some archs, like x86, that use debug registers to set |
1392 watchpoints, it's possible that the way to know which watched | 1348 watchpoints, it's possible that the way to know which watched |
1393 address trapped, is to check the register that is used to select | 1349 address trapped, is to check the register that is used to select |
1394 which address to watch. Problem is, between setting the | 1350 which address to watch. Problem is, between setting the |
1395 watchpoint and reading back which data address trapped, the user | 1351 watchpoint and reading back which data address trapped, the user |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 siginfo_t info; | 1552 siginfo_t info; |
1597 struct regcache *regcache; | 1553 struct regcache *regcache; |
1598 | 1554 |
1599 /* The si_addr on a few signals references the address | 1555 /* The si_addr on a few signals references the address |
1600 of the faulting instruction. Adjust that as | 1556 of the faulting instruction. Adjust that as |
1601 well. */ | 1557 well. */ |
1602 if ((WSTOPSIG (*wstat) == SIGILL | 1558 if ((WSTOPSIG (*wstat) == SIGILL |
1603 || WSTOPSIG (*wstat) == SIGFPE | 1559 || WSTOPSIG (*wstat) == SIGFPE |
1604 || WSTOPSIG (*wstat) == SIGBUS | 1560 || WSTOPSIG (*wstat) == SIGBUS |
1605 || WSTOPSIG (*wstat) == SIGSEGV) | 1561 || WSTOPSIG (*wstat) == SIGSEGV) |
1606 » » && ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), 0, &info) == 0 | 1562 » » && ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), |
| 1563 » » » (PTRACE_TYPE_ARG3) 0, &info) == 0 |
1607 /* Final check just to make sure we don't clobber | 1564 /* Final check just to make sure we don't clobber |
1608 the siginfo of non-kernel-sent signals. */ | 1565 the siginfo of non-kernel-sent signals. */ |
1609 && (uintptr_t) info.si_addr == lwp->stop_pc) | 1566 && (uintptr_t) info.si_addr == lwp->stop_pc) |
1610 { | 1567 { |
1611 info.si_addr = (void *) (uintptr_t) status.tpoint_addr; | 1568 info.si_addr = (void *) (uintptr_t) status.tpoint_addr; |
1612 » » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), 0, &info); | 1569 » » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), |
| 1570 » » » (PTRACE_TYPE_ARG3) 0, &info); |
1613 } | 1571 } |
1614 | 1572 |
1615 regcache = get_thread_regcache (get_lwp_thread (lwp), 1); | 1573 regcache = get_thread_regcache (get_lwp_thread (lwp), 1); |
1616 (*the_low_target.set_pc) (regcache, status.tpoint_addr); | 1574 (*the_low_target.set_pc) (regcache, status.tpoint_addr); |
1617 lwp->stop_pc = status.tpoint_addr; | 1575 lwp->stop_pc = status.tpoint_addr; |
1618 | 1576 |
1619 /* Cancel any fast tracepoint lock this thread was | 1577 /* Cancel any fast tracepoint lock this thread was |
1620 holding. */ | 1578 holding. */ |
1621 force_unlock_trace_buffer (); | 1579 force_unlock_trace_buffer (); |
1622 } | 1580 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 lwpid_of (lwp)); | 1655 lwpid_of (lwp)); |
1698 return; | 1656 return; |
1699 } | 1657 } |
1700 } | 1658 } |
1701 } | 1659 } |
1702 | 1660 |
1703 p_sig = xmalloc (sizeof (*p_sig)); | 1661 p_sig = xmalloc (sizeof (*p_sig)); |
1704 p_sig->prev = lwp->pending_signals_to_report; | 1662 p_sig->prev = lwp->pending_signals_to_report; |
1705 p_sig->signal = WSTOPSIG (*wstat); | 1663 p_sig->signal = WSTOPSIG (*wstat); |
1706 memset (&p_sig->info, 0, sizeof (siginfo_t)); | 1664 memset (&p_sig->info, 0, sizeof (siginfo_t)); |
1707 ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), 0, &p_sig->info); | 1665 ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), (PTRACE_TYPE_ARG3) 0, |
| 1666 » &p_sig->info); |
1708 | 1667 |
1709 lwp->pending_signals_to_report = p_sig; | 1668 lwp->pending_signals_to_report = p_sig; |
1710 } | 1669 } |
1711 | 1670 |
1712 /* Dequeue one signal from the "signals to report later when out of | 1671 /* Dequeue one signal from the "signals to report later when out of |
1713 the jump pad" list. */ | 1672 the jump pad" list. */ |
1714 | 1673 |
1715 static int | 1674 static int |
1716 dequeue_one_deferred_signal (struct lwp_info *lwp, int *wstat) | 1675 dequeue_one_deferred_signal (struct lwp_info *lwp, int *wstat) |
1717 { | 1676 { |
1718 if (lwp->pending_signals_to_report != NULL) | 1677 if (lwp->pending_signals_to_report != NULL) |
1719 { | 1678 { |
1720 struct pending_signals **p_sig; | 1679 struct pending_signals **p_sig; |
1721 | 1680 |
1722 p_sig = &lwp->pending_signals_to_report; | 1681 p_sig = &lwp->pending_signals_to_report; |
1723 while ((*p_sig)->prev != NULL) | 1682 while ((*p_sig)->prev != NULL) |
1724 p_sig = &(*p_sig)->prev; | 1683 p_sig = &(*p_sig)->prev; |
1725 | 1684 |
1726 *wstat = W_STOPCODE ((*p_sig)->signal); | 1685 *wstat = W_STOPCODE ((*p_sig)->signal); |
1727 if ((*p_sig)->info.si_signo != 0) | 1686 if ((*p_sig)->info.si_signo != 0) |
1728 » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), 0, &(*p_sig)->info); | 1687 » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), (PTRACE_TYPE_ARG3) 0, |
| 1688 » » &(*p_sig)->info); |
1729 free (*p_sig); | 1689 free (*p_sig); |
1730 *p_sig = NULL; | 1690 *p_sig = NULL; |
1731 | 1691 |
1732 if (debug_threads) | 1692 if (debug_threads) |
1733 fprintf (stderr, "Reporting deferred signal %d for LWP %ld.\n", | 1693 fprintf (stderr, "Reporting deferred signal %d for LWP %ld.\n", |
1734 WSTOPSIG (*wstat), lwpid_of (lwp)); | 1694 WSTOPSIG (*wstat), lwpid_of (lwp)); |
1735 | 1695 |
1736 if (debug_threads) | 1696 if (debug_threads) |
1737 { | 1697 { |
1738 struct pending_signals *sig; | 1698 struct pending_signals *sig; |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 { | 2256 { |
2297 int w; | 2257 int w; |
2298 struct lwp_info *event_child; | 2258 struct lwp_info *event_child; |
2299 int options; | 2259 int options; |
2300 int pid; | 2260 int pid; |
2301 int step_over_finished; | 2261 int step_over_finished; |
2302 int bp_explains_trap; | 2262 int bp_explains_trap; |
2303 int maybe_internal_trap; | 2263 int maybe_internal_trap; |
2304 int report_to_gdb; | 2264 int report_to_gdb; |
2305 int trace_event; | 2265 int trace_event; |
| 2266 int in_step_range; |
2306 | 2267 |
2307 /* Translate generic target options into linux options. */ | 2268 /* Translate generic target options into linux options. */ |
2308 options = __WALL; | 2269 options = __WALL; |
2309 if (target_options & TARGET_WNOHANG) | 2270 if (target_options & TARGET_WNOHANG) |
2310 options |= WNOHANG; | 2271 options |= WNOHANG; |
2311 | 2272 |
2312 retry: | 2273 retry: |
2313 bp_explains_trap = 0; | 2274 bp_explains_trap = 0; |
2314 trace_event = 0; | 2275 trace_event = 0; |
| 2276 in_step_range = 0; |
2315 ourstatus->kind = TARGET_WAITKIND_IGNORE; | 2277 ourstatus->kind = TARGET_WAITKIND_IGNORE; |
2316 | 2278 |
2317 /* If we were only supposed to resume one thread, only wait for | 2279 /* If we were only supposed to resume one thread, only wait for |
2318 that thread - if it's still alive. If it died, however - which | 2280 that thread - if it's still alive. If it died, however - which |
2319 can happen if we're coming from the thread death case below - | 2281 can happen if we're coming from the thread death case below - |
2320 then we need to make sure we restart the other threads. We could | 2282 then we need to make sure we restart the other threads. We could |
2321 pick a thread at random or restart all; restarting all is less | 2283 pick a thread at random or restart all; restarting all is less |
2322 arbitrary. */ | 2284 arbitrary. */ |
2323 if (!non_stop | 2285 if (!non_stop |
2324 && !ptid_equal (cont_thread, null_ptid) | 2286 && !ptid_equal (cont_thread, null_ptid) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2588 (pass_signals[gdb_signal_from_host (WSTOPSIG (w))] | 2550 (pass_signals[gdb_signal_from_host (WSTOPSIG (w))] |
2589 && !(WSTOPSIG (w) == SIGSTOP | 2551 && !(WSTOPSIG (w) == SIGSTOP |
2590 && current_inferior->last_resume_kind == resume_stop)))) | 2552 && current_inferior->last_resume_kind == resume_stop)))) |
2591 { | 2553 { |
2592 siginfo_t info, *info_p; | 2554 siginfo_t info, *info_p; |
2593 | 2555 |
2594 if (debug_threads) | 2556 if (debug_threads) |
2595 fprintf (stderr, "Ignored signal %d for LWP %ld.\n", | 2557 fprintf (stderr, "Ignored signal %d for LWP %ld.\n", |
2596 WSTOPSIG (w), lwpid_of (event_child)); | 2558 WSTOPSIG (w), lwpid_of (event_child)); |
2597 | 2559 |
2598 if (ptrace (PTRACE_GETSIGINFO, lwpid_of (event_child), 0, &info) == 0) | 2560 if (ptrace (PTRACE_GETSIGINFO, lwpid_of (event_child), |
| 2561 » » (PTRACE_TYPE_ARG3) 0, &info) == 0) |
2599 info_p = &info; | 2562 info_p = &info; |
2600 else | 2563 else |
2601 info_p = NULL; | 2564 info_p = NULL; |
2602 linux_resume_one_lwp (event_child, event_child->stepping, | 2565 linux_resume_one_lwp (event_child, event_child->stepping, |
2603 WSTOPSIG (w), info_p); | 2566 WSTOPSIG (w), info_p); |
2604 goto retry; | 2567 goto retry; |
2605 } | 2568 } |
2606 | 2569 |
2607 /* If GDB wanted this thread to single step, we always want to | 2570 /* Note that all addresses are always "out of the step range" when |
2608 report the SIGTRAP, and let GDB handle it. Watchpoints should | 2571 there's no range to begin with. */ |
2609 always be reported. So should signals we can't explain. A | 2572 in_step_range = lwp_in_step_range (event_child); |
2610 SIGTRAP we can't explain could be a GDB breakpoint --- we may or | 2573 |
2611 not support Z0 breakpoints. If we do, we're be able to handle | 2574 /* If GDB wanted this thread to single step, and the thread is out |
2612 GDB breakpoints on top of internal breakpoints, by handling the | 2575 of the step range, we always want to report the SIGTRAP, and let |
2613 internal breakpoint and still reporting the event to GDB. If we | 2576 GDB handle it. Watchpoints should always be reported. So should |
2614 don't, we're out of luck, GDB won't see the breakpoint hit. */ | 2577 signals we can't explain. A SIGTRAP we can't explain could be a |
| 2578 GDB breakpoint --- we may or not support Z0 breakpoints. If we |
| 2579 do, we're be able to handle GDB breakpoints on top of internal |
| 2580 breakpoints, by handling the internal breakpoint and still |
| 2581 reporting the event to GDB. If we don't, we're out of luck, GDB |
| 2582 won't see the breakpoint hit. */ |
2615 report_to_gdb = (!maybe_internal_trap | 2583 report_to_gdb = (!maybe_internal_trap |
2616 » » || current_inferior->last_resume_kind == resume_step | 2584 » » || (current_inferior->last_resume_kind == resume_step |
| 2585 » » && !in_step_range) |
2617 || event_child->stopped_by_watchpoint | 2586 || event_child->stopped_by_watchpoint |
2618 » » || (!step_over_finished | 2587 » » || (!step_over_finished && !in_step_range |
2619 && !bp_explains_trap && !trace_event) | 2588 && !bp_explains_trap && !trace_event) |
2620 || (gdb_breakpoint_here (event_child->stop_pc) | 2589 || (gdb_breakpoint_here (event_child->stop_pc) |
2621 && gdb_condition_true_at_breakpoint (event_child->stop_pc
) | 2590 && gdb_condition_true_at_breakpoint (event_child->stop_pc
) |
2622 && gdb_no_commands_at_breakpoint (event_child->stop_pc)))
; | 2591 && gdb_no_commands_at_breakpoint (event_child->stop_pc)))
; |
2623 | 2592 |
2624 run_breakpoint_commands (event_child->stop_pc); | 2593 run_breakpoint_commands (event_child->stop_pc); |
2625 | 2594 |
2626 /* We found no reason GDB would want us to stop. We either hit one | 2595 /* We found no reason GDB would want us to stop. We either hit one |
2627 of our own breakpoints, or finished an internal step GDB | 2596 of our own breakpoints, or finished an internal step GDB |
2628 shouldn't know about. */ | 2597 shouldn't know about. */ |
2629 if (!report_to_gdb) | 2598 if (!report_to_gdb) |
2630 { | 2599 { |
2631 if (debug_threads) | 2600 if (debug_threads) |
2632 { | 2601 { |
2633 if (bp_explains_trap) | 2602 if (bp_explains_trap) |
2634 fprintf (stderr, "Hit a gdbserver breakpoint.\n"); | 2603 fprintf (stderr, "Hit a gdbserver breakpoint.\n"); |
2635 if (step_over_finished) | 2604 if (step_over_finished) |
2636 fprintf (stderr, "Step-over finished.\n"); | 2605 fprintf (stderr, "Step-over finished.\n"); |
2637 if (trace_event) | 2606 if (trace_event) |
2638 fprintf (stderr, "Tracepoint event.\n"); | 2607 fprintf (stderr, "Tracepoint event.\n"); |
| 2608 if (lwp_in_step_range (event_child)) |
| 2609 fprintf (stderr, "Range stepping pc 0x%s [0x%s, 0x%s).\n", |
| 2610 paddress (event_child->stop_pc), |
| 2611 paddress (event_child->step_range_start), |
| 2612 paddress (event_child->step_range_end)); |
2639 } | 2613 } |
2640 | 2614 |
2641 /* We're not reporting this breakpoint to GDB, so apply the | 2615 /* We're not reporting this breakpoint to GDB, so apply the |
2642 decr_pc_after_break adjustment to the inferior's regcache | 2616 decr_pc_after_break adjustment to the inferior's regcache |
2643 ourselves. */ | 2617 ourselves. */ |
2644 | 2618 |
2645 if (the_low_target.set_pc != NULL) | 2619 if (the_low_target.set_pc != NULL) |
2646 { | 2620 { |
2647 struct regcache *regcache | 2621 struct regcache *regcache |
2648 = get_thread_regcache (get_lwp_thread (event_child), 1); | 2622 = get_thread_regcache (get_lwp_thread (event_child), 1); |
(...skipping 11 matching lines...) Expand all Loading... |
2660 if (step_over_finished) | 2634 if (step_over_finished) |
2661 unsuspend_all_lwps (event_child); | 2635 unsuspend_all_lwps (event_child); |
2662 | 2636 |
2663 proceed_all_lwps (); | 2637 proceed_all_lwps (); |
2664 goto retry; | 2638 goto retry; |
2665 } | 2639 } |
2666 | 2640 |
2667 if (debug_threads) | 2641 if (debug_threads) |
2668 { | 2642 { |
2669 if (current_inferior->last_resume_kind == resume_step) | 2643 if (current_inferior->last_resume_kind == resume_step) |
2670 » fprintf (stderr, "GDB wanted to single-step, reporting event.\n"); | 2644 » { |
| 2645 » if (event_child->step_range_start == event_child->step_range_end) |
| 2646 » fprintf (stderr, "GDB wanted to single-step, reporting event.\n"); |
| 2647 » else if (!lwp_in_step_range (event_child)) |
| 2648 » fprintf (stderr, "Out of step range, reporting event.\n"); |
| 2649 » } |
2671 if (event_child->stopped_by_watchpoint) | 2650 if (event_child->stopped_by_watchpoint) |
2672 fprintf (stderr, "Stopped by watchpoint.\n"); | 2651 fprintf (stderr, "Stopped by watchpoint.\n"); |
2673 if (gdb_breakpoint_here (event_child->stop_pc)) | 2652 if (gdb_breakpoint_here (event_child->stop_pc)) |
2674 fprintf (stderr, "Stopped by GDB breakpoint.\n"); | 2653 fprintf (stderr, "Stopped by GDB breakpoint.\n"); |
2675 if (debug_threads) | 2654 if (debug_threads) |
2676 fprintf (stderr, "Hit a non-gdbserver trap event.\n"); | 2655 fprintf (stderr, "Hit a non-gdbserver trap event.\n"); |
2677 } | 2656 } |
2678 | 2657 |
2679 /* Alright, we're going to report a stop. */ | 2658 /* Alright, we're going to report a stop. */ |
2680 | 2659 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 Making this stack would also shrink the window in which breakpoints are | 3162 Making this stack would also shrink the window in which breakpoints are |
3184 uninserted (see comment in linux_wait_for_lwp) but not enough for | 3163 uninserted (see comment in linux_wait_for_lwp) but not enough for |
3185 complete correctness, so it won't solve that problem. It may be | 3164 complete correctness, so it won't solve that problem. It may be |
3186 worthwhile just to solve this one, however. */ | 3165 worthwhile just to solve this one, however. */ |
3187 if (lwp->bp_reinsert != 0) | 3166 if (lwp->bp_reinsert != 0) |
3188 { | 3167 { |
3189 if (debug_threads) | 3168 if (debug_threads) |
3190 fprintf (stderr, " pending reinsert at 0x%s\n", | 3169 fprintf (stderr, " pending reinsert at 0x%s\n", |
3191 paddress (lwp->bp_reinsert)); | 3170 paddress (lwp->bp_reinsert)); |
3192 | 3171 |
3193 if (lwp->bp_reinsert != 0 && can_hardware_single_step ()) | 3172 if (can_hardware_single_step ()) |
3194 { | 3173 { |
3195 if (fast_tp_collecting == 0) | 3174 if (fast_tp_collecting == 0) |
3196 { | 3175 { |
3197 if (step == 0) | 3176 if (step == 0) |
3198 fprintf (stderr, "BAD - reinserting but not stepping.\n"); | 3177 fprintf (stderr, "BAD - reinserting but not stepping.\n"); |
3199 if (lwp->suspended) | 3178 if (lwp->suspended) |
3200 fprintf (stderr, "BAD - reinserting and suspended(%d).\n", | 3179 fprintf (stderr, "BAD - reinserting and suspended(%d).\n", |
3201 lwp->suspended); | 3180 lwp->suspended); |
3202 } | 3181 } |
3203 | 3182 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3268 && fast_tp_collecting == 0) | 3247 && fast_tp_collecting == 0) |
3269 { | 3248 { |
3270 struct pending_signals **p_sig; | 3249 struct pending_signals **p_sig; |
3271 | 3250 |
3272 p_sig = &lwp->pending_signals; | 3251 p_sig = &lwp->pending_signals; |
3273 while ((*p_sig)->prev != NULL) | 3252 while ((*p_sig)->prev != NULL) |
3274 p_sig = &(*p_sig)->prev; | 3253 p_sig = &(*p_sig)->prev; |
3275 | 3254 |
3276 signal = (*p_sig)->signal; | 3255 signal = (*p_sig)->signal; |
3277 if ((*p_sig)->info.si_signo != 0) | 3256 if ((*p_sig)->info.si_signo != 0) |
3278 » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), 0, &(*p_sig)->info); | 3257 » ptrace (PTRACE_SETSIGINFO, lwpid_of (lwp), (PTRACE_TYPE_ARG3) 0, |
| 3258 » » &(*p_sig)->info); |
3279 | 3259 |
3280 free (*p_sig); | 3260 free (*p_sig); |
3281 *p_sig = NULL; | 3261 *p_sig = NULL; |
3282 } | 3262 } |
3283 | 3263 |
3284 if (the_low_target.prepare_to_resume != NULL) | 3264 if (the_low_target.prepare_to_resume != NULL) |
3285 the_low_target.prepare_to_resume (lwp); | 3265 the_low_target.prepare_to_resume (lwp); |
3286 | 3266 |
3287 regcache_invalidate_one ((struct inferior_list_entry *) | 3267 regcache_invalidate_thread (get_lwp_thread (lwp)); |
3288 » » » get_lwp_thread (lwp)); | |
3289 errno = 0; | 3268 errno = 0; |
3290 lwp->stopped = 0; | 3269 lwp->stopped = 0; |
3291 lwp->stopped_by_watchpoint = 0; | 3270 lwp->stopped_by_watchpoint = 0; |
3292 lwp->stepping = step; | 3271 lwp->stepping = step; |
3293 ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (lwp), 0, | 3272 ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (lwp), |
| 3273 » (PTRACE_TYPE_ARG3) 0, |
3294 /* Coerce to a uintptr_t first to avoid potential gcc warning | 3274 /* Coerce to a uintptr_t first to avoid potential gcc warning |
3295 of coercing an 8 byte integer to a 4 byte pointer. */ | 3275 of coercing an 8 byte integer to a 4 byte pointer. */ |
3296 » (PTRACE_ARG4_TYPE) (uintptr_t) signal); | 3276 » (PTRACE_TYPE_ARG4) (uintptr_t) signal); |
3297 | 3277 |
3298 current_inferior = saved_inferior; | 3278 current_inferior = saved_inferior; |
3299 if (errno) | 3279 if (errno) |
3300 { | 3280 { |
3301 /* ESRCH from ptrace either means that the thread was already | 3281 /* ESRCH from ptrace either means that the thread was already |
3302 running (an error) or that it is gone (a race condition). If | 3282 running (an error) or that it is gone (a race condition). If |
3303 it's gone, we will get a notification the next time we wait, | 3283 it's gone, we will get a notification the next time we wait, |
3304 so we can ignore the error. We could differentiate these | 3284 so we can ignore the error. We could differentiate these |
3305 two, but it's tricky without waiting; the thread still exists | 3285 two, but it's tricky without waiting; the thread still exists |
3306 as a zombie, so sending it signal 0 would succeed. So just | 3286 as a zombie, so sending it signal 0 would succeed. So just |
3307 ignore ESRCH. */ | 3287 ignore ESRCH. */ |
3308 if (errno == ESRCH) | 3288 if (errno == ESRCH) |
3309 return; | 3289 return; |
3310 | 3290 |
3311 perror_with_name ("ptrace"); | 3291 perror_with_name ("ptrace"); |
3312 } | 3292 } |
3313 } | 3293 } |
3314 | 3294 |
3315 struct thread_resume_array | 3295 struct thread_resume_array |
3316 { | 3296 { |
3317 struct thread_resume *resume; | 3297 struct thread_resume *resume; |
3318 size_t n; | 3298 size_t n; |
3319 }; | 3299 }; |
3320 | 3300 |
3321 /* This function is called once per thread. We look up the thread | 3301 /* This function is called once per thread via find_inferior. |
3322 in RESUME_PTR, and mark the thread with a pointer to the appropriate | 3302 ARG is a pointer to a thread_resume_array struct. |
3323 resume request. | 3303 We look up the thread specified by ENTRY in ARG, and mark the thread |
| 3304 with a pointer to the appropriate resume request. |
3324 | 3305 |
3325 This algorithm is O(threads * resume elements), but resume elements | 3306 This algorithm is O(threads * resume elements), but resume elements |
3326 is small (and will remain small at least until GDB supports thread | 3307 is small (and will remain small at least until GDB supports thread |
3327 suspension). */ | 3308 suspension). */ |
| 3309 |
3328 static int | 3310 static int |
3329 linux_set_resume_request (struct inferior_list_entry *entry, void *arg) | 3311 linux_set_resume_request (struct inferior_list_entry *entry, void *arg) |
3330 { | 3312 { |
3331 struct lwp_info *lwp; | 3313 struct lwp_info *lwp; |
3332 struct thread_info *thread; | 3314 struct thread_info *thread; |
3333 int ndx; | 3315 int ndx; |
3334 struct thread_resume_array *r; | 3316 struct thread_resume_array *r; |
3335 | 3317 |
3336 thread = (struct thread_info *) entry; | 3318 thread = (struct thread_info *) entry; |
3337 lwp = get_thread_lwp (thread); | 3319 lwp = get_thread_lwp (thread); |
(...skipping 19 matching lines...) Expand all Loading... |
3357 ? "stopped" | 3339 ? "stopped" |
3358 : "stopping", | 3340 : "stopping", |
3359 lwpid_of (lwp)); | 3341 lwpid_of (lwp)); |
3360 | 3342 |
3361 continue; | 3343 continue; |
3362 } | 3344 } |
3363 | 3345 |
3364 lwp->resume = &r->resume[ndx]; | 3346 lwp->resume = &r->resume[ndx]; |
3365 thread->last_resume_kind = lwp->resume->kind; | 3347 thread->last_resume_kind = lwp->resume->kind; |
3366 | 3348 |
| 3349 lwp->step_range_start = lwp->resume->step_range_start; |
| 3350 lwp->step_range_end = lwp->resume->step_range_end; |
| 3351 |
3367 /* If we had a deferred signal to report, dequeue one now. | 3352 /* If we had a deferred signal to report, dequeue one now. |
3368 This can happen if LWP gets more than one signal while | 3353 This can happen if LWP gets more than one signal while |
3369 trying to get out of a jump pad. */ | 3354 trying to get out of a jump pad. */ |
3370 if (lwp->stopped | 3355 if (lwp->stopped |
3371 && !lwp->status_pending_p | 3356 && !lwp->status_pending_p |
3372 && dequeue_one_deferred_signal (lwp, &lwp->status_pending)) | 3357 && dequeue_one_deferred_signal (lwp, &lwp->status_pending)) |
3373 { | 3358 { |
3374 lwp->status_pending_p = 1; | 3359 lwp->status_pending_p = 1; |
3375 | 3360 |
3376 if (debug_threads) | 3361 if (debug_threads) |
3377 fprintf (stderr, | 3362 fprintf (stderr, |
3378 "Dequeueing deferred signal %d for LWP %ld, " | 3363 "Dequeueing deferred signal %d for LWP %ld, " |
3379 "leaving status pending.\n", | 3364 "leaving status pending.\n", |
3380 WSTOPSIG (lwp->status_pending), lwpid_of (lwp)); | 3365 WSTOPSIG (lwp->status_pending), lwpid_of (lwp)); |
3381 } | 3366 } |
3382 | 3367 |
3383 return 0; | 3368 return 0; |
3384 } | 3369 } |
3385 } | 3370 } |
3386 | 3371 |
3387 /* No resume action for this thread. */ | 3372 /* No resume action for this thread. */ |
3388 lwp->resume = NULL; | 3373 lwp->resume = NULL; |
3389 | 3374 |
3390 return 0; | 3375 return 0; |
3391 } | 3376 } |
3392 | 3377 |
| 3378 /* find_inferior callback for linux_resume. |
| 3379 Set *FLAG_P if this lwp has an interesting status pending. */ |
3393 | 3380 |
3394 /* Set *FLAG_P if this lwp has an interesting status pending. */ | |
3395 static int | 3381 static int |
3396 resume_status_pending_p (struct inferior_list_entry *entry, void *flag_p) | 3382 resume_status_pending_p (struct inferior_list_entry *entry, void *flag_p) |
3397 { | 3383 { |
3398 struct lwp_info *lwp = (struct lwp_info *) entry; | 3384 struct lwp_info *lwp = (struct lwp_info *) entry; |
3399 | 3385 |
3400 /* LWPs which will not be resumed are not interesting, because | 3386 /* LWPs which will not be resumed are not interesting, because |
3401 we might not wait for them next time through linux_wait. */ | 3387 we might not wait for them next time through linux_wait. */ |
3402 if (lwp->resume == NULL) | 3388 if (lwp->resume == NULL) |
3403 return 0; | 3389 return 0; |
3404 | 3390 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3751 p_sig->prev = lwp->pending_signals; | 3737 p_sig->prev = lwp->pending_signals; |
3752 p_sig->signal = lwp->resume->sig; | 3738 p_sig->signal = lwp->resume->sig; |
3753 memset (&p_sig->info, 0, sizeof (siginfo_t)); | 3739 memset (&p_sig->info, 0, sizeof (siginfo_t)); |
3754 | 3740 |
3755 /* If this is the same signal we were previously stopped by, | 3741 /* If this is the same signal we were previously stopped by, |
3756 make sure to queue its siginfo. We can ignore the return | 3742 make sure to queue its siginfo. We can ignore the return |
3757 value of ptrace; if it fails, we'll skip | 3743 value of ptrace; if it fails, we'll skip |
3758 PTRACE_SETSIGINFO. */ | 3744 PTRACE_SETSIGINFO. */ |
3759 if (WIFSTOPPED (lwp->last_status) | 3745 if (WIFSTOPPED (lwp->last_status) |
3760 && WSTOPSIG (lwp->last_status) == lwp->resume->sig) | 3746 && WSTOPSIG (lwp->last_status) == lwp->resume->sig) |
3761 » ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), 0, &p_sig->info); | 3747 » ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), (PTRACE_TYPE_ARG3) 0, |
| 3748 » » &p_sig->info); |
3762 | 3749 |
3763 lwp->pending_signals = p_sig; | 3750 lwp->pending_signals = p_sig; |
3764 } | 3751 } |
3765 } | 3752 } |
3766 | 3753 |
3767 thread->last_status.kind = TARGET_WAITKIND_IGNORE; | 3754 thread->last_status.kind = TARGET_WAITKIND_IGNORE; |
3768 lwp->resume = NULL; | 3755 lwp->resume = NULL; |
3769 return 0; | 3756 return 0; |
3770 } | 3757 } |
3771 | 3758 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3981 find_inferior (&all_lwps, unsuspend_and_proceed_one_lwp, except); | 3968 find_inferior (&all_lwps, unsuspend_and_proceed_one_lwp, except); |
3982 else | 3969 else |
3983 find_inferior (&all_lwps, proceed_one_lwp, except); | 3970 find_inferior (&all_lwps, proceed_one_lwp, except); |
3984 } | 3971 } |
3985 | 3972 |
3986 | 3973 |
3987 #ifdef HAVE_LINUX_REGSETS | 3974 #ifdef HAVE_LINUX_REGSETS |
3988 | 3975 |
3989 #define use_linux_regsets 1 | 3976 #define use_linux_regsets 1 |
3990 | 3977 |
| 3978 /* Returns true if REGSET has been disabled. */ |
| 3979 |
3991 static int | 3980 static int |
3992 regsets_fetch_inferior_registers (struct regcache *regcache) | 3981 regset_disabled (struct regsets_info *info, struct regset_info *regset) |
| 3982 { |
| 3983 return (info->disabled_regsets != NULL |
| 3984 » && info->disabled_regsets[regset - info->regsets]); |
| 3985 } |
| 3986 |
| 3987 /* Disable REGSET. */ |
| 3988 |
| 3989 static void |
| 3990 disable_regset (struct regsets_info *info, struct regset_info *regset) |
| 3991 { |
| 3992 int dr_offset; |
| 3993 |
| 3994 dr_offset = regset - info->regsets; |
| 3995 if (info->disabled_regsets == NULL) |
| 3996 info->disabled_regsets = xcalloc (1, info->num_regsets); |
| 3997 info->disabled_regsets[dr_offset] = 1; |
| 3998 } |
| 3999 |
| 4000 static int |
| 4001 regsets_fetch_inferior_registers (struct regsets_info *regsets_info, |
| 4002 » » » » struct regcache *regcache) |
3993 { | 4003 { |
3994 struct regset_info *regset; | 4004 struct regset_info *regset; |
3995 int saw_general_regs = 0; | 4005 int saw_general_regs = 0; |
3996 int pid; | 4006 int pid; |
3997 struct iovec iov; | 4007 struct iovec iov; |
3998 | 4008 |
3999 regset = target_regsets; | 4009 regset = regsets_info->regsets; |
4000 | 4010 |
4001 pid = lwpid_of (get_thread_lwp (current_inferior)); | 4011 pid = lwpid_of (get_thread_lwp (current_inferior)); |
4002 while (regset->size >= 0) | 4012 while (regset->size >= 0) |
4003 { | 4013 { |
4004 void *buf, *data; | 4014 void *buf, *data; |
4005 int nt_type, res; | 4015 int nt_type, res; |
4006 | 4016 |
4007 if (regset->size == 0 || disabled_regsets[regset - target_regsets]) | 4017 if (regset->size == 0 || regset_disabled (regsets_info, regset)) |
4008 { | 4018 { |
4009 regset ++; | 4019 regset ++; |
4010 continue; | 4020 continue; |
4011 } | 4021 } |
4012 | 4022 |
4013 buf = xmalloc (regset->size); | 4023 buf = xmalloc (regset->size); |
4014 | 4024 |
4015 nt_type = regset->nt_type; | 4025 nt_type = regset->nt_type; |
4016 if (nt_type) | 4026 if (nt_type) |
4017 { | 4027 { |
4018 iov.iov_base = buf; | 4028 iov.iov_base = buf; |
4019 iov.iov_len = regset->size; | 4029 iov.iov_len = regset->size; |
4020 data = (void *) &iov; | 4030 data = (void *) &iov; |
4021 } | 4031 } |
4022 else | 4032 else |
4023 data = buf; | 4033 data = buf; |
4024 | 4034 |
4025 #ifndef __sparc__ | 4035 #ifndef __sparc__ |
4026 res = ptrace (regset->get_request, pid, | 4036 res = ptrace (regset->get_request, pid, |
4027 » » (PTRACE_ARG3_TYPE) (long) nt_type, data); | 4037 » » (PTRACE_TYPE_ARG3) (long) nt_type, data); |
4028 #else | 4038 #else |
4029 res = ptrace (regset->get_request, pid, data, nt_type); | 4039 res = ptrace (regset->get_request, pid, data, nt_type); |
4030 #endif | 4040 #endif |
4031 if (res < 0) | 4041 if (res < 0) |
4032 { | 4042 { |
4033 if (errno == EIO) | 4043 if (errno == EIO) |
4034 { | 4044 { |
4035 /* If we get EIO on a regset, do not try it again for | 4045 /* If we get EIO on a regset, do not try it again for |
4036 » » this process. */ | 4046 » » this process mode. */ |
4037 » disabled_regsets[regset - target_regsets] = 1; | 4047 » disable_regset (regsets_info, regset); |
4038 free (buf); | 4048 free (buf); |
4039 continue; | 4049 continue; |
4040 } | 4050 } |
4041 else | 4051 else |
4042 { | 4052 { |
4043 char s[256]; | 4053 char s[256]; |
4044 sprintf (s, "ptrace(regsets_fetch_inferior_registers) PID=%d", | 4054 sprintf (s, "ptrace(regsets_fetch_inferior_registers) PID=%d", |
4045 pid); | 4055 pid); |
4046 perror (s); | 4056 perror (s); |
4047 } | 4057 } |
4048 } | 4058 } |
4049 else if (regset->type == GENERAL_REGS) | 4059 else if (regset->type == GENERAL_REGS) |
4050 saw_general_regs = 1; | 4060 saw_general_regs = 1; |
4051 regset->store_function (regcache, buf); | 4061 regset->store_function (regcache, buf); |
4052 regset ++; | 4062 regset ++; |
4053 free (buf); | 4063 free (buf); |
4054 } | 4064 } |
4055 if (saw_general_regs) | 4065 if (saw_general_regs) |
4056 return 0; | 4066 return 0; |
4057 else | 4067 else |
4058 return 1; | 4068 return 1; |
4059 } | 4069 } |
4060 | 4070 |
4061 static int | 4071 static int |
4062 regsets_store_inferior_registers (struct regcache *regcache) | 4072 regsets_store_inferior_registers (struct regsets_info *regsets_info, |
| 4073 » » » » struct regcache *regcache) |
4063 { | 4074 { |
4064 struct regset_info *regset; | 4075 struct regset_info *regset; |
4065 int saw_general_regs = 0; | 4076 int saw_general_regs = 0; |
4066 int pid; | 4077 int pid; |
4067 struct iovec iov; | 4078 struct iovec iov; |
4068 | 4079 |
4069 regset = target_regsets; | 4080 regset = regsets_info->regsets; |
4070 | 4081 |
4071 pid = lwpid_of (get_thread_lwp (current_inferior)); | 4082 pid = lwpid_of (get_thread_lwp (current_inferior)); |
4072 while (regset->size >= 0) | 4083 while (regset->size >= 0) |
4073 { | 4084 { |
4074 void *buf, *data; | 4085 void *buf, *data; |
4075 int nt_type, res; | 4086 int nt_type, res; |
4076 | 4087 |
4077 if (regset->size == 0 || disabled_regsets[regset - target_regsets]) | 4088 if (regset->size == 0 || regset_disabled (regsets_info, regset)) |
4078 { | 4089 { |
4079 regset ++; | 4090 regset ++; |
4080 continue; | 4091 continue; |
4081 } | 4092 } |
4082 | 4093 |
4083 buf = xmalloc (regset->size); | 4094 buf = xmalloc (regset->size); |
4084 | 4095 |
4085 /* First fill the buffer with the current register set contents, | 4096 /* First fill the buffer with the current register set contents, |
4086 in case there are any items in the kernel's regset that are | 4097 in case there are any items in the kernel's regset that are |
4087 not in gdbserver's regcache. */ | 4098 not in gdbserver's regcache. */ |
4088 | 4099 |
4089 nt_type = regset->nt_type; | 4100 nt_type = regset->nt_type; |
4090 if (nt_type) | 4101 if (nt_type) |
4091 { | 4102 { |
4092 iov.iov_base = buf; | 4103 iov.iov_base = buf; |
4093 iov.iov_len = regset->size; | 4104 iov.iov_len = regset->size; |
4094 data = (void *) &iov; | 4105 data = (void *) &iov; |
4095 } | 4106 } |
4096 else | 4107 else |
4097 data = buf; | 4108 data = buf; |
4098 | 4109 |
4099 #ifndef __sparc__ | 4110 #ifndef __sparc__ |
4100 res = ptrace (regset->get_request, pid, | 4111 res = ptrace (regset->get_request, pid, |
4101 » » (PTRACE_ARG3_TYPE) (long) nt_type, data); | 4112 » » (PTRACE_TYPE_ARG3) (long) nt_type, data); |
4102 #else | 4113 #else |
4103 res = ptrace (regset->get_request, pid, data, nt_type); | 4114 res = ptrace (regset->get_request, pid, data, nt_type); |
4104 #endif | 4115 #endif |
4105 | 4116 |
4106 if (res == 0) | 4117 if (res == 0) |
4107 { | 4118 { |
4108 /* Then overlay our cached registers on that. */ | 4119 /* Then overlay our cached registers on that. */ |
4109 regset->fill_function (regcache, buf); | 4120 regset->fill_function (regcache, buf); |
4110 | 4121 |
4111 /* Only now do we write the register set. */ | 4122 /* Only now do we write the register set. */ |
4112 #ifndef __sparc__ | 4123 #ifndef __sparc__ |
4113 res = ptrace (regset->set_request, pid, | 4124 res = ptrace (regset->set_request, pid, |
4114 » » » (PTRACE_ARG3_TYPE) (long) nt_type, data); | 4125 » » » (PTRACE_TYPE_ARG3) (long) nt_type, data); |
4115 #else | 4126 #else |
4116 res = ptrace (regset->set_request, pid, data, nt_type); | 4127 res = ptrace (regset->set_request, pid, data, nt_type); |
4117 #endif | 4128 #endif |
4118 } | 4129 } |
4119 | 4130 |
4120 if (res < 0) | 4131 if (res < 0) |
4121 { | 4132 { |
4122 if (errno == EIO) | 4133 if (errno == EIO) |
4123 { | 4134 { |
4124 /* If we get EIO on a regset, do not try it again for | 4135 /* If we get EIO on a regset, do not try it again for |
4125 » » this process. */ | 4136 » » this process mode. */ |
4126 » disabled_regsets[regset - target_regsets] = 1; | 4137 » disable_regset (regsets_info, regset); |
4127 free (buf); | 4138 free (buf); |
4128 continue; | 4139 continue; |
4129 } | 4140 } |
4130 else if (errno == ESRCH) | 4141 else if (errno == ESRCH) |
4131 { | 4142 { |
4132 /* At this point, ESRCH should mean the process is | 4143 /* At this point, ESRCH should mean the process is |
4133 already gone, in which case we simply ignore attempts | 4144 already gone, in which case we simply ignore attempts |
4134 to change its registers. See also the related | 4145 to change its registers. See also the related |
4135 comment in linux_resume_one_lwp. */ | 4146 comment in linux_resume_one_lwp. */ |
4136 free (buf); | 4147 free (buf); |
(...skipping 11 matching lines...) Expand all Loading... |
4148 } | 4159 } |
4149 if (saw_general_regs) | 4160 if (saw_general_regs) |
4150 return 0; | 4161 return 0; |
4151 else | 4162 else |
4152 return 1; | 4163 return 1; |
4153 } | 4164 } |
4154 | 4165 |
4155 #else /* !HAVE_LINUX_REGSETS */ | 4166 #else /* !HAVE_LINUX_REGSETS */ |
4156 | 4167 |
4157 #define use_linux_regsets 0 | 4168 #define use_linux_regsets 0 |
4158 #define regsets_fetch_inferior_registers(regcache) 1 | 4169 #define regsets_fetch_inferior_registers(regsets_info, regcache) 1 |
4159 #define regsets_store_inferior_registers(regcache) 1 | 4170 #define regsets_store_inferior_registers(regsets_info, regcache) 1 |
4160 | 4171 |
4161 #endif | 4172 #endif |
4162 | 4173 |
4163 /* Return 1 if register REGNO is supported by one of the regset ptrace | 4174 /* Return 1 if register REGNO is supported by one of the regset ptrace |
4164 calls or 0 if it has to be transferred individually. */ | 4175 calls or 0 if it has to be transferred individually. */ |
4165 | 4176 |
4166 static int | 4177 static int |
4167 linux_register_in_regsets (int regno) | 4178 linux_register_in_regsets (const struct regs_info *regs_info, int regno) |
4168 { | 4179 { |
4169 unsigned char mask = 1 << (regno % 8); | 4180 unsigned char mask = 1 << (regno % 8); |
4170 size_t index = regno / 8; | 4181 size_t index = regno / 8; |
4171 | 4182 |
4172 return (use_linux_regsets | 4183 return (use_linux_regsets |
4173 » && (the_low_target.regset_bitmap == NULL | 4184 » && (regs_info->regset_bitmap == NULL |
4174 » || (the_low_target.regset_bitmap[index] & mask) != 0)); | 4185 » || (regs_info->regset_bitmap[index] & mask) != 0)); |
4175 } | 4186 } |
4176 | 4187 |
4177 #ifdef HAVE_LINUX_USRREGS | 4188 #ifdef HAVE_LINUX_USRREGS |
4178 | 4189 |
4179 int | 4190 int |
4180 register_addr (int regnum) | 4191 register_addr (const struct usrregs_info *usrregs, int regnum) |
4181 { | 4192 { |
4182 int addr; | 4193 int addr; |
4183 | 4194 |
4184 if (regnum < 0 || regnum >= the_low_target.num_regs) | 4195 if (regnum < 0 || regnum >= usrregs->num_regs) |
4185 error ("Invalid register number %d.", regnum); | 4196 error ("Invalid register number %d.", regnum); |
4186 | 4197 |
4187 addr = the_low_target.regmap[regnum]; | 4198 addr = usrregs->regmap[regnum]; |
4188 | 4199 |
4189 return addr; | 4200 return addr; |
4190 } | 4201 } |
4191 | 4202 |
4192 /* Fetch one register. */ | 4203 /* Fetch one register. */ |
4193 static void | 4204 static void |
4194 fetch_register (struct regcache *regcache, int regno) | 4205 fetch_register (const struct usrregs_info *usrregs, |
| 4206 » » struct regcache *regcache, int regno) |
4195 { | 4207 { |
4196 CORE_ADDR regaddr; | 4208 CORE_ADDR regaddr; |
4197 int i, size; | 4209 int i, size; |
4198 char *buf; | 4210 char *buf; |
4199 int pid; | 4211 int pid; |
4200 | 4212 |
4201 if (regno >= the_low_target.num_regs) | 4213 if (regno >= usrregs->num_regs) |
4202 return; | 4214 return; |
4203 if ((*the_low_target.cannot_fetch_register) (regno)) | 4215 if ((*the_low_target.cannot_fetch_register) (regno)) |
4204 return; | 4216 return; |
4205 | 4217 |
4206 regaddr = register_addr (regno); | 4218 regaddr = register_addr (usrregs, regno); |
4207 if (regaddr == -1) | 4219 if (regaddr == -1) |
4208 return; | 4220 return; |
4209 | 4221 |
4210 size = ((register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1) | 4222 size = ((register_size (regcache->tdesc, regno) |
| 4223 » + sizeof (PTRACE_XFER_TYPE) - 1) |
4211 & -sizeof (PTRACE_XFER_TYPE)); | 4224 & -sizeof (PTRACE_XFER_TYPE)); |
4212 buf = alloca (size); | 4225 buf = alloca (size); |
4213 | 4226 |
4214 pid = lwpid_of (get_thread_lwp (current_inferior)); | 4227 pid = lwpid_of (get_thread_lwp (current_inferior)); |
4215 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) | 4228 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) |
4216 { | 4229 { |
4217 errno = 0; | 4230 errno = 0; |
4218 *(PTRACE_XFER_TYPE *) (buf + i) = | 4231 *(PTRACE_XFER_TYPE *) (buf + i) = |
4219 ptrace (PTRACE_PEEKUSER, pid, | 4232 ptrace (PTRACE_PEEKUSER, pid, |
4220 /* Coerce to a uintptr_t first to avoid potential gcc warning | 4233 /* Coerce to a uintptr_t first to avoid potential gcc warning |
4221 of coercing an 8 byte integer to a 4 byte pointer. */ | 4234 of coercing an 8 byte integer to a 4 byte pointer. */ |
4222 » » (PTRACE_ARG3_TYPE) (uintptr_t) regaddr, 0); | 4235 » » (PTRACE_TYPE_ARG3) (uintptr_t) regaddr, (PTRACE_TYPE_ARG4) 0); |
4223 regaddr += sizeof (PTRACE_XFER_TYPE); | 4236 regaddr += sizeof (PTRACE_XFER_TYPE); |
4224 if (errno != 0) | 4237 if (errno != 0) |
4225 error ("reading register %d: %s", regno, strerror (errno)); | 4238 error ("reading register %d: %s", regno, strerror (errno)); |
4226 } | 4239 } |
4227 | 4240 |
4228 if (the_low_target.supply_ptrace_register) | 4241 if (the_low_target.supply_ptrace_register) |
4229 the_low_target.supply_ptrace_register (regcache, regno, buf); | 4242 the_low_target.supply_ptrace_register (regcache, regno, buf); |
4230 else | 4243 else |
4231 supply_register (regcache, regno, buf); | 4244 supply_register (regcache, regno, buf); |
4232 } | 4245 } |
4233 | 4246 |
4234 /* Store one register. */ | 4247 /* Store one register. */ |
4235 static void | 4248 static void |
4236 store_register (struct regcache *regcache, int regno) | 4249 store_register (const struct usrregs_info *usrregs, |
| 4250 » » struct regcache *regcache, int regno) |
4237 { | 4251 { |
4238 CORE_ADDR regaddr; | 4252 CORE_ADDR regaddr; |
4239 int i, size; | 4253 int i, size; |
4240 char *buf; | 4254 char *buf; |
4241 int pid; | 4255 int pid; |
4242 | 4256 |
4243 if (regno >= the_low_target.num_regs) | 4257 if (regno >= usrregs->num_regs) |
4244 return; | 4258 return; |
4245 if ((*the_low_target.cannot_store_register) (regno)) | 4259 if ((*the_low_target.cannot_store_register) (regno)) |
4246 return; | 4260 return; |
4247 | 4261 |
4248 regaddr = register_addr (regno); | 4262 regaddr = register_addr (usrregs, regno); |
4249 if (regaddr == -1) | 4263 if (regaddr == -1) |
4250 return; | 4264 return; |
4251 | 4265 |
4252 size = ((register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1) | 4266 size = ((register_size (regcache->tdesc, regno) |
| 4267 » + sizeof (PTRACE_XFER_TYPE) - 1) |
4253 & -sizeof (PTRACE_XFER_TYPE)); | 4268 & -sizeof (PTRACE_XFER_TYPE)); |
4254 buf = alloca (size); | 4269 buf = alloca (size); |
4255 memset (buf, 0, size); | 4270 memset (buf, 0, size); |
4256 | 4271 |
4257 if (the_low_target.collect_ptrace_register) | 4272 if (the_low_target.collect_ptrace_register) |
4258 the_low_target.collect_ptrace_register (regcache, regno, buf); | 4273 the_low_target.collect_ptrace_register (regcache, regno, buf); |
4259 else | 4274 else |
4260 collect_register (regcache, regno, buf); | 4275 collect_register (regcache, regno, buf); |
4261 | 4276 |
4262 pid = lwpid_of (get_thread_lwp (current_inferior)); | 4277 pid = lwpid_of (get_thread_lwp (current_inferior)); |
4263 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) | 4278 for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) |
4264 { | 4279 { |
4265 errno = 0; | 4280 errno = 0; |
4266 ptrace (PTRACE_POKEUSER, pid, | 4281 ptrace (PTRACE_POKEUSER, pid, |
4267 /* Coerce to a uintptr_t first to avoid potential gcc warning | 4282 /* Coerce to a uintptr_t first to avoid potential gcc warning |
4268 about coercing an 8 byte integer to a 4 byte pointer. */ | 4283 about coercing an 8 byte integer to a 4 byte pointer. */ |
4269 » (PTRACE_ARG3_TYPE) (uintptr_t) regaddr, | 4284 » (PTRACE_TYPE_ARG3) (uintptr_t) regaddr, |
4270 » (PTRACE_ARG4_TYPE) *(PTRACE_XFER_TYPE *) (buf + i)); | 4285 » (PTRACE_TYPE_ARG4) *(PTRACE_XFER_TYPE *) (buf + i)); |
4271 if (errno != 0) | 4286 if (errno != 0) |
4272 { | 4287 { |
4273 /* At this point, ESRCH should mean the process is | 4288 /* At this point, ESRCH should mean the process is |
4274 already gone, in which case we simply ignore attempts | 4289 already gone, in which case we simply ignore attempts |
4275 to change its registers. See also the related | 4290 to change its registers. See also the related |
4276 comment in linux_resume_one_lwp. */ | 4291 comment in linux_resume_one_lwp. */ |
4277 if (errno == ESRCH) | 4292 if (errno == ESRCH) |
4278 return; | 4293 return; |
4279 | 4294 |
4280 if ((*the_low_target.cannot_store_register) (regno) == 0) | 4295 if ((*the_low_target.cannot_store_register) (regno) == 0) |
4281 error ("writing register %d: %s", regno, strerror (errno)); | 4296 error ("writing register %d: %s", regno, strerror (errno)); |
4282 } | 4297 } |
4283 regaddr += sizeof (PTRACE_XFER_TYPE); | 4298 regaddr += sizeof (PTRACE_XFER_TYPE); |
4284 } | 4299 } |
4285 } | 4300 } |
4286 | 4301 |
4287 /* Fetch all registers, or just one, from the child process. | 4302 /* Fetch all registers, or just one, from the child process. |
4288 If REGNO is -1, do this for all registers, skipping any that are | 4303 If REGNO is -1, do this for all registers, skipping any that are |
4289 assumed to have been retrieved by regsets_fetch_inferior_registers, | 4304 assumed to have been retrieved by regsets_fetch_inferior_registers, |
4290 unless ALL is non-zero. | 4305 unless ALL is non-zero. |
4291 Otherwise, REGNO specifies which register (so we can save time). */ | 4306 Otherwise, REGNO specifies which register (so we can save time). */ |
4292 static void | 4307 static void |
4293 usr_fetch_inferior_registers (struct regcache *regcache, int regno, int all) | 4308 usr_fetch_inferior_registers (const struct regs_info *regs_info, |
| 4309 » » » struct regcache *regcache, int regno, int all) |
4294 { | 4310 { |
| 4311 struct usrregs_info *usr = regs_info->usrregs; |
| 4312 |
4295 if (regno == -1) | 4313 if (regno == -1) |
4296 { | 4314 { |
4297 for (regno = 0; regno < the_low_target.num_regs; regno++) | 4315 for (regno = 0; regno < usr->num_regs; regno++) |
4298 » if (all || !linux_register_in_regsets (regno)) | 4316 » if (all || !linux_register_in_regsets (regs_info, regno)) |
4299 » fetch_register (regcache, regno); | 4317 » fetch_register (usr, regcache, regno); |
4300 } | 4318 } |
4301 else | 4319 else |
4302 fetch_register (regcache, regno); | 4320 fetch_register (usr, regcache, regno); |
4303 } | 4321 } |
4304 | 4322 |
4305 /* Store our register values back into the inferior. | 4323 /* Store our register values back into the inferior. |
4306 If REGNO is -1, do this for all registers, skipping any that are | 4324 If REGNO is -1, do this for all registers, skipping any that are |
4307 assumed to have been saved by regsets_store_inferior_registers, | 4325 assumed to have been saved by regsets_store_inferior_registers, |
4308 unless ALL is non-zero. | 4326 unless ALL is non-zero. |
4309 Otherwise, REGNO specifies which register (so we can save time). */ | 4327 Otherwise, REGNO specifies which register (so we can save time). */ |
4310 static void | 4328 static void |
4311 usr_store_inferior_registers (struct regcache *regcache, int regno, int all) | 4329 usr_store_inferior_registers (const struct regs_info *regs_info, |
| 4330 » » » struct regcache *regcache, int regno, int all) |
4312 { | 4331 { |
| 4332 struct usrregs_info *usr = regs_info->usrregs; |
| 4333 |
4313 if (regno == -1) | 4334 if (regno == -1) |
4314 { | 4335 { |
4315 for (regno = 0; regno < the_low_target.num_regs; regno++) | 4336 for (regno = 0; regno < usr->num_regs; regno++) |
4316 » if (all || !linux_register_in_regsets (regno)) | 4337 » if (all || !linux_register_in_regsets (regs_info, regno)) |
4317 » store_register (regcache, regno); | 4338 » store_register (usr, regcache, regno); |
4318 } | 4339 } |
4319 else | 4340 else |
4320 store_register (regcache, regno); | 4341 store_register (usr, regcache, regno); |
4321 } | 4342 } |
4322 | 4343 |
4323 #else /* !HAVE_LINUX_USRREGS */ | 4344 #else /* !HAVE_LINUX_USRREGS */ |
4324 | 4345 |
4325 #define usr_fetch_inferior_registers(regcache, regno, all) do {} while (0) | 4346 #define usr_fetch_inferior_registers(regs_info, regcache, regno, all) do {} whil
e (0) |
4326 #define usr_store_inferior_registers(regcache, regno, all) do {} while (0) | 4347 #define usr_store_inferior_registers(regs_info, regcache, regno, all) do {} whil
e (0) |
4327 | 4348 |
4328 #endif | 4349 #endif |
4329 | 4350 |
4330 | 4351 |
4331 void | 4352 void |
4332 linux_fetch_registers (struct regcache *regcache, int regno) | 4353 linux_fetch_registers (struct regcache *regcache, int regno) |
4333 { | 4354 { |
4334 int use_regsets; | 4355 int use_regsets; |
4335 int all = 0; | 4356 int all = 0; |
| 4357 const struct regs_info *regs_info = (*the_low_target.regs_info) (); |
4336 | 4358 |
4337 if (regno == -1) | 4359 if (regno == -1) |
4338 { | 4360 { |
4339 if (the_low_target.fetch_register != NULL) | 4361 if (the_low_target.fetch_register != NULL |
4340 » for (regno = 0; regno < the_low_target.num_regs; regno++) | 4362 » && regs_info->usrregs != NULL) |
| 4363 » for (regno = 0; regno < regs_info->usrregs->num_regs; regno++) |
4341 (*the_low_target.fetch_register) (regcache, regno); | 4364 (*the_low_target.fetch_register) (regcache, regno); |
4342 | 4365 |
4343 all = regsets_fetch_inferior_registers (regcache); | 4366 all = regsets_fetch_inferior_registers (regs_info->regsets_info, regcache)
; |
4344 usr_fetch_inferior_registers (regcache, -1, all); | 4367 if (regs_info->usrregs != NULL) |
| 4368 » usr_fetch_inferior_registers (regs_info, regcache, -1, all); |
4345 } | 4369 } |
4346 else | 4370 else |
4347 { | 4371 { |
4348 if (the_low_target.fetch_register != NULL | 4372 if (the_low_target.fetch_register != NULL |
4349 && (*the_low_target.fetch_register) (regcache, regno)) | 4373 && (*the_low_target.fetch_register) (regcache, regno)) |
4350 return; | 4374 return; |
4351 | 4375 |
4352 use_regsets = linux_register_in_regsets (regno); | 4376 use_regsets = linux_register_in_regsets (regs_info, regno); |
4353 if (use_regsets) | 4377 if (use_regsets) |
4354 » all = regsets_fetch_inferior_registers (regcache); | 4378 » all = regsets_fetch_inferior_registers (regs_info->regsets_info, |
4355 if (!use_regsets || all) | 4379 » » » » » » regcache); |
4356 » usr_fetch_inferior_registers (regcache, regno, 1); | 4380 if ((!use_regsets || all) && regs_info->usrregs != NULL) |
| 4381 » usr_fetch_inferior_registers (regs_info, regcache, regno, 1); |
4357 } | 4382 } |
4358 } | 4383 } |
4359 | 4384 |
4360 void | 4385 void |
4361 linux_store_registers (struct regcache *regcache, int regno) | 4386 linux_store_registers (struct regcache *regcache, int regno) |
4362 { | 4387 { |
4363 int use_regsets; | 4388 int use_regsets; |
4364 int all = 0; | 4389 int all = 0; |
| 4390 const struct regs_info *regs_info = (*the_low_target.regs_info) (); |
4365 | 4391 |
4366 if (regno == -1) | 4392 if (regno == -1) |
4367 { | 4393 { |
4368 all = regsets_store_inferior_registers (regcache); | 4394 all = regsets_store_inferior_registers (regs_info->regsets_info, |
4369 usr_store_inferior_registers (regcache, regno, all); | 4395 » » » » » regcache); |
| 4396 if (regs_info->usrregs != NULL) |
| 4397 » usr_store_inferior_registers (regs_info, regcache, regno, all); |
4370 } | 4398 } |
4371 else | 4399 else |
4372 { | 4400 { |
4373 use_regsets = linux_register_in_regsets (regno); | 4401 use_regsets = linux_register_in_regsets (regs_info, regno); |
4374 if (use_regsets) | 4402 if (use_regsets) |
4375 » all = regsets_store_inferior_registers (regcache); | 4403 » all = regsets_store_inferior_registers (regs_info->regsets_info, |
4376 if (!use_regsets || all) | 4404 » » » » » » regcache); |
4377 » usr_store_inferior_registers (regcache, regno, 1); | 4405 if ((!use_regsets || all) && regs_info->usrregs != NULL) |
| 4406 » usr_store_inferior_registers (regs_info, regcache, regno, 1); |
4378 } | 4407 } |
4379 } | 4408 } |
4380 | 4409 |
4381 | 4410 |
4382 /* Copy LEN bytes from inferior's memory starting at MEMADDR | 4411 /* Copy LEN bytes from inferior's memory starting at MEMADDR |
4383 to debugger memory starting at MYADDR. */ | 4412 to debugger memory starting at MYADDR. */ |
4384 | 4413 |
4385 static int | 4414 static int |
4386 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) | 4415 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
4387 { | 4416 { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4440 /* Allocate buffer of that many longwords. */ | 4469 /* Allocate buffer of that many longwords. */ |
4441 buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); | 4470 buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); |
4442 | 4471 |
4443 /* Read all the longwords */ | 4472 /* Read all the longwords */ |
4444 errno = 0; | 4473 errno = 0; |
4445 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | 4474 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) |
4446 { | 4475 { |
4447 /* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning | 4476 /* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning |
4448 about coercing an 8 byte integer to a 4 byte pointer. */ | 4477 about coercing an 8 byte integer to a 4 byte pointer. */ |
4449 buffer[i] = ptrace (PTRACE_PEEKTEXT, pid, | 4478 buffer[i] = ptrace (PTRACE_PEEKTEXT, pid, |
4450 » » » (PTRACE_ARG3_TYPE) (uintptr_t) addr, 0); | 4479 » » » (PTRACE_TYPE_ARG3) (uintptr_t) addr, |
| 4480 » » » (PTRACE_TYPE_ARG4) 0); |
4451 if (errno) | 4481 if (errno) |
4452 break; | 4482 break; |
4453 } | 4483 } |
4454 ret = errno; | 4484 ret = errno; |
4455 | 4485 |
4456 /* Copy appropriate bytes out of the buffer. */ | 4486 /* Copy appropriate bytes out of the buffer. */ |
4457 if (i > 0) | 4487 if (i > 0) |
4458 { | 4488 { |
4459 i *= sizeof (PTRACE_XFER_TYPE); | 4489 i *= sizeof (PTRACE_XFER_TYPE); |
4460 i -= memaddr & (sizeof (PTRACE_XFER_TYPE) - 1); | 4490 i -= memaddr & (sizeof (PTRACE_XFER_TYPE) - 1); |
4461 memcpy (myaddr, | 4491 memcpy (myaddr, |
4462 (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | 4492 (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), |
4463 i < len ? i : len); | 4493 i < len ? i : len); |
4464 } | 4494 } |
4465 | 4495 |
4466 return ret; | 4496 return ret; |
4467 } | 4497 } |
4468 | 4498 |
4469 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's | 4499 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's |
4470 memory at MEMADDR. On failure (cannot write to the inferior) | 4500 memory at MEMADDR. On failure (cannot write to the inferior) |
4471 returns the value of errno. */ | 4501 returns the value of errno. Always succeeds if LEN is zero. */ |
4472 | 4502 |
4473 static int | 4503 static int |
4474 linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len) | 4504 linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len) |
4475 { | 4505 { |
4476 register int i; | 4506 register int i; |
4477 /* Round starting address down to longword boundary. */ | 4507 /* Round starting address down to longword boundary. */ |
4478 register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE); | 4508 register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE); |
4479 /* Round ending address up; get number of longwords that makes. */ | 4509 /* Round ending address up; get number of longwords that makes. */ |
4480 register int count | 4510 register int count |
4481 = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) | 4511 = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) |
4482 / sizeof (PTRACE_XFER_TYPE); | 4512 / sizeof (PTRACE_XFER_TYPE); |
4483 | 4513 |
4484 /* Allocate buffer of that many longwords. */ | 4514 /* Allocate buffer of that many longwords. */ |
4485 register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) | 4515 register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) |
4486 alloca (count * sizeof (PTRACE_XFER_TYPE)); | 4516 alloca (count * sizeof (PTRACE_XFER_TYPE)); |
4487 | 4517 |
4488 int pid = lwpid_of (get_thread_lwp (current_inferior)); | 4518 int pid = lwpid_of (get_thread_lwp (current_inferior)); |
4489 | 4519 |
| 4520 if (len == 0) |
| 4521 { |
| 4522 /* Zero length write always succeeds. */ |
| 4523 return 0; |
| 4524 } |
| 4525 |
4490 if (debug_threads) | 4526 if (debug_threads) |
4491 { | 4527 { |
4492 /* Dump up to four bytes. */ | 4528 /* Dump up to four bytes. */ |
4493 unsigned int val = * (unsigned int *) myaddr; | 4529 unsigned int val = * (unsigned int *) myaddr; |
4494 if (len == 1) | 4530 if (len == 1) |
4495 val = val & 0xff; | 4531 val = val & 0xff; |
4496 else if (len == 2) | 4532 else if (len == 2) |
4497 val = val & 0xffff; | 4533 val = val & 0xffff; |
4498 else if (len == 3) | 4534 else if (len == 3) |
4499 val = val & 0xffffff; | 4535 val = val & 0xffffff; |
4500 fprintf (stderr, "Writing %0*x to 0x%08lx\n", 2 * ((len < 4) ? len : 4), | 4536 fprintf (stderr, "Writing %0*x to 0x%08lx\n", 2 * ((len < 4) ? len : 4), |
4501 val, (long)memaddr); | 4537 val, (long)memaddr); |
4502 } | 4538 } |
4503 | 4539 |
4504 /* Fill start and end extra bytes of buffer with existing memory data. */ | 4540 /* Fill start and end extra bytes of buffer with existing memory data. */ |
4505 | 4541 |
4506 errno = 0; | 4542 errno = 0; |
4507 /* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning | 4543 /* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning |
4508 about coercing an 8 byte integer to a 4 byte pointer. */ | 4544 about coercing an 8 byte integer to a 4 byte pointer. */ |
4509 buffer[0] = ptrace (PTRACE_PEEKTEXT, pid, | 4545 buffer[0] = ptrace (PTRACE_PEEKTEXT, pid, |
4510 » » (PTRACE_ARG3_TYPE) (uintptr_t) addr, 0); | 4546 » » (PTRACE_TYPE_ARG3) (uintptr_t) addr, |
| 4547 » » (PTRACE_TYPE_ARG4) 0); |
4511 if (errno) | 4548 if (errno) |
4512 return errno; | 4549 return errno; |
4513 | 4550 |
4514 if (count > 1) | 4551 if (count > 1) |
4515 { | 4552 { |
4516 errno = 0; | 4553 errno = 0; |
4517 buffer[count - 1] | 4554 buffer[count - 1] |
4518 = ptrace (PTRACE_PEEKTEXT, pid, | 4555 = ptrace (PTRACE_PEEKTEXT, pid, |
4519 /* Coerce to a uintptr_t first to avoid potential gcc warning | 4556 /* Coerce to a uintptr_t first to avoid potential gcc warning |
4520 about coercing an 8 byte integer to a 4 byte pointer. */ | 4557 about coercing an 8 byte integer to a 4 byte pointer. */ |
4521 » » (PTRACE_ARG3_TYPE) (uintptr_t) (addr + (count - 1) | 4558 » » (PTRACE_TYPE_ARG3) (uintptr_t) (addr + (count - 1) |
4522 * sizeof (PTRACE_XFER_TYPE)), | 4559 * sizeof (PTRACE_XFER_TYPE)), |
4523 » » 0); | 4560 » » (PTRACE_TYPE_ARG4) 0); |
4524 if (errno) | 4561 if (errno) |
4525 return errno; | 4562 return errno; |
4526 } | 4563 } |
4527 | 4564 |
4528 /* Copy data to be written over corresponding part of buffer. */ | 4565 /* Copy data to be written over corresponding part of buffer. */ |
4529 | 4566 |
4530 memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | 4567 memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), |
4531 myaddr, len); | 4568 myaddr, len); |
4532 | 4569 |
4533 /* Write the entire buffer. */ | 4570 /* Write the entire buffer. */ |
4534 | 4571 |
4535 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | 4572 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) |
4536 { | 4573 { |
4537 errno = 0; | 4574 errno = 0; |
4538 ptrace (PTRACE_POKETEXT, pid, | 4575 ptrace (PTRACE_POKETEXT, pid, |
4539 /* Coerce to a uintptr_t first to avoid potential gcc warning | 4576 /* Coerce to a uintptr_t first to avoid potential gcc warning |
4540 about coercing an 8 byte integer to a 4 byte pointer. */ | 4577 about coercing an 8 byte integer to a 4 byte pointer. */ |
4541 » (PTRACE_ARG3_TYPE) (uintptr_t) addr, | 4578 » (PTRACE_TYPE_ARG3) (uintptr_t) addr, |
4542 » (PTRACE_ARG4_TYPE) buffer[i]); | 4579 » (PTRACE_TYPE_ARG4) buffer[i]); |
4543 if (errno) | 4580 if (errno) |
4544 return errno; | 4581 return errno; |
4545 } | 4582 } |
4546 | 4583 |
4547 return 0; | 4584 return 0; |
4548 } | 4585 } |
4549 | 4586 |
4550 /* Non-zero if the kernel supports PTRACE_O_TRACEFORK. */ | |
4551 static int linux_supports_tracefork_flag; | |
4552 | |
4553 static void | |
4554 linux_enable_event_reporting (int pid) | |
4555 { | |
4556 if (!linux_supports_tracefork_flag) | |
4557 return; | |
4558 | |
4559 ptrace (PTRACE_SETOPTIONS, pid, 0, (PTRACE_ARG4_TYPE) PTRACE_O_TRACECLONE); | |
4560 } | |
4561 | |
4562 /* Helper functions for linux_test_for_tracefork, called via clone (). */ | |
4563 | |
4564 static int | |
4565 linux_tracefork_grandchild (void *arg) | |
4566 { | |
4567 _exit (0); | |
4568 } | |
4569 | |
4570 #define STACK_SIZE 4096 | |
4571 | |
4572 static int | |
4573 linux_tracefork_child (void *arg) | |
4574 { | |
4575 ptrace (PTRACE_TRACEME, 0, 0, 0); | |
4576 kill (getpid (), SIGSTOP); | |
4577 | |
4578 #if !(defined(__UCLIBC__) && defined(HAS_NOMMU)) | |
4579 | |
4580 if (fork () == 0) | |
4581 linux_tracefork_grandchild (NULL); | |
4582 | |
4583 #else /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4584 | |
4585 #ifdef __ia64__ | |
4586 __clone2 (linux_tracefork_grandchild, arg, STACK_SIZE, | |
4587 CLONE_VM | SIGCHLD, NULL); | |
4588 #else | |
4589 clone (linux_tracefork_grandchild, (char *) arg + STACK_SIZE, | |
4590 CLONE_VM | SIGCHLD, NULL); | |
4591 #endif | |
4592 | |
4593 #endif /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4594 | |
4595 _exit (0); | |
4596 } | |
4597 | |
4598 /* Determine if PTRACE_O_TRACEFORK can be used to follow fork events. Make | |
4599 sure that we can enable the option, and that it had the desired | |
4600 effect. */ | |
4601 | |
4602 static void | |
4603 linux_test_for_tracefork (void) | |
4604 { | |
4605 int child_pid, ret, status; | |
4606 long second_pid; | |
4607 #if defined(__UCLIBC__) && defined(HAS_NOMMU) | |
4608 char *stack = xmalloc (STACK_SIZE * 4); | |
4609 #endif /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4610 | |
4611 linux_supports_tracefork_flag = 0; | |
4612 | |
4613 #if !(defined(__UCLIBC__) && defined(HAS_NOMMU)) | |
4614 | |
4615 child_pid = fork (); | |
4616 if (child_pid == 0) | |
4617 linux_tracefork_child (NULL); | |
4618 | |
4619 #else /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4620 | |
4621 /* Use CLONE_VM instead of fork, to support uClinux (no MMU). */ | |
4622 #ifdef __ia64__ | |
4623 child_pid = __clone2 (linux_tracefork_child, stack, STACK_SIZE, | |
4624 CLONE_VM | SIGCHLD, stack + STACK_SIZE * 2); | |
4625 #else /* !__ia64__ */ | |
4626 child_pid = clone (linux_tracefork_child, stack + STACK_SIZE, | |
4627 CLONE_VM | SIGCHLD, stack + STACK_SIZE * 2); | |
4628 #endif /* !__ia64__ */ | |
4629 | |
4630 #endif /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4631 | |
4632 if (child_pid == -1) | |
4633 perror_with_name ("clone"); | |
4634 | |
4635 ret = my_waitpid (child_pid, &status, 0); | |
4636 if (ret == -1) | |
4637 perror_with_name ("waitpid"); | |
4638 else if (ret != child_pid) | |
4639 error ("linux_test_for_tracefork: waitpid: unexpected result %d.", ret); | |
4640 if (! WIFSTOPPED (status)) | |
4641 error ("linux_test_for_tracefork: waitpid: unexpected status %d.", status); | |
4642 | |
4643 ret = ptrace (PTRACE_SETOPTIONS, child_pid, 0, | |
4644 (PTRACE_ARG4_TYPE) PTRACE_O_TRACEFORK); | |
4645 if (ret != 0) | |
4646 { | |
4647 ret = ptrace (PTRACE_KILL, child_pid, 0, 0); | |
4648 if (ret != 0) | |
4649 { | |
4650 warning ("linux_test_for_tracefork: failed to kill child"); | |
4651 return; | |
4652 } | |
4653 | |
4654 ret = my_waitpid (child_pid, &status, 0); | |
4655 if (ret != child_pid) | |
4656 warning ("linux_test_for_tracefork: failed to wait for killed child"); | |
4657 else if (!WIFSIGNALED (status)) | |
4658 warning ("linux_test_for_tracefork: unexpected wait status 0x%x from " | |
4659 "killed child", status); | |
4660 | |
4661 return; | |
4662 } | |
4663 | |
4664 ret = ptrace (PTRACE_CONT, child_pid, 0, 0); | |
4665 if (ret != 0) | |
4666 warning ("linux_test_for_tracefork: failed to resume child"); | |
4667 | |
4668 ret = my_waitpid (child_pid, &status, 0); | |
4669 | |
4670 if (ret == child_pid && WIFSTOPPED (status) | |
4671 && status >> 16 == PTRACE_EVENT_FORK) | |
4672 { | |
4673 second_pid = 0; | |
4674 ret = ptrace (PTRACE_GETEVENTMSG, child_pid, 0, &second_pid); | |
4675 if (ret == 0 && second_pid != 0) | |
4676 { | |
4677 int second_status; | |
4678 | |
4679 linux_supports_tracefork_flag = 1; | |
4680 my_waitpid (second_pid, &second_status, 0); | |
4681 ret = ptrace (PTRACE_KILL, second_pid, 0, 0); | |
4682 if (ret != 0) | |
4683 warning ("linux_test_for_tracefork: failed to kill second child"); | |
4684 my_waitpid (second_pid, &status, 0); | |
4685 } | |
4686 } | |
4687 else | |
4688 warning ("linux_test_for_tracefork: unexpected result from waitpid " | |
4689 "(%d, status 0x%x)", ret, status); | |
4690 | |
4691 do | |
4692 { | |
4693 ret = ptrace (PTRACE_KILL, child_pid, 0, 0); | |
4694 if (ret != 0) | |
4695 warning ("linux_test_for_tracefork: failed to kill child"); | |
4696 my_waitpid (child_pid, &status, 0); | |
4697 } | |
4698 while (WIFSTOPPED (status)); | |
4699 | |
4700 #if defined(__UCLIBC__) && defined(HAS_NOMMU) | |
4701 free (stack); | |
4702 #endif /* defined(__UCLIBC__) && defined(HAS_NOMMU) */ | |
4703 } | |
4704 | |
4705 | |
4706 static void | 4587 static void |
4707 linux_look_up_symbols (void) | 4588 linux_look_up_symbols (void) |
4708 { | 4589 { |
4709 #ifdef USE_THREAD_DB | 4590 #ifdef USE_THREAD_DB |
4710 struct process_info *proc = current_process (); | 4591 struct process_info *proc = current_process (); |
4711 | 4592 |
4712 if (proc->private->thread_db != NULL) | 4593 if (proc->private->thread_db != NULL) |
4713 return; | 4594 return; |
4714 | 4595 |
4715 /* If the kernel supports tracing forks then it also supports tracing | 4596 /* If the kernel supports tracing clones, then we don't need to |
4716 clones, and then we don't need to use the magic thread event breakpoint | 4597 use the magic thread event breakpoint to learn about |
4717 to learn about threads. */ | 4598 threads. */ |
4718 thread_db_init (!linux_supports_tracefork_flag); | 4599 thread_db_init (!linux_supports_traceclone ()); |
4719 #endif | 4600 #endif |
4720 } | 4601 } |
4721 | 4602 |
4722 static void | 4603 static void |
4723 linux_request_interrupt (void) | 4604 linux_request_interrupt (void) |
4724 { | 4605 { |
4725 extern unsigned long signal_pid; | 4606 extern unsigned long signal_pid; |
4726 | 4607 |
4727 if (!ptid_equal (cont_thread, null_ptid) | 4608 if (!ptid_equal (cont_thread, null_ptid) |
4728 && !ptid_equal (cont_thread, minus_one_ptid)) | 4609 && !ptid_equal (cont_thread, minus_one_ptid)) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4798 } | 4679 } |
4799 | 4680 |
4800 static CORE_ADDR | 4681 static CORE_ADDR |
4801 linux_stopped_data_address (void) | 4682 linux_stopped_data_address (void) |
4802 { | 4683 { |
4803 struct lwp_info *lwp = get_thread_lwp (current_inferior); | 4684 struct lwp_info *lwp = get_thread_lwp (current_inferior); |
4804 | 4685 |
4805 return lwp->stopped_data_address; | 4686 return lwp->stopped_data_address; |
4806 } | 4687 } |
4807 | 4688 |
4808 #if defined(__UCLIBC__) && defined(HAS_NOMMU) | 4689 #if defined(__UCLIBC__) && defined(HAS_NOMMU)» \ |
4809 #if ! (defined(PT_TEXT_ADDR) \ | 4690 && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \ |
4810 || defined(PT_DATA_ADDR) \ | 4691 && defined(PT_TEXT_END_ADDR) |
4811 || defined(PT_TEXT_END_ADDR)) | 4692 |
4812 #if defined(__mcoldfire__) | 4693 /* This is only used for targets that define PT_TEXT_ADDR, |
4813 /* These should really be defined in the kernel's ptrace.h header. */ | 4694 PT_DATA_ADDR and PT_TEXT_END_ADDR. If those are not defined, supposedly |
4814 #define PT_TEXT_ADDR 49*4 | 4695 the target has different ways of acquiring this information, like |
4815 #define PT_DATA_ADDR 50*4 | 4696 loadmaps. */ |
4816 #define PT_TEXT_END_ADDR 51*4 | |
4817 #elif defined(BFIN) | |
4818 #define PT_TEXT_ADDR 220 | |
4819 #define PT_TEXT_END_ADDR 224 | |
4820 #define PT_DATA_ADDR 228 | |
4821 #elif defined(__TMS320C6X__) | |
4822 #define PT_TEXT_ADDR (0x10000*4) | |
4823 #define PT_DATA_ADDR (0x10004*4) | |
4824 #define PT_TEXT_END_ADDR (0x10008*4) | |
4825 #endif | |
4826 #endif | |
4827 | 4697 |
4828 /* Under uClinux, programs are loaded at non-zero offsets, which we need | 4698 /* Under uClinux, programs are loaded at non-zero offsets, which we need |
4829 to tell gdb about. */ | 4699 to tell gdb about. */ |
4830 | 4700 |
4831 static int | 4701 static int |
4832 linux_read_offsets (CORE_ADDR *text_p, CORE_ADDR *data_p) | 4702 linux_read_offsets (CORE_ADDR *text_p, CORE_ADDR *data_p) |
4833 { | 4703 { |
4834 #if defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) && defined(PT_TEXT_END_ADDR) | |
4835 unsigned long text, text_end, data; | 4704 unsigned long text, text_end, data; |
4836 int pid = lwpid_of (get_thread_lwp (current_inferior)); | 4705 int pid = lwpid_of (get_thread_lwp (current_inferior)); |
4837 | 4706 |
4838 errno = 0; | 4707 errno = 0; |
4839 | 4708 |
4840 text = ptrace (PTRACE_PEEKUSER, pid, (long)PT_TEXT_ADDR, 0); | 4709 text = ptrace (PTRACE_PEEKUSER, pid, (PTRACE_TYPE_ARG3) PT_TEXT_ADDR, |
4841 text_end = ptrace (PTRACE_PEEKUSER, pid, (long)PT_TEXT_END_ADDR, 0); | 4710 » » (PTRACE_TYPE_ARG4) 0); |
4842 data = ptrace (PTRACE_PEEKUSER, pid, (long)PT_DATA_ADDR, 0); | 4711 text_end = ptrace (PTRACE_PEEKUSER, pid, (PTRACE_TYPE_ARG3) PT_TEXT_END_ADDR, |
| 4712 » » (PTRACE_TYPE_ARG4) 0); |
| 4713 data = ptrace (PTRACE_PEEKUSER, pid, (PTRACE_TYPE_ARG3) PT_DATA_ADDR, |
| 4714 » » (PTRACE_TYPE_ARG4) 0); |
4843 | 4715 |
4844 if (errno == 0) | 4716 if (errno == 0) |
4845 { | 4717 { |
4846 /* Both text and data offsets produced at compile-time (and so | 4718 /* Both text and data offsets produced at compile-time (and so |
4847 used by gdb) are relative to the beginning of the program, | 4719 used by gdb) are relative to the beginning of the program, |
4848 with the data segment immediately following the text segment. | 4720 with the data segment immediately following the text segment. |
4849 However, the actual runtime layout in memory may put the data | 4721 However, the actual runtime layout in memory may put the data |
4850 somewhere else, so when we send gdb a data base-address, we | 4722 somewhere else, so when we send gdb a data base-address, we |
4851 use the real data base address and subtract the compile-time | 4723 use the real data base address and subtract the compile-time |
4852 data base-address from it (which is just the length of the | 4724 data base-address from it (which is just the length of the |
4853 text segment). BSS immediately follows data in both | 4725 text segment). BSS immediately follows data in both |
4854 cases. */ | 4726 cases. */ |
4855 *text_p = text; | 4727 *text_p = text; |
4856 *data_p = data - (text_end - text); | 4728 *data_p = data - (text_end - text); |
4857 | 4729 |
4858 return 1; | 4730 return 1; |
4859 } | 4731 } |
4860 #endif | |
4861 return 0; | 4732 return 0; |
4862 } | 4733 } |
4863 #endif | 4734 #endif |
4864 | 4735 |
4865 static int | 4736 static int |
4866 linux_qxfer_osdata (const char *annex, | 4737 linux_qxfer_osdata (const char *annex, |
4867 unsigned char *readbuf, unsigned const char *writebuf, | 4738 unsigned char *readbuf, unsigned const char *writebuf, |
4868 CORE_ADDR offset, int len) | 4739 CORE_ADDR offset, int len) |
4869 { | 4740 { |
4870 return linux_common_xfer_osdata (annex, readbuf, offset, len); | 4741 return linux_common_xfer_osdata (annex, readbuf, offset, len); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4906 pid = lwpid_of (get_thread_lwp (current_inferior)); | 4777 pid = lwpid_of (get_thread_lwp (current_inferior)); |
4907 | 4778 |
4908 if (debug_threads) | 4779 if (debug_threads) |
4909 fprintf (stderr, "%s siginfo for lwp %d.\n", | 4780 fprintf (stderr, "%s siginfo for lwp %d.\n", |
4910 readbuf != NULL ? "Reading" : "Writing", | 4781 readbuf != NULL ? "Reading" : "Writing", |
4911 pid); | 4782 pid); |
4912 | 4783 |
4913 if (offset >= sizeof (siginfo)) | 4784 if (offset >= sizeof (siginfo)) |
4914 return -1; | 4785 return -1; |
4915 | 4786 |
4916 if (ptrace (PTRACE_GETSIGINFO, pid, 0, &siginfo) != 0) | 4787 if (ptrace (PTRACE_GETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo) != 0) |
4917 return -1; | 4788 return -1; |
4918 | 4789 |
4919 /* When GDBSERVER is built as a 64-bit application, ptrace writes into | 4790 /* When GDBSERVER is built as a 64-bit application, ptrace writes into |
4920 SIGINFO an object with 64-bit layout. Since debugging a 32-bit | 4791 SIGINFO an object with 64-bit layout. Since debugging a 32-bit |
4921 inferior with a 64-bit GDBSERVER should look the same as debugging it | 4792 inferior with a 64-bit GDBSERVER should look the same as debugging it |
4922 with a 32-bit GDBSERVER, we need to convert it. */ | 4793 with a 32-bit GDBSERVER, we need to convert it. */ |
4923 siginfo_fixup (&siginfo, inf_siginfo, 0); | 4794 siginfo_fixup (&siginfo, inf_siginfo, 0); |
4924 | 4795 |
4925 if (offset + len > sizeof (siginfo)) | 4796 if (offset + len > sizeof (siginfo)) |
4926 len = sizeof (siginfo) - offset; | 4797 len = sizeof (siginfo) - offset; |
4927 | 4798 |
4928 if (readbuf != NULL) | 4799 if (readbuf != NULL) |
4929 memcpy (readbuf, inf_siginfo + offset, len); | 4800 memcpy (readbuf, inf_siginfo + offset, len); |
4930 else | 4801 else |
4931 { | 4802 { |
4932 memcpy (inf_siginfo + offset, writebuf, len); | 4803 memcpy (inf_siginfo + offset, writebuf, len); |
4933 | 4804 |
4934 /* Convert back to ptrace layout before flushing it out. */ | 4805 /* Convert back to ptrace layout before flushing it out. */ |
4935 siginfo_fixup (&siginfo, inf_siginfo, 1); | 4806 siginfo_fixup (&siginfo, inf_siginfo, 1); |
4936 | 4807 |
4937 if (ptrace (PTRACE_SETSIGINFO, pid, 0, &siginfo) != 0) | 4808 if (ptrace (PTRACE_SETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo) != 0) |
4938 return -1; | 4809 return -1; |
4939 } | 4810 } |
4940 | 4811 |
4941 return len; | 4812 return len; |
4942 } | 4813 } |
4943 | 4814 |
4944 /* SIGCHLD handler that serves two purposes: In non-stop/async mode, | 4815 /* SIGCHLD handler that serves two purposes: In non-stop/async mode, |
4945 so we notice when children change state; as the handler for the | 4816 so we notice when children change state; as the handler for the |
4946 sigsuspend in my_waitpid. */ | 4817 sigsuspend in my_waitpid. */ |
4947 | 4818 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5045 return 0; | 4916 return 0; |
5046 #endif | 4917 #endif |
5047 } | 4918 } |
5048 | 4919 |
5049 static int | 4920 static int |
5050 linux_supports_agent (void) | 4921 linux_supports_agent (void) |
5051 { | 4922 { |
5052 return 1; | 4923 return 1; |
5053 } | 4924 } |
5054 | 4925 |
| 4926 static int |
| 4927 linux_supports_range_stepping (void) |
| 4928 { |
| 4929 if (*the_low_target.supports_range_stepping == NULL) |
| 4930 return 0; |
| 4931 |
| 4932 return (*the_low_target.supports_range_stepping) (); |
| 4933 } |
| 4934 |
5055 /* Enumerate spufs IDs for process PID. */ | 4935 /* Enumerate spufs IDs for process PID. */ |
5056 static int | 4936 static int |
5057 spu_enumerate_spu_ids (long pid, unsigned char *buf, CORE_ADDR offset, int len) | 4937 spu_enumerate_spu_ids (long pid, unsigned char *buf, CORE_ADDR offset, int len) |
5058 { | 4938 { |
5059 int pos = 0; | 4939 int pos = 0; |
5060 int written = 0; | 4940 int written = 0; |
5061 char path[128]; | 4941 char path[128]; |
5062 DIR *dir; | 4942 DIR *dir; |
5063 struct dirent *entry; | 4943 struct dirent *entry; |
5064 | 4944 |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5639 0, /* r_version offset. */ | 5519 0, /* r_version offset. */ |
5640 8, /* r_debug.r_map offset. */ | 5520 8, /* r_debug.r_map offset. */ |
5641 0, /* l_addr offset in link_map. */ | 5521 0, /* l_addr offset in link_map. */ |
5642 8, /* l_name offset in link_map. */ | 5522 8, /* l_name offset in link_map. */ |
5643 16, /* l_ld offset in link_map. */ | 5523 16, /* l_ld offset in link_map. */ |
5644 24, /* l_next offset in link_map. */ | 5524 24, /* l_next offset in link_map. */ |
5645 32 /* l_prev offset in link_map. */ | 5525 32 /* l_prev offset in link_map. */ |
5646 }; | 5526 }; |
5647 const struct link_map_offsets *lmo; | 5527 const struct link_map_offsets *lmo; |
5648 unsigned int machine; | 5528 unsigned int machine; |
| 5529 int ptr_size; |
| 5530 CORE_ADDR lm_addr = 0, lm_prev = 0; |
| 5531 int allocated = 1024; |
| 5532 char *p; |
| 5533 CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev; |
| 5534 int header_done = 0; |
5649 | 5535 |
5650 if (writebuf != NULL) | 5536 if (writebuf != NULL) |
5651 return -2; | 5537 return -2; |
5652 if (readbuf == NULL) | 5538 if (readbuf == NULL) |
5653 return -1; | 5539 return -1; |
5654 | 5540 |
5655 pid = lwpid_of (get_thread_lwp (current_inferior)); | 5541 pid = lwpid_of (get_thread_lwp (current_inferior)); |
5656 xsnprintf (filename, sizeof filename, "/proc/%d/exe", pid); | 5542 xsnprintf (filename, sizeof filename, "/proc/%d/exe", pid); |
5657 is_elf64 = elf_64_file_p (filename, &machine); | 5543 is_elf64 = elf_64_file_p (filename, &machine); |
5658 lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets; | 5544 lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets; |
| 5545 ptr_size = is_elf64 ? 8 : 4; |
5659 | 5546 |
5660 if (priv->r_debug == 0) | 5547 while (annex[0] != '\0') |
5661 priv->r_debug = get_r_debug (pid, is_elf64); | 5548 { |
| 5549 const char *sep; |
| 5550 CORE_ADDR *addrp; |
| 5551 int len; |
5662 | 5552 |
5663 /* We failed to find DT_DEBUG. Such situation will not change for this | 5553 sep = strchr (annex, '='); |
5664 inferior - do not retry it. Report it to GDB as E01, see for the reasons | 5554 if (sep == NULL) |
5665 at the GDB solib-svr4.c side. */ | 5555 » break; |
5666 if (priv->r_debug == (CORE_ADDR) -1) | |
5667 return -1; | |
5668 | 5556 |
5669 if (priv->r_debug == 0) | 5557 len = sep - annex; |
5670 { | 5558 if (len == 5 && strncmp (annex, "start", 5) == 0) |
5671 document = xstrdup ("<library-list-svr4 version=\"1.0\"/>\n"); | 5559 » addrp = &lm_addr; |
5672 } | 5560 else if (len == 4 && strncmp (annex, "prev", 4) == 0) |
5673 else | 5561 » addrp = &lm_prev; |
5674 { | 5562 else |
5675 int allocated = 1024; | |
5676 char *p; | |
5677 const int ptr_size = is_elf64 ? 8 : 4; | |
5678 CORE_ADDR lm_addr, lm_prev, l_name, l_addr, l_ld, l_next, l_prev; | |
5679 int r_version, header_done = 0; | |
5680 | |
5681 document = xmalloc (allocated); | |
5682 strcpy (document, "<library-list-svr4 version=\"1.0\""); | |
5683 p = document + strlen (document); | |
5684 | |
5685 r_version = 0; | |
5686 if (linux_read_memory (priv->r_debug + lmo->r_version_offset, | |
5687 » » » (unsigned char *) &r_version, | |
5688 » » » sizeof (r_version)) != 0 | |
5689 » || r_version != 1) | |
5690 { | 5563 { |
5691 » warning ("unexpected r_debug version %d", r_version); | 5564 » annex = strchr (sep, ';'); |
5692 » goto done; | 5565 » if (annex == NULL) |
| 5566 » break; |
| 5567 » annex++; |
| 5568 » continue; |
5693 } | 5569 } |
5694 | 5570 |
5695 if (read_one_ptr (priv->r_debug + lmo->r_map_offset, | 5571 annex = decode_address_to_semicolon (addrp, sep + 1); |
5696 » » » &lm_addr, ptr_size) != 0) | 5572 } |
| 5573 |
| 5574 if (lm_addr == 0) |
| 5575 { |
| 5576 int r_version = 0; |
| 5577 |
| 5578 if (priv->r_debug == 0) |
| 5579 » priv->r_debug = get_r_debug (pid, is_elf64); |
| 5580 |
| 5581 /* We failed to find DT_DEBUG. Such situation will not change |
| 5582 » for this inferior - do not retry it. Report it to GDB as |
| 5583 » E01, see for the reasons at the GDB solib-svr4.c side. */ |
| 5584 if (priv->r_debug == (CORE_ADDR) -1) |
| 5585 » return -1; |
| 5586 |
| 5587 if (priv->r_debug != 0) |
5697 { | 5588 { |
5698 » warning ("unable to read r_map from 0x%lx", | 5589 » if (linux_read_memory (priv->r_debug + lmo->r_version_offset, |
5699 » » (long) priv->r_debug + lmo->r_map_offset); | 5590 » » » » (unsigned char *) &r_version, |
5700 » goto done; | 5591 » » » » sizeof (r_version)) != 0 |
| 5592 » || r_version != 1) |
| 5593 » { |
| 5594 » warning ("unexpected r_debug version %d", r_version); |
| 5595 » } |
| 5596 » else if (read_one_ptr (priv->r_debug + lmo->r_map_offset, |
| 5597 » » » » &lm_addr, ptr_size) != 0) |
| 5598 » { |
| 5599 » warning ("unable to read r_map from 0x%lx", |
| 5600 » » (long) priv->r_debug + lmo->r_map_offset); |
| 5601 » } |
| 5602 » } |
| 5603 } |
| 5604 |
| 5605 document = xmalloc (allocated); |
| 5606 strcpy (document, "<library-list-svr4 version=\"1.0\""); |
| 5607 p = document + strlen (document); |
| 5608 |
| 5609 while (lm_addr |
| 5610 » && read_one_ptr (lm_addr + lmo->l_name_offset, |
| 5611 » » » &l_name, ptr_size) == 0 |
| 5612 » && read_one_ptr (lm_addr + lmo->l_addr_offset, |
| 5613 » » » &l_addr, ptr_size) == 0 |
| 5614 » && read_one_ptr (lm_addr + lmo->l_ld_offset, |
| 5615 » » » &l_ld, ptr_size) == 0 |
| 5616 » && read_one_ptr (lm_addr + lmo->l_prev_offset, |
| 5617 » » » &l_prev, ptr_size) == 0 |
| 5618 » && read_one_ptr (lm_addr + lmo->l_next_offset, |
| 5619 » » » &l_next, ptr_size) == 0) |
| 5620 { |
| 5621 unsigned char libname[PATH_MAX]; |
| 5622 |
| 5623 if (lm_prev != l_prev) |
| 5624 » { |
| 5625 » warning ("Corrupted shared library list: 0x%lx != 0x%lx", |
| 5626 » » (long) lm_prev, (long) l_prev); |
| 5627 » break; |
5701 } | 5628 } |
5702 | 5629 |
5703 lm_prev = 0; | 5630 /* Ignore the first entry even if it has valid name as the first entry |
5704 while (read_one_ptr (lm_addr + lmo->l_name_offset, | 5631 » corresponds to the main executable. The first entry should not be |
5705 » » » &l_name, ptr_size) == 0 | 5632 » skipped if the dynamic loader was loaded late by a static executable |
5706 » && read_one_ptr (lm_addr + lmo->l_addr_offset, | 5633 » (see solib-svr4.c parameter ignore_first). But in such case the main |
5707 » » » &l_addr, ptr_size) == 0 | 5634 » executable does not have PT_DYNAMIC present and this function already |
5708 » && read_one_ptr (lm_addr + lmo->l_ld_offset, | 5635 » exited above due to failed get_r_debug. */ |
5709 » » » &l_ld, ptr_size) == 0 | 5636 if (lm_prev == 0) |
5710 » && read_one_ptr (lm_addr + lmo->l_prev_offset, | |
5711 » » » &l_prev, ptr_size) == 0 | |
5712 » && read_one_ptr (lm_addr + lmo->l_next_offset, | |
5713 » » » &l_next, ptr_size) == 0) | |
5714 { | 5637 { |
5715 » unsigned char libname[PATH_MAX]; | 5638 » sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); |
5716 | 5639 » p = p + strlen (p); |
5717 » if (lm_prev != l_prev) | 5640 » } |
5718 » { | 5641 else |
5719 » warning ("Corrupted shared library list: 0x%lx != 0x%lx", | 5642 » { |
5720 » » (long) lm_prev, (long) l_prev); | |
5721 » break; | |
5722 » } | |
5723 | |
5724 /* Not checking for error because reading may stop before | 5643 /* Not checking for error because reading may stop before |
5725 we've got PATH_MAX worth of characters. */ | 5644 we've got PATH_MAX worth of characters. */ |
5726 libname[0] = '\0'; | 5645 libname[0] = '\0'; |
5727 linux_read_memory (l_name, libname, sizeof (libname) - 1); | 5646 linux_read_memory (l_name, libname, sizeof (libname) - 1); |
5728 libname[sizeof (libname) - 1] = '\0'; | 5647 libname[sizeof (libname) - 1] = '\0'; |
5729 if (libname[0] != '\0') | 5648 if (libname[0] != '\0') |
5730 { | 5649 { |
5731 /* 6x the size for xml_escape_text below. */ | 5650 /* 6x the size for xml_escape_text below. */ |
5732 size_t len = 6 * strlen ((char *) libname); | 5651 size_t len = 6 * strlen ((char *) libname); |
5733 char *name; | 5652 char *name; |
(...skipping 10 matching lines...) Expand all Loading... |
5744 /* Expand to guarantee sufficient storage. */ | 5663 /* Expand to guarantee sufficient storage. */ |
5745 uintptr_t document_len = p - document; | 5664 uintptr_t document_len = p - document; |
5746 | 5665 |
5747 document = xrealloc (document, 2 * allocated); | 5666 document = xrealloc (document, 2 * allocated); |
5748 allocated *= 2; | 5667 allocated *= 2; |
5749 p = document + document_len; | 5668 p = document + document_len; |
5750 } | 5669 } |
5751 | 5670 |
5752 name = xml_escape_text ((char *) libname); | 5671 name = xml_escape_text ((char *) libname); |
5753 p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" " | 5672 p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" " |
5754 » » » "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>", | 5673 » » » "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>", |
5755 name, (unsigned long) lm_addr, | 5674 name, (unsigned long) lm_addr, |
5756 (unsigned long) l_addr, (unsigned long) l_ld); | 5675 (unsigned long) l_addr, (unsigned long) l_ld); |
5757 free (name); | 5676 free (name); |
5758 } | 5677 } |
5759 » else if (lm_prev == 0) | 5678 » } |
5760 » { | |
5761 » sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); | |
5762 » p = p + strlen (p); | |
5763 » } | |
5764 | 5679 |
5765 » if (l_next == 0) | 5680 lm_prev = lm_addr; |
5766 » break; | 5681 lm_addr = l_next; |
| 5682 } |
5767 | 5683 |
5768 » lm_prev = lm_addr; | 5684 if (!header_done) |
5769 » lm_addr = l_next; | 5685 { |
5770 » } | 5686 /* Empty list; terminate `<library-list-svr4'. */ |
5771 done: | 5687 strcpy (p, "/>"); |
5772 if (!header_done) | |
5773 » { | |
5774 » /* Empty list; terminate `<library-list-svr4'. */ | |
5775 » strcpy (p, "/>"); | |
5776 » } | |
5777 else | |
5778 » strcpy (p, "</library-list-svr4>"); | |
5779 } | 5688 } |
| 5689 else |
| 5690 strcpy (p, "</library-list-svr4>"); |
5780 | 5691 |
5781 document_len = strlen (document); | 5692 document_len = strlen (document); |
5782 if (offset < document_len) | 5693 if (offset < document_len) |
5783 document_len -= offset; | 5694 document_len -= offset; |
5784 else | 5695 else |
5785 document_len = 0; | 5696 document_len = 0; |
5786 if (len > document_len) | 5697 if (len > document_len) |
5787 len = document_len; | 5698 len = document_len; |
5788 | 5699 |
5789 memcpy (readbuf, document + offset, len); | 5700 memcpy (readbuf, document + offset, len); |
5790 xfree (document); | 5701 xfree (document); |
5791 | 5702 |
5792 return len; | 5703 return len; |
5793 } | 5704 } |
5794 | 5705 |
| 5706 #ifdef HAVE_LINUX_BTRACE |
| 5707 |
| 5708 /* Enable branch tracing. */ |
| 5709 |
| 5710 static struct btrace_target_info * |
| 5711 linux_low_enable_btrace (ptid_t ptid) |
| 5712 { |
| 5713 struct btrace_target_info *tinfo; |
| 5714 |
| 5715 tinfo = linux_enable_btrace (ptid); |
| 5716 |
| 5717 if (tinfo != NULL) |
| 5718 { |
| 5719 struct thread_info *thread = find_thread_ptid (ptid); |
| 5720 struct regcache *regcache = get_thread_regcache (thread, 0); |
| 5721 |
| 5722 tinfo->ptr_bits = register_size (regcache->tdesc, 0) * 8; |
| 5723 } |
| 5724 |
| 5725 return tinfo; |
| 5726 } |
| 5727 |
| 5728 /* Read branch trace data as btrace xml document. */ |
| 5729 |
| 5730 static void |
| 5731 linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer, |
| 5732 int type) |
| 5733 { |
| 5734 VEC (btrace_block_s) *btrace; |
| 5735 struct btrace_block *block; |
| 5736 int i; |
| 5737 |
| 5738 btrace = linux_read_btrace (tinfo, type); |
| 5739 |
| 5740 buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n"); |
| 5741 buffer_grow_str (buffer, "<btrace version=\"1.0\">\n"); |
| 5742 |
| 5743 for (i = 0; VEC_iterate (btrace_block_s, btrace, i, block); i++) |
| 5744 buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n", |
| 5745 paddress (block->begin), paddress (block->end)); |
| 5746 |
| 5747 buffer_grow_str (buffer, "</btrace>\n"); |
| 5748 |
| 5749 VEC_free (btrace_block_s, btrace); |
| 5750 } |
| 5751 #endif /* HAVE_LINUX_BTRACE */ |
| 5752 |
5795 static struct target_ops linux_target_ops = { | 5753 static struct target_ops linux_target_ops = { |
5796 linux_create_inferior, | 5754 linux_create_inferior, |
5797 linux_attach, | 5755 linux_attach, |
5798 linux_kill, | 5756 linux_kill, |
5799 linux_detach, | 5757 linux_detach, |
5800 linux_mourn, | 5758 linux_mourn, |
5801 linux_join, | 5759 linux_join, |
5802 linux_thread_alive, | 5760 linux_thread_alive, |
5803 linux_resume, | 5761 linux_resume, |
5804 linux_wait, | 5762 linux_wait, |
5805 linux_fetch_registers, | 5763 linux_fetch_registers, |
5806 linux_store_registers, | 5764 linux_store_registers, |
5807 linux_prepare_to_access_memory, | 5765 linux_prepare_to_access_memory, |
5808 linux_done_accessing_memory, | 5766 linux_done_accessing_memory, |
5809 linux_read_memory, | 5767 linux_read_memory, |
5810 linux_write_memory, | 5768 linux_write_memory, |
5811 linux_look_up_symbols, | 5769 linux_look_up_symbols, |
5812 linux_request_interrupt, | 5770 linux_request_interrupt, |
5813 linux_read_auxv, | 5771 linux_read_auxv, |
5814 linux_insert_point, | 5772 linux_insert_point, |
5815 linux_remove_point, | 5773 linux_remove_point, |
5816 linux_stopped_by_watchpoint, | 5774 linux_stopped_by_watchpoint, |
5817 linux_stopped_data_address, | 5775 linux_stopped_data_address, |
5818 #if defined(__UCLIBC__) && defined(HAS_NOMMU) | 5776 #if defined(__UCLIBC__) && defined(HAS_NOMMU)» \ |
| 5777 && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \ |
| 5778 && defined(PT_TEXT_END_ADDR) |
5819 linux_read_offsets, | 5779 linux_read_offsets, |
5820 #else | 5780 #else |
5821 NULL, | 5781 NULL, |
5822 #endif | 5782 #endif |
5823 #ifdef USE_THREAD_DB | 5783 #ifdef USE_THREAD_DB |
5824 thread_db_get_tls_address, | 5784 thread_db_get_tls_address, |
5825 #else | 5785 #else |
5826 NULL, | 5786 NULL, |
5827 #endif | 5787 #endif |
5828 linux_qxfer_spu, | 5788 linux_qxfer_spu, |
(...skipping 20 matching lines...) Expand all Loading... |
5849 linux_pause_all, | 5809 linux_pause_all, |
5850 linux_unpause_all, | 5810 linux_unpause_all, |
5851 linux_cancel_breakpoints, | 5811 linux_cancel_breakpoints, |
5852 linux_stabilize_threads, | 5812 linux_stabilize_threads, |
5853 linux_install_fast_tracepoint_jump_pad, | 5813 linux_install_fast_tracepoint_jump_pad, |
5854 linux_emit_ops, | 5814 linux_emit_ops, |
5855 linux_supports_disable_randomization, | 5815 linux_supports_disable_randomization, |
5856 linux_get_min_fast_tracepoint_insn_len, | 5816 linux_get_min_fast_tracepoint_insn_len, |
5857 linux_qxfer_libraries_svr4, | 5817 linux_qxfer_libraries_svr4, |
5858 linux_supports_agent, | 5818 linux_supports_agent, |
| 5819 #ifdef HAVE_LINUX_BTRACE |
| 5820 linux_supports_btrace, |
| 5821 linux_low_enable_btrace, |
| 5822 linux_disable_btrace, |
| 5823 linux_low_read_btrace, |
| 5824 #else |
| 5825 NULL, |
| 5826 NULL, |
| 5827 NULL, |
| 5828 NULL, |
| 5829 #endif |
| 5830 linux_supports_range_stepping, |
5859 }; | 5831 }; |
5860 | 5832 |
5861 static void | 5833 static void |
5862 linux_init_signals () | 5834 linux_init_signals () |
5863 { | 5835 { |
5864 /* FIXME drow/2002-06-09: As above, we should check with LinuxThreads | 5836 /* FIXME drow/2002-06-09: As above, we should check with LinuxThreads |
5865 to find what the cancel signal actually is. */ | 5837 to find what the cancel signal actually is. */ |
5866 #ifndef __ANDROID__ /* Bionic doesn't use SIGRTMIN the way glibc does. */ | 5838 #ifndef __ANDROID__ /* Bionic doesn't use SIGRTMIN the way glibc does. */ |
5867 signal (__SIGRTMIN+1, SIG_IGN); | 5839 signal (__SIGRTMIN+1, SIG_IGN); |
5868 #endif | 5840 #endif |
5869 } | 5841 } |
5870 | 5842 |
| 5843 #ifdef HAVE_LINUX_REGSETS |
| 5844 void |
| 5845 initialize_regsets_info (struct regsets_info *info) |
| 5846 { |
| 5847 for (info->num_regsets = 0; |
| 5848 info->regsets[info->num_regsets].size >= 0; |
| 5849 info->num_regsets++) |
| 5850 ; |
| 5851 } |
| 5852 #endif |
| 5853 |
5871 void | 5854 void |
5872 initialize_low (void) | 5855 initialize_low (void) |
5873 { | 5856 { |
5874 struct sigaction sigchld_action; | 5857 struct sigaction sigchld_action; |
5875 memset (&sigchld_action, 0, sizeof (sigchld_action)); | 5858 memset (&sigchld_action, 0, sizeof (sigchld_action)); |
5876 set_target_ops (&linux_target_ops); | 5859 set_target_ops (&linux_target_ops); |
5877 set_breakpoint_data (the_low_target.breakpoint, | 5860 set_breakpoint_data (the_low_target.breakpoint, |
5878 the_low_target.breakpoint_len); | 5861 the_low_target.breakpoint_len); |
5879 linux_init_signals (); | 5862 linux_init_signals (); |
5880 linux_test_for_tracefork (); | |
5881 linux_ptrace_init_warnings (); | 5863 linux_ptrace_init_warnings (); |
5882 #ifdef HAVE_LINUX_REGSETS | |
5883 for (num_regsets = 0; target_regsets[num_regsets].size >= 0; num_regsets++) | |
5884 ; | |
5885 disabled_regsets = xmalloc (num_regsets); | |
5886 #endif | |
5887 | 5864 |
5888 sigchld_action.sa_handler = sigchld_handler; | 5865 sigchld_action.sa_handler = sigchld_handler; |
5889 sigemptyset (&sigchld_action.sa_mask); | 5866 sigemptyset (&sigchld_action.sa_mask); |
5890 sigchld_action.sa_flags = SA_RESTART; | 5867 sigchld_action.sa_flags = SA_RESTART; |
5891 sigaction (SIGCHLD, &sigchld_action, NULL); | 5868 sigaction (SIGCHLD, &sigchld_action, NULL); |
| 5869 |
| 5870 initialize_low_arch (); |
5892 } | 5871 } |
OLD | NEW |