blob: 52a7e1d9e94497ccb9de2e19467b7ae4f851f42e [file] [log] [blame]
Dean Michael Berris938c5032016-07-21 07:39:55 +00001//===-- xray_interface.h ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of XRay, a dynamic runtime instrumentation system.
11//
12// APIs for controlling XRay functionality explicitly.
13//===----------------------------------------------------------------------===//
14#ifndef XRAY_XRAY_INTERFACE_H
15#define XRAY_XRAY_INTERFACE_H
16
17#include <cstdint>
18
19extern "C" {
20
Dean Michael Berrisa814c942017-03-06 07:25:41 +000021// Synchronize this with AsmPrinter::SledKind in LLVM.
22enum XRayEntryType {
23 ENTRY = 0,
24 EXIT = 1,
25 TAIL = 2,
26 LOG_ARGS_ENTRY = 3,
27};
Dean Michael Berris938c5032016-07-21 07:39:55 +000028
29// Provide a function to invoke for when instrumentation points are hit. This is
30// a user-visible control surface that overrides the default implementation. The
31// function provided should take the following arguments:
32//
33// - function id: an identifier that indicates the id of a function; this id
34// is generated by xray; the mapping between the function id
35// and the actual function pointer is available through
36// __xray_table.
37// - entry type: identifies what kind of instrumentation point was encountered
38// (function entry, function exit, etc.). See the enum
39// XRayEntryType for more details.
40//
Dean Michael Berrisbad8f0f2016-11-21 03:20:43 +000041// The user handler must handle correctly spurious calls after this handler is
42// removed or replaced with another handler, because it would be too costly for
43// XRay runtime to avoid spurious calls.
44// To prevent circular calling, the handler function itself and all its
45// direct&indirect callees must not be instrumented with XRay, which can be
46// achieved by marking them all with: __attribute__((xray_never_instrument))
47//
Dean Michael Berris938c5032016-07-21 07:39:55 +000048// Returns 1 on success, 0 on error.
49extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));
50
51// This removes whatever the currently provided handler is. Returns 1 on
52// success, 0 on error.
53extern int __xray_remove_handler();
54
55enum XRayPatchingStatus {
56 NOT_INITIALIZED = 0,
Dean Michael Berris17a586e2016-07-29 07:11:58 +000057 SUCCESS = 1,
Dean Michael Berris938c5032016-07-21 07:39:55 +000058 ONGOING = 2,
Dean Michael Berris17a586e2016-07-29 07:11:58 +000059 FAILED = 3,
Dean Michael Berris938c5032016-07-21 07:39:55 +000060};
61
Dean Michael Berris17a586e2016-07-29 07:11:58 +000062// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
63// for possible result values.
Dean Michael Berris938c5032016-07-21 07:39:55 +000064extern XRayPatchingStatus __xray_patch();
65
Dean Michael Berris17a586e2016-07-29 07:11:58 +000066// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
67// result values.
68extern XRayPatchingStatus __xray_unpatch();
Dean Michael Berrisa814c942017-03-06 07:25:41 +000069
70// Use XRay to log the first argument of each (instrumented) function call.
71// When this function exits, all threads will have observed the effect and
72// start logging their subsequent affected function calls (if patched).
73//
74// Returns 1 on success, 0 on error.
75extern int __xray_set_handler_arg1(void (*)(int32_t, XRayEntryType, uint64_t));
76
77// Disables the XRay handler used to log first arguments of function calls.
78// Returns 1 on success, 0 on error.
79extern int __xray_remove_handler_arg1();
Dean Michael Berris938c5032016-07-21 07:39:55 +000080}
81
82#endif