Home > OS >  Check if mac executable has debug info
Check if mac executable has debug info

Time:12-04

I want to make sure my executable has debug info, trying the linux equivalent doesn't help:

$ file ./my_lovely_program
./my_lovely_program: Mach-O 64-bit executable arm64 # with debug info? without?

EDIT (from the answer of @haggbart)

It seems that my executable has no debug info (?)

$ dwarfdump --debug-info ./compi
./compi:    file format Mach-O arm64

.debug_info contents: # <--- empty, right?

And with the other option, I'm not sure:

$ otool -hv ./compi
./compi:
Mach header
      magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64    ARM64        ALL  0x00     EXECUTE    19       1816   NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK PIE

This is very weird because I can perfectly debug it with lldb

(lldb) b main
Breakpoint 1: where = compi`main   24 at main.cpp:50:9, address = 0x0000000100018650
(lldb) run
Process 6067 launched: '/Users/oren/Downloads/compi' (arm64)
Process 6067 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100018650 compi`main(argc=3, argv=0x000000016fdff7b8) at main.cpp:50:9
   47   /*****************/
   48   int main(int argc, char **argv)
   49   {
-> 50       if (argc == 3)
   51       {
   52           const char *input = argv[1];
   53           const char *output = argv[2];
Target 0: (compi) stopped.

CodePudding user response:

To check whether a Mac executable has debug information, you can use the otool command with the -h option. For example:

otool -hv /path/to/executable

If the output of the command includes a LC_DYSYMTAB section, then the executable has debug information. Here's an example of what that output might look like:

dwarfdump command is another tool that you can use to view debug information:

dwarfdump --debug-info ./my_lovely_program

The output of the dwarfdump command will include a list of the debug information in the executable. If the output includes a .debug_info section, then the executable has debug information.

Use the nm command to view the symbols in an executable. The nm command lists the symbols in an executable along with their type and value. If you see any symbols that start with _dyld, then the executable has debug information. Here's an example of how to use the nm command:

nm /path/to/executable

You can use the file command to view the type of a file. The file command can identify the type of a file based on its contents. If the file command identifies the executable as a Mach-O dynamically linked shared library or Mach-O dynamically linked shared library stub, then it has debug information. Here's an example of how to use the file command:

file /path/to/executable

If you have access to the source code for the executable, you can check the build settings to see if debug information was included. In most cases, debug information is included by default when you build an executable in a debug configuration, but you can also enable or disable debug information in the build settings. For example, in Xcode, you can check the "Debug Information Format" build setting to see if debug information is included in the executable.

CodePudding user response:

If you run :

dsymutil -s ./my_lovely_propgram | grep N_OSO

and it shows output, it means there is debug info.

  • Related