From: Ian Lance Taylor <iant@golang.org>
To: "Björn Schäpers" <gcc@hazardy.de>
Cc: Eli Zaretskii <eliz@gnu.org>, gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org
Subject: Re: [PATCH 2/4] libbacktrace: detect executable path on windows
Date: Wed, 29 Nov 2023 14:05:33 -0800 [thread overview]
Message-ID: <CAKOQZ8xhaBeOwO6+4+BvUoqFC0FXcr-FYD9E13whe0tY6ikFLQ@mail.gmail.com> (raw)
In-Reply-To: <542460b4-0647-1f1e-a160-9f81d03279cb@hazardy.de>
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
On Mon, Nov 20, 2023 at 11:57 AM Björn Schäpers <gcc@hazardy.de> wrote:
>
> this is what I'm using with GCC 12 and 13 on my windows machines, rebased onto
> the current HEAD.
Thanks. Committed as follows.
Ian
* fileline.c: Include <windows.h> if available.
(windows_get_executable_path): New static function.
(fileline_initialize): Call windows_get_executable_path.
* configure.ac: Checked for windows.h
* configure: Regenerate.
* config.h.in: Regenerate.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3728 bytes --]
0ee01dfacbcc9bc05d11433a69c0a0ac13afa42f
diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in
index a4f5bddddf6..ee2616335c7 100644
--- a/libbacktrace/config.h.in
+++ b/libbacktrace/config.h.in
@@ -104,6 +104,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* Define to 1 if you have the <windows.h> header file. */
+#undef HAVE_WINDOWS_H
+
/* Define if -lz is available. */
#undef HAVE_ZLIB
diff --git a/libbacktrace/configure b/libbacktrace/configure
index 0ccc060901d..7ade966b54d 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -13509,6 +13509,19 @@ $as_echo "#define HAVE_LOADQUERY 1" >>confdefs.h
fi
+for ac_header in windows.h
+do :
+ ac_fn_c_check_header_mongrel "$LINENO" "windows.h" "ac_cv_header_windows_h" "$ac_includes_default"
+if test "x$ac_cv_header_windows_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_WINDOWS_H 1
+_ACEOF
+
+fi
+
+done
+
+
# Check for the fcntl function.
if test -n "${with_target_subdir}"; then
case "${host}" in
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 71cd50f8cdf..00acb42eb6d 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -379,6 +379,8 @@ if test "$have_loadquery" = "yes"; then
AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
fi
+AC_CHECK_HEADERS(windows.h)
+
# Check for the fcntl function.
if test -n "${with_target_subdir}"; then
case "${host}" in
diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index 0e560b44e7a..773f3a92969 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -47,6 +47,18 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <mach-o/dyld.h>
#endif
+#ifdef HAVE_WINDOWS_H
+#ifndef WIN32_MEAN_AND_LEAN
+#define WIN32_MEAN_AND_LEAN
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include <windows.h>
+#endif
+
#include "backtrace.h"
#include "internal.h"
@@ -165,6 +177,37 @@ macho_get_executable_path (struct backtrace_state *state,
#endif /* !HAVE_DECL__PGMPTR */
+#ifdef HAVE_WINDOWS_H
+
+#define FILENAME_BUF_SIZE (MAX_PATH)
+
+static char *
+windows_get_executable_path (char *buf, backtrace_error_callback error_callback,
+ void *data)
+{
+ size_t got;
+ int error;
+
+ got = GetModuleFileNameA (NULL, buf, FILENAME_BUF_SIZE - 1);
+ error = GetLastError ();
+ if (got == 0
+ || (got == FILENAME_BUF_SIZE - 1 && error == ERROR_INSUFFICIENT_BUFFER))
+ {
+ error_callback (data,
+ "could not get the filename of the current executable",
+ error);
+ return NULL;
+ }
+ return buf;
+}
+
+#else /* !defined (HAVE_WINDOWS_H) */
+
+#define windows_get_executable_path(buf, error_callback, data) NULL
+#define FILENAME_BUF_SIZE 64
+
+#endif /* !defined (HAVE_WINDOWS_H) */
+
/* Initialize the fileline information from the executable. Returns 1
on success, 0 on failure. */
@@ -178,7 +221,7 @@ fileline_initialize (struct backtrace_state *state,
int called_error_callback;
int descriptor;
const char *filename;
- char buf[64];
+ char buf[FILENAME_BUF_SIZE];
if (!state->threaded)
failed = state->fileline_initialization_failed;
@@ -202,7 +245,7 @@ fileline_initialize (struct backtrace_state *state,
descriptor = -1;
called_error_callback = 0;
- for (pass = 0; pass < 9; ++pass)
+ for (pass = 0; pass < 10; ++pass)
{
int does_not_exist;
@@ -239,6 +282,9 @@ fileline_initialize (struct backtrace_state *state,
case 8:
filename = macho_get_executable_path (state, error_callback, data);
break;
+ case 9:
+ filename = windows_get_executable_path (buf, error_callback, data);
+ break;
default:
abort ();
}
next prev parent reply other threads:[~2023-11-29 22:05 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 10:54 [PATCH 1/4] libbacktrace: change all pc related variables to uintptr_t Björn Schäpers
2023-01-20 10:54 ` [PATCH 2/4] libbacktrace: detect executable path on windows Björn Schäpers
2023-01-23 23:00 ` Ian Lance Taylor
2023-01-24 13:11 ` Eli Zaretskii
2023-01-24 14:35 ` Ian Lance Taylor
2023-01-24 16:52 ` Eli Zaretskii
2023-01-24 17:58 ` Ian Lance Taylor
2023-01-24 18:11 ` Eli Zaretskii
2023-01-24 18:32 ` Ian Lance Taylor
2023-02-05 9:20 ` Björn Schäpers
2023-02-06 0:22 ` Ian Lance Taylor
2023-11-20 19:56 ` Björn Schäpers
2023-11-29 22:05 ` Ian Lance Taylor [this message]
2023-01-24 21:00 ` Björn Schäpers
2023-01-20 10:54 ` [PATCH 3/4] libbacktrace: work with aslr " Björn Schäpers
2023-01-20 13:39 ` Eli Zaretskii
2023-01-20 16:46 ` Gabriel Ravier
2023-01-20 19:19 ` Eli Zaretskii
2023-01-20 20:39 ` Gabriel Ravier
2023-01-21 4:05 ` Eli Zaretskii
2023-01-21 9:18 ` LIU Hao
2023-01-21 9:25 ` Eli Zaretskii
2023-01-21 10:47 ` Gabriel Ravier
2023-01-21 11:42 ` Eli Zaretskii
2023-11-20 19:57 ` Björn Schäpers
2023-11-20 20:07 ` Eli Zaretskii
2023-11-21 19:35 ` Björn Schäpers
2023-11-22 1:13 ` LIU Hao
2023-11-30 19:25 ` Ian Lance Taylor
2023-01-20 10:54 ` [PATCH 4/4] libbacktrace: get debug information for loaded dlls Björn Schäpers
2023-11-30 19:53 ` Ian Lance Taylor
2023-11-30 20:16 ` Eli Zaretskii
2024-01-02 23:12 ` Björn Schäpers
2024-01-04 22:33 ` [PATCH 5/4] libbacktrace: improve getting " Björn Schäpers
2024-01-06 22:15 ` [PATCH 6/4] libbacktrace: Add loaded dlls after initialize Björn Schäpers
2024-01-07 6:50 ` Eli Zaretskii
[not found] ` <4cb3a2a5-c0b3-40c8-b460-f21d65a9aea2@hazardy.de>
2024-01-07 14:46 ` Eli Zaretskii
2024-01-07 16:07 ` Björn Schäpers
2024-01-07 17:03 ` Eli Zaretskii
2024-01-09 20:02 ` Björn Schäpers
2024-01-10 12:34 ` Eli Zaretskii
2024-03-15 20:41 ` Björn Schäpers
2024-01-23 22:37 ` [PATCH 5/4] libbacktrace: improve getting debug information for loaded dlls Ian Lance Taylor
2024-01-25 19:53 ` Björn Schäpers
2024-01-25 22:04 ` Ian Lance Taylor
2024-03-15 20:40 ` Björn Schäpers
2024-04-25 20:14 ` Björn Schäpers
2024-04-28 18:16 ` Ian Lance Taylor
2024-05-02 19:23 ` Björn Schäpers
2024-05-03 22:27 ` Ian Lance Taylor
2024-01-23 21:24 ` [PATCH 4/4] libbacktrace: get " Björn Schäpers
2023-01-20 22:25 ` [PATCH 1/4] libbacktrace: change all pc related variables to uintptr_t Ian Lance Taylor
2023-01-23 20:17 ` Björn Schäpers
-- strict thread matches above, loose matches on Subject: below --
2022-12-06 19:50 Björn Schäpers
2022-12-06 19:50 ` [PATCH 2/4] libbacktrace: detect executable path on windows Björn Schäpers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKOQZ8xhaBeOwO6+4+BvUoqFC0FXcr-FYD9E13whe0tY6ikFLQ@mail.gmail.com \
--to=iant@golang.org \
--cc=eliz@gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc@gcc.gnu.org \
--cc=gcc@hazardy.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).