From patchwork Mon Sep 24 20:51:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 29525 Received: (qmail 48465 invoked by alias); 24 Sep 2018 20:52:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 48382 invoked by uid 89); 24 Sep 2018 20:51:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Sep 2018 20:51:58 +0000 Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id A228A10B6E9; Mon, 24 Sep 2018 16:51:55 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: andrew.burgess@embecosm.com, jimw@sifive.com Subject: [PATCH v2 1/4] Add helper functions to trad_frame to support register cache maps. Date: Mon, 24 Sep 2018 13:51:48 -0700 Message-Id: <20180924205151.22217-2-jhb@FreeBSD.org> In-Reply-To: <20180924205151.22217-1-jhb@FreeBSD.org> References: <20180924205151.22217-1-jhb@FreeBSD.org> X-IsSubscribed: yes Currently, signal frame handlers require explicitly coded calls to trad_frame_set_reg_addr() to describe the location of saved registers within a signal frame. This change permits the regcache_map_entry arrays used with regcache::supply_regset and regcache::collect_regset to be used to describe a block of saved registers given an initial address for the register block. Some systems use the same layout for registers in core dump notes, native register sets with ptrace(), and the register contexts saved in signal frames. On these systems, a single register map can now be used to describe the layout of registers in all three places. If a register map entry's size does not match the native size of a register, try to match the semantics used by regcache::transfer_regset. If a register slot is too large, assume that the register's value is stored in the first N bytes and ignore the remaning bytes. If the register slot is smaller than the register, assume the slot holds the low N bytes of the register's value. Read these low N bytes from the target and zero-extend them to generate a register value. gdb/ChangeLog: * trad-frame.c (trad_frame_set_regmap, trad_frame_set_reg_regmap): New. * trad-frame.h (trad_frame_set_regmap, trad_frame_set_reg_regmap): New. --- gdb/ChangeLog | 7 +++++ gdb/trad-frame.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ gdb/trad-frame.h | 8 ++++++ 3 files changed, 84 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 13fac9256f..2624975146 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2018-09-24 John Baldwin + + * trad-frame.c (trad_frame_set_regmap, trad_frame_set_reg_regmap): + New. + * trad-frame.h (trad_frame_set_regmap, trad_frame_set_reg_regmap): + New. + 2018-09-24 Tom Tromey * common/pathstuff.c (get_standard_cache_dir): Make diff --git a/gdb/trad-frame.c b/gdb/trad-frame.c index fd9f24084d..e09a333499 100644 --- a/gdb/trad-frame.c +++ b/gdb/trad-frame.c @@ -22,6 +22,7 @@ #include "trad-frame.h" #include "regcache.h" #include "frame-unwind.h" +#include "target.h" #include "value.h" struct trad_frame_cache @@ -125,6 +126,64 @@ trad_frame_set_addr (struct trad_frame_saved_reg this_saved_regs[], this_saved_regs[regnum].addr = addr; } +void +trad_frame_set_regmap (struct trad_frame_saved_reg this_saved_regs[], + struct gdbarch *gdbarch, const void *regmap, + CORE_ADDR addr, size_t size) +{ + const struct regcache_map_entry *map; + int offs = 0, count; + + for (map = (const struct regcache_map_entry *) regmap; + (count = map->count) != 0; + map++) + { + int regno = map->regno; + int slot_size = map->size; + + if (slot_size == 0 && regno != REGCACHE_MAP_SKIP) + slot_size = register_size (gdbarch, regno); + + if (offs + slot_size > size) + break; + + if (regno == REGCACHE_MAP_SKIP) + offs += count * slot_size; + else + for (; count--; regno++, offs += slot_size) + { + /* Mimic the semantics of regcache::transfer_regset if a + register slot's size does not match the size of a + register. + + If a register slot is larger than a register, assume + the register's value is stored in the first N bytes of + the slot and ignore the remaining bytes. + + If the register slot is smaller than the register, + assume that the slot contains the low N bytes of the + register's value. Since trad_frame assumes that + registers stored by address are sized according to the + register, read the low N bytes and zero-extend them to + generate a register value. */ + if (slot_size >= register_size (gdbarch, regno)) + trad_frame_set_addr (this_saved_regs, regno, addr + offs); + else + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + gdb_byte buf[slot_size]; + + if (target_read_memory (addr + offs, buf, sizeof buf) == 0) + { + LONGEST val + = extract_unsigned_integer (buf, sizeof buf, byte_order); + trad_frame_set_value (this_saved_regs, regno, val); + } + } + } + } +} + void trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache, int regnum, LONGEST val) @@ -148,6 +207,16 @@ trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache, trad_frame_set_addr (this_trad_cache->prev_regs, regnum, addr); } +void +trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache, + const void *regmap, CORE_ADDR addr, size_t size) +{ + struct gdbarch *gdbarch = get_frame_arch (this_trad_cache->this_frame); + + trad_frame_set_regmap (this_trad_cache->prev_regs, gdbarch, regmap, addr, + size); +} + void trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[], int regnum) diff --git a/gdb/trad-frame.h b/gdb/trad-frame.h index a11a2c29c9..1fc1859996 100644 --- a/gdb/trad-frame.h +++ b/gdb/trad-frame.h @@ -45,6 +45,9 @@ void trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache, int regnum, int realreg); void trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr); +void trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache, + const void *regmap, CORE_ADDR addr, + size_t size); void trad_frame_set_reg_value (struct trad_frame_cache *this_cache, int regnum, LONGEST val); @@ -96,6 +99,11 @@ void trad_frame_set_realreg (struct trad_frame_saved_reg this_saved_regs[], void trad_frame_set_addr (struct trad_frame_saved_reg this_trad_cache[], int regnum, CORE_ADDR addr); +/* Encode registers in REGMAP are at address ADDR in the trad-frame. */ +void trad_frame_set_regmap (struct trad_frame_saved_reg this_saved_regs[], + struct gdbarch *gdbarch, const void *regmap, + CORE_ADDR addr, size_t size); + /* Mark REGNUM as unknown. */ void trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[], int regnum);