1 /* Target-dependent code for GNU/Linux, architecture independent.
3 Copyright (C) 2009-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "linux-tdep.h"
25 #include "gdbthread.h"
29 #include "elf/common.h"
30 #include "elf-bfd.h" /* for elfcore_write_* */
32 #include "cli/cli-utils.h"
33 #include "arch-utils.h"
34 #include "gdb_obstack.h"
38 #include "nat/linux-maps.h"
43 /* Whether to take the /proc/PID/coredump_filter into account when
44 generating a corefile. */
46 static int use_coredump_filter
= 1;
48 /* This enum represents the signals' numbers on a generic architecture
49 running the Linux kernel. The definition of "generic" comes from
50 the file <include/uapi/asm-generic/signal.h>, from the Linux kernel
51 tree, which is the "de facto" implementation of signal numbers to
52 be used by new architecture ports.
54 For those architectures which have differences between the generic
55 standard (e.g., Alpha), we define the different signals (and *only*
56 those) in the specific target-dependent file (e.g.,
57 alpha-linux-tdep.c, for Alpha). Please refer to the architecture's
58 tdep file for more information.
60 ARM deserves a special mention here. On the file
61 <arch/arm/include/uapi/asm/signal.h>, it defines only one different
62 (and ARM-only) signal, which is SIGSWI, with the same number as
63 SIGRTMIN. This signal is used only for a very specific target,
64 called ArthurOS (from RISCOS). Therefore, we do not handle it on
65 the ARM-tdep file, and we can safely use the generic signal handler
68 As stated above, this enum is derived from
69 <include/uapi/asm-generic/signal.h>, from the Linux kernel
100 LINUX_SIGVTALRM
= 26,
104 LINUX_SIGPOLL
= LINUX_SIGIO
,
107 LINUX_SIGUNUSED
= 31,
113 static struct gdbarch_data
*linux_gdbarch_data_handle
;
115 struct linux_gdbarch_data
117 struct type
*siginfo_type
;
121 init_linux_gdbarch_data (struct gdbarch
*gdbarch
)
123 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct linux_gdbarch_data
);
126 static struct linux_gdbarch_data
*
127 get_linux_gdbarch_data (struct gdbarch
*gdbarch
)
129 return gdbarch_data (gdbarch
, linux_gdbarch_data_handle
);
132 /* Per-inferior data key. */
133 static const struct inferior_data
*linux_inferior_data
;
135 /* Linux-specific cached data. This is used by GDB for caching
136 purposes for each inferior. This helps reduce the overhead of
137 transfering data from a remote target to the local host. */
140 /* Cache of the inferior's vsyscall/vDSO mapping range. Only valid
141 if VSYSCALL_RANGE_P is positive. This is cached because getting
142 at this info requires an auxv lookup (which is itself cached),
143 and looking through the inferior's mappings (which change
144 throughout execution and therefore cannot be cached). */
145 struct mem_range vsyscall_range
;
147 /* Zero if we haven't tried looking up the vsyscall's range before
148 yet. Positive if we tried looking it up, and found it. Negative
149 if we tried looking it up but failed. */
150 int vsyscall_range_p
;
153 /* Frees whatever allocated space there is to be freed and sets INF's
154 linux cache data pointer to NULL. */
157 invalidate_linux_cache_inf (struct inferior
*inf
)
159 struct linux_info
*info
;
161 info
= inferior_data (inf
, linux_inferior_data
);
165 set_inferior_data (inf
, linux_inferior_data
, NULL
);
169 /* Handles the cleanup of the linux cache for inferior INF. ARG is
170 ignored. Callback for the inferior_appeared and inferior_exit
174 linux_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
176 invalidate_linux_cache_inf (inf
);
179 /* Fetch the linux cache info for INF. This function always returns a
180 valid INFO pointer. */
182 static struct linux_info
*
183 get_linux_inferior_data (void)
185 struct linux_info
*info
;
186 struct inferior
*inf
= current_inferior ();
188 info
= inferior_data (inf
, linux_inferior_data
);
191 info
= XCNEW (struct linux_info
);
192 set_inferior_data (inf
, linux_inferior_data
, info
);
198 /* This function is suitable for architectures that don't
199 extend/override the standard siginfo structure. */
202 linux_get_siginfo_type (struct gdbarch
*gdbarch
)
204 struct linux_gdbarch_data
*linux_gdbarch_data
;
205 struct type
*int_type
, *uint_type
, *long_type
, *void_ptr_type
;
206 struct type
*uid_type
, *pid_type
;
207 struct type
*sigval_type
, *clock_type
;
208 struct type
*siginfo_type
, *sifields_type
;
211 linux_gdbarch_data
= get_linux_gdbarch_data (gdbarch
);
212 if (linux_gdbarch_data
->siginfo_type
!= NULL
)
213 return linux_gdbarch_data
->siginfo_type
;
215 int_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
217 uint_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
219 long_type
= arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
221 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
224 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
225 TYPE_NAME (sigval_type
) = xstrdup ("sigval_t");
226 append_composite_type_field (sigval_type
, "sival_int", int_type
);
227 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
230 pid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
231 TYPE_LENGTH (int_type
), "__pid_t");
232 TYPE_TARGET_TYPE (pid_type
) = int_type
;
233 TYPE_TARGET_STUB (pid_type
) = 1;
236 uid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
237 TYPE_LENGTH (uint_type
), "__uid_t");
238 TYPE_TARGET_TYPE (uid_type
) = uint_type
;
239 TYPE_TARGET_STUB (uid_type
) = 1;
242 clock_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
243 TYPE_LENGTH (long_type
), "__clock_t");
244 TYPE_TARGET_TYPE (clock_type
) = long_type
;
245 TYPE_TARGET_STUB (clock_type
) = 1;
248 sifields_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
251 const int si_max_size
= 128;
253 int size_of_int
= gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
256 if (gdbarch_ptr_bit (gdbarch
) == 64)
257 si_pad_size
= (si_max_size
/ size_of_int
) - 4;
259 si_pad_size
= (si_max_size
/ size_of_int
) - 3;
260 append_composite_type_field (sifields_type
, "_pad",
261 init_vector_type (int_type
, si_pad_size
));
265 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
266 append_composite_type_field (type
, "si_pid", pid_type
);
267 append_composite_type_field (type
, "si_uid", uid_type
);
268 append_composite_type_field (sifields_type
, "_kill", type
);
271 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
272 append_composite_type_field (type
, "si_tid", int_type
);
273 append_composite_type_field (type
, "si_overrun", int_type
);
274 append_composite_type_field (type
, "si_sigval", sigval_type
);
275 append_composite_type_field (sifields_type
, "_timer", type
);
278 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
279 append_composite_type_field (type
, "si_pid", pid_type
);
280 append_composite_type_field (type
, "si_uid", uid_type
);
281 append_composite_type_field (type
, "si_sigval", sigval_type
);
282 append_composite_type_field (sifields_type
, "_rt", type
);
285 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
286 append_composite_type_field (type
, "si_pid", pid_type
);
287 append_composite_type_field (type
, "si_uid", uid_type
);
288 append_composite_type_field (type
, "si_status", int_type
);
289 append_composite_type_field (type
, "si_utime", clock_type
);
290 append_composite_type_field (type
, "si_stime", clock_type
);
291 append_composite_type_field (sifields_type
, "_sigchld", type
);
294 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
295 append_composite_type_field (type
, "si_addr", void_ptr_type
);
296 append_composite_type_field (sifields_type
, "_sigfault", type
);
299 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
300 append_composite_type_field (type
, "si_band", long_type
);
301 append_composite_type_field (type
, "si_fd", int_type
);
302 append_composite_type_field (sifields_type
, "_sigpoll", type
);
305 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
306 TYPE_NAME (siginfo_type
) = xstrdup ("siginfo");
307 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
308 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
309 append_composite_type_field (siginfo_type
, "si_code", int_type
);
310 append_composite_type_field_aligned (siginfo_type
,
311 "_sifields", sifields_type
,
312 TYPE_LENGTH (long_type
));
314 linux_gdbarch_data
->siginfo_type
= siginfo_type
;
319 /* Return true if the target is running on uClinux instead of normal
323 linux_is_uclinux (void)
327 return (target_auxv_search (¤t_target
, AT_NULL
, &dummy
) > 0
328 && target_auxv_search (¤t_target
, AT_PAGESZ
, &dummy
) == 0);
332 linux_has_shared_address_space (struct gdbarch
*gdbarch
)
334 return linux_is_uclinux ();
337 /* This is how we want PTIDs from core files to be printed. */
340 linux_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
344 if (ptid_get_lwp (ptid
) != 0)
346 snprintf (buf
, sizeof (buf
), "LWP %ld", ptid_get_lwp (ptid
));
350 return normal_pid_to_str (ptid
);
353 /* Implement the "info proc" command. */
356 linux_info_proc (struct gdbarch
*gdbarch
, const char *args
,
357 enum info_proc_what what
)
359 /* A long is used for pid instead of an int to avoid a loss of precision
360 compiler warning from the output of strtoul. */
362 int cmdline_f
= (what
== IP_MINIMAL
|| what
== IP_CMDLINE
|| what
== IP_ALL
);
363 int cwd_f
= (what
== IP_MINIMAL
|| what
== IP_CWD
|| what
== IP_ALL
);
364 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
365 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
366 int status_f
= (what
== IP_STATUS
|| what
== IP_ALL
);
367 int stat_f
= (what
== IP_STAT
|| what
== IP_ALL
);
372 if (args
&& isdigit (args
[0]))
376 pid
= strtoul (args
, &tem
, 10);
381 if (!target_has_execution
)
382 error (_("No current process: you must name one."));
383 if (current_inferior ()->fake_pid_p
)
384 error (_("Can't determine the current process's PID: you must name one."));
386 pid
= current_inferior ()->pid
;
389 args
= skip_spaces_const (args
);
391 error (_("Too many parameters: %s"), args
);
393 printf_filtered (_("process %ld\n"), pid
);
396 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cmdline", pid
);
397 data
= target_fileio_read_stralloc (NULL
, filename
);
400 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
401 printf_filtered ("cmdline = '%s'\n", data
);
402 do_cleanups (cleanup
);
405 warning (_("unable to open /proc file '%s'"), filename
);
409 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cwd", pid
);
410 data
= target_fileio_readlink (NULL
, filename
, &target_errno
);
413 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
414 printf_filtered ("cwd = '%s'\n", data
);
415 do_cleanups (cleanup
);
418 warning (_("unable to read link '%s'"), filename
);
422 xsnprintf (filename
, sizeof filename
, "/proc/%ld/exe", pid
);
423 data
= target_fileio_readlink (NULL
, filename
, &target_errno
);
426 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
427 printf_filtered ("exe = '%s'\n", data
);
428 do_cleanups (cleanup
);
431 warning (_("unable to read link '%s'"), filename
);
435 xsnprintf (filename
, sizeof filename
, "/proc/%ld/maps", pid
);
436 data
= target_fileio_read_stralloc (NULL
, filename
);
439 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
442 printf_filtered (_("Mapped address spaces:\n\n"));
443 if (gdbarch_addr_bit (gdbarch
) == 32)
445 printf_filtered ("\t%10s %10s %10s %10s %s\n",
448 " Size", " Offset", "objfile");
452 printf_filtered (" %18s %18s %10s %10s %s\n",
455 " Size", " Offset", "objfile");
458 for (line
= strtok (data
, "\n"); line
; line
= strtok (NULL
, "\n"))
460 ULONGEST addr
, endaddr
, offset
, inode
;
461 const char *permissions
, *device
, *filename
;
462 size_t permissions_len
, device_len
;
464 read_mapping (line
, &addr
, &endaddr
,
465 &permissions
, &permissions_len
,
466 &offset
, &device
, &device_len
,
469 if (gdbarch_addr_bit (gdbarch
) == 32)
471 printf_filtered ("\t%10s %10s %10s %10s %s\n",
472 paddress (gdbarch
, addr
),
473 paddress (gdbarch
, endaddr
),
474 hex_string (endaddr
- addr
),
476 *filename
? filename
: "");
480 printf_filtered (" %18s %18s %10s %10s %s\n",
481 paddress (gdbarch
, addr
),
482 paddress (gdbarch
, endaddr
),
483 hex_string (endaddr
- addr
),
485 *filename
? filename
: "");
489 do_cleanups (cleanup
);
492 warning (_("unable to open /proc file '%s'"), filename
);
496 xsnprintf (filename
, sizeof filename
, "/proc/%ld/status", pid
);
497 data
= target_fileio_read_stralloc (NULL
, filename
);
500 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
501 puts_filtered (data
);
502 do_cleanups (cleanup
);
505 warning (_("unable to open /proc file '%s'"), filename
);
509 xsnprintf (filename
, sizeof filename
, "/proc/%ld/stat", pid
);
510 data
= target_fileio_read_stralloc (NULL
, filename
);
513 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
514 const char *p
= data
;
516 printf_filtered (_("Process: %s\n"),
517 pulongest (strtoulst (p
, &p
, 10)));
519 p
= skip_spaces_const (p
);
522 /* ps command also relies on no trailing fields
524 const char *ep
= strrchr (p
, ')');
527 printf_filtered ("Exec file: %.*s\n",
528 (int) (ep
- p
- 1), p
+ 1);
533 p
= skip_spaces_const (p
);
535 printf_filtered (_("State: %c\n"), *p
++);
538 printf_filtered (_("Parent process: %s\n"),
539 pulongest (strtoulst (p
, &p
, 10)));
541 printf_filtered (_("Process group: %s\n"),
542 pulongest (strtoulst (p
, &p
, 10)));
544 printf_filtered (_("Session id: %s\n"),
545 pulongest (strtoulst (p
, &p
, 10)));
547 printf_filtered (_("TTY: %s\n"),
548 pulongest (strtoulst (p
, &p
, 10)));
550 printf_filtered (_("TTY owner process group: %s\n"),
551 pulongest (strtoulst (p
, &p
, 10)));
554 printf_filtered (_("Flags: %s\n"),
555 hex_string (strtoulst (p
, &p
, 10)));
557 printf_filtered (_("Minor faults (no memory page): %s\n"),
558 pulongest (strtoulst (p
, &p
, 10)));
560 printf_filtered (_("Minor faults, children: %s\n"),
561 pulongest (strtoulst (p
, &p
, 10)));
563 printf_filtered (_("Major faults (memory page faults): %s\n"),
564 pulongest (strtoulst (p
, &p
, 10)));
566 printf_filtered (_("Major faults, children: %s\n"),
567 pulongest (strtoulst (p
, &p
, 10)));
569 printf_filtered (_("utime: %s\n"),
570 pulongest (strtoulst (p
, &p
, 10)));
572 printf_filtered (_("stime: %s\n"),
573 pulongest (strtoulst (p
, &p
, 10)));
575 printf_filtered (_("utime, children: %s\n"),
576 pulongest (strtoulst (p
, &p
, 10)));
578 printf_filtered (_("stime, children: %s\n"),
579 pulongest (strtoulst (p
, &p
, 10)));
581 printf_filtered (_("jiffies remaining in current "
583 pulongest (strtoulst (p
, &p
, 10)));
585 printf_filtered (_("'nice' value: %s\n"),
586 pulongest (strtoulst (p
, &p
, 10)));
588 printf_filtered (_("jiffies until next timeout: %s\n"),
589 pulongest (strtoulst (p
, &p
, 10)));
591 printf_filtered (_("jiffies until next SIGALRM: %s\n"),
592 pulongest (strtoulst (p
, &p
, 10)));
594 printf_filtered (_("start time (jiffies since "
595 "system boot): %s\n"),
596 pulongest (strtoulst (p
, &p
, 10)));
598 printf_filtered (_("Virtual memory size: %s\n"),
599 pulongest (strtoulst (p
, &p
, 10)));
601 printf_filtered (_("Resident set size: %s\n"),
602 pulongest (strtoulst (p
, &p
, 10)));
604 printf_filtered (_("rlim: %s\n"),
605 pulongest (strtoulst (p
, &p
, 10)));
607 printf_filtered (_("Start of text: %s\n"),
608 hex_string (strtoulst (p
, &p
, 10)));
610 printf_filtered (_("End of text: %s\n"),
611 hex_string (strtoulst (p
, &p
, 10)));
613 printf_filtered (_("Start of stack: %s\n"),
614 hex_string (strtoulst (p
, &p
, 10)));
615 #if 0 /* Don't know how architecture-dependent the rest is...
616 Anyway the signal bitmap info is available from "status". */
618 printf_filtered (_("Kernel stack pointer: %s\n"),
619 hex_string (strtoulst (p
, &p
, 10)));
621 printf_filtered (_("Kernel instr pointer: %s\n"),
622 hex_string (strtoulst (p
, &p
, 10)));
624 printf_filtered (_("Pending signals bitmap: %s\n"),
625 hex_string (strtoulst (p
, &p
, 10)));
627 printf_filtered (_("Blocked signals bitmap: %s\n"),
628 hex_string (strtoulst (p
, &p
, 10)));
630 printf_filtered (_("Ignored signals bitmap: %s\n"),
631 hex_string (strtoulst (p
, &p
, 10)));
633 printf_filtered (_("Catched signals bitmap: %s\n"),
634 hex_string (strtoulst (p
, &p
, 10)));
636 printf_filtered (_("wchan (system call): %s\n"),
637 hex_string (strtoulst (p
, &p
, 10)));
639 do_cleanups (cleanup
);
642 warning (_("unable to open /proc file '%s'"), filename
);
646 /* Implement "info proc mappings" for a corefile. */
649 linux_core_info_proc_mappings (struct gdbarch
*gdbarch
, const char *args
)
652 ULONGEST count
, page_size
;
653 unsigned char *descdata
, *filenames
, *descend
, *contents
;
655 unsigned int addr_size_bits
, addr_size
;
656 struct cleanup
*cleanup
;
657 struct gdbarch
*core_gdbarch
= gdbarch_from_bfd (core_bfd
);
658 /* We assume this for reading 64-bit core files. */
659 gdb_static_assert (sizeof (ULONGEST
) >= 8);
661 section
= bfd_get_section_by_name (core_bfd
, ".note.linuxcore.file");
664 warning (_("unable to find mappings in core file"));
668 addr_size_bits
= gdbarch_addr_bit (core_gdbarch
);
669 addr_size
= addr_size_bits
/ 8;
670 note_size
= bfd_get_section_size (section
);
672 if (note_size
< 2 * addr_size
)
673 error (_("malformed core note - too short for header"));
675 contents
= xmalloc (note_size
);
676 cleanup
= make_cleanup (xfree
, contents
);
677 if (!bfd_get_section_contents (core_bfd
, section
, contents
, 0, note_size
))
678 error (_("could not get core note contents"));
681 descend
= descdata
+ note_size
;
683 if (descdata
[note_size
- 1] != '\0')
684 error (_("malformed note - does not end with \\0"));
686 count
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
687 descdata
+= addr_size
;
689 page_size
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
690 descdata
+= addr_size
;
692 if (note_size
< 2 * addr_size
+ count
* 3 * addr_size
)
693 error (_("malformed note - too short for supplied file count"));
695 printf_filtered (_("Mapped address spaces:\n\n"));
696 if (gdbarch_addr_bit (gdbarch
) == 32)
698 printf_filtered ("\t%10s %10s %10s %10s %s\n",
701 " Size", " Offset", "objfile");
705 printf_filtered (" %18s %18s %10s %10s %s\n",
708 " Size", " Offset", "objfile");
711 filenames
= descdata
+ count
* 3 * addr_size
;
714 ULONGEST start
, end
, file_ofs
;
716 if (filenames
== descend
)
717 error (_("malformed note - filenames end too early"));
719 start
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
720 descdata
+= addr_size
;
721 end
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
722 descdata
+= addr_size
;
723 file_ofs
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
724 descdata
+= addr_size
;
726 file_ofs
*= page_size
;
728 if (gdbarch_addr_bit (gdbarch
) == 32)
729 printf_filtered ("\t%10s %10s %10s %10s %s\n",
730 paddress (gdbarch
, start
),
731 paddress (gdbarch
, end
),
732 hex_string (end
- start
),
733 hex_string (file_ofs
),
736 printf_filtered (" %18s %18s %10s %10s %s\n",
737 paddress (gdbarch
, start
),
738 paddress (gdbarch
, end
),
739 hex_string (end
- start
),
740 hex_string (file_ofs
),
743 filenames
+= 1 + strlen ((char *) filenames
);
746 do_cleanups (cleanup
);
749 /* Implement "info proc" for a corefile. */
752 linux_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
753 enum info_proc_what what
)
755 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
756 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
762 exe
= bfd_core_file_failing_command (core_bfd
);
764 printf_filtered ("exe = '%s'\n", exe
);
766 warning (_("unable to find command name in core file"));
770 linux_core_info_proc_mappings (gdbarch
, args
);
772 if (!exe_f
&& !mappings_f
)
773 error (_("unable to handle request"));
776 /* A structure for passing information through
777 linux_find_memory_regions_full. */
779 struct linux_find_memory_regions_data
781 /* The original callback. */
783 find_memory_region_ftype func
;
785 /* The original datum. */
790 /* A callback for linux_find_memory_regions that converts between the
791 "full"-style callback and find_memory_region_ftype. */
794 linux_find_memory_regions_thunk (ULONGEST vaddr
, ULONGEST size
,
795 ULONGEST offset
, ULONGEST inode
,
796 int read
, int write
, int exec
, int modified
,
797 const char *filename
, void *arg
)
799 struct linux_find_memory_regions_data
*data
= arg
;
801 return data
->func (vaddr
, size
, read
, write
, exec
, modified
, data
->data
);
804 /* Wrapper of linux_find_memory_regions_full handling FAKE_PID_P in GDB. */
807 linux_find_memory_regions_gdb (struct gdbarch
*gdbarch
,
808 linux_find_memory_region_ftype
*func
,
812 /* Default dump behavior of coredump_filter (0x33), according to
813 Documentation/filesystems/proc.txt from the Linux kernel
815 enum filterflags filterflags
= (COREFILTER_ANON_PRIVATE
816 | COREFILTER_ANON_SHARED
817 | COREFILTER_ELF_HEADERS
818 | COREFILTER_HUGETLB_PRIVATE
);
820 /* We need to know the real target PID so
821 linux_find_memory_regions_full can access /proc. */
822 if (current_inferior ()->fake_pid_p
)
825 pid
= current_inferior ()->pid
;
827 if (use_coredump_filter
)
829 char coredumpfilter_name
[100], *coredumpfilterdata
;
831 xsnprintf (coredumpfilter_name
, sizeof (coredumpfilter_name
),
832 "/proc/%d/coredump_filter", pid
);
833 coredumpfilterdata
= target_fileio_read_stralloc (NULL
,
834 coredumpfilter_name
);
835 if (coredumpfilterdata
!= NULL
)
837 sscanf (coredumpfilterdata
, "%x", &filterflags
);
838 xfree (coredumpfilterdata
);
842 return linux_find_memory_regions_full (pid
, filterflags
, func
, func_data
);
845 /* A variant of linux_find_memory_regions_full that is suitable as the
846 gdbarch find_memory_regions method. */
849 linux_find_memory_regions (struct gdbarch
*gdbarch
,
850 find_memory_region_ftype func
, void *func_data
)
852 struct linux_find_memory_regions_data data
;
855 data
.data
= func_data
;
857 return linux_find_memory_regions_gdb (gdbarch
,
858 linux_find_memory_regions_thunk
, &data
);
861 /* Determine which signal stopped execution. */
864 find_signalled_thread (struct thread_info
*info
, void *data
)
866 if (info
->suspend
.stop_signal
!= GDB_SIGNAL_0
867 && ptid_get_pid (info
->ptid
) == ptid_get_pid (inferior_ptid
))
873 static enum gdb_signal
874 find_stop_signal (void)
876 struct thread_info
*info
=
877 iterate_over_threads (find_signalled_thread
, NULL
);
880 return info
->suspend
.stop_signal
;
885 /* Generate corefile notes for SPU contexts. */
888 linux_spu_make_corefile_notes (bfd
*obfd
, char *note_data
, int *note_size
)
890 static const char *spu_files
[] =
912 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
916 /* Determine list of SPU ids. */
917 size
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
920 /* Generate corefile notes for each SPU file. */
921 for (i
= 0; i
< size
; i
+= 4)
923 int fd
= extract_unsigned_integer (spu_ids
+ i
, 4, byte_order
);
925 for (j
= 0; j
< sizeof (spu_files
) / sizeof (spu_files
[0]); j
++)
927 char annex
[32], note_name
[32];
931 xsnprintf (annex
, sizeof annex
, "%d/%s", fd
, spu_files
[j
]);
932 spu_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
936 xsnprintf (note_name
, sizeof note_name
, "SPU/%s", annex
);
937 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
957 /* This is used to pass information from
958 linux_make_mappings_corefile_notes through
959 linux_find_memory_regions_full. */
961 struct linux_make_mappings_data
963 /* Number of files mapped. */
966 /* The obstack for the main part of the data. */
967 struct obstack
*data_obstack
;
969 /* The filename obstack. */
970 struct obstack
*filename_obstack
;
972 /* The architecture's "long" type. */
973 struct type
*long_type
;
976 static linux_find_memory_region_ftype linux_make_mappings_callback
;
978 /* A callback for linux_find_memory_regions_full that updates the
979 mappings data for linux_make_mappings_corefile_notes. */
982 linux_make_mappings_callback (ULONGEST vaddr
, ULONGEST size
,
983 ULONGEST offset
, ULONGEST inode
,
984 int read
, int write
, int exec
, int modified
,
985 const char *filename
, void *data
)
987 struct linux_make_mappings_data
*map_data
= data
;
988 gdb_byte buf
[sizeof (ULONGEST
)];
990 if (*filename
== '\0' || inode
== 0)
993 ++map_data
->file_count
;
995 pack_long (buf
, map_data
->long_type
, vaddr
);
996 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
997 pack_long (buf
, map_data
->long_type
, vaddr
+ size
);
998 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
999 pack_long (buf
, map_data
->long_type
, offset
);
1000 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1002 obstack_grow_str0 (map_data
->filename_obstack
, filename
);
1007 /* Write the file mapping data to the core file, if possible. OBFD is
1008 the output BFD. NOTE_DATA is the current note data, and NOTE_SIZE
1009 is a pointer to the note size. Returns the new NOTE_DATA and
1010 updates NOTE_SIZE. */
1013 linux_make_mappings_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
,
1014 char *note_data
, int *note_size
)
1016 struct cleanup
*cleanup
;
1017 struct obstack data_obstack
, filename_obstack
;
1018 struct linux_make_mappings_data mapping_data
;
1019 struct type
*long_type
1020 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
), 0, "long");
1021 gdb_byte buf
[sizeof (ULONGEST
)];
1023 obstack_init (&data_obstack
);
1024 cleanup
= make_cleanup_obstack_free (&data_obstack
);
1025 obstack_init (&filename_obstack
);
1026 make_cleanup_obstack_free (&filename_obstack
);
1028 mapping_data
.file_count
= 0;
1029 mapping_data
.data_obstack
= &data_obstack
;
1030 mapping_data
.filename_obstack
= &filename_obstack
;
1031 mapping_data
.long_type
= long_type
;
1033 /* Reserve space for the count. */
1034 obstack_blank (&data_obstack
, TYPE_LENGTH (long_type
));
1035 /* We always write the page size as 1 since we have no good way to
1036 determine the correct value. */
1037 pack_long (buf
, long_type
, 1);
1038 obstack_grow (&data_obstack
, buf
, TYPE_LENGTH (long_type
));
1040 linux_find_memory_regions_gdb (gdbarch
, linux_make_mappings_callback
,
1043 if (mapping_data
.file_count
!= 0)
1045 /* Write the count to the obstack. */
1046 pack_long ((gdb_byte
*) obstack_base (&data_obstack
),
1047 long_type
, mapping_data
.file_count
);
1049 /* Copy the filenames to the data obstack. */
1050 obstack_grow (&data_obstack
, obstack_base (&filename_obstack
),
1051 obstack_object_size (&filename_obstack
));
1053 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1055 obstack_base (&data_obstack
),
1056 obstack_object_size (&data_obstack
));
1059 do_cleanups (cleanup
);
1063 /* Structure for passing information from
1064 linux_collect_thread_registers via an iterator to
1065 linux_collect_regset_section_cb. */
1067 struct linux_collect_regset_section_cb_data
1069 struct gdbarch
*gdbarch
;
1070 const struct regcache
*regcache
;
1075 enum gdb_signal stop_signal
;
1076 int abort_iteration
;
1079 /* Callback for iterate_over_regset_sections that records a single
1080 regset in the corefile note section. */
1083 linux_collect_regset_section_cb (const char *sect_name
, int size
,
1084 const struct regset
*regset
,
1085 const char *human_name
, void *cb_data
)
1088 struct linux_collect_regset_section_cb_data
*data
= cb_data
;
1090 if (data
->abort_iteration
)
1093 gdb_assert (regset
&& regset
->collect_regset
);
1095 buf
= xmalloc (size
);
1096 regset
->collect_regset (regset
, data
->regcache
, -1, buf
, size
);
1098 /* PRSTATUS still needs to be treated specially. */
1099 if (strcmp (sect_name
, ".reg") == 0)
1100 data
->note_data
= (char *) elfcore_write_prstatus
1101 (data
->obfd
, data
->note_data
, data
->note_size
, data
->lwp
,
1102 gdb_signal_to_host (data
->stop_signal
), buf
);
1104 data
->note_data
= (char *) elfcore_write_register_note
1105 (data
->obfd
, data
->note_data
, data
->note_size
,
1106 sect_name
, buf
, size
);
1109 if (data
->note_data
== NULL
)
1110 data
->abort_iteration
= 1;
1113 /* Records the thread's register state for the corefile note
1117 linux_collect_thread_registers (const struct regcache
*regcache
,
1118 ptid_t ptid
, bfd
*obfd
,
1119 char *note_data
, int *note_size
,
1120 enum gdb_signal stop_signal
)
1122 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1123 struct linux_collect_regset_section_cb_data data
;
1125 data
.gdbarch
= gdbarch
;
1126 data
.regcache
= regcache
;
1128 data
.note_data
= note_data
;
1129 data
.note_size
= note_size
;
1130 data
.stop_signal
= stop_signal
;
1131 data
.abort_iteration
= 0;
1133 /* For remote targets the LWP may not be available, so use the TID. */
1134 data
.lwp
= ptid_get_lwp (ptid
);
1136 data
.lwp
= ptid_get_tid (ptid
);
1138 gdbarch_iterate_over_regset_sections (gdbarch
,
1139 linux_collect_regset_section_cb
,
1141 return data
.note_data
;
1144 /* Fetch the siginfo data for the current thread, if it exists. If
1145 there is no data, or we could not read it, return NULL. Otherwise,
1146 return a newly malloc'd buffer holding the data and fill in *SIZE
1147 with the size of the data. The caller is responsible for freeing
1151 linux_get_siginfo_data (struct gdbarch
*gdbarch
, LONGEST
*size
)
1153 struct type
*siginfo_type
;
1156 struct cleanup
*cleanups
;
1158 if (!gdbarch_get_siginfo_type_p (gdbarch
))
1161 siginfo_type
= gdbarch_get_siginfo_type (gdbarch
);
1163 buf
= xmalloc (TYPE_LENGTH (siginfo_type
));
1164 cleanups
= make_cleanup (xfree
, buf
);
1166 bytes_read
= target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
1167 buf
, 0, TYPE_LENGTH (siginfo_type
));
1168 if (bytes_read
== TYPE_LENGTH (siginfo_type
))
1170 discard_cleanups (cleanups
);
1175 do_cleanups (cleanups
);
1182 struct linux_corefile_thread_data
1184 struct gdbarch
*gdbarch
;
1189 enum gdb_signal stop_signal
;
1192 /* Called by gdbthread.c once per thread. Records the thread's
1193 register state for the corefile note section. */
1196 linux_corefile_thread_callback (struct thread_info
*info
, void *data
)
1198 struct linux_corefile_thread_data
*args
= data
;
1200 /* It can be current thread
1201 which cannot be removed by update_thread_list. */
1202 if (info
->state
== THREAD_EXITED
)
1205 if (ptid_get_pid (info
->ptid
) == args
->pid
)
1207 struct cleanup
*old_chain
;
1208 struct regcache
*regcache
;
1209 gdb_byte
*siginfo_data
;
1210 LONGEST siginfo_size
= 0;
1212 regcache
= get_thread_arch_regcache (info
->ptid
, args
->gdbarch
);
1214 old_chain
= save_inferior_ptid ();
1215 inferior_ptid
= info
->ptid
;
1216 target_fetch_registers (regcache
, -1);
1217 siginfo_data
= linux_get_siginfo_data (args
->gdbarch
, &siginfo_size
);
1218 do_cleanups (old_chain
);
1220 old_chain
= make_cleanup (xfree
, siginfo_data
);
1222 args
->note_data
= linux_collect_thread_registers
1223 (regcache
, info
->ptid
, args
->obfd
, args
->note_data
,
1224 args
->note_size
, args
->stop_signal
);
1226 /* Don't return anything if we got no register information above,
1227 such a core file is useless. */
1228 if (args
->note_data
!= NULL
)
1229 if (siginfo_data
!= NULL
)
1230 args
->note_data
= elfcore_write_note (args
->obfd
,
1234 siginfo_data
, siginfo_size
);
1236 do_cleanups (old_chain
);
1239 return !args
->note_data
;
1242 /* Fill the PRPSINFO structure with information about the process being
1243 debugged. Returns 1 in case of success, 0 for failures. Please note that
1244 even if the structure cannot be entirely filled (e.g., GDB was unable to
1245 gather information about the process UID/GID), this function will still
1246 return 1 since some information was already recorded. It will only return
1247 0 iff nothing can be gathered. */
1250 linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo
*p
)
1252 /* The filename which we will use to obtain some info about the process.
1253 We will basically use this to store the `/proc/PID/FILENAME' file. */
1255 /* The full name of the program which generated the corefile. */
1257 /* The basename of the executable. */
1258 const char *basename
;
1259 /* The arguments of the program. */
1262 /* The contents of `/proc/PID/stat' and `/proc/PID/status' files. */
1263 char *proc_stat
, *proc_status
;
1264 /* Temporary buffer. */
1266 /* The valid states of a process, according to the Linux kernel. */
1267 const char valid_states
[] = "RSDTZW";
1268 /* The program state. */
1269 const char *prog_state
;
1270 /* The state of the process. */
1272 /* The PID of the program which generated the corefile. */
1274 /* Process flags. */
1275 unsigned int pr_flag
;
1276 /* Process nice value. */
1278 /* The number of fields read by `sscanf'. */
1284 gdb_assert (p
!= NULL
);
1286 /* Obtaining PID and filename. */
1287 pid
= ptid_get_pid (inferior_ptid
);
1288 xsnprintf (filename
, sizeof (filename
), "/proc/%d/cmdline", (int) pid
);
1289 fname
= target_fileio_read_stralloc (NULL
, filename
);
1291 if (fname
== NULL
|| *fname
== '\0')
1293 /* No program name was read, so we won't be able to retrieve more
1294 information about the process. */
1299 c
= make_cleanup (xfree
, fname
);
1300 memset (p
, 0, sizeof (*p
));
1302 /* Defining the PID. */
1305 /* Copying the program name. Only the basename matters. */
1306 basename
= lbasename (fname
);
1307 strncpy (p
->pr_fname
, basename
, sizeof (p
->pr_fname
));
1308 p
->pr_fname
[sizeof (p
->pr_fname
) - 1] = '\0';
1310 infargs
= get_inferior_args ();
1312 psargs
= xstrdup (fname
);
1313 if (infargs
!= NULL
)
1314 psargs
= reconcat (psargs
, psargs
, " ", infargs
, NULL
);
1316 make_cleanup (xfree
, psargs
);
1318 strncpy (p
->pr_psargs
, psargs
, sizeof (p
->pr_psargs
));
1319 p
->pr_psargs
[sizeof (p
->pr_psargs
) - 1] = '\0';
1321 xsnprintf (filename
, sizeof (filename
), "/proc/%d/stat", (int) pid
);
1322 proc_stat
= target_fileio_read_stralloc (NULL
, filename
);
1323 make_cleanup (xfree
, proc_stat
);
1325 if (proc_stat
== NULL
|| *proc_stat
== '\0')
1327 /* Despite being unable to read more information about the
1328 process, we return 1 here because at least we have its
1329 command line, PID and arguments. */
1334 /* Ok, we have the stats. It's time to do a little parsing of the
1335 contents of the buffer, so that we end up reading what we want.
1337 The following parsing mechanism is strongly based on the
1338 information generated by the `fs/proc/array.c' file, present in
1339 the Linux kernel tree. More details about how the information is
1340 displayed can be obtained by seeing the manpage of proc(5),
1341 specifically under the entry of `/proc/[pid]/stat'. */
1343 /* Getting rid of the PID, since we already have it. */
1344 while (isdigit (*proc_stat
))
1347 proc_stat
= skip_spaces (proc_stat
);
1349 /* ps command also relies on no trailing fields ever contain ')'. */
1350 proc_stat
= strrchr (proc_stat
, ')');
1351 if (proc_stat
== NULL
)
1358 proc_stat
= skip_spaces (proc_stat
);
1360 n_fields
= sscanf (proc_stat
,
1361 "%c" /* Process state. */
1362 "%d%d%d" /* Parent PID, group ID, session ID. */
1363 "%*d%*d" /* tty_nr, tpgid (not used). */
1365 "%*s%*s%*s%*s" /* minflt, cminflt, majflt,
1366 cmajflt (not used). */
1367 "%*s%*s%*s%*s" /* utime, stime, cutime,
1368 cstime (not used). */
1369 "%*s" /* Priority (not used). */
1372 &p
->pr_ppid
, &p
->pr_pgrp
, &p
->pr_sid
,
1378 /* Again, we couldn't read the complementary information about
1379 the process state. However, we already have minimal
1380 information, so we just return 1 here. */
1385 /* Filling the structure fields. */
1386 prog_state
= strchr (valid_states
, pr_sname
);
1387 if (prog_state
!= NULL
)
1388 p
->pr_state
= prog_state
- valid_states
;
1391 /* Zero means "Running". */
1395 p
->pr_sname
= p
->pr_state
> 5 ? '.' : pr_sname
;
1396 p
->pr_zomb
= p
->pr_sname
== 'Z';
1397 p
->pr_nice
= pr_nice
;
1398 p
->pr_flag
= pr_flag
;
1400 /* Finally, obtaining the UID and GID. For that, we read and parse the
1401 contents of the `/proc/PID/status' file. */
1402 xsnprintf (filename
, sizeof (filename
), "/proc/%d/status", (int) pid
);
1403 proc_status
= target_fileio_read_stralloc (NULL
, filename
);
1404 make_cleanup (xfree
, proc_status
);
1406 if (proc_status
== NULL
|| *proc_status
== '\0')
1408 /* Returning 1 since we already have a bunch of information. */
1413 /* Extracting the UID. */
1414 tmpstr
= strstr (proc_status
, "Uid:");
1417 /* Advancing the pointer to the beginning of the UID. */
1418 tmpstr
+= sizeof ("Uid:");
1419 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1422 if (isdigit (*tmpstr
))
1423 p
->pr_uid
= strtol (tmpstr
, &tmpstr
, 10);
1426 /* Extracting the GID. */
1427 tmpstr
= strstr (proc_status
, "Gid:");
1430 /* Advancing the pointer to the beginning of the GID. */
1431 tmpstr
+= sizeof ("Gid:");
1432 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1435 if (isdigit (*tmpstr
))
1436 p
->pr_gid
= strtol (tmpstr
, &tmpstr
, 10);
1444 /* Build the note section for a corefile, and return it in a malloc
1448 linux_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
1450 struct linux_corefile_thread_data thread_args
;
1451 struct elf_internal_linux_prpsinfo prpsinfo
;
1452 char *note_data
= NULL
;
1456 if (! gdbarch_iterate_over_regset_sections_p (gdbarch
))
1459 if (linux_fill_prpsinfo (&prpsinfo
))
1461 if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch
))
1463 note_data
= gdbarch_elfcore_write_linux_prpsinfo (gdbarch
, obfd
,
1464 note_data
, note_size
,
1469 if (gdbarch_ptr_bit (gdbarch
) == 64)
1470 note_data
= elfcore_write_linux_prpsinfo64 (obfd
,
1471 note_data
, note_size
,
1474 note_data
= elfcore_write_linux_prpsinfo32 (obfd
,
1475 note_data
, note_size
,
1480 /* Thread register information. */
1483 update_thread_list ();
1485 CATCH (e
, RETURN_MASK_ERROR
)
1487 exception_print (gdb_stderr
, e
);
1491 thread_args
.gdbarch
= gdbarch
;
1492 thread_args
.pid
= ptid_get_pid (inferior_ptid
);
1493 thread_args
.obfd
= obfd
;
1494 thread_args
.note_data
= note_data
;
1495 thread_args
.note_size
= note_size
;
1496 thread_args
.stop_signal
= find_stop_signal ();
1497 iterate_over_threads (linux_corefile_thread_callback
, &thread_args
);
1498 note_data
= thread_args
.note_data
;
1502 /* Auxillary vector. */
1503 auxv_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_AUXV
,
1507 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1508 "CORE", NT_AUXV
, auxv
, auxv_len
);
1515 /* SPU information. */
1516 note_data
= linux_spu_make_corefile_notes (obfd
, note_data
, note_size
);
1520 /* File mappings. */
1521 note_data
= linux_make_mappings_corefile_notes (gdbarch
, obfd
,
1522 note_data
, note_size
);
1527 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
1528 gdbarch.h. This function is not static because it is exported to
1529 other -tdep files. */
1532 linux_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1537 return GDB_SIGNAL_0
;
1540 return GDB_SIGNAL_HUP
;
1543 return GDB_SIGNAL_INT
;
1546 return GDB_SIGNAL_QUIT
;
1549 return GDB_SIGNAL_ILL
;
1552 return GDB_SIGNAL_TRAP
;
1555 return GDB_SIGNAL_ABRT
;
1558 return GDB_SIGNAL_BUS
;
1561 return GDB_SIGNAL_FPE
;
1564 return GDB_SIGNAL_KILL
;
1567 return GDB_SIGNAL_USR1
;
1570 return GDB_SIGNAL_SEGV
;
1573 return GDB_SIGNAL_USR2
;
1576 return GDB_SIGNAL_PIPE
;
1579 return GDB_SIGNAL_ALRM
;
1582 return GDB_SIGNAL_TERM
;
1585 return GDB_SIGNAL_CHLD
;
1588 return GDB_SIGNAL_CONT
;
1591 return GDB_SIGNAL_STOP
;
1594 return GDB_SIGNAL_TSTP
;
1597 return GDB_SIGNAL_TTIN
;
1600 return GDB_SIGNAL_TTOU
;
1603 return GDB_SIGNAL_URG
;
1606 return GDB_SIGNAL_XCPU
;
1609 return GDB_SIGNAL_XFSZ
;
1611 case LINUX_SIGVTALRM
:
1612 return GDB_SIGNAL_VTALRM
;
1615 return GDB_SIGNAL_PROF
;
1617 case LINUX_SIGWINCH
:
1618 return GDB_SIGNAL_WINCH
;
1620 /* No way to differentiate between SIGIO and SIGPOLL.
1621 Therefore, we just handle the first one. */
1623 return GDB_SIGNAL_IO
;
1626 return GDB_SIGNAL_PWR
;
1629 return GDB_SIGNAL_SYS
;
1631 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
1632 therefore we have to handle them here. */
1633 case LINUX_SIGRTMIN
:
1634 return GDB_SIGNAL_REALTIME_32
;
1636 case LINUX_SIGRTMAX
:
1637 return GDB_SIGNAL_REALTIME_64
;
1640 if (signal
>= LINUX_SIGRTMIN
+ 1 && signal
<= LINUX_SIGRTMAX
- 1)
1642 int offset
= signal
- LINUX_SIGRTMIN
+ 1;
1644 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_33
+ offset
);
1647 return GDB_SIGNAL_UNKNOWN
;
1650 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1651 gdbarch.h. This function is not static because it is exported to
1652 other -tdep files. */
1655 linux_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1656 enum gdb_signal signal
)
1663 case GDB_SIGNAL_HUP
:
1664 return LINUX_SIGHUP
;
1666 case GDB_SIGNAL_INT
:
1667 return LINUX_SIGINT
;
1669 case GDB_SIGNAL_QUIT
:
1670 return LINUX_SIGQUIT
;
1672 case GDB_SIGNAL_ILL
:
1673 return LINUX_SIGILL
;
1675 case GDB_SIGNAL_TRAP
:
1676 return LINUX_SIGTRAP
;
1678 case GDB_SIGNAL_ABRT
:
1679 return LINUX_SIGABRT
;
1681 case GDB_SIGNAL_FPE
:
1682 return LINUX_SIGFPE
;
1684 case GDB_SIGNAL_KILL
:
1685 return LINUX_SIGKILL
;
1687 case GDB_SIGNAL_BUS
:
1688 return LINUX_SIGBUS
;
1690 case GDB_SIGNAL_SEGV
:
1691 return LINUX_SIGSEGV
;
1693 case GDB_SIGNAL_SYS
:
1694 return LINUX_SIGSYS
;
1696 case GDB_SIGNAL_PIPE
:
1697 return LINUX_SIGPIPE
;
1699 case GDB_SIGNAL_ALRM
:
1700 return LINUX_SIGALRM
;
1702 case GDB_SIGNAL_TERM
:
1703 return LINUX_SIGTERM
;
1705 case GDB_SIGNAL_URG
:
1706 return LINUX_SIGURG
;
1708 case GDB_SIGNAL_STOP
:
1709 return LINUX_SIGSTOP
;
1711 case GDB_SIGNAL_TSTP
:
1712 return LINUX_SIGTSTP
;
1714 case GDB_SIGNAL_CONT
:
1715 return LINUX_SIGCONT
;
1717 case GDB_SIGNAL_CHLD
:
1718 return LINUX_SIGCHLD
;
1720 case GDB_SIGNAL_TTIN
:
1721 return LINUX_SIGTTIN
;
1723 case GDB_SIGNAL_TTOU
:
1724 return LINUX_SIGTTOU
;
1729 case GDB_SIGNAL_XCPU
:
1730 return LINUX_SIGXCPU
;
1732 case GDB_SIGNAL_XFSZ
:
1733 return LINUX_SIGXFSZ
;
1735 case GDB_SIGNAL_VTALRM
:
1736 return LINUX_SIGVTALRM
;
1738 case GDB_SIGNAL_PROF
:
1739 return LINUX_SIGPROF
;
1741 case GDB_SIGNAL_WINCH
:
1742 return LINUX_SIGWINCH
;
1744 case GDB_SIGNAL_USR1
:
1745 return LINUX_SIGUSR1
;
1747 case GDB_SIGNAL_USR2
:
1748 return LINUX_SIGUSR2
;
1750 case GDB_SIGNAL_PWR
:
1751 return LINUX_SIGPWR
;
1753 case GDB_SIGNAL_POLL
:
1754 return LINUX_SIGPOLL
;
1756 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1757 therefore we have to handle it here. */
1758 case GDB_SIGNAL_REALTIME_32
:
1759 return LINUX_SIGRTMIN
;
1761 /* Same comment applies to _64. */
1762 case GDB_SIGNAL_REALTIME_64
:
1763 return LINUX_SIGRTMAX
;
1766 /* GDB_SIGNAL_REALTIME_33 to _64 are continuous. */
1767 if (signal
>= GDB_SIGNAL_REALTIME_33
1768 && signal
<= GDB_SIGNAL_REALTIME_63
)
1770 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1772 return LINUX_SIGRTMIN
+ 1 + offset
;
1778 /* Rummage through mappings to find a mapping's size. */
1781 find_mapping_size (CORE_ADDR vaddr
, unsigned long size
,
1782 int read
, int write
, int exec
, int modified
,
1785 struct mem_range
*range
= data
;
1787 if (vaddr
== range
->start
)
1789 range
->length
= size
;
1795 /* Helper for linux_vsyscall_range that does the real work of finding
1796 the vsyscall's address range. */
1799 linux_vsyscall_range_raw (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1801 if (target_auxv_search (¤t_target
, AT_SYSINFO_EHDR
, &range
->start
) <= 0)
1804 /* This is installed by linux_init_abi below, so should always be
1806 gdb_assert (gdbarch_find_memory_regions_p (target_gdbarch ()));
1809 gdbarch_find_memory_regions (gdbarch
, find_mapping_size
, range
);
1813 /* Implementation of the "vsyscall_range" gdbarch hook. Handles
1814 caching, and defers the real work to linux_vsyscall_range_raw. */
1817 linux_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1819 struct linux_info
*info
= get_linux_inferior_data ();
1821 if (info
->vsyscall_range_p
== 0)
1823 if (linux_vsyscall_range_raw (gdbarch
, &info
->vsyscall_range
))
1824 info
->vsyscall_range_p
= 1;
1826 info
->vsyscall_range_p
= -1;
1829 if (info
->vsyscall_range_p
< 0)
1832 *range
= info
->vsyscall_range
;
1836 /* Symbols for linux_infcall_mmap's ARG_FLAGS; their Linux MAP_* system
1837 definitions would be dependent on compilation host. */
1838 #define GDB_MMAP_MAP_PRIVATE 0x02 /* Changes are private. */
1839 #define GDB_MMAP_MAP_ANONYMOUS 0x20 /* Don't use a file. */
1841 /* See gdbarch.sh 'infcall_mmap'. */
1844 linux_infcall_mmap (CORE_ADDR size
, unsigned prot
)
1846 struct objfile
*objf
;
1847 /* Do there still exist any Linux systems without "mmap64"?
1848 "mmap" uses 64-bit off_t on x86_64 and 32-bit off_t on i386 and x32. */
1849 struct value
*mmap_val
= find_function_in_inferior ("mmap64", &objf
);
1850 struct value
*addr_val
;
1851 struct gdbarch
*gdbarch
= get_objfile_arch (objf
);
1855 ARG_ADDR
, ARG_LENGTH
, ARG_PROT
, ARG_FLAGS
, ARG_FD
, ARG_OFFSET
, ARG_LAST
1857 struct value
*arg
[ARG_LAST
];
1859 arg
[ARG_ADDR
] = value_from_pointer (builtin_type (gdbarch
)->builtin_data_ptr
,
1861 /* Assuming sizeof (unsigned long) == sizeof (size_t). */
1862 arg
[ARG_LENGTH
] = value_from_ulongest
1863 (builtin_type (gdbarch
)->builtin_unsigned_long
, size
);
1864 gdb_assert ((prot
& ~(GDB_MMAP_PROT_READ
| GDB_MMAP_PROT_WRITE
1865 | GDB_MMAP_PROT_EXEC
))
1867 arg
[ARG_PROT
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, prot
);
1868 arg
[ARG_FLAGS
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
,
1869 GDB_MMAP_MAP_PRIVATE
1870 | GDB_MMAP_MAP_ANONYMOUS
);
1871 arg
[ARG_FD
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, -1);
1872 arg
[ARG_OFFSET
] = value_from_longest (builtin_type (gdbarch
)->builtin_int64
,
1874 addr_val
= call_function_by_hand (mmap_val
, ARG_LAST
, arg
);
1875 retval
= value_as_address (addr_val
);
1876 if (retval
== (CORE_ADDR
) -1)
1877 error (_("Failed inferior mmap call for %s bytes, errno is changed."),
1882 /* See gdbarch.sh 'infcall_munmap'. */
1885 linux_infcall_munmap (CORE_ADDR addr
, CORE_ADDR size
)
1887 struct objfile
*objf
;
1888 struct value
*munmap_val
= find_function_in_inferior ("munmap", &objf
);
1889 struct value
*retval_val
;
1890 struct gdbarch
*gdbarch
= get_objfile_arch (objf
);
1894 ARG_ADDR
, ARG_LENGTH
, ARG_LAST
1896 struct value
*arg
[ARG_LAST
];
1898 arg
[ARG_ADDR
] = value_from_pointer (builtin_type (gdbarch
)->builtin_data_ptr
,
1900 /* Assuming sizeof (unsigned long) == sizeof (size_t). */
1901 arg
[ARG_LENGTH
] = value_from_ulongest
1902 (builtin_type (gdbarch
)->builtin_unsigned_long
, size
);
1903 retval_val
= call_function_by_hand (munmap_val
, ARG_LAST
, arg
);
1904 retval
= value_as_long (retval_val
);
1906 warning (_("Failed inferior munmap call at %s for %s bytes, "
1907 "errno is changed."),
1908 hex_string (addr
), pulongest (size
));
1911 /* See linux-tdep.h. */
1914 linux_displaced_step_location (struct gdbarch
*gdbarch
)
1919 /* Determine entry point from target auxiliary vector. This avoids
1920 the need for symbols. Also, when debugging a stand-alone SPU
1921 executable, entry_point_address () will point to an SPU
1922 local-store address and is thus not usable as displaced stepping
1923 location. The auxiliary vector gets us the PowerPC-side entry
1924 point address instead. */
1925 if (target_auxv_search (¤t_target
, AT_ENTRY
, &addr
) <= 0)
1926 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
1928 /* Make certain that the address points at real code, and not a
1929 function descriptor. */
1930 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
1933 /* Inferior calls also use the entry point as a breakpoint location.
1934 We don't want displaced stepping to interfere with those
1935 breakpoints, so leave space. */
1936 gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bp_len
);
1942 /* Display whether the gcore command is using the
1943 /proc/PID/coredump_filter file. */
1946 show_use_coredump_filter (struct ui_file
*file
, int from_tty
,
1947 struct cmd_list_element
*c
, const char *value
)
1949 fprintf_filtered (file
, _("Use of /proc/PID/coredump_filter file to generate"
1950 " corefiles is %s.\n"), value
);
1953 /* To be called from the various GDB_OSABI_LINUX handlers for the
1954 various GNU/Linux architectures and machine types. */
1957 linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1959 set_gdbarch_core_pid_to_str (gdbarch
, linux_core_pid_to_str
);
1960 set_gdbarch_info_proc (gdbarch
, linux_info_proc
);
1961 set_gdbarch_core_info_proc (gdbarch
, linux_core_info_proc
);
1962 set_gdbarch_find_memory_regions (gdbarch
, linux_find_memory_regions
);
1963 set_gdbarch_make_corefile_notes (gdbarch
, linux_make_corefile_notes
);
1964 set_gdbarch_has_shared_address_space (gdbarch
,
1965 linux_has_shared_address_space
);
1966 set_gdbarch_gdb_signal_from_target (gdbarch
,
1967 linux_gdb_signal_from_target
);
1968 set_gdbarch_gdb_signal_to_target (gdbarch
,
1969 linux_gdb_signal_to_target
);
1970 set_gdbarch_vsyscall_range (gdbarch
, linux_vsyscall_range
);
1971 set_gdbarch_infcall_mmap (gdbarch
, linux_infcall_mmap
);
1972 set_gdbarch_infcall_munmap (gdbarch
, linux_infcall_munmap
);
1973 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
1976 /* Provide a prototype to silence -Wmissing-prototypes. */
1977 extern initialize_file_ftype _initialize_linux_tdep
;
1980 _initialize_linux_tdep (void)
1982 linux_gdbarch_data_handle
=
1983 gdbarch_data_register_post_init (init_linux_gdbarch_data
);
1985 /* Set a cache per-inferior. */
1987 = register_inferior_data_with_cleanup (NULL
, linux_inferior_data_cleanup
);
1988 /* Observers used to invalidate the cache when needed. */
1989 observer_attach_inferior_exit (invalidate_linux_cache_inf
);
1990 observer_attach_inferior_appeared (invalidate_linux_cache_inf
);
1992 add_setshow_boolean_cmd ("use-coredump-filter", class_files
,
1993 &use_coredump_filter
, _("\
1994 Set whether gcore should consider /proc/PID/coredump_filter."),
1996 Show whether gcore should consider /proc/PID/coredump_filter."),
1998 Use this command to set whether gcore should consider the contents\n\
1999 of /proc/PID/coredump_filter when generating the corefile. For more information\n\
2000 about this file, refer to the manpage of core(5)."),
2001 NULL
, show_use_coredump_filter
,
2002 &setlist
, &showlist
);