[PATCH 2/2] gdb: change functions returning value contents to use gdb::array_view

Simon Marchi simon.marchi@polymtl.ca
Mon Oct 25 18:52:28 GMT 2021



On 2021-10-25 14:47, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> The bug fixed by this [1] patch was caused by an out-of-bounds access to
> Simon> a value's content.  The code gets the value's content (just a pointer)
> Simon> and then indexes it with a non-sensical index.
> 
> Simon> This made me think of changing functions that return value contents to
> Simon> return array_views instead of a plain pointer.  This has the advantage
> Simon> that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view
> Simon> are checked, making bugs more apparent / easier to find.
> 
> Simon> This patch changes the return types of these functions, and updates
> Simon> callers to call .data() on the result, meaning it's not changing
> Simon> anything in practice.  Additional work will be needed (which can be done
> Simon> little by little) to make callers propagate the use of array_view and
> Simon> reap the benefits.
> 
> At first I was a bit meh on this proposal, but it seems to me that you
> are right -- we can incrementally improve the callers -- and also that
> new calls will also probably benefit.  So I think it is good.
> 
> Tom
> 

Ok, thanks.  I'm always super keen on adding infrastructure that let us add more
consistency checks.

Simon


More information about the Gdb-patches mailing list