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

夙愿已清 提交于 2019-12-18 13:33:22

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/17680401/xcode-doesnt-break-in-included-cpp-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!