Naming threads for debugging

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
a-s-z
Posts: 106
Joined: Wed 03 Dec 2008 06:01

Naming threads for debugging

Post by a-s-z » Thu 21 Jan 2010 09:03

Hi,

is it possible to make use of NameThreadForDebugging/NameThread functions for any background thread created by Odac, e.g. DBMonitor send thread?
This would be a nice feature for debugging programs using Odac.

Here is a code snippet:

Code: Select all

type
  tagTHREADNAME_INFO = record
    dwType     : LongWord;  // Must be 0x1000.
    szName     : PAnsiChar; // Pointer to name (in user addr space).
    dwThreadId : LongWord;  // Thread ID (-1=caller thread).
    dwFlags    : LongWord;  // Reserved for future use, must be zero.
  end;

procedure NameThreadForDebugging (threadId: dword; threadName: AnsiString);
const
  MS_VC_EXCEPTION = $406D1388;
{$ifdef VER7P} var tni : tagTHREADNAME_INFO; {$endif}
begin
  {$ifdef VER7P}
    if (threadName  '') and (DebugHook  0) then begin
      tni.dwType     := $1000;
      tni.szName     := PAnsiChar(threadName);
      tni.dwThreadID := threadID;
      tni.dwFlags    := 0;
      try
        RaiseException(MS_VC_EXCEPTION, 0, SizeOf(tni) div SizeOf(LongWord), @tni);
      except end;
    end;
  {$endif}
end;
Usage in thread method (e.g. DBMonitor send thread):

Code: Select all

NameThreadForDebugging($FFFFFFFF, 'DBMonitor send thread')

Post Reply