2

Is it possible to set an automatic (or permanent) breakpoint on malloc_error_break under Xcode? (If its in Xcode and I missed it, please point it out). I want it to work everywhere under Xcode - from GDB to LLDB, to old and new projects. I would really like it to work on device, but that might be stretch (it appears something is broken with malloc guard on device).

I was thinking .lldbinit might be helpful, but LLDB kind of kills that idea. It appears LLDB does not honor breakpoints set in .lldbinit (according to breakpoint list) (http://lldb.llvm.org/tutorial.html). LLDB also disregards breakpoints in .lldbinit-Xcode (thanks Rob).

.gdbinit might also be useful, but we will likely run into the bug discussed at Unable to set pending breakpoints in .gdbinit. This is Apple, and they have a completely broken QA process, so I don't expect it to be fixed.

To summarize, the following does not work on this Mac (MacBook Pro, 10.8) and Xcode (4.5.2):

riemann: jwalton$ cat ~/.lldbinit
# http://lldb.llvm.org/tutorial.html
# Not honored by LLDB
breakpoint set --name malloc_error_break
# Shot in the dark since the previous is not honored
breakpoint set pending --name malloc_error_break
riemann: jwalton$ cat ~/.gdbinit 
set breakpoint pending on
set breakpoint malloc_error_break
set breakpoint pending auto

EDIT (2013/02/07): Also see lldb equivalent of .gdbinit and future break?.

Jeff

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

3

UPDATE

There is an easy way to set up a permanent, all-projects breakpoint in Xcode.

Open up any project. Go to the Breakpoints navigator. Create a symbolic breakpoint on malloc_error_break. Then, right-click the breakpoint in the navigator, and from the pop-up menu, choose Move Breakpoint To > User. Xcode applies User breakpoints to all projects.

See step 2 of this blog post for a video.

ORIGINAL

LLDB has its own init file, which is called… (drumroll please)… .lldbinit. You can set the breakpoint there too. The “Session 415 - Debugging with LLDB” video from WWDC 2012 discusses this file in depth starting at 29m43s. You can even make a .lldbinit-Xcode file that LLDB will load only when it's running under Xcode.

I don't have any advice for you regarding the GDB pending breakpoint problem.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Thanks Rob. It appears LLDB does not honor the breakpoint specified in `.lldbinit` (according to `breakpoint list`). Its Apple. What do you expect other than broken software? – jww Nov 15 '12 at 07:47
  • As I explained in my answer, this is a known limitation of lldb in Xcode 4.5. It will be fixed in the next release. – Jason Molenda Nov 19 '12 at 21:06
1

Regarding your gdb breakpoint, the Mac OS X gdb is a little different than the generic FSF gdb, you should be fine with just b malloc_error_break to have a permanent breakpoint there or worst case use fb malloc_error_break (an Apple-gdb specific future-break command that makes it explicit).

With lldb in Xcode 4.5 there was a bug that breakpoints set in the .lldbinit file were not added. Not so much a bug as a design shortcoming, really, breakpoints are added to a target and when the .lldbinit file is being read, lldb doesn't have a target set up yet. I think Greg Clayton fixed that in the svn repository lldb sources a couple of months ago, creating a placeholder for applying settings like this that are installed in any newly-created Targets from that point on. With the svn lldb sources, putting br s -n malloc_error_break in your .lldbinit should work fine.

Jason Molenda
  • 14,835
  • 1
  • 59
  • 61
  • thanks. "With the svn lldb sources..." - there's no telling what will break on Apple platforms. The platform is fragile, and not like Linux/GDB or Windows/WinDbg. I'm afraid to try it. – jww Nov 19 '12 at 14:13
  • I know it’s been a while, but which SVN revision of LLDB are you referring to? The version of LLDB that—at the time of this writing—ships with Xcode does **not** appear to include that patch—Xcode version in this case is 5.0.2 (5A3005), LLDB version is lldb-300.2.53. – danyowdee Jan 15 '14 at 15:46