From: Zoran Zaric <Zoran.Zaric@amd.com>
To: gdb-patches@sourceware.org
Cc: Zoran Zaric <Zoran.Zaric@amd.com>
Subject: [PATCH 23/30] Rename and update the piece_closure structure
Date: Mon, 7 Dec 2020 19:00:24 +0000 [thread overview]
Message-ID: <20201207190031.13341-24-Zoran.Zaric@amd.com> (raw)
In-Reply-To: <20201207190031.13341-1-Zoran.Zaric@amd.com>
Class that describes a computed_lval closure needs to be update to fit
better with the new dwarf_entry set of classes. This also means that a
pieced_value_funcs interface with that closure, needs to be renamed and
updated accordingly.
Considering that a closure is designed to describe a computed location
description, it makes sense to rename piece_closure to a
computed_closure.
gdb/ChangeLog:
* dwarf2/expr.c (struct piece_closure): Change to
computed_closure class.
(allocate_piece_closure): Remove function.
(rw_pieced_value): Rename to rw_closure_value and change to use
computed_closure class.
(read_pieced_value): Rename to read_closure_value and change to
use computed_closure class.
(write_pieced_value): Rename to write_closure_value and change
to use computed_closure class.
(check_pieced_synthetic_pointer): Rename to
check_synthetic_pointer and change to use computed_closure
class.
(indirect_pieced_value): Rename to indirect_closure_value and
change to use computed_closure class.
(coerce_pieced_ref): Rename to coerce_closure_ref and change
to use computed_closure class.
(copy_pieced_value_closure): Rename to copy_value_closure and
change to use computed_closure class.
(free_pieced_value_closure): Rename to free_value_closure and
change to use computed_closure class.
(dwarf_expr_context::gdb_value_to_dwarf_entry): Change to use
computed_closure class.
(dwarf_expr_context::dwarf_entry_to_gdb_value): Change to use
computed_closure class.
---
gdb/dwarf2/expr.c | 206 +++++++++++++++++++++++-----------------------
1 file changed, 103 insertions(+), 103 deletions(-)
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 9ed0ad8baf..a259f5d5d5 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -1351,77 +1351,68 @@ dwarf_entry_factory::value_cast_op (const dwarf_value *arg, struct type *type)
return create_value (value_contents_raw (result), type);
}
-struct piece_closure
+/* Closure class that encapsulates a location description and
+ a context in which that description is created. Used for
+ lval_computed value abstraction. */
+class computed_closure : public refcounted_object
{
- /* Reference count. */
- int refc = 0;
-
- /* The objfile from which this closure's expression came. */
- dwarf2_per_objfile *per_objfile = nullptr;
-
- /* The CU from which this closure's expression came. */
- struct dwarf2_per_cu_data *per_cu = NULL;
+public:
+ computed_closure (dwarf_entry *entry, struct frame_id frame_id) :
+ m_entry (entry), m_frame_id (frame_id)
+ {entry->incref ();}
- /* Location description of this variable. */
- dwarf_location *location;
+ virtual ~computed_closure ()
+ {
+ m_entry->decref ();
- /* Frame ID of frame to which a register value is relative, used
- only by DWARF_VALUE_REGISTER. */
- struct frame_id frame_id;
-};
+ if (m_entry->refcount () == 0)
+ delete m_entry;
+ }
-/* Allocate a closure for a value formed from separately-described
- PIECES. */
+ dwarf_entry *get_entry () const
+ {
+ return m_entry;
+ }
-static struct piece_closure *
-allocate_piece_closure (dwarf2_per_cu_data *per_cu,
- dwarf2_per_objfile *per_objfile,
- dwarf_location *location,
- struct frame_info *frame)
-{
- struct piece_closure *c = new piece_closure;
+ struct frame_id get_frame_id () const
+ {
+ return m_frame_id;
+ }
- c->refc = 1;
- /* We must capture this here due to sharing of DWARF state. */
- c->per_objfile = per_objfile;
- c->per_cu = per_cu;
- if (frame == NULL)
- c->frame_id = null_frame_id;
- else
- c->frame_id = get_frame_id (frame);
+private:
+ /* Entry that this class encloses. */
+ dwarf_entry *m_entry;
- location->incref ();
- c->location = location;
- return c;
-}
+ /* Frame ID context of the closure. */
+ struct frame_id m_frame_id;
+};
-/* Read or write a pieced value V. If FROM != NULL, operate in "write
- mode": copy FROM into the pieces comprising V. If FROM == NULL,
+/* Read or write a closure value V. If FROM != NULL, operate in "write
+ mode": copy FROM into the closure comprising V. If FROM == NULL,
operate in "read mode": fetch the contents of the (lazy) value V by
- composing it from its pieces. */
+ composing it from its closure. */
static void
-rw_pieced_value (struct value *v, struct value *from)
+rw_closure_value (struct value *v, struct value *from)
{
LONGEST bit_offset = 0, max_bit_offset;
- struct piece_closure *closure
- = (struct piece_closure *) value_computed_closure (v);
+ computed_closure *closure = ((computed_closure*) value_computed_closure (v));
bool big_endian = type_byte_order (value_type (v)) == BFD_ENDIAN_BIG;
- dwarf_entry *entry = closure->location;
+ dwarf_entry *entry = closure->get_entry ();
/* Only expect implicit pointer and composite location
description here. */
if (entry == nullptr
|| (dynamic_cast<dwarf_implicit_pointer *> (entry) == nullptr
- && dynamic_cast<dwarf_composite *> (entry) == nullptr))
+ && dynamic_cast<dwarf_composite *> (entry) == nullptr))
internal_error (__FILE__, __LINE__, _("invalid location type"));
if (from == NULL)
{
if (value_type (v) != value_enclosing_type (v))
- internal_error (__FILE__, __LINE__,
- _("Should not be able to create a lazy value with "
- "an enclosing type"));
+ internal_error (__FILE__, __LINE__,
+ _("Should not be able to create a lazy value with "
+ "an enclosing type"));
}
ULONGEST bits_to_skip = HOST_CHAR_BIT * value_offset (v);
@@ -1454,7 +1445,7 @@ rw_pieced_value (struct value *v, struct value *from)
return;
}
- struct frame_info *frame = frame_find_by_id (closure->frame_id);
+ struct frame_info *frame = frame_find_by_id (closure->get_frame_id ());
dwarf_composite *composite_entry = dynamic_cast<dwarf_composite *> (entry);
@@ -1524,15 +1515,15 @@ rw_pieced_value (struct value *v, struct value *from)
}
static void
-read_pieced_value (struct value *v)
+read_closure_value (struct value *v)
{
- rw_pieced_value (v, NULL);
+ rw_closure_value (v, NULL);
}
static void
-write_pieced_value (struct value *to, struct value *from)
+write_closure_value (struct value *to, struct value *from)
{
- rw_pieced_value (to, from);
+ rw_closure_value (to, from);
}
/* Check if a given location contains an implicit pointer
@@ -1592,17 +1583,18 @@ check_synthetic_pointer_location (const dwarf_location *location,
a synthetic pointer. */
static int
-check_pieced_synthetic_pointer (const struct value *value, LONGEST bit_offset,
- int bit_length)
+check_synthetic_pointer (const struct value *value, LONGEST bit_offset,
+ int bit_length)
{
LONGEST total_bit_offset = bit_offset + HOST_CHAR_BIT * value_offset (value);
if (value_bitsize (value))
total_bit_offset += value_bitpos (value);
- struct piece_closure *closure
- = (struct piece_closure *) value_computed_closure (value);
- dwarf_location *location = closure->location;
+ computed_closure *closure
+ = (computed_closure *) value_computed_closure (value);
+ auto location
+ = dynamic_cast<dwarf_location *> (closure->get_entry ());
if (location == nullptr)
return 0;
@@ -1680,10 +1672,10 @@ indirect_from_location (const dwarf_location *location,
pointer. This handles the synthetic pointer case when needed. */
static struct value *
-indirect_pieced_value (struct value *value)
+indirect_closure_value (struct value *value)
{
- struct piece_closure *closure
- = (struct piece_closure *) value_computed_closure (value);
+ computed_closure *closure
+ = (computed_closure *) value_computed_closure (value);
struct type *type = check_typedef (value_type (value));
if (type->code () != TYPE_CODE_PTR)
@@ -1695,7 +1687,8 @@ indirect_pieced_value (struct value *value)
if (value_bitsize (value))
bit_offset += value_bitpos (value);
- dwarf_location *location = closure->location;
+ auto location
+ = dynamic_cast<dwarf_location *> (closure->get_entry ());
/* Only location descriptions are meaningful here. */
if (location == nullptr)
@@ -1726,20 +1719,20 @@ indirect_pieced_value (struct value *value)
references. */
static struct value *
-coerce_pieced_ref (const struct value *value)
+coerce_closure_ref (const struct value *value)
{
struct type *type = check_typedef (value_type (value));
if (value_bits_synthetic_pointer (value, value_embedded_offset (value),
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
{
- struct piece_closure *closure
- = (struct piece_closure *) value_computed_closure (value);
+ computed_closure *closure
+ = (computed_closure *) value_computed_closure (value);
struct frame_info *frame
= get_selected_frame (_("No frame selected."));
auto pointer_entry
- = dynamic_cast<dwarf_implicit_pointer *> (closure->location);
+ = dynamic_cast<dwarf_implicit_pointer *> (closure->get_entry ());
/* Only implicit pointer location description is meaningful here. */
if (pointer_entry == nullptr)
@@ -1747,8 +1740,8 @@ coerce_pieced_ref (const struct value *value)
return indirect_synthetic_pointer (pointer_entry->get_die_offset (),
pointer_entry->get_offset (),
- closure->per_cu,
- closure->per_objfile,
+ pointer_entry->get_per_cu (),
+ pointer_entry->get_per_objfile (),
frame, type);
}
else
@@ -1759,38 +1752,41 @@ coerce_pieced_ref (const struct value *value)
}
static void *
-copy_pieced_value_closure (const struct value *v)
+copy_value_closure (const struct value *v)
{
- struct piece_closure *c
- = (struct piece_closure *) value_computed_closure (v);
+ computed_closure *closure = ((computed_closure*) value_computed_closure (v));
- ++c->refc;
- return c;
+ if (closure == nullptr)
+ internal_error (__FILE__, __LINE__, _("invalid closure type"));
+
+ closure->incref ();
+ return closure;
}
static void
-free_pieced_value_closure (struct value *v)
+free_value_closure (struct value *v)
{
- struct piece_closure *c
- = (struct piece_closure *) value_computed_closure (v);
+ computed_closure *closure = ((computed_closure*) value_computed_closure (v));
- --c->refc;
- if (c->refc == 0)
- {
- c->location->decref ();
- delete c;
- }
+ if (closure == nullptr)
+ internal_error (__FILE__, __LINE__, _("invalid closure type"));
+
+ closure->decref ();
+
+ if (closure->refcount () == 0)
+ delete closure;
}
-/* Functions for accessing a variable described by DW_OP_piece. */
-static const struct lval_funcs pieced_value_funcs = {
- read_pieced_value,
- write_pieced_value,
- indirect_pieced_value,
- coerce_pieced_ref,
- check_pieced_synthetic_pointer,
- copy_pieced_value_closure,
- free_pieced_value_closure
+/* Functions for accessing a variable described by DW_OP_piece,
+ DW_OP_bit_piece or DW_OP_implicit_pointer. */
+static const struct lval_funcs closure_value_funcs = {
+ read_closure_value,
+ write_closure_value,
+ indirect_closure_value,
+ coerce_closure_ref,
+ check_synthetic_pointer,
+ copy_value_closure,
+ free_value_closure
};
/* Given context CTX, section offset SECT_OFF, and compilation unit
@@ -2331,9 +2327,9 @@ dwarf_expr_context::gdb_value_to_dwarf_entry (struct value *value)
{
/* Dwarf entry is enclosed by the closure anyway so we just
need to unwrap it here. */
- struct piece_closure *closure
- = (struct piece_closure *) value_computed_closure (value);
- auto location = dynamic_cast<dwarf_location *> (closure->location);
+ computed_closure *closure
+ = ((computed_closure *) value_computed_closure (value));
+ auto location = dynamic_cast<dwarf_location *> (closure->get_entry ());
if (location == nullptr)
internal_error (__FILE__, __LINE__, _("invalid closure type"));
@@ -2425,15 +2421,19 @@ dwarf_expr_context::dwarf_entry_to_gdb_value (dwarf_entry *entry,
(void *)(implicit_entry->get_contents () + subobj_offset),
subtype_len);
}
- else if (auto implicit_pointer_entry
- = dynamic_cast<dwarf_implicit_pointer *> (entry))
+ else if (dynamic_cast<dwarf_implicit_pointer *> (entry) != nullptr)
{
- struct piece_closure *closure
- = allocate_piece_closure (this->per_cu, this->per_objfile,
- implicit_pointer_entry, this->frame);
+ /* Complain if the expression is larger than the size of the
+ outer type. */
+ if (this->addr_size > HOST_CHAR_BIT * TYPE_LENGTH (type))
+ invalid_synthetic_pointer ();
+
+ computed_closure *closure
+ = new computed_closure (entry, get_frame_id (frame));
+ closure->incref ();
retval
- = allocate_computed_value (subobj_type, &pieced_value_funcs, closure);
+ = allocate_computed_value (subobj_type, &closure_value_funcs, closure);
set_value_offset (retval, subobj_offset);
}
else if (auto composite_entry = dynamic_cast<dwarf_composite *> (entry))
@@ -2449,12 +2449,12 @@ dwarf_expr_context::dwarf_entry_to_gdb_value (dwarf_entry *entry,
if (bit_size > HOST_CHAR_BIT * TYPE_LENGTH (type))
invalid_synthetic_pointer ();
- struct piece_closure *closure
- = allocate_piece_closure (this->per_cu, this->per_objfile,
- composite_entry, this->frame);
+ computed_closure *closure
+ = new computed_closure (entry, get_frame_id (frame));
+ closure->incref ();
retval
- = allocate_computed_value (subobj_type, &pieced_value_funcs, closure);
+ = allocate_computed_value (subobj_type, &closure_value_funcs, closure);
set_value_offset (retval, subobj_offset);
}
--
2.17.1
next prev parent reply other threads:[~2020-12-07 19:01 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 19:00 [PATCH 00/30] Allow location description on the DWARF stack Zoran Zaric
2020-12-07 19:00 ` [PATCH 01/30] Replace the symbol needs evaluator with a parser Zoran Zaric
2021-01-21 21:16 ` Tom Tromey
2021-01-21 21:48 ` Zoran Zaric
2021-02-23 14:15 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 02/30] Move frame context info to dwarf_expr_context Zoran Zaric
2021-01-21 21:23 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 03/30] Remove get_frame_cfa from dwarf_expr_context Zoran Zaric
2021-01-21 21:23 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 04/30] Move compilation unit info to dwarf_expr_context Zoran Zaric
2021-01-21 21:28 ` Tom Tromey
2021-02-23 14:21 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 05/30] Move dwarf_call " Zoran Zaric
2021-01-21 21:30 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 06/30] Move get_object_address " Zoran Zaric
2021-01-21 21:31 ` Tom Tromey
2021-02-23 14:33 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 07/30] Move read_mem " Zoran Zaric
2021-01-21 21:34 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 08/30] Move push_dwarf_reg_entry_value to expr.c Zoran Zaric
2021-01-21 21:35 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 09/30] Inline get_reg_value method of dwarf_expr_context Zoran Zaric
2021-01-21 21:36 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 10/30] Remove empty frame and full evaluators Zoran Zaric
2021-01-21 21:37 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 11/30] Merge evaluate_for_locexpr_baton evaluator Zoran Zaric
2021-02-08 21:21 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 12/30] Move piece_closure and its support to expr.c Zoran Zaric
2021-02-08 21:32 ` Tom Tromey
2021-02-09 14:53 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 13/30] Make DWARF evaluator return a single struct value Zoran Zaric
2021-02-08 21:35 ` Tom Tromey
2021-02-09 14:55 ` Zoran Zaric
2021-02-09 17:13 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 14/30] Simplify dwarf_expr_context class interface Zoran Zaric
2021-02-08 21:38 ` Tom Tromey
2021-02-09 14:56 ` Zoran Zaric
2021-02-23 14:38 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 15/30] Add as_lval argument to expression evaluator Zoran Zaric
2021-02-08 21:41 ` Tom Tromey
2021-02-09 15:25 ` Zoran Zaric
2021-02-09 20:33 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 16/30] Add new register access interface to expr.c Zoran Zaric
2021-02-09 19:37 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 17/30] Add new memory " Zoran Zaric
2021-02-09 19:45 ` Tom Tromey
2021-02-23 15:35 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 18/30] Add new classes that model DWARF stack element Zoran Zaric
2021-02-08 21:54 ` Tom Tromey
2021-02-09 17:34 ` Zoran Zaric
2021-02-09 20:36 ` Tom Tromey
2021-02-09 21:07 ` Tom Tromey
2021-02-09 21:26 ` Zoran Zaric
2021-02-23 14:57 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 19/30] Add new location description access interface Zoran Zaric
2021-02-08 21:46 ` Tom Tromey
2021-02-09 16:00 ` Zoran Zaric
2021-02-09 17:30 ` Zoran Zaric
2021-02-23 14:49 ` Zoran Zaric
2020-12-07 19:00 ` [PATCH 20/30] Add dwarf_entry factory class to expr.c Zoran Zaric
2021-02-09 19:54 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 21/30] Change DWARF stack to use new dwarf_entry classes Zoran Zaric
2021-02-09 20:11 ` Tom Tromey
2020-12-07 19:00 ` [PATCH 22/30] Remove dwarf_expr_context from expr.h interface Zoran Zaric
2020-12-07 19:00 ` Zoran Zaric [this message]
2020-12-07 19:00 ` [PATCH 24/30] Move read_addr_from_reg function to frame.c Zoran Zaric
2020-12-07 19:00 ` [PATCH 25/30] Add frame info check to DW_OP_reg operations Zoran Zaric
2020-12-07 19:00 ` [PATCH 26/30] Remove DWARF expression composition check Zoran Zaric
2020-12-07 19:00 ` [PATCH 27/30] Add support for any location description in CFI Zoran Zaric
2020-12-07 19:00 ` [PATCH 28/30] Add DWARF operations for byte and bit offset Zoran Zaric
2020-12-07 19:00 ` [PATCH 29/30] Add support for DW_OP_LLVM_undefined operation Zoran Zaric
2020-12-07 19:00 ` [PATCH 30/30] Add support for nested composite locations Zoran Zaric
2020-12-08 14:48 ` [PATCH 00/30] Allow location description on the DWARF stack Metzger, Markus T
2020-12-08 16:17 ` Simon Marchi
2020-12-09 0:30 ` Tye, Tony
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=20201207190031.13341-24-Zoran.Zaric@amd.com \
--to=zoran.zaric@amd.com \
--cc=gdb-patches@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).