From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73958 invoked by alias); 1 Nov 2017 09:43:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 73932 invoked by uid 89); 1 Nov 2017 09:43:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:clients, NEXT, deciding, sk:frame_o X-HELO: mail-wm0-f47.google.com Received: from mail-wm0-f47.google.com (HELO mail-wm0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Nov 2017 09:42:58 +0000 Received: by mail-wm0-f47.google.com with SMTP id b189so3594524wmd.4 for ; Wed, 01 Nov 2017 02:42:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=W1tNICQDSiF3jN0oq45KmzmHByPXnPKU6P9QPQSaT68=; b=T0wbL0RYZdBNkswI9BAhSjt//4ihz8i/0JCDse3tUNecicYIdTiVCVMjr9hEvQB6zb or4IGMmN4IiuWKByxzrMrDSu26s9Bdp7bAvVbIo2/s+GaNXktZ+b2j3DZjMvfnnTP3ea Y8H5BnfLJNcdH07kNSSP4pmmr6GKujeH50/hu9pEmJxHZfGIFhQ2nCiiKovts0KP7LeA QNr6hwLxCNWjYPM7+j65j1054jf/fTQO0EvCuFnwk6257e1n3jOkmEnhewnxcAYYdChW co8glLt+rB31GL0VZE1ZWOziW7Rf1lpjP6CbvYWuOB/sw5ZVZRcL6zuhEs+XEdi+4UaD 0vhg== X-Gm-Message-State: AMCzsaUt4FYTaKBV2aGtHaov7sOjcYQ+hgovOY7t7JoZfGiF4cbF6vxN utsPZyYyhZ+Z5xOB0KczCh5amA== X-Google-Smtp-Source: ABhQp+RCDc1phNvwYE/NlqdcNtv6LyJTKkJlPP4J8aWtKrXcoA2gWTZfVqHrVZzNFCXjdVVzVoZKbw== X-Received: by 10.28.45.72 with SMTP id t69mr3943241wmt.108.1509529375784; Wed, 01 Nov 2017 02:42:55 -0700 (PDT) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id z35sm58336wrc.9.2017.11.01.02.42.54 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 01 Nov 2017 02:42:55 -0700 (PDT) From: Yao Qi To: Simon Marchi Cc: Subject: Re: [PATCH 6/8] const-fy regcache::m_aspace References: <1509096702-12202-1-git-send-email-yao.qi@linaro.org> <1509096702-12202-7-git-send-email-yao.qi@linaro.org> <75902364-b335-e37e-75e8-db5a0ff969c3@ericsson.com> Date: Wed, 01 Nov 2017 09:43:00 -0000 In-Reply-To: <75902364-b335-e37e-75e8-db5a0ff969c3@ericsson.com> (Simon Marchi's message of "Tue, 31 Oct 2017 10:19:17 -0400") Message-ID: <86d152xrl0.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00002.txt.bz2 Simon Marchi writes: > I don't really understand what this patch tries to achieve. From the > description above, I thought you wanted to make the m_aspace field const, > not the pointed object. > I want to achieve both, the field m_aspace is a const, and the pointed object is const too. /* The address space of this register cache (for registers where it makes sense, like PC or SP). */ - struct address_space *m_aspace; + const address_space * const m_aspace; > If constifying the pointed address_space object is really what you meant = to > do, I find having the const_cast more confusing than anything else. I th= ink > we should constify all the way (removing const_casts, putting more consts > where needed) or not at all. OK, const_cast is removed in the updated patch, what do you think? --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom 9e7e0560bafbb736a7a7fda79fd99fa37bd4c701 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Mon, 23 Oct 2017 10:42:54 +0100 Subject: [PATCH] const-fy regcache::m_aspace regcache::m_aspace is a const, never changed during the lifetime of regcache object. The address_space object is a const object too. gdb: 2017-10-23 Yao Qi * breakpoint.c (insert_single_step_breakpoints): Update. * frame.c (struct frame_info) : Add const. (frame_save_as_regcache): Add const. (get_frame_address_space): Return const address_space *. * frame.h (get_frame_address_space): Update declaration. * infrun.c (struct step_over_info) : Add const. (set_step_over_info): Make aspace const. (displaced_step_prepare_throw): Change variable const. (resume): Likewise. (proceed): Likewise. (adjust_pc_after_break): Likewise. (save_waitstatus): Likewise. (handle_signal_stop): Likewise. (keep_going_pass_signal): Likewise. * jit.c (jit_frame_sniffer): Add const. * mips-tdep.c (mips_single_step_through_delay): Likewise. * ppc-linux-tdep.c (ppu2spu_sniffer): Likewise. * record-full.c (record_full_wait_1): Likewise. * regcache.c (regcache::regcache): Change parameter to const. * regcache.h (regcache::regcache): Likewise. (regcache::aspace): Return const address_space *. (regcache) : Add const. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index ada72e0..98cedb4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -14572,7 +14572,7 @@ insert_single_step_breakpoints (struct gdbarch *gdb= arch) if (!next_pcs.empty ()) { struct frame_info *frame =3D get_current_frame (); - struct address_space *aspace =3D get_frame_address_space (frame); + const address_space *aspace =3D get_frame_address_space (frame); =20 for (CORE_ADDR pc : next_pcs) insert_single_step_breakpoint (gdbarch, aspace, pc); diff --git a/gdb/frame.c b/gdb/frame.c index 5380c7d..e40685f 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -99,7 +99,7 @@ struct frame_info struct program_space *pspace; =20 /* The frame's address space. */ - struct address_space *aspace; + const address_space *aspace; =20 /* The frame's low-level unwinder and corresponding cache. The low-level unwinder is responsible for unwinding register values @@ -1020,7 +1020,7 @@ do_frame_register_read (void *src, int regnum, gdb_by= te *buf) std::unique_ptr frame_save_as_regcache (struct frame_info *this_frame) { - struct address_space *aspace =3D get_frame_address_space (this_frame); + const address_space *aspace =3D get_frame_address_space (this_frame); std::unique_ptr regcache (new struct regcache (get_frame_arch (this_frame), aspace)); =20 @@ -2643,7 +2643,7 @@ frame_unwind_program_space (struct frame_info *this_f= rame) return this_frame->pspace; } =20 -struct address_space * +const address_space * get_frame_address_space (struct frame_info *frame) { return frame->aspace; diff --git a/gdb/frame.h b/gdb/frame.h index 190ce76..c751002 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -494,8 +494,10 @@ extern struct program_space *get_frame_program_space (= struct frame_info *); /* Unwind THIS frame's program space from the NEXT frame. */ extern struct program_space *frame_unwind_program_space (struct frame_info= *); =20 +class address_space; + /* Return the frame's address space. */ -extern struct address_space *get_frame_address_space (struct frame_info *); +extern const address_space *get_frame_address_space (struct frame_info *); =20 /* For frames where we can not unwind further, describe why. */ =20 diff --git a/gdb/infrun.c b/gdb/infrun.c index 0e31dbc..ef5a505 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1289,7 +1289,7 @@ struct step_over_info and address of the instruction the breakpoint is set at. We'll skip inserting all breakpoints here. Valid iff ASPACE is non-NULL. */ - struct address_space *aspace; + const address_space *aspace; CORE_ADDR address; =20 /* The instruction being stepped over triggers a nonsteppable @@ -1332,7 +1332,7 @@ static struct step_over_info step_over_info; because when we need the info later the thread may be running. */ =20 static void -set_step_over_info (struct address_space *aspace, CORE_ADDR address, +set_step_over_info (const address_space *aspace, CORE_ADDR address, int nonsteppable_watchpoint_p, int thread) { @@ -1760,7 +1760,7 @@ displaced_step_prepare_throw (ptid_t ptid) struct thread_info *tp =3D find_thread_ptid (ptid); struct regcache *regcache =3D get_thread_regcache (ptid); struct gdbarch *gdbarch =3D regcache->arch (); - struct address_space *aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); CORE_ADDR original, copy; ULONGEST len; struct displaced_step_closure *closure; @@ -2388,7 +2388,7 @@ resume (enum gdb_signal sig) struct gdbarch *gdbarch =3D regcache->arch (); struct thread_info *tp =3D inferior_thread (); CORE_ADDR pc =3D regcache_read_pc (regcache); - struct address_space *aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); ptid_t resume_ptid; /* This represents the user's step vs continue request. When deciding whether "set scheduler-locking step" applies, it's the @@ -2983,7 +2983,6 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) struct gdbarch *gdbarch; struct thread_info *tp; CORE_ADDR pc; - struct address_space *aspace; ptid_t resume_ptid; struct execution_control_state ecss; struct execution_control_state *ecs =3D &ecss; @@ -3007,7 +3006,8 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) =20 regcache =3D get_current_regcache (); gdbarch =3D regcache->arch (); - aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); + pc =3D regcache_read_pc (regcache); tp =3D inferior_thread (); =20 @@ -4070,7 +4070,6 @@ adjust_pc_after_break (struct thread_info *thread, { struct regcache *regcache; struct gdbarch *gdbarch; - struct address_space *aspace; CORE_ADDR breakpoint_pc, decr_pc; =20 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If @@ -4150,7 +4149,7 @@ adjust_pc_after_break (struct thread_info *thread, if (decr_pc =3D=3D 0) return; =20 - aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); =20 /* Find the location where (if we've hit a breakpoint) the breakpoint would be. */ @@ -4385,7 +4384,6 @@ static void save_waitstatus (struct thread_info *tp, struct target_waitstatus *ws) { struct regcache *regcache; - struct address_space *aspace; =20 if (debug_infrun) { @@ -4404,7 +4402,7 @@ save_waitstatus (struct thread_info *tp, struct targe= t_waitstatus *ws) tp->suspend.waitstatus_pending_p =3D 1; =20 regcache =3D get_thread_regcache (tp->ptid); - aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); =20 if (ws->kind =3D=3D TARGET_WAITKIND_STOPPED && ws->value.sig =3D=3D GDB_SIGNAL_TRAP) @@ -5776,11 +5774,11 @@ handle_signal_stop (struct execution_control_state = *ecs) if (ecs->event_thread->suspend.stop_signal =3D=3D GDB_SIGNAL_TRAP) { struct regcache *regcache; - struct address_space *aspace; CORE_ADDR pc; =20 regcache =3D get_thread_regcache (ecs->ptid); - aspace =3D regcache->aspace (); + const address_space *aspace =3D regcache->aspace (); + pc =3D regcache_read_pc (regcache); =20 /* However, before doing so, if this single-step breakpoint was @@ -5871,7 +5869,7 @@ handle_signal_stop (struct execution_control_state *e= cs) inline function call sites). */ if (ecs->event_thread->control.step_range_end !=3D 1) { - struct address_space *aspace =3D=20 + const address_space *aspace =3D get_thread_regcache (ecs->ptid)->aspace (); =20 /* skip_inline_frames is expensive, so we avoid it if we can diff --git a/gdb/jit.c b/gdb/jit.c index a2d1f6d..b70f87c 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -1186,7 +1186,6 @@ jit_frame_sniffer (const struct frame_unwind *self, struct jit_unwind_private *priv_data; struct gdb_unwind_callbacks callbacks; struct gdb_reader_funcs *funcs; - struct address_space *aspace; struct gdbarch *gdbarch; =20 callbacks.reg_get =3D jit_unwind_reg_get_impl; @@ -1200,7 +1199,8 @@ jit_frame_sniffer (const struct frame_unwind *self, =20 gdb_assert (!*cache); =20 - aspace =3D get_frame_address_space (this_frame); + const address_space *aspace =3D get_frame_address_space (this_frame); + gdbarch =3D get_frame_arch (this_frame); =20 *cache =3D XCNEW (struct jit_unwind_private); diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 4b19896..20bd5d3 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -6598,7 +6598,6 @@ mips_single_step_through_delay (struct gdbarch *gdbar= ch, { enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); CORE_ADDR pc =3D get_frame_pc (frame); - struct address_space *aspace; enum mips_isa isa; ULONGEST insn; int status; @@ -6616,7 +6615,9 @@ mips_single_step_through_delay (struct gdbarch *gdbar= ch, /* _has_delay_slot above will have validated the read. */ insn =3D mips_fetch_instruction (gdbarch, isa, pc, NULL); size =3D mips_insn_size (isa, insn); - aspace =3D get_frame_address_space (frame); + + const address_space *aspace =3D get_frame_address_space (frame); + return breakpoint_here_p (aspace, pc + size) !=3D no_breakpoint_here; } =20 diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 67d8305..d01cff8 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1362,7 +1362,7 @@ ppu2spu_sniffer (const struct frame_unwind *self, struct ppu2spu_cache *cache =3D FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); =20 - struct address_space *aspace =3D get_frame_address_space (this_frame); + const address_space *aspace =3D get_frame_address_space (this_frame); std::unique_ptr regcache (new struct regcache (data.gdbarch, aspace)); regcache_save (regcache.get (), ppu2spu_unwind_register, &data); diff --git a/gdb/record-full.c b/gdb/record-full.c index 0488b71..6fc29d6 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -1098,7 +1098,6 @@ record_full_wait_1 (struct target_ops *ops, && status->value.sig =3D=3D GDB_SIGNAL_TRAP) { struct regcache *regcache; - struct address_space *aspace; enum target_stop_reason *stop_reason_p =3D &record_full_stop_reason; =20 @@ -1109,7 +1108,7 @@ record_full_wait_1 (struct target_ops *ops, registers_changed (); regcache =3D get_current_regcache (); tmp_pc =3D regcache_read_pc (regcache); - aspace =3D regcache->aspace (); + const struct address_space *aspace =3D regcache->aspace (); =20 if (target_stopped_by_watchpoint ()) { @@ -1172,7 +1171,7 @@ record_full_wait_1 (struct target_ops *ops, { struct regcache *regcache =3D get_current_regcache (); struct gdbarch *gdbarch =3D regcache->arch (); - struct address_space *aspace =3D regcache->aspace (); + const struct address_space *aspace =3D regcache->aspace (); int continue_flag =3D 1; int first_record_full_end =3D 1; struct cleanup *old_cleanups diff --git a/gdb/regcache.c b/gdb/regcache.c index 6985dc9..2cffb70 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -181,7 +181,7 @@ regcache_register_size (const struct regcache *regcache= , int n) return register_size (regcache->arch (), n); } =20 -regcache::regcache (gdbarch *gdbarch, address_space *aspace_, +regcache::regcache (gdbarch *gdbarch, const address_space *aspace_, bool readonly_p_) : m_aspace (aspace_), m_readonly_p (readonly_p_) { diff --git a/gdb/regcache.h b/gdb/regcache.h index 2360e27..cea76fb 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -232,7 +232,7 @@ typedef struct cached_reg class regcache { public: - regcache (gdbarch *gdbarch, address_space *aspace_) + regcache (gdbarch *gdbarch, const address_space *aspace_) : regcache (gdbarch, aspace_, true) {} =20 @@ -254,7 +254,7 @@ public: gdbarch *arch () const; =20 /* Return REGCACHE's address space. */ - address_space *aspace () const + const address_space *aspace () const { return m_aspace; } @@ -338,7 +338,7 @@ public: =20 static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_pt= id); protected: - regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_); + regcache (gdbarch *gdbarch, const address_space *aspace_, bool readonly_= p_); =20 static std::forward_list current_regcache; =20 @@ -362,7 +362,7 @@ private: =20 /* The address space of this register cache (for registers where it makes sense, like PC or SP). */ - struct address_space *m_aspace; + const address_space * const m_aspace; =20 /* The register buffers. A read-only register cache can hold the full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/w= rite