microsoft / microsoft/vscode-cpptools

Large Vector Causes Debugger to Completely Freeze

Open
#11,662 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Environment
  • OS and version: macOS 13.5.2
  • VS Code: 13.5.2
  • C/C++ extension: 1.18.2
  • OS and version of remote machine (if applicable): n/a
  • GDB / LLDB version: 1400.0.38.17
Bug Summary and Steps to Reproduce

Bug Summary:

Program runs fine without debugging, and I can debug until I try to populate an vector with ~30M entries. I get a spinner in the Locals portion of the debugger and I can't continue.

image

(see for similar
https://github.com/Microsoft/vscode/issues/26660
https://github.com/microsoft/vscode/issues/76798
)

Offending function that reads from Binary file

std::vector<uint8_t> FileIO::ReadFileToBuffer(const fs::path &filepath)
    {
        // Validate the file path
        std::error_code ec;
        if (!std::filesystem::exists(filepath, ec) || ec)
        {
            throw std::runtime_error("File does not exist: " + filepath.string());
        }

        // Open the file in binary mode
        std::ifstream file(filepath, std::ios::binary);
        if (!file)
        {
            throw std::runtime_error("Unable to open file: " + filepath.string());
        }

        // Seek to the end of the file to find its size
        file.seekg(0, std::ios::end);
        std::streamsize size = file.tellg();
        file.seekg(0, std::ios::beg); // Seek back to the start of the file

        // Create a buffer to store the data
        std::vector<uint8_t> buffer(size);

        // Read the data from the file into the buffer
        if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
        {
            throw std::runtime_error("Error reading file: " + filepath.string());
        }

        return buffer;
    }

CMakeLists.txt

# https://chat.openai.com/share/390a47d7-310c-4e55-81d2-8e5a6fc84e64

cmake_minimum_required(VERSION 3.14)
project(fhmm)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Define a macro with the root path of the project
add_definitions(-DPROJECT_ROOT_PATH="${CMAKE_SOURCE_DIR}")

# Include directories
include_directories(include ${CMAKE_SOURCE_DIR}/extern/Eigen)

# Define the source files for the library
set(LIB_SOURCE_FILES
    src/hmm.cpp
    src/fileIO.cpp
    src/utility.cpp
    # ... other library source files
)

# Define the source file for the executable
set(EXE_SOURCE_FILES
    src/main.cpp
    # ... other executable source files if needed
)

# Define the library target
add_library(fhmm SHARED ${LIB_SOURCE_FILES})
target_compile_definitions(fhmm PRIVATE BUILDING_FHMM)

# Define the executable target
add_executable(FHMMExecutable ${EXE_SOURCE_FILES})

# Link the executable to FHMM library
target_link_libraries(FHMMExecutable fhmm)

# For Unix-like systems, enforce position-independent code
set_target_properties(fhmm PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Set the output directory for the build executables and libraries
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

# Installation rules
install(TARGETS fhmm FHMMExecutable DESTINATION bin)
install(FILES 
    include/hmm.h 
    include/fileIO.h
    include/utility.h
    DESTINATION include)
Debugger Configurations
launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "(lldb) Launch",
          "type": "cppdbg",
          "request": "launch",
          "targetArchitecture": "arm64",
          // Resolved by CMake Tools:
          "program": "${command:cmake.launchTargetPath}",
          "args": [],
          "stopAtEntry": false,
          "cwd": "${workspaceFolder}",
          "environment": [
              {
                  // add the directory where our target was built to the PATHs
                  // it gets resolved by CMake Tools:
                  "name": "PATH",
                  "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
              },
          ],
          "MIMode": "lldb",
      }
  ]
}
Debugger Logs
(tail of logs, total too long)

