Code::Blocks Forums

User forums => Help => Topic started by: Stauricus on July 27, 2020, 10:33:22 pm

Title: kernel freezes when watcing some variables
Post by: Stauricus on July 27, 2020, 10:33:22 pm
hello everybody
i'm having some strange behaviour when trying to watch some specific variables in codeblocks and GDB in Linux
to be honest, i didn't even knew in which forum post this  :(

I have this code in C++ and SFML (a lib):
Code: cpp
#include <SFML/Graphics.hpp>

int main(){
    int a = 0;
    sf::VertexArray v(sf::Quads, 88);
    int b = 0;
    return 0;
}
this runs fine and I can debug it and watch variables. BUT if I change the VertexArray to 89, when I start the debugger and try to open the watches window, the whole system freezes. not even the mouse or keyboard respond, and I have to hard reset. if I dont open the watches window, it runs ok.

this is what VertexArray looks like (its simple, actually): https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1VertexArray.php

OS: Linux Debian 64 Testing with Cinnamon

C::B is
Name             : Code::Blocks
Version          : 20.03-r11997
SDK Version      : 2.0.0
Scintilla Version: 3.7.5

gcc (Debian 9.3.0-15) 9.3.0
GNU gdb (Debian 9.2-1) 9.2

i tried rebuilding the whole project, doing make/install to the SFML files again, updating the system, reinstalling code::blocks and GDB, but the problem persists. if idebug it in command line, nothing seems to freeze and I can close the application.

any help ins this case is appreciated. thanks in advance :)
Title: Re: kernel freezes when watcing some variables
Post by: oBFusCATed on July 28, 2020, 09:39:20 pm
Can you paste a code sample which doesn't depend on external libraries?
Title: Re: kernel freezes when watcing some variables
Post by: Stauricus on July 29, 2020, 02:24:45 pm
unfortunately no... i could only get a smaller class that causes the problem, sf::Color

Code: cpp
#include <SFML/Graphics.hpp>
#include <vector>

int main(){
    int a = 0;
    std::vector<sf::Color> v(200);
    int b = 0;
    return 0;
}

https://www.sfml-dev.org/documentation/2.5.1/Color_8hpp_source.php
https://www.sfml-dev.org/documentation/2.5.1/Graphics_2Export_8hpp_source.php
https://www.sfml-dev.org/documentation/2.5.1/Config_8hpp_source.php
Title: Re: kernel freezes when watcing some variables
Post by: oBFusCATed on July 29, 2020, 07:09:22 pm
You can run the preprocessor and start trimming the resulting code.

See an example here https://stackoverflow.com/questions/4900870/can-gcc-output-c-code-after-preprocessing
Title: Re: kernel freezes when watcing some variables
Post by: Stauricus on July 31, 2020, 03:27:48 pm
right, I actually trimmed the results directly from the source code, which is avaliable at github: https://github.com/SFML/SFML
this is the simplest I could get to, and if i set a breakpoint at line 25, it freezes the whole system while trying to watch local variables:
Code: cpp
typedef unsigned char Uint8;

class Color{
public:
    Color();
    Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
    static const Color Black;       ///< Black predefined color
    static const Color White;       ///< White predefined color
    static const Color Red;         ///< Red predefined color
    static const Color Green;       ///< Green predefined color
    static const Color Blue;        ///< Blue predefined color
    static const Color Yellow;      ///< Yellow predefined color

    Uint8 r; ///< Red component
    Uint8 g; ///< Green component
    Uint8 b; ///< Blue component
    Uint8 a; ///< Alpha (opacity) component
};

#include <vector>

int main(){
    int a = 0;
    std::vector<Color> v(2);
    int b = 0;
    return 0;
}

const Color Color::Black(0, 0, 0);
const Color Color::White(255, 255, 255);
const Color Color::Red(255, 0, 0);
const Color Color::Green(0, 255, 0);
const Color Color::Blue(0, 0, 255);
const Color Color::Yellow(255, 255, 0);

Color::Color() : r(0), g(0), b(0), a(255) {
}

Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : r(red), g(green), b(blue), a(alpha) {
}

for some reason, if I remove one of the predefined colors, it works. now i'm thinking this may be a GDB problem, as running the same code in this site (https://www.onlinegdb.com/online_c++_compiler/) also makes the application unresponsive
Title: Re: kernel freezes when watcing some variables
Post by: oBFusCATed on July 31, 2020, 08:15:48 pm
You can try to run this in a command line gdb. But I guess this is an infinite recursion, be cause gdb tries to print the static objects, too.
For me it works fine, probably you need newer gdb.

You can try this gdb command: set print static-members off
Title: Re: kernel freezes when watcing some variables
Post by: Stauricus on July 31, 2020, 08:30:15 pm
yeah, it really looks like an infinite recursion  :( does that mean i'm not able to watch static members then?
well, maybe it is temporary...
my GDB is version 9.2-1, I think that there isn't a newer one.

adding
Code
set print static-members off
to 'Debugger initialization commands' in Settings->Debugger->GDB/CDG debugger->Default did the trick. thanks for the help.
Title: Re: kernel freezes when watcing some variables
Post by: oBFusCATed on July 31, 2020, 11:21:51 pm
gdb 9.2 on gentoo, works just fine with your example.

This is how the gdb output looks like:
Code
{static Black = {static Black = <same as static member of an already seen type>, static ...