Author Topic: kernel freezes when watcing some variables  (Read 404 times)

Offline Stauricus

  • Single posting newcomer
  • *
  • Posts: 7
kernel freezes when watcing some variables
« 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: C++
  1. #include <SFML/Graphics.hpp>
  2.  
  3. int main(){
  4.     int a = 0;
  5.     sf::VertexArray v(sf::Quads, 88);
  6.     int b = 0;
  7.     return 0;
  8. }
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 :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: kernel freezes when watcing some variables
« Reply #1 on: July 28, 2020, 09:39:20 pm »
Can you paste a code sample which doesn't depend on external libraries?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Stauricus

  • Single posting newcomer
  • *
  • Posts: 7
Re: kernel freezes when watcing some variables
« Reply #2 on: July 29, 2020, 02:24:45 pm »
unfortunately no... i could only get a smaller class that causes the problem, sf::Color

Code: C++
  1. #include <SFML/Graphics.hpp>
  2. #include <vector>
  3.  
  4. int main(){
  5.     int a = 0;
  6.     std::vector<sf::Color> v(200);
  7.     int b = 0;
  8.     return 0;
  9. }

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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: kernel freezes when watcing some variables
« Reply #3 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Stauricus

  • Single posting newcomer
  • *
  • Posts: 7
Re: kernel freezes when watcing some variables
« Reply #4 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: C++
  1. typedef unsigned char Uint8;
  2.  
  3. class Color{
  4. public:
  5.     Color();
  6.     Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
  7.     static const Color Black;       ///< Black predefined color
  8.     static const Color White;       ///< White predefined color
  9.     static const Color Red;         ///< Red predefined color
  10.     static const Color Green;       ///< Green predefined color
  11.     static const Color Blue;        ///< Blue predefined color
  12.     static const Color Yellow;      ///< Yellow predefined color
  13.  
  14.     Uint8 r; ///< Red component
  15.     Uint8 g; ///< Green component
  16.     Uint8 b; ///< Blue component
  17.     Uint8 a; ///< Alpha (opacity) component
  18. };
  19.  
  20. #include <vector>
  21.  
  22. int main(){
  23.     int a = 0;
  24.     std::vector<Color> v(2);
  25.     int b = 0;
  26.     return 0;
  27. }
  28.  
  29. const Color Color::Black(0, 0, 0);
  30. const Color Color::White(255, 255, 255);
  31. const Color Color::Red(255, 0, 0);
  32. const Color Color::Green(0, 255, 0);
  33. const Color Color::Blue(0, 0, 255);
  34. const Color Color::Yellow(255, 255, 0);
  35.  
  36. Color::Color() : r(0), g(0), b(0), a(255) {
  37. }
  38.  
  39. Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : r(red), g(green), b(blue), a(alpha) {
  40. }

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 also makes the application unresponsive
« Last Edit: July 31, 2020, 04:03:12 pm by Stauricus »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: kernel freezes when watcing some variables
« Reply #5 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Stauricus

  • Single posting newcomer
  • *
  • Posts: 7
Re: kernel freezes when watcing some variables
« Reply #6 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: [Select]
set print static-members off to 'Debugger initialization commands' in Settings->Debugger->GDB/CDG debugger->Default did the trick. thanks for the help.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: kernel freezes when watcing some variables
« Reply #7 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: [Select]
{static Black = {static Black = <same as static member of an already seen type>, static ...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]