From patchwork Thu Jul 13 14:05:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72649 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 940A93854E83 for ; Thu, 13 Jul 2023 14:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 940A93854E83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257158; bh=iZp3m+sBCkNOVzu20zjujFdRq7FlsIfhI8HANjTguHw=; 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=ORd10StUdJEQV+lZoYLp3Ia1QVPQHvls+9X28XAYLvb7gxRSVRMoHW/Nv9lIy67Kv 1AXclipr5D/VmbCi5W25wEaukRxJ9LeLaheleuxoXgQywly4/vtJuSbQJBBwyaMyzt KaIzcnZ0sKzu/fuo0JBOyox2g73adyT82V//Qdtc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id 9A24E3858D32 for ; Thu, 13 Jul 2023 14:05:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A24E3858D32 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-78362f57500so26749039f.3 for ; Thu, 13 Jul 2023 07:05:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257131; x=1691849131; 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=iZp3m+sBCkNOVzu20zjujFdRq7FlsIfhI8HANjTguHw=; b=QilDWUCySq/Jwkq7NTGlB45FH2k+kdBQbL6/bZwDvCBuxEtnPtodDsTPrAssPJkVRe L9/TkUBR7hE7DbbmErNBSXQ1tNN8hyHKsteA7POZF9sc4QuUQ8g1/UMUKJtTpoVUWG5M osO1A1xmTzEP/SNGq+uA4lR1xBzWqkNzKRsroFRy+lnO1FcSl/k+xByNShxvftKKlni0 Uqd1DNgUZMEUurQZ/baG72qHGFd79rzmIolJOvZCb3G7vJDv/Ng5f1QQVbs+N/Kkd+Ao q+PKrZ6piUuYvZuXb1RWu1pxhYAx8nDQyhX+HUbenu7sf+o9obsDA6mFN9PKQycCdtUl 5yLg== X-Gm-Message-State: ABy/qLao84ixM5v2O2k6sMfhNKtW8PutKl0XGZCJJkFZeGfn+BnquynZ fAt58dtYEcFqVX55VIoe26HsuyKOprSbllyOVzgXdg== X-Google-Smtp-Source: APBJJlFNgkC+iO2A7O8wEMIBjHVPvRHL3/QEuLDUTSINm1VQ3DVP3tomTfIMafZSP0XZQ85n7W9AZA== X-Received: by 2002:a5d:9c57:0:b0:786:463b:2ceb with SMTP id 23-20020a5d9c57000000b00786463b2cebmr2339814iof.11.1689257130828; Thu, 13 Jul 2023 07:05:30 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:30 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:26 -0600 Subject: [PATCH v3 1/6] Minor cleanups in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-1-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" While working on this series, I noticed a some oddities in py-inferior.exp. One is an obviously incorrect comment, and the others are confusing test names. This patch fixes these. --- gdb/testsuite/gdb.python/py-inferior.exp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 58deece5d5f..576c2b716e6 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -206,8 +206,7 @@ if [isnative] { } } -# Test Inferior is_valid. This must always be the last test in -# this testcase as it kills the inferior. +# Test Inferior is_valid. with_test_prefix "is_valid" { gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get initial list" 1 @@ -247,7 +246,7 @@ with_test_prefix "is_valid" { gdb_test "python print (inf_list\[1\].is_valid())" "True" \ "check inferior validity 3" - gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3" + gdb_test_no_output "remove-inferiors 2" gdb_test "python print (inf_list\[0\].is_valid())" "True" \ "check inferior validity 4" @@ -318,7 +317,7 @@ with_test_prefix "selected_inferior" { "print a connection object" gdb_test "inferior 1" ".*" "switch back to first inferior" - gdb_test_no_output "remove-inferiors 3" "remove second inferior" + gdb_test_no_output "remove-inferiors 3" } # Test repr()/str() From patchwork Thu Jul 13 14:05:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72650 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 E495F385DC22 for ; Thu, 13 Jul 2023 14:06:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E495F385DC22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257164; bh=Hc43djFECLk2fRZ3M6NkUPcvg60roiXJ8CgQZLcTDUs=; h=Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=tn8zp/GzZ6PvoWK/gdbtSc3yyw1iuKnFO0KVIAlv0K+BKZ5P3DE3ReRzVflLCR2pU A5kNsVeiwyhmUdburj2MkofiVYV/G7ihx5rQyMG9EcQ24at8kxchnxWrtsckXFkLTk TuHCk9goD349yg3gb7cXZY0ReeEbCDqABYiUt+20= 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 962703858CDB for ; Thu, 13 Jul 2023 14:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 962703858CDB Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-78360f61ba0so27235939f.1 for ; Thu, 13 Jul 2023 07:05:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257132; x=1691849132; h=cc: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=Hc43djFECLk2fRZ3M6NkUPcvg60roiXJ8CgQZLcTDUs=; b=ELglwVMLGy3FhF+gZCLpleUpSpW11rz1NGkpJScUFxGMwY2+T2esOnj8gvPQVlpw7/ FYgKsQtGmdUOdIGLXS4LI7gsZAD14U8Z/AlEYrWnbkU1UnIjpQwndBNMjQVEjtcNDHjb JfMoroJpa2xWSdRvLoGXRQOxdcP8aatWbVW2jR+MjiXMjrjnew3EDMho5dmw0E56J/LC adEMjWmmRsnpblnq7ph0enKuhpCL0v69zg/DLHbm+FM+vKi+FrQFJIWc0n/gkFcKO8vT 2p6OrYJH2vwuoRga0vF3EO2fkVOHSX/2kALfyC831UMpAIZv9N9qbifI+Q+t1QdrY+8d VGwg== X-Gm-Message-State: ABy/qLZ0OQS0KcW0GecwANUgXsiM4LvkdkusS7p/LOOcV+QR23DWSv/A fQm62I/3Eh4IJEESdlveEZ92vWgi7CcGBhHF15Losw== X-Google-Smtp-Source: APBJJlGPFKKBMShElxNmQNY+2TtfIAiYExXnUPlzpkWHvq3KXBdPinoaZiHAUHwCLbSL2SsRPuaoxQ== X-Received: by 2002:a5d:938f:0:b0:787:1990:d2de with SMTP id c15-20020a5d938f000000b007871990d2demr1852794iol.5.1689257131512; Thu, 13 Jul 2023 07:05:31 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:31 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:27 -0600 Subject: [PATCH v3 2/6] Refactor py-inferior.exp MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-2-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org Cc: Pedro Alves X-Mailer: b4 0.12.3 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 changes py-inferior.exp to make it a bit more robust when adding new inferiors during the course of the test. Approved-By: Pedro Alves --- gdb/testsuite/gdb.python/py-inferior.exp | 43 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 576c2b716e6..723f212ecc3 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -40,6 +40,20 @@ if {![runto_main]} { return 0 } +# The most recently added inferior. +set most_recent_inf 1 + +# A helper function that adds a new inferior. It returns the expected +# number of the new inferior. ARG is a string to pass to +# add-inferior. +proc add_inferior {{arg ""}} { + global most_recent_inf + incr most_recent_inf + gdb_test "add-inferior $arg" "Added inferior $most_recent_inf.*" \ + "add inferior $most_recent_inf" + return $most_recent_inf +} + # Test basic gdb.Inferior attributes and methods. gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1 @@ -234,7 +248,7 @@ with_test_prefix "is_valid" { "gdb.events.inferior_deleted.connect(del_inf_handler)" "" \ "end" "" - gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2" + set num [add_inferior] gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1 gdb_test "python print (len(inf_list))" "2" "get inferior list length 2" gdb_test "python print (inf_list\[0\].is_valid())" "True" \ @@ -246,7 +260,7 @@ with_test_prefix "is_valid" { gdb_test "python print (inf_list\[1\].is_valid())" "True" \ "check inferior validity 3" - gdb_test_no_output "remove-inferiors 2" + gdb_test_no_output "remove-inferiors $num" gdb_test "python print (inf_list\[0\].is_valid())" "True" \ "check inferior validity 4" @@ -287,15 +301,16 @@ with_test_prefix "selected_inferior" { # Figure out if inf 1 has a native target. set inf_1_is_native [gdb_is_target_native] - gdb_test "add-inferior -no-connection" "Added inferior 3" "create new inferior" - gdb_test "inferior 3" ".*" "switch to third inferior" - gdb_test "py print (gdb.selected_inferior().num)" "3" "third inferior selected" + set num [add_inferior "-no-connection"] + gdb_test "inferior $num" ".*" "switch to inferior $num" + gdb_test "py print (gdb.selected_inferior().num)" "$num" \ + "inferior $num selected" gdb_test "py print (gdb.selected_inferior().connection_num)" "None" \ - "third inferior's None connection number" + "inferior $num's None connection number" gdb_test "py print (gdb.selected_inferior().connection)" "None" \ - "third inferior's None connection" + "inferior $num's None connection" gdb_test "target native" "Done. Use the \"run\" command to start a process." \ - "target for the third inferior" + "target for inferior $num" # If inf 1 has a native target, inf 3's target is shared with 1's. # Otherwise, it must have created a new target with a new number. @@ -306,10 +321,10 @@ with_test_prefix "selected_inferior" { } gdb_test "py print (gdb.selected_inferior().connection_num)" \ "$expected_connection_num" \ - "third inferior's native connection number" + "inferior $num's native connection number" gdb_test "py print (gdb.selected_inferior().connection.num)" \ "$expected_connection_num" \ - "third inferior's native connection number, though connection object" + "inferior $num's native connection number, though connection object" # Test printing of gdb.TargetConnection object. gdb_test "py print (gdb.selected_inferior().connection)" \ @@ -317,18 +332,18 @@ with_test_prefix "selected_inferior" { "print a connection object" gdb_test "inferior 1" ".*" "switch back to first inferior" - gdb_test_no_output "remove-inferiors 3" + gdb_test_no_output "remove-inferiors $num" } # Test repr()/str() with_test_prefix "__repr__" { - gdb_test "add-inferior" "Added inferior 4 on connection .*" "add inferior 4" + set num [add_inferior] gdb_py_test_silent_cmd "python infs = gdb.inferiors()" "get inferior list" 1 gdb_test "python print (infs\[0\])" "" gdb_test "python print (infs)" \ - "\\\(, \\\)" \ + "\\\(, \\\)" \ "print all inferiors 1" - gdb_test_no_output "remove-inferiors 4" + gdb_test_no_output "remove-inferiors $num" gdb_test "python print (infs)" \ "\\\(, \\\)" \ "print all inferiors 2" From patchwork Thu Jul 13 14:05:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72653 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 8FDE03848BB4 for ; Thu, 13 Jul 2023 14:06:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FDE03848BB4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257193; bh=fuzOD0S+gc2J0wbl8rnoIaPBlfhPGq445lXV4XZcONc=; 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=PAgtaECJpSjOTes1sua5Nz2g/TYuGk1Av0zxzNhbdmLqAiCjum3GAVyQk8KKl3Heu 4a7Pu72SN7Y1w+ySN3Se/mO/XMhu4XzVluyP4rGTmGGQ9mKEVYTG7i2AFz0DviHX4Q yDZV+5QJvwseNHi+Z9uH5/pFAa9UckaBscL/bR2Y= 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 3F17C3858C62 for ; Thu, 13 Jul 2023 14:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F17C3858C62 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-78372b896d0so25866739f.2 for ; Thu, 13 Jul 2023 07:05:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257132; x=1691849132; 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=fuzOD0S+gc2J0wbl8rnoIaPBlfhPGq445lXV4XZcONc=; b=LgamJ1i0IkDd6KJU4kB7jRxvg3yWtjF59leFVwMUUV+mFeRM+5hrNE40qALjUoJiAs T+FGCXn4nsNzDxNGFZjTnjOXFp6mu0x2A428Y/zFrS3m+jYtVtIe3D3GyD0pCQ5YQL6k 74Xixtpg/4DGZRY9voT5ZMCG/XtZMUPrVv2FVRIPsc9KRacKg65dQMcxB2zDkTXFMJeW 4eCFEfocwbGNIyqGYHUZnfbwglnkN4H1JXfZgy4ph+Od2gTZvoO3xchG4RclZQwTSzDl Dnx8lGyrBcYe6prSaYtiRBYNfdcHwBOymdUyd9n/sbrOE/1n8/FX8QrOW8FbUTEyMHZK jKPA== X-Gm-Message-State: ABy/qLYtze5MvZsG1o2qqfCm+JJ1HDIuc9NJwaBlLZ04wAZaaFtViRxb XNh1ldchooXI7GzC+p6M3RqVmlNqnxHu24NLXlksnw== X-Google-Smtp-Source: APBJJlGIdbqBOhvgayxna7Tcf0A1Yq/gx1AeTyYh5pnazaQmZO81H0d+jtP42+EY1sXOn1s53iJ6Nw== X-Received: by 2002:a6b:4102:0:b0:787:8fc:307d with SMTP id n2-20020a6b4102000000b0078708fc307dmr1773933ioa.5.1689257132229; Thu, 13 Jul 2023 07:05:32 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:31 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:28 -0600 Subject: [PATCH v3 3/6] Rename Python variable in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-3-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" py-inferior.exp creates a Python variable named 'str'. This clashes with the built-in type of the same name and can be confusing when trying to evaluate Python code when debugging the test case. This patch renames it. --- gdb/testsuite/gdb.python/py-inferior.exp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 723f212ecc3..8762b6992ca 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -88,13 +88,14 @@ gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*" gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ "read str address" 0 -gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ - "read str contents" 1 +gdb_test "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(astr)" \ + "" \ + "read str contents" gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0 -gdb_py_test_silent_cmd "python str\[1\] = a" "change str" 0 -gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \ +gdb_py_test_silent_cmd "python astr\[1\] = a" "change str" 0 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \ "write str" 1 -gdb_test "print (str)" " = \"hallo, testsuite\"" \ +gdb_test "print str" " = \"hallo, testsuite\"" \ "ensure str was changed in the inferior" # Test memory search. From patchwork Thu Jul 13 14:05:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72651 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 CFB47384C6A9 for ; Thu, 13 Jul 2023 14:06:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFB47384C6A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257187; bh=CgBqoVXNBSK3YIGKKk0HC35fnVzOUOZqHhlLZ0FarDU=; h=Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NyKEaxt5B/psA9FkQPNjNZNc8/ymTPV+nX0W5E/URu+tuMzJGR1/Nl6hsEgk4C9XU 5Orss3pWAPzzEODhHkcpq+dvn4h12MxvsJJr44A2C9INrdaRbR0X+tItBn2lW5yWyF wr++P2pgpFAb3ouP4JD/swYRdWYCz4KVLRCXIctk= 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 1BF373858C00 for ; Thu, 13 Jul 2023 14:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BF373858C00 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-76c64da0e46so24962939f.0 for ; Thu, 13 Jul 2023 07:05:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257133; x=1691849133; h=cc: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=CgBqoVXNBSK3YIGKKk0HC35fnVzOUOZqHhlLZ0FarDU=; b=T7Oc0nWgmu7FCmz0BS+MgfBHoWEk0i2AB0ZzGkDgCUnVcY+PbCYhBHeHl8klHtxFBp D9CMdNdPy15YGayikp5ewuKifr0jPj4JuZJ7Giz/T1QvYBob5WV9cEVGJr+sapBA/Jp/ E5AL08RmaELDSdSR6gCGq8Igg12LrWwZptK8FOzms9BLwkTHZHZCBy5f2LQ8OnCE9kLB 8tXxRaoIHhzblUImRLEWHUtchY9rX24CpcxSD17s48N0UDFAjPiDMWC5sBWy35OkR0Wu +2/paFc0/CrkkjYzZmc9FWSGgL/pP+iJVhgYYRuuy2fRT2A8lcQQ7MjKqn5bN8Al2/XS Sa5w== X-Gm-Message-State: ABy/qLa1thuXv5R/fsyjLFSe4JShSFbS2i+zc7oG/Bp4KeMGNSD2oWYA J92YwbsMvEIBQS5oBVj8crUWI/CX8OEU2bmDK6AWgA== X-Google-Smtp-Source: APBJJlGUJ15x9uWCde0nyxZxGnjbYB1ByCXlMqu/I9aefXPXqUP5x2qGRO7f75+D803W4W+1uH6Eng== X-Received: by 2002:a5e:8608:0:b0:783:56f2:e733 with SMTP id z8-20020a5e8608000000b0078356f2e733mr1899839ioj.4.1689257132924; Thu, 13 Jul 2023 07:05:32 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:32 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:29 -0600 Subject: [PATCH v3 4/6] Remove obsolete comment from gdbthread.h MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-4-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org Cc: Pedro Alves X-Mailer: b4 0.12.3 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" A comment in gdbthread.h refers to a global that no longer exists. Approved-By: Pedro Alves --- gdb/gdbthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 7135515bf45..d294be6762b 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -764,7 +764,7 @@ extern int thread_count (process_stratum_target *proc_target); /* Return true if we have any thread in any inferior. */ extern bool any_thread_p (); -/* Switch context to thread THR. Also sets the STOP_PC global. */ +/* Switch context to thread THR. */ extern void switch_to_thread (struct thread_info *thr); /* Switch context to no thread selected. */ From patchwork Thu Jul 13 14:05:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72652 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 E20E13865C2D for ; Thu, 13 Jul 2023 14:06:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E20E13865C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257189; bh=3TJyL9VXGTdhfrjnFX8NGe3dhiRDXcCizlSU3zWpqVA=; 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=J6LG6D9wMh01Mrczzqt80jqqDTCWjtxE9AO5xIGGM/VIgPY4nfVmbg2/1k0eY9dpQ Q91UkG5CnFkiEEgByQ3ze8hf41e2XgkKWgqCkz1v4VA0tGij7FENvP5VEzRCDa0BTV HsBLV36S6BG1XnMDCTxHgmrTFIomEdbjVHFCP1Es= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id DEA4B3858404 for ; Thu, 13 Jul 2023 14:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DEA4B3858404 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7835e2286c4so24560439f.1 for ; Thu, 13 Jul 2023 07:05:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257134; x=1691849134; 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=3TJyL9VXGTdhfrjnFX8NGe3dhiRDXcCizlSU3zWpqVA=; b=Ap18MUJ51oJc6Ve6ikTLEmOE0UVPnCeRNE84xgSpKmhV6yyWRYod8KcYn7m095AgJy q6rHX7fxZ7TyE6huO6HjYhYazmQ5pu7/EOiWcWDTcU0oI+wB+pOAcJj7l1qMzMyVfg6h 4MAIuj8Zsq08b3zyCDT7jm+7GdqG5qZR09iP9Ipzz+g+kAe/9FDWki4cxxRqHV8kQrow 6VbDKCEZWi6/EiZl7ouBfqWNyfhH+vKmUy1H6VcrfAUqbk/UjSWJmNkGsEPzf3eUq5M4 zrAicA3Ng6qh7RcHRjcPUzrpUNEg5l9BvwbivW5t2bsPX1ZfMFwPwyFiGe+i24OA2K24 SISw== X-Gm-Message-State: ABy/qLbnxU/Ndsb3tuQj7sFc5UpfF61isdCo+XKbKKibJrZyN7miIkTW diqYREsMSqi/za0D0alQmlqbtV6awRhPikRfStAhYQ== X-Google-Smtp-Source: APBJJlH4xuqPMGXNW8IfAEZPRffqwlGERuWaUiI9NNhOlZ/o1jwAI/SYhn4ozbLkCWCNnLs+tfLxLQ== X-Received: by 2002:a6b:d919:0:b0:787:167e:f796 with SMTP id r25-20020a6bd919000000b00787167ef796mr1734920ioc.15.1689257133728; Thu, 13 Jul 2023 07:05:33 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:33 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:30 -0600 Subject: [PATCH v3 5/6] Introduce scoped_restore_current_inferior_for_memory MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-5-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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 introduces a new class, scoped_restore_current_inferior_for_memory, and arranges to use it in a few places. This class is intended to handle setting up and restoring the various globals that are needed to read or write memory -- but without invalidating the frame cache. I wasn't able to test the change to aix-thread.c. --- gdb/aix-thread.c | 18 ++++-------------- gdb/inferior.h | 29 +++++++++++++++++++++++++++++ gdb/proc-service.c | 10 ++-------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index fbe80d656c2..74cc67c942b 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -615,13 +615,8 @@ pdc_read_data (pthdb_user_t user_current_pid, void *buf, /* This is needed to eliminate the dependency of current thread which is null so that thread reads the correct target memory. */ { - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - inferior_ptid = ptid_t (user_current_pid); - scoped_restore_current_inferior restore_inferior; - set_current_inferior (inf); - - scoped_restore_current_program_space restore_current_progspace; - set_current_program_space (inf->pspace); + scoped_restore_current_inferior_for_memory save_inferior + (inf, ptid_t (user_current_pid)); status = target_read_memory (addr, (gdb_byte *) buf, len); } ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE; @@ -648,13 +643,8 @@ pdc_write_data (pthdb_user_t user_current_pid, void *buf, user_current_pid, (long) buf, hex_string (addr), len); { - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - inferior_ptid = ptid_t (user_current_pid); - scoped_restore_current_inferior restore_inferior; - set_current_inferior (inf); - - scoped_restore_current_program_space restore_current_progspace; - set_current_program_space (inf->pspace); + scoped_restore_current_inferior_for_memory save_inferior + (inf, ptid_t (user_current_pid)); status = target_write_memory (addr, (gdb_byte *) buf, len); } diff --git a/gdb/inferior.h b/gdb/inferior.h index caa8e4d494a..be76c456c8c 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -761,6 +761,35 @@ class scoped_restore_current_inferior inferior *m_saved_inf; }; +/* When reading memory from an inferior, the global inferior_ptid must + also be set. This class arranges to save and restore the necessary + state for reading or writing memory, but without invalidating the + frame cache. */ + +class scoped_restore_current_inferior_for_memory +{ +public: + + /* Save the current globals and switch to the given inferior and the + inferior's program space. PTID must name a thread in INF, it is + used as the new inferior_ptid. */ + scoped_restore_current_inferior_for_memory (inferior *inf, ptid_t ptid) + : m_save_ptid (&inferior_ptid) + { + set_current_inferior (inf); + set_current_program_space (inf->pspace); + inferior_ptid = ptid; + } + + DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior_for_memory); + +private: + + scoped_restore_current_inferior m_save_inferior; + scoped_restore_current_program_space m_save_progspace; + scoped_restore_tmpl m_save_ptid; +}; + /* Traverse all inferiors. */ diff --git a/gdb/proc-service.c b/gdb/proc-service.c index 509836ec1a8..366e0510070 100644 --- a/gdb/proc-service.c +++ b/gdb/proc-service.c @@ -72,14 +72,8 @@ static ps_err_e ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr, gdb_byte *buf, size_t len, int write) { - scoped_restore_current_inferior restore_inferior; - set_current_inferior (ph->thread->inf); - - scoped_restore_current_program_space restore_current_progspace; - set_current_program_space (ph->thread->inf->pspace); - - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - inferior_ptid = ph->thread->ptid; + scoped_restore_current_inferior_for_memory save_inferior (ph->thread->inf, + ph->thread->ptid); CORE_ADDR core_addr = ps_addr_to_core_addr (addr); From patchwork Thu Jul 13 14:05:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72654 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 89E3C385773F for ; Thu, 13 Jul 2023 14:06:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89E3C385773F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257218; bh=RZYupIS6bCDfKnKo+8vb5qM1YMs1DmdCsbRHUj89RTc=; 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=f9DROeYvtPhb65TenjZQTHpvfqBvs6r3aEqHbYFrBVr5sBoH8ldf8DMU7WD4Sf7ny 6JZLT1jMdPHN3A+GetutUrenITMNSLs0PCbe/tdE8a8cH9CAk6AfUB6E3WNDH25CV+ hBTfLwJsPV05840BUHymwEGMXRhoT2PtS8p7Kbug= 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 977333858288 for ; Thu, 13 Jul 2023 14:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 977333858288 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7837329a00aso24423139f.2 for ; Thu, 13 Jul 2023 07:05:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257134; x=1691849134; 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=RZYupIS6bCDfKnKo+8vb5qM1YMs1DmdCsbRHUj89RTc=; b=ZQ5hvCgZivJbEDVmg0x9iY6OVVvOHcl0jY6TPrlswcID5ttKlLhMobdpxQcxTdrE95 MtMcu2lGUxFXXjYwU0LhAISrbsDEkY+bVbaDl0H2FXqF47hfCYPchdtVnp/wil0phw1f DgnJH2br8V1S9sAOvx4tkhm1K+WX0HzbkrkP4P5ZF0vW0lyMkjOMVZ8PB7FzfYEmErq9 ZOTGqpJ5j4wszMPMuB+SbF21Sp4LQNkYo1JgQTiTDvVt5KvaQ7LqfDpsMSzbc4Lg/B9J tc36I2Rm388G9p3eWAYaT8ccSt8Kc9i/ZzKzxsPNq0dcem+Ys67KZjY/aXvfvDLsSGJ9 xjvA== X-Gm-Message-State: ABy/qLafGh464Fh41u4CVIpT+0jMVc/L7j/5HjtpPXEsrQ0o8Y8BNOQB H8PaFMJgM4GhQ5/fjBCIHloygmX5A5rS6UklqhrPng== X-Google-Smtp-Source: APBJJlFDLIzgH1PN/icAbfWGUfMbvELk4qrqd2xC9vi306UeaUPAhdcprPZzO1Bs9tSnoihujYpc0A== X-Received: by 2002:a05:6602:2208:b0:786:267e:bd4 with SMTP id n8-20020a056602220800b00786267e0bd4mr1605254ion.10.1689257134402; Thu, 13 Jul 2023 07:05:34 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:33 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:31 -0600 Subject: [PATCH v3 6/6] Use correct inferior in Inferior.read_memory et al MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-6-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" A user noticed that Inferior.read_memory and a few other Python APIs will always use the currently selected inferior, not the one passed to the call. This patch fixes the bug by arranging to switch to the inferior. I found this same issue in several APIs, so this fixes them all. I also added a few missing calls to INFPY_REQUIRE_VALID to these methods. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30615 --- gdb/python/py-inferior.c | 43 ++++++++++++++++++++++++++------ gdb/testsuite/gdb.python/py-inferior.exp | 26 +++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index af8bd8855a3..f6000b944da 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -30,6 +30,7 @@ #include "gdbsupport/gdb_signals.h" #include "py-event.h" #include "py-stopevent.h" +#include "progspace-and-thread.h" #include using thread_map_t @@ -528,11 +529,14 @@ gdbpy_inferiors (PyObject *unused, PyObject *unused2) static PyObject * infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) { + inferior_object *inf = (inferior_object *) self; CORE_ADDR addr, length; gdb::unique_xmalloc_ptr buffer; PyObject *addr_obj, *length_obj; static const char *keywords[] = { "address", "length", NULL }; + INFPY_REQUIRE_VALID (inf); + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords, &addr_obj, &length_obj)) return NULL; @@ -543,6 +547,11 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) try { + /* Use this scoped-restore because we want to be able to read + memory from an unwinder. */ + scoped_restore_current_inferior_for_memory restore_inferior + (inf->inferior, any_thread_of_inferior (inf->inferior)->ptid); + buffer.reset ((gdb_byte *) xmalloc (length)); read_memory (addr, buffer.get (), length); @@ -565,6 +574,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) static PyObject * infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) { + inferior_object *inf = (inferior_object *) self; struct gdb_exception except; Py_ssize_t buf_len; const gdb_byte *buffer; @@ -573,6 +583,8 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) static const char *keywords[] = { "address", "buffer", "length", NULL }; Py_buffer pybuf; + INFPY_REQUIRE_VALID (inf); + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords, &addr_obj, &pybuf, &length_obj)) return NULL; @@ -591,6 +603,13 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) try { + /* It's probably not too important to avoid invalidating the + frame cache when writing memory, but this scoped-restore is + still used here, just to keep the code similar to other code + in this file. */ + scoped_restore_current_inferior_for_memory restore_inferior + (inf->inferior, any_thread_of_inferior (inf->inferior)->ptid); + write_memory_with_notification (addr, buffer, length); } catch (gdb_exception &ex) @@ -604,7 +623,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) } /* Implementation of - gdb.search_memory (address, length, pattern). ADDRESS is the + Inferior.search_memory (address, length, pattern). ADDRESS is the address to start the search. LENGTH specifies the scope of the search from ADDRESS. PATTERN is the pattern to search for (and must be a Python object supporting the buffer protocol). @@ -614,6 +633,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) static PyObject * infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) { + inferior_object *inf = (inferior_object *) self; struct gdb_exception except; CORE_ADDR start_addr, length; static const char *keywords[] = { "address", "length", "pattern", NULL }; @@ -624,6 +644,8 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) int found = 0; Py_buffer pybuf; + INFPY_REQUIRE_VALID (inf); + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords, &start_addr_obj, &length_obj, &pybuf)) @@ -656,6 +678,13 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) try { + /* It's probably not too important to avoid invalidating the + frame cache when searching memory, but this scoped-restore is + still used here, just to keep the code similar to other code + in this file. */ + scoped_restore_current_inferior_for_memory restore_inferior + (inf->inferior, any_thread_of_inferior (inf->inferior)->ptid); + found = target_search_memory (start_addr, length, buffer, pattern_size, &found_addr); @@ -910,12 +939,12 @@ infpy_get_main_name (PyObject *self, void *closure) try { /* This is unfortunate but the implementation of main_name can - reach into memory. */ - scoped_restore_current_inferior restore_inferior; - set_current_inferior (inf->inferior); - - scoped_restore_current_program_space restore_current_progspace; - set_current_program_space (inf->inferior->pspace); + reach into memory. It's probably not too important to avoid + invalidating the frame cache here, but this scoped-restore is + still used, just to keep the code similar to other code in + this file. */ + scoped_restore_current_inferior_for_memory restore_inferior + (inf->inferior, any_thread_of_inferior (inf->inferior)->ptid); name = main_name (); } diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 8762b6992ca..eb501838117 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -91,6 +91,7 @@ gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ gdb_test "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(astr)" \ "" \ "read str contents" +gdb_test "python print(astr\[0\])" .* gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0 gdb_py_test_silent_cmd "python astr\[1\] = a" "change str" 0 gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \ @@ -98,6 +99,10 @@ gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \ gdb_test "print str" " = \"hallo, testsuite\"" \ "ensure str was changed in the inferior" +# Add a new inferior here, so we can test that operations work on the +# correct inferior. +set num [add_inferior] + # Test memory search. set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*} @@ -115,6 +120,9 @@ with_test_prefix "string" { gdb_test_no_output "py start_addr = search_buf.address" gdb_test_no_output "py length = search_buf.type.sizeof" + # Switch to the new inferior before testing. + gdb_test "inferior $num" ".*" "switch to inferior $num" + gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa'))" \ "${one_pattern_found}" "find string pattern" @@ -128,6 +136,24 @@ with_test_prefix "string" { "${one_pattern_found}" "pattern found at end of range" } +# While still in the new inferior, test reading and writing memory +# again. +gdb_test "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(astr)" \ + "" \ + "read str while other inferior selected" +gdb_test "python print(astr\[1\])" "b'a'" \ + "print a character from the string" +gdb_py_test_silent_cmd "python astr\[1\] = b'X'" "change str again" 0 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \ + "write str while other inferior selected" 1 + +gdb_test "inferior 1" ".*" "switch back to inferior 1" + +gdb_test "print str" " = \"hXllo, testsuite\"" \ + "ensure str was changed while other inferior selected" + +gdb_test_no_output "remove-inferiors $num" "remove-inferiors $num" + # Import struct to pack the following patterns. gdb_test_no_output "py from struct import *"