简体   繁体   中英

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, ie 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. NB 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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM