From patchwork Fri Jul 7 15:07: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: 72302 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 C3A213850ADB for ; Fri, 7 Jul 2023 15:08:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3A213850ADB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688742507; bh=fNCaO4oOFL4eltZRxkQ/1LOU2GCqnnrgUoB3rrhvBNo=; 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=VCeAR0uQTske7ErwEV8ek506U6aaTuZ1StzYbfMHntH7RXMQICtPuQi1n4lRaB7sb gJEK1qTlixx/lQbVAsFVtHyDPmALf8/I4gT2rICHSc68BkgMwEa3avT69c64quwNP6 XEXjlu+IfWnEI7JYk7tiEujtsACSzVhof5gSHjEY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id 09E463852AC8 for ; Fri, 7 Jul 2023 15:08:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09E463852AC8 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-78666994bc2so72052239f.0 for ; Fri, 07 Jul 2023 08:08:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688742480; x=1691334480; 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=fNCaO4oOFL4eltZRxkQ/1LOU2GCqnnrgUoB3rrhvBNo=; b=SoR997fzBD1LTyeRx8HWxSly9sp6ak7ZfMZDX95pnB/8Gi9F7XYuEKaHyGsv/6P70L fbCm8ae207/e80CdZXIX31OR26fKLztbnqL2Fo+ByuVK8+zVNadPLyxV27h3wrnMhBBb arXQ73aCb99IHNolU2mGoa6SqmCHDls6Gotc7cUW52CHuzIImpahA5UawThhsjAXAIUp InuGiYfcCF6/ZmdJZbupk07WtJUZsO7EmeLEuP0jmkPAuTuHwB5XTHmBxgcG0/La8doE Fu8MMWM3VCJ6Pqj+yQfb2DresTfOop2FCOrPDd5yTR8wdhG7ou+glgxnJNHWzhRetnl/ KInA== X-Gm-Message-State: ABy/qLZDEEWuUz42KDxK6cJaRBBfMxluJIFHQlzlMYWTauhnfG9qAhro 1KcKecTTirBTbnAbToG53vPtw6635hQKbIn12c/Zkw== X-Google-Smtp-Source: APBJJlForKNpmLPrYSc+KeHDNih+WeeoMXKqw+dSnSXdS9ailJuveyDcAoRZRaXBbwaFM+KM4u2r9w== X-Received: by 2002:a6b:dc16:0:b0:783:74a5:b73f with SMTP id s22-20020a6bdc16000000b0078374a5b73fmr5376747ioc.13.1688742480120; Fri, 07 Jul 2023 08:08:00 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id b16-20020a5ea710000000b0076ffebfc9fasm1340650iod.47.2023.07.07.08.07.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:07:59 -0700 (PDT) Date: Fri, 07 Jul 2023 09:07:57 -0600 Subject: [PATCH 1/5] Minor cleanups in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230707-py-inf-fixes-30615-v1-1-7792ab559530@adacore.com> References: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> In-Reply-To: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" While working on this series, I noticed a couple of oddities in py-inferior.exp. One is an obviously incorrect comment, and the other is a confusing test name. This patch fixes these. --- gdb/testsuite/gdb.python/py-inferior.exp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 58deece5d5f..33bc27ee86d 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" "remove-inferiors 2" gdb_test "python print (inf_list\[0\].is_valid())" "True" \ "check inferior validity 4" From patchwork Fri Jul 7 15:07: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: 72305 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 8554C3852AC9 for ; Fri, 7 Jul 2023 15:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8554C3852AC9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688742579; bh=L0Ixpm5298FSIhplgGAcUNt+JfQ4Ju42kCyZ4tI0yPQ=; 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=tP9dc9beN0/U+1sMuc0Ndwddwhi5NqxIMe6ox8m+XVMulEgTAXA7ofdhWFgIQyf98 iwAQX4hDVAMMG0v1wZR6Sras2ilDL+wzM+SyMH7niPbdmh9ZSb9RDUg1oLYieGTJoN y9gcQDMWmIaxSx3ERaVrUeufWP9C8bNwM8Z7xtZE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 2220C3852AD0 for ; Fri, 7 Jul 2023 15:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2220C3852AD0 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7835e5fa459so71359439f.2 for ; Fri, 07 Jul 2023 08:08:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688742481; x=1691334481; 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=L0Ixpm5298FSIhplgGAcUNt+JfQ4Ju42kCyZ4tI0yPQ=; b=SZrP2auNxOA6srw5yuahHERRNGQYANQFCuMP8O65R4xpSe4RsVqSV14oH2IxWR36cq Yd7TVY47FRxmVw7eYE6lpupDfRLnToara6JdOnmq1tQ/K6qQJRtXrV7ftnYE3Akn5gNu Y7vnUIYW46Ztqw6YHCf0sQa2fnA3TP85xaQpHJwnVMzIHe6NKWgLle0LLpPnoaWqVLpr 1lHiWo2swL5ILQu1UQM+184DPvbyOzbM6oTVY3tSmRNGCK7pSko4W53N7NVTK/dIMMvQ b+ID7zRZvVm5rebXuDEY1+ulX102rqqlT2JAUB4azl1VO5t4Flx8LaD2Y0CkG5pzPTaf /1Tg== X-Gm-Message-State: ABy/qLaZt4jBJr742wSuysm0Yg4BXlbyoHKN5+Xrlk4AYpVd9FtLQh0x t8UFUjpv5fET8yq/brs0ze5Vqk6zqPSQAeXJPsRS+Q== X-Google-Smtp-Source: APBJJlFoyXhRP7DmNpO+OhtWEQGalRgm8YJfOuKZCu0i6DYAQBqfutmYzSnvzPKdervGfcfbnqc/4w== X-Received: by 2002:a05:6602:274e:b0:785:caec:17c7 with SMTP id b14-20020a056602274e00b00785caec17c7mr5951614ioe.9.1688742480747; Fri, 07 Jul 2023 08:08:00 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id b16-20020a5ea710000000b0076ffebfc9fasm1340650iod.47.2023.07.07.08.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:08:00 -0700 (PDT) Date: Fri, 07 Jul 2023 09:07:58 -0600 Subject: [PATCH 2/5] Refactor py-inferior.exp MIME-Version: 1.0 Message-Id: <20230707-py-inf-fixes-30615-v1-2-7792ab559530@adacore.com> References: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> In-Reply-To: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.3 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. --- 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 33bc27ee86d..a29624f4fd5 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" "remove-inferiors 2" + gdb_test_no_output "remove-inferiors $num" "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" "remove second inferior" + gdb_test_no_output "remove-inferiors $num" "remove inferior $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 7 15:07: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: 72303 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 078C6385267E for ; Fri, 7 Jul 2023 15:08:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 078C6385267E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688742511; bh=xjrw29j/gj/5i56bbsGTxFOpw1trHuYsiKk/E8lP2f0=; 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=Hicex4u96BLp2eJdLv5J9wu0SclTPn5/Cn4xTuahczEBmEasQnoKBU90BGjYyFrN3 NLh7YXYC0r5q31PIh1tbg6BlBL++F+iXomeIAuBOjyHNHejPOjO8OPmO4FnMD9aA9A B5KjJ8LR680zD143GWQ2uorqTld1otNLRKWYwl0k= 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 3E046385480C for ; Fri, 7 Jul 2023 15:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E046385480C Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-78360b822abso71096939f.2 for ; Fri, 07 Jul 2023 08:08:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688742481; x=1691334481; 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=xjrw29j/gj/5i56bbsGTxFOpw1trHuYsiKk/E8lP2f0=; b=YOxCiTPlDUVZYgHl/yINth2FIKKOVpMmrHpK4/wF5C5W+FqueWeSvAwR74pMAMyKuX bdlUyOLFYcJmVlIAkABoAC3MikF8PidQldFJDK+w4m7HXjMwyh5236V1u3BH/wo4cVAU PMozitQXJAY1danqQzqLUP+4v2+aU1Wkr4+I89R7znrm6u+kHRYFxw/L9fdf8FlWiJ+8 CZegLpKU48cS8BxFX+2+5gYsQHVzB8JTa+HRBq3evp3IqRcVT1v6sNC2FAQd+O8bAr2q eKLepSq/4Pti1HIg6j3HlJH4893JD1ZCm4xdWnIQhT46J8qbMrd0A8rSQdDPrJnyFBkR +yug== X-Gm-Message-State: ABy/qLZFPfCD2m5lAN4W3wfZD7KPvx2sziGT9x/C01/rMJ95PSbg3ycj P+AkVW32/HSJyOV367ovmwCEQ8s8trNI+t7194EXTQ== X-Google-Smtp-Source: APBJJlGC4k67+bn7OeotMDxUHkCxgaFBi7GjGVydgwkRRuA6U3ly3Tb3IB2Prnh+498Rt6M0EcmRZw== X-Received: by 2002:a6b:7e4c:0:b0:783:5452:e343 with SMTP id k12-20020a6b7e4c000000b007835452e343mr5236323ioq.14.1688742481399; Fri, 07 Jul 2023 08:08:01 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id b16-20020a5ea710000000b0076ffebfc9fasm1340650iod.47.2023.07.07.08.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:08:01 -0700 (PDT) Date: Fri, 07 Jul 2023 09:07:59 -0600 Subject: [PATCH 3/5] Rename Python variable in py-inferior.exp MIME-Version: 1.0 Message-Id: <20230707-py-inf-fixes-30615-v1-3-7792ab559530@adacore.com> References: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> In-Reply-To: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index a29624f4fd5..41e26878031 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -88,13 +88,13 @@ 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)" \ +gdb_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ "read str contents" 1 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 7 15:08: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: 72304 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 239BC3850AC3 for ; Fri, 7 Jul 2023 15:08:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 239BC3850AC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688742539; bh=xM5R3/S7J7eiJV1O5A4yKULsjLthxZLJplWEI9M+8K4=; 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=Qpuz/FwGZzX6Rr2reLIBFiFo5Yaq/79mKA2crNiNTv53O+VguFqp0EihvBP/wN7WV pbWiGt2wzvNzhLyXPuGdthQPIhccuQ+gPz4NlGtHNlFOmt8uBPIYPaGfPvWiO4L7a6 W5iol4sa9PBpq02yfpSocdMd9XzqJrJgu8u4O6Ik= 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 949D93852AE0 for ; Fri, 7 Jul 2023 15:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 949D93852AE0 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-786bb09e595so66238939f.1 for ; Fri, 07 Jul 2023 08:08:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688742482; x=1691334482; 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=xM5R3/S7J7eiJV1O5A4yKULsjLthxZLJplWEI9M+8K4=; b=RBHShbvlQekYPgKuYY8jzA5mdKi9/g4WzOSxGbORx7klDISXze8HS1zUnSFHQl1Iga 5kUgtR9co3kL8dryCSs2kQb68K65HFRunFfk9gdlQlZhh4EjyH5jlBBy1CS4QxuZxzMo 8pHDBTh5UxCT8mbarbwqtt81cNccAMXTqx7hQ8r8fkrpqWzGaIKhQ5/ua4vFkhAazqk4 fExTlmtCEB2gOLeyzIZDgyLj4IUzalD6dPWjAiPzoheIHskiyVGaXqvsuKT+ajZRDFJg aUtUcyBzNcpKQpwoO58i6M6C/tpnmmtpWaJbWV48qss5OpQOaCC9b7jCwMXBPGj4E46B EWTw== X-Gm-Message-State: ABy/qLY2tRcbThNGg7B0edRwqbQWebV+GZg/jcqQ1A72yaIoZE0YgnSG ebrnK/DkoMz2nVCu+bmrHuJYR4zySfianP3C+swwAw== X-Google-Smtp-Source: APBJJlFKznmrD/YxW6Zd5yjXuH7VvqiRGnQ+b8Ld4z075r/Mawjtf0Yjn/srRdU3ZW2XfemKTO9o5Q== X-Received: by 2002:a05:6602:2c89:b0:783:6aa0:9816 with SMTP id i9-20020a0566022c8900b007836aa09816mr7023964iow.7.1688742481919; Fri, 07 Jul 2023 08:08:01 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id b16-20020a5ea710000000b0076ffebfc9fasm1340650iod.47.2023.07.07.08.08.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:08:01 -0700 (PDT) Date: Fri, 07 Jul 2023 09:08:00 -0600 Subject: [PATCH 4/5] Remove obsolete comment from gdbthread.h MIME-Version: 1.0 Message-Id: <20230707-py-inf-fixes-30615-v1-4-7792ab559530@adacore.com> References: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> In-Reply-To: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.3 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. --- 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 7 15:08: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: 72306 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 8FEFC3852ACD for ; Fri, 7 Jul 2023 15:10:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FEFC3852ACD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688742607; bh=H88h79Zx6GmlQ69v7nB1EeebnIjl+StdqbV4GA/8lgQ=; 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=Jx5JRUGWYlZwbDwePkeuuCUJFXX5kZMxzcT7DJEgYthnSAykmp8fOCcmVln0S1g9K oxRyJnyi7W8zoJXWfVukujR3fIiEi2nukgpfQvitq1R+vgZ4dIUKW3O4oETP8Z/wKu SGFamxV03GtjLFdJLmsG1G/yYcm4J2IFETZMtmWE= 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 7C79C3852ACC for ; Fri, 7 Jul 2023 15:08:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C79C3852ACC Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-7866189cff1so70517339f.0 for ; Fri, 07 Jul 2023 08:08:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688742482; x=1691334482; 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=H88h79Zx6GmlQ69v7nB1EeebnIjl+StdqbV4GA/8lgQ=; b=ItMsTHy51OdFjMdK+BWhzQU868NDS+fejoWFyjJzFAt07GQnCcBQvxLJtzbdbPeJ68 SrgL82AlIf/ZWY+iaHJEjHXTJBZfU/knmDr1pYGxY/9hqImiSqTuLU4cc3dTWEzNXhlc PHJivu59MkJf/tcF0dpTuGBj01xWwDHjuhGxk2Bug6Kc9iZFefryhH9MzryY9EiLzkfo eAcFHoPciTJKTyjsyLc2Nph1M129uCyWvpKZ2lU/f6MUzsRZSVBwTb4Tcqr1DRmHtYaK GIXSfCEEVV/wTkOlod6VN05fR69bII9/NN+iR8P9FCYOsBdTCcNu+GPmXYCEsJOXalqF bjng== X-Gm-Message-State: ABy/qLbEuP+YoVE/fnAaDKNvv/QqgmmROeO2Hvy56+NPatgND4svK9C+ YUQdbam8zycobmzKwuaeunbxuOY4NF/7Vr+1aiksjA== X-Google-Smtp-Source: APBJJlFU1ILX4xOjauf3rhDNYRtT1mTdWERzUgrK/VLmEtTvFueWweXdkbHNSAtqK3yCXWjWVxOIgg== X-Received: by 2002:a5e:8914:0:b0:786:7100:72de with SMTP id k20-20020a5e8914000000b00786710072demr5390863ioj.16.1688742482481; Fri, 07 Jul 2023 08:08:02 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id b16-20020a5ea710000000b0076ffebfc9fasm1340650iod.47.2023.07.07.08.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:08:02 -0700 (PDT) Date: Fri, 07 Jul 2023 09:08:01 -0600 Subject: [PATCH 5/5] Use correct inferior in Inferior.read_memory et al MIME-Version: 1.0 Message-Id: <20230707-py-inf-fixes-30615-v1-5-7792ab559530@adacore.com> References: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> In-Reply-To: <20230707-py-inf-fixes-30615-v1-0-7792ab559530@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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" 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 found out that setting current_inferior isn't enough when reading memory -- one must also set inferior_ptid. This seems very confusing to me, especially considering that current_inferior must be set properly anyway in order to access the target stack. Finally, 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 | 36 ++++++++++++++++++++++++++++---- gdb/testsuite/gdb.python/py-inferior.exp | 25 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index af8bd8855a3..7fb422f621e 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,12 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) try { + scoped_restore_current_inferior restore_inferior; + scoped_restore_current_pspace_and_thread restore_thread; + + thread_info *thr = any_thread_of_inferior (inf->inferior); + switch_to_thread_no_regs (thr); + buffer.reset ((gdb_byte *) xmalloc (length)); read_memory (addr, buffer.get (), length); @@ -565,6 +575,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 +584,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 +604,12 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) try { + scoped_restore_current_inferior restore_inferior; + scoped_restore_current_pspace_and_thread restore_thread; + + thread_info *thr = any_thread_of_inferior (inf->inferior); + switch_to_thread_no_regs (thr); + 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,12 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) try { + scoped_restore_current_inferior restore_inferior; + scoped_restore_current_pspace_and_thread restore_thread; + + thread_info *thr = any_thread_of_inferior (inf->inferior); + switch_to_thread_no_regs (thr); + found = target_search_memory (start_addr, length, buffer, pattern_size, &found_addr); @@ -912,10 +940,10 @@ infpy_get_main_name (PyObject *self, void *closure) /* 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_pspace_and_thread restore_thread; - scoped_restore_current_program_space restore_current_progspace; - set_current_program_space (inf->inferior->pspace); + thread_info *thr = any_thread_of_inferior (inf->inferior); + switch_to_thread_no_regs (thr); name = main_name (); } diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 41e26878031..9b0643d63e2 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -90,6 +90,7 @@ gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ "read str address" 0 gdb_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ "read str contents" 1 +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)" \ @@ -97,6 +98,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]*} @@ -114,6 +119,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" @@ -127,6 +135,23 @@ 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_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ + "read str while other inferior selected" 1 +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 *"