public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>,
	tom@tromey.com, luis.machado@arm.com, simark@simark.ca
Subject: Re: [PATCH] gdb: fix command lookup in execute_command () commands"
Date: Wed, 14 Dec 2022 11:07:47 +0000	[thread overview]
Message-ID: <20221214110747.1150349-1-jan.vrany@labware.com> (raw)
In-Reply-To: <4dc13e01-2fd8-a63e-24f2-a1f7c7650d3b@simark.ca>

On Tue, 2022-12-13 at 14:29 -0500, Simon Marchi wrote:
> On 12/13/22 13:48, Jan Vraný wrote:
> > On Tue, 2022-12-13 at 08:05 -0700, Tom Tromey wrote:
> > > > > > > > "Jan" == Jan Vrany via Gdb-patches <gdb-patches@sourceware.org> writes:
> > > 
> > > Jan> The below patch should fix this case - with it on my system
> > > Jan> gdb.base/define.exp passes.
> > > 
> > > Jan> Alternatively I may just revert the commit until better solution
> > > Jan> is found.
> > > 
> > > This patch looks ok to me, but could you say whether you ran all the
> > > tests or just define.exp?  Given the history I think a full regression
> > > test is warranted.
> > 
> > I did use try-build which succeeded (build #28) but it seems to me it
> > runs only very limited number of tests. 
> > 
> > I did run all of gdb.base and did not spot any new regression compared
> > to master with my (previous, broken) patch reverted. I did not run more
> > than gdb.base mainly because just gdb.base takes about an hour on my machine.
> > Also I get weird intermittent failures when running testsuite. 
> > 
> > Jan
> 
> Here are the unexpected failures I saw:
> 
> UNRESOLVED: gdb.base/bp-cmds-execution-x-script.exp: run to end
> UNRESOLVED: gdb.base/bp-cmds-run-with-ex.exp: execute bp commands
> UNRESOLVED: gdb.base/bp-cmds-sourced-script.exp: source the script
> UNRESOLVED: gdb.base/bp-cmds-sourced-script.exp: continue until exit
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_test: source file containing xxx_yyy command and its alias
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_test: deprecated alias with prefix give a warning
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: define real_command: input 1: define real_command
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: alias alias_command = real_command
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: alias alias_with_args_command = real_command 123
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: help real_command, before
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: maintenance deprecate alias_command
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: maintenance deprecate alias_with_args_command
> UNRESOLVED: gdb.base/commands.exp: deprecated_command_alias_help_test: help real_command, after
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: delete all breakpoints in delete_breakpoints
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: break factorial
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: begin commands
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: add silent command
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: add clear command
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: add printf command
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: add cont command
> UNRESOLVED: gdb.base/commands.exp: bp_deleted_in_command_test: end commands
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: delete all breakpoints in delete_breakpoints
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: breakpoint
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: begin commands in bp_deleted_in_command_test
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: add silent tbreak command
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: add printf tbreak command
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: add cont tbreak command
> UNRESOLVED: gdb.base/commands.exp: temporary_breakpoint_commands: end tbreak commands
> UNRESOLVED: gdb.base/commands.exp: stray_arg0_test: #1
> UNRESOLVED: gdb.base/commands.exp: stray_arg0_test: #2
> UNRESOLVED: gdb.base/commands.exp: stray_arg0_test: #3
> UNRESOLVED: gdb.base/commands.exp: stray_arg0_test: #4
> UNRESOLVED: gdb.base/commands.exp: source_file_with_indented_comment: source file
> UNRESOLVED: gdb.base/commands.exp: recursive_source_test: source file
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: set $tem
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: if $tem == 2 - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: break -q main - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: else - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: break factorial - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: commands - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: silent - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: set $tem = 3 - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: continue - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: first end - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: second end - if_commands_test 1
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: if $tem == 1 - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: break -q main - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: else - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: break factorial - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: commands - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: silent - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: set $tem = 3 - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: continue - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: first end - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: if_commands_test: second end - if_commands_test 2
> UNRESOLVED: gdb.base/commands.exp: error_clears_commands_left: hook-stop 1
> UNRESOLVED: gdb.base/commands.exp: error_clears_commands_left: hook-stop 1a
> UNRESOLVED: gdb.base/commands.exp: error_clears_commands_left: hook-stop 1b
> UNRESOLVED: gdb.base/commands.exp: error_clears_commands_left: delete all breakpoints in delete_breakpoints
> UNRESOLVED: gdb.base/dprintf-execution-x-script.exp: load and run script with -x
> UNRESOLVED: gdb.base/dprintf-execution-x-script.exp: load and run script using source command
> UNRESOLVED: gdb.base/dprintf-execution-x-script.exp: run again
> UNRESOLVED: gdb.base/save-bp.exp: source bps
> UNRESOLVED: gdb.base/save-bp.exp: info break (pattern 1) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: source -v (pattern 4) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: set trace-commands
> UNRESOLVED: gdb.base/trace-commands.exp: show trace-commands says on
> UNRESOLVED: gdb.base/trace-commands.exp: simple trace-commands test
> UNRESOLVED: gdb.base/trace-commands.exp: nested trace-commands test (pattern 1) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: define user command (pattern 1) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: nested trace-commands test with source (pattern 1) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: depth resets on error part 1 (pattern 1) (timeout)
> UNRESOLVED: gdb.base/trace-commands.exp: depth resets on error part 2
> UNRESOLVED: gdb.trace/save-trace.exp: relative: read back saved tracepoints
> UNRESOLVED: gdb.trace/save-trace.exp: relative: verify recovered tracepoints
> DUPLICATE: gdb.trace/save-trace.exp: relative: verify recovered tracepoints
> UNRESOLVED: gdb.trace/save-trace.exp: relative: verify default-collect
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: save tracepoint definitions
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: clear default-collect
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: delete tracepoints
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: read back saved tracepoints
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: verify recovered tracepoints
> DUPLICATE: gdb.trace/save-trace.exp: absolute: verify recovered tracepoints
> UNRESOLVED: gdb.trace/save-trace.exp: absolute: verify default-collect
> UNRESOLVED: gdb.trace/save-trace.exp: verify help save tracepoints
>

Hmm. I do not see these failures. When I run tests with second patch applied
atop of dc3fb44540 ("gdb/testsuite: avoid creating temp file in gdb/testsuite/ directory")
using command:

    make -C gdb check RUNTESTFLAGS='TRANSCRIPT=y gdb.base/*.exp'

Then I do not see them:

    $ grep UNRESOLVED gdb.sum.with-second-patch
    UNRESOLVED: gdb.base/gdb-sigterm.exp: 50 SIGTERM passes
    $ grep DUPLICATE gdb.sum.with-second-patch
    $

When I run gdb.base tests with on commit dc3fb44540 but with first
patch (b5661ff24) `git revert`ed, the only difference in tests I see is

$ diff -u gdb.sum.with-second-patch gdb.sum.with-first-patch-reverted
--- gdb.sum.with-second-patch	2022-12-14 09:14:46.790229064 +0000
+++ gdb.sum.with-first-patch-reverted	2022-12-14 09:40:53.460377645 +0000
@@ -1,4 +1,4 @@
-Test run by jv on Wed Dec 14 08:19:53 2022
+Test run by jv on Wed Dec 14 09:16:33 2022
 Native configuration is x86_64-pc-linux-gnu
 
 		=== gdb tests ===
@@ -1931,9 +1931,9 @@
 PASS: gdb.base/step-over-syscall.exp: clone: displaced=on: set displaced-stepping on
 PASS: gdb.base/step-over-syscall.exp: clone: displaced=on: single step over clone
 PASS: gdb.base/step-over-syscall.exp: clone: displaced=on: check_pc_after_cross_syscall: get hexadecimal valueof "$pc"
-PASS: gdb.base/step-over-syscall.exp: clone: displaced=on: check_pc_after_cross_syscall: single step over clone final pc
+KFAIL: gdb.base/step-over-syscall.exp: clone: displaced=on: check_pc_after_cross_syscall: single step over clone final pc (PRMS: gdb/19675)
 PASS: gdb.base/step-over-syscall.exp: clone: displaced=on: break marker
-KFAIL: gdb.base/step-over-syscall.exp: clone: displaced=on: continue to marker (clone) (PRMS: gdb/19675)
+KPASS: gdb.base/step-over-syscall.exp: clone: displaced=on: continue to marker (clone) (PRMS gdb/19675)
 Running /home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.base/siginfo-infcall.exp ...
 PASS: gdb.base/siginfo-infcall.exp: continue to SIGUSR1
 PASS: gdb.base/siginfo-infcall.exp: p callme ()
@@ -58069,9 +58069,10 @@
 
 		=== gdb Summary ===
 
-# of expected passes		57356
+# of expected passes		57355
 # of unexpected failures	6
 # of expected failures		33
+# of unknown successes		1
 # of known failures		32
 # of unresolved testcases	1
 # of untested testcases		6

gdb.base/step-over-syscall.exp seems to be one of the shaky tests on my machine.
It does not seem to define any custom commands nor does it use post-hooks so
I'd think it is unrelated (but I must admit I do not understand exactly what it
does and which parts of the system it excercises).

