CS-FreeStyle / 10000-How-To-Do-in-CS

1 stars 0 forks source link

How to use Ltrace and strace? #23

Open liuty10 opened 5 years ago

liuty10 commented 5 years ago

Ltrace: library call tracer intercept and record the dynamic calls made to shared libraries.

  1. Use Ltrace to find program bugs ltrace ./program OR ltrace -p process_id https://www.go4expert.com/articles/ltrace-linux-debugging-utility-tutorial-t29095/ a) check version of ltrace ltrace --v b) redirecting output to a file ltrace -o fibonacci.log ./fibonacci 20 c) trace selected library calls, use -e command. eg. Trace malloc and free functions but to omit those that are done by the libc library, use: ltrace -e malloc+free-@libc.so* program eg. ltrace -e opendir+readdir+closedir ls d) display timestamp ltrace -t program [argument...] ltrace -tt program [argument...] e) display each line of the trace with time required to execute the respective system call, use -r command line. eg. ltrace -r program [argument...] f) use -c command line to display how many time were these system calls or library calls executed? ltrace -c program [argument...]

Strace: to intercept and record system calls and the signals received by a process. using strace to analyze how a program interacts with the system when source code is not available.

  1. Use strace to find system calls that you are instrested strace program strace -p program_id https://www.thegeekdiary.com/how-to-use-strace-and-ltrace-commands-in-linux/ https://access.redhat.com/documentation/en-US/Red_Hat_Developer_Toolset/3/html/User_Guide/sect-strace-Use.html