-
Content Count
2771 -
Joined
-
Last visited
-
Days Won
147
Everything posted by Anders Melander
-
🙂 yeah they need to be fairly recent. Since LLVm only produce they "new" PDB format it doesn't need to support the older formats. I think anything older that 5 years will probably fail.
-
Historical reasons probably. https://softwareengineering.stackexchange.com/questions/171565/why-is-the-code-section-called-a-text-section https://stackoverflow.com/questions/1282506/where-did-the-text-segment-get-its-name
-
I'm not sure what saying - or asking... I know what the values in the map file means (they're all absolute [*]). It's the values that I need to put in the yaml/pdb that I'm unsure about. [*] Of course all addresses are relative in a sense, since it's only after the exe has been mapped into virtual memory that absolute addresses can be known. When I say "relative to the segment" I mean these from the map file: Start Length Name Class 0001:00401000 0011B0C0H .text CODE 0002:0051D000 00001144H .itext ICODE 0003:0051F000 00003BACH .data DATA 0004:00523000 0000645CH .bss BSS 0005:00000000 00000020H .tls TLS 0006:00400000 00000000H .pdata PDATA
-
Yes. As far as I can tell. I have also tried validating the pdb but there aren't really any tools (that I've found) that can analyze a pdb for validity. I think the problem is more about what values I need to provide in the pdb (for example I don't have type information or mangled names so I can't write those) and what the meaning of the values are. One of the things I've struggled with are address values. Are they absolute or relative and if relative, then relative to what. I currently assume the following: Segment: Absolute Module (Unit): Relative to Segment Line: Relative to Module Symbol (method/function): Relative to Module But I have tried just about all different combinations. Since VTune doesn't provide any feedback on the address resolution (other than crash/no crash) I have just to throw everything at the wall to see what sticks. Pretty frustrating. I even tried attaching to the VTune backend with the debugger to examine what it did but I quickly gave up on that as it (not surprising) is massively multi threaded and simply too complex for that approach.
-
Don't count your chickens before they hatch... I think you jinxed me there. Here's what works so far: Parse a MAP file and produce an YAML file. Convert the YAML to PDB. Update the EXE with a reference to the PDB. Not crash VTune while it's loading the PDB Here's what doesn't work: Getting VTune to use any of the information in the PDB I know that VTune reads the PDB because I can see in Process Monitor that it looks for the source files. Unfortunately the file names it looks for are the module (i.e. unit) names and not the file names and it doesn't search the source folders I have defined: I'm using VTune 2019 btw since that's the last version to support Windows 7. Anyway if you can stomach watching the sausages getting made then the current source is available here: https://bitbucket.org/anders_melander/map2pdb/ There are two projects: map2yaml and bindpdb. In addition to that the llvm-pdbutil tool is needed. The Tools folder contains a batch file that calls all three in order. Delphi 10.3 or later is required (inline vars).
-
Loading of translated resourcestrings broken in 10.4.2
Anders Melander replied to Vandrovnik's topic in RTL and Delphi Object Pascal
I haven't looked at it at all (still fighting with the damned PDB stuff) but maybe that could have been done automatically when a new resource module is loaded? That would have made the change backward compatible. -
Loading of translated resourcestrings broken in 10.4.2
Anders Melander replied to Vandrovnik's topic in RTL and Delphi Object Pascal
Got it. Wow. Nice that they've added a hook but they really seem to have made that complicated. I'll look at it later. -
Loading of translated resourcestrings broken in 10.4.2
Anders Melander replied to Vandrovnik's topic in RTL and Delphi Object Pascal
I don't have time to investigate myself right now but can you see where LoadResStringFunc is assigned? I briefly scanned through the 10.4 source and I couldn't find anything there. -
It turns out the null GUID was what kept VTune from looking for the pdb file. VTune now loads my pdb file but doesn't resolve the addresses to source lines. I will probably have to populate the pdb with method information for that to work. Makes sense. I guess I'm not getting any sleep tonight
-
As I wrote, VTune doesn't even look for the pdb file so the problem must be in the exe. Anyhow I have now managed to patch the exe so VTune at least logs that it is looking for a pdb (it didn't before) but can't find one. Process Monitor still shows that it isn't looking for the file though so I'm not there yet. My pdb file only contains module/unit and line number information as I couldn't find a way to pass the method names on to the yaml2pdb tool at that time. I think I have found out how to do that now but I haven't tried it yet. Yes, that is one of the resources I'm using - and as far as I can see it states exactly the opposite: So far I'm doing this: Set NtHeaders32.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size = SizeOf(TImageDebugDirectory) Old value was 1 which is invalid. Set DebugDirectory._Type := IMAGE_DEBUG_TYPE_CODEVIEW Old value was IMAGE_DEBUG_TYPE_UNKNOWN (zero). A bit lazy on Borland's behalf since there is a IMAGE_DEBUG_TYPE_BORLAND defined. Replace the old TDS debug data with a CV_INFO_PDB70 structure containing the RSDS signature, a null GUID, 1 for the Age and the pdb filenamer as a zero terminated UTF8 string. Clear the checksum to zero. I have verified the patched exe with various PE editors and viewers and everything seems to be in place but still no cigar.
-
Not quite Game Over it seems. It appears that the Size being 1 is just because whomever wrote the linker has misunderstood the meaning of the field. 1 in this case means that there one entry, so I could replace the 1 with $1C and the entry would be valid. If I then assume that data in the debug directory is now valid then the one entry points to the .debug segment. I assume this segment contains the TDS debug data or something like (it starts with the TDS signature "FB09"). It's only present (for both 32- and 64-bit) if I link with debug info enabled. Now since this debug info isn't used anyway when profiling with VTune, I can just hijack the area occupied by it and store my IMAGE_DEBUG_TYPE_CODEVIEW structure there. This means that I won't have to deal with adding new sections and updating all the various offsets in the PE header. Should be doable with what I know so far. I have to some gardening to take care of now but I'll give it another go this evening. Stay (V)tuned...
-
No. By default VTune will look for the file in the same folder as the executable and I have also tried to add this folder manually to the search list but, as I said, VTune doesn't look for the file anywhere. I'm sure those two have their uses but for me they simply does not provide the level of detail that I need. I need call graphs and asm level analysis.
-
The content of a .NET pdb file is not the same as one produced by the native linker so that will not help. Besides I have already solved the pdb part of the problem and am able to generate a pdb file from the Delphi map file. The remaining problem is that VTune will not load the pdb file unless the file is referenced inside the exe file. I have verified with process monitor that VTune doesn't even look for the pdb file when loading an application compiled with Delphi. It's probably a fairly simple task to patch the exe with the required information but it involves altering the PE structures and that is something I know very little about - and I don't really have time to learn that stuff. The following is the PE layout of an application that does contain the required debug information (the tool used is PE View) : An entry in the PE header points to the debug directory (an array of IMAGE_DATA_DIRECTORY). The number of entries in the debug directory is Size div SizeOf( IMAGE_DATA_DIRECTORY). In this case the size is $1C so the count is one. The entry in the debug directory contains a value that specifies the type of the entry (in this case CodeView) and a pointer (relative address) to the debug data (a IMAGE_DEBUG_TYPE_CODEVIEW structure): Finally the IMAGE_DEBUG_TYPE_CODEVIEW structure contains the name of the PDB file: The IMAGE_DEBUG_TYPE_CODEVIEW structure looks like this: struct CV_INFO_PDB70 { DWORD CvSignature; GUID Signature; DWORD Age; BYTE PdbFileName[]; }; And this is the same information of a Delphi compiled application: Notice that the size of the debug directory is 1 (an invalid value incidentally), so the count is zero. Game over.
-
I know that VS refuses to load a PDB if the GUID doesn't match and I assume VTune does as well. They probably both use the DbgHelp API so maybe it's a feature of that. I think the flow here would be to generate a PDB with a GUID and then update the EXE with the GUID and the name of the PDB (sans the path). I can't see patching the EXE with a hex editor would buy me anything and it's not that easy when there isn't already room in the debug directory. It could be used to verify that the PDB is valid, but since the final tool chain will need to patch the EXE anyway one might as well get that out of the way first and only then worry about the validity of the PDB.
-
I have several tools that can edit PE files (among them PE Explorer), but I think it would be faster to just write a tool that does the job the right way. It seems there also a GUID that needs to be matched between the PDB and EXE.
-
Well that turned out to be a big waste of time I can now produce a YAML file from the MAP file using my own tool and a PDB file from the YAML file with the LLVM tool. Unfortunately VTune couldn't care less. It turns out that in order for VTune to load the PDB file the file needs to be referenced in the PE debug section of the exe file. This is something Microsoft's linker does when you specify the /DEBUG option but Delphi's linker of course doesn't. I can't even patch the debug section Delphi's linker does produce since it's only a single byte. I assume that it's possible to patch the file by replacing the whole debug section and update the PE header but right now I don't know the required format of it. The format of the debug section is documented here: http://www.debuginfo.com/articles/debuginfomatch.html and http://www.godevtool.com/Other/pdb.htm I don't have time to pursue this any further right now, so I hope someone else is willing to have a go at it. I'll post my source when I have a spare moment.
-
Burned? DevExpress wouldn't have existed if it wasn't for Delphi.
-
I'm once again in need of a good 64-bit profiler so I've been looking into what would be needed in order to generate PDB files from whatever Delphi can produce. First of all it seems the only good debug info source on the Delphi side is the MAP file and the format of that seems a bit unstable. However since it's a text file it should be easy to adapt to any changes in it. Then there's the PDB file format. The only good and reliable documentation of that appears to be what the LLVM project has produced. Microsoft at one time published some of their source code for dealing with PDB files but since then the repository appears to have gone into limbo and they have not kept it up to date like they said they would. Anyway, in short, a PDB file is a MSF container file consisting of a number of streams containing the different debug info in CodeView format. The MSF format is pretty simple and since I only need to produce PDBs I don't need to bother about decoding MSF files. That leaves the PDB CodeView streams. Thanks to the LLVM documentation their format are known. However, after reading the LLVM source, it has become clear that it would be a huge task to implement all the different stream formats and all the different data types. I guess one could get by with a subset but it doesn't really seems worth the effort to create something that only works sometimes. The biggest problem however is that I would be implementing something based on a port of a third party's interpretation of Microsoft's old (and by now out of date) source. PDB is an internal VS format and Microsoft has stated that it can, and mostly will, change with each new version of VS. For this reason they provide the Debug Interface Access API for those that need to read PDB files. Unfortunately there's no (known) corresponding API to write PDB files. PDB support is important for the LLVM project (they too would like VTune to work with their output ) so they appear to be trying to keep up with the PDB changes and since they obviously have more resources for that task than I do I've decided to aim for a solution that piggybacks on their work instead of rolling my own. The solution I'm going to try is to parse the MAP file in Delphi, write out the relevant information in YAML format and then use the LLVM llvm-pdbtil tool to convert the YAML to PDB. Sounds easy and it probably would be except for the fact that the required YAML format is undocumented... The llvm-pdbutil yaml2pdb documentation does a handwave with "The YAML syntax is not described here. Instead, use llvm-pdbutil pdb2yaml and examine the output for an example starting point.". Lazy bastards Anyway, this was just a dump of the information I've been able to gather on the topic of generating PDB from Delphi in case I burn out before completing anything usable.
-
dpm DPM Package Manager Progress - 8 March 2021
Anders Melander replied to Vincent Parrett's topic in Delphi Third-Party
I have a feeling Vincent might already have code that does this from "some of his other projects" 🙂 -
TRtlCriticalSection with custom SpinCount
Anders Melander replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
Some more stuff you might not be aware of WRT critical sections_ https://devblogs.microsoft.com/oldnewthing/20140911-00/?p=44103 http://joeduffyblog.com/2006/12/14/anticonvoy-locks-in-windows-server-2003-sp1-and-windows-vista/ A spin count of 100 seems very low - but then again I don't know what your threads are doing and I don't really have time to look at your code to see what problem (if any...) you are trying to solve. -
Instead of preconstructing the different formats so they are ready when the drag start, you could defer the creation and have the drop target initiate the creation when it requests the data. If it only takes ~2 seconds to create the data then that shouldn't be much of a problem and that also solves the problem of when to delete the source data; Delete it when the target closes the source stream - or if the drop is synchronous, when the drop completes. The D&D Suite has several examples that uses this technique... 🙂
-
Debugger activates breakpoint - do not understand yet why
Anders Melander replied to Daniel's topic in Delphi IDE and APIs
You wish. The Delphi compiler doesn't optimize at that level. -
Not sure what you're asking but: https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#dpiaware
-
Removing Hints & Warnings — Specifically, "H2443 Inline function"?
Anders Melander replied to Steve Maughan's topic in Delphi IDE and APIs
Did you start by reading the help? -
spinlock primitives
Anders Melander replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
You are writing your own spinlock to get better performance - and then you use Sleep() which is guaranteed to cause a context switch...? Unless you really know what you're doing then you better of using the synchronization primitives provided by the OS. https://devblogs.microsoft.com/oldnewthing/20051004-09/?p=33923 http://joeduffyblog.com/2006/08/22/priorityinduced-starvation-why-sleep1-is-better-than-sleep0-and-the-windows-balance-set-manager/ Apparently this can't be repeated often enough.