So, since the original patch (which I pushed little too hastily) clearly break things
and a fix causes problems elsewhere which I cannot reproduce yet, I suggest to
revert b5661ff2 "gdb: fix possible use-after-free when executing commands"
until I find a better solution (patch below)

What do you think?

-- >8 --
Subject: [PATCH] Revert "gdb: fix possible use-after-free when executing
 commands"

Commit b5661ff2 causes gdb.base/define.exp. Using lookup_cmd ()
instead lookup_cmd_exact () fixed this test but causes failures
elsewhere.

This reverts commit b5661ff2 until a better solution is found.
---
 gdb/top.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/gdb/top.c b/gdb/top.c
index 742997808bd..e9794184f07 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -655,11 +655,6 @@ execute_command (const char *p, int from_tty)
 	    }
 	}
 
-      /* Remember name of the command.  This is needed later when
-	 executing command post-hooks to handle the case when command
-	 is redefined or removed during it's execution.  See below.  */
-      std::string c_name (c->name);
-
       /* If this command has been pre-hooked, run the hook first.  */
       execute_cmd_pre_hook (c);
 
@@ -698,13 +693,8 @@ execute_command (const char *p, int from_tty)
 
       maybe_wait_sync_command_done (was_sync);
 
-      /* If this command has been post-hooked, run the hook last.
-	 We need to lookup the command again since during its execution,
-	 a command may redefine itself.  In this case, C pointer
-	 becomes invalid so we need to look it up again.  */
-      c = lookup_cmd_exact (c_name.c_str (), cmdlist);
-      if (c != nullptr)
-	execute_cmd_post_hook (c);
+      /* If this command has been post-hooked, run the hook last.  */
+      execute_cmd_post_hook (c);
 
       if (repeat_arguments != NULL && cmd_start == saved_command_line)
 	{
-- 
2.35.1


  reply	other threads:[~2022-12-14 11:08 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 14:20 [PATCH] gdb: fix possible use-after-free when executing commands Jan Vrany
2022-12-09 17:55 ` Tom Tromey
2022-12-12 15:05   ` Luis Machado
2022-12-12 15:08     ` Jan Vraný
2022-12-12 15:09     ` Luis Machado
2022-12-13 11:22     ` [PATCH] gdb: fix command lookup in execute_command () Jan Vrany
2022-12-13 15:05       ` Tom Tromey
2022-12-13 16:43         ` Simon Marchi
2022-12-13 18:48         ` Jan Vraný
2022-12-13 19:29           ` Simon Marchi
2022-12-14 11:07             ` Jan Vrany [this message]
2022-12-14 15:35               ` [PATCH] gdb: fix command lookup in execute_command () commands" Simon Marchi
2022-12-14 15:41                 ` Jan Vraný
2022-12-14 15:59               ` Tom Tromey
2022-12-14 16:01                 ` Simon Marchi
2022-12-14 18:05                   ` Tom Tromey
2022-12-14 18:30                     ` Simon Marchi
2022-12-14 22:01                       ` Simon Marchi
2022-12-16 14:07             ` [PATCH] gdb: fix command lookup in execute_command () Jan Vraný
2022-12-16 16:47               ` Simon Marchi
2022-12-19 11:48                 ` Jan Vraný
2022-12-19 14:46                   ` Tom Tromey
2022-12-19 15:51                     ` Jan Vraný
2022-12-20 19:10                       ` Tom Tromey
2022-12-14 19:52 ` [PATCH] gdb: fix possible use-after-free when executing commands Simon Marchi
2022-12-14 20:39   ` Jan Vraný
2022-12-14 20:42     ` Simon Marchi
2022-12-15 12:57       ` Jan Vrany
2022-12-15 13:53         ` Simon Marchi
2022-12-15 14:51           ` Jan Vrany
2022-12-15 16:00             ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214110747.1150349-1-jan.vrany@labware.com \
    --to=jan.vrany@labware.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=simark@simark.ca \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).