microsoft / microsoft/vscode-cpptools

Unable to debug on wsl ubuntu any C++ project using remote VSCode gdb

Open
#8,433 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugger
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Brief Issue Summary

Unable to debug on wsl ubuntu any c++ project using remote VSCode gdb

I try to debug perfectly OK executables, which I can manually debug with gdb, but trying to debug on VSCode gives the error attached below, in which every executable return right away with exit code 42.
Couldn't find anything online about this.
The problem reproduces on my machine with the following simple project:

Main.cpp
#include <iostream>

int main()
{
	std::cout << "insert x:\n";
	int x;
	std::cin >>x;
	std::cout << "hello x="<< x<< "\n";
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.18.0 FATAL_ERROR)

project(Server)

add_executable(server "Main.cpp")
launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/server",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "logging": {
                "engineLogging": true
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
            ]
        }
    ]
}
CMake Tools Diagnostics
<!-- Paste the `CMake: Log Diagnostics` output HERE -->
{
  "os": "linux",
  "vscodeVersion": "1.62.3",
  "cmtVersion": "1.9.1",
  "configurations": [
    {
      "folder": "/home/theroyn/repos/hihi",
      "cmakeVersion": "3.18.4",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/cc",
        "CXX": "/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///home/theroyn/repos/hihi/Main.cpp"
    ],
    "responses": [
      {
        "uri": "file:///home/theroyn/repos/hihi/Main.cpp",
        "configuration": {
          "defines": [],
          "includePath": [],
          "compilerPath": "/usr/bin/c++",
          "compilerArgs": [
            "-g"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "server",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log
<!-- Paste the debug log contents HERE -->
1: (130) LaunchOptions{"name":"(gdb) Launch","type":"cppdbg","request":"launch","program":"/home/theroyn/repos/hihi/build/server","args":[],"stopAtEntry":false,"cwd":"/home/theroyn/repos/hihi/.vscode","environment":[],"externalConsole":false,"MIMode":"gdb","logging":{"engineLogging":true},"setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"__configurationTarget":5,"__sessionId":"d443712e-2593-48ce-83e7-327942b61d57"}
1: (186) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-qayufm5k.vzr ; cd "/home/theroyn/repos/hihi/build" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm "/tmp/Microsoft-MIEngine-In-yrkyx3qm.mxs" "/tmp/Microsoft-MIEngine-Out-ua0i20rj.gzr" "/tmp/Microsoft-MIEngine-Pid-qayufm5k.vzr" "/tmp/Microsoft-MIEngine-Cmd-euq2p4kh.hc1"' EXIT ; "/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-yrkyx3qm.mxs" > "/tmp/Microsoft-MIEngine-Out-ua0i20rj.gzr" & clear; pid=$! ; echo $pid > "/tmp/Microsoft-MIEngine-Pid-qayufm5k.vzr" ; wait $pid;
1: (202) Wait for connection completion.
1: (318) ->=thread-group-added,id="i1"
1: (319) ->~"GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1\n"
1: (319) ->~"Copyright (C) 2018 Free Software Foundation, Inc.\n"
1: (320) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
1: (320) ->~"This GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details."
1: (321) ->~"\nFor bug reporting instructions, please see:\n"
1: (321) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
1: (321) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
1: (321) ->~"For help, type \"help\".\n"
1: (321) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (321) ->(gdb)
1: (330) <-1001-gdb-set target-async on
1: (331) ->1001^done
1: (332) ->(gdb)
1: (337) 1001: elapsed time 11
1: (359) <-1002-enable-pretty-printing
1: (360) ->1002^done
1: (361) ->(gdb)
1: (361) 1002: elapsed time 1
1: (361) <-1003-interpreter-exec console "set pagination off"
1: (362) ->=cmd-param-changed,param="pagination",value="off"
1: (362) ->1003^done
1: (362) ->(gdb)
1: (362) 1003: elapsed time 1
1: (363) <-1004-gdb-set auto-solib-add on
1: (363) ->1004^done
1: (363) ->(gdb)
1: (363) 1004: elapsed time 0
1: (364) <-1005-gdb-set solib-search-path /home/theroyn/repos/hihi/build:
1: (364) ->1005^done
1: (364) ->(gdb)
1: (364) 1005: elapsed time 0
1: (365) <-1006-gdb-set stop-on-solib-events 1
1: (366) ->1006^done
1: (366) ->(gdb)
1: (366) 1006: elapsed time 1
1: (366) <-1007-environment-cd /home/theroyn/repos/hihi/.vscode
1: (367) ->1007^done
1: (367) ->(gdb)
1: (367) 1007: elapsed time 0
1: (367) <-1008-file-exec-and-symbols /home/theroyn/repos/hihi/build/server
1: (376) ->1008^done
1: (376) ->(gdb)
1: (376) 1008: elapsed time 8
1: (380) <-1009-interpreter-exec console "show architecture"
1: (381) ->~"The target architecture is set automatically (currently i386:x86-64)\n"
1: (381) ->1009^done
1: (381) ->(gdb)
1: (381) 1009: elapsed time 1
1: (384) <-1010-break-insert -f main
1: (385) ->1010^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000000942",func="main()",file="/home/theroyn/repos/hihi/Main.cpp",fullname="/home/theroyn/repos/hihi/Main.cpp",line="4",thread-groups=["i1"],times="0",original-location="main"}
1: (386) ->(gdb)
1: (393) 1010: elapsed time 9
1: (400) Send Event AD7EngineCreateEvent
1: (404) Send Event AD7ProgramCreateEvent
1: (459) ShellPid=4638
1: (460) DebuggerPid=4640
1: (461) Shell exited, stop debugging
1: (600) Send Event AD7LoadCompleteEvent
=thread-group-added,id="i1"
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
1: (605) Send Event AD7MessageEvent
ERROR: Unable to start debugging. GDB exited unexpectedly.
1: (610) Send Event AD7ProgramDestroyEvent
The program '/home/theroyn/repos/hihi/build/server' has exited with code 42 (0x0000002a).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with Main.cpp, CMakeLists.txt, and .vscode/launch.json under WSL Ubuntu, comparing manual gdb with the VS Code launch. Start with the provided debug log around the shell and debugger exit, then trace the relevant launch path. Done means the sample executable starts debugging through VS Code without exiting unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, ubuntu, vscode
Domain
build-system, devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.