Re: [PATCH 16/43] Simplify dwarf_expr_context class interface

Simon Marchi via Gdb-patches
2021-04-28T14:41:25Z

>>> diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h
>>> index a0ac21f2ed1..d1374068732 100644
>>> --- a/gdb/dwarf2/expr.h
>>> +++ b/gdb/dwarf2/expr.h
>>> @@ -119,19 +119,30 @@ struct dwarf_stack_value
>>> its current state and its callbacks. */
>>> struct dwarf_expr_context
>>> {
>>> - dwarf_expr_context (dwarf2_per_objfile *per_objfile);
>>> + /* We should ever only pass in the PER_OBJFILE, while the ADDR_SIZE
>>> + information should be retrievable from there. The PER_OBJFILE
>>> + contains a pointer to the PER_BFD information anyway and the
>>> + address size information must be the same for the whole BFD. */
>>> + dwarf_expr_context (struct dwarf2_per_objfile *per_objfile,
>>> + int addr_size);
>>
>> I don't really understand the comment. What do you mean by "We should
>> ever only pass..."? In general, I don't find that the comment helps me
>> understand what the parameters are and do. Try to change it to be more
>> concrete and straight to the point.
>
> This was more me venting about that particular design choice

Haha, it indeed did feel this way.

> because the reality is that an address size has to be consistent with what is defined in the original object file but there is no interface to always get it in a clean way in gdb.

In this case, it looks like it's because an expression can come from a
DIE attribute, directly linked to a CU. So the address size comes from
that CU's header. And at other times, the expression comes from a frame
description entry (FDE) / common information entry (CIE), so the address
size comes from that CIE's header. So I don't see any other easy way than
making the caller provide it.

> It makes sense for me to remove that comment altogether in the next iteration and thing about a future change that would clean it up.

Ok. Or, just make a simple comment. You could say that ADDRESS_SIZE is
the address size coming from the CU's header or the CIE's header,
depending on the context.

Anyway, this is all perhaps subject to change if I understand correctly.
In the end do you still expose a class, or just one function, to
evaluate a DWARF expression?

Simon