adfjoawesdfi
adfjoawesdfi

Reputation:

How to tell if a binary is release or debug in both win and *nix

Is there a simple command line utility to inspect binaries like executable and dynamic libraries to tell if they are release or debug versions? Is there anything like that on *nix or windows?

Upvotes: 35

Views: 29524

Answers (8)

Srikanth Baratam
Srikanth Baratam

Reputation: 11

Use depends.exe to find out which version it is. when You open the file through depends walker it will show file which are needed. By seeing the list of system32 files you can it whether it is debug or release

Upvotes: 0

Idan P
Idan P

Reputation: 275

You can use filever.exe.

filever.exe <my binary file>
--a-- W32i   APP   -         1.0.0.0 shp     25,600 11-03-2013 <my file>

To get filever, you can download the support tools for windows xp.

If you moved to Windows 7 or above (like most windows users), you can download it, open it via winzip.

Then extract filever from support.cab.

It works for Windows 7 just fine.

Upvotes: 0

Bob Yoplait
Bob Yoplait

Reputation: 2501

  • for C++ on Linux, you can do:

        objdump --source yourbin |grep printf
    

    Replace printf with whatever function call you do. If it is debug, it will display all the actual source code call you do. If it is release, it will just display the founded symbol from the symbol table.

  • for C++ on Windows, you can use depends.exe and see if it depends on MSVCRT (release) or MSVCRTD (debug)

Upvotes: 34

Macke
Macke

Reputation: 25710

For Windows, the Dependency Walker has optional cmd-line output listing every dll the exe loads (and their dependencies). Run that through grep and see if the msvcrt-dll popups with a d or not.

This only works if it's dynamically linked. Otherwise it might be trickier.

You could perhaps grep for certain functions that are different in debug/release, if those strings are visible in the executable.

If your apps doesn't use the runtime at all, it'd be pretty tricky.

Upvotes: 3

leander
leander

Reputation: 8737

For unix: with ELF executables you may be able to use objdump or nm to look at the symbol tables for the executable (note that this will work a lot better if it's not stripped). The presence or absence of certain symbols will tend to indicate a debug or release build. (As to which, that probably depends on what libraries you're using, etc. You'd have to do a bit of digging to find common ones; feel free to suggest things to look for in comments, and I'll update the answer.)

For Windows: the dependencywalker suggestions are good. For command-line equivalents, you can find dumpbin in most Visual Studio installations and it's somewhat equivalent to objdump on *nix. You may also be able to find an nm or objdump in e.g. msys or cygwin that'll work on some windows exe files.

Upvotes: 4

Piotr Dobrogost
Piotr Dobrogost

Reputation: 42474

Most often debug versions of both executables and libraries are linked against debug version of runtime. On Windows there's a name scheme for debug/release versions that some follow, MS among them. The name of debug version of a library should end with d. You can use tool like Dependency Walker (http://www.dependencywalker.com) to see on what libraries your executable or library depends. If you find debug versions of runtime libraries there there is a big chance your executable or library was built in debug mode.

This however works only if

  • you can tell by looking at a name of runtime which version it is (it follows some naming scheme like the one I described above)
  • your executable/library is linked against dynamic runtime not static one. In the second case the runtime gets pulled into executable/library and it's no longer a dependency
  • you are on Windows :)

Upvotes: 2

Joshua Belden
Joshua Belden

Reputation: 10523

There's not much to go on. If you open an assembly in Reflector, you can look for the Assembly Attribute:

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)]

But apparently that's added to release mode as well.

If it's your own assembly than the solution is to use some preprocessor directives.

#ifdef DEBUG
[MyAttribute("foo")]
#endif

edit: Sorry, I assumed .NET. There goes my hammer.

Upvotes: 3

Norbert Hartl
Norbert Hartl

Reputation: 10851

On linux you can use the "file" command even for dynamic libraries. If it says "stripped" than all debugging symbols are stripped out. If it is saying "not stripped" it is the opposite

Upvotes: 20

Related Questions