LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   debug shared library (https://www.linuxquestions.org/questions/programming-9/debug-shared-library-867016/)

pike87 03-07-2011 12:20 PM

debug shared library
 
Suppose, I debug a *nux application and put a breakpoint into a function defined by a dynamically linked used by the application. Will that breakpoint stop any other application that makes use of the same library?

Thanks

Ygrex 03-07-2011 04:36 PM

sure, other applications should stop by a contagion magic

johnsfine 03-07-2011 04:41 PM

Quote:

Originally Posted by pike87 (Post 4281738)
Suppose, I debug a *nux application and put a breakpoint into a function defined by a dynamically linked used by the application. Will that breakpoint stop any other application that makes use of the same library?

No. When your process (or the debugger for your process) writes to a page of the shared area, the kernel copies that whole page (4096 bytes) to give your process a private copy of that page.

Quote:

Originally Posted by Ygrex (Post 4281978)
sure, other applications should stop by a contagion magic

Sarcasm really wasn't called for. If you know the basics of how shared objects work and you know the basics of how breakpoints work, you would have legitimate reason to be concerned about the issue the OP raised.

Most code pages of a .so are shared by all processes using that .so at the same time. Breakpoints are implemented by the debugger changing a byte of an instruction into a breakpoint instruction. So it is normal to wonder why those two facts don't combine to put that breakpoint instruction into the address space of every process using that .so.

There are a number of different situations in Linux in which a page of virtual memory is shareable by multiple processes as long as none of them write to it, but any process writing to the page gets a private copy. I don't know the exact details of how that mechanism is used for breakpoints in .so mappings, but that is the basic concept.

pike87 03-08-2011 12:26 AM

johnsfine, Thanks!

Anyone can give a detailed example please?


All times are GMT -5. The time now is 10:09 AM.