aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r--gdb/linux-nat.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 2f98060..af081fc 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -42,7 +42,6 @@
#include "elf-bfd.h"
#include "gregset.h"
#include "gdbcore.h"
-#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "inf-loop.h"
@@ -51,17 +50,13 @@
#include <pwd.h>
#include <sys/types.h>
#include <dirent.h>
-#include "xml-support.h"
#include <sys/vfs.h>
-#include "solib.h"
#include "nat/linux-osdata.h"
#include "linux-tdep.h"
-#include "symfile.h"
#include "gdbsupport/agent.h"
#include "tracepoint.h"
#include "target-descriptions.h"
#include "gdbsupport/filestuff.h"
-#include "objfiles.h"
#include "nat/linux-namespaces.h"
#include "gdbsupport/block-signals.h"
#include "gdbsupport/fileio.h"
@@ -486,8 +481,8 @@ num_lwps (int pid)
{
int count = 0;
- for (const lwp_info *lp ATTRIBUTE_UNUSED : all_lwps ())
- if (lp->ptid.pid () == pid)
+ for (const lwp_info &lp : all_lwps ())
+ if (lp.ptid.pid () == pid)
count++;
return count;
@@ -553,8 +548,8 @@ linux_nat_target::follow_fork (inferior *child_inf, ptid_t child_ptid,
/* Note that we consult the parent's architecture instead of
the child's because there's no inferior for the child at
this point. */
- if (!gdbarch_software_single_step_p (target_thread_architecture
- (parent_ptid)))
+ if (!gdbarch_get_next_pcs_p (target_thread_architecture
+ (parent_ptid)))
{
int status;
@@ -712,7 +707,9 @@ static intrusive_list<lwp_info> lwp_list;
lwp_info_range
all_lwps ()
{
- return lwp_info_range (lwp_list.begin ());
+ lwp_info_iterator begin (lwp_list.begin ());
+
+ return lwp_info_range (std::move (begin));
}
/* See linux-nat.h. */
@@ -720,7 +717,7 @@ all_lwps ()
lwp_info_safe_range
all_lwps_safe ()
{
- return lwp_info_safe_range (lwp_list.begin ());
+ return lwp_info_safe_range (all_lwps ());
}
/* Add LP to sorted-by-reverse-creation-order doubly-linked list. */
@@ -935,12 +932,12 @@ struct lwp_info *
iterate_over_lwps (ptid_t filter,
gdb::function_view<iterate_over_lwps_ftype> callback)
{
- for (lwp_info *lp : all_lwps_safe ())
+ for (lwp_info &lp : all_lwps_safe ())
{
- if (lp->ptid.matches (filter))
+ if (lp.ptid.matches (filter))
{
- if (callback (lp) != 0)
- return lp;
+ if (callback (&lp) != 0)
+ return &lp;
}
}
@@ -2129,7 +2126,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
open_proc_mem_file (lp->ptid);
ourstatus->set_execd
- (make_unique_xstrdup (linux_proc_pid_to_exec_file (pid)));
+ (make_unique_xstrdup (linux_target->pid_to_exec_file (pid)));
/* The thread that execed must have been resumed, but, when a
thread execs, it changes its tid to the tgid, and the old
@@ -2146,9 +2143,9 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
PTRACE_GETEVENTMSG, we'd still need to lookup the
corresponding LWP object, and it would be an extra ptrace
syscall, so this way may even be more efficient. */
- for (lwp_info *other_lp : all_lwps_safe ())
- if (other_lp != lp && other_lp->ptid.pid () == lp->ptid.pid ())
- exit_lwp (other_lp);
+ for (lwp_info &other_lp : all_lwps_safe ())
+ if (&other_lp != lp && other_lp.ptid.pid () == lp->ptid.pid ())
+ exit_lwp (&other_lp);
return 0;
}
@@ -3861,11 +3858,11 @@ linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
static lwp_info *
find_stopped_lwp (int pid)
{
- for (lwp_info *lp : all_lwps ())
- if (lp->ptid.pid () == pid
- && lp->stopped
- && !is_lwp_marked_dead (lp))
- return lp;
+ for (lwp_info &lp : all_lwps ())
+ if (lp.ptid.pid () == pid
+ && lp.stopped
+ && !is_lwp_marked_dead (&lp))
+ return &lp;
return nullptr;
}
@@ -3967,13 +3964,13 @@ linux_nat_target::update_thread_list ()
/* Update the processor core that each lwp/thread was last seen
running on. */
- for (lwp_info *lwp : all_lwps ())
+ for (lwp_info &lwp : all_lwps ())
{
/* Avoid accessing /proc if the thread hasn't run since we last
time we fetched the thread's core. Accessing /proc becomes
noticeably expensive when we have thousands of LWPs. */
- if (lwp->core == -1)
- lwp->core = linux_common_core_of_thread (lwp->ptid);
+ if (lwp.core == -1)
+ lwp.core = linux_common_core_of_thread (lwp.ptid);
}
}
@@ -4000,7 +3997,14 @@ linux_nat_target::thread_name (struct thread_info *thr)
const char *
linux_nat_target::pid_to_exec_file (int pid)
{
- return linux_proc_pid_to_exec_file (pid);
+ /* If there's no sysroot. Or the sysroot is just 'target:' and the
+ inferior is in the same mount namespce, then we can consider the
+ filesystem local. */
+ bool local_fs = (gdb_sysroot.empty ()
+ || (gdb_sysroot == TARGET_SYSROOT_PREFIX
+ && linux_ns_same (pid, LINUX_NS_MNT)));
+
+ return linux_proc_pid_to_exec_file (pid, local_fs);
}
/* Object representing an /proc/PID/mem open file. We keep one such
@@ -4585,6 +4589,20 @@ linux_nat_target::fileio_open (struct inferior *inf, const char *filename,
return fd;
}
+/* Implementation of to_fileio_lstat. */
+
+int
+linux_nat_target::fileio_lstat (struct inferior *inf, const char *filename,
+ struct stat *sb, fileio_error *target_errno)
+{
+ int r = linux_mntns_lstat (linux_nat_fileio_pid_of (inf), filename, sb);
+
+ if (r == -1)
+ *target_errno = host_to_fileio_error (errno);
+
+ return r;
+}
+
/* Implementation of to_fileio_readlink. */
std::optional<std::string>
@@ -4680,8 +4698,8 @@ maintenance_info_lwps (const char *arg, int from_tty)
figure out the widest ptid string. We'll use this to build our
output table below. */
size_t ptid_width = 8;
- for (lwp_info *lp : all_lwps ())
- ptid_width = std::max (ptid_width, lp->ptid.to_string ().size ());
+ for (lwp_info &lp : all_lwps ())
+ ptid_width = std::max (ptid_width, lp.ptid.to_string ().size ());
/* Setup the table headers. */
struct ui_out *uiout = current_uiout;
@@ -4691,13 +4709,13 @@ maintenance_info_lwps (const char *arg, int from_tty)
uiout->table_body ();
/* Display one table row for each lwp_info. */
- for (lwp_info *lp : all_lwps ())
+ for (lwp_info &lp : all_lwps ())
{
ui_out_emit_tuple tuple_emitter (uiout, "lwp-entry");
- thread_info *th = linux_target->find_thread (lp->ptid);
+ thread_info *th = linux_target->find_thread (lp.ptid);
- uiout->field_string ("lwp-ptid", lp->ptid.to_string ().c_str ());
+ uiout->field_string ("lwp-ptid", lp.ptid.to_string ().c_str ());
if (th == nullptr)
uiout->field_string ("thread-info", "None");
else
@@ -4707,9 +4725,7 @@ maintenance_info_lwps (const char *arg, int from_tty)
}
}
-void _initialize_linux_nat ();
-void
-_initialize_linux_nat ()
+INIT_GDB_FILE (linux_nat)
{
add_setshow_boolean_cmd ("linux-nat", class_maintenance,
&debug_linux_nat, _("\