Crash handler: Use PRIdPTR format where available

Printing pointers from the crash handler has been broken starting
with an update to MinGW at some point in the past, when they stopped
using printf from MSVCRT, instead replacing it with a private
implementation. Fix this by checking for inttypes.h availability, and
using it (and its format macro) when possible.
issue1247
Nicolas Hake 2015-01-15 10:13:18 +01:00
parent f2830311a6
commit 8a729b4c6f
2 changed files with 9 additions and 1 deletions

View File

@ -761,6 +761,7 @@ CHECK_INCLUDE_FILE_CXX(locale.h HAVE_LOCALE_H)
CHECK_INCLUDE_FILE_CXX(share.h HAVE_SHARE_H)
CHECK_INCLUDE_FILE_CXX(signal.h HAVE_SIGNAL_H)
CHECK_INCLUDE_FILE_CXX(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILE_CXX(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE_CXX(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE_CXX(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE_CXX(unistd.h HAVE_UNISTD_H)

View File

@ -28,6 +28,11 @@
#include <fcntl.h>
#include <string.h>
#include <tlhelp32.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#endif
static bool FirstCrash = true;
@ -59,7 +64,9 @@ namespace {
#define LOG_DYNAMIC_TEXT(...) write(fd, DumpBuffer, LOG_SNPRINTF(DumpBuffer, DumpBufferSize-1, __VA_ARGS__))
// Figure out which kind of format string will output a pointer in hex
#if defined(_MSC_VER) || defined(__MINGW32__)
#if defined(PRIdPTR)
# define POINTER_FORMAT_SUFFIX PRIdPTR
#elif defined(_MSC_VER)
# define POINTER_FORMAT_SUFFIX "Ix"
#elif defined(__GNUC__)
# define POINTER_FORMAT_SUFFIX "zx"