From patchwork Fri Jul 14 17:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72717 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 AD248385770D for ; Fri, 14 Jul 2023 17:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD248385770D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354423; 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=jME1ow9khnSGNTttEHgUn0i/h8PRtaVlPoeU2iYOQNBL+xiI8t7YB1V45q1fz3573 +ANsFWVHpYtP/ctfmwywEuJ/aBNz2nqkx5jK6kjDSqGkWu+9J2MVaUkebLq71JgWGR seakkCRErbqSCo7CN1l6ABLIjVX8wTNmsXtikdc4= 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 884603858C52 for ; Fri, 14 Jul 2023 17:06:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 884603858C52 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-78362f57500so87077539f.3 for ; Fri, 14 Jul 2023 10:06:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354395; x=1691946395; 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=g4bQa0d2ZuzIgOLM+zfUxAcM9kKLOaCWNTehmllR3pSbU5chapzWEbJMhm4OsTJCnO YdK5sbrivOzGwtx8Id3I2MqWfkC3IG/YdCrcIV+Dn98XyL+IUiBFWQKkd0fDAMEYGPP9 shLY83/dlPtgdmbI0rj/An84mk6AgpiMgiRqKQsc/nYBDwYm6z7vAuI5dVCe5aLDo1Jx 8edSwoHpW/G1t7LgDzbQwgnB3k73681FPiNF8NDA6ACKzyaaOEcsZz9X+6GcAR5Do+Ov 6hUlGmOh6+SaZdCq+RUixc23qEwobTiDAZz4QJ97Sqmrg8T7ugLq7KG95lybfMY17iOv jdug== X-Gm-Message-State: ABy/qLaIPqryuacoEyuoQZsABthUDK0ML9xoWNj5nGg8t4G4ug9nqjY6 ioyWDLjFpM/gMB0Q5H4eSwGo4EKCaGrskhxArz1sxA== X-Google-Smtp-Source: APBJJlHTy83RqeaHmKxxtMlU2rDmt79ebltbdUOG48i2fUfEZicKp/BhpvyLwnFN192itaiNsTrhNg== X-Received: by 2002:a6b:fb03:0:b0:783:572c:9caa with SMTP id h3-20020a6bfb03000000b00783572c9caamr5643251iog.0.1689354395630; Fri, 14 Jul 2023 10:06:35 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:35 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:25 -0600 Subject: [PATCH v4 1/6] Minor cleanups in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-1-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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 Fri Jul 14 17:06: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: 72718 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 A7B213856DF1 for ; Fri, 14 Jul 2023 17:07:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7B213856DF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354437; 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=Gepr4IykVT0/1W3tCe7ZubBVZgKqWCE/m2bzA1sMjFMvBm3sTy2mCERxWmWtf4wme 2s0X+ECKhX/4LEpyN08MvcErHO2HxNfqi3GrRfi3DJQJ8SMF95JyQhHzvQlnZOaxEI za0uR6HDM8uZ84s3MjRjW9IBN8cXA+6yoxQj12Ss= 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 1C9F03858C53 for ; Fri, 14 Jul 2023 17:06:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C9F03858C53 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-78372625badso81098339f.3 for ; Fri, 14 Jul 2023 10:06:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354396; x=1691946396; 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=SrRPvfMnRtm/8BfsE4uezcg/z2TfwpkUZYQwdLbNfOGd32o976QYmF9MEzreAPsne/ g34YhvqN1hJbOjfxcKtC+8/NHF03XvtRMcTwr4P3M4ztsvruVyQuDFnV3XJSCtSvEH+d Gp6gO/itz+OXyxXYwaASWaYjoNvuxLl1zk5lTB/UEZj83AK4dl1hYEySUwRipDhb+Mfb tVSMHETKv78p/XLsTg9pPxFIBfoq0yNm/p5Ew+OlTVtmRWL81IwcZzNF+glvAr7cZUaZ OGDyV6B6aAiDKODE84sm4hSzYLifiYUtMmVE96mKHzKyqfmvuJiXg9c3+0keG5uYTQgN YCgA== X-Gm-Message-State: ABy/qLa3QVt5uVNZj+MZ2naLtnmzwT0FHylvhhw9zJlAt6SYHBhS4V0l ZZjo8w1VgyQGGOkKX/k9mPqL5PzQ1S+LTEn8SmMfXw== X-Google-Smtp-Source: APBJJlHuAKWr4oQ8tA9O+z73X8wXKwhM32d7Q7UtIuTagQTSw78ULbIG8qsRxInTFLQ1g34423TIHg== X-Received: by 2002:a6b:908:0:b0:783:606b:740f with SMTP id t8-20020a6b0908000000b00783606b740fmr5232137ioi.15.1689354396183; Fri, 14 Jul 2023 10:06:36 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:35 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:26 -0600 Subject: [PATCH v4 2/6] Refactor py-inferior.exp MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-2-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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 Fri Jul 14 17:06: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: 72719 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 BE66C385AF91 for ; Fri, 14 Jul 2023 17:07:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE66C385AF91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354454; bh=0dFUpulqc63Pl758nK5WPbvPOg4hphPwDZoo3/oEF6E=; 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=jP9X/BdD13H7N2lFF8KJCPBDfFgkV8T+4GZZ4cMnweu4MqXmtMCvc9puxIoARlw1/ 58HxAGf49V9JlNjHoewBxYiCTNSjoXlIHGDg8vfudsdmF6ZzuEpnl2kel/JEA6Ig/l X4r97GFVNQTBSVhPGGDR4n+91oQDBUYcup4Od/1E= 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 8604A3858C54 for ; Fri, 14 Jul 2023 17:06:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8604A3858C54 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7872d448c5aso88066239f.0 for ; Fri, 14 Jul 2023 10:06:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354397; x=1691946397; 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=0dFUpulqc63Pl758nK5WPbvPOg4hphPwDZoo3/oEF6E=; b=KOOOO3ShZaWvakbQmCKeXGWcR4aRoatbgkgNTUVFh3lGfSkexQSE+Dxrhj4ucrBNMo DIq6vtrhpPao8EDMNSa/TVwo7LiZcWllN1qTo7iN2QIDpmZtatt3kjbo/v2JE/817JMZ Y4IZjRnPvuJXFX9PZg3c8Xx/9Omm3TGxikn9J4nHUxGjC9wosIWvPNezeaYqb2PAHe// n0MJyzWU+C0y48XdOlcegC9oXw5B1OzGu5sxy1QNrLDH+iwDQG3rZPgeNuyTCBBoULWU vypnTlj8MQqtsXjxA60xJ784vz3dXYVpmL7lWNpd90g/GR2PXZ49Fdc/CLZ6+F2o2gop q6Xg== X-Gm-Message-State: ABy/qLYKEqVmxCUgdehCHV3lKW1qds7YGLocQT/mZmPgu35UCt5+9hgI BqnJNRp1oXMNpEkbXLN6uN22sbCYIfXzjWjVKKxn/A== X-Google-Smtp-Source: APBJJlG8rN0xWfuzgOj6oM+ZQ5ttLesV4RBOuvgoj2VWPdKUCJDQYfnDHK5CQhVn6FzLjbfQy2bj3w== X-Received: by 2002:a5d:9c57:0:b0:786:463b:2ceb with SMTP id 23-20020a5d9c57000000b00786463b2cebmr5643803iof.11.1689354396788; Fri, 14 Jul 2023 10:06:36 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:36 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:27 -0600 Subject: [PATCH v4 3/6] Rename Python variable in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-3-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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" 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. Approved-By: Pedro Alves --- 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 Fri Jul 14 17:06: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: 72722 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 3DBBC3857C51 for ; Fri, 14 Jul 2023 17:08:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DBBC3857C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354485; 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=cgd2cy6P/ipxTLQ+MAYABtOMJlDP/qhUx0AbFjkHooRmA+lD9EPYU8aFZ86jPyGFO VjVb42ZOhV4NhzwPQGeFLrrXmTiruxb0mQREw3nS7hiZgFcP/M+7UBK0kGTEBq2xGs JJUVBzU8+shE4OLNG6d4OmYWHjHZWKNWuHGToonM= 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 0B00D3858C78 for ; Fri, 14 Jul 2023 17:06:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B00D3858C78 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-78362f57500so87079439f.3 for ; Fri, 14 Jul 2023 10:06:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354397; x=1691946397; 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=CJdMfr1RoExct1mFS1S48vvIRctzUTZaLsn+GYXhMJ5bVW0RX8n2TpNQ69DKApT/BB 7sNyn9tbKjLv1xRvhhB/wyvWeueE89EQVRXJeVHkC5YiUdiS3WjuKtm4zGs/SolJIZmX p0maLSE7HNgsV52AYHGr1YCLp+vCKrR9ollf9btlnhaDGd2W8OJixxej8J62mD2VVE5g 5+A/GfjZD/NkL/ue1e7s0FWvEueVEXFOz6iLHnUagXRqoI22NPnfo2vQxWNHwzPr1t3x c+dfAsoVC0riWlz8dNygHk0hicEf0vIBlnMrhEbfhsFq60UXuBF1MbI8VFpXIV+i4Us7 0jeA== X-Gm-Message-State: ABy/qLampnU+jpo29ZFcbd0DTbssYq5y6EbztdT3t4/bWFmQ+TrwnOkB bBG23C25ZG/FHtD4n54iouk/OAxk1GCJw0YmzIT5pw== X-Google-Smtp-Source: APBJJlEVhaaFMWmE2veBSNdVpLxS6x//40HS+llUF4KoqKPfA43UWL0V4zgZJR89MTb8yEu9lp3pSA== X-Received: by 2002:a5e:8b49:0:b0:785:ca70:46a2 with SMTP id z9-20020a5e8b49000000b00785ca7046a2mr5938828iom.4.1689354397332; Fri, 14 Jul 2023 10:06:37 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:37 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:28 -0600 Subject: [PATCH v4 4/6] Remove obsolete comment from gdbthread.h MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-4-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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 Fri Jul 14 17:06: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: 72720 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 DADD4385AF94 for ; Fri, 14 Jul 2023 17:07:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DADD4385AF94 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354457; bh=Ort72HGqQMXrb2eYST6Ap4PTt8YGeoB4XPsXh2kt0RE=; 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=by4t0em1pS2JEts57iTwnZ1r9NO6dvDDsuGsIyR9JxfjUQI3zACiUxrfKm+lSNJTD 96ufKhM2jshWTL5AWNMXL8Lz+yX6llve7sFYdOZTzLRa1q4fGLq1JhKQmd9F39WMyj 70Ro52vq7VHx1V90LdPFSkSjeQTVZUq40M7PG+rQ= 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 DDF7A3858C2B for ; Fri, 14 Jul 2023 17:06:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDF7A3858C2B Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7878e573827so23239939f.1 for ; Fri, 14 Jul 2023 10:06:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354398; x=1691946398; 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=Ort72HGqQMXrb2eYST6Ap4PTt8YGeoB4XPsXh2kt0RE=; b=gbuSNfToI9TpoYvBgbFaZS9ERKQT/eriJsE9rgxMlySfLOiVLcpYfd1MpgqXaDmuev N+BPV7E7Zpm9dxJX6jibLiazC6xYK3RmtABWVl858kg2DhhU3wR0unuXgtWg8Jmz20dh ziU/+/rx5p4t+/hWE46i/kdUBr8TMg3d5An8mWkn6f6LXL9AezsaJsm+iKLV2if13OUC EdDCde5MLQasNLU5MMQq01//ET43KNY7pbo+h5rGT4i9Hmsm3kyJfCyiEvnV3TUd0LkV xeHk9F/BIKFOnPfYsLYsBoCUg6GdFJDSu426VXLvmUcSn0SYqr7pGZ6X1QVbxLBHDkY9 1ycg== X-Gm-Message-State: ABy/qLbfqSWFfO3Xl4I2c0sCFcH1unfHwDvYVRTrcf2kzrrEjnwGtgZj o1zA/ebjcdEhp7F3bihTSisiaJHxAv4nGLJh9RqKxg== X-Google-Smtp-Source: APBJJlFRPqMI3A4tMtNMYYnsEPXsp5hukABYGVWd+4YF3k0Hb9wic5Ua0YFn0AjRP67nHLZayUhPtA== X-Received: by 2002:a6b:fd06:0:b0:786:2b08:709d with SMTP id c6-20020a6bfd06000000b007862b08709dmr6077038ioi.13.1689354398038; Fri, 14 Jul 2023 10:06:38 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:37 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:29 -0600 Subject: [PATCH v4 5/6] Introduce scoped_restore_current_inferior_for_memory MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-5-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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 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. Approved-By: Pedro Alves --- 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 Fri Jul 14 17:06: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: 72721 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 75DA2385701C for ; Fri, 14 Jul 2023 17:07:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75DA2385701C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689354459; bh=WWIbrthQlwaJVWDTaXKErKdde564Bl6uwIhxZT57/tI=; 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=ED2/HHoxAIBZy3F5ZGICypkAuDF5YoP+N4ThClzkcLuuu9D7SX2FRgvImQP3F7gmu UiIb1/thMhwha5vLRAwWQ+Ad0BXT4bHDMFrZGFSgCIcJjhVwf+zeDRXfJ7ezL1znXE RENP01CRYqW6tvKNTEMqCOmh9qudC/hvOy0321aY= 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 71C26385840C for ; Fri, 14 Jul 2023 17:06:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71C26385840C Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-78374596182so86924739f.0 for ; Fri, 14 Jul 2023 10:06:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689354398; x=1691946398; 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=WWIbrthQlwaJVWDTaXKErKdde564Bl6uwIhxZT57/tI=; b=dunQRbgOm3n2Udf0ZcZWnRD4EQAdlUBG2bEJNQNY37gTVsF8H0UR7iSdFGNOsjiJyb b0hFkUze7FPRYK8tA0qxzPsVnwUQs7/VEAQtAt0pclBwV48DZgcZk0cZa57jqo0sJDZK O3DYu9USALK7tZJdWu2tSujglBF1B4S12tD5NMAGDfeCKiNK/RPpsPcdmHGLTjApzVyY knPGg0wjzVyRlk3zk1VfCcQ6X4QB8CmN0hjlHFwtlxyatKGp+s1kF74Q5Ws57aeOYdKx S9Jkzx/qzC3dULFmHhgtWwTNrCYVbgM8k307qX7glEX9yqjmNOQpg0f6lsNueTstW0CT yJKA== X-Gm-Message-State: ABy/qLb6GI0ZN5aC3giYYpzdCqdAOhxyLzDF+CkdMcbyCo/jnY8RGOvt +rkJ0rzDad5YC/H4s+aYkVjOKKQshoxJlaYqutpgxw== X-Google-Smtp-Source: APBJJlFGlbzyVlbqh7shMziGE/e0i0uQOt3vZ6knDXuw1LG4B0rho/RAHQHZMvaJ53PBoYrf+Wlr2w== X-Received: by 2002:a05:6602:2114:b0:783:65ba:8614 with SMTP id x20-20020a056602211400b0078365ba8614mr5381213iox.10.1689354398605; Fri, 14 Jul 2023 10:06:38 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id cz8-20020a0566384a0800b0042bb09e9345sm2667476jab.90.2023.07.14.10.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 10:06:38 -0700 (PDT) Date: Fri, 14 Jul 2023 11:06:30 -0600 Subject: [PATCH v4 6/6] Use correct inferior in Inferior.read_memory et al MIME-Version: 1.0 Message-Id: <20230714-py-inf-fixes-30615-v4-6-9189744d8547@adacore.com> References: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@adacore.com> In-Reply-To: <20230714-py-inf-fixes-30615-v4-0-9189744d8547@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" 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 Reviewed-By: Tom Tromey --- gdb/python/py-inferior.c | 43 ++++++++++++++++++++++++++------ gdb/testsuite/gdb.python/py-inferior.exp | 27 ++++++++++++++++++++ 2 files changed, 63 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..13beebd08cc 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\])" "b'h'" 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,10 @@ 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" "Switching to 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 +137,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" "Switching to 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 *"