Handmade Hero»Forums»Code
9 posts
None
source code baked into the exe
Edited by NoobSaibot on
Hi,

is it possible in C/C++ to tell the compiler or linker to put the whole source code into the executable, so that i could just grab the executable later on and start debugging, without having to worry about having to have the code laying around somewhere for a particular version of this exe?
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
source code baked into the exe
That would be a good feature, but no, I don't think it exists currently in MSVC :( It would probably be easy to add to CLANG, though, if one were motivated to do so! It's open-source.

- Casey
9 posts
None
source code baked into the exe
You think it'd be worthwhile to bother jon with a request to build that feature into his new language?
Mārtiņš Možeiko
2559 posts / 2 projects
source code baked into the exe
What is use case for this situation?
Typically developers store source code in some revision control system. So any time you build executable, you can put revision number of that particular build somewhere. Then when you are debugging specific executable, simply checkout source code with revision that executable has and that's it. No need to worry where and which source code to use.
9 posts
None
source code baked into the exe
Edited by NoobSaibot on
if *you* are the developer, then yes. pretend, though, you are using a -- licensed -- 3rd party lib where you have a "release" build and an additional "debug" build, then you can link against the debug lib and start debugging.

another case would be, that your permissions as a developer are limited, and you can't grab the code for a particular version of the module you link against.

might be a silly idea though, i don't know.
Mārtiņš Možeiko
2559 posts / 2 projects
source code baked into the exe
Edited by Mārtiņš Možeiko on
Well if you don't have permissions for some module then there must be reasons why you shouldn't get source code, right? So it should not be visible even when debugging your executable. Otherwise what's the point of such permissions, if you could see and extract source code during debugging session.

Similar thinking goes for 3rd party modules. If somebody doesn't want to give you source code, then wouldn't want you to see it even during debugging. Otherwise they could just give you source code directly, right?
9 posts
None
source code baked into the exe
both cases actually work in real life ;)

the use case is actually something i had the other day, and something like that feature would have been pretty sweet!
Chris
21 posts
source code baked into the exe
I'm not aware of a feature to include your source code directly into your EXE. Microsoft does have one thing that may be interesting to you: Source Server. A Source Server setup basically adds instructions into your PDB files on how to get the specific revision of source code that was used to build your binaries. So, I'm not sure if Source Server works without a Symbol Server (easy to setup) and a version control system. But, I think it sort of gets at what you're asking for.

Now that I think of it, if you were really intent on having source code bundled with your exes you might be able to create a hack to do it. First, you'd add a build step, or possibly just an RC file modification to pack your source code into your exes' resource sections. Then, you'd modify the Source Server Perl scripts to treat your exes' as your custom version control system. You'd still need to have access to your PDBs, but attaching a debugger to your running executable should cause it to open the PDBs. Which would trigger them to request source code from your version control system. Which would "check out" your code from your exes' resource sections.

Figuring out the Source Server Perl scripts would probably be the hard part. And, the solution would be totally Windows specific. Although, I believe that Linux also has some support for setting up a source server as well.