It is currently Mon Dec 11, 2017 1:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: What is the right way to debug a threaded proc
PostPosted: Mon Nov 20, 2017 10:08 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 14, 2011 6:07 pm
Posts: 322
Hi :)

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

Said


Top
 Profile  
Reply with quote  
 Post subject: Re: What is the right way to debug a threaded proc
PostPosted: Mon Nov 20, 2017 2:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:17 pm
Posts: 250
Location: United Kingdom
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/viewtopic.php?f=12&t=14231
and DebugView from https://docs.microsoft.com/en-gb/sysinternals/downloads/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.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is the right way to debug a threaded proc
PostPosted: Mon Nov 20, 2017 9:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 14, 2011 6:07 pm
Posts: 322
@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


Top
 Profile  
Reply with quote  
 Post subject: Re: What is the right way to debug a threaded proc
PostPosted: Mon Nov 20, 2017 10:10 pm 
Online
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2485
Location: Boston, MA
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.

_________________
Intelligence is like underwear. It is important to have it, but showing it to the wrong people has the tendency to make them feel uncomfortable. ~ Angela Johnson


Top
 Profile  
Reply with quote  
 Post subject: Re: What is the right way to debug a threaded proc
PostPosted: Mon Nov 20, 2017 11:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Feb 12, 2006 10:06 pm
Posts: 624
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


Top
 Profile  
Reply with quote  
 Post subject: Re: What is the right way to debug a threaded proc
PostPosted: Tue Nov 21, 2017 10:29 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 14, 2011 6:07 pm
Posts: 322
@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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: netmaestro and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye