2

I am currently trying to perform a detailed analysis of a dynamic C library's "mimalloc" behavior when loaded by a specific program in a Linux environment. Specifically, I want to comprehensively understand which functions within the mimalloc library's source code are called, how many times each function is called, and what arguments are passed to them during the execution of a test program. how do I trace functions of library source code?

After researching methods to achieve this, I have identified the following tools as potential candidates: strace ltrace utrace ftrace etrace

  • My environment and library details are as follows: OS: Linux (Ubuntu)
  • Library Executable Path: /home/user/mimalloc-2.1.7/out/release/libmimalloc.so.2
  • Library Source Code Path: /home/user/mimalloc-2.1.7/src/
  • Test Program: A simple C program linked with the mimalloc library, designed to call functions such as mi_malloc and mi_free.

Add information

  • Library "Mimalloc " Document and Source code[https://github.com/microsoft/mimalloc/?tab=readme-ov-file#using-the-library]

My primary goal is to trace in detail within libmimalloc.so itself how functions call other functions (e.g., helper functions called within the implementation of mi_malloc), how many times they are called, and what arguments are passed.

In my situation, there is no separate library like libX.so for which I don't have the source code. The scope of my investigation involves only libmimalloc.so (for which I do have the source code).

As pointed out, since I have the source code for mimalloc, I can rebuild it with debug symbols (e.g., using -g).

Regarding the suggestion of ltrace from a previous comment: I tried using it. While it successfully traced calls from my test program to libmimalloc.so functions (like mi_malloc), it did not trace the function calls internal to the library (e.g., calls from mi_malloc to its internal helper functions) as I had hoped.

Therefore, I am looking for more effective tracing methods to gain detailed insight into the internal behavior of the mimalloc library. GDB is not suitable for this purpose due to its slow execution speed during debugging.

6
  • 1
    Possibly related: stackoverflow.com/questions/311840/…
    – SuibianP
    Commented Mar 25 at 15:50
  • Release versions of libraries typically do not contain debug symbols. You can step into them with a debugger, but you'll probably have trouble extracting some of the information you're looking for. Commented Mar 25 at 16:59
  • So, you have two libs, libX.so [no source code] and libmimalloc.so [which you do have source for]? Because, you have the source you should be able to add debug function calls to the mimalloc lib functions. There are other ways if you don't have the source [but only a .h]. Does libX have debug info [symbols]? If not, what symbols does it have? (e.g.) Look at the output of readelf -a You can use this to build up a table where your S/W can divine the start/end addrs of functions Commented Mar 25 at 17:56
  • ltrace is what you are looking for: manned.org/man/ltrace Commented Mar 25 at 22:07
  • Thank you for answering. Now I add some information to my question.
    – sveerrr
    Commented Mar 26 at 4:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.