Jump to content
Lars Fosdal

Cross platform version of Windows.WinAPI.IsDebuggerPresent ?

Recommended Posts

Is there a cross-platform version of IsDebuggerPresent?  I want to disable some of my automatic maintenance threads when the app is running under a debugger, now also for a FireMonkey app.

Share this post


Link to post
var
  IsCrossPlatformDebuggerPresent: Boolean;
begin
  IsCrossPlatformDebuggerPresent := System.DebugHook <> 0;
end;

 

Share this post


Link to post

Too easy @TiGü:

Quote

[dcc64 Warnung] Project26.dpr(24): W1002 Symbol 'DebugHook' ist plattformspezifisch

 

Share this post


Link to post
17 minutes ago, Sherlock said:

To easy @TiGü:

 

But as we can see in the 

class procedure TThread.NameThreadForDebugging(AThreadName: string; AThreadID: TThreadID);

there are following lines:

...
{$ELSEIF Defined(ANDROID)}
  if (System.DebugHook <> 0) or (getenv(EMBDBKPRESENTNAME) <> nil) then
{$ELSE}
...

So, i guess it's defined for Windows and Android and working on both platforms.

 

Hast du wirklich deine IDE auf Deutsch gestellt?  

Share this post


Link to post
1 minute ago, TiGü said:

Hast du wirklich deine IDE auf Deutsch gestellt?  

😄

BTT: Windows and Android are not all the supported platforms, hence the warning.

Share this post


Link to post
6 hours ago, TiGü said:

var
  IsCrossPlatformDebuggerPresent: Boolean;
begin
  IsCrossPlatformDebuggerPresent := System.DebugHook <> 0;
end;

 

Even on windows, IsDebuggerPresent is not the same as System.DebugHook <> 0. The former tests for any debugger, the latter tests for the Emba debugger.

Share this post


Link to post
18 hours ago, David Heffernan said:

Even on windows, IsDebuggerPresent is not the same as System.DebugHook <> 0. The former tests for any debugger, the latter tests for the Emba debugger.

That's good to know! Thank you for the clarification. 

I stumbled upon this interesting blog post:

https://xorl.wordpress.com/2017/11/20/reverse-engineering-isdebuggerpresent/

 

There must be similar mechanics on iOS, Android, Linux and macOS. I personally know too little about that. 😞

Share this post


Link to post

Hm...in Delphi Tokyo we can find in SysSysctlTypes.inc:

 

(* TODO -otgerdes -cTranslate: kinfo_proc (needs proc.h)
struct kinfo_proc {
        struct  extern_proc kp_proc;                    // proc structure
        struct  eproc {
                struct  proc *e_paddr;          // address of proc
                struct  session *e_sess;        // session pointer
                struct  _pcred e_pcred;         // process credentials
                struct  _ucred e_ucred;         // current credentials
                struct   vmspace e_vm;          // address space
                pid_t   e_ppid;                 // parent process id
                pid_t   e_pgid;                 // process group id
                short   e_jobc;                 // job control counter
                dev_t   e_tdev;                 // controlling tty dev
                pid_t   e_tpgid;                // tty process group id
                struct  session *e_tsess;       // tty session pointer
#define WMESGLEN        7
                char    e_wmesg[WMESGLEN+1];    // wchan message
                segsz_t e_xsize;                // text size
                short   e_xrssize;              // text rss
                short   e_xccount;              // text references
                short   e_xswrss;
                int32_t e_flag;
#define EPROC_CTTY      0x01    // controlling tty vnode active
#define EPROC_SLEADER   0x02    // session leader
#define COMAPT_MAXLOGNAME       12
                char    e_login[COMAPT_MAXLOGNAME];     // short setlogin() name
#if CONFIG_LCTX
                pid_t   e_lcid;
                int32_t e_spare[3];
#else
                int32_t e_spare[4];
#endif
        } kp_eproc;
};
*)

 

Share this post


Link to post

Funny, the embedded PASCAL code editor don't recognized the (* and *) comments.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×