Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode doesn't break in #include'd CPP files

If you include a CPP file from another CPP file, XCode refuses to break at any breakpoints in the included CPP file. I'm going to raise a bug with Apple but just wanted to mention it here in case others have come across this and have maybe found ways around it.

There are very good reasons that you may want to include CPP files from CPP files which I won't go into here. Suffice to say, I can't simple re-arrange the project to compile the included files directly.

Example: A very simple iPhone project

main.mm

extern void FunctionInSource1( int a );

int main(int argc, char * argv[])
{
    FunctionInSource1( 1 );

    return 0;
}

source1.cpp

#include "source2.cpp"

void FunctionInSource1( int a )
{
    int b = a;

    FunctionInSource2( b );

    return;
}

source2.cpp

void FunctionInSource2( int b )
{
    int c = b;

    c = c + 1;

    return;
}

main.mm and source1.cpp are members of the target, i.e. they are set to build. source2.cpp is NOT a member of the target and is NOT compiled except through its inclusion in source1.cpp

Setting a breakpoint anywhere in source2.cpp fails to trigger. Breakpoints anywhere else work fine. N.B. You can still step into source2.cpp from source1.cpp for example, just not break directly in source2.cpp

If anyone has come up with a solution I'd be very happy to hear about it.

Max

like image 804
MrMaxP Avatar asked Jul 16 '13 15:07

MrMaxP


People also ask

Why breakpoint is not working in Xcode?

See this post: Breakpoints not working in Xcode?. You might be pushing "Run" instead of "Debug" in which case your program is not running with the help of gdb, in which case you cannot expect breakpoints to work!

What does a dotted breakpoint mean in Xcode?

New in Xcode 13, if a breakpoint is not resolved to any location by LLDB, Xcode will show you a dashed icon. There is a myriad of reasons why a breakpoint is not resolved but there are some common explanations. If you hover over the unresolved breakpoint icon, we have a tooltip that can help you out.

How do I enable debugging in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.


1 Answers

Thanks to a reply over on the Apple developer forums I have now solved this problem.

The compiler is in-lining these files and by default LLDB doesn't break on in-lined files. To force it to break you need to add a setting to your .lldbinit file.

Edit (or create) the file ~/.lldbinit and add the following line:

settings set target.inline-breakpoint-strategy always

It's as simple as that!

like image 145
MrMaxP Avatar answered Oct 18 '22 00:10

MrMaxP