简体   繁体   中英

xcode breakpoints not resolved with included cpp files - MacOS

Update : Based on the answer given by Jason Molenda, I realize that the settings command isn't the issue at all - it is being read properly and has the correct value, and yet breakpoints still aren't resolved. I've changed the topic name to more accurately fit the problem.

Summary of problem: I include cpp files, Xcode can't resolve them when setting breakpoints using the gutter, application is built externally (not developed in Xcode), and my .lldbinit already has settings set target.inline-breakpoint-strategy always set.

Previous version : My issue is that I cannot get Xcode's debugger to break at breakpoints in included .cpp files (from an externally built application, just trying to use Xcode as the debugger).

I found that the answer is to add the following to the .lldbinit file:

settings set target.inline-breakpoint-strategy always

And I did. It doesn't seem to be read at all and doesn't change anything. When running the command myself using:

command source ~/.lldbinit

It tells me:

-bash: settings: command not found

I do not understand why it can't figure out the 'settings' command. I'll add that I have very little knowledge of how this file is supposed to work, but I see this command used in many lldbinit files without issue.

I searched for information about this and Google gives me absolutely nothing even a little bit related to it, no matter how I search.

Other notes:

-Application is built with debug information.

-To set up Xcode, I created an empty project, set a new scheme's executable to debug to the one I built, and added code folder references for code browsing.

-I add breakpoints using the Xcode gutter.

-I'm using MacOS 10.12 - Sierra, not Linux, and Xcode 8.2.1.

-If I run LLDB through the command line and set breakpoints using: b filename.cpp:line, everything works fine. This is true even despite the 'settings: command not found' error I get when running manually. But it never works in Xcode's visual debugger. Perhaps I'm being misled by this error?

-Breakpoints work fine in the base .cpp file that includes the others, but not in any included ones.

Thanks for any help.

Okay, this is issue has been haunting me for the last few days, and there is literally nothing on the internet that would help - but I finally figured it out! Kinda accidentally - I fiddled with stuff and now it works for some completely mysterious reason.

This is for Xcode 8 - macOS Sierra - mid 2010 computer

The Issue:

On an external build, break points work for the main cpp file, but breakpoints are not working for any included files - cpp files included with "#include". lldbinit settings do nothing to improve the situation.

Symptoms:

Run the program with some new breakpoints created in the included files, and then press the pause key in the xcode debugger. In the LLDB console (bottom right of the screen), type: breakpoint list You'll see all your broken breakpoints say "location = 0 (pending)" at the end of them. If you add a working breakpoint from you main file, you will see it says "location = 1".

Solution:

In the Project manager, click on the main project file, then click on your Target, goto "Info" - since I'm assuming you're able to build properly, you will have the path to your build.sh file in the Build Tool box. But make sure the Directory box is empty (My arguments box is also empty, but I doubt this is related.)

Once that Directory box is empty, build.sh will no longer work because it won't be able to find your file. To fix this, hardcode your paths like so:

clang++ -g -I/usr/local/include/SDL2 -lSDL2 /absolute/path/to/sdl_mygame.cpp -o /absolute/path/to/mygameexecutable

Now the build works, and mysteriously, now your breakpoints all work!

Other notes about my setup:

  • I created this project as an External Build
  • I created a target which points to my build file and unchecked "Pass build settings in environment"
  • I selected this target in my Scheme under Build.
  • I selected the executable in my scheme under run and checked Debug Executable
  • Most other xcode settings don't seem to be necessary.
  • I'm following along with Handmade Hero

Hope this helps!

command source ~/.lldbinit should be run inside lldb. You're running it from your shell; that error message is from bash. (" settings " doesn't mean anything to bash)

settings set target.inline-breakpoint-strategy always is needed when your project includes source files (instead of just headers). This is not common, so it is not the default behavior -- it reduces the debugger's performance to scan through every file as is needed here. It is documneted at the top of https://lldb.llvm.org/troubleshooting.html . Most people do not need this setting.

I'm not sure why breakpoints in Xcode, when you click in the source editor's breakpoint gutter, are working. It may be a separate issue. If you launch your project and pause it, you can do

(lldb) settings show target.inline-breakpoint-strategy

in the debugger console window to verify that it is always like you intended to do. If your breakpoints are not working, I would start by looking at your build settings and see if one of your build settings is not generating debug information.

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