Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 1999-07

Better proposition for debug code.

16 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author
to Michael A. Hess: OK guys it seems to be 6 of one, half a dozen of another. Which way do we go at this? The…
Michael A. Hess wrote 16 lines
wrote: > > This is the default behaviour; if you set the procedural variable > 'asserterrorproc' then you can customize the behaviour; the > application just continues after the assertion handler. > > careful; the systutils unit sets the handler, and turns it into an > exception. you must be sure that sysutils doesn't override your > handler. (normally, it should not) OK guys it seems to be 6 of one, half a dozen of another. Which way do we go at this? The Assertion method does seem to be fairly clean. It is there an only compiled it when the $ASSERTION switch is turned on. Now my question is can we monitor this switch in the code? If so then we can make sure that the udebug unit is also not included in the code.

Yes:

{$IFOPT C}
   Uses UDebug;
{$endif}

But this won't work if in general assertionas are off and you do somewhere in your code:

{$ASSERTIONS ON}
  some code
{$ASSERTIONS OFF}

Assertions is a local switch, So better to include the unit always.

Michael.

Reply by email

Unknown author
to Michael A. Hess: So now are you saying that it will always abort the program? Does modifing…
Michael A. Hess wrote 11 lines
wrote: > > Correction: The default behaviour is to print the error on StdErr, and > then to continue the program. > > The sysutils unit does make it an exception. So now are you saying that it will always abort the program? Does modifing 'asserterrorproc' just change how or what is output and the exception is fired regardless or can we circumvent the exception being fired as well?
The exception will not be fired if you override the asserterrorproc;
sysutils sets its value to an internal procedure.

If you set its value, your procedure will be called, and no exception is raised.

Michael.

Reply by email

Peter Vreman
to P Jean dit Bailleul: For the macro way seems the better because the code will run the same with or without the…
Show quoted text 20 lines
> wrote: >> >> This is the default behaviour; if you set the procedural variable >> 'asserterrorproc' then you can customize the behaviour; the >> application just continues after the assertion handler. >> >> careful; the systutils unit sets the handler, and turns it into an >> exception. you must be sure that sysutils doesn't override your >> handler. (normally, it should not) > >OK guys it seems to be 6 of one, half a dozen of another. Which way do >we go at this? The Assertion method does seem to be fairly clean. It is >there an only compiled it when the $ASSERTION switch is turned on. > >Now my question is can we monitor this switch in the code? If so then we >can make sure that the udebug unit is also not included in the code. For the macro way seems the better because the code will run the same with or without the debug code. With $Assertion we may have wifferences in the way of handling exceptions.

No, just create your own assert handler.

Procedure AssertErrorHandler (Const Msg,FN : String;LineNo,TheAddr :Longint);
Var
  S : String;
begin
  If Msg='' then
    S:=SAssertionFailed
  else
    S:=Msg;
  WriteLn(StdErr,Format(SAssertError,[S,Fn,LineNo]));
end;

And init it with

;

Peter

Reply by email

Unknown author
to Michael A. Hess: But doesn't the Assert abort the application after it is called? We want to use the debug…
Michael A. Hess wrote 20 lines
Michael Van Canneyt wrote: > > Hello, > > May I remind you that the compiler supports the ASSERT() construct of Delphi; > that you can specify a > AssertErrorProc > which takes care of the asserts ? > > This means that you can have the whole debug class stuff without the > juggling with macros. > > Just do a > > Assert(False,'Some debug message'); But doesn't the Assert abort the application after it is called? We want to use the debug as a tracing feature to give us processing out of the code as it runs. This would print the Assert line and stop. Or am I misunderstanding how Assert is used in FPC?

This is the default behaviour; if you set the procedural variable 'asserterrorproc' then you can customize the behaviour; the application just continues after the assertion handler.

careful; the systutils unit sets the handler, and turns it into an exception. you must be sure that sysutils doesn't override your handler. (normally, it should not)

Michael.

Reply by email

Michael A. Hess
to Unknown author
Show quoted text 8 lines
This is the default behaviour; if you set the procedural variable 'asserterrorproc' then you can customize the behaviour; the application just continues after the assertion handler. careful; the systutils unit sets the handler, and turns it into an exception. you must be sure that sysutils doesn't override your handler. (normally, it should not)

OK guys it seems to be 6 of one, half a dozen of another. Which way do we go at this? The Assertion method does seem to be fairly clean. It is there an only compiled it when the $ASSERTION switch is turned on.

