From patchwork Sat Dec 10 16:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Domani X-Patchwork-Id: 61754 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A76FF3844685 for ; Sat, 10 Dec 2022 16:22:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A76FF3844685 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670689360; bh=/jmRIQAv5j8zquLRcDt2MxDa0DhJilkdq5Ktpe9ZewQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RersH31vvMC9vm/b9pxw/UDw0HF5Awb2qC5Q1UX414TtZ6z783BZuaFllNtfakEDm sQDEf4m1woV1KCW584ZfmbMexFToUc7Xzrwv/3wcpWAwa7hNqNq8d4td4yVbJqkvFc /FfO0r4Xj/hIcdckH7mJ4cX+7HD4XmWQxQmfSVAg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from sonic304-22.consmr.mail.ir2.yahoo.com (sonic304-22.consmr.mail.ir2.yahoo.com [77.238.179.147]) by sourceware.org (Postfix) with ESMTPS id 365BD3844B1F for ; Sat, 10 Dec 2022 16:22:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 365BD3844B1F X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1670689333; bh=xvc4dceKRQ6g6p7Ou9oiAivqkri/RQBFUte5WZTxcuj=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=KtMKaPJwTprOGlW1uvdpUF5CakhPC6w7bEuP6NhMGlh0VmbhYxJDho0NeioVxOFmJ5/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juKeP730dPNu5WmoHLq3lbyUSuX7iwzBTuG0jBsaWOzL7uYcXBRrf.WG 5YaPJsuNsF3iG2j1n5murSAPSfas6J092uZuByI0vQHORQkh_iglJDHIwNIk7JHG3PeDkBf537VW RTZ6CZuHGpoCgUuOFLXzl_QC58.iEZmauxVlY7fO79cuq4mBTiFb0M0kwgNpnotYGUWkVPBME1M0 E8Ts90Qt1NQfaUokQfeWE7H9l.QCa6_XU80tmo3.ApqpvHpkHQ03LxtzogmVcDzZ_sMRTwdOTPRY V_2EyRLYgb_g9uFCG.KNZeCQ7qCLM3O8CKAJNzkkKtCNKFBfQZ9WcgYtut8q03TVHFpSqv0zpgAS LqOFr_w_WwFFKpJCYMLewTk9hpdEtG_DYPvfpqspJ8_ddqWRYPawvux2HSO6ESA8Nmb_eCstHJy7 hp3fe0Q0D_C1Lj_Rrpn9TIqXkeFzj.zcGfOE1aw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Sat, 10 Dec 2022 16:22:13 +0000 Received: by hermes--production-ir2-5795fc58c8-xpjmk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 3d85437d5a35860ed1c98bc98c221dd7; Sat, 10 Dec 2022 16:22:12 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH 2/3] Move return_value_info and refactor code setting its members Date: Sat, 10 Dec 2022 17:23:25 +0100 Message-Id: <20221210162326.854-2-ssbssa@yahoo.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221210162326.854-1-ssbssa@yahoo.de> References: <20221210162326.854-1-ssbssa@yahoo.de> MIME-Version: 1.0 X-Antivirus: Avast (VPS 221210-4, 12/10/2022), Outbound message X-Antivirus-Status: Clean X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Hannes Domani via Gdb-patches From: Hannes Domani Reply-To: Hannes Domani Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This moves the function and return_buf members from finish_command_fsm to return_value_info, and refactors the code setting its members into functions get_callee_info and get_return_value_info. And all of that is moved before step_command_fsm, since it will use them in the next patch. --- gdb/infcmd.c | 157 ++++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 71 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index a5fcf2f8ea5..9c96d9a39ee 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -800,6 +800,86 @@ nexti_command (const char *count_string, int from_tty) step_1 (1, 1, count_string); } +/* The captured function return value/type and its position in the + value history. */ + +struct return_value_info +{ + /* The function that we're stepping out of. */ + struct symbol *function; + + /* If the current function uses the "struct return convention", + this holds the address at which the value being returned will + be stored, or zero if that address could not be determined or + the "struct return convention" is not being used. */ + CORE_ADDR return_buf; + + /* The captured return value. May be NULL if we weren't able to + retrieve it. See get_return_value. */ + struct value *value; + + /* The return type. In some cases, we'll not be able extract the + return value, but we always know the type. */ + struct type *type; + + /* If we captured a value, this is the value history index. */ + int value_history_index; +}; + +/* Get calle function symbol and return convention. */ + +static void +get_callee_info (return_value_info *rv, frame_info_ptr frame) +{ + rv->function = find_pc_function (get_frame_pc (frame)); + + /* Determine the return convention. If it is RETURN_VALUE_STRUCT_CONVENTION, + attempt to determine the address of the return buffer. */ + if (rv->function != nullptr) + { + enum return_value_convention return_value; + struct gdbarch *gdbarch = get_frame_arch (frame); + + struct type * val_type + = check_typedef (rv->function->type ()->target_type ()); + + return_value = gdbarch_return_value + (gdbarch, read_var_value (rv->function, nullptr, frame), + val_type, nullptr, nullptr, nullptr); + + if (return_value == RETURN_VALUE_STRUCT_CONVENTION + && val_type->code () != TYPE_CODE_VOID) + rv->return_buf + = gdbarch_get_return_buf_addr (gdbarch, val_type, frame); + } +} + +/* Get return value and add it to value history. */ + +static void +get_return_value_info (return_value_info *rv) +{ + rv->type = rv->function->type ()->target_type (); + if (rv->type == nullptr) + internal_error (_("finish_command: function has no target type")); + + if (check_typedef (rv->type)->code () != TYPE_CODE_VOID) + { + struct value *func; + + func = read_var_value (rv->function, nullptr, get_current_frame ()); + + if (rv->return_buf != 0) + /* Retrieve return value from the buffer where it was saved. */ + rv->value = value_at (rv->type, rv->return_buf); + else + rv->value = get_return_value (rv->function, func); + + if (rv->value != nullptr) + rv->value_history_index = record_latest_value (rv->value); + } +} + /* Data for the FSM that manages the step/next/stepi/nexti commands. */ @@ -1517,23 +1597,6 @@ get_return_value (struct symbol *func_symbol, struct value *function) return value; } -/* The captured function return value/type and its position in the - value history. */ - -struct return_value_info -{ - /* The captured return value. May be NULL if we weren't able to - retrieve it. See get_return_value. */ - struct value *value; - - /* The return type. In some cases, we'll not be able extract the - return value, but we always know the type. */ - struct type *type; - - /* If we captured a value, this is the value history index. */ - int value_history_index; -}; - /* Helper for print_return_value. */ static void @@ -1603,19 +1666,10 @@ struct finish_command_fsm : public thread_fsm the caller. */ breakpoint_up breakpoint; - /* The function that we're stepping out of. */ - struct symbol *function = nullptr; - /* If the FSM finishes successfully, this stores the function's return value. */ struct return_value_info return_value_info {}; - /* If the current function uses the "struct return convention", - this holds the address at which the value being returned will - be stored, or zero if that address could not be determined or - the "struct return convention" is not being used. */ - CORE_ADDR return_buf; - explicit finish_command_fsm (struct interp *cmd_interp) : thread_fsm (cmd_interp) { @@ -1637,32 +1691,14 @@ finish_command_fsm::should_stop (struct thread_info *tp) { struct return_value_info *rv = &return_value_info; - if (function != nullptr + if (rv->function != nullptr && bpstat_find_breakpoint (tp->control.stop_bpstat, breakpoint.get ()) != nullptr) { /* We're done. */ set_finished (); - rv->type = function->type ()->target_type (); - if (rv->type == nullptr) - internal_error (_("finish_command: function has no target type")); - - if (check_typedef (rv->type)->code () != TYPE_CODE_VOID) - { - struct value *func; - - func = read_var_value (function, nullptr, get_current_frame ()); - - if (return_buf != 0) - /* Retrieve return value from the buffer where it was saved. */ - rv->value = value_at (rv->type, return_buf); - else - rv->value = get_return_value (function, func); - - if (rv->value != nullptr) - rv->value_history_index = record_latest_value (rv->value); - } + get_return_value_info (rv); } else if (tp->control.stop_step) { @@ -1876,29 +1912,7 @@ finish_command (const char *arg, int from_tty) /* Find the function we will return from. */ frame_info_ptr callee_frame = get_selected_frame (nullptr); - sm->function = find_pc_function (get_frame_pc (callee_frame)); - sm->return_buf = 0; /* Initialize buffer address is not available. */ - - /* Determine the return convention. If it is RETURN_VALUE_STRUCT_CONVENTION, - attempt to determine the address of the return buffer. */ - if (sm->function != nullptr) - { - enum return_value_convention return_value; - struct gdbarch *gdbarch = get_frame_arch (callee_frame); - - struct type * val_type - = check_typedef (sm->function->type ()->target_type ()); - - return_value = gdbarch_return_value (gdbarch, - read_var_value (sm->function, nullptr, - callee_frame), - val_type, nullptr, nullptr, nullptr); - - if (return_value == RETURN_VALUE_STRUCT_CONVENTION - && val_type->code () != TYPE_CODE_VOID) - sm->return_buf = gdbarch_get_return_buf_addr (gdbarch, val_type, - callee_frame); - } + get_callee_info (&sm->return_value_info, callee_frame); /* Print info on the selected frame, including level number but not source. */ @@ -1908,10 +1922,11 @@ finish_command (const char *arg, int from_tty) gdb_printf (_("Run back to call of ")); else { - if (sm->function != nullptr && TYPE_NO_RETURN (sm->function->type ()) + if (sm->return_value_info.function != nullptr + && TYPE_NO_RETURN (sm->return_value_info.function->type ()) && !query (_("warning: Function %s does not return normally.\n" "Try to finish anyway? "), - sm->function->print_name ())) + sm->return_value_info.function->print_name ())) error (_("Not confirmed.")); gdb_printf (_("Run till exit from ")); }