[V3,PR,gdb/17903] Implement to_pid_to_exec_file for solaris

Message ID CAEJ-0i_AcN+C8HaeF62K+vfGXcNFH1GK6Nef9F_CWxo3+Lf3kw@mail.gmail.com
State New, archived
Headers

Commit Message

Brian Vandenberg Aug. 7, 2018, 7:45 p.m. UTC
  This patch is to address an issue in Solaris, bug 17903.

This is my third submission for this issue with changes requested by
Pedro Alvez / Joel Brobecker.

Problem:

When attaching to a process by PID the current implementation in
gdb/procfs.c leaves "to_pid_to_exec_file" at the default -- a stub
function that returns NULL.

This causes symbols not to load when attaching, forcing the user to
either attach by specifying the path on the command line or inside
gdb.  After specifying the file inside gdb it's also necessary to
manually load symbolic information.

The proposed change resembles the implementation in gdb/linux-nat.c.
Pedro indicated Solaris is likely the only OS affected by this code &
still needs support; at his suggestion I tailored this change for
Solaris


I cannot easily run the test suite against these changes right now.
If this gets rejected based on that, I'll see about getting something
setup at home to run the tests when I have time.

----

note: this patch was tested against 8.1.1.  In its current form this
patch cannot be used against 8.2 / master, however it looks like it
won't take much to apply the same change against the new C++ procfs
interface.

-brian

ps, my assignment/release forms were completed/received 10/30/2017
gdb/Changelog:
2018-08-07  Brian Vandenberg  <phantall@gmail.com>

	PR gdb/17903
	* procfs.c (inclusions): Included ansidecl.h for ARG_UNUSED
	(procfs_target): added procfs_child_pid_to_exec_file to target_ops
	(procfs_child_pid_to_exec_file): solaris implementation of
	to_pid_to_exec_file
  

Patch

diff --git a/gdb/procfs.c b/gdb/procfs.c
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -46,6 +46,7 @@ 
 #include "auxv.h"
 #include "procfs.h"
 #include "observer.h"
+#include "ansidecl.h"

/* This module provides the interface between GDB and the
   /proc file system, which is used on many versions of Unix
@@ -95,6 +96,7 @@  static void procfs_fetch_registers (struct target_ops *,
                                    struct regcache *, int);
 static void procfs_store_registers (struct target_ops *,
                                    struct regcache *, int);
+static char* procfs_child_pid_to_exec_file( struct target_ops*, int );
 static void procfs_pass_signals (struct target_ops *self,
                                 int, unsigned char *);
 static void procfs_kill_inferior (struct target_ops *ops);
@@ -169,6 +171,7 @@ procfs_target (void)
   t->to_resume = procfs_resume;
   t->to_fetch_registers = procfs_fetch_registers;
   t->to_store_registers = procfs_store_registers;
+  t->to_pid_to_exec_file = procfs_child_pid_to_exec_file;
   t->to_xfer_partial = procfs_xfer_partial;
   t->to_pass_signals = procfs_pass_signals;
   t->to_files_info = procfs_files_info;
@@ -2175,6 +2178,29 @@  procfs_store_registers (struct target_ops *ops,
     }
 }

+/* Get a fully qualified path to the debugged process */
+static char*
+procfs_child_pid_to_exec_file( struct target_ops *ARG_UNUSED(self),
+                                          int pid )
+{
+  static char buf[PATH_MAX];
+  char name[PATH_MAX];
+  ssize_t sz = -1;
+
+  xsnprintf( name, sizeof(name), "/proc/%u/path/a.out", pid );
+  sz = readlink( name, buf, sizeof( name ) );
+
+  if( 0 < sz )
+  {
+    buf[sz] = '\0';
+    return buf;
+  }
+
+  /* This is the default behavior as defined in target.h
+   * and implemented in inf_child_pid_to_exec_file() */
+  return NULL;
+}
+
static int
syscall_is_lwp_exit (procinfo *pi, int scall)
{