Sign in Join

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

Mailing lists / lazarus / 2013-05

Maybe using CodeTools to modify source code

8 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I want to ease my debugging by implementing a stand-alone tool that inserts trace calls (modified dbugintf calls) via a checkbox style treeview interface of my selected unit. Checking a method inserts a begin/end trace call pair, unchecking a method removes the trace calls.

This way I don't have to leave {$IFDEF DEBUG} code blocks in some units to debug a call stack etc. Checking and unchecking methods must be quick and fully reversible - using the same tool.

I have a basic working example (based on fpprofiler code) which uses a pascal tokenizer, and injects the trace calls - but it garbles my units code formatting, when in generates the modified code. I want the modified code to still look exactly like it did before, just with added trace calls.

For example:

Before:
=======
procedure TMainForm.Button1Clicked(...)
begin
  // do something here
end;
After:
======
procedure TMainForm.Button1Clicked(...)
begin
  SendMethodEnter('TMainForm.Button1Clicked');
  // do something here
  SendMethodExit('TMainForm.Button1Clicked');
end;

I ask Michael van Canneyt if fcl-passrc could possible be used to do something like this, but he said no.

Is there code in Lazarus (maybe CodeTools) that could be modified to do this?

My idea is that you can add trace calls, and continue coding as normal, fix bugs etc. Then when done, uncheck all methods, and trace calls are removed.

With my current implementation "continue coding as normal" is rather hard with garbled units. :(

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Martin
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
Hi, I want to ease my debugging by implementing a stand-alone tool that inserts trace calls (modified dbugintf calls) via a checkbox style treeview interface of my selected unit. Checking a method inserts a begin/end trace call pair, unchecking a method removes the trace calls. This way I don't have to leave {$IFDEF DEBUG} code blocks in some units to debug a call stack etc. Checking and unchecking methods must be quick and fully reversible - using the same tool.

Just an alternative proposal:

Do something like lazlogger does.

Have a 2nd unit "TraceToolsDummy", that defines
    procedure SendMethodEnter(Atext: string); inline;
   begin end;

empty.

fpc should not generate any code for that (unless you use open array as param)

Then you can toggle by changing the unit.

You can also tell the Lavarus IDE (1.1) to display " SendMethodEnter" in a diff color (just the name, not the whole call)

Reply by email

Graeme Geldenhuys
to Martin
Martin wrote
Do something like lazlogger does.

Thanks for the suggestion, I'll take a closer do
prefer not to leave debug code in all my units though. Otherwise I could simply continue using my code templates ('sme' and 'smx') that inserts code like

 {$IFDEF DEBUG}SendMethodEnter('SomeClass.SomeMethod');{$ENDIF DEBUG}

Also, sometimes I would like to only trace a select few methods in a class or unit. With the checkbox treeview idea that should make it very easy to do, and revert those changes when I am done.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Sven Barth
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
On 2013-05-08 12:59, Martin wrote: > Do something like lazlogger does. Thanks for the suggestion, I'll take a closer do prefer not to leave debug code in all my units though. Otherwise I could simply continue using my code templates ('sme' and 'smx') that inserts code like {$IFDEF DEBUG}SendMethodEnter('SomeClass.SomeMethod');{$ENDIF DEBUG} Also, sometimes I would like to only trace a select few methods in a class or unit. With the checkbox treeview idea that should make it very easy to do, and revert those changes when I am done.

Seems like I should indeed implement my "compiler supported tracing" somewhen :P

Regards,
Sven

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: I want to ease my debugging by implementing a stand-alone tool that inserts trace calls…
Show quoted text 30 lines
Graeme Geldenhuys hat am 8. Mai 2013 um 13:38 geschrieben: [...] For example: Before: ======= procedure TMainForm.Button1Clicked(...) begin // do something here end; After: ====== procedure TMainForm.Button1Clicked(...) begin SendMethodEnter('TMainForm.Button1Clicked'); // do something here SendMethodExit('TMainForm.Button1Clicked'); end; I ask Michael van Canneyt if fcl-passrc could possible be used to do something like this, but he said no. Is there code in Lazarus (maybe CodeTools) that could be modified to do this?

Codetools has functions to locate methods and insert/delete code. I'm not aware of a simple tool that you could use as start. Maybe I can write an example command line utility.

Show quoted text 6 lines
My idea is that you can add trace calls, and continue coding as normal, fix bugs etc. Then when done, uncheck all methods, and trace calls are removed. With my current implementation "continue coding as normal" is rather hard with garbled units. :(

Mattias

Reply by email

Martin
to Graeme Geldenhuys: Thanks for the suggestion, I'll take a closer do prefer not to leave debug code in all…
Graeme Geldenhuys wrote 14 lines
On 2013-05-08 12:59, Martin wrote: > Do something like lazlogger does. Thanks for the suggestion, I'll take a closer do prefer not to leave debug code in all my units though. Otherwise I could simply continue using my code templates ('sme' and 'smx') that inserts code like {$IFDEF DEBUG}SendMethodEnter('SomeClass.SomeMethod');{$ENDIF DEBUG} Also, sometimes I would like to only trace a select few methods in a class or unit. With the checkbox treeview idea that should make it very easy to do, and revert those changes when I am done.

Lazlogger can do selected.

It has 3 levels

LazLoggerDummy: empty methods (the ones wit open array, may generate some code, the rest should not)

LazLoggerBase: always generates code, but installs an inactive logger object (use in packages, then the project can activate it)

LazLogger: the full deal (use in project)

register an option:

var
   DBG_LOCATION_INFO: PLazLoggerLogGroup;
initialization
   DBG_LOCATION_INFO :=
DebugLogger.FindOrRegisterLogGroup('DBG_LOCATION_INFO' {$IFDEF
DBG_LOCATION_INFO} , True {$ENDIF} );
     debugln(DBG_LOCATION_INFO, 'Text');

will only log if called with commandline (or set in project) --debug-enable=DBG_LOCATION_INFO

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 6 lines
On 2013-05-08 13:37, Mattias Gaertner wrote: > > Codetools has functions to locate methods and insert/delete code. Thanks Mattias, I'll take a added an example:

components/codetools/examples/addfpprofcalls.lpr

Mattias

Reply by email