It took me a bit longer than expected to get here but I believe I've finally reached the goal.
The following shows VTune profiling a Delphi application, with symbol, line number and source code resolution:
Download
Get the source here: https://bitbucket.org/anders_melander/map2pdb/
And a precompiled exe here: https://bitbucket.org/anders_melander/map2pdb/downloads/
The source has only been tested with Delphi 10.3 - uses inline vars so it will not compile with older versions.
Usage
map2pdb - Copyright (c) 2021 Anders Melander
Version 2.0
Parses the map file produced by Delphi and writes a PDB file.
Usage: map2pdb [options] <map-filename>
Options:
-v Verbose output
-pdb[:<output-filename>] Writes a PDB (default)
-yaml[:<output-filename>] Writes an YAML file that can be used with llvm-pdbutil
-bind[:<exe-filename>] Patches a Delphi compiled exe file to include a reference to the pdb file
-test Works on test data. Ignores the input file
Example:
Configure your project linker options to output a Detailed map file.
Compile the project.
Execute map2pdb <map-filename> -bind
Profile the application with VTune (or whatever)
Known issues
The -bind switch must occur after the filename contrary to the usage instructions.
PDB files larger than 16Mb are not valid. This is currently by design.
64-bit PE files are not yet supported by the -bind option.
As should be evident I decided not to go the DWARF route after all. After using a few days to read the DWARF specification and examine the FPC source I decided that it would be easier to leverage the PDB knowledge I had already acquired. Not that this has been easy. Even though I've been able to use the LLVM PDB implementation and Microsoft's PDB source as a reference LLVM's implementation is incomplete and buggy and the LLVM source is "modern C++" which means that it's close to unreadable in places. Microsoft's source, while written in clean C and guaranteed to be correct, doesn't compile and is poorly commented. Luckily it was nothing a few all-nighters with a disassembler and a hex editor couldn't solve.
Enjoy!