Ltrace Equivalent for Osx

How to trace system calls of a program in Mac OS X?

You can use dtruss like in

sudo dtruss find ~/repo -depth 2 -type d -name '.git'

The manual page of that utility will help you to tailor the use of the tool to your needs.

Mac OSX: Using dtruss?

This article explains how to accomplish this:
Enabling D-Trace on system with SIP

You can disable SIP entirely by doing the following:

  1. Reboot your mac
  2. Hold ⌘R during reboot
  3. From the Utilities menu, run Terminal
  4. Enter the following command
csrutil disable

Alternatively you can re-enable SIP while still allowing dtrace to work by also running the following:

csrutil enable --without dtrace

Finding number of dlopen calls of an ELF binary in C

You could simply use ltrace:

Example:

#include <dlfcn.h>
#include <stdio.h>
int main(int C, char **V)
{
char **a = V+1;
while(*a){
void *h;
if(0==(h=dlopen(*a++, RTLD_LAZY)))
fprintf(stderr, "%s\n", dlerror());
}

}

Compile it:

$ gcc example.c -fpic -pie 

Invoke it on self and count dlopen calls:

$ ltrace -o /dev/fd/3 \ 
./a.out ./a.out ./a.out ./a.out 3>&1 >/dev/null| \
grep ^dlopen\( -c
3


Related Topics



Leave a reply



Submit