From: Simon Marchi <simark@simark.ca>
To: Jan Vrany <jan.vrany@labware.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdb: allocate blockvector on heap
Date: Tue, 14 Oct 2025 14:41:32 -0400 [thread overview]
Message-ID: <4178904d-9d3e-406d-9446-9ca2ce8b4a8d@simark.ca> (raw)
In-Reply-To: <20251013182318.1045138-2-jan.vrany@labware.com>
On 10/13/25 2:23 PM, Jan Vrany wrote:
> This patch changes blockvector to be allocated on the heap, using
> 'new'.
>
> The code is little awkward since blockvector uses flexible array member
> to hold on blocks. So in order to make it working, this commit overloads
> 'new' and 'delete' operators to take the number of blocks as parameter
> and allocates/deallocates memory using std::malloc and std::free.
> This will go away in following commit that will change blockvector to
> use std::vector rather than flexible array member.
It's already written, so if it works, I don't mind, but otherwise I
think you could have made the switch to 'new' and to std::vector in the
same patch, since they are not very large changes.
> ---
> gdb/block.h | 18 ++++++++++++++++++
> gdb/buildsym.c | 5 +----
> gdb/jit.c | 8 +-------
> gdb/mdebugread.c | 38 +++++++++++---------------------------
> 4 files changed, 31 insertions(+), 38 deletions(-)
>
> diff --git a/gdb/block.h b/gdb/block.h
> index 8a3ea822d04..d1ca41d7482 100644
> --- a/gdb/block.h
> +++ b/gdb/block.h
> @@ -420,6 +420,24 @@ struct global_block : public block
>
> struct blockvector
> {
> + void *operator new (size_t size, size_t num_blocks)
> + {
> + size_t size_in_bytes = size + (num_blocks - 1) * (sizeof (struct block *));
> + return std::malloc (size_in_bytes);
> + }
> +
> + void operator delete (void *memory)
> + {
> + std::free (memory);
> + }
> +
> + blockvector (int nblocks)
explicit
> + : m_map (nullptr),
Can you initialize m_map inline?
addrmap_fixed *m_map = nullptr;
Otherwise, LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
next prev parent reply other threads:[~2025-10-14 18:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 18:23 [PATCH 0/2] use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-10-13 18:23 ` [PATCH 1/2] gdb: allocate blockvector on heap Jan Vrany
2025-10-14 18:41 ` Simon Marchi [this message]
2025-10-13 18:23 ` [PATCH 2/2] gdb: use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-10-14 15:00 ` Andrew Burgess
2025-10-14 19:41 ` Simon Marchi
2025-10-15 21:34 ` Jan Vraný
2025-10-14 19:29 ` Simon Marchi
2025-10-14 20:05 ` Tom Tromey
2025-10-14 20:19 ` Simon Marchi
2025-10-14 20:40 ` Jan Vraný
2025-10-15 2:00 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4178904d-9d3e-406d-9446-9ca2ce8b4a8d@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=jan.vrany@labware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox