C++ XCode debugging

Discussion in 'Mac Programming' started by kamy, Mar 31, 2014.

  1. kamy, Mar 31, 2014
    Last edited: Mar 31, 2014

    kamy macrumors member

    Jul 27, 2011
    Hey guys,

    I use CLang compiler to build our binaries for the MACOSX platform.
    I also provide the '-g' option which ensures that debugging symbols are enabled.

    This is my CLang command with the flags - Do note that the '-g' flag is provided

    I want to use XCode to debug an isssue.
    I issue a sleep(30) command, my program waits 30 seconds, so that gives me time to go to XCode - Debug-->Attach To Process --> mtxtests (my executable)

    As soon as XCode attaches, the sleep is aborted and teh execution continues!
    Thus, I cant debug any code.
    Also my XCode project has 'C++ library' as the target

    What could be the problem?

    If i remember i used to be able to debug fine when i used to use the LLVM-GCC compiler. But with Maverics, we need to move to CLang...

    Any suggestions would be appreciated.
  2. kamy thread starter macrumors member

    Jul 27, 2011
    C++ Sample file debugging

    I dug around some more info. Apparently xcode you can build executables with "dsym" debug information, which puts the debug info in a separate file (instead of embedding it in the executable)

    But as we are using the command line, i dont see any DEBUG Symbol files or "dsym" files.

    So i used the util to generate the Symbol files
    dsymutil mtxtests -o mtxtests.dSYM

    Still the same behavior. The executable sleeps and as soon as we attach the process , the process resumes without allowing me to debug!!!
  3. kamy thread starter macrumors member

    Jul 27, 2011
    Trying some more

    Ok. This is me again trying more stuff...

    I created a simple .C file
    And compiled using CLang

    clang -g -o tempraturefn tempraturefn.c

    This time i see 'tempraturefn.dSYM' automatically created...

    i see that the executable sleeps and then i open the file in XCode and try to attach my executable and voilla i can debug!!

    So this means that something is wrong with the flags am sending, while compiling my code .....
  4. subsonix macrumors 68040

    Feb 2, 2008
    Just add the -g flag and a .dSYM file will be created with the same name as your target. So for example,

    clang test.c -g 
    will create a.out and a.out.dSYM

    Have you considered using a makefile?
  5. kamy thread starter macrumors member

    Jul 27, 2011
    Hey subsonix,

    if you see the flags for our compilation command, we do pass the "-g" flag.
    Yes we do use a Makefile.

    But when i use our compilation command, it does not generate any 'dSYM' file.

    Is a 'dSYM' file mandatory for debugging?
    If yes, that explains the fact that my sample file could be dubbuged, but not my main executable.
  6. subsonix macrumors 68040

    Feb 2, 2008
    As far as I know it gives you more information when you debug with debug symbols, but you should be able to attach a debugger anyway. However, it should create a dSYM file, perhaps it has something to do with the fact that you are building a library.

Share This Page