From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.66]) by sourceware.org (Postfix) with ESMTPS id 01A2D3858D35 for ; Thu, 3 Feb 2022 18:27:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01A2D3858D35 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EXIIL8w631NLgCaok3rtbBAAEeuFSHfZAbIB0xutE5kLGu6Yf4gBTO64hzaiSu59CtXnEcPlC1X7PMTleV/EeF8dVJuL18e+GFmyUB5a53yMqtkGEvWBsfQCeUhLts+JC3Xucd52fiaOCQpSFYE37SMVMcRnYqniMILAju+N28X1TNtrX/bWTlfKaLYBjg9E/sP730Eq1dX99lT+9PxCB4C2Biqwg0lxCEAOY5TdQ9049ypY1ba6H6ga6YJmg9j+2urA8hFIvvuNlTZDOx4x9KVpQ2nmyGWfYU3fFuHBiNr/sy4ymo+T08RLMXIKIEvK6Omrm4uczZRub8NZ+rQ2PQ== 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=DYP7ti9oZ4VeBK2rbR0imgKP8/W9QkY2Y/FMl32gHhc=; b=FcI5SMUOs2vYc5nrQgzhGjU5UOUEQJE5a/vaRUNkvcFtuzjnYtpHK3SBOXmz8sasTqCEUz0Az4RwNKuRk9VQLmdGMDo0gx2xtLfjY/34RvnZTROpiULLebtZ+BS4uaUjSHrHp7VTG0Sug26FzZucuaFQdWYcrDWPqdd5z6wuq4TVatYQilgNCKVl8fc8YqXjE68iICS/8yiLXStieqqbJOK+LnTafJZkReBLrPnkYtqRfrqZ8on8ZPTtNROS4mZeRZdsvpfviZnsBMNGSQceeVffhrQXO19pU+XrXnmtX2J4uA0UuKMjyDqxDMhu4+loIr3Gi81i5IEtY1gjhbSWTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org 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 DS7PR07CA0019.namprd07.prod.outlook.com (2603:10b6:5:3af::7) by BL0PR12MB5556.namprd12.prod.outlook.com (2603:10b6:208:1cf::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 18:27:10 +0000 Received: from DM6NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3af:cafe::42) by DS7PR07CA0019.outlook.office365.com (2603:10b6:5:3af::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 18:27:09 +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 DM6NAM11FT063.mail.protection.outlook.com (10.13.172.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 18:27:09 +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; Thu, 3 Feb 2022 12:27:08 -0600 From: Lancelot SIX To: CC: , , Subject: [PATCH v5] gdb: add a symbol* argument to get_return_value Date: Thu, 3 Feb 2022 12:28:21 -0600 Message-ID: <20220203182821.20793-1-lancelot.six@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: 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: fe9c52c3-d1dd-4b6e-0f9c-08d9e742ca4d X-MS-TrafficTypeDiagnostic: BL0PR12MB5556:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hQNuGtQe615aAeeFHuAdmAbb3+uZjhOQhlLol0xfHqUOjThaEWyBQEJ8aDzNv6uZsHYA3uWYxZGMz75PnMODcEJ9e1DM8RYUgMDJi36VnuKybjeur2Xx3UYg0qNbieKztajcY2/LI8IJDaQs4QJLlUDACEt02FFrbBGdbgDMn8m7gUpvnJzwdM5otdYtnCVn9PRBTae+OBf9jw8SERXHuELIXAL4rkWo2XfHwuLqK1T/2HqauFRAip+lhkJsP+ika9f/+gwF9PpvtcXp6tBDEHqQFYEzWR96lqwWuxEcESTljFVhdOyH/MdKohvHdXpCa5Rz+LfiQ55DEtITO/gHGf0YlTom0Nx2bAYPCnWgT6HWk0BIAfkDlZsDvsAG2zWvhyZ5cMkckU8eL6ElN7nPpEuj9/paPm7U3GlbpSj/+ZEBJ9NV6yYW5E0st31/lyHyx1RJLDQ9dctTLza1Q0/mdj7uedKMbl5bjGQ08ndGiTU0gI5BoCS0pjnlF1aCATrRYTtZQR+PX1Ktp2uTWgsjoymUxESy2CbESmL/z3/ndkFmaHXLpU7VrrUvd82WKx3rIyYYK1FK0dVaZwj1Cd88HTsajtncR8iU7sTZRirTVDiO87TeXhPK5O1xZf0T0Yq95nPTZnE/UEoVNEgjFoQuM+OVqg6qkhN+79A7sZ/ZtGv8U4ViHGQNHALsOzyYXAKJXkTX18lcTJo1J0hAK4O/Ag== 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)(40470700004)(46966006)(36840700001)(83380400001)(47076005)(26005)(186003)(426003)(336012)(16526019)(1076003)(2616005)(81166007)(40460700003)(356005)(82310400004)(86362001)(36860700001)(316002)(6666004)(508600001)(4326008)(36756003)(70206006)(70586007)(6916009)(54906003)(8936002)(8676002)(2906002)(7696005)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 18:27:09.6604 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe9c52c3-d1dd-4b6e-0f9c-08d9e742ca4d 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: DM6NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5556 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, RCVD_IN_MSPIKE_H2, 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: Thu, 03 Feb 2022 18:27:14 -0000 Hi, Here is an updated version which includes the changes proposed by Simon. I have also made sure that PyErr_Clear is properly called in bpfinishpy_init. 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. Since the function return type can be deduced from the symbol remove the value_type argument which becomes redundant. No user visible change after this patch. Tested on x86_64-linux. Change-Id: Idf1279f1f7199f5022738a6679e0fa63fbd22edc Co-authored-by: Simon Marchi --- gdb/infcmd.c | 11 +++---- gdb/inferior.h | 10 ++++-- gdb/python/py-finishbreakpoint.c | 55 +++++++++++++++++--------------- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 994dd5b32a3..9a3214374e3 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1405,18 +1405,17 @@ 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) { regcache *stop_regs = get_current_regcache (); struct gdbarch *gdbarch = stop_regs->arch (); struct value *value; - value_type = check_typedef (value_type); + struct type *value_type + = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (func_symbol))); gdb_assert (value_type->code () != TYPE_CODE_VOID); /* FIXME: 2003-09-27: When returning from a nested inferior function @@ -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); 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..45de3c2d9c8 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -219,8 +219,14 @@ 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, - struct type *value_type); +/* 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. */ + +extern struct value *get_return_value (struct symbol *func_symbol, + struct value *function); /* Prepare for execution command. TARGET is the target that will run the command. BACKGROUND determines whether this is a foreground diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 03bd4934506..2298c179ba8 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -40,13 +40,15 @@ struct finish_breakpoint_object { /* gdb.Breakpoint base class. */ gdbpy_breakpoint_object py_bp; - /* 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. */ - PyObject *return_type; - /* gdb.Value object of the function finished by this breakpoint. Will be - NULL if return_type is NULL. */ + + /* gdb.Symbol object of the function finished by this breakpoint. */ + PyObject *func_symbol; + + /* gdb.Value object of the function finished by this breakpoint. + + nullptr if no debug information was available or return type was VOID. */ PyObject *function_value; + /* When stopped at this FinishBreakpoint, gdb.Value object returned by the function; Py_None if the value is not computable; NULL if GDB is not stopped at a FinishBreakpoint. */ @@ -80,8 +82,8 @@ 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); Py_TYPE (self)->tp_free (self); } @@ -99,16 +101,17 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj) /* Can compute return_value only once. */ gdb_assert (!self_finishbp->return_value); - if (!self_finishbp->return_type) + if (self_finishbp->func_symbol == nullptr) return; 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); if (ret) { @@ -165,7 +168,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,15 +241,15 @@ 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->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) { struct type *ret_type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (function))); @@ -255,14 +257,14 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) /* Remember only non-void return types. */ if (ret_type->code () != TYPE_CODE_VOID) { - struct value *func_value; - /* Ignore Python errors at this stage. */ - self_bpfinish->return_type = type_to_type_object (ret_type); + value *func_value = read_var_value (function, NULL, frame); + self_bpfinish->function_value + = value_to_value_object (func_value); PyErr_Clear (); - func_value = read_var_value (function, NULL, frame); - self_bpfinish->function_value = - value_to_value_object (func_value); + + self_bpfinish->func_symbol + = symbol_to_symbol_object (function); PyErr_Clear (); } } @@ -274,14 +276,15 @@ 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->function_value == nullptr) { /* Won't be able to compute return value. */ - Py_XDECREF (self_bpfinish->return_type); + Py_XDECREF (self_bpfinish->func_symbol); Py_XDECREF (self_bpfinish->function_value); - self_bpfinish->return_type = NULL; - self_bpfinish->function_value = NULL; + self_bpfinish->func_symbol = nullptr; + self_bpfinish->function_value = nullptr; } bppy_pending_object = &self_bpfinish->py_bp; base-commit: 0d8cbc5f2fcbcb9eb207f12507fdfe04f3d3ae14 -- 2.25.1