views:

15

answers:

1

I am wondering what methods people are using for guaranteeing that the source code they are looking at matches the binary they are debugging. I am a single developer managing a fairly large code set and I find that when debugging an application I always want to know for certain that the binary that generated an error exactly matches the code I am looking at. I built a simple application to compare the binaries and wondering if others are using this approach, or use other methods like versioning, etc..

A: 

doesn't Visual Studio does this for you?

Whenever you try to load the symbols/source for a binary, VS checks whether the pdb file (which it needs if you want to debug source code and not just assembly) matches the binary. Not sure about the exact mechanism, but it works pretty: VS refuses to load if the pdb does not match and in the same way refuses to set breakpoints in source if the source does not match the binary.

edit: also see Options->Debugging->General: there's an option Require source file to exactly match the original version. When checked, VS will issue a warning when stepping into a source file that does not match the binary exactly.

edit in response to comment: although I don't see a good reason to have ten executables, here's how I do the versioning in my projects; it could be used to do what you ask for.

  • the AssemblyInfo for each project only contains description, company, ..., and a commented out section containing for example

    //VERSION_MAJOR 2 //VERSION_MAJOR 1

    (these files are also checked into svn btw)

  • furthermore there's an AssemblyVersion.cs in each project, containing again some commented out code

    //VERSION_BUILD 1223 //VERSION_QFE 10

    and also the actual version numbers eg

    [assembly: AssemblyFileVersion ( "2.1.1223.10" )]

    (these files are not checked into svn, but i have a simple script to generate them after a fresh checkout)

  • all my projects import a base project with common properties, amongst which a prebuild event that invokes an executable which does the interesting work: it can read and write the VERSION_XXX numbers as well as the AssemblyFileVersion string. The prebuild looks like

    <Exec Command="versioner -d$(ProjectDir) -f$(ProjectDir)Properties\AssemblyInfo.cs" />

    it reads AssemblyInfo.cs to fetch the main version numbers, reads the AssemblyVersion.cs for the other numbers, sets BUILD to the current svn revision of the main project directory, increments the QFE number and writes back to AssemblyVersion.cs. Incrementing a number is the key to achieving what you'd like: no single build will have the same version, unless you overflow the QFE number.

For C++ I use

#define VERSION_MAJOR 2

etc, which are passed into a resource file that populates a VERSIONINFO section with the numbers.

So in your case, when debugging, you'd look at the version file and compare the number with the binary's version. Apart from that, you'd also have to check that the last modified date of each single source file is not newer than the last modified date of the version file, else you're still not sure.

stijn
I'll restate the question. I give you a VS2008 C# project and 10 binary files and want you to tell me which if any of the binaries will exactly match the binary that the source will build.
patrick
"Incrementing a number is the key to achieving what you'd like: no single build will have the same version..."That is exactly what I do not want, multiple versions of the exact same code, which is what you get with auto-incrementing versions. What I am trying to do is simplify the problem which is why I restated the question as hypothetical situation to clarify the problem. I will restate the question from a more practical perspective.A programmer reads an email accidentally left open on his bosses computer which tells him that he will be fired in 8 weeks time. He decides to plant a
patrick
bug in the versioning scripts. He is fired, his plan works and 8 weeks after his termination his trick is discovered. You are offered a hefty sum of money to identify which of the 30 binaries scattered across 25 different client computers are the same and which are different and using the dates you will re-assign version numbers accordingly. How do you proceed?
patrick
in that case: sorry, no idea.
stijn