[go: nahoru, domu]

Bug 30249 - [13 regression] hookpost-extended-remote will not work
Summary: [13 regression] hookpost-extended-remote will not work
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 13.1
: P1 normal
Target Milestone: 13.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-20 08:57 UTC by wenyan.xin
Modified: 2023-05-24 18:48 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wenyan.xin 2023-03-20 08:57:37 UTC
upgrade the GDB to 13.1 version, hookpost-extended-remote will not work.


GNU gdb (GDB) 14.0.50.20230320-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) define target hookpost-extended-remote
Type commands for definition of "target hookpost-extended-remote".
End with a line saying just "end".
>echo hookpost-extended-remote\n
>end
(gdb) target extended-remote 127.0.0.1:2345
Remote debugging using 127.0.0.1:2345

please note here: after issue target extended-remote 127.0.0.1:2345, the "hookpost-extended-remote; string didnot echo.


this issue exist on version 13.1 and later.
Comment 1 Jan Vrany 2023-03-29 13:17:39 UTC
I can reproduce the bug and created a tentative fix, see

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f48f80529710f7dc9a87c6821315b7a1fa66853e

I'll run it through my CI and eventually submit.
Comment 2 Sourceware Commits 2023-05-19 12:38:56 UTC
The master branch has been updated by Jan Vrany <jv@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b69378ced6a2db6adfbea9974a246a65d931bab2

commit b69378ced6a2db6adfbea9974a246a65d931bab2
Author: Jan Vrany <jan.vrany@labware.com>
Date:   Fri May 19 13:20:04 2023 +0100

    gdb: fix post-hook execution for remote targets
    
    Commit b5661ff2 ("gdb: fix possible use-after-free when
    executing commands") attempted to fix possible use-after-free
    in case command redefines itself.
    
    Commit 37e5833d ("gdb: fix command lookup in execute_command ()")
    updated the previous fix to handle subcommands as well by using the
    original command string to lookup the command again after its execution.
    
    This fixed the test in gdb.base/define.exp but it turned out that it
    does not work (at least) for "target remote" and "target extended-remote".
    
    The problem is that the command buffer P passed to execute_command ()
    gets overwritten in dont_repeat () while executing "target remote"
    command itself:
    
            #0  dont_repeat () at top.c:822
            #1  0x000055555730982a in target_preopen (from_tty=1) at target.c:2483
            #2  0x000055555711e911 in remote_target::open_1 (name=0x55555881c7fe ":1234", from_tty=1, extended_p=0)
                at remote.c:5946
            #3  0x000055555711d577 in remote_target::open (name=0x55555881c7fe ":1234", from_tty=1) at remote.c:5272
            #4  0x00005555573062f2 in open_target (args=0x55555881c7fe ":1234", from_tty=1, command=0x5555589d0490)
                at target.c:853
            #5  0x0000555556ad22fa in cmd_func (cmd=0x5555589d0490, args=0x55555881c7fe ":1234", from_tty=1)
                at cli/cli-decode.c:2737
            #6  0x00005555573487fd in execute_command (p=0x55555881c802 "4", from_tty=1) at top.c:688
    
    Therefore the second call to lookup_cmd () at line 697 fails to find
    command because the original command string is gone.
    
    This commit addresses this particular problem by creating a *copy* of
    original command string for the sole purpose of using it after command
    execution to lookup the command again. It may not be the most efficient
    way but it's safer given that command buffer is shared and overwritten
    in hard-to-foresee situations.
    
    Tested on x86_64-linux.
    
    PR 30249
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30249
    
    Approved-By: Tom Tromey <tom@tromey.com>
Comment 3 Tom Tromey 2023-05-20 00:27:07 UTC
Could you "git cherry-pick -x" this to the gdb 13 branch?
Comment 4 Tom Tromey 2023-05-20 00:27:26 UTC
Optimistically setting the target milestone.
Comment 5 Sourceware Commits 2023-05-20 19:45:35 UTC
The gdb-13-branch branch has been updated by Jan Vrany <jv@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bcd95b84d3045aef8ec50c019d7d9d4d0d5f3817

commit bcd95b84d3045aef8ec50c019d7d9d4d0d5f3817
Author: Jan Vrany <jan.vrany@labware.com>
Date:   Fri May 19 13:20:04 2023 +0100

    gdb: fix post-hook execution for remote targets
    
    Commit b5661ff2 ("gdb: fix possible use-after-free when
    executing commands") attempted to fix possible use-after-free
    in case command redefines itself.
    
    Commit 37e5833d ("gdb: fix command lookup in execute_command ()")
    updated the previous fix to handle subcommands as well by using the
    original command string to lookup the command again after its execution.
    
    This fixed the test in gdb.base/define.exp but it turned out that it
    does not work (at least) for "target remote" and "target extended-remote".
    
    The problem is that the command buffer P passed to execute_command ()
    gets overwritten in dont_repeat () while executing "target remote"
    command itself:
    
            #0  dont_repeat () at top.c:822
            #1  0x000055555730982a in target_preopen (from_tty=1) at target.c:2483
            #2  0x000055555711e911 in remote_target::open_1 (name=0x55555881c7fe ":1234", from_tty=1, extended_p=0)
                at remote.c:5946
            #3  0x000055555711d577 in remote_target::open (name=0x55555881c7fe ":1234", from_tty=1) at remote.c:5272
            #4  0x00005555573062f2 in open_target (args=0x55555881c7fe ":1234", from_tty=1, command=0x5555589d0490)
                at target.c:853
            #5  0x0000555556ad22fa in cmd_func (cmd=0x5555589d0490, args=0x55555881c7fe ":1234", from_tty=1)
                at cli/cli-decode.c:2737
            #6  0x00005555573487fd in execute_command (p=0x55555881c802 "4", from_tty=1) at top.c:688
    
    Therefore the second call to lookup_cmd () at line 697 fails to find
    command because the original command string is gone.
    
    This commit addresses this particular problem by creating a *copy* of
    original command string for the sole purpose of using it after command
    execution to lookup the command again. It may not be the most efficient
    way but it's safer given that command buffer is shared and overwritten
    in hard-to-foresee situations.
    
    Tested on x86_64-linux.
    
    PR 30249
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30249
    
    Approved-By: Tom Tromey <tom@tromey.com>
    (cherry picked from commit b69378ced6a2db6adfbea9974a246a65d931bab2)
Comment 6 Jan Vrany 2023-05-20 19:50:10 UTC
(In reply to Tom Tromey from comment #3)
> Could you "git cherry-pick -x" this to the gdb 13 branch?

I did that, run the test suite and pushed. Hope all is all right.
Comment 7 Tom Tromey 2023-05-24 18:48:45 UTC
Looks great, going to close this.