Home > Back-end >  Will a breakpoint in a shared library cause all applications to break on it
Will a breakpoint in a shared library cause all applications to break on it

Time:10-14

Using Linux for example, a new application is using a shared / dynamic .so library.

On debugging the application, if we are able to set a breakpoint in that shared library, will any other applications using that shared library at that same time be affected?

CodePudding user response:

Normally the text segment of a process, which includes all the code from the executable and shared libraries, as well as constant data, is marked read-only. When debugging, the debugger marks the code pages copy-on-write. When the code is modified to set a breakpoint, this causes the process to get a private copy of the code, so the breakpoint doesn't affect other processes.

I'm really surprised that this isn't documented anywhere. I found lots of web pages and other SO answers that explain that the breakpoint is implemented by replacing the instruction with INT 3 (on x86 hardware), but none of them mention that the process gets a private copy of the code. But it surely must work this way, because it makes no sense for other processes that are running the same program or using the same shared libraries to get interrupts from breakpoints. They don't have a debugger running to handle these interrupts, and the instruction that was replaced by INT 3 is in the debugger's memory.

  • Related