* [PATCH] gdb: add an assert to cmd_list_element constructor
@ 2025-04-13 13:08 Andrew Burgess
2025-04-13 13:48 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2025-04-13 13:08 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
The cmd_list_element::doc variable must be non-nullptr, otherwise, in
`help_cmd` (cli/cli-decode.c), we will trigger an assert when we run
one of these lines:
gdb_puts (c->doc, stream);
or,
gdb_puts (alias->doc, stream);
as gdb_puts requires that the first argument (the doc string) be
non-nullptr.
Better, I think, to assert when the cmd_list_element is created,
rather than catching an assert later when 'help CMD' is used.
I only ran into this case when messing with the Python API command
creation code, I accidentally created a command with a nullptr doc
string, and only found out when I ran 'help CMD' and got an
assertion.
Built and tested on x86-64 GNU/Linux with an all-targets build; I
don't see any regressions, so (I hope) there are no commands that
currently violate this assertion.
---
gdb/cli/cli-decode.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 217afbc8ca7..673cf6518d3 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -62,6 +62,7 @@ struct cmd_list_element
type (not_set_cmd),
doc (doc_)
{
+ gdb_assert (doc != nullptr);
memset (&function, 0, sizeof (function));
}
base-commit: 33d5188ab101bf414c9950ba914a128d08166105
--
2.47.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: add an assert to cmd_list_element constructor
2025-04-13 13:08 [PATCH] gdb: add an assert to cmd_list_element constructor Andrew Burgess
@ 2025-04-13 13:48 ` Simon Marchi
2025-04-14 8:30 ` Andrew Burgess
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2025-04-13 13:48 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
On 2025-04-13 09:08, Andrew Burgess wrote:
> The cmd_list_element::doc variable must be non-nullptr, otherwise, in
> `help_cmd` (cli/cli-decode.c), we will trigger an assert when we run
> one of these lines:
>
> gdb_puts (c->doc, stream);
>
> or,
>
> gdb_puts (alias->doc, stream);
>
> as gdb_puts requires that the first argument (the doc string) be
> non-nullptr.
>
> Better, I think, to assert when the cmd_list_element is created,
> rather than catching an assert later when 'help CMD' is used.
>
> I only ran into this case when messing with the Python API command
> creation code, I accidentally created a command with a nullptr doc
> string, and only found out when I ran 'help CMD' and got an
> assertion.
>
> Built and tested on x86-64 GNU/Linux with an all-targets build; I
> don't see any regressions, so (I hope) there are no commands that
> currently violate this assertion.
> ---
> gdb/cli/cli-decode.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
> index 217afbc8ca7..673cf6518d3 100644
> --- a/gdb/cli/cli-decode.h
> +++ b/gdb/cli/cli-decode.h
> @@ -62,6 +62,7 @@ struct cmd_list_element
> type (not_set_cmd),
> doc (doc_)
> {
> + gdb_assert (doc != nullptr);
> memset (&function, 0, sizeof (function));
> }
>
>
> base-commit: 33d5188ab101bf414c9950ba914a128d08166105
Would it make sense to add an assert that `name` isn't nullptr at the
same time?
LGTM in any case.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: add an assert to cmd_list_element constructor
2025-04-13 13:48 ` Simon Marchi
@ 2025-04-14 8:30 ` Andrew Burgess
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2025-04-14 8:30 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
Simon Marchi <simark@simark.ca> writes:
> On 2025-04-13 09:08, Andrew Burgess wrote:
>> The cmd_list_element::doc variable must be non-nullptr, otherwise, in
>> `help_cmd` (cli/cli-decode.c), we will trigger an assert when we run
>> one of these lines:
>>
>> gdb_puts (c->doc, stream);
>>
>> or,
>>
>> gdb_puts (alias->doc, stream);
>>
>> as gdb_puts requires that the first argument (the doc string) be
>> non-nullptr.
>>
>> Better, I think, to assert when the cmd_list_element is created,
>> rather than catching an assert later when 'help CMD' is used.
>>
>> I only ran into this case when messing with the Python API command
>> creation code, I accidentally created a command with a nullptr doc
>> string, and only found out when I ran 'help CMD' and got an
>> assertion.
>>
>> Built and tested on x86-64 GNU/Linux with an all-targets build; I
>> don't see any regressions, so (I hope) there are no commands that
>> currently violate this assertion.
>> ---
>> gdb/cli/cli-decode.h | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
>> index 217afbc8ca7..673cf6518d3 100644
>> --- a/gdb/cli/cli-decode.h
>> +++ b/gdb/cli/cli-decode.h
>> @@ -62,6 +62,7 @@ struct cmd_list_element
>> type (not_set_cmd),
>> doc (doc_)
>> {
>> + gdb_assert (doc != nullptr);
>> memset (&function, 0, sizeof (function));
>> }
>>
>>
>> base-commit: 33d5188ab101bf414c9950ba914a128d08166105
>
> Would it make sense to add an assert that `name` isn't nullptr at the
> same time?
Good idea. I've added this assert, and (after some testing) pushed the
patch.
Thanks,
Andrew
>
> LGTM in any case.
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-14 8:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-13 13:08 [PATCH] gdb: add an assert to cmd_list_element constructor Andrew Burgess
2025-04-13 13:48 ` Simon Marchi
2025-04-14 8:30 ` Andrew Burgess
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox