Recent

Author Topic: fpdebug stand-alone ?  (Read 11611 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
fpdebug stand-alone ?
« on: November 19, 2021, 05:58:54 pm »
Hello.

About https://wiki.freepascal.org/FpDebug.

Is it possible to compile fpdebug as stand-alone executable and use it like gdb, on console ?
If yes, how to do, I see part of code in fpc and Lazarus too.

Thanks.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #1 on: November 19, 2021, 06:14:02 pm »
There is a sample project in the fpdebug folder. But it is not maintained, and currently does not compile. It may also not be complete.
But in general, FpDebug can be used outside the IDE (like Joost's DAB version).

So it is possible, if someone writes and maintains the code.

If you are interested I can answer questions.

LazdebuggerFp would be the first point of study. So you only need the part that interacts with FpDebug.

Threading is only needed, if you wont the console-dbg-app responsive while running. E.g. if you want to be able to "interrupt" the running target app.
Because FpDebug does only return from "run" when it hits a breakpoint, or otherwise stops.
Note that on some OS (linux) all kernel calls must be in the same thread. So other threads cannot call FpDebug functions that inspect the target.
(This is part of what makes LazDebuggerFp so complex)


FpDebug will probably still undergo some changes to its API.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #2 on: November 19, 2021, 06:33:34 pm »
There is a sample project in the fpdebug folder. But it is not maintained, and currently does not compile. It may also not be complete.
But in general, FpDebug can be used outside the IDE (like Joost's DAB version).

So it is possible, if someone writes and maintains the code.

If you are interested I can answer questions.

LazdebuggerFp would be the first point of study. So you only need the part that interacts with FpDebug.

Threading is only needed, if you wont the console-dbg-app responsive while running. E.g. if you want to be able to "interrupt" the running target app.
Because FpDebug does only return from "run" when it hits a breakpoint, or otherwise stops.
Note that on some OS (linux) all kernel calls must be in the same thread. So other threads cannot call FpDebug functions that inspect the target.
(This is part of what makes LazDebuggerFp so complex)


FpDebug will probably still undergo some changes to its API.

OK, thanks Martin, I will jump into LazdebuggerFp (asap), write you later.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #3 on: November 19, 2021, 07:18:20 pm »
There is a sample project in the fpdebug folder. But it is not maintained, and currently does not compile. It may also not be complete.

OK for compiling ( after very few modif ), but seems to have problem with Json while running.
Hum, maybe too deep for me to jump into this...

 :-[
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #4 on: November 19, 2021, 07:24:48 pm »
The stand-alone console version is fpd/fpd.lpr

I haven't checked what the fpdserver does / what client it needs.


ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: fpdebug stand-alone ?
« Reply #5 on: November 19, 2021, 07:41:00 pm »
The stand-alone console version is fpd/fpd.lpr

Yes, fpd is more like a very basic gdb console application. It exposes only basic functionality, see the help listing for commands supported.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #6 on: November 19, 2021, 07:47:29 pm »
Yes, but you can add commands.

E.g. Change the stack frame (or thread) for eval commands.

You need to store the given thread/frame in the fpd app. Then get the correct context (and make sure the stackframe is prepared), and eval with that context.

The same is for a hit count on breakpoints.


At the moment, stepping after exceptions is partly done in LazDebuggerFp => that needs review, and maybe some may move into fpdebug.

Also FpDebug needs more support for dll, and setting breakpoints for dll that are not yet loaded.... But those things still have to be done from scratch.
« Last Edit: November 19, 2021, 07:49:08 pm by Martin_fr »

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #7 on: November 19, 2021, 08:05:41 pm »
The stand-alone console version is fpd/fpd.lpr

Ha, OK, after some light modifs, it compiles and run.
But while loading the binary to debug after the "run" command it crash.

Imho, it will be great to have a console fpdebug version working.

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #8 on: November 19, 2021, 08:08:10 pm »
like any threaded app on linux... uses cthreads

That is fpc, not fpdebug.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #9 on: November 19, 2021, 08:13:15 pm »
Quote
like any threaded app on linux... uses cthreads

Ooops, of course, added and it works ( but you may also add some {$ifdef unix}cthreads,{$endif}, it does not hurt  ;) )

OK, compiled with cthreads and it works.

Nice.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #10 on: November 19, 2021, 08:13:29 pm »
Since it is threaded, ensure to test with
-dFPDEBUG_THREAD_CHECK

And of course -Sa
and all the bells and whistles....


For logging, you can enable via LazLogger (you may have to add the unit), and then on either with LazLoggers command line
(wiki on LazLogger / and/or similar example at https://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session )
Or by compiling with the following defined (there may be others...)
FPDBG_BREAKPOINT_ERRORS
FPDBG_BREAKPOINTS
FPDBG_COMMANDS
FPDBG_THREADS
FPDBG_QUEUE

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #11 on: November 19, 2021, 08:18:03 pm »
Since it is threaded, ensure to test with
-dFPDEBUG_THREAD_CHECK

And of course -Sa
and all the bells and whistles....


For logging, you can enable via LazLogger (you may have to add the unit), and then on either with LazLoggers command line
(wiki on LazLogger / and/or similar example at https://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session )
Or by compiling with the following defined (there may be others...)
FPDBG_BREAKPOINT_ERRORS
FPDBG_BREAKPOINTS
FPDBG_COMMANDS
FPDBG_THREADS
FPDBG_QUEUE

OK, perfect, many thanks.
Write you later after deeper jump.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #12 on: November 19, 2021, 08:23:49 pm »
... see the help listing for commands supported.

Ho, perfect, many thanks for this.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: fpdebug stand-alone ?
« Reply #13 on: November 19, 2021, 08:36:30 pm »
Oh, and please, if you got it compiling (and added the IFDEF for LINUX), create a merge request :)

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: fpdebug stand-alone ?
« Reply #14 on: November 19, 2021, 08:52:52 pm »
Oh, and please, if you got it compiling (and added the IFDEF for LINUX), create a merge request :)


Ok, with pleasure but to make it compiles, I needed to comment this because in last release MemManager is read only.

Code: Pascal  [Select][+][-]
  1. procedure TFPDLoop.GControllerDebugInfoLoaded(Sender: TObject);
  2. begin
  3.   //TFpDwarfInfo(GController.CurrentProcess.DbgInfo).MemManager := FMemManager;
  4. end;  

Also, have to change this:

Code: Pascal  [Select][+][-]
  1. var
  2.    GController: TDbgController = nil;
  3.  
  4. implementation
  5. ...
  6. initialization
  7.   GController :=  TDbgController.Create;        
  8.  

with this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   ...  FpdMemoryTools,  // added this
  3.  
  4. var
  5.    GController: TDbgController = nil;
  6.   Gmemmanage: TFpDbgMemManager = nil; // add this
  7.  
  8. implementation
  9.  
  10. initialization
  11.   GController := TDbgController.Create(Gmemmanage);    // change this

And then the compiler is happy.
Not sure the initialization is ok, but, while running, it seems so.

Also there are some change to do to be FreeBSD compatible.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018