File: prepare-bt-script.awk

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (53 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download
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
# SPDX-License-Identifier: BSD-2-Clause

# Example inputs:
# group:name { some %s fmt %d spec %d -> str(arg0), (int)arg1, arg2 - 10 }
{
	if (!has_contents)
		printf("BEGIN { printf(\"STARTED!\\n\"); }\n");
	has_contents = 1;

	# Split between { and }, extract insides of { }
	split($0, parts, /[{}]/)

	probe_spec = parts[1]
	gsub(/^[ \t]+|[ \t]+$/, "", probe_spec) # trim trailing whitespaces

	split(probe_spec, probe, ":")
	if (length(probe) == 3 && probe[1] == "lib") {	# lib:<group>:<name>
		path = OUTPUT "/lib" TEST ".so";
		group = probe[2];
		name = probe[3];
	} else if (length(probe) == 2) {		# <group>:<name>
		path = OUTPUT "/" TEST;
		group = probe[1];
		name = probe[2];
	} else {
		printf("UNEXPECTED target binary specification in '%s'!\n", parts[1]);
		exit(1);
	}

	stmt_spec = parts[2]
	gsub(/^[ \t]+|[ \t]+$/, "", stmt_spec) # trim trailing whitespaces

	# Split by (optional) ->, trim spaces, extract fmt spec and args
	split(stmt_spec, stmt_parts, "->");
	fmt = stmt_parts[1];
	args = stmt_parts[2];
	gsub(/^[ \t]+|[ \t]+$/, "", fmt) # trim trailing whitespaces
	gsub(/^[ \t]+|[ \t]+$/, "", args) # trim trailin whitespaces

	# Emit corresponding bpftrace probe spec:
	# U:./test:group:name { printf("%s: some %s fmt %d spec %d\n", probe, str(arg0), (int)arg1, arg2 - 10); }
	printf("U:%s:%s:%s { printf(\"%s%s:%s: %s\\n\"%s); }\n",
	       path, group, name,
	       probe[1] == "lib" ? "lib:" : "", group, name,
	       fmt, args == "" ? "" : ", " args);
}

END {
	if (has_contents) {
		printf("uretprobe:%s:main { exit(); }\n", OUTPUT "/" TEST);
		printf("END { printf(\"DONE!\\n\"); }\n");
	}
}