* [PATCH] [gdb/tdep] Eliminate ostringstream use from arc_check_tdesc_feature
@ 2026-03-22 6:58 Tom de Vries
2026-03-22 14:41 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-03-22 6:58 UTC (permalink / raw)
To: gdb-patches
We generally avoid C++ streams in GDB sources [1].
Remove an instance of std::ostringstream in arc_check_tdesc_feature.
While we're at it, fix an array index bug:
...
- reg_names << " or '" << reg.names[0] << "'";
+ string_appendf (reg_names, " or '%s'", reg.names[i]);
...
Tested on x86_64-linux, using a trigger patch:
...
- if (!found && reg.required_p)
+ if (true || (!found && reg.required_p))
...
and doing "maint selftest" and observing the output:
...
Running selftest unpack_field_as_long::ARC600.
Error: Cannot find required register(s) 'r0' in feature 'org.gnu.gdb.arc.core'.
Error: Cannot find required register(s) 'pc' in feature 'org.gnu.gdb.arc.aux'.
...
[1] https://sourceware.org/pipermail/gdb-patches/2026-March/226117.html
---
gdb/arc-tdep.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index ff283014e52..4936a5c8fbb 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -44,7 +44,6 @@
/* Standard headers. */
#include <algorithm>
-#include <sstream>
/* The frame unwind cache for ARC. */
@@ -2100,16 +2099,16 @@ arc_check_tdesc_feature (struct tdesc_arch_data *tdesc_data,
if (!found && reg.required_p)
{
- std::ostringstream reg_names;
+ std::string reg_names;
for (std::size_t i = 0; i < reg.names.size(); ++i)
{
if (i == 0)
- reg_names << "'" << reg.names[0] << "'";
+ string_appendf (reg_names, "'%s'", reg.names[0]);
else
- reg_names << " or '" << reg.names[0] << "'";
+ string_appendf (reg_names, " or '%s'", reg.names[i]);
}
arc_print (_("Error: Cannot find required register(s) %s "
- "in feature '%s'.\n"), reg_names.str ().c_str (),
+ "in feature '%s'.\n"), reg_names.c_str (),
feature->name.c_str ());
return false;
}
base-commit: d1cb5bd656a253cd69dbcd096f21f658cda697c7
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] [gdb/tdep] Eliminate ostringstream use from arc_check_tdesc_feature
2026-03-22 6:58 [PATCH] [gdb/tdep] Eliminate ostringstream use from arc_check_tdesc_feature Tom de Vries
@ 2026-03-22 14:41 ` Simon Marchi
2026-03-22 16:10 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-03-22 14:41 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 3/22/26 2:58 AM, Tom de Vries wrote:
> We generally avoid C++ streams in GDB sources [1].
>
> Remove an instance of std::ostringstream in arc_check_tdesc_feature.
>
> While we're at it, fix an array index bug:
> ...
> - reg_names << " or '" << reg.names[0] << "'";
> + string_appendf (reg_names, " or '%s'", reg.names[i]);
> ...
>
> Tested on x86_64-linux, using a trigger patch:
> ...
> - if (!found && reg.required_p)
> + if (true || (!found && reg.required_p))
> ...
> and doing "maint selftest" and observing the output:
> ...
> Running selftest unpack_field_as_long::ARC600.
> Error: Cannot find required register(s) 'r0' in feature 'org.gnu.gdb.arc.core'.
> Error: Cannot find required register(s) 'pc' in feature 'org.gnu.gdb.arc.aux'.
> ...
>
> [1] https://sourceware.org/pipermail/gdb-patches/2026-March/226117.html
> ---
> gdb/arc-tdep.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
> index ff283014e52..4936a5c8fbb 100644
> --- a/gdb/arc-tdep.c
> +++ b/gdb/arc-tdep.c
> @@ -44,7 +44,6 @@
>
> /* Standard headers. */
> #include <algorithm>
> -#include <sstream>
>
> /* The frame unwind cache for ARC. */
>
> @@ -2100,16 +2099,16 @@ arc_check_tdesc_feature (struct tdesc_arch_data *tdesc_data,
>
> if (!found && reg.required_p)
> {
> - std::ostringstream reg_names;
> + std::string reg_names;
> for (std::size_t i = 0; i < reg.names.size(); ++i)
> {
> if (i == 0)
> - reg_names << "'" << reg.names[0] << "'";
> + string_appendf (reg_names, "'%s'", reg.names[0]);
> else
> - reg_names << " or '" << reg.names[0] << "'";
> + string_appendf (reg_names, " or '%s'", reg.names[i]);
Looks like you fixed a bug here (0 -> i).
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] [gdb/tdep] Eliminate ostringstream use from arc_check_tdesc_feature
2026-03-22 14:41 ` Simon Marchi
@ 2026-03-22 16:10 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-03-22 16:10 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 3/22/26 3:41 PM, Simon Marchi wrote:
> On 3/22/26 2:58 AM, Tom de Vries wrote:
>> We generally avoid C++ streams in GDB sources [1].
>>
>> Remove an instance of std::ostringstream in arc_check_tdesc_feature.
>>
>> While we're at it, fix an array index bug:
>> ...
>> - reg_names << " or '" << reg.names[0] << "'";
>> + string_appendf (reg_names, " or '%s'", reg.names[i]);
>> ...
>>
>> Tested on x86_64-linux, using a trigger patch:
>> ...
>> - if (!found && reg.required_p)
>> + if (true || (!found && reg.required_p))
>> ...
>> and doing "maint selftest" and observing the output:
>> ...
>> Running selftest unpack_field_as_long::ARC600.
>> Error: Cannot find required register(s) 'r0' in feature 'org.gnu.gdb.arc.core'.
>> Error: Cannot find required register(s) 'pc' in feature 'org.gnu.gdb.arc.aux'.
>> ...
>>
>> [1] https://sourceware.org/pipermail/gdb-patches/2026-March/226117.html
>> ---
>> gdb/arc-tdep.c | 9 ++++-----
>> 1 file changed, 4 insertions(+), 5 deletions(-)
>>
>> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
>> index ff283014e52..4936a5c8fbb 100644
>> --- a/gdb/arc-tdep.c
>> +++ b/gdb/arc-tdep.c
>> @@ -44,7 +44,6 @@
>>
>> /* Standard headers. */
>> #include <algorithm>
>> -#include <sstream>
>>
>> /* The frame unwind cache for ARC. */
>>
>> @@ -2100,16 +2099,16 @@ arc_check_tdesc_feature (struct tdesc_arch_data *tdesc_data,
>>
>> if (!found && reg.required_p)
>> {
>> - std::ostringstream reg_names;
>> + std::string reg_names;
>> for (std::size_t i = 0; i < reg.names.size(); ++i)
>> {
>> if (i == 0)
>> - reg_names << "'" << reg.names[0] << "'";
>> + string_appendf (reg_names, "'%s'", reg.names[0]);
>> else
>> - reg_names << " or '" << reg.names[0] << "'";
>> + string_appendf (reg_names, " or '%s'", reg.names[i]);
>
Hi Simon,
thanks for the review.
> Looks like you fixed a bug here (0 -> i).
Yes, that's what I meant by "fix an array index bug".
Thanks,
- Tom
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
> Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-22 16:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-22 6:58 [PATCH] [gdb/tdep] Eliminate ostringstream use from arc_check_tdesc_feature Tom de Vries
2026-03-22 14:41 ` Simon Marchi
2026-03-22 16:10 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox