1

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.

1 Answer 1

2

The reason you can't set a breakpoint on malloc_error_break is 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 start instead of run, and when the program stops on main, you should then be able to set the breakpoint on malloc_error_break.

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

Comments

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.