diff options
Diffstat (limited to 'gdb/nat')
62 files changed, 242 insertions, 108 deletions
diff --git a/gdb/nat/aarch64-hw-point.c b/gdb/nat/aarch64-hw-point.c index 8ab91fe..6d8dce8 100644 --- a/gdb/nat/aarch64-hw-point.c +++ b/gdb/nat/aarch64-hw-point.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-hw-point.h b/gdb/nat/aarch64-hw-point.h index 9f9c85e..f8ab55f 100644 --- a/gdb/nat/aarch64-hw-point.h +++ b/gdb/nat/aarch64-hw-point.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c index 43e04fe..3f0c8b9 100644 --- a/gdb/nat/aarch64-linux-hw-point.c +++ b/gdb/nat/aarch64-linux-hw-point.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. Contributed by ARM Ltd. This file is part of GDB. diff --git a/gdb/nat/aarch64-linux-hw-point.h b/gdb/nat/aarch64-linux-hw-point.h index 618f79f..8cbe6c5 100644 --- a/gdb/nat/aarch64-linux-hw-point.h +++ b/gdb/nat/aarch64-linux-hw-point.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. Contributed by ARM Ltd. This file is part of GDB. diff --git a/gdb/nat/aarch64-linux.c b/gdb/nat/aarch64-linux.c index 5a95f22..23158bc 100644 --- a/gdb/nat/aarch64-linux.c +++ b/gdb/nat/aarch64-linux.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. Contributed by ARM Ltd. This file is part of GDB. diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h index 969bb52..be32f6d 100644 --- a/gdb/nat/aarch64-linux.h +++ b/gdb/nat/aarch64-linux.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. Contributed by ARM Ltd. This file is part of GDB. diff --git a/gdb/nat/aarch64-mte-linux-ptrace.c b/gdb/nat/aarch64-mte-linux-ptrace.c index f215588..308bc9a 100644 --- a/gdb/nat/aarch64-mte-linux-ptrace.c +++ b/gdb/nat/aarch64-mte-linux-ptrace.c @@ -1,6 +1,6 @@ /* Common Linux native ptrace code for AArch64 MTE. - Copyright (C) 2021-2024 Free Software Foundation, Inc. + Copyright (C) 2021-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-mte-linux-ptrace.h b/gdb/nat/aarch64-mte-linux-ptrace.h index e02a081..7c496a9 100644 --- a/gdb/nat/aarch64-mte-linux-ptrace.h +++ b/gdb/nat/aarch64-mte-linux-ptrace.h @@ -1,6 +1,6 @@ /* Common native Linux definitions for AArch64 MTE. - Copyright (C) 2021-2024 Free Software Foundation, Inc. + Copyright (C) 2021-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.c b/gdb/nat/aarch64-scalable-linux-ptrace.c index 1d226b4..ec8ee33 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.c +++ b/gdb/nat/aarch64-scalable-linux-ptrace.c @@ -1,6 +1,6 @@ /* Common native Linux code for the AArch64 scalable extensions: SVE and SME. - Copyright (C) 2018-2024 Free Software Foundation, Inc. + Copyright (C) 2018-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.h b/gdb/nat/aarch64-scalable-linux-ptrace.h index 2c6d899..f9dbf00 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.h +++ b/gdb/nat/aarch64-scalable-linux-ptrace.h @@ -1,7 +1,7 @@ /* Common native Linux definitions for the AArch64 scalable extensions: SVE and SME. - Copyright (C) 2018-2024 Free Software Foundation, Inc. + Copyright (C) 2018-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/aarch64-scalable-linux-sigcontext.h b/gdb/nat/aarch64-scalable-linux-sigcontext.h index bfda9be..a588b64 100644 --- a/gdb/nat/aarch64-scalable-linux-sigcontext.h +++ b/gdb/nat/aarch64-scalable-linux-sigcontext.h @@ -1,7 +1,7 @@ /* Linux Kernel sigcontext definitions for AArch64 Scalable Extensions (SVE/SME). - Copyright (C) 2018-2024 Free Software Foundation, Inc. + Copyright (C) 2018-2025 Free Software Foundation, Inc. Contributed by Arm Ltd. This file is part of GDB. diff --git a/gdb/nat/amd64-linux-siginfo.c b/gdb/nat/amd64-linux-siginfo.c index f5e9994..9200721 100644 --- a/gdb/nat/amd64-linux-siginfo.c +++ b/gdb/nat/amd64-linux-siginfo.c @@ -1,6 +1,6 @@ /* Low-level siginfo manipulation for amd64. - Copyright (C) 2002-2024 Free Software Foundation, Inc. + Copyright (C) 2002-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/amd64-linux-siginfo.h b/gdb/nat/amd64-linux-siginfo.h index 1e102ae..298574f 100644 --- a/gdb/nat/amd64-linux-siginfo.h +++ b/gdb/nat/amd64-linux-siginfo.h @@ -1,6 +1,6 @@ /* Low-level siginfo manipulation for amd64. - Copyright (C) 2016-2024 Free Software Foundation, Inc. + Copyright (C) 2016-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index 46fe897..b6cf410 100644 --- a/gdb/nat/fork-inferior.c +++ b/gdb/nat/fork-inferior.c @@ -1,6 +1,6 @@ /* Fork a Unix child process, and set up to debug it, for GDB and GDBserver. - Copyright (C) 1990-2024 Free Software Foundation, Inc. + Copyright (C) 1990-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/fork-inferior.h b/gdb/nat/fork-inferior.h index 41dad71..d52aa44 100644 --- a/gdb/nat/fork-inferior.h +++ b/gdb/nat/fork-inferior.h @@ -1,6 +1,6 @@ /* Functions and data responsible for forking the inferior process. - Copyright (C) 1986-2024 Free Software Foundation, Inc. + Copyright (C) 1986-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/gdb_ptrace.h b/gdb/nat/gdb_ptrace.h index 1785884..dee6e58 100644 --- a/gdb/nat/gdb_ptrace.h +++ b/gdb/nat/gdb_ptrace.h @@ -1,6 +1,6 @@ /* Portable <sys/ptrace.h> - Copyright (C) 2004-2024 Free Software Foundation, Inc. + Copyright (C) 2004-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/gdb_thread_db.h b/gdb/nat/gdb_thread_db.h index 446b921..4560064 100644 --- a/gdb/nat/gdb_thread_db.h +++ b/gdb/nat/gdb_thread_db.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2024 Free Software Foundation, Inc. +/* Copyright (C) 2000-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/i386-linux.c b/gdb/nat/i386-linux.c index 64605be..7a09862 100644 --- a/gdb/nat/i386-linux.c +++ b/gdb/nat/i386-linux.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux i386. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/i386-linux.h b/gdb/nat/i386-linux.h index f222d51..d80e0f9 100644 --- a/gdb/nat/i386-linux.h +++ b/gdb/nat/i386-linux.h @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux i386. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index 3dc5da7..9eadd46 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -1,6 +1,6 @@ /* Linux-dependent part of branch trace support for GDB, and GDBserver. - Copyright (C) 2013-2024 Free Software Foundation, Inc. + Copyright (C) 2013-2025 Free Software Foundation, Inc. Contributed by Intel Corp. <markus.t.metzger@intel.com> diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h index 6fd8107..01d1efa 100644 --- a/gdb/nat/linux-btrace.h +++ b/gdb/nat/linux-btrace.h @@ -1,6 +1,6 @@ /* Linux-dependent part of branch trace support for GDB, and GDBserver. - Copyright (C) 2013-2024 Free Software Foundation, Inc. + Copyright (C) 2013-2025 Free Software Foundation, Inc. Contributed by Intel Corp. <markus.t.metzger@intel.com> diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c index 19a05ee..2a65fb0 100644 --- a/gdb/nat/linux-namespaces.c +++ b/gdb/nat/linux-namespaces.c @@ -1,6 +1,6 @@ /* Linux namespaces(7) support. - Copyright (C) 2015-2024 Free Software Foundation, Inc. + Copyright (C) 2015-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -233,6 +233,12 @@ enum mnsh_msg_type MNSH_RET_INT. */ MNSH_REQ_SETNS, + /* A request that the helper call lstat. The single + argument (the filename) should be passed in BUF, and + should include a terminating NUL character. The helper + should respond with a MNSH_RET_INTSTR. */ + MNSH_REQ_LSTAT, + /* A request that the helper call open. Arguments should be passed in BUF, INT1 and INT2. The filename (in BUF) should include a terminating NUL character. The helper @@ -265,62 +271,69 @@ enum mnsh_msg_type MNSH_RET_INTSTR, }; -/* Print a string representation of a message using debug_printf. - This function is not async-signal-safe so should never be - called from the helper. */ +/* Return a string representation of a message. This function is not + async-signal-safe so should never be called from the helper. */ -static void +static std::string mnsh_debug_print_message (enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz) { + std::string res; + gdb_byte *c = (gdb_byte *) buf; gdb_byte *cl = c + bufsiz; switch (type) { case MNSH_MSG_ERROR: - debug_printf ("ERROR"); + res += "ERROR"; + break; + + case MNSH_REQ_LSTAT: + res += "LSTAT"; break; case MNSH_REQ_SETNS: - debug_printf ("SETNS"); + res += "SETNS"; break; case MNSH_REQ_OPEN: - debug_printf ("OPEN"); + res += "OPEN"; break; case MNSH_REQ_UNLINK: - debug_printf ("UNLINK"); + res += "UNLINK"; break; case MNSH_REQ_READLINK: - debug_printf ("READLINK"); + res += "READLINK"; break; case MNSH_RET_INT: - debug_printf ("INT"); + res += "INT"; break; case MNSH_RET_FD: - debug_printf ("FD"); + res += "FD"; break; case MNSH_RET_INTSTR: - debug_printf ("INTSTR"); + res += "INTSTR"; break; default: - debug_printf ("unknown-packet-%d", type); + res += string_printf ("unknown-packet-%d", type); } - debug_printf (" %d %d %d \"", fd, int1, int2); + res += string_printf (" %d %d %d \"", fd, int1, int2); for (; c < cl; c++) - debug_printf (*c >= ' ' && *c <= '~' ? "%c" : "\\%o", *c); + res += string_printf (*c >= ' ' && *c <= '~' ? "%c" : "\\%o", *c); - debug_printf ("\""); + res += "\""; + + return res; } /* Forward declaration. */ @@ -390,12 +403,10 @@ mnsh_send_message (int sock, enum mnsh_msg_type type, if (size < 0) mnsh_maybe_mourn_peer (); - if (debug_linux_namespaces) - { - debug_printf ("mnsh: send: "); - mnsh_debug_print_message (type, fd, int1, int2, buf, bufsiz); - debug_printf (" -> %s\n", pulongest (size)); - } + linux_namespaces_debug_printf + ("send: %s -> %s", + mnsh_debug_print_message (type, fd, int1, int2, buf, bufsiz).c_str (), + pulongest (size)); return size; } @@ -445,9 +456,8 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type, size = recvmsg (sock, &msg, MSG_CMSG_CLOEXEC); if (size < 0) { - if (debug_linux_namespaces) - debug_printf ("namespace-helper: recv failed (%s)\n", - pulongest (size)); + linux_namespaces_debug_printf + ("namespace-helper: recv failed (%s)", pulongest (size)); mnsh_maybe_mourn_peer (); @@ -457,9 +467,9 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type, /* Check for truncation. */ if (size < fixed_size || (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { - if (debug_linux_namespaces) - debug_printf ("namespace-helper: recv truncated (%s 0x%x)\n", - pulongest (size), msg.msg_flags); + linux_namespaces_debug_printf + ("namespace-helper: recv truncated (%s 0x%x)", + pulongest (size), msg.msg_flags); mnsh_maybe_mourn_peer (); @@ -477,13 +487,10 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type, else *fd = -1; - if (debug_linux_namespaces) - { - debug_printf ("mnsh: recv: "); - mnsh_debug_print_message (*type, *fd, *int1, *int2, buf, - size - fixed_size); - debug_printf ("\n"); - } + linux_namespaces_debug_printf + ("recv: %s", + mnsh_debug_print_message (*type, *fd, *int1, *int2, buf, + size - fixed_size).c_str ()); /* Return the number of bytes of data in BUF. */ return size - fixed_size; @@ -514,6 +521,20 @@ mnsh_handle_setns (int sock, int fd, int nstype) return mnsh_return_int (sock, result, errno); } + +/* Handle a MNSH_REQ_LSTAT message. Must be async-signal-safe. */ + +static ssize_t +mnsh_handle_lstat (int sock, const char *filename) +{ + struct stat sb; + int stat_ok = lstat (filename, &sb); + + return mnsh_return_intstr (sock, stat_ok, &sb, + stat_ok == -1 ? 0 : sizeof (sb), + errno); +} + /* Handle a MNSH_REQ_OPEN message. Must be async-signal-safe. */ static ssize_t @@ -574,6 +595,11 @@ mnsh_main (int sock) response = mnsh_handle_setns (sock, fd, int1); break; + case MNSH_REQ_LSTAT: + if (size > 0 && buf[size - 1] == '\0') + response = mnsh_handle_lstat (sock, buf); + break; + case MNSH_REQ_OPEN: if (size > 0 && buf[size - 1] == '\0') response = mnsh_handle_open (sock, buf, int1, int2); @@ -673,7 +699,7 @@ linux_mntns_get_helper (void) mnsh_creator_pid = helper_creator; /* Debug printing isn't async-signal-safe. */ - debug_linux_namespaces = 0; + debug_linux_namespaces = false; mnsh_main (sv[1]); } @@ -685,9 +711,8 @@ linux_mntns_get_helper (void) helper->sock = sv[0]; helper->nsid = ns->id; - if (debug_linux_namespaces) - debug_printf ("Started mount namespace helper process %d\n", - helper->pid); + linux_namespaces_debug_printf + ("Started mount namespace helper process %d", helper->pid); } return helper; @@ -765,6 +790,10 @@ mnsh_maybe_mourn_peer (void) mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \ filename, strlen (filename) + 1) +#define mnsh_send_lstat(helper, filename) \ + mnsh_send_message (helper->sock, MNSH_REQ_LSTAT, -1, 0, 0, \ + filename, strlen (filename) + 1) + #define mnsh_send_unlink(helper, filename) \ mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \ filename, strlen (filename) + 1) @@ -884,7 +913,7 @@ linux_mntns_access_fs (pid_t pid) struct stat sb; struct linux_mnsh *helper; ssize_t size; - int fd; + int fd, fd_user = -1; if (pid == getpid ()) return MNSH_FS_DIRECT; @@ -901,6 +930,8 @@ linux_mntns_access_fs (pid_t pid) { int save_errno = errno; close (fd); + if (fd_user >= 0) + close (fd_user); errno = save_errno; }; @@ -910,6 +941,13 @@ linux_mntns_access_fs (pid_t pid) if (sb.st_ino == ns->id) return MNSH_FS_DIRECT; + struct linux_ns *ns_user = linux_ns_get_namespace (LINUX_NS_USER); + if (ns_user != nullptr) + { + const char *ns_filename = linux_ns_filename (ns_user, pid); + fd_user = gdb_open_cloexec (ns_filename, O_RDONLY, 0).release (); + } + helper = linux_mntns_get_helper (); if (helper == NULL) return MNSH_FS_ERROR; @@ -918,6 +956,19 @@ linux_mntns_access_fs (pid_t pid) { int result, error; + /* Try to enter the user namespace first. The current user might + have elevated privileges within the user namespace, which would + then allow the attempt to enter the mount namespace to succeed. */ + if (fd_user >= 0) + { + size = mnsh_send_setns (helper, fd_user, 0); + if (size < 0) + return MNSH_FS_ERROR; + + if (mnsh_recv_int (helper, &result, &error) != 0) + return MNSH_FS_ERROR; + } + size = mnsh_send_setns (helper, fd, 0); if (size < 0) return MNSH_FS_ERROR; @@ -948,6 +999,42 @@ linux_mntns_access_fs (pid_t pid) /* See nat/linux-namespaces.h. */ int +linux_mntns_lstat (pid_t pid, const char *filename, + struct stat *sb) +{ + enum mnsh_fs_code access = linux_mntns_access_fs (pid); + + if (access == MNSH_FS_ERROR) + return -1; + + if (access == MNSH_FS_DIRECT) + return lstat (filename, sb); + + gdb_assert (access == MNSH_FS_HELPER); + + struct linux_mnsh *helper = linux_mntns_get_helper (); + + ssize_t size = mnsh_send_lstat (helper, filename); + if (size < 0) + return -1; + + int stat_ok, error; + size = mnsh_recv_intstr (helper, &stat_ok, &error, sb, sizeof (*sb)); + + if (size < 0) + { + stat_ok = -1; + errno = error; + } + else + gdb_assert (stat_ok == -1 || size == sizeof (*sb)); + + return stat_ok; +} + +/* See nat/linux-namespaces.h. */ + +int linux_mntns_open_cloexec (pid_t pid, const char *filename, int flags, mode_t mode) { diff --git a/gdb/nat/linux-namespaces.h b/gdb/nat/linux-namespaces.h index 4327292..a9a99f1 100644 --- a/gdb/nat/linux-namespaces.h +++ b/gdb/nat/linux-namespaces.h @@ -1,6 +1,6 @@ /* Linux namespaces(7) support. - Copyright (C) 2015-2024 Free Software Foundation, Inc. + Copyright (C) 2015-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -24,6 +24,12 @@ extern bool debug_linux_namespaces; +/* Print a "linux-namespaces" debug statement. */ + +#define linux_namespaces_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (debug_linux_namespaces, "linux-namespaces", \ + fmt, ##__VA_ARGS__) + /* Enumeration of Linux namespace types. */ enum linux_ns_type @@ -58,6 +64,11 @@ enum linux_ns_type extern int linux_ns_same (pid_t pid, enum linux_ns_type type); +/* Like lstat(2), but in the mount namespace of process PID. */ + +extern int linux_mntns_lstat (pid_t pid, const char *filename, + struct stat *sb); + /* Like gdb_open_cloexec, but in the mount namespace of process PID. */ diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h index f85d072..59bbd1b 100644 --- a/gdb/nat/linux-nat.h +++ b/gdb/nat/linux-nat.h @@ -1,6 +1,6 @@ /* Code for native debugging support for GNU/Linux (LWP layer). - Copyright (C) 2000-2024 Free Software Foundation, Inc. + Copyright (C) 2000-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 3a62150..b52a8ed 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -1,6 +1,6 @@ /* Linux-specific functions to retrieve OS data. - Copyright (C) 2009-2024 Free Software Foundation, Inc. + Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h index b688116..6b263c5 100644 --- a/gdb/nat/linux-osdata.h +++ b/gdb/nat/linux-osdata.h @@ -1,6 +1,6 @@ /* Linux-specific functions to retrieve OS data. - Copyright (C) 2009-2024 Free Software Foundation, Inc. + Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c index a406c73..1f91477 100644 --- a/gdb/nat/linux-personality.c +++ b/gdb/nat/linux-personality.c @@ -1,6 +1,6 @@ /* Disable address space randomization based on inferior personality. - Copyright (C) 2008-2024 Free Software Foundation, Inc. + Copyright (C) 2008-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-personality.h b/gdb/nat/linux-personality.h index ab67270..630d493 100644 --- a/gdb/nat/linux-personality.h +++ b/gdb/nat/linux-personality.h @@ -1,6 +1,6 @@ /* Disable address space randomization based on inferior personality. - Copyright (C) 2008-2024 Free Software Foundation, Inc. + Copyright (C) 2008-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index d762713..d4f9af3 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -1,5 +1,5 @@ /* Linux-specific PROCFS manipulation routines. - Copyright (C) 2009-2024 Free Software Foundation, Inc. + Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -424,7 +424,7 @@ linux_proc_task_list_dir_exists (pid_t pid) /* See linux-procfs.h. */ const char * -linux_proc_pid_to_exec_file (int pid) +linux_proc_pid_to_exec_file (int pid, bool is_local_fs) { static char buf[PATH_MAX]; char name[PATH_MAX]; @@ -437,9 +437,31 @@ linux_proc_pid_to_exec_file (int pid) else buf[len] = '\0'; - /* Use /proc/PID/exe if the actual file can't be read, but /proc/PID/exe - can be. */ - if (access (buf, R_OK) != 0 && access (name, R_OK) == 0) + /* If the inferior and GDB can see the same filesystem, and NAME + cannot be read, maybe the file has been deleted, then we can + potentially use /proc/PID/exe instead. + + GDB always interprets the results of this function within the + current sysroot (which is 'target:' by default). This means + that, if we return /proc/PID/exe, GDB will try to find this file + within the sysroot. + + This doesn't make sense if GDB is using a sysroot like: + '/some/random/directory/', not only is it possible that NAME + could be found within the sysroot, it is unlikely that + /proc/PID/exe will exist within the sysroot. + + Similarly, if the sysroot is 'target:', but the inferior is + running within a separate MNT namespace, then it is more than + likely that the inferior will also be running in a separate PID + namespace, in this case PID is the pid on the host system, + /proc/PID/exe will not be correct within the inferiors MNT/PID + namespace. + + So, we can fallback to use /proc/PID/exe only if IS_LOCAL_FS is + true, this indicates that GDB and the inferior are using the same + MNT namespace, and GDB's sysroot is either empty, or 'target:'. */ + if (is_local_fs && access (buf, R_OK) != 0 && access (name, R_OK) == 0) strcpy (buf, name); return buf; diff --git a/gdb/nat/linux-procfs.h b/gdb/nat/linux-procfs.h index d484cc8..4b02d31 100644 --- a/gdb/nat/linux-procfs.h +++ b/gdb/nat/linux-procfs.h @@ -1,5 +1,5 @@ /* Linux-specific PROCFS manipulation routines. - Copyright (C) 2011-2024 Free Software Foundation, Inc. + Copyright (C) 2011-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -87,9 +87,19 @@ extern int linux_proc_task_list_dir_exists (pid_t pid); /* Return the full absolute name of the executable file that was run to create the process PID. The returned value persists until this - function is next called. */ + function is next called. -extern const char *linux_proc_pid_to_exec_file (int pid); + LOCAL_FS should be true if the file returned from the function will + be searched for in the same filesystem as GDB itself is running. + In practice, this means LOCAL_FS should be true if PID and GDB are + running in the same MNT namespace and GDB's sysroot is either the + empty string, or is 'target:'. + + When used from gdbserver, where there is no sysroot, the only check + that matters is that PID and gdbserver are running in the same MNT + namespace. */ + +extern const char *linux_proc_pid_to_exec_file (int pid, bool local_fs); /* Display possible problems on this system. Display them only once per GDB execution. */ diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c index f90183b..f73058b 100644 --- a/gdb/nat/linux-ptrace.c +++ b/gdb/nat/linux-ptrace.c @@ -1,5 +1,5 @@ /* Linux-specific ptrace manipulation routines. - Copyright (C) 2012-2024 Free Software Foundation, Inc. + Copyright (C) 2012-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -23,6 +23,7 @@ #include <sys/procfs.h> #endif #include "gdbsupport/eintr.h" +#include "gdbsupport/signals-state-save-restore.h" /* Stores the ptrace options supported by the running kernel. A value of -1 means we did not check for features yet. A value @@ -148,6 +149,9 @@ linux_ptrace_test_ret_to_nx (void) return; case 0: + /* Set signal handlers to their default because it doesn't make sense + to call GDB-specific handlers any more in the child process. */ + restore_original_signals_state (); l = ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) NULL, (PTRACE_TYPE_ARG4) NULL); if (l != 0) diff --git a/gdb/nat/linux-ptrace.h b/gdb/nat/linux-ptrace.h index c7d4023..725ff9f 100644 --- a/gdb/nat/linux-ptrace.h +++ b/gdb/nat/linux-ptrace.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2024 Free Software Foundation, Inc. +/* Copyright (C) 2011-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-waitpid.c b/gdb/nat/linux-waitpid.c index f4ae612..8ee7d97 100644 --- a/gdb/nat/linux-waitpid.c +++ b/gdb/nat/linux-waitpid.c @@ -1,6 +1,6 @@ /* Wrapper implementation for waitpid for GNU/Linux (LWP layer). - Copyright (C) 2001-2024 Free Software Foundation, Inc. + Copyright (C) 2001-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/linux-waitpid.h b/gdb/nat/linux-waitpid.h index b75782d..238dc2a 100644 --- a/gdb/nat/linux-waitpid.h +++ b/gdb/nat/linux-waitpid.h @@ -1,6 +1,6 @@ /* Wrapper for waitpid for GNU/Linux (LWP layer). - Copyright (C) 2000-2024 Free Software Foundation, Inc. + Copyright (C) 2000-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/loongarch-hw-point.c b/gdb/nat/loongarch-hw-point.c index af954c6..93c4462 100644 --- a/gdb/nat/loongarch-hw-point.c +++ b/gdb/nat/loongarch-hw-point.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/loongarch-hw-point.h b/gdb/nat/loongarch-hw-point.h index 3d3d2c1..90926ef 100644 --- a/gdb/nat/loongarch-hw-point.h +++ b/gdb/nat/loongarch-hw-point.h @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/loongarch-linux-hw-point.c b/gdb/nat/loongarch-linux-hw-point.c index 26a88ee..f41fa1b 100644 --- a/gdb/nat/loongarch-linux-hw-point.c +++ b/gdb/nat/loongarch-linux-hw-point.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/loongarch-linux-hw-point.h b/gdb/nat/loongarch-linux-hw-point.h index d8b8feb..9c244a4 100644 --- a/gdb/nat/loongarch-linux-hw-point.h +++ b/gdb/nat/loongarch-linux-hw-point.h @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/loongarch-linux.c b/gdb/nat/loongarch-linux.c index 9486785..89c83bc 100644 --- a/gdb/nat/loongarch-linux.c +++ b/gdb/nat/loongarch-linux.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/loongarch-linux.h b/gdb/nat/loongarch-linux.h index 0505bf3..2d17ae0 100644 --- a/gdb/nat/loongarch-linux.h +++ b/gdb/nat/loongarch-linux.h @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux on LoongArch processors. - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by Loongson Ltd. This file is part of GDB. diff --git a/gdb/nat/mips-linux-watch.c b/gdb/nat/mips-linux-watch.c index 7d105e8..b9be3a0 100644 --- a/gdb/nat/mips-linux-watch.c +++ b/gdb/nat/mips-linux-watch.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/mips-linux-watch.h b/gdb/nat/mips-linux-watch.h index b18b009..3cada37 100644 --- a/gdb/nat/mips-linux-watch.h +++ b/gdb/nat/mips-linux-watch.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2024 Free Software Foundation, Inc. +/* Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c index 713ed6a..a6d9b14 100644 --- a/gdb/nat/netbsd-nat.c +++ b/gdb/nat/netbsd-nat.c @@ -1,6 +1,6 @@ /* Internal interfaces for the NetBSD code. - Copyright (C) 2006-2024 Free Software Foundation, Inc. + Copyright (C) 2006-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/netbsd-nat.h b/gdb/nat/netbsd-nat.h index 1ffd705..99208cb 100644 --- a/gdb/nat/netbsd-nat.h +++ b/gdb/nat/netbsd-nat.h @@ -1,6 +1,6 @@ /* Internal interfaces for the NetBSD code. - Copyright (C) 2006-2024 Free Software Foundation, Inc. + Copyright (C) 2006-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/ppc-linux.c b/gdb/nat/ppc-linux.c index d64ed33..e48455e 100644 --- a/gdb/nat/ppc-linux.c +++ b/gdb/nat/ppc-linux.c @@ -1,4 +1,4 @@ -/*Copyright (C) 2015-2024 Free Software Foundation, Inc. +/*Copyright (C) 2015-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/ppc-linux.h b/gdb/nat/ppc-linux.h index 3efc1b9..9779274 100644 --- a/gdb/nat/ppc-linux.h +++ b/gdb/nat/ppc-linux.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2024 Free Software Foundation, Inc. +/* Copyright (C) 1995-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/riscv-linux-tdesc.c b/gdb/nat/riscv-linux-tdesc.c index 0cd3843..254a25c 100644 --- a/gdb/nat/riscv-linux-tdesc.c +++ b/gdb/nat/riscv-linux-tdesc.c @@ -1,5 +1,5 @@ /* GNU/Linux/RISC-V native target description support for GDB. - Copyright (C) 2020-2024 Free Software Foundation, Inc. + Copyright (C) 2020-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/riscv-linux-tdesc.h b/gdb/nat/riscv-linux-tdesc.h index 875135e..de10d91 100644 --- a/gdb/nat/riscv-linux-tdesc.h +++ b/gdb/nat/riscv-linux-tdesc.h @@ -1,5 +1,5 @@ /* GNU/Linux/RISC-V native target description support for GDB. - Copyright (C) 2020-2024 Free Software Foundation, Inc. + Copyright (C) 2020-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 6f1ce81..7b0fbc5 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -1,5 +1,5 @@ /* Internal interfaces for the Windows code - Copyright (C) 1995-2024 Free Software Foundation, Inc. + Copyright (C) 1995-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index c01f58f..2f50742 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -1,5 +1,5 @@ /* Internal interfaces for the Windows code - Copyright (C) 1995-2024 Free Software Foundation, Inc. + Copyright (C) 1995-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-cpuid.h b/gdb/nat/x86-cpuid.h index 02a204c..6889f56 100644 --- a/gdb/nat/x86-cpuid.h +++ b/gdb/nat/x86-cpuid.h @@ -1,5 +1,5 @@ /* C API for x86 cpuid insn. - Copyright (C) 2007-2024 Free Software Foundation, Inc. + Copyright (C) 2007-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-dregs.c b/gdb/nat/x86-dregs.c index 7ea9f49..4119214 100644 --- a/gdb/nat/x86-dregs.c +++ b/gdb/nat/x86-dregs.c @@ -1,6 +1,6 @@ /* Debug register code for x86 (i386 and x86-64). - Copyright (C) 2001-2024 Free Software Foundation, Inc. + Copyright (C) 2001-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-dregs.h b/gdb/nat/x86-dregs.h index 3dcbf8e..c7f38f6 100644 --- a/gdb/nat/x86-dregs.h +++ b/gdb/nat/x86-dregs.h @@ -1,6 +1,6 @@ /* Debug register code for x86 (i386 and x86-64). - Copyright (C) 2009-2024 Free Software Foundation, Inc. + Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-gcc-cpuid.h b/gdb/nat/x86-gcc-cpuid.h index b0f2d23..1498100 100644 --- a/gdb/nat/x86-gcc-cpuid.h +++ b/gdb/nat/x86-gcc-cpuid.h @@ -7,7 +7,7 @@ #define GDB_NAT_X86_GCC_CPUID_H /* - * Copyright (C) 2007-2024 Free Software Foundation, Inc. + * Copyright (C) 2007-2025 Free Software Foundation, Inc. * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/gdb/nat/x86-linux-dregs.c b/gdb/nat/x86-linux-dregs.c index a6c0ea6..2953932 100644 --- a/gdb/nat/x86-linux-dregs.c +++ b/gdb/nat/x86-linux-dregs.c @@ -1,6 +1,6 @@ /* Low-level debug register code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 1999-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-linux-dregs.h b/gdb/nat/x86-linux-dregs.h index 6f6a6e3..4c3bcfb 100644 --- a/gdb/nat/x86-linux-dregs.h +++ b/gdb/nat/x86-linux-dregs.h @@ -1,6 +1,6 @@ /* Low-level debug register code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 1999-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-linux-tdesc.c b/gdb/nat/x86-linux-tdesc.c index 1824f57..80e4337 100644 --- a/gdb/nat/x86-linux-tdesc.c +++ b/gdb/nat/x86-linux-tdesc.c @@ -1,6 +1,6 @@ /* Target description related code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-linux-tdesc.h b/gdb/nat/x86-linux-tdesc.h index 2a2d869..38c71f1 100644 --- a/gdb/nat/x86-linux-tdesc.h +++ b/gdb/nat/x86-linux-tdesc.h @@ -1,6 +1,6 @@ /* Target description related code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2024-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c index ad3ed3c..0bdff73 100644 --- a/gdb/nat/x86-linux.c +++ b/gdb/nat/x86-linux.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 1999-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h index 7c0ac77..dbdef08 100644 --- a/gdb/nat/x86-linux.h +++ b/gdb/nat/x86-linux.h @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux x86 (i386 and x86-64). - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 1999-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-xstate.c b/gdb/nat/x86-xstate.c index ca6fbbf..6f2dfde 100644 --- a/gdb/nat/x86-xstate.c +++ b/gdb/nat/x86-xstate.c @@ -1,6 +1,6 @@ /* x86 XSAVE extended state functions. - Copyright (C) 2022-2024 Free Software Foundation, Inc. + Copyright (C) 2022-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/nat/x86-xstate.h b/gdb/nat/x86-xstate.h index 14b58cd..0046ab8 100644 --- a/gdb/nat/x86-xstate.h +++ b/gdb/nat/x86-xstate.h @@ -1,6 +1,6 @@ /* x86 XSAVE extended state functions. - Copyright (C) 2022-2024 Free Software Foundation, Inc. + Copyright (C) 2022-2025 Free Software Foundation, Inc. This file is part of GDB. |