From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 0748338618D7; Fri, 24 Jun 2022 11:05:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0748338618D7 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: make use of RAII in run_inferior_call X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 39b8a8090ed7e8967ceca3655aa5f3a2ae91219d X-Git-Newrev: a32c1a92d5d5a8ed32cb30b161daedb1aca72cb4 Message-Id: <20220624110501.0748338618D7@sourceware.org> Date: Fri, 24 Jun 2022 11:05:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 11:05:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da32c1a92d5d5= a8ed32cb30b161daedb1aca72cb4 commit a32c1a92d5d5a8ed32cb30b161daedb1aca72cb4 Author: Andrew Burgess Date: Sat May 14 10:35:54 2022 +0100 gdb: make use of RAII in run_inferior_call =20 In passing I noticed that there are three local variables in run_inferior_call that are used to save, and then restore some state, I think these could all be replaced with a RAII style scoped_restore instead. =20 Of the three locals that I've changed, the only one that I believe is now restored in a different location is ui::async, before this commit the async field was restored after a call to either delete_file_handle or ui_register_input_event_handler, and after this commit, the field is restored before these calls. However, I don't believe that either of these functions depend on the value of the async field, so I believe the commit is fine. =20 Tested on x86-64/Linux passes with no regressions. Diff: --- gdb/infcall.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gdb/infcall.c b/gdb/infcall.c index 5365f97049c..9334648ac0e 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -578,21 +578,13 @@ run_inferior_call (std::unique_ptr s= m, struct thread_info *call_thread, CORE_ADDR real_pc) { struct gdb_exception caught_error; - int saved_in_infcall =3D call_thread->control.in_infcall; ptid_t call_thread_ptid =3D call_thread->ptid; - enum prompt_state saved_prompt_state =3D current_ui->prompt_state; int was_running =3D call_thread->state =3D=3D THREAD_RUNNING; - int saved_ui_async =3D current_ui->async; - - /* Infcalls run synchronously, in the foreground. */ - current_ui->prompt_state =3D PROMPT_BLOCKED; - /* So that we don't print the prompt prematurely in - fetch_inferior_event. */ - current_ui->async =3D 0; =20 delete_file_handler (current_ui->input_fd); =20 - call_thread->control.in_infcall =3D 1; + scoped_restore restore_in_infcall + =3D make_scoped_restore (&call_thread->control.in_infcall, 1); =20 clear_proceed_status (0); =20 @@ -607,6 +599,15 @@ run_inferior_call (std::unique_ptr sm, =20 try { + /* Infcalls run synchronously, in the foreground. */ + scoped_restore restore_prompt_state + =3D make_scoped_restore (¤t_ui->prompt_state, PROMPT_BLOCKED); + + /* So that we don't print the prompt prematurely in + fetch_inferior_event. */ + scoped_restore restore_ui_async + =3D make_scoped_restore (¤t_ui->async, 0); + proceed (real_pc, GDB_SIGNAL_0); =20 /* Inferior function calls are always synchronous, even if the @@ -622,12 +623,10 @@ run_inferior_call (std::unique_ptr s= m, so. normal_stop calls async_enable_stdin, so reset the prompt state again here. In other cases, stdin will be re-enabled by inferior_event_handler, when an exception is thrown. */ - current_ui->prompt_state =3D saved_prompt_state; if (current_ui->prompt_state =3D=3D PROMPT_BLOCKED) delete_file_handler (current_ui->input_fd); else ui_register_input_event_handler (current_ui); - current_ui->async =3D saved_ui_async; =20 /* If the infcall does NOT succeed, normal_stop will have already finished the thread states. However, on success, normal_stop @@ -663,8 +662,6 @@ run_inferior_call (std::unique_ptr sm, breakpoint_auto_delete (call_thread->control.stop_bpstat); } =20 - call_thread->control.in_infcall =3D saved_in_infcall; - return caught_error; }