29#include "elf/common.h"
34#include "gdbsupport/gdb_obstack.h"
39#include "gdbsupport/gdb_regex.h"
40#include "gdbsupport/enum-flags.h"
41#include "gdbsupport/gdb_optional.h"
48#include <unordered_map>
209 if (result ==
nullptr)
273 linux_siginfo_extra_fields extra_fields)
276 struct type *int_type, *uint_type, *long_type, *void_ptr_type, *short_type;
277 struct type *uid_type, *pid_type;
278 struct type *sigval_type, *clock_type;
279 struct type *siginfo_type, *sifields_type;
300 sigval_type->
set_name (xstrdup (
"sigval_t"));
305 pid_type = alloc.
new_type (TYPE_CODE_TYPEDEF,
306 int_type->
length () * TARGET_CHAR_BIT,
312 uid_type = alloc.
new_type (TYPE_CODE_TYPEDEF,
313 uint_type->
length () * TARGET_CHAR_BIT,
319 clock_type = alloc.
new_type (TYPE_CODE_TYPEDEF,
320 long_type->
length () * TARGET_CHAR_BIT,
329 const int si_max_size = 128;
335 si_pad_size = (si_max_size / size_of_int) - 4;
337 si_pad_size = (si_max_size / size_of_int) - 3;
378 struct type *sigfault_bnd_fields;
403 siginfo_type->
set_name (xstrdup (
"siginfo"));
408 "_sifields", sifields_type,
448 if (ptid.lwp () != 0)
449 return string_printf (
"LWP %ld", ptid.lwp ());
476 const char *p = line;
484 const char *permissions_start = p;
485 while (*p && !isspace (*p))
492 const char *device_start = p;
493 while (*p && !isspace (*p))
495 mapping.
device = {device_start, (size_t) (p - device_start)};
517 char *saveptr = NULL;
521 p = skip_to_space (p);
524 for (s = strtok_r (p,
" ", &saveptr);
526 s = strtok_r (NULL,
" ", &saveptr))
528 if (strcmp (s,
"io") == 0)
530 else if (strcmp (s,
"ht") == 0)
532 else if (strcmp (s,
"dd") == 0)
534 else if (strcmp (s,
"sh") == 0)
536 else if (strcmp (s,
"mt") == 0)
551 {
"^/dev/zero\\( (deleted)\\)\\?$", REG_NOSUB,
552 _(
"Could not compile regex to match /dev/zero filename")};
559 {
"^/\\?SYSV[0-9a-fA-F]\\{8\\}\\( (deleted)\\)\\?$", REG_NOSUB,
560 _(
"Could not compile regex to match shmem filenames")};
575 {
" (deleted)$", REG_NOSUB,
576 _(
"Could not compile regex to match '<file> (deleted)'")};
592 static gdb::optional<mapping_regexes> regexes;
593 static int init_regex_p = 0;
607 if (init_regex_p == -1)
609 const char deleted[] =
" (deleted)";
610 size_t del_len =
sizeof (deleted) - 1;
611 size_t filename_len = strlen (filename);
618 return (filename_len >= del_len
619 && strcmp (filename + filename_len - del_len, deleted) == 0);
622 if (*filename ==
'\0'
623 || regexes->dev_zero.exec (filename, 0, NULL, 0) == 0
624 || regexes->shmem_file.exec (filename, 0, NULL, 0) == 0
625 || regexes->file_deleted.exec (filename, 0, NULL, 0) == 0)
680 int maybe_private_p,
int mapping_anon_p,
int mapping_file_p,
681 const char *filename, ULONGEST addr, ULONGEST offset)
690 int private_p = maybe_private_p;
696 if (strcmp (
"[vdso]", filename) == 0
697 || strcmp (
"[vsyscall]", filename) == 0)
727 if (mapping_anon_p && mapping_file_p)
735 else if (mapping_anon_p)
742 if (mapping_anon_p && mapping_file_p)
750 else if (mapping_anon_p)
764 if (!dump_p && private_p && offset == 0
779 if (h[EI_MAG0] == ELFMAG0 && h[EI_MAG1] == ELFMAG1
780 && h[EI_MAG2] == ELFMAG2 && h[EI_MAG3] == ELFMAG3)
797 int maybe_private_p,
int mapping_anon_p,
int mapping_file_p,
798 const char *filename, ULONGEST addr, ULONGEST offset)
802 if (strcmp (
"[vdso]", filename) == 0
803 || strcmp (
"[vsyscall]", filename) == 0)
827 fileio_error target_errno;
829 if (args && isdigit (args[0]))
833 pid = strtoul (args, &tem, 10);
839 error (_(
"No current process: you must name one."));
841 error (_(
"Can't determine the current process's PID: you must name one."));
846 args = skip_spaces (args);
848 error (_(
"Too many parameters: %s"), args);
853 xsnprintf (filename,
sizeof filename,
"/proc/%ld/cmdline",
pid);
859 gdb::unique_xmalloc_ptr<char> cmdline ((
char *) buffer);
862 for (pos = 0; pos < len - 1; pos++)
864 if (buffer[pos] ==
'\0')
867 buffer[len - 1] =
'\0';
871 warning (_(
"unable to open /proc file '%s'"), filename);
875 xsnprintf (filename,
sizeof filename,
"/proc/%ld/cwd",
pid);
876 gdb::optional<std::string> contents
878 if (contents.has_value ())
879 gdb_printf (
"cwd = '%s'\n", contents->c_str ());
881 warning (_(
"unable to read link '%s'"), filename);
885 xsnprintf (filename,
sizeof filename,
"/proc/%ld/exe",
pid);
886 gdb::optional<std::string> contents
888 if (contents.has_value ())
889 gdb_printf (
"exe = '%s'\n", contents->c_str ());
891 warning (_(
"unable to read link '%s'"), filename);
895 xsnprintf (filename,
sizeof filename,
"/proc/%ld/maps",
pid);
896 gdb::unique_xmalloc_ptr<char> map
906 "Start Addr",
" End Addr",
" Size",
907 " Offset",
"Perms ",
"objfile");
912 "Start Addr",
" End Addr",
" Size",
913 " Offset",
"Perms ",
"objfile");
917 for (line = strtok_r (map.get (),
"\n", &saveptr);
919 line = strtok_r (NULL,
"\n", &saveptr))
925 gdb_printf (
"\t%10s %10s %10s %10s %-5.*s %s\n",
928 hex_string (m.endaddr - m.addr),
929 hex_string (m.offset),
930 (
int) m.permissions.size (),
931 m.permissions.data (),
936 gdb_printf (
" %18s %18s %10s %10s %-5.*s %s\n",
939 hex_string (m.endaddr - m.addr),
940 hex_string (m.offset),
941 (
int) m.permissions.size (),
942 m.permissions.data (),
948 warning (_(
"unable to open /proc file '%s'"),
filename);
953 gdb::unique_xmalloc_ptr<char>
status
958 warning (_(
"unable to open /proc file '%s'"),
filename);
963 gdb::unique_xmalloc_ptr<char> statstr
967 const char *p = statstr.get ();
970 pulongest (strtoulst (p, &p, 10)));
977 const char *ep = strrchr (p,
')');
981 (
int) (ep - p - 1), p + 1);
992 pulongest (strtoulst (p, &p, 10)));
995 pulongest (strtoulst (p, &p, 10)));
998 pulongest (strtoulst (p, &p, 10)));
1001 pulongest (strtoulst (p, &p, 10)));
1003 gdb_printf (_(
"TTY owner process group: %s\n"),
1004 pulongest (strtoulst (p, &p, 10)));
1008 hex_string (strtoulst (p, &p, 10)));
1010 gdb_printf (_(
"Minor faults (no memory page): %s\n"),
1011 pulongest (strtoulst (p, &p, 10)));
1013 gdb_printf (_(
"Minor faults, children: %s\n"),
1014 pulongest (strtoulst (p, &p, 10)));
1016 gdb_printf (_(
"Major faults (memory page faults): %s\n"),
1017 pulongest (strtoulst (p, &p, 10)));
1019 gdb_printf (_(
"Major faults, children: %s\n"),
1020 pulongest (strtoulst (p, &p, 10)));
1023 pulongest (strtoulst (p, &p, 10)));
1026 pulongest (strtoulst (p, &p, 10)));
1029 pulongest (strtoulst (p, &p, 10)));
1032 pulongest (strtoulst (p, &p, 10)));
1034 gdb_printf (_(
"jiffies remaining in current "
1035 "time slice: %s\n"),
1036 pulongest (strtoulst (p, &p, 10)));
1039 pulongest (strtoulst (p, &p, 10)));
1041 gdb_printf (_(
"jiffies until next timeout: %s\n"),
1042 pulongest (strtoulst (p, &p, 10)));
1044 gdb_printf (_(
"jiffies until next SIGALRM: %s\n"),
1045 pulongest (strtoulst (p, &p, 10)));
1048 "system boot): %s\n"),
1049 pulongest (strtoulst (p, &p, 10)));
1052 pulongest (strtoulst (p, &p, 10)));
1055 pulongest (strtoulst (p, &p, 10)));
1058 pulongest (strtoulst (p, &p, 10)));
1061 hex_string (strtoulst (p, &p, 10)));
1064 hex_string (strtoulst (p, &p, 10)));
1067 hex_string (strtoulst (p, &p, 10)));
1072 hex_string (strtoulst (p, &p, 10)));
1075 hex_string (strtoulst (p, &p, 10)));
1077 gdb_printf (_(
"Pending signals bitmap: %s\n"),
1078 hex_string (strtoulst (p, &p, 10)));
1080 gdb_printf (_(
"Blocked signals bitmap: %s\n"),
1081 hex_string (strtoulst (p, &p, 10)));
1083 gdb_printf (_(
"Ignored signals bitmap: %s\n"),
1084 hex_string (strtoulst (p, &p, 10)));
1086 gdb_printf (_(
"Catched signals bitmap: %s\n"),
1087 hex_string (strtoulst (p, &p, 10)));
1090 hex_string (strtoulst (p, &p, 10)));
1094 warning (_(
"unable to open /proc file '%s'"),
filename);
1137 asection *section = bfd_get_section_by_name (cbfd,
".note.linuxcore.file");
1138 if (section ==
nullptr)
1142 unsigned int addr_size = addr_size_bits / 8;
1143 size_t note_size = bfd_section_size (section);
1147 warning (_(
"malformed core note - too short for header"));
1151 gdb::def_vector<gdb_byte> contents (
note_size);
1152 if (!bfd_get_section_contents (
core_bfd, section, contents.data (),
1155 warning (_(
"could not get core note contents"));
1159 gdb_byte *descdata = contents.data ();
1160 char *descend = (
char *) descdata +
note_size;
1164 warning (_(
"malformed note - does not end with \\0"));
1168 ULONGEST count = bfd_get (addr_size_bits,
core_bfd, descdata);
1169 descdata += addr_size;
1171 ULONGEST page_size = bfd_get (addr_size_bits,
core_bfd, descdata);
1172 descdata += addr_size;
1174 if (
note_size < 2 * addr_size + count * 3 * addr_size)
1176 warning (_(
"malformed note - too short for supplied file count"));
1180 char *filenames = (
char *) descdata + count * 3 * addr_size;
1184 char *
f = filenames;
1185 for (
int i = 0; i < count; i++)
1189 warning (_(
"malformed note - filename area is too small"));
1192 f += strnlen (
f, descend -
f) + 1;
1196 warning (_(
"malformed note - filename area is too big"));
1198 const bfd_build_id *orig_build_id = cbfd->build_id;
1199 std::unordered_map<ULONGEST, const bfd_build_id *> vma_map;
1203 for (bfd_section *sec = cbfd->sections; sec !=
nullptr; sec = sec->next)
1205 cbfd->build_id =
nullptr;
1207 if (sec->flags & SEC_LOAD
1208 && (get_elf_backend_data (cbfd)->elf_backend_core_find_build_id
1209 (cbfd, (bfd_vma) sec->filepos)))
1210 vma_map[sec->vma] = cbfd->build_id;
1213 cbfd->build_id = orig_build_id;
1214 pre_loop_cb (count);
1216 for (
int i = 0; i < count; i++)
1218 ULONGEST start = bfd_get (addr_size_bits,
core_bfd, descdata);
1219 descdata += addr_size;
1220 ULONGEST end = bfd_get (addr_size_bits,
core_bfd, descdata);
1221 descdata += addr_size;
1223 = bfd_get (addr_size_bits,
core_bfd, descdata) * page_size;
1224 descdata += addr_size;
1226 filenames += strlen ((
char *) filenames) + 1;
1227 const bfd_build_id *build_id =
nullptr;
1228 auto vma_map_it = vma_map.find (start);
1230 if (vma_map_it != vma_map.end ())
1231 build_id = vma_map_it->second;
1233 loop_cb (i, start, end, file_ofs,
filename, build_id);
1243 [=] (ULONGEST count)
1245 gdb_printf (_(
"Mapped address spaces:\n\n"));
1251 " Size",
" Offset",
"objfile");
1258 " Size",
" Offset",
"objfile");
1261 [=] (
int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs,
1262 const char *
filename,
const bfd_build_id *build_id)
1268 hex_string (end - start),
1269 hex_string (file_ofs),
1275 hex_string (end - start),
1276 hex_string (file_ofs),
1294 exe = bfd_core_file_failing_command (
core_bfd);
1298 warning (_(
"unable to find command name in core file"));
1304 if (!exe_f && !mappings_f)
1305 error (_(
"unable to handle request"));
1315 ULONGEST
offset, ULONGEST len)
1318 asection *section = bfd_get_section_by_name (
core_bfd, section_name.
c_str ());
1319 if (section == NULL)
1322 if (!bfd_get_section_contents (
core_bfd, section, readbuf,
offset, len))
1330 int read,
int write,
1331 int exec,
int modified,
1338 int maybe_private_p,
1351static std::vector<struct smaps_data>
1353 const std::string maps_filename)
1357 gdb_assert (data !=
nullptr);
1359 line = strtok_r ((
char *) data,
"\n", &t);
1361 std::vector<struct smaps_data> smaps;
1363 while (line != NULL)
1366 int read, write, exec, priv;
1367 int has_anonymous = 0;
1371 memset (&v, 0,
sizeof (v));
1383 mapping_file_p = !mapping_anon_p;
1386 auto has_perm = [&m] (
char c)
1387 {
return m.permissions.find (c) != gdb::string_view::npos; };
1388 read = has_perm (
'r');
1389 write = has_perm (
'w');
1390 exec = has_perm (
'x');
1401 priv = has_perm (
'p');
1405 for (line = strtok_r (NULL,
"\n", &t);
1406 line != NULL && line[0] >=
'A' && line[0] <=
'Z';
1407 line = strtok_r (NULL,
"\n", &t))
1411 if (sscanf (line,
"%64s",
keyword) != 1)
1413 warning (_(
"Error parsing {s,}maps file '%s'"),
1414 maps_filename.c_str ());
1418 if (strcmp (
keyword,
"Anonymous:") == 0)
1424 else if (strcmp (
keyword,
"VmFlags:") == 0)
1427 if (strcmp (
keyword,
"AnonHugePages:") == 0
1428 || strcmp (
keyword,
"Anonymous:") == 0)
1430 unsigned long number;
1432 if (sscanf (line,
"%*s%lu", &number) != 1)
1434 warning (_(
"Error parsing {s,}maps file '%s' number"),
1435 maps_filename.c_str ());
1475 map.
inode = m.inode;
1477 smaps.emplace_back (map);
1494 std::string smaps_file = string_printf (
"/proc/%d/smaps",
pid);
1496 gdb::unique_xmalloc_ptr<char> data
1499 if (data ==
nullptr)
1503 std::vector<struct smaps_data> smaps
1510 if (address >= map.start_address
1511 && address < map.end_address
1512 && map.vmflags.memory_tagging)
1568 std::string core_dump_filter_name
1569 = string_printf (
"/proc/%d/coredump_filter",
pid);
1571 gdb::unique_xmalloc_ptr<char> coredumpfilterdata
1574 if (coredumpfilterdata != NULL)
1578 sscanf (coredumpfilterdata.get (),
"%x", &
flags);
1583 std::string maps_filename = string_printf (
"/proc/%d/smaps",
pid);
1585 gdb::unique_xmalloc_ptr<char> data
1591 maps_filename = string_printf (
"/proc/%d/maps",
pid);
1594 if (data ==
nullptr)
1599 std::vector<struct smaps_data> smaps
1604 int should_dump_p = 0;
1606 if (map.has_anonymous)
1609 = should_dump_mapping_p (filterflags, &map.vmflags,
1613 map.filename.c_str (),
1627 func (map.start_address, map.end_address - map.start_address,
1628 map.offset, map.inode, map.read, map.write, map.exec,
1631 map.vmflags.memory_tagging != 0,
1632 map.filename.c_str (),
obfd);
1658 ULONGEST offset, ULONGEST inode,
1659 int read,
int write,
int exec,
int modified,
1661 const char *filename,
void *arg)
1666 return data->func (vaddr,
size,
read, write, exec, modified, memory_tagged,
1717 ULONGEST offset, ULONGEST inode,
1718 int read,
int write,
int exec,
int modified,
1720 const char *filename,
void *data)
1724 gdb_byte buf[
sizeof (ULONGEST)];
1726 if (*filename ==
'\0' || inode == 0)
1749 gdb::unique_xmalloc_ptr<char> ¬e_data,
1754 struct type *long_type
1756 gdb_byte buf[
sizeof (ULONGEST)];
1758 auto_obstack data_obstack, filename_obstack;
1766 obstack_blank (&data_obstack, long_type->
length ());
1770 obstack_grow (&data_obstack, buf, long_type->
length ());
1780 pack_long ((gdb_byte *) obstack_base (&data_obstack),
1784 int size = obstack_object_size (&filename_obstack);
1785 obstack_grow (&data_obstack, obstack_base (&filename_obstack),
1788 note_data.reset (elfcore_write_file_note (
obfd, note_data.release (),
note_size,
1789 obstack_base (&data_obstack),
1790 obstack_object_size (&data_obstack)));
1798static gdb::byte_vector
1801 struct type *siginfo_type;
1805 return gdb::byte_vector ();
1812 gdb::byte_vector buf (siginfo_type->
length ());
1816 buf.data (), 0, siginfo_type->
length ());
1817 if (bytes_read != siginfo_type->
length ())
1829 gdb::unique_xmalloc_ptr<char> ¬e_data,
1837 if (note_data !=
nullptr)
1839 gdb::byte_vector siginfo_data
1841 if (!siginfo_data.empty ())
1842 note_data.reset (elfcore_write_note (
obfd, note_data.release (),
1844 siginfo_data.data (),
1845 siginfo_data.size ()));
1863 const char *basename;
1867 const char valid_states[] =
"RSDTZW";
1869 const char *prog_state;
1875 unsigned int pr_flag;
1881 gdb_assert (p != NULL);
1885 xsnprintf (filename,
sizeof (filename),
"/proc/%d/cmdline", (
int)
pid);
1887 gdb::unique_xmalloc_ptr<char> fname
1890 if (fname == NULL || fname.get ()[0] ==
'\0')
1897 memset (p, 0,
sizeof (*p));
1903 basename = lbasename (fname.get ());
1904 strncpy (p->pr_fname, basename, sizeof (p->pr_fname) - 1);
1905 p->pr_fname[
sizeof (p->pr_fname) - 1] =
'\0';
1910 std::string psargs = fname.get ();
1911 if (!infargs.empty ())
1912 psargs +=
' ' + infargs;
1914 strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs) - 1);
1915 p->pr_psargs[
sizeof (p->pr_psargs) - 1] =
'\0';
1917 xsnprintf (filename,
sizeof (filename),
"/proc/%d/stat", (
int)
pid);
1919 gdb::unique_xmalloc_ptr<char> proc_stat_contents
1921 char *proc_stat = proc_stat_contents.get ();
1923 if (proc_stat == NULL || *proc_stat ==
'\0')
1941 while (isdigit (*proc_stat))
1944 proc_stat = skip_spaces (proc_stat);
1947 proc_stat = strrchr (proc_stat,
')');
1948 if (proc_stat == NULL)
1952 proc_stat = skip_spaces (proc_stat);
1954 n_fields = sscanf (proc_stat,
1966 &p->pr_ppid, &p->pr_pgrp, &p->pr_sid,
1979 prog_state = strchr (valid_states, pr_sname);
1980 if (prog_state != NULL)
1981 p->pr_state = prog_state - valid_states;
1988 p->pr_sname = p->pr_state > 5 ?
'.' : pr_sname;
1989 p->pr_zomb = p->pr_sname ==
'Z';
1990 p->pr_nice = pr_nice;
1991 p->pr_flag = pr_flag;
1995 xsnprintf (filename,
sizeof (filename),
"/proc/%d/status", (
int)
pid);
1997 gdb::unique_xmalloc_ptr<char> proc_status_contents
1999 char *proc_status = proc_status_contents.get ();
2001 if (proc_status == NULL || *proc_status ==
'\0')
2008 tmpstr = strstr (proc_status,
"Uid:");
2012 tmpstr +=
sizeof (
"Uid:");
2013 while (*tmpstr !=
'\0' && !isdigit (*tmpstr))
2016 if (isdigit (*tmpstr))
2017 p->pr_uid = strtol (tmpstr, &tmpstr, 10);
2021 tmpstr = strstr (proc_status,
"Gid:");
2025 tmpstr +=
sizeof (
"Gid:");
2026 while (*tmpstr !=
'\0' && !isdigit (*tmpstr))
2029 if (isdigit (*tmpstr))
2030 p->pr_gid = strtol (tmpstr, &tmpstr, 10);
2039static gdb::unique_xmalloc_ptr<char>
2042 struct elf_internal_linux_prpsinfo prpsinfo;
2043 gdb::unique_xmalloc_ptr<char> note_data;
2051 note_data.reset (elfcore_write_linux_prpsinfo64 (
obfd,
2052 note_data.release (),
2055 note_data.reset (elfcore_write_linux_prpsinfo32 (
obfd,
2056 note_data.release (),
2065 catch (
const gdb_exception_error &e)
2074 gdb_signal stop_signal;
2075 if (signalled_thr !=
nullptr)
2078 stop_signal = GDB_SIGNAL_0;
2080 if (signalled_thr !=
nullptr)
2094 if (thr == signalled_thr)
2111 gdb::optional<gdb::byte_vector> auxv =
2114 if (auxv && !auxv->empty ())
2116 note_data.reset (elfcore_write_note (
obfd, note_data.release (),
2118 auxv->data (), auxv->size ()));
2147 return GDB_SIGNAL_0;
2150 return GDB_SIGNAL_HUP;
2153 return GDB_SIGNAL_INT;
2156 return GDB_SIGNAL_QUIT;
2159 return GDB_SIGNAL_ILL;
2162 return GDB_SIGNAL_TRAP;
2165 return GDB_SIGNAL_ABRT;
2168 return GDB_SIGNAL_BUS;
2171 return GDB_SIGNAL_FPE;
2174 return GDB_SIGNAL_KILL;
2177 return GDB_SIGNAL_USR1;
2180 return GDB_SIGNAL_SEGV;
2183 return GDB_SIGNAL_USR2;
2186 return GDB_SIGNAL_PIPE;
2189 return GDB_SIGNAL_ALRM;
2192 return GDB_SIGNAL_TERM;
2195 return GDB_SIGNAL_CHLD;
2198 return GDB_SIGNAL_CONT;
2201 return GDB_SIGNAL_STOP;
2204 return GDB_SIGNAL_TSTP;
2207 return GDB_SIGNAL_TTIN;
2210 return GDB_SIGNAL_TTOU;
2213 return GDB_SIGNAL_URG;
2216 return GDB_SIGNAL_XCPU;
2219 return GDB_SIGNAL_XFSZ;
2222 return GDB_SIGNAL_VTALRM;
2225 return GDB_SIGNAL_PROF;
2228 return GDB_SIGNAL_WINCH;
2233 return GDB_SIGNAL_IO;
2236 return GDB_SIGNAL_PWR;
2239 return GDB_SIGNAL_SYS;
2244 return GDB_SIGNAL_REALTIME_32;
2247 return GDB_SIGNAL_REALTIME_64;
2254 return (
enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_33 + offset);
2257 return GDB_SIGNAL_UNKNOWN;
2266 enum gdb_signal signal)
2273 case GDB_SIGNAL_HUP:
2276 case GDB_SIGNAL_INT:
2279 case GDB_SIGNAL_QUIT:
2282 case GDB_SIGNAL_ILL:
2285 case GDB_SIGNAL_TRAP:
2288 case GDB_SIGNAL_ABRT:
2291 case GDB_SIGNAL_FPE:
2294 case GDB_SIGNAL_KILL:
2297 case GDB_SIGNAL_BUS:
2300 case GDB_SIGNAL_SEGV:
2303 case GDB_SIGNAL_SYS:
2306 case GDB_SIGNAL_PIPE:
2309 case GDB_SIGNAL_ALRM:
2312 case GDB_SIGNAL_TERM:
2315 case GDB_SIGNAL_URG:
2318 case GDB_SIGNAL_STOP:
2321 case GDB_SIGNAL_TSTP:
2324 case GDB_SIGNAL_CONT:
2327 case GDB_SIGNAL_CHLD:
2330 case GDB_SIGNAL_TTIN:
2333 case GDB_SIGNAL_TTOU:
2339 case GDB_SIGNAL_XCPU:
2342 case GDB_SIGNAL_XFSZ:
2345 case GDB_SIGNAL_VTALRM:
2348 case GDB_SIGNAL_PROF:
2351 case GDB_SIGNAL_WINCH:
2354 case GDB_SIGNAL_USR1:
2357 case GDB_SIGNAL_USR2:
2360 case GDB_SIGNAL_PWR:
2363 case GDB_SIGNAL_POLL:
2368 case GDB_SIGNAL_REALTIME_32:
2372 case GDB_SIGNAL_REALTIME_64:
2377 if (signal >= GDB_SIGNAL_REALTIME_33
2378 && signal <= GDB_SIGNAL_REALTIME_63)
2380 int offset = signal - GDB_SIGNAL_REALTIME_33;
2408 phdrs_size = bfd_get_elf_phdr_upper_bound (
core_bfd);
2409 if (phdrs_size == -1)
2412 gdb::unique_xmalloc_ptr<Elf_Internal_Phdr>
2413 phdrs ((Elf_Internal_Phdr *)
xmalloc (phdrs_size));
2414 num_phdrs = bfd_get_elf_phdrs (
core_bfd, phdrs.get ());
2415 if (num_phdrs == -1)
2418 for (i = 0; i < num_phdrs; i++)
2419 if (phdrs.get ()[i].p_type == PT_LOAD
2420 && phdrs.get ()[i].p_vaddr ==
range->start)
2443 xsnprintf (filename,
sizeof filename,
"/proc/%ld/task/%ld/maps",
pid,
pid);
2444 gdb::unique_xmalloc_ptr<char> data
2449 char *saveptr = NULL;
2451 for (line = strtok_r (data.get (),
"\n", &saveptr);
2453 line = strtok_r (NULL,
"\n", &saveptr))
2455 ULONGEST addr, endaddr;
2456 const char *p = line;
2458 addr = strtoulst (p, &p, 16);
2459 if (addr ==
range->start)
2463 endaddr = strtoulst (p, &p, 16);
2470 warning (_(
"unable to open /proc file '%s'"), filename);
2483 if (info->vsyscall_range_p == 0)
2486 info->vsyscall_range_p = 1;
2488 info->vsyscall_range_p = -1;
2491 if (info->vsyscall_range_p < 0)
2494 *
range = info->vsyscall_range;
2500#define GDB_MMAP_MAP_PRIVATE 0x02
2501#define GDB_MMAP_MAP_ANONYMOUS 0x20
2512 struct value *addr_val;
2517 ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_LAST
2519 struct value *arg[ARG_LAST];
2538 if (retval == (CORE_ADDR) -1)
2539 error (_(
"Failed inferior mmap call for %s bytes, errno is changed."),
2551 struct value *retval_val;
2556 ARG_ADDR, ARG_LENGTH, ARG_LAST
2558 struct value *arg[ARG_LAST];
2568 warning (_(
"Failed inferior munmap call at %s for %s bytes, "
2569 "errno is changed."),
2570 hex_string (addr), pulongest (
size));
2588 throw_error (NOT_SUPPORTED_ERROR,
2589 _(
"Cannot find AT_ENTRY auxiliary vector entry."));
2609 CORE_ADDR &displaced_pc)
2617 CORE_ADDR disp_step_buf_addr
2624 std::vector<CORE_ADDR> buffers;
2626 buffers.push_back (disp_step_buf_addr + i * buf_len);
2631 return per_inferior->
disp_step_bufs->prepare (thread, displaced_pc);
2654 if (per_inferior ==
nullptr
2658 return per_inferior->
disp_step_bufs->copy_insn_closure_by_addr (addr);
2668 if (per_inferior ==
nullptr
2682 if (!auxv.has_value ()
2733 gdb_printf (file, _(
"Use of /proc/PID/coredump_filter file to generate"
2734 " corefiles is %s.\n"),
value);
2744 gdb_printf (file, _(
"Dumping of mappings marked with the VM_DONTDUMP"
2745 " flag is %s.\n"),
value);
2756 int num_disp_step_buffers)
2758 if (num_disp_step_buffers > 0)
2805Set whether gcore should consider /proc/PID/coredump_filter."),
2807Show whether gcore should consider /proc/PID/coredump_filter."),
2809Use this command to set whether gcore should consider the contents\n\
2810of /proc/PID/coredump_filter when generating the corefile. For more information\n\
2811about this file, refer to the manpage of core(5)."),
2817Set whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
2819Show whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
2821Use this command to set whether gcore should dump mappings marked with the\n\
2822VM_DONTDUMP flag (\"dd\" in /proc/PID/smaps) when generating the corefile. For\n\
2823more information about this file, refer to the manpage of proc(5) and core(5)."),
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
#define GDB_MMAP_PROT_WRITE
#define GDB_MMAP_PROT_EXEC
#define GDB_MMAP_PROT_READ
int target_auxv_search(const gdb::byte_vector &auxv, target_ops *ops, gdbarch *gdbarch, CORE_ADDR match, CORE_ADDR *valp)
const gdb::optional< gdb::byte_vector > & target_read_auxv()
const std::string & args() const
inf_non_exited_threads_range non_exited_threads()
gdb_signal stop_signal() const
const char * c_str() const
struct cmd_list_element * showlist
struct cmd_list_element * setlist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, bool memory_tagged, void *data)
displaced_step_prepare_status
displaced_step_finish_status
void exception_print(struct ui_file *file, const struct gdb_exception &e)
ssize_t read(int fd, void *buf, size_t count)
void gcore_elf_make_tdesc_note(struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr< char > *note_data, int *note_size)
void gcore_elf_build_thread_register_notes(struct gdbarch *gdbarch, struct thread_info *info, gdb_signal stop_signal, bfd *obfd, gdb::unique_xmalloc_ptr< char > *note_data, int *note_size)
thread_info * gcore_find_signalled_thread()
const gdb_byte * gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
void set_gdbarch_displaced_step_restore_all_in_ptid(struct gdbarch *gdbarch, gdbarch_displaced_step_restore_all_in_ptid_ftype *displaced_step_restore_all_in_ptid)
void set_gdbarch_find_memory_regions(struct gdbarch *gdbarch, gdbarch_find_memory_regions_ftype *find_memory_regions)
void set_gdbarch_displaced_step_finish(struct gdbarch *gdbarch, gdbarch_displaced_step_finish_ftype *displaced_step_finish)
void set_gdbarch_displaced_step_prepare(struct gdbarch *gdbarch, gdbarch_displaced_step_prepare_ftype *displaced_step_prepare)
void set_gdbarch_infcall_mmap(struct gdbarch *gdbarch, gdbarch_infcall_mmap_ftype *infcall_mmap)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
bool gdbarch_get_siginfo_type_p(struct gdbarch *gdbarch)
void set_gdbarch_core_info_proc(struct gdbarch *gdbarch, gdbarch_core_info_proc_ftype *core_info_proc)
void set_gdbarch_core_xfer_siginfo(struct gdbarch *gdbarch, gdbarch_core_xfer_siginfo_ftype *core_xfer_siginfo)
void set_gdbarch_vsyscall_range(struct gdbarch *gdbarch, gdbarch_vsyscall_range_ftype *vsyscall_range)
void set_gdbarch_get_siginfo_type(struct gdbarch *gdbarch, gdbarch_get_siginfo_type_ftype *get_siginfo_type)
int gdbarch_int_bit(struct gdbarch *gdbarch)
void set_gdbarch_read_core_file_mappings(struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings)
void set_gdbarch_infcall_munmap(struct gdbarch *gdbarch, gdbarch_infcall_munmap_ftype *infcall_munmap)
void set_gdbarch_gdb_signal_from_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_from_target_ftype *gdb_signal_from_target)
void set_gdbarch_core_pid_to_str(struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str)
void set_gdbarch_gdb_signal_to_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_to_target_ftype *gdb_signal_to_target)
bool gdbarch_iterate_over_regset_sections_p(struct gdbarch *gdbarch)
void set_gdbarch_make_corefile_notes(struct gdbarch *gdbarch, gdbarch_make_corefile_notes_ftype *make_corefile_notes)
void set_gdbarch_has_shared_address_space(struct gdbarch *gdbarch, gdbarch_has_shared_address_space_ftype *has_shared_address_space)
ULONGEST gdbarch_displaced_step_buffer_length(struct gdbarch *gdbarch)
void set_gdbarch_displaced_step_copy_insn_closure_by_addr(struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_closure_by_addr_ftype *displaced_step_copy_insn_closure_by_addr)
void set_gdbarch_info_proc(struct gdbarch *gdbarch, gdbarch_info_proc_ftype *info_proc)
struct type * gdbarch_get_siginfo_type(struct gdbarch *gdbarch)
int gdbarch_long_bit(struct gdbarch *gdbarch)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
gdb::function_view< void(ULONGEST count)> read_core_file_mappings_pre_loop_ftype
gdb::function_view< void(int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const bfd_build_id *build_id)> read_core_file_mappings_loop_ftype
void update_thread_list(void)
void switch_to_thread(struct thread_info *thr)
struct type * lookup_pointer_type(struct type *type)
struct type * init_integer_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
struct type * arch_composite_type(struct gdbarch *gdbarch, const char *name, enum type_code code)
struct type * init_vector_type(struct type *elt_type, int n)
void append_composite_type_field_aligned(struct type *t, const char *name, struct type *field, int alignment)
void append_composite_type_field(struct type *t, const char *name, struct type *field)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
struct inferior * current_inferior(void)
link_map_offsets * linux_lp64_fetch_link_map_offsets()
displaced_step_prepare_status linux_displaced_step_prepare(gdbarch *arch, thread_info *thread, CORE_ADDR &displaced_pc)
static CORE_ADDR linux_infcall_mmap(CORE_ADDR size, unsigned prot)
static void show_dump_excluded_mappings(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static std::vector< struct smaps_data > parse_smaps_data(const char *data, const std::string maps_filename)
int linux_find_memory_region_ftype(ULONGEST vaddr, ULONGEST size, ULONGEST offset, ULONGEST inode, int read, int write, int exec, int modified, bool memory_tagged, const char *filename, void *data)
@ COREFILTER_MAPPED_PRIVATE
@ COREFILTER_ANON_PRIVATE
@ COREFILTER_MAPPED_SHARED
@ COREFILTER_HUGETLB_SHARED
@ COREFILTER_HUGETLB_PRIVATE
static const registry< gdbarch >::key< linux_gdbarch_data > linux_gdbarch_data_handle
static gdb::unique_xmalloc_ptr< char > linux_make_corefile_notes(struct gdbarch *gdbarch, bfd *obfd, int *note_size)
static int dump_mapping_p(filter_flags filterflags, const struct smaps_vmflags *v, int maybe_private_p, int mapping_anon_p, int mapping_file_p, const char *filename, ULONGEST addr, ULONGEST offset)
DEF_ENUM_FLAGS_TYPE(enum filter_flag, filter_flags)
static void linux_inferior_execd(inferior *exec_inf, inferior *follow_inf)
static int linux_fill_prpsinfo(struct elf_internal_linux_prpsinfo *p)
static struct linux_info * get_linux_inferior_data(inferior *inf)
void linux_displaced_step_restore_all_in_ptid(inferior *parent_inf, ptid_t ptid)
static int linux_vsyscall_range_raw(struct gdbarch *gdbarch, struct mem_range *range)
int linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
static std::string linux_core_pid_to_str(struct gdbarch *gdbarch, ptid_t ptid)
static mapping read_mapping(const char *line)
static void show_use_coredump_filter(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static bool linux_core_file_address_in_memtag_page(CORE_ADDR address)
enum gdb_signal linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
static LONGEST linux_core_xfer_siginfo(struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
static int linux_find_memory_regions_thunk(ULONGEST vaddr, ULONGEST size, ULONGEST offset, ULONGEST inode, int read, int write, int exec, int modified, bool memory_tagged, const char *filename, void *arg)
static bool use_coredump_filter
displaced_step_finish_status linux_displaced_step_finish(gdbarch *arch, thread_info *thread, const target_waitstatus &status)
CORE_ADDR linux_displaced_step_location(struct gdbarch *gdbarch)
static int linux_find_memory_regions_full(struct gdbarch *gdbarch, linux_dump_mapping_p_ftype *should_dump_mapping_p, linux_find_memory_region_ftype *func, void *obfd)
static int linux_has_shared_address_space(struct gdbarch *gdbarch)
static bool dump_excluded_mappings
link_map_offsets * linux_ilp32_fetch_link_map_offsets()
static int linux_vsyscall_range(struct gdbarch *gdbarch, struct mem_range *range)
static void linux_info_proc(struct gdbarch *gdbarch, const char *args, enum info_proc_what what)
CORE_ADDR linux_get_hwcap2()
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
bool linux_address_in_memtag_page(CORE_ADDR address)
static void linux_make_mappings_corefile_notes(struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr< char > ¬e_data, int *note_size)
#define GDB_MMAP_MAP_ANONYMOUS
#define GDB_MMAP_MAP_PRIVATE
static void linux_corefile_thread(struct thread_info *info, struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr< char > ¬e_data, int *note_size, gdb_signal stop_signal)
static struct type * linux_get_siginfo_type(struct gdbarch *gdbarch)
static linux_find_memory_region_ftype linux_make_mappings_callback
int linux_dump_mapping_p_ftype(filter_flags filterflags, const struct smaps_vmflags *v, int maybe_private_p, int mapping_anon_p, int mapping_file_p, const char *filename, ULONGEST addr, ULONGEST offset)
static int mapping_is_anonymous_p(const char *filename)
static struct linux_gdbarch_data * get_linux_gdbarch_data(struct gdbarch *gdbarch)
const displaced_step_copy_insn_closure * linux_displaced_step_copy_insn_closure_by_addr(inferior *inf, CORE_ADDR addr)
int linux_is_uclinux(void)
static int dump_note_entry_p(filter_flags filterflags, const struct smaps_vmflags *v, int maybe_private_p, int mapping_anon_p, int mapping_file_p, const char *filename, ULONGEST addr, ULONGEST offset)
CORE_ADDR linux_get_hwcap()
static CORE_ADDR linux_get_hwcap_helper(const gdb::optional< gdb::byte_vector > &auxv, target_ops *target, gdbarch *gdbarch, CORE_ADDR match)
static void decode_vmflags(char *p, struct smaps_vmflags *v)
static void linux_core_info_proc_mappings(struct gdbarch *gdbarch, const char *args)
static const registry< inferior >::key< linux_info > linux_inferior_data
struct type * linux_get_siginfo_type_with_fields(struct gdbarch *gdbarch, linux_siginfo_extra_fields extra_fields)
static int linux_find_memory_regions(struct gdbarch *gdbarch, find_memory_region_ftype func, void *obfd)
static bool linux_process_address_in_memtag_page(CORE_ADDR address)
static void linux_infcall_munmap(CORE_ADDR addr, CORE_ADDR size)
static void linux_core_info_proc(struct gdbarch *gdbarch, const char *args, enum info_proc_what what)
static gdb::byte_vector linux_get_siginfo_data(thread_info *thread, struct gdbarch *gdbarch)
void _initialize_linux_tdep()
static void invalidate_linux_cache_inf(struct inferior *inf)
static void linux_read_core_file_mappings(struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb)
@ LINUX_SIGINFO_FIELD_ADDR_BND
bool get_next_core_memtag_section(bfd *abfd, asection *section, CORE_ADDR address, memtag_section_info &info)
observable< struct inferior * > inferior_exit
observable< inferior *, inferior * > inferior_execd
observable< struct inferior * > inferior_appeared
void(* func)(remote_target *remote, char *)
find_memory_region_ftype func
struct type * siginfo_type
int num_disp_step_buffers
gdb::optional< displaced_step_buffers > disp_step_bufs
struct obstack * filename_obstack
struct obstack * data_obstack
compiled_regex file_deleted
compiled_regex shmem_file
gdb::string_view permissions
struct gdbarch * arch() const
struct smaps_vmflags vmflags
unsigned int initialized_p
unsigned int shared_mapping
unsigned int uses_huge_tlb
unsigned int exclude_coredump
unsigned int memory_tagging
void set_target_type(struct type *target_type)
void set_name(const char *name)
void set_target_is_stub(bool target_is_stub)
struct gdbarch * arch() const
gdb::unique_xmalloc_ptr< char > target_fileio_read_stralloc(struct inferior *inf, const char *filename)
gdbarch * target_thread_architecture(ptid_t ptid)
LONGEST target_fileio_read_alloc(struct inferior *inf, const char *filename, gdb_byte **buf_p)
bool target_has_execution(inferior *inf)
gdb::optional< gdb::byte_vector > target_read_alloc(struct target_ops *ops, enum target_object object, const char *annex)
LONGEST target_read(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *buf, ULONGEST offset, LONGEST len)
std::string normal_pid_to_str(ptid_t ptid)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
gdb::optional< std::string > target_fileio_readlink(struct inferior *inf, const char *filename, fileio_error *target_errno)
@ TARGET_OBJECT_SIGNAL_INFO
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
CORE_ADDR value_as_address(struct value *val)
struct value * value_from_ulongest(struct type *type, ULONGEST num)
struct value * value_from_longest(struct type *type, LONGEST num)
LONGEST value_as_long(struct value *val)
void pack_long(gdb_byte *buf, struct type *type, LONGEST num)
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)