Forum > Debugger

Debugger ignoring assertions

(1/3) > >>

EganSolo:
Laz 3.0, FPC: 3.2.2 win64 on win 11. Assertions are being ignored with both Gdb and fpDebug.
Running in Debug Mode with
   Checks and assertion:  all checked.
   Run uses the debugger is on
   Generate info for the debugger checked
   Debugger info: Dwarf 3 (beta)
   Generate code for valgrind: not checked
   Use external debug symbols file: checked
   Use Heaptrc: checked
   Trash variables: checked
   Generate code for gprof: not checked
   Strip symbols: not checked

Assertions to check if a pointer is nil are skipped (seemingly not compiled).
These assertions take the form:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  Assert(Assigned(P), 'P is nil'); The assertions are silently skipped and they are not raised when the pointer is nil.

What am I missing?

Thaddy:
Can it be that there is a spurious {$C-} in your app. That will override the compiler debug settings. I can not reproduce your code.
There is an easy way to test this because assertions are local, so you can do this:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ This code will override any compiler settings regarding assertions }{$PUSH}// save state{$C+}// force assertions onAssert(Assigned(P), 'P is nil');{$POP}// restore original settingsThis code will override any global settings, just for that piece of code.
Btw: I used trunk from today, i.e. 331/399 on Windows11 and dwarf3 debug settings.
But that should not matter: it always worked.

Let us know if it worked: if it does then it is likely that your code contains a directive that turns the assertions off. Either {$C-} or {$assertions off} or {$assertions-}

But beware of dangling pointers: in that case the assert thinks it is valid because P is not nil...
If that is the case, you have my permission to guard P temporalily with the dreaded FreeAndNil, if applicable, and remove that after you have determined the real cause.
( I am one of those that are of the opinion that FreeAndNil is evil because it can hide hard to debug real errors )

Remark: "Trash variables: checked" makes it likely a var is NOT nil.....
So turn that off. As per documentation its use is limited to special cases, usually to investigate stack corruption.

Martin_fr:
Assertions are done in the app itself. They happen even if there is no debugger.

But anyway, have you tried the following.

1) Set  a breakpoint immediately after the assertion. And check the value of p ?

2) Explicitly set p to nil right before the assertion?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---p := nil;Assert(Assigned(P), 'P is nil');

Thaddy:
1) Set it immediately *before* the assertion and check the value of P.
2) That won't help to diagnose the issue? Does it?

Martin_fr:

--- Quote from: Thaddy on January 25, 2024, 12:48:42 pm ---1) Set it immediately *before* the assertion and check the value of P.

--- End quote ---
After.
If we don't reach then the assertion did trigger, and we don't need to check.


--- Quote ---2) That won't help to diagnose the issue? Does it?

--- End quote ---
It will show if the assert code is inserted by the compiler.

Navigation

[0] Message Index

[#] Next page

Go to full version