From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id E16E43858D3C; Thu, 5 May 2022 14:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E16E43858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 8e1ada9e0bd4f57597b835b2d09b100d24c604d8 X-Git-Newrev: d890c720b8c4daf8892a175296d8e88ec992c92d Message-Id: <20220505145434.E16E43858D3C@sourceware.org> Date: Thu, 5 May 2022 14:54:34 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 14:54:35 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd890c720b8c4= daf8892a175296d8e88ec992c92d commit d890c720b8c4daf8892a175296d8e88ec992c92d Author: Simon Marchi Date: Thu May 5 09:54:59 2022 -0400 gdb: make regcache's cooked_write_test selftest work with native-extend= ed-gdbserver board =20 Running =20 $ make check TESTS=3D"gdb.gdb/unittest.exp" RUNTESTFLAGS=3D"--targe= t_board=3Dnative-extended-gdbserver" =20 I get some failures: =20 Running selftest regcache::cooked_write_test::i386.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i386:intel.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i386:x64-32.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i386:x64-32:intel.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i386:x86-64.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i386:x86-64:intel.^M Self test failed: target already pushed^M Running selftest regcache::cooked_write_test::i8086.^M Self test failed: target already pushed^M =20 This is because the native-extended-gdbserver automatically connects GDB to a GDBserver on startup, and therefore pushes a remote target on the initial inferior. cooked_write_test is currently written in a way that errors out if the current inferior has a process_stratum_target pushed. =20 Rewrite it to use scoped_mock_context, so it doesn't depend on the current inferior (the current one upon entering the function). =20 Change-Id: I0357f989eacbdecc4bf88b043754451b476052ad Diff: --- gdb/regcache.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index a5e83da1ca4..037659ef8fa 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1944,30 +1944,9 @@ cooked_read_test (struct gdbarch *gdbarch) static void cooked_write_test (struct gdbarch *gdbarch) { - /* Error out if debugging something, because we're going to push the - test target, which would pop any existing target. */ - if (current_inferior ()->top_target ()->stratum () >=3D process_stratum) - error (_("target already pushed")); - /* Create a mock environment. A process_stratum target pushed. */ - - target_ops_no_register mock_target; - - /* Push the process_stratum target so we can mock accessing - registers. */ - current_inferior ()->push_target (&mock_target); - - /* Pop it again on exit (return/exception). */ - struct on_exit - { - ~on_exit () - { - pop_all_targets_at_and_above (process_stratum); - } - } pop_targets; - - readwrite_regcache readwrite (&mock_target, gdbarch); - + scoped_mock_context ctx (gdbarch); + readwrite_regcache readwrite (&ctx.mock_target, gdbarch); const int num_regs =3D gdbarch_num_cooked_regs (gdbarch); =20 for (auto regnum =3D 0; regnum < num_regs; regnum++)