Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board
@ 2022-05-05 14:09 Simon Marchi via Gdb-patches
  2022-05-05 14:38 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi via Gdb-patches @ 2022-05-05 14:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Running

    $ make check TESTS="gdb.gdb/unittest.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"

I get some failures:

    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

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.

Rewrite it to use scoped_mock_context, so it doesn't depend on the
current inferior (the current one upon entering the function).

Change-Id: I0357f989eacbdecc4bf88b043754451b476052ad
---
 gdb/regcache.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index a5e83da1ca41..037659ef8fae 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 () >= 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<target_ops_no_register> ctx (gdbarch);
+  readwrite_regcache readwrite (&ctx.mock_target, gdbarch);
   const int num_regs = gdbarch_num_cooked_regs (gdbarch);
 
   for (auto regnum = 0; regnum < num_regs; regnum++)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board
  2022-05-05 14:09 [PATCH] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board Simon Marchi via Gdb-patches
@ 2022-05-05 14:38 ` Pedro Alves
  2022-05-05 14:54   ` Simon Marchi via Gdb-patches
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2022-05-05 14:38 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2022-05-05 15:09, Simon Marchi via Gdb-patches wrote:
> Running
> 
>     $ make check TESTS="gdb.gdb/unittest.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"
> 
> I get some failures:
> 
>     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
> 
> 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.
> 
> Rewrite it to use scoped_mock_context, so it doesn't depend on the
> current inferior (the current one upon entering the function).
> 
> Change-Id: I0357f989eacbdecc4bf88b043754451b476052ad

OK.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board
  2022-05-05 14:38 ` Pedro Alves
@ 2022-05-05 14:54   ` Simon Marchi via Gdb-patches
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi via Gdb-patches @ 2022-05-05 14:54 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 2022-05-05 10:38, Pedro Alves wrote:
> On 2022-05-05 15:09, Simon Marchi via Gdb-patches wrote:
>> Running
>>
>>     $ make check TESTS="gdb.gdb/unittest.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"
>>
>> I get some failures:
>>
>>     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
>>
>> 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.
>>
>> Rewrite it to use scoped_mock_context, so it doesn't depend on the
>> current inferior (the current one upon entering the function).
>>
>> Change-Id: I0357f989eacbdecc4bf88b043754451b476052ad
> 
> OK.

Pushed, thanks.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-05 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 14:09 [PATCH] gdb: make regcache's cooked_write_test selftest work with native-extended-gdbserver board Simon Marchi via Gdb-patches
2022-05-05 14:38 ` Pedro Alves
2022-05-05 14:54   ` Simon Marchi via Gdb-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox