Skip to content

Commit

Permalink
Export patch series to _PATCHES/
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeubank committed May 24, 2021
1 parent 4f09889 commit 9415ca8
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 0 deletions.
108 changes: 108 additions & 0 deletions _PATCHES/colorize-mintty.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Emit colored text when running under MinTTY.

From: J.M. Eubank <[email protected]>


---
gdb/ui-file.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
gdb/ui-file.h | 3 +++
2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index eb1d72bf..0663e59f 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -26,6 +26,12 @@
#include "gdbsupport/filestuff.h"
#include "cli/cli-style.h"

+#if defined(__MINGW32_VERSION) /* MinGW.org */
+# include <ddk/ntifs.h>
+#elif defined(_WIN32) /* MinGW-w64 */
+# include <winternl.h>
+#endif
+
null_file null_stream;

ui_file::ui_file ()
@@ -152,7 +158,8 @@ stdio_file::stdio_file (FILE *file, bool close_p)
stdio_file::stdio_file ()
: m_file (NULL),
m_fd (-1),
- m_close_p (false)
+ m_close_p (false),
+ m_is_a_tty (-1)
{}

stdio_file::~stdio_file ()
@@ -253,7 +260,55 @@ stdio_file::puts (const char *linebuffer)
bool
stdio_file::isatty ()
{
- return ::isatty (m_fd);
+ if (m_is_a_tty != -1)
+ return m_is_a_tty;
+
+ m_is_a_tty = ::isatty (m_fd);
+
+#ifdef _WIN32
+ /* isatty() might be wrong, check GetConsoleMode first */
+ HANDLE h;
+ if ((h = (HANDLE) _get_osfhandle (m_fd)) == INVALID_HANDLE_VALUE)
+ return (m_is_a_tty = 0);
+
+ DWORD ignored;
+ if (GetConsoleMode (h, &ignored) != 0)
+ return (m_is_a_tty = 1);
+ m_is_a_tty = 0;
+
+ /* Also check if we are running in MinTTY */
+ HMODULE ntdll = GetModuleHandle ("ntdll.dll");
+ if (ntdll != INVALID_HANDLE_VALUE)
+ {
+ typedef NTSTATUS NTAPI func_NtQueryObject (HANDLE, OBJECT_INFORMATION_CLASS, PVOID, ULONG, PULONG);
+ func_NtQueryObject *fNtQueryObject =
+ (func_NtQueryObject*) GetProcAddress (ntdll, "NtQueryObject");
+ if (fNtQueryObject)
+ {
+ ULONG s = 0xffff * sizeof (WCHAR);
+ OBJECT_NAME_INFORMATION *oni = (OBJECT_NAME_INFORMATION*) xmalloc (s);
+ ULONG len;
+ /* mintty uses a named pipe like "ptyNNNN-to-master". */
+ if (!fNtQueryObject (h, ObjectNameInformation, oni, s, &len))
+ {
+ wchar_t namedPipe[] = L"\\Device\\NamedPipe\\";
+ size_t l1 = sizeof (namedPipe) / 2 - 1;
+ wchar_t toMaster[] = L"-to-master";
+ size_t l2 = sizeof (toMaster) / 2 - 1;
+ USHORT name_length = oni->Name.Length / 2;
+ if (name_length > l1 + l2 &&
+ !memcmp (oni->Name.Buffer, namedPipe, l1 * 2) &&
+ !memcmp (oni->Name.Buffer + (name_length - l2), toMaster, l2 * 2))
+ m_is_a_tty = 1;
+ }
+ free (oni);
+ if (m_is_a_tty == 1)
+ return 1;
+ }
+ }
+#endif
+
+ return m_is_a_tty;
}

/* See ui-file.h. */
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 61509735..b8377180 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -210,6 +210,9 @@ class stdio_file : public ui_file

/* If true, M_FILE is closed on destruction. */
bool m_close_p;
+
+ /* Cache the result of isatty */
+ int m_is_a_tty;
};

typedef std::unique_ptr<stdio_file> stdio_file_up;
39 changes: 39 additions & 0 deletions _PATCHES/gdb-7.12-dynamic-libs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Don't ask for libgcc and libstdc++ static linkage by default when building GDB

From: Orgad Shaneh <[email protected]>

(but TDM-GCC will perform static linkage for these libraries anyway)
From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gdb/gdb-7.12-dynamic-libs.patch>

From 04a27a15b268e07c76578c074c3822477ceabc50 Mon Sep 17 00:00:00 2001
Subject: [PATCH] configure: Disable static linking with standard libs

Linking statically causes spurious crashes on exception handling
with mingw32.
---
configure | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 68779feb..c05704a5 100755
--- a/configure
+++ b/configure
@@ -5883,7 +5883,7 @@ else
# trust that they are doing what they want.
if test "$with_static_standard_libraries" = yes -a "$stage1_libs" = "" \
-a "$have_static_libs" = yes; then
- stage1_ldflags="-static-libstdc++ -static-libgcc"
+ stage1_ldflags=""
fi
fi

@@ -5919,7 +5919,7 @@ else
# statically. But if the user explicitly specified the libraries to
# use, trust that they are doing what they want.
if test "$poststage1_libs" = ""; then
- poststage1_ldflags="-static-libstdc++ -static-libgcc"
+ poststage1_ldflags=""
fi
fi

60 changes: 60 additions & 0 deletions _PATCHES/gdb-8.3-lib-order.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Fix link order due to library interdependency

From: Orgad Shaneh <[email protected]>

From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gdb/gdb-8.3-lib-order.patch>

From 699d1bec385c16261eb9fe3de0f71a8cafc73082 Mon Sep 17 00:00:00 2001
Subject: [PATCH] Fix link order on Windows

libgnu uses ntop, which comes from ws2_32 library, so ws2_32 needs
to be linked after libgnu.
---
gdb/Makefile.in | 7 ++++---
gdbserver/Makefile.in | 4 ++--
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index ec371fc7..8f9d27ff 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -626,9 +626,9 @@ CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) \
$(XM_CLIBS) $(GDBTKLIBS) \
@LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \
$(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \
- $(WIN32LIBS) $(LIBGNU) $(LIBICONV) \
+ $(LIBGNU) $(LIBICONV) \
$(LIBMPFR) $(SRCHIGH_LIBS) $(LIBXXHASH) $(PTHREAD_LIBS) \
- $(DEBUGINFOD_LIBS)
+ $(DEBUGINFOD_LIBS) $(WIN32LIBS)
CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(CTF_DEPS) \
$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU) \
$(LIBSUPPORT)
@@ -1864,8 +1864,9 @@ libgdb.a: $(LIBGDB_OBS)
# Removing the old gdb first works better if it is running, at least on SunOS.
gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(CDEPS) $(TDEPLIBS)
$(SILENCE) rm -f gdb$(EXEEXT)
- $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
+ $(ECHO_CXXLD) $(CC_LD) $(WIN32LDAPP) \
-o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \
+ $(INTERNAL_LDFLAGS) \
$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
ifneq ($(CODESIGN_CERT),)
$(ECHO_SIGN) $(CODESIGN) -s $(CODESIGN_CERT) gdb$(EXEEXT)
diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
index 2bd3a578..3484a655 100644
--- a/gdbserver/Makefile.in
+++ b/gdbserver/Makefile.in
@@ -352,9 +352,9 @@ clean-info:
gdbserver$(EXEEXT): $(sort $(OBS)) ${CDEPS} $(LIBGNU) $(LIBIBERTY) \
$(INTL_DEPS) $(GDBSUPPORT)
$(SILENCE) rm -f gdbserver$(EXEEXT)
- $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
+ $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) \
-o gdbserver$(EXEEXT) $(OBS) $(GDBSUPPORT) $(LIBGNU) \
- $(LIBIBERTY) $(INTL) $(GDBSERVER_LIBS) $(XM_CLIBS) \
+ $(LIBIBERTY) $(INTL) $(INTERNAL_LDFLAGS) $(GDBSERVER_LIBS) $(XM_CLIBS) \
$(WIN32APILIBS)

gdbreplay$(EXEEXT): $(sort $(GDBREPLAY_OBS)) $(LIBGNU) $(LIBIBERTY) \
38 changes: 38 additions & 0 deletions _PATCHES/gdb-fix-tui-with-pdcurses.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Fix typecasting hygiene when building with pdcurses

From: J.M. Eubank <[email protected]>

From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gdb/gdb-fix-tui-with-pdcurses.patch>
---
gdb/tui/tui-win.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index ea417323..143db850 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -118,15 +118,15 @@ struct tui_translate
The list of values must be terminated by a NULL.
After the NULL value, an entry defines the default. */
static struct tui_translate tui_border_mode_translate[] = {
- { "normal", A_NORMAL },
- { "standout", A_STANDOUT },
- { "reverse", A_REVERSE },
- { "half", A_DIM },
- { "half-standout", A_DIM | A_STANDOUT },
- { "bold", A_BOLD },
- { "bold-standout", A_BOLD | A_STANDOUT },
+ { "normal", static_cast<int>(A_NORMAL) },
+ { "standout", static_cast<int>(A_STANDOUT) },
+ { "reverse", static_cast<int>(A_REVERSE) },
+ { "half", static_cast<int>(A_DIM) },
+ { "half-standout", static_cast<int>(A_DIM | A_STANDOUT) },
+ { "bold", static_cast<int>(A_BOLD) },
+ { "bold-standout", static_cast<int>(A_BOLD | A_STANDOUT) },
{ 0, 0 },
- { "normal", A_NORMAL }
+ { "normal", static_cast<int>(A_NORMAL) }
};

/* Translation tables for border-kind, one for each border
99 changes: 99 additions & 0 deletions _PATCHES/gdb-fix-using-gnu-print.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Fix formatted printing by using ANSI specifiers if __USE_MINGW_ANSI_STDIO is requested

From: J.M. Eubank <[email protected]>

From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gdb/gdb-fix-using-gnu-print.patch>

# HG changeset patch
# Parent 36581a69f2d88d85964156d286a6cf6a3fae9e3d
---
bfd/bfd-in.h | 2 +-
bfd/bfd-in2.h | 2 +-
gdbsupport/format.h | 6 +++++-
gnulib/import/inttypes.in.h | 8 ++++----
4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 76b17bf7..f0a5be08 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -158,7 +158,7 @@ typedef BFD_HOST_U_64_BIT symvalue;

#if BFD_HOST_64BIT_LONG
#define BFD_VMA_FMT "l"
-#elif defined (__MSVCRT__)
+#elif defined(__MSVCRT__) && !defined( __USE_MINGW_ANSI_STDIO)
#define BFD_VMA_FMT "I64"
#else
#define BFD_VMA_FMT "ll"
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 935ba535..b04cd11f 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -165,7 +165,7 @@ typedef BFD_HOST_U_64_BIT symvalue;

#if BFD_HOST_64BIT_LONG
#define BFD_VMA_FMT "l"
-#elif defined (__MSVCRT__)
+#elif defined (__MSVCRT__) && !defined(__USE_MINGW_ANSI_STDIO)
#define BFD_VMA_FMT "I64"
#else
#define BFD_VMA_FMT "ll"
diff --git a/gdbsupport/format.h b/gdbsupport/format.h
index 921fca5e..75d12ae5 100644
--- a/gdbsupport/format.h
+++ b/gdbsupport/format.h
@@ -23,7 +23,11 @@
#include "gdbsupport/gdb_string_view.h"

#if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
-# define USE_PRINTF_I64 1
+# if !defined(__USE_MINGW_ANSI_STDIO)
+# define USE_PRINTF_I64 1
+# else
+# define USE_PRINTF_I64 0
+# endif
# define PRINTF_HAS_LONG_LONG
#else
# define USE_PRINTF_I64 0
diff --git a/gnulib/import/inttypes.in.h b/gnulib/import/inttypes.in.h
index 9f04a6ce..f595c7a2 100644
--- a/gnulib/import/inttypes.in.h
+++ b/gnulib/import/inttypes.in.h
@@ -189,7 +189,7 @@
#ifdef INT64_MAX
# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
# define _PRI64_PREFIX "l"
-# elif defined _MSC_VER || defined __MINGW32__
+# elif (defined _MSC_VER || defined __MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
# define _PRI64_PREFIX "I64"
# elif LONG_MAX >> 30 == 1
# define _PRI64_PREFIX _LONG_LONG_FORMAT_PREFIX
@@ -206,7 +206,7 @@
#ifdef UINT64_MAX
# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
# define _PRIu64_PREFIX "l"
-# elif defined _MSC_VER || defined __MINGW32__
+# elif (defined _MSC_VER || defined __MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
# define _PRIu64_PREFIX "I64"
# elif ULONG_MAX >> 31 == 1
# define _PRIu64_PREFIX _LONG_LONG_FORMAT_PREFIX
@@ -682,7 +682,7 @@
#ifdef INT64_MAX
# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
# define _SCN64_PREFIX "l"
-# elif defined _MSC_VER || defined __MINGW32__
+# elif (defined _MSC_VER || defined __MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
# define _SCN64_PREFIX "I64"
# elif LONG_MAX >> 30 == 1
# define _SCN64_PREFIX _LONG_LONG_FORMAT_PREFIX
@@ -699,7 +699,7 @@
#ifdef UINT64_MAX
# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
# define _SCNu64_PREFIX "l"
-# elif defined _MSC_VER || defined __MINGW32__
+# elif (defined _MSC_VER || defined __MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
# define _SCNu64_PREFIX "I64"
# elif ULONG_MAX >> 31 == 1
# define _SCNu64_PREFIX _LONG_LONG_FORMAT_PREFIX
29 changes: 29 additions & 0 deletions _PATCHES/gdb-performance.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Improve print performance on large codebases

From: J.M. Eubank <[email protected]>

with a hack to use raw printing when `info {func,var,type}` is invoked; from
<https://sourceware.org/bugzilla/show_bug.cgi?id=15412>

# HG changeset patch
# Parent bb0cf755760039ed58778ecf3d0c8980825bde24
As DJE said, the workaround looks like below:
gdb/typeprint.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
gdb/typeprint.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index cab6afa7..4baca8e9 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -54,7 +54,7 @@ const struct type_print_options type_print_raw_options =

static struct type_print_options default_ptype_flags =
{
- 0, /* raw */
+ 1, /* raw */
1, /* print_methods */
1, /* print_typedefs */
0, /* print_offsets */
8 changes: 8 additions & 0 deletions _PATCHES/series
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This series applies on GIT commit e03c6ed583ca3dd1be8d6718c33f200e47282c5b
colorize-mintty.patch
gdb-performance.patch
gdb-fix-using-gnu-print.patch
gdb-7.12-dynamic-libs.patch
gdb-fix-tui-with-pdcurses.patch
gdb-8.3-lib-order.patch
windows-home.patch
Loading

0 comments on commit 9415ca8

Please sign in to comment.