From patchwork Wed May 24 16:36:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69963 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 4C4283857734 for ; Wed, 24 May 2023 16:37:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C4283857734 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946269; bh=X813gv5U+ZDrYn4sTkHpO1/BI1JjV0kcFr/XuxWL1ms=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=suNJVigB7zwUXWh65cRG5j81fEmyE1Xu58xUr7lkZ4t52o3mmshvvJ1gNumF9nNO8 ByjZKBPGrKKeH+dWtSKzneKPtTOQF/r3dUd/9LGd4m5HS+riQDv6zcRpgHYyoGxiot Yc9daBrkYQyRSBInXgBCfgyNlc0+s+BUOBr2Td68= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 5E9F73858D28 for ; Wed, 24 May 2023 16:37:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E9F73858D28 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-76c636b6306so94100639f.3 for ; Wed, 24 May 2023 09:37:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946244; x=1687538244; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X813gv5U+ZDrYn4sTkHpO1/BI1JjV0kcFr/XuxWL1ms=; b=bUHHm2L1/uqBBM0q8ZNTHHrx8uYrW3qDuk+mbYFilEPtdwNmBDwCJHPgxeQBjY7BYO qLxyvJIQKH5FaqYntIS11s3LtHlXeGb6IjImw7RU19TbJ/R5FchVJy8U/UR64P5vQl7F Igz11ioRw+pE6kxmQcTkVKH61C655PEWDL5oPCr3QJ9URrLz3Rc9smQ2JvQmZxy2tOOo 2kTvWha31Wi3qF/TYSpXZ9mK32GKTyLqUeCKeoNWGQJ+kY2vKnqPuKGIc8lsopQATO1T MPzQPfdkE+MkZOmtIbGY5MMzMYexjl3vyciy57k7qfyEvrqdG08vGEju9jdlnXwszyHb /47Q== X-Gm-Message-State: AC+VfDyPn16HVtOndLlAwyqOEroKNHUF1Fzn3/Xw7ycGIuD8j/UAxjaN gGyL+CCoMYmJURuCeBWUsjiIcEMxi86z79a9MX3Arg== X-Google-Smtp-Source: ACHHUZ7k+i7y/MXtFxjHBWk/A8YWGfHdefEZTZ0XuYWvbObfAdkmvwq+cR0MeSKuSxSiMLzbx3NJeQ== X-Received: by 2002:a5d:93d1:0:b0:76c:7fb0:9d91 with SMTP id j17-20020a5d93d1000000b0076c7fb09d91mr12914921ioo.10.1684946244620; Wed, 24 May 2023 09:37:24 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:24 -0700 (PDT) Date: Wed, 24 May 2023 10:36:52 -0600 Subject: [PATCH 01/25] Stop gdb in gnat_runtime_has_debug_info MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-1-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" gnat_runtime_has_debug_info starts a new gdb to do its work. However, it also leaves this gdb running, which can potentially confuse the calling test -- I encountered this when writing a new DAP test. This patch changes the proc to shut down gdb. --- gdb/testsuite/lib/ada.exp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index b728e3a2aba..b4a93faefa5 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -204,5 +204,7 @@ gdb_caching_proc gnat_runtime_has_debug_info {} { } } + gdb_exit + return $has_debug_info } From patchwork Wed May 24 16:36:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69967 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 0A13238708C6 for ; Wed, 24 May 2023 16:38:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A13238708C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946304; bh=wmrvQoz/meROnEs2GDDjC8jTnokOUlTQCTozAkSj7CM=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BOPqanpy38St7P9odZqJe1HyxH/u1BGUIzEB/EGH0muQcZCPxFnhWa8nOxqRRKH0J 5G2l3CsEFc0i3Q5Q4NeQfVC+jFSIOw9pWFJ1oeiIFgtnGvhczF+9wkhZbzFhD4ixzO x1NxJn2h3CSUan5WE+oXS+CnQK2MCnHz5ZQ6Im8o= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 5BF163858C5E for ; Wed, 24 May 2023 16:37:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BF163858C5E Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-76c64da0e46so36172639f.0 for ; Wed, 24 May 2023 09:37:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946245; x=1687538245; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wmrvQoz/meROnEs2GDDjC8jTnokOUlTQCTozAkSj7CM=; b=NVEgOSkTm74TnW/8gbzGPNXPpyDcucLidhKnKIWfx39WU7lESH/jp/tpOEDDMpo0Lf 2FP6Bu2fi2t/OsM1GeYiNaDs12j70fYh/1IW7c7W5QiCPFxUwuB7SBBHERBBkLb5/qjy PCNGwvBC6zQgFPoJGDDKqFv8iPmNaVj9YwOSrdOI4ldd7LdUh7swn2ESND6eDeb4plwD DvieIMI+wxDf2qCSMlT5yl+zj5srHy4g4VJObSHc5JK/tognZjuv2IVj3MSI1lubEXaF 5nOnHNvtQb5ZEALm+Vp672uZZEYpo1LFWwcLs8nJ38lfo09ZeeuL3f02fg+XtPs9CA8R 2Q8g== X-Gm-Message-State: AC+VfDwpTX7HVa+3aay6cVmFl/9XREGv4iN54WIEURje/UeEDYm5n1hW QuidHPEWtx5o8ri10bWh4f6zIyNUYDNyLeP64fyfrg== X-Google-Smtp-Source: ACHHUZ6MeBrCp2gDfqV02Z2pN1Nci7CGlHJNg+eOnuDvo8UcKFRZa19SqMjEjt0OPEkb7WRZuiBh9g== X-Received: by 2002:a5e:c102:0:b0:763:bb4d:a415 with SMTP id v2-20020a5ec102000000b00763bb4da415mr12036425iol.18.1684946245205; Wed, 24 May 2023 09:37:25 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:24 -0700 (PDT) Date: Wed, 24 May 2023 10:36:53 -0600 Subject: [PATCH 02/25] Use gnat_runtime_has_debug_info in Ada catchpoint tests MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-2-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This changes the Ada catchpoint tests to use gnat_runtime_has_debug_info. This simplifies the code. --- gdb/testsuite/gdb.ada/catch_assert_if.exp | 28 +------------------------ gdb/testsuite/gdb.ada/catch_ex.exp | 18 ++++------------ gdb/testsuite/gdb.ada/catch_ex_std.exp | 27 ++++++++---------------- gdb/testsuite/gdb.ada/excep_handle.exp | 24 +++++----------------- gdb/testsuite/gdb.ada/mi_catch_assert.exp | 33 +----------------------------- gdb/testsuite/gdb.ada/mi_catch_ex.exp | 31 ++-------------------------- gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp | 32 +---------------------------- gdb/testsuite/gdb.ada/mi_ex_cond.exp | 33 +++--------------------------- 8 files changed, 25 insertions(+), 201 deletions(-) diff --git a/gdb/testsuite/gdb.ada/catch_assert_if.exp b/gdb/testsuite/gdb.ada/catch_assert_if.exp index f5b6096ecb0..4078fa408d1 100644 --- a/gdb/testsuite/gdb.ada/catch_assert_if.exp +++ b/gdb/testsuite/gdb.ada/catch_assert_if.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile bla @@ -25,35 +25,9 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional clean_restart ${testfile} -###################################################################### -# 1. Try catching all exceptions to check that runtime supports it. # -###################################################################### - set eol "\[\r\n\]+" set sp "\[ \t\]*" -if {![runto_main]} { - return 0 -} - -set msg "insert catchpoint on all Ada exceptions" -gdb_test_multiple "catch exception" $msg { - -re "Catchpoint $decimal: all Ada exceptions$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} - -################################################## -# 2. Try catching conditional failed assertion. # -################################################## - # Here is the scenario: # - Restart the debugger from scratch, runto_main # We'll catch assertions if Global_Var = 2 diff --git a/gdb/testsuite/gdb.ada/catch_ex.exp b/gdb/testsuite/gdb.ada/catch_ex.exp index de1e53243fb..388eb949e37 100644 --- a/gdb/testsuite/gdb.ada/catch_ex.exp +++ b/gdb/testsuite/gdb.ada/catch_ex.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -44,19 +44,9 @@ if {![runto_main]} { return 0 } -set msg "insert catchpoint on all Ada exceptions" -gdb_test_multiple "catch exception" $msg { - -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} +gdb_test "catch exception" \ + "Catchpoint $any_nb: all Ada exceptions" \ + "insert catchpoint on all Ada exceptions" gdb_test "info break" \ "$info_break_header$eol.*$catch_exception_info" \ diff --git a/gdb/testsuite/gdb.ada/catch_ex_std.exp b/gdb/testsuite/gdb.ada/catch_ex_std.exp index 73cbdaf90ca..3a2b10a8c13 100644 --- a/gdb/testsuite/gdb.ada/catch_ex_std.exp +++ b/gdb/testsuite/gdb.ada/catch_ex_std.exp @@ -17,7 +17,7 @@ require allow_shlib_tests load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -69,23 +69,12 @@ if {![runto_main]} { return 0 } -set can_catch_exceptions 0 -gdb_test_multiple "catch exception some_kind_of_error" "" { - -re "Catchpoint \[0-9\]+: `some_kind_of_error' Ada exception\r\n$gdb_prompt $" { - pass $gdb_test_name - set can_catch_exceptions 1 - } +gdb_test "catch exception some_kind_of_error" \ + "Catchpoint \[0-9\]+: `some_kind_of_error' Ada exception" - -re "Your Ada runtime appears to be missing some debugging information.\r\nCannot insert Ada exception catchpoint in this configuration.\r\n$gdb_prompt $" { - unsupported $gdb_test_name - } -} - -if { $can_catch_exceptions } { - gdb_test "cont" \ - "Catchpoint \[0-9\]+, .* at .*foo\.adb:\[0-9\]+.*" \ - "caught the exception" +gdb_test "cont" \ + "Catchpoint \[0-9\]+, .* at .*foo\.adb:\[0-9\]+.*" \ + "caught the exception" - gdb_test "print \$_ada_exception = some_package.some_kind_of_error'Address" \ - " = true" -} +gdb_test "print \$_ada_exception = some_package.some_kind_of_error'Address" \ + " = true" diff --git a/gdb/testsuite/gdb.ada/excep_handle.exp b/gdb/testsuite/gdb.ada/excep_handle.exp index 2cc80fbb988..deb3ace2987 100644 --- a/gdb/testsuite/gdb.ada/excep_handle.exp +++ b/gdb/testsuite/gdb.ada/excep_handle.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -40,32 +40,18 @@ set catchpoint_program_error_msg \ set catchpoint_storage_error_msg \ "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>" -############################################ -# Check that runtime supports catchpoint. # -############################################ - if {![runto_main]} { return 0 } -set msg "insert catchpoint on all Ada exceptions handlers" -gdb_test_multiple "catch handlers" $msg { - -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception handlers - # catchpoints. - unsupported $msg - return -1 - } -} - ############################################ # 1. Try catching all exceptions handlers. # ############################################ +gdb_test "catch handlers" \ + "Catchpoint $decimal: all Ada exceptions handlers" \ + "insert catchpoint on all Ada exceptions handlers" + # Continue. The program should stop at first exception handling. gdb_test "continue" \ diff --git a/gdb/testsuite/gdb.ada/mi_catch_assert.exp b/gdb/testsuite/gdb.ada/mi_catch_assert.exp index c3673fab8e8..7586e0a4256 100644 --- a/gdb/testsuite/gdb.ada/mi_catch_assert.exp +++ b/gdb/testsuite/gdb.ada/mi_catch_assert.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile bla @@ -23,37 +23,6 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional return -1 } -# Some global variables used to simplify the maintenance of some of -# the regular expressions below. -set eol "\[\r\n\]+" -set sp "\[ \t\]*" - -# Before going any further, verify that we can insert exception -# catchpoints... That way, we won't have to do this while doing -# the actual GDB/MI testing. - -clean_restart ${testfile} - -if {![runto_main]} { - return 0 -} - -set msg "insert catchpoint on all Ada exceptions" -gdb_test_multiple "catch exception" $msg { - -re "Catchpoint $decimal: all Ada exceptions$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*\[\r\n\]+$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} - -# Now, we can start the GDB/MI testing itself... - load_lib mi-support.exp set MIFLAGS "-i=mi" diff --git a/gdb/testsuite/gdb.ada/mi_catch_ex.exp b/gdb/testsuite/gdb.ada/mi_catch_ex.exp index d0dfbd59764..8cbcbe7e1a8 100644 --- a/gdb/testsuite/gdb.ada/mi_catch_ex.exp +++ b/gdb/testsuite/gdb.ada/mi_catch_ex.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -23,36 +23,9 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional return -1 } -# Some global variables used to simplify the maintenance of some of +# A global variable used to simplify the maintenance of some of # the regular expressions below. set any_nb "\[0-9\]+" -set eol "\[\r\n\]+" - -# Before going any further, verify that we can insert exception -# catchpoints... That way, we won't have to do this while doing -# the actual GDB/MI testing. - -clean_restart ${testfile} - -if {![runto_main]} { - return 0 -} - -set msg "insert catchpoint on all Ada exceptions" -gdb_test_multiple "catch exception" $msg { - -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*\[\r\n\]+$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} - -# Now, we can start the GDB/MI testing itself... load_lib mi-support.exp set MIFLAGS "-i=mi" diff --git a/gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp b/gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp index 2cd175f098b..ae081448553 100644 --- a/gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp +++ b/gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -23,36 +23,6 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional return -1 } -# A global variable used to simplify the maintenance of some of -# the regular expressions below. -set eol "\[\r\n\]+" - -# Before going any further, verify that we can insert exception -# handlers catchpoints... That way, we won't have to do this while -# doing the actual GDB/MI testing. - -clean_restart ${testfile} - -if {![runto_main]} { - return 0 -} - -set msg "insert catchpoint on all Ada exceptions handlers" -gdb_test_multiple "catch handlers" $msg { - -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*\[\r\n\]+$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} - -# Now, we can start the GDB/MI testing itself... - load_lib mi-support.exp set MIFLAGS "-i=mi" diff --git a/gdb/testsuite/gdb.ada/mi_ex_cond.exp b/gdb/testsuite/gdb.ada/mi_ex_cond.exp index 54aa6b54ee1..c0bc079f5f9 100644 --- a/gdb/testsuite/gdb.ada/mi_ex_cond.exp +++ b/gdb/testsuite/gdb.ada/mi_ex_cond.exp @@ -15,7 +15,7 @@ load_lib "ada.exp" -require allow_ada_tests +require allow_ada_tests gnat_runtime_has_debug_info standard_ada_testfile foo @@ -23,36 +23,9 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional return -1 } -# # Some global variables used to simplify the maintenance of some of -# # the regular expressions below. +# A global variable used to simplify the maintenance of some of +# the regular expressions below. set any_nb "\[0-9\]+" -set eol "\[\r\n\]+" - -# Before going any further, verify that we can insert exception -# catchpoints... That way, we won't have to do this while doing -# the actual GDB/MI testing. - -clean_restart ${testfile} - -if {![runto_main]} { - return 0 -} - -set msg "insert catchpoint on all Ada exceptions" -gdb_test_multiple "catch exception" $msg { - -re "Catchpoint $any_nb: all Ada exceptions$eol$gdb_prompt $" { - pass $msg - } - -re "Your Ada runtime appears to be missing some debugging information.*\[\r\n\]+$gdb_prompt $" { - # If the runtime was not built with enough debug information, - # or if it was stripped, we can not test exception - # catchpoints. - unsupported $msg - return -1 - } -} - -# Now, we can start the GDB/MI testing itself... load_lib mi-support.exp set MIFLAGS "-i=mi" From patchwork Wed May 24 16:36:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69964 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 C2C9B3853D17 for ; Wed, 24 May 2023 16:37:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2C9B3853D17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946272; bh=HKJPXxX5J6vJDIFF000lm59ouGN83o3dBurgtzQoURE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RTQ+iwQHP5c/XiAL14qPtcksVEBdWovsieNq7GNzepOXBV2yQuo4c6pwMfUkeTNBc wNrMGHCJPAXhYjqipUj9o4/djQwMsTgxU1NXnYIsoIOiMhyMxB8Wnzmjbo40eAnJVl VKF1pk3jqXgGaJmE4quH2K7BzcqFzoTQy91XHnzc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 7081D3858C27 for ; Wed, 24 May 2023 16:37:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7081D3858C27 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-76c5db6a5cfso93666839f.2 for ; Wed, 24 May 2023 09:37:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946246; x=1687538246; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HKJPXxX5J6vJDIFF000lm59ouGN83o3dBurgtzQoURE=; b=DwETIeb567WIik5WiCba6c4sJh0mSOST3Qyp5LC/56yuUx/X/Y7aPDIe6TTQ3eEaH7 8I8dcZS703vKhOhkNGt/sCpW1Mfbx2+N1HTYE77xsRhkSqDpqfNmaBdMYDmH/oiNyRx2 +7RL9q9M2Az4MCzuT6xzkUOVgmuwv5458thlENAuqmlhsfs8zCRbTUOc5dBWJD5fh1+S FVKMNFrJ3x1574S3HQCB+moj7sYkqz1w6HgW3R7h7Q8q2EKVmaSyBt8MgUaOCA2VGGQU nxk6FlJh7yAkglu2Fw4CS/zPFV6fNjWj0tol0gOE19HpqZYYKw1b2V2VKJAAZS0rbrpi uwOw== X-Gm-Message-State: AC+VfDwXHtczXCqY1ZpFLPleKosX1tsmIfqrlrvWCl/0jzCd6SWXyZM0 UNIcAjhB+/JStHGZEm85/tc11bytbXtiPH39gIC/EQ== X-Google-Smtp-Source: ACHHUZ7coA7P0OB9oUrNpfMxupPoFPvAIC7PBFvRFZ/kRgSAAdWT7BkM8hZg2vNuGgLT2M7+3aD3VA== X-Received: by 2002:a6b:610e:0:b0:760:ebf0:bdfa with SMTP id v14-20020a6b610e000000b00760ebf0bdfamr13462309iob.2.1684946245818; Wed, 24 May 2023 09:37:25 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:25 -0700 (PDT) Date: Wed, 24 May 2023 10:36:54 -0600 Subject: [PATCH 03/25] Pass tempflag to ada_catchpoint constructor MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-3-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This is a minor cleanup to pass tempflag to the ada_catchpoint constructor. --- gdb/ada-lang.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 21f3348a161..50eea4860ba 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12140,7 +12140,7 @@ struct ada_catchpoint : public code_breakpoint bool tempflag, bool enabled, bool from_tty) - : code_breakpoint (gdbarch_, bp_catchpoint), + : code_breakpoint (gdbarch_, bp_catchpoint, tempflag), m_kind (kind) { add_location (sal); @@ -12169,7 +12169,6 @@ struct ada_catchpoint : public code_breakpoint } enable_state = enabled ? bp_enabled : bp_disabled; - disposition = tempflag ? disp_del : disp_donttouch; locspec = string_to_location_spec (&addr_string_, language_def (language_ada)); language = language_ada; From patchwork Wed May 24 16:36:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69966 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 215CB3857009 for ; Wed, 24 May 2023 16:38:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 215CB3857009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946301; bh=n56hcQykSY8IKEACSTY/0nG3sNW6ci7UrUhuQCg675M=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=oXz1/4U1+WrDVZmK8anpqRVSqu1ytGexIk2iv+YHf6A7COKby57PUQSk2732/7IOU COS0BtA/rjv7fSbPLvp+vrG5m3EffDLChSxxvtl6I3XgfziSKBr2kt4shHaUtS40Z3 rlyjTmAbOIysuC721XNZ8fWIW614oVu+jez09kxA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 325DF385840F for ; Wed, 24 May 2023 16:37:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 325DF385840F Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-774942ddfe0so62212739f.2 for ; Wed, 24 May 2023 09:37:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946246; x=1687538246; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n56hcQykSY8IKEACSTY/0nG3sNW6ci7UrUhuQCg675M=; b=RO/xKCt3s8Diu1DsXbSuBqoF/ixLHFV3fUMLG30ADyFpwDz/76HfmDFPD14/HmlPHQ 64sNjJdwet/BF/fCv1JjtZXLznN7Tewrt/yguc1/S9X/GD2radSoWgz+yc7dlqD7qV9Y 4M9OgQVHY1TfrV79NE7O6SKfxSG28YyeyMr8MSz6rFg1B0tiZPncfjkoPNuT1HMHtka0 2w/BGBkPFbpWp87O8YekitLUCExijn2VYLANqK7tXPsTD1bbWOEA+LlClTtNa7DGOeXF xd7b/A84oVEU/7B4CCameJj91TmFCWE8ZrIYalapSPHZTy3Htw/MEqWfsvKvMwwoFRTh EWVA== X-Gm-Message-State: AC+VfDzncLUIplcR3NQCm5OWxnfmjINIspNFkWGx4WpL5VU/7/epLS20 x0guVdxSDshEMPNMOLczAac0WIap/ayXO3FyYToyBA== X-Google-Smtp-Source: ACHHUZ7mZIdbtVq9abQymkwAkg7a2y9pYQfgyPFLFW+lma9yoVetqpmRFK0kYww8wycuBSVWxmo9Gg== X-Received: by 2002:a5d:8ac2:0:b0:766:5445:2690 with SMTP id e2-20020a5d8ac2000000b0076654452690mr12355737iot.14.1684946246419; Wed, 24 May 2023 09:37:26 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:26 -0700 (PDT) Date: Wed, 24 May 2023 10:36:55 -0600 Subject: [PATCH 04/25] Transfer ownership of exception string to ada_catchpoint MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-4-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This changes the ada_catchpoint to require an rvalue ref, so that ownership of the exception string can be transferred to the catchpoint object. --- gdb/ada-lang.c | 16 +++++++++------- gdb/ada-lang.h | 2 +- gdb/mi/mi-cmd-catch.c | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 50eea4860ba..374cec57090 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12139,8 +12139,10 @@ struct ada_catchpoint : public code_breakpoint const char *addr_string_, bool tempflag, bool enabled, - bool from_tty) + bool from_tty, + std::string &&excep_string_) : code_breakpoint (gdbarch_, bp_catchpoint, tempflag), + excep_string (std::move (excep_string_)), m_kind (kind) { add_location (sal); @@ -12807,7 +12809,7 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, void create_ada_exception_catchpoint (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, - const std::string &excep_string, + std::string &&excep_string, const std::string &cond_string, int tempflag, int enabled, @@ -12818,8 +12820,8 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, std::unique_ptr c (new ada_catchpoint (gdbarch, ex_kind, sal, addr_string.c_str (), - tempflag, enabled, from_tty)); - c->excep_string = excep_string; + tempflag, enabled, from_tty, + std::move (excep_string))); create_excep_cond_exprs (c.get (), ex_kind); if (!cond_string.empty ()) set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty, false); @@ -12846,7 +12848,7 @@ catch_ada_exception_command (const char *arg_entry, int from_tty, catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string, &cond_string); create_ada_exception_catchpoint (gdbarch, ex_kind, - excep_string, cond_string, + std::move (excep_string), cond_string, tempflag, 1 /* enabled */, from_tty); } @@ -12871,7 +12873,7 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty, catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string, &cond_string); create_ada_exception_catchpoint (gdbarch, ex_kind, - excep_string, cond_string, + std::move (excep_string), cond_string, tempflag, 1 /* enabled */, from_tty); } @@ -12938,7 +12940,7 @@ catch_assert_command (const char *arg_entry, int from_tty, arg = ""; catch_ada_assert_command_split (arg, cond_string); create_ada_exception_catchpoint (gdbarch, ada_catch_assert, - "", cond_string, + {}, cond_string, tempflag, 1 /* enabled */, from_tty); } diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index f5bb54c7d36..08620d7ed7c 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -341,7 +341,7 @@ extern const char *ada_main_name (); extern void create_ada_exception_catchpoint (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, - const std::string &excep_string, const std::string &cond_string, int tempflag, + std::string &&excep_string, const std::string &cond_string, int tempflag, int enabled, int from_tty); /* Return true if BP is an Ada catchpoint. */ diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c index 082703740af..dcd48a84a5d 100644 --- a/gdb/mi/mi-cmd-catch.c +++ b/gdb/mi/mi-cmd-catch.c @@ -153,7 +153,7 @@ mi_cmd_catch_exception (const char *cmd, char *argv[], int argc) scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); create_ada_exception_catchpoint (gdbarch, ex_kind, - exception_name, + std::move (exception_name), condition, temp, enabled, 0); } @@ -217,7 +217,7 @@ mi_cmd_catch_handlers (const char *cmd, char *argv[], int argc) scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); create_ada_exception_catchpoint (gdbarch, ada_catch_handlers, - exception_name, + std::move (exception_name), condition, temp, enabled, 0); } From patchwork Wed May 24 16:36:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69965 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 D22D8384D193 for ; Wed, 24 May 2023 16:38:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D22D8384D193 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946286; bh=Gp0zTsbqMHN6vDWP2h2EVG9c9AWF2LVTzlpnIK+s93w=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=C1I9vxhCkRF2XmQxhRy2fO6DYObzxVE0CRjaB0QM5ikcNGycA7tz9FrYfmALcsNNr wGTWISrW9pqpMk5LI4irelniDNyH6+4P64HmeXmTbsBM6wqBcBBWRlsMJqRuZ5rbqC HgmksVC0/a1UlqAgoz2630Ak0vyReuvw1Or+0fkM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id CFA323858418 for ; Wed, 24 May 2023 16:37:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFA323858418 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-77496b0b345so17095339f.3 for ; Wed, 24 May 2023 09:37:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946247; x=1687538247; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gp0zTsbqMHN6vDWP2h2EVG9c9AWF2LVTzlpnIK+s93w=; b=R/PuliJ7HzW+URjKOmJpqcyXvIR9q1YM9zn951DNyTw79bJgtj237u5oo46YTBvyM2 6NHyzpF7aWaVK46vvF57OHRr+iYmf5fSz3qOJME6T571E0gnAjTQqKCu9+yei1UGOeZI y9imYChGQhMC/bzjJz4CVzJ32DvQ0urqMRjwJX7y/Qo304kdLJLxdgvbi8EZLVoFBAH0 UIzDyzq889DJE+b0UWa9SeGcn+xLGJhQkOsXem6A3lLZblaByDgM+Cdj7ic5haSyM8XP d1l5SYMY1fbvAu5EIET3PKpfVRsjZD/o0gnmTlsTv5yC1Bqo7vjwReFCZwpN7M7W/UyI KOEA== X-Gm-Message-State: AC+VfDwgG36rDQtoKL0bzIe1xt7TXrwvrjc/FM05Z0Miyj7NahZGUDht C4t/kQGIsfWRP/eOdKPUgFdsuF7X2SfBZaTuNZuRJw== X-Google-Smtp-Source: ACHHUZ7FSMHuToBPV5jA/qtFNaJn755Go5yewcq25wqz1JDoRLLW7yxV40001J8sRmgwx1zTgue2cg== X-Received: by 2002:a5d:91d4:0:b0:76e:fc55:fdc4 with SMTP id k20-20020a5d91d4000000b0076efc55fdc4mr11527389ior.5.1684946247004; Wed, 24 May 2023 09:37:27 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:26 -0700 (PDT) Date: Wed, 24 May 2023 10:36:56 -0600 Subject: [PATCH 05/25] Combine create_excep_cond_exprs and ada_catchpoint::re_set MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-5-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This patch merges create_excep_cond_exprs into ada_catchpoint::re_set. This is less verbose and is also a step toward making ada_catchpoint work more like the other code_breakpoint-based exception catchpoints. --- gdb/ada-lang.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 374cec57090..24ed93f2004 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12174,6 +12174,8 @@ struct ada_catchpoint : public code_breakpoint locspec = string_to_location_spec (&addr_string_, language_def (language_ada)); language = language_ada; + + re_set (); } struct bp_location *allocate_location () override; @@ -12207,29 +12209,35 @@ class ada_catchpoint_location : public bp_location expression_up excep_cond_expr; }; -/* Parse the exception condition string in the context of each of the - catchpoint's locations, and store them for later evaluation. */ +/* Implement the RE_SET method in the structure for all exception + catchpoint kinds. */ -static void -create_excep_cond_exprs (struct ada_catchpoint *c, - enum ada_exception_catchpoint_kind ex) +void +ada_catchpoint::re_set () { + /* Call the base class's method. This updates the catchpoint's + locations. */ + this->code_breakpoint::re_set (); + + /* Reparse the exception conditional expressions. One for each + location. */ + /* Nothing to do if there's no specific exception to catch. */ - if (c->excep_string.empty ()) + if (excep_string.empty ()) return; /* Same if there are no locations... */ - if (c->loc == NULL) + if (loc == NULL) return; /* Compute the condition expression in text form, from the specific expection we want to catch. */ std::string cond_string - = ada_exception_catchpoint_cond_string (c->excep_string.c_str (), ex); + = ada_exception_catchpoint_cond_string (excep_string.c_str (), m_kind); /* Iterate over all the catchpoint's locations, and parse an expression for each. */ - for (bp_location *bl : c->locations ()) + for (bp_location *bl : locations ()) { struct ada_catchpoint_location *ada_loc = (struct ada_catchpoint_location *) bl; @@ -12250,7 +12258,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c, { warning (_("failed to reevaluate internal exception condition " "for catchpoint %d: %s"), - c->number, e.what ()); + number, e.what ()); } } @@ -12267,21 +12275,6 @@ ada_catchpoint::allocate_location () return new ada_catchpoint_location (this); } -/* Implement the RE_SET method in the structure for all exception - catchpoint kinds. */ - -void -ada_catchpoint::re_set () -{ - /* Call the base class's method. This updates the catchpoint's - locations. */ - this->code_breakpoint::re_set (); - - /* Reparse the exception conditional expressions. One for each - location. */ - create_excep_cond_exprs (this, m_kind); -} - /* Returns true if we should stop for this breakpoint hit. If the user specified a specific exception, we only want to cause a stop if the program thrown that exception. */ @@ -12822,7 +12815,6 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, (new ada_catchpoint (gdbarch, ex_kind, sal, addr_string.c_str (), tempflag, enabled, from_tty, std::move (excep_string))); - create_excep_cond_exprs (c.get (), ex_kind); if (!cond_string.empty ()) set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty, false); install_breakpoint (0, std::move (c), 1); From patchwork Wed May 24 16:36:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69971 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 827583882018 for ; Wed, 24 May 2023 16:38:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 827583882018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946339; bh=I7zJXUqigdiJ2nM8FVmVUqg7ZaJfF8kbZcs14FV1g74=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iLuIwvTtnaIypMb4GlzVv/oB8R0hVQWmTGLEesBlLbwSgK0fuhkaS70F8R2wqJz28 bGngaEj4SNNuC91Edrw5kLkcBzP+UuJrezPEvF3eoZ2KwxQYaRbEghORjyWNq6TAKi wAUsfbr4wC8cXj/IOJPB25Xu8E5JOQALABACo1lQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 54B4C3858289 for ; Wed, 24 May 2023 16:37:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54B4C3858289 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-77487baabbbso32317539f.3 for ; Wed, 24 May 2023 09:37:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946247; x=1687538247; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I7zJXUqigdiJ2nM8FVmVUqg7ZaJfF8kbZcs14FV1g74=; b=Aqs7YfKBA1folFaX+Tfzk6ltlGFmwdACIwKbecfYmsn5qxsrwskbEz55zrZI3/Y20v 6eTOmGrah8duVEZQuqayZDIfxBQFWnts9HEm92sjMPHdPYmaackqUv6BmK9n/LnGZ9fW r+4jdpE1PF7RymRbBVFrPm0R1HQQGgGyZFm8hr9CaMpYcxydsygQbyGgOebLfg+18xRU +gTiAsfTiLRCiTppmyAEL4xJ6F7RbM5Bfn7EqWjP73ybG8Q+EvCUX1Nb1V3VbUViHqJT A1X7bMYKMRqp4vJkF8i+5UyVZDYmzSL7v3ch6/nSv2tqh/nsEgg/tFLbxeFJCEA4X0X1 sQrA== X-Gm-Message-State: AC+VfDx3by6LntJUd3GoGDwc++dqsGu2o5pwW/8V3X7cpPpuTRcYoTr3 edRUKgDdNA7ot+wcuIz+Mvl1Am105kmZB3X5WMwq7A== X-Google-Smtp-Source: ACHHUZ40USXH9U/rsfqFDrZvvLv0aQzbk10qx7NvwYm7AhL0HOjIvqi6AWejT8ydj/tI8+rtJCBMGw== X-Received: by 2002:a6b:db0a:0:b0:774:8d9f:e3e2 with SMTP id t10-20020a6bdb0a000000b007748d9fe3e2mr2875900ioc.17.1684946247610; Wed, 24 May 2023 09:37:27 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:27 -0700 (PDT) Date: Wed, 24 May 2023 10:36:57 -0600 Subject: [PATCH 06/25] Turn should_stop_exception into a method of ada_catchpoint MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-6-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This turns the should_stop_exception function in ada-lang.c into a method of ada_catchpoint. --- gdb/ada-lang.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 24ed93f2004..d8c7492551c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12186,6 +12186,12 @@ struct ada_catchpoint : public code_breakpoint void print_mention () const override; void print_recreate (struct ui_file *fp) const override; + /* A helper function for check_status. Returns true if we should + stop for this breakpoint hit. If the user specified a specific + exception, we only want to cause a stop if the program thrown + that exception. */ + bool should_stop_exception (const struct bp_location *bl) const; + /* The name of the specific exception the user specified. */ std::string excep_string; @@ -12275,12 +12281,10 @@ ada_catchpoint::allocate_location () return new ada_catchpoint_location (this); } -/* Returns true if we should stop for this breakpoint hit. If the - user specified a specific exception, we only want to cause a stop - if the program thrown that exception. */ +/* See declaration. */ -static bool -should_stop_exception (const struct bp_location *bl) +bool +ada_catchpoint::should_stop_exception (const struct bp_location *bl) const { struct ada_catchpoint *c = (struct ada_catchpoint *) bl->owner; const struct ada_catchpoint_location *ada_loc From patchwork Wed May 24 16:36:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69969 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 41CA238323F0 for ; Wed, 24 May 2023 16:38:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41CA238323F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946334; bh=/CG1Lv+ItoQLBCN4LTcPmK7nXWRzTHizZ1KyTUArPnM=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CeuN/t/1bHE+OXPEAu5eQuCUGfSuMGbxjjsxF+EivmQfh3lFeGwAIwFpslN5fqkyB m+7VYVs/ccLbOwdxStwea+3GOwXa1CSjZTJGeupqhQr10RtG4Y8c4Y7SG6kmzUABWM Kr1Ay10waZ2kuH1CgWl670yadGJdnzv+OLmOCDak= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id EFBCB3857711 for ; Wed, 24 May 2023 16:37:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFBCB3857711 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-76c64da0e46so36174239f.0 for ; Wed, 24 May 2023 09:37:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946248; x=1687538248; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/CG1Lv+ItoQLBCN4LTcPmK7nXWRzTHizZ1KyTUArPnM=; b=Gzns7oSCs5ctD0Eyj89IcfwR0hM8SQxhFbcJJpZIo0AaYJmKZooFK7VA4NjIaRZrWV VBO+YGGkbl5ieMMKMEVoBUdsbz4UHWThrDnhL5dNGE8FzEFje4CrGQb4Mt4+5Y5eAnTd iZUKtx/LT4lUeL7yv8xOhBxPcGiJhwU5NJ0+83uZGQ++ylzUuy2+JJM84DkaCQzhMS7r QPDh8XKlGxCWJ9As+Ienq1OVxdQ48HRSgTYzH7cWOYg7fSc/UlXAltgN9iLSp44RjgiU 0rXAkPxS8rqbaWBTazsEkoeF6fh0J9XiGttOuEe7iTjwL0uox6B0/Use+NYrK1LxM2Qq gRYA== X-Gm-Message-State: AC+VfDxK5cvjJZ3qJISg0i/opqxXE1Scx3U4trzVbo1O1kYyKefadbDF SMso71vvchQ2+s70g+fa+gsduINC6SYDKAEmq2R2iA== X-Google-Smtp-Source: ACHHUZ5mRTbsSaguPvodgkH3Dx4jq9eJnbsyFvTHc96g+sw7RqOmTjLGBCanmKlNOrLHedXwCx4StQ== X-Received: by 2002:a5e:d610:0:b0:774:982e:cb0a with SMTP id w16-20020a5ed610000000b00774982ecb0amr865858iom.15.1684946248173; Wed, 24 May 2023 09:37:28 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:27 -0700 (PDT) Date: Wed, 24 May 2023 10:36:58 -0600 Subject: [PATCH 07/25] Mark members of ada_catchpoint "private" MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-7-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This changes the members of ada_catchpoint to be private. --- gdb/ada-lang.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d8c7492551c..6ee507147cb 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12142,7 +12142,7 @@ struct ada_catchpoint : public code_breakpoint bool from_tty, std::string &&excep_string_) : code_breakpoint (gdbarch_, bp_catchpoint, tempflag), - excep_string (std::move (excep_string_)), + m_excep_string (std::move (excep_string_)), m_kind (kind) { add_location (sal); @@ -12186,6 +12186,8 @@ struct ada_catchpoint : public code_breakpoint void print_mention () const override; void print_recreate (struct ui_file *fp) const override; +private: + /* A helper function for check_status. Returns true if we should stop for this breakpoint hit. If the user specified a specific exception, we only want to cause a stop if the program thrown @@ -12193,7 +12195,7 @@ struct ada_catchpoint : public code_breakpoint bool should_stop_exception (const struct bp_location *bl) const; /* The name of the specific exception the user specified. */ - std::string excep_string; + std::string m_excep_string; /* What kind of catchpoint this is. */ enum ada_exception_catchpoint_kind m_kind; @@ -12229,7 +12231,7 @@ ada_catchpoint::re_set () location. */ /* Nothing to do if there's no specific exception to catch. */ - if (excep_string.empty ()) + if (m_excep_string.empty ()) return; /* Same if there are no locations... */ @@ -12239,7 +12241,7 @@ ada_catchpoint::re_set () /* Compute the condition expression in text form, from the specific expection we want to catch. */ std::string cond_string - = ada_exception_catchpoint_cond_string (excep_string.c_str (), m_kind); + = ada_exception_catchpoint_cond_string (m_excep_string.c_str (), m_kind); /* Iterate over all the catchpoint's locations, and parse an expression for each. */ @@ -12316,7 +12318,7 @@ ada_catchpoint::should_stop_exception (const struct bp_location *bl) const } /* With no specific exception, should always stop. */ - if (c->excep_string.empty ()) + if (c->m_excep_string.empty ()) return true; if (ada_loc->excep_cond_expr == NULL) @@ -12456,10 +12458,10 @@ ada_catchpoint::print_one (bp_location **last_loc) const switch (m_kind) { case ada_catch_exception: - if (!excep_string.empty ()) + if (!m_excep_string.empty ()) { std::string msg = string_printf (_("`%s' Ada exception"), - excep_string.c_str ()); + m_excep_string.c_str ()); uiout->field_string ("what", msg); } @@ -12473,11 +12475,11 @@ ada_catchpoint::print_one (bp_location **last_loc) const break; case ada_catch_handlers: - if (!excep_string.empty ()) + if (!m_excep_string.empty ()) { uiout->field_fmt ("what", _("`%s' Ada exception handlers"), - excep_string.c_str ()); + m_excep_string.c_str ()); } else uiout->field_string ("what", "all Ada exceptions handlers"); @@ -12511,10 +12513,10 @@ ada_catchpoint::print_mention () const switch (m_kind) { case ada_catch_exception: - if (!excep_string.empty ()) + if (!m_excep_string.empty ()) { std::string info = string_printf (_("`%s' Ada exception"), - excep_string.c_str ()); + m_excep_string.c_str ()); uiout->text (info); } else @@ -12526,11 +12528,11 @@ ada_catchpoint::print_mention () const break; case ada_catch_handlers: - if (!excep_string.empty ()) + if (!m_excep_string.empty ()) { std::string info = string_printf (_("`%s' Ada exception handlers"), - excep_string.c_str ()); + m_excep_string.c_str ()); uiout->text (info); } else @@ -12557,8 +12559,8 @@ ada_catchpoint::print_recreate (struct ui_file *fp) const { case ada_catch_exception: gdb_printf (fp, "catch exception"); - if (!excep_string.empty ()) - gdb_printf (fp, " %s", excep_string.c_str ()); + if (!m_excep_string.empty ()) + gdb_printf (fp, " %s", m_excep_string.c_str ()); break; case ada_catch_exception_unhandled: From patchwork Wed May 24 16:36:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69968 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 AAE43384B81B for ; Wed, 24 May 2023 16:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAE43384B81B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946320; bh=lQHNz5o5QXMI3C0lc/NQTYDDvimJRWkmHw35d4iibhQ=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=cSxOWwX3RlD7B6/bCYbljaI0Ikmy+u0Rx9Vr8KnnQ9qoXCiuLUvKzq+BJyvzw/eE6 rbCbsJ78y9zkCfPPM0A/hZR5L/8bmhPdZOSD4qvxHgCRSms7EMORUT5SiqS9lntodN OH7pvv4ifMA8gSarMTkEq6GveXYMSF/UkgAY0i04= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id 95C173857720 for ; Wed, 24 May 2023 16:37:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95C173857720 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7748edd6c87so33105639f.0 for ; Wed, 24 May 2023 09:37:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946249; x=1687538249; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lQHNz5o5QXMI3C0lc/NQTYDDvimJRWkmHw35d4iibhQ=; b=ilKPavR+5n9aDT3VOO9jzXWmjul8ukgpPMHt5cJCMWpoXRntHzH/giEdL6+SYQi24g t9W7vYTS/fp7zzF2++OPqvh/of0OxCbF1RzNTsWOT7Btrbq0SP0hbNcUN2PtxqQ75TP5 oqCugY5UZXib7C8FluAeWlEybZlosefjbtFUyiyjSNScocmZU9N3m5NOsJ4e02fkjkgh 0rHTzO0p60RQtSFRjXTT+PqoHSCUTMHdJuOQgBrQwHjiHhEO7Q0lN+ZIroKTMeLDeAQC atnQNBCj/8dH9JazZ32dYIGcx67mBp0sZ1CQouevhyBT3bSU+w/kRcO7sccsZIgC7N+Z pxhw== X-Gm-Message-State: AC+VfDz467rV18FnqiJXYkyGHx6XMICLH6d1KCpWJlXyJ7f47lzS/ml1 CTGWDiOQqa3pl2qEQfFPuAaP/K0OQ8Hw+Fwcn8CxTQ== X-Google-Smtp-Source: ACHHUZ4hVhP459ePgLNoHWbHdIJK9R/NfLC4nynpIIGaDzd2XS8U+JbJIuVo7picX0BuRjHMVbakQw== X-Received: by 2002:a5e:a907:0:b0:774:91f6:9530 with SMTP id c7-20020a5ea907000000b0077491f69530mr1849159iod.9.1684946248758; Wed, 24 May 2023 09:37:28 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:28 -0700 (PDT) Date: Wed, 24 May 2023 10:36:59 -0600 Subject: [PATCH 08/25] Don't require inferior execution for Ada catchpoints MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-8-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" Currently, Ada catchpoints require that the inferior be running. However, there's no deep reason for this -- for example, C++ exception catchpoints do not have this requirement. Instead, those work like ordinary breakpoints: they are pending until the needed runtime locations are seen. This patch changes Ada catchpoints to work the same way. --- gdb/ada-lang.c | 115 +++++++++++++++------------------------------------------ 1 file changed, 29 insertions(+), 86 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 6ee507147cb..f9d5965f055 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -790,18 +790,6 @@ ada_get_decoded_type (struct type *type) /* Language Selection */ -/* If the main program is in Ada, return language_ada, otherwise return LANG - (the main program is in Ada iif the adainit symbol is found). */ - -static enum language -ada_update_initial_language (enum language lang) -{ - if (lookup_minimal_symbol ("adainit", NULL, NULL).minsym != NULL) - return language_ada; - - return lang; -} - /* If the main procedure is written in Ada, then return its name. The result is good until the next call. Return NULL if the main procedure doesn't appear to be in Ada. */ @@ -11827,31 +11815,8 @@ ada_exception_support_info_sniffer (void) return; } - /* Sometimes, it is normal for us to not be able to find the routine - we are looking for. This happens when the program is linked with - the shared version of the GNAT runtime, and the program has not been - started yet. Inform the user of these two possible causes if - applicable. */ - - if (ada_update_initial_language (language_unknown) != language_ada) - error (_("Unable to insert catchpoint. Is this an Ada main program?")); - - /* If the symbol does not exist, then check that the program is - already started, to make sure that shared libraries have been - loaded. If it is not started, this may mean that the symbol is - in a shared library. */ - - if (inferior_ptid.pid () == 0) - error (_("Unable to insert catchpoint. Try to start the program first.")); - - /* At this point, we know that we are debugging an Ada program and - that the inferior has been started, but we still are not able to - find the run-time symbols. That can mean that we are in - configurable run time mode, or that a-except as been optimized - out by the linker... In any case, at this point it is not worth - supporting this feature. */ - - error (_("Cannot insert Ada exception catchpoints in this configuration.")); + throw_error (NOT_FOUND_ERROR, + _("Could not find Ada runtime exception support")); } /* True iff FRAME is very likely to be that of a function that is @@ -12135,44 +12100,19 @@ struct ada_catchpoint : public code_breakpoint { ada_catchpoint (struct gdbarch *gdbarch_, enum ada_exception_catchpoint_kind kind, - struct symtab_and_line sal, - const char *addr_string_, + const char *cond_string, bool tempflag, bool enabled, bool from_tty, std::string &&excep_string_) - : code_breakpoint (gdbarch_, bp_catchpoint, tempflag), + : code_breakpoint (gdbarch_, bp_catchpoint, tempflag, cond_string), m_excep_string (std::move (excep_string_)), m_kind (kind) { - add_location (sal); - /* Unlike most code_breakpoint types, Ada catchpoints are pspace-specific. */ - gdb_assert (sal.pspace != nullptr); - this->pspace = sal.pspace; - - if (from_tty) - { - struct gdbarch *loc_gdbarch = get_sal_arch (sal); - if (!loc_gdbarch) - loc_gdbarch = gdbarch; - - describe_other_breakpoints (loc_gdbarch, - sal.pspace, sal.pc, sal.section, -1); - /* FIXME: brobecker/2006-12-28: Actually, re-implement a special - version for exception catchpoints, because two catchpoints - used for different exception names will use the same address. - In this case, a "breakpoint ... also set at..." warning is - unproductive. Besides, the warning phrasing is also a bit - inappropriate, we should use the word catchpoint, and tell - the user what type of catchpoint it is. The above is good - enough for now, though. */ - } - + pspace = current_program_space; enable_state = enabled ? bp_enabled : bp_disabled; - locspec = string_to_location_spec (&addr_string_, - language_def (language_ada)); language = language_ada; re_set (); @@ -12217,15 +12157,29 @@ class ada_catchpoint_location : public bp_location expression_up excep_cond_expr; }; +static struct symtab_and_line ada_exception_sal + (enum ada_exception_catchpoint_kind ex); + /* Implement the RE_SET method in the structure for all exception catchpoint kinds. */ void ada_catchpoint::re_set () { - /* Call the base class's method. This updates the catchpoint's - locations. */ - this->code_breakpoint::re_set (); + std::vector sals; + try + { + struct symtab_and_line sal = ada_exception_sal (m_kind); + sals.push_back (sal); + } + catch (const gdb_exception_error &ex) + { + /* For NOT_FOUND_ERROR, the breakpoint will be pending. */ + if (ex.error != NOT_FOUND_ERROR) + throw; + } + + update_breakpoint_locations (this, pspace, sals, {}); /* Reparse the exception conditional expressions. One for each location. */ @@ -12756,16 +12710,11 @@ ada_exception_catchpoint_cond_string (const char *excep_string, return result; } -/* Return the symtab_and_line that should be used to insert an exception - catchpoint of the TYPE kind. - - ADDR_STRING returns the name of the function where the real - breakpoint that implements the catchpoints is set, depending on the - type of catchpoint we need to create. */ +/* Return the symtab_and_line that should be used to insert an + exception catchpoint of the TYPE kind. */ static struct symtab_and_line -ada_exception_sal (enum ada_exception_catchpoint_kind ex, - std::string *addr_string) +ada_exception_sal (enum ada_exception_catchpoint_kind ex) { const char *sym_name; struct symbol *sym; @@ -12779,14 +12728,12 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, sym = standard_lookup (sym_name, NULL, VAR_DOMAIN); if (sym == NULL) - error (_("Catchpoint symbol not found: %s"), sym_name); + throw_error (NOT_FOUND_ERROR, _("Catchpoint symbol not found: %s"), + sym_name); if (sym->aclass () != LOC_BLOCK) error (_("Unable to insert catchpoint. %s is not a function."), sym_name); - /* Set ADDR_STRING. */ - *addr_string = sym_name; - return find_function_start_sal (sym, 1); } @@ -12814,15 +12761,11 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, int enabled, int from_tty) { - std::string addr_string; - struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string); - std::unique_ptr c - (new ada_catchpoint (gdbarch, ex_kind, sal, addr_string.c_str (), + (new ada_catchpoint (gdbarch, ex_kind, + cond_string.empty () ? nullptr : cond_string.c_str (), tempflag, enabled, from_tty, std::move (excep_string))); - if (!cond_string.empty ()) - set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty, false); install_breakpoint (0, std::move (c), 1); } From patchwork Wed May 24 16:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69977 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 2740138845A6 for ; Wed, 24 May 2023 16:40:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2740138845A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946405; bh=rtcu6P7FB9NOrFAl6weu9ph5nDpj/CWHcFTPf+UAPUE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=x2kijyafO9XIWPc6RO3bVYqsv3GEPRdjLiIUK964sqpQdjXGvTZ411goy1l3rDoI/ 7FM9yz9TxQTYIjHocxpVNnVPesvzggw2PmlP+2NzO4xHXLk9EUs2XmfRFSdLwObAD0 HHxLnQ11MMmM9xWRgYsXq+lwsjLxuu1KMCCmSnu4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id BD9F33857722 for ; Wed, 24 May 2023 16:37:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD9F33857722 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7665e607d1bso30451839f.3 for ; Wed, 24 May 2023 09:37:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946249; x=1687538249; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rtcu6P7FB9NOrFAl6weu9ph5nDpj/CWHcFTPf+UAPUE=; b=YHnuM3RBH37q5Kgc761nmSU0GoNIuFx5JorMbe3dr2K7hXJBOqK/odijdI9QKYmQMq uNkwvlTXWN9s/9laYh/qJiIvgBmauLWSSAOcgXIux6e6ZaB7UvBRisvU7DcneyXG3WvP u/lKz5xvIDAjCer3HkXUHDcKyHfHvKKRiPhgrS8XF/F0+6WuYUStHO3gnZYmrXgiPD1F IO1AgvEgAYC6/CHq+2AucoJQ6c799DrOWE613pjwE6n/rRa1KtqCYXLRWXQCRwjcIMi/ YgnPoiaa/fz3hw6rdkoo+UOG+SgTK2bjo7NL++/FGBDPsG+c/9iPB7+c2IvcD8yTpgPe NapA== X-Gm-Message-State: AC+VfDyGdgYnheG3Kq42aTedYCnNw1AO3TpLfhiIP4lUqp5VQ4/pgvAf R5vMoMf4jztvnCIY6Mf8nzApe1QB2z7zTmMZvGnLdw== X-Google-Smtp-Source: ACHHUZ4HVqTZ/VCPfJ2bJ1+ZPA3J08DIINiFeP3+diG4IwiyeBTM7r7Uk8zhvXCjiKLoKAGRKIexEA== X-Received: by 2002:a05:6602:2211:b0:760:ea10:757 with SMTP id n17-20020a056602221100b00760ea100757mr10875879ion.20.1684946249351; Wed, 24 May 2023 09:37:29 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:29 -0700 (PDT) Date: Wed, 24 May 2023 10:37:00 -0600 Subject: [PATCH 09/25] Implement DAP setExceptionBreakpoints request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-9-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.8 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, T_SCC_BODY_TEXT_LINE 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" This implements the DAP setExceptionBreakpoints request for Ada. This is a somewhat minimal implementation, in that "exceptionOptions" are not implemented (or advertised) -- I wasn't completely sure how this feature is supposed to work. I haven't added C++ exception handling here, but it's easy to do if needed. This patch relies on the new MI command execution support to do its work. --- gdb/python/lib/gdb/dap/breakpoint.py | 65 ++++++++++++++++++++++++-- gdb/python/lib/gdb/dap/server.py | 4 +- gdb/testsuite/gdb.dap/catch-exception.exp | 65 ++++++++++++++++++++++++++ gdb/testsuite/gdb.dap/catch-exception/pck.ads | 18 +++++++ gdb/testsuite/gdb.dap/catch-exception/prog.adb | 44 +++++++++++++++++ 5 files changed, 189 insertions(+), 7 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index f0e1f103d1b..877069f79a5 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -37,12 +37,11 @@ def breakpoint_descriptor(bp): # https://github.com/microsoft/debug-adapter-protocol/issues/13 loc = bp.locations[0] (basename, line) = loc.source - return { + result = { "id": bp.number, "verified": True, "source": { "name": os.path.basename(basename), - "path": loc.fullname, # We probably don't need this but it doesn't hurt to # be explicit. "sourceReference": 0, @@ -50,6 +49,10 @@ def breakpoint_descriptor(bp): "line": line, "instructionReference": hex(loc.address), } + path = loc.fullname + if path is not None: + result["source"]["path"] = path + return result else: return { "id": bp.number, @@ -58,9 +61,10 @@ def breakpoint_descriptor(bp): # Helper function to set some breakpoints according to a list of -# specifications. +# specifications and a callback function to do the work of creating +# the breakpoint. @in_gdb_thread -def _set_breakpoints(kind, specs): +def _set_breakpoints_callback(kind, specs, creator): global breakpoint_map # Try to reuse existing breakpoints if possible. if kind in breakpoint_map: @@ -75,7 +79,7 @@ def _set_breakpoints(kind, specs): bp = saved_map.pop(keyspec) else: # FIXME handle exceptions here - bp = gdb.Breakpoint(**spec) + bp = creator(**spec) breakpoint_map[kind][keyspec] = bp result.append(breakpoint_descriptor(bp)) # Delete any breakpoints that were not reused. @@ -84,6 +88,13 @@ def _set_breakpoints(kind, specs): return result +# Helper function to set odinary breakpoints according to a list of +# specifications. +@in_gdb_thread +def _set_breakpoints(kind, specs): + return _set_breakpoints_callback(kind, specs, gdb.Breakpoint) + + @request("setBreakpoints") def set_breakpoint(*, source, breakpoints=[], **args): if "path" not in source: @@ -141,3 +152,47 @@ def set_insn_breakpoints(*, breakpoints, offset=None, **args): return { "breakpoints": result, } + + +@in_gdb_thread +def _catch_exception(filterId, condition=None, **args): + if filterId == "assert": + args = ["-catch-assert"] + elif filterId == "exception": + args = ["-catch-exception"] + else: + raise Exception(f"Invalid exception filterID: {filterId}") + if condition is not None: + args.extend(["-c", condition]) + result = gdb.execute_mi(*args) + # A little lame that there's no more direct way. + for bp in gdb.breakpoints(): + if bp.number == result["bkptno"]: + return bp + raise Exception("Could not find catchpoint after creating") + + +@in_gdb_thread +def _set_exception_catchpoints(filter_options): + return _set_breakpoints_callback("exception", filter_options, _catch_exception) + + +@request("setExceptionBreakpoints") +@capability("supportsExceptionFilterOptions") +@capability("exceptionBreakpointFilters", ({ + "filter": "assert", + "label": "Ada assertions", + "supportsCondition": True, +}, { + "filter": "exception", + "label": "Ada exceptions", + "supportsCondition": True, +})) +def set_exception_breakpoints(*, filters, filterOptions=[], **args): + # Convert the 'filters' to the filter-options style. + options = [{"filterId": filter} for filter in filters] + options.extend(filterOptions) + result = send_gdb_with_response(lambda: _set_exception_catchpoints(options)) + return { + "breakpoints": result, + } diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index ff88282049f..f27fa9caa4f 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -171,13 +171,13 @@ def request(name): return wrap -def capability(name): +def capability(name, value=True): """A decorator that indicates that the wrapper function implements the DAP capability NAME.""" def wrap(func): global _capabilities - _capabilities[name] = True + _capabilities[name] = value return func return wrap diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp new file mode 100644 index 00000000000..6bfeb3ed87e --- /dev/null +++ b/gdb/testsuite/gdb.dap/catch-exception.exp @@ -0,0 +1,65 @@ +# 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 . + +load_lib ada.exp +load_lib dap-support.exp + +require allow_ada_tests allow_dap_tests gnat_runtime_has_debug_info + +standard_ada_testfile prog + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \ + {debug additional_flags=-gnata}] != ""} { + return -1 +} + +if {[dap_launch $binfile] == ""} { + return +} + +set obj [dap_check_request_and_response "set exception catchpoints" \ + setExceptionBreakpoints \ + {o filters [a [s assert]] \ + filterOptions [a [o filterId [s exception] \ + condition [s "Global_Var = 23"]]]}] + +set bps [dict get [lindex $obj 0] body breakpoints] +gdb_assert {[llength $bps] == 2} "two breakpoints" + +# The "path" should never be "null". +set i 1 +foreach spec $bps { + # If "path" does not exist, then that is fine as well. + if {![dict exists $spec source path]} { + pass "breakpoint $i path" + } else { + gdb_assert {[dict get $spec source path] != "null"} \ + "breakpoint $i path" + } + incr i +} + +dap_check_request_and_response "start inferior" configurationDone + +dap_wait_for_event_and_check "stopped at first raise" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" 2 + +dap_check_request_and_response "continue to assert" continue +dap_wait_for_event_and_check "stopped at assert" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" 1 + +dap_shutdown diff --git a/gdb/testsuite/gdb.dap/catch-exception/pck.ads b/gdb/testsuite/gdb.dap/catch-exception/pck.ads new file mode 100644 index 00000000000..e82a54fa60a --- /dev/null +++ b/gdb/testsuite/gdb.dap/catch-exception/pck.ads @@ -0,0 +1,18 @@ +-- 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 . + +package Pck is + Global_Var : Integer := 91; +end Pck; diff --git a/gdb/testsuite/gdb.dap/catch-exception/prog.adb b/gdb/testsuite/gdb.dap/catch-exception/prog.adb new file mode 100644 index 00000000000..287eb2492f9 --- /dev/null +++ b/gdb/testsuite/gdb.dap/catch-exception/prog.adb @@ -0,0 +1,44 @@ +-- 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 . + +with Pck; use Pck; + +procedure Prog is +begin + + begin + raise Program_Error; + exception + when others => + null; + end; + + begin + Global_Var := 23; + raise Program_Error; + exception + when others => + null; + end; + + begin + pragma Assert (False); + null; + exception + when others => + null; + end; + +end Prog; From patchwork Wed May 24 16:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69972 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 4F6543857711 for ; Wed, 24 May 2023 16:39:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F6543857711 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946355; bh=KLaA2PwpqbnuGyG0pEhYLjMEAVaL+55VeJWqPFJo5h0=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OZdur4JjeNcM88ZIBpnb2zzl4BcLFVE7TwPb63MJuttcWWgXyzaX+VBk38HAH86IL Eby6Kjwyhp076nviIWrx221TvynN7aC0E0HlBQ18FsuuvpozUXXLmfAmqukCYI9C+l WrAbRoUF5AturD6ojTPkV50xvOhdltr6jnJE9wfs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id D80293857718 for ; Wed, 24 May 2023 16:37:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D80293857718 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-76c5c806fc5so32533739f.1 for ; Wed, 24 May 2023 09:37:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946250; x=1687538250; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLaA2PwpqbnuGyG0pEhYLjMEAVaL+55VeJWqPFJo5h0=; b=bgF+gJqgWRg30SzKvbmGS0Jf/iECrtM7nTvOcPJaAUb0h/NQsZTPsNxzIJuAfzELFQ O0YN2AuwKfXuz23A6ymzdX8K/ksZx4w34pr1E9BryWuCHl1kYuxgT8SN8QTeBi96U+wB GxDyoPGwQpzwaIMZTIL+yW5ZqQ7W67ruxpjG3oxi7Bu4Y0HsAl3K9ZZ1t6ccVL0r8xVF hYsTrPdifwN2U8rW37FHFVmlAdrZ6MaxTDIaCPNVUeak+RMgKhdLJlkv07VJQk94OUcN YUWqAsStexhuRKS9l8IwMb6JhEP0o+lB872oF+3m2TFKMr7tCFOrbWXA+G+OFoM7A8lp u8tg== X-Gm-Message-State: AC+VfDx+b+VPH554W6HS24ZbSxHnL78yVQUE2iM3Hy/bE9L2endXj/SB gvKXqi8W+akze1/QdhVM7C/MFDASY/MFf3L/Gmbk7g== X-Google-Smtp-Source: ACHHUZ63EG31vLqco/3BvYUWU188PLYfR3HTpduWCo9IKxViZ5dpSRywPWoSb8N2RuunH3yadSLfNw== X-Received: by 2002:a5d:8582:0:b0:76c:5641:136 with SMTP id f2-20020a5d8582000000b0076c56410136mr10698848ioj.0.1684946249955; Wed, 24 May 2023 09:37:29 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:29 -0700 (PDT) Date: Wed, 24 May 2023 10:37:01 -0600 Subject: [PATCH 10/25] Implement DAP attach request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-10-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.8 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, T_SCC_BODY_TEXT_LINE 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" This implements the DAP "attach" request. Note that the copyright dates on the new test source file are not incorrect -- this was copied verbatim from another directory. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 8 ++++++++ gdb/python/lib/gdb/dap/launch.py | 13 ++++++++++++- gdb/testsuite/gdb.dap/attach.c | 25 +++++++++++++++++++++++++ gdb/testsuite/gdb.dap/attach.exp | 36 ++++++++++++++++++++++++++++++++++++ gdb/testsuite/lib/dap-support.exp | 19 ++++++++++++++++--- 5 files changed, 97 insertions(+), 4 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index d1059e0cb7f..1b967485bc6 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39020,6 +39020,14 @@ If provided, this is a string that specifies the program to use. This corresponds to the @code{file} command. @xref{Files}. @end table +@value{GDBN} defines a parameter that can be passed to the +@code{attach} request: + +@table @code +@item pid +The process ID to which @value{GDBN} should attach. @xref{Attach}. +@end table + @node JIT Interface @chapter JIT Compilation Interface @cindex just-in-time compilation diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 21499a339e1..a46be1dcca2 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -16,7 +16,7 @@ import gdb from .events import ExecutionInvoker from .server import request, capability -from .startup import send_gdb, in_gdb_thread +from .startup import send_gdb, send_gdb_with_response, in_gdb_thread _program = None @@ -45,6 +45,17 @@ def launch(*, program=None, args=[], env=None, **extra): send_gdb(lambda: _set_args_env(args, env)) +@request("attach") +def attach(*, pid, **args): + # Ensure configurationDone does not try to run. + global _program + _program = None + # Use send_gdb_with_response to ensure we get an error if the + # attach fails. + send_gdb_with_response("attach " + str(pid)) + return None + + @capability("supportsConfigurationDoneRequest") @request("configurationDone") def config_done(**args): diff --git a/gdb/testsuite/gdb.dap/attach.c b/gdb/testsuite/gdb.dap/attach.c new file mode 100644 index 00000000000..24c5283d1e6 --- /dev/null +++ b/gdb/testsuite/gdb.dap/attach.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011-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 . */ + +#include + +int +main () +{ + sleep (600); + return 0; +} diff --git a/gdb/testsuite/gdb.dap/attach.exp b/gdb/testsuite/gdb.dap/attach.exp new file mode 100644 index 00000000000..5b308f94975 --- /dev/null +++ b/gdb/testsuite/gdb.dap/attach.exp @@ -0,0 +1,36 @@ +# 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 "attach" in DAP. + +require can_spawn_for_attach allow_dap_tests + +load_lib dap-support.exp + +standard_testfile + +if {[build_executable ${testfile}.exp $testfile] == -1} { + return +} + +set test_spawn_id [spawn_wait_for_attach $binfile] +set testpid [spawn_id_get_pid $test_spawn_id] + +# We just want to test that attaching works at all. +if {[dap_attach $testpid] != ""} { + dap_shutdown true +} + +kill_wait_spawned_process $test_spawn_id diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index ead295bdbfe..8667164fa11 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -270,9 +270,22 @@ proc dap_launch {file {args {}} {env {}}} { return [dap_check_request_and_response "startup - launch" launch $params] } -# Cleanly shut down gdb. NAME is used as the test name. -proc dap_shutdown {{name shutdown}} { - dap_check_request_and_response $name disconnect +# Start gdb, send a DAP initialize request, and then an attach request +# specifying PID as the inferior process ID. Returns the empty string +# on failure, or the response object from the attach request. +proc dap_attach {pid} { + if {[_dap_initialize "startup - initialize"] == ""} { + return "" + } + return [dap_check_request_and_response "startup - attach" attach \ + [format {o pid [i %s]} $pid]] +} + +# Cleanly shut down gdb. TERMINATE is passed as the terminateDebuggee +# parameter to the request. +proc dap_shutdown {{terminate false}} { + dap_check_request_and_response "shutdown" disconnect \ + [format {o terminateDebuggee [l %s]} $terminate] } # Search the event list EVENTS for an output event matching the regexp From patchwork Wed May 24 16:37:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69980 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 BA0943888C54 for ; Wed, 24 May 2023 16:40:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA0943888C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946433; bh=q/cf3//S/tYc6CEwgMIqIAKb0bfyjHETvVYzNeBCkCE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=x9RcEUHwXeK1IsK8FPJKwvcF6RR/4RgWPw7vskkgc42QVFtsywzhvwuRjyMltN4hi +Eg321clX1A5jrhv/soaFXFJJDRztEzIAr8121XVKXJ4FRcuR+NXCXqeUjZ9Q2h9tW cg4mjM+cCN+mH/F5DcjLEMThdD0n2qg/Z6ortEcA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id 4766B385772A for ; Wed, 24 May 2023 16:37:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4766B385772A Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7747f76946bso224539f.1 for ; Wed, 24 May 2023 09:37:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946250; x=1687538250; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q/cf3//S/tYc6CEwgMIqIAKb0bfyjHETvVYzNeBCkCE=; b=ZP7f2xVSi2ScE1Ek9exvmm/vs9JLuISXwJclk8k7mpezUI6L8ou70s41KBHjf72Weq fftrrgw3dZk+2X39YA1XN+T7VQx5c76ATc6TSU9eLwj63M2HnnqAHdCUQlDtMJ8FALKi v6Z1HmgEu/Okny6HLEtMGXKwqD2r9ShcWhJF5WsgAx4xG37qHzHczcy13o91+oHcpy3v C8s4sinCaWPlcjtgeIjoaaMU1vx4ovjBCCCuhGRyBEfwxOoNlodQSbUZrI9z9dQvUJQ9 KZMCM2LXoV4JWfq6CAIUbSCbClrgWy7hHDYpgKZ4LKRo9PUQNUV+WPm4p+cfYlvANvL1 r55w== X-Gm-Message-State: AC+VfDwbZ8j0t+43LQqzkjLZ1ouAM8CUxdQdL3NtwG6uXwajZDMup98X wuV3cIhuBo2vPRMjgXdJBUloB1mqTCikocT5vd0X9w== X-Google-Smtp-Source: ACHHUZ5IHt5HmdDJVjKNV1hlT7qkbS4ocm1zSxBDTWwEceuXG76hdlpEp7a5Wu4vF0DzBzGoOYUywg== X-Received: by 2002:a5e:dc0a:0:b0:76c:8cbe:c8fc with SMTP id b10-20020a5edc0a000000b0076c8cbec8fcmr13912iok.3.1684946250632; Wed, 24 May 2023 09:37:30 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:30 -0700 (PDT) Date: Wed, 24 May 2023 10:37:02 -0600 Subject: [PATCH 11/25] Implement DAP stepOut request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-11-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This implements the DAP "stepOut" request. --- gdb/python/lib/gdb/dap/next.py | 6 ++++++ gdb/testsuite/gdb.dap/basic-dap.c | 10 +++++++++- gdb/testsuite/gdb.dap/basic-dap.exp | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 636dfce997d..232b1529fe5 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -44,6 +44,12 @@ def stepIn(*, threadId, granularity="statement", **args): send_gdb(ExecutionInvoker(cmd, StopKinds.STEP)) +@request("stepOut") +def step_out(*, threadId): + _handle_thread_step(threadId) + send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) + + @request("continue") def continue_request(**args): send_gdb(ExecutionInvoker("continue", None)) diff --git a/gdb/testsuite/gdb.dap/basic-dap.c b/gdb/testsuite/gdb.dap/basic-dap.c index a8327141fb0..2570b8b0702 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.c +++ b/gdb/testsuite/gdb.dap/basic-dap.c @@ -35,10 +35,18 @@ address_breakpoint_here () { } -int main () +int +line_breakpoint_here () { do_not_stop_here (); function_breakpoint_here (); address_breakpoint_here (); return 0; /* BREAK */ } + + +int +main () +{ + return line_breakpoint_here (); +} diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index f28239d8268..d4dbdac70ff 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -146,6 +146,11 @@ dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $line_bpno +dap_check_request_and_response "return from function" stepOut \ + {o threadId [i 1]} +dap_wait_for_event_and_check "stopped after return" stopped \ + "body reason" step + set obj [dap_check_request_and_response "evaluate global in main" \ evaluate {o expression [s global_variable]}] dap_match_values "global value in main" [lindex $obj 0] \ From patchwork Wed May 24 16:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69975 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 790543884506 for ; Wed, 24 May 2023 16:39:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 790543884506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946387; bh=C+pRqRmr8LkaDcwu5fBccACxv36XHJktyvbzMxUuxb8=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pzdZS0+6BLz1ecWkfl4u/FzGB51VQWfPxxANEBD6sr2CovNbrHKv/KEy4uqlFOiEo bdSA8NCTYObKdm61fJlA+4SQC4pLIyfnGYFWQSOEaxyCZJzsbB+wlznjw5sVDlsWG5 DVWcnsMsxOuOu/WA1/zy/quEy5ZDNF3GGz7lXSrI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 0EFD73857714 for ; Wed, 24 May 2023 16:37:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EFD73857714 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-76c5c806fc5so32534639f.1 for ; Wed, 24 May 2023 09:37:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946251; x=1687538251; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C+pRqRmr8LkaDcwu5fBccACxv36XHJktyvbzMxUuxb8=; b=WjXG3wzWmvjlr8FxfmCfuwtEpzrM3U6ooGy52BCnWzoIoJoaWBx84oEAL6B60zWzG5 iErbNVEvFo9P5IFqnpN6ZXvFqu65cFRT7BlhPrsZw784/gDJgASSlzWa+4yMYdDHM4Jl XvMRumHLW+NCDm5KvWw4S6p6NNycyFvKWJCXX8meaaGPNCkyxY5a8MJlMZ3+LH3Jmd4d iN2YoEstkTatTRZ1mIBEQfeVWdnR9v4RkKmJe7m3sTlMc+Hb8QfpoyW20lHKNCFahFrp LkCEq7n0NoTM+gfm2/ViKArmg3OE1D4K9Tc43DO4tSomYP2wskgsSmtM3xTP3AhHjntS CNfw== X-Gm-Message-State: AC+VfDwB1o3s0kqbDRMZdJ1xjc8Rp5Txtwqt+0/FPcn8Bb+HgSYvSvGD SS5/iG1iFABIAFmztsQDPodktVDRR6L1MfUWiMxufg== X-Google-Smtp-Source: ACHHUZ5x+f5yE8T9QQYauEXNm7VYtlNtKnTJR4lBDSz5UlrBTJDLMuibtSllPronY34LBOaIMJb3ug== X-Received: by 2002:a6b:e80f:0:b0:76c:615c:7c1 with SMTP id f15-20020a6be80f000000b0076c615c07c1mr11635072ioh.16.1684946251356; Wed, 24 May 2023 09:37:31 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:30 -0700 (PDT) Date: Wed, 24 May 2023 10:37:03 -0600 Subject: [PATCH 12/25] Add singleThread support to some DAP requests MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-12-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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, T_SCC_BODY_TEXT_LINE 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" A few DAP requests support a "singleThread" parameter, which is somewhat similar to scheduler-locking. This patch implements support for this. --- gdb/python/lib/gdb/dap/next.py | 45 ++++++++++++++++++++++--------- gdb/testsuite/gdb.dap/basic-dap.exp | 9 ++++--- gdb/testsuite/gdb.dap/catch-exception.exp | 3 ++- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 232b1529fe5..290b9b855ba 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -13,21 +13,40 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import gdb + from .events import StopKinds, ExecutionInvoker from .server import capability, request -from .startup import send_gdb +from .startup import in_gdb_thread, send_gdb, send_gdb_with_response from .state import set_thread -# Helper function to set the current thread. -def _handle_thread_step(threadId): +# Helper function to set the current thread and the scheduler-locking +# mode. Returns True if scheduler-locking was successfully set to +# 'on', False in all other cases, including error. +@in_gdb_thread +def _handle_thread_step(thread_id, single_thread): # Ensure we're going to step the correct thread. - send_gdb(lambda: set_thread(threadId)) + set_thread(thread_id) + if single_thread: + result = True + arg = "on" + else: + result = False + arg = "off" + try: + # This can fail, depending on the target, so catch the error + # and report to our caller. We can't use exec_and_log because + # that does not propagate exceptions. + gdb.execute("set scheduler-locking " + arg, from_tty=True, to_string=True) + except gdb.error: + result = False + return result @request("next") -def next(*, threadId, granularity="statement", **args): - _handle_thread_step(threadId) +def next(*, threadId, singleThread=False, granularity="statement", **args): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "next" if granularity == "instruction": cmd += "i" @@ -35,9 +54,10 @@ def next(*, threadId, granularity="statement", **args): @capability("supportsSteppingGranularity") +@capability("supportsSingleThreadExecutionRequests") @request("stepIn") -def stepIn(*, threadId, granularity="statement", **args): - _handle_thread_step(threadId) +def stepIn(*, threadId, singleThread=False, granularity="statement", **args): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "step" if granularity == "instruction": cmd += "i" @@ -45,12 +65,13 @@ def stepIn(*, threadId, granularity="statement", **args): @request("stepOut") -def step_out(*, threadId): - _handle_thread_step(threadId) +def step_out(*, threadId, singleThread=False): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) @request("continue") -def continue_request(**args): +def continue_request(*, threadId, singleThread=False, **args): + locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("continue", None)) - return {"allThreadsContinued": True} + return {"allThreadsContinued": not locked} diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index d4dbdac70ff..ce739875404 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -136,15 +136,18 @@ set obj [dap_check_request_and_response "evaluate global second time" \ dap_match_values "global value after step" [lindex $obj 0] \ "body result" 24 -dap_check_request_and_response "continue to address" continue +dap_check_request_and_response "continue to address" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at address breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $insn_bpno -dap_check_request_and_response "continue to line" continue +dap_check_request_and_response "continue to line" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ - "body hitBreakpointIds" $line_bpno + "body hitBreakpointIds" $line_bpno \ + "body allThreadsStopped" true dap_check_request_and_response "return from function" stepOut \ {o threadId [i 1]} diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp index 6bfeb3ed87e..7f2e750b32e 100644 --- a/gdb/testsuite/gdb.dap/catch-exception.exp +++ b/gdb/testsuite/gdb.dap/catch-exception.exp @@ -57,7 +57,8 @@ dap_wait_for_event_and_check "stopped at first raise" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 2 -dap_check_request_and_response "continue to assert" continue +dap_check_request_and_response "continue to assert" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at assert" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 1 From patchwork Wed May 24 16:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69973 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 C33EF388216C for ; Wed, 24 May 2023 16:39:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C33EF388216C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946367; bh=RLiEN8Gq5K7VVM/tBvT/YBmxrutd/v7n7IdZFgKfxZA=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=d8stdtWPL8IcX1/GR8b454Axrw1ytpzwpBp6gNXrWWkZPvhMXtzk5lum23linGG8/ Cdq4HMl3G6TqCa6cCbMaGeI8b8qQk5hN2wPD0FbRwySH/v95onqZ/f5zhR+DXuTKtn 4TaWmdBrtHjrFoTq6ljrYZW/NGJIhqFzGftz6Yis= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id 9E3C13857353 for ; Wed, 24 May 2023 16:37:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E3C13857353 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-76c5558ba95so408139f.1 for ; Wed, 24 May 2023 09:37:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946252; x=1687538252; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLiEN8Gq5K7VVM/tBvT/YBmxrutd/v7n7IdZFgKfxZA=; b=WWARuOTocR5hbzIaFc4bCGY8gpYviNyCSBGk5AMC7mSAUaCHtj8UgOwhefGkmJunSX lXtQmMrQk+MJovktKBTo+P0Z/iW2G/7bP0Nbp4CKpt5FwgWNNi7rqF5wakie7DFGcaJn izvC/ZdzF0gy1KMW67bShw71vKo1CK6m9mWFxOU7dDg4W1PLB2mVe1fRyyv0ZrgpFLlf OZJHXfVQQK6LZ845J65k77Bb0gPmiBh3olXzGI341l6pOZhs5u4n6gq6OOQvxPlmQT9B XmmLszVBc5WMEtEzed4HDvf2PrFmjK1W+DNJMxnlHe3UgKwyYo9Mysl7n7HJGjGMJS08 8GIw== X-Gm-Message-State: AC+VfDz6SILXzevQqJ0vlACXLLuw1TxqRt90lNZA/2JLa2bMXjLeCMnb m5cbcl/BRVjcB9FU5y8pUOvG5FDcRTUroMVTKKET4Q== X-Google-Smtp-Source: ACHHUZ5HnlPVsYJdtwJBA7rOdD0EMDQNJ0eooYMzTJoWZwQdt27rdPk7TFTfkyaHy0H5NFY3+5Ojqw== X-Received: by 2002:a6b:750c:0:b0:760:ed78:a252 with SMTP id l12-20020a6b750c000000b00760ed78a252mr11945795ioh.9.1684946251944; Wed, 24 May 2023 09:37:31 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:31 -0700 (PDT) Date: Wed, 24 May 2023 10:37:04 -0600 Subject: [PATCH 13/25] Rename one DAP function MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-13-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" When I first started implementing DAP, I had some vague plan of having the implementation functions use the same name as the request. I abandoned this idea, but one vestige remained. This patch renames the one remaining function to be gdb-ish. --- gdb/python/lib/gdb/dap/next.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 290b9b855ba..75f2fa6f31a 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -56,7 +56,7 @@ def next(*, threadId, singleThread=False, granularity="statement", **args): @capability("supportsSteppingGranularity") @capability("supportsSingleThreadExecutionRequests") @request("stepIn") -def stepIn(*, threadId, singleThread=False, granularity="statement", **args): +def step_in(*, threadId, singleThread=False, granularity="statement", **args): send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "step" if granularity == "instruction": From patchwork Wed May 24 16:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69970 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 0017B38432CF for ; Wed, 24 May 2023 16:38:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0017B38432CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946336; bh=KVu2bwbv/DyQATSnAMBlfrJVQJ6fm/UwNJC89cWdYTI=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fpqOMICI2m6BJyx9/XBuh6O5AzdyTF+41SZBN4Je8bpoXBkp382jZJEfEn1ifowB6 oMfoXDQstDTiaFkQU0oxGJpjs5RPtZlkN6zjnceyCD7ZvFyQ929siIp0GAN7Rsq3x/ /hxvIANsdPdpqN8a9yEy41e5PJYXuxcXsAGInytc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 3E38C385843E for ; Wed, 24 May 2023 16:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E38C385843E Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-76c75d32005so31316339f.1 for ; Wed, 24 May 2023 09:37:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946252; x=1687538252; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KVu2bwbv/DyQATSnAMBlfrJVQJ6fm/UwNJC89cWdYTI=; b=ccTmlu+RvotRWIlBlNRbYd0ghBdO6KOYHN8faAwS83Pz1nd/11nHt9EdW5igEXx4+J z/YOopy4pNseGjNp+YglC61RY02i3ax5a/cbG7MB+aUcXBExCXmBfN4v1Ao5XJbELC43 denjsIxNh5YlObWfQJTNc4YaWtwuXXxg53IqYBlgsCcglqZQszSE8uffFOZ0cQnO+hvp nrHhxXdSRJ8ugu6gc/gjLjygNcC7zTENyoG+gRZ2ewh03kKwRpYobO4vqEb9XoL84GP9 dgEluNAs3CS4zkpXi/JrLsDNgbkMbWlSiEhJrKTD9/SLTBivVibJH+zZTUx+JFT03pZq 3gsQ== X-Gm-Message-State: AC+VfDyZEXguu4avA8SGC+YRl45mdNlEcS9HPqj7JTzO7R4SD7mx1EPh 0Q71Pn9gxWUbaICw38inrevHWSwOfHTw/MPKzATnqQ== X-Google-Smtp-Source: ACHHUZ7lJVOvosINARYd2YfKbk1wZohNG6oZ/JLJ3YJLqa2ZFygc/0cj63N8DRyXZTip49FGHXcTUw== X-Received: by 2002:a05:6602:2202:b0:760:ced3:4481 with SMTP id n2-20020a056602220200b00760ced34481mr10501588ion.4.1684946252539; Wed, 24 May 2023 09:37:32 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:32 -0700 (PDT) Date: Wed, 24 May 2023 10:37:05 -0600 Subject: [PATCH 14/25] Add test for DAP pause request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-14-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 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, T_SCC_BODY_TEXT_LINE 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" I neglected to write a test for the DAP "pause" request. This patch adds one. --- gdb/testsuite/gdb.dap/pause.exp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/gdb/testsuite/gdb.dap/pause.exp b/gdb/testsuite/gdb.dap/pause.exp new file mode 100644 index 00000000000..27955d31526 --- /dev/null +++ b/gdb/testsuite/gdb.dap/pause.exp @@ -0,0 +1,41 @@ +# 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 "pause" in DAP. + +require allow_dap_tests + +load_lib dap-support.exp + +standard_testfile attach.c + +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return +} + +if {[dap_launch $testfile] == ""} { + return +} + +dap_check_request_and_response "start inferior" configurationDone +dap_wait_for_event_and_check "inferior started" thread "body reason" started + +dap_check_request_and_response pause pause \ + {o threadId [i 1]} + +dap_wait_for_event_and_check "stopped by pause" stopped \ + "body reason" pause + +dap_shutdown From patchwork Wed May 24 16:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69983 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 B83BF3836E98 for ; Wed, 24 May 2023 16:41:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B83BF3836E98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946461; bh=Di0gUk2slZqejb5n365YpPY36eOtY9J1QEvgJtq9H5g=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jHkOZr5Bfu1c07TRJ+d+FDNfy3zX6lJuLXZ/pbFjuLUnTQs5SgNnoxGzPDH8To29S IT3BT3O6Ru3tz7mUYJw93mI68cnOOCS4DwRJcdj9EokWyIiomqCmmO4RgfFWrW8XQJ cBgazn6qjWjVkN5Rn/xHTwf3o2iYN5+Y2EIt/cWY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id D2D933857345 for ; Wed, 24 May 2023 16:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2D933857345 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-76c5a225388so32011039f.1 for ; Wed, 24 May 2023 09:37:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946253; x=1687538253; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Di0gUk2slZqejb5n365YpPY36eOtY9J1QEvgJtq9H5g=; b=JVm5g6KiBCCRQTU/v1wP0edwWI+UP1sxZ9VbsPiAv/iwOQmOJEqIacXjYkQ4HcRRd7 8Z3BxkBlGpnXw3rLKu5//iN0am4QZJlvkyM5Fm+fM4pw4RetS3p6Avb+ghWx5a2AayqQ VrkOLAGNHBbVBtdjEsjfWz/sx5f+FSq8FAljR9B96HNTE7FvGACyJNKD0lcRYYDa1Oz/ phXDROmWVLj+tylKsf78tKzlp7jV67m9O75QCDqYxq1THJ0u6lmcizqiczOcUUotuRPr Uv/yH2v3V8Ra08Fs/1OfMCStWP+ceMZDOxUJTBV3MqHZmmwKwOEapsNOveApuPG5YcAc 0XwA== X-Gm-Message-State: AC+VfDxZWOWcrRhNGPY3UhIPmxr8Obl0ca0qFr0uYyxolF16skSdkneb LJDPZS0Tb7GeVkKCCLylcfYJA7It/vfWaWzBtx2PBg== X-Google-Smtp-Source: ACHHUZ66Bt4R8tZlIRr3d0b6oKmNQ74qDX+utX7gEGjdE81n+diSVALsVL1GiCT4qKqpvdaqYOHYTw== X-Received: by 2002:a6b:6203:0:b0:774:9b45:f5ea with SMTP id f3-20020a6b6203000000b007749b45f5eamr441824iog.11.1684946253161; Wed, 24 May 2023 09:37:33 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:32 -0700 (PDT) Date: Wed, 24 May 2023 10:37:06 -0600 Subject: [PATCH 15/25] Fix a latent bug in DAP request decorator MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-15-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 'request' decorator is intended to also ensure that the request function runs in the DAP thread. However, the unwrapped function is installed in the global request map, so the wrapped version is never called. This patch fixes the bug. --- gdb/python/lib/gdb/dap/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index f27fa9caa4f..8abe475b031 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -164,9 +164,10 @@ def request(name): def wrap(func): global _commands - _commands[name] = func # All requests must run in the DAP thread. - return in_dap_thread(func) + func = in_dap_thread(func) + _commands[name] = func + return func return wrap From patchwork Wed May 24 16:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69976 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 39F5D382E693 for ; Wed, 24 May 2023 16:39:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39F5D382E693 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946396; bh=NEGQ5q36FskjGnSXMfn598/YoxoWWeRzqtvoB7clJY0=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GmuIzC1Oeg/UPpPN2NzfrXNL4rLtk8s3Mm0qPoplFMc/um3dzJjFSoTOiVZk2n4mX uSz2MK0DScI3il4qqov8r4S1jxpVE7sQKkYCw0nUU6lsBemIq1bWD3CjvxVBMzjAzI V0BioI0C82PIjG7LmF/iJDnLD/qbo5zSUXf9wPdk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 64B5A3857728 for ; Wed, 24 May 2023 16:37:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64B5A3857728 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7747df5b674so96834739f.3 for ; Wed, 24 May 2023 09:37:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946253; x=1687538253; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NEGQ5q36FskjGnSXMfn598/YoxoWWeRzqtvoB7clJY0=; b=SHiNeAnt1ET3SQDRfu8i026V29K2Vek7ONnEY5XuiYgagovAGvE5/oAxcL5QU2rVn2 HIYeeK4FYr4drIzimHztp12tXSC4UT788uKUSIWA+Mg3GJP5FmJHqoEt+gLIFj8P2hq3 4qJsP+fbQs+hNbTjpEqtN4Cj/8/g2+2r2+V3nGZ0QLwrchu8OqHinCCZOkET5ge7lvQ4 100vio+CAaScelZh4lP8y01b1CLKgILQoMcaYC4LQp/SNoFVoo0djfIDnmJS1alKz32t iPStyouXJv6NpKMNJVY7kWGsK+FVMFRM3/mgOJFkmyG1MbQ7STW6L6MMI0qFD2kvRfmJ taIw== X-Gm-Message-State: AC+VfDzKl+WSkx1iBtPX/oivvHyzmvWZ9jcxAZp3nUzhUCKJkcIXEVik ajkfzIhn+qzKe+VQ/5OVNbIoMEHw3VS5yzX73PwaMw== X-Google-Smtp-Source: ACHHUZ78Xk1ij2mF5B/EIjoKYCP+uiaFRIWr8EtianeJM8LPCipW22s/8Gr9QxDYmDtJKZSYXwHGBA== X-Received: by 2002:a6b:db19:0:b0:769:82a4:4419 with SMTP id t25-20020a6bdb19000000b0076982a44419mr12203230ioc.14.1684946253740; Wed, 24 May 2023 09:37:33 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:33 -0700 (PDT) Date: Wed, 24 May 2023 10:37:07 -0600 Subject: [PATCH 16/25] Use tuples for default arguments in DAP MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-16-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" My co-worker Kévin taught me that using a mutable object as a default argument in Python is somewhat dangerous, because the object is created a single time (when the function is defined), and so if it is mutated in the body of the function, the changes will stick around. This patch changes the cases like this in DAP to use () rather than [] as the default. This patch is merely preventative, as no bugs like this are in the code. --- gdb/python/lib/gdb/dap/breakpoint.py | 4 ++-- gdb/python/lib/gdb/dap/launch.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 877069f79a5..8ffa1829031 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -96,7 +96,7 @@ def _set_breakpoints(kind, specs): @request("setBreakpoints") -def set_breakpoint(*, source, breakpoints=[], **args): +def set_breakpoint(*, source, breakpoints=(), **args): if "path" not in source: result = [] else: @@ -188,7 +188,7 @@ def _set_exception_catchpoints(filter_options): "label": "Ada exceptions", "supportsCondition": True, })) -def set_exception_breakpoints(*, filters, filterOptions=[], **args): +def set_exception_breakpoints(*, filters, filterOptions=(), **args): # Convert the 'filters' to the filter-options style. options = [{"filterId": filter} for filter in filters] options.extend(filterOptions) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index a46be1dcca2..dc4bf3c6d15 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -36,7 +36,7 @@ def _set_args_env(args, env): # from implementations. Any additions or changes here should be # documented in the gdb manual. @request("launch") -def launch(*, program=None, args=[], env=None, **extra): +def launch(*, program=None, args=(), env=None, **extra): if program is not None: global _program _program = program From patchwork Wed May 24 16:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69979 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 698C23888821 for ; Wed, 24 May 2023 16:40:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 698C23888821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946427; bh=Ap9i4Ax+QMRNKvEDfJRwOClZQMDgZbcA9tc8XyYBK70=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ExQFpKKWUikAEyyhqHlBybPmWnoUofcb6wgWpRBz7c6MD6wYGXsEi+FkKSxo2Jdnn 2XkZJsAI46yAO4hz3K4nrMkuMoVYDLqg+nwPBnnxWB+WoYLtP/h5Oov/ue/KVYFHVk n+ECL0lD0vS92leDyVP9p4dBjXE6kUvbIChS9so4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 84EE8385770D for ; Wed, 24 May 2023 16:37:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84EE8385770D Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-77491a28035so86291339f.2 for ; Wed, 24 May 2023 09:37:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946255; x=1687538255; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ap9i4Ax+QMRNKvEDfJRwOClZQMDgZbcA9tc8XyYBK70=; b=jnwQVtzKcGzLAiDB2TMN3sLuIjWIdsiuwq+u4tugBVZPESJAMFv1QpDK+NwTwOTYAw dQcZGmudRU5R60Y28Er5S4JJD4w7xgOFpXflhKF+3JGadHXlKv8GICI7KEzUfAhTg4vm PeqBZztuRbGc4owXgBC5HjzfM5hkDdXMdoFTpel4PjTtRDzWUt3jnSFDfzjKoP/el9Zb TUzSVvV67U1dC7EKVoE0Qjj+4FMjYL6fUHkEsbzMLcL3EwgVX2tZZbA5qIW+Kfic3Jez 4MWgXnd2G2EkO30AJ3Xp76WT2Tfr662kneixuCw9Ai/jh6zwUTIX7mvO1EzpWk9nGPls 24Ew== X-Gm-Message-State: AC+VfDzmIa+MWlhT0GUiKm27nHr8qrdmU/fMLwGJYChFNfSGD2yop+Re /HO66j5cEYyFuXAfpkxd/3+nEPwiXgw/RJsCGUgf1w== X-Google-Smtp-Source: ACHHUZ5Q8x7FYtvtkRcjhDwSKrHQRU9mBfik0HxTSNQPe93ifrTu5UoO+/PC7jagX2AvpQuwbTUGAg== X-Received: by 2002:a6b:dc0f:0:b0:774:9156:d32f with SMTP id s15-20020a6bdc0f000000b007749156d32fmr2210259ioc.18.1684946254366; Wed, 24 May 2023 09:37:34 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:34 -0700 (PDT) Date: Wed, 24 May 2023 10:37:08 -0600 Subject: [PATCH 17/25] Add type-checking to DAP requests MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-17-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 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, T_SCC_BODY_TEXT_LINE 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" It occurred to me recently that gdb's DAP implementation should probably check the types of objects coming from the client. This patch implements this idea by reusing Python's existing type annotations, and supplying a decorator that verifies these at runtime. Python doesn't make it very easy to do runtime type-checking, so the core of the checker is written by hand. I haven't tried to make a fully generic runtime type checker. Instead, this only checks the subset that is needed by DAP. For example, only keyword-only functions are handled. Furthermore, in a few spots, it wasn't convenient to spell out the type that is accepted. I've added a couple of comments to this effect in breakpoint.py. I've tried to make this code compatible with older versions of Python, but I've only been able to try it with 3.9 and 3.10. --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/breakpoint.py | 41 ++++++++++----- gdb/python/lib/gdb/dap/bt.py | 2 +- gdb/python/lib/gdb/dap/disassemble.py | 7 ++- gdb/python/lib/gdb/dap/evaluate.py | 13 ++++- gdb/python/lib/gdb/dap/launch.py | 14 ++++- gdb/python/lib/gdb/dap/memory.py | 4 +- gdb/python/lib/gdb/dap/next.py | 12 +++-- gdb/python/lib/gdb/dap/scopes.py | 2 +- gdb/python/lib/gdb/dap/server.py | 6 ++- gdb/python/lib/gdb/dap/typecheck.py | 88 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.dap/type_check.exp | 29 +++++++++++ gdb/testsuite/gdb.dap/type_check.py | 96 +++++++++++++++++++++++++++++++++++ 13 files changed, 287 insertions(+), 28 deletions(-) diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index a95c2d7ab37..9e34d4cffd3 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -105,6 +105,7 @@ PYTHON_FILE_LIST = \ gdb/dap/startup.py \ gdb/dap/state.py \ gdb/dap/threads.py \ + gdb/dap/typecheck.py \ gdb/dap/varref.py \ gdb/function/__init__.py \ gdb/function/as_string.py \ diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 8ffa1829031..ad019333fea 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -16,6 +16,9 @@ import gdb import os +# These are deprecated in 3.9, but required in older versions. +from typing import Optional, Sequence + from .server import request, capability from .startup import send_gdb_with_response, in_gdb_thread @@ -95,8 +98,10 @@ def _set_breakpoints(kind, specs): return _set_breakpoints_callback(kind, specs, gdb.Breakpoint) +# FIXME we do not specify a type for 'source'. +# FIXME 'breakpoints' is really a list[SourceBreakpoint]. @request("setBreakpoints") -def set_breakpoint(*, source, breakpoints=(), **args): +def set_breakpoint(*, source, breakpoints: Sequence = (), **args): if "path" not in source: result = [] else: @@ -119,7 +124,7 @@ def set_breakpoint(*, source, breakpoints=(), **args): @request("setFunctionBreakpoints") @capability("supportsFunctionBreakpoints") -def set_fn_breakpoint(*, breakpoints, **args): +def set_fn_breakpoint(*, breakpoints: Sequence, **args): specs = [] for bp in breakpoints: specs.append( @@ -135,7 +140,9 @@ def set_fn_breakpoint(*, breakpoints, **args): @request("setInstructionBreakpoints") @capability("supportsInstructionBreakpoints") -def set_insn_breakpoints(*, breakpoints, offset=None, **args): +def set_insn_breakpoints( + *, breakpoints: Sequence, offset: Optional[int] = None, **args +): specs = [] for bp in breakpoints: # There's no way to set an explicit address breakpoint @@ -179,16 +186,24 @@ def _set_exception_catchpoints(filter_options): @request("setExceptionBreakpoints") @capability("supportsExceptionFilterOptions") -@capability("exceptionBreakpointFilters", ({ - "filter": "assert", - "label": "Ada assertions", - "supportsCondition": True, -}, { - "filter": "exception", - "label": "Ada exceptions", - "supportsCondition": True, -})) -def set_exception_breakpoints(*, filters, filterOptions=(), **args): +@capability( + "exceptionBreakpointFilters", + ( + { + "filter": "assert", + "label": "Ada assertions", + "supportsCondition": True, + }, + { + "filter": "exception", + "label": "Ada exceptions", + "supportsCondition": True, + }, + ), +) +def set_exception_breakpoints( + *, filters: Sequence[str], filterOptions: Sequence = (), **args +): # Convert the 'filters' to the filter-options style. options = [{"filterId": filter} for filter in filters] options.extend(filterOptions) diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index 21cedb73d26..a38573fbba8 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -88,5 +88,5 @@ def _backtrace(thread_id, levels, startFrame): @request("stackTrace") @capability("supportsDelayedStackTraceLoading") -def stacktrace(*, levels=0, startFrame=0, threadId, **extra): +def stacktrace(*, levels: int = 0, startFrame: int = 0, threadId: int, **extra): return send_gdb_with_response(lambda: _backtrace(threadId, levels, startFrame)) diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py index 900a3c6adbb..bc091eb2c89 100644 --- a/gdb/python/lib/gdb/dap/disassemble.py +++ b/gdb/python/lib/gdb/dap/disassemble.py @@ -43,7 +43,12 @@ def _disassemble(pc, skip_insns, count): @request("disassemble") @capability("supportsDisassembleRequest") def disassemble( - *, memoryReference, offset=0, instructionOffset=0, instructionCount, **extra + *, + memoryReference: str, + offset: int = 0, + instructionOffset: int = 0, + instructionCount: int, + **extra ): pc = int(memoryReference, 0) + offset return send_gdb_with_response( diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index fffd255417b..4fc0f31486c 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -16,6 +16,9 @@ import gdb import gdb.printing +# This is deprecated in 3.9, but required in older versions. +from typing import Optional + from .frames import frame_for_id from .server import request from .startup import send_gdb_with_response, in_gdb_thread @@ -55,7 +58,13 @@ def _repl(command, frame_id): # FIXME supportsVariableType handling @request("evaluate") -def eval_request(*, expression, frameId=None, context="variables", **args): +def eval_request( + *, + expression: str, + frameId: Optional[int] = None, + context: str = "variables", + **args, +): if context in ("watch", "variables"): # These seem to be expression-like. return send_gdb_with_response(lambda: _evaluate(expression, frameId)) @@ -75,7 +84,7 @@ def _variables(ref, start, count): @request("variables") # Note that we ignore the 'filter' field. That seems to be # specific to javascript. -def variables(*, variablesReference, start=0, count=0, **args): +def variables(*, variablesReference: int, start: int = 0, count: int = 0, **args): result = send_gdb_with_response( lambda: _variables(variablesReference, start, count) ) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index dc4bf3c6d15..e187c3144d7 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -14,6 +14,10 @@ # along with this program. If not, see . import gdb + +# These are deprecated in 3.9, but required in older versions. +from typing import Mapping, Optional, Sequence + from .events import ExecutionInvoker from .server import request, capability from .startup import send_gdb, send_gdb_with_response, in_gdb_thread @@ -36,7 +40,13 @@ def _set_args_env(args, env): # from implementations. Any additions or changes here should be # documented in the gdb manual. @request("launch") -def launch(*, program=None, args=(), env=None, **extra): +def launch( + *, + program: Optional[str] = None, + args: Sequence[str] = (), + env: Optional[Mapping[str, str]] = None, + **extra, +): if program is not None: global _program _program = program @@ -46,7 +56,7 @@ def launch(*, program=None, args=(), env=None, **extra): @request("attach") -def attach(*, pid, **args): +def attach(*, pid: int, **args): # Ensure configurationDone does not try to run. global _program _program = None diff --git a/gdb/python/lib/gdb/dap/memory.py b/gdb/python/lib/gdb/dap/memory.py index 7eb8a27ce47..85948bda9f4 100644 --- a/gdb/python/lib/gdb/dap/memory.py +++ b/gdb/python/lib/gdb/dap/memory.py @@ -28,7 +28,7 @@ def _read_memory(addr, count): @request("readMemory") @capability("supportsReadMemoryRequest") -def read_memory(*, memoryReference, offset=0, count, **extra): +def read_memory(*, memoryReference: str, offset: int = 0, count: int, **extra): addr = int(memoryReference, 0) + offset buf = send_gdb_with_response(lambda: _read_memory(addr, count)) return { @@ -45,7 +45,7 @@ def _write_memory(addr, contents): @request("writeMemory") @capability("supportsWriteMemoryRequest") -def write_memory(*, memoryReference, offset=0, data, **extra): +def write_memory(*, memoryReference: str, offset: int = 0, data: str, **extra): addr = int(memoryReference, 0) + offset send_gdb_with_response(lambda: _write_memory(addr, data)) return {} diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 75f2fa6f31a..8b112770a0c 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -45,7 +45,9 @@ def _handle_thread_step(thread_id, single_thread): @request("next") -def next(*, threadId, singleThread=False, granularity="statement", **args): +def next( + *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args +): send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "next" if granularity == "instruction": @@ -56,7 +58,9 @@ def next(*, threadId, singleThread=False, granularity="statement", **args): @capability("supportsSteppingGranularity") @capability("supportsSingleThreadExecutionRequests") @request("stepIn") -def step_in(*, threadId, singleThread=False, granularity="statement", **args): +def step_in( + *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args +): send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "step" if granularity == "instruction": @@ -65,13 +69,13 @@ def step_in(*, threadId, singleThread=False, granularity="statement", **args): @request("stepOut") -def step_out(*, threadId, singleThread=False): +def step_out(*, threadId: int, singleThread: bool = False): send_gdb(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) @request("continue") -def continue_request(*, threadId, singleThread=False, **args): +def continue_request(*, threadId: int, singleThread: bool = False, **args): locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("continue", None)) return {"allThreadsContinued": not locked} diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py index 8e9af5064c2..9b80dd9ce80 100644 --- a/gdb/python/lib/gdb/dap/scopes.py +++ b/gdb/python/lib/gdb/dap/scopes.py @@ -109,6 +109,6 @@ def _get_scope(id): @request("scopes") -def scopes(*, frameId, **extra): +def scopes(*, frameId: int, **extra): scopes = send_gdb_with_response(lambda: _get_scope(frameId)) return {"scopes": scopes} diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 8abe475b031..be66676f730 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -25,6 +25,7 @@ from .startup import ( log_stack, send_gdb_with_response, ) +from .typecheck import type_check # Map capability names to values. @@ -165,7 +166,8 @@ def request(name): def wrap(func): global _commands # All requests must run in the DAP thread. - func = in_dap_thread(func) + # Also type-check the calls. + func = in_dap_thread(type_check(func)) _commands[name] = func return func @@ -202,7 +204,7 @@ def terminate(**args): @request("disconnect") @capability("supportTerminateDebuggee") -def disconnect(*, terminateDebuggee=False, **args): +def disconnect(*, terminateDebuggee: bool = False, **args): if terminateDebuggee: terminate() _server.shutdown() diff --git a/gdb/python/lib/gdb/dap/typecheck.py b/gdb/python/lib/gdb/dap/typecheck.py new file mode 100644 index 00000000000..791dc75f7b3 --- /dev/null +++ b/gdb/python/lib/gdb/dap/typecheck.py @@ -0,0 +1,88 @@ +# 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 . + +# A simple runtime type checker. + +import collections.abc +import functools +import typing + + +# 'isinstance' won't work in general for type variables, so we +# implement the subset that is needed by DAP. +def _check_instance(value, typevar): + base = typing.get_origin(typevar) + if base is None: + return isinstance(value, typevar) + arg_types = typing.get_args(typevar) + if base == collections.abc.Mapping or base == typing.Mapping: + if not isinstance(value, collections.abc.Mapping): + return False + assert len(arg_types) == 2 + (keytype, valuetype) = arg_types + return all( + _check_instance(k, keytype) and _check_instance(v, valuetype) + for k, v in value.items() + ) + elif base == collections.abc.Sequence or base == typing.Sequence: + # In some places we simply use 'Sequence' without arguments. + if not isinstance(value, base): + return False + if len(arg_types) == 0: + return True + assert len(arg_types) == 1 + arg_type = arg_types[0] + return all(_check_instance(item, arg_type) for item in value) + elif base == typing.Union: + return any(_check_instance(value, arg_type) for arg_type in arg_types) + raise TypeError("unsupported type variable '" + str(typevar) + "'") + + +def type_check(func): + """A decorator that checks FUNC's argument types at runtime.""" + + # The type checker relies on 'typing.get_origin', which was added + # in Python 3.8. (It also relies on 'typing.get_args', but that + # was added at the same time.) + if not hasattr(typing, "get_origin"): + return func + + hints = typing.get_type_hints(func) + # We don't check the return type, but we allow it in case someone + # wants to use it on a function definition. + if "return" in hints: + del hints["return"] + + # Note that keyword-only is fine for our purposes, because this is + # only used for DAP requests, and those are always called this + # way. + @functools.wraps(func) + def check_arguments(**kwargs): + for key in hints: + # The argument might not be passed in; we could type-check + # any default value here, but it seems fine to just rely + # on the code being correct -- the main goal of this + # checking is to verify JSON coming from the client. + if key in kwargs and not _check_instance(kwargs[key], hints[key]): + raise TypeError( + "value for '" + + key + + "' does not have expected type '" + + str(hints[key]) + + "'" + ) + return func(**kwargs) + + return check_arguments diff --git a/gdb/testsuite/gdb.dap/type_check.exp b/gdb/testsuite/gdb.dap/type_check.exp new file mode 100644 index 00000000000..346b4ba75b1 --- /dev/null +++ b/gdb/testsuite/gdb.dap/type_check.exp @@ -0,0 +1,29 @@ +# 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 the DAP type-checker. + +require allow_dap_tests allow_python_tests + +load_lib dap-support.exp +load_lib gdb-python.exp + +clean_restart + +set remote_python_file \ + [gdb_remote_download host ${srcdir}/${subdir}/${gdb_test_file_name}.py] +gdb_test_no_output "source ${remote_python_file}" "load python file" + +gdb_test "python check_everything()" OK "type checker" diff --git a/gdb/testsuite/gdb.dap/type_check.py b/gdb/testsuite/gdb.dap/type_check.py new file mode 100644 index 00000000000..1fdb595f3c6 --- /dev/null +++ b/gdb/testsuite/gdb.dap/type_check.py @@ -0,0 +1,96 @@ +# 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 the type checker. + +import typing +from gdb.dap.typecheck import type_check + + +# A wrapper to call a function that should cause a type-checking +# failure. Returns if the exception was seen. Throws an exception if +# a TypeError was not seen. +def should_fail(func, **args): + try: + func(**args) + except TypeError: + return + raise RuntimeError("function failed to throw TypeError") + + +# Also specify a return type to make sure return types do not confuse +# the checker. +@type_check +def simple_types(*, b: bool, s: str, i: int = 23) -> int: + return i + + +def check_simple(): + simple_types(b=True, s="DEI", i=97) + # Check the absence of a defaulted argument. + simple_types(b=True, s="DEI") + simple_types(b=False, s="DEI", i=97) + should_fail(simple_types, b=97, s="DEI", i=97) + should_fail(simple_types, b=True, s=None, i=97) + should_fail(simple_types, b=True, s="DEI", i={}) + + +@type_check +def sequence_type(*, s: typing.Sequence[str]): + pass + + +def check_sequence(): + sequence_type(s=("hi", "out", "there")) + sequence_type(s=["hi", "out", "there"]) + sequence_type(s=()) + sequence_type(s=[]) + should_fail(sequence_type, s=23) + should_fail(sequence_type, s=["hi", 97]) + + +@type_check +def map_type(*, m: typing.Mapping[str, int]): + pass + + +def check_map(): + map_type(m={}) + map_type(m={"dei": 23}) + should_fail(map_type, m=[1, 2, 3]) + should_fail(map_type, m=None) + should_fail(map_type, m={"dei": "string"}) + + +@type_check +def opt_type(*, u: typing.Optional[int]): + pass + + +def check_opt(): + opt_type(u=23) + opt_type(u=None) + should_fail(opt_type, u="string") + + +def check_everything(): + # Older versions of Python can't really implement this. + if hasattr(typing, "get_origin"): + # Just let any exception propagate and end up in the log. + check_simple() + check_sequence() + check_map() + check_opt() + print("OK") From patchwork Wed May 24 16:37:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69978 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 926173839DCF for ; Wed, 24 May 2023 16:40:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 926173839DCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946416; bh=Z1ssdJsnFh9k6lnhH0/408C33n/dkemwodN1KR3ja4g=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DjH4t5A/NzM5xsPzghlz9sYaioHQ77ZgLyzUWrRK5a/HWOjcqkwnuFqofYGxnMFy+ 53Ohz+wetp+sLSb0ZRlm7eLJ3D7+bX78n+Bbd8zaA7IhVlQF5TMtKZ6une4Sa55foT HJ7cPzNroMR/jMyrZtp1mT5B8Wskp+ELg4OmryhM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id B54A93857016 for ; Wed, 24 May 2023 16:37:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B54A93857016 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-77480507360so31076839f.3 for ; Wed, 24 May 2023 09:37:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946255; x=1687538255; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z1ssdJsnFh9k6lnhH0/408C33n/dkemwodN1KR3ja4g=; b=mIfLgSz36gqk75hYj+b1vXNcyPr+i+t+JgYudTuhkcC0haOHVKOwkd0tw/y+fK5mF5 xILecIqO2De8C6KfXhtwr9/Ar1TM+fuBWa5dXqL9bRTNyX7wK6FvnQGGgDSb9raVfB7w ugSz5Zj4Ic2gQCP/R4LIYVud/Gsj/GU+sana8sU9rgZpoMMGTVq/ivvZR2+dGQphJo5f qkxh+fKpvxqqkRWTJy8rjWRTA7S6Whvu4CwP0GzIe1WWsgipbKwjiXMVy/SYIChJzg2B Hvf376WytNxpkGVevFmq+KEXwI0jpQA1vfruf4K2B992s+Z5Saua3VgsQ73mbckaIG0I J/Kg== X-Gm-Message-State: AC+VfDyqjPQWC4xZHsgcxEFo/SqACekhJA+/jFJcNcW1RCDCFKoPj/N1 FBuGhT81mZGIrJT7Lm8gsDkX1mB1XORvqPkHys55qA== X-Google-Smtp-Source: ACHHUZ5XCqDjZ1hKuHnHN5rBe0YuhdPjod/WgnQzV9D3g+11I5SlpN1NsVa4h7f1Wi6HSWLQqsHz/A== X-Received: by 2002:a5e:c006:0:b0:76f:e9ec:d62e with SMTP id u6-20020a5ec006000000b0076fe9ecd62emr12548881iol.5.1684946255009; Wed, 24 May 2023 09:37:35 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:34 -0700 (PDT) Date: Wed, 24 May 2023 10:37:09 -0600 Subject: [PATCH 18/25] Add gdb.Value.assign method MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-18-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This adds an 'assign' method to gdb.Value. This allows for assignment without requiring the use of parse_and_eval. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 2 ++ gdb/doc/python.texi | 6 ++++++ gdb/python/py-value.c | 30 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-value.exp | 14 ++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index d97e3c15a87..4c4df060b62 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -209,6 +209,8 @@ info main "unset_env". These can be used to modify the inferior's environment before it is started. + ** gdb.Value now has the 'assign' method. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 69755e96143..64ddbe21fc5 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -947,6 +947,12 @@ If @var{type} is @code{None} then this version of @code{__init__} behaves as though @var{type} was not passed at all. @end defun +@defun Value.assign (rhs) +Assign @var{rhs} to this value, and return @code{None}. If this value +cannot be assigned to, or if the assignment is invalid for some reason +(for example a type-checking failure), an exception will be thrown. +@end defun + @defun Value.cast (type) Return a new instance of @code{gdb.Value} that is the result of casting this instance to the type described by @var{type}, which must diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 6c62820c63b..2be223da4ea 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -856,6 +856,33 @@ valpy_reinterpret_cast (PyObject *self, PyObject *args) return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST); } +/* Implementation of the "assign" method. */ + +static PyObject * +valpy_assign (PyObject *self_obj, PyObject *args) +{ + PyObject *val_obj; + + if (! PyArg_ParseTuple (args, "O", &val_obj)) + return nullptr; + + struct value *val = convert_value_from_python (val_obj); + if (val == nullptr) + return nullptr; + + try + { + value_object *self = (value_object *) self_obj; + value_assign (self->value, val); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + Py_RETURN_NONE; +} + static Py_ssize_t valpy_length (PyObject *self) { @@ -2121,6 +2148,9 @@ Return Unicode string representation of the value." }, "format_string (...) -> string\n\ Return a string representation of the value using the specified\n\ formatting options" }, + { "assign", (PyCFunction) valpy_assign, METH_VARARGS, + "assign (VAL) -> None\n\ +Assign VAL to this value." }, {NULL} /* Sentinel */ }; diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 9fc25814721..cdfcd414cd4 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -633,6 +633,19 @@ proc test_history_count {} { } } +# Test Value.assign. +proc test_assign {} { + gdb_test_no_output "python i_value = gdb.parse_and_eval('i')" \ + "evaluate i" + gdb_test_no_output "python i_value.assign(27)" \ + "set i to 27" + gdb_test "print i" " = 27" + gdb_test_no_output "python i_value = gdb.Value(27)" \ + "reset i_value" + gdb_test "python i_value.assign(89)" "not an lvalue.*" \ + "cannot assign to integer" +} + # Build C version of executable. C++ is built later. if { [build_inferior "${binfile}" "c"] < 0 } { return -1 @@ -663,6 +676,7 @@ test_value_in_inferior test_value_from_buffer test_value_sub_classes test_inferior_function_call +test_assign test_value_after_death # Test either C or C++ values. From patchwork Wed May 24 16:37:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69981 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 917E5388981F for ; Wed, 24 May 2023 16:40:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 917E5388981F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946444; bh=0ltZs90hJVadHb2k2EY7EOXd9nQnKQxP+VV/0ttKABo=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BJQmuUln8BIBB0nSO6e4/PVXLDTATsZh1cLafwEeAvhNNC/DMT5BiBzea5GO02Ulj MYgiyDGhRZMu3PRKemoPRe8MWdc8ZTA62o3eZOcu1qYRpl6JISq0q8HTK/0FNDfygY Ojwcz2UBBcHeamXlUfuWHCeeMyhveX3+M/tUn+hQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 45FBC3857359 for ; Wed, 24 May 2023 16:37:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45FBC3857359 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-77480507360so31077339f.3 for ; Wed, 24 May 2023 09:37:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946255; x=1687538255; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0ltZs90hJVadHb2k2EY7EOXd9nQnKQxP+VV/0ttKABo=; b=gQ96IE2PiuxaO8es5toSxw9gadjGF5Stf9W7IppLGwx4J8wZZPrXXmyHH7WiTnlRZQ 4iGO0v07XnbCU3RoC0Nxwlz4EwDQr1M10No5ObBI+wHLrgIbUS6hFADBCJHRWgt5B9pP 0WiKRFCJe2viDcg5DHg+C0Zp5Bq469goWDTlGE281PlDlT++Zd3v+1XqPffQr/3yK/RR EFjfM7Qk1oWk3z5BJqhZ52K2TJiTh0H4eISN4bBeCHCTkFq0IzeVW3VDlKIgnMHSM4wP GNdBkSmyh3YfHEk5gXmcbd7wS++jHye1Ai2AH+7yuE6wWdcZwe7sFhb/JsqIh4RmEUxO 31JA== X-Gm-Message-State: AC+VfDy5UYIfBVevT3+kXu4qg7P/7dKlLYv7CoE7jXW6wPKLYWZTjuOC n8n1kZnbuuE1iGhl4FdcjWTKO3HSedjV0A+gACVPzA== X-Google-Smtp-Source: ACHHUZ5/P/rjf6DqY8jrTzWQRPyIGbQOrBSmaQlncTX97QOSTkqmD9MAEgIg8D+ML0aGmEa2GNBs3w== X-Received: by 2002:a5d:8ad7:0:b0:76c:6382:8d5b with SMTP id e23-20020a5d8ad7000000b0076c63828d5bmr12169194iot.10.1684946255626; Wed, 24 May 2023 09:37:35 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:35 -0700 (PDT) Date: Wed, 24 May 2023 10:37:10 -0600 Subject: [PATCH 19/25] Implement DAP setExpression request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-19-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" This implements the DAP setExpression request. --- gdb/python/lib/gdb/dap/evaluate.py | 24 +++++++++++++++++++++++- gdb/testsuite/gdb.dap/basic-dap.exp | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 4fc0f31486c..1db6962f8e0 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -20,7 +20,7 @@ import gdb.printing from typing import Optional from .frames import frame_for_id -from .server import request +from .server import capability, request from .startup import send_gdb_with_response, in_gdb_thread from .varref import find_variable, VariableReference @@ -43,6 +43,20 @@ def _evaluate(expr, frame_id): return ref.to_object() +# Helper function to perform an assignment. +@in_gdb_thread +def _set_expression(expression, value, frame_id): + global_context = True + if frame_id is not None: + frame = frame_for_id(frame_id) + frame.select() + global_context = False + lhs = gdb.parse_and_eval(expression, global_context=global_context) + rhs = gdb.parse_and_eval(value, global_context=global_context) + lhs.assign(rhs) + return EvaluateResult(lhs).to_object() + + # Helper function to evaluate a gdb command in a certain frame. @in_gdb_thread def _repl(command, frame_id): @@ -89,3 +103,11 @@ def variables(*, variablesReference: int, start: int = 0, count: int = 0, **args lambda: _variables(variablesReference, start, count) ) return {"variables": result} + + +@capability("supportsSetExpression") +@request("setExpression") +def set_expression( + *, expression: str, value: str, frameId: Optional[int] = None, **args +): + return send_gdb_with_response(lambda: _set_expression(expression, value, frameId)) diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index ce739875404..9aaa94051e6 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -159,6 +159,11 @@ set obj [dap_check_request_and_response "evaluate global in main" \ dap_match_values "global value in main" [lindex $obj 0] \ "body result" 25 +set obj [dap_check_request_and_response "set global in main" \ + setExpression {o expression [s global_variable] value [s 23]}] +dap_match_values "global value in main after set" [lindex $obj 0] \ + "body result" 23 + set obj [dap_request_and_response \ evaluate {o expression [s nosuchvariable]}] set response [lindex $obj 0] From patchwork Wed May 24 16:37:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69985 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 B3EBB3850404 for ; Wed, 24 May 2023 16:41:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3EBB3850404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946490; bh=MTI6s+eTgbZF9pdd0TYJIEPhScyIHTW3I1EBD1u9py4=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dY/Dc3qHfQEIXQXGih85Bmje0woDJh2x04i1+aQTy3EFyfNojbhMZ3oqZSx1ymXjY ZuUZljQHa6JgRYRp8aky65L+uWCEtf4M2XLQAb6jOVlzxIX62iWpKC6kWKRDasVwpY J4UHrHJ5qrqVj2NaurM7ipXv1kNo+OMp+GEKu2u8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 897963858D28 for ; Wed, 24 May 2023 16:37:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 897963858D28 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-76c75d32005so31317639f.1 for ; Wed, 24 May 2023 09:37:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946256; x=1687538256; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MTI6s+eTgbZF9pdd0TYJIEPhScyIHTW3I1EBD1u9py4=; b=Q9sv3JFeWqpXp9BfszZgaXhSFqdXNFY3/7AOS0V18lVE0YoZaMO5+vAU83AuH1FumM qW1ddgLiKbH/48BkiQMY0sVpTvRoSg6zBmwd+RFNCfSchgqFoG21CF08grPWG0Wk9NTb gwcJgHmkeqBjcFYNBbyhQcS90FBI/enn7pjjqr2UieL9J7QpYf+St82//2TVDZ9tRQUM m8ljHfTmza+vRTfAnPK+auUwjBwILR30ktqTd0NkAR77iCCxqys6szvHqPyzn0tl1jW2 sEkZrpugbTymIRpiTFuN6F/a/sf6Cl8YO126rVJHSXWliREtdo91EN0FhyWjWcz4sWNg ioZw== X-Gm-Message-State: AC+VfDw+x+4A+aXqQzS+0JQwERI0ysJEh1XksZcFTTjRtri0FC+PbSWm UV4VexE4aAl1TpDLP4/todeg+d8DgUjJXc+3pEBixA== X-Google-Smtp-Source: ACHHUZ7F21+Ey/vlkitdE9MQi2NqbPdWH08NWaafRi/Lv5a1IO1uKVWtYs+wusOGKInx48xbmxBHzQ== X-Received: by 2002:a05:6602:2202:b0:760:ced3:4481 with SMTP id n2-20020a056602220200b00760ced34481mr10501694ion.4.1684946256224; Wed, 24 May 2023 09:37:36 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:35 -0700 (PDT) Date: Wed, 24 May 2023 10:37:11 -0600 Subject: [PATCH 20/25] Handle DAP supportsVariableType capability MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-20-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" A DAP client can report the supportsVariableType in the initialize request. In this case, gdb can include the type of a variable or expression in various results. --- gdb/python/lib/gdb/dap/evaluate.py | 1 - gdb/python/lib/gdb/dap/server.py | 11 +++++++++++ gdb/python/lib/gdb/dap/varref.py | 3 +++ gdb/testsuite/gdb.dap/basic-dap.exp | 3 ++- gdb/testsuite/lib/dap-support.exp | 4 +++- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 1db6962f8e0..2b400651b67 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -70,7 +70,6 @@ def _repl(command, frame_id): } -# FIXME supportsVariableType handling @request("evaluate") def eval_request( *, diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index be66676f730..b1c75ab967f 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -186,6 +186,17 @@ def capability(name, value=True): return wrap +def client_bool_capability(name): + """Return the value of a boolean client capability. + + If the capability was not specified, or did not have boolean type, + False is returned.""" + global _server + if name in _server.config and isinstance(_server.config[name], bool): + return _server.config[name] + return False + + @request("initialize") def initialize(**args): global _server, _capabilities diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 88c34c20468..23f18d647c3 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -15,6 +15,7 @@ import gdb from .startup import in_gdb_thread +from .server import client_bool_capability from abc import abstractmethod @@ -165,6 +166,8 @@ class VariableReference(BaseReference): result["memoryReference"] = hex(int(self.value)) elif self.value.address is not None: result["memoryReference"] = hex(int(self.value.address)) + if client_bool_capability("supportsVariableType"): + result["type"] = str(self.value.type) return result @in_gdb_thread diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index 9aaa94051e6..ca0d1be9f12 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -162,7 +162,8 @@ dap_match_values "global value in main" [lindex $obj 0] \ set obj [dap_check_request_and_response "set global in main" \ setExpression {o expression [s global_variable] value [s 23]}] dap_match_values "global value in main after set" [lindex $obj 0] \ - "body result" 23 + "body result" 23 \ + "body type" int set obj [dap_request_and_response \ evaluate {o expression [s nosuchvariable]}] diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 8667164fa11..5c547480d09 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -230,7 +230,9 @@ proc _dap_initialize {name} { if {[dap_gdb_start]} { return "" } - return [dap_check_request_and_response $name initialize] + return [dap_check_request_and_response $name initialize \ + {o clientID [s "gdb testsuite"] \ + supportsVariableType [l true]}] } # Start gdb, send a DAP initialize request, and then a launch request From patchwork Wed May 24 16:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69982 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 BF0BD388265A for ; Wed, 24 May 2023 16:40:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF0BD388265A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946455; bh=PFqn5VuIDU8D36QEOVEuy2lW4cztNU99+5y+t5mkdkw=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GjAEPKE3Zu16wfv+UDWuCh4vntjNIl7D7EhotU3dCTXFtgbr6FTto8yd3EE1VRAUx ly5eHFK17bY9uqQbOq8MRRxx5D31N7F4Gs5CN3zhh7KOWhmI6zrXeWB4XcioI3RzZE mGysAb/GgLH/0HW8bAmeJDPUpox3hWV/6Q0GA5Us= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 8FB2A385772B for ; Wed, 24 May 2023 16:37:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FB2A385772B Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-77483a5a350so30979039f.0 for ; Wed, 24 May 2023 09:37:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946257; x=1687538257; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PFqn5VuIDU8D36QEOVEuy2lW4cztNU99+5y+t5mkdkw=; b=F7AzlBWjQpnYYuSxrApAzUm6mmwXml/y3ywolhk5d1Soz5ikvlVNlmh6xQ+GYeuZ0c gxepftqW8tjMRmmseD6B+zrzo+FUTnnCtdbikpcmEBMSg5JamGgvDtxg+Qdoql57EWZu VDAsq2vr8GC+kJQvrObQxf+Rbdy143IDG9ZDXxEaw7RRwNH9YXa1aJGj5MgWNXlnIvRY bLYNe4xe1/787ao8HTJAcE9N2xM3D14OqcaN8kX93EledGZr44791FQXRRh5+ogXeD1k 9jj2dxTPXbrQ3wAaecExfKCRbyW+0x7CuVsrLTLPJuG260/V5M27wMhESgoCLmBEgzYt HqXA== X-Gm-Message-State: AC+VfDxHufmsPJYS3d1uoZwZ26H9vq6wOWLeglm2mCfeY5m+Qgs172AC erOsqt2sn+ESvc4dD+lIrFwBa6LPYQ7g+sQO+f4Hiw== X-Google-Smtp-Source: ACHHUZ6q1rqjtKVOuw54FGWRnWfXaa2sePwSDdjhDgAIaNnamu+/gxPRKdr3PJ4TBLSOPJnBdGIePw== X-Received: by 2002:a5e:9241:0:b0:76c:5694:5c2e with SMTP id z1-20020a5e9241000000b0076c56945c2emr10921472iop.13.1684946256832; Wed, 24 May 2023 09:37:36 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:36 -0700 (PDT) Date: Wed, 24 May 2023 10:37:12 -0600 Subject: [PATCH 21/25] Add "target" parameter to DAP attach request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-21-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 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, T_SCC_BODY_TEXT_LINE 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" This adds a new "target" to the DAP attach request. This is passed to "target remote". I thought "attach" made the most sense for this, because in some sense gdb is attaching to a running process. It's worth noting that all DAP "attach" parameters are defined by the implementation. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 8 ++++-- gdb/python/lib/gdb/dap/launch.py | 10 ++++++-- gdb/testsuite/gdb.dap/remote-dap.exp | 49 ++++++++++++++++++++++++++++++++++++ gdb/testsuite/lib/dap-support.exp | 11 ++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 1b967485bc6..f66dd4df3cf 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39020,12 +39020,16 @@ If provided, this is a string that specifies the program to use. This corresponds to the @code{file} command. @xref{Files}. @end table -@value{GDBN} defines a parameter that can be passed to the -@code{attach} request: +@value{GDBN} defines some parameters that can be passed to the +@code{attach} request. One of these must be specified. @table @code @item pid The process ID to which @value{GDBN} should attach. @xref{Attach}. + +@item target +The target to which @value{GDBN} should connect. This is a string and +is passed to the @code{target remote} command. @xref{Connecting}. @end table @node JIT Interface diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index e187c3144d7..2fec3267cbb 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -56,13 +56,19 @@ def launch( @request("attach") -def attach(*, pid: int, **args): +def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): # Ensure configurationDone does not try to run. global _program _program = None + if pid is not None: + cmd = "attach " + str(pid) + elif target is not None: + cmd = "target remote " + target + else: + raise Exception("attach requires either 'pid' or 'target'") # Use send_gdb_with_response to ensure we get an error if the # attach fails. - send_gdb_with_response("attach " + str(pid)) + send_gdb_with_response(cmd) return None diff --git a/gdb/testsuite/gdb.dap/remote-dap.exp b/gdb/testsuite/gdb.dap/remote-dap.exp new file mode 100644 index 00000000000..33524082051 --- /dev/null +++ b/gdb/testsuite/gdb.dap/remote-dap.exp @@ -0,0 +1,49 @@ +# 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 "attach" with a remote target in DAP. + +load_lib gdbserver-support.exp +load_lib dap-support.exp + +require allow_dap_tests allow_gdbserver_tests +# We want to have control over where we start gdbserver. +require {!is_remote target} + +# This test is only for remote targets. +if {[target_info exists gdb_protocol] + && [target_info gdb_protocol] != "remote"} { + unsupported "requires remote" + return +} + +standard_testfile attach.c + +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return +} + +set target_exec [gdb_remote_download target [standard_output_file $testfile]] + +lassign [gdbserver_start "" $target_exec] protocol port +# Really should have been caught up above. +gdb_assert {$protocol == "remote"} + +# We just want to test that attaching works at all. +if {[dap_target_remote $port] != ""} { + dap_shutdown true +} + +close_gdbserver diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 5c547480d09..e1fada8b703 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -283,6 +283,17 @@ proc dap_attach {pid} { [format {o pid [i %s]} $pid]] } +# Start gdb, send a DAP initialize request, and then an attach request +# specifying TARGET as the remote target. Returns the empty string on +# failure, or the response object from the attach request. +proc dap_target_remote {target} { + if {[_dap_initialize "startup - initialize"] == ""} { + return "" + } + return [dap_check_request_and_response "startup - target" attach \ + [format {o target [s %s]} $target]] +} + # Cleanly shut down gdb. TERMINATE is passed as the terminateDebuggee # parameter to the request. proc dap_shutdown {{terminate false}} { From patchwork Wed May 24 16:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69984 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 6E9C038323F8 for ; Wed, 24 May 2023 16:41:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E9C038323F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946484; bh=86+GWqQaN8wrCoDjAHnDeJAuwNAn+BA2Xv0tzVrEIoQ=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pd34fRTpooeiI/As1Q6MehBkgibPc76i/Oed5/WeX+cp5r2RYS6jNfYKg4OrstHQP iCbR28TUZx+mgO5YusTAj9tig9wZ29HiFSEXoKLNApHgJvE/1fwVGdvPnyp87byWQZ VhtL29r22albxfzlMuM9+o8ryGkc2ewxCzVI4wME= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 3BA233856DC8 for ; Wed, 24 May 2023 16:37:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BA233856DC8 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7606d460da7so30689939f.1 for ; Wed, 24 May 2023 09:37:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946257; x=1687538257; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=86+GWqQaN8wrCoDjAHnDeJAuwNAn+BA2Xv0tzVrEIoQ=; b=AjCPqyYlKfZpv3L3DDtMmx6IrznRJmozdHkhoitKgg2+VMwsXoN+hyMFKOQEPQGvDN ERAWtQt4zUXb8DSBpG/4j1WrZdMlQq6oS58rf6ePZbm46FOu59n0F8M4+Qe1c5bfVQPP Z3jcTJPpmSt8KZsp4SzXgwxd+CAUzIl1Mo+dBrTIV7v8Fre+P1IpVyNBYpAU5wJN85nD frbvpy8CfdVvaHTlHTUOphl3DgL1jXSQxadXm81gzvao5Uw+ROjsc9jNtCvsGKUAdI0X W16feRTlPeV/jPbMPtUNkhtRw5SW5ewIYHNIUwjSXc7jpeanYOtfLoevXqx9fuoDsYZF 2k1g== X-Gm-Message-State: AC+VfDxxpPXKnRuCu1UjaaXKFfMdeBr3DFgNZS7fc2kiJnmAedheR+2F TeCAqBsFyNxInG88xHz2eAitSftDZSb8NCVnVZ/YWQ== X-Google-Smtp-Source: ACHHUZ5jgCf5qB3UVYWqhonCxOUUkSoL00xTzoSGHCnRReFGcyQsn2ce7obapOya4VGP1wzli9vWYw== X-Received: by 2002:a6b:ef04:0:b0:774:9af9:f45e with SMTP id k4-20020a6bef04000000b007749af9f45emr615239ioh.11.1684946257531; Wed, 24 May 2023 09:37:37 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:37 -0700 (PDT) Date: Wed, 24 May 2023 10:37:13 -0600 Subject: [PATCH 22/25] Add "stop at main" extension to DAP launch request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-22-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 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, T_SCC_BODY_TEXT_LINE 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" Co-workers who work on a program that uses DAP asked for the ability to have gdb stop at the main subprogram when launching. This patch implements this extension. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 5 +++++ gdb/python/lib/gdb/dap/launch.py | 13 +++++++++++- gdb/testsuite/gdb.dap/stop-at-main.exp | 37 ++++++++++++++++++++++++++++++++++ gdb/testsuite/lib/dap-support.exp | 9 +++++++-- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f66dd4df3cf..eb95273d93d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39018,6 +39018,11 @@ inferior will be set to exactly as passed in. @xref{Environment}. @item program If provided, this is a string that specifies the program to use. This corresponds to the @code{file} command. @xref{Files}. + +@item stopAtBeginningOfMainSubprogram +If provided, this must be a boolean. When @samp{True}, @value{GDBN} +will set a temporary breakpoint at the program's main procedure, using +the same approach as the @code{start} command. @xref{Starting}. @end table @value{GDBN} defines some parameters that can be passed to the diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 2fec3267cbb..aee8c2f9ae6 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,7 +20,7 @@ from typing import Mapping, Optional, Sequence from .events import ExecutionInvoker from .server import request, capability -from .startup import send_gdb, send_gdb_with_response, in_gdb_thread +from .startup import send_gdb, send_gdb_with_response, in_gdb_thread, exec_and_log _program = None @@ -36,6 +36,14 @@ def _set_args_env(args, env): inf.set_env(name, value) +@in_gdb_thread +def _break_at_main(): + inf = gdb.selected_inferior() + main = inf.main_name + if main is not None: + exec_and_log("tbreak " + main) + + # Any parameters here are necessarily extensions -- DAP requires this # from implementations. Any additions or changes here should be # documented in the gdb manual. @@ -45,12 +53,15 @@ def launch( program: Optional[str] = None, args: Sequence[str] = (), env: Optional[Mapping[str, str]] = None, + stopAtBeginningOfMainSubprogram: bool = False, **extra, ): if program is not None: global _program _program = program send_gdb(f"file {_program}") + if stopAtBeginningOfMainSubprogram: + send_gdb(_break_at_main) if len(args) > 0 or env is not None: send_gdb(lambda: _set_args_env(args, env)) diff --git a/gdb/testsuite/gdb.dap/stop-at-main.exp b/gdb/testsuite/gdb.dap/stop-at-main.exp new file mode 100644 index 00000000000..80a9b81e152 --- /dev/null +++ b/gdb/testsuite/gdb.dap/stop-at-main.exp @@ -0,0 +1,37 @@ +# 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 +# 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 the stop-at-main extension. + +require allow_dap_tests + +load_lib dap-support.exp + +standard_testfile attach.c + +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return +} + +if {[dap_launch $testfile {} {} 1] == ""} { + return +} + +dap_check_request_and_response "start inferior" configurationDone +# We didn't explicitly set a breakpoint, so if we hit one, it worked. +dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint + +dap_shutdown diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index e1fada8b703..92484bfdb8d 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -241,8 +241,9 @@ proc _dap_initialize {name} { # request. If specified, ARGS is a list of command-line arguments, # and ENV is a list of pairs of the form {VAR VALUE} that is used to # populate the inferior's environment. After this is called, gdb will -# be ready to accept breakpoint requests. -proc dap_launch {file {args {}} {env {}}} { +# be ready to accept breakpoint requests. If STOP_AT_MAIN is nonzero, +# pass "stopAtBeginningOfMainSubprogram" to the launch request. +proc dap_launch {file {args {}} {env {}} {stop_at_main 0}} { if {[_dap_initialize "startup - initialize"] == ""} { return "" } @@ -269,6 +270,10 @@ proc dap_launch {file {args {}} {env {}}} { append params " \[o $envlist\]" } + if {$stop_at_main} { + append params { stopAtBeginningOfMainSubprogram [l true]} + } + return [dap_check_request_and_response "startup - launch" launch $params] } From patchwork Wed May 24 16:37:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69987 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 4E8743884573 for ; Wed, 24 May 2023 16:42:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E8743884573 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946520; bh=cIZykJ0+Ns0uiMT5urg7qrfHpGSLd3XTt1P84sTTktc=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aKI3hoOwPho+er2EQUKm+yQuULqbhxjCeOiS++sQdiUKbQUt55R1rIiKHD7ojFpzD Eg4bd4DfMJiGocrBiRGBhhCvB+aVOZP6dAsidg6woBIrHYhau3tkRmXboYYNWa0oqp JnXrWmt3eSWDB1b19PaH9x732RbrSNMx57fRsbls= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id D9F073857736 for ; Wed, 24 May 2023 16:37:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9F073857736 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-7749559d60aso705139f.0 for ; Wed, 24 May 2023 09:37:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946258; x=1687538258; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cIZykJ0+Ns0uiMT5urg7qrfHpGSLd3XTt1P84sTTktc=; b=Xr/7zWHR4RC1rpjqTxn6gEqRI0VxAJgiOl9doiU6dnT/6tfakbZ4G6wMCdXoNS/xiU m6yFSsW58sPeNLfo10sEA5egsyY5V7rLSEOwc2vZnEY7/ycXykv5BAGpU/tHcZUTdQE+ x7qTrklU7ZJHCE9dbh3hcx0w8V3Fq4L2FBe7XnaWvV75hNvv/IpTqWcfaIxkVDs9+7eA 1GKi2TQAh1aogbeVwqwxWZ1b7rWHF/YlvT+2cd+7T4iyrQIBMi6Keg4b4aip1ucBfbSf COKWr0ds62kv3UsRRpeY4mZww1//wYFJsbfoXpZZ06xBo650nOV64rg7cKmSTpMkt7O0 zJ2g== X-Gm-Message-State: AC+VfDzA7YAkwvTkUfsf6cXVNNVbfMbSDsoaHuH19jNruqGrz3WmRNcK CZvDcl4SW/u2jdms9iEO/YSSreUsSR81jXOl8Iia5w== X-Google-Smtp-Source: ACHHUZ6KwJ+KpUyCvEVhle1hl0wGNXTXUE/HLA1nj4GHvemkHO//xA95gYqbnKTquhH6i1VgUTwshA== X-Received: by 2002:a05:6602:1548:b0:76c:e93a:e2a with SMTP id h8-20020a056602154800b0076ce93a0e2amr19387301iow.8.1684946258142; Wed, 24 May 2023 09:37:38 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:37 -0700 (PDT) Date: Wed, 24 May 2023 10:37:14 -0600 Subject: [PATCH 23/25] Implement DAP breakpointLocations request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-23-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.0 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, T_SCC_BODY_TEXT_LINE 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" This implements the DAP breakpointLocations request. --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/locations.py | 45 +++++++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.dap/basic-dap.c | 2 +- gdb/testsuite/gdb.dap/basic-dap.exp | 15 +++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index 9e34d4cffd3..a3775a4a666 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -96,6 +96,7 @@ PYTHON_FILE_LIST = \ gdb/dap/__init__.py \ gdb/dap/io.py \ gdb/dap/launch.py \ + gdb/dap/locations.py \ gdb/dap/memory.py \ gdb/dap/next.py \ gdb/dap/pause.py \ diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index f07228e46ce..f3dd3ff7ea8 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -25,6 +25,7 @@ from . import bt from . import disassemble from . import evaluate from . import launch +from . import locations from . import memory from . import next from . import pause diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py new file mode 100644 index 00000000000..6c591579920 --- /dev/null +++ b/gdb/python/lib/gdb/dap/locations.py @@ -0,0 +1,45 @@ +# 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 . + +import gdb + +# This is deprecated in 3.9, but required in older versions. +from typing import Optional + +from .server import request +from .startup import in_gdb_thread, send_gdb_with_response + + +@in_gdb_thread +def _find_lines(filename, start_line, end_line): + lines = set() + for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: + line = entry["line"] + if line >= start_line and line <= end_line: + lines.add(line) + return {"breakpoints": [{"line": x} for x in sorted(lines)]} + + +@request("breakpointLocations") +def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra): + if endLine is None: + endLine = line + if "path" in source: + filename = source["path"] + elif "name" in source: + filename = source["name"] + else: + raise Exception("") + return send_gdb_with_response(lambda: _find_lines(filename, line, endLine)) diff --git a/gdb/testsuite/gdb.dap/basic-dap.c b/gdb/testsuite/gdb.dap/basic-dap.c index 2570b8b0702..5fb11fae41c 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.c +++ b/gdb/testsuite/gdb.dap/basic-dap.c @@ -38,7 +38,7 @@ address_breakpoint_here () int line_breakpoint_here () { - do_not_stop_here (); + do_not_stop_here (); /* FIRST */ function_breakpoint_here (); address_breakpoint_here (); return 0; /* BREAK */ diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index ca0d1be9f12..df9afcfcdfc 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -71,6 +71,21 @@ if {!$ok} { fail "check new breakpoint event" } +# Check that there are breakpoint locations on each line between FIRST +# and BREAK. +set first_line [gdb_get_line_number "FIRST"] +set last_line [expr {$line - 1}] +set obj [dap_check_request_and_response "breakpoint locations" \ + breakpointLocations \ + [format {o source [o path [%s]] line [i %d] endLine [i %d]} \ + [list s $srcfile] $first_line $last_line]] +# We know gdb returns the lines in sorted order. +foreach entry [dict get [lindex $obj 0] body breakpoints] { + gdb_assert {[dict get $entry line] == $first_line} \ + "line $first_line in result" + incr first_line +} + set obj [dap_check_request_and_response "reset breakpoint by line number" \ setBreakpoints \ [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \ From patchwork Wed May 24 16:37:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69986 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 179033884587 for ; Wed, 24 May 2023 16:41:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 179033884587 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946513; bh=Xt8JOCWFUpLk0uXutifu2Dl78Sinj597hMAY729iO+Q=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xZMscExGqiE8Di5o+e2OXdEK4h76oIiuYn/+ClC6XRmSNkgsypRA9D3aj989is5Ng Cm7ZSm8X4k6ZjVJRdkgJDajzwqmofN6ukrzGsjZ2wf1xG+aXgZlr/5QTMH1CPki0DK 6kQ+psfcBTarzkxvSiP5JmP90UWfDXowHA5tRqSY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 6E6DC3856DDF for ; Wed, 24 May 2023 16:37:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E6DC3856DDF Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-76c626eb5d1so31673239f.0 for ; Wed, 24 May 2023 09:37:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946258; x=1687538258; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xt8JOCWFUpLk0uXutifu2Dl78Sinj597hMAY729iO+Q=; b=U0JoXrBZuX5uIwTRcAbzhP3kkECoMCCNYhyXCoGJ0GMzi/0d8pDXUNTO70y13Qhsk4 3TnOMnvSX6zMmX7a7UUREqUUQl5alFBfmnK/T9NkG3Gn2DMQIBbcTQLAU6YvUInuPQAt lvX+3PacKMACfysvcrBSFIsE3wKqgSUXo+AFlG/fjiVyL/U18o+kLSe/aLcgk9OMHJQu XGB5FmM0EpIKYks16lUcHLTf9s2lvom3t/9SOwObaqTOOjgbUdsli2DDUEjE7DU37IcP A6dm9vxUtIDgRNYcZp6gAJLOtN3+7IiA4YUj7KwTRY0X3N6juZyUA+VvTfLwtQpqdgK2 mcuw== X-Gm-Message-State: AC+VfDy/djdUCxvPxFbndZk4ks9rOEvyOTFer6HooSNFdqTEXYbp6Rto dJYzoJjEb/RNZTNRwWUm3D9kop2gXJ/5CS4v+jeUWw== X-Google-Smtp-Source: ACHHUZ4OdNgt3I52cweIKjJvvvj5O3//JOsWu1i2tSlJYh3eqJa2rP37xZN8+1LJz7UFpZDKoqMK0A== X-Received: by 2002:a5d:8ad7:0:b0:76c:6382:8d5b with SMTP id e23-20020a5d8ad7000000b0076c63828d5bmr12169325iot.10.1684946258699; Wed, 24 May 2023 09:37:38 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:38 -0700 (PDT) Date: Wed, 24 May 2023 10:37:15 -0600 Subject: [PATCH 24/25] Do not report totalFrames from DAP stackTrace request MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-24-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" Currently, gdb will unwind the entire stack in response to the stackTrace request. I had erroneously thought that the totalFrames attribute was required in the response. However, the spec says: If omitted or if `totalFrames` is larger than the available frames, a client is expected to request frames until a request returns less frames than requested (which indicates the end of the stack). This patch removes this from the response in order to improve performance when the stack trace is very long. --- gdb/python/lib/gdb/dap/bt.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index a38573fbba8..4439b428926 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -50,13 +50,9 @@ def _backtrace(thread_id, levels, startFrame): current_frame = gdb.newest_frame() except gdb.error: current_frame = None - # Note that we always iterate over all frames, which is lame, but - # seemingly necessary to support the totalFrames response. - # FIXME maybe the mildly mysterious note about "monotonically - # increasing totalFrames values" would let us fix this. - while current_frame is not None: + while current_frame is not None and (levels == 0 or len(frames) < levels): # This condition handles the startFrame==0 case as well. - if current_number >= startFrame and (levels == 0 or len(frames) < levels): + if current_number >= startFrame: newframe = { "id": frame_id(current_frame), "name": _frame_name(current_frame), @@ -80,9 +76,11 @@ def _backtrace(thread_id, levels, startFrame): frames.append(newframe) current_number = current_number + 1 current_frame = current_frame.older() + # Note that we do not calculate totalFrames here. Its absence + # tells the client that it may simply ask for frames until a + # response yields fewer frames than requested. return { "stackFrames": frames, - "totalFrames": current_number, } From patchwork Wed May 24 16:37:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 69974 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 8930B382E69E for ; Wed, 24 May 2023 16:39:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8930B382E69E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684946382; bh=+TZOGGeWjPQMzsK2e9KX29U1ZZ/yOELfbBcgyW/Yd8w=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tEFSYGPWRgncY+WpDLKzSe/E02YPsm7PJzEipIQGt78HaVeJ3MZ1AeP5fpslfqKzT OxTdNoGASThB2hD6PmVITyAK5fL3Pduy7cKbPb41BRYE6aMiHHbAnqYs2ybWdRjK/7 tNo5XQglwJEuFSHZQUXGSO12oRxl1weOzMVSKAt4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id B93E9385700B for ; Wed, 24 May 2023 16:37:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B93E9385700B Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-77483a5a350so30983239f.0 for ; Wed, 24 May 2023 09:37:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946259; x=1687538259; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+TZOGGeWjPQMzsK2e9KX29U1ZZ/yOELfbBcgyW/Yd8w=; b=RozN0Wyz18hCnMsEA1ZE25hKjrYmqoJML3cLC4cEKTNf5FZTGjOxeej449a0ibqowv gB6C8T0HgvV6lKG7p4uC2os2mlEj16RXADgmGXwhhwprgg9ZV55lBfaNrAGCa+KH9Bsn OXw44KlCMEYl7iXBLhjBuKI7xUfoUYud6GxwwmPd/435q0DsYpp/smxtMnL/jiZJPB5G am/FIPU36pZc5swBhBTS8OLF/x0LQz6mO3q3c8AqPJfE4CC2lokcynVo0Q9lxUGZ7/i3 s3yje2pjas9uRWpQkOVwQ98xXZ7Wi40rcljWa85h2NYj21LpsCxw4vralx9018Ictjc4 YKLg== X-Gm-Message-State: AC+VfDwtYUEiZ6+aVkhxu1v/H2obXY9c9Ano3gnQCO96Cmv5lJbD77xl s/of2q6ZP7I1y9yHJsu6jgrIJAdkw9tNczxh8ANQ0g== X-Google-Smtp-Source: ACHHUZ6OqDLAU5wKTJGT2dpJdtRMweoCCZYw16ccAQ9cTaKC69OBFyQOA0W/HctmET9PD/JT4ZYl4w== X-Received: by 2002:a6b:5b08:0:b0:763:92eb:f81e with SMTP id v8-20020a6b5b08000000b0076392ebf81emr11287322ioh.8.1684946259344; Wed, 24 May 2023 09:37:39 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:39 -0700 (PDT) Date: Wed, 24 May 2023 10:37:16 -0600 Subject: [PATCH 25/25] Implement DAP conditional breakpoints MIME-Version: 1.0 Message-Id: <20230427-ada-catch-exception-v1-25-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-12.1 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, T_SCC_BODY_TEXT_LINE 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" I realized that I had only implemented DAP breakpoint conditions for exception breakpoints, and not other kinds of breakpoints. This patch corrects the oversight. --- gdb/python/lib/gdb/dap/breakpoint.py | 69 +++++++++++++++++++++++++++--------- gdb/testsuite/gdb.dap/cond-bp.c | 26 ++++++++++++++ gdb/testsuite/gdb.dap/cond-bp.exp | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 16 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index ad019333fea..20e65aa0e61 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -63,6 +63,14 @@ def breakpoint_descriptor(bp): } +# Extract entries from a hash table and return a list of them. Each +# entry is a string. If a key of that name appears in the hash table, +# it is removed and pushed on the result list; if it does not appear, +# None is pushed on the list. +def _remove_entries(table, *names): + return [table.pop(name, None) for name in names] + + # Helper function to set some breakpoints according to a list of # specifications and a callback function to do the work of creating # the breakpoint. @@ -78,11 +86,20 @@ def _set_breakpoints_callback(kind, specs, creator): result = [] for spec in specs: keyspec = frozenset(spec.items()) + + (condition, hit_condition) = _remove_entries(spec, "condition", "hitCondition") + if keyspec in saved_map: bp = saved_map.pop(keyspec) else: # FIXME handle exceptions here bp = creator(**spec) + + if condition is not None: + bp.condition = condition + if hit_condition is not None: + bp.ignore_count = hit_condition + breakpoint_map[kind][keyspec] = bp result.append(breakpoint_descriptor(bp)) # Delete any breakpoints that were not reused. @@ -98,9 +115,22 @@ def _set_breakpoints(kind, specs): return _set_breakpoints_callback(kind, specs, gdb.Breakpoint) +# Turn a DAP SourceBreakpoint, FunctionBreakpoint, or +# InstructionBreakpoint into a "spec" that is used by +# _set_breakpoints. SPEC is a dictionary of parameters that is used +# as the base of the result; it is modified in place. +def _basic_spec(bp_info, spec): + for name in ("condition", "hitCondition"): + if name in bp_info: + spec[name] = bp_info[name] + return spec + + # FIXME we do not specify a type for 'source'. # FIXME 'breakpoints' is really a list[SourceBreakpoint]. @request("setBreakpoints") +@capability("supportsHitConditionalBreakpoints") +@capability("supportsConditionalBreakpoints") def set_breakpoint(*, source, breakpoints: Sequence = (), **args): if "path" not in source: result = [] @@ -108,10 +138,13 @@ def set_breakpoint(*, source, breakpoints: Sequence = (), **args): specs = [] for obj in breakpoints: specs.append( - { - "source": source["path"], - "line": obj["line"], - } + _basic_spec( + obj, + { + "source": source["path"], + "line": obj["line"], + }, + ) ) # Be sure to include the path in the key, so that we only # clear out breakpoints coming from this same source. @@ -128,9 +161,12 @@ def set_fn_breakpoint(*, breakpoints: Sequence, **args): specs = [] for bp in breakpoints: specs.append( - { - "function": bp["name"], - } + _basic_spec( + bp, + { + "function": bp["name"], + }, + ) ) result = send_gdb_with_response(lambda: _set_breakpoints("function", specs)) return { @@ -151,9 +187,12 @@ def set_insn_breakpoints( if offset is not None: val = val + " + " + str(offset) specs.append( - { - "spec": val, - } + _basic_spec( + bp, + { + "spec": val, + }, + ) ) result = send_gdb_with_response(lambda: _set_breakpoints("instruction", specs)) return { @@ -162,16 +201,14 @@ def set_insn_breakpoints( @in_gdb_thread -def _catch_exception(filterId, condition=None, **args): +def _catch_exception(filterId, **args): if filterId == "assert": - args = ["-catch-assert"] + cmd = "-catch-assert" elif filterId == "exception": - args = ["-catch-exception"] + cmd = "-catch-exception" else: raise Exception(f"Invalid exception filterID: {filterId}") - if condition is not None: - args.extend(["-c", condition]) - result = gdb.execute_mi(*args) + result = gdb.execute_mi(cmd) # A little lame that there's no more direct way. for bp in gdb.breakpoints(): if bp.number == result["bkptno"]: diff --git a/gdb/testsuite/gdb.dap/cond-bp.c b/gdb/testsuite/gdb.dap/cond-bp.c new file mode 100644 index 00000000000..535b15d1420 --- /dev/null +++ b/gdb/testsuite/gdb.dap/cond-bp.c @@ -0,0 +1,26 @@ +/* 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 . */ + +int +main () +{ + int acc = 0, i, j; + for (i = 0; i < 5; ++i) + for (j = 0; j < 5; ++j) + acc += i + j; /* STOP */ + return acc; +} diff --git a/gdb/testsuite/gdb.dap/cond-bp.exp b/gdb/testsuite/gdb.dap/cond-bp.exp new file mode 100644 index 00000000000..376db4b3548 --- /dev/null +++ b/gdb/testsuite/gdb.dap/cond-bp.exp @@ -0,0 +1,65 @@ +# 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 breakpoint conditions. + +require allow_dap_tests + +load_lib dap-support.exp + +standard_testfile + +if {[build_executable ${testfile}.exp $testfile] == -1} { + return +} + +if {[dap_launch $testfile] == ""} { + return +} + +set line [gdb_get_line_number "STOP"] +set obj [dap_check_request_and_response "set conditional breakpoint" \ + setBreakpoints \ + [format {o source [o path [%s]] \ + breakpoints [a [o line [i %d] \ + condition [s "i == 3"] \ + hitCondition [i 3]]]} \ + [list s $srcfile] $line]] +set fn_bpno [dap_get_breakpoint_number $obj] + +dap_check_request_and_response "start inferior" configurationDone + +dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $fn_bpno + +set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \ + {o threadId [i 1]}] \ + 0] +set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id] + +set obj [dap_check_request_and_response "evaluate i" \ + evaluate \ + [format {o expression [s i] frameId [i %s]} $frame_id]] +dap_match_values "value of i" [lindex $obj 0] \ + "body result" 3 + +set obj [dap_check_request_and_response "evaluate j" \ + evaluate \ + [format {o expression [s j] frameId [i %s]} $frame_id]] +dap_match_values "value of j" [lindex $obj 0] \ + "body result" 3 + +dap_shutdown