Page 1 of 1

What is the right way to debug a threaded proc

Posted: Mon Nov 20, 2017 10:08 am
by said
Hi :)

I think the title says it all ... thanks in advance :D

Said

Re: What is the right way to debug a threaded proc

Posted: Mon Nov 20, 2017 2:31 pm
by spikey
It does depend what your thread is supposed to be doing and what sort of problem you are running into.

1) If it's feasible to do so, extract the thread logic into a separate synchronous/sequential test file and use that to debug and eliminate any non-threading related logic errors so that these aren't making matters worse in the threaded version.

2) Make sure that you're using mutexes for all shared resources, especially if your thread could be multi-threaded.

3) Get one of the assert macros running around the forum and use it to make sure that critical states are valid at points which might derail your thread. Remember that in multi-thread situations just because a particular state was true at the start of the thread doesn't mean that this state will still be around further down the line...

4) Get Rescator's debug api macro from http://www.purebasic.fr/english/viewtop ... 12&t=14231
and DebugView from https://docs.microsoft.com/en-gb/sysint ... /debugview if you don't already have something similar; so you can get feedback from the real live thread if the problem doesn't exhibit within the IDE/debugger.

Re: What is the right way to debug a threaded proc

Posted: Mon Nov 20, 2017 9:34 pm
by said
@spikey many thanks for your valuable tips and the links, really appreciated. I will try to use them :D

My question is too general and it is not easy to guess what i have in mind :!: To be more specific, how would you properly debug a thread inside the IDE using Breakpoints (F9,F7,F8) ... sometimes i just loose track of a running thread, the ide seems to mostly focus on the main thread or probably i am doing something wrong :(

thanks again

Said

Re: What is the right way to debug a threaded proc

Posted: Mon Nov 20, 2017 10:10 pm
by skywalk
I also attempt debugging threaded apps within the IDE.
If you set a breakpoint in Main, before stepping into your threaded procedure, you can step into the thread and view as normal.
If you only put a breakpoint in the threaded procedure, there is no guarantee the debugger will stop.

It would be great if there was a help doc for debugging threaded apps.

Re: What is the right way to debug a threaded proc

Posted: Mon Nov 20, 2017 11:44 pm
by citystate
My main method, as spikey suggests, is to separate the threaded portion into a non-threaded procedure - that way, using breakpoints and program stepping, you can see what the thread is doing - also, display your variables with the debugger window

Re: What is the right way to debug a threaded proc

Posted: Tue Nov 21, 2017 10:29 am
by said
@skywalk , @citystate, thanks for your feedback, so that's the best we can have :o there must be a more reliable and systematic way
skywalk wrote: If you set a breakpoint in Main, before stepping into your threaded procedure, you can step into the thread and view as normal.
If you only put a breakpoint in the threaded procedure, there is no guarantee the debugger will stop.
Not sure, this always works fine, what i have noticed is, as soon as an event is present in the main thread loop then you loose track of the other thread
skywalk wrote: It would be great if there was a help doc for debugging threaded apps.
the best would be if the ide can track 2 threads at a time, if this cant be done, then yes a little help would be really helpful :) maybe we should post a doc feature request about