mirror of
https://github.com/ianlancetaylor/libbacktrace.git
synced 2026-04-01 23:19:07 +08:00
libbacktrace: call GetModuleFileNameA on Windows
Patch from Björn Schäpers. * 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.
This commit is contained in:
@@ -104,6 +104,9 @@
|
|||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
#undef HAVE_UNISTD_H
|
#undef HAVE_UNISTD_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <windows.h> header file. */
|
||||||
|
#undef HAVE_WINDOWS_H
|
||||||
|
|
||||||
/* Define if -lz is available. */
|
/* Define if -lz is available. */
|
||||||
#undef HAVE_ZLIB
|
#undef HAVE_ZLIB
|
||||||
|
|
||||||
|
|||||||
13
configure
vendored
13
configure
vendored
@@ -12440,6 +12440,19 @@ $as_echo "#define HAVE_LOADQUERY 1" >>confdefs.h
|
|||||||
|
|
||||||
fi
|
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.
|
# Check for the fcntl function.
|
||||||
if test -n "${with_target_subdir}"; then
|
if test -n "${with_target_subdir}"; then
|
||||||
case "${host}" in
|
case "${host}" in
|
||||||
|
|||||||
@@ -373,6 +373,8 @@ if test "$have_loadquery" = "yes"; then
|
|||||||
AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
|
AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_CHECK_HEADERS(windows.h)
|
||||||
|
|
||||||
# Check for the fcntl function.
|
# Check for the fcntl function.
|
||||||
if test -n "${with_target_subdir}"; then
|
if test -n "${with_target_subdir}"; then
|
||||||
case "${host}" in
|
case "${host}" in
|
||||||
|
|||||||
50
fileline.c
50
fileline.c
@@ -47,6 +47,18 @@ POSSIBILITY OF SUCH DAMAGE. */
|
|||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#endif
|
#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 "backtrace.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
@@ -165,6 +177,37 @@ macho_get_executable_path (struct backtrace_state *state,
|
|||||||
|
|
||||||
#endif /* !HAVE_DECL__PGMPTR */
|
#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
|
/* Initialize the fileline information from the executable. Returns 1
|
||||||
on success, 0 on failure. */
|
on success, 0 on failure. */
|
||||||
|
|
||||||
@@ -178,7 +221,7 @@ fileline_initialize (struct backtrace_state *state,
|
|||||||
int called_error_callback;
|
int called_error_callback;
|
||||||
int descriptor;
|
int descriptor;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
char buf[64];
|
char buf[FILENAME_BUF_SIZE];
|
||||||
|
|
||||||
if (!state->threaded)
|
if (!state->threaded)
|
||||||
failed = state->fileline_initialization_failed;
|
failed = state->fileline_initialization_failed;
|
||||||
@@ -202,7 +245,7 @@ fileline_initialize (struct backtrace_state *state,
|
|||||||
|
|
||||||
descriptor = -1;
|
descriptor = -1;
|
||||||
called_error_callback = 0;
|
called_error_callback = 0;
|
||||||
for (pass = 0; pass < 9; ++pass)
|
for (pass = 0; pass < 10; ++pass)
|
||||||
{
|
{
|
||||||
int does_not_exist;
|
int does_not_exist;
|
||||||
|
|
||||||
@@ -239,6 +282,9 @@ fileline_initialize (struct backtrace_state *state,
|
|||||||
case 8:
|
case 8:
|
||||||
filename = macho_get_executable_path (state, error_callback, data);
|
filename = macho_get_executable_path (state, error_callback, data);
|
||||||
break;
|
break;
|
||||||
|
case 9:
|
||||||
|
filename = windows_get_executable_path (buf, error_callback, data);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user