Skip to content

Instantly share code, notes, and snippets.

@snoe925
Created November 8, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snoe925/b32beb6e6cf89ae3fa4368bc3fc271b3 to your computer and use it in GitHub Desktop.
Save snoe925/b32beb6e6cf89ae3fa4368bc3fc271b3 to your computer and use it in GitHub Desktop.
Using -finstrument-functions to trace function calls with call-trace
Using the debugger or profiler to trace function calls can be a bit tedious.
This repository https://github.com/EmilOhlsson/call-trace implements the call trace in the executable.
apt-get install -y binutils-dev libbfd-dev libiberty-dev
My install was missing the demangle.h header. I could not find the DMGL defines so I inlined them.
I was patching an existing C build. I just included the code in one of the C files.
Then compile and link with -finstrument-functions.
#define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
#include "call-trace.c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment