Recent

Author Topic: debugging FCL modules  (Read 9604 times)

dmitryb

  • Jr. Member
  • **
  • Posts: 62
debugging FCL modules
« on: April 21, 2014, 12:13:23 am »
How to debug debug FCL components.
I want to go through TDataset and other components when I debug my app.
I read about it here:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#How_can_I_debug_FCL_components_from_packages_with_Lazarus
so I recompiled FCL package with checkbox - (-gl) (look at the screenshot) and recompiled my app
but still the debuger (F7) skip TDataset methods.
« Last Edit: April 22, 2014, 12:29:32 pm by dmitryb »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: debug FCL modules
« Reply #1 on: April 21, 2014, 12:33:16 am »
TDAtaSet itself is in
  FPC\packages\fcl-db\src\base\db.pas

That would mean, you must recompile FPC.

That is not possible with the fpc that comes with Lazarus as it does not contain the makefiles, you nee to download a full Version with Makefiles.

BUT there is another way.

First: Do NOT / NEVER make changes inside the fpc folder, that comes with Lazarus


1) Make a copy of the folder  FPC\packages\fcl-db\
2) Remove ppu and o files from this folder (from the copy)
3) either create a package for this folder, or add the sources ( \packages\fcl-db\src\ and sub folders) to your project.
Easiest is to just add the source containing folders to your project unit search path. [1]
4) Rename, or move the original folder, so it will not be found (yes that is an exception to the "never" rule above). After the debug session you need to restore it, so other projects will have it.

Now if you build your project, it should use the copied sources. And you can debug them.

---
[1] Maybe you have to add it to the unit search path of the FCL package instead
« Last Edit: April 21, 2014, 12:41:52 am by Martin_fr »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: debug FCL modules
« Reply #2 on: April 21, 2014, 01:48:55 am »
Quote
That would mean, you must recompile FPC.

That is not possible with the fpc that comes with Lazarus as it does not contain the makefiles, you nee to download a full Version with Makefiles.
Actually, the Makefiles in packages still exist. So one just need to go inside respective package folder (or top level packages if all packages are going to be recompiled) and make from there.

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: debug FCL modules
« Reply #3 on: April 21, 2014, 11:15:24 am »
Quote
That would mean, you must recompile FPC.

Yes, I think I want to recompile the whole FPC.
I want to have a possibility to debug db.pas and other FCL modules from all applications.
How can I do it? If I need to download a full Version where can I get it?
There are no something about full version on the official download page:
http://www.lazarus.freepascal.org/index.php?page=downloads

I noticed an interesting thing.
with code

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Dbf1.Open;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Button1.Caption := 'Button1New';
end;

Using (F7), I can go into SetText method for "Button1.Caption" but I can't
go into TDataSet.Open.
So it means that LCL is compiled with Debug Info and FCL without.

Why did they do so?
Why they build Lazarus installer that only a part of the code can be debugged.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: debug FCL modules
« Reply #4 on: April 21, 2014, 04:55:06 pm »
Quote
How can I do it? If I need to download a full Version where can I get it?
http://sourceforge.net/projects/freepascal/files/Source/
Quote
Why did they do so?
Why they build Lazarus installer that only a part of the code can be debugged.
Because only LCL belongs to Lazarus. FCL is part of FPC. Lazarus can only control LCL (though FCL is registered as built-in package in Lazarus).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: debug FCL modules
« Reply #5 on: April 21, 2014, 05:45:24 pm »
Actually, the contained FPC is build from sources for the installer.

But those packages being part of FPC, does explain why they are not individual Lazarus packages, that can be rebuild from within the IDE, like the LCL.

Adding debug info there too, would massively increase the size of the installer, and very few people will need it.

In fact adding debug info there would annoy most people. If you build the entire FCL and RTL with debug info, and you step your app, then you also step into AnsiStringIncRef/DeRef and other helpers.

SomeString := SomeFunc(OtherString);

Stepping with F7, will not (immediately) enter SomeFunc, but go into AnsiStringIncRef first.
Then you must use F7 at the end of AnsiStringIncRef to step to SomeFunc. If you use F8 at the end of AnsiStringIncRef you will never step to SomeFunc.

So an RTL with debug info, would annoy 99% of the users. The line needs to be drawn somewhere, FCL could be either way. But RTL and FCL ace build together, with one call to "make". Splitting this up would be a lot of work.


