Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it any way to add .map file as resource of the project when compiling?

I'd like to add the map file as resource, then extract the file every time that execute the system, to ensure that the map file is always right, and make the life of support easier. In Delphi 7 I can compile the project, with the map file as resource, but the map is wrong, because when an exception is raised the call stack is wrong. In Delphi Seattle, I can't even compile, because it tries to add the resource before generate the map. I know that I can add the file in a post-compile thask, but is there any way to do it in compiling/building time? Sorry if I'm not very specific, that's my first question here. Thanks.

UPDATE

After I read some answers, I did some research. I was already using JEDI exception unit in my project, but I did not know the JEDI Debug expert. It does exactly what I want and more. JEDI Debug expert convert a .map file to .jdbg file, wich is an encrypted file of map (map is just a text file). Also, the jdbg file is about 12% smaller then the map. It also has the options to insert the jdbg into binary (exe). To do that, I enabled the options:

  • Project -> JCL Debug expert -> Generate .jdbg files -> Enabled for this project

  • Project -> JCL Debug expert -> Insert jdbg data into binary -> Enabled for this project

  • Project -> JCL Debug expert -> Delete map files after conversion -> Enabled for this project (if you want to delete the file, of course)

To use this tool outside the IDE, with Jenkins for example, I had to build the project available in JEDI\jcl\examples\windows\debug\tools\MakeJclDbg.dpr. After build, it will generate the exe file in the bin directory of jcl. How to use:

MakeJclDbg -J -E -M map_filename

J - Create .JDBG files

E - Insert debug data into executable files

M - Delete MAP file after conversion

Executable files must be in the same directory as the MAP files. This will create the jdbg file (based in the map file), insert into the exe and delete the map. With this (and with the exception unit of JEDI), when an exception is raised, It's available to me the stack trace, the versions of all dll's used by the system, operation system info, and more, and also send all this to an email.

I realised that Embarcadero also have jdbg files of theirs bpl, so I think they use JCL tool as well.

like image 497
Rodrigo Caetano Avatar asked Oct 17 '22 23:10

Rodrigo Caetano


2 Answers

No, the map file is generated after the program output is linked. It is impossible to incorporate a, not-yet generated, map file as a resource into the project.

like image 144
Sertac Akyuz Avatar answered Oct 21 '22 04:10

Sertac Akyuz


You're missing the point.

The MAP files are generated as a separate file to avoid increasing the size of your executable. Trying to embed that file back into the executable as a resource simply defeats the purpose.

You haven't mentioned what debug framework you're using. But there are other ways to provide debug information, and I suggest you refer to the documentation of the debug framework you using for the specifics. I'll just offer some general concepts applicable to most of the frameworks I've tried.

  • If you're happy with increased EXE size and want debug information included within your executable: Don't use the map file option. Simply enable the linking option to include debug information. (And ensure your debug framework will use it.)
  • Most debug frameworks recommend compiling with stack frames turned on. This is very important because it makes it easier for the debug framework to deduce the call stack.
  • Some debugging frameworks have a feature that allows guessing missing call stack information. If enabled, you will need to manually ignore any stack entries that don't actually make sense.
  • Of course, don't forget that any units compiled without debug information won't have debug information to include in the final executable.
like image 27
Disillusioned Avatar answered Oct 21 '22 03:10

Disillusioned