Now my question is can we monitor this switch in the code? If so then we can make sure that the udebug unit is also not included in the code.

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com

Reply by email

Michael Van Canneyt

Hello,

May I remind you that the compiler supports the ASSERT() construct of Delphi; that you can specify a
AssertErrorProc
which takes care of the asserts ?

This means that you can have the whole debug class stuff without the juggling with macros.

Just do a

 Assert(False,'Some debug message');

The assertErrorProc will then give you the line number, source file and this message.

Assert code is compiled in or not depending on the LOCAL switch:
{$ASSERTIONS ON}

So they can be switched on or off at will, if they are off, no code is even generated.

better yet; you can implement debug levels thus:

 Assert(Debug.Debuglevel>2,'Some serious error');
 Assert(Debug.DebugLevel=3,'Some esoteric error');

Just an idea; why use ugly constructs with macros if you can have more (i.e. source and line number) with this compiler construct ?

Michael.

Reply by email

Unknown author
to Unknown author: This is the default behaviour; if you set the procedural variable 'asserterrorproc' then…
Show quoted text 28 lines
On Wed, 21 Jul 1999, Michael A. Hess wrote: > Michael Van Canneyt wrote: > > > > Hello, > > > > May I remind you that the compiler supports the ASSERT() construct of Delphi; > > that you can specify a > > AssertErrorProc > > which takes care of the asserts ? > > > > This means that you can have the whole debug class stuff without the > > juggling with macros. > > > > Just do a > > > > Assert(False,'Some debug message'); > > But doesn't the Assert abort the application after it is called? We want > to use the debug as a tracing feature to give us processing out of the > code as it runs. This would print the Assert line and stop. Or am I > misunderstanding how Assert is used in FPC? This is the default behaviour; if you set the procedural variable 'asserterrorproc' then you can customize the behaviour; the application just continues after the assertion handler.

Correction: The default behaviour is to print the error on StdErr, and then to continue the program.

The sysutils unit does make it an exception.

Michael.

Reply by email

Michael A. Hess
to Unknown author
Show quoted text 5 lines
Correction: The default behaviour is to print the error on StdErr, and then to continue the program. The sysutils unit does make it an exception.

So now are you saying that it will always abort the program? Does modifing 'asserterrorproc' just change how or what is output and the exception is fired regardless or can we circumvent the exception being fired as well?

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com

Reply by email

Baeseman, Cliff

The debugging stuff should really be in the gtkint unit if you ask me we can treat it just as we do any other component code. This would allow other tool kits to implement how and where that type of thing is displayed.

Cliff

Earlier message 48 lines
-----Original Message----- From: Sent: Wednesday, July 21, 1999 8:16 AM To: Subject: Re: [lazarus] Better proposition for debug code. On Wed, 21 Jul 1999, Michael A. Hess wrote: > Michael Van Canneyt wrote: > > > > Hello, > > > > May I remind you that the compiler supports the ASSERT() construct of Delphi; > > that you can specify a > > AssertErrorProc > > which takes care of the asserts ? > > > > This means that you can have the whole debug class stuff without the > > juggling with macros. > > > > Just do a > > > > Assert(False,'Some debug message'); > > But doesn't the Assert abort the application after it is called? We want > to use the debug as a tracing feature to give us processing out of the > code as it runs. This would print the Assert line and stop. Or am I > misunderstanding how Assert is used in FPC? This is the default behaviour; if you set the procedural variable 'asserterrorproc' then you can customize the behaviour; the application just continues after the assertion handler. careful; the systutils unit sets the handler, and turns it into an exception. you must be sure that sysutils doesn't override your handler. (normally, it should not) Michael. _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

P Jean dit Bailleul
to Unknown author: This is the default behaviour; if you set the procedural variable 'asserterrorproc' then…
you wrote 16 lines
wrote: > > This is the default behaviour; if you set the procedural variable > 'asserterrorproc' then you can customize the behaviour; the > application just continues after the assertion handler. > > careful; the systutils unit sets the handler, and turns it into an > exception. you must be sure that sysutils doesn't override your > handler. (normally, it should not) OK guys it seems to be 6 of one, half a dozen of another. Which way do we go at this? The Assertion method does seem to be fairly clean. It is there an only compiled it when the $ASSERTION switch is turned on. Now my question is can we monitor this switch in the code? If so then we can make sure that the udebug unit is also not included in the code.

For the macro way seems the better because the code will run the same with or without the debug code. With $Assertion we may have wifferences in the way of handling exceptions.

