I’m trying to learn more about malloc & free, so I’ve created a dylib that implements those functions, and I’m loading into a common system binary. However, it has bugs and I’m trying to debug them.
- malloc.dylib is my dynamic library
Here’s the gdb output:
(gdb) set env DYLD_INSERT_LIBRARIES malloc.dylib
(gdb) break malloc_error_break
Function "malloc_error_break" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) r
Starting program: /bin/ls
[+] init()
[-] myMalloc requesting: 4096 bytes
[-] memory address: 200000
bash(2035) malloc: *** error for object 0x200000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program terminated with signal SIGABRT, Aborted.
The program no longer exists.
(gdb)
What I’m confused about is the message
Function "malloc_error_break" not defined.
When I try to set a breakpoint on it. Clearly, it’s not breaking because it’s unknown.
Any help? Thanks in advance.
The reason you can’t set a breakpoint on
malloc_error_breakis that this function is defined in a shared library which has not been loaded yet.You should be able to set the breakpoint after you run the program once.
Alternatively, use
startinstead ofrun, and when the program stops onmain, you should then be able to set the breakpoint onmalloc_error_break.