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"
38 /* This enum represents the signals' numbers on a generic architecture
39 running the Linux kernel. The definition of "generic" comes from
40 the file <include/uapi/asm-generic/signal.h>, from the Linux kernel
41 tree, which is the "de facto" implementation of signal numbers to
42 be used by new architecture ports.
44 For those architectures which have differences between the generic
45 standard (e.g., Alpha), we define the different signals (and *only*
46 those) in the specific target-dependent file (e.g.,
47 alpha-linux-tdep.c, for Alpha). Please refer to the architecture's
48 tdep file for more information.
50 ARM deserves a special mention here. On the file
51 <arch/arm/include/uapi/asm/signal.h>, it defines only one different
52 (and ARM-only) signal, which is SIGSWI, with the same number as
53 SIGRTMIN. This signal is used only for a very specific target,
54 called ArthurOS (from RISCOS). Therefore, we do not handle it on
55 the ARM-tdep file, and we can safely use the generic signal handler
58 As stated above, this enum is derived from
59 <include/uapi/asm-generic/signal.h>, from the Linux kernel
94 LINUX_SIGPOLL
= LINUX_SIGIO
,
103 static struct gdbarch_data
*linux_gdbarch_data_handle
;
105 struct linux_gdbarch_data
107 struct type
*siginfo_type
;
111 init_linux_gdbarch_data (struct gdbarch
*gdbarch
)
113 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct linux_gdbarch_data
);
116 static struct linux_gdbarch_data
*
117 get_linux_gdbarch_data (struct gdbarch
*gdbarch
)
119 return gdbarch_data (gdbarch
, linux_gdbarch_data_handle
);
122 /* This function is suitable for architectures that don't
123 extend/override the standard siginfo structure. */
126 linux_get_siginfo_type (struct gdbarch
*gdbarch
)
128 struct linux_gdbarch_data
*linux_gdbarch_data
;
129 struct type
*int_type
, *uint_type
, *long_type
, *void_ptr_type
;
130 struct type
*uid_type
, *pid_type
;
131 struct type
*sigval_type
, *clock_type
;
132 struct type
*siginfo_type
, *sifields_type
;
135 linux_gdbarch_data
= get_linux_gdbarch_data (gdbarch
);
136 if (linux_gdbarch_data
->siginfo_type
!= NULL
)
137 return linux_gdbarch_data
->siginfo_type
;
139 int_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
141 uint_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
143 long_type
= arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
145 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
148 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
149 TYPE_NAME (sigval_type
) = xstrdup ("sigval_t");
150 append_composite_type_field (sigval_type
, "sival_int", int_type
);
151 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
154 pid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
155 TYPE_LENGTH (int_type
), "__pid_t");
156 TYPE_TARGET_TYPE (pid_type
) = int_type
;
157 TYPE_TARGET_STUB (pid_type
) = 1;
160 uid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
161 TYPE_LENGTH (uint_type
), "__uid_t");
162 TYPE_TARGET_TYPE (uid_type
) = uint_type
;
163 TYPE_TARGET_STUB (uid_type
) = 1;
166 clock_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
167 TYPE_LENGTH (long_type
), "__clock_t");
168 TYPE_TARGET_TYPE (clock_type
) = long_type
;
169 TYPE_TARGET_STUB (clock_type
) = 1;
172 sifields_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
175 const int si_max_size
= 128;
177 int size_of_int
= gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
180 if (gdbarch_ptr_bit (gdbarch
) == 64)
181 si_pad_size
= (si_max_size
/ size_of_int
) - 4;
183 si_pad_size
= (si_max_size
/ size_of_int
) - 3;
184 append_composite_type_field (sifields_type
, "_pad",
185 init_vector_type (int_type
, si_pad_size
));
189 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
190 append_composite_type_field (type
, "si_pid", pid_type
);
191 append_composite_type_field (type
, "si_uid", uid_type
);
192 append_composite_type_field (sifields_type
, "_kill", type
);
195 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
196 append_composite_type_field (type
, "si_tid", int_type
);
197 append_composite_type_field (type
, "si_overrun", int_type
);
198 append_composite_type_field (type
, "si_sigval", sigval_type
);
199 append_composite_type_field (sifields_type
, "_timer", type
);
202 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
203 append_composite_type_field (type
, "si_pid", pid_type
);
204 append_composite_type_field (type
, "si_uid", uid_type
);
205 append_composite_type_field (type
, "si_sigval", sigval_type
);
206 append_composite_type_field (sifields_type
, "_rt", type
);
209 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
210 append_composite_type_field (type
, "si_pid", pid_type
);
211 append_composite_type_field (type
, "si_uid", uid_type
);
212 append_composite_type_field (type
, "si_status", int_type
);
213 append_composite_type_field (type
, "si_utime", clock_type
);
214 append_composite_type_field (type
, "si_stime", clock_type
);
215 append_composite_type_field (sifields_type
, "_sigchld", type
);
218 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
219 append_composite_type_field (type
, "si_addr", void_ptr_type
);
220 append_composite_type_field (sifields_type
, "_sigfault", type
);
223 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
224 append_composite_type_field (type
, "si_band", long_type
);
225 append_composite_type_field (type
, "si_fd", int_type
);
226 append_composite_type_field (sifields_type
, "_sigpoll", type
);
229 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
230 TYPE_NAME (siginfo_type
) = xstrdup ("siginfo");
231 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
232 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
233 append_composite_type_field (siginfo_type
, "si_code", int_type
);
234 append_composite_type_field_aligned (siginfo_type
,
235 "_sifields", sifields_type
,
236 TYPE_LENGTH (long_type
));
238 linux_gdbarch_data
->siginfo_type
= siginfo_type
;
243 /* Return true if the target is running on uClinux instead of normal
247 linux_is_uclinux (void)
251 return (target_auxv_search (¤t_target
, AT_NULL
, &dummy
) > 0
252 && target_auxv_search (¤t_target
, AT_PAGESZ
, &dummy
) == 0);
256 linux_has_shared_address_space (struct gdbarch
*gdbarch
)
258 return linux_is_uclinux ();
261 /* This is how we want PTIDs from core files to be printed. */
264 linux_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
268 if (ptid_get_lwp (ptid
) != 0)
270 snprintf (buf
, sizeof (buf
), "LWP %ld", ptid_get_lwp (ptid
));
274 return normal_pid_to_str (ptid
);
277 /* Service function for corefiles and info proc. */
280 read_mapping (const char *line
,
281 ULONGEST
*addr
, ULONGEST
*endaddr
,
282 const char **permissions
, size_t *permissions_len
,
284 const char **device
, size_t *device_len
,
286 const char **filename
)
288 const char *p
= line
;
290 *addr
= strtoulst (p
, &p
, 16);
293 *endaddr
= strtoulst (p
, &p
, 16);
295 p
= skip_spaces_const (p
);
297 while (*p
&& !isspace (*p
))
299 *permissions_len
= p
- *permissions
;
301 *offset
= strtoulst (p
, &p
, 16);
303 p
= skip_spaces_const (p
);
305 while (*p
&& !isspace (*p
))
307 *device_len
= p
- *device
;
309 *inode
= strtoulst (p
, &p
, 10);
311 p
= skip_spaces_const (p
);
315 /* Implement the "info proc" command. */
318 linux_info_proc (struct gdbarch
*gdbarch
, const char *args
,
319 enum info_proc_what what
)
321 /* A long is used for pid instead of an int to avoid a loss of precision
322 compiler warning from the output of strtoul. */
324 int cmdline_f
= (what
== IP_MINIMAL
|| what
== IP_CMDLINE
|| what
== IP_ALL
);
325 int cwd_f
= (what
== IP_MINIMAL
|| what
== IP_CWD
|| what
== IP_ALL
);
326 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
327 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
328 int status_f
= (what
== IP_STATUS
|| what
== IP_ALL
);
329 int stat_f
= (what
== IP_STAT
|| what
== IP_ALL
);
334 if (args
&& isdigit (args
[0]))
338 pid
= strtoul (args
, &tem
, 10);
343 if (!target_has_execution
)
344 error (_("No current process: you must name one."));
345 if (current_inferior ()->fake_pid_p
)
346 error (_("Can't determine the current process's PID: you must name one."));
348 pid
= current_inferior ()->pid
;
351 args
= skip_spaces_const (args
);
353 error (_("Too many parameters: %s"), args
);
355 printf_filtered (_("process %ld\n"), pid
);
358 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cmdline", pid
);
359 data
= target_fileio_read_stralloc (filename
);
362 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
363 printf_filtered ("cmdline = '%s'\n", data
);
364 do_cleanups (cleanup
);
367 warning (_("unable to open /proc file '%s'"), filename
);
371 xsnprintf (filename
, sizeof filename
, "/proc/%ld/cwd", pid
);
372 data
= target_fileio_readlink (filename
, &target_errno
);
375 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
376 printf_filtered ("cwd = '%s'\n", data
);
377 do_cleanups (cleanup
);
380 warning (_("unable to read link '%s'"), filename
);
384 xsnprintf (filename
, sizeof filename
, "/proc/%ld/exe", pid
);
385 data
= target_fileio_readlink (filename
, &target_errno
);
388 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
389 printf_filtered ("exe = '%s'\n", data
);
390 do_cleanups (cleanup
);
393 warning (_("unable to read link '%s'"), filename
);
397 xsnprintf (filename
, sizeof filename
, "/proc/%ld/maps", pid
);
398 data
= target_fileio_read_stralloc (filename
);
401 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
404 printf_filtered (_("Mapped address spaces:\n\n"));
405 if (gdbarch_addr_bit (gdbarch
) == 32)
407 printf_filtered ("\t%10s %10s %10s %10s %s\n",
410 " Size", " Offset", "objfile");
414 printf_filtered (" %18s %18s %10s %10s %s\n",
417 " Size", " Offset", "objfile");
420 for (line
= strtok (data
, "\n"); line
; line
= strtok (NULL
, "\n"))
422 ULONGEST addr
, endaddr
, offset
, inode
;
423 const char *permissions
, *device
, *filename
;
424 size_t permissions_len
, device_len
;
426 read_mapping (line
, &addr
, &endaddr
,
427 &permissions
, &permissions_len
,
428 &offset
, &device
, &device_len
,
431 if (gdbarch_addr_bit (gdbarch
) == 32)
433 printf_filtered ("\t%10s %10s %10s %10s %s\n",
434 paddress (gdbarch
, addr
),
435 paddress (gdbarch
, endaddr
),
436 hex_string (endaddr
- addr
),
438 *filename
? filename
: "");
442 printf_filtered (" %18s %18s %10s %10s %s\n",
443 paddress (gdbarch
, addr
),
444 paddress (gdbarch
, endaddr
),
445 hex_string (endaddr
- addr
),
447 *filename
? filename
: "");
451 do_cleanups (cleanup
);
454 warning (_("unable to open /proc file '%s'"), filename
);
458 xsnprintf (filename
, sizeof filename
, "/proc/%ld/status", pid
);
459 data
= target_fileio_read_stralloc (filename
);
462 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
463 puts_filtered (data
);
464 do_cleanups (cleanup
);
467 warning (_("unable to open /proc file '%s'"), filename
);
471 xsnprintf (filename
, sizeof filename
, "/proc/%ld/stat", pid
);
472 data
= target_fileio_read_stralloc (filename
);
475 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
476 const char *p
= data
;
478 printf_filtered (_("Process: %s\n"),
479 pulongest (strtoulst (p
, &p
, 10)));
481 p
= skip_spaces_const (p
);
484 /* ps command also relies on no trailing fields
486 const char *ep
= strrchr (p
, ')');
489 printf_filtered ("Exec file: %.*s\n",
490 (int) (ep
- p
- 1), p
+ 1);
495 p
= skip_spaces_const (p
);
497 printf_filtered (_("State: %c\n"), *p
++);
500 printf_filtered (_("Parent process: %s\n"),
501 pulongest (strtoulst (p
, &p
, 10)));
503 printf_filtered (_("Process group: %s\n"),
504 pulongest (strtoulst (p
, &p
, 10)));
506 printf_filtered (_("Session id: %s\n"),
507 pulongest (strtoulst (p
, &p
, 10)));
509 printf_filtered (_("TTY: %s\n"),
510 pulongest (strtoulst (p
, &p
, 10)));
512 printf_filtered (_("TTY owner process group: %s\n"),
513 pulongest (strtoulst (p
, &p
, 10)));
516 printf_filtered (_("Flags: %s\n"),
517 hex_string (strtoulst (p
, &p
, 10)));
519 printf_filtered (_("Minor faults (no memory page): %s\n"),
520 pulongest (strtoulst (p
, &p
, 10)));
522 printf_filtered (_("Minor faults, children: %s\n"),
523 pulongest (strtoulst (p
, &p
, 10)));
525 printf_filtered (_("Major faults (memory page faults): %s\n"),
526 pulongest (strtoulst (p
, &p
, 10)));
528 printf_filtered (_("Major faults, children: %s\n"),
529 pulongest (strtoulst (p
, &p
, 10)));
531 printf_filtered (_("utime: %s\n"),
532 pulongest (strtoulst (p
, &p
, 10)));
534 printf_filtered (_("stime: %s\n"),
535 pulongest (strtoulst (p
, &p
, 10)));
537 printf_filtered (_("utime, children: %s\n"),
538 pulongest (strtoulst (p
, &p
, 10)));
540 printf_filtered (_("stime, children: %s\n"),
541 pulongest (strtoulst (p
, &p
, 10)));
543 printf_filtered (_("jiffies remaining in current "
545 pulongest (strtoulst (p
, &p
, 10)));
547 printf_filtered (_("'nice' value: %s\n"),
548 pulongest (strtoulst (p
, &p
, 10)));
550 printf_filtered (_("jiffies until next timeout: %s\n"),
551 pulongest (strtoulst (p
, &p
, 10)));
553 printf_filtered (_("jiffies until next SIGALRM: %s\n"),
554 pulongest (strtoulst (p
, &p
, 10)));
556 printf_filtered (_("start time (jiffies since "
557 "system boot): %s\n"),
558 pulongest (strtoulst (p
, &p
, 10)));
560 printf_filtered (_("Virtual memory size: %s\n"),
561 pulongest (strtoulst (p
, &p
, 10)));
563 printf_filtered (_("Resident set size: %s\n"),
564 pulongest (strtoulst (p
, &p
, 10)));
566 printf_filtered (_("rlim: %s\n"),
567 pulongest (strtoulst (p
, &p
, 10)));
569 printf_filtered (_("Start of text: %s\n"),
570 hex_string (strtoulst (p
, &p
, 10)));
572 printf_filtered (_("End of text: %s\n"),
573 hex_string (strtoulst (p
, &p
, 10)));
575 printf_filtered (_("Start of stack: %s\n"),
576 hex_string (strtoulst (p
, &p
, 10)));
577 #if 0 /* Don't know how architecture-dependent the rest is...
578 Anyway the signal bitmap info is available from "status". */
580 printf_filtered (_("Kernel stack pointer: %s\n"),
581 hex_string (strtoulst (p
, &p
, 10)));
583 printf_filtered (_("Kernel instr pointer: %s\n"),
584 hex_string (strtoulst (p
, &p
, 10)));
586 printf_filtered (_("Pending signals bitmap: %s\n"),
587 hex_string (strtoulst (p
, &p
, 10)));
589 printf_filtered (_("Blocked signals bitmap: %s\n"),
590 hex_string (strtoulst (p
, &p
, 10)));
592 printf_filtered (_("Ignored signals bitmap: %s\n"),
593 hex_string (strtoulst (p
, &p
, 10)));
595 printf_filtered (_("Catched signals bitmap: %s\n"),
596 hex_string (strtoulst (p
, &p
, 10)));
598 printf_filtered (_("wchan (system call): %s\n"),
599 hex_string (strtoulst (p
, &p
, 10)));
601 do_cleanups (cleanup
);
604 warning (_("unable to open /proc file '%s'"), filename
);
608 /* Implement "info proc mappings" for a corefile. */
611 linux_core_info_proc_mappings (struct gdbarch
*gdbarch
, const char *args
)
614 ULONGEST count
, page_size
;
615 unsigned char *descdata
, *filenames
, *descend
, *contents
;
617 unsigned int addr_size_bits
, addr_size
;
618 struct cleanup
*cleanup
;
619 struct gdbarch
*core_gdbarch
= gdbarch_from_bfd (core_bfd
);
620 /* We assume this for reading 64-bit core files. */
621 gdb_static_assert (sizeof (ULONGEST
) >= 8);
623 section
= bfd_get_section_by_name (core_bfd
, ".note.linuxcore.file");
626 warning (_("unable to find mappings in core file"));
630 addr_size_bits
= gdbarch_addr_bit (core_gdbarch
);
631 addr_size
= addr_size_bits
/ 8;
632 note_size
= bfd_get_section_size (section
);
634 if (note_size
< 2 * addr_size
)
635 error (_("malformed core note - too short for header"));
637 contents
= xmalloc (note_size
);
638 cleanup
= make_cleanup (xfree
, contents
);
639 if (!bfd_get_section_contents (core_bfd
, section
, contents
, 0, note_size
))
640 error (_("could not get core note contents"));
643 descend
= descdata
+ note_size
;
645 if (descdata
[note_size
- 1] != '\0')
646 error (_("malformed note - does not end with \\0"));
648 count
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
649 descdata
+= addr_size
;
651 page_size
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
652 descdata
+= addr_size
;
654 if (note_size
< 2 * addr_size
+ count
* 3 * addr_size
)
655 error (_("malformed note - too short for supplied file count"));
657 printf_filtered (_("Mapped address spaces:\n\n"));
658 if (gdbarch_addr_bit (gdbarch
) == 32)
660 printf_filtered ("\t%10s %10s %10s %10s %s\n",
663 " Size", " Offset", "objfile");
667 printf_filtered (" %18s %18s %10s %10s %s\n",
670 " Size", " Offset", "objfile");
673 filenames
= descdata
+ count
* 3 * addr_size
;
676 ULONGEST start
, end
, file_ofs
;
678 if (filenames
== descend
)
679 error (_("malformed note - filenames end too early"));
681 start
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
682 descdata
+= addr_size
;
683 end
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
684 descdata
+= addr_size
;
685 file_ofs
= bfd_get (addr_size_bits
, core_bfd
, descdata
);
686 descdata
+= addr_size
;
688 file_ofs
*= page_size
;
690 if (gdbarch_addr_bit (gdbarch
) == 32)
691 printf_filtered ("\t%10s %10s %10s %10s %s\n",
692 paddress (gdbarch
, start
),
693 paddress (gdbarch
, end
),
694 hex_string (end
- start
),
695 hex_string (file_ofs
),
698 printf_filtered (" %18s %18s %10s %10s %s\n",
699 paddress (gdbarch
, start
),
700 paddress (gdbarch
, end
),
701 hex_string (end
- start
),
702 hex_string (file_ofs
),
705 filenames
+= 1 + strlen ((char *) filenames
);
708 do_cleanups (cleanup
);
711 /* Implement "info proc" for a corefile. */
714 linux_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
715 enum info_proc_what what
)
717 int exe_f
= (what
== IP_MINIMAL
|| what
== IP_EXE
|| what
== IP_ALL
);
718 int mappings_f
= (what
== IP_MAPPINGS
|| what
== IP_ALL
);
724 exe
= bfd_core_file_failing_command (core_bfd
);
726 printf_filtered ("exe = '%s'\n", exe
);
728 warning (_("unable to find command name in core file"));
732 linux_core_info_proc_mappings (gdbarch
, args
);
734 if (!exe_f
&& !mappings_f
)
735 error (_("unable to handle request"));
738 typedef int linux_find_memory_region_ftype (ULONGEST vaddr
, ULONGEST size
,
739 ULONGEST offset
, ULONGEST inode
,
741 int exec
, int modified
,
742 const char *filename
,
745 /* List memory regions in the inferior for a corefile. */
748 linux_find_memory_regions_full (struct gdbarch
*gdbarch
,
749 linux_find_memory_region_ftype
*func
,
752 char mapsfilename
[100];
755 /* We need to know the real target PID to access /proc. */
756 if (current_inferior ()->fake_pid_p
)
759 xsnprintf (mapsfilename
, sizeof mapsfilename
,
760 "/proc/%d/smaps", current_inferior ()->pid
);
761 data
= target_fileio_read_stralloc (mapsfilename
);
764 /* Older Linux kernels did not support /proc/PID/smaps. */
765 xsnprintf (mapsfilename
, sizeof mapsfilename
,
766 "/proc/%d/maps", current_inferior ()->pid
);
767 data
= target_fileio_read_stralloc (mapsfilename
);
771 struct cleanup
*cleanup
= make_cleanup (xfree
, data
);
774 line
= strtok (data
, "\n");
777 ULONGEST addr
, endaddr
, offset
, inode
;
778 const char *permissions
, *device
, *filename
;
779 size_t permissions_len
, device_len
;
780 int read
, write
, exec
;
781 int modified
= 0, has_anonymous
= 0;
783 read_mapping (line
, &addr
, &endaddr
, &permissions
, &permissions_len
,
784 &offset
, &device
, &device_len
, &inode
, &filename
);
786 /* Decode permissions. */
787 read
= (memchr (permissions
, 'r', permissions_len
) != 0);
788 write
= (memchr (permissions
, 'w', permissions_len
) != 0);
789 exec
= (memchr (permissions
, 'x', permissions_len
) != 0);
791 /* Try to detect if region was modified by parsing smaps counters. */
792 for (line
= strtok (NULL
, "\n");
793 line
&& line
[0] >= 'A' && line
[0] <= 'Z';
794 line
= strtok (NULL
, "\n"))
796 char keyword
[64 + 1];
798 if (sscanf (line
, "%64s", keyword
) != 1)
800 warning (_("Error parsing {s,}maps file '%s'"), mapsfilename
);
803 if (strcmp (keyword
, "Anonymous:") == 0)
805 if (strcmp (keyword
, "Shared_Dirty:") == 0
806 || strcmp (keyword
, "Private_Dirty:") == 0
807 || strcmp (keyword
, "Swap:") == 0
808 || strcmp (keyword
, "Anonymous:") == 0)
810 unsigned long number
;
812 if (sscanf (line
, "%*s%lu", &number
) != 1)
814 warning (_("Error parsing {s,}maps file '%s' number"),
823 /* Older Linux kernels did not support the "Anonymous:" counter.
824 If it is missing, we can't be sure - dump all the pages. */
828 /* Invoke the callback function to create the corefile segment. */
829 func (addr
, endaddr
- addr
, offset
, inode
,
830 read
, write
, exec
, modified
, filename
, obfd
);
833 do_cleanups (cleanup
);
840 /* A structure for passing information through
841 linux_find_memory_regions_full. */
843 struct linux_find_memory_regions_data
845 /* The original callback. */
847 find_memory_region_ftype func
;
849 /* The original datum. */
854 /* A callback for linux_find_memory_regions that converts between the
855 "full"-style callback and find_memory_region_ftype. */
858 linux_find_memory_regions_thunk (ULONGEST vaddr
, ULONGEST size
,
859 ULONGEST offset
, ULONGEST inode
,
860 int read
, int write
, int exec
, int modified
,
861 const char *filename
, void *arg
)
863 struct linux_find_memory_regions_data
*data
= arg
;
865 return data
->func (vaddr
, size
, read
, write
, exec
, modified
, data
->obfd
);
868 /* A variant of linux_find_memory_regions_full that is suitable as the
869 gdbarch find_memory_regions method. */
872 linux_find_memory_regions (struct gdbarch
*gdbarch
,
873 find_memory_region_ftype func
, void *obfd
)
875 struct linux_find_memory_regions_data data
;
880 return linux_find_memory_regions_full (gdbarch
,
881 linux_find_memory_regions_thunk
,
885 /* Determine which signal stopped execution. */
888 find_signalled_thread (struct thread_info
*info
, void *data
)
890 if (info
->suspend
.stop_signal
!= GDB_SIGNAL_0
891 && ptid_get_pid (info
->ptid
) == ptid_get_pid (inferior_ptid
))
897 static enum gdb_signal
898 find_stop_signal (void)
900 struct thread_info
*info
=
901 iterate_over_threads (find_signalled_thread
, NULL
);
904 return info
->suspend
.stop_signal
;
909 /* Generate corefile notes for SPU contexts. */
912 linux_spu_make_corefile_notes (bfd
*obfd
, char *note_data
, int *note_size
)
914 static const char *spu_files
[] =
936 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
940 /* Determine list of SPU ids. */
941 size
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
944 /* Generate corefile notes for each SPU file. */
945 for (i
= 0; i
< size
; i
+= 4)
947 int fd
= extract_unsigned_integer (spu_ids
+ i
, 4, byte_order
);
949 for (j
= 0; j
< sizeof (spu_files
) / sizeof (spu_files
[0]); j
++)
951 char annex
[32], note_name
[32];
955 xsnprintf (annex
, sizeof annex
, "%d/%s", fd
, spu_files
[j
]);
956 spu_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_SPU
,
960 xsnprintf (note_name
, sizeof note_name
, "SPU/%s", annex
);
961 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
981 /* This is used to pass information from
982 linux_make_mappings_corefile_notes through
983 linux_find_memory_regions_full. */
985 struct linux_make_mappings_data
987 /* Number of files mapped. */
990 /* The obstack for the main part of the data. */
991 struct obstack
*data_obstack
;
993 /* The filename obstack. */
994 struct obstack
*filename_obstack
;
996 /* The architecture's "long" type. */
997 struct type
*long_type
;
1000 static linux_find_memory_region_ftype linux_make_mappings_callback
;
1002 /* A callback for linux_find_memory_regions_full that updates the
1003 mappings data for linux_make_mappings_corefile_notes. */
1006 linux_make_mappings_callback (ULONGEST vaddr
, ULONGEST size
,
1007 ULONGEST offset
, ULONGEST inode
,
1008 int read
, int write
, int exec
, int modified
,
1009 const char *filename
, void *data
)
1011 struct linux_make_mappings_data
*map_data
= data
;
1012 gdb_byte buf
[sizeof (ULONGEST
)];
1014 if (*filename
== '\0' || inode
== 0)
1017 ++map_data
->file_count
;
1019 pack_long (buf
, map_data
->long_type
, vaddr
);
1020 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1021 pack_long (buf
, map_data
->long_type
, vaddr
+ size
);
1022 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1023 pack_long (buf
, map_data
->long_type
, offset
);
1024 obstack_grow (map_data
->data_obstack
, buf
, TYPE_LENGTH (map_data
->long_type
));
1026 obstack_grow_str0 (map_data
->filename_obstack
, filename
);
1031 /* Write the file mapping data to the core file, if possible. OBFD is
1032 the output BFD. NOTE_DATA is the current note data, and NOTE_SIZE
1033 is a pointer to the note size. Returns the new NOTE_DATA and
1034 updates NOTE_SIZE. */
1037 linux_make_mappings_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
,
1038 char *note_data
, int *note_size
)
1040 struct cleanup
*cleanup
;
1041 struct obstack data_obstack
, filename_obstack
;
1042 struct linux_make_mappings_data mapping_data
;
1043 struct type
*long_type
1044 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
), 0, "long");
1045 gdb_byte buf
[sizeof (ULONGEST
)];
1047 obstack_init (&data_obstack
);
1048 cleanup
= make_cleanup_obstack_free (&data_obstack
);
1049 obstack_init (&filename_obstack
);
1050 make_cleanup_obstack_free (&filename_obstack
);
1052 mapping_data
.file_count
= 0;
1053 mapping_data
.data_obstack
= &data_obstack
;
1054 mapping_data
.filename_obstack
= &filename_obstack
;
1055 mapping_data
.long_type
= long_type
;
1057 /* Reserve space for the count. */
1058 obstack_blank (&data_obstack
, TYPE_LENGTH (long_type
));
1059 /* We always write the page size as 1 since we have no good way to
1060 determine the correct value. */
1061 pack_long (buf
, long_type
, 1);
1062 obstack_grow (&data_obstack
, buf
, TYPE_LENGTH (long_type
));
1064 linux_find_memory_regions_full (gdbarch
, linux_make_mappings_callback
,
1067 if (mapping_data
.file_count
!= 0)
1069 /* Write the count to the obstack. */
1070 pack_long ((gdb_byte
*) obstack_base (&data_obstack
),
1071 long_type
, mapping_data
.file_count
);
1073 /* Copy the filenames to the data obstack. */
1074 obstack_grow (&data_obstack
, obstack_base (&filename_obstack
),
1075 obstack_object_size (&filename_obstack
));
1077 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1079 obstack_base (&data_obstack
),
1080 obstack_object_size (&data_obstack
));
1083 do_cleanups (cleanup
);
1087 /* Structure for passing information from
1088 linux_collect_thread_registers via an iterator to
1089 linux_collect_regset_section_cb. */
1091 struct linux_collect_regset_section_cb_data
1093 struct gdbarch
*gdbarch
;
1094 const struct regcache
*regcache
;
1099 enum gdb_signal stop_signal
;
1100 int abort_iteration
;
1103 /* Callback for iterate_over_regset_sections that records a single
1104 regset in the corefile note section. */
1107 linux_collect_regset_section_cb (const char *sect_name
, int size
,
1108 const char *human_name
, void *cb_data
)
1110 const struct regset
*regset
;
1112 struct linux_collect_regset_section_cb_data
*data
= cb_data
;
1114 if (data
->abort_iteration
)
1117 regset
= gdbarch_regset_from_core_section (data
->gdbarch
, sect_name
, size
);
1118 gdb_assert (regset
&& regset
->collect_regset
);
1120 buf
= xmalloc (size
);
1121 regset
->collect_regset (regset
, data
->regcache
, -1, buf
, size
);
1123 /* PRSTATUS still needs to be treated specially. */
1124 if (strcmp (sect_name
, ".reg") == 0)
1125 data
->note_data
= (char *) elfcore_write_prstatus
1126 (data
->obfd
, data
->note_data
, data
->note_size
, data
->lwp
,
1127 gdb_signal_to_host (data
->stop_signal
), buf
);
1129 data
->note_data
= (char *) elfcore_write_register_note
1130 (data
->obfd
, data
->note_data
, data
->note_size
,
1131 sect_name
, buf
, size
);
1134 if (data
->note_data
== NULL
)
1135 data
->abort_iteration
= 1;
1138 /* Records the thread's register state for the corefile note
1142 linux_collect_thread_registers (const struct regcache
*regcache
,
1143 ptid_t ptid
, bfd
*obfd
,
1144 char *note_data
, int *note_size
,
1145 enum gdb_signal stop_signal
)
1147 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1148 struct linux_collect_regset_section_cb_data data
;
1150 data
.gdbarch
= gdbarch
;
1151 data
.regcache
= regcache
;
1153 data
.note_data
= note_data
;
1154 data
.note_size
= note_size
;
1155 data
.stop_signal
= stop_signal
;
1156 data
.abort_iteration
= 0;
1158 /* For remote targets the LWP may not be available, so use the TID. */
1159 data
.lwp
= ptid_get_lwp (ptid
);
1161 data
.lwp
= ptid_get_tid (ptid
);
1163 gdbarch_iterate_over_regset_sections (gdbarch
,
1164 linux_collect_regset_section_cb
,
1166 return data
.note_data
;
1169 /* Fetch the siginfo data for the current thread, if it exists. If
1170 there is no data, or we could not read it, return NULL. Otherwise,
1171 return a newly malloc'd buffer holding the data and fill in *SIZE
1172 with the size of the data. The caller is responsible for freeing
1176 linux_get_siginfo_data (struct gdbarch
*gdbarch
, LONGEST
*size
)
1178 struct type
*siginfo_type
;
1181 struct cleanup
*cleanups
;
1183 if (!gdbarch_get_siginfo_type_p (gdbarch
))
1186 siginfo_type
= gdbarch_get_siginfo_type (gdbarch
);
1188 buf
= xmalloc (TYPE_LENGTH (siginfo_type
));
1189 cleanups
= make_cleanup (xfree
, buf
);
1191 bytes_read
= target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
1192 buf
, 0, TYPE_LENGTH (siginfo_type
));
1193 if (bytes_read
== TYPE_LENGTH (siginfo_type
))
1195 discard_cleanups (cleanups
);
1200 do_cleanups (cleanups
);
1207 struct linux_corefile_thread_data
1209 struct gdbarch
*gdbarch
;
1214 enum gdb_signal stop_signal
;
1215 linux_collect_thread_registers_ftype collect
;
1218 /* Called by gdbthread.c once per thread. Records the thread's
1219 register state for the corefile note section. */
1222 linux_corefile_thread_callback (struct thread_info
*info
, void *data
)
1224 struct linux_corefile_thread_data
*args
= data
;
1226 /* It can be current thread
1227 which cannot be removed by update_thread_list. */
1228 if (info
->state
== THREAD_EXITED
)
1231 if (ptid_get_pid (info
->ptid
) == args
->pid
)
1233 struct cleanup
*old_chain
;
1234 struct regcache
*regcache
;
1235 gdb_byte
*siginfo_data
;
1236 LONGEST siginfo_size
= 0;
1238 regcache
= get_thread_arch_regcache (info
->ptid
, args
->gdbarch
);
1240 old_chain
= save_inferior_ptid ();
1241 inferior_ptid
= info
->ptid
;
1242 target_fetch_registers (regcache
, -1);
1243 siginfo_data
= linux_get_siginfo_data (args
->gdbarch
, &siginfo_size
);
1244 do_cleanups (old_chain
);
1246 old_chain
= make_cleanup (xfree
, siginfo_data
);
1248 args
->note_data
= args
->collect (regcache
, info
->ptid
, args
->obfd
,
1249 args
->note_data
, args
->note_size
,
1252 /* Don't return anything if we got no register information above,
1253 such a core file is useless. */
1254 if (args
->note_data
!= NULL
)
1255 if (siginfo_data
!= NULL
)
1256 args
->note_data
= elfcore_write_note (args
->obfd
,
1260 siginfo_data
, siginfo_size
);
1262 do_cleanups (old_chain
);
1265 return !args
->note_data
;
1268 /* Fill the PRPSINFO structure with information about the process being
1269 debugged. Returns 1 in case of success, 0 for failures. Please note that
1270 even if the structure cannot be entirely filled (e.g., GDB was unable to
1271 gather information about the process UID/GID), this function will still
1272 return 1 since some information was already recorded. It will only return
1273 0 iff nothing can be gathered. */
1276 linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo
*p
)
1278 /* The filename which we will use to obtain some info about the process.
1279 We will basically use this to store the `/proc/PID/FILENAME' file. */
1281 /* The full name of the program which generated the corefile. */
1283 /* The basename of the executable. */
1284 const char *basename
;
1285 /* The arguments of the program. */
1288 /* The contents of `/proc/PID/stat' and `/proc/PID/status' files. */
1289 char *proc_stat
, *proc_status
;
1290 /* Temporary buffer. */
1292 /* The valid states of a process, according to the Linux kernel. */
1293 const char valid_states
[] = "RSDTZW";
1294 /* The program state. */
1295 const char *prog_state
;
1296 /* The state of the process. */
1298 /* The PID of the program which generated the corefile. */
1300 /* Process flags. */
1301 unsigned int pr_flag
;
1302 /* Process nice value. */
1304 /* The number of fields read by `sscanf'. */
1310 gdb_assert (p
!= NULL
);
1312 /* Obtaining PID and filename. */
1313 pid
= ptid_get_pid (inferior_ptid
);
1314 xsnprintf (filename
, sizeof (filename
), "/proc/%d/cmdline", (int) pid
);
1315 fname
= target_fileio_read_stralloc (filename
);
1317 if (fname
== NULL
|| *fname
== '\0')
1319 /* No program name was read, so we won't be able to retrieve more
1320 information about the process. */
1325 c
= make_cleanup (xfree
, fname
);
1326 memset (p
, 0, sizeof (*p
));
1328 /* Defining the PID. */
1331 /* Copying the program name. Only the basename matters. */
1332 basename
= lbasename (fname
);
1333 strncpy (p
->pr_fname
, basename
, sizeof (p
->pr_fname
));
1334 p
->pr_fname
[sizeof (p
->pr_fname
) - 1] = '\0';
1336 infargs
= get_inferior_args ();
1338 psargs
= xstrdup (fname
);
1339 if (infargs
!= NULL
)
1340 psargs
= reconcat (psargs
, psargs
, " ", infargs
, NULL
);
1342 make_cleanup (xfree
, psargs
);
1344 strncpy (p
->pr_psargs
, psargs
, sizeof (p
->pr_psargs
));
1345 p
->pr_psargs
[sizeof (p
->pr_psargs
) - 1] = '\0';
1347 xsnprintf (filename
, sizeof (filename
), "/proc/%d/stat", (int) pid
);
1348 proc_stat
= target_fileio_read_stralloc (filename
);
1349 make_cleanup (xfree
, proc_stat
);
1351 if (proc_stat
== NULL
|| *proc_stat
== '\0')
1353 /* Despite being unable to read more information about the
1354 process, we return 1 here because at least we have its
1355 command line, PID and arguments. */
1360 /* Ok, we have the stats. It's time to do a little parsing of the
1361 contents of the buffer, so that we end up reading what we want.
1363 The following parsing mechanism is strongly based on the
1364 information generated by the `fs/proc/array.c' file, present in
1365 the Linux kernel tree. More details about how the information is
1366 displayed can be obtained by seeing the manpage of proc(5),
1367 specifically under the entry of `/proc/[pid]/stat'. */
1369 /* Getting rid of the PID, since we already have it. */
1370 while (isdigit (*proc_stat
))
1373 proc_stat
= skip_spaces (proc_stat
);
1375 /* ps command also relies on no trailing fields ever contain ')'. */
1376 proc_stat
= strrchr (proc_stat
, ')');
1377 if (proc_stat
== NULL
)
1384 proc_stat
= skip_spaces (proc_stat
);
1386 n_fields
= sscanf (proc_stat
,
1387 "%c" /* Process state. */
1388 "%d%d%d" /* Parent PID, group ID, session ID. */
1389 "%*d%*d" /* tty_nr, tpgid (not used). */
1391 "%*s%*s%*s%*s" /* minflt, cminflt, majflt,
1392 cmajflt (not used). */
1393 "%*s%*s%*s%*s" /* utime, stime, cutime,
1394 cstime (not used). */
1395 "%*s" /* Priority (not used). */
1398 &p
->pr_ppid
, &p
->pr_pgrp
, &p
->pr_sid
,
1404 /* Again, we couldn't read the complementary information about
1405 the process state. However, we already have minimal
1406 information, so we just return 1 here. */
1411 /* Filling the structure fields. */
1412 prog_state
= strchr (valid_states
, pr_sname
);
1413 if (prog_state
!= NULL
)
1414 p
->pr_state
= prog_state
- valid_states
;
1417 /* Zero means "Running". */
1421 p
->pr_sname
= p
->pr_state
> 5 ? '.' : pr_sname
;
1422 p
->pr_zomb
= p
->pr_sname
== 'Z';
1423 p
->pr_nice
= pr_nice
;
1424 p
->pr_flag
= pr_flag
;
1426 /* Finally, obtaining the UID and GID. For that, we read and parse the
1427 contents of the `/proc/PID/status' file. */
1428 xsnprintf (filename
, sizeof (filename
), "/proc/%d/status", (int) pid
);
1429 proc_status
= target_fileio_read_stralloc (filename
);
1430 make_cleanup (xfree
, proc_status
);
1432 if (proc_status
== NULL
|| *proc_status
== '\0')
1434 /* Returning 1 since we already have a bunch of information. */
1439 /* Extracting the UID. */
1440 tmpstr
= strstr (proc_status
, "Uid:");
1443 /* Advancing the pointer to the beginning of the UID. */
1444 tmpstr
+= sizeof ("Uid:");
1445 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1448 if (isdigit (*tmpstr
))
1449 p
->pr_uid
= strtol (tmpstr
, &tmpstr
, 10);
1452 /* Extracting the GID. */
1453 tmpstr
= strstr (proc_status
, "Gid:");
1456 /* Advancing the pointer to the beginning of the GID. */
1457 tmpstr
+= sizeof ("Gid:");
1458 while (*tmpstr
!= '\0' && !isdigit (*tmpstr
))
1461 if (isdigit (*tmpstr
))
1462 p
->pr_gid
= strtol (tmpstr
, &tmpstr
, 10);
1470 /* Fills the "to_make_corefile_note" target vector. Builds the note
1471 section for a corefile, and returns it in a malloc buffer. */
1474 linux_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
,
1475 linux_collect_thread_registers_ftype collect
)
1477 struct linux_corefile_thread_data thread_args
;
1478 struct elf_internal_linux_prpsinfo prpsinfo
;
1479 char *note_data
= NULL
;
1482 volatile struct gdb_exception e
;
1484 if (linux_fill_prpsinfo (&prpsinfo
))
1486 if (gdbarch_elfcore_write_linux_prpsinfo_p (gdbarch
))
1488 note_data
= gdbarch_elfcore_write_linux_prpsinfo (gdbarch
, obfd
,
1489 note_data
, note_size
,
1494 if (gdbarch_ptr_bit (gdbarch
) == 64)
1495 note_data
= elfcore_write_linux_prpsinfo64 (obfd
,
1496 note_data
, note_size
,
1499 note_data
= elfcore_write_linux_prpsinfo32 (obfd
,
1500 note_data
, note_size
,
1505 /* Thread register information. */
1506 TRY_CATCH (e
, RETURN_MASK_ERROR
)
1508 update_thread_list ();
1511 exception_print (gdb_stderr
, e
);
1512 thread_args
.gdbarch
= gdbarch
;
1513 thread_args
.pid
= ptid_get_pid (inferior_ptid
);
1514 thread_args
.obfd
= obfd
;
1515 thread_args
.note_data
= note_data
;
1516 thread_args
.note_size
= note_size
;
1517 thread_args
.stop_signal
= find_stop_signal ();
1518 thread_args
.collect
= collect
;
1519 iterate_over_threads (linux_corefile_thread_callback
, &thread_args
);
1520 note_data
= thread_args
.note_data
;
1524 /* Auxillary vector. */
1525 auxv_len
= target_read_alloc (¤t_target
, TARGET_OBJECT_AUXV
,
1529 note_data
= elfcore_write_note (obfd
, note_data
, note_size
,
1530 "CORE", NT_AUXV
, auxv
, auxv_len
);
1537 /* SPU information. */
1538 note_data
= linux_spu_make_corefile_notes (obfd
, note_data
, note_size
);
1542 /* File mappings. */
1543 note_data
= linux_make_mappings_corefile_notes (gdbarch
, obfd
,
1544 note_data
, note_size
);
1550 linux_make_corefile_notes_1 (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
1552 /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been
1553 converted to gdbarch_core_regset_sections, we no longer need to fall back
1554 to the target method at this point. */
1556 if (!gdbarch_iterate_over_regset_sections_p (gdbarch
))
1557 return target_make_corefile_notes (obfd
, note_size
);
1559 return linux_make_corefile_notes (gdbarch
, obfd
, note_size
,
1560 linux_collect_thread_registers
);
1563 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
1564 gdbarch.h. This function is not static because it is exported to
1565 other -tdep files. */
1568 linux_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1573 return GDB_SIGNAL_0
;
1576 return GDB_SIGNAL_HUP
;
1579 return GDB_SIGNAL_INT
;
1582 return GDB_SIGNAL_QUIT
;
1585 return GDB_SIGNAL_ILL
;
1588 return GDB_SIGNAL_TRAP
;
1591 return GDB_SIGNAL_ABRT
;
1594 return GDB_SIGNAL_BUS
;
1597 return GDB_SIGNAL_FPE
;
1600 return GDB_SIGNAL_KILL
;
1603 return GDB_SIGNAL_USR1
;
1606 return GDB_SIGNAL_SEGV
;
1609 return GDB_SIGNAL_USR2
;
1612 return GDB_SIGNAL_PIPE
;
1615 return GDB_SIGNAL_ALRM
;
1618 return GDB_SIGNAL_TERM
;
1621 return GDB_SIGNAL_CHLD
;
1624 return GDB_SIGNAL_CONT
;
1627 return GDB_SIGNAL_STOP
;
1630 return GDB_SIGNAL_TSTP
;
1633 return GDB_SIGNAL_TTIN
;
1636 return GDB_SIGNAL_TTOU
;
1639 return GDB_SIGNAL_URG
;
1642 return GDB_SIGNAL_XCPU
;
1645 return GDB_SIGNAL_XFSZ
;
1647 case LINUX_SIGVTALRM
:
1648 return GDB_SIGNAL_VTALRM
;
1651 return GDB_SIGNAL_PROF
;
1653 case LINUX_SIGWINCH
:
1654 return GDB_SIGNAL_WINCH
;
1656 /* No way to differentiate between SIGIO and SIGPOLL.
1657 Therefore, we just handle the first one. */
1659 return GDB_SIGNAL_IO
;
1662 return GDB_SIGNAL_PWR
;
1665 return GDB_SIGNAL_SYS
;
1667 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
1668 therefore we have to handle them here. */
1669 case LINUX_SIGRTMIN
:
1670 return GDB_SIGNAL_REALTIME_32
;
1672 case LINUX_SIGRTMAX
:
1673 return GDB_SIGNAL_REALTIME_64
;
1676 if (signal
>= LINUX_SIGRTMIN
+ 1 && signal
<= LINUX_SIGRTMAX
- 1)
1678 int offset
= signal
- LINUX_SIGRTMIN
+ 1;
1680 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_33
+ offset
);
1683 return GDB_SIGNAL_UNKNOWN
;
1686 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1687 gdbarch.h. This function is not static because it is exported to
1688 other -tdep files. */
1691 linux_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1692 enum gdb_signal signal
)
1699 case GDB_SIGNAL_HUP
:
1700 return LINUX_SIGHUP
;
1702 case GDB_SIGNAL_INT
:
1703 return LINUX_SIGINT
;
1705 case GDB_SIGNAL_QUIT
:
1706 return LINUX_SIGQUIT
;
1708 case GDB_SIGNAL_ILL
:
1709 return LINUX_SIGILL
;
1711 case GDB_SIGNAL_TRAP
:
1712 return LINUX_SIGTRAP
;
1714 case GDB_SIGNAL_ABRT
:
1715 return LINUX_SIGABRT
;
1717 case GDB_SIGNAL_FPE
:
1718 return LINUX_SIGFPE
;
1720 case GDB_SIGNAL_KILL
:
1721 return LINUX_SIGKILL
;
1723 case GDB_SIGNAL_BUS
:
1724 return LINUX_SIGBUS
;
1726 case GDB_SIGNAL_SEGV
:
1727 return LINUX_SIGSEGV
;
1729 case GDB_SIGNAL_SYS
:
1730 return LINUX_SIGSYS
;
1732 case GDB_SIGNAL_PIPE
:
1733 return LINUX_SIGPIPE
;
1735 case GDB_SIGNAL_ALRM
:
1736 return LINUX_SIGALRM
;
1738 case GDB_SIGNAL_TERM
:
1739 return LINUX_SIGTERM
;
1741 case GDB_SIGNAL_URG
:
1742 return LINUX_SIGURG
;
1744 case GDB_SIGNAL_STOP
:
1745 return LINUX_SIGSTOP
;
1747 case GDB_SIGNAL_TSTP
:
1748 return LINUX_SIGTSTP
;
1750 case GDB_SIGNAL_CONT
:
1751 return LINUX_SIGCONT
;
1753 case GDB_SIGNAL_CHLD
:
1754 return LINUX_SIGCHLD
;
1756 case GDB_SIGNAL_TTIN
:
1757 return LINUX_SIGTTIN
;
1759 case GDB_SIGNAL_TTOU
:
1760 return LINUX_SIGTTOU
;
1765 case GDB_SIGNAL_XCPU
:
1766 return LINUX_SIGXCPU
;
1768 case GDB_SIGNAL_XFSZ
:
1769 return LINUX_SIGXFSZ
;
1771 case GDB_SIGNAL_VTALRM
:
1772 return LINUX_SIGVTALRM
;
1774 case GDB_SIGNAL_PROF
:
1775 return LINUX_SIGPROF
;
1777 case GDB_SIGNAL_WINCH
:
1778 return LINUX_SIGWINCH
;
1780 case GDB_SIGNAL_USR1
:
1781 return LINUX_SIGUSR1
;
1783 case GDB_SIGNAL_USR2
:
1784 return LINUX_SIGUSR2
;
1786 case GDB_SIGNAL_PWR
:
1787 return LINUX_SIGPWR
;
1789 case GDB_SIGNAL_POLL
:
1790 return LINUX_SIGPOLL
;
1792 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1793 therefore we have to handle it here. */
1794 case GDB_SIGNAL_REALTIME_32
:
1795 return LINUX_SIGRTMIN
;
1797 /* Same comment applies to _64. */
1798 case GDB_SIGNAL_REALTIME_64
:
1799 return LINUX_SIGRTMAX
;
1802 /* GDB_SIGNAL_REALTIME_33 to _64 are continuous. */
1803 if (signal
>= GDB_SIGNAL_REALTIME_33
1804 && signal
<= GDB_SIGNAL_REALTIME_63
)
1806 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1808 return LINUX_SIGRTMIN
+ 1 + offset
;
1814 /* To be called from the various GDB_OSABI_LINUX handlers for the
1815 various GNU/Linux architectures and machine types. */
1818 linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1820 set_gdbarch_core_pid_to_str (gdbarch
, linux_core_pid_to_str
);
1821 set_gdbarch_info_proc (gdbarch
, linux_info_proc
);
1822 set_gdbarch_core_info_proc (gdbarch
, linux_core_info_proc
);
1823 set_gdbarch_find_memory_regions (gdbarch
, linux_find_memory_regions
);
1824 set_gdbarch_make_corefile_notes (gdbarch
, linux_make_corefile_notes_1
);
1825 set_gdbarch_has_shared_address_space (gdbarch
,
1826 linux_has_shared_address_space
);
1827 set_gdbarch_gdb_signal_from_target (gdbarch
,
1828 linux_gdb_signal_from_target
);
1829 set_gdbarch_gdb_signal_to_target (gdbarch
,
1830 linux_gdb_signal_to_target
);
1833 /* Provide a prototype to silence -Wmissing-prototypes. */
1834 extern initialize_file_ftype _initialize_linux_tdep
;
1837 _initialize_linux_tdep (void)
1839 linux_gdbarch_data_handle
=
1840 gdbarch_data_register_post_init (init_linux_gdbarch_data
);