Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger: corrupted double-linked list #12945

Open
Sving1024 opened this issue Nov 9, 2024 · 6 comments
Open

Debugger: corrupted double-linked list #12945

Sving1024 opened this issue Nov 9, 2024 · 6 comments
Labels
debugger help wanted Can be fixed in the public (open source) repo.

Comments

@Sving1024
Copy link

Sving1024 commented Nov 9, 2024

Environment

  • OS and version: archlinux
  • VS Code: 1.96.0 - insider
  • C/C++ extension: 1.23.1
  • GDB / LLDB version: GNU gdb (GDB) 15.2

Bug Summary and Steps to Reproduce

Bug Summary:
Sometimes when I start to debug a cpp file, gdb crashes with "corrupted double-linked list". That seems to happen randomly, and usually disappear after a restart or rebuild.

Steps to reproduce:

  1. In the latest archlinux, install vscode-insider from aur.
  2. install the C/C++ extension.
  3. Write a cpp file.
  4. build
  5. launch.
  6. There's "corrupted double-linked list" in the shell.

Debugger Configurations

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ Build",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/Problems/bin/${fileBasenameNoExtension}",
                "-Wall",
                "-mcmodel=large",
                "-fsanitize=undefined,address"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

launch.json:

    {
        "name": "(gdb) launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/Problems/bin/${fileBasenameNoExtension}",
        "args": [
                "2>",
                "${workspaceFolder}/Problems/logs/${fileBasenameNoExtension}.log",
                "<",
                "${workspaceFolder}/Problems/input/${fileBasenameNoExtension}.in",
                ">",
                "${workspaceFolder}/Problems/output/${fileBasenameNoExtension}.out"
            ],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "enable-pretty-printing",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            },
            {
                "description": "gdb-set disassembly-flavor intel",
                "text": "-gdb-set disassembly-flavor intel",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false,
            "engineLogging": false
        }
    }

Debugger Logs

Shell:
 /tmp/Microsoft-MIEngine-Cmd-o4wyfsi1.uvj: 第 2 行:44048 已中止               (核心已转储)"/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-bm43zbsy.hm0" > "/tmp/Microsoft-MIEngine-Out-bjnwcvx0.uct"
