Recent

Author Topic: Thread local breakpoint  (Read 415 times)

Peter H

  • Full Member
  • ***
  • Posts: 142
Thread local breakpoint
« on: November 26, 2020, 11:51:45 am »
Hello,

How can I set a breakpoint local to a thread?
A conditional breakpoint where the condition is "self=mythread" works for me inside derived TThread methods.
What is the best way, if the breakpoint is in a non member procedure?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6818
  • Debugger - SynEdit - and more
    • wiki
Re: Thread local breakpoint
« Reply #1 on: November 26, 2020, 01:37:44 pm »
Unfortunately this is not yet implemented.

I also cannot think of any workaround. There is a global CurrentThreadId, but its a threadvar (IIRC), and when I last tested threadvars where not marked as such in the debug info. So they can not even be inspected (afaik an fpc issue).


There may be one hack to get something. (not tested)

Compile the IDE with -dDBG_WITH_DEBUGGER_DEBUG

Now the "View > Debug Windows > Debug Output" has an input field (and a button to sent the text to the debugger).

That allows you to bypass the IDE and directly sent commands to GDB.
HOWEVER: Do NOT sent any run or step commands => That will hang your debug session.
This has no safeguards and no comfort features. This exists to help testing and developing the gdb integration.

You can then sent
  break unit1.pas:31 thread 2

This break will not show up in the IDE, but it should stop.


Patches to help integrating thread control in the debugger are welcome.

Peter H

  • Full Member
  • ***
  • Posts: 142
Re: Thread local breakpoint
« Reply #2 on: November 26, 2020, 03:18:13 pm »
Thank you, you got me on the right track with this.

I use now this helper proc:
Code: Pascal  [Select][+][-]
  1. procedure testproc;
  2.  var a:integer;
  3. begin
  4.   if TThread.currentthread = th then
  5.     a :=0;  // dummy assignment to set breakpoint here
  6.             // you cannot write "exit" instead, doesnt work, probably due to optimization?
  7. end;
"th" is a global helper variable, it points to the TThread instance.

I would be glad to contribute to the debugger, but I fear I dont have the skills, I am just playing around. :-[
However the main problem to solve is the debugger doesnt understand properties; TThread.currentthread is a property.
If this where possible then "TThread.currentthread=th" could be used as a breakpoint condition.
« Last Edit: November 27, 2020, 01:30:52 pm by Peter H »

Peter H

  • Full Member
  • ***
  • Posts: 142
Re: Thread local breakpoint
« Reply #3 on: November 26, 2020, 07:44:45 pm »
I added "DBG_WITH_DEBUGGER_DEBUG" to configure build Lazarus defines, set the checkmarks and rebuilt "normal IDE".
But no input field appears in the Output Window.
I also tried other ways, but without success.
Did I do it wrong, or was the feature removed or has it changed?
My version:
Lazarus 2.1.0 r64158M FPC 3.3.1 x86_64-win64-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6818
  • Debugger - SynEdit - and more
    • wiki
Re: Thread local breakpoint
« Reply #4 on: November 26, 2020, 08:19:35 pm »
Maybe the wrong "Output Window" ?

In 2.1.0 its in the menu under: View > Ide Internals > Debug Output
(You know its the right window, if it displays gdb output as soon as you start debugging.)

This only works with the gdb based debugger. The window will be empty with fpdebug, and sending gdb commands to fpdebug will
have no effect either.


Quote
I added "DBG_WITH_DEBUGGER_DEBUG" to configure build Lazarus defines, set the checkmarks and rebuilt "normal IDE".
Sounds correct.
Maybe try a "clean" build?

Peter H

  • Full Member
  • ***
  • Posts: 142
Re: Thread local breakpoint
« Reply #5 on: November 26, 2020, 09:05:59 pm »
I already found the output window, this was not the problem.
I choose now "Clean up and build all" and additionally checked the radio button "Clean all".
This does the trick apparently, thank you!

I post the image for others who might be interested as a reference.
« Last Edit: November 26, 2020, 09:41:01 pm by Peter H »

 

TinyPortal © 2005-2018