This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 3/3] (patch 2/4, v2) [nto] Implement procfs_pid_to_exec_file.
- From: Aleksandar Ristovski <aristovski at qnx dot com>
- To: gdb-patches at sourceware dot org
- Cc: palves at redhat dot com, Aleksandar Ristovski <aristovski at qnx dot com>
- Date: Tue, 20 Oct 2015 10:28:14 -0400
- Subject: [PATCH 3/3] (patch 2/4, v2) [nto] Implement procfs_pid_to_exec_file.
- Authentication-results: sourceware.org; auth=none
- References: <56263FED dot 3050602 at redhat dot com> <1445351294-18179-1-git-send-email-aristovski at qnx dot com>
gdb/ChangeLog:
* gdb/nto-procfs.c (procfs_pid_to_exec_file): New function.
(init_procfs_targets): Wire new function.
---
gdb/nto-procfs.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index ac54c32..e7882ba 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -617,6 +617,33 @@ procfs_files_info (struct target_ops *ignore)
(nodestr != NULL) ? nodestr : "local node");
}
+/* Read executable file name for the given PID. */
+
+static char *
+procfs_pid_to_exec_file (struct target_ops *ops, const int pid)
+{
+ int proc_fd;
+ static char proc_path[PATH_MAX];
+ ssize_t rd;
+
+ /* Read exe file name. */
+ snprintf (proc_path, sizeof (proc_path), "%s/proc/%d/exefile",
+ (nodestr != NULL) ? nodestr : "", pid);
+ proc_fd = open (proc_path, O_RDONLY);
+ if (proc_fd == -1)
+ return NULL;
+
+ rd = read (proc_fd, proc_path, sizeof (proc_path) - 1);
+ close (proc_fd);
+ if (rd <= 0)
+ {
+ proc_path[0] = '\0';
+ return NULL;
+ }
+ proc_path[rd] = '\0';
+ return proc_path;
+}
+
/* Attach to process PID, then initialize for debugging it. */
static void
procfs_attach (struct target_ops *ops, const char *args, int from_tty)
@@ -1493,6 +1520,7 @@ init_procfs_targets (void)
t->to_interrupt = procfs_interrupt;
t->to_have_continuable_watchpoint = 1;
t->to_extra_thread_info = nto_extra_thread_info;
+ t->to_pid_to_exec_file = procfs_pid_to_exec_file;
nto_native_ops = t;
--
1.9.1