Reputation:
While disassembling my C# program (release build), I noticed that it contained the names of the functions and the variables I used in the project (that I believe to be debug info, correct me if I'm wrong).
Can someone please explain why is it there and if it is necessary for the program.
Upvotes: 2
Views: 1207
Reputation: 7111
There are three levels of what you call "debug info" in managed code.
Included Metadata: This includes all exposed namespaces, names and types (it doesn't include things like local variable names). It gets bundled in the assembly and allows consumers of that code to know how to refer to the code and reference it. In C/C++ land, this level of metadata gets carted around in H files. In COM land, you get type libraries. All assemblies get this - they can't be consumed without it.
Symbols Files (aka PDB files). This is extended information about internal names, line numbers, etc. Debuggers consume this information to make debugging work better. You can create PDB files for both a "debug build" or a "release build" (or another other kind of build). This is controlled by settings on the Advanced Build Settings dialog box accessible from the Build tab of the project properties. By default, release builds get set to PDB Only while debug builds get set to Full (which I believe may put more information directly in the assembly). PDB files aren't as important in managed code as they are in C/C++ land. There, debugging is nearly impossible without a matching PDB file.
Defining the DEBUG constant: (set on the Build tab of a project's properties). This #defined constant is used as a switch to include (or not include) Debug-only code. Code may work subtly different with or without this constant defined.
Upvotes: 2