Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with debugging in VSCode+gdb  (Read 525 times)

0 Members and 1 Guest are viewing this topic.

HelbMePlease

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Problem with debugging in VSCode+gdb
« on: July 31, 2023, 09:35:56 pm »
Hey everyone,
I used the CMake Tools VSCode extension to set up a debugging environment (I hardly did anything) using the gcc kit. It was all going fine until I tried to inspect the contents of a vector and it shows empty even though I know (almost for certain) it isn't. Here's the relevant code:
void squares(std::vector<sf::RectangleShape> &squares_vec)
{
    for (size_t i = 0; i < 81; i++)
    {
        sf::Color grey(140,140,140);
        sf::Color gainsboro_grey(207,208,207);
        sf::RectangleShape square(sf::Vector2f(70,70));
        square.setFillColor(gainsboro_grey);
        square.setOutlineColor(grey);
        square.setOutlineThickness(3);
        squares_vec.push_back(square);
    }
    std::cout<<"Number of squares in vec: "<<squares_vec.size()<<std::endl;
    place_squares(squares_vec);        
}
 
The std::cout prints 81 squares in vec (as intended) so everything in that function seems okay  but I need the debugger to be working well to debug the subsequent function ( place_squares() ) which is not working okay. What I mean by the debugger is telling me the vector is empty is that is what it shows in the VSCode debugging GUI on the left panel of VSCode, which I am using. Below are some more documents you may find useful.

CMakeLists.txt:

Quote

#This CMakeLists.txt is a frankenstein mixture between what CMake Tools auto generates and some changes I made based on
#this Example CMake script (so it would link the libraries): https://en.sfml-dev.org/forums/index.php?topic=24070.0

cmake_minimum_required(VERSION 3.0.0)
project(sfml-app VERSION 0.1.0 LANGUAGES C CXX)

include(CTest)
enable_testing()

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(sfml-app main.cpp)
target_link_libraries(sfml-app sfml-graphics sfml-audio)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")
include(CPack)

cmake_minimum_required(VERSION 3.1)

project(SFMLTest)

## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache


compile_commands.json:

Quote
[
{
  "directory": "/home/dudefellaman/Desktop/SFML Code/Sudoku/build",
  "command": "/usr/bin/g++   -g -o CMakeFiles/sfml-app.dir/main.cpp.o -c \"/home/dudefellaman/Desktop/SFML Code/Sudoku/main.cpp\"",
  "file": "/home/dudefellaman/Desktop/SFML Code/Sudoku/main.cpp"
}
]

If you need anymore info, ask away!
« Last Edit: July 31, 2023, 09:40:35 pm by HelbMePlease »

HelbMePlease

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Problem with debugging in VSCode+gdb
« Reply #1 on: August 01, 2023, 10:11:51 pm »
Update: it's definitely an SFML-related problem as I tried a very similar scenario with a vector of primitive types and a little class I whipped up for testing and it all worked fine. Only when I tried to use a vector of sf::RectangleShape did the problem reappear.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10783
    • View Profile
    • development blog
    • Email
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HelbMePlease

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Problem with debugging in VSCode+gdb
« Reply #3 on: August 16, 2023, 05:32:37 pm »
A quick web search lead me to some similar posts, maybe you can find some answers there:

https://stackoverflow.com/questions/56828562/unable-to-see-elements-of-stdvector-with-gcc-in-vs-code
https://stackoverflow.com/questions/64189683/unable-to-inspect-c-stl-content-in-vs-code
Oh thanks, but I already solved this problem with the nice folks over at the discord server. I just needed to use the CMake boilerplate you guys put up on GitHub and download some linux dependencies so the debugger knew how to interpret the data. Should I mark this thread with [SOLVED] marker or do we not do that in these forums?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10783
    • View Profile
    • development blog
    • Email
Re: Problem with debugging in VSCode+gdb
« Reply #4 on: August 16, 2023, 11:01:16 pm »
Should I mark this thread with [SOLVED] marker or do we not do that in these forums?
Some people do it, some don't. The important part is to provide an update somewhere, when stuff is solved, so people don't feel the need to help out further :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/