JDB

les opinions et recommandations exprim�es dans ce courrier sont ceux de l'auteur, ils ne sont pas n�cessairement endoss�s par Agritulture et AgroAlimentaire Canada
-------------------------------------------------------------- Philippe JEAN DIT BAILLEUL
Agriculture & AgroAlimentaire Canada - Agriculture & AgriFood Canada Email :
Web : Http://res.agr.ca/swinenet/porcexpert/jeanditbailleulp Tel : +1 (819) 565 9174 poste 251
Fax : +1 (819) 564 5507

Reply by email

Michael A. Hess
to Michael Van Canneyt: May I remind you that the compiler supports the ASSERT() construct of Delphi; that you…
Michael Van Canneyt wrote 14 lines
Hello, May I remind you that the compiler supports the ASSERT() construct of Delphi; that you can specify a AssertErrorProc which takes care of the asserts ? This means that you can have the whole debug class stuff without the juggling with macros. Just do a Assert(False,'Some debug message');

But doesn't the Assert abort the application after it is called? We want to use the debug as a tracing feature to give us processing out of the code as it runs. This would print the Assert line and stop. Or am I misunderstanding how Assert is used in FPC?

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com

Reply by email

Peter Vreman
to Michael Van Canneyt: May I remind you that the compiler supports the ASSERT() construct of Delphi; that you…
Show quoted text 28 lines
Hello, May I remind you that the compiler supports the ASSERT() construct of Delphi; that you can specify a AssertErrorProc which takes care of the asserts ? This means that you can have the whole debug class stuff without the juggling with macros. Just do a Assert(False,'Some debug message'); The assertErrorProc will then give you the line number, source file and this message. Assert code is compiled in or not depending on the LOCAL switch: {$ASSERTIONS ON} So they can be switched on or off at will, if they are off, no code is even generated. better yet; you can implement debug levels thus: Assert(Debug.Debuglevel>2,'Some serious error'); Assert(Debug.DebugLevel=3,'Some esoteric error'); Just an idea; why use ugly constructs with macros if you can have more (i.e. source and line number) with this compiler construct ?

Even in gtk and all other big libraries asserts are used. See all the error messages from gtk you'll get, they are all assert() calls.

Peter

Reply by email

Peter Vreman
to Michael A. Hess: OK cool! I think we should opt for this method then. Hey Cliff since this is really…
Show quoted text 12 lines
> The exception will not be fired if you override the asserterrorproc; > sysutils sets its value to an internal procedure. > > If you set its value, your procedure will be called, and no exception > is raised. OK cool! I think we should opt for this method then. Hey Cliff since this is really changing how TDebug is currently designed how about if I make all the modifications to the udebug unit so that it will work with Assertions. When that is done I'll commit it to CVS and then we can start adding it to the code.

You only need a debug unit which sets the assertproc. And it only needs to be included once instead of every unit.

Peter

Reply by email

Michael A. Hess
to Peter Vreman
Peter Vreman wrote
You only need a debug unit which sets the assertproc. And it only needs to be included once instead of every unit.

Unless you want to display by debugLevels then the unit would need to include the debug unit.

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com

Reply by email

Baeseman, Cliff

yep add it to the cvs when ready...

Cliff

Earlier message 34 lines
-----Original Message----- From: Michael A. Hess Sent: Wednesday, July 21, 1999 9:43 AM To: Subject: Re: [lazarus] Better proposition for debug code. wrote: > > The exception will not be fired if you override the asserterrorproc; > sysutils sets its value to an internal procedure. > > If you set its value, your procedure will be called, and no exception > is raised. OK cool! I think we should opt for this method then. Hey Cliff since this is really changing how TDebug is currently designed how about if I make all the modifications to the udebug unit so that it will work with Assertions. When that is done I'll commit it to CVS and then we can start adding it to the code. I'll recode this tonight and add it. -- ==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

Michael A. Hess
to Unknown author: The exception will not be fired if you override the asserterrorproc; sysutils sets its…
Show quoted text 6 lines
The exception will not be fired if you override the asserterrorproc; sysutils sets its value to an internal procedure. If you set its value, your procedure will be called, and no exception is raised.

OK cool! I think we should opt for this method then. Hey Cliff since this is really changing how TDebug is currently designed how about if I make all the modifications to the udebug unit so that it will work with Assertions. When that is done I'll commit it to CVS and then we can start adding it to the code.

I'll recode this tonight and add it.

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com

Reply by email