From patchwork Wed Feb 7 10:32:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 25846 Received: (qmail 22870 invoked by alias); 7 Feb 2018 10:33:14 -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 22658 invoked by uid 89); 7 Feb 2018 10:33:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=16457, Raw X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 10:33:10 +0000 Received: by mail-wm0-f46.google.com with SMTP id i186so2179703wmi.4 for ; Wed, 07 Feb 2018 02:33:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=5hvziCaNNGELq6npQid7uFogN5Rc2rs5EcknwoZfTaQ=; b=i/HlCNkx8U8SrxlFAEwQ2zSFnwrAUvtfWp/mrNflm42g4eXJXyW5gjaTOXcpGaoL6t EEiHr0mzyP+UcwlJNSDXGRm8sXpvLa7bDSHSel/sSTmcYKP/DRfjTk0nwsnglLw2+BBq ske+Rda8iqaGUUgz2BI5G47NLXMQ4qZU4YRcPH6Fankml8lauaw6fUbKQRHJI+2cFI2H EFYVPsT1cDWeyCt0m6s7UZscV+ZlmjYJC7bhc/rnFTvZlqndIjFhInxgCFn+mFzOcmsh yYUdJdyubyymv2voei+jTPJ66uVDaVGZAtK8aORWT+o4GtyxUQRWFgluk4meK4MXTDp6 22ww== X-Gm-Message-State: APf1xPB9cYnm3lea0mC10WokZNOPx4Bo/AjRhwAMJctZiJzf2w+ia5DR zCzLMVBnk4HiWbzOULgrPCanug== X-Google-Smtp-Source: AH8x227vUegyO4hPLUm7vTeGCoLfahsT9cyIIXYiEUzGy/7XckVssFPJpfxbXdBpvyGXrSM0Y164zA== X-Received: by 10.28.213.77 with SMTP id m74mr4565306wmg.137.1517999588365; Wed, 07 Feb 2018 02:33:08 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id x135sm1138884wmf.35.2018.02.07.02.33.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Feb 2018 02:33:07 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 07/10] No longer create readonly regcache Date: Wed, 7 Feb 2018 10:32:49 +0000 Message-Id: <1517999572-14987-8-git-send-email-yao.qi@linaro.org> In-Reply-To: <1517999572-14987-1-git-send-email-yao.qi@linaro.org> References: <1517999572-14987-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes Nowadays, we create a readonly regcache in get_return_value, and pass it to gdbarch_return_value to get the return value. In theory, we can pass a readable_regcache instance and get the return value, because we don't need to modify the regcache. Unfortunately, gdbarch_return_value is designed to multiplex regcache, according to READBUF and WRITEBUF. # If READBUF is not NULL, extract the return value and save it in this # buffer. # # If WRITEBUF is not NULL, it contains a return value which will be # stored into the appropriate register. In fact, gdbarch_return_value should be split to three functions, 1) only return return_value_convention, 2) pass regcache_readonly and readbuf, 3) pass regcache and writebuf. These changes are out of the scope of this patch series, so I pass regcache to gdbarch_return_value even for read, and trust each gdbarch backend doesn't modify regcache. gdb: 2017-11-02 Yao Qi * infcmd.c (get_return_value): Let stop_regs point to get_current_regcache. * regcache.c (regcache::regcache): Remove. (register_dump_reg_buffer): New class. (regcache_print): Adjust. * regcache.h (regcache): Remove constructors. --- gdb/infcmd.c | 6 ++--- gdb/regcache.c | 71 +++++++++++++++++++++++++++++++++++++++++++++------------- gdb/regcache.h | 10 --------- 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 3879df3..170c8d5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1624,8 +1624,8 @@ advance_command (const char *arg, int from_tty) struct value * get_return_value (struct value *function, struct type *value_type) { - regcache stop_regs (regcache::readonly, *get_current_regcache ()); - struct gdbarch *gdbarch = stop_regs.arch (); + regcache *stop_regs = get_current_regcache (); + struct gdbarch *gdbarch = stop_regs->arch (); struct value *value; value_type = check_typedef (value_type); @@ -1645,7 +1645,7 @@ get_return_value (struct value *function, struct type *value_type) case RETURN_VALUE_ABI_RETURNS_ADDRESS: case RETURN_VALUE_ABI_PRESERVES_ADDRESS: value = allocate_value (value_type); - gdbarch_return_value (gdbarch, function, value_type, &stop_regs, + gdbarch_return_value (gdbarch, function, value_type, stop_regs, value_contents_raw (value), NULL); break; case RETURN_VALUE_STRUCT_CONVENTION: diff --git a/gdb/regcache.c b/gdb/regcache.c index 389c016..8f81163 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -219,13 +219,6 @@ do_cooked_read (void *src, int regnum, gdb_byte *buf) return regcache_cooked_read (regcache, regnum, buf); } -regcache::regcache (readonly_t, const regcache &src) - : regcache (src.arch (), nullptr, true) -{ - gdb_assert (!src.m_readonly_p); - save (do_cooked_read, (void *) &src); -} - readonly_detached_regcache::readonly_detached_regcache (const regcache &src) : readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src) { @@ -1512,6 +1505,55 @@ private: const bool m_dump_pseudo; }; +/* Dump from reg_buffer, used when there is no thread or + registers. */ + +class register_dump_reg_buffer : public register_dump, reg_buffer +{ +public: + register_dump_reg_buffer (gdbarch *gdbarch, bool dump_pseudo) + : register_dump (gdbarch), reg_buffer (gdbarch, dump_pseudo) + { + } + +protected: + void dump_reg (ui_file *file, int regnum) override + { + if (regnum < 0) + { + if (m_has_pseudo) + fprintf_unfiltered (file, "Cooked value"); + else + fprintf_unfiltered (file, "Raw value"); + } + else + { + if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo) + { + auto size = register_size (m_gdbarch, regnum); + + if (size == 0) + return; + + auto status = get_register_status (regnum); + + gdb_assert (status != REG_VALID); + + if (status == REG_UNKNOWN) + fprintf_unfiltered (file, ""); + else + fprintf_unfiltered (file, ""); + } + else + { + /* Just print "" for pseudo register when + regcache_dump_raw. */ + fprintf_unfiltered (file, ""); + } + } + } +}; + /* For "maint print registers". */ class register_dump_none : public register_dump @@ -1633,22 +1675,19 @@ regcache_print (const char *args, enum regcache_dump_what what_to_dump) case regcache_dump_raw: case regcache_dump_cooked: { - regcache *reg; + auto dump_pseudo = (what_to_dump == regcache_dump_cooked); if (target_has_registers) - reg = get_current_regcache (); + dump.reset (new register_dump_regcache (get_current_regcache (), + dump_pseudo)); else { /* For the benefit of "maint print registers" & co when debugging an executable, allow dumping a regcache even when there is no thread selected / no registers. */ - reg = new regcache (target_gdbarch ()); - regs.reset (reg); + dump.reset (new register_dump_reg_buffer (target_gdbarch (), + dump_pseudo)); } - - auto dump_pseudo = (what_to_dump == regcache_dump_cooked); - - dump.reset (new register_dump_regcache (reg, dump_pseudo)); } break; } @@ -1937,7 +1976,7 @@ cooked_read_test (struct gdbarch *gdbarch) mock_target.reset (); } - regcache readonly (regcache::readonly, readwrite); + readonly_detached_regcache readonly (readwrite); /* GDB may go to target layer to fetch all registers and memory for readonly regcache. */ diff --git a/gdb/regcache.h b/gdb/regcache.h index 0bca9f3..8a65d38 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -307,16 +307,6 @@ class readonly_detached_regcache; class regcache : public detached_regcache { public: - regcache (gdbarch *gdbarch) - : regcache (gdbarch, nullptr, true) - {} - - struct readonly_t {}; - static constexpr readonly_t readonly {}; - - /* Create a readonly regcache from a non-readonly regcache. */ - regcache (readonly_t, const regcache &src); - DISABLE_COPY_AND_ASSIGN (regcache); /* Return REGCACHE's address space. */