Qt6 topics merged with General

Debug and Release execution issues

  • Hey Gurus,
    I have written a program that is similar to Facebook Messenger. It’s a chat program. The program consists of a server and a client.
    I have an issue which has stumped me. The software is running on my PC.
    Up until now everything has been running very well. Over the last couple of days, I have done some fairly major changes to some sections of the code. Now all of a sudden I have this weird issue.
    If I run the server compiled in debug mode, it works perfectly. Clients can connect to it and the program runs flawlessly.
    If I run the server compiled in release mode, it launches and looks to be running fine, but it won't accept any incoming connections. In fact it doesn't seem to even know there is an incoming connection.
    It's not firewall issues. In my test, the client and server were both running on the same machine. Debug works, release won't work.
    It gets better though...
    I have cross compiled my software to run on my Raspberry Pi. When my server is running day to day, it runs on the Raspberry Pi. The exact same code compiled in release mode on the Raspberry Pi works flawlessly!

    I did a Clean All, Run Qmake, Rebuild All, but no difference.

    I really have no idea where to start looking for this bug.

    Why will the debug version work and the release version not work on my PC, but the release version will work on my Raspberry Pi?

    I'd really appreciate it if someone could please point me in the right direction on how to solve this.

    Thanks so much,

    Steve Q. :-)

  • @steveq
    In the time it took you to type this, you could have put a couple of judicious log-to-file messages and compiled for Release mode on PC to verify e.g.

    If I run the server compiled in release mode, it launches and looks to be running fine, but it won't accept any incoming connections. In fact it doesn't seem to even know there is an incoming connection.

    One guess is that they do all still work, and somehow the Release one is not working because there is still some artefact left over from previous compilations, or wrong library versions, or something. Scrub hard/solid disk vigorously with soap just in case :) Or, you'll wake up tomorrow, perhaps relink, and miraculously it will work OK after all.

    Now assume there is some bug in your code. I wouldn't read too much into "but it works in Release mode on some other machine/environment". Doesn't mean it isn't a bug which does show up on original PC, you may just be getting away with it on RPi, as you are when compiled Debug.

    It won't help you track it down much, but one of the commonest reasons in that in Release build uninitialized memory really does contain "random" content, whereas it might be initialized to 0s in Debug. Bugs show up when something happens to have non-zero content. But it could be anything --- timings differing Release vs Debug can mean things happen closer together. If your server is using threads(?), that's nasty for only showing up bugs when e.g. running faster in Release.

    Since you can't repro under Debug, do yourself a favor and put in some log-to-file statements. You could at least confirm whether the bad server isn't even listening.

  • Thanks @JonB for your comments!

    I'll go looking for random content in my variables and I'll do your suggestion of commenting into a log file.

    It was late last night when I threw my hands up in disgust! Hopefully the fresh light of a new day will bring with it an epiphany and my programming woes will all but disappear.

    Thanks again!

    Steve Q. :-)

  • @steveq
    In another similar new post, user @JKSH has just posted a refernce to https://exceptionshub.com/program-only-crashes-as-release-build-how-to-debug.html. This includes among its suggestions the issue of unitialized variables behaving differently under Release vs Debug, but also other common ones. And some possible tools to help. You should take a look.

  • Are you using SSL to secure the transmissions?

  • @JonB thanks again. That’s an interesting read. It appears an uninitialised variable is most likely my issue! This is in spite of the fact that I am anal about this sort of thing. Hopefully it is something this simple.

  • @VRonin I encrypt data in both directions to and from the server, but... I didn't use QT's SSL classes as I wasn’t aware of their existence at the time. Doh! Still it works (apart from my release issue) . :-)

  • I found a stray uninitialised variable that I had missed, it appears to have been the culprit. It seems to be running again now. :-)
    Thanks for your help guys. :-)

Log in to reply