Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simon.marchi@efficios.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/dwarf: fix order of operations when reading .debug_names
Date: Wed, 20 May 2026 11:38:56 -0400	[thread overview]
Message-ID: <23229f43-fbb7-4138-a4ab-26946c124744@polymtl.ca> (raw)
In-Reply-To: <87zf1u9kok.fsf@tromey.com>



On 2026-05-20 11:15, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon>  - calls to the build_and_check_* functions, which do some lookups in
> Simon>    the all_units vector, requiring it to be sorted (oops)
> 
> I wonder if either there's some way to assert that the vector must be
> sorted on entry, or if there's a way to have a self-sorting data type
> here, rendering this kind of bug impossible.

assert: in dwarf2_find_unit, we could check that the vector is sorted,
but that would replicate the check done by -D_GLIBCXX_DEBUG.  I'm not
sure we want to pay this price for every dwarf2_find_unit call in
production binaries.

Alternatively, we could maintain a flag that says "is all_units
currently sorted", clear that flag when doing any modification to the
vector, and set it in the sort_all_units method.  All modifications to
the vector should be done through methods to ensure the flag gets
cleared.  I think that would be cheap enough to implement, I'll give it
a try.

self-sorting data type: we could insert the new units at the right place
from the start, but that would be less efficient, because that would be
akin to an insertion sort.  It's more efficient to do one sort at the
end.

We could perhaps use std::set, but there is also the case in
fill_in_sig_entry_from_dwo_file, when the section of a unit becomes
known at a later time.  At this point, the key for the unit would
change, so we would still need to remove it and reinsert it in the set.
I don't see a way to enforce that automatically.

> Anyway I think this is ok.
> Approved-By: Tom Tromey <tom@tromey.com>

Thanks, I'll push it and work on a patch to add the assert.

Simon

      reply	other threads:[~2026-05-20 15:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 20:09 Simon Marchi
2026-05-20 15:15 ` Tom Tromey
2026-05-20 15:38   ` Simon Marchi [this message]

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=23229f43-fbb7-4138-a4ab-26946c124744@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=tom@tromey.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