From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id F3CD7385841D for ; Mon, 22 Nov 2021 16:28:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F3CD7385841D X-ASG-Debug-ID: 1637598452-0c856e2e46238460001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id IiDyBwrBplWtT2ot (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Nov 2021 11:27:32 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 3D719441D65; Mon, 22 Nov 2021 11:27:32 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/3] gdb: pass more const target_waitstatus by reference Date: Mon, 22 Nov 2021 11:27:31 -0500 X-ASG-Orig-Subj: [PATCH 3/3] gdb: pass more const target_waitstatus by reference Message-Id: <20211122162731.3316783-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211122162731.3316783-1-simon.marchi@efficios.com> References: <20211122162731.3316783-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1637598452 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 36333 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.94135 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-19.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2021 16:28:23 -0000 While working on target_waitstatus changes, I noticed a few places where const target_waitstatus objects could be passed by reference instead of by pointers. And in some cases, places where a target_waitstatus could be passed as const, but was not. Convert them as much as possible. Change-Id: Ied552d464be5d5b87489913b95f9720a5ad50c5a --- gdb/break-catch-sig.c | 6 ++-- gdb/break-catch-syscall.c | 8 ++--- gdb/breakpoint.c | 52 ++++++++++++++++---------------- gdb/breakpoint.h | 10 +++---- gdb/infrun.c | 62 +++++++++++++++++++-------------------- gdb/infrun.h | 2 +- gdb/remote.c | 36 +++++++++++------------ gdbserver/remote-utils.cc | 45 ++++++++++++++-------------- gdbserver/remote-utils.h | 2 +- gdbserver/server.cc | 26 ++++++++-------- 10 files changed, 124 insertions(+), 125 deletions(-) diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c index 0998aa95c4f..7fe35dcdb0c 100644 --- a/gdb/break-catch-sig.c +++ b/gdb/break-catch-sig.c @@ -149,16 +149,16 @@ static int signal_catchpoint_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { const struct signal_catchpoint *c = (const struct signal_catchpoint *) bl->owner; gdb_signal signal_number; - if (ws->kind () != TARGET_WAITKIND_STOPPED) + if (ws.kind () != TARGET_WAITKIND_STOPPED) return 0; - signal_number = ws->sig (); + signal_number = ws.sig (); /* If we are catching specific signals in this breakpoint, then we must guarantee that the called signal is the same signal we are diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index cb2d77643ca..02123736ff4 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -143,7 +143,7 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason) static int breakpoint_hit_catch_syscall (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { /* We must check if we are catching specific syscalls in this breakpoint. If we are, then we must guarantee that the called @@ -152,11 +152,11 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl, const struct syscall_catchpoint *c = (const struct syscall_catchpoint *) bl->owner; - if (ws->kind () != TARGET_WAITKIND_SYSCALL_ENTRY - && ws->kind () != TARGET_WAITKIND_SYSCALL_RETURN) + if (ws.kind () != TARGET_WAITKIND_SYSCALL_ENTRY + && ws.kind () != TARGET_WAITKIND_SYSCALL_RETURN) return 0; - syscall_number = ws->syscall_number (); + syscall_number = ws.syscall_number (); /* Now, checking if the syscall is the same. */ if (!c->syscalls_to_be_caught.empty ()) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d98c3a7cf0f..b1eae3af634 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4771,7 +4771,7 @@ bpstat::bpstat () watchpoints have triggered, according to the target. */ int -watchpoints_triggered (struct target_waitstatus *ws) +watchpoints_triggered (const target_waitstatus &ws) { bool stopped_by_watchpoint = target_stopped_by_watchpoint (); CORE_ADDR addr; @@ -5014,7 +5014,7 @@ watchpoint_check (bpstat *bs) static int bpstat_check_location (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct breakpoint *b = bl->owner; @@ -5349,7 +5349,7 @@ need_moribund_for_location_type (struct bp_location *loc) bpstat * build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { bpstat *bs_head = nullptr, **bs_link = &bs_head; @@ -5425,7 +5425,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, bpstat * bpstat_stop_status (const address_space *aspace, CORE_ADDR bp_addr, thread_info *thread, - const struct target_waitstatus *ws, + const target_waitstatus &ws, bpstat *stop_chain) { struct breakpoint *b = NULL; @@ -7760,14 +7760,14 @@ remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) static int breakpoint_hit_catch_fork (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; - if (ws->kind () != TARGET_WAITKIND_FORKED) + if (ws.kind () != TARGET_WAITKIND_FORKED) return 0; - c->forked_inferior_pid = ws->child_ptid (); + c->forked_inferior_pid = ws.child_ptid (); return 1; } @@ -7876,14 +7876,14 @@ remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) static int breakpoint_hit_catch_vfork (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; - if (ws->kind () != TARGET_WAITKIND_VFORKED) + if (ws.kind () != TARGET_WAITKIND_VFORKED) return 0; - c->forked_inferior_pid = ws->child_ptid (); + c->forked_inferior_pid = ws.child_ptid (); return 1; } @@ -7998,11 +7998,11 @@ static int breakpoint_hit_catch_solib (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; - if (ws->kind () == TARGET_WAITKIND_LOADED) + if (ws.kind () == TARGET_WAITKIND_LOADED) return 1; for (breakpoint *other : all_breakpoints ()) @@ -8274,14 +8274,14 @@ remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) static int breakpoint_hit_catch_exec (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; - if (ws->kind () != TARGET_WAITKIND_EXECD) + if (ws.kind () != TARGET_WAITKIND_EXECD) return 0; - c->exec_pathname = make_unique_xstrdup (ws->execd_pathname ()); + c->exec_pathname = make_unique_xstrdup (ws.execd_pathname ()); return 1; } @@ -9781,10 +9781,10 @@ static int breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { - if (ws->kind () != TARGET_WAITKIND_STOPPED - || ws->sig () != GDB_SIGNAL_TRAP) + if (ws.kind () != TARGET_WAITKIND_STOPPED + || ws.sig () != GDB_SIGNAL_TRAP) return 0; return breakpoint_address_match_range (bl->pspace->aspace, bl->address, @@ -10125,7 +10125,7 @@ remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) static int breakpoint_hit_watchpoint (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { struct breakpoint *b = bl->owner; struct watchpoint *w = (struct watchpoint *) b; @@ -12280,7 +12280,7 @@ static int base_breakpoint_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { internal_error_pure_virtual_called (); } @@ -12447,10 +12447,10 @@ bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) static int bkpt_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { - if (ws->kind () != TARGET_WAITKIND_STOPPED - || ws->sig () != GDB_SIGNAL_TRAP) + if (ws.kind () != TARGET_WAITKIND_STOPPED + || ws.sig () != GDB_SIGNAL_TRAP) return 0; if (!breakpoint_address_match (bl->pspace->aspace, bl->address, @@ -12468,7 +12468,7 @@ bkpt_breakpoint_hit (const struct bp_location *bl, static int dprintf_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { if (dprintf_style == dprintf_style_agent && target_can_run_breakpoint_commands ()) @@ -12822,7 +12822,7 @@ tracepoint_re_set (struct breakpoint *b) static int tracepoint_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { /* By definition, the inferior does not report stops at tracepoints. */ @@ -15194,7 +15194,7 @@ is_non_inline_function (struct breakpoint *b) int pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, - const struct target_waitstatus *ws) + const target_waitstatus &ws) { for (breakpoint *b : all_breakpoints ()) { diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index c9048d33816..1704d6a3fd7 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -587,7 +587,7 @@ struct breakpoint_ops int (*breakpoint_hit) (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws); + const target_waitstatus &ws); /* Check internal conditions of the breakpoint referred to by BS. If we should not stop for this breakpoint, set BS->stop to 0. */ @@ -948,7 +948,7 @@ extern bpstat *bpstat_copy (bpstat *); extern bpstat *build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, - const struct target_waitstatus *ws); + const target_waitstatus &ws); /* Get a bpstat associated with having just stopped at address BP_ADDR in thread PTID. STOP_CHAIN may be supplied as a previously @@ -972,7 +972,7 @@ extern bpstat *build_bpstat_chain (const address_space *aspace, extern bpstat *bpstat_stop_status (const address_space *aspace, CORE_ADDR pc, thread_info *thread, - const struct target_waitstatus *ws, + const target_waitstatus &ws, bpstat *stop_chain = nullptr); /* This bpstat_what stuff tells wait_for_inferior what to do with a @@ -1609,7 +1609,7 @@ extern int insert_single_step_breakpoints (struct gdbarch *); /* Check if any hardware watchpoints have triggered, according to the target. */ -int watchpoints_triggered (struct target_waitstatus *); +int watchpoints_triggered (const target_waitstatus &); /* Helper for transparent breakpoint hiding for memory read and write routines. @@ -1745,7 +1745,7 @@ const std::vector &all_bp_locations (); extern int pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, - const struct target_waitstatus *ws); + const target_waitstatus &ws); extern int user_breakpoint_p (struct breakpoint *); diff --git a/gdb/infrun.c b/gdb/infrun.c index dba4f33a327..e4739ed14f6 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3470,7 +3470,7 @@ delete_just_stopped_threads_single_step_breakpoints (void) void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, - const struct target_waitstatus *ws) + const struct target_waitstatus &ws) { infrun_debug_printf ("target_wait (%s [%s], status) =", waiton_ptid.to_string ().c_str (), @@ -3478,7 +3478,7 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, infrun_debug_printf (" %s [%s],", result_ptid.to_string ().c_str (), target_pid_to_str (result_ptid).c_str ()); - infrun_debug_printf (" %s", ws->to_string ().c_str ()); + infrun_debug_printf (" %s", ws.to_string ().c_str ()); } /* Select a thread at random, out of those which are resumed and have @@ -3833,7 +3833,7 @@ prepare_for_detach (void) event.ptid = do_target_wait_1 (inf, pid_ptid, &event.ws, 0); if (debug_infrun) - print_target_wait_results (pid_ptid, event.ptid, &event.ws); + print_target_wait_results (pid_ptid, event.ptid, event.ws); handle_one (event); } @@ -3880,7 +3880,7 @@ wait_for_inferior (inferior *inf) ecs->target = inf->process_target (); if (debug_infrun) - print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws); + print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws); /* Now figure out what to do with the result of the result. */ handle_inferior_event (ecs); @@ -4070,7 +4070,7 @@ fetch_inferior_event () switch_to_target_no_thread (ecs->target); if (debug_infrun) - print_target_wait_results (minus_one_ptid, ecs->ptid, &ecs->ws); + print_target_wait_results (minus_one_ptid, ecs->ptid, ecs->ws); /* If an error happens while handling the event, propagate GDB's knowledge of the executing state to the frontend/user running @@ -4257,7 +4257,7 @@ context_switch (execution_control_state *ecs) static void adjust_pc_after_break (struct thread_info *thread, - const target_waitstatus *ws) + const target_waitstatus &ws) { struct regcache *regcache; struct gdbarch *gdbarch; @@ -4284,10 +4284,10 @@ adjust_pc_after_break (struct thread_info *thread, target with both of these set in GDB history, and it seems unlikely to be correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ - if (ws->kind () != TARGET_WAITKIND_STOPPED) + if (ws.kind () != TARGET_WAITKIND_STOPPED) return; - if (ws->sig () != GDB_SIGNAL_TRAP) + if (ws.sig () != GDB_SIGNAL_TRAP) return; /* In reverse execution, when a breakpoint is hit, the instruction @@ -4494,7 +4494,7 @@ handle_syscall_event (struct execution_control_state *ecs) ecs->event_thread->control.stop_bpstat = bpstat_stop_status (regcache->aspace (), ecs->event_thread->stop_pc (), - ecs->event_thread, &ecs->ws); + ecs->event_thread, ecs->ws); if (handle_stop_requested (ecs)) return false; @@ -4593,7 +4593,7 @@ poll_one_curr_target (struct target_waitstatus *ws) event_ptid = target_wait (minus_one_ptid, ws, TARGET_WNOHANG); if (debug_infrun) - print_target_wait_results (minus_one_ptid, event_ptid, ws); + print_target_wait_results (minus_one_ptid, event_ptid, *ws); return event_ptid; } @@ -4674,23 +4674,23 @@ wait_one () /* Save the thread's event and stop reason to process it later. */ static void -save_waitstatus (struct thread_info *tp, const target_waitstatus *ws) +save_waitstatus (struct thread_info *tp, const target_waitstatus &ws) { infrun_debug_printf ("saving status %s for %s", - ws->to_string ().c_str (), + ws.to_string ().c_str (), tp->ptid.to_string ().c_str ()); /* Record for later. */ - tp->set_pending_waitstatus (*ws); + tp->set_pending_waitstatus (ws); - if (ws->kind () == TARGET_WAITKIND_STOPPED - && ws->sig () == GDB_SIGNAL_TRAP) + if (ws.kind () == TARGET_WAITKIND_STOPPED + && ws.sig () == GDB_SIGNAL_TRAP) { struct regcache *regcache = get_thread_regcache (tp); const address_space *aspace = regcache->aspace (); CORE_ADDR pc = regcache_read_pc (regcache); - adjust_pc_after_break (tp, &tp->pending_waitstatus ()); + adjust_pc_after_break (tp, tp->pending_waitstatus ()); scoped_restore_current_thread restore_thread; switch_to_thread (tp); @@ -4824,7 +4824,7 @@ handle_one (const wait_one_event &event) switch_to_thread_no_regs (t); mark_non_executing_threads (event.target, event.ptid, event.ws); - save_waitstatus (t, &event.ws); + save_waitstatus (t, event.ws); t->stop_requested = false; } } @@ -4878,7 +4878,7 @@ handle_one (const wait_one_event &event) t->ptid.to_string ().c_str ()); /* Record for later. */ - save_waitstatus (t, &event.ws); + save_waitstatus (t, event.ws); sig = (event.ws.kind () == TARGET_WAITKIND_STOPPED ? event.ws.sig () : GDB_SIGNAL_0); @@ -5236,7 +5236,7 @@ handle_inferior_event (struct execution_control_state *ecs) } /* Dependent on valid ECS->EVENT_THREAD. */ - adjust_pc_after_break (ecs->event_thread, &ecs->ws); + adjust_pc_after_break (ecs->event_thread, ecs->ws); /* Dependent on the current PC value modified by adjust_pc_after_break. */ reinit_frame_cache (); @@ -5295,7 +5295,7 @@ handle_inferior_event (struct execution_control_state *ecs) ecs->event_thread->control.stop_bpstat = bpstat_stop_status (regcache->aspace (), ecs->event_thread->stop_pc (), - ecs->event_thread, &ecs->ws); + ecs->event_thread, ecs->ws); if (handle_stop_requested (ecs)) return; @@ -5538,7 +5538,7 @@ handle_inferior_event (struct execution_control_state *ecs) ecs->event_thread->control.stop_bpstat = bpstat_stop_status (get_current_regcache ()->aspace (), ecs->event_thread->stop_pc (), - ecs->event_thread, &ecs->ws); + ecs->event_thread, ecs->ws); if (handle_stop_requested (ecs)) return; @@ -5649,7 +5649,7 @@ handle_inferior_event (struct execution_control_state *ecs) ecs->event_thread->control.stop_bpstat = bpstat_stop_status (get_current_regcache ()->aspace (), ecs->event_thread->stop_pc (), - ecs->event_thread, &ecs->ws); + ecs->event_thread, ecs->ws); if (handle_stop_requested (ecs)) return; @@ -5886,7 +5886,7 @@ finish_step_over (struct execution_control_state *ecs) gdb_assert (pending != tp); /* Record the event thread's event for later. */ - save_waitstatus (tp, &ecs->ws); + save_waitstatus (tp, ecs->ws); /* This was cleared early, by handle_inferior_event. Set it so this pending event is considered by do_target_wait. */ @@ -6061,7 +6061,7 @@ handle_signal_stop (struct execution_control_state *ecs) && ecs->event_thread->stepping_over_watchpoint) stopped_by_watchpoint = 0; else - stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); + stopped_by_watchpoint = watchpoints_triggered (ecs->ws); /* If necessary, step over this watchpoint. We'll be back to display it in a moment. */ @@ -6134,16 +6134,16 @@ handle_signal_stop (struct execution_control_state *ecs) that's an extremely unlikely scenario. */ if (!pc_at_non_inline_function (aspace, ecs->event_thread->stop_pc (), - &ecs->ws) + ecs->ws) && !(ecs->event_thread->stop_signal () == GDB_SIGNAL_TRAP && ecs->event_thread->control.trap_expected && pc_at_non_inline_function (aspace, ecs->event_thread->prev_pc, - &ecs->ws))) + ecs->ws))) { stop_chain = build_bpstat_chain (aspace, ecs->event_thread->stop_pc (), - &ecs->ws); + ecs->ws); skip_inline_frames (ecs->event_thread, stop_chain); /* Re-fetch current thread's frame in case that invalidated @@ -6195,7 +6195,7 @@ handle_signal_stop (struct execution_control_state *ecs) ecs->event_thread->control.stop_bpstat = bpstat_stop_status (get_current_regcache ()->aspace (), ecs->event_thread->stop_pc (), - ecs->event_thread, &ecs->ws, stop_chain); + ecs->event_thread, ecs->ws, stop_chain); /* Following in case break condition called a function. */ @@ -8258,14 +8258,14 @@ print_no_history_reason (struct ui_out *uiout) based on the event(s) that just occurred. */ static void -print_stop_location (struct target_waitstatus *ws) +print_stop_location (const target_waitstatus &ws) { int bpstat_ret; enum print_what source_flag; int do_frame_printing = 1; struct thread_info *tp = inferior_thread (); - bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind ()); + bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws.kind ()); switch (bpstat_ret) { case PRINT_UNKNOWN: @@ -8325,7 +8325,7 @@ print_stop_event (struct ui_out *uiout, bool displays) { scoped_restore save_uiout = make_scoped_restore (¤t_uiout, uiout); - print_stop_location (&last); + print_stop_location (last); /* Display the auto-display expressions. */ if (displays) diff --git a/gdb/infrun.h b/gdb/infrun.h index c5f98d9d305..644e57f0bca 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -209,7 +209,7 @@ extern void print_stop_event (struct ui_out *uiout, bool displays = true); /* Pretty print the results of target_wait, for debugging purposes. */ extern void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, - const struct target_waitstatus *ws); + const struct target_waitstatus &ws); extern int signal_stop_state (int); diff --git a/gdb/remote.c b/gdb/remote.c index 61bde5aaa94..724386e0916 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -762,7 +762,7 @@ class remote_target : public process_stratum_target target_waitstatus *status); ptid_t select_thread_for_ambiguous_stop_reply - (const struct target_waitstatus *status); + (const struct target_waitstatus &status); void remote_notice_new_inferior (ptid_t currthread, bool executing); @@ -4542,7 +4542,7 @@ remote_target::process_initial_stop_replies (int from_tty) event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG); if (remote_debug) - print_target_wait_results (waiton_ptid, event_ptid, &ws); + print_target_wait_results (waiton_ptid, event_ptid, ws); switch (ws.kind ()) { @@ -7224,11 +7224,11 @@ struct notif_client notif_client_stop = -1 if we want to check all threads. */ static int -is_pending_fork_parent (const target_waitstatus *ws, int event_pid, +is_pending_fork_parent (const target_waitstatus &ws, int event_pid, ptid_t thread_ptid) { - if (ws->kind () == TARGET_WAITKIND_FORKED - || ws->kind () == TARGET_WAITKIND_VFORKED) + if (ws.kind () == TARGET_WAITKIND_FORKED + || ws.kind () == TARGET_WAITKIND_VFORKED) { if (event_pid == -1 || event_pid == thread_ptid.pid ()) return 1; @@ -7240,13 +7240,13 @@ is_pending_fork_parent (const target_waitstatus *ws, int event_pid, /* Return the thread's pending status used to determine whether the thread is a fork parent stopped at a fork event. */ -static const target_waitstatus * +static const target_waitstatus & thread_pending_fork_status (struct thread_info *thread) { if (thread->has_pending_waitstatus ()) - return &thread->pending_waitstatus (); + return thread->pending_waitstatus (); else - return &thread->pending_follow; + return thread->pending_follow; } /* Determine if THREAD is a pending fork parent thread. */ @@ -7254,7 +7254,7 @@ thread_pending_fork_status (struct thread_info *thread) static int is_pending_fork_parent_thread (struct thread_info *thread) { - const target_waitstatus *ws = thread_pending_fork_status (thread); + const target_waitstatus &ws = thread_pending_fork_status (thread); int pid = -1; return is_pending_fork_parent (ws, pid, thread->ptid); @@ -7276,10 +7276,10 @@ remote_target::remove_new_fork_children (threads_listing_context *context) fork child threads from the CONTEXT list. */ for (thread_info *thread : all_non_exited_threads (this)) { - const target_waitstatus *ws = thread_pending_fork_status (thread); + const target_waitstatus &ws = thread_pending_fork_status (thread); if (is_pending_fork_parent (ws, pid, thread->ptid)) - context->remove_thread (ws->child_ptid ()); + context->remove_thread (ws.child_ptid ()); } /* Check for any pending fork events (not reported or processed yet) @@ -7940,15 +7940,15 @@ remote_notif_get_pending_events (remote_target *remote, notif_client *nc) ptid_t remote_target::select_thread_for_ambiguous_stop_reply - (const struct target_waitstatus *status) + (const target_waitstatus &status) { REMOTE_SCOPED_DEBUG_ENTER_EXIT; /* Some stop events apply to all threads in an inferior, while others only apply to a single thread. */ bool process_wide_stop - = (status->kind () == TARGET_WAITKIND_EXITED - || status->kind () == TARGET_WAITKIND_SIGNALLED); + = (status.kind () == TARGET_WAITKIND_EXITED + || status.kind () == TARGET_WAITKIND_SIGNALLED); remote_debug_printf ("process_wide_stop = %d", process_wide_stop); @@ -8030,7 +8030,7 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, /* If no thread/process was reported by the stub then select a suitable thread/process. */ if (ptid == null_ptid) - ptid = select_thread_for_ambiguous_stop_reply (status); + ptid = select_thread_for_ambiguous_stop_reply (*status); gdb_assert (ptid != null_ptid); if (status->kind () != TARGET_WAITKIND_EXITED @@ -10056,11 +10056,11 @@ remote_target::kill_new_fork_children (int pid) that are stopped at a fork event. */ for (thread_info *thread : all_non_exited_threads (this)) { - struct target_waitstatus *ws = &thread->pending_follow; + const target_waitstatus &ws = thread->pending_follow; if (is_pending_fork_parent (ws, pid, thread->ptid)) { - int child_pid = ws->child_ptid ().pid (); + int child_pid = ws.child_ptid ().pid (); int res; res = remote_vkill (child_pid); @@ -10073,7 +10073,7 @@ remote_target::kill_new_fork_children (int pid) in process PID and kill those fork child threads as well. */ remote_notif_get_pending_events (notif); for (auto &event : rs->stop_reply_queue) - if (is_pending_fork_parent (&event->ws, pid, event->ptid)) + if (is_pending_fork_parent (event->ws, pid, event->ptid)) { int child_pid = event->ws.child_ptid ().pid (); int res; diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index 5bc261a9c7b..8202365350a 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1081,15 +1081,14 @@ outreg (struct regcache *regcache, int regno, char *buf) } void -prepare_resume_reply (char *buf, ptid_t ptid, - struct target_waitstatus *status) +prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status) { client_state &cs = get_client_state (); if (debug_threads) debug_printf ("Writing resume reply for %s:%d\n", - target_pid_to_str (ptid).c_str (), status->kind ()); + target_pid_to_str (ptid).c_str (), status.kind ()); - switch (status->kind ()) + switch (status.kind ()) { case TARGET_WAITKIND_STOPPED: case TARGET_WAITKIND_FORKED: @@ -1104,27 +1103,27 @@ prepare_resume_reply (char *buf, ptid_t ptid, const char **regp; struct regcache *regcache; - if ((status->kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events) - || (status->kind () == TARGET_WAITKIND_VFORKED + if ((status.kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events) + || (status.kind () == TARGET_WAITKIND_VFORKED && cs.report_vfork_events)) { enum gdb_signal signal = GDB_SIGNAL_TRAP; - const char *event = (status->kind () == TARGET_WAITKIND_FORKED + const char *event = (status.kind () == TARGET_WAITKIND_FORKED ? "fork" : "vfork"); sprintf (buf, "T%02x%s:", signal, event); buf += strlen (buf); - buf = write_ptid (buf, status->child_ptid ()); + buf = write_ptid (buf, status.child_ptid ()); strcat (buf, ";"); } - else if (status->kind () == TARGET_WAITKIND_VFORK_DONE + else if (status.kind () == TARGET_WAITKIND_VFORK_DONE && cs.report_vfork_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; sprintf (buf, "T%02xvforkdone:;", signal); } - else if (status->kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events) + else if (status.kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; const char *event = "exec"; @@ -1134,32 +1133,32 @@ prepare_resume_reply (char *buf, ptid_t ptid, buf += strlen (buf); /* Encode pathname to hexified format. */ - bin2hex ((const gdb_byte *) status->execd_pathname (), + bin2hex ((const gdb_byte *) status.execd_pathname (), hexified_pathname, - strlen (status->execd_pathname ())); + strlen (status.execd_pathname ())); sprintf (buf, "%s;", hexified_pathname); buf += strlen (buf); } - else if (status->kind () == TARGET_WAITKIND_THREAD_CREATED + else if (status.kind () == TARGET_WAITKIND_THREAD_CREATED && cs.report_thread_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; sprintf (buf, "T%02xcreate:;", signal); } - else if (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY - || status->kind () == TARGET_WAITKIND_SYSCALL_RETURN) + else if (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY + || status.kind () == TARGET_WAITKIND_SYSCALL_RETURN) { enum gdb_signal signal = GDB_SIGNAL_TRAP; - const char *event = (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY + const char *event = (status.kind () == TARGET_WAITKIND_SYSCALL_ENTRY ? "syscall_entry" : "syscall_return"); sprintf (buf, "T%02x%s:%x;", signal, event, - status->syscall_number ()); + status.syscall_number ()); } else - sprintf (buf, "T%02x", status->sig ()); + sprintf (buf, "T%02x", status.sig ()); if (disable_packet_T) { @@ -1281,19 +1280,19 @@ prepare_resume_reply (char *buf, ptid_t ptid, case TARGET_WAITKIND_EXITED: if (cs.multi_process) sprintf (buf, "W%x;process:%x", - status->exit_status (), ptid.pid ()); + status.exit_status (), ptid.pid ()); else - sprintf (buf, "W%02x", status->exit_status ()); + sprintf (buf, "W%02x", status.exit_status ()); break; case TARGET_WAITKIND_SIGNALLED: if (cs.multi_process) sprintf (buf, "X%x;process:%x", - status->sig (), ptid.pid ()); + status.sig (), ptid.pid ()); else - sprintf (buf, "X%02x", status->sig ()); + sprintf (buf, "X%02x", status.sig ()); break; case TARGET_WAITKIND_THREAD_EXITED: - sprintf (buf, "w%x;", status->exit_status ()); + sprintf (buf, "w%x;", status.exit_status ()); buf += strlen (buf); buf = write_ptid (buf, ptid); break; diff --git a/gdbserver/remote-utils.h b/gdbserver/remote-utils.h index 25074bcc2b9..b856862d367 100644 --- a/gdbserver/remote-utils.h +++ b/gdbserver/remote-utils.h @@ -41,7 +41,7 @@ void enable_async_io (void); void disable_async_io (void); void check_remote_input_interrupt_request (void); void prepare_resume_reply (char *buf, ptid_t ptid, - struct target_waitstatus *status); + const target_waitstatus &status); const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start); void decode_address (CORE_ADDR *addrp, const char *start, int len); diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 2807525d11c..b1d4c92b3d9 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -173,12 +173,12 @@ get_client_state () /* Put a stop reply to the stop reply queue. */ static void -queue_stop_reply (ptid_t ptid, struct target_waitstatus *status) +queue_stop_reply (ptid_t ptid, const target_waitstatus &status) { struct vstop_notif *new_notif = new struct vstop_notif; new_notif->ptid = ptid; - new_notif->status = *status; + new_notif->status = status; notif_event_enque (¬if_stop, new_notif); } @@ -225,7 +225,7 @@ vstop_notif_reply (struct notif_event *event, char *own_buf) { struct vstop_notif *vstop = (struct vstop_notif *) event; - prepare_resume_reply (own_buf, vstop->ptid, &vstop->status); + prepare_resume_reply (own_buf, vstop->ptid, vstop->status); } /* Helper for in_queued_stop_replies. */ @@ -2795,7 +2795,7 @@ handle_pending_status (const struct thread_resume *resumption, cs.last_status = thread->last_status; cs.last_ptid = thread->id; - prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status); + prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status); return 1; } return 0; @@ -2963,7 +2963,7 @@ resume (struct thread_resume *actions, size_t num_actions) so by now). Tag all threads as "want-stopped", so we don't resume them implicitly without the client telling us to. */ gdb_wants_all_threads_stopped (); - prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status); + prepare_resume_reply (cs.own_buf, cs.last_ptid, cs.last_status); disable_async_io (); if (cs.last_status.kind () == TARGET_WAITKIND_EXITED @@ -2996,7 +2996,7 @@ handle_v_attach (char *own_buf) write_ok (own_buf); } else - prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status); + prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status); } else write_enn (own_buf); @@ -3114,7 +3114,7 @@ handle_v_run (char *own_buf) if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED) { - prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status); + prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status); /* In non-stop, sending a resume reply doesn't set the general thread, but GDB assumes a vRun sets it (this is so GDB can @@ -3313,7 +3313,7 @@ queue_stop_reply_callback (thread_info *thread) /* Pass the last stop reply back to GDB, but don't notify yet. */ - queue_stop_reply (thread->id, &thread->last_status); + queue_stop_reply (thread->id, thread->last_status); } } } @@ -3436,7 +3436,7 @@ handle_status (char *own_buf) set_desired_thread (); gdb_assert (tp->last_status.kind () != TARGET_WAITKIND_IGNORE); - prepare_resume_reply (own_buf, tp->id, &tp->last_status); + prepare_resume_reply (own_buf, tp->id, tp->last_status); } else strcpy (own_buf, "W00"); @@ -4562,11 +4562,11 @@ handle_serial_event (int err, gdb_client_data client_data) /* Push a stop notification on the notification queue. */ static void -push_stop_notification (ptid_t ptid, struct target_waitstatus *status) +push_stop_notification (ptid_t ptid, const target_waitstatus &status) { struct vstop_notif *vstop_notif = new struct vstop_notif; - vstop_notif->status = *status; + vstop_notif->status = status; vstop_notif->ptid = ptid; /* Push Stop notification. */ notif_push (¬if_stop, vstop_notif); @@ -4587,7 +4587,7 @@ handle_target_event (int err, gdb_client_data client_data) if (cs.last_status.kind () == TARGET_WAITKIND_NO_RESUMED) { if (gdb_connected () && report_no_resumed) - push_stop_notification (null_ptid, &cs.last_status); + push_stop_notification (null_ptid, cs.last_status); } else if (cs.last_status.kind () != TARGET_WAITKIND_IGNORE) { @@ -4645,7 +4645,7 @@ handle_target_event (int err, gdb_client_data client_data) } } else - push_stop_notification (cs.last_ptid, &cs.last_status); + push_stop_notification (cs.last_ptid, cs.last_status); } /* Be sure to not change the selected thread behind GDB's back. -- 2.33.1