Windows: SetThreadDebugName does not work lazarus / 12-Debugger ---------------------------------------------------------------------- Pascal · 2022-04-04 09:06 Is there a way to make SetThreadDebugName (TThread.NameThreadForDebugging) work for Windwos 10 x86_64 with fpdebug? ---------------------------------------------------------------------- Martin_fr · 2022-04-04 09:29 You mean to display the name in the IDE thread window? That is not yet implemented. So the (technically correct) answer is: "Yes, the way is to implement it in FpDebug". ---------------------------------------------------------------------- Pascal · 2022-04-04 10:24 So SetThreadDebugName (TThread.NameThreadForDebugging) works but the reading of the name in the IDE thread windows is not implemented atm, right? ---------------------------------------------------------------------- Martin_fr · 2022-04-04 10:39 Quote from: Pascal on April 04, 2022, 12:24:02 pmSo SetThreadDebugName (TThread.NameThreadForDebugging) works but the reading of the name in the IDE thread windows is not implemented atm, right? I don't know if SetThreadDebugName  works, I never tested / used it. (googling msdn it seems to be SetThreadDescription ?) I don't know if gdb has any support for it, so I don't know if it can be tested there.   (I did assume that you may have tested that, since you did ask specifically fpdebug only?) I have to check, but I thing the frontend gets a string for the thread id. So that could be used to make the frontend display it. ---------------------------------------------------------------------- PascalDragon · 2022-04-04 11:19 SetThreadDebugName is the name of the low level function of the RTL. The classic way to set the thread name for the debugger is to raise a specific exception and the debugger captures it (see RaiseMSVCExceptionMethod in rtl/win/systhrd.inc). SetThreadDescription which is only available in newer versions of Windows 10 is used if available as well as it is not dependant on whether a debugger is present or not (you'd then need to use GetThreadDescription on a handle of the thread in question). ---------------------------------------------------------------------- Pascal · 2022-04-04 11:25 Okay, thanks. I'll try to implement it. ---------------------------------------------------------------------- Martin_fr · 2022-04-04 12:44 If you do, consider the following please. components\fpdebug\fpdbgwinclasses.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TDbgWinThread = class(TDbgThread) Windows specific code only goes into: TDbgWinThread If a new field is needed to store the name, that should go into: TDbgThread (since in future other OS may use it too) Currently the Thread has  FHandle => the handle  FId => On Windows: MDebugEvent.dwThreadId Those 2 fields must be kept as they are. A new field for the name must be added: FName That new field will be set by FpDebug. It will be read in Package LazDebuggerFp when creating the threads list for the IDE. It might be an interesting idea to add a 2nd "id" like field: FNum or FThreadNum This could be assigned for each thread, as an continuously increasing number. The first/main thread will always be: 1, then the next gets 2 and so on. If a thread ends, the number disappears. It will not be re-used. The counter resets only between debug sessions. If that number is shown in the IDE too, then threads can be identified by that too. Maybe that can be added at the same time? FpDebugs mainloop is in unit FPDbgController procedure TDbgController.ProcessLoop; Windows specific processing:  function TDbgWinProcess.AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; If you only change the thread name, then the event type is deInternalContinue. ---- In LazDebuggerFp look at: procedure TFPThreads.RequestMasterData; Be aware, that data from fpDebug has to be retrieved in the worker thread TFpThreadWorkerThreadsUpdate ---- There is also procedure TFPThreads.RequestEntries; This can only access fields => i.e. this is NOT allowed to trigger any code in fpdebug. Since your data is in fields, it can be updated in this method too (you may need to add your data in BOTH methods) ----- For testing compile with -dFPDEBUG_THREAD_CHECK ---------------------------------------------------------------------- Pascal · 2022-04-04 14:16 Thanks for the in-depth hints! ---------------------------------------------------------------------- avra · 2022-04-04 22:04 In case someone is interested in old topic with similar problem (but not quite the same): https://forum.lazarus.freepascal.org/index.php/topic,32745 ---------------------------------------------------------------------- PascalDragon · 2022-04-05 07:06 Quote from: avra on April 05, 2022, 12:04:03 amIn case someone is interested in old topic with similar problem (but not quite the same): https://forum.lazarus.freepascal.org/index.php/topic,32745 That thread is the application side of this. That is already implemented. This is about the debugger side. ---------------------------------------------------------------------- Pascal · 2022-04-19 21:33 Hi Martin, i did a first try. Works for me: Please review: https://gitlab.com/fre epascal.org/lazarus/lazarus/-/tree/FpDebug_NameThreadForDebugging ---------------------------------------------------------------------- Martin_fr · 2022-04-20 07:37 Thanks. Unfortunately, it might be until next month before I get to it.