From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 4BDA7385BF83 for ; Tue, 14 Apr 2020 17:54:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4BDA7385BF83 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-487-Ix-I8EjGNXuW6sMPA-ohYA-1; Tue, 14 Apr 2020 13:54:39 -0400 X-MC-Unique: Ix-I8EjGNXuW6sMPA-ohYA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6E0C8017F6 for ; Tue, 14 Apr 2020 17:54:38 +0000 (UTC) Received: from cascais.Home (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54BC99F99D for ; Tue, 14 Apr 2020 17:54:38 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 04/28] Don't write to inferior_ptid in gdbarch-selftests.c, mock address_space too Date: Tue, 14 Apr 2020 18:54:10 +0100 Message-Id: <20200414175434.8047-5-palves@redhat.com> In-Reply-To: <20200414175434.8047-1-palves@redhat.com> References: <20200414175434.8047-1-palves@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-27.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 14 Apr 2020 17:54:42 -0000 Use switch_to_thread instead of writing to inferior_ptid. This requires a couple of improvements to the mocking environment. One is to mock a pspace too, and assigning it to the inferior. In turn, this requires heap-allocating the address space, so that the regular program_space dtor destroys the address space correctly. (Note that new the mock program_space is allocated on the stack, and thus depends on the previous patch that eliminated delete_program_space.) gdb/ChangeLog: yyyy-mm-dd Pedro Alves =09* gdbarch-selftests.c: Include "progspace-and-thread.h". =09(register_to_value_test): Mock a program_space too. Heap-allocate =09the address space. Don't write to inferior_ptid. Use =09switch_to_thread instead. --- gdb/gdbarch-selftests.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c index 787a3f4058..9ab5e9fbe4 100644 --- a/gdb/gdbarch-selftests.c +++ b/gdb/gdbarch-selftests.c @@ -27,6 +27,7 @@ #include "target-float.h" #include "gdbsupport/def-vector.h" #include "gdbarch.h" +#include "progspace-and-thread.h" =20 namespace selftests { =20 @@ -75,24 +76,25 @@ register_to_value_test (struct gdbarch *gdbarch) =20 test_target_ops mock_target; ptid_t mock_ptid (1, 1); + program_space mock_pspace (new_address_space ()); inferior mock_inferior (mock_ptid.pid ()); - address_space mock_aspace {}; mock_inferior.gdbarch =3D gdbarch; - mock_inferior.aspace =3D &mock_aspace; + mock_inferior.aspace =3D mock_pspace.aspace; + mock_inferior.pspace =3D &mock_pspace; thread_info mock_thread (&mock_inferior, mock_ptid); =20 + scoped_restore_current_pspace_and_thread restore_pspace_thread; + scoped_restore restore_thread_list =3D make_scoped_restore (&mock_inferior.thread_list, &mock_thread); =20 /* Add the mock inferior to the inferior list so that look ups by target+ptid can find it. */ scoped_restore restore_inferior_list - =3D make_scoped_restore (&inferior_list); - inferior_list =3D &mock_inferior; + =3D make_scoped_restore (&inferior_list, &mock_inferior); =20 /* Switch to the mock inferior. */ - scoped_restore_current_inferior restore_current_inferior; - set_current_inferior (&mock_inferior); + switch_to_inferior_no_thread (&mock_inferior); =20 /* Push the process_stratum target so we can mock accessing registers. */ @@ -102,8 +104,7 @@ register_to_value_test (struct gdbarch *gdbarch) SCOPE_EXIT { pop_all_targets_at_and_above (process_stratum); }; =20 /* Switch to the mock thread. */ - scoped_restore restore_inferior_ptid - =3D make_scoped_restore (&inferior_ptid, mock_ptid); + switch_to_thread (&mock_thread); =20 struct frame_info *frame =3D get_current_frame (); const int num_regs =3D gdbarch_num_cooked_regs (gdbarch); --=20 2.14.5