Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Zoran Zaric via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH 15/43] Make DWARF evaluator return a single struct value
Date: Wed, 28 Apr 2021 12:47:48 +0100	[thread overview]
Message-ID: <320722e8-79e8-1890-bda8-bccf57ad52a3@amd.com> (raw)
In-Reply-To: <bdb2a907-cb8a-056d-9640-20bfac743679@polymtl.ca>



On 4/28/21 3:21 AM, Simon Marchi wrote:
> [CAUTION: External Email]
> 
>> @@ -886,6 +887,162 @@ dwarf_expr_context::push_dwarf_reg_entry_value
>>     this->eval (data_src, size);
>>   }
>>
>> +/* See expr.h.  */
>> +
>> +struct value *
>> +dwarf_expr_context::fetch_result (struct type *type,
>> +                               struct type *subobj_type,
>> +                               LONGEST subobj_offset)
>> +{
>> +  struct value *retval = nullptr;
>> +
>> +  if (type == nullptr)
>> +    type = address_type ();
>> +
>> +  if (subobj_type == nullptr)
>> +    subobj_type = type;
>> +
>> +  if (this->pieces.size () > 0)
>> +    {
>> +      struct piece_closure *c;
> 
> You can move this to where it's first initialized (and drop the struct
> keyword).
> 
>> +      ULONGEST bit_size = 0;
>> +
>> +      for (dwarf_expr_piece &piece : this->pieces)
>> +     bit_size += piece.size;
>> +      /* Complain if the expression is larger than the size of the
>> +      outer type.  */
>> +      if (bit_size > 8 * TYPE_LENGTH (type))
>> +     invalid_synthetic_pointer ();
>> +
>> +      c = allocate_piece_closure (this->per_cu, this->per_objfile,
>> +                               std::move (this->pieces), this->frame);
>> +      retval = allocate_computed_value (subobj_type,
>> +                                     &pieced_value_funcs, c);
>> +      set_value_offset (retval, subobj_offset);
>> +    }
>> +  else
>> +    {
>> +      switch (this->location)
>> +     {
>> +     case DWARF_VALUE_REGISTER:
>> +       {
>> +         int dwarf_regnum
>> +           = longest_to_int (value_as_long (this->fetch (0)));
>> +         int gdb_regnum = dwarf_reg_to_regnum_or_error (this->gdbarch,
>> +                                                        dwarf_regnum);
>> +
>> +         if (subobj_offset != 0)
>> +           error (_("cannot use offset on synthetic pointer to register"));
>> +
>> +         gdb_assert (this->frame != NULL);
>> +
>> +         retval = value_from_register (subobj_type, gdb_regnum,
>> +                                       this->frame);
>> +         if (value_optimized_out (retval))
>> +           {
>> +             struct value *tmp;
>> +
>> +             /* This means the register has undefined value / was
>> +                not saved.  As we're computing the location of some
>> +                variable etc. in the program, not a value for
>> +                inspecting a register ($pc, $sp, etc.), return a
>> +                generic optimized out value instead, so that we show
>> +                <optimized out> instead of <not saved>.  */
>> +             tmp = allocate_value (subobj_type);
>> +             value_contents_copy (tmp, 0, retval, 0,
>> +                                  TYPE_LENGTH (subobj_type));
>> +             retval = tmp;
>> +           }
>> +       }
>> +       break;
>> +
>> +     case DWARF_VALUE_MEMORY:
>> +       {
>> +         struct type *ptr_type;
>> +         CORE_ADDR address = this->fetch_address (0);
>> +         bool in_stack_memory = this->fetch_in_stack_memory (0);
>> +
>> +         /* DW_OP_deref_size (and possibly other operations too) may
>> +            create a pointer instead of an address.  Ideally, the
>> +            pointer to address conversion would be performed as part
>> +            of those operations, but the type of the object to
>> +            which the address refers is not known at the time of
>> +            the operation.  Therefore, we do the conversion here
>> +            since the type is readily available.  */
>> +
>> +         switch (subobj_type->code ())
>> +           {
>> +             case TYPE_CODE_FUNC:
>> +             case TYPE_CODE_METHOD:
>> +               ptr_type = builtin_type (this->gdbarch)->builtin_func_ptr;
>> +               break;
>> +             default:
>> +               ptr_type = builtin_type (this->gdbarch)->builtin_data_ptr;
>> +               break;
>> +           }
>> +         address = value_as_address (value_from_pointer (ptr_type, address));
>> +
>> +         retval = value_at_lazy (subobj_type,
>> +                                 address + subobj_offset);
>> +         if (in_stack_memory)
>> +           set_value_stack (retval, 1);
>> +       }
>> +       break;
>> +
>> +     case DWARF_VALUE_STACK:
>> +       {
>> +         struct value *value = this->fetch (0);
>> +         size_t n = TYPE_LENGTH (value_type (value));
>> +         size_t len = TYPE_LENGTH (subobj_type);
>> +         size_t max = TYPE_LENGTH (type);
>> +
>> +         if (subobj_offset + len > max)
>> +           invalid_synthetic_pointer ();
>> +
>> +         retval = allocate_value (subobj_type);
>> +
>> +         /* The given offset is relative to the actual object.  */
>> +         if (gdbarch_byte_order (this->gdbarch) == BFD_ENDIAN_BIG)
>> +           subobj_offset += n - max;
>> +
>> +         memcpy (value_contents_raw (retval),
>> +                 value_contents_all (value) + subobj_offset, len);
>> +       }
>> +       break;
>> +
>> +     case DWARF_VALUE_LITERAL:
>> +       {
>> +         bfd_byte *contents;
> 
> Same here, declare where initialized.
> 
>> +         size_t n = TYPE_LENGTH (subobj_type);
>> +
>> +         if (subobj_offset + n > this->len)
>> +           invalid_synthetic_pointer ();
>> +
>> +         retval = allocate_value (subobj_type);
>> +         contents = value_contents_raw (retval);
>> +         memcpy (contents, this->data + subobj_offset, n);
>> +       }
>> +       break;
>> +
>> +     case DWARF_VALUE_OPTIMIZED_OUT:
>> +       retval = allocate_optimized_out_value (subobj_type);
>> +       break;
>> +
>> +       /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
>> +          operation by execute_stack_op.  */
>> +     case DWARF_VALUE_IMPLICIT_POINTER:
>> +       /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
>> +          it can only be encountered when making a piece.  */
>> +     default:
>> +       internal_error (__FILE__, __LINE__, _("invalid location type"));
> 
> You could change this to use gdb_assert_not_reached.
> 
>> @@ -1479,155 +1481,15 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
>>        throw;
>>       }
>>
>> -  if (ctx.pieces.size () > 0)
>> -    {
>> -      struct piece_closure *c;
>> -      ULONGEST bit_size = 0;
>> -
>> -      for (dwarf_expr_piece &piece : ctx.pieces)
>> -     bit_size += piece.size;
>> -      /* Complain if the expression is larger than the size of the
>> -      outer type.  */
>> -      if (bit_size > 8 * TYPE_LENGTH (type))
>> -     invalid_synthetic_pointer ();
>> -
>> -      c = allocate_piece_closure (per_cu, per_objfile, std::move (ctx.pieces),
>> -                               frame);
>> -      /* We must clean up the value chain after creating the piece
>> -      closure but before allocating the result.  */
>> -      free_values.free_to_mark ();
>> -      retval = allocate_computed_value (subobj_type,
>> -                                     &pieced_value_funcs, c);
>> -      set_value_offset (retval, subobj_byte_offset);
>> -    }
>> -  else
>> -    {
>> -      switch (ctx.location)
>> -     {
>> -     case DWARF_VALUE_REGISTER:
>> -       {
>> -         struct gdbarch *arch = get_frame_arch (frame);
>> -         int dwarf_regnum
>> -           = longest_to_int (value_as_long (ctx.fetch (0)));
>> -         int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, dwarf_regnum);
>> -
>> -         if (subobj_byte_offset != 0)
>> -           error (_("cannot use offset on synthetic pointer to register"));
>> -         free_values.free_to_mark ();
>> -         retval = value_from_register (subobj_type, gdb_regnum, frame);
>> -         if (value_optimized_out (retval))
>> -           {
>> -             struct value *tmp;
>> -
>> -             /* This means the register has undefined value / was
>> -                not saved.  As we're computing the location of some
>> -                variable etc. in the program, not a value for
>> -                inspecting a register ($pc, $sp, etc.), return a
>> -                generic optimized out value instead, so that we show
>> -                <optimized out> instead of <not saved>.  */
>> -             tmp = allocate_value (subobj_type);
>> -             value_contents_copy (tmp, 0, retval, 0,
>> -                                  TYPE_LENGTH (subobj_type));
>> -             retval = tmp;
>> -           }
>> -       }
>> -       break;
>> -
>> -     case DWARF_VALUE_MEMORY:
>> -       {
>> -         struct type *ptr_type;
>> -         CORE_ADDR address = ctx.fetch_address (0);
>> -         bool in_stack_memory = ctx.fetch_in_stack_memory (0);
>> -
>> -         /* DW_OP_deref_size (and possibly other operations too) may
>> -            create a pointer instead of an address.  Ideally, the
>> -            pointer to address conversion would be performed as part
>> -            of those operations, but the type of the object to
>> -            which the address refers is not known at the time of
>> -            the operation.  Therefore, we do the conversion here
>> -            since the type is readily available.  */
>> -
>> -         switch (subobj_type->code ())
>> -           {
>> -             case TYPE_CODE_FUNC:
>> -             case TYPE_CODE_METHOD:
>> -               ptr_type = builtin_type (ctx.gdbarch)->builtin_func_ptr;
>> -               break;
>> -             default:
>> -               ptr_type = builtin_type (ctx.gdbarch)->builtin_data_ptr;
>> -               break;
>> -           }
>> -         address = value_as_address (value_from_pointer (ptr_type, address));
>> -
>> -         free_values.free_to_mark ();
>> -         retval = value_at_lazy (subobj_type,
>> -                                 address + subobj_byte_offset);
>> -         if (in_stack_memory)
>> -           set_value_stack (retval, 1);
>> -       }
>> -       break;
>> -
>> -     case DWARF_VALUE_STACK:
>> -       {
>> -         struct value *value = ctx.fetch (0);
>> -         size_t n = TYPE_LENGTH (value_type (value));
>> -         size_t len = TYPE_LENGTH (subobj_type);
>> -         size_t max = TYPE_LENGTH (type);
>> -         gdbarch *objfile_gdbarch = per_objfile->objfile->arch ();
>> -
>> -         if (subobj_byte_offset + len > max)
>> -           invalid_synthetic_pointer ();
>> -
>> -         /* Preserve VALUE because we are going to free values back
>> -            to the mark, but we still need the value contents
>> -            below.  */
>> -         value_ref_ptr value_holder = value_ref_ptr::new_reference (value);
>> -         free_values.free_to_mark ();
>> -
>> -         retval = allocate_value (subobj_type);
>> -
>> -         /* The given offset is relative to the actual object.  */
>> -         if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
>> -           subobj_byte_offset += n - max;
>> -
>> -         memcpy (value_contents_raw (retval),
>> -                 value_contents_all (value) + subobj_byte_offset, len);
>> -       }
>> -       break;
>> -
>> -     case DWARF_VALUE_LITERAL:
>> -       {
>> -         bfd_byte *contents;
>> -         size_t n = TYPE_LENGTH (subobj_type);
>> -
>> -         if (subobj_byte_offset + n > ctx.len)
>> -           invalid_synthetic_pointer ();
>> -
>> -         free_values.free_to_mark ();
>> -         retval = allocate_value (subobj_type);
>> -         contents = value_contents_raw (retval);
>> -         memcpy (contents, ctx.data + subobj_byte_offset, n);
>> -       }
>> -       break;
>> -
>> -     case DWARF_VALUE_OPTIMIZED_OUT:
>> -       free_values.free_to_mark ();
>> -       retval = allocate_optimized_out_value (subobj_type);
>> -       break;
>> -
>> -       /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
>> -          operation by execute_stack_op.  */
>> -     case DWARF_VALUE_IMPLICIT_POINTER:
>> -       /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
>> -          it can only be encountered when making a piece.  */
>> -     default:
>> -       internal_error (__FILE__, __LINE__, _("invalid location type"));
>> -     }
>> -    }

