From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Zoran Zaric <Zoran.Zaric@amd.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 19/43] Add new memory access interface to expr.c
Date: Fri, 30 Apr 2021 17:24:41 -0400 [thread overview]
Message-ID: <764283de-8366-64da-d5d9-859cdef5c4f5@polymtl.ca> (raw)
In-Reply-To: <20210301144620.103016-20-Zoran.Zaric@amd.com>
On 2021-03-01 9:45 a.m., Zoran Zaric via Gdb-patches wrote:
> DWARF expression evaluator is currently using a few different
> interfaces for memory access: write_memory_with_notification,
> read_value_memory, read_memory.
>
> They all seem incosistent, while some of them even need a struct
> value typed argument to be present.
>
> This patch is simplifying that interface by replacing it with two new
> low level functions: read_from_memory and write_to_memory.
>
> The advantage of this new interface is that it behaves in the same way
> as the register access interface from the previous patch. Both of these
> have the same error returning policy, which will be usefull for the
> following patches.
>
> * dwarf2/expr.c (xfer_memory): New function.
> (read_from_memory): New function.
> (write_to_memory): New function.
> (rw_pieced_value): Now calls the read_from_memory and
> write_to_memory functions.
> ---
> gdb/dwarf2/expr.c | 187 +++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 144 insertions(+), 43 deletions(-)
>
> diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
> index 5a1fd5b941f..1abece7d173 100644
> --- a/gdb/dwarf2/expr.c
> +++ b/gdb/dwarf2/expr.c
> @@ -32,6 +32,8 @@
> #include "frame.h"
> #include "gdbsupport/underlying.h"
> #include "gdbarch.h"
> +#include "inferior.h"
> +#include "observable.h"
>
> /* Cookie for gdbarch data. */
>
> @@ -196,6 +198,85 @@ write_to_register (struct frame_info *frame, int regnum,
> return;
> }
>
> +/* Helper for read_from_memory and write_to_memory. */
> +
> +static void
> +xfer_memory (CORE_ADDR address, gdb_byte *readbuf,
> + const gdb_byte *writebuf,
> + size_t length, bool stack, int *unavailable)
unavailable should probably be bool (end-to-end).
> +{
> + *unavailable = 0;
> +
> + enum target_object object
> + = stack ? TARGET_OBJECT_STACK_MEMORY : TARGET_OBJECT_MEMORY;
> +
> + ULONGEST xfered_total = 0;
> +
> + while (xfered_total < length)
> + {
> + ULONGEST xfered_partial;
> +
> + enum target_xfer_status status
> + = target_xfer_partial (current_top_target (), object, NULL,
> + (readbuf != nullptr
> + ? readbuf + xfered_total
> + : nullptr),
> + (writebuf != nullptr
> + ? writebuf + xfered_total
> + : nullptr),
> + address + xfered_total, length - xfered_total,
> + &xfered_partial);
> +
> + if (status == TARGET_XFER_OK)
> + {
> + xfered_total += xfered_partial;
> + QUIT;
> + }
> + else if (status == TARGET_XFER_UNAVAILABLE)
> + {
> + *unavailable = 1;
> + return;
> + }
> + else if (status == TARGET_XFER_EOF)
> + memory_error (TARGET_XFER_E_IO, address + xfered_total);
> + else
> + memory_error (status, address + xfered_total);
> + }
> +}
> +
> +/* Read LENGTH bytes of memory contents starting at ADDRESS.
> +
> + The data read is copied to a caller-managed buffer BUF. STACK
BUF -> BUFFER.
> + indicates whether the memory range specified belongs to a stack
> + memory region.
> +
> + If the memory is unavailable, the UNAVAILABLE output is set. */
> +
> +static void
> +read_from_memory (CORE_ADDR address, gdb_byte *buffer,
> + size_t length, bool stack, int *unavailable)
> +{
> + xfer_memory (address, buffer, nullptr, length, stack, unavailable);
> +}
> +
> +/* Write LENGTH bytes of memory contents starting at ADDRESS.
> +
> + The data written is copied from a caller-managed buffer buf. STACK
buf -> BUFFER
> + indicates whether the memory range specified belongs to a stack
> + memory region.
> +
> + If the memory is unavailable, the UNAVAILABLE output is set. */
> +
> +static void
> +write_to_memory (CORE_ADDR address, const gdb_byte *buffer,
> + size_t length, bool stack, int *unavailable)
> +{
> + xfer_memory (address, nullptr, buffer, length, stack, unavailable);
> +
> + gdb::observers::memory_changed.notify (current_inferior (), address,
> + length, buffer);
> +}
> +
> struct piece_closure
> {
> /* Reference count. */
> @@ -381,66 +462,86 @@ rw_pieced_value (struct value *v, struct value *from)
> bits_to_skip += p->offset;
>
> CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8;
> + bool in_stack_memory = p->v.mem.in_stack_memory;
> + int unavail = 0;
>
> if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0
> && offset % 8 == 0)
> {
> /* Everything is byte-aligned; no buffer needed. */
> if (from != NULL)
> - write_memory_with_notification (start_addr,
> - (from_contents
> - + offset / 8),
> - this_size_bits / 8);
> + write_to_memory (start_addr, (from_contents + offset / 8),
> + this_size_bits / 8, in_stack_memory,
> + &unavail);
> else
> - read_value_memory (v, offset,
> - p->v.mem.in_stack_memory,
> - p->v.mem.addr + bits_to_skip / 8,
> - v_contents + offset / 8,
> - this_size_bits / 8);
> - break;
> - }
> -
> - this_size = bits_to_bytes (bits_to_skip, this_size_bits);
> - buffer.resize (this_size);
> -
> - if (from == NULL)
> - {
> - /* Read mode. */
> - read_value_memory (v, offset,
> - p->v.mem.in_stack_memory,
> - p->v.mem.addr + bits_to_skip / 8,
> - buffer.data (), this_size);
> - copy_bitwise (v_contents, offset,
> - buffer.data (), bits_to_skip % 8,
> - this_size_bits, bits_big_endian);
> + read_from_memory (start_addr, (v_contents + offset / 8),
> + this_size_bits / 8, in_stack_memory,
> + &unavail);
> }
> else
> {
> - /* Write mode. */
> - if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
> + this_size = bits_to_bytes (bits_to_skip, this_size_bits);
> + buffer.resize (this_size);
> +
> + if (from == NULL)
> {
> - if (this_size <= 8)
> + /* Read mode. */
> + read_from_memory (start_addr, buffer.data (),
> + this_size, in_stack_memory,
> + &unavail);
> + if (!unavail)
> + copy_bitwise (v_contents, offset,
> + buffer.data (), bits_to_skip % 8,
> + this_size_bits, bits_big_endian);
> + }
> + else
> + {
> + /* Write mode. */
> + if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
> {
> - /* Perform a single read for small sizes. */
> - read_memory (start_addr, buffer.data (),
> - this_size);
> + if (this_size <= 8)
> + {
> + /* Perform a single read for small sizes. */
> + read_from_memory (start_addr, buffer.data (),
> + this_size, in_stack_memory,
> + &unavail);
> + }
> + else
> + {
> + /* Only the first and last bytes can possibly have
> + any bits reused. */
> + read_from_memory (start_addr, buffer.data (),
> + 1, in_stack_memory,
> + &unavail);
> + if (!unavail)
> + read_from_memory (start_addr + this_size - 1,
> + &buffer[this_size - 1], 1,
> + in_stack_memory, &unavail);
> + }
> }
> - else
> +
> + if (!unavail)
> {
> - /* Only the first and last bytes can possibly have
> - any bits reused. */
> - read_memory (start_addr, buffer.data (), 1);
> - read_memory (start_addr + this_size - 1,
> - &buffer[this_size - 1], 1);
> + copy_bitwise (buffer.data (), bits_to_skip % 8,
> + from_contents, offset,
> + this_size_bits, bits_big_endian);
> + write_to_memory (start_addr, buffer.data (),
> + this_size, in_stack_memory,
> + &unavail);
> }
> }
> + }
>
> - copy_bitwise (buffer.data (), bits_to_skip % 8,
> - from_contents, offset,
> - this_size_bits, bits_big_endian);
> - write_memory_with_notification (start_addr,
> - buffer.data (),
> - this_size);
> + if (unavail)
> + {
> + if (from == NULL)
> + mark_value_bits_unavailable (v, (offset + bits_to_skip % 8),
> + this_size_bits);
> + else
> + throw_error (NOT_AVAILABLE_ERROR,
> + _("Can't do read-modify-write to "
> + "update bitfield; containing word "
> + "is unavailable"));
Did you get inspiration from existing code for this unavailable byte
error handling? Were you able to test it?
Simon
next prev parent reply other threads:[~2021-04-30 21:24 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
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 [this message]
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=764283de-8366-64da-d5d9-859cdef5c4f5@polymtl.ca \
--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