From 11bf33c32cb22f85d59f4be0cf9f816b3535418f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 13 Mar 2024 00:15:10 +0100 Subject: [PATCH] libbacktrace: look for _pgmptr on Windows (c1c86fa2) --- public/libbacktrace/fileline.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/public/libbacktrace/fileline.cpp b/public/libbacktrace/fileline.cpp index 8645d754..3db800dc 100644 --- a/public/libbacktrace/fileline.cpp +++ b/public/libbacktrace/fileline.cpp @@ -158,6 +158,16 @@ macho_get_executable_path (struct backtrace_state *state, #endif /* !defined (HAVE_MACH_O_DYLD_H) */ +#if HAVE_DECL__PGMPTR + +#define windows_executable_filename() _pgmptr + +#else /* !HAVE_DECL__PGMPTR */ + +#define windows_executable_filename() NULL + +#endif /* !HAVE_DECL__PGMPTR */ + /* Initialize the fileline information from the executable. Returns 1 on success, 0 on failure. */ @@ -195,7 +205,7 @@ fileline_initialize (struct backtrace_state *state, descriptor = -1; called_error_callback = 0; - for (pass = 0; pass < 8; ++pass) + for (pass = 0; pass < 9; ++pass) { int does_not_exist; @@ -208,23 +218,28 @@ fileline_initialize (struct backtrace_state *state, filename = getexecname (); break; case 2: - filename = "/proc/self/exe"; + /* Test this before /proc/self/exe, as the latter exists but points + to the wine binary (and thus doesn't work). */ + filename = windows_executable_filename (); break; case 3: - filename = "/proc/curproc/file"; + filename = "/proc/self/exe"; break; case 4: + filename = "/proc/curproc/file"; + break; + case 5: snprintf (buf, sizeof (buf), "/proc/%ld/object/a.out", (long) getpid ()); filename = buf; break; - case 5: + case 6: filename = sysctl_exec_name1 (state, error_callback, data); break; - case 6: + case 7: filename = sysctl_exec_name2 (state, error_callback, data); break; - case 7: + case 8: filename = macho_get_executable_path (state, error_callback, data); break; default: