Skip to main content

Source code storing along with debug information

1 reply [Last post]
Joined: 2003-06-19


I thought of a nice idea. Today, the javac allows the developer to specify what debuging information is stored in the result ".class" files - line info, variables, etc. Why not add an option to store the source code itself?

This would result in the following benefits:
1. 3rd party libraries and projects can be distributed with their source code automatically (if they wish) without requiring the user to download the source code or checking it out of an SCM.
2. IDEs won't have to synchronize the source code while debugging, which would result in simpler tools support.
3. Often when debugging complex and large systems with custom build processes, one can mistakenly debug a compiled class but attach it (via his/her IDE) to the wrong source code root (old version, etc). I know this happened to me on more than one occasion. Having the source code built into the classes would immediately indicate that something is not right and I'm not debugging the correct version of the class.
4. A nice feature would be to enable this via an annotation (although I'm not sure that's wise, since this takes away the control from the build process).

1. Might considerably increase the size of resulting class files. Therefor distributions with debug source code might /should be distributed seperately, or with source code distributions.
2. Can't think of more cons - but I'm biased ;-)

What do you think?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-09-03

Many years ago I remember discussions about the same kind of thing for C and C++, storing the source in an Elf section of the .o file. At the time (this was well before open-source) the concerns about copyrights and trade secrets kind of ruled it out. C/C++ also has the nasty preprocessing issue, which source do you save etc.

It's an interesting idea, but sources can be zipped in with the class files now, so I'm not sure I see the big gain in having the source increase the size of the class file.

IDE's and debuggers have had this historic issue of making sure the source displayed is indeed the source that was compiled into the binary you were using. And this would help with that, but I'm not sure it's worth the cost.