xref: /openbmc/linux/tools/perf/util/intel-pt-decoder/intel-pt-log.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
253af9284SAdrian Hunter /*
353af9284SAdrian Hunter  * intel_pt_log.h: Intel Processor Trace support
453af9284SAdrian Hunter  * Copyright (c) 2013-2014, Intel Corporation.
553af9284SAdrian Hunter  */
653af9284SAdrian Hunter 
753af9284SAdrian Hunter #ifndef INCLUDE__INTEL_PT_LOG_H__
853af9284SAdrian Hunter #define INCLUDE__INTEL_PT_LOG_H__
953af9284SAdrian Hunter 
10afaed6d3SArnaldo Carvalho de Melo #include <linux/compiler.h>
1153af9284SAdrian Hunter #include <stdint.h>
1253af9284SAdrian Hunter #include <inttypes.h>
1353af9284SAdrian Hunter 
1453af9284SAdrian Hunter struct intel_pt_pkt;
1553af9284SAdrian Hunter 
1693f8be27SAdrian Hunter void *intel_pt_log_fp(void);
17*65aee81aSAdrian Hunter void intel_pt_log_enable(bool dump_log_on_error, unsigned int log_on_error_size);
1853af9284SAdrian Hunter void intel_pt_log_disable(void);
1953af9284SAdrian Hunter void intel_pt_log_set_name(const char *name);
20*65aee81aSAdrian Hunter void intel_pt_log_dump_buf(void);
2153af9284SAdrian Hunter 
22116f349cSAdrian Hunter void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,
2353af9284SAdrian Hunter 			   uint64_t pos, const unsigned char *buf);
2453af9284SAdrian Hunter 
2553af9284SAdrian Hunter struct intel_pt_insn;
2653af9284SAdrian Hunter 
27116f349cSAdrian Hunter void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip);
28116f349cSAdrian Hunter void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
2953af9284SAdrian Hunter 				 uint64_t ip);
3053af9284SAdrian Hunter 
31afaed6d3SArnaldo Carvalho de Melo void __intel_pt_log(const char *fmt, ...) __printf(1, 2);
32116f349cSAdrian Hunter 
33116f349cSAdrian Hunter #define intel_pt_log(fmt, ...) \
34116f349cSAdrian Hunter 	do { \
35116f349cSAdrian Hunter 		if (intel_pt_enable_logging) \
36116f349cSAdrian Hunter 			__intel_pt_log(fmt, ##__VA_ARGS__); \
37116f349cSAdrian Hunter 	} while (0)
38116f349cSAdrian Hunter 
39116f349cSAdrian Hunter #define intel_pt_log_packet(arg, ...) \
40116f349cSAdrian Hunter 	do { \
41116f349cSAdrian Hunter 		if (intel_pt_enable_logging) \
42116f349cSAdrian Hunter 			__intel_pt_log_packet(arg, ##__VA_ARGS__); \
43116f349cSAdrian Hunter 	} while (0)
44116f349cSAdrian Hunter 
45116f349cSAdrian Hunter #define intel_pt_log_insn(arg, ...) \
46116f349cSAdrian Hunter 	do { \
47116f349cSAdrian Hunter 		if (intel_pt_enable_logging) \
48116f349cSAdrian Hunter 			__intel_pt_log_insn(arg, ##__VA_ARGS__); \
49116f349cSAdrian Hunter 	} while (0)
50116f349cSAdrian Hunter 
51116f349cSAdrian Hunter #define intel_pt_log_insn_no_data(arg, ...) \
52116f349cSAdrian Hunter 	do { \
53116f349cSAdrian Hunter 		if (intel_pt_enable_logging) \
54116f349cSAdrian Hunter 			__intel_pt_log_insn_no_data(arg, ##__VA_ARGS__); \
55116f349cSAdrian Hunter 	} while (0)
5653af9284SAdrian Hunter 
5753af9284SAdrian Hunter #define x64_fmt "0x%" PRIx64
5853af9284SAdrian Hunter 
59116f349cSAdrian Hunter extern bool intel_pt_enable_logging;
60116f349cSAdrian Hunter 
intel_pt_log_at(const char * msg,uint64_t u)6153af9284SAdrian Hunter static inline void intel_pt_log_at(const char *msg, uint64_t u)
6253af9284SAdrian Hunter {
6353af9284SAdrian Hunter 	intel_pt_log("%s at " x64_fmt "\n", msg, u);
6453af9284SAdrian Hunter }
6553af9284SAdrian Hunter 
intel_pt_log_to(const char * msg,uint64_t u)6653af9284SAdrian Hunter static inline void intel_pt_log_to(const char *msg, uint64_t u)
6753af9284SAdrian Hunter {
6853af9284SAdrian Hunter 	intel_pt_log("%s to " x64_fmt "\n", msg, u);
6953af9284SAdrian Hunter }
7053af9284SAdrian Hunter 
71fa8f949dSAdrian Hunter #define intel_pt_log_var(var, fmt) intel_pt_log("%s: " #var " " fmt "\n", __func__, var)
72fa8f949dSAdrian Hunter 
73fa8f949dSAdrian Hunter #define intel_pt_log_x32(var) intel_pt_log_var(var, "%#x")
74fa8f949dSAdrian Hunter #define intel_pt_log_x64(var) intel_pt_log_var(var, "%#" PRIx64)
75fa8f949dSAdrian Hunter 
7653af9284SAdrian Hunter #endif
77