1 /* Target-dependent code for GNU/Linux, architecture independent.
3 Copyright (C) 2009-2014 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"
39 /* This enum represents the signals' numbers on a generic architecture
40 running the Linux kernel. The definition of "generic" comes from
41 the file <include/uapi/asm-generic/signal.h>, from the Linux kernel
42 tree, which is the "de facto" implementation of signal numbers to
43 be used by new architecture ports.
45 For those architectures which have differences between the generic
46 standard (e.g., Alpha), we define the different signals (and *only*
47 those) in the specific target-dependent file (e.g.,
48 alpha-linux-tdep.c, for Alpha). Please refer to the architecture's
49 tdep file for more information.
51 ARM deserves a special mention here. On the file
52 <arch/arm/include/uapi/asm/signal.h>, it defines only one different
53 (and ARM-only) signal, which is SIGSWI, with the same number as
54 SIGRTMIN. This signal is used only for a very specific target,
55 called ArthurOS (from RISCOS). Therefore, we do not handle it on
56 the ARM-tdep file, and we can safely use the generic signal handler
59 As stated above, this enum is derived from
60 <include/uapi/asm-generic/signal.h>, from the Linux kernel
95 LINUX_SIGPOLL
= LINUX_SIGIO
,
104 static struct gdbarch_data
*linux_gdbarch_data_handle
;
106 struct linux_gdbarch_data
108 struct type
*siginfo_type
;
112 init_linux_gdbarch_data (struct gdbarch
*gdbarch
)
114 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct linux_gdbarch_data
);
117 static struct linux_gdbarch_data
*
118 get_linux_gdbarch_data (struct gdbarch
*gdbarch
)
120 return gdbarch_data (gdbarch
, linux_gdbarch_data_handle
);
123 /* Per-inferior data key. */
124 static const struct inferior_data
*linux_inferior_data
;
126 /* Linux-specific cached data. This is used by GDB for caching
127 purposes for each inferior. This helps reduce the overhead of
128 transfering data from a remote target to the local host. */
131 /* Cache of the inferior's vsyscall/vDSO mapping range. Only valid
132 if VSYSCALL_RANGE_P is positive. This is cached because getting
133 at this info requires an auxv lookup (which is itself cached),
134 and looking through the inferior's mappings (which change
135 throughout execution and therefore cannot be cached). */
136 struct mem_range vsyscall_range
;
138 /* Zero if we haven't tried looking up the vsyscall's range before
139 yet. Positive if we tried looking it up, and found it. Negative
140 if we tried looking it up but failed. */
141 int vsyscall_range_p
;
144 /* Frees whatever allocated space there is to be freed and sets INF's
145 linux cache data pointer to NULL. */
148 invalidate_linux_cache_inf (struct inferior
*inf
)
150 struct linux_info
*info
;
152 info
= inferior_data (inf
, linux_inferior_data
);
156 set_inferior_data (inf
, linux_inferior_data
, NULL
);
160 /* Handles the cleanup of the linux cache for inferior INF. ARG is
161 ignored. Callback for the inferior_appeared and inferior_exit
165 linux_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
167 invalidate_linux_cache_inf (inf
);
170 /* Fetch the linux cache info for INF. This function always returns a
171 valid INFO pointer. */
173 static struct linux_info
*
174 get_linux_inferior_data (void)
176 struct linux_info
*info
;
177 struct inferior
*inf
= current_inferior ();
179 info
= inferior_data (inf
, linux_inferior_data
);
182 info
= XCNEW (struct linux_info
);
183 set_inferior_data (inf
, linux_inferior_data
, info
);
189 /* This function is suitable for architectures that don't
190 extend/override the standard siginfo structure. */
193 linux_get_siginfo_type (struct gdbarch
*gdbarch
)
195 struct linux_gdbarch_data
*linux_gdbarch_data
;
196 struct type
*int_type
, *uint_type
, *long_type
, *void_ptr_type
;
197 struct type
*uid_type
, *pid_type
;
198 struct type
*sigval_type
, *clock_type
;
199 struct type
*siginfo_type
, *sifields_type
;
202 linux_gdbarch_data
= get_linux_gdbarch_data (gdbarch
);
203 if (linux_gdbarch_data
->siginfo_type
!= NULL
)
204 return linux_gdbarch_data
->siginfo_type
;
206 int_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
208 uint_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
210 long_type
= arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
212 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
215 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
216 TYPE_NAME (sigval_type
) = xstrdup ("sigval_t");
217 append_composite_type_field (sigval_type
, "sival_int", int_type
);
218 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
221 pid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
222 TYPE_LENGTH (int_type
), "__pid_t");
223 TYPE_TARGET_TYPE (pid_type
) = int_type
;
224 TYPE_TARGET_STUB (pid_type
) = 1;
227 uid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
228 TYPE_LENGTH (uint_type
), "__uid_t");
229 TYPE_TARGET_TYPE (uid_type
) = uint_type
;
230 TYPE_TARGET_STUB (uid_type
) = 1;
233 clock_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
234 TYPE_LENGTH (long_type
), "__clock_t");
235 TYPE_TARGET_TYPE (clock_type
) = long_type
;
236 TYPE_TARGET_STUB (clock_type
) = 1;
239 sifields_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
242 const int si_max_size
= 128;
244 int size_of_int
= gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
247 if (gdbarch_ptr_bit (gdbarch
) == 64)
248 si_pad_size
= (si_max_size
/ size_of_int
) - 4;
250 si_pad_size
= (si_max_size
/ size_of_int
) - 3;
251 append_composite_type_field (sifields_type
, "_pad",
252 init_vector_type (int_type
, si_pad_size
));
256 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
257 append_composite_type_field (type
, "si_pid", pid_type
);
258 append_composite_type_field (type
, "si_uid", uid_type
);
259 append_composite_type_field (sifields_type
, "_kill", type
);
262 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
263 append_composite_type_field (type
, "si_tid", int_type
);
264 append_composite_type_field (type
, "si_overrun", int_type
);
265 append_composite_type_field (type
, "si_sigval", sigval_type
);
266 append_composite_type_field (sifields_type
, "_timer", type
);
269 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
270 append_composite_type_field (type
, "si_pid", pid_type
);
271 append_composite_type_field (type
, "si_uid", uid_type
);
272 append_composite_type_field (type
, "si_sigval", sigval_type
);
273 append_composite_type_field (sifields_type
, "_rt", type
);
276 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
277 append_composite_type_field (type
, "si_pid", pid_type
);
278 append_composite_type_field (type
, "si_uid", uid_type
);
279 append_composite_type_field (type
, "si_status", int_type
);
280 append_composite_type_field (type
, "si_utime", clock_type
);
281 append_composite_type_field (type
, "si_stime", clock_type
);
282 append_composite_type_field (sifields_type
, "_sigchld", type
);
285 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
286 append_composite_type_field (type
, "si_addr", void_ptr_type
);
287 append_composite_type_field (sifields_type
, "_sigfault", type
);
290 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
291 append_composite_type_field (type
, "si_band", long_type
);
292 append_composite_type_field (type
, "si_fd", int_type
);
293 append_composite_type_field (sifields_type
, "_sigpoll", type
);
296 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
297 TYPE_NAME (siginfo_type
) = xstrdup ("siginfo");
298 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
299 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
300 append_composite_type_field (siginfo_type
, "si_code", int_type
);
301 append_composite_type_field_aligned (siginfo_type
,
302 "_sifields", sifields_type
,
303 TYPE_LENGTH (long_type
));
305 linux_gdbarch_data
->siginfo_type
= siginfo_type
;
310 /* Return true if the target is running on uClinux instead of normal
314 linux_is_uclinux (void)
318 return (target_auxv_search (¤t_target
, AT_NULL
, &dummy
) > 0
319 && target_auxv_search (¤t_target
, AT_PAGESZ
, &dummy
) == 0);
323 linux_has_shared_address_space (struct gdbarch
*gdbarch
)
325 return linux_is_uclinux ();
328 /* This is how we want PTIDs from core files to be printed. */
331 linux_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
335 if (ptid_get_lwp (ptid
) != 0)
337 snprintf (buf
, sizeof (buf
), "LWP %ld", ptid_get_lwp (ptid
));
341 return normal_pid_to_str (ptid
);
344 /* Service function for corefiles and info proc. */
347 read_mapping (const char *line
,
348 ULONGEST
*addr
, ULONGEST
*endaddr
,
349 const char **permissions
, size_t *permissions_len
,
351 const char **device
, size_t *device_len
,
353 const char **filename
)
355 const char *p
= line
;
357 *addr
= strtoulst (p
, &p
, 16);
360 *endaddr
= strtoulst (p
, &p
, 16);
362 p
= skip_spaces_const (p
);
364 while (*p
&& !isspace (*p
))
366 *permissions_len
= p
- *permissions
;
368 *offset
= strtoulst (p
, &p
, 16);
370 p
= skip_spaces_const (p
);
372 while (*p
&& !isspace (*p
))
374 *device_len
= p
- *device
;
376 *inode
= strtoulst (p
, &p
, 10);
378 p
= skip_spaces_const (p
);
382 /* Implement the "info proc" command. */
385 linux_info_proc (struct gdbarch
*gdbarch
, const char *args
,
386 enum info_proc_what what
)
388 /* A long is used for pid instead of an int to avoid a loss of precision
389 compiler warning from the output of strtoul. */
391 int cmdline_f
= (what
== IP_MINIMAL
|| what
== IP_CMDLINE
|| what
== IP_ALL
);
392 int cwd_f
= (what
== IP_MINIMAL
|| what
== IP_CWD
|| what
== IP_ALL
);
393 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
394 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
395 int status_f
= (what
== IP_STATUS
|| what
== IP_ALL
);
396 int stat_f
= (what
== IP_STAT
|| what
== IP_ALL
);
401 if (args
&& isdigit (args
[0]))
405 pid
= strtoul (args
, &tem
, 10);
410 if (!target_has_execution
)
411 error (_("No current process: you must name one."));
412 if (current_inferior ()->fake_pid_p
)
413 error (_("Can't determine the current process's PID: you must name one."));
415 pid
= current_inferior ()->pid
;
418 args
= skip_spaces_const (args
);
420 error (_("Too many parameters: %s"), args
);
422 printf_filtered (_("process %ld\n"), pid
);
425 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cmdline", pid
);
426 data
= target_fileio_read_stralloc (filename
);
429 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
430 printf_filtered ("cmdline = '%s'\n", data
);
431 do_cleanups (cleanup
);
434 warning (_("unable to open /proc file '%s'"), filename
);
438 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cwd", pid
);
439 data
= target_fileio_readlink (filename
, &target_errno
);
442 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
443 printf_filtered ("cwd = '%s'\n", data
);
444 do_cleanups (cleanup
);
447 warning (_("unable to read link '%s'"), filename
);
451 xsnprintf (filename
, sizeof filename
, "/proc/%ld/exe", pid
);
452 data
= target_fileio_readlink (filename
, &target_errno
);
455 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
456 printf_filtered ("exe = '%s'\n", data
);
457 do_cleanups (cleanup
);
460 warning (_("unable to read link '%s'"), filename
);
464 xsnprintf (filename
, sizeof filename
, "/proc/%ld/maps", pid
);
465 data
= target_fileio_read_stralloc (filename
);
468 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
471 printf_filtered (_("Mapped address spaces:\n\n"));
472 if (gdbarch_addr_bit (gdbarch
) == 32)
474 printf_filtered ("\t%10s %10s %10s %10s %s\n",
477 " Size", " Offset", "objfile");
481 printf_filtered (" %18s %18s %10s %10s %s\n",
484 " Size", " Offset", "objfile");
487 for (line
= strtok (data
, "\n"); line
; line
= strtok (NULL
, "\n"))
489 ULONGEST addr
, endaddr
, offset
, inode
;
490 const char *permissions
, *device
, *filename
;
491 size_t permissions_len
, device_len
;
493 read_mapping (line
, &addr
, &endaddr
,
494 &permissions
, &permissions_len
,
495 &offset
, &device
, &device_len
,
498 if (gdbarch_addr_bit (gdbarch
) == 32)
500 printf_filtered ("\t%10s %10s %10s %10s %s\n",
501 paddress (gdbarch
, addr
),
502 paddress (gdbarch
, endaddr
),
503 hex_string (endaddr
- addr
),
505 *filename
? filename
: "");
509 printf_filtered (" %18s %18s %10s %10s %s\n",
510 paddress (gdbarch
, addr
),
511 paddress (gdbarch
, endaddr
),
512 hex_string (endaddr
- addr
),
514 *filename
? filename
: "");
518 do_cleanups (cleanup
);
521 warning (_("unable to open /proc file '%s'"), filename
);
525 xsnprintf (filename
, sizeof filename
, "/proc/%ld/status", pid
);
526 data
= target_fileio_read_stralloc (filename
);
529 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
530 puts_filtered (data
);
531 do_cleanups (cleanup
);
534 warning (_("unable to open /proc file '%s'"), filename
);
538 xsnprintf (filename
, sizeof filename
, "/proc/%ld/stat", pid
);
539 data
= target_fileio_read_stralloc (filename
);
542 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
543 const char *p
= data
;
545 printf_filtered (_("Process: %s\n"),
546 pulongest (strtoulst (p
, &p
, 10)));
548 p
= skip_spaces_const (p
);
551 /* ps command also relies on no trailing fields
553 const char *ep
= strrchr (p
, ')');
556 printf_filtered ("Exec file: %.*s\n",
557 (int) (ep
- p
- 1), p
+ 1);
562 p
= skip_spaces_const (p
);
564 printf_filtered (_("State: %c\n"), *p
++);
567 printf_filtered (_("Parent process: %s\n"),
568 pulongest (strtoulst (p
, &p
, 10)));
570 printf_filtered (_("Process group: %s\n"),
571 pulongest (strtoulst (p
, &p
, 10)));
573 printf_filtered (_("Session id: %s\n"),
574 pulongest (strtoulst (p
, &p
, 10)));
576 printf_filtered (_("TTY: %s\n"),
577 pulongest (strtoulst (p
, &p
, 10)));
579 printf_filtered (_("TTY owner process group: %s\n"),
580 pulongest (strtoulst (p
, &p
, 10)));
583 printf_filtered (_("Flags: %s\n"),
584 hex_string (strtoulst (p
, &p
, 10)));
586 printf_filtered (_("Minor faults (no memory page): %s\n"),
587 pulongest (strtoulst (p
, &p
, 10)));
589 printf_filtered (_("Minor faults, children: %s\n"),
590 pulongest (strtoulst (p
, &p
, 10)));
592 printf_filtered (_("Major faults (memory page faults): %s\n"),
593 pulongest (strtoulst (p
, &p
, 10)));
595 printf_filtered (_("Major faults, children: %s\n"),
596 pulongest (strtoulst (p
, &p
, 10)));
598 printf_filtered (_("utime: %s\n"),
599 pulongest (strtoulst (p
, &p
, 10)));
601 printf_filtered (_("stime: %s\n"),
602 pulongest (strtoulst (p
, &p
, 10)));
604 printf_filtered (_("utime, children: %s\n"),
605 pulongest (strtoulst (p
, &p
, 10)));
607 printf_filtered (_("stime, children: %s\n"),
608 pulongest (strtoulst (p
, &p
, 10)));
610 printf_filtered (_("jiffies remaining in current "
612 pulongest (strtoulst (p
, &p
, 10)));
614 printf_filtered (_("'nice' value: %s\n"),
615 pulongest (strtoulst (p
, &p
, 10)));
617 printf_filtered (_("jiffies until next timeout: %s\n"),
618 pulongest (strtoulst (p
, &p
, 10)));
620 printf_filtered (_("jiffies until next SIGALRM: %s\n"),
621 pulongest (strtoulst (p
, &p
, 10)));
623 printf_filtered (_("start time (jiffies since "
624 "system boot): %s\n"),
625 pulongest (strtoulst (p
, &p
, 10)));
627 printf_filtered (_("Virtual memory size: %s\n"),
628 pulongest (strtoulst (p
, &p
, 10)));
630 printf_filtered (_("Resident set size: %s\n"),
631 pulongest (strtoulst (p
, &p
, 10)));
633 printf_filtered (_("rlim: %s\n"),
634 pulongest (strtoulst (p
, &p
, 10)));
636 printf_filtered (_("Start of text: %s\n"),
637 hex_string (strtoulst (p
, &p
, 10)));
639 printf_filtered (_("End of text: %s\n"),
640 hex_string (strtoulst (p
, &p
, 10)));
642 printf_filtered (_("Start of stack: %s\n"),
643 hex_string (strtoulst (p
, &p
, 10)));
644 #if 0 /* Don't know how architecture-dependent the rest is...
645 Anyway the signal bitmap info is available from "status". */
647 printf_filtered (_("Kernel stack pointer: %s\n"),
648 hex_string (strtoulst (p
, &p
, 10)));
650 printf_filtered (_("Kernel instr pointer: %s\n"),
651 hex_string (strtoulst (p
, &p
, 10)));
653 printf_filtered (_("Pending signals bitmap: %s\n"),
654 hex_string (strtoulst (p
, &p
, 10)));
656 printf_filtered (_("Blocked signals bitmap: %s\n"),
657 hex_string (strtoulst (p
, &p
, 10)));
659 printf_filtered (_("Ignored signals bitmap: %s\n"),
660 hex_string (strtoulst (p
, &p
, 10)));
662 printf_filtered (_("Catched signals bitmap: %s\n"),
663 hex_string (strtoulst (p
, &p
, 10)));
665 printf_filtered (_("wchan (system call): %s\n"),
666 hex_string (strtoulst (p
, &p
, 10)));
668 do_cleanups (cleanup
);
671 warning (_("unable to open /proc file '%s'"), filename
);
675 /* Implement "info proc mappings" for a corefile. */
678 linux_core_info_proc_mappings (struct gdbarch
*gdbarch
, const char *args
)
681 ULONGEST count
, page_size
;
682 unsigned char *descdata
, *filenames
, *descend
, *contents
;
684 unsigned int addr_size_bits
, addr_size
;
685 struct cleanup
*cleanup
;
686 struct gdbarch
*core_gdbarch
= gdbarch_from_bfd (core_bfd
);
687 /* We assume this for reading 64-bit core files. */
688 gdb_static_assert (sizeof (ULONGEST
) >= 8);
690 section
= bfd_get_section_by_name (core_bfd
, ".note.linuxcore.file");
693 warning (_("unable to find mappings in core file"));
697 addr_size_bits
= gdbarch_addr_bit (core_gdbarch
);
698 addr_size
= addr_size_bits
/ 8;
699 note_size
= bfd_get_section_size (section
);
701 if (note_size
< 2 * addr_size
)
702 error (_("malformed core note - too short for header"));
704 contents
= xmalloc (note_size
);
705 cleanup
= make_cleanup (xfree
, contents
);
706 if (!bfd_get_section_contents (core_bfd
, section
, contents
, 0, note_size
))
707 error (_("could not get core note contents"));
710 descend
= descdata
+ note_size
;
712 if (descdata
[note_size
- 1] != '\0')
713 error (_("malformed note - does not end with \\0"));
715 count
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
716 descdata
+= addr_size
;
718 page_size
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
719 descdata
+= addr_size
;
721 if (note_size
< 2 * addr_size
+ count
* 3 * addr_size
)
722 error (_("malformed note - too short for supplied file count"));
724 printf_filtered (_("Mapped address spaces:\n\n"));
725 if (gdbarch_addr_bit (gdbarch
) == 32)
727 printf_filtered ("\t%10s %10s %10s %10s %s\n",
730 " Size", " Offset", "objfile");
734 printf_filtered (" %18s %18s %10s %10s %s\n",
737 " Size", " Offset", "objfile");
740 filenames
= descdata
+ count
* 3 * addr_size
;
743 ULONGEST start
, end
, file_ofs
;
745 if (filenames
== descend
)
746 error (_("malformed note - filenames end too early"));
748 start
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
749 descdata
+= addr_size
;
750 end
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
751 descdata
+= addr_size
;
752 file_ofs
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
753 descdata
+= addr_size
;
755 file_ofs
*= page_size
;
757 if (gdbarch_addr_bit (gdbarch
) == 32)
758 printf_filtered ("\t%10s %10s %10s %10s %s\n",
759 paddress (gdbarch
, start
),
760 paddress (gdbarch
, end
),
761 hex_string (end
- start
),
762 hex_string (file_ofs
),
765 printf_filtered (" %18s %18s %10s %10s %s\n",
766 paddress (gdbarch
, start
),
767 paddress (gdbarch
, end
),
768 hex_string (end
- start
),
769 hex_string (file_ofs
),
772 filenames
+= 1 + strlen ((char *) filenames
);
775 do_cleanups (cleanup
);
778 /* Implement "info proc" for a corefile. */
781 linux_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
782 enum info_proc_what what
)
784 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
785 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
791 exe
= bfd_core_file_failing_command (core_bfd
);
793 printf_filtered ("exe = '%s'\n", exe
);
795 warning (_("unable to find command name in core file"));
799 linux_core_info_proc_mappings (gdbarch
, args
);
801 if (!exe_f
&& !mappings_f
)
802 error (_("unable to handle request"));
805 typedef int linux_find_memory_region_ftype (ULONGEST vaddr
, ULONGEST size
,
806 ULONGEST offset
, ULONGEST inode
,
808 int exec
, int modified
,
809 const char *filename
,
812 /* List memory regions in the inferior for a corefile. */
815 linux_find_memory_regions_full (struct gdbarch
*gdbarch
,
816 linux_find_memory_region_ftype
*func
,
819 char mapsfilename
[100];
822 /* We need to know the real target PID to access /proc. */
823 if (current_inferior ()->fake_pid_p
)
826 xsnprintf (mapsfilename
, sizeof mapsfilename
,
827 "/proc/%d/smaps", current_inferior ()->pid
);
828 data
= target_fileio_read_stralloc (mapsfilename
);
831 /* Older Linux kernels did not support /proc/PID/smaps. */
832 xsnprintf (mapsfilename
, sizeof mapsfilename
,
833 "/proc/%d/maps", current_inferior ()->pid
);
834 data
= target_fileio_read_stralloc (mapsfilename
);
838 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
841 line
= strtok (data
, "\n");
844 ULONGEST addr
, endaddr
, offset
, inode
;
845 const char *permissions
, *device
, *filename
;
846 size_t permissions_len
, device_len
;
847 int read
, write
, exec
;
848 int modified
= 0, has_anonymous
= 0;
850 read_mapping (line
, &addr
, &endaddr
, &permissions
, &permissions_len
,
851 &offset
, &device
, &device_len
, &inode
, &filename
);
853 /* Decode permissions. */
854 read
= (memchr (permissions
, 'r', permissions_len
) != 0);
855 write
= (memchr (permissions
, 'w', permissions_len
) != 0);
856 exec
= (memchr (permissions
, 'x', permissions_len
) != 0);
858 /* Try to detect if region was modified by parsing smaps counters. */
859 for (line
= strtok (NULL
, "\n");
860 line
&& line
[0] >= 'A' && line
[0] <= 'Z';
861 line
= strtok (NULL
, "\n"))
863 char keyword
[64 + 1];
865 if (sscanf (line
, "%64s", keyword
) != 1)
867 warning (_("Error parsing {s,}maps file '%s'"), mapsfilename
);
870 if (strcmp (keyword
, "Anonymous:") == 0)
872 if (strcmp (keyword
, "Shared_Dirty:") == 0
873 || strcmp (keyword
, "Private_Dirty:") == 0
874 || strcmp (keyword
, "Swap:") == 0
875 || strcmp (keyword
, "Anonymous:") == 0)
877 unsigned long number
;
879 if (sscanf (line
, "%*s%lu", &number
) != 1)
881 warning (_("Error parsing {s,}maps file '%s' number"),
890 /* Older Linux kernels did not support the "Anonymous:" counter.
891 If it is missing, we can't be sure - dump all the pages. */
895 /* Invoke the callback function to create the corefile segment. */
896 func (addr
, endaddr
- addr
, offset
, inode
,
897 read
, write
, exec
, modified
, filename
, obfd
);
900 do_cleanups (cleanup
);
907 /* A structure for passing information through
908 linux_find_memory_regions_full. */
910 struct linux_find_memory_regions_data
912 /* The original callback. */
914 find_memory_region_ftype func
;
916 /* The original datum. */
921 /* A callback for linux_find_memory_regions that converts between the
922 "full"-style callback and find_memory_region_ftype. */
925 linux_find_memory_regions_thunk (ULONGEST vaddr
, ULONGEST size
,
926 ULONGEST offset
, ULONGEST inode
,
927 int read
, int write
, int exec
, int modified
,
928 const char *filename
, void *arg
)
930 struct linux_find_memory_regions_data
*data
= arg
;
932 return data
->func (vaddr
, size
, read
, write
, exec
, modified
, data
->obfd
);
935 /* A variant of linux_find_memory_regions_full that is suitable as the
936 gdbarch find_memory_regions method. */
939 linux_find_memory_regions (struct gdbarch
*gdbarch
,
940 find_memory_region_ftype func
, void *obfd
)
942 struct linux_find_memory_regions_data data
;
947 return linux_find_memory_regions_full (gdbarch
,
948 linux_find_memory_regions_thunk
,
952 /* Determine which signal stopped execution. */
955 find_signalled_thread (struct thread_info
*info
, void *data
)
957 if (info
->suspend
.stop_signal
!= GDB_SIGNAL_0
958 && ptid_get_pid (info
->ptid
) == ptid_get_pid (inferior_ptid
))
964 static enum gdb_signal
965 find_stop_signal (void)
967 struct thread_info
*info
=
968 iterate_over_threads (find_signalled_thread
, NULL
);
971 return info
->suspend
.stop_signal
;
976 /* Generate corefile notes for SPU contexts. */
979 linux_spu_make_corefile_notes (bfd
*obfd
, char *note_data
, int *note_size
)
981 static const char *spu_files
[] =
1003 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
1007 /* Determine list of SPU ids. */
1008 size
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
1011 /* Generate corefile notes for each SPU file. */
1012 for (i
= 0; i
< size
; i
+= 4)
1014 int fd
= extract_unsigned_integer (spu_ids
+ i
, 4, byte_order
);
1016 for (j
= 0; j
< sizeof (spu_files
) / sizeof (spu_files
[0]); j
++)
1018 char annex
[32], note_name
[32];
1022 xsnprintf (annex
, sizeof annex
, "%d/%s", fd
, spu_files
[j
]);
1023 spu_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
1027 xsnprintf (note_name
, sizeof note_name
, "SPU/%s", annex
);
1028 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1048 /* This is used to pass information from
1049 linux_make_mappings_corefile_notes through
1050 linux_find_memory_regions_full. */
1052 struct linux_make_mappings_data
1054 /* Number of files mapped. */
1055 ULONGEST file_count
;
1057 /* The obstack for the main part of the data. */
1058 struct obstack
*data_obstack
;
1060 /* The filename obstack. */
1061 struct obstack
*filename_obstack
;
1063 /* The architecture's "long" type. */
1064 struct type
*long_type
;
1067 static linux_find_memory_region_ftype linux_make_mappings_callback
;
1069 /* A callback for linux_find_memory_regions_full that updates the
1070 mappings data for linux_make_mappings_corefile_notes. */
1073 linux_make_mappings_callback (ULONGEST vaddr
, ULONGEST size
,
1074 ULONGEST offset
, ULONGEST inode
,
1075 int read
, int write
, int exec
, int modified
,
1076 const char *filename
, void *data
)
1078 struct linux_make_mappings_data
*map_data
= data
;
1079 gdb_byte buf
[sizeof (ULONGEST
)];
1081 if (*filename
== '\0' || inode
== 0)
1084 ++map_data
->file_count
;
1086 pack_long (buf
, map_data
->long_type
, vaddr
);
1087 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1088 pack_long (buf
, map_data
->long_type
, vaddr
+ size
);
1089 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1090 pack_long (buf
, map_data
->long_type
, offset
);
1091 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1093 obstack_grow_str0 (map_data
->filename_obstack
, filename
);
1098 /* Write the file mapping data to the core file, if possible. OBFD is
1099 the output BFD. NOTE_DATA is the current note data, and NOTE_SIZE
1100 is a pointer to the note size. Returns the new NOTE_DATA and
1101 updates NOTE_SIZE. */
1104 linux_make_mappings_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
,
1105 char *note_data
, int *note_size
)
1107 struct cleanup
*cleanup
;
1108 struct obstack data_obstack
, filename_obstack
;
1109 struct linux_make_mappings_data mapping_data
;
1110 struct type
*long_type
1111 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
), 0, "long");
1112 gdb_byte buf
[sizeof (ULONGEST
)];
1114 obstack_init (&data_obstack
);
1115 cleanup
= make_cleanup_obstack_free (&data_obstack
);
1116 obstack_init (&filename_obstack
);
1117 make_cleanup_obstack_free (&filename_obstack
);
1119 mapping_data
.file_count
= 0;
1120 mapping_data
.data_obstack
= &data_obstack
;
1121 mapping_data
.filename_obstack
= &filename_obstack
;
1122 mapping_data
.long_type
= long_type
;
1124 /* Reserve space for the count. */
1125 obstack_blank (&data_obstack
, TYPE_LENGTH (long_type
));
1126 /* We always write the page size as 1 since we have no good way to
1127 determine the correct value. */
1128 pack_long (buf
, long_type
, 1);
1129 obstack_grow (&data_obstack
, buf
, TYPE_LENGTH (long_type
));
1131 linux_find_memory_regions_full (gdbarch
, linux_make_mappings_callback
,
1134 if (mapping_data
.file_count
!= 0)
1136 /* Write the count to the obstack. */
1137 pack_long ((gdb_byte
*) obstack_base (&data_obstack
),
1138 long_type
, mapping_data
.file_count
);
1140 /* Copy the filenames to the data obstack. */
1141 obstack_grow (&data_obstack
, obstack_base (&filename_obstack
),
1142 obstack_object_size (&filename_obstack
));
1144 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1146 obstack_base (&data_obstack
),
1147 obstack_object_size (&data_obstack
));
1150 do_cleanups (cleanup
);
1154 /* Structure for passing information from
1155 linux_collect_thread_registers via an iterator to
1156 linux_collect_regset_section_cb. */
1158 struct linux_collect_regset_section_cb_data
1160 struct gdbarch
*gdbarch
;
1161 const struct regcache
*regcache
;
1166 enum gdb_signal stop_signal
;
1167 int abort_iteration
;
1170 /* Callback for iterate_over_regset_sections that records a single
1171 regset in the corefile note section. */
1174 linux_collect_regset_section_cb (const char *sect_name
, int size
,
1175 const struct regset
*regset
,
1176 const char *human_name
, void *cb_data
)
1179 struct linux_collect_regset_section_cb_data
*data
= cb_data
;
1181 if (data
->abort_iteration
)
1184 gdb_assert (regset
&& regset
->collect_regset
);
1186 buf
= xmalloc (size
);
1187 regset
->collect_regset (regset
, data
->regcache
, -1, buf
, size
);
1189 /* PRSTATUS still needs to be treated specially. */
1190 if (strcmp (sect_name
, ".reg") == 0)
1191 data
->note_data
= (char *) elfcore_write_prstatus
1192 (data
->obfd
, data
->note_data
, data
->note_size
, data
->lwp
,
1193 gdb_signal_to_host (data
->stop_signal
), buf
);
1195 data
->note_data
= (char *) elfcore_write_register_note
1196 (data
->obfd
, data
->note_data
, data
->note_size
,
1197 sect_name
, buf
, size
);
1200 if (data
->note_data
== NULL
)
1201 data
->abort_iteration
= 1;
1204 /* Records the thread's register state for the corefile note
1208 linux_collect_thread_registers (const struct regcache
*regcache
,
1209 ptid_t ptid
, bfd
*obfd
,
1210 char *note_data
, int *note_size
,
1211 enum gdb_signal stop_signal
)
1213 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1214 struct linux_collect_regset_section_cb_data data
;
1216 data
.gdbarch
= gdbarch
;
1217 data
.regcache
= regcache
;
1219 data
.note_data
= note_data
;
1220 data
.note_size
= note_size
;
1221 data
.stop_signal
= stop_signal
;
1222 data
.abort_iteration
= 0;
1224 /* For remote targets the LWP may not be available, so use the TID. */
1225 data
.lwp
= ptid_get_lwp (ptid
);
1227 data
.lwp
= ptid_get_tid (ptid
);
1229 gdbarch_iterate_over_regset_sections (gdbarch
,
1230 linux_collect_regset_section_cb
,
1232 return data
.note_data
;
1235 /* Fetch the siginfo data for the current thread, if it exists. If
1236 there is no data, or we could not read it, return NULL. Otherwise,
1237 return a newly malloc'd buffer holding the data and fill in *SIZE
1238 with the size of the data. The caller is responsible for freeing
1242 linux_get_siginfo_data (struct gdbarch
*gdbarch
, LONGEST
*size
)
1244 struct type
*siginfo_type
;
1247 struct cleanup
*cleanups
;
1249 if (!gdbarch_get_siginfo_type_p (gdbarch
))
1252 siginfo_type
= gdbarch_get_siginfo_type (gdbarch
);
1254 buf
= xmalloc (TYPE_LENGTH (siginfo_type
));
1255 cleanups
= make_cleanup (xfree
, buf
);
1257 bytes_read
= target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
1258 buf
, 0, TYPE_LENGTH (siginfo_type
));
1259 if (bytes_read
== TYPE_LENGTH (siginfo_type
))
1261 discard_cleanups (cleanups
);
1266 do_cleanups (cleanups
);
1273 struct linux_corefile_thread_data
1275 struct gdbarch
*gdbarch
;
1280 enum gdb_signal stop_signal
;
1283 /* Called by gdbthread.c once per thread. Records the thread's
1284 register state for the corefile note section. */
1287 linux_corefile_thread_callback (struct thread_info
*info
, void *data
)
1289 struct linux_corefile_thread_data
*args
= data
;
1291 /* It can be current thread
1292 which cannot be removed by update_thread_list. */
1293 if (info
->state
== THREAD_EXITED
)
1296 if (ptid_get_pid (info
->ptid
) == args
->pid
)
1298 struct cleanup
*old_chain
;
1299 struct regcache
*regcache
;
1300 gdb_byte
*siginfo_data
;
1301 LONGEST siginfo_size
= 0;
1303 regcache
= get_thread_arch_regcache (info
->ptid
, args
->gdbarch
);
1305 old_chain
= save_inferior_ptid ();
1306 inferior_ptid
= info
->ptid
;
1307 target_fetch_registers (regcache
, -1);
1308 siginfo_data
= linux_get_siginfo_data (args
->gdbarch
, &siginfo_size
);
1309 do_cleanups (old_chain
);
1311 old_chain
= make_cleanup (xfree
, siginfo_data
);
1313 args
->note_data
= linux_collect_thread_registers
1314 (regcache
, info
->ptid
, args
->obfd
, args
->note_data
,
1315 args
->note_size
, args
->stop_signal
);
1317 /* Don't return anything if we got no register information above,
1318 such a core file is useless. */
1319 if (args
->note_data
!= NULL
)
1320 if (siginfo_data
!= NULL
)
1321 args
->note_data
= elfcore_write_note (args
->obfd
,
1325 siginfo_data
, siginfo_size
);
1327 do_cleanups (old_chain
);
1330 return !args
->note_data
;
1333 /* Fill the PRPSINFO structure with information about the process being
1334 debugged. Returns 1 in case of success, 0 for failures. Please note that
1335 even if the structure cannot be entirely filled (e.g., GDB was unable to
1336 gather information about the process UID/GID), this function will still
1337 return 1 since some information was already recorded. It will only return
1338 0 iff nothing can be gathered. */
1341 linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo
*p
)
1343 /* The filename which we will use to obtain some info about the process.
1344 We will basically use this to store the `/proc/PID/FILENAME' file. */
1346 /* The full name of the program which generated the corefile. */
1348 /* The basename of the executable. */
1349 const char *basename
;
1350 /* The arguments of the program. */
1353 /* The contents of `/proc/PID/stat' and `/proc/PID/status' files. */
1354 char *proc_stat
, *proc_status
;
1355 /* Temporary buffer. */
1357 /* The valid states of a process, according to the Linux kernel. */
1358 const char valid_states
[] = "RSDTZW";
1359 /* The program state. */
1360 const char *prog_state
;
1361 /* The state of the process. */
1363 /* The PID of the program which generated the corefile. */
1365 /* Process flags. */
1366 unsigned int pr_flag
;
1367 /* Process nice value. */
1369 /* The number of fields read by `sscanf'. */
1375 gdb_assert (p
!= NULL
);
1377 /* Obtaining PID and filename. */
1378 pid
= ptid_get_pid (inferior_ptid
);
1379 xsnprintf (filename
, sizeof (filename
), "/proc/%d/cmdline", (int) pid
);
1380 fname
= target_fileio_read_stralloc (filename
);
1382 if (fname
== NULL
|| *fname
== '\0')
1384 /* No program name was read, so we won't be able to retrieve more
1385 information about the process. */
1390 c
= make_cleanup (xfree
, fname
);
1391 memset (p
, 0, sizeof (*p
));
1393 /* Defining the PID. */
1396 /* Copying the program name. Only the basename matters. */
1397 basename
= lbasename (fname
);
1398 strncpy (p
->pr_fname
, basename
, sizeof (p
->pr_fname
));
1399 p
->pr_fname
[sizeof (p
->pr_fname
) - 1] = '\0';
1401 infargs
= get_inferior_args ();
1403 psargs
= xstrdup (fname
);
1404 if (infargs
!= NULL
)
1405 psargs
= reconcat (psargs
, psargs
, " ", infargs
, NULL
);
1407 make_cleanup (xfree
, psargs
);
1409 strncpy (p
->pr_psargs
, psargs
, sizeof (p
->pr_psargs
));
1410 p
->pr_psargs
[sizeof (p
->pr_psargs
) - 1] = '\0';
1412 xsnprintf (filename
, sizeof (filename
), "/proc/%d/stat", (int) pid
);
1413 proc_stat
= target_fileio_read_stralloc (filename
);
1414 make_cleanup (xfree
, proc_stat
);
1416 if (proc_stat
== NULL
|| *proc_stat
== '\0')
1418 /* Despite being unable to read more information about the
1419 process, we return 1 here because at least we have its
1420 command line, PID and arguments. */
1425 /* Ok, we have the stats. It's time to do a little parsing of the
1426 contents of the buffer, so that we end up reading what we want.
1428 The following parsing mechanism is strongly based on the
1429 information generated by the `fs/proc/array.c' file, present in
1430 the Linux kernel tree. More details about how the information is
1431 displayed can be obtained by seeing the manpage of proc(5),
1432 specifically under the entry of `/proc/[pid]/stat'. */
1434 /* Getting rid of the PID, since we already have it. */
1435 while (isdigit (*proc_stat
))
1438 proc_stat
= skip_spaces (proc_stat
);
1440 /* ps command also relies on no trailing fields ever contain ')'. */
1441 proc_stat
= strrchr (proc_stat
, ')');
1442 if (proc_stat
== NULL
)
1449 proc_stat
= skip_spaces (proc_stat
);
1451 n_fields
= sscanf (proc_stat
,
1452 "%c" /* Process state. */
1453 "%d%d%d" /* Parent PID, group ID, session ID. */
1454 "%*d%*d" /* tty_nr, tpgid (not used). */
1456 "%*s%*s%*s%*s" /* minflt, cminflt, majflt,
1457 cmajflt (not used). */
1458 "%*s%*s%*s%*s" /* utime, stime, cutime,
1459 cstime (not used). */
1460 "%*s" /* Priority (not used). */
1463 &p
->pr_ppid
, &p
->pr_pgrp
, &p
->pr_sid
,
1469 /* Again, we couldn't read the complementary information about
1470 the process state. However, we already have minimal
1471 information, so we just return 1 here. */
1476 /* Filling the structure fields. */
1477 prog_state
= strchr (valid_states
, pr_sname
);
1478 if (prog_state
!= NULL
)
1479 p
->pr_state
= prog_state
- valid_states
;
1482 /* Zero means "Running". */
1486 p
->pr_sname
= p
->pr_state
> 5 ? '.' : pr_sname
;
1487 p
->pr_zomb
= p
->pr_sname
== 'Z';
1488 p
->pr_nice
= pr_nice
;
1489 p
->pr_flag
= pr_flag
;
1491 /* Finally, obtaining the UID and GID. For that, we read and parse the
1492 contents of the `/proc/PID/status' file. */
1493 xsnprintf (filename
, sizeof (filename
), "/proc/%d/status", (int) pid
);
1494 proc_status
= target_fileio_read_stralloc (filename
);
1495 make_cleanup (xfree
, proc_status
);
1497 if (proc_status
== NULL
|| *proc_status
== '\0')
1499 /* Returning 1 since we already have a bunch of information. */
1504 /* Extracting the UID. */
1505 tmpstr
= strstr (proc_status
, "Uid:");
1508 /* Advancing the pointer to the beginning of the UID. */
1509 tmpstr
+= sizeof ("Uid:");
1510 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1513 if (isdigit (*tmpstr
))
1514 p
->pr_uid
= strtol (tmpstr
, &tmpstr
, 10);
1517 /* Extracting the GID. */
1518 tmpstr
= strstr (proc_status
, "Gid:");
1521 /* Advancing the pointer to the beginning of the GID. */
1522 tmpstr
+= sizeof ("Gid:");
1523 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1526 if (isdigit (*tmpstr
))
1527 p
->pr_gid
= strtol (tmpstr
, &tmpstr
, 10);
1535 /* Build the note section for a corefile, and return it in a malloc
1539 linux_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
1541 struct linux_corefile_thread_data thread_args
;
1542 struct elf_internal_linux_prpsinfo prpsinfo
;
1543 char *note_data
= NULL
;
1546 volatile struct gdb_exception e
;
1548 if (! gdbarch_iterate_over_regset_sections_p (gdbarch
))
1551 if (linux_fill_prpsinfo (&prpsinfo
))
1553 if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch
))
1555 note_data
= gdbarch_elfcore_write_linux_prpsinfo (gdbarch
, obfd
,
1556 note_data
, note_size
,
1561 if (gdbarch_ptr_bit (gdbarch
) == 64)
1562 note_data
= elfcore_write_linux_prpsinfo64 (obfd
,
1563 note_data
, note_size
,
1566 note_data
= elfcore_write_linux_prpsinfo32 (obfd
,
1567 note_data
, note_size
,
1572 /* Thread register information. */
1573 TRY_CATCH (e
, RETURN_MASK_ERROR
)
1575 update_thread_list ();
1578 exception_print (gdb_stderr
, e
);
1579 thread_args
.gdbarch
= gdbarch
;
1580 thread_args
.pid
= ptid_get_pid (inferior_ptid
);
1581 thread_args
.obfd
= obfd
;
1582 thread_args
.note_data
= note_data
;
1583 thread_args
.note_size
= note_size
;
1584 thread_args
.stop_signal
= find_stop_signal ();
1585 iterate_over_threads (linux_corefile_thread_callback
, &thread_args
);
1586 note_data
= thread_args
.note_data
;
1590 /* Auxillary vector. */
1591 auxv_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_AUXV
,
1595 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1596 "CORE", NT_AUXV
, auxv
, auxv_len
);
1603 /* SPU information. */
1604 note_data
= linux_spu_make_corefile_notes (obfd
, note_data
, note_size
);
1608 /* File mappings. */
1609 note_data
= linux_make_mappings_corefile_notes (gdbarch
, obfd
,
1610 note_data
, note_size
);
1615 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
1616 gdbarch.h. This function is not static because it is exported to
1617 other -tdep files. */
1620 linux_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1625 return GDB_SIGNAL_0
;
1628 return GDB_SIGNAL_HUP
;
1631 return GDB_SIGNAL_INT
;
1634 return GDB_SIGNAL_QUIT
;
1637 return GDB_SIGNAL_ILL
;
1640 return GDB_SIGNAL_TRAP
;
1643 return GDB_SIGNAL_ABRT
;
1646 return GDB_SIGNAL_BUS
;
1649 return GDB_SIGNAL_FPE
;
1652 return GDB_SIGNAL_KILL
;
1655 return GDB_SIGNAL_USR1
;
1658 return GDB_SIGNAL_SEGV
;
1661 return GDB_SIGNAL_USR2
;
1664 return GDB_SIGNAL_PIPE
;
1667 return GDB_SIGNAL_ALRM
;
1670 return GDB_SIGNAL_TERM
;
1673 return GDB_SIGNAL_CHLD
;
1676 return GDB_SIGNAL_CONT
;
1679 return GDB_SIGNAL_STOP
;
1682 return GDB_SIGNAL_TSTP
;
1685 return GDB_SIGNAL_TTIN
;
1688 return GDB_SIGNAL_TTOU
;
1691 return GDB_SIGNAL_URG
;
1694 return GDB_SIGNAL_XCPU
;
1697 return GDB_SIGNAL_XFSZ
;
1699 case LINUX_SIGVTALRM
:
1700 return GDB_SIGNAL_VTALRM
;
1703 return GDB_SIGNAL_PROF
;
1705 case LINUX_SIGWINCH
:
1706 return GDB_SIGNAL_WINCH
;
1708 /* No way to differentiate between SIGIO and SIGPOLL.
1709 Therefore, we just handle the first one. */
1711 return GDB_SIGNAL_IO
;
1714 return GDB_SIGNAL_PWR
;
1717 return GDB_SIGNAL_SYS
;
1719 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
1720 therefore we have to handle them here. */
1721 case LINUX_SIGRTMIN
:
1722 return GDB_SIGNAL_REALTIME_32
;
1724 case LINUX_SIGRTMAX
:
1725 return GDB_SIGNAL_REALTIME_64
;
1728 if (signal
>= LINUX_SIGRTMIN
+ 1 && signal
<= LINUX_SIGRTMAX
- 1)
1730 int offset
= signal
- LINUX_SIGRTMIN
+ 1;
1732 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_33
+ offset
);
1735 return GDB_SIGNAL_UNKNOWN
;
1738 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1739 gdbarch.h. This function is not static because it is exported to
1740 other -tdep files. */
1743 linux_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1744 enum gdb_signal signal
)
1751 case GDB_SIGNAL_HUP
:
1752 return LINUX_SIGHUP
;
1754 case GDB_SIGNAL_INT
:
1755 return LINUX_SIGINT
;
1757 case GDB_SIGNAL_QUIT
:
1758 return LINUX_SIGQUIT
;
1760 case GDB_SIGNAL_ILL
:
1761 return LINUX_SIGILL
;
1763 case GDB_SIGNAL_TRAP
:
1764 return LINUX_SIGTRAP
;
1766 case GDB_SIGNAL_ABRT
:
1767 return LINUX_SIGABRT
;
1769 case GDB_SIGNAL_FPE
:
1770 return LINUX_SIGFPE
;
1772 case GDB_SIGNAL_KILL
:
1773 return LINUX_SIGKILL
;
1775 case GDB_SIGNAL_BUS
:
1776 return LINUX_SIGBUS
;
1778 case GDB_SIGNAL_SEGV
:
1779 return LINUX_SIGSEGV
;
1781 case GDB_SIGNAL_SYS
:
1782 return LINUX_SIGSYS
;
1784 case GDB_SIGNAL_PIPE
:
1785 return LINUX_SIGPIPE
;
1787 case GDB_SIGNAL_ALRM
:
1788 return LINUX_SIGALRM
;
1790 case GDB_SIGNAL_TERM
:
1791 return LINUX_SIGTERM
;
1793 case GDB_SIGNAL_URG
:
1794 return LINUX_SIGURG
;
1796 case GDB_SIGNAL_STOP
:
1797 return LINUX_SIGSTOP
;
1799 case GDB_SIGNAL_TSTP
:
1800 return LINUX_SIGTSTP
;
1802 case GDB_SIGNAL_CONT
:
1803 return LINUX_SIGCONT
;
1805 case GDB_SIGNAL_CHLD
:
1806 return LINUX_SIGCHLD
;
1808 case GDB_SIGNAL_TTIN
:
1809 return LINUX_SIGTTIN
;
1811 case GDB_SIGNAL_TTOU
:
1812 return LINUX_SIGTTOU
;
1817 case GDB_SIGNAL_XCPU
:
1818 return LINUX_SIGXCPU
;
1820 case GDB_SIGNAL_XFSZ
:
1821 return LINUX_SIGXFSZ
;
1823 case GDB_SIGNAL_VTALRM
:
1824 return LINUX_SIGVTALRM
;
1826 case GDB_SIGNAL_PROF
:
1827 return LINUX_SIGPROF
;
1829 case GDB_SIGNAL_WINCH
:
1830 return LINUX_SIGWINCH
;
1832 case GDB_SIGNAL_USR1
:
1833 return LINUX_SIGUSR1
;
1835 case GDB_SIGNAL_USR2
:
1836 return LINUX_SIGUSR2
;
1838 case GDB_SIGNAL_PWR
:
1839 return LINUX_SIGPWR
;
1841 case GDB_SIGNAL_POLL
:
1842 return LINUX_SIGPOLL
;
1844 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1845 therefore we have to handle it here. */
1846 case GDB_SIGNAL_REALTIME_32
:
1847 return LINUX_SIGRTMIN
;
1849 /* Same comment applies to _64. */
1850 case GDB_SIGNAL_REALTIME_64
:
1851 return LINUX_SIGRTMAX
;
1854 /* GDB_SIGNAL_REALTIME_33 to _64 are continuous. */
1855 if (signal
>= GDB_SIGNAL_REALTIME_33
1856 && signal
<= GDB_SIGNAL_REALTIME_63
)
1858 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1860 return LINUX_SIGRTMIN
+ 1 + offset
;
1866 /* Rummage through mappings to find a mapping's size. */
1869 find_mapping_size (CORE_ADDR vaddr
, unsigned long size
,
1870 int read
, int write
, int exec
, int modified
,
1873 struct mem_range
*range
= data
;
1875 if (vaddr
== range
->start
)
1877 range
->length
= size
;
1883 /* Helper for linux_vsyscall_range that does the real work of finding
1884 the vsyscall's address range. */
1887 linux_vsyscall_range_raw (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1889 if (target_auxv_search (¤t_target
, AT_SYSINFO_EHDR
, &range
->start
) <= 0)
1892 /* This is installed by linux_init_abi below, so should always be
1894 gdb_assert (gdbarch_find_memory_regions_p (target_gdbarch ()));
1897 gdbarch_find_memory_regions (gdbarch
, find_mapping_size
, range
);
1901 /* Implementation of the "vsyscall_range" gdbarch hook. Handles
1902 caching, and defers the real work to linux_vsyscall_range_raw. */
1905 linux_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1907 struct linux_info
*info
= get_linux_inferior_data ();
1909 if (info
->vsyscall_range_p
== 0)
1911 if (linux_vsyscall_range_raw (gdbarch
, &info
->vsyscall_range
))
1912 info
->vsyscall_range_p
= 1;
1914 info
->vsyscall_range_p
= -1;
1917 if (info
->vsyscall_range_p
< 0)
1920 *range
= info
->vsyscall_range
;
1924 /* To be called from the various GDB_OSABI_LINUX handlers for the
1925 various GNU/Linux architectures and machine types. */
1928 linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1930 set_gdbarch_core_pid_to_str (gdbarch
, linux_core_pid_to_str
);
1931 set_gdbarch_info_proc (gdbarch
, linux_info_proc
);
1932 set_gdbarch_core_info_proc (gdbarch
, linux_core_info_proc
);
1933 set_gdbarch_find_memory_regions (gdbarch
, linux_find_memory_regions
);
1934 set_gdbarch_make_corefile_notes (gdbarch
, linux_make_corefile_notes
);
1935 set_gdbarch_has_shared_address_space (gdbarch
,
1936 linux_has_shared_address_space
);
1937 set_gdbarch_gdb_signal_from_target (gdbarch
,
1938 linux_gdb_signal_from_target
);
1939 set_gdbarch_gdb_signal_to_target (gdbarch
,
1940 linux_gdb_signal_to_target
);
1941 set_gdbarch_vsyscall_range (gdbarch
, linux_vsyscall_range
);
1944 /* Provide a prototype to silence -Wmissing-prototypes. */
1945 extern initialize_file_ftype _initialize_linux_tdep
;
1948 _initialize_linux_tdep (void)
1950 linux_gdbarch_data_handle
=
1951 gdbarch_data_register_post_init (init_linux_gdbarch_data
);
1953 /* Set a cache per-inferior. */
1955 = register_inferior_data_with_cleanup (NULL
, linux_inferior_data_cleanup
);
1956 /* Observers used to invalidate the cache when needed. */
1957 observer_attach_inferior_exit (invalidate_linux_cache_inf
);
1958 observer_attach_inferior_appeared (invalidate_linux_cache_inf
);