* [PATCH] [gdbsupport] Poison ctype.h / cctype functions
@ 2026-03-22 16:03 Tom de Vries
2026-03-23 14:17 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2026-03-22 16:03 UTC (permalink / raw)
To: gdb-patches
GDB generally uses c_isprint instead of isprint or std::isprint [1].
Poison uses of ctype.h / cctype functions in gdbsupport/poison.h.
This excludes isupper, islower and toupper because they're currently used in
GDB. Add a fixme to find out whether these exceptions are ok, and if so
document why, otherwise fix them.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34017
[1] https://sourceware.org/pipermail/gdb-patches/2026-March/226117.html
---
gdbsupport/poison.h | 52 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/gdbsupport/poison.h b/gdbsupport/poison.h
index 904646110a5..0963645ee81 100644
--- a/gdbsupport/poison.h
+++ b/gdbsupport/poison.h
@@ -237,4 +237,56 @@ non-POD data type.");
#undef XOBNEWVEC
#define XOBNEWVEC(O, T, N) xobnewvec<T> (O, N)
+#ifndef IN_PROCESS_AGENT
+/* Poison functions like isprint from header filer ctype.h and std::isprint
+ from header file cctype. */
+
+#define POISON_CCTYPE(F) \
+ template<typename T> \
+ F \
+ { \
+ static_assert (false, "Please use gnulib's c-ctype.h"); \
+ return 0; \
+ }
+
+/* Poisoning of some functions is disabled:
+ - isupper, because it's used in ada_decode.
+ - islower and toupper, because they're used in UNCTRL from readline,
+ which is used in tui_redisplay_readline and gdb_fnprint.
+
+ FIXME: Find out whether these exceptions are ok, and if so document
+ why, otherwise fix them. */
+
+POISON_CCTYPE (int isalnum (T c));
+POISON_CCTYPE (int std::isalnum (T c));
+POISON_CCTYPE (int isalpha (T c));
+POISON_CCTYPE (int std::isalpha (T c));
+POISON_CCTYPE (int isblank (T c));
+POISON_CCTYPE (int std::isblank (T c));
+POISON_CCTYPE (int iscntrl (T c));
+POISON_CCTYPE (int std::iscntrl (T c));
+POISON_CCTYPE (int isdigit (T c));
+POISON_CCTYPE (int std::isdigit (T c));
+POISON_CCTYPE (int isgraph (T c));
+POISON_CCTYPE (int std::isgraph (T c));
+/* Disabled: int islower (T c)). */
+POISON_CCTYPE (int std::islower (T c));
+POISON_CCTYPE (int isprint (T c));
+POISON_CCTYPE (int std::isprint (T c));
+POISON_CCTYPE (int ispunct (T c));
+POISON_CCTYPE (int std::ispunct (T c));
+POISON_CCTYPE (int isspace (T c));
+POISON_CCTYPE (int std::isspace (T c));
+/* Disabled: int isupper (T c). */
+POISON_CCTYPE (int std::isupper (T c));
+POISON_CCTYPE (int isxdigit (T c));
+POISON_CCTYPE (int std::isxdigit (T c));
+POISON_CCTYPE (int tolower (T c));
+POISON_CCTYPE (int std::tolower (T c));
+/* Disabled: int toupper (T c). */
+POISON_CCTYPE (int std::toupper (T c));
+
+#undef POISON_CCTYPE
+#endif
+
#endif /* GDBSUPPORT_POISON_H */
base-commit: efc26507d9998eef6dc0b17480e0d921f40958c1
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [gdbsupport] Poison ctype.h / cctype functions
2026-03-22 16:03 [PATCH] [gdbsupport] Poison ctype.h / cctype functions Tom de Vries
@ 2026-03-23 14:17 ` Tom Tromey
2026-03-24 9:05 ` Tom de Vries
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Tom Tromey @ 2026-03-23 14:17 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> GDB generally uses c_isprint instead of isprint or std::isprint [1].
Tom> Poison uses of ctype.h / cctype functions in gdbsupport/poison.h.
Tom> This excludes isupper, islower and toupper because they're currently used in
Tom> GDB. Add a fixme to find out whether these exceptions are ok, and if so
Tom> document why, otherwise fix them.
Tom> +#define POISON_CCTYPE(F) \
Tom> + template<typename T> \
Tom> + F \
Tom> + { \
Tom> + static_assert (false, "Please use gnulib's c-ctype.h"); \
Tom> + return 0; \
Tom> + }
Tom> +
Tom> +/* Poisoning of some functions is disabled:
Tom> + - isupper, because it's used in ada_decode.
This is just an oversight.
Tom> + - islower and toupper, because they're used in UNCTRL from readline,
Tom> + which is used in tui_redisplay_readline and gdb_fnprint.
Can't really touch readline but we could write our own UNCTRL variant.
Tom> +POISON_CCTYPE (int isalnum (T c));
Tom> +POISON_CCTYPE (int std::isalnum (T c));
I suspect redefining standard functions like this is not allowed in C++.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [gdbsupport] Poison ctype.h / cctype functions
2026-03-23 14:17 ` Tom Tromey
@ 2026-03-24 9:05 ` Tom de Vries
2026-03-24 13:28 ` Tom de Vries
2026-03-24 13:55 ` Tom de Vries
2 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-03-24 9:05 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 3/23/26 3:17 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> GDB generally uses c_isprint instead of isprint or std::isprint [1].
> Tom> Poison uses of ctype.h / cctype functions in gdbsupport/poison.h.
>
> Tom> This excludes isupper, islower and toupper because they're currently used in
> Tom> GDB. Add a fixme to find out whether these exceptions are ok, and if so
> Tom> document why, otherwise fix them.
>
> Tom> +#define POISON_CCTYPE(F) \
> Tom> + template<typename T> \
> Tom> + F \
> Tom> + { \
> Tom> + static_assert (false, "Please use gnulib's c-ctype.h"); \
> Tom> + return 0; \
> Tom> + }
> Tom> +
> Tom> +/* Poisoning of some functions is disabled:
> Tom> + - isupper, because it's used in ada_decode.
>
> This is just an oversight.
>
I've submitted a patch for this (
https://sourceware.org/pipermail/gdb-patches/2026-March/226148.html ).
Thanks,
- Tom
> Tom> + - islower and toupper, because they're used in UNCTRL from readline,
> Tom> + which is used in tui_redisplay_readline and gdb_fnprint.
>
> Can't really touch readline but we could write our own UNCTRL variant.
>
> Tom> +POISON_CCTYPE (int isalnum (T c));
> Tom> +POISON_CCTYPE (int std::isalnum (T c));
>
> I suspect redefining standard functions like this is not allowed in C++.
>
> Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [gdbsupport] Poison ctype.h / cctype functions
2026-03-23 14:17 ` Tom Tromey
2026-03-24 9:05 ` Tom de Vries
@ 2026-03-24 13:28 ` Tom de Vries
2026-03-24 13:55 ` Tom de Vries
2 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-03-24 13:28 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 3/23/26 3:17 PM, Tom Tromey wrote:
> Tom> + - islower and toupper, because they're used in UNCTRL from readline,
> Tom> + which is used in tui_redisplay_readline and gdb_fnprint.
>
> Can't really touch readline but we could write our own UNCTRL variant.
I've given that a try (
https://sourceware.org/pipermail/gdb-patches/2026-March/226171.html ).
Thanks,
- Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [gdbsupport] Poison ctype.h / cctype functions
2026-03-23 14:17 ` Tom Tromey
2026-03-24 9:05 ` Tom de Vries
2026-03-24 13:28 ` Tom de Vries
@ 2026-03-24 13:55 ` Tom de Vries
2026-03-24 14:42 ` Tom Tromey
2 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2026-03-24 13:55 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 3/23/26 3:17 PM, Tom Tromey wrote:
> Tom> +POISON_CCTYPE (int isalnum (T c));
> Tom> +POISON_CCTYPE (int std::isalnum (T c));
>
> I suspect redefining standard functions like this is not allowed in C++.
That's a pity.
Then automatically checking this falls in the domain of precommit
checkers. Maybe I could extend check-gnu-style to include this (though
this isn't really a GNU style thing I suppose).
Thanks,
- Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [gdbsupport] Poison ctype.h / cctype functions
2026-03-24 13:55 ` Tom de Vries
@ 2026-03-24 14:42 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2026-03-24 14:42 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> On 3/23/26 3:17 PM, Tom Tromey wrote:
Tom> +POISON_CCTYPE (int isalnum (T c));
Tom> +POISON_CCTYPE (int std::isalnum (T c));
>> I suspect redefining standard functions like this is not allowed in
>> C++.
Tom> That's a pity.
Tom> Then automatically checking this falls in the domain of precommit
Tom> checkers. Maybe I could extend check-gnu-style to include this
Tom> (though this isn't really a GNU style thing I suppose).
Yeah. I considered adding a checker to avoid includes of <ctype.h>
but that doesn't actually prevent the use of these things, because they
can be made visible via other includes anyway.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-24 14:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-22 16:03 [PATCH] [gdbsupport] Poison ctype.h / cctype functions Tom de Vries
2026-03-23 14:17 ` Tom Tromey
2026-03-24 9:05 ` Tom de Vries
2026-03-24 13:28 ` Tom de Vries
2026-03-24 13:55 ` Tom de Vries
2026-03-24 14:42 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox