Bug 23188 - Process record does not support instruction 0xc5 (vmovd %esi,%xmm0 / AVX2)
Summary: Process record does not support instruction 0xc5 (vmovd %esi,%xmm0 / AVX2)
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: record (show other bugs)
Version: 8.1
: P2 normal
Target Milestone: 16.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-16 14:20 UTC by Peter Wu
Modified: 2024-10-28 14:37 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-04-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Wu 2018-05-16 14:20:26 UTC
Reverse debugging using the "record" command halts when it encounters an AVX2-related instruction.

(gdb) record full
(gdb) c
Process record does not support instruction 0xc5 at address 0x7fffddca0010.
Process record: failed to record execution log.

0x00007fffddca0010 in __memset_avx2_unaligned_erms () from /usr/lib/libc.so.6
(gdb) x/i $rip
=> 0x7fffddca0010 <__memset_avx2_unaligned_erms>:       vmovd  %esi,%xmm0


As a workaround, libc can be patched to hide the AVX2 CPU feature, but it is rather cumbersome to use: https://stackoverflow.com/q/42451492

Affects glibc 2.24, 2.25, 2.27 on Arch Linux and Ubuntu.
CPU: i7-6700HQ
Comment 1 Nathaniel M. Beaver 2018-09-29 00:28:34 UTC
Maybe a duplicate of #17346?

https://sourceware.org/bugzilla/show_bug.cgi?id=17346
Comment 2 Peter Wu 2018-09-29 08:57:24 UTC
Not a duplicate, the bug 17346 is about AVX while this one is about AVX2. The other would be a good starting point for this one I suppose.
Comment 3 Jan Engelhardt 2019-01-17 10:29:36 UTC
---
#include <string.h>
int main(int argc, char **argv)
{
        return strcasecmp(argv[0], "foooooooooooooooooooooooooooobaaaar") == 0;
}
---

(gcc 7.4.0)
$ gcc-7 t.c -ggdb3
$ gdb a.out 
GNU gdb (GDB; openSUSE Tumbleweed) 8.2
Copyright (C) 2018 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-suse-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.opensuse.org/>.
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"...
Reading symbols from a.out...done.
(gdb) b main
Breakpoint 1 at 0x401126: file t.c, line 4.
(gdb) r
Starting program: a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffde68) at t.c:4
4               return strcasecmp(argv[0], "foooooooooooooooooooooooooooobaaaar") == 0;
(gdb) record
(gdb) c
Continuing.
Process record does not support instruction 0xc5 at address 0x7ffff7b7134f.

[1]+  Stopped                 gdb a.out
$ fg
gdb a.out
Process record: failed to record execution log.

Program stopped.
__strcasecmp_l_avx () at ../sysdeps/x86_64/multiarch/strcmp-sse42.S:187
187             movdqa  LABEL(belowupper)(%rip), %xmm4
(gdb) disas
Dump of assembler code for function __strcasecmp_l_avx:
   0x00007ffff7b71330 <+0>:     mov    (%rdx),%rax
   0x00007ffff7b71333 <+3>:     testl  $0x1,0x278(%rax)
   0x00007ffff7b7133d <+13>:    jne    0x7ffff7abaca0 <__strcasecmp_l_nonascii>
   0x00007ffff7b71343 <+19>:    mov    %esi,%ecx
   0x00007ffff7b71345 <+21>:    mov    %edi,%eax
   0x00007ffff7b71347 <+23>:    and    $0x3f,%rcx
   0x00007ffff7b7134b <+27>:    and    $0x3f,%rax
=> 0x00007ffff7b7134f <+31>:    vmovdqa 0x2f649(%rip),%xmm4        # 0x7ffff7ba09a0
   0x00007ffff7b71357 <+39>:    vmovdqa 0x2f661(%rip),%xmm5        # 0x7ffff7ba09c0
   0x00007ffff7b7135f <+47>:    vmovdqa 0x2f629(%rip),%xmm6        # 0x7ffff7ba0990 <blanks>
   0x00007ffff7b71367 <+55>:    cmp    $0x30,%ecx
   0x00007ffff7b7136a <+58>:    ja     0x7ffff7b713d0 <__strcasecmp_l_avx+160>
   0x00007ffff7b7136c <+60>:    cmp    $0x30,%eax
   0x00007ffff7b7136f <+63>:    ja     0x7ffff7b713d0 <__strcasecmp_l_avx+160>
   0x00007ffff7b71371 <+65>:    vmovdqu (%rdi),%xmm1
   0x00007ffff7b71375 <+69>:    vmovdqu (%rsi),%xmm2
   0x00007ffff7b71379 <+73>:    vpcmpgtb %xmm4,%xmm1,%xmm7
   0x00007ffff7b7137d <+77>:    vpcmpgtb %xmm5,%xmm1,%xmm8
   0x00007ffff7b71381 <+81>:    vpcmpgtb %xmm4,%xmm2,%xmm9
   0x00007ffff7b71385 <+85>:    vpcmpgtb %xmm5,%xmm2,%xmm10
   0x00007ffff7b71389 <+89>:    vpandn %xmm7,%xmm8,%xmm8
   0x00007ffff7b7138d <+93>:    vpandn %xmm9,%xmm10,%xmm10
   0x00007ffff7b71392 <+98>:    vpand  %xmm6,%xmm8,%xmm8
   [..]
Comment 4 Alan Hayward 2019-04-11 07:49:49 UTC
Using HEAD, on Ubuntu 16.04 X86-64 I get this error many times when running gdb.reverse/sigall-reverse.exp

make check "RUNTESTFLAGS=gdb.reverse/sigall-reverse.exp"
# of expected passes		424
# of unexpected failures	493
# of expected failures		71

Snippet from gdb.log:

(gdb) PASS: gdb.reverse/sigall-reverse.exp: b gen_TTIN
continue^M
Continuing.^M
Process record does not support instruction 0xc5 at address 0x7ffff7dee8b7.^M
Process record: failed to record execution log.^M
(gdb) FAIL: gdb.reverse/sigall-reverse.exp: get signal CHLD
continue^M
Continuing.^M
Process record does not support instruction 0xc5 at address 0x7ffff7dee8b7.^M
Process record: failed to record execution log.^M


$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.3 LTS
Release:	16.04
Codename:	xenial

$ cat /proc/version
Linux version 4.4.0-121-generic (buildd@lcy01-amd64-004) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) ) #145-Ubuntu SMP Fri Apr 13 13:47:23 UTC 2018
Comment 5 Sourceware Commits 2019-09-27 08:36:59 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 68f7d34dd506d1ccdaab9e772a533f8e76a5fe19
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Sep 27 10:36:18 2019 +0200

    [gdb/testsuite] Add KFAIL for missing support of reverse-debugging of vmovd
    
    On my openSUSE Leap 15.1 system I run into:
    ...
    (gdb) PASS: gdb.reverse/step-precsave.exp: turn on process record
    break 76^M
    Breakpoint 2 at 0x400654: file step-reverse.c, line 76.^M
    (gdb) PASS: gdb.reverse/step-precsave.exp: breakpoint at end of main
    continue^M
    Continuing.^M
    Process record does not support instruction 0xc5 at address 0x7ffff783fc70.^M
    Process record: failed to record execution log.^M
    ^M
    Program stopped.^M
    0x00007ffff783fc70 in __memset_avx2_unaligned_erms () from /lib64/libc.so.6^M
    (gdb) FAIL: gdb.reverse/step-precsave.exp: run to end of main
    ...
    
    The problem is that the vmovd instruction is not supported in
    reverse-debugging (PR record/23188).
    
    Add a KFAIL for this PR.
    
    Tested on x86_64-linux.
    
    gdb/testsuite/ChangeLog:
    
    2019-09-27  Tom de Vries  <tdevries@suse.de>
    
    	PR record/23188
    	* gdb.reverse/step-precsave.exp: Add kfail for PR record/23188.
Comment 6 Peter Wu 2020-02-06 22:54:00 UTC
The problem still exists in GDB 8.3.1.
A workaround for typical programs is described in https://stackoverflow.com/q/42451492/427545

Bug 19365 is about AVX while this bug is about AVX2.

Full AVX/AVX2 support looks like a ton of work:
- At minimum VEX prefix support (C4 for 3-byte VEX, C5 for 2-byte VEX) [1]
- AVX-specific instructions [2] - currently not supported.
- AVX2-specific instructions [3] - currently not supported.

Luckily AVX-512 is not common yet, the full set of extensions is quite big.[4]

It looks like i386_process_record in i386-tdep.c has to be updated to support new features. For the original case (vmovd), support for the VEX prefixes (the 'v' in 'vmovd') should be sufficient.

 [1]: https://en.wikipedia.org/wiki/VEX_prefix
 [2]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#New_instructions
 [3]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#New_instructions_2
 [4]: https://en.wikipedia.org/wiki/AVX-512
Comment 7 Sourceware Commits 2024-10-28 13:54:58 UTC
The master branch has been updated by Guinevere Larsen <guinevere@sourceware.org>:

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

commit 4b672a4a6d087a12ff24cb5125dbbb5dfa876b9a
Author: Guinevere Larsen <guinevere@redhat.com>
Date:   Mon Jul 29 14:52:59 2024 -0300

    gdb/record: add support to vmovd and vmovq instructions
    
    This commit adds support to the x86_64 AVX instructions vmovd and vmovq.
    The programmers manuals for Intel and AMD describe these 2 instructions
    as being almost the same, but my local testing, using gcc 13.2 on Fedora
    39, showed several differences and inconsistencies.
    
    The instruction is supposed to always use the 3-byte VEX prefix, but I
    could only find 2-byte versions. The instructions aren't differentiated
    by the VEX.w bit, but by opcodes and VEX.pp.
    
    This patch adds a test with many different uses for both vmovd and
    vmovq. It also updates the test gdb.reverse/step-precsave.exp to
    reference the generic "missing avx support" bug open in the bug tracker
    (17346), instead of pointing to one that specifically calls out to
    vmovd instructions.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23188
    Approved-By: Tom Tromey <tom@tromey.com>
Comment 8 Guinevere Larsen 2024-10-28 14:36:13 UTC
Fixed by the commit mentioned by the bot