From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89804 invoked by alias); 4 Nov 2019 10:23:44 -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 89676 invoked by uid 89); 4 Nov 2019 10:23:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=convenience, refactoring X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Nov 2019 10:23:41 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 0CDF320250; Mon, 4 Nov 2019 05:23:39 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 81BB420266 for ; Mon, 4 Nov 2019 05:23:36 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 70A532816E for ; Mon, 4 Nov 2019 05:23:36 -0500 (EST) X-Gerrit-PatchSet: 1 Date: Mon, 04 Nov 2019 10:23:00 -0000 From: "Tankut Baris Aktemur (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] infrun: extract out a code piece into the 'handle_inferior_exit' func... X-Gerrit-Change-Id: Id8c7d485805cf39623c3e06b4a565515b7e9625c X-Gerrit-Change-Number: 508 X-Gerrit-ChangeURL: X-Gerrit-Commit: c54aca430f561561d3e8ddbc3b247868083ad572 References: Reply-To: tankut.baris.aktemur@intel.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/3.0.3-75-g9005159e5d Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2019-11/txt/msg00085.txt.bz2 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/508 ...................................................................... infrun: extract out a code piece into the 'handle_inferior_exit' function This is a refactoring. The extracted function is placed deliberately before 'stop_all_threads' because the the function will be re-used there in a subsequent patch for handling a TARGET_WAITKIND_EXITED or TARGET_WAITKIND_SIGNALLED status kind received from a thread that GDB attempted to stop. gdb/ChangeLog: 2019-11-04 Tankut Baris Aktemur * infrun.c (handle_inferior_event): Extract out a piece of code into... (handle_inferior_exit): ...this new function. Change-Id: Id8c7d485805cf39623c3e06b4a565515b7e9625c --- M gdb/infrun.c 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 57405d7..f628fd1 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4317,6 +4317,74 @@ set_resumed (mark_ptid, 0); } +/* Handle a TARGET_WAITKIND_EXITED or TARGET_WAITKIND_SIGNALLED + event. */ + +static void +handle_inferior_exit (ptid_t event_ptid, + struct target_waitstatus ws) +{ + gdb_assert (ws.kind == TARGET_WAITKIND_EXITED + || ws.kind == TARGET_WAITKIND_SIGNALLED); + + inferior_ptid = event_ptid; + set_current_inferior (find_inferior_ptid (event_ptid)); + set_current_program_space (current_inferior ()->pspace); + handle_vfork_child_exec_or_exit (0); + target_terminal::ours (); /* Must do this before mourn anyway. */ + + /* Clearing any previous state of convenience variables. */ + clear_exit_convenience_vars (); + + if (ws.kind == TARGET_WAITKIND_EXITED) + { + /* Record the exit code in the convenience variable $_exitcode, so + that the user can inspect this again later. */ + set_internalvar_integer (lookup_internalvar ("_exitcode"), + (LONGEST) ws.value.integer); + + /* Also record this in the inferior itself. */ + current_inferior ()->has_exit_code = 1; + current_inferior ()->exit_code = (LONGEST) ws.value.integer; + + /* Support the --return-child-result option. */ + return_child_result_value = ws.value.integer; + + gdb::observers::exited.notify (ws.value.integer); + } + else + { + struct gdbarch *gdbarch = current_inferior ()->gdbarch; + + if (gdbarch_gdb_signal_to_target_p (gdbarch)) + { + /* Set the value of the internal variable $_exitsignal, + which holds the signal uncaught by the inferior. */ + set_internalvar_integer (lookup_internalvar ("_exitsignal"), + gdbarch_gdb_signal_to_target (gdbarch, + ws.value.sig)); + } + else + { + /* We don't have access to the target's method used for + converting between signal numbers (GDB's internal + representation <-> target's representation). + Therefore, we cannot do a good job at displaying this + information to the user. It's better to just warn + her about it (if infrun debugging is enabled), and + give up. */ + if (debug_infrun) + fprintf_filtered (gdb_stdlog, _("\ +Cannot fill $_exitsignal with the correct signal number.\n")); + } + + gdb::observers::signal_exited.notify (ws.value.sig); + } + + gdb_flush (gdb_stdout); + target_mourn_inferior (inferior_ptid); +} + /* See infrun.h. */ void @@ -4842,62 +4910,7 @@ case TARGET_WAITKIND_EXITED: case TARGET_WAITKIND_SIGNALLED: - inferior_ptid = ecs->ptid; - set_current_inferior (find_inferior_ptid (ecs->ptid)); - set_current_program_space (current_inferior ()->pspace); - handle_vfork_child_exec_or_exit (0); - target_terminal::ours (); /* Must do this before mourn anyway. */ - - /* Clearing any previous state of convenience variables. */ - clear_exit_convenience_vars (); - - if (ecs->ws.kind == TARGET_WAITKIND_EXITED) - { - /* Record the exit code in the convenience variable $_exitcode, so - that the user can inspect this again later. */ - set_internalvar_integer (lookup_internalvar ("_exitcode"), - (LONGEST) ecs->ws.value.integer); - - /* Also record this in the inferior itself. */ - current_inferior ()->has_exit_code = 1; - current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer; - - /* Support the --return-child-result option. */ - return_child_result_value = ecs->ws.value.integer; - - gdb::observers::exited.notify (ecs->ws.value.integer); - } - else - { - struct gdbarch *gdbarch = current_inferior ()->gdbarch; - - if (gdbarch_gdb_signal_to_target_p (gdbarch)) - { - /* Set the value of the internal variable $_exitsignal, - which holds the signal uncaught by the inferior. */ - set_internalvar_integer (lookup_internalvar ("_exitsignal"), - gdbarch_gdb_signal_to_target (gdbarch, - ecs->ws.value.sig)); - } - else - { - /* We don't have access to the target's method used for - converting between signal numbers (GDB's internal - representation <-> target's representation). - Therefore, we cannot do a good job at displaying this - information to the user. It's better to just warn - her about it (if infrun debugging is enabled), and - give up. */ - if (debug_infrun) - fprintf_filtered (gdb_stdlog, _("\ -Cannot fill $_exitsignal with the correct signal number.\n")); - } - - gdb::observers::signal_exited.notify (ecs->ws.value.sig); - } - - gdb_flush (gdb_stdout); - target_mourn_inferior (inferior_ptid); + handle_inferior_exit (ecs->ptid, ecs->ws); stop_print_frame = 0; stop_waiting (ecs); return; -- Gerrit-Project: binutils-gdb Gerrit-Branch: master Gerrit-Change-Id: Id8c7d485805cf39623c3e06b4a565515b7e9625c Gerrit-Change-Number: 508 Gerrit-PatchSet: 1 Gerrit-Owner: Tankut Baris Aktemur Gerrit-MessageType: newchange