multithread debugging questions

General FreeBASIC programming questions.
riemann
Posts: 1
Joined: Sep 16, 2013 3:06

multithread debugging questions

Postby riemann » Sep 16, 2013 3:44

Dear All:

I want to use fbc.exe, gdb.exe and pipe(in win32) to write a FreeBASIC IDE, like FbEdit. but when I use FbEdit debugging a multithread program its works not very well. so I use (mingw)gdb and (cygwin)gdb in win32 to debug the program, some times it will receive signal like:

message 1:
(gdb)c
Continuing.
Program received signal SIGTRAP, Tracepoint trap.
[Switching to Thread 3596.0xa0c]
0x00401820 in fb_Sleep@4 ()
(gdb)

message 2:(mingw gdb will show this message frequently, cygwin gdb is ok)
Breakpoint 2, TASK2 () at task2.bas:4
4 j += 1
(gdb) Exception condition detected on fd 0
error detected on stdin
A debugging session is active.

Inferior 1 [process 5064] will be killed.

Quit anyway? (y or n) y
//----------------------------------------------------------
the testing code and cmd as follow

fbc.exe -g main.bas task1.bas task2.bas task3.bas
gdb.exe main.exe

//------------------------------------------------------------------
'main.bas
#define TASK_1
#define TASK_2
#define TASK_3
'....
'#define TASK_max
'initialize environment
'...
'create and run thread
#ifdef TASK_1
Declare Sub task1(byval num as any ptr)
Dim pt1 As Any Ptr = ThreadCreate(@task1,cast(any ptr,0)) 'ThreadCall task1()
#endif
#ifdef TASK_2
Declare Sub task2(byval num as any ptr)
Dim pt2 As Any Ptr = ThreadCreate(@task2,cast(any ptr,0)) 'ThreadCall task2()
#endif
#ifdef TASK_3
Declare Sub task3(byval num as any ptr)
Dim pt3 As Any Ptr = ThreadCreate(@task3,cast(any ptr,0)) 'ThreadCall task3()
#endif
'waiting for thread exit
#ifdef TASK_1
ThreadWait pt1
#endif
#ifdef TASK_2
ThreadWait pt2
#endif
#ifdef TASK_3
ThreadWait pt3
#endif
'release environment
'...
//------------------------------------------------
'task1.bas/task2.bas/task3.bas
Sub task1(byval num as any ptr)
Dim x as integer = 0
For i As Integer = 1 To 10
x += 1
'Print "task1 i=";i
Sleep 500
Next
End Sub


regards,
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: multithread debugging questions

Postby Gonzo » Sep 16, 2013 5:20

maybe wrong gdb version?
nothing wrong with your code.. check gcc version used to build fb, compare with expected gdb version and libs
dodicat
Posts: 5990
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: multithread debugging questions

Postby dodicat » Sep 16, 2013 23:42

If you make your print into one statement, and your sleep into non interrupt mode then at least your code runs all the way through.

I am no expert on threads, but I would say that care is needed to make sure that code in subroutines is in blocks, inasmuch that execute a thing wholly without allowing possible deviations.
Sleep 500 on it's own , I think allows a portal for a key press, but you don't want that option, so dismiss it by using sleep 500,1
Also, just print one thing wholly, and perhaps avoid using print "something"; blah ... blah.
Your code:

Code: Select all

 
'main.bas
#define TASK_1
#define TASK_2
#define TASK_3
'....
'#define TASK_max
'initialize environment
'...
'create and run thread
#ifdef TASK_1
Declare Sub task1(byval num as any ptr)
Dim pt1 As Any Ptr = ThreadCreate(@task1,cast(any ptr,0)) 'ThreadCall task1()
#endif
#ifdef TASK_2
Declare Sub task2(byval num as any ptr)
Dim pt2 As Any Ptr = ThreadCreate(@task2,cast(any ptr,0)) 'ThreadCall task2()
#endif
#ifdef TASK_3
Declare Sub task3(byval num as any ptr)
Dim pt3 As Any Ptr = ThreadCreate(@task3,cast(any ptr,0)) 'ThreadCall task3()
#endif
'waiting for thread exit
#ifdef TASK_1
ThreadWait pt1
#endif
#ifdef TASK_2
ThreadWait pt2
#endif
#ifdef TASK_3
ThreadWait pt3
#endif
'release environment
'...
'------------------------------------------------

'task1.bas/task2.bas/task3.bas
Sub task1(byval num as any ptr)
Dim x as integer = 0
For i As Integer = 1 To 10
x += 1
Print "task1 i= " &i
Sleep 500,1
Next
End Sub

Sub task2(byval num as any ptr)
Dim x as integer = 0
For i As Integer = 1 To 10
x += 1
Print "task2 i= "&i
Sleep 500,1
Next
End Sub

Sub task3(byval num as any ptr)
Dim x as integer = 0
For i As Integer = 1 To 10
x += 1
Print "task3 i= "&i
Sleep 500,1
Next
End Sub
print "DONE"
sleep
 

But, as I say, I am no expert at this.
dodicat
Posts: 5990
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: multithread debugging questions

Postby dodicat » Sep 18, 2013 10:08

riemann.
I cannot get gdb to work with any freebasic .exe.
I use the fb-.0.9.1-mingw freebasic build, and flag -gen gcc to compile with the -g option of course.

and, gdb/gcc versions:

(gdb) show version
GNU gdb (GDB) 7.5

gcc (GCC) 4.7.2

I get this:
Error creating process
, (error 193).
(gdb)

gdb works ok with executables created directly by gcc, i.e. code written in c
strange!
SARG
Posts: 909
Joined: May 27, 2005 7:15
Location: FRANCE

Re: multithread debugging questions

Postby SARG » Sep 18, 2013 12:52

@riemann
Have you tried fbdebugger ? It can manage threads but I'm always curious if there are bugs....
Fbdebugger

Return to “General”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest