我有类似的程序
int main()
{
char *ptr = malloc(2);
free(ptr);
}
所以我只想跟踪程序内部发生的所有函数调用,直到系统调用
喜欢
malloc
|____ libc( sme_fn)
|
|__sme_system_call
你能告诉一些方法来得到这个吗?
As you know, "system calls" come in two flavors:
Calls directly to the operating system ("open", "close", "fork", "exec", "exit", etc)
Standard C runtime functions for the platform ("printf()", "malloc()", "free(), etc.)
You can view the former with "strace".
You can view (at least calls into) the latter with gdb.
You can look at the complete implementation, and all internals, directly from the source code:
Finally, if you're having issues with "malloc()", "valgrind" is (one of several) very, very useful tools to consider.
如果您使用 gcc,请使用 -pg 编译,然后使用 gprof 命令。
或者,如果您在 Linux 上,您可以使用oprofile执行类似的操作而无需重新编译。
这两种工具都应该为您提供调用图,这是您正在寻找的。