From patchwork Wed Feb 15 19:48:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65060 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 0731A3858428 for ; Wed, 15 Feb 2023 19:49:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0731A3858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676490561; bh=NCyUtIMjtIS/H8lGxYyFNLdzklWjM1UXMhA72bNaYYY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bOcGepX9kuq40dM2kxFopSqvvT6o7u8MN8X505HY4pkj1kdcjaR1wzjYWeoD986Bv x4u9ND1/bDHdca54Iu1ZLkCMlnF5giMC9lgfNtpavTGdhGJowaVZ6MpHgj3AW4g4gw IPAw3NofUht6MnV1AK70Mx2su1Yk1xPOglDAfpWo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 6FBA03858D28 for ; Wed, 15 Feb 2023 19:48:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FBA03858D28 Received: by mail-io1-xd34.google.com with SMTP id l128so7566939iof.2 for ; Wed, 15 Feb 2023 11:48:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NCyUtIMjtIS/H8lGxYyFNLdzklWjM1UXMhA72bNaYYY=; b=GnO39tobGIg0UjxVOMqEBAYwB7S2uQ0umLyodZfW0JvY9ZfwOGOnT84ADuV9gZdZV5 ggAsg5uILFn8+/gYwjQWVlWgu93wdHJavDrcS1hbfQfQqFVRVnPNTGHGyuLVi0IKUv7S xY0mN5nQJv3lzbmii+K3uBm7TWmgXPCXzVMLt9GyM3zUylfaOQ9m57NRn/gywZwD9sNx 2Kx7PS+sUpLZwFZehXU3T6gl0tKlPKqP/By81mwswbrxfVoRYPfkP8tSmp68l39bx+rt IiQLyHPTtjns6yg23Glfze8vMMwUJ/sLhvLIJPlUVT4ztIBSkq4ZcmWVkRVgJ3qFmJ3U n6iA== X-Gm-Message-State: AO0yUKVCrVBuikL9+PsEq8x6yciuQEybXrXLoIx6ElIumysQfJ1YsoSV uTXhb36y6xwrWQyV7jCiCcfgvpyxPB9Fqqdi X-Google-Smtp-Source: AK7set9GAFibPSPYmxgD6f8G6Bap/9jZN1YTQBH4ie6WaQzNI2g5dWRF958V3kBNGuxcoGU0hQUxlg== X-Received: by 2002:a5d:9284:0:b0:721:90c5:7d0e with SMTP id s4-20020a5d9284000000b0072190c57d0emr2761288iom.9.1676490535094; Wed, 15 Feb 2023 11:48:55 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id g10-20020a92cdaa000000b0030314a7f039sm4700212ild.10.2023.02.15.11.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 11:48:54 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix DAP stackTrace through frames without debuginfo Date: Wed, 15 Feb 2023 12:48:47 -0700 Message-Id: <20230215194847.3805619-1-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The DAP stackTrace implementation did not fully account for frames without debuginfo. Attemping this would yield a result like: {"request_seq": 5, "type": "response", "command": "stackTrace", "success": false, "message": "'NoneType' object has no attribute 'filename'", "seq": 11} This patch fixes the problem by adding another check for None. Tested-by: Tom de Vries --- gdb/python/lib/gdb/dap/bt.py | 4 +-- gdb/testsuite/gdb.dap/bt-inner.c | 24 ++++++++++++++ gdb/testsuite/gdb.dap/bt-main.c | 29 +++++++++++++++++ gdb/testsuite/gdb.dap/bt-nodebug.exp | 47 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.dap/bt-inner.c create mode 100644 gdb/testsuite/gdb.dap/bt-main.c create mode 100644 gdb/testsuite/gdb.dap/bt-nodebug.exp diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index 990ab135b05..01d1aa088e2 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -1,4 +1,4 @@ -# Copyright 2022 Free Software Foundation, Inc. +# Copyright 2022, 2023 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -69,7 +69,7 @@ def _backtrace(thread_id, levels, startFrame): "instructionPointerReference": hex(current_frame.pc()), } sal = _safe_sal(current_frame) - if sal is not None: + if sal is not None and sal.symtab is not None: newframe["source"] = { "name": os.path.basename(sal.symtab.filename), "path": sal.symtab.filename, diff --git a/gdb/testsuite/gdb.dap/bt-inner.c b/gdb/testsuite/gdb.dap/bt-inner.c new file mode 100644 index 00000000000..f5d48ab128e --- /dev/null +++ b/gdb/testsuite/gdb.dap/bt-inner.c @@ -0,0 +1,24 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern void function_breakpoint_here (void); + +void +no_debug_info (void) +{ + function_breakpoint_here (); +} diff --git a/gdb/testsuite/gdb.dap/bt-main.c b/gdb/testsuite/gdb.dap/bt-main.c new file mode 100644 index 00000000000..7664ef79932 --- /dev/null +++ b/gdb/testsuite/gdb.dap/bt-main.c @@ -0,0 +1,29 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +extern void no_debug_info (void); + +void +function_breakpoint_here (void) +{ +} + +int main () +{ + no_debug_info (); + return 0; +} diff --git a/gdb/testsuite/gdb.dap/bt-nodebug.exp b/gdb/testsuite/gdb.dap/bt-nodebug.exp new file mode 100644 index 00000000000..e365f0877d4 --- /dev/null +++ b/gdb/testsuite/gdb.dap/bt-nodebug.exp @@ -0,0 +1,47 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test DAP 'bt' through a function without debuginfo. + +load_lib dap-support.exp + +standard_testfile bt-main.c bt-inner.c + +if {[build_executable_from_specs $testfile.exp $testfile {} \ + $srcfile debug \ + $srcfile2 {}] == -1} { + return +} + +if {[dap_launch $testfile] == ""} { + return +} + +set obj [dap_check_request_and_response "set breakpoint on inner" \ + setFunctionBreakpoints \ + {o breakpoints [a [o name [s function_breakpoint_here]]]}] +set fn_bpno [dap_get_breakpoint_number $obj] + +dap_check_request_and_response "start inferior" configurationDone +dap_wait_for_event_and_check "inferior started" thread "body reason" started + +lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $fn_bpno] unused objs + +# The bug was that this request would fail. +dap_check_request_and_response "backtrace" stackTrace {o threadId [i 1]} + +dap_shutdown