LIBC_PROBE 宏在 Glibc 中是如何工作的?

How does LIBC_PROBE macro actually work in Glibc?

我试图了解 mallopt() 在 glibc 中的工作原理,但无法理解函数 mallopt() 中使用的 LIBC_PROBE 宏的用法。 LIBC_PROBE 的定义正在创建另一个宏 LIBC_PROBE_1,它又在创建另一个宏 STAP_PROBE##n。在 mallopt() 的情况下,它是 STAP_PROBE3(a1, a2, a3)。在此之后就不知道如何 STAP_PROBE3 去工作了?
源文件:https://github.com/lattera/glibc/blob/master/malloc/malloc.c(行:5141)。

来自include/stap-probe.h

Without USE_STAP_PROBE, that does nothing but evaluates all
its arguments (to prevent bit rot, unlike e.g. assert).

Systemtap's header defines the macros STAP_PROBE (provider, name) and
STAP_PROBEn (provider, name, arg1, ..., argn).  For "provider" we paste
in MODULE_NAME (libc, libpthread, etc.) automagically.

The format of the arg parameters is discussed here:

https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation

The precise details of how register names are specified is
architecture specific and can be found in the gdb and SystemTap
source code.  */

所以:

  1. 别担心——这对于理解 malloopt() 的工作原理并不重要。
  2. 如果您真的很在意,请阅读上面引用的 wiki 文章,并查看宏是如何在 SystemTap 源代码中定义的(SystemTap 是完全独立于 GLIBC 的项目)。