| 1 |
/* -*- linux-c -*- |
| 2 |
* Print Functions |
| 3 |
* Copyright (C) 2012-2018 Red Hat Inc. |
| 4 |
* |
| 5 |
* This file is part of systemtap, and is free software. You can |
| 6 |
* redistribute it and/or modify it under the terms of the GNU General |
| 7 |
* Public License (GPL); either version 2, or (at your option) any |
| 8 |
* later version. |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef _STAPDYN_PRINT_C_ |
| 12 |
#define _STAPDYN_PRINT_C_ |
| 13 |
|
| 14 |
#ifdef STP_BULKMODE |
| 15 |
#error "Bulk mode output (percpu files) not supported for --runtime=dyninst" |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "transport.c" |
| 19 |
#include "vsprintf.c" |
| 20 |
|
| 21 |
static void _stp_print_kernel_info(char *sname, char *vstr, int ctx, int num_probes) |
| 22 |
{ |
| 23 |
// nah... |
| 24 |
} |
| 25 |
|
| 26 |
static int _stp_print_init(void) |
| 27 |
{ |
| 28 |
/* Since 'print_buf' is now in the context structure (see |
| 29 |
* common_probe_context.h), there isn't anything to do for |
| 30 |
* regular print buffers. */ |
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
static void _stp_print_cleanup(void) |
| 35 |
{ |
| 36 |
/* Since 'print_buf' is now in the context structure (see |
| 37 |
* common_probe_context.h), there isn't anything to free for |
| 38 |
* it. */ |
| 39 |
} |
| 40 |
|
| 41 |
static inline void _stp_print_flush(void) |
| 42 |
{ |
| 43 |
_stp_dyninst_transport_write(); |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
static void * _stp_reserve_bytes (int numbytes) |
| 48 |
{ |
| 49 |
return _stp_dyninst_transport_reserve_bytes(numbytes); |
| 50 |
} |
| 51 |
|
| 52 |
#ifndef STP_MAXBINARYARGS |
| 53 |
#define STP_MAXBINARYARGS 127 |
| 54 |
#endif |
| 55 |
|
| 56 |
static void _stp_unreserve_bytes (int numbytes) |
| 57 |
{ |
| 58 |
_stp_dyninst_transport_unreserve_bytes(numbytes); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
/** Write 64-bit args directly into the output stream. |
| 63 |
* This function takes a variable number of 64-bit arguments |
| 64 |
* and writes them directly into the output stream. Marginally faster |
| 65 |
* than doing the same in _stp_vsnprintf(). |
| 66 |
* @sa _stp_vsnprintf() |
| 67 |
*/ |
| 68 |
static void _stp_print_binary (int num, ...) |
| 69 |
{ |
| 70 |
va_list vargs; |
| 71 |
int i; |
| 72 |
int64_t *args; |
| 73 |
|
| 74 |
if (unlikely(num > STP_MAXBINARYARGS)) |
| 75 |
num = STP_MAXBINARYARGS; |
| 76 |
|
| 77 |
args = _stp_reserve_bytes(num * sizeof(int64_t)); |
| 78 |
|
| 79 |
if (likely(args != NULL)) { |
| 80 |
va_start(vargs, num); |
| 81 |
for (i = 0; i < num; i++) { |
| 82 |
args[i] = va_arg(vargs, int64_t); |
| 83 |
} |
| 84 |
va_end(vargs); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
static void _stp_printf (const char *fmt, ...) |
| 89 |
{ |
| 90 |
va_list args; |
| 91 |
va_start(args, fmt); |
| 92 |
_stp_vsnprintf(NULL, 0, fmt, args); |
| 93 |
va_end(args); |
| 94 |
} |
| 95 |
|
| 96 |
static void _stp_print (const char *str) |
| 97 |
{ |
| 98 |
_stp_printf("%s", str); |
| 99 |
} |
| 100 |
|
| 101 |
static void _stp_print_char (const char c) |
| 102 |
{ |
| 103 |
char *p = _stp_reserve_bytes(1);; |
| 104 |
|
| 105 |
if (p) { |
| 106 |
*p = c; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
/* libdw includes stdbool.h which defines bool as _Bool which clashes with |
| 112 |
* stap definition of _stp_print_trylock_irqsave. */ |
| 113 |
#undef bool |
| 114 |
/* no-op stub synchronization */ |
| 115 |
static bool _stp_print_trylock_irqsave(unsigned long *flags) |
| 116 |
{ |
| 117 |
(void) flags; |
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
static void _stp_print_unlock_irqrestore(unsigned long *flags) |
| 122 |
{ |
| 123 |
(void) flags; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
#endif /* _STAPDYN_PRINT_C_ */ |