I've just copied this whole block from the loc.c. Everything is replaced 
with a new implementation in the later patch.

Do you still feel that I need to clean it up here or it doesn't really 
matter considering the later patches?

>> -
>> -  set_value_initialized (retval, ctx.initialized);
>> +  /* We need to clean up all the values that are not needed any more.
>> +     The problem with a value_ref_ptr class is that it disconnects the
>> +     RETVAL from the value garbage collection, so we need to make
>> +     a copy of that value on the stack to keep everything consistent.
>> +     The value_ref_ptr will clean up after itself at the end of this block.  */
>> +  value_ref_ptr value_holder = value_ref_ptr::new_reference (retval);
>> +  free_values.free_to_mark ();
>>
>> -  return retval;
>> +  return value_copy(retval);
> 
> Missing space.
> 
> Simon
> 

Thanks, I will fix it in the next iteration.

Zoran

  reply	other threads:[~2021-04-28 11:48 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 14:45 [PATCH 00/43 V2] Allow location description on the DWARF stack Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 01/43] Replace the symbol needs evaluator with a parser Zoran Zaric via Gdb-patches
2021-04-27  1:20   ` Simon Marchi via Gdb-patches
2021-04-28 10:17     ` Zoran Zaric via Gdb-patches
2021-04-28 14:08       ` Simon Marchi via Gdb-patches
2021-04-28 15:02         ` Zoran Zaric via Gdb-patches
2021-04-28 15:31         ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 02/43] Cleanup of the dwarf_expr_context constructor Zoran Zaric via Gdb-patches
2021-04-27  1:23   ` Simon Marchi via Gdb-patches
2021-04-28 10:19     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 03/43] Move frame context info to dwarf_expr_context Zoran Zaric via Gdb-patches
2021-04-27  2:19   ` Simon Marchi via Gdb-patches
2021-04-28 10:51     ` Zoran Zaric via Gdb-patches
2021-04-28 14:14       ` Simon Marchi via Gdb-patches
2021-04-28 15:55         ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 04/43] Remove get_frame_cfa from dwarf_expr_context Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 05/43] Move compilation unit info to dwarf_expr_context Zoran Zaric via Gdb-patches
2021-04-27  2:58   ` Simon Marchi via Gdb-patches
2021-04-28 11:28     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 06/43] Move dwarf_call " Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 07/43] Move get_object_address " Zoran Zaric via Gdb-patches
2021-04-27  3:12   ` Simon Marchi via Gdb-patches
2021-04-28 11:34     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 08/43] Move read_mem " Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 09/43] Move push_dwarf_reg_entry_value to expr.c Zoran Zaric via Gdb-patches
2021-04-27  3:56   ` Simon Marchi via Gdb-patches
2021-04-28 11:36     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 10/43] Inline get_reg_value method of dwarf_expr_context Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 11/43] Remove empty frame and full evaluators Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 12/43] Merge evaluate_for_locexpr_baton evaluator Zoran Zaric via Gdb-patches
2021-04-28  1:33   ` Simon Marchi via Gdb-patches
2021-04-28 11:39     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 13/43] Move piece_closure and its support to expr.c Zoran Zaric via Gdb-patches
2021-04-28  1:56   ` Simon Marchi via Gdb-patches
2021-04-28 11:40     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 14/43] Make value_copy also copy the stack data member Zoran Zaric via Gdb-patches
2021-04-28  2:01   ` Simon Marchi via Gdb-patches
2021-04-28 11:43     ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 15/43] Make DWARF evaluator return a single struct value Zoran Zaric via Gdb-patches
2021-04-28  2:21   ` Simon Marchi via Gdb-patches
2021-04-28 11:47     ` Zoran Zaric via Gdb-patches [this message]
2021-04-28 14:24       ` Simon Marchi via Gdb-patches
2021-03-01 14:45 ` [PATCH 16/43] Simplify dwarf_expr_context class interface Zoran Zaric via Gdb-patches
2021-04-28  2:45   ` Simon Marchi via Gdb-patches
2021-04-28 13:15     ` Zoran Zaric via Gdb-patches
2021-04-28 14:41       ` Simon Marchi via Gdb-patches
2021-04-28 15:39         ` Zoran Zaric via Gdb-patches
2021-04-28 19:19           ` Simon Marchi via Gdb-patches
2021-04-29 15:49       ` Simon Marchi via Gdb-patches
2021-04-29 15:55         ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 17/43] Add as_lval argument to expression evaluator Zoran Zaric via Gdb-patches
2021-04-28  3:04   ` Simon Marchi via Gdb-patches
2021-04-28 13:16     ` Zoran Zaric via Gdb-patches
2021-04-28  3:30   ` Simon Marchi via Gdb-patches
2021-03-01 14:45 ` [PATCH 18/43] Add new register access interface to expr.c Zoran Zaric via Gdb-patches
2021-03-08 23:52   ` Lancelot SIX via Gdb-patches
2021-04-28  3:25   ` Simon Marchi via Gdb-patches
2021-04-28 13:29     ` Zoran Zaric via Gdb-patches
2021-04-28 14:48       ` Simon Marchi via Gdb-patches
2021-04-28 15:42         ` Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 19/43] Add new memory " Zoran Zaric via Gdb-patches
2021-04-30 21:24   ` Simon Marchi via Gdb-patches
2021-03-01 14:45 ` [PATCH 20/43] Add new classes that model DWARF stack element Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 21/43] Add to_location method to DWARF entry classes Zoran Zaric via Gdb-patches
2021-03-01 14:45 ` [PATCH 22/43] Add to_value " Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 23/43] Add read method to location description classes Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 24/43] Add write " Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 25/43] Add deref " Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 26/43] Add read_from_gdb_value method to dwarf_location Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 27/43] Add write_to_gdb_value " Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 28/43] Add is_implicit_ptr_at " Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 29/43] Add indirect_implicit_ptr to dwarf_location class Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 30/43] Add new computed struct value callback interface Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 31/43] Add to_gdb_value method to DWARF entry class Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 32/43] Change DWARF stack to use new dwarf_entry classes Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 33/43] Remove old computed struct value callbacks Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 34/43] Comments cleanup between expr.h and expr.c Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 35/43] Remove dwarf_expr_context from expr.h interface Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 36/43] Move read_addr_from_reg function to frame.c Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 37/43] Add frame info check to DW_OP_reg operations Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 38/43] Remove DWARF expression composition check Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 39/43] Change back the symbol needs to use the evaluator Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 40/43] Add support for any location description in CFI Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 41/43] Add DWARF operations for byte and bit offset Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 42/43] Add support for DW_OP_LLVM_undefined operation Zoran Zaric via Gdb-patches
2021-03-01 14:46 ` [PATCH 43/43] Add support for nested composite locations Zoran Zaric via Gdb-patches

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=320722e8-79e8-1890-bda8-bccf57ad52a3@amd.com \
    --to=gdb-patches@sourceware.org \
    --cc=Zoran.Zaric@amd.com \
    --cc=simon.marchi@polymtl.ca \
    /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