iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

`bcc_procutils_which_so(libname, pid)` finds library unused by the process #5013

Closed gukoff closed 2 months ago

gukoff commented 4 months ago

Problem

When debugging a specific process, I might need to set the probes in the shared library that this process is using.

The function bcc_procutils_which_so(libname, pid) seemingly helps with this. But in reality, it also looks for the library in the ldconfig cache.

It potentially returns the libraries unrelated to the given process even if I pass a pid to this function, which breaks my expectations as a library user. Example: https://github.com/sumerc/gilstats.py/pull/1

Potential solutions

  1. Backwards-compatible: export a more specialized function bcc_procutils_which_so_in_process(libname, pid).
  2. Backwards-incompatible: force bcc_procutils_which_so(..., pid) to search only the libraries of the given process when pid != 0.

Also, here's an implementation of the backwards-compatible solution: https://github.com/iovisor/bcc/pull/5014