Forum > Debugger

[SOLVED] Debugging dynamic (shared object) library on linux

(1/2) > >>

linvon:
Hello! I am trying debug dynamic library and having some troubles with this on linux. I have Lazarus 3.4 and FPC 3.2.2.
I have 2 separated project: for library and for application
Compiling all this things in debug mode.
Using standard debugger (FpDebug).
Loading libaray in app with LoadLibrary and getting correct lib handle.

But when i put break-point in application project debugger ingores it from app. I also tried set 'host application' in library project - no effect.
Can you help me please?

Martin_fr:
I don't currently have 3.4 installed on Linux. Only 3.99.  (testing with Fedora 38)

There were some fixes, but I don't know if they cover your case. E.g.:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40973

In any case in 3.99 it worked both ways
- Using the library project and setting host application
- Using the host project and just loading the library (if that is compiled with debug info)

My test code:

Host project:

--- 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";}};} ---program project1; {$mode delphi}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes, dynlibs; var  hl:TLibHandle;  hello_lib:function(const pc:PAnsiChar):integer;begin   writeln('Start test');  hl:=LoadLibrary({$ifdef LINUX}'./libproja.so'{$endif}     {$ifdef MSWINDOWS}'./proja.dll'{$endif}     );  if hl>0 then  begin    @hello_lib:=GetProcAddress(hl,'hello_lib');    if Assigned(hello_lib) then    hello_lib('Out form lib OK');  end;end.
lib:

--- 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";}};} ---library proja; {$mode delphi}{$H+}  function hello_lib(const pc:PAnsiChar):integer;begin  Result:=0;  writeln(pc);end; exports  hello_lib;end.
When debugging the host project, and the library has not yet been loaded, then the breakpoint shows as "paused" (a red dot, whit 2 green/yellow bars (like pause on a music player). And then becomes active when the lib is loaded.

I haven't tested what happens if there are units of the same name in both the host, and the lib... IIRC it should work.

I need more info on your case.
- Do you at least get the "paused" breakpoint?
- If you open the debugger "event log" does it say something like "Loaded: libfoo.so (/path/to/libfoo.so)"

linvon:
Yes, I have "paused" breakpoints, but nothing in "event log".
However, the library works, I just can't debug it.

Martin_fr:
What is your exact Linux environment?

Maybe something changed in one of the involved libraries.

You can always try to debug your app using the gdb backend. But that has of course other limits.

linvon:
I will look for the environment.
But with gdb same behaviour.

Navigation

[0] Message Index

[#] Next page

Go to full version