File: print.c

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (127 lines) | stat: -rw-r--r-- 2,700 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* -*- linux-c -*- 
 * Print Functions
 * Copyright (C) 2012-2018 Red Hat Inc.
 *
 * This file is part of systemtap, and is free software.  You can
 * redistribute it and/or modify it under the terms of the GNU General
 * Public License (GPL); either version 2, or (at your option) any
 * later version.
 */

#ifndef _STAPDYN_PRINT_C_
#define _STAPDYN_PRINT_C_

#ifdef STP_BULKMODE
#error "Bulk mode output (percpu files) not supported for --runtime=dyninst"
#endif

#include "transport.c"
#include "vsprintf.c"

static void _stp_print_kernel_info(char *sname, char *vstr, int ctx, int num_probes)
{
	// nah...
}

static int _stp_print_init(void)
{
	/* Since 'print_buf' is now in the context structure (see
	 * common_probe_context.h), there isn't anything to do for
	 * regular print buffers. */
	return 0;
}

static void _stp_print_cleanup(void)
{
	/* Since 'print_buf' is now in the context structure (see
	 * common_probe_context.h), there isn't anything to free for
	 * it. */
}

static inline void _stp_print_flush(void)
{
	_stp_dyninst_transport_write();
	return;
}

static void * _stp_reserve_bytes (int numbytes)
{
	return _stp_dyninst_transport_reserve_bytes(numbytes);
}

#ifndef STP_MAXBINARYARGS
#define STP_MAXBINARYARGS 127
#endif

static void _stp_unreserve_bytes (int numbytes)
{
	_stp_dyninst_transport_unreserve_bytes(numbytes);
	return;
}

/** Write 64-bit args directly into the output stream.
 * This function takes a variable number of 64-bit arguments
 * and writes them directly into the output stream.  Marginally faster
 * than doing the same in _stp_vsnprintf().
 * @sa _stp_vsnprintf()
 */
static void _stp_print_binary (int num, ...)
{
	va_list vargs;
	int i;
	int64_t *args;
	
	if (unlikely(num > STP_MAXBINARYARGS))
		num = STP_MAXBINARYARGS;

	args = _stp_reserve_bytes(num * sizeof(int64_t));

	if (likely(args != NULL)) {
		va_start(vargs, num);
		for (i = 0; i < num; i++) {
			args[i] = va_arg(vargs, int64_t);
		}
		va_end(vargs);
	}
}

static void _stp_printf (const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	_stp_vsnprintf(NULL, 0, fmt, args);
	va_end(args);
}

static void _stp_print (const char *str)
{
	_stp_printf("%s", str);
}

static void _stp_print_char (const char c)
{
	char *p = _stp_reserve_bytes(1);;

	if (p) {
		*p = c;
	}
}


/* libdw includes stdbool.h which defines bool as _Bool which clashes with
 * stap definition of _stp_print_trylock_irqsave. */
#undef bool
/* no-op stub synchronization */
static bool _stp_print_trylock_irqsave(unsigned long *flags)
{
        (void) flags;
        return true;
}

static void _stp_print_unlock_irqrestore(unsigned long *flags)
{
        (void) flags;
}


#endif /* _STAPDYN_PRINT_C_ */