Tested on hppa64-hp-hpux11.11.

Okay?

Dave
---

libbacktrace: Add hpux fileline support

Fixes libstdc++ stacktrace tests.

2025-04-09  John David Anglin  <dang...@gcc.gnu.org>

libbacktrace/ChangeLog:
        * fileline.c (hpux_get_executable_path): New.
        (fileline_initialize): Add pass to get hpux executable path.

diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index c9fd86b8c0c..e46ea05e528 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -66,6 +66,35 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #define getexecname() NULL
 #endif
 
+#ifdef __hpux__
+#include <dl.h>
+
+static char *
+hpux_get_executable_path (struct backtrace_state *state,
+                         backtrace_error_callback error_callback, void *data)
+{
+  struct shl_descriptor *desc;
+  size_t len = sizeof (struct shl_descriptor);
+
+  desc = backtrace_alloc (state, len, error_callback, data);
+  if (desc == NULL)
+    return NULL;
+
+  if (shl_get_r (0, desc) == -1)
+    {
+      backtrace_free (state, desc, len, error_callback, data);
+      return NULL;
+    }
+
+  return desc->filename;
+}
+
+#else
+
+#define hpux_get_executable_path(state, error_callback, data) NULL
+
+#endif
+
 #if !defined (HAVE_KERN_PROC_ARGS) && !defined (HAVE_KERN_PROC)
 
 #define sysctl_exec_name1(state, error_callback, data) NULL
@@ -245,7 +274,7 @@ fileline_initialize (struct backtrace_state *state,
 
   descriptor = -1;
   called_error_callback = 0;
-  for (pass = 0; pass < 10; ++pass)
+  for (pass = 0; pass < 11; ++pass)
     {
       int does_not_exist;
 
@@ -285,6 +314,9 @@ fileline_initialize (struct backtrace_state *state,
        case 9:
          filename = windows_get_executable_path (buf, error_callback, data);
          break;
+       case 10:
+         filename = hpux_get_executable_path (state, error_callback, data);
+         break;
        default:
          abort ();
        }

Attachment: signature.asc
Description: PGP signature

Reply via email to