* [PATCH v2] gdb: Fix building with latest libc++
@ 2023-04-17 21:07 Manoj Gupta
2023-04-21 14:01 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Manoj Gupta @ 2023-04-17 21:07 UTC (permalink / raw)
To: gdb-patches; +Cc: manojgupta
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
---
gdb/cp-name-parser.y | 2 +-
gdb/cp-support.c | 2 +-
gdb/dictionary.c | 2 +-
gdb/disasm.c | 2 +-
gdb/dwarf2/cooked-index.c | 2 +-
gdb/mi/mi-cmd-stack.c | 2 +-
gdb/minsyms.c | 2 +-
gdb/or1k-tdep.c | 2 +-
gdb/printcmd.c | 2 +-
gdb/riscv-tdep.c | 2 +-
gdb/tui/tui-layout.c | 2 +-
gdb/tui/tui-winsource.c | 2 +-
gdb/xml-support.c | 2 +-
gdbsupport/common-utils.cc | 2 +-
gdbsupport/gdb-safe-ctype.h | 8 +++++++-
15 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 175e763a423..80188074202 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -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"
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index f39c5d051dd..e804024c08f 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -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>
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 403508adfdc..4f8df240a3e 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -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"
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 03cd4b7ee02..e6b31bf3633 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -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"
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 1b1a16b1ae2..25635d9b72e 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -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>
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 4c4662ab5d7..b8169a67e44 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -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"
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 3fa07f47b9f..e269420e87f 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -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"
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 0d520661f09..5cef1fa279c 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -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"
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index dd92e31d31b..d732c6d704d 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -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. */
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 144eb7e0132..500279e1ae9 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -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
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 01d243ba9a1..50c568fb7d7 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -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 *);
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 84f9d97c554..3c4ce501e5e 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -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"
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index 255c10864c5..0c98dc7e6b4 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -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>
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index 4a96f2c0e11..a2dde636011 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -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 *
diff --git a/gdbsupport/gdb-safe-ctype.h b/gdbsupport/gdb-safe-ctype.h
index f9743ba26f1..ed522dc72dd 100644
--- a/gdbsupport/gdb-safe-ctype.h
+++ b/gdbsupport/gdb-safe-ctype.h
@@ -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, aldo include <locale> before "safe-ctype.h"
+ which also defines is* functions. */
static inline int
gdb_isprint (int ch)
@@ -41,6 +43,10 @@ gdb_isprint (int ch)
#undef ISUPPER
#undef ISXDIGIT
+#ifdef __cplusplus
+#include <locale>
+#endif
+
#include "safe-ctype.h"
#endif
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gdb: Fix building with latest libc++
2023-04-17 21:07 [PATCH v2] gdb: Fix building with latest libc++ Manoj Gupta
@ 2023-04-21 14:01 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-04-21 14:01 UTC (permalink / raw)
To: Manoj Gupta via Gdb-patches; +Cc: Manoj Gupta
>>>>> "Manoj" == Manoj Gupta via Gdb-patches <gdb-patches@sourceware.org> writes:
Manoj> Latest libc++[1] causes transitive include to <locale> when
Manoj> <mutex> or <thread> header is included. This causes
Manoj> gdb to not build[2] since <locale> defines isupper/islower etc.
Manoj> functions that are explicitly macroed-out in safe-ctype.h to
Manoj> prevent their use.
Manoj> Use the suggestion from libc++ to include <locale> internally when
Manoj> building in C++ mode to avoid build errors.
Manoj> Use safe-gdb-ctype.h as the include instead of "safe-ctype.h"
Manoj> to keep this isolated to gdb since rest of binutils
Manoj> does not seem to use much C++.
Thank you for the patch.
Manoj> /* After safe-ctype.h is included, we can no longer use the host's
Manoj> ctype routines. Trying to do so results in compile errors. Code
Manoj> that uses safe-ctype.h that wants to refer to the locale-dependent
Manoj> - ctype functions must call these wrapper versions instead. */
Manoj> + ctype functions must call these wrapper versions instead.
Manoj> + When compiling in C++ mode, aldo include <locale> before "safe-ctype.h"
"also"
Manoj> +#ifdef __cplusplus
Manoj> +#include <locale>
Manoj> +#endif
I don't think the #ifdef is needed, anything that uses gdbsupport is
also written in C++.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-21 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17 21:07 [PATCH v2] gdb: Fix building with latest libc++ Manoj Gupta
2023-04-21 14:01 ` Tom Tromey
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).