3

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.

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

Thanks for the reply. This clarified a few things that I didn't understand. The settings command is clearly working as intended and it is set to 'always'. Clearly then, my issue is something else entirely and I don't know what. My build is generating debug information, and I am including .cpp files.
Try running your project in Xcode, pause in the debugger, then do breakpoint list to see how exactly Xcode is specifying the filename. Then try target module dump line-table filename for just the base filename of your source file to see what the full path for your source file looks like in the debug information. Do either of the paths have /../'s in them? You might want to file a bug report at bugreport.apple.com with all of these details and it can be debugged there - might be something specific to how your project's files are being compiled.
I finally got a chance to test this. For some reason, target module dump line-table always tells me there's no match whatsoever. It even tells me this for the base .cpp file that does correctly resolve breakpoints. "warning: No source filenames matched '<file>.cpp'. error: no source filenames matched any command arguments"
Scratch that. The line-table dump works correctly for my base .cpp file. And the paths to the included .cpp files have /./ in them. I am unsure about what is going on here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.