Portable and non-deletable breakpoint lazarus / 21-General ---------------------------------------------------------------------- MarkMLl · 2021-07-13 08:03 Is there an approved way of putting something in a program which will act as a breakpoint if run under a debugger but is otherwise ignored? I don't really want to use Assert(false) since that will always raise an exception. The scenario is that I've got a fork of some old code I'm modernising gradually, it runs OK standalone but I want to mark the place I'm currently working on so that it's immediately apparent in the (Lazarus etc.) IDE. I don't want to use a standard breakpoint since this can obviously be cleared by the IDE, irrespective of any dire warnings in the source. Yesterday evening I caused myself much headscratching when I put a breakpoint on a valid line but it didn't actually trigger, at which point control headed off into (what I should have remembered was) Terra Incognita. MarkMLl ---------------------------------------------------------------------- 440bx · 2021-07-13 08:52 From your posts, I suspect you want a cross platform solution. First, I'll mention the Windows-only solution which is use IsDebuggerPresent() followed by an int 3.  Code like this: 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 if IsDebuggerPresent() then asm int 3 end;Quite simple but, unfortunately Windows only. I presume there has to be a way under other operating systems (commonly Linux) to determine if a program is being debugged, if so, just implement your own version of IsDebuggerPresent() for that platform and problem solved. HTH. ---------------------------------------------------------------------- MarkMLl · 2021-07-13 08:59 @440bx The int can be easily replaced by an Assert(false). I was pretty sure I'd seen this discussed (multiple times) before, and Google points me at https://forum.lazarus.freepascal.org/index.php?topic=46981.0 where Thaddy suggests a Linux hack via /proc... I'll experiment and report back but can't test behaviour on Mac etc. MarkMLl ---------------------------------------------------------------------- MarkMLl · 2021-07-13 09:59 This works nicely under Linux: 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 {$if not declared(IsDebuggerPresent)    } function grep(caseInsensitive: boolean; const pattern, fn: ansistring): ansistring; var  scratch: TStringList;  i: integer; begin  result := '';  if not FileExists(fn) then    exit;  scratch := TStringList.Create;  try    scratch.LoadFromFile(fn);    for i := 0 to scratch.Count - 1 do      if caseInsensitive then begin        if AnsiContainsText(scratch[i], pattern) then          exit(scratch[i])              (* Via finally                        *)      end else        if AnsiContainsStr(scratch[i], pattern) then          exit(scratch[i])            (* Via finally                          *)  finally    scratch.Free  endend { grep } ;  function isDebuggerPresent(): boolean; var  scratch: ansistring; begin  scratch := grep(true, 'TracerPid', '/proc/' + IntToStr(GetProcessID()) + '/status'); (* TracerPid has existed since at least late Linux kernel 2.x, as of 2021 it's  *)(* unreasonable to expect Lazarus/FPC to be running on anything older and while *)(* the /proc tree might be supressed on embedded systems this is unlikely to be *)(* the case on a system that might have a debugger on it. Having no TracerPid   *)(* can reasonably be interpreted as there being no active debugger, but it is   *)(* still necessary to check that it is non-zero.                              *)   if scratch = '' then    result := false  else begin    scratch := DelSpace(Tab2Space(scratch, 1));    result := Pos(':0', scratch) <> Length(scratch) - 1  endend { isDebuggerPresent } ; {$endif not declared(IsDebuggerPresent) } ...  if IsDebuggerPresent() then // Non-continuable forced breakpoint    Assert(false);   if IsDebuggerPresent() then // Continuable forced breakpoint    try Assert(false, 'Terra Incognita (here be dragons!)') except end;  Google suggests that Solaris/SunOS has something comparable but not in the same place. Can anybody speak for Macs and the BSDs? MarkMLl