Lars Fosdal 1792 Posted February 28, 2019 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
TiGü 21 Posted February 28, 2019 var IsCrossPlatformDebuggerPresent: Boolean; begin IsCrossPlatformDebuggerPresent := System.DebugHook <> 0; end; Share this post Link to post
Sherlock 663 Posted February 28, 2019 Too easy @TiGü: Quote [dcc64 Warnung] Project26.dpr(24): W1002 Symbol 'DebugHook' ist plattformspezifisch Share this post Link to post
TiGü 21 Posted February 28, 2019 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
Sherlock 663 Posted February 28, 2019 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
Markus Kinzler 174 Posted February 28, 2019 2 hours ago, TiGü said: Hast du wirklich deine IDE auf Deutsch gestellt? Share this post Link to post
David Heffernan 2345 Posted February 28, 2019 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
TiGü 21 Posted March 1, 2019 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
TiGü 21 Posted March 1, 2019 Okay, here we have solutions for macOS and Linux. https://stackoverflow.com/questions/2200277/detecting-debugger-on-mac-os-x It looks like easy to convert (depends of the status of the source\rtl\osx-Units). Share this post Link to post
TiGü 21 Posted March 1, 2019 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
TiGü 21 Posted March 1, 2019 Funny, the embedded PASCAL code editor don't recognized the (* and *) comments. Share this post Link to post