From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4CtQEvNmoWVzszkAWB0awg (envelope-from ) for ; Fri, 12 Jan 2024 11:21:07 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JIJ9zNxv; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 47BB41E0C2; Fri, 12 Jan 2024 11:21:07 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 31E2B1E092 for ; Fri, 12 Jan 2024 11:21:05 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA1AB385842C for ; Fri, 12 Jan 2024 16:21:04 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C2F363858D1E for ; Fri, 12 Jan 2024 16:20:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2F363858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2F363858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705076439; cv=none; b=DQIz+3b+0x57ViEQdCnC+agWkJzyX9br/0gdGImp7PA2cSf6/cClhSykbO0FSQfLAbFyY5nE32aQAlnd+OHHfxuGPNrQNCX7WYSfhoZvoN7kBdyaexd4NZfBS06WLEbrAk+tQG9tWRYaG8kc4lAFyjsDkJSkTBtmd+dmVgPhD7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705076439; c=relaxed/simple; bh=OhdPfx2CgjP8P24NjPDQZRLWDAXoJVTSLOlOSAn5DnE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sS3bOllxuoWc1B0xpvtlABeuiOvg7jA8pnumtjRWgDWMBi9FaOOXDes2dm1C9E9FfzfS8ZORRpI3WwzRXnVL44znwhqPfJOTS+CEerL++VpNpqj+T3epD5GLsxMIsGrwGGsWi+CwVLgNxOKDj+siE/yZWKc/LDkl94cqSO8En5U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705076437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8HJ9havKE5V21JCs7w++ndsAdBKmW6Ij0ENKyPh/itY=; b=JIJ9zNxvRwufbIMyayLj69JR+sZwQWx4S1knKp3dq8Q9XA9/N84x13BY9OPPnxUNOY1WAM a5akPYs4TG+vTII1vrsXAbt6aOE8PZOgbyWTP3nC4gkv5QlxEjFW6msBqi82mOjYVk678g /QW3a6+pfiLfzoDiE8BSYua7FyKvFcU= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-PoAZErM5OHaBfc1HPFcWjQ-1; Fri, 12 Jan 2024 11:20:36 -0500 X-MC-Unique: PoAZErM5OHaBfc1HPFcWjQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2c2f913b25so94696866b.3 for ; Fri, 12 Jan 2024 08:20:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705076435; x=1705681235; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8HJ9havKE5V21JCs7w++ndsAdBKmW6Ij0ENKyPh/itY=; b=q0naIQLtfN44EXggPkf54LjNiy8sf04DLFKWFD1HapqTyrkoewmcm4GbhIhXCImxxV aCaYrq6KLmsDE9io7kFC7hGuz3AiK+kUNLvewE9QDxRQlvCtwCPk7xCiTcntncSK1Fgh UHjIAD6VwQTSBcJDJC4NaZQmQNJcCfUwQPArT1tB+zBx5s5x0WJZX5247KVvRw0HQ4my /SH+3KA41fgigT95oBVk0ynOnFd5kV7VX39Y86n/0SnDVTmO2DlfRdiu65fGsnzCmcC9 EV7L9Ijm3ZKVOQvD2r3zfY+pWyMfbulphrHcRKH165dQ39XH7nP6mBex8iK897uVwLqT AB/g== X-Gm-Message-State: AOJu0Yx9caosi6LctwAqW0r3+kYEHpvyuzwF89CotgF2YQcnWncsE2Y6 KRr1OCTzmKIVV3R2QYZXYBgc2gqp6GIFEcFZFPV0b6Q7sEqnMBFOgcqH5NKwt5SEsq2gXt/55wE rnX/RcA0bJGpxqqflQ2q5LZRU8bkncA== X-Received: by 2002:a17:907:9047:b0:a28:dfcf:3b72 with SMTP id az7-20020a170907904700b00a28dfcf3b72mr643735ejc.13.1705076435014; Fri, 12 Jan 2024 08:20:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6e4MYkA19wXmkgutZ4K+iPnSJyZAYChH427BWAQNzY9g3tYnGQyVjuX8yjDpg0EVIq9Up4g== X-Received: by 2002:a17:907:9047:b0:a28:dfcf:3b72 with SMTP id az7-20020a170907904700b00a28dfcf3b72mr643725ejc.13.1705076434700; Fri, 12 Jan 2024 08:20:34 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id z19-20020a170906271300b00a2ae0aa9002sm1944957ejc.40.2024.01.12.08.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:20:34 -0800 (PST) From: Andrew Burgess To: Tom de Vries , Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCHv2 0/8] Python __repr__() methods and new __dict__ attributes In-Reply-To: References: <87mstdrrgw.fsf@tromey.com> <87msta7jk7.fsf@redhat.com> Date: Fri, 12 Jan 2024 16:20:33 +0000 Message-ID: <87h6ji7cby.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Tom de Vries writes: > On 1/12/24 14:44, Andrew Burgess wrote: >> Tom Tromey writes: >> >>>>>>>> "Andrew" == Andrew Burgess writes: >>> >>> Andrew> In V2: >>> Andrew> - Fixed problems in thpy_dealloc that Tom pointed out, >>> >>> Andrew> - Used @group...@end group in the docs as suggested by Eli, >>> >>> Andrew> - Added patches #7 and #8, which are both docs only patches. The >>> Andrew> first adds advice for naming attributes as Tom suggested, the >>> Andrew> second is just some doc updates that I noticed in passing. >>> >>> Thanks, this looks good & addresses my comments. >>> Approved-By: Tom Tromey >> >> Pushed. >> > > Hi Andrew, > > I'm seeing this new FAIL: > ... > FAIL: gdb.python/py-inferior.exp: test repr of an invalid thread > ... > > Filed as https://sourceware.org/bugzilla/show_bug.cgi?id=31238 . I pushed this patch which I this should address this issue. Let me know if you are still seeing failures. Thanks, Andrew --- commit 98138c62cd7f721af132f9b24f274332fd8bf079 Author: Andrew Burgess Date: Fri Jan 12 16:08:14 2024 +0000 gdb/testsuite: fix failure in gdb.python/py-inferior.exp After this commit: commit 1925bba80edd37c2ef90ef1d2c599dfc2fc17f72 Date: Thu Jan 4 10:01:24 2024 +0000 gdb/python: add gdb.InferiorThread.__repr__() method failures were reported for gdb.python/py-inferior.exp. The test grabs a gdb.InferiorThread object representing an inferior thread, and then, later in the test, expects this Python object to become invalid when the inferior thread has exited. The gdb.InferiorThread object was obtained from the list returned by calling gdb.Inferior.threads(). The mistake I made in the original commit was to assume that the order of the threads returned from gdb.Inferior.threads() somehow reflected the thread creation order. Specifically, I was expecting the main thread to be first in the list, and "other" threads to appear ... not first. However, the gdb.Inferior.threads() function creates a list and populates it from a map. The order of the threads in the returned list has no obvious relationship to the thread creation order, and can vary from host to host. On my machine the ordering was as I expected, so the test passed for me. For others the ordering was not as expected, and it just happened that we ended up recording the gdb.InferiorThread for the main thread. As the main thread doesn't exit (until the test is over), the gdb.InferiorThread object never became invalid, and the test failed. Fixed in this commit by taking more care to correctly find a non-main thread. I do this by recording the main thread early on (when there is only one inferior thread), and then finding any thread that is not this main thread. Then, once all of the secondary threads have exited, I know that the second InferiorThread object I found should now be invalid. The test still passes for me, and I believe this should fix the issue for everyone else too. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31238 diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 04231dd893d..2968e027812 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -94,27 +94,33 @@ gdb_test "python print(i0._user_attr)" \ gdb_test "python print(gdb.inferiors()\[0\]._user_attr)" \ "123" "read back user defined attribute from gdb.inferiors" +# Record the main thread, and check its __repr__ while we're at it. +gdb_test_no_output "python main_thread = gdb.inferiors()\[0\].threads()\[0\]" +gdb_test "python print(main_thread)" \ + "" \ + # Test the number of inferior threads. gdb_breakpoint check_threads gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*" gdb_test "python print (len (i0.threads ()))" "\r\n9" "test Inferior.threads 2" -# Grab the last thread from the list. This thread object will become -# invalid when the corresponding thread exits. -gdb_test_no_output "python last_thread = i0.threads()\[-1\]" -gdb_test "python print(last_thread)" \ +# Grab a worker thread from the thread list. A worker thread is the +# first thread that is not the main thread. The worker thread object +# will become invalid when the corresponding thread exits. +gdb_test_no_output "python worker_thread = next(filter(lambda thr : thr != main_thread, i0.threads()))" +gdb_test "python print(worker_thread)" \ "" \ "test repr of a valid thread" -# Add a user defined attribute to this thread, check the attribute can -# be read back, and check the attribute is not present on other -# threads. -gdb_test_no_output "python last_thread._user_attribute = 123" \ +# Add a user defined attribute to the worker thread, check the +# attribute can be read back, and check the attribute is not present +# on the main thread. +gdb_test_no_output "python worker_thread._user_attribute = 123" \ "add user defined attribute to InferiorThread object" -gdb_test "python print(last_thread._user_attribute)" "123" \ +gdb_test "python print(worker_thread._user_attribute)" "123" \ "read back user defined attribute" -gdb_test "python print(i0.threads ()\[0\]._user_attribute)" \ +gdb_test "python print(main_thread._user_attribute)" \ [multi_line \ "AttributeError: 'gdb\\.InferiorThread' object has no attribute '_user_attribute'" \ "Error while executing Python code\\."] \ @@ -126,12 +132,11 @@ gdb_breakpoint [gdb_get_line_number "Break here."] gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*" # Check the repr() for an invalid gdb.InferiorThread object. -gdb_test "python print(last_thread)" \ - "" \ +gdb_test "python print(worker_thread)" "" \ "test repr of an invalid thread" # Check the user defined attribute is still present on the invalid thread object. -gdb_test "python print(last_thread._user_attribute)" "123" \ +gdb_test "python print(worker_thread._user_attribute)" "123" \ "check user defined attribute on an invalid InferiorThread object" # Test memory read and write operations.