[Github-comments] [geany/geany-plugins] How to debug a multithread application [ Debugger / gdb ] (#1069)

avafinger notifications at github.com
Mon Apr 4 14:29:24 UTC 2022


@nomadbyte 

I tested your fix with the sample thread2.c (attached). Here are my findings:
1. No more hangs (fixed!)
2. It now debugs the thread in the same context, well, that depends on the concept, let me try to explain below:

Threads are not predictable, but in the sample, Thread[0] will always finish first, because it is fired first, in theory.

**First run:**
```
./thread2
Thread[0] created successfully
Thread[0] processing...
Inside First thread: Thread[0]
Thread[1] created successfully
Thread[1] processing...
Inside Second thread: Thread[1]
Thread[0]: 0x7f102b58b700 [ x = 0xFFFFFFFF ]
Thread[0] finished successfully with status: 0
Thread[1]: 0x7f102ad8a700 [ x = 0xFFFFFFFF ]
Thread[1] finished successfully with status: 1
```
**Second run:**
```
./thread2
Thread[0] processing...
Inside First thread: Thread[0]
Thread[0] created successfully
Thread[1] created successfully
Thread[1] processing...
Inside Second thread: Thread[1]
Thread[0]: 0x7f6cbc155700 [ x = 0xFFFFFFFF ]
Thread[0] finished successfully with status: 0
Thread[1]: 0x7f6cbb954700 [ x = 0xFFFFFFFF ]
Thread[1] finished successfully with status: 1
```
 
So we can assume that. Maybe **printf** is not the best thing to use in the example.

Now let's build and put a breakpoint on lines 25 and 34. 
Add variable **i** to Watch and debug.
In my assumption, if I am right, when the first thread (Thread[0] or Thread[1] does not matter which one) hit the breakpoint (line 25) and you now can watch the value of **i**, if you do a **[Step Over]** and since we should be in the same context, variable **i** should not change until we exit the thread. Why? because we want to debug this thread (the first hit).

But it switches to the new context when the next thread hits the breakpoint (line 25) and if you keep pushing **[Step Over]** until the end of the thread, you can notice variable **i** does not change, but we are now on next thread context.

I think the next breakpoint hit on line 25 should be ignored and we should stay on the previous context until we exit from the thread.

I will port this sample to Visual C and compare the results and mark this Closed or make any new comments.

If anyone would like to comment on the assumption, please, be free to do so.

Anyway, @nomadbyte thank you for your work.
[thread2.c.zip](https://github.com/geany/geany-plugins/files/8410529/thread2.c.zip)



-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/1069#issuecomment-1087630994
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany-plugins/issues/1069/1087630994 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20220404/53b7b4b0/attachment.htm>


More information about the Github-comments mailing list