gdb: Fix building with latest libc++
authorManoj Gupta <manojgupta@google.com>
Mon, 17 Apr 2023 20:33:15 +0000 (13:33 -0700)
committerRoland McGrath <mcgrathr@google.com>
Sat, 29 Apr 2023 07:35:11 +0000 (00:35 -0700)
Latest libc++[1] causes transitive include to <locale> when
<mutex> or <thread> header is included. This causes
gdb to not build[2] since <locale> defines isupper/islower etc.
functions that are explicitly macroed-out in safe-ctype.h to
prevent their use.
Use the suggestion from libc++ to include <locale> internally when
building in C++ mode to avoid build errors.
Use safe-gdb-ctype.h as the include instead of "safe-ctype.h"
to keep this isolated to gdb since rest of binutils
does not seem to use much C++.

[1]: https://reviews.llvm.org/D144331
[2]: https://issuetracker.google.com/issues/277967395

15 files changed:
gdb/cp-name-parser.y
gdb/cp-support.c
gdb/dictionary.c
gdb/disasm.c
gdb/dwarf2/cooked-index.c
gdb/mi/mi-cmd-stack.c
gdb/minsyms.c
gdb/or1k-tdep.c
gdb/printcmd.c
gdb/riscv-tdep.c
gdb/tui/tui-layout.c
gdb/tui/tui-winsource.c
gdb/xml-support.c
gdbsupport/common-utils.cc
gdbsupport/gdb-safe-ctype.h

index 175e763a423f36cc43cb8ede06ed0abc949f50ef..80188074202f6551b39430aefd580ee3fa2cd721 100644 (file)
@@ -40,7 +40,7 @@
 #include "defs.h"
 
 #include <unistd.h>
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "demangle.h"
 #include "cp-support.h"
 #include "c-support.h"
index f39c5d051dd63f6742382d95d37fd3fc7aae8204..e804024c08f9e75334e123da36331f08e4e05cf5 100644 (file)
@@ -36,7 +36,7 @@
 #include "namespace.h"
 #include <signal.h>
 #include "gdbsupport/gdb_setjmp.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "gdbsupport/selftest.h"
 #include "gdbsupport/gdb-sigmask.h"
 #include <atomic>
index 403508adfdc60de26c33d762ea077e356d8acc0b..4f8df240a3e8c4bfefd5af5bf0cdf42da2593916 100644 (file)
@@ -26,7 +26,7 @@
 #include "symtab.h"
 #include "buildsym.h"
 #include "dictionary.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include <unordered_map>
 #include "language.h"
 
index 03cd4b7ee025744ab31ad8f7c85236818c00836f..e6b31bf36330559321e6ba24e7ef4c9de6d11ed7 100644 (file)
@@ -27,7 +27,7 @@
 #include "gdbcmd.h"
 #include "dis-asm.h"
 #include "source.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include <algorithm>
 #include "gdbsupport/gdb_optional.h"
 #include "valprint.h"
index 1b1a16b1ae26e1736723b694046ee6cf0ccf9a35..25635d9b72e9ce738fad417d915a253cccf54c4c 100644 (file)
@@ -29,7 +29,7 @@
 #include "observable.h"
 #include "run-on-main-thread.h"
 #include <algorithm>
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "gdbsupport/selftest.h"
 #include <chrono>
 #include <unordered_set>
index 4c4662ab5d73cef358c2ae4459a6b30d3ff61b36..b8169a67e4426e052db4a513f95500098d830f9e 100644 (file)
@@ -35,7 +35,7 @@
 #include <ctype.h>
 #include "mi-parse.h"
 #include "gdbsupport/gdb_optional.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "inferior.h"
 #include "observable.h"
 
index 5fcc724262699ff7ea590674bf4028c4195c52ab..07e83e87c1a1c9bc2582fa664e55229e6d629ca3 100644 (file)
@@ -52,7 +52,7 @@
 #include "cli/cli-utils.h"
 #include "gdbsupport/symbol.h"
 #include <algorithm>
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "gdbsupport/parallel-for.h"
 #include "inferior.h"
 
index 0d520661f09ecae783ecba256d6b302d02c51714..5cef1fa279c0fa4974a8a2b1ad27a0eb6c65a2eb 100644 (file)
@@ -29,7 +29,7 @@
 #include "gdbtypes.h"
 #include "target.h"
 #include "regcache.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "reggroups.h"
 #include "arch-utils.h"
 #include "frame-unwind.h"
index 6435311736b09902f4b2b9c57bc772997aa61e78..f6d5bad8ae06a39f2dba492ba198d2ecdc5058f5 100644 (file)
@@ -53,7 +53,7 @@
 #include "source.h"
 #include "gdbsupport/byte-vector.h"
 #include "gdbsupport/gdb_optional.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "gdbsupport/rsp-low.h"
 
 /* Chain containing all defined memory-tag subcommands.  */
index 144eb7e0132737dddd83f5f25d7317e7b33f14b3..500279e1ae9ecc9bd1971aef000a5c7f91f1a0ec 100644 (file)
@@ -56,7 +56,7 @@
 #include "prologue-value.h"
 #include "arch/riscv.h"
 #include "riscv-ravenscar-thread.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 
 /* The stack must be 16-byte aligned.  */
 #define SP_ALIGNMENT 16
index 01d243ba9a12656fc113336b8e2509895fe78226..50c568fb7d7cc74adcf16550d8892aab7766e034 100644 (file)
@@ -43,7 +43,7 @@
 #include "tui/tui-layout.h"
 #include "tui/tui-source.h"
 #include "gdb_curses.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 
 static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
 
index 84f9d97c554aa2d30a210a0ae3249e94434cb403..3c4ce501e5eef97e42f83313c1f21019bad7d71b 100644 (file)
@@ -28,7 +28,7 @@
 #include "source.h"
 #include "objfiles.h"
 #include "filenames.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 
 #include "tui/tui.h"
 #include "tui/tui-data.h"
index 255c10864c5f7a83aa62088fabe0eadb0c7c9807..0c98dc7e6b493b9bfba1b2d4206e902612999d2b 100644 (file)
@@ -22,7 +22,7 @@
 #include "xml-builtin.h"
 #include "xml-support.h"
 #include "gdbsupport/filestuff.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include <vector>
 #include <string>
 
index 4a96f2c0e119f3693467dc002fb3a7036db75501..a2dde636011586dc5f5d2683df16caa3228efdc0 100644 (file)
@@ -20,7 +20,7 @@
 #include "common-defs.h"
 #include "common-utils.h"
 #include "host-defs.h"
-#include "safe-ctype.h"
+#include "gdbsupport/gdb-safe-ctype.h"
 #include "gdbsupport/gdb-xfree.h"
 
 void *
index f9743ba26f178399344f5a4f3d3c41d17be5a6db..bec85c0014d37fc3819f0de47f24818029369358 100644 (file)
@@ -23,7 +23,9 @@
 /* After safe-ctype.h is included, we can no longer use the host's
    ctype routines.  Trying to do so results in compile errors.  Code
    that uses safe-ctype.h that wants to refer to the locale-dependent
-   ctype functions must call these wrapper versions instead.  */
+   ctype functions must call these wrapper versions instead.
+   When compiling in C++ mode, also include <locale> before "safe-ctype.h"
+   which also defines is* functions.  */
 
 static inline int
 gdb_isprint (int ch)
@@ -41,6 +43,7 @@ gdb_isprint (int ch)
 #undef ISUPPER
 #undef ISXDIGIT
 
+#include <locale>
 #include "safe-ctype.h"
 
 #endif