There are tools like fpup (or fpcup?), that can help maintain your self build copies of fpc and Lazarus. (search forum and wiki)


dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: debug FCL modules
« Reply #6 on: April 22, 2014, 12:22:12 pm »
Ok. I will try to install the whole FPC.

But now I would like to check the second method of debuging some of FPC files.
Method of copying files in the project directory.

I have a run time error "EReadError" in the method procedure TReader.ReadListEnd;

So I copied files

From C:\Lazarus\fpc\2.6.2\source\rtl\objpas\classes\
action.inc
bits.inc
classes.inc
classesh.inc
collect.inc
compon.inc
constsg.inc
constss.inc
cregist.inc
dm.inc
filer.inc
intf.inc
lists.inc
parser.inc
persist.inc
reader.inc
resref.inc
sllist.inc
streams.inc
stringl.inc
tthread.inc
twriter.inc
util.inc
writer.inc

From C:\Lazarus\fpc\2.6.2\source\rtl\win32\
classes.pp

to the directory of my project and tried to compile it:

I got compilation error:
FclSrc\classes.pp(80,1) Fatal: Selected assembler reader not supported

on the line
Code: [Select]
function TrampolineWndProc(Window: HWND; Message, WParam: WPARAM;LParam: LPARAM): HRESULT; stdcall; assembler;
asm

how to fix it?

Chaning Assembler style to Intel or AT&T in the project Options doesn't help.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: debug FCL modules
« Reply #7 on: April 22, 2014, 12:55:48 pm »
Stepping with F7, will not (immediately) enter SomeFunc, but go into AnsiStringIncRef first.
Then you must use F7 at the end of AnsiStringIncRef to step to SomeFunc. If you use F8 at the end of AnsiStringIncRef you will never step to SomeFunc.

So an RTL with debug info, would annoy 99% of the users. The line needs to be drawn somewhere, FCL could be either way. But RTL and FCL ace build together, with one call to "make". Splitting this up would be a lot of work.

On targets where debug symbols are weakly linked, building the snapshot with debuginfo, backing up the .o's of system, objpas, sysutils and optionally classes and then stripping those .o's is a good remedy for that.


dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: debugging FCL modules
« Reply #8 on: April 22, 2014, 01:50:41 pm »
Quote
In fact adding debug info there would annoy most people. If you build the entire FCL and RTL with debug info, and you step your app, then you also step into AnsiStringIncRef/DeRef and other helpers.

Yes, I don't need this low level debugging
But such classes as TDataSet, TStream, TFiler, TReader, TWriter, TComponent are classes where I constantly work when debugging.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: debugging FCL modules
« Reply #9 on: April 22, 2014, 02:10:04 pm »
Delphi actually has (had?) {$D} switch. It allows to disable debugging information per unit. I don't think the switch is supported by FPC currently.

I presume the behavior of the switch could be handled on the debugger level. So it could skip stepping through lines of a unit "excluded" from the debugging.
Implementation of "exclusion" list at the debugger level provides more flexibility, since a compiled unit could still maintain the debugging information.

Something similar is actually happening right now, when a debugger doesn't have a source for a module :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: debug FCL modules
« Reply #10 on: April 22, 2014, 05:30:36 pm »
Ok. I will try to install the whole FPC.

But now I would like to check the second method of debuging some of FPC files.
Method of copying files in the project directory.

<skip>

to the directory of my project and tried to compile it:

I got compilation error:
FclSrc\classes.pp(80,1) Fatal: Selected assembler reader not supported

on the line
Code: [Select]
function TrampolineWndProc(Window: HWND; Message, WParam: WPARAM;LParam: LPARAM): HRESULT; stdcall; assembler;
asm

how to fix it?

Chaning Assembler style to Intel or AT&T in the project Options doesn't help.
Short answer: it's not that easy, copying to project directory doesn't always work, especially for rtl units. If you've ever tried the Makefile, and watch it as the compilation goes on, you'll notice the script passes several options to the compiler while compiling.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: debugging FCL modules
« Reply #11 on: April 22, 2014, 07:00:21 pm »
Newer GDB have a command, that allows to specify functions that are ignored when stepping in.

But IDE support is yet missing.

 

TinyPortal © 2005-2018