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)
265 linux_siginfo_extra_fields extra_fields)
268 struct type *int_type, *uint_type, *long_type, *void_ptr_type, *short_type;
269 struct type *uid_type, *pid_type;
270 struct type *sigval_type, *clock_type;
271 struct type *siginfo_type, *sifields_type;
290 sigval_type->
set_name (xstrdup (
"sigval_t"));
296 int_type->
length () * TARGET_CHAR_BIT,
"__pid_t");
302 uint_type->
length () * TARGET_CHAR_BIT,
"__uid_t");
308 long_type->
length () * TARGET_CHAR_BIT,
317 const int si_max_size = 128;
323 si_pad_size = (si_max_size / size_of_int) - 4;
325 si_pad_size = (si_max_size / size_of_int) - 3;
366 struct type *sigfault_bnd_fields;
391 siginfo_type->
set_name (xstrdup (
"siginfo"));
396 "_sifields", sifields_type,
436 if (ptid.lwp () != 0)
437 return string_printf (
"LWP %ld", ptid.lwp ());
464 const char *p = line;
472 const char *permissions_start = p;
473 while (*p && !isspace (*p))
480 const char *device_start = p;
481 while (*p && !isspace (*p))
483 mapping.
device = {device_start, (size_t) (p - device_start)};
505 char *saveptr = NULL;
509 p = skip_to_space (p);
512 for (s = strtok_r (p,
" ", &saveptr);
514 s = strtok_r (NULL,
" ", &saveptr))
516 if (strcmp (s,
"io") == 0)
518 else if (strcmp (s,
"ht") == 0)
520 else if (strcmp (s,
"dd") == 0)
522 else if (strcmp (s,
"sh") == 0)
524 else if (strcmp (s,
"mt") == 0)
539 {
"^/dev/zero\\( (deleted)\\)\\?$", REG_NOSUB,
540 _(
"Could not compile regex to match /dev/zero filename")};
547 {
"^/\\?SYSV[0-9a-fA-F]\\{8\\}\\( (deleted)\\)\\?$", REG_NOSUB,
548 _(
"Could not compile regex to match shmem filenames")};
563 {
" (deleted)$", REG_NOSUB,
564 _(
"Could not compile regex to match '<file> (deleted)'")};
580 static gdb::optional<mapping_regexes> regexes;
581 static int init_regex_p = 0;
595 if (init_regex_p == -1)
597 const char deleted[] =
" (deleted)";
598 size_t del_len =
sizeof (deleted) - 1;
599 size_t filename_len = strlen (filename);
606 return (filename_len >= del_len
607 && strcmp (filename + filename_len - del_len, deleted) == 0);
610 if (*filename ==
'\0'
611 || regexes->dev_zero.exec (filename, 0, NULL, 0) == 0
612 || regexes->shmem_file.exec (filename, 0, NULL, 0) == 0
613 || regexes->file_deleted.exec (filename, 0, NULL, 0) == 0)
668 int maybe_private_p,
int mapping_anon_p,
int mapping_file_p,
669 const char *filename, ULONGEST addr, ULONGEST offset)
678 int private_p = maybe_private_p;
684 if (strcmp (
"[vdso]", filename) == 0
685 || strcmp (
"[vsyscall]", filename) == 0)
715 if (mapping_anon_p && mapping_file_p)
723 else if (mapping_anon_p)
730 if (mapping_anon_p && mapping_file_p)
738 else if (mapping_anon_p)
752 if (!dump_p && private_p && offset == 0
767 if (h[EI_MAG0] == ELFMAG0 && h[EI_MAG1] == ELFMAG1
768 && h[EI_MAG2] == ELFMAG2 && h[EI_MAG3] == ELFMAG3)
785 int maybe_private_p,
int mapping_anon_p,
int mapping_file_p,
786 const char *filename, ULONGEST addr, ULONGEST offset)
790 if (strcmp (
"[vdso]", filename) == 0
791 || strcmp (
"[vsyscall]", filename) == 0)
815 fileio_error target_errno;
817 if (args && isdigit (args[0]))
821 pid = strtoul (args, &tem, 10);
827 error (_(
"No current process: you must name one."));
829 error (_(
"Can't determine the current process's PID: you must name one."));
834 args = skip_spaces (args);
836 error (_(
"Too many parameters: %s"), args);
841 xsnprintf (filename,
sizeof filename,
"/proc/%ld/cmdline",
pid);
847 gdb::unique_xmalloc_ptr<char> cmdline ((
char *) buffer);
850 for (pos = 0; pos < len - 1; pos++)
852 if (buffer[pos] ==
'\0')
855 buffer[len - 1] =
'\0';
859 warning (_(
"unable to open /proc file '%s'"), filename);
863 xsnprintf (filename,
sizeof filename,
"/proc/%ld/cwd",
pid);
864 gdb::optional<std::string> contents
866 if (contents.has_value ())
867 gdb_printf (
"cwd = '%s'\n", contents->c_str ());
869 warning (_(
"unable to read link '%s'"), filename);
873 xsnprintf (filename,
sizeof filename,
"/proc/%ld/exe",
pid);
874 gdb::optional<std::string> contents
876 if (contents.has_value ())
877 gdb_printf (
"exe = '%s'\n", contents->c_str ());
879 warning (_(
"unable to read link '%s'"), filename);
883 xsnprintf (filename,
sizeof filename,
"/proc/%ld/maps",
pid);
884 gdb::unique_xmalloc_ptr<char> map
894 "Start Addr",
" End Addr",
" Size",
895 " Offset",
"Perms ",
"objfile");
900 "Start Addr",
" End Addr",
" Size",
901 " Offset",
"Perms ",
"objfile");
905 for (line = strtok_r (map.get (),
"\n", &saveptr);
907 line = strtok_r (NULL,
"\n", &saveptr))
913 gdb_printf (
"\t%10s %10s %10s %10s %-5.*s %s\n",
916 hex_string (m.endaddr - m.addr),
917 hex_string (m.offset),
918 (
int) m.permissions.size (),
919 m.permissions.data (),
924 gdb_printf (
" %18s %18s %10s %10s %-5.*s %s\n",
927 hex_string (m.endaddr - m.addr),
928 hex_string (m.offset),
929 (
int) m.permissions.size (),
930 m.permissions.data (),
936 warning (_(
"unable to open /proc file '%s'"),
filename);
941 gdb::unique_xmalloc_ptr<char>
status
946 warning (_(
"unable to open /proc file '%s'"),
filename);
951 gdb::unique_xmalloc_ptr<char> statstr
955 const char *p = statstr.get ();
958 pulongest (strtoulst (p, &p, 10)));
965 const char *ep = strrchr (p,
')');
969 (
int) (ep - p - 1), p + 1);
980 pulongest (strtoulst (p, &p, 10)));
983 pulongest (strtoulst (p, &p, 10)));
986 pulongest (strtoulst (p, &p, 10)));
989 pulongest (strtoulst (p, &p, 10)));
991 gdb_printf (_(
"TTY owner process group: %s\n"),
992 pulongest (strtoulst (p, &p, 10)));
996 hex_string (strtoulst (p, &p, 10)));
998 gdb_printf (_(
"Minor faults (no memory page): %s\n"),
999 pulongest (strtoulst (p, &p, 10)));
1001 gdb_printf (_(
"Minor faults, children: %s\n"),
1002 pulongest (strtoulst (p, &p, 10)));
1004 gdb_printf (_(
"Major faults (memory page faults): %s\n"),
1005 pulongest (strtoulst (p, &p, 10)));
1007 gdb_printf (_(
"Major faults, children: %s\n"),
1008 pulongest (strtoulst (p, &p, 10)));
1011 pulongest (strtoulst (p, &p, 10)));
1014 pulongest (strtoulst (p, &p, 10)));
1017 pulongest (strtoulst (p, &p, 10)));
1020 pulongest (strtoulst (p, &p, 10)));
1022 gdb_printf (_(
"jiffies remaining in current "
1023 "time slice: %s\n"),
1024 pulongest (strtoulst (p, &p, 10)));
1027 pulongest (strtoulst (p, &p, 10)));
1029 gdb_printf (_(
"jiffies until next timeout: %s\n"),
1030 pulongest (strtoulst (p, &p, 10)));
1032 gdb_printf (_(
"jiffies until next SIGALRM: %s\n"),
1033 pulongest (strtoulst (p, &p, 10)));
1036 "system boot): %s\n"),
1037 pulongest (strtoulst (p, &p, 10)));
1040 pulongest (strtoulst (p, &p, 10)));
1043 pulongest (strtoulst (p, &p, 10)));
1046 pulongest (strtoulst (p, &p, 10)));
1049 hex_string (strtoulst (p, &p, 10)));
1052 hex_string (strtoulst (p, &p, 10)));
1055 hex_string (strtoulst (p, &p, 10)));
1060 hex_string (strtoulst (p, &p, 10)));
1063 hex_string (strtoulst (p, &p, 10)));
1065 gdb_printf (_(
"Pending signals bitmap: %s\n"),
1066 hex_string (strtoulst (p, &p, 10)));
1068 gdb_printf (_(
"Blocked signals bitmap: %s\n"),
1069 hex_string (strtoulst (p, &p, 10)));
1071 gdb_printf (_(
"Ignored signals bitmap: %s\n"),
1072 hex_string (strtoulst (p, &p, 10)));
1074 gdb_printf (_(
"Catched signals bitmap: %s\n"),
1075 hex_string (strtoulst (p, &p, 10)));
1078 hex_string (strtoulst (p, &p, 10)));
1082 warning (_(
"unable to open /proc file '%s'"),
filename);
1125 asection *section = bfd_get_section_by_name (cbfd,
".note.linuxcore.file");
1126 if (section ==
nullptr)
1130 unsigned int addr_size = addr_size_bits / 8;
1131 size_t note_size = bfd_section_size (section);
1135 warning (_(
"malformed core note - too short for header"));
1139 gdb::def_vector<gdb_byte> contents (
note_size);
1140 if (!bfd_get_section_contents (
core_bfd, section, contents.data (),
1143 warning (_(
"could not get core note contents"));
1147 gdb_byte *descdata = contents.data ();
1148 char *descend = (
char *) descdata +
note_size;
1152 warning (_(
"malformed note - does not end with \\0"));
1156 ULONGEST count = bfd_get (addr_size_bits,
core_bfd, descdata);
1157 descdata += addr_size;
1159 ULONGEST page_size = bfd_get (addr_size_bits,
core_bfd, descdata);
1160 descdata += addr_size;
1162 if (
note_size < 2 * addr_size + count * 3 * addr_size)
1164 warning (_(
"malformed note - too short for supplied file count"));
1168 char *filenames = (
char *) descdata + count * 3 * addr_size;
1172 char *
f = filenames;
1173 for (
int i = 0; i < count; i++)
1177 warning (_(
"malformed note - filename area is too small"));
1180 f += strnlen (
f, descend -
f) + 1;
1184 warning (_(
"malformed note - filename area is too big"));
1186 const bfd_build_id *orig_build_id = cbfd->build_id;
1187 std::unordered_map<ULONGEST, const bfd_build_id *> vma_map;
1191 for (bfd_section *sec = cbfd->sections; sec !=
nullptr; sec = sec->next)
1193 cbfd->build_id =
nullptr;
1195 if (sec->flags & SEC_LOAD
1196 && (get_elf_backend_data (cbfd)->elf_backend_core_find_build_id
1197 (cbfd, (bfd_vma) sec->filepos)))
1198 vma_map[sec->vma] = cbfd->build_id;
1201 cbfd->build_id = orig_build_id;
1202 pre_loop_cb (count);
1204 for (
int i = 0; i < count; i++)
1206 ULONGEST start = bfd_get (addr_size_bits,
core_bfd, descdata);
1207 descdata += addr_size;
1208 ULONGEST end = bfd_get (addr_size_bits,
core_bfd, descdata);
1209 descdata += addr_size;
1211 = bfd_get (addr_size_bits,
core_bfd, descdata) * page_size;
1212 descdata += addr_size;
1214 filenames += strlen ((
char *) filenames) + 1;
1215 const bfd_build_id *build_id =
nullptr;
1216 auto vma_map_it = vma_map.find (start);
1218 if (vma_map_it != vma_map.end ())
1219 build_id = vma_map_it->second;
1221 loop_cb (i, start, end, file_ofs,
filename, build_id);
1231 [=] (ULONGEST count)
1233 gdb_printf (_(
"Mapped address spaces:\n\n"));
1239 " Size",
" Offset",
"objfile");
1246 " Size",
" Offset",
"objfile");
1249 [=] (
int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs,
1250 const char *
filename,
const bfd_build_id *build_id)
1256 hex_string (end - start),
1257 hex_string (file_ofs),
1263 hex_string (end - start),
1264 hex_string (file_ofs),
1282 exe = bfd_core_file_failing_command (
core_bfd);
1286 warning (_(
"unable to find command name in core file"));
1292 if (!exe_f && !mappings_f)
1293 error (_(
"unable to handle request"));
1303 ULONGEST
offset, ULONGEST len)
1306 asection *section = bfd_get_section_by_name (
core_bfd, section_name.
c_str ());
1307 if (section == NULL)
1310 if (!bfd_get_section_contents (
core_bfd, section, readbuf,
offset, len))
1318 int read,
int write,
1319 int exec,
int modified,
1326 int maybe_private_p,
1339static std::vector<struct smaps_data>
1341 const std::string maps_filename)
1345 gdb_assert (data !=
nullptr);
1347 line = strtok_r ((
char *) data,
"\n", &t);
1349 std::vector<struct smaps_data> smaps;
1351 while (line != NULL)
1354 int read, write, exec, priv;
1355 int has_anonymous = 0;
1359 memset (&v, 0,
sizeof (v));
1371 mapping_file_p = !mapping_anon_p;
1374 auto has_perm = [&m] (
char c)
1375 {
return m.permissions.find (c) != gdb::string_view::npos; };
1376 read = has_perm (
'r');
1377 write = has_perm (
'w');
1378 exec = has_perm (
'x');
1389 priv = has_perm (
'p');
1393 for (line = strtok_r (NULL,
"\n", &t);
1394 line != NULL && line[0] >=
'A' && line[0] <=
'Z';
1395 line = strtok_r (NULL,
"\n", &t))
1399 if (sscanf (line,
"%64s",
keyword) != 1)
1401 warning (_(
"Error parsing {s,}maps file '%s'"),
1402 maps_filename.c_str ());
1406 if (strcmp (
keyword,
"Anonymous:") == 0)
1412 else if (strcmp (
keyword,
"VmFlags:") == 0)
1415 if (strcmp (
keyword,
"AnonHugePages:") == 0
1416 || strcmp (
keyword,
"Anonymous:") == 0)
1418 unsigned long number;
1420 if (sscanf (line,
"%*s%lu", &number) != 1)
1422 warning (_(
"Error parsing {s,}maps file '%s' number"),
1423 maps_filename.c_str ());
1463 map.
inode = m.inode;
1465 smaps.emplace_back (map);
1482 std::string smaps_file = string_printf (
"/proc/%d/smaps",
pid);
1484 gdb::unique_xmalloc_ptr<char> data
1487 if (data ==
nullptr)
1491 std::vector<struct smaps_data> smaps
1498 if (address >= map.start_address
1499 && address < map.end_address
1500 && map.vmflags.memory_tagging)
1556 std::string core_dump_filter_name
1557 = string_printf (
"/proc/%d/coredump_filter",
pid);
1559 gdb::unique_xmalloc_ptr<char> coredumpfilterdata
1562 if (coredumpfilterdata != NULL)
1566 sscanf (coredumpfilterdata.get (),
"%x", &
flags);
1571 std::string maps_filename = string_printf (
"/proc/%d/smaps",
pid);
1573 gdb::unique_xmalloc_ptr<char> data
1579 maps_filename = string_printf (
"/proc/%d/maps",
pid);
1582 if (data ==
nullptr)
1587 std::vector<struct smaps_data> smaps
1592 int should_dump_p = 0;
1594 if (map.has_anonymous)
1597 = should_dump_mapping_p (filterflags, &map.vmflags,
1601 map.filename.c_str (),
1615 func (map.start_address, map.end_address - map.start_address,
1616 map.offset, map.inode, map.read, map.write, map.exec,
1619 map.vmflags.memory_tagging != 0,
1620 map.filename.c_str (),
obfd);
1646 ULONGEST offset, ULONGEST inode,
1647 int read,
int write,
int exec,
int modified,
1649 const char *filename,
void *arg)
1654 return data->func (vaddr,
size,
read, write, exec, modified, memory_tagged,
1705 ULONGEST offset, ULONGEST inode,
1706 int read,
int write,
int exec,
int modified,
1708 const char *filename,
void *data)
1712 gdb_byte buf[
sizeof (ULONGEST)];
1714 if (*filename ==
'\0' || inode == 0)
1737 gdb::unique_xmalloc_ptr<char> ¬e_data,
1741 struct type *long_type
1743 gdb_byte buf[
sizeof (ULONGEST)];
1745 auto_obstack data_obstack, filename_obstack;
1753 obstack_blank (&data_obstack, long_type->
length ());
1757 obstack_grow (&data_obstack, buf, long_type->
length ());
1767 pack_long ((gdb_byte *) obstack_base (&data_obstack),
1771 int size = obstack_object_size (&filename_obstack);
1772 obstack_grow (&data_obstack, obstack_base (&filename_obstack),
1775 note_data.reset (elfcore_write_file_note (
obfd, note_data.release (),
note_size,
1776 obstack_base (&data_obstack),
1777 obstack_object_size (&data_obstack)));
1785static gdb::byte_vector
1788 struct type *siginfo_type;
1792 return gdb::byte_vector ();
1799 gdb::byte_vector buf (siginfo_type->
length ());
1803 buf.data (), 0, siginfo_type->
length ());
1804 if (bytes_read != siginfo_type->
length ())
1813 gdb::unique_xmalloc_ptr<char> &
note_data,
1835 args->obfd, &args->note_data,
1840 if (args->note_data != NULL)
1842 gdb::byte_vector siginfo_data
1844 if (!siginfo_data.empty ())
1845 args->note_data.reset (elfcore_write_note (args->obfd,
1846 args->note_data.release (),
1849 siginfo_data.data (),
1850 siginfo_data.size ()));
1868 const char *basename;
1872 const char valid_states[] =
"RSDTZW";
1874 const char *prog_state;
1880 unsigned int pr_flag;
1886 gdb_assert (p != NULL);
1890 xsnprintf (filename,
sizeof (filename),
"/proc/%d/cmdline", (
int)
pid);
1892 gdb::unique_xmalloc_ptr<char> fname
1895 if (fname == NULL || fname.get ()[0] ==
'\0')
1902 memset (p, 0,
sizeof (*p));
1908 basename = lbasename (fname.get ());
1909 strncpy (p->pr_fname, basename, sizeof (p->pr_fname) - 1);
1910 p->pr_fname[
sizeof (p->pr_fname) - 1] =
'\0';
1915 std::string psargs = fname.get ();
1916 if (!infargs.empty ())
1917 psargs +=
' ' + infargs;
1919 strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs) - 1);
1920 p->pr_psargs[
sizeof (p->pr_psargs) - 1] =
'\0';
1922 xsnprintf (filename,
sizeof (filename),
"/proc/%d/stat", (
int)
pid);
1924 gdb::unique_xmalloc_ptr<char> proc_stat_contents
1926 char *proc_stat = proc_stat_contents.get ();
1928 if (proc_stat == NULL || *proc_stat ==
'\0')
1946 while (isdigit (*proc_stat))
1949 proc_stat = skip_spaces (proc_stat);
1952 proc_stat = strrchr (proc_stat,
')');
1953 if (proc_stat == NULL)
1957 proc_stat = skip_spaces (proc_stat);
1959 n_fields = sscanf (proc_stat,
1971 &p->pr_ppid, &p->pr_pgrp, &p->pr_sid,
1984 prog_state = strchr (valid_states, pr_sname);
1985 if (prog_state != NULL)
1986 p->pr_state = prog_state - valid_states;
1993 p->pr_sname = p->pr_state > 5 ?
'.' : pr_sname;
1994 p->pr_zomb = p->pr_sname ==
'Z';
1995 p->pr_nice = pr_nice;
1996 p->pr_flag = pr_flag;
2000 xsnprintf (filename,
sizeof (filename),
"/proc/%d/status", (
int)
pid);
2002 gdb::unique_xmalloc_ptr<char> proc_status_contents
2004 char *proc_status = proc_status_contents.get ();
2006 if (proc_status == NULL || *proc_status ==
'\0')
2013 tmpstr = strstr (proc_status,
"Uid:");
2017 tmpstr +=
sizeof (
"Uid:");
2018 while (*tmpstr !=
'\0' && !isdigit (*tmpstr))
2021 if (isdigit (*tmpstr))
2022 p->pr_uid = strtol (tmpstr, &tmpstr, 10);
2026 tmpstr = strstr (proc_status,
"Gid:");
2030 tmpstr +=
sizeof (
"Gid:");
2031 while (*tmpstr !=
'\0' && !isdigit (*tmpstr))
2034 if (isdigit (*tmpstr))
2035 p->pr_gid = strtol (tmpstr, &tmpstr, 10);
2044static gdb::unique_xmalloc_ptr<char>
2047 struct elf_internal_linux_prpsinfo prpsinfo;
2048 gdb::unique_xmalloc_ptr<char> note_data;
2056 note_data.reset (elfcore_write_linux_prpsinfo64 (
obfd,
2057 note_data.release (),
2060 note_data.reset (elfcore_write_linux_prpsinfo32 (
obfd,
2061 note_data.release (),
2070 catch (
const gdb_exception_error &e)
2079 gdb_signal stop_signal;
2080 if (signalled_thr !=
nullptr)
2083 stop_signal = GDB_SIGNAL_0;
2088 if (signalled_thr !=
nullptr)
2092 if (thr == signalled_thr)
2102 gdb::optional<gdb::byte_vector> auxv =
2105 if (auxv && !auxv->empty ())
2107 note_data.reset (elfcore_write_note (
obfd, note_data.release (),
2109 auxv->data (), auxv->size ()));
2134 return GDB_SIGNAL_0;
2137 return GDB_SIGNAL_HUP;
2140 return GDB_SIGNAL_INT;
2143 return GDB_SIGNAL_QUIT;
2146 return GDB_SIGNAL_ILL;
2149 return GDB_SIGNAL_TRAP;
2152 return GDB_SIGNAL_ABRT;
2155 return GDB_SIGNAL_BUS;
2158 return GDB_SIGNAL_FPE;
2161 return GDB_SIGNAL_KILL;
2164 return GDB_SIGNAL_USR1;
2167 return GDB_SIGNAL_SEGV;
2170 return GDB_SIGNAL_USR2;
2173 return GDB_SIGNAL_PIPE;
2176 return GDB_SIGNAL_ALRM;
2179 return GDB_SIGNAL_TERM;
2182 return GDB_SIGNAL_CHLD;
2185 return GDB_SIGNAL_CONT;
2188 return GDB_SIGNAL_STOP;
2191 return GDB_SIGNAL_TSTP;
2194 return GDB_SIGNAL_TTIN;
2197 return GDB_SIGNAL_TTOU;
2200 return GDB_SIGNAL_URG;
2203 return GDB_SIGNAL_XCPU;
2206 return GDB_SIGNAL_XFSZ;
2209 return GDB_SIGNAL_VTALRM;
2212 return GDB_SIGNAL_PROF;
2215 return GDB_SIGNAL_WINCH;
2220 return GDB_SIGNAL_IO;
2223 return GDB_SIGNAL_PWR;
2226 return GDB_SIGNAL_SYS;
2231 return GDB_SIGNAL_REALTIME_32;
2234 return GDB_SIGNAL_REALTIME_64;
2241 return (
enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_33 + offset);
2244 return GDB_SIGNAL_UNKNOWN;
2253 enum gdb_signal signal)
2260 case GDB_SIGNAL_HUP:
2263 case GDB_SIGNAL_INT:
2266 case GDB_SIGNAL_QUIT:
2269 case GDB_SIGNAL_ILL:
2272 case GDB_SIGNAL_TRAP:
2275 case GDB_SIGNAL_ABRT:
2278 case GDB_SIGNAL_FPE:
2281 case GDB_SIGNAL_KILL:
2284 case GDB_SIGNAL_BUS:
2287 case GDB_SIGNAL_SEGV:
2290 case GDB_SIGNAL_SYS:
2293 case GDB_SIGNAL_PIPE:
2296 case GDB_SIGNAL_ALRM:
2299 case GDB_SIGNAL_TERM:
2302 case GDB_SIGNAL_URG:
2305 case GDB_SIGNAL_STOP:
2308 case GDB_SIGNAL_TSTP:
2311 case GDB_SIGNAL_CONT:
2314 case GDB_SIGNAL_CHLD:
2317 case GDB_SIGNAL_TTIN:
2320 case GDB_SIGNAL_TTOU:
2326 case GDB_SIGNAL_XCPU:
2329 case GDB_SIGNAL_XFSZ:
2332 case GDB_SIGNAL_VTALRM:
2335 case GDB_SIGNAL_PROF:
2338 case GDB_SIGNAL_WINCH:
2341 case GDB_SIGNAL_USR1:
2344 case GDB_SIGNAL_USR2:
2347 case GDB_SIGNAL_PWR:
2350 case GDB_SIGNAL_POLL:
2355 case GDB_SIGNAL_REALTIME_32:
2359 case GDB_SIGNAL_REALTIME_64:
2364 if (signal >= GDB_SIGNAL_REALTIME_33
2365 && signal <= GDB_SIGNAL_REALTIME_63)
2367 int offset = signal - GDB_SIGNAL_REALTIME_33;
2395 phdrs_size = bfd_get_elf_phdr_upper_bound (
core_bfd);
2396 if (phdrs_size == -1)
2399 gdb::unique_xmalloc_ptr<Elf_Internal_Phdr>
2400 phdrs ((Elf_Internal_Phdr *)
xmalloc (phdrs_size));
2401 num_phdrs = bfd_get_elf_phdrs (
core_bfd, phdrs.get ());
2402 if (num_phdrs == -1)
2405 for (i = 0; i < num_phdrs; i++)
2406 if (phdrs.get ()[i].p_type == PT_LOAD
2407 && phdrs.get ()[i].p_vaddr ==
range->start)
2430 xsnprintf (filename,
sizeof filename,
"/proc/%ld/task/%ld/maps",
pid,
pid);
2431 gdb::unique_xmalloc_ptr<char> data
2436 char *saveptr = NULL;
2438 for (line = strtok_r (data.get (),
"\n", &saveptr);
2440 line = strtok_r (NULL,
"\n", &saveptr))
2442 ULONGEST addr, endaddr;
2443 const char *p = line;
2445 addr = strtoulst (p, &p, 16);
2446 if (addr ==
range->start)
2450 endaddr = strtoulst (p, &p, 16);
2457 warning (_(
"unable to open /proc file '%s'"), filename);
2470 if (info->vsyscall_range_p == 0)
2473 info->vsyscall_range_p = 1;
2475 info->vsyscall_range_p = -1;
2478 if (info->vsyscall_range_p < 0)
2481 *
range = info->vsyscall_range;
2487#define GDB_MMAP_MAP_PRIVATE 0x02
2488#define GDB_MMAP_MAP_ANONYMOUS 0x20
2499 struct value *addr_val;
2504 ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_LAST
2506 struct value *arg[ARG_LAST];
2525 if (retval == (CORE_ADDR) -1)
2526 error (_(
"Failed inferior mmap call for %s bytes, errno is changed."),
2538 struct value *retval_val;
2543 ARG_ADDR, ARG_LENGTH, ARG_LAST
2545 struct value *arg[ARG_LAST];
2555 warning (_(
"Failed inferior munmap call at %s for %s bytes, "
2556 "errno is changed."),
2557 hex_string (addr), pulongest (
size));
2575 throw_error (NOT_SUPPORTED_ERROR,
2576 _(
"Cannot find AT_ENTRY auxiliary vector entry."));
2596 CORE_ADDR &displaced_pc)
2604 CORE_ADDR disp_step_buf_addr
2611 std::vector<CORE_ADDR> buffers;
2613 buffers.push_back (disp_step_buf_addr + i * buf_len);
2618 return per_inferior->
disp_step_bufs->prepare (thread, displaced_pc);
2640 if (per_inferior ==
nullptr
2644 return per_inferior->
disp_step_bufs->copy_insn_closure_by_addr (addr);
2654 if (per_inferior ==
nullptr
2668 if (!auxv.has_value ()
2719 gdb_printf (file, _(
"Use of /proc/PID/coredump_filter file to generate"
2720 " corefiles is %s.\n"),
value);
2730 gdb_printf (file, _(
"Dumping of mappings marked with the VM_DONTDUMP"
2731 " flag is %s.\n"),
value);
2742 int num_disp_step_buffers)
2744 if (num_disp_step_buffers > 0)
2791Set whether gcore should consider /proc/PID/coredump_filter."),
2793Show whether gcore should consider /proc/PID/coredump_filter."),
2795Use this command to set whether gcore should consider the contents\n\
2796of /proc/PID/coredump_filter when generating the corefile. For more information\n\
2797about this file, refer to the manpage of core(5)."),
2803Set whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
2805Show whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
2807Use this command to set whether gcore should dump mappings marked with the\n\
2808VM_DONTDUMP flag (\"dd\" in /proc/PID/smaps) when generating the corefile. For\n\
2809more 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)
gdb::optional< gdb::byte_vector > target_read_auxv()
const std::string & args() const
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(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)
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)
ULONGEST gdbarch_max_insn_length(struct gdbarch *gdbarch)
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
gdb::function_view< void(ULONGEST count)> read_core_file_mappings_pre_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 * arch_composite_type(struct gdbarch *gdbarch, const char *name, enum type_code code)
struct type * init_vector_type(struct type *elt_type, int n)
struct type * arch_type(struct gdbarch *gdbarch, enum type_code code, int bit, const char *name)
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)
struct type * arch_integer_type(struct gdbarch *gdbarch, int bit, int unsigned_p, const char *name)
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 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 void linux_corefile_thread(struct thread_info *info, struct linux_corefile_thread_data *args)
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
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 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)
displaced_step_finish_status linux_displaced_step_finish(gdbarch *arch, thread_info *thread, gdb_signal sig)
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< struct inferior * > inferior_execd
observable< struct inferior * > inferior_appeared
void(* func)(remote_target *remote, char *)
gdb::unique_xmalloc_ptr< char > & note_data
linux_corefile_thread_data(struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr< char > ¬e_data, int *note_size, gdb_signal stop_signal)
enum gdb_signal stop_signal
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)
gdb::unique_xmalloc_ptr< char > target_fileio_read_stralloc(struct inferior *inf, const char *filename)
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)