From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20609.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::609]) by sourceware.org (Postfix) with ESMTPS id 414673858D37 for ; Wed, 2 Feb 2022 21:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 414673858D37 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kR8AWwt97Dox1qnOIDDJZgkJOElscwk0SlA7wTkPoYM7djzo/gDMqQzPwTW61JIgRrlDa4RVN8tIQ/VfycgdXPmn4qi9Dt5/flY01Qt3rsEEcfQlXN5Yi6VDub4AlbLbnB4b/Aytq5EcwO7K3VgAyzO3WYYCf8pdv4vWive2qYj5AaKGta0gGEa/mad+CTSMJx5TEY1vp3uJs/ItLh+oMUhIUfjdLWZb48ZOAx36A89jh2iym2oAGB3KTB3ei5HPo0dTjjRLKQb+JMIC1qnDpHrSUKm5xJY4EesB4CUHU3GyfWELiRTwNJZODc6alxLIC14l1drJYTicjfibnn+/Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2Q6X8roKMqvc20MblNxfztNxN4sewjW95dsrajAUYTI=; b=V4qq26a5Czr5OGA/VZPwglGwDVRsqD0VlI/bNpAzj9AAMzQoCat1c9s9M5UDuRq2is7lN3eHIut4WtApcC3nDK5DzWB8huEi6/2CmxiXFOazf+zvepcbHsY4pHr3EaIdm4ITN8W4W8pywV434WjL7hqI4ZNAqFC4kzqKvGmnRnCjeR1aodlm+r82vliZZQ1lb7gLsSPIjDGJ9leHCDJP3l9YQJKvCVhRLB7iTqji38v9qA232BX+TdQWsg5cERf1S/rcr74gYN/rhc0Q4xQ5d71sGIcwTtC0lxN1kq4b3Zp1Au8D5kelSQ/kGLek4Gx3z3+9irlQWS9zpE3BpzjS+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=simark.ca smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from DM5PR1401CA0002.namprd14.prod.outlook.com (2603:10b6:4:4a::12) by DM6PR12MB2634.namprd12.prod.outlook.com (2603:10b6:5:49::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.19; Wed, 2 Feb 2022 21:57:57 +0000 Received: from DM6NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:4:4a:cafe::47) by DM5PR1401CA0002.outlook.office365.com (2603:10b6:4:4a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 21:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT008.mail.protection.outlook.com (10.13.172.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 21:57:57 +0000 Received: from node-bp126-r03c.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 2 Feb 2022 15:57:56 -0600 From: Lancelot SIX To: CC: , , Subject: [PATCH v4] gdb: add a symbol* argument to get_return_value Date: Wed, 2 Feb 2022 15:59:14 -0600 Message-ID: <20220202215914.23534-1-lancelot.six@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <8ebbde37-0acc-c430-ea36-d21c14163ef8@simark.ca> References: <8ebbde37-0acc-c430-ea36-d21c14163ef8@simark.ca> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9a859a9-d1e6-4153-85e4-08d9e6971263 X-MS-TrafficTypeDiagnostic: DM6PR12MB2634:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lEg6uV2DdA6gtjewNUw+9IdqbDWencXSMBGdm2mQzJAib+xnkiuAf1ocEivj4JCxZHwxDdfxHtNNummxivjWEOMM9WP5j2lvgFkjSgUbf/wfvqHFXd+MQzCBiP7Ykq6e2j51w+/hQ9qeWxY4adV5lauGV36WVUzBf/Otm9AiS4YUybW5AhtFiyg2W+7uOZArKwSaoNIcHzf/P7uuIfSveqVJz5aVjWp72/1ey0onV2MVnC5XQDGrIPwR+nFYcPXZ6roD/AAQb30HgaapV/74GayzIgdC60S6AdI5uXp6VzhtkbrbOMmAR4LNDLZxsV7NlJ2fHwlZn1q0GI9wM4mIkto5PVnWw66fkvb7KwjEBf3HWaSTg8Srbhxc69g5MrpkvjREs7XE6hYqfH8rs2UdHHbu0QlLGyOj6IZTuhX8p/sLhm2G9VfukyzYXyqYfrKloV8L+End4Zvbo1ykY0o0nsGpTf/Xf5HOp8u5OrcOt8JBSgvaOUWZEl/XooGK0/IJRceSOfHzSF3KKeJP0K8Y0IXy1IUXbDPBI69m6VUK6ajxE1cVMjVlS80adxcUZnE+HIsM2iMWDyKoTJSxKOxA+6rVOS7Z98yqsRbCDwd29nRz+XdPyzbdt/VMRK8qmnBh3+jaH4Bk0yApQMiSC2OIOGzSGduKfk9QR/vpdmVIDxvf05Bjzz8lMULEVN8+13XtuLMr+FFnsxD7L9CjnhOmIQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(86362001)(81166007)(8936002)(336012)(426003)(26005)(8676002)(4326008)(316002)(16526019)(186003)(1076003)(36756003)(40460700003)(83380400001)(508600001)(2616005)(6916009)(2906002)(54906003)(36860700001)(7696005)(356005)(70206006)(6666004)(47076005)(5660300002)(82310400004)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 21:57:57.1504 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9a859a9-d1e6-4153-85e4-08d9e6971263 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2634 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Wed, 02 Feb 2022 21:58:03 -0000 Hi, Here is a revised version of the patch. Since V3: - Update documentation of get_return_value and move in inferior.h. Best, Lancelot. --- Add an argument to the get_return_value function to indicate the symbol of the function the debuggee is returning from. This will be used by the following patch. No user visible change after this patch. Tested on x86_64-linux. Change-Id: Idf1279f1f7199f5022738a6679e0fa63fbd22edc --- gdb/infcmd.c | 9 ++++----- gdb/inferior.h | 10 +++++++++- gdb/python/py-finishbreakpoint.c | 29 ++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 994dd5b32a3..6be126aedab 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1405,12 +1405,11 @@ advance_command (const char *arg, int from_tty) until_break_command (arg, from_tty, 1); } -/* Return the value of the result of a function at the end of a 'finish' - command/BP. DTOR_DATA (if not NULL) can represent inferior registers - right after an inferior call has finished. */ +/* See inferior.h. */ struct value * -get_return_value (struct value *function, struct type *value_type) +get_return_value (struct symbol *func_symbol, struct value *function, + struct type *value_type) { regcache *stop_regs = get_current_regcache (); struct gdbarch *gdbarch = stop_regs->arch (); @@ -1577,7 +1576,7 @@ finish_command_fsm::should_stop (struct thread_info *tp) struct value *func; func = read_var_value (function, NULL, get_current_frame ()); - rv->value = get_return_value (func, rv->type); + rv->value = get_return_value (function, func, rv->type); if (rv->value != NULL) rv->value_history_index = record_latest_value (rv->value); } diff --git a/gdb/inferior.h b/gdb/inferior.h index ec0fb6e8b16..ef18fcb2482 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -219,7 +219,15 @@ extern void detach_command (const char *, int); extern void notice_new_inferior (struct thread_info *, bool, int); -extern struct value *get_return_value (struct value *function, +/* Return the value of the result of a function at the end of a 'finish' + command/BP. If the result's value cannot be retrieved, return NULL. + + FUNC_SYMBOL is the symbol of the function being returned from, FUNCTION is + a value containing the address of the function, and VALUE_TYPE the type of + the value the function returns. */ + +extern struct value *get_return_value (struct symbol *func_symbol, + struct value *function, struct type *value_type); /* Prepare for execution command. TARGET is the target that will run diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 03bd4934506..a322918dfca 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -40,6 +40,8 @@ struct finish_breakpoint_object { /* gdb.Breakpoint base class. */ gdbpy_breakpoint_object py_bp; + /* gdb.Symbol object of the function finished by this breakpoint. */ + PyObject *func_symbol; /* gdb.Type object of the value return by the breakpointed function. May be NULL if no debug information was available or return type was VOID. */ @@ -80,6 +82,7 @@ bpfinishpy_dealloc (PyObject *self) struct finish_breakpoint_object *self_bpfinish = (struct finish_breakpoint_object *) self; + Py_XDECREF (self_bpfinish->func_symbol); Py_XDECREF (self_bpfinish->function_value); Py_XDECREF (self_bpfinish->return_type); Py_XDECREF (self_bpfinish->return_value); @@ -104,11 +107,14 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj) try { + struct symbol *func_symbol = + symbol_object_to_symbol (self_finishbp->func_symbol); struct value *function = value_object_to_value (self_finishbp->function_value); struct type *value_type = type_object_to_type (self_finishbp->return_type); - struct value *ret = get_return_value (function, value_type); + struct value *ret = + get_return_value (func_symbol, function, value_type); if (ret) { @@ -165,7 +171,6 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) PyObject *internal = NULL; int internal_bp = 0; CORE_ADDR pc; - struct symbol *function; if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords, &frame_obj, &internal)) @@ -239,16 +244,18 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) } /* Find the function we will return from. */ - self_bpfinish->return_type = NULL; - self_bpfinish->function_value = NULL; + self_bpfinish->func_symbol = nullptr; + self_bpfinish->return_type = nullptr; + self_bpfinish->function_value = nullptr; try { if (get_frame_pc_if_available (frame, &pc)) { - function = find_pc_function (pc); - if (function != NULL) + struct symbol *function = find_pc_function (pc); + if (function != nullptr) { + self_bpfinish->func_symbol = symbol_to_symbol_object (function); struct type *ret_type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (function))); @@ -274,14 +281,18 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) remain NULL. */ } - if (self_bpfinish->return_type == NULL || self_bpfinish->function_value == NULL) + if (self_bpfinish->func_symbol == nullptr + || self_bpfinish->return_type == nullptr + || self_bpfinish->function_value == nullptr) { /* Won't be able to compute return value. */ + Py_XDECREF (self_bpfinish->func_symbol); Py_XDECREF (self_bpfinish->return_type); Py_XDECREF (self_bpfinish->function_value); - self_bpfinish->return_type = NULL; - self_bpfinish->function_value = NULL; + self_bpfinish->func_symbol = nullptr; + self_bpfinish->return_type = nullptr; + self_bpfinish->function_value = nullptr; } bppy_pending_object = &self_bpfinish->py_bp; base-commit: 0d8cbc5f2fcbcb9eb207f12507fdfe04f3d3ae14 -- 2.25.1