Recent

Author Topic: An alternative way of debugging FPC executables in Windows  (Read 8382 times)

440bx

  • Hero Member
  • *****
  • Posts: 3921
An alternative way of debugging FPC executables in Windows
« on: July 24, 2018, 03:01:22 pm »
Hello,

I wasn't sure where to put this information, I hope this is a reasonably good place for it.  It only applies to Windows.

Lazarus does a very nice job using GDB to debug at the source code level.  When having to debug at the assembly level, GDB makes the process painful and clumsy.  It gets worse, close to unusable, when one needs to step through system dlls.

There is a little utility, cv2pdb, which can convert DWARF debug information to PDB information and store it in a separate PDB file.  Then to debug the executable, one only needs to do "devenv exename.exe" and Visual Studio will load the executable, allow source level debugging and full assembly level debugging along with the PDB files it can automatically download when stepping through system dlls.

The process has some limitations.   The debugging experience isn't as full as when the exe was developed in VS itself but, for assembly level debugging, it's way better than GDB.   It should also be possible to use WinDbg for those cases when system information is really needed.

I attached a screenshot of VS2017 debugging a simple GUI app.

the url where to find cv2pdb is https://github.com/rainers/cv2pdb
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: An alternative way of debugging FPC executables in Windows
« Reply #1 on: August 21, 2018, 11:21:41 pm »
Thanks, @440bx

This is very helpful.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: An alternative way of debugging FPC executables in Windows
« Reply #2 on: August 21, 2018, 11:36:11 pm »
Thanks, @440bx

This is very helpful.
I'm pleased you found it useful.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: An alternative way of debugging FPC executables in Windows
« Reply #3 on: August 21, 2018, 11:39:20 pm »
While I full agree, the asm debugging in the IDE is missing a lot. Depending on how much asm you need, there is another little trick.

1) In Lazarus 1.9 in the global options you can change between Intel and ATT asm.

2) Use the power button in the asm window. Enlarge the window, so it loads plenty of lines of asm. Then power off. Now you can quickly step as the window caches the asm content. But if you step outside the current view, you need to power on, to load the new lines, then power off again.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: An alternative way of debugging FPC executables in Windows
« Reply #4 on: August 21, 2018, 11:40:42 pm »
Btw, it would be nice to keep such info on the wiki. Maybe a page "Alternative Debuggers" should be created.

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: An alternative way of debugging FPC executables in Windows
« Reply #5 on: August 22, 2018, 12:24:40 am »
Martin, I agree with you.

The things that make asm debugging with GDB "inconvenient" is that the data one wants to look at is either, not available, or it takes a fair amount of work to get to it, e.g, multiple memory windows, registers always visible and in hex.  The watches window in VS is really convenient.  Having symbols for the system DLLs is quite often very convenient too.

I haven't "promoted" (so to speak) the VS debugger because, there are some significant downsides to using it.  For instance, quite often the assembly code and the source are not in synch, that can be a real problem for some people.  Many subroutine names have a generic "call publicxxxx" which is not very informative.  It's useful for someone who is comfortable with raw assembler but, could likely be very frustrating for someone who isn't.

The cv2pdb is a nice utility but, there is room for improvement in it.  I've thought about improving it quite a few times but, MS makes it "laborious" to develop and test a utility of that kind because of the many dll dependencies.  It really doesn't make it easy for a utility of that kind to operate properly.

Ideally, there would be a full fledged, graphical, standalone debugger 'a la VS2017' available for FPC but, that's no "breakfast" project. 

I'm just thinking out loud.  I think the debugger is the "achille's heel" of the FPC/Lazarus environment and, it isn't one that is easily and quickly fixed.  That said, the current implementation is very usable and often sufficient.

If there was a debugger like VS2017's available for FPC/Lazarus, I doubt I'd write another line of C. 

I miss SoftICE... really miss SoftICE.  I still have a Windows XP installation with SoftICE and Delphi2.  SoftICE understood Delphi2's debugging symbols which makes it possible to debug at source level while having assembly and all the power of a system level debugger at one's fingertips.  That's nirvana... can't give it up, even though now it is rarely genuinely useful.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JernejL

  • Jr. Member
  • **
  • Posts: 92
Re: An alternative way of debugging FPC executables in Windows
« Reply #6 on: August 22, 2018, 09:44:20 am »
i've been debugging in windbg in past because my project uses a dll which had to be debugged, and this looks like it can help make that experience much better if i need it again, on the other hand if lazarus + GDB supported pdb debug symbols.. i could just debug it in lazarus itself :)
 

JernejL

  • Jr. Member
  • **
  • Posts: 92
Re: An alternative way of debugging FPC executables in Windows
« Reply #7 on: September 12, 2018, 09:30:46 am »
I've tried this in order to profile my game. Visual studio 2013 did not load the PDBs if you use external debug symbols file:
 
Profiling finished.
Failed to load symbols for J:\AppBuilder\Top Down City\Game\tdc.exe.
 
After compiling dwarf2 debug symbols INTO the program ( without -Xg ) it worked:
 
Profiling finished.
Loaded symbols for J:\AppBuilder\Delfi\Top Down City\Game\tdc.exe.
 
So there's that - keep that in mind.
 
See attachment, that's result of a simple sampling profiling of 32 bit lazarus app in visual studio 2013.
 

JernejL

  • Jr. Member
  • **
  • Posts: 92
Re: An alternative way of debugging FPC executables in Windows
« Reply #8 on: September 12, 2018, 07:06:06 pm »
This is one of weirdest things i've done.. Since valgrind is not availible on windows, gprof cannot link to cygwin/mingw in fpc to be of any use, and the various source-injector profilers availible for lazarus don't work very well (FPProfiler) or are bizzarely complex to install (LazProfiler).
 
It turns out that cv2pbdb + visal studio 2013 is a really decent environment for code profiling on windows, it works very well, and reliably, we should write up a tutorial for the wiki.
 

 

TinyPortal © 2005-2018