Search code examples
xcodegdbbreakpointslldb

Xcode: Automatic (Permanent) Breakpoint on malloc_error_break?


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


Solution

  • 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.