Files
binutils-gdb/gdbsupport
Simon Marchi bd21dd6807 gdbsupport: remove xmalloc in format_pieces
Remove the use of xmalloc (and the arbitrary allocation size) in
format_pieces.  This turned out a bit more involved than expected, but
not too bad.

format_pieces::m_storage is a buffer with multiple concatenated
null-terminated strings, referenced by format_piece::string.  Change
this to an std::string, while keeping its purpose (use the std::string
as a buffer with embedded null characters).

However, because the std::string's internal buffer can be reallocated as
it grows, and I do not want to hardcode a big reserved size like we have
now, it's not possible to store the direct pointer to the string in
format_piece::string.  Those pointers would become stale as the buffer
gets reallocated.  Therefore, change format_piece to hold an index into
the storage instead.  Add format_pieces::piece_str for the callers to be
able to access the piece's string.  This requires changing the few
callers, but in a trivial way.

The selftest also needs to be updated.  I want to keep the test cases
as-is, where the expected pieces contain the expected string, and not
hard-code an expected index.  To achieve this, add the
expected_format_piece structure.  Note that the previous
format_piece::operator== didn't compare the n_int_args fields, while the
test provides expected values for that field.  I guess that was a
mistake.  The new code checks it, and the test still passes.

Change-Id: I80630ff60e01c8caaa800ae22f69a9a7660bc9e9
Reviewed-By: Keith Seitz <keiths@redhat.com>
2025-09-15 10:40:52 -04:00
..
2024-11-23 12:40:36 +01:00
2025-04-08 10:54:39 -06:00
2025-04-08 10:54:39 -06:00
2025-08-19 20:34:03 -04:00
2025-08-19 20:34:03 -04:00
2025-04-08 10:54:39 -06:00
2025-04-08 10:54:39 -06:00
2025-05-29 11:13:08 -04:00
2025-04-08 10:54:39 -06:00
2025-04-08 10:54:39 -06:00
2025-03-12 14:23:50 -06:00
2025-04-08 10:54:39 -06:00

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.