* [PATCH 0/2] Implement pid_to_exec_file for Windows in gdbserver
@ 2022-04-27 17:27 Tom Tromey
2022-04-27 17:27 ` [PATCH 1/2] Constify target_pid_to_exec_file Tom Tromey
2022-04-27 17:28 ` [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
0 siblings, 2 replies; 8+ messages in thread
From: Tom Tromey @ 2022-04-27 17:27 UTC (permalink / raw)
To: gdb-patches
This changes gdbserver to implement the pid_to_exec_file method for
Windows. It was more convenient to do this after constifying
target_pid_to_exec_file in gdb itself.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] Constify target_pid_to_exec_file
2022-04-27 17:27 [PATCH 0/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
@ 2022-04-27 17:27 ` Tom Tromey
2022-04-27 17:49 ` John Baldwin
2022-04-27 17:28 ` [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2022-04-27 17:27 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes target_pid_to_exec_file and target_ops::pid_to_exec_file
to return a "const char *". I couldn't build many of these targets,
but did examine the code by hand -- also, as this only affects the
return type, it's normally pretty safe. This brings gdb and gdbserver
a bit closer, and allows for the removal of a const_cast as well.
---
gdb/darwin-nat.c | 2 +-
gdb/darwin-nat.h | 2 +-
gdb/exec.c | 2 +-
gdb/fbsd-nat.c | 2 +-
gdb/fbsd-nat.h | 2 +-
gdb/inf-child.c | 2 +-
gdb/inf-child.h | 2 +-
gdb/linux-nat.c | 2 +-
gdb/linux-nat.h | 2 +-
gdb/nat/linux-procfs.c | 2 +-
gdb/nat/linux-procfs.h | 2 +-
gdb/netbsd-nat.c | 4 ++--
gdb/netbsd-nat.h | 2 +-
gdb/nto-procfs.c | 4 ++--
gdb/procfs.c | 4 ++--
gdb/remote.c | 4 ++--
gdb/target-delegates.c | 14 +++++++-------
gdb/target.c | 2 +-
gdb/target.h | 4 ++--
gdb/windows-nat.c | 4 ++--
20 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 17723656930..eca97c9bde9 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -2373,7 +2373,7 @@ set_enable_mach_exceptions (const char *args, int from_tty,
}
}
-char *
+const char *
darwin_nat_target::pid_to_exec_file (int pid)
{
static char path[PATH_MAX];
diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h
index 733ac7cc058..e3dcd963706 100644
--- a/gdb/darwin-nat.h
+++ b/gdb/darwin-nat.h
@@ -100,7 +100,7 @@ class darwin_nat_target : public inf_child_target
std::string pid_to_str (ptid_t) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
enum target_xfer_status xfer_partial (enum target_object object,
const char *annex,
diff --git a/gdb/exec.c b/gdb/exec.c
index 38540c0840b..40c89d53ba9 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -314,7 +314,7 @@ validate_exec_file (int from_tty)
void
exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
{
- char *exec_file_target;
+ const char *exec_file_target;
symfile_add_flags add_flags = 0;
/* Do nothing if we already have an executable filename. */
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 8e5107c26f8..22349d49aee 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -52,7 +52,7 @@
/* Return the name of a file that can be opened to get the symbols for
the child process identified by PID. */
-char *
+const char *
fbsd_nat_target::pid_to_exec_file (int pid)
{
static char buf[PATH_MAX];
diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h
index 82f7ee47949..ff62a5826a9 100644
--- a/gdb/fbsd-nat.h
+++ b/gdb/fbsd-nat.h
@@ -44,7 +44,7 @@
class fbsd_nat_target : public inf_ptrace_target
{
public:
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
int find_memory_regions (find_memory_region_ftype func, void *data) override;
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index cc00867787a..56ebd2a5549 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -220,7 +220,7 @@ inf_child_target::can_attach ()
return true;
}
-char *
+const char *
inf_child_target::pid_to_exec_file (int pid)
{
/* This target doesn't support translation of a process ID to the
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index a017032a32f..ae5ace46f30 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -71,7 +71,7 @@ class inf_child_target
void post_attach (int) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
int fileio_open (struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index dff8d07d3f7..ca8ddc7100e 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3773,7 +3773,7 @@ linux_nat_target::thread_name (struct thread_info *thr)
/* Accepts an integer PID; Returns a string representing a file that
can be opened to get the symbols for the child process. */
-char *
+const char *
linux_nat_target::pid_to_exec_file (int pid)
{
return linux_proc_pid_to_exec_file (pid);
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index 12a90eccb28..11043c4b9f6 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -123,7 +123,7 @@ class linux_nat_target : public inf_ptrace_target
int set_syscall_catchpoint (int pid, bool needed, int any_count,
gdb::array_view<const int> syscall_counts) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
void post_attach (int) override;
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index 2618c99d9f4..99e645786c2 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -341,7 +341,7 @@ linux_proc_task_list_dir_exists (pid_t pid)
/* See linux-procfs.h. */
-char *
+const char *
linux_proc_pid_to_exec_file (int pid)
{
static char buf[PATH_MAX];
diff --git a/gdb/nat/linux-procfs.h b/gdb/nat/linux-procfs.h
index fa1280a8967..fcc8280adf1 100644
--- a/gdb/nat/linux-procfs.h
+++ b/gdb/nat/linux-procfs.h
@@ -78,7 +78,7 @@ extern int linux_proc_task_list_dir_exists (pid_t pid);
to create the process PID. The returned value persists until this
function is next called. */
-extern char *linux_proc_pid_to_exec_file (int pid);
+extern const char *linux_proc_pid_to_exec_file (int pid);
/* Display possible problems on this system. Display them only once
per GDB execution. */
diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c
index f2eeb3ff61e..2ccd0e014c2 100644
--- a/gdb/netbsd-nat.c
+++ b/gdb/netbsd-nat.c
@@ -34,10 +34,10 @@
/* Return the name of a file that can be opened to get the symbols for
the child process identified by PID. */
-char *
+const char *
nbsd_nat_target::pid_to_exec_file (int pid)
{
- return const_cast<char *> (netbsd_nat::pid_to_exec_file (pid));
+ return netbsd_nat::pid_to_exec_file (pid);
}
/* Return the current directory for the process identified by PID. */
diff --git a/gdb/netbsd-nat.h b/gdb/netbsd-nat.h
index ef190c4e471..ff468452b2c 100644
--- a/gdb/netbsd-nat.h
+++ b/gdb/netbsd-nat.h
@@ -28,7 +28,7 @@ struct thread_info;
struct nbsd_nat_target : public inf_ptrace_target
{
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
bool thread_alive (ptid_t ptid) override;
const char *thread_name (struct thread_info *thr) override;
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index 61374c9fad4..ef9e0f05261 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -121,7 +121,7 @@ struct nto_procfs_target : public inf_child_target
const char *extra_thread_info (struct thread_info *) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
};
/* For "target native". */
@@ -664,7 +664,7 @@ nto_procfs_target::files_info ()
/* Target to_pid_to_exec_file implementation. */
-char *
+const char *
nto_procfs_target::pid_to_exec_file (const int pid)
{
int proc_fd;
diff --git a/gdb/procfs.c b/gdb/procfs.c
index f6ca1345a21..d290505d8c3 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -127,7 +127,7 @@ class procfs_target final : public inf_child_target
std::string pid_to_str (ptid_t) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
thread_control_capabilities get_thread_control_capabilities () override
{ return tc_schedlock; }
@@ -2927,7 +2927,7 @@ procfs_target::pid_to_str (ptid_t ptid)
/* Accepts an integer PID; Returns a string representing a file that
can be opened to get the symbols for the child process. */
-char *
+const char *
procfs_target::pid_to_exec_file (int pid)
{
static char buf[PATH_MAX];
diff --git a/gdb/remote.c b/gdb/remote.c
index 562cc586f2b..09994009e48 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -508,7 +508,7 @@ class remote_target : public process_stratum_target
void rcmd (const char *command, struct ui_file *output) override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
void log_command (const char *cmd) override
{
@@ -14338,7 +14338,7 @@ remote_target::load (const char *name, int from_tty)
can be opened on the remote side to get the symbols for the child
process. Returns NULL if the operation is not supported. */
-char *
+const char *
remote_target::pid_to_exec_file (int pid)
{
static gdb::optional<gdb::char_vector> filename;
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 4e653e8f429..8a9986454dd 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -94,7 +94,7 @@ struct dummy_target : public target_ops
void interrupt () override;
void pass_ctrlc () override;
void rcmd (const char *arg0, struct ui_file *arg1) override;
- char *pid_to_exec_file (int arg0) override;
+ const char *pid_to_exec_file (int arg0) override;
void log_command (const char *arg0) override;
const target_section_table *get_section_table () override;
thread_control_capabilities get_thread_control_capabilities () override;
@@ -268,7 +268,7 @@ struct debug_target : public target_ops
void interrupt () override;
void pass_ctrlc () override;
void rcmd (const char *arg0, struct ui_file *arg1) override;
- char *pid_to_exec_file (int arg0) override;
+ const char *pid_to_exec_file (int arg0) override;
void log_command (const char *arg0) override;
const target_section_table *get_section_table () override;
thread_control_capabilities get_thread_control_capabilities () override;
@@ -1983,28 +1983,28 @@ debug_target::rcmd (const char *arg0, struct ui_file *arg1)
gdb_puts (")\n", gdb_stdlog);
}
-char *
+const char *
target_ops::pid_to_exec_file (int arg0)
{
return this->beneath ()->pid_to_exec_file (arg0);
}
-char *
+const char *
dummy_target::pid_to_exec_file (int arg0)
{
return NULL;
}
-char *
+const char *
debug_target::pid_to_exec_file (int arg0)
{
- char * result;
+ const char * result;
gdb_printf (gdb_stdlog, "-> %s->pid_to_exec_file (...)\n", this->beneath ()->shortname ());
result = this->beneath ()->pid_to_exec_file (arg0);
gdb_printf (gdb_stdlog, "<- %s->pid_to_exec_file (", this->beneath ()->shortname ());
target_debug_print_int (arg0);
gdb_puts (") = ", gdb_stdlog);
- target_debug_print_char_p (result);
+ target_debug_print_const_char_p (result);
gdb_puts ("\n", gdb_stdlog);
return result;
}
diff --git a/gdb/target.c b/gdb/target.c
index 7d291fd4d0d..46cd17b4610 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -423,7 +423,7 @@ target_extra_thread_info (thread_info *tp)
/* See target.h. */
-char *
+const char *
target_pid_to_exec_file (int pid)
{
return current_inferior ()->top_target ()->pid_to_exec_file (pid);
diff --git a/gdb/target.h b/gdb/target.h
index 093178af0bc..8b4e497e5e5 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -688,7 +688,7 @@ struct target_ops
TARGET_DEFAULT_FUNC (default_target_pass_ctrlc);
virtual void rcmd (const char *command, struct ui_file *output)
TARGET_DEFAULT_FUNC (default_rcmd);
- virtual char *pid_to_exec_file (int pid)
+ virtual const char *pid_to_exec_file (int pid)
TARGET_DEFAULT_RETURN (NULL);
virtual void log_command (const char *)
TARGET_DEFAULT_IGNORE ();
@@ -1942,7 +1942,7 @@ extern gdb::byte_vector target_thread_info_to_thread_handle
the client if the string will not be immediately used, or if
it must persist. */
-extern char *target_pid_to_exec_file (int pid);
+extern const char *target_pid_to_exec_file (int pid);
/* See the to_thread_architecture description in struct target_ops. */
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 1068558cd21..cd43409a02f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -276,7 +276,7 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
void interrupt () override;
- char *pid_to_exec_file (int pid) override;
+ const char *pid_to_exec_file (int pid) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
@@ -2005,7 +2005,7 @@ windows_get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len)
/* The pid_to_exec_file target_ops method for this platform. */
-char *
+const char *
windows_nat_target::pid_to_exec_file (int pid)
{
static char path[__PMAX];
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver
2022-04-27 17:27 [PATCH 0/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
2022-04-27 17:27 ` [PATCH 1/2] Constify target_pid_to_exec_file Tom Tromey
@ 2022-04-27 17:28 ` Tom Tromey
2022-04-28 1:33 ` Simon Marchi
1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2022-04-27 17:28 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that gdbserver did not implement pid_to_exec_file for
Windows, while gdb did implement it. This patch moves the code to
nat/windows-nat.c, so that it can be shared. This makes the gdbserver
implementation trivial.
---
gdb/nat/windows-nat.c | 93 ++++++++++++++++++++++++++++++++++++++++++
gdb/nat/windows-nat.h | 14 +++++++
gdb/windows-nat.c | 88 +--------------------------------------
gdbserver/win32-low.cc | 6 +++
gdbserver/win32-low.h | 5 +++
5 files changed, 119 insertions(+), 87 deletions(-)
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index c8db19439f3..71a18a0efa9 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -144,6 +144,99 @@ windows_thread_info::thread_name ()
return name.get ();
}
+/* Try to determine the executable filename.
+
+ EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN.
+
+ Upon success, the filename is stored inside EXE_NAME_RET, and
+ this function returns nonzero.
+
+ Otherwise, this function returns zero and the contents of
+ EXE_NAME_RET is undefined. */
+
+int
+windows_process_info::get_exec_module_filename (char *exe_name_ret,
+ size_t exe_name_max_len)
+{
+ DWORD len;
+ HMODULE dh_buf;
+ DWORD cbNeeded;
+
+ cbNeeded = 0;
+#ifdef __x86_64__
+ if (wow64_process)
+ {
+ if (!EnumProcessModulesEx (handle,
+ &dh_buf, sizeof (HMODULE), &cbNeeded,
+ LIST_MODULES_32BIT)
+ || !cbNeeded)
+ return 0;
+ }
+ else
+#endif
+ {
+ if (!EnumProcessModules (handle,
+ &dh_buf, sizeof (HMODULE), &cbNeeded)
+ || !cbNeeded)
+ return 0;
+ }
+
+ /* We know the executable is always first in the list of modules,
+ which we just fetched. So no need to fetch more. */
+
+#ifdef __CYGWIN__
+ {
+ /* Cygwin prefers that the path be in /x/y/z format, so extract
+ the filename into a temporary buffer first, and then convert it
+ to POSIX format into the destination buffer. */
+ cygwin_buf_t *pathbuf = (cygwin_buf_t *) alloca (exe_name_max_len * sizeof (cygwin_buf_t));
+
+ len = GetModuleFileNameEx (current_process_handle,
+ dh_buf, pathbuf, exe_name_max_len);
+ if (len == 0)
+ error (_("Error getting executable filename: %u."),
+ (unsigned) GetLastError ());
+ if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret,
+ exe_name_max_len) < 0)
+ error (_("Error converting executable filename to POSIX: %d."), errno);
+ }
+#else
+ len = GetModuleFileNameEx (handle,
+ dh_buf, exe_name_ret, exe_name_max_len);
+ if (len == 0)
+ error (_("Error getting executable filename: %u."),
+ (unsigned) GetLastError ());
+#endif
+
+ return 1; /* success */
+}
+
+const char *
+windows_process_info::pid_to_exec_file (int pid)
+{
+ static char path[MAX_PATH];
+#ifdef __CYGWIN__
+ /* Try to find exe name as symlink target of /proc/<pid>/exe. */
+ int nchars;
+ char procexe[sizeof ("/proc/4294967295/exe")];
+
+ xsnprintf (procexe, sizeof (procexe), "/proc/%u/exe", pid);
+ nchars = readlink (procexe, path, sizeof(path));
+ if (nchars > 0 && nchars < sizeof (path))
+ {
+ path[nchars] = '\0'; /* Got it */
+ return path;
+ }
+#endif
+
+ /* If we get here then either Cygwin is hosed, this isn't a Cygwin version
+ of gdb, or we're trying to debug a non-Cygwin windows executable. */
+ if (!get_exec_module_filename (path, sizeof (path)))
+ path[0] = '\0';
+
+ return path;
+}
+
/* Return the name of the DLL referenced by H at ADDRESS. UNICODE
determines what sort of string is read from the inferior. Returns
the name of the DLL, or NULL on error. If a name is returned, it
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 29fd0a3a69b..4244426f5eb 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -249,6 +249,8 @@ struct windows_process_info
gdb::optional<pending_stop> fetch_pending_stop (bool debug_events);
+ const char *pid_to_exec_file (int);
+
private:
/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
@@ -267,6 +269,18 @@ struct windows_process_info
presumed loaded. */
void add_dll (LPVOID load_addr);
+
+ /* Try to determine the executable filename.
+
+ EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN.
+
+ Upon success, the filename is stored inside EXE_NAME_RET, and
+ this function returns nonzero.
+
+ Otherwise, this function returns zero and the contents of
+ EXE_NAME_RET is undefined. */
+
+ int get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len);
};
/* A simple wrapper for ContinueDebugEvent that continues the last
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index cd43409a02f..11f54302b11 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1937,98 +1937,12 @@ windows_nat_target::detach (inferior *inf, int from_tty)
maybe_unpush_target ();
}
-/* Try to determine the executable filename.
-
- EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN.
-
- Upon success, the filename is stored inside EXE_NAME_RET, and
- this function returns nonzero.
-
- Otherwise, this function returns zero and the contents of
- EXE_NAME_RET is undefined. */
-
-static int
-windows_get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len)
-{
- DWORD len;
- HMODULE dh_buf;
- DWORD cbNeeded;
-
- cbNeeded = 0;
-#ifdef __x86_64__
- if (windows_process.wow64_process)
- {
- if (!EnumProcessModulesEx (windows_process.handle,
- &dh_buf, sizeof (HMODULE), &cbNeeded,
- LIST_MODULES_32BIT)
- || !cbNeeded)
- return 0;
- }
- else
-#endif
- {
- if (!EnumProcessModules (windows_process.handle,
- &dh_buf, sizeof (HMODULE), &cbNeeded)
- || !cbNeeded)
- return 0;
- }
-
- /* We know the executable is always first in the list of modules,
- which we just fetched. So no need to fetch more. */
-
-#ifdef __CYGWIN__
- {
- /* Cygwin prefers that the path be in /x/y/z format, so extract
- the filename into a temporary buffer first, and then convert it
- to POSIX format into the destination buffer. */
- cygwin_buf_t *pathbuf = (cygwin_buf_t *) alloca (exe_name_max_len * sizeof (cygwin_buf_t));
-
- len = GetModuleFileNameEx (current_process_handle,
- dh_buf, pathbuf, exe_name_max_len);
- if (len == 0)
- error (_("Error getting executable filename: %u."),
- (unsigned) GetLastError ());
- if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret,
- exe_name_max_len) < 0)
- error (_("Error converting executable filename to POSIX: %d."), errno);
- }
-#else
- len = GetModuleFileNameEx (windows_process.handle,
- dh_buf, exe_name_ret, exe_name_max_len);
- if (len == 0)
- error (_("Error getting executable filename: %u."),
- (unsigned) GetLastError ());
-#endif
-
- return 1; /* success */
-}
-
/* The pid_to_exec_file target_ops method for this platform. */
const char *
windows_nat_target::pid_to_exec_file (int pid)
{
- static char path[__PMAX];
-#ifdef __CYGWIN__
- /* Try to find exe name as symlink target of /proc/<pid>/exe. */
- int nchars;
- char procexe[sizeof ("/proc/4294967295/exe")];
-
- xsnprintf (procexe, sizeof (procexe), "/proc/%u/exe", pid);
- nchars = readlink (procexe, path, sizeof(path));
- if (nchars > 0 && nchars < sizeof (path))
- {
- path[nchars] = '\0'; /* Got it */
- return path;
- }
-#endif
-
- /* If we get here then either Cygwin is hosed, this isn't a Cygwin version
- of gdb, or we're trying to debug a non-Cygwin windows executable. */
- if (!windows_get_exec_module_filename (path, sizeof (path)))
- path[0] = '\0';
-
- return path;
+ return windows_process.pid_to_exec_file (pid);
}
/* Print status information about what we're accessing. */
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 192ea465e69..ca9df030fd6 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -1516,6 +1516,12 @@ win32_process_target::thread_name (ptid_t thread)
return th->thread_name ();
}
+const char *
+win32_process_target::pid_to_exec_file (int pid)
+{
+ return windows_process.pid_to_exec_file (pid);
+}
+
/* The win32 target ops object. */
static win32_process_target the_win32_target;
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index c5f40dd8d0a..d16f1f9609c 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -160,6 +160,11 @@ class win32_process_target : public process_stratum_target
bool supports_stopped_by_sw_breakpoint () override;
const char *thread_name (ptid_t thread) override;
+
+ bool supports_pid_to_exec_file () override
+ { return true; }
+
+ const char *pid_to_exec_file (int pid) override;
};
/* The sole Windows process. */
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Constify target_pid_to_exec_file
2022-04-27 17:27 ` [PATCH 1/2] Constify target_pid_to_exec_file Tom Tromey
@ 2022-04-27 17:49 ` John Baldwin
0 siblings, 0 replies; 8+ messages in thread
From: John Baldwin @ 2022-04-27 17:49 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 4/27/22 10:27 AM, Tom Tromey via Gdb-patches wrote:
> This changes target_pid_to_exec_file and target_ops::pid_to_exec_file
> to return a "const char *". I couldn't build many of these targets,
> but did examine the code by hand -- also, as this only affects the
> return type, it's normally pretty safe. This brings gdb and gdbserver
> a bit closer, and allows for the removal of a const_cast as well.
> ---
> gdb/darwin-nat.c | 2 +-
> gdb/darwin-nat.h | 2 +-
> gdb/exec.c | 2 +-
> gdb/fbsd-nat.c | 2 +-
> gdb/fbsd-nat.h | 2 +-
> gdb/inf-child.c | 2 +-
> gdb/inf-child.h | 2 +-
> gdb/linux-nat.c | 2 +-
> gdb/linux-nat.h | 2 +-
> gdb/nat/linux-procfs.c | 2 +-
> gdb/nat/linux-procfs.h | 2 +-
> gdb/netbsd-nat.c | 4 ++--
> gdb/netbsd-nat.h | 2 +-
> gdb/nto-procfs.c | 4 ++--
> gdb/procfs.c | 4 ++--
> gdb/remote.c | 4 ++--
> gdb/target-delegates.c | 14 +++++++-------
> gdb/target.c | 2 +-
> gdb/target.h | 4 ++--
> gdb/windows-nat.c | 4 ++--
> 20 files changed, 32 insertions(+), 32 deletions(-)
The trivial *BSD target changes all look fine to me. I don't mind fixing
FreeBSD post-merge anyway if need be.
--
John Baldwin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver
2022-04-27 17:28 ` [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
@ 2022-04-28 1:33 ` Simon Marchi
2022-04-28 13:09 ` Tom Tromey
2022-04-28 19:50 ` Tom Tromey
0 siblings, 2 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-28 1:33 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
> diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
> index 29fd0a3a69b..4244426f5eb 100644
> --- a/gdb/nat/windows-nat.h
> +++ b/gdb/nat/windows-nat.h
> @@ -249,6 +249,8 @@ struct windows_process_info
>
> gdb::optional<pending_stop> fetch_pending_stop (bool debug_events);
>
> + const char *pid_to_exec_file (int);
It seems a bit strange to pass a pid to this method. Doesn't a
windows_process_info object know its own pid? And so passing the pid as
a parameter would be redundant?
Right now gdb/windows-nat.c supports a single process only, so it must
be that the pid that is requested as a parameter must match the (only)
process' pid. So maybe we can have a gdb_assert in
windows_nat_target::pid_to_exec_file to verify that (and the same
GDBserver-side)?
The day the windows-nat target becomes multi-process, then I guess we'll
use the passed-in pid to look up a specific windows_process_info by pid
in whatever data structure will contain all the windows_process_infos.
And then we can call windows_process_info::pid_to_exec_file without
passing any pid.
Note that this is all speculation, I haven't tried anything. I'm just
assuming that windows_process_info::id is the same as "pid".
Otherwise, LGTM.
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver
2022-04-28 1:33 ` Simon Marchi
@ 2022-04-28 13:09 ` Tom Tromey
2022-04-28 19:50 ` Tom Tromey
1 sibling, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2022-04-28 13:09 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>> + const char *pid_to_exec_file (int);
Simon> It seems a bit strange to pass a pid to this method. Doesn't a
Simon> windows_process_info object know its own pid? And so passing the pid as
Simon> a parameter would be redundant?
Yes, I thought so too, but that's how it works in both programs.
I considered changing this -- I think we could pass an 'inferior *' in
gdb -- but that's a more invasive change and I can't compile all the
places I'd have to touch.
Also, the PID is part of the remote protocol, so in the end it would be
a change without a difference, in a way. Probably this should have been
written so that the PID was implicitly taken from the selected inferior
in the remote.
Simon> Right now gdb/windows-nat.c supports a single process only, so it must
Simon> be that the pid that is requested as a parameter must match the (only)
Simon> process' pid. So maybe we can have a gdb_assert in
Simon> windows_nat_target::pid_to_exec_file to verify that (and the same
Simon> GDBserver-side)?
Sure.
Simon> The day the windows-nat target becomes multi-process, then I guess we'll
Simon> use the passed-in pid to look up a specific windows_process_info by pid
Simon> in whatever data structure will contain all the windows_process_infos.
Simon> And then we can call windows_process_info::pid_to_exec_file without
Simon> passing any pid.
Yes, that's right.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver
2022-04-28 1:33 ` Simon Marchi
2022-04-28 13:09 ` Tom Tromey
@ 2022-04-28 19:50 ` Tom Tromey
2022-04-28 19:56 ` Simon Marchi
1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2022-04-28 19:50 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> It seems a bit strange to pass a pid to this method. Doesn't a
Simon> windows_process_info object know its own pid?
It does, but only in gdbserver. And, even there, the 'id' field isn't
really needed and can be removed -- it just replicates information
already stored elsewhere.
Simon> So maybe we can have a gdb_assert in
Simon> windows_nat_target::pid_to_exec_file to verify that (and the same
Simon> GDBserver-side)?
... so I think instead of doing this, I'd rather just drop the 'id'
field.
Simon> The day the windows-nat target becomes multi-process, then I guess we'll
Simon> use the passed-in pid to look up a specific windows_process_info by pid
Simon> in whatever data structure will contain all the windows_process_infos.
Simon> And then we can call windows_process_info::pid_to_exec_file without
Simon> passing any pid.
I think we'll still need to pass it, given that the Cygwin code needs
it.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver
2022-04-28 19:50 ` Tom Tromey
@ 2022-04-28 19:56 ` Simon Marchi
0 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-28 19:56 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2022-04-28 15:50, Tom Tromey wrote:
> Simon> It seems a bit strange to pass a pid to this method. Doesn't a
> Simon> windows_process_info object know its own pid?
>
> It does, but only in gdbserver. And, even there, the 'id' field isn't
> really needed and can be removed -- it just replicates information
> already stored elsewhere.
>
> Simon> So maybe we can have a gdb_assert in
> Simon> windows_nat_target::pid_to_exec_file to verify that (and the same
> Simon> GDBserver-side)?
>
> ... so I think instead of doing this, I'd rather just drop the 'id'
> field.
>
> Simon> The day the windows-nat target becomes multi-process, then I guess we'll
> Simon> use the passed-in pid to look up a specific windows_process_info by pid
> Simon> in whatever data structure will contain all the windows_process_infos.
> Simon> And then we can call windows_process_info::pid_to_exec_file without
> Simon> passing any pid.
>
> I think we'll still need to pass it, given that the Cygwin code needs
> it.
>
> Tom
No problem, I was just raising the concern, but you know more about this
than me.
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-04-28 19:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 17:27 [PATCH 0/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
2022-04-27 17:27 ` [PATCH 1/2] Constify target_pid_to_exec_file Tom Tromey
2022-04-27 17:49 ` John Baldwin
2022-04-27 17:28 ` [PATCH 2/2] Implement pid_to_exec_file for Windows in gdbserver Tom Tromey
2022-04-28 1:33 ` Simon Marchi
2022-04-28 13:09 ` Tom Tromey
2022-04-28 19:50 ` Tom Tromey
2022-04-28 19:56 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).