<details>
  <summary>logs</summary>
   1: (6849) <-1040-stack-list-variables 0 --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6850) ->1040^done,variables=[{name=\"projectRoot\"},{name=\"subPath\"},{name=\"filename\"},{name=\"fullPath\"},{name=\"utility\"},{name=\"fileIO\"},{name=\"buffer\"},{name=\"data\"}]\n"},"seq":912}
  1: (6850) ->1040^done,variables=[{name="projectRoot"},{name="subPath"},{name="filename"},{name="fullPath"},{name="utility"},{name="fileIO"},{name="buffer"},{name="data"}]
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6850) ->(gdb)\n"},"seq":914}
  1: (6850) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6850) 1040: elapsed time 1\n"},"seq":916}
  1: (6850) 1040: elapsed time 1
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6850) <-1041-var-create - - \"projectRoot\" --thread 1 --frame 0\n"},"seq":918}
  1: (6850) <-1041-var-create - - "projectRoot" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6851) ->1041^done,name=\"var10\",numchild=\"2\",value=\"{...}\",type=\"std::filesystem::__cxx11::path\",thread-id=\"1\",has_more=\"0\"\n"},"seq":920}
  1: (6851) ->1041^done,name="var10",numchild="2",value="{...}",type="std::filesystem::__cxx11::path",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6851) ->(gdb)\n"},"seq":922}
  1: (6851) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6851) 1041: elapsed time 0\n"},"seq":924}
  1: (6851) 1041: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6851) <-1042-var-create - - \"subPath\" --thread 1 --frame 0\n"},"seq":926}
  1: (6851) <-1042-var-create - - "subPath" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6852) ->1042^done,name=\"var11\",numchild=\"2\",value=\"{...}\",type=\"std::filesystem::__cxx11::path\",thread-id=\"1\",has_more=\"0\"\n"},"seq":928}
  1: (6852) ->1042^done,name="var11",numchild="2",value="{...}",type="std::filesystem::__cxx11::path",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6852) ->(gdb)\n"},"seq":930}
  1: (6852) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6852) 1042: elapsed time 0\n"},"seq":932}
  1: (6852) 1042: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6852) <-1043-var-create - - \"filename\" --thread 1 --frame 0\n"},"seq":934}
  1: (6852) <-1043-var-create - - "filename" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6853) ->1043^done,name=\"var12\",numchild=\"2\",value=\"{...}\",type=\"std::filesystem::__cxx11::path\",thread-id=\"1\",has_more=\"0\"\n"},"seq":936}
  1: (6853) ->1043^done,name="var12",numchild="2",value="{...}",type="std::filesystem::__cxx11::path",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6853) ->(gdb)\n"},"seq":938}
  1: (6853) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6853) 1043: elapsed time 0\n"},"seq":940}
  1: (6853) 1043: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6853) <-1044-var-create - - \"fullPath\" --thread 1 --frame 0\n"},"seq":942}
  1: (6853) <-1044-var-create - - "fullPath" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) ->1044^done,name=\"var13\",numchild=\"2\",value=\"{...}\",type=\"std::filesystem::__cxx11::path\",thread-id=\"1\",has_more=\"0\"\n"},"seq":944}
  1: (6854) ->1044^done,name="var13",numchild="2",value="{...}",type="std::filesystem::__cxx11::path",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) ->(gdb)\n"},"seq":946}
  1: (6854) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) 1044: elapsed time 0\n"},"seq":948}
  1: (6854) 1044: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) <-1045-var-create - - \"utility\" --thread 1 --frame 0\n"},"seq":950}
  1: (6854) <-1045-var-create - - "utility" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) ->1045^done,name=\"var14\",numchild=\"0\",value=\"??\",type=\"fluxus::Utility\",thread-id=\"1\",has_more=\"0\"\n"},"seq":952}
  1: (6854) ->1045^done,name="var14",numchild="0",value="??",type="fluxus::Utility",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) ->(gdb)\n"},"seq":954}
  1: (6854) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6854) 1045: elapsed time 0\n"},"seq":956}
  1: (6854) 1045: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6855) <-1046-var-create - - \"fileIO\" --thread 1 --frame 0\n"},"seq":958}
  1: (6855) <-1046-var-create - - "fileIO" --thread 1 --frame 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6855) ->1046^done,name=\"var15\",numchild=\"0\",value=\"??\",type=\"fluxus::FileIO\",thread-id=\"1\",has_more=\"0\"\n"},"seq":960}
  1: (6855) ->1046^done,name="var15",numchild="0",value="??",type="fluxus::FileIO",thread-id="1",has_more="0"
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6855) ->(gdb)\n"},"seq":962}
  1: (6855) ->(gdb)
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6855) 1046: elapsed time 0\n"},"seq":964}
  1: (6855) 1046: elapsed time 0
  --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (6855) <-1047-var-create - - \"buffer\" --thread 1 --frame 0\n"},"seq":966}
Other Extensions

CMake Pack

Additional Information

No response

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

Start by reproducing the freeze with the C++ function shown in the issue, using the provided launch.json and CMakeLists.txt. Inspect the debugger log around stack-list-variables and the buffer local; done means a roughly 30-million-entry vector no longer leaves the Locals view spinning or prevents continuing.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.