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"
41 /* This enum represents the signals' numbers on a generic architecture
42 running the Linux kernel. The definition of "generic" comes from
43 the file <include/uapi/asm-generic/signal.h>, from the Linux kernel
44 tree, which is the "de facto" implementation of signal numbers to
45 be used by new architecture ports.
47 For those architectures which have differences between the generic
48 standard (e.g., Alpha), we define the different signals (and *only*
49 those) in the specific target-dependent file (e.g.,
50 alpha-linux-tdep.c, for Alpha). Please refer to the architecture's
51 tdep file for more information.
53 ARM deserves a special mention here. On the file
54 <arch/arm/include/uapi/asm/signal.h>, it defines only one different
55 (and ARM-only) signal, which is SIGSWI, with the same number as
56 SIGRTMIN. This signal is used only for a very specific target,
57 called ArthurOS (from RISCOS). Therefore, we do not handle it on
58 the ARM-tdep file, and we can safely use the generic signal handler
61 As stated above, this enum is derived from
62 <include/uapi/asm-generic/signal.h>, from the Linux kernel
97 LINUX_SIGPOLL
= LINUX_SIGIO
,
100 LINUX_SIGUNUSED
= 31,
106 static struct gdbarch_data
*linux_gdbarch_data_handle
;
108 struct linux_gdbarch_data
110 struct type
*siginfo_type
;
114 init_linux_gdbarch_data (struct gdbarch
*gdbarch
)
116 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct linux_gdbarch_data
);
119 static struct linux_gdbarch_data
*
120 get_linux_gdbarch_data (struct gdbarch
*gdbarch
)
122 return gdbarch_data (gdbarch
, linux_gdbarch_data_handle
);
125 /* Per-inferior data key. */
126 static const struct inferior_data
*linux_inferior_data
;
128 /* Linux-specific cached data. This is used by GDB for caching
129 purposes for each inferior. This helps reduce the overhead of
130 transfering data from a remote target to the local host. */
133 /* Cache of the inferior's vsyscall/vDSO mapping range. Only valid
134 if VSYSCALL_RANGE_P is positive. This is cached because getting
135 at this info requires an auxv lookup (which is itself cached),
136 and looking through the inferior's mappings (which change
137 throughout execution and therefore cannot be cached). */
138 struct mem_range vsyscall_range
;
140 /* Zero if we haven't tried looking up the vsyscall's range before
141 yet. Positive if we tried looking it up, and found it. Negative
142 if we tried looking it up but failed. */
143 int vsyscall_range_p
;
146 /* Frees whatever allocated space there is to be freed and sets INF's
147 linux cache data pointer to NULL. */
150 invalidate_linux_cache_inf (struct inferior
*inf
)
152 struct linux_info
*info
;
154 info
= inferior_data (inf
, linux_inferior_data
);
158 set_inferior_data (inf
, linux_inferior_data
, NULL
);
162 /* Handles the cleanup of the linux cache for inferior INF. ARG is
163 ignored. Callback for the inferior_appeared and inferior_exit
167 linux_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
169 invalidate_linux_cache_inf (inf
);
172 /* Fetch the linux cache info for INF. This function always returns a
173 valid INFO pointer. */
175 static struct linux_info
*
176 get_linux_inferior_data (void)
178 struct linux_info
*info
;
179 struct inferior
*inf
= current_inferior ();
181 info
= inferior_data (inf
, linux_inferior_data
);
184 info
= XCNEW (struct linux_info
);
185 set_inferior_data (inf
, linux_inferior_data
, info
);
191 /* This function is suitable for architectures that don't
192 extend/override the standard siginfo structure. */
195 linux_get_siginfo_type (struct gdbarch
*gdbarch
)
197 struct linux_gdbarch_data
*linux_gdbarch_data
;
198 struct type
*int_type
, *uint_type
, *long_type
, *void_ptr_type
;
199 struct type
*uid_type
, *pid_type
;
200 struct type
*sigval_type
, *clock_type
;
201 struct type
*siginfo_type
, *sifields_type
;
204 linux_gdbarch_data
= get_linux_gdbarch_data (gdbarch
);
205 if (linux_gdbarch_data
->siginfo_type
!= NULL
)
206 return linux_gdbarch_data
->siginfo_type
;
208 int_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
210 uint_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
212 long_type
= arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
214 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
217 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
218 TYPE_NAME (sigval_type
) = xstrdup ("sigval_t");
219 append_composite_type_field (sigval_type
, "sival_int", int_type
);
220 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
223 pid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
224 TYPE_LENGTH (int_type
), "__pid_t");
225 TYPE_TARGET_TYPE (pid_type
) = int_type
;
226 TYPE_TARGET_STUB (pid_type
) = 1;
229 uid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
230 TYPE_LENGTH (uint_type
), "__uid_t");
231 TYPE_TARGET_TYPE (uid_type
) = uint_type
;
232 TYPE_TARGET_STUB (uid_type
) = 1;
235 clock_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
236 TYPE_LENGTH (long_type
), "__clock_t");
237 TYPE_TARGET_TYPE (clock_type
) = long_type
;
238 TYPE_TARGET_STUB (clock_type
) = 1;
241 sifields_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
244 const int si_max_size
= 128;
246 int size_of_int
= gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
249 if (gdbarch_ptr_bit (gdbarch
) == 64)
250 si_pad_size
= (si_max_size
/ size_of_int
) - 4;
252 si_pad_size
= (si_max_size
/ size_of_int
) - 3;
253 append_composite_type_field (sifields_type
, "_pad",
254 init_vector_type (int_type
, si_pad_size
));
258 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
259 append_composite_type_field (type
, "si_pid", pid_type
);
260 append_composite_type_field (type
, "si_uid", uid_type
);
261 append_composite_type_field (sifields_type
, "_kill", type
);
264 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
265 append_composite_type_field (type
, "si_tid", int_type
);
266 append_composite_type_field (type
, "si_overrun", int_type
);
267 append_composite_type_field (type
, "si_sigval", sigval_type
);
268 append_composite_type_field (sifields_type
, "_timer", type
);
271 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
272 append_composite_type_field (type
, "si_pid", pid_type
);
273 append_composite_type_field (type
, "si_uid", uid_type
);
274 append_composite_type_field (type
, "si_sigval", sigval_type
);
275 append_composite_type_field (sifields_type
, "_rt", 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_status", int_type
);
282 append_composite_type_field (type
, "si_utime", clock_type
);
283 append_composite_type_field (type
, "si_stime", clock_type
);
284 append_composite_type_field (sifields_type
, "_sigchld", type
);
287 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
288 append_composite_type_field (type
, "si_addr", void_ptr_type
);
289 append_composite_type_field (sifields_type
, "_sigfault", type
);
292 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
293 append_composite_type_field (type
, "si_band", long_type
);
294 append_composite_type_field (type
, "si_fd", int_type
);
295 append_composite_type_field (sifields_type
, "_sigpoll", type
);
298 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
299 TYPE_NAME (siginfo_type
) = xstrdup ("siginfo");
300 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
301 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
302 append_composite_type_field (siginfo_type
, "si_code", int_type
);
303 append_composite_type_field_aligned (siginfo_type
,
304 "_sifields", sifields_type
,
305 TYPE_LENGTH (long_type
));
307 linux_gdbarch_data
->siginfo_type
= siginfo_type
;
312 /* Return true if the target is running on uClinux instead of normal
316 linux_is_uclinux (void)
320 return (target_auxv_search (¤t_target
, AT_NULL
, &dummy
) > 0
321 && target_auxv_search (¤t_target
, AT_PAGESZ
, &dummy
) == 0);
325 linux_has_shared_address_space (struct gdbarch
*gdbarch
)
327 return linux_is_uclinux ();
330 /* This is how we want PTIDs from core files to be printed. */
333 linux_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
337 if (ptid_get_lwp (ptid
) != 0)
339 snprintf (buf
, sizeof (buf
), "LWP %ld", ptid_get_lwp (ptid
));
343 return normal_pid_to_str (ptid
);
346 /* Service function for corefiles and info proc. */
349 read_mapping (const char *line
,
350 ULONGEST
*addr
, ULONGEST
*endaddr
,
351 const char **permissions
, size_t *permissions_len
,
353 const char **device
, size_t *device_len
,
355 const char **filename
)
357 const char *p
= line
;
359 *addr
= strtoulst (p
, &p
, 16);
362 *endaddr
= strtoulst (p
, &p
, 16);
364 p
= skip_spaces_const (p
);
366 while (*p
&& !isspace (*p
))
368 *permissions_len
= p
- *permissions
;
370 *offset
= strtoulst (p
, &p
, 16);
372 p
= skip_spaces_const (p
);
374 while (*p
&& !isspace (*p
))
376 *device_len
= p
- *device
;
378 *inode
= strtoulst (p
, &p
, 10);
380 p
= skip_spaces_const (p
);
384 /* Implement the "info proc" command. */
387 linux_info_proc (struct gdbarch
*gdbarch
, const char *args
,
388 enum info_proc_what what
)
390 /* A long is used for pid instead of an int to avoid a loss of precision
391 compiler warning from the output of strtoul. */
393 int cmdline_f
= (what
== IP_MINIMAL
|| what
== IP_CMDLINE
|| what
== IP_ALL
);
394 int cwd_f
= (what
== IP_MINIMAL
|| what
== IP_CWD
|| what
== IP_ALL
);
395 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
396 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
397 int status_f
= (what
== IP_STATUS
|| what
== IP_ALL
);
398 int stat_f
= (what
== IP_STAT
|| what
== IP_ALL
);
403 if (args
&& isdigit (args
[0]))
407 pid
= strtoul (args
, &tem
, 10);
412 if (!target_has_execution
)
413 error (_("No current process: you must name one."));
414 if (current_inferior ()->fake_pid_p
)
415 error (_("Can't determine the current process's PID: you must name one."));
417 pid
= current_inferior ()->pid
;
420 args
= skip_spaces_const (args
);
422 error (_("Too many parameters: %s"), args
);
424 printf_filtered (_("process %ld\n"), pid
);
427 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cmdline", pid
);
428 data
= target_fileio_read_stralloc (filename
);
431 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
432 printf_filtered ("cmdline = '%s'\n", data
);
433 do_cleanups (cleanup
);
436 warning (_("unable to open /proc file '%s'"), filename
);
440 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cwd", pid
);
441 data
= target_fileio_readlink (filename
, &target_errno
);
444 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
445 printf_filtered ("cwd = '%s'\n", data
);
446 do_cleanups (cleanup
);
449 warning (_("unable to read link '%s'"), filename
);
453 xsnprintf (filename
, sizeof filename
, "/proc/%ld/exe", pid
);
454 data
= target_fileio_readlink (filename
, &target_errno
);
457 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
458 printf_filtered ("exe = '%s'\n", data
);
459 do_cleanups (cleanup
);
462 warning (_("unable to read link '%s'"), filename
);
466 xsnprintf (filename
, sizeof filename
, "/proc/%ld/maps", pid
);
467 data
= target_fileio_read_stralloc (filename
);
470 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
473 printf_filtered (_("Mapped address spaces:\n\n"));
474 if (gdbarch_addr_bit (gdbarch
) == 32)
476 printf_filtered ("\t%10s %10s %10s %10s %s\n",
479 " Size", " Offset", "objfile");
483 printf_filtered (" %18s %18s %10s %10s %s\n",
486 " Size", " Offset", "objfile");
489 for (line
= strtok (data
, "\n"); line
; line
= strtok (NULL
, "\n"))
491 ULONGEST addr
, endaddr
, offset
, inode
;
492 const char *permissions
, *device
, *filename
;
493 size_t permissions_len
, device_len
;
495 read_mapping (line
, &addr
, &endaddr
,
496 &permissions
, &permissions_len
,
497 &offset
, &device
, &device_len
,
500 if (gdbarch_addr_bit (gdbarch
) == 32)
502 printf_filtered ("\t%10s %10s %10s %10s %s\n",
503 paddress (gdbarch
, addr
),
504 paddress (gdbarch
, endaddr
),
505 hex_string (endaddr
- addr
),
507 *filename
? filename
: "");
511 printf_filtered (" %18s %18s %10s %10s %s\n",
512 paddress (gdbarch
, addr
),
513 paddress (gdbarch
, endaddr
),
514 hex_string (endaddr
- addr
),
516 *filename
? filename
: "");
520 do_cleanups (cleanup
);
523 warning (_("unable to open /proc file '%s'"), filename
);
527 xsnprintf (filename
, sizeof filename
, "/proc/%ld/status", pid
);
528 data
= target_fileio_read_stralloc (filename
);
531 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
532 puts_filtered (data
);
533 do_cleanups (cleanup
);
536 warning (_("unable to open /proc file '%s'"), filename
);
540 xsnprintf (filename
, sizeof filename
, "/proc/%ld/stat", pid
);
541 data
= target_fileio_read_stralloc (filename
);
544 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
545 const char *p
= data
;
547 printf_filtered (_("Process: %s\n"),
548 pulongest (strtoulst (p
, &p
, 10)));
550 p
= skip_spaces_const (p
);
553 /* ps command also relies on no trailing fields
555 const char *ep
= strrchr (p
, ')');
558 printf_filtered ("Exec file: %.*s\n",
559 (int) (ep
- p
- 1), p
+ 1);
564 p
= skip_spaces_const (p
);
566 printf_filtered (_("State: %c\n"), *p
++);
569 printf_filtered (_("Parent process: %s\n"),
570 pulongest (strtoulst (p
, &p
, 10)));
572 printf_filtered (_("Process group: %s\n"),
573 pulongest (strtoulst (p
, &p
, 10)));
575 printf_filtered (_("Session id: %s\n"),
576 pulongest (strtoulst (p
, &p
, 10)));
578 printf_filtered (_("TTY: %s\n"),
579 pulongest (strtoulst (p
, &p
, 10)));
581 printf_filtered (_("TTY owner process group: %s\n"),
582 pulongest (strtoulst (p
, &p
, 10)));
585 printf_filtered (_("Flags: %s\n"),
586 hex_string (strtoulst (p
, &p
, 10)));
588 printf_filtered (_("Minor faults (no memory page): %s\n"),
589 pulongest (strtoulst (p
, &p
, 10)));
591 printf_filtered (_("Minor faults, children: %s\n"),
592 pulongest (strtoulst (p
, &p
, 10)));
594 printf_filtered (_("Major faults (memory page faults): %s\n"),
595 pulongest (strtoulst (p
, &p
, 10)));
597 printf_filtered (_("Major faults, children: %s\n"),
598 pulongest (strtoulst (p
, &p
, 10)));
600 printf_filtered (_("utime: %s\n"),
601 pulongest (strtoulst (p
, &p
, 10)));
603 printf_filtered (_("stime: %s\n"),
604 pulongest (strtoulst (p
, &p
, 10)));
606 printf_filtered (_("utime, children: %s\n"),
607 pulongest (strtoulst (p
, &p
, 10)));
609 printf_filtered (_("stime, children: %s\n"),
610 pulongest (strtoulst (p
, &p
, 10)));
612 printf_filtered (_("jiffies remaining in current "
614 pulongest (strtoulst (p
, &p
, 10)));
616 printf_filtered (_("'nice' value: %s\n"),
617 pulongest (strtoulst (p
, &p
, 10)));
619 printf_filtered (_("jiffies until next timeout: %s\n"),
620 pulongest (strtoulst (p
, &p
, 10)));
622 printf_filtered (_("jiffies until next SIGALRM: %s\n"),
623 pulongest (strtoulst (p
, &p
, 10)));
625 printf_filtered (_("start time (jiffies since "
626 "system boot): %s\n"),
627 pulongest (strtoulst (p
, &p
, 10)));
629 printf_filtered (_("Virtual memory size: %s\n"),
630 pulongest (strtoulst (p
, &p
, 10)));
632 printf_filtered (_("Resident set size: %s\n"),
633 pulongest (strtoulst (p
, &p
, 10)));
635 printf_filtered (_("rlim: %s\n"),
636 pulongest (strtoulst (p
, &p
, 10)));
638 printf_filtered (_("Start of text: %s\n"),
639 hex_string (strtoulst (p
, &p
, 10)));
641 printf_filtered (_("End of text: %s\n"),
642 hex_string (strtoulst (p
, &p
, 10)));
644 printf_filtered (_("Start of stack: %s\n"),
645 hex_string (strtoulst (p
, &p
, 10)));
646 #if 0 /* Don't know how architecture-dependent the rest is...
647 Anyway the signal bitmap info is available from "status". */
649 printf_filtered (_("Kernel stack pointer: %s\n"),
650 hex_string (strtoulst (p
, &p
, 10)));
652 printf_filtered (_("Kernel instr pointer: %s\n"),
653 hex_string (strtoulst (p
, &p
, 10)));
655 printf_filtered (_("Pending signals bitmap: %s\n"),
656 hex_string (strtoulst (p
, &p
, 10)));
658 printf_filtered (_("Blocked signals bitmap: %s\n"),
659 hex_string (strtoulst (p
, &p
, 10)));
661 printf_filtered (_("Ignored signals bitmap: %s\n"),
662 hex_string (strtoulst (p
, &p
, 10)));
664 printf_filtered (_("Catched signals bitmap: %s\n"),
665 hex_string (strtoulst (p
, &p
, 10)));
667 printf_filtered (_("wchan (system call): %s\n"),
668 hex_string (strtoulst (p
, &p
, 10)));
670 do_cleanups (cleanup
);
673 warning (_("unable to open /proc file '%s'"), filename
);
677 /* Implement "info proc mappings" for a corefile. */
680 linux_core_info_proc_mappings (struct gdbarch
*gdbarch
, const char *args
)
683 ULONGEST count
, page_size
;
684 unsigned char *descdata
, *filenames
, *descend
, *contents
;
686 unsigned int addr_size_bits
, addr_size
;
687 struct cleanup
*cleanup
;
688 struct gdbarch
*core_gdbarch
= gdbarch_from_bfd (core_bfd
);
689 /* We assume this for reading 64-bit core files. */
690 gdb_static_assert (sizeof (ULONGEST
) >= 8);
692 section
= bfd_get_section_by_name (core_bfd
, ".note.linuxcore.file");
695 warning (_("unable to find mappings in core file"));
699 addr_size_bits
= gdbarch_addr_bit (core_gdbarch
);
700 addr_size
= addr_size_bits
/ 8;
701 note_size
= bfd_get_section_size (section
);
703 if (note_size
< 2 * addr_size
)
704 error (_("malformed core note - too short for header"));
706 contents
= xmalloc (note_size
);
707 cleanup
= make_cleanup (xfree
, contents
);
708 if (!bfd_get_section_contents (core_bfd
, section
, contents
, 0, note_size
))
709 error (_("could not get core note contents"));
712 descend
= descdata
+ note_size
;
714 if (descdata
[note_size
- 1] != '\0')
715 error (_("malformed note - does not end with \\0"));
717 count
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
718 descdata
+= addr_size
;
720 page_size
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
721 descdata
+= addr_size
;
723 if (note_size
< 2 * addr_size
+ count
* 3 * addr_size
)
724 error (_("malformed note - too short for supplied file count"));
726 printf_filtered (_("Mapped address spaces:\n\n"));
727 if (gdbarch_addr_bit (gdbarch
) == 32)
729 printf_filtered ("\t%10s %10s %10s %10s %s\n",
732 " Size", " Offset", "objfile");
736 printf_filtered (" %18s %18s %10s %10s %s\n",
739 " Size", " Offset", "objfile");
742 filenames
= descdata
+ count
* 3 * addr_size
;
745 ULONGEST start
, end
, file_ofs
;
747 if (filenames
== descend
)
748 error (_("malformed note - filenames end too early"));
750 start
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
751 descdata
+= addr_size
;
752 end
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
753 descdata
+= addr_size
;
754 file_ofs
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
755 descdata
+= addr_size
;
757 file_ofs
*= page_size
;
759 if (gdbarch_addr_bit (gdbarch
) == 32)
760 printf_filtered ("\t%10s %10s %10s %10s %s\n",
761 paddress (gdbarch
, start
),
762 paddress (gdbarch
, end
),
763 hex_string (end
- start
),
764 hex_string (file_ofs
),
767 printf_filtered (" %18s %18s %10s %10s %s\n",
768 paddress (gdbarch
, start
),
769 paddress (gdbarch
, end
),
770 hex_string (end
- start
),
771 hex_string (file_ofs
),
774 filenames
+= 1 + strlen ((char *) filenames
);
777 do_cleanups (cleanup
);
780 /* Implement "info proc" for a corefile. */
783 linux_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
784 enum info_proc_what what
)
786 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
787 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
793 exe
= bfd_core_file_failing_command (core_bfd
);
795 printf_filtered ("exe = '%s'\n", exe
);
797 warning (_("unable to find command name in core file"));
801 linux_core_info_proc_mappings (gdbarch
, args
);
803 if (!exe_f
&& !mappings_f
)
804 error (_("unable to handle request"));
807 typedef int linux_find_memory_region_ftype (ULONGEST vaddr
, ULONGEST size
,
808 ULONGEST offset
, ULONGEST inode
,
810 int exec
, int modified
,
811 const char *filename
,
814 /* List memory regions in the inferior for a corefile. */
817 linux_find_memory_regions_full (struct gdbarch
*gdbarch
,
818 linux_find_memory_region_ftype
*func
,
821 char mapsfilename
[100];
824 /* We need to know the real target PID to access /proc. */
825 if (current_inferior ()->fake_pid_p
)
828 xsnprintf (mapsfilename
, sizeof mapsfilename
,
829 "/proc/%d/smaps", current_inferior ()->pid
);
830 data
= target_fileio_read_stralloc (mapsfilename
);
833 /* Older Linux kernels did not support /proc/PID/smaps. */
834 xsnprintf (mapsfilename
, sizeof mapsfilename
,
835 "/proc/%d/maps", current_inferior ()->pid
);
836 data
= target_fileio_read_stralloc (mapsfilename
);
840 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
843 line
= strtok (data
, "\n");
846 ULONGEST addr
, endaddr
, offset
, inode
;
847 const char *permissions
, *device
, *filename
;
848 size_t permissions_len
, device_len
;
849 int read
, write
, exec
;
850 int modified
= 0, has_anonymous
= 0;
852 read_mapping (line
, &addr
, &endaddr
, &permissions
, &permissions_len
,
853 &offset
, &device
, &device_len
, &inode
, &filename
);
855 /* Decode permissions. */
856 read
= (memchr (permissions
, 'r', permissions_len
) != 0);
857 write
= (memchr (permissions
, 'w', permissions_len
) != 0);
858 exec
= (memchr (permissions
, 'x', permissions_len
) != 0);
860 /* Try to detect if region was modified by parsing smaps counters. */
861 for (line
= strtok (NULL
, "\n");
862 line
&& line
[0] >= 'A' && line
[0] <= 'Z';
863 line
= strtok (NULL
, "\n"))
865 char keyword
[64 + 1];
867 if (sscanf (line
, "%64s", keyword
) != 1)
869 warning (_("Error parsing {s,}maps file '%s'"), mapsfilename
);
872 if (strcmp (keyword
, "Anonymous:") == 0)
874 if (strcmp (keyword
, "Shared_Dirty:") == 0
875 || strcmp (keyword
, "Private_Dirty:") == 0
876 || strcmp (keyword
, "Swap:") == 0
877 || strcmp (keyword
, "Anonymous:") == 0)
879 unsigned long number
;
881 if (sscanf (line
, "%*s%lu", &number
) != 1)
883 warning (_("Error parsing {s,}maps file '%s' number"),
892 /* Older Linux kernels did not support the "Anonymous:" counter.
893 If it is missing, we can't be sure - dump all the pages. */
897 /* Invoke the callback function to create the corefile segment. */
898 func (addr
, endaddr
- addr
, offset
, inode
,
899 read
, write
, exec
, modified
, filename
, obfd
);
902 do_cleanups (cleanup
);
909 /* A structure for passing information through
910 linux_find_memory_regions_full. */
912 struct linux_find_memory_regions_data
914 /* The original callback. */
916 find_memory_region_ftype func
;
918 /* The original datum. */
923 /* A callback for linux_find_memory_regions that converts between the
924 "full"-style callback and find_memory_region_ftype. */
927 linux_find_memory_regions_thunk (ULONGEST vaddr
, ULONGEST size
,
928 ULONGEST offset
, ULONGEST inode
,
929 int read
, int write
, int exec
, int modified
,
930 const char *filename
, void *arg
)
932 struct linux_find_memory_regions_data
*data
= arg
;
934 return data
->func (vaddr
, size
, read
, write
, exec
, modified
, data
->obfd
);
937 /* A variant of linux_find_memory_regions_full that is suitable as the
938 gdbarch find_memory_regions method. */
941 linux_find_memory_regions (struct gdbarch
*gdbarch
,
942 find_memory_region_ftype func
, void *obfd
)
944 struct linux_find_memory_regions_data data
;
949 return linux_find_memory_regions_full (gdbarch
,
950 linux_find_memory_regions_thunk
,
954 /* Determine which signal stopped execution. */
957 find_signalled_thread (struct thread_info
*info
, void *data
)
959 if (info
->suspend
.stop_signal
!= GDB_SIGNAL_0
960 && ptid_get_pid (info
->ptid
) == ptid_get_pid (inferior_ptid
))
966 static enum gdb_signal
967 find_stop_signal (void)
969 struct thread_info
*info
=
970 iterate_over_threads (find_signalled_thread
, NULL
);
973 return info
->suspend
.stop_signal
;
978 /* Generate corefile notes for SPU contexts. */
981 linux_spu_make_corefile_notes (bfd
*obfd
, char *note_data
, int *note_size
)
983 static const char *spu_files
[] =
1005 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
1009 /* Determine list of SPU ids. */
1010 size
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
1013 /* Generate corefile notes for each SPU file. */
1014 for (i
= 0; i
< size
; i
+= 4)
1016 int fd
= extract_unsigned_integer (spu_ids
+ i
, 4, byte_order
);
1018 for (j
= 0; j
< sizeof (spu_files
) / sizeof (spu_files
[0]); j
++)
1020 char annex
[32], note_name
[32];
1024 xsnprintf (annex
, sizeof annex
, "%d/%s", fd
, spu_files
[j
]);
1025 spu_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
1029 xsnprintf (note_name
, sizeof note_name
, "SPU/%s", annex
);
1030 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1050 /* This is used to pass information from
1051 linux_make_mappings_corefile_notes through
1052 linux_find_memory_regions_full. */
1054 struct linux_make_mappings_data
1056 /* Number of files mapped. */
1057 ULONGEST file_count
;
1059 /* The obstack for the main part of the data. */
1060 struct obstack
*data_obstack
;
1062 /* The filename obstack. */
1063 struct obstack
*filename_obstack
;
1065 /* The architecture's "long" type. */
1066 struct type
*long_type
;
1069 static linux_find_memory_region_ftype linux_make_mappings_callback
;
1071 /* A callback for linux_find_memory_regions_full that updates the
1072 mappings data for linux_make_mappings_corefile_notes. */
1075 linux_make_mappings_callback (ULONGEST vaddr
, ULONGEST size
,
1076 ULONGEST offset
, ULONGEST inode
,
1077 int read
, int write
, int exec
, int modified
,
1078 const char *filename
, void *data
)
1080 struct linux_make_mappings_data
*map_data
= data
;
1081 gdb_byte buf
[sizeof (ULONGEST
)];
1083 if (*filename
== '\0' || inode
== 0)
1086 ++map_data
->file_count
;
1088 pack_long (buf
, map_data
->long_type
, vaddr
);
1089 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1090 pack_long (buf
, map_data
->long_type
, vaddr
+ size
);
1091 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1092 pack_long (buf
, map_data
->long_type
, offset
);
1093 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1095 obstack_grow_str0 (map_data
->filename_obstack
, filename
);
1100 /* Write the file mapping data to the core file, if possible. OBFD is
1101 the output BFD. NOTE_DATA is the current note data, and NOTE_SIZE
1102 is a pointer to the note size. Returns the new NOTE_DATA and
1103 updates NOTE_SIZE. */
1106 linux_make_mappings_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
,
1107 char *note_data
, int *note_size
)
1109 struct cleanup
*cleanup
;
1110 struct obstack data_obstack
, filename_obstack
;
1111 struct linux_make_mappings_data mapping_data
;
1112 struct type
*long_type
1113 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
), 0, "long");
1114 gdb_byte buf
[sizeof (ULONGEST
)];
1116 obstack_init (&data_obstack
);
1117 cleanup
= make_cleanup_obstack_free (&data_obstack
);
1118 obstack_init (&filename_obstack
);
1119 make_cleanup_obstack_free (&filename_obstack
);
1121 mapping_data
.file_count
= 0;
1122 mapping_data
.data_obstack
= &data_obstack
;
1123 mapping_data
.filename_obstack
= &filename_obstack
;
1124 mapping_data
.long_type
= long_type
;
1126 /* Reserve space for the count. */
1127 obstack_blank (&data_obstack
, TYPE_LENGTH (long_type
));
1128 /* We always write the page size as 1 since we have no good way to
1129 determine the correct value. */
1130 pack_long (buf
, long_type
, 1);
1131 obstack_grow (&data_obstack
, buf
, TYPE_LENGTH (long_type
));
1133 linux_find_memory_regions_full (gdbarch
, linux_make_mappings_callback
,
1136 if (mapping_data
.file_count
!= 0)
1138 /* Write the count to the obstack. */
1139 pack_long ((gdb_byte
*) obstack_base (&data_obstack
),
1140 long_type
, mapping_data
.file_count
);
1142 /* Copy the filenames to the data obstack. */
1143 obstack_grow (&data_obstack
, obstack_base (&filename_obstack
),
1144 obstack_object_size (&filename_obstack
));
1146 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1148 obstack_base (&data_obstack
),
1149 obstack_object_size (&data_obstack
));
1152 do_cleanups (cleanup
);
1156 /* Structure for passing information from
1157 linux_collect_thread_registers via an iterator to
1158 linux_collect_regset_section_cb. */
1160 struct linux_collect_regset_section_cb_data
1162 struct gdbarch
*gdbarch
;
1163 const struct regcache
*regcache
;
1168 enum gdb_signal stop_signal
;
1169 int abort_iteration
;
1172 /* Callback for iterate_over_regset_sections that records a single
1173 regset in the corefile note section. */
1176 linux_collect_regset_section_cb (const char *sect_name
, int size
,
1177 const struct regset
*regset
,
1178 const char *human_name
, void *cb_data
)
1181 struct linux_collect_regset_section_cb_data
*data
= cb_data
;
1183 if (data
->abort_iteration
)
1186 gdb_assert (regset
&& regset
->collect_regset
);
1188 buf
= xmalloc (size
);
1189 regset
->collect_regset (regset
, data
->regcache
, -1, buf
, size
);
1191 /* PRSTATUS still needs to be treated specially. */
1192 if (strcmp (sect_name
, ".reg") == 0)
1193 data
->note_data
= (char *) elfcore_write_prstatus
1194 (data
->obfd
, data
->note_data
, data
->note_size
, data
->lwp
,
1195 gdb_signal_to_host (data
->stop_signal
), buf
);
1197 data
->note_data
= (char *) elfcore_write_register_note
1198 (data
->obfd
, data
->note_data
, data
->note_size
,
1199 sect_name
, buf
, size
);
1202 if (data
->note_data
== NULL
)
1203 data
->abort_iteration
= 1;
1206 /* Records the thread's register state for the corefile note
1210 linux_collect_thread_registers (const struct regcache
*regcache
,
1211 ptid_t ptid
, bfd
*obfd
,
1212 char *note_data
, int *note_size
,
1213 enum gdb_signal stop_signal
)
1215 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1216 struct linux_collect_regset_section_cb_data data
;
1218 data
.gdbarch
= gdbarch
;
1219 data
.regcache
= regcache
;
1221 data
.note_data
= note_data
;
1222 data
.note_size
= note_size
;
1223 data
.stop_signal
= stop_signal
;
1224 data
.abort_iteration
= 0;
1226 /* For remote targets the LWP may not be available, so use the TID. */
1227 data
.lwp
= ptid_get_lwp (ptid
);
1229 data
.lwp
= ptid_get_tid (ptid
);
1231 gdbarch_iterate_over_regset_sections (gdbarch
,
1232 linux_collect_regset_section_cb
,
1234 return data
.note_data
;
1237 /* Fetch the siginfo data for the current thread, if it exists. If
1238 there is no data, or we could not read it, return NULL. Otherwise,
1239 return a newly malloc'd buffer holding the data and fill in *SIZE
1240 with the size of the data. The caller is responsible for freeing
1244 linux_get_siginfo_data (struct gdbarch
*gdbarch
, LONGEST
*size
)
1246 struct type
*siginfo_type
;
1249 struct cleanup
*cleanups
;
1251 if (!gdbarch_get_siginfo_type_p (gdbarch
))
1254 siginfo_type
= gdbarch_get_siginfo_type (gdbarch
);
1256 buf
= xmalloc (TYPE_LENGTH (siginfo_type
));
1257 cleanups
= make_cleanup (xfree
, buf
);
1259 bytes_read
= target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
1260 buf
, 0, TYPE_LENGTH (siginfo_type
));
1261 if (bytes_read
== TYPE_LENGTH (siginfo_type
))
1263 discard_cleanups (cleanups
);
1268 do_cleanups (cleanups
);
1275 struct linux_corefile_thread_data
1277 struct gdbarch
*gdbarch
;
1282 enum gdb_signal stop_signal
;
1285 /* Called by gdbthread.c once per thread. Records the thread's
1286 register state for the corefile note section. */
1289 linux_corefile_thread_callback (struct thread_info
*info
, void *data
)
1291 struct linux_corefile_thread_data
*args
= data
;
1293 /* It can be current thread
1294 which cannot be removed by update_thread_list. */
1295 if (info
->state
== THREAD_EXITED
)
1298 if (ptid_get_pid (info
->ptid
) == args
->pid
)
1300 struct cleanup
*old_chain
;
1301 struct regcache
*regcache
;
1302 gdb_byte
*siginfo_data
;
1303 LONGEST siginfo_size
= 0;
1305 regcache
= get_thread_arch_regcache (info
->ptid
, args
->gdbarch
);
1307 old_chain
= save_inferior_ptid ();
1308 inferior_ptid
= info
->ptid
;
1309 target_fetch_registers (regcache
, -1);
1310 siginfo_data
= linux_get_siginfo_data (args
->gdbarch
, &siginfo_size
);
1311 do_cleanups (old_chain
);
1313 old_chain
= make_cleanup (xfree
, siginfo_data
);
1315 args
->note_data
= linux_collect_thread_registers
1316 (regcache
, info
->ptid
, args
->obfd
, args
->note_data
,
1317 args
->note_size
, args
->stop_signal
);
1319 /* Don't return anything if we got no register information above,
1320 such a core file is useless. */
1321 if (args
->note_data
!= NULL
)
1322 if (siginfo_data
!= NULL
)
1323 args
->note_data
= elfcore_write_note (args
->obfd
,
1327 siginfo_data
, siginfo_size
);
1329 do_cleanups (old_chain
);
1332 return !args
->note_data
;
1335 /* Fill the PRPSINFO structure with information about the process being
1336 debugged. Returns 1 in case of success, 0 for failures. Please note that
1337 even if the structure cannot be entirely filled (e.g., GDB was unable to
1338 gather information about the process UID/GID), this function will still
1339 return 1 since some information was already recorded. It will only return
1340 0 iff nothing can be gathered. */
1343 linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo
*p
)
1345 /* The filename which we will use to obtain some info about the process.
1346 We will basically use this to store the `/proc/PID/FILENAME' file. */
1348 /* The full name of the program which generated the corefile. */
1350 /* The basename of the executable. */
1351 const char *basename
;
1352 /* The arguments of the program. */
1355 /* The contents of `/proc/PID/stat' and `/proc/PID/status' files. */
1356 char *proc_stat
, *proc_status
;
1357 /* Temporary buffer. */
1359 /* The valid states of a process, according to the Linux kernel. */
1360 const char valid_states
[] = "RSDTZW";
1361 /* The program state. */
1362 const char *prog_state
;
1363 /* The state of the process. */
1365 /* The PID of the program which generated the corefile. */
1367 /* Process flags. */
1368 unsigned int pr_flag
;
1369 /* Process nice value. */
1371 /* The number of fields read by `sscanf'. */
1377 gdb_assert (p
!= NULL
);
1379 /* Obtaining PID and filename. */
1380 pid
= ptid_get_pid (inferior_ptid
);
1381 xsnprintf (filename
, sizeof (filename
), "/proc/%d/cmdline", (int) pid
);
1382 fname
= target_fileio_read_stralloc (filename
);
1384 if (fname
== NULL
|| *fname
== '\0')
1386 /* No program name was read, so we won't be able to retrieve more
1387 information about the process. */
1392 c
= make_cleanup (xfree
, fname
);
1393 memset (p
, 0, sizeof (*p
));
1395 /* Defining the PID. */
1398 /* Copying the program name. Only the basename matters. */
1399 basename
= lbasename (fname
);
1400 strncpy (p
->pr_fname
, basename
, sizeof (p
->pr_fname
));
1401 p
->pr_fname
[sizeof (p
->pr_fname
) - 1] = '\0';
1403 infargs
= get_inferior_args ();
1405 psargs
= xstrdup (fname
);
1406 if (infargs
!= NULL
)
1407 psargs
= reconcat (psargs
, psargs
, " ", infargs
, NULL
);
1409 make_cleanup (xfree
, psargs
);
1411 strncpy (p
->pr_psargs
, psargs
, sizeof (p
->pr_psargs
));
1412 p
->pr_psargs
[sizeof (p
->pr_psargs
) - 1] = '\0';
1414 xsnprintf (filename
, sizeof (filename
), "/proc/%d/stat", (int) pid
);
1415 proc_stat
= target_fileio_read_stralloc (filename
);
1416 make_cleanup (xfree
, proc_stat
);
1418 if (proc_stat
== NULL
|| *proc_stat
== '\0')
1420 /* Despite being unable to read more information about the
1421 process, we return 1 here because at least we have its
1422 command line, PID and arguments. */
1427 /* Ok, we have the stats. It's time to do a little parsing of the
1428 contents of the buffer, so that we end up reading what we want.
1430 The following parsing mechanism is strongly based on the
1431 information generated by the `fs/proc/array.c' file, present in
1432 the Linux kernel tree. More details about how the information is
1433 displayed can be obtained by seeing the manpage of proc(5),
1434 specifically under the entry of `/proc/[pid]/stat'. */
1436 /* Getting rid of the PID, since we already have it. */
1437 while (isdigit (*proc_stat
))
1440 proc_stat
= skip_spaces (proc_stat
);
1442 /* ps command also relies on no trailing fields ever contain ')'. */
1443 proc_stat
= strrchr (proc_stat
, ')');
1444 if (proc_stat
== NULL
)
1451 proc_stat
= skip_spaces (proc_stat
);
1453 n_fields
= sscanf (proc_stat
,
1454 "%c" /* Process state. */
1455 "%d%d%d" /* Parent PID, group ID, session ID. */
1456 "%*d%*d" /* tty_nr, tpgid (not used). */
1458 "%*s%*s%*s%*s" /* minflt, cminflt, majflt,
1459 cmajflt (not used). */
1460 "%*s%*s%*s%*s" /* utime, stime, cutime,
1461 cstime (not used). */
1462 "%*s" /* Priority (not used). */
1465 &p
->pr_ppid
, &p
->pr_pgrp
, &p
->pr_sid
,
1471 /* Again, we couldn't read the complementary information about
1472 the process state. However, we already have minimal
1473 information, so we just return 1 here. */
1478 /* Filling the structure fields. */
1479 prog_state
= strchr (valid_states
, pr_sname
);
1480 if (prog_state
!= NULL
)
1481 p
->pr_state
= prog_state
- valid_states
;
1484 /* Zero means "Running". */
1488 p
->pr_sname
= p
->pr_state
> 5 ? '.' : pr_sname
;
1489 p
->pr_zomb
= p
->pr_sname
== 'Z';
1490 p
->pr_nice
= pr_nice
;
1491 p
->pr_flag
= pr_flag
;
1493 /* Finally, obtaining the UID and GID. For that, we read and parse the
1494 contents of the `/proc/PID/status' file. */
1495 xsnprintf (filename
, sizeof (filename
), "/proc/%d/status", (int) pid
);
1496 proc_status
= target_fileio_read_stralloc (filename
);
1497 make_cleanup (xfree
, proc_status
);
1499 if (proc_status
== NULL
|| *proc_status
== '\0')
1501 /* Returning 1 since we already have a bunch of information. */
1506 /* Extracting the UID. */
1507 tmpstr
= strstr (proc_status
, "Uid:");
1510 /* Advancing the pointer to the beginning of the UID. */
1511 tmpstr
+= sizeof ("Uid:");
1512 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1515 if (isdigit (*tmpstr
))
1516 p
->pr_uid
= strtol (tmpstr
, &tmpstr
, 10);
1519 /* Extracting the GID. */
1520 tmpstr
= strstr (proc_status
, "Gid:");
1523 /* Advancing the pointer to the beginning of the GID. */
1524 tmpstr
+= sizeof ("Gid:");
1525 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1528 if (isdigit (*tmpstr
))
1529 p
->pr_gid
= strtol (tmpstr
, &tmpstr
, 10);
1537 /* Build the note section for a corefile, and return it in a malloc
1541 linux_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
1543 struct linux_corefile_thread_data thread_args
;
1544 struct elf_internal_linux_prpsinfo prpsinfo
;
1545 char *note_data
= NULL
;
1548 volatile struct gdb_exception e
;
1550 if (! gdbarch_iterate_over_regset_sections_p (gdbarch
))
1553 if (linux_fill_prpsinfo (&prpsinfo
))
1555 if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch
))
1557 note_data
= gdbarch_elfcore_write_linux_prpsinfo (gdbarch
, obfd
,
1558 note_data
, note_size
,
1563 if (gdbarch_ptr_bit (gdbarch
) == 64)
1564 note_data
= elfcore_write_linux_prpsinfo64 (obfd
,
1565 note_data
, note_size
,
1568 note_data
= elfcore_write_linux_prpsinfo32 (obfd
,
1569 note_data
, note_size
,
1574 /* Thread register information. */
1575 TRY_CATCH (e
, RETURN_MASK_ERROR
)
1577 update_thread_list ();
1580 exception_print (gdb_stderr
, e
);
1581 thread_args
.gdbarch
= gdbarch
;
1582 thread_args
.pid
= ptid_get_pid (inferior_ptid
);
1583 thread_args
.obfd
= obfd
;
1584 thread_args
.note_data
= note_data
;
1585 thread_args
.note_size
= note_size
;
1586 thread_args
.stop_signal
= find_stop_signal ();
1587 iterate_over_threads (linux_corefile_thread_callback
, &thread_args
);
1588 note_data
= thread_args
.note_data
;
1592 /* Auxillary vector. */
1593 auxv_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_AUXV
,
1597 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1598 "CORE", NT_AUXV
, auxv
, auxv_len
);
1605 /* SPU information. */
1606 note_data
= linux_spu_make_corefile_notes (obfd
, note_data
, note_size
);
1610 /* File mappings. */
1611 note_data
= linux_make_mappings_corefile_notes (gdbarch
, obfd
,
1612 note_data
, note_size
);
1617 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
1618 gdbarch.h. This function is not static because it is exported to
1619 other -tdep files. */
1622 linux_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1627 return GDB_SIGNAL_0
;
1630 return GDB_SIGNAL_HUP
;
1633 return GDB_SIGNAL_INT
;
1636 return GDB_SIGNAL_QUIT
;
1639 return GDB_SIGNAL_ILL
;
1642 return GDB_SIGNAL_TRAP
;
1645 return GDB_SIGNAL_ABRT
;
1648 return GDB_SIGNAL_BUS
;
1651 return GDB_SIGNAL_FPE
;
1654 return GDB_SIGNAL_KILL
;
1657 return GDB_SIGNAL_USR1
;
1660 return GDB_SIGNAL_SEGV
;
1663 return GDB_SIGNAL_USR2
;
1666 return GDB_SIGNAL_PIPE
;
1669 return GDB_SIGNAL_ALRM
;
1672 return GDB_SIGNAL_TERM
;
1675 return GDB_SIGNAL_CHLD
;
1678 return GDB_SIGNAL_CONT
;
1681 return GDB_SIGNAL_STOP
;
1684 return GDB_SIGNAL_TSTP
;
1687 return GDB_SIGNAL_TTIN
;
1690 return GDB_SIGNAL_TTOU
;
1693 return GDB_SIGNAL_URG
;
1696 return GDB_SIGNAL_XCPU
;
1699 return GDB_SIGNAL_XFSZ
;
1701 case LINUX_SIGVTALRM
:
1702 return GDB_SIGNAL_VTALRM
;
1705 return GDB_SIGNAL_PROF
;
1707 case LINUX_SIGWINCH
:
1708 return GDB_SIGNAL_WINCH
;
1710 /* No way to differentiate between SIGIO and SIGPOLL.
1711 Therefore, we just handle the first one. */
1713 return GDB_SIGNAL_IO
;
1716 return GDB_SIGNAL_PWR
;
1719 return GDB_SIGNAL_SYS
;
1721 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
1722 therefore we have to handle them here. */
1723 case LINUX_SIGRTMIN
:
1724 return GDB_SIGNAL_REALTIME_32
;
1726 case LINUX_SIGRTMAX
:
1727 return GDB_SIGNAL_REALTIME_64
;
1730 if (signal
>= LINUX_SIGRTMIN
+ 1 && signal
<= LINUX_SIGRTMAX
- 1)
1732 int offset
= signal
- LINUX_SIGRTMIN
+ 1;
1734 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_33
+ offset
);
1737 return GDB_SIGNAL_UNKNOWN
;
1740 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1741 gdbarch.h. This function is not static because it is exported to
1742 other -tdep files. */
1745 linux_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1746 enum gdb_signal signal
)
1753 case GDB_SIGNAL_HUP
:
1754 return LINUX_SIGHUP
;
1756 case GDB_SIGNAL_INT
:
1757 return LINUX_SIGINT
;
1759 case GDB_SIGNAL_QUIT
:
1760 return LINUX_SIGQUIT
;
1762 case GDB_SIGNAL_ILL
:
1763 return LINUX_SIGILL
;
1765 case GDB_SIGNAL_TRAP
:
1766 return LINUX_SIGTRAP
;
1768 case GDB_SIGNAL_ABRT
:
1769 return LINUX_SIGABRT
;
1771 case GDB_SIGNAL_FPE
:
1772 return LINUX_SIGFPE
;
1774 case GDB_SIGNAL_KILL
:
1775 return LINUX_SIGKILL
;
1777 case GDB_SIGNAL_BUS
:
1778 return LINUX_SIGBUS
;
1780 case GDB_SIGNAL_SEGV
:
1781 return LINUX_SIGSEGV
;
1783 case GDB_SIGNAL_SYS
:
1784 return LINUX_SIGSYS
;
1786 case GDB_SIGNAL_PIPE
:
1787 return LINUX_SIGPIPE
;
1789 case GDB_SIGNAL_ALRM
:
1790 return LINUX_SIGALRM
;
1792 case GDB_SIGNAL_TERM
:
1793 return LINUX_SIGTERM
;
1795 case GDB_SIGNAL_URG
:
1796 return LINUX_SIGURG
;
1798 case GDB_SIGNAL_STOP
:
1799 return LINUX_SIGSTOP
;
1801 case GDB_SIGNAL_TSTP
:
1802 return LINUX_SIGTSTP
;
1804 case GDB_SIGNAL_CONT
:
1805 return LINUX_SIGCONT
;
1807 case GDB_SIGNAL_CHLD
:
1808 return LINUX_SIGCHLD
;
1810 case GDB_SIGNAL_TTIN
:
1811 return LINUX_SIGTTIN
;
1813 case GDB_SIGNAL_TTOU
:
1814 return LINUX_SIGTTOU
;
1819 case GDB_SIGNAL_XCPU
:
1820 return LINUX_SIGXCPU
;
1822 case GDB_SIGNAL_XFSZ
:
1823 return LINUX_SIGXFSZ
;
1825 case GDB_SIGNAL_VTALRM
:
1826 return LINUX_SIGVTALRM
;
1828 case GDB_SIGNAL_PROF
:
1829 return LINUX_SIGPROF
;
1831 case GDB_SIGNAL_WINCH
:
1832 return LINUX_SIGWINCH
;
1834 case GDB_SIGNAL_USR1
:
1835 return LINUX_SIGUSR1
;
1837 case GDB_SIGNAL_USR2
:
1838 return LINUX_SIGUSR2
;
1840 case GDB_SIGNAL_PWR
:
1841 return LINUX_SIGPWR
;
1843 case GDB_SIGNAL_POLL
:
1844 return LINUX_SIGPOLL
;
1846 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1847 therefore we have to handle it here. */
1848 case GDB_SIGNAL_REALTIME_32
:
1849 return LINUX_SIGRTMIN
;
1851 /* Same comment applies to _64. */
1852 case GDB_SIGNAL_REALTIME_64
:
1853 return LINUX_SIGRTMAX
;
1856 /* GDB_SIGNAL_REALTIME_33 to _64 are continuous. */
1857 if (signal
>= GDB_SIGNAL_REALTIME_33
1858 && signal
<= GDB_SIGNAL_REALTIME_63
)
1860 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1862 return LINUX_SIGRTMIN
+ 1 + offset
;
1868 /* Rummage through mappings to find a mapping's size. */
1871 find_mapping_size (CORE_ADDR vaddr
, unsigned long size
,
1872 int read
, int write
, int exec
, int modified
,
1875 struct mem_range
*range
= data
;
1877 if (vaddr
== range
->start
)
1879 range
->length
= size
;
1885 /* Helper for linux_vsyscall_range that does the real work of finding
1886 the vsyscall's address range. */
1889 linux_vsyscall_range_raw (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1891 if (target_auxv_search (¤t_target
, AT_SYSINFO_EHDR
, &range
->start
) <= 0)
1894 /* This is installed by linux_init_abi below, so should always be
1896 gdb_assert (gdbarch_find_memory_regions_p (target_gdbarch ()));
1899 gdbarch_find_memory_regions (gdbarch
, find_mapping_size
, range
);
1903 /* Implementation of the "vsyscall_range" gdbarch hook. Handles
1904 caching, and defers the real work to linux_vsyscall_range_raw. */
1907 linux_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
1909 struct linux_info
*info
= get_linux_inferior_data ();
1911 if (info
->vsyscall_range_p
== 0)
1913 if (linux_vsyscall_range_raw (gdbarch
, &info
->vsyscall_range
))
1914 info
->vsyscall_range_p
= 1;
1916 info
->vsyscall_range_p
= -1;
1919 if (info
->vsyscall_range_p
< 0)
1922 *range
= info
->vsyscall_range
;
1926 /* Symbols for linux_infcall_mmap's ARG_FLAGS; their Linux MAP_* system
1927 definitions would be dependent on compilation host. */
1928 #define GDB_MMAP_MAP_PRIVATE 0x02 /* Changes are private. */
1929 #define GDB_MMAP_MAP_ANONYMOUS 0x20 /* Don't use a file. */
1931 /* See gdbarch.sh 'infcall_mmap'. */
1934 linux_infcall_mmap (CORE_ADDR size
, unsigned prot
)
1936 struct objfile
*objf
;
1937 /* Do there still exist any Linux systems without "mmap64"?
1938 "mmap" uses 64-bit off_t on x86_64 and 32-bit off_t on i386 and x32. */
1939 struct value
*mmap_val
= find_function_in_inferior ("mmap64", &objf
);
1940 struct value
*addr_val
;
1941 struct gdbarch
*gdbarch
= get_objfile_arch (objf
);
1945 ARG_ADDR
, ARG_LENGTH
, ARG_PROT
, ARG_FLAGS
, ARG_FD
, ARG_OFFSET
, ARG_LAST
1947 struct value
*arg
[ARG_LAST
];
1949 arg
[ARG_ADDR
] = value_from_pointer (builtin_type (gdbarch
)->builtin_data_ptr
,
1951 /* Assuming sizeof (unsigned long) == sizeof (size_t). */
1952 arg
[ARG_LENGTH
] = value_from_ulongest
1953 (builtin_type (gdbarch
)->builtin_unsigned_long
, size
);
1954 gdb_assert ((prot
& ~(GDB_MMAP_PROT_READ
| GDB_MMAP_PROT_WRITE
1955 | GDB_MMAP_PROT_EXEC
))
1957 arg
[ARG_PROT
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, prot
);
1958 arg
[ARG_FLAGS
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
,
1959 GDB_MMAP_MAP_PRIVATE
1960 | GDB_MMAP_MAP_ANONYMOUS
);
1961 arg
[ARG_FD
] = value_from_longest (builtin_type (gdbarch
)->builtin_int
, -1);
1962 arg
[ARG_OFFSET
] = value_from_longest (builtin_type (gdbarch
)->builtin_int64
,
1964 addr_val
= call_function_by_hand (mmap_val
, ARG_LAST
, arg
);
1965 retval
= value_as_address (addr_val
);
1966 if (retval
== (CORE_ADDR
) -1)
1967 error (_("Failed inferior mmap call for %s bytes, errno is changed."),
1972 /* To be called from the various GDB_OSABI_LINUX handlers for the
1973 various GNU/Linux architectures and machine types. */
1976 linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1978 set_gdbarch_core_pid_to_str (gdbarch
, linux_core_pid_to_str
);
1979 set_gdbarch_info_proc (gdbarch
, linux_info_proc
);
1980 set_gdbarch_core_info_proc (gdbarch
, linux_core_info_proc
);
1981 set_gdbarch_find_memory_regions (gdbarch
, linux_find_memory_regions
);
1982 set_gdbarch_make_corefile_notes (gdbarch
, linux_make_corefile_notes
);
1983 set_gdbarch_has_shared_address_space (gdbarch
,
1984 linux_has_shared_address_space
);
1985 set_gdbarch_gdb_signal_from_target (gdbarch
,
1986 linux_gdb_signal_from_target
);
1987 set_gdbarch_gdb_signal_to_target (gdbarch
,
1988 linux_gdb_signal_to_target
);
1989 set_gdbarch_vsyscall_range (gdbarch
, linux_vsyscall_range
);
1990 set_gdbarch_infcall_mmap (gdbarch
, linux_infcall_mmap
);
1993 /* Provide a prototype to silence -Wmissing-prototypes. */
1994 extern initialize_file_ftype _initialize_linux_tdep
;
1997 _initialize_linux_tdep (void)
1999 linux_gdbarch_data_handle
=
2000 gdbarch_data_register_post_init (init_linux_gdbarch_data
);
2002 /* Set a cache per-inferior. */
2004 = register_inferior_data_with_cleanup (NULL
, linux_inferior_data_cleanup
);
2005 /* Observers used to invalidate the cache when needed. */
2006 observer_attach_inferior_exit (invalidate_linux_cache_inf
);
2007 observer_attach_inferior_appeared (invalidate_linux_cache_inf
);