What is the right way to debug a threaded proc

Just starting out? Need help? Post your questions and find answers here.
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

What is the right way to debug a threaded proc

Post by said »

Hi :)

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

Said
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

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

Post 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.
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

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

Post 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
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

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

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

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

Post 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
Post Reply