[Lazarus] Maybe using CodeTools to modify source code

Graeme Geldenhuys graeme at geldenhuys.co.uk
Wed May 8 13:38:04 CEST 2013


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/





More information about the Lazarus mailing list