Output:
Activating task providers cppbuild
Debug Console:
Nothing after gdb's copyright information.
Core dump:
           PID: 44048 (gdb)
           UID: 1000 (Sving1024)
           GID: 1000 (Sving1024)
        Signal: 6 (ABRT)
     Timestamp: Sat 2024-11-09 21:50:47 CST (7min ago)
  Command Line: /usr/bin/gdb --interpreter=mi --tty=/dev/pts/2
    Executable: /usr/bin/gdb
 Control Group: /user.slice/user-1000.slice/[email protected]/session.slice/[email protected]
          Unit: [email protected]
     User Unit: [email protected]
         Slice: user-1000.slice
     Owner UID: 1000 (Sving1024)
       Boot ID: 0decefcddda24410bcd734a899f90617
    Machine ID: f708d61fa25b4732ad2631e253cfbfa6
      Hostname: archlinux-asm236x
       Storage: /var/lib/systemd/coredump/core.gdb.1000.0decefcddda24410bcd734a899f90617.44048.1731160247000000.zst (present)
  Size on Disk: 3.9M
       Message: Process 44048 (gdb) of user 1000 dumped core.
                
                Module /usr/lib/guile/3.0/ccache/ice-9/format.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/vlist.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-26.go without build-id.
                Module /usr/lib/guile/3.0/ccache/language/scheme/decompile-tree-il.go without build-id.
                Module /usr/lib/guile/3.0/ccache/language/scheme/compile-tree-il.go without build-id.
                Module /usr/lib/guile/3.0/ccache/language/scheme/spec.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/vm/loader.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/receive.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/message.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/language.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/compile.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/eval-string.go without build-id.
                Module /usr/share/gdb/guile/gdb.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/regex.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/target.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/foreign.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/foreign-library.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-16.go without build-id.
                Module /usr/lib/guile/3.0/ccache/language/tree-il.go without build-id.
                Module /usr/lib/guile/3.0/ccache/oop/goops.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/syntax.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/pmatch.go without build-id.
                Module /usr/lib/guile/3.0/ccache/language/tree-il/primitives.go without build-id.
                Module /usr/lib/guile/3.0/ccache/rnrs/bytevectors.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-4.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/exceptions.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/control.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/q.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-9/gnu.go without build-id.
                Module /usr/lib/guile/3.0/ccache/system/base/ck.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-9.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-1.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/futures.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/match.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/threads.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/ports.go without build-id.
                Module /usr/lib/guile/3.0/ccache/srfi/srfi-11.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/copy-tree.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/deprecated.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/networking.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/psyntax-pp.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/boot-9.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/posix.go without build-id.
                Module /usr/lib/guile/3.0/ccache/ice-9/eval.go without build-id.
                Stack trace of thread 44048:
                #0  0x000071f420bb63f4 n/a (libc.so.6 + 0x963f4)
                #1  0x000071f420b5d120 raise (libc.so.6 + 0x3d120)
                #2  0x00006234c1650772 n/a (gdb + 0x2bf772)
                #3  0x000071f420b5d1d0 n/a (libc.so.6 + 0x3d1d0)
                #4  0x000071f420bb63f4 n/a (libc.so.6 + 0x963f4)
                #5  0x000071f420b5d120 raise (libc.so.6 + 0x3d120)
                #6  0x000071f420b444c3 abort (libc.so.6 + 0x244c3)
                #7  0x000071f420b45354 n/a (libc.so.6 + 0x25354)
                #8  0x000071f420bc0765 n/a (libc.so.6 + 0xa0765)
                #9  0x000071f420bc138c n/a (libc.so.6 + 0xa138c)
                #10 0x000071f420bc425a n/a (libc.so.6 + 0xa425a)
                #11 0x000071f420bc5fae __libc_calloc (libc.so.6 + 0xa5fae)
                #12 0x00006234c1ea79fc n/a (gdb + 0xb169fc)
                #13 0x00006234c17368b1 n/a (gdb + 0x3a58b1)
                #14 0x00006234c17369f7 n/a (gdb + 0x3a59f7)
                #15 0x00006234c174652d n/a (gdb + 0x3b552d)
                #16 0x00006234c1747aeb n/a (gdb + 0x3b6aeb)
                #17 0x00006234c1ef9524 n/a (gdb + 0xb68524)
                #18 0x00006234c1517d82 n/a (gdb + 0x186d82)
                #19 0x00006234c1520395 n/a (gdb + 0x18f395)
                #20 0x00006234c1f5677f n/a (gdb + 0xbc577f)
                #21 0x00006234c17c1773 n/a (gdb + 0x430773)
                #22 0x00006234c17c2cad n/a (gdb + 0x431cad)
                #23 0x00006234c17c3194 n/a (gdb + 0x432194)
                #24 0x00006234c16505f7 n/a (gdb + 0x2bf5f7)
                #25 0x00006234c1a26740 n/a (gdb + 0x695740)
                #26 0x00006234c1ebc3e1 n/a (gdb + 0xb2b3e1)
                #27 0x00006234c1f0b703 n/a (gdb + 0xb7a703)
                #28 0x00006234c178f765 n/a (gdb + 0x3fe765)
                #29 0x00006234c1428c15 n/a (gdb + 0x97c15)
                #30 0x000071f420b45e08 n/a (libc.so.6 + 0x25e08)
                #31 0x000071f420b45ecc __libc_start_main (libc.so.6 + 0x25ecc)
                #32 0x00006234c143fc25 n/a (gdb + 0xaec25)
                
                Stack trace of thread 44053:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f420ed6c31 __gthread_cond_wait (libstdc++.so.6 + 0xd6c31)
                #3  0x00006234c1ebf8ec n/a (gdb + 0xb2e8ec)
                #4  0x000071f420ee1c34 execute_native_thread_routine (libstdc++.so.6 + 0xe1c34)
                #5  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #6  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44054:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f420ed6c31 __gthread_cond_wait (libstdc++.so.6 + 0xd6c31)
                #3  0x00006234c1ebf8ec n/a (gdb + 0xb2e8ec)
                #4  0x000071f420ee1c34 execute_native_thread_routine (libstdc++.so.6 + 0xe1c34)
                #5  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #6  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44055:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f420ed6c31 __gthread_cond_wait (libstdc++.so.6 + 0xd6c31)
                #3  0x00006234c1ebf8ec n/a (gdb + 0xb2e8ec)
                #4  0x000071f420ee1c34 execute_native_thread_routine (libstdc++.so.6 + 0xe1c34)
                #5  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #6  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44056:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f420ed6c31 __gthread_cond_wait (libstdc++.so.6 + 0xd6c31)
                #3  0x00006234c1ebf8ec n/a (gdb + 0xb2e8ec)
                #4  0x000071f420ee1c34 execute_native_thread_routine (libstdc++.so.6 + 0xe1c34)
                #5  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #6  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44060:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f4210f36a1 n/a (libgc.so.1 + 0x1f6a1)
                #3  0x000071f4210f382f n/a (libgc.so.1 + 0x1f82f)
                #4  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #5  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44061:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f4210f36a1 n/a (libgc.so.1 + 0x1f6a1)
                #3  0x000071f4210f382f n/a (libgc.so.1 + 0x1f82f)
                #4  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #5  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                
                Stack trace of thread 44062:
                #0  0x000071f420bb0a19 n/a (libc.so.6 + 0x90a19)
                #1  0x000071f420bb3479 pthread_cond_wait (libc.so.6 + 0x93479)
                #2  0x000071f4210f36a1 n/a (libgc.so.1 + 0x1f6a1)
                #3  0x000071f4210f382f n/a (libgc.so.1 + 0x1f82f)
                #4  0x000071f420bb439d n/a (libc.so.6 + 0x9439d)
                #5  0x000071f420c3949c n/a (libc.so.6 + 0x11949c)
                ELF object binary architecture: AMD x86-64

