[llvm-dev] How to add custom instrumentation?

ORiordan, Martin via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 13 01:57:03 PDT 2017


The '-finstrument-functions' option may already be sufficient for your needs.

When selected this inserts the following two calls on entry-to and exit-from a function:

  __cyg_profile_func_enter(void* this_fn, void* call_site)
  __cyg_profile_func_exit(void* this_fn, void* call_site)

You can then provide a custom implementation of these calls to perform the analysis tasks that you require.

The two parameters are the address of the function into which the instrumentation is inserted, and the address of the call site to the instrumentation function.

There is an "Execution Trace" implementation of these instrumentation hooks on GitHub called 'eTrace' that may guide you, though I can't recall the link.

All the best,

  MartinO

-----Original Message-----
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Alex Denisov via llvm-dev
Sent: Thursday, July 13, 2017 8:57 AM
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [llvm-dev] How to add custom instrumentation?

Hi everyone,

I run some functions using ORC JIT, now I need to add custom instrumentation.
I want to add two callbacks to each function: ‘enterFunction' at the beginning and ‘leaveFunction' at the end.
Intuition says that I could ‘just' insert CallInst's to the first and the last basic blocks in the function.

Am I correct? Are there any other/better way to do this? Is there anything special I need to be aware of?

Thank you.
--
AlexDenisov
Software Engineer, https://lowlevelbits.org

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.


More information about the llvm-dev mailing list