| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * intel_pt_log.h: Intel Processor Trace support |
| 4 | * Copyright (c) 2013-2014, Intel Corporation. |
| 5 | */ |
| 6 | |
| 7 | #ifndef INCLUDE__INTEL_PT_LOG_H__ |
| 8 | #define INCLUDE__INTEL_PT_LOG_H__ |
| 9 | |
| 10 | #include <linux/compiler.h> |
| 11 | #include <stdint.h> |
| 12 | #include <inttypes.h> |
| 13 | |
| 14 | struct intel_pt_pkt; |
| 15 | |
| 16 | void *intel_pt_log_fp(void); |
| 17 | void intel_pt_log_enable(bool dump_log_on_error, unsigned int log_on_error_size); |
| 18 | void intel_pt_log_disable(void); |
| 19 | void intel_pt_log_set_name(const char *name); |
| 20 | void intel_pt_log_dump_buf(void); |
| 21 | |
| 22 | void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, |
| 23 | uint64_t pos, const unsigned char *buf); |
| 24 | |
| 25 | struct intel_pt_insn; |
| 26 | |
| 27 | void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip); |
| 28 | void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, |
| 29 | uint64_t ip); |
| 30 | |
| 31 | void __intel_pt_log(const char *fmt, ...) __printf(1, 2); |
| 32 | |
| 33 | #define intel_pt_log(fmt, ...) \ |
| 34 | do { \ |
| 35 | if (intel_pt_enable_logging) \ |
| 36 | __intel_pt_log(fmt, ##__VA_ARGS__); \ |
| 37 | } while (0) |
| 38 | |
| 39 | #define intel_pt_log_packet(arg, ...) \ |
| 40 | do { \ |
| 41 | if (intel_pt_enable_logging) \ |
| 42 | __intel_pt_log_packet(arg, ##__VA_ARGS__); \ |
| 43 | } while (0) |
| 44 | |
| 45 | #define intel_pt_log_insn(arg, ...) \ |
| 46 | do { \ |
| 47 | if (intel_pt_enable_logging) \ |
| 48 | __intel_pt_log_insn(arg, ##__VA_ARGS__); \ |
| 49 | } while (0) |
| 50 | |
| 51 | #define intel_pt_log_insn_no_data(arg, ...) \ |
| 52 | do { \ |
| 53 | if (intel_pt_enable_logging) \ |
| 54 | __intel_pt_log_insn_no_data(arg, ##__VA_ARGS__); \ |
| 55 | } while (0) |
| 56 | |
| 57 | #define x64_fmt "0x%" PRIx64 |
| 58 | |
| 59 | extern bool intel_pt_enable_logging; |
| 60 | |
| 61 | static inline void intel_pt_log_at(const char *msg, uint64_t u) |
| 62 | { |
| 63 | intel_pt_log("%s at " x64_fmt "\n" , msg, u); |
| 64 | } |
| 65 | |
| 66 | static inline void intel_pt_log_to(const char *msg, uint64_t u) |
| 67 | { |
| 68 | intel_pt_log("%s to " x64_fmt "\n" , msg, u); |
| 69 | } |
| 70 | |
| 71 | #define intel_pt_log_var(var, fmt) intel_pt_log("%s: " #var " " fmt "\n", __func__, var) |
| 72 | |
| 73 | #define intel_pt_log_x32(var) intel_pt_log_var(var, "%#x") |
| 74 | #define intel_pt_log_x64(var) intel_pt_log_var(var, "%#" PRIx64) |
| 75 | |
| 76 | #endif |
| 77 | |