Other Extensions

core.gdb.1000.0decefcddda24410bcd734a899f90617.44048.1731160247000000.zip

Additional Information

No response

@sean-mcmanus
Copy link
Contributor

@Sving1024 This sounds like a gdb bug. I think you would need to file a bug on gdb.

@sean-mcmanus
Copy link
Contributor

@Sving1024 Or do you believe it's a bug in MIEngine? I'm not sure if MIEngine could cause such a gdb crash.

@sean-mcmanus
Copy link
Contributor

@Sving1024 There's a similar issue at microsoft/MIEngine#968 you may want to refer to.

@sean-mcmanus sean-mcmanus added the help wanted Can be fixed in the public (open source) repo. label Nov 11, 2024
@Eletary
Copy link

Eletary commented Nov 16, 2024

@Sving1024 This sounds like a gdb bug. I think you would need to file a bug on gdb.

I met the same problem with vsc-cpp. But when I use gdb manually there is no such problem.

@sean-mcmanus sean-mcmanus reopened this Nov 16, 2024
@sean-mcmanus
Copy link
Contributor

@Eletary Sure, if that's the case, then it sounds like a bug from our extension/MIEngine.

@Sving1024
Copy link
Author

Sving1024 commented Nov 22, 2024

It seems the issue is related to std::priority_queue.
The two codes trigger the bug nearly every time on my machine, neither rebooting nor restarting vscode doesn't help.

#include <iostream>
#include <queue>
using namespace std;

using ll = long long;
using ull = unsigned long long;

struct location {
    ll x, y;
    location() { x = y = 0; }
    location(ll _x, ll _y) : x(_x), y(_y) {}
    location operator+(const location &b) const {
        return location(x + b.x, y + b.y);
    }
    location operator*(const ll &k) const { return location(x * k, y * k); }
    location operator/(const ll &k) const { return location(x / k, y / k); }
};

struct node {
    location l;
    ll val;
    bool operator<(const node &b) const { return val > b.val; }
};

int main(){
    priority_queue<node> q;
    for (ll i=0;i<5;i++) {
        ll x,y,z;
        cin>>x>>y>>z;
        q.push({{x,y},z});
    }
    cout<<(q.top().l.x);
}

use input(from keyboard):

1 2 3 ^Z
[1]  + 9393 suspended  /usr/bin/env /bin/sh /tmp/Microsoft-MIEngine-Cmd-ugnqs3fb.t0r

If you redirect from a file, gdb crashes with a corrupted double-linked list initially, not even hitting the breakpoint at line 26.

With proper inputs (at least 5 integers in the input), the program works well.

However, in a more complex program(you can find that in the attachment), gdb will crash as soon as it starts whether the input is from the keyboard or redirected from a file.

#include <iostream>
#include <queue>
using namespace std;

using ll = long long;
using ull = unsigned long long;

struct test2{
    ll x,y;
};

struct test{
    ll x;
    test2 t;
    test(ll _x){
        x=_x;
    }
    ~test(){
        cout<<"rm obj\n";
        return;
    }
    bool operator<(const test& b)const{return x<b.x;}
};

int main(){
    priority_queue<test> q;
    for (ll i=0;i<5;i++) {
        ll x;
        cin>>x;
        q.push({x});
    }
    cout<<(q.top().x);
}

using std::vector or other stl containers will not trigger the bug. The bug only appears with gdb 15.
attachment:
cpp.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugger help wanted Can be fixed in the public (open source) repo.
Projects
None yet
Development

No branches or pull requests

3 participants