How to properly debug in (Ubuntu) VS Code?

Viewed 577

I recently made a fresh linux install, so I can write down all of the steps I made: After installing ubuntu 20.04:

  • apt update
  • apt install build-essential git ca-certificates libssl-dev gdb
  • git clone https://github.com/Kitware/Cmake
  • ./bootstrap
  • make
  • make install
  • installed VS code, and added C/C++ and CMake Tools extensions

After that I made a really simple C++ code:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project (hello_cmake)
add_executable(hello_cmake main.cpp)

main.cpp:

#include <iostream>

int main(int argc, char *argv[])
{
   for(int i=0; i<10; i++)
   {
      int test = 12;
      std::cout << "Hello CMake!" << std::endl;
      int test2 = 12;
   }
   return 0;
}

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/hello_cmake",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

So I can build and run the code properly (in the build folder cmake .. , make , ./hello_make), its working, but at debugging if I make a breakpoint (for example) at int test = 12; , I run the debug Step-over/Step-in and got an error:

Unable to open 'libc-start.c': Unable to read file '/build/glibc-eX1tMB/glibc-2.31/csu/libc-start.c' (Error: Unable to resolve non-existing file '/build/glibc-eX1tMB/glibc-2.31/csu/libc-start.c')

I read that its not really an error, so just skip it. But if I click Step-over the debug will end and I cant see the test variable at the left side in the Variables tab.

What am I missing?

0 Answers
Related