aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/Makefile2
-rw-r--r--tools/perf/Documentation/perf-list.txt6
-rw-r--r--tools/perf/Makefile.perf2
-rw-r--r--tools/perf/arch/powerpc/util/header.c4
-rw-r--r--tools/perf/bench/bench.h22
-rw-r--r--tools/perf/bench/mem-memcpy-arch.h2
-rw-r--r--tools/perf/bench/mem-memset-arch.h2
-rw-r--r--tools/perf/bench/numa.c2
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-diff.c2
-rw-r--r--tools/perf/builtin-help.c69
-rw-r--r--tools/perf/builtin-inject.c8
-rw-r--r--tools/perf/builtin-mem.c2
-rw-r--r--tools/perf/builtin-report.c3
-rw-r--r--tools/perf/builtin-script.c46
-rw-r--r--tools/perf/builtin-timechart.c2
-rw-r--r--tools/perf/builtin-top.c8
-rw-r--r--tools/perf/builtin-trace.c9
-rw-r--r--tools/perf/builtin.h64
-rw-r--r--tools/perf/config/Makefile2
-rw-r--r--tools/perf/config/utilities.mak179
-rw-r--r--tools/perf/tests/code-reading.c5
-rw-r--r--tools/perf/tests/dwarf-unwind.c4
-rw-r--r--tools/perf/tests/hists_common.c6
-rw-r--r--tools/perf/tests/hists_cumulate.c9
-rw-r--r--tools/perf/tests/hists_filter.c9
-rw-r--r--tools/perf/tests/hists_link.c20
-rw-r--r--tools/perf/tests/hists_output.c9
-rw-r--r--tools/perf/ui/gtk/hists.c2
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/abspath.c37
-rw-r--r--tools/perf/util/annotate.h2
-rw-r--r--tools/perf/util/auxtrace.h2
-rw-r--r--tools/perf/util/build-id.c3
-rw-r--r--tools/perf/util/cache.h24
-rw-r--r--tools/perf/util/callchain.h4
-rw-r--r--tools/perf/util/cgroup.h4
-rw-r--r--tools/perf/util/cloexec.h2
-rw-r--r--tools/perf/util/data-convert-bt.c2
-rw-r--r--tools/perf/util/db-export.c2
-rw-r--r--tools/perf/util/dso.h3
-rw-r--r--tools/perf/util/dwarf-aux.c10
-rw-r--r--tools/perf/util/dwarf-aux.h72
-rw-r--r--tools/perf/util/event.c23
-rw-r--r--tools/perf/util/event.h13
-rw-r--r--tools/perf/util/evsel.c1
-rw-r--r--tools/perf/util/genelf.h8
-rw-r--r--tools/perf/util/header.c5
-rw-r--r--tools/perf/util/header.h2
-rw-r--r--tools/perf/util/hist.c2
-rw-r--r--tools/perf/util/hist.h3
-rw-r--r--tools/perf/util/intel-bts.c2
-rw-r--r--tools/perf/util/jit.h12
-rw-r--r--tools/perf/util/llvm-utils.c24
-rw-r--r--tools/perf/util/llvm-utils.h7
-rw-r--r--tools/perf/util/machine.c14
-rw-r--r--tools/perf/util/machine.h2
-rw-r--r--tools/perf/util/parse-events.h21
-rw-r--r--tools/perf/util/path.c30
-rw-r--r--tools/perf/util/probe-event.c2
-rw-r--r--tools/perf/util/probe-event.h57
-rw-r--r--tools/perf/util/probe-finder.c8
-rw-r--r--tools/perf/util/probe-finder.h24
-rw-r--r--tools/perf/util/quote.h2
-rw-r--r--tools/perf/util/session.c5
-rw-r--r--tools/perf/util/sort.c2
-rw-r--r--tools/perf/util/stat-shadow.c18
-rw-r--r--tools/perf/util/strbuf.c9
-rw-r--r--tools/perf/util/strbuf.h21
-rw-r--r--tools/perf/util/svghelper.h51
-rw-r--r--tools/perf/util/symbol-elf.c12
-rw-r--r--tools/perf/util/symbol.h4
-rw-r--r--tools/perf/util/usage.c8
-rw-r--r--tools/perf/util/util.h27
-rw-r--r--tools/perf/util/wrapper.c12
75 files changed, 370 insertions, 731 deletions
diff --git a/tools/perf/Documentation/Makefile b/tools/perf/Documentation/Makefile
index 3ba1c0b09908..098cfb9ca8f0 100644
--- a/tools/perf/Documentation/Makefile
+++ b/tools/perf/Documentation/Makefile
@@ -1,5 +1,5 @@
1include ../../scripts/Makefile.include 1include ../../scripts/Makefile.include
2include ../config/utilities.mak 2include ../../scripts/utilities.mak
3 3
4MAN1_TXT= \ 4MAN1_TXT= \
5 $(filter-out $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \ 5 $(filter-out $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 79483f40e991..ec723d0a5bb3 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -40,10 +40,12 @@ address should be. The 'p' modifier can be specified multiple times:
40 0 - SAMPLE_IP can have arbitrary skid 40 0 - SAMPLE_IP can have arbitrary skid
41 1 - SAMPLE_IP must have constant skid 41 1 - SAMPLE_IP must have constant skid
42 2 - SAMPLE_IP requested to have 0 skid 42 2 - SAMPLE_IP requested to have 0 skid
43 3 - SAMPLE_IP must have 0 skid 43 3 - SAMPLE_IP must have 0 skid, or uses randomization to avoid
44 sample shadowing effects.
44 45
45For Intel systems precise event sampling is implemented with PEBS 46For Intel systems precise event sampling is implemented with PEBS
46which supports up to precise-level 2. 47which supports up to precise-level 2, and precise level 3 for
48some special cases
47 49
48On AMD systems it is implemented using IBS (up to precise-level 2). 50On AMD systems it is implemented using IBS (up to precise-level 2).
49The precise modifier works with event types 0x76 (cpu-cycles, CPU 51The precise modifier works with event types 0x76 (cpu-cycles, CPU
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 4a4fad4182f5..000ea210389d 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -3,7 +3,7 @@ include ../scripts/Makefile.include
3# The default target of this Makefile is... 3# The default target of this Makefile is...
4all: 4all:
5 5
6include config/utilities.mak 6include ../scripts/utilities.mak
7 7
8# Define V to have a more verbose compile. 8# Define V to have a more verbose compile.
9# 9#
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index 6c1b8a75db09..6138bdef6e63 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -3,9 +3,7 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h> 5#include <string.h>
6 6#include <linux/stringify.h>
7#include "../../util/header.h"
8#include "../../util/util.h"
9 7
10#define mfspr(rn) ({unsigned long rval; \ 8#define mfspr(rn) ({unsigned long rval; \
11 asm volatile("mfspr %0," __stringify(rn) \ 9 asm volatile("mfspr %0," __stringify(rn) \
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index a50df86f2b9b..579a592990dd 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -25,19 +25,17 @@
25# endif 25# endif
26#endif 26#endif
27 27
28extern int bench_numa(int argc, const char **argv, const char *prefix); 28int bench_numa(int argc, const char **argv, const char *prefix);
29extern int bench_sched_messaging(int argc, const char **argv, const char *prefix); 29int bench_sched_messaging(int argc, const char **argv, const char *prefix);
30extern int bench_sched_pipe(int argc, const char **argv, const char *prefix); 30int bench_sched_pipe(int argc, const char **argv, const char *prefix);
31extern int bench_mem_memcpy(int argc, const char **argv, 31int bench_mem_memcpy(int argc, const char **argv, const char *prefix);
32 const char *prefix __maybe_unused); 32int bench_mem_memset(int argc, const char **argv, const char *prefix);
33extern int bench_mem_memset(int argc, const char **argv, const char *prefix); 33int bench_futex_hash(int argc, const char **argv, const char *prefix);
34extern int bench_futex_hash(int argc, const char **argv, const char *prefix); 34int bench_futex_wake(int argc, const char **argv, const char *prefix);
35extern int bench_futex_wake(int argc, const char **argv, const char *prefix); 35int bench_futex_wake_parallel(int argc, const char **argv, const char *prefix);
36extern int bench_futex_wake_parallel(int argc, const char **argv, 36int bench_futex_requeue(int argc, const char **argv, const char *prefix);
37 const char *prefix);
38extern int bench_futex_requeue(int argc, const char **argv, const char *prefix);
39/* pi futexes */ 37/* pi futexes */
40extern int bench_futex_lock_pi(int argc, const char **argv, const char *prefix); 38int bench_futex_lock_pi(int argc, const char **argv, const char *prefix);
41 39
42#define BENCH_FORMAT_DEFAULT_STR "default" 40#define BENCH_FORMAT_DEFAULT_STR "default"
43#define BENCH_FORMAT_DEFAULT 0 41#define BENCH_FORMAT_DEFAULT 0
diff --git a/tools/perf/bench/mem-memcpy-arch.h b/tools/perf/bench/mem-memcpy-arch.h
index 57b4ed871459..5aad2a9408b0 100644
--- a/tools/perf/bench/mem-memcpy-arch.h
+++ b/tools/perf/bench/mem-memcpy-arch.h
@@ -2,7 +2,7 @@
2#ifdef HAVE_ARCH_X86_64_SUPPORT 2#ifdef HAVE_ARCH_X86_64_SUPPORT
3 3
4#define MEMCPY_FN(fn, name, desc) \ 4#define MEMCPY_FN(fn, name, desc) \
5 extern void *fn(void *, const void *, size_t); 5 void *fn(void *, const void *, size_t);
6 6
7#include "mem-memcpy-x86-64-asm-def.h" 7#include "mem-memcpy-x86-64-asm-def.h"
8 8
diff --git a/tools/perf/bench/mem-memset-arch.h b/tools/perf/bench/mem-memset-arch.h
index 633800cb0dcb..0d15786d9ae3 100644
--- a/tools/perf/bench/mem-memset-arch.h
+++ b/tools/perf/bench/mem-memset-arch.h
@@ -2,7 +2,7 @@
2#ifdef HAVE_ARCH_X86_64_SUPPORT 2#ifdef HAVE_ARCH_X86_64_SUPPORT
3 3
4#define MEMSET_FN(fn, name, desc) \ 4#define MEMSET_FN(fn, name, desc) \
5 extern void *fn(void *, int, size_t); 5 void *fn(void *, int, size_t);
6 6
7#include "mem-memset-x86-64-asm-def.h" 7#include "mem-memset-x86-64-asm-def.h"
8 8
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 5049d6357a46..7500d959d7eb 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -293,7 +293,7 @@ static void bind_to_memnode(int node)
293 if (node == -1) 293 if (node == -1)
294 return; 294 return;
295 295
296 BUG_ON(g->p.nr_nodes > (int)sizeof(nodemask)); 296 BUG_ON(g->p.nr_nodes > (int)sizeof(nodemask)*8);
297 nodemask = 1L << node; 297 nodemask = 1L << node;
298 298
299 ret = set_mempolicy(MPOL_BIND, &nodemask, sizeof(nodemask)*8); 299 ret = set_mempolicy(MPOL_BIND, &nodemask, sizeof(nodemask)*8);
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index cfe366375c4b..814158393656 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -94,7 +94,7 @@ static int process_sample_event(struct perf_tool *tool,
94 struct addr_location al; 94 struct addr_location al;
95 int ret = 0; 95 int ret = 0;
96 96
97 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 97 if (machine__resolve(machine, &al, sample) < 0) {
98 pr_warning("problem processing %d event, skipping it.\n", 98 pr_warning("problem processing %d event, skipping it.\n",
99 event->header.type); 99 event->header.type);
100 return -1; 100 return -1;
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 4d72359fd15a..8053a8ceefda 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -330,7 +330,7 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
330 struct hists *hists = evsel__hists(evsel); 330 struct hists *hists = evsel__hists(evsel);
331 int ret = -1; 331 int ret = -1;
332 332
333 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 333 if (machine__resolve(machine, &al, sample) < 0) {
334 pr_warning("problem processing %d event, skipping it.\n", 334 pr_warning("problem processing %d event, skipping it.\n",
335 event->header.type); 335 event->header.type);
336 return -1; 336 return -1;
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 49d55e21b1b0..bc1de9b8fd67 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -106,12 +106,14 @@ static void exec_woman_emacs(const char *path, const char *page)
106 106
107 if (!check_emacsclient_version()) { 107 if (!check_emacsclient_version()) {
108 /* This works only with emacsclient version >= 22. */ 108 /* This works only with emacsclient version >= 22. */
109 struct strbuf man_page = STRBUF_INIT; 109 char *man_page;
110 110
111 if (!path) 111 if (!path)
112 path = "emacsclient"; 112 path = "emacsclient";
113 strbuf_addf(&man_page, "(woman \"%s\")", page); 113 if (asprintf(&man_page, "(woman \"%s\")", page) > 0) {
114 execlp(path, "emacsclient", "-e", man_page.buf, NULL); 114 execlp(path, "emacsclient", "-e", man_page, NULL);
115 free(man_page);
116 }
115 warning("failed to exec '%s': %s", path, 117 warning("failed to exec '%s': %s", path,
116 strerror_r(errno, sbuf, sizeof(sbuf))); 118 strerror_r(errno, sbuf, sizeof(sbuf)));
117 } 119 }
@@ -122,7 +124,7 @@ static void exec_man_konqueror(const char *path, const char *page)
122 const char *display = getenv("DISPLAY"); 124 const char *display = getenv("DISPLAY");
123 125
124 if (display && *display) { 126 if (display && *display) {
125 struct strbuf man_page = STRBUF_INIT; 127 char *man_page;
126 const char *filename = "kfmclient"; 128 const char *filename = "kfmclient";
127 char sbuf[STRERR_BUFSIZE]; 129 char sbuf[STRERR_BUFSIZE];
128 130
@@ -141,8 +143,10 @@ static void exec_man_konqueror(const char *path, const char *page)
141 filename = file; 143 filename = file;
142 } else 144 } else
143 path = "kfmclient"; 145 path = "kfmclient";
144 strbuf_addf(&man_page, "man:%s(1)", page); 146 if (asprintf(&man_page, "man:%s(1)", page) > 0) {
145 execlp(path, filename, "newTab", man_page.buf, NULL); 147 execlp(path, filename, "newTab", man_page, NULL);
148 free(man_page);
149 }
146 warning("failed to exec '%s': %s", path, 150 warning("failed to exec '%s': %s", path,
147 strerror_r(errno, sbuf, sizeof(sbuf))); 151 strerror_r(errno, sbuf, sizeof(sbuf)));
148 } 152 }
@@ -161,11 +165,13 @@ static void exec_man_man(const char *path, const char *page)
161 165
162static void exec_man_cmd(const char *cmd, const char *page) 166static void exec_man_cmd(const char *cmd, const char *page)
163{ 167{
164 struct strbuf shell_cmd = STRBUF_INIT;
165 char sbuf[STRERR_BUFSIZE]; 168 char sbuf[STRERR_BUFSIZE];
169 char *shell_cmd;
166 170
167 strbuf_addf(&shell_cmd, "%s %s", cmd, page); 171 if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) {
168 execl("/bin/sh", "sh", "-c", shell_cmd.buf, NULL); 172 execl("/bin/sh", "sh", "-c", shell_cmd, NULL);
173 free(shell_cmd);
174 }
169 warning("failed to exec '%s': %s", cmd, 175 warning("failed to exec '%s': %s", cmd,
170 strerror_r(errno, sbuf, sizeof(sbuf))); 176 strerror_r(errno, sbuf, sizeof(sbuf)));
171} 177}
@@ -299,43 +305,33 @@ static int is_perf_command(const char *s)
299 is_in_cmdlist(&other_cmds, s); 305 is_in_cmdlist(&other_cmds, s);
300} 306}
301 307
302static const char *prepend(const char *prefix, const char *cmd)
303{
304 size_t pre_len = strlen(prefix);
305 size_t cmd_len = strlen(cmd);
306 char *p = malloc(pre_len + cmd_len + 1);
307 memcpy(p, prefix, pre_len);
308 strcpy(p + pre_len, cmd);
309 return p;
310}
311
312static const char *cmd_to_page(const char *perf_cmd) 308static const char *cmd_to_page(const char *perf_cmd)
313{ 309{
310 char *s;
311
314 if (!perf_cmd) 312 if (!perf_cmd)
315 return "perf"; 313 return "perf";
316 else if (!prefixcmp(perf_cmd, "perf")) 314 else if (!prefixcmp(perf_cmd, "perf"))
317 return perf_cmd; 315 return perf_cmd;
318 else 316
319 return prepend("perf-", perf_cmd); 317 return asprintf(&s, "perf-%s", perf_cmd) < 0 ? NULL : s;
320} 318}
321 319
322static void setup_man_path(void) 320static void setup_man_path(void)
323{ 321{
324 struct strbuf new_path = STRBUF_INIT; 322 char *new_path;
325 const char *old_path = getenv("MANPATH"); 323 const char *old_path = getenv("MANPATH");
326 324
327 /* We should always put ':' after our path. If there is no 325 /* We should always put ':' after our path. If there is no
328 * old_path, the ':' at the end will let 'man' to try 326 * old_path, the ':' at the end will let 'man' to try
329 * system-wide paths after ours to find the manual page. If 327 * system-wide paths after ours to find the manual page. If
330 * there is old_path, we need ':' as delimiter. */ 328 * there is old_path, we need ':' as delimiter. */
331 strbuf_addstr(&new_path, system_path(PERF_MAN_PATH)); 329 if (asprintf(&new_path, "%s:%s", system_path(PERF_MAN_PATH), old_path ?: "") > 0) {
332 strbuf_addch(&new_path, ':'); 330 setenv("MANPATH", new_path, 1);
333 if (old_path) 331 free(new_path);
334 strbuf_addstr(&new_path, old_path); 332 } else {
335 333 error("Unable to setup man path");
336 setenv("MANPATH", new_path.buf, 1); 334 }
337
338 strbuf_release(&new_path);
339} 335}
340 336
341static void exec_viewer(const char *name, const char *page) 337static void exec_viewer(const char *name, const char *page)
@@ -380,7 +376,7 @@ static int show_info_page(const char *perf_cmd)
380 return -1; 376 return -1;
381} 377}
382 378
383static int get_html_page_path(struct strbuf *page_path, const char *page) 379static int get_html_page_path(char **page_path, const char *page)
384{ 380{
385 struct stat st; 381 struct stat st;
386 const char *html_path = system_path(PERF_HTML_PATH); 382 const char *html_path = system_path(PERF_HTML_PATH);
@@ -392,10 +388,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)
392 return -1; 388 return -1;
393 } 389 }
394 390
395 strbuf_init(page_path, 0); 391 return asprintf(page_path, "%s/%s.html", html_path, page);
396 strbuf_addf(page_path, "%s/%s.html", html_path, page);
397
398 return 0;
399} 392}
400 393
401/* 394/*
@@ -413,12 +406,12 @@ static void open_html(const char *path)
413static int show_html_page(const char *perf_cmd) 406static int show_html_page(const char *perf_cmd)
414{ 407{
415 const char *page = cmd_to_page(perf_cmd); 408 const char *page = cmd_to_page(perf_cmd);
416 struct strbuf page_path; /* it leaks but we exec bellow */ 409 char *page_path; /* it leaks but we exec bellow */
417 410
418 if (get_html_page_path(&page_path, page) != 0) 411 if (get_html_page_path(&page_path, page) < 0)
419 return -1; 412 return -1;
420 413
421 open_html(page_path.buf); 414 open_html(page_path);
422 415
423 return 0; 416 return 0;
424} 417}
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 7fa68663ed72..d1a2d104f2bc 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -131,8 +131,7 @@ static int copy_bytes(struct perf_inject *inject, int fd, off_t size)
131 131
132static s64 perf_event__repipe_auxtrace(struct perf_tool *tool, 132static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,
133 union perf_event *event, 133 union perf_event *event,
134 struct perf_session *session 134 struct perf_session *session)
135 __maybe_unused)
136{ 135{
137 struct perf_inject *inject = container_of(tool, struct perf_inject, 136 struct perf_inject *inject = container_of(tool, struct perf_inject,
138 tool); 137 tool);
@@ -417,9 +416,6 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
417{ 416{
418 struct addr_location al; 417 struct addr_location al;
419 struct thread *thread; 418 struct thread *thread;
420 u8 cpumode;
421
422 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
423 419
424 thread = machine__findnew_thread(machine, sample->pid, sample->tid); 420 thread = machine__findnew_thread(machine, sample->pid, sample->tid);
425 if (thread == NULL) { 421 if (thread == NULL) {
@@ -428,7 +424,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
428 goto repipe; 424 goto repipe;
429 } 425 }
430 426
431 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al); 427 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
432 428
433 if (al.map != NULL) { 429 if (al.map != NULL) {
434 if (!al.map->dso->hit) { 430 if (!al.map->dso->hit) {
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 88aeac9aa1da..85db3be4b3cb 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -131,7 +131,7 @@ dump_raw_samples(struct perf_tool *tool,
131 struct addr_location al; 131 struct addr_location al;
132 const char *fmt; 132 const char *fmt;
133 133
134 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 134 if (machine__resolve(machine, &al, sample) < 0) {
135 fprintf(stderr, "problem processing %d event, skipping it.\n", 135 fprintf(stderr, "problem processing %d event, skipping it.\n",
136 event->header.type); 136 event->header.type);
137 return -1; 137 return -1;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 7eea49f9ed46..160ea23b45aa 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -41,6 +41,7 @@
41 41
42#include <dlfcn.h> 42#include <dlfcn.h>
43#include <linux/bitmap.h> 43#include <linux/bitmap.h>
44#include <linux/stringify.h>
44 45
45struct report { 46struct report {
46 struct perf_tool tool; 47 struct perf_tool tool;
@@ -154,7 +155,7 @@ static int process_sample_event(struct perf_tool *tool,
154 }; 155 };
155 int ret = 0; 156 int ret = 0;
156 157
157 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 158 if (machine__resolve(machine, &al, sample) < 0) {
158 pr_debug("problem processing %d event, skipping it.\n", 159 pr_debug("problem processing %d event, skipping it.\n",
159 event->header.type); 160 event->header.type);
160 return -1; 161 return -1;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 57f9a7e7f7d3..3770c3dffe5e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -405,9 +405,7 @@ out:
405 return 0; 405 return 0;
406} 406}
407 407
408static void print_sample_iregs(union perf_event *event __maybe_unused, 408static void print_sample_iregs(struct perf_sample *sample,
409 struct perf_sample *sample,
410 struct thread *thread __maybe_unused,
411 struct perf_event_attr *attr) 409 struct perf_event_attr *attr)
412{ 410{
413 struct regs_dump *regs = &sample->intr_regs; 411 struct regs_dump *regs = &sample->intr_regs;
@@ -476,10 +474,7 @@ mispred_str(struct branch_entry *br)
476 return br->flags.predicted ? 'P' : 'M'; 474 return br->flags.predicted ? 'P' : 'M';
477} 475}
478 476
479static void print_sample_brstack(union perf_event *event __maybe_unused, 477static void print_sample_brstack(struct perf_sample *sample)
480 struct perf_sample *sample,
481 struct thread *thread __maybe_unused,
482 struct perf_event_attr *attr __maybe_unused)
483{ 478{
484 struct branch_stack *br = sample->branch_stack; 479 struct branch_stack *br = sample->branch_stack;
485 u64 i; 480 u64 i;
@@ -498,14 +493,11 @@ static void print_sample_brstack(union perf_event *event __maybe_unused,
498 } 493 }
499} 494}
500 495
501static void print_sample_brstacksym(union perf_event *event __maybe_unused, 496static void print_sample_brstacksym(struct perf_sample *sample,
502 struct perf_sample *sample, 497 struct thread *thread)
503 struct thread *thread __maybe_unused,
504 struct perf_event_attr *attr __maybe_unused)
505{ 498{
506 struct branch_stack *br = sample->branch_stack; 499 struct branch_stack *br = sample->branch_stack;
507 struct addr_location alf, alt; 500 struct addr_location alf, alt;
508 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
509 u64 i, from, to; 501 u64 i, from, to;
510 502
511 if (!(br && br->nr)) 503 if (!(br && br->nr))
@@ -518,11 +510,11 @@ static void print_sample_brstacksym(union perf_event *event __maybe_unused,
518 from = br->entries[i].from; 510 from = br->entries[i].from;
519 to = br->entries[i].to; 511 to = br->entries[i].to;
520 512
521 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, from, &alf); 513 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
522 if (alf.map) 514 if (alf.map)
523 alf.sym = map__find_symbol(alf.map, alf.addr, NULL); 515 alf.sym = map__find_symbol(alf.map, alf.addr, NULL);
524 516
525 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, to, &alt); 517 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
526 if (alt.map) 518 if (alt.map)
527 alt.sym = map__find_symbol(alt.map, alt.addr, NULL); 519 alt.sym = map__find_symbol(alt.map, alt.addr, NULL);
528 520
@@ -538,8 +530,7 @@ static void print_sample_brstacksym(union perf_event *event __maybe_unused,
538} 530}
539 531
540 532
541static void print_sample_addr(union perf_event *event, 533static void print_sample_addr(struct perf_sample *sample,
542 struct perf_sample *sample,
543 struct thread *thread, 534 struct thread *thread,
544 struct perf_event_attr *attr) 535 struct perf_event_attr *attr)
545{ 536{
@@ -550,7 +541,7 @@ static void print_sample_addr(union perf_event *event,
550 if (!sample_addr_correlates_sym(attr)) 541 if (!sample_addr_correlates_sym(attr))
551 return; 542 return;
552 543
553 perf_event__preprocess_sample_addr(event, sample, thread, &al); 544 thread__resolve(thread, &al, sample);
554 545
555 if (PRINT_FIELD(SYM)) { 546 if (PRINT_FIELD(SYM)) {
556 printf(" "); 547 printf(" ");
@@ -567,8 +558,7 @@ static void print_sample_addr(union perf_event *event,
567 } 558 }
568} 559}
569 560
570static void print_sample_bts(union perf_event *event, 561static void print_sample_bts(struct perf_sample *sample,
571 struct perf_sample *sample,
572 struct perf_evsel *evsel, 562 struct perf_evsel *evsel,
573 struct thread *thread, 563 struct thread *thread,
574 struct addr_location *al) 564 struct addr_location *al)
@@ -598,7 +588,7 @@ static void print_sample_bts(union perf_event *event,
598 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) && 588 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
599 !output[attr->type].user_set)) { 589 !output[attr->type].user_set)) {
600 printf(" => "); 590 printf(" => ");
601 print_sample_addr(event, sample, thread, attr); 591 print_sample_addr(sample, thread, attr);
602 } 592 }
603 593
604 if (print_srcline_last) 594 if (print_srcline_last)
@@ -747,7 +737,7 @@ static size_t data_src__printf(u64 data_src)
747 return printf("%-*s", maxlen, out); 737 return printf("%-*s", maxlen, out);
748} 738}
749 739
750static void process_event(struct perf_script *script, union perf_event *event, 740static void process_event(struct perf_script *script,
751 struct perf_sample *sample, struct perf_evsel *evsel, 741 struct perf_sample *sample, struct perf_evsel *evsel,
752 struct addr_location *al) 742 struct addr_location *al)
753{ 743{
@@ -776,7 +766,7 @@ static void process_event(struct perf_script *script, union perf_event *event,
776 print_sample_flags(sample->flags); 766 print_sample_flags(sample->flags);
777 767
778 if (is_bts_event(attr)) { 768 if (is_bts_event(attr)) {
779 print_sample_bts(event, sample, evsel, thread, al); 769 print_sample_bts(sample, evsel, thread, al);
780 return; 770 return;
781 } 771 }
782 772
@@ -784,7 +774,7 @@ static void process_event(struct perf_script *script, union perf_event *event,
784 event_format__print(evsel->tp_format, sample->cpu, 774 event_format__print(evsel->tp_format, sample->cpu,
785 sample->raw_data, sample->raw_size); 775 sample->raw_data, sample->raw_size);
786 if (PRINT_FIELD(ADDR)) 776 if (PRINT_FIELD(ADDR))
787 print_sample_addr(event, sample, thread, attr); 777 print_sample_addr(sample, thread, attr);
788 778
789 if (PRINT_FIELD(DATA_SRC)) 779 if (PRINT_FIELD(DATA_SRC))
790 data_src__printf(sample->data_src); 780 data_src__printf(sample->data_src);
@@ -804,12 +794,12 @@ static void process_event(struct perf_script *script, union perf_event *event,
804 } 794 }
805 795
806 if (PRINT_FIELD(IREGS)) 796 if (PRINT_FIELD(IREGS))
807 print_sample_iregs(event, sample, thread, attr); 797 print_sample_iregs(sample, attr);
808 798
809 if (PRINT_FIELD(BRSTACK)) 799 if (PRINT_FIELD(BRSTACK))
810 print_sample_brstack(event, sample, thread, attr); 800 print_sample_brstack(sample);
811 else if (PRINT_FIELD(BRSTACKSYM)) 801 else if (PRINT_FIELD(BRSTACKSYM))
812 print_sample_brstacksym(event, sample, thread, attr); 802 print_sample_brstacksym(sample, thread);
813 803
814 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) 804 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
815 print_sample_bpf_output(sample); 805 print_sample_bpf_output(sample);
@@ -905,7 +895,7 @@ static int process_sample_event(struct perf_tool *tool,
905 return 0; 895 return 0;
906 } 896 }
907 897
908 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 898 if (machine__resolve(machine, &al, sample) < 0) {
909 pr_err("problem processing %d event, skipping it.\n", 899 pr_err("problem processing %d event, skipping it.\n",
910 event->header.type); 900 event->header.type);
911 return -1; 901 return -1;
@@ -920,7 +910,7 @@ static int process_sample_event(struct perf_tool *tool,
920 if (scripting_ops) 910 if (scripting_ops)
921 scripting_ops->process_event(event, sample, evsel, &al); 911 scripting_ops->process_event(event, sample, evsel, &al);
922 else 912 else
923 process_event(scr, event, sample, evsel, &al); 913 process_event(scr, sample, evsel, &al);
924 914
925out_put: 915out_put:
926 addr_location__put(&al); 916 addr_location__put(&al);
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index bd7a7757176f..40cc9bb3506c 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -489,7 +489,7 @@ static const char *cat_backtrace(union perf_event *event,
489 if (!chain) 489 if (!chain)
490 goto exit; 490 goto exit;
491 491
492 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 492 if (machine__resolve(machine, &al, sample) < 0) {
493 fprintf(stderr, "problem processing %d event, skipping it.\n", 493 fprintf(stderr, "problem processing %d event, skipping it.\n",
494 event->header.type); 494 event->header.type);
495 goto exit; 495 goto exit;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 94af190f6843..833214979c4f 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -67,6 +67,7 @@
67#include <sys/utsname.h> 67#include <sys/utsname.h>
68#include <sys/mman.h> 68#include <sys/mman.h>
69 69
70#include <linux/stringify.h>
70#include <linux/types.h> 71#include <linux/types.h>
71 72
72static volatile int done; 73static volatile int done;
@@ -728,7 +729,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
728 if (event->header.misc & PERF_RECORD_MISC_EXACT_IP) 729 if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
729 top->exact_samples++; 730 top->exact_samples++;
730 731
731 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) 732 if (machine__resolve(machine, &al, sample) < 0)
732 return; 733 return;
733 734
734 if (!top->kptr_restrict_warned && 735 if (!top->kptr_restrict_warned &&
@@ -809,7 +810,6 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
809 struct perf_session *session = top->session; 810 struct perf_session *session = top->session;
810 union perf_event *event; 811 union perf_event *event;
811 struct machine *machine; 812 struct machine *machine;
812 u8 origin;
813 int ret; 813 int ret;
814 814
815 while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { 815 while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
@@ -822,12 +822,10 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
822 evsel = perf_evlist__id2evsel(session->evlist, sample.id); 822 evsel = perf_evlist__id2evsel(session->evlist, sample.id);
823 assert(evsel != NULL); 823 assert(evsel != NULL);
824 824
825 origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
826
827 if (event->header.type == PERF_RECORD_SAMPLE) 825 if (event->header.type == PERF_RECORD_SAMPLE)
828 ++top->samples; 826 ++top->samples;
829 827
830 switch (origin) { 828 switch (sample.cpumode) {
831 case PERF_RECORD_MISC_USER: 829 case PERF_RECORD_MISC_USER:
832 ++top->us_samples; 830 ++top->us_samples;
833 if (top->hide_user_symbols) 831 if (top->hide_user_symbols)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 8dc98c598b1a..93ac724fb635 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2256,11 +2256,10 @@ static void print_location(FILE *f, struct perf_sample *sample,
2256 2256
2257static int trace__pgfault(struct trace *trace, 2257static int trace__pgfault(struct trace *trace,
2258 struct perf_evsel *evsel, 2258 struct perf_evsel *evsel,
2259 union perf_event *event, 2259 union perf_event *event __maybe_unused,
2260 struct perf_sample *sample) 2260 struct perf_sample *sample)
2261{ 2261{
2262 struct thread *thread; 2262 struct thread *thread;
2263 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
2264 struct addr_location al; 2263 struct addr_location al;
2265 char map_type = 'd'; 2264 char map_type = 'd';
2266 struct thread_trace *ttrace; 2265 struct thread_trace *ttrace;
@@ -2279,7 +2278,7 @@ static int trace__pgfault(struct trace *trace,
2279 if (trace->summary_only) 2278 if (trace->summary_only)
2280 goto out; 2279 goto out;
2281 2280
2282 thread__find_addr_location(thread, cpumode, MAP__FUNCTION, 2281 thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION,
2283 sample->ip, &al); 2282 sample->ip, &al);
2284 2283
2285 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); 2284 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output);
@@ -2292,11 +2291,11 @@ static int trace__pgfault(struct trace *trace,
2292 2291
2293 fprintf(trace->output, "] => "); 2292 fprintf(trace->output, "] => ");
2294 2293
2295 thread__find_addr_location(thread, cpumode, MAP__VARIABLE, 2294 thread__find_addr_location(thread, sample->cpumode, MAP__VARIABLE,
2296 sample->addr, &al); 2295 sample->addr, &al);
2297 2296
2298 if (!al.map) { 2297 if (!al.map) {
2299 thread__find_addr_location(thread, cpumode, 2298 thread__find_addr_location(thread, sample->cpumode,
2300 MAP__FUNCTION, sample->addr, &al); 2299 MAP__FUNCTION, sample->addr, &al);
2301 2300
2302 if (al.map) 2301 if (al.map)
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 3f871b54e261..41c24010ab43 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -7,38 +7,38 @@
7extern const char perf_usage_string[]; 7extern const char perf_usage_string[];
8extern const char perf_more_info_string[]; 8extern const char perf_more_info_string[];
9 9
10extern void list_common_cmds_help(void); 10void list_common_cmds_help(void);
11extern const char *help_unknown_cmd(const char *cmd); 11const char *help_unknown_cmd(const char *cmd);
12extern void prune_packed_objects(int); 12void prune_packed_objects(int);
13extern int read_line_with_nul(char *buf, int size, FILE *file); 13int read_line_with_nul(char *buf, int size, FILE *file);
14extern int check_pager_config(const char *cmd); 14int check_pager_config(const char *cmd);
15 15
16extern int cmd_annotate(int argc, const char **argv, const char *prefix); 16int cmd_annotate(int argc, const char **argv, const char *prefix);
17extern int cmd_bench(int argc, const char **argv, const char *prefix); 17int cmd_bench(int argc, const char **argv, const char *prefix);
18extern int cmd_buildid_cache(int argc, const char **argv, const char *prefix); 18int cmd_buildid_cache(int argc, const char **argv, const char *prefix);
19extern int cmd_buildid_list(int argc, const char **argv, const char *prefix); 19int cmd_buildid_list(int argc, const char **argv, const char *prefix);
20extern int cmd_config(int argc, const char **argv, const char *prefix); 20int cmd_config(int argc, const char **argv, const char *prefix);
21extern int cmd_diff(int argc, const char **argv, const char *prefix); 21int cmd_diff(int argc, const char **argv, const char *prefix);
22extern int cmd_evlist(int argc, const char **argv, const char *prefix); 22int cmd_evlist(int argc, const char **argv, const char *prefix);
23extern int cmd_help(int argc, const char **argv, const char *prefix); 23int cmd_help(int argc, const char **argv, const char *prefix);
24extern int cmd_sched(int argc, const char **argv, const char *prefix); 24int cmd_sched(int argc, const char **argv, const char *prefix);
25extern int cmd_list(int argc, const char **argv, const char *prefix); 25int cmd_list(int argc, const char **argv, const char *prefix);
26extern int cmd_record(int argc, const char **argv, const char *prefix); 26int cmd_record(int argc, const char **argv, const char *prefix);
27extern int cmd_report(int argc, const char **argv, const char *prefix); 27int cmd_report(int argc, const char **argv, const char *prefix);
28extern int cmd_stat(int argc, const char **argv, const char *prefix); 28int cmd_stat(int argc, const char **argv, const char *prefix);
29extern int cmd_timechart(int argc, const char **argv, const char *prefix); 29int cmd_timechart(int argc, const char **argv, const char *prefix);
30extern int cmd_top(int argc, const char **argv, const char *prefix); 30int cmd_top(int argc, const char **argv, const char *prefix);
31extern int cmd_script(int argc, const char **argv, const char *prefix); 31int cmd_script(int argc, const char **argv, const char *prefix);
32extern int cmd_version(int argc, const char **argv, const char *prefix); 32int cmd_version(int argc, const char **argv, const char *prefix);
33extern int cmd_probe(int argc, const char **argv, const char *prefix); 33int cmd_probe(int argc, const char **argv, const char *prefix);
34extern int cmd_kmem(int argc, const char **argv, const char *prefix); 34int cmd_kmem(int argc, const char **argv, const char *prefix);
35extern int cmd_lock(int argc, const char **argv, const char *prefix); 35int cmd_lock(int argc, const char **argv, const char *prefix);
36extern int cmd_kvm(int argc, const char **argv, const char *prefix); 36int cmd_kvm(int argc, const char **argv, const char *prefix);
37extern int cmd_test(int argc, const char **argv, const char *prefix); 37int cmd_test(int argc, const char **argv, const char *prefix);
38extern int cmd_trace(int argc, const char **argv, const char *prefix); 38int cmd_trace(int argc, const char **argv, const char *prefix);
39extern int cmd_inject(int argc, const char **argv, const char *prefix); 39int cmd_inject(int argc, const char **argv, const char *prefix);
40extern int cmd_mem(int argc, const char **argv, const char *prefix); 40int cmd_mem(int argc, const char **argv, const char *prefix);
41extern int cmd_data(int argc, const char **argv, const char *prefix); 41int cmd_data(int argc, const char **argv, const char *prefix);
42 42
43extern int find_scripts(char **scripts_array, char **scripts_path_array); 43int find_scripts(char **scripts_array, char **scripts_path_array);
44#endif 44#endif
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index eca6a912e8c2..f7d7f5a1cad5 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -109,7 +109,7 @@ ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
109 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET 109 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
110endif 110endif
111 111
112include $(src-perf)/config/utilities.mak 112include $(srctree)/tools/scripts/utilities.mak
113 113
114ifeq ($(call get-executable,$(FLEX)),) 114ifeq ($(call get-executable,$(FLEX)),)
115 dummy := $(error Error: $(FLEX) is missing on this system, please install it) 115 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
diff --git a/tools/perf/config/utilities.mak b/tools/perf/config/utilities.mak
deleted file mode 100644
index c16ce833079c..000000000000
--- a/tools/perf/config/utilities.mak
+++ /dev/null
@@ -1,179 +0,0 @@
1# This allows us to work with the newline character:
2define newline
3
4
5endef
6newline := $(newline)
7
8# nl-escape
9#
10# Usage: escape = $(call nl-escape[,escape])
11#
12# This is used as the common way to specify
13# what should replace a newline when escaping
14# newlines; the default is a bizarre string.
15#
16nl-escape = $(if $(1),$(1),m822df3020w6a44id34bt574ctac44eb9f4n)
17
18# escape-nl
19#
20# Usage: escaped-text = $(call escape-nl,text[,escape])
21#
22# GNU make's $(shell ...) function converts to a
23# single space each newline character in the output
24# produced during the expansion; this may not be
25# desirable.
26#
27# The only solution is to change each newline into
28# something that won't be converted, so that the
29# information can be recovered later with
30# $(call unescape-nl...)
31#
32escape-nl = $(subst $(newline),$(call nl-escape,$(2)),$(1))
33
34# unescape-nl
35#
36# Usage: text = $(call unescape-nl,escaped-text[,escape])
37#
38# See escape-nl.
39#
40unescape-nl = $(subst $(call nl-escape,$(2)),$(newline),$(1))
41
42# shell-escape-nl
43#
44# Usage: $(shell some-command | $(call shell-escape-nl[,escape]))
45#
46# Use this to escape newlines from within a shell call;
47# the default escape is a bizarre string.
48#
49# NOTE: The escape is used directly as a string constant
50# in an `awk' program that is delimited by shell
51# single-quotes, so be wary of the characters
52# that are chosen.
53#
54define shell-escape-nl
55awk 'NR==1 {t=$$0} NR>1 {t=t "$(nl-escape)" $$0} END {printf t}'
56endef
57
58# shell-unescape-nl
59#
60# Usage: $(shell some-command | $(call shell-unescape-nl[,escape]))
61#
62# Use this to unescape newlines from within a shell call;
63# the default escape is a bizarre string.
64#
65# NOTE: The escape is used directly as an extended regular
66# expression constant in an `awk' program that is
67# delimited by shell single-quotes, so be wary
68# of the characters that are chosen.
69#
70# (The bash shell has a bug where `{gsub(...),...}' is
71# misinterpreted as a brace expansion; this can be
72# overcome by putting a space between `{' and `gsub').
73#
74define shell-unescape-nl
75awk 'NR==1 {t=$$0} NR>1 {t=t "\n" $$0} END { gsub(/$(nl-escape)/,"\n",t); printf t }'
76endef
77
78# escape-for-shell-sq
79#
80# Usage: embeddable-text = $(call escape-for-shell-sq,text)
81#
82# This function produces text that is suitable for
83# embedding in a shell string that is delimited by
84# single-quotes.
85#
86escape-for-shell-sq = $(subst ','\'',$(1))
87
88# shell-sq
89#
90# Usage: single-quoted-and-escaped-text = $(call shell-sq,text)
91#
92shell-sq = '$(escape-for-shell-sq)'
93
94# shell-wordify
95#
96# Usage: wordified-text = $(call shell-wordify,text)
97#
98# For instance:
99#
100# |define text
101# |hello
102# |world
103# |endef
104# |
105# |target:
106# | echo $(call shell-wordify,$(text))
107#
108# At least GNU make gets confused by expanding a newline
109# within the context of a command line of a makefile rule
110# (this is in constrast to a `$(shell ...)' function call,
111# which can handle it just fine).
112#
113# This function avoids the problem by producing a string
114# that works as a shell word, regardless of whether or
115# not it contains a newline.
116#
117# If the text to be wordified contains a newline, then
118# an intrictate shell command substitution is constructed
119# to render the text as a single line; when the shell
120# processes the resulting escaped text, it transforms
121# it into the original unescaped text.
122#
123# If the text does not contain a newline, then this function
124# produces the same results as the `$(shell-sq)' function.
125#
126shell-wordify = $(if $(findstring $(newline),$(1)),$(_sw-esc-nl),$(shell-sq))
127define _sw-esc-nl
128"$$(echo $(call escape-nl,$(shell-sq),$(2)) | $(call shell-unescape-nl,$(2)))"
129endef
130
131# is-absolute
132#
133# Usage: bool-value = $(call is-absolute,path)
134#
135is-absolute = $(shell echo $(shell-sq) | grep -q ^/ && echo y)
136
137# lookup
138#
139# Usage: absolute-executable-path-or-empty = $(call lookup,path)
140#
141# (It's necessary to use `sh -c' because GNU make messes up by
142# trying too hard and getting things wrong).
143#
144lookup = $(call unescape-nl,$(shell sh -c $(_l-sh)))
145_l-sh = $(call shell-sq,command -v $(shell-sq) | $(call shell-escape-nl,))
146
147# is-executable
148#
149# Usage: bool-value = $(call is-executable,path)
150#
151# (It's necessary to use `sh -c' because GNU make messes up by
152# trying too hard and getting things wrong).
153#
154is-executable = $(call _is-executable-helper,$(shell-sq))
155_is-executable-helper = $(shell sh -c $(_is-executable-sh))
156_is-executable-sh = $(call shell-sq,test -f $(1) -a -x $(1) && echo y)
157
158# get-executable
159#
160# Usage: absolute-executable-path-or-empty = $(call get-executable,path)
161#
162# The goal is to get an absolute path for an executable;
163# the `command -v' is defined by POSIX, but it's not
164# necessarily very portable, so it's only used if
165# relative path resolution is requested, as determined
166# by the presence of a leading `/'.
167#
168get-executable = $(if $(1),$(if $(is-absolute),$(_ge-abspath),$(lookup)))
169_ge-abspath = $(if $(is-executable),$(1))
170
171# get-supplied-or-default-executable
172#
173# Usage: absolute-executable-path-or-empty = $(call get-executable-or-default,variable,default)
174#
175define get-executable-or-default
176$(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
177endef
178_ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))
179_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index afc9ad0a0515..abd3f0ec0c0b 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -293,7 +293,6 @@ static int process_sample_event(struct machine *machine,
293{ 293{
294 struct perf_sample sample; 294 struct perf_sample sample;
295 struct thread *thread; 295 struct thread *thread;
296 u8 cpumode;
297 int ret; 296 int ret;
298 297
299 if (perf_evlist__parse_sample(evlist, event, &sample)) { 298 if (perf_evlist__parse_sample(evlist, event, &sample)) {
@@ -307,9 +306,7 @@ static int process_sample_event(struct machine *machine,
307 return -1; 306 return -1;
308 } 307 }
309 308
310 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 309 ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, state);
311
312 ret = read_object_code(sample.ip, READLEN, cpumode, thread, state);
313 thread__put(thread); 310 thread__put(thread);
314 return ret; 311 return ret;
315} 312}
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 1c5c0221cea2..8f6eb853aaf7 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -20,10 +20,10 @@
20 20
21static int mmap_handler(struct perf_tool *tool __maybe_unused, 21static int mmap_handler(struct perf_tool *tool __maybe_unused,
22 union perf_event *event, 22 union perf_event *event,
23 struct perf_sample *sample __maybe_unused, 23 struct perf_sample *sample,
24 struct machine *machine) 24 struct machine *machine)
25{ 25{
26 return machine__process_mmap2_event(machine, event, NULL); 26 return machine__process_mmap2_event(machine, event, sample);
27} 27}
28 28
29static int init_live_machine(struct machine *machine) 29static int init_live_machine(struct machine *machine)
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index 071a8b5f5232..f55f4bd47932 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -100,9 +100,11 @@ struct machine *setup_fake_machine(struct machines *machines)
100 } 100 }
101 101
102 for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { 102 for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) {
103 struct perf_sample sample = {
104 .cpumode = PERF_RECORD_MISC_USER,
105 };
103 union perf_event fake_mmap_event = { 106 union perf_event fake_mmap_event = {
104 .mmap = { 107 .mmap = {
105 .header = { .misc = PERF_RECORD_MISC_USER, },
106 .pid = fake_mmap_info[i].pid, 108 .pid = fake_mmap_info[i].pid,
107 .tid = fake_mmap_info[i].pid, 109 .tid = fake_mmap_info[i].pid,
108 .start = fake_mmap_info[i].start, 110 .start = fake_mmap_info[i].start,
@@ -114,7 +116,7 @@ struct machine *setup_fake_machine(struct machines *machines)
114 strcpy(fake_mmap_event.mmap.filename, 116 strcpy(fake_mmap_event.mmap.filename,
115 fake_mmap_info[i].filename); 117 fake_mmap_info[i].filename);
116 118
117 machine__process_mmap_event(machine, &fake_mmap_event, NULL); 119 machine__process_mmap_event(machine, &fake_mmap_event, &sample);
118 } 120 }
119 121
120 for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) { 122 for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index ecf136c385d5..ed5aa9eaeb6c 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -81,11 +81,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
81 size_t i; 81 size_t i;
82 82
83 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { 83 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
84 const union perf_event event = {
85 .header = {
86 .misc = PERF_RECORD_MISC_USER,
87 },
88 };
89 struct hist_entry_iter iter = { 84 struct hist_entry_iter iter = {
90 .evsel = evsel, 85 .evsel = evsel,
91 .sample = &sample, 86 .sample = &sample,
@@ -97,13 +92,13 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
97 else 92 else
98 iter.ops = &hist_iter_normal; 93 iter.ops = &hist_iter_normal;
99 94
95 sample.cpumode = PERF_RECORD_MISC_USER;
100 sample.pid = fake_samples[i].pid; 96 sample.pid = fake_samples[i].pid;
101 sample.tid = fake_samples[i].pid; 97 sample.tid = fake_samples[i].pid;
102 sample.ip = fake_samples[i].ip; 98 sample.ip = fake_samples[i].ip;
103 sample.callchain = (struct ip_callchain *)fake_callchains[i]; 99 sample.callchain = (struct ip_callchain *)fake_callchains[i];
104 100
105 if (perf_event__preprocess_sample(&event, machine, &al, 101 if (machine__resolve(machine, &al, &sample) < 0)
106 &sample) < 0)
107 goto out; 102 goto out;
108 103
109 if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH, 104 if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c
index 34b945a55d4d..b825d24f8186 100644
--- a/tools/perf/tests/hists_filter.c
+++ b/tools/perf/tests/hists_filter.c
@@ -58,11 +58,6 @@ static int add_hist_entries(struct perf_evlist *evlist,
58 */ 58 */
59 evlist__for_each(evlist, evsel) { 59 evlist__for_each(evlist, evsel) {
60 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { 60 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
61 const union perf_event event = {
62 .header = {
63 .misc = PERF_RECORD_MISC_USER,
64 },
65 };
66 struct hist_entry_iter iter = { 61 struct hist_entry_iter iter = {
67 .evsel = evsel, 62 .evsel = evsel,
68 .sample = &sample, 63 .sample = &sample,
@@ -76,12 +71,12 @@ static int add_hist_entries(struct perf_evlist *evlist,
76 hists->dso_filter = NULL; 71 hists->dso_filter = NULL;
77 hists->symbol_filter_str = NULL; 72 hists->symbol_filter_str = NULL;
78 73
74 sample.cpumode = PERF_RECORD_MISC_USER;
79 sample.pid = fake_samples[i].pid; 75 sample.pid = fake_samples[i].pid;
80 sample.tid = fake_samples[i].pid; 76 sample.tid = fake_samples[i].pid;
81 sample.ip = fake_samples[i].ip; 77 sample.ip = fake_samples[i].ip;
82 78
83 if (perf_event__preprocess_sample(&event, machine, &al, 79 if (machine__resolve(machine, &al, &sample) < 0)
84 &sample) < 0)
85 goto out; 80 goto out;
86 81
87 al.socket = fake_samples[i].socket; 82 al.socket = fake_samples[i].socket;
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 64b257d8d557..358324e47805 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -76,17 +76,12 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
76 struct hists *hists = evsel__hists(evsel); 76 struct hists *hists = evsel__hists(evsel);
77 77
78 for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) { 78 for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) {
79 const union perf_event event = { 79 sample.cpumode = PERF_RECORD_MISC_USER;
80 .header = {
81 .misc = PERF_RECORD_MISC_USER,
82 },
83 };
84
85 sample.pid = fake_common_samples[k].pid; 80 sample.pid = fake_common_samples[k].pid;
86 sample.tid = fake_common_samples[k].pid; 81 sample.tid = fake_common_samples[k].pid;
87 sample.ip = fake_common_samples[k].ip; 82 sample.ip = fake_common_samples[k].ip;
88 if (perf_event__preprocess_sample(&event, machine, &al, 83
89 &sample) < 0) 84 if (machine__resolve(machine, &al, &sample) < 0)
90 goto out; 85 goto out;
91 86
92 he = __hists__add_entry(hists, &al, NULL, 87 he = __hists__add_entry(hists, &al, NULL,
@@ -102,17 +97,10 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
102 } 97 }
103 98
104 for (k = 0; k < ARRAY_SIZE(fake_samples[i]); k++) { 99 for (k = 0; k < ARRAY_SIZE(fake_samples[i]); k++) {
105 const union perf_event event = {
106 .header = {
107 .misc = PERF_RECORD_MISC_USER,
108 },
109 };
110
111 sample.pid = fake_samples[i][k].pid; 100 sample.pid = fake_samples[i][k].pid;
112 sample.tid = fake_samples[i][k].pid; 101 sample.tid = fake_samples[i][k].pid;
113 sample.ip = fake_samples[i][k].ip; 102 sample.ip = fake_samples[i][k].ip;
114 if (perf_event__preprocess_sample(&event, machine, &al, 103 if (machine__resolve(machine, &al, &sample) < 0)
115 &sample) < 0)
116 goto out; 104 goto out;
117 105
118 he = __hists__add_entry(hists, &al, NULL, 106 he = __hists__add_entry(hists, &al, NULL,
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index 23cce67c7e48..d3556fbe8c5c 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -51,11 +51,6 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
51 size_t i; 51 size_t i;
52 52
53 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { 53 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
54 const union perf_event event = {
55 .header = {
56 .misc = PERF_RECORD_MISC_USER,
57 },
58 };
59 struct hist_entry_iter iter = { 54 struct hist_entry_iter iter = {
60 .evsel = evsel, 55 .evsel = evsel,
61 .sample = &sample, 56 .sample = &sample,
@@ -63,13 +58,13 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
63 .hide_unresolved = false, 58 .hide_unresolved = false,
64 }; 59 };
65 60
61 sample.cpumode = PERF_RECORD_MISC_USER;
66 sample.cpu = fake_samples[i].cpu; 62 sample.cpu = fake_samples[i].cpu;
67 sample.pid = fake_samples[i].pid; 63 sample.pid = fake_samples[i].pid;
68 sample.tid = fake_samples[i].pid; 64 sample.tid = fake_samples[i].pid;
69 sample.ip = fake_samples[i].ip; 65 sample.ip = fake_samples[i].ip;
70 66
71 if (perf_event__preprocess_sample(&event, machine, &al, 67 if (machine__resolve(machine, &al, &sample) < 0)
72 &sample) < 0)
73 goto out; 68 goto out;
74 69
75 if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH, 70 if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index bd9bf7e343b1..2aa45b606fa4 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -55,7 +55,7 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
55 return he->stat_acc->_field; \ 55 return he->stat_acc->_field; \
56} \ 56} \
57 \ 57 \
58static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 58static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
59 struct perf_hpp *hpp, \ 59 struct perf_hpp *hpp, \
60 struct hist_entry *he) \ 60 struct hist_entry *he) \
61{ \ 61{ \
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index eea25e2424e9..da48fd843438 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,4 +1,3 @@
1libperf-y += abspath.o
2libperf-y += alias.o 1libperf-y += alias.o
3libperf-y += annotate.o 2libperf-y += annotate.o
4libperf-y += build-id.o 3libperf-y += build-id.o
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c
deleted file mode 100644
index 0e76affe9c36..000000000000
--- a/tools/perf/util/abspath.c
+++ /dev/null
@@ -1,37 +0,0 @@
1#include "cache.h"
2
3static const char *get_pwd_cwd(void)
4{
5 static char cwd[PATH_MAX + 1];
6 char *pwd;
7 struct stat cwd_stat, pwd_stat;
8 if (getcwd(cwd, PATH_MAX) == NULL)
9 return NULL;
10 pwd = getenv("PWD");
11 if (pwd && strcmp(pwd, cwd)) {
12 stat(cwd, &cwd_stat);
13 if (!stat(pwd, &pwd_stat) &&
14 pwd_stat.st_dev == cwd_stat.st_dev &&
15 pwd_stat.st_ino == cwd_stat.st_ino) {
16 strlcpy(cwd, pwd, PATH_MAX);
17 }
18 }
19 return cwd;
20}
21
22const char *make_nonrelative_path(const char *path)
23{
24 static char buf[PATH_MAX + 1];
25
26 if (is_absolute_path(path)) {
27 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
28 die("Too long path: %.*s", 60, path);
29 } else {
30 const char *cwd = get_pwd_cwd();
31 if (!cwd)
32 die("Cannot determine the current working directory");
33 if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
34 die("Too long path: %.*s", 60, path);
35 }
36 return buf;
37}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index cea323d9ee7e..9241f8c2b7e1 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -158,7 +158,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
158 158
159int hist_entry__annotate(struct hist_entry *he, size_t privsize); 159int hist_entry__annotate(struct hist_entry *he, size_t privsize);
160 160
161int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym); 161int symbol__annotate_init(struct map *map, struct symbol *sym);
162int symbol__annotate_printf(struct symbol *sym, struct map *map, 162int symbol__annotate_printf(struct symbol *sym, struct map *map,
163 struct perf_evsel *evsel, bool full_paths, 163 struct perf_evsel *evsel, bool full_paths,
164 int min_pcnt, int max_lines, int context); 164 int min_pcnt, int max_lines, int context);
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index e5a8e2d4f2af..57ff31ecb8e4 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -517,7 +517,7 @@ static inline void auxtrace__free(struct perf_session *session)
517 517
518static inline struct auxtrace_record * 518static inline struct auxtrace_record *
519auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, 519auxtrace_record__init(struct perf_evlist *evlist __maybe_unused,
520 int *err __maybe_unused) 520 int *err)
521{ 521{
522 *err = 0; 522 *err = 0;
523 return NULL; 523 return NULL;
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index f1479eeef7da..0573c2ec861d 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -28,7 +28,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
28 struct machine *machine) 28 struct machine *machine)
29{ 29{
30 struct addr_location al; 30 struct addr_location al;
31 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
32 struct thread *thread = machine__findnew_thread(machine, sample->pid, 31 struct thread *thread = machine__findnew_thread(machine, sample->pid,
33 sample->tid); 32 sample->tid);
34 33
@@ -38,7 +37,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
38 return -1; 37 return -1;
39 } 38 }
40 39
41 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al); 40 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
42 41
43 if (al.map != NULL) 42 if (al.map != NULL)
44 al.map->dso->hit = 1; 43 al.map->dso->hit = 1;
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 3ca453f0c51f..1f5a93c2c9a2 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -26,14 +26,14 @@
26extern const char *config_exclusive_filename; 26extern const char *config_exclusive_filename;
27 27
28typedef int (*config_fn_t)(const char *, const char *, void *); 28typedef int (*config_fn_t)(const char *, const char *, void *);
29extern int perf_default_config(const char *, const char *, void *); 29int perf_default_config(const char *, const char *, void *);
30extern int perf_config(config_fn_t fn, void *); 30int perf_config(config_fn_t fn, void *);
31extern int perf_config_int(const char *, const char *); 31int perf_config_int(const char *, const char *);
32extern u64 perf_config_u64(const char *, const char *); 32u64 perf_config_u64(const char *, const char *);
33extern int perf_config_bool(const char *, const char *); 33int perf_config_bool(const char *, const char *);
34extern int config_error_nonbool(const char *); 34int config_error_nonbool(const char *);
35extern const char *perf_config_dirname(const char *, const char *); 35const char *perf_config_dirname(const char *, const char *);
36extern const char *perf_etc_perfconfig(void); 36const char *perf_etc_perfconfig(void);
37 37
38char *alias_lookup(const char *alias); 38char *alias_lookup(const char *alias);
39int split_cmdline(char *cmdline, const char ***argv); 39int split_cmdline(char *cmdline, const char ***argv);
@@ -64,13 +64,9 @@ static inline int is_absolute_path(const char *path)
64 return path[0] == '/'; 64 return path[0] == '/';
65} 65}
66 66
67const char *make_nonrelative_path(const char *path);
68char *strip_path_suffix(const char *path, const char *suffix); 67char *strip_path_suffix(const char *path, const char *suffix);
69 68
70extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); 69char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
71extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); 70char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
72
73extern char *perf_pathdup(const char *fmt, ...)
74 __attribute__((format (printf, 1, 2)));
75 71
76#endif /* __PERF_CACHE_H */ 72#endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 18dd22269764..d2a9e694810c 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -220,7 +220,7 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
220 bool hide_unresolved); 220 bool hide_unresolved);
221 221
222extern const char record_callchain_help[]; 222extern const char record_callchain_help[];
223extern int parse_callchain_record(const char *arg, struct callchain_param *param); 223int parse_callchain_record(const char *arg, struct callchain_param *param);
224int parse_callchain_record_opt(const char *arg, struct callchain_param *param); 224int parse_callchain_record_opt(const char *arg, struct callchain_param *param);
225int parse_callchain_report_opt(const char *arg); 225int parse_callchain_report_opt(const char *arg);
226int parse_callchain_top_opt(const char *arg); 226int parse_callchain_top_opt(const char *arg);
@@ -236,7 +236,7 @@ static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,
236} 236}
237 237
238#ifdef HAVE_SKIP_CALLCHAIN_IDX 238#ifdef HAVE_SKIP_CALLCHAIN_IDX
239extern int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain); 239int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain);
240#else 240#else
241static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused, 241static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused,
242 struct ip_callchain *chain __maybe_unused) 242 struct ip_callchain *chain __maybe_unused)
diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h
index b4b8cb42fe5e..31f8dcdbd7ef 100644
--- a/tools/perf/util/cgroup.h
+++ b/tools/perf/util/cgroup.h
@@ -13,7 +13,7 @@ struct cgroup_sel {
13 13
14 14
15extern int nr_cgroups; /* number of explicit cgroups defined */ 15extern int nr_cgroups; /* number of explicit cgroups defined */
16extern void close_cgroup(struct cgroup_sel *cgrp); 16void close_cgroup(struct cgroup_sel *cgrp);
17extern int parse_cgroups(const struct option *opt, const char *str, int unset); 17int parse_cgroups(const struct option *opt, const char *str, int unset);
18 18
19#endif /* __CGROUP_H__ */ 19#endif /* __CGROUP_H__ */
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index 3bee6773ddb0..d0d465953d36 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -5,7 +5,7 @@ unsigned long perf_event_open_cloexec_flag(void);
5 5
6#ifdef __GLIBC_PREREQ 6#ifdef __GLIBC_PREREQ
7#if !__GLIBC_PREREQ(2, 6) && !defined(__UCLIBC__) 7#if !__GLIBC_PREREQ(2, 6) && !defined(__UCLIBC__)
8extern int sched_getcpu(void) __THROW; 8int sched_getcpu(void) __THROW;
9#endif 9#endif
10#endif 10#endif
11 11
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 811af89ce0bb..bbf69d248ec5 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -632,7 +632,7 @@ static bool is_flush_needed(struct ctf_stream *cs)
632} 632}
633 633
634static int process_sample_event(struct perf_tool *tool, 634static int process_sample_event(struct perf_tool *tool,
635 union perf_event *_event __maybe_unused, 635 union perf_event *_event,
636 struct perf_sample *sample, 636 struct perf_sample *sample,
637 struct perf_evsel *evsel, 637 struct perf_evsel *evsel,
638 struct machine *machine __maybe_unused) 638 struct machine *machine __maybe_unused)
diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 1c9689e4cc17..049438d51b9a 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -333,7 +333,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,
333 sample_addr_correlates_sym(&evsel->attr)) { 333 sample_addr_correlates_sym(&evsel->attr)) {
334 struct addr_location addr_al; 334 struct addr_location addr_al;
335 335
336 perf_event__preprocess_sample_addr(event, sample, thread, &addr_al); 336 thread__resolve(thread, &addr_al, sample);
337 err = db_ids_from_al(dbe, &addr_al, &es.addr_dso_db_id, 337 err = db_ids_from_al(dbe, &addr_al, &es.addr_dso_db_id,
338 &es.addr_sym_db_id, &es.addr_offset); 338 &es.addr_sym_db_id, &es.addr_offset);
339 if (err) 339 if (err)
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 45ec4d0a50ed..0953280629cf 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -162,6 +162,7 @@ struct dso {
162 u8 loaded; 162 u8 loaded;
163 u8 rel; 163 u8 rel;
164 u8 build_id[BUILD_ID_SIZE]; 164 u8 build_id[BUILD_ID_SIZE];
165 u64 text_offset;
165 const char *short_name; 166 const char *short_name;
166 const char *long_name; 167 const char *long_name;
167 u16 long_name_len; 168 u16 long_name_len;
@@ -301,7 +302,7 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,
301 * TODO 302 * TODO
302*/ 303*/
303int dso__data_get_fd(struct dso *dso, struct machine *machine); 304int dso__data_get_fd(struct dso *dso, struct machine *machine);
304void dso__data_put_fd(struct dso *dso __maybe_unused); 305void dso__data_put_fd(struct dso *dso);
305void dso__data_close(struct dso *dso); 306void dso__data_close(struct dso *dso);
306 307
307off_t dso__data_size(struct dso *dso, struct machine *machine); 308off_t dso__data_size(struct dso *dso, struct machine *machine);
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index a509aa8433a1..577e600c8eb1 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -915,7 +915,7 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
915 tmp = "*"; 915 tmp = "*";
916 else if (tag == DW_TAG_subroutine_type) { 916 else if (tag == DW_TAG_subroutine_type) {
917 /* Function pointer */ 917 /* Function pointer */
918 strbuf_addf(buf, "(function_type)"); 918 strbuf_add(buf, "(function_type)", 15);
919 return 0; 919 return 0;
920 } else { 920 } else {
921 if (!dwarf_diename(&type)) 921 if (!dwarf_diename(&type))
@@ -932,7 +932,7 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
932 } 932 }
933 ret = die_get_typename(&type, buf); 933 ret = die_get_typename(&type, buf);
934 if (ret == 0) 934 if (ret == 0)
935 strbuf_addf(buf, "%s", tmp); 935 strbuf_addstr(buf, tmp);
936 936
937 return ret; 937 return ret;
938} 938}
@@ -951,7 +951,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
951 ret = die_get_typename(vr_die, buf); 951 ret = die_get_typename(vr_die, buf);
952 if (ret < 0) { 952 if (ret < 0) {
953 pr_debug("Failed to get type, make it unknown.\n"); 953 pr_debug("Failed to get type, make it unknown.\n");
954 strbuf_addf(buf, "(unknown_type)"); 954 strbuf_add(buf, " (unknown_type)", 14);
955 } 955 }
956 956
957 strbuf_addf(buf, "\t%s", dwarf_diename(vr_die)); 957 strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
@@ -1013,7 +1013,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,
1013 } 1013 }
1014 1014
1015 if (!first) 1015 if (!first)
1016 strbuf_addf(buf, "]>"); 1016 strbuf_add(buf, "]>", 2);
1017 1017
1018out: 1018out:
1019 free(scopes); 1019 free(scopes);
@@ -1076,7 +1076,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)
1076 } 1076 }
1077 1077
1078 if (!first) 1078 if (!first)
1079 strbuf_addf(buf, "]>"); 1079 strbuf_add(buf, "]>", 2);
1080 1080
1081 return ret; 1081 return ret;
1082} 1082}
diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h
index c42ec366f2a7..dc0ce1adb075 100644
--- a/tools/perf/util/dwarf-aux.h
+++ b/tools/perf/util/dwarf-aux.h
@@ -25,48 +25,48 @@
25#include <elfutils/version.h> 25#include <elfutils/version.h>
26 26
27/* Find the realpath of the target file */ 27/* Find the realpath of the target file */
28extern const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname); 28const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname);
29 29
30/* Get DW_AT_comp_dir (should be NULL with older gcc) */ 30/* Get DW_AT_comp_dir (should be NULL with older gcc) */
31extern const char *cu_get_comp_dir(Dwarf_Die *cu_die); 31const char *cu_get_comp_dir(Dwarf_Die *cu_die);
32 32
33/* Get a line number and file name for given address */ 33/* Get a line number and file name for given address */
34extern int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr, 34int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr,
35 const char **fname, int *lineno); 35 const char **fname, int *lineno);
36 36
37/* Walk on funcitons at given address */ 37/* Walk on funcitons at given address */
38extern int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr, 38int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
39 int (*callback)(Dwarf_Die *, void *), void *data); 39 int (*callback)(Dwarf_Die *, void *), void *data);
40 40
41/* Ensure that this DIE is a subprogram and definition (not declaration) */ 41/* Ensure that this DIE is a subprogram and definition (not declaration) */
42extern bool die_is_func_def(Dwarf_Die *dw_die); 42bool die_is_func_def(Dwarf_Die *dw_die);
43 43
44/* Ensure that this DIE is an instance of a subprogram */ 44/* Ensure that this DIE is an instance of a subprogram */
45extern bool die_is_func_instance(Dwarf_Die *dw_die); 45bool die_is_func_instance(Dwarf_Die *dw_die);
46 46
47/* Compare diename and tname */ 47/* Compare diename and tname */
48extern bool die_compare_name(Dwarf_Die *dw_die, const char *tname); 48bool die_compare_name(Dwarf_Die *dw_die, const char *tname);
49 49
50/* Matching diename with glob pattern */ 50/* Matching diename with glob pattern */
51extern bool die_match_name(Dwarf_Die *dw_die, const char *glob); 51bool die_match_name(Dwarf_Die *dw_die, const char *glob);
52 52
53/* Get callsite line number of inline-function instance */ 53/* Get callsite line number of inline-function instance */
54extern int die_get_call_lineno(Dwarf_Die *in_die); 54int die_get_call_lineno(Dwarf_Die *in_die);
55 55
56/* Get callsite file name of inlined function instance */ 56/* Get callsite file name of inlined function instance */
57extern const char *die_get_call_file(Dwarf_Die *in_die); 57const char *die_get_call_file(Dwarf_Die *in_die);
58 58
59/* Get type die */ 59/* Get type die */
60extern Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); 60Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem);
61 61
62/* Get a type die, but skip qualifiers and typedef */ 62/* Get a type die, but skip qualifiers and typedef */
63extern Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); 63Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem);
64 64
65/* Check whether the DIE is signed or not */ 65/* Check whether the DIE is signed or not */
66extern bool die_is_signed_type(Dwarf_Die *tp_die); 66bool die_is_signed_type(Dwarf_Die *tp_die);
67 67
68/* Get data_member_location offset */ 68/* Get data_member_location offset */
69extern int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs); 69int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs);
70 70
71/* Return values for die_find_child() callbacks */ 71/* Return values for die_find_child() callbacks */
72enum { 72enum {
@@ -77,29 +77,29 @@ enum {
77}; 77};
78 78
79/* Search child DIEs */ 79/* Search child DIEs */
80extern Dwarf_Die *die_find_child(Dwarf_Die *rt_die, 80Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
81 int (*callback)(Dwarf_Die *, void *), 81 int (*callback)(Dwarf_Die *, void *),
82 void *data, Dwarf_Die *die_mem); 82 void *data, Dwarf_Die *die_mem);
83 83
84/* Search a non-inlined function including given address */ 84/* Search a non-inlined function including given address */
85extern Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, 85Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
86 Dwarf_Die *die_mem); 86 Dwarf_Die *die_mem);
87 87
88/* Search a non-inlined function with tail call at given address */ 88/* Search a non-inlined function with tail call at given address */
89Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, 89Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
90 Dwarf_Die *die_mem); 90 Dwarf_Die *die_mem);
91 91
92/* Search the top inlined function including given address */ 92/* Search the top inlined function including given address */
93extern Dwarf_Die *die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, 93Dwarf_Die *die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
94 Dwarf_Die *die_mem); 94 Dwarf_Die *die_mem);
95 95
96/* Search the deepest inlined function including given address */ 96/* Search the deepest inlined function including given address */
97extern Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, 97Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
98 Dwarf_Die *die_mem); 98 Dwarf_Die *die_mem);
99 99
100/* Walk on the instances of given DIE */ 100/* Walk on the instances of given DIE */
101extern int die_walk_instances(Dwarf_Die *in_die, 101int die_walk_instances(Dwarf_Die *in_die,
102 int (*callback)(Dwarf_Die *, void *), void *data); 102 int (*callback)(Dwarf_Die *, void *), void *data);
103 103
104/* Walker on lines (Note: line number will not be sorted) */ 104/* Walker on lines (Note: line number will not be sorted) */
105typedef int (* line_walk_callback_t) (const char *fname, int lineno, 105typedef int (* line_walk_callback_t) (const char *fname, int lineno,
@@ -109,22 +109,20 @@ typedef int (* line_walk_callback_t) (const char *fname, int lineno,
109 * Walk on lines inside given DIE. If the DIE is a subprogram, walk only on 109 * Walk on lines inside given DIE. If the DIE is a subprogram, walk only on
110 * the lines inside the subprogram, otherwise the DIE must be a CU DIE. 110 * the lines inside the subprogram, otherwise the DIE must be a CU DIE.
111 */ 111 */
112extern int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, 112int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data);
113 void *data);
114 113
115/* Find a variable called 'name' at given address */ 114/* Find a variable called 'name' at given address */
116extern Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, 115Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name,
117 Dwarf_Addr addr, Dwarf_Die *die_mem); 116 Dwarf_Addr addr, Dwarf_Die *die_mem);
118 117
119/* Find a member called 'name' */ 118/* Find a member called 'name' */
120extern Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, 119Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
121 Dwarf_Die *die_mem); 120 Dwarf_Die *die_mem);
122 121
123/* Get the name of given variable DIE */ 122/* Get the name of given variable DIE */
124extern int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf); 123int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);
125 124
126/* Get the name and type of given variable DIE, stored as "type\tname" */ 125/* Get the name and type of given variable DIE, stored as "type\tname" */
127extern int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf); 126int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf);
128extern int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, 127int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf);
129 struct strbuf *buf);
130#endif 128#endif
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 7bad5c3fa7b7..52cf479bc593 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1295,12 +1295,9 @@ void thread__find_addr_location(struct thread *thread,
1295 * Callers need to drop the reference to al->thread, obtained in 1295 * Callers need to drop the reference to al->thread, obtained in
1296 * machine__findnew_thread() 1296 * machine__findnew_thread()
1297 */ 1297 */
1298int perf_event__preprocess_sample(const union perf_event *event, 1298int machine__resolve(struct machine *machine, struct addr_location *al,
1299 struct machine *machine, 1299 struct perf_sample *sample)
1300 struct addr_location *al,
1301 struct perf_sample *sample)
1302{ 1300{
1303 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1304 struct thread *thread = machine__findnew_thread(machine, sample->pid, 1301 struct thread *thread = machine__findnew_thread(machine, sample->pid,
1305 sample->tid); 1302 sample->tid);
1306 1303
@@ -1315,11 +1312,11 @@ int perf_event__preprocess_sample(const union perf_event *event,
1315 * events, but for older perf.data files there was no such thing, so do 1312 * events, but for older perf.data files there was no such thing, so do
1316 * it now. 1313 * it now.
1317 */ 1314 */
1318 if (cpumode == PERF_RECORD_MISC_KERNEL && 1315 if (sample->cpumode == PERF_RECORD_MISC_KERNEL &&
1319 machine__kernel_map(machine) == NULL) 1316 machine__kernel_map(machine) == NULL)
1320 machine__create_kernel_maps(machine); 1317 machine__create_kernel_maps(machine);
1321 1318
1322 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al); 1319 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, al);
1323 dump_printf(" ...... dso: %s\n", 1320 dump_printf(" ...... dso: %s\n",
1324 al->map ? al->map->dso->long_name : 1321 al->map ? al->map->dso->long_name :
1325 al->level == 'H' ? "[hypervisor]" : "<not found>"); 1322 al->level == 'H' ? "[hypervisor]" : "<not found>");
@@ -1395,16 +1392,12 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
1395 return false; 1392 return false;
1396} 1393}
1397 1394
1398void perf_event__preprocess_sample_addr(union perf_event *event, 1395void thread__resolve(struct thread *thread, struct addr_location *al,
1399 struct perf_sample *sample, 1396 struct perf_sample *sample)
1400 struct thread *thread,
1401 struct addr_location *al)
1402{ 1397{
1403 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 1398 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al);
1404
1405 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
1406 if (!al->map) 1399 if (!al->map)
1407 thread__find_addr_map(thread, cpumode, MAP__VARIABLE, 1400 thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE,
1408 sample->addr, al); 1401 sample->addr, al);
1409 1402
1410 al->cpu = sample->cpu; 1403 al->cpu = sample->cpu;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index b7ffb7ee9971..6bb1c928350d 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -192,6 +192,7 @@ struct perf_sample {
192 u64 data_src; 192 u64 data_src;
193 u32 flags; 193 u32 flags;
194 u16 insn_len; 194 u16 insn_len;
195 u8 cpumode;
195 void *raw_data; 196 void *raw_data;
196 struct ip_callchain *callchain; 197 struct ip_callchain *callchain;
197 struct branch_stack *branch_stack; 198 struct branch_stack *branch_stack;
@@ -597,10 +598,8 @@ int perf_event__process(struct perf_tool *tool,
597 598
598struct addr_location; 599struct addr_location;
599 600
600int perf_event__preprocess_sample(const union perf_event *event, 601int machine__resolve(struct machine *machine, struct addr_location *al,
601 struct machine *machine, 602 struct perf_sample *sample);
602 struct addr_location *al,
603 struct perf_sample *sample);
604 603
605void addr_location__put(struct addr_location *al); 604void addr_location__put(struct addr_location *al);
606 605
@@ -608,10 +607,8 @@ struct thread;
608 607
609bool is_bts_event(struct perf_event_attr *attr); 608bool is_bts_event(struct perf_event_attr *attr);
610bool sample_addr_correlates_sym(struct perf_event_attr *attr); 609bool sample_addr_correlates_sym(struct perf_event_attr *attr);
611void perf_event__preprocess_sample_addr(union perf_event *event, 610void thread__resolve(struct thread *thread, struct addr_location *al,
612 struct perf_sample *sample, 611 struct perf_sample *sample);
613 struct thread *thread,
614 struct addr_location *al);
615 612
616const char *perf_event__name(unsigned int id); 613const char *perf_event__name(unsigned int id);
617 614
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0902fe418754..738ce226002b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1643,6 +1643,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1643 data->stream_id = data->id = data->time = -1ULL; 1643 data->stream_id = data->id = data->time = -1ULL;
1644 data->period = evsel->attr.sample_period; 1644 data->period = evsel->attr.sample_period;
1645 data->weight = 0; 1645 data->weight = 0;
1646 data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1646 1647
1647 if (event->header.type != PERF_RECORD_SAMPLE) { 1648 if (event->header.type != PERF_RECORD_SAMPLE) {
1648 if (!evsel->attr.sample_id_all) 1649 if (!evsel->attr.sample_id_all)
diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
index 45bf9c6d3257..cd67e64a0494 100644
--- a/tools/perf/util/genelf.h
+++ b/tools/perf/util/genelf.h
@@ -2,12 +2,10 @@
2#define __GENELF_H__ 2#define __GENELF_H__
3 3
4/* genelf.c */ 4/* genelf.c */
5extern int jit_write_elf(int fd, uint64_t code_addr, const char *sym, 5int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
6 const void *code, int csize, 6 const void *code, int csize, void *debug, int nr_debug_entries);
7 void *debug, int nr_debug_entries);
8/* genelf_debug.c */ 7/* genelf_debug.c */
9extern int jit_add_debug_info(Elf *e, uint64_t code_addr, 8int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
10 void *debug, int nr_debug_entries);
11 9
12#if defined(__arm__) 10#if defined(__arm__)
13#define GEN_ELF_ARCH EM_ARM 11#define GEN_ELF_ARCH EM_ARM
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 73e38e472ecd..90680ec9f8b8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1872,11 +1872,6 @@ static int process_cpu_topology(struct perf_file_section *section,
1872 if (ph->needs_swap) 1872 if (ph->needs_swap)
1873 nr = bswap_32(nr); 1873 nr = bswap_32(nr);
1874 1874
1875 if (nr > (u32)cpu_nr) {
1876 pr_debug("core_id number is too big."
1877 "You may need to upgrade the perf tool.\n");
1878 goto free_cpu;
1879 }
1880 ph->env.cpu[i].core_id = nr; 1875 ph->env.cpu[i].core_id = nr;
1881 1876
1882 ret = readn(fd, &nr, sizeof(nr)); 1877 ret = readn(fd, &nr, sizeof(nr));
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 3d87ca823c0a..d306ca118449 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -121,7 +121,7 @@ int perf_event__synthesize_event_update_cpus(struct perf_tool *tool,
121 perf_event__handler_t process); 121 perf_event__handler_t process);
122int perf_event__process_attr(struct perf_tool *tool, union perf_event *event, 122int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
123 struct perf_evlist **pevlist); 123 struct perf_evlist **pevlist);
124int perf_event__process_event_update(struct perf_tool *tool __maybe_unused, 124int perf_event__process_event_update(struct perf_tool *tool,
125 union perf_event *event, 125 union perf_event *event,
126 struct perf_evlist **pevlist); 126 struct perf_evlist **pevlist);
127size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp); 127size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 290b3cbf6877..31c4641fe5ff 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -670,7 +670,7 @@ iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al
670} 670}
671 671
672static int 672static int
673iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused, 673iter_add_single_branch_entry(struct hist_entry_iter *iter,
674 struct addr_location *al __maybe_unused) 674 struct addr_location *al __maybe_unused)
675{ 675{
676 /* to avoid calling callback function */ 676 /* to avoid calling callback function */
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index ead18c82294f..bec0cd660fbd 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -433,8 +433,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
433 struct perf_sample *sample, bool nonany_branch_mode); 433 struct perf_sample *sample, bool nonany_branch_mode);
434 434
435struct option; 435struct option;
436int parse_filter_percentage(const struct option *opt __maybe_unused, 436int parse_filter_percentage(const struct option *opt, const char *arg, int unset);
437 const char *arg, int unset __maybe_unused);
438int perf_hist_config(const char *var, const char *value); 437int perf_hist_config(const char *var, const char *value);
439 438
440void perf_hpp_list__init(struct perf_hpp_list *list); 439void perf_hpp_list__init(struct perf_hpp_list *list);
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index eb0e7f8bf515..6bc3ecd2e7ca 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -678,7 +678,7 @@ static int intel_bts_process_auxtrace_event(struct perf_session *session,
678 return 0; 678 return 0;
679} 679}
680 680
681static int intel_bts_flush(struct perf_session *session __maybe_unused, 681static int intel_bts_flush(struct perf_session *session,
682 struct perf_tool *tool __maybe_unused) 682 struct perf_tool *tool __maybe_unused)
683{ 683{
684 struct intel_bts *bts = container_of(session->auxtrace, struct intel_bts, 684 struct intel_bts *bts = container_of(session->auxtrace, struct intel_bts,
diff --git a/tools/perf/util/jit.h b/tools/perf/util/jit.h
index a1e99da0715a..3f42ee4d2a0b 100644
--- a/tools/perf/util/jit.h
+++ b/tools/perf/util/jit.h
@@ -3,13 +3,9 @@
3 3
4#include <data.h> 4#include <data.h>
5 5
6extern int jit_process(struct perf_session *session, 6int jit_process(struct perf_session *session, struct perf_data_file *output,
7 struct perf_data_file *output, 7 struct machine *machine, char *filename, pid_t pid, u64 *nbytes);
8 struct machine *machine, 8
9 char *filename, 9int jit_inject_record(const char *filename);
10 pid_t pid,
11 u64 *nbytes);
12
13extern int jit_inject_record(const char *filename);
14 10
15#endif /* __JIT_H__ */ 11#endif /* __JIT_H__ */
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 00724d496d38..33071d6159bc 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -3,11 +3,11 @@
3 * Copyright (C) 2015, Huawei Inc. 3 * Copyright (C) 2015, Huawei Inc.
4 */ 4 */
5 5
6#include <limits.h>
6#include <stdio.h> 7#include <stdio.h>
7#include "util.h" 8#include <stdlib.h>
8#include "debug.h" 9#include "debug.h"
9#include "llvm-utils.h" 10#include "llvm-utils.h"
10#include "cache.h"
11 11
12#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 12#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
13 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 13 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
@@ -98,11 +98,12 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
98 void *buf = NULL; 98 void *buf = NULL;
99 FILE *file = NULL; 99 FILE *file = NULL;
100 size_t read_sz = 0, buf_sz = 0; 100 size_t read_sz = 0, buf_sz = 0;
101 char serr[STRERR_BUFSIZE];
101 102
102 file = popen(cmd, "r"); 103 file = popen(cmd, "r");
103 if (!file) { 104 if (!file) {
104 pr_err("ERROR: unable to popen cmd: %s\n", 105 pr_err("ERROR: unable to popen cmd: %s\n",
105 strerror(errno)); 106 strerror_r(errno, serr, sizeof(serr)));
106 return -EINVAL; 107 return -EINVAL;
107 } 108 }
108 109
@@ -136,7 +137,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
136 137
137 if (ferror(file)) { 138 if (ferror(file)) {
138 pr_err("ERROR: error occurred when reading from pipe: %s\n", 139 pr_err("ERROR: error occurred when reading from pipe: %s\n",
139 strerror(errno)); 140 strerror_r(errno, serr, sizeof(serr)));
140 err = -EIO; 141 err = -EIO;
141 goto errout; 142 goto errout;
142 } 143 }
@@ -334,10 +335,18 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
334 unsigned int kernel_version; 335 unsigned int kernel_version;
335 char linux_version_code_str[64]; 336 char linux_version_code_str[64];
336 const char *clang_opt = llvm_param.clang_opt; 337 const char *clang_opt = llvm_param.clang_opt;
337 char clang_path[PATH_MAX], nr_cpus_avail_str[64]; 338 char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64];
339 char serr[STRERR_BUFSIZE];
338 char *kbuild_dir = NULL, *kbuild_include_opts = NULL; 340 char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
339 const char *template = llvm_param.clang_bpf_cmd_template; 341 const char *template = llvm_param.clang_bpf_cmd_template;
340 342
343 if (path[0] != '-' && realpath(path, abspath) == NULL) {
344 err = errno;
345 pr_err("ERROR: problems with path %s: %s\n",
346 path, strerror_r(err, serr, sizeof(serr)));
347 return -err;
348 }
349
341 if (!template) 350 if (!template)
342 template = CLANG_BPF_CMD_DEFAULT_TEMPLATE; 351 template = CLANG_BPF_CMD_DEFAULT_TEMPLATE;
343 352
@@ -362,7 +371,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
362 if (nr_cpus_avail <= 0) { 371 if (nr_cpus_avail <= 0) {
363 pr_err( 372 pr_err(
364"WARNING:\tunable to get available CPUs in this system: %s\n" 373"WARNING:\tunable to get available CPUs in this system: %s\n"
365" \tUse 128 instead.\n", strerror(errno)); 374" \tUse 128 instead.\n", strerror_r(errno, serr, sizeof(serr)));
366 nr_cpus_avail = 128; 375 nr_cpus_avail = 128;
367 } 376 }
368 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d", 377 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
@@ -387,8 +396,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
387 * stdin to be source file (testing). 396 * stdin to be source file (testing).
388 */ 397 */
389 force_set_env("CLANG_SOURCE", 398 force_set_env("CLANG_SOURCE",
390 (path[0] == '-') ? path : 399 (path[0] == '-') ? path : abspath);
391 make_nonrelative_path(path));
392 400
393 pr_debug("llvm compiling command template: %s\n", template); 401 pr_debug("llvm compiling command template: %s\n", template);
394 err = read_from_pipe(template, &obj_buf, &obj_buf_sz); 402 err = read_from_pipe(template, &obj_buf, &obj_buf_sz);
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
index 5b3cf1c229e2..23b9a743fe72 100644
--- a/tools/perf/util/llvm-utils.h
+++ b/tools/perf/util/llvm-utils.h
@@ -39,11 +39,10 @@ struct llvm_param {
39}; 39};
40 40
41extern struct llvm_param llvm_param; 41extern struct llvm_param llvm_param;
42extern int perf_llvm_config(const char *var, const char *value); 42int perf_llvm_config(const char *var, const char *value);
43 43
44extern int llvm__compile_bpf(const char *path, void **p_obj_buf, 44int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
45 size_t *p_obj_buf_sz);
46 45
47/* This function is for test__llvm() use only */ 46/* This function is for test__llvm() use only */
48extern int llvm__search_clang(void); 47int llvm__search_clang(void);
49#endif 48#endif
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index ad79297c76c8..80b9b6a87990 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1301,9 +1301,8 @@ out_problem:
1301 1301
1302int machine__process_mmap2_event(struct machine *machine, 1302int machine__process_mmap2_event(struct machine *machine,
1303 union perf_event *event, 1303 union perf_event *event,
1304 struct perf_sample *sample __maybe_unused) 1304 struct perf_sample *sample)
1305{ 1305{
1306 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1307 struct thread *thread; 1306 struct thread *thread;
1308 struct map *map; 1307 struct map *map;
1309 enum map_type type; 1308 enum map_type type;
@@ -1312,8 +1311,8 @@ int machine__process_mmap2_event(struct machine *machine,
1312 if (dump_trace) 1311 if (dump_trace)
1313 perf_event__fprintf_mmap2(event, stdout); 1312 perf_event__fprintf_mmap2(event, stdout);
1314 1313
1315 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 1314 if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
1316 cpumode == PERF_RECORD_MISC_KERNEL) { 1315 sample->cpumode == PERF_RECORD_MISC_KERNEL) {
1317 ret = machine__process_kernel_mmap_event(machine, event); 1316 ret = machine__process_kernel_mmap_event(machine, event);
1318 if (ret < 0) 1317 if (ret < 0)
1319 goto out_problem; 1318 goto out_problem;
@@ -1355,9 +1354,8 @@ out_problem:
1355} 1354}
1356 1355
1357int machine__process_mmap_event(struct machine *machine, union perf_event *event, 1356int machine__process_mmap_event(struct machine *machine, union perf_event *event,
1358 struct perf_sample *sample __maybe_unused) 1357 struct perf_sample *sample)
1359{ 1358{
1360 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1361 struct thread *thread; 1359 struct thread *thread;
1362 struct map *map; 1360 struct map *map;
1363 enum map_type type; 1361 enum map_type type;
@@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
1366 if (dump_trace) 1364 if (dump_trace)
1367 perf_event__fprintf_mmap(event, stdout); 1365 perf_event__fprintf_mmap(event, stdout);
1368 1366
1369 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 1367 if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
1370 cpumode == PERF_RECORD_MISC_KERNEL) { 1368 sample->cpumode == PERF_RECORD_MISC_KERNEL) {
1371 ret = machine__process_kernel_mmap_event(machine, event); 1369 ret = machine__process_kernel_mmap_event(machine, event);
1372 if (ret < 0) 1370 if (ret < 0)
1373 goto out_problem; 1371 goto out_problem;
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 1a3e45baf97f..8499db281158 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -94,7 +94,7 @@ int machine__process_aux_event(struct machine *machine,
94 union perf_event *event); 94 union perf_event *event);
95int machine__process_itrace_start_event(struct machine *machine, 95int machine__process_itrace_start_event(struct machine *machine,
96 union perf_event *event); 96 union perf_event *event);
97int machine__process_switch_event(struct machine *machine __maybe_unused, 97int machine__process_switch_event(struct machine *machine,
98 union perf_event *event); 98 union perf_event *event);
99int machine__process_mmap_event(struct machine *machine, union perf_event *event, 99int machine__process_mmap_event(struct machine *machine, union perf_event *event,
100 struct perf_sample *sample); 100 struct perf_sample *sample);
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 67e493088e81..d740c3ca9a1d 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -22,19 +22,18 @@ struct tracepoint_path {
22 struct tracepoint_path *next; 22 struct tracepoint_path *next;
23}; 23};
24 24
25extern struct tracepoint_path *tracepoint_id_to_path(u64 config); 25struct tracepoint_path *tracepoint_id_to_path(u64 config);
26extern struct tracepoint_path *tracepoint_name_to_path(const char *name); 26struct tracepoint_path *tracepoint_name_to_path(const char *name);
27extern bool have_tracepoints(struct list_head *evlist); 27bool have_tracepoints(struct list_head *evlist);
28 28
29const char *event_type(int type); 29const char *event_type(int type);
30 30
31extern int parse_events_option(const struct option *opt, const char *str, 31int parse_events_option(const struct option *opt, const char *str, int unset);
32 int unset); 32int parse_events(struct perf_evlist *evlist, const char *str,
33extern int parse_events(struct perf_evlist *evlist, const char *str, 33 struct parse_events_error *error);
34 struct parse_events_error *error); 34int parse_events_terms(struct list_head *terms, const char *str);
35extern int parse_events_terms(struct list_head *terms, const char *str); 35int parse_filter(const struct option *opt, const char *str, int unset);
36extern int parse_filter(const struct option *opt, const char *str, int unset); 36int exclude_perf(const struct option *opt, const char *arg, int unset);
37extern int exclude_perf(const struct option *opt, const char *arg, int unset);
38 37
39#define EVENTS_HELP_MAX (128*1024) 38#define EVENTS_HELP_MAX (128*1024)
40 39
@@ -183,7 +182,7 @@ void print_symbol_events(const char *event_glob, unsigned type,
183void print_tracepoint_events(const char *subsys_glob, const char *event_glob, 182void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
184 bool name_only); 183 bool name_only);
185int print_hwcache_events(const char *event_glob, bool name_only); 184int print_hwcache_events(const char *event_glob, bool name_only);
186extern int is_valid_tracepoint(const char *event_string); 185int is_valid_tracepoint(const char *event_string);
187 186
188int valid_event_mount(const char *eventfs); 187int valid_event_mount(const char *eventfs);
189char *parse_events_formats_error_string(char *additional_terms); 188char *parse_events_formats_error_string(char *additional_terms);
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 3654d964e49d..3bf6bf82ff2d 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -41,36 +41,6 @@ static char *cleanup_path(char *path)
41 return path; 41 return path;
42} 42}
43 43
44static char *perf_vsnpath(char *buf, size_t n, const char *fmt, va_list args)
45{
46 const char *perf_dir = get_perf_dir();
47 size_t len;
48
49 len = strlen(perf_dir);
50 if (n < len + 1)
51 goto bad;
52 memcpy(buf, perf_dir, len);
53 if (len && !is_dir_sep(perf_dir[len-1]))
54 buf[len++] = '/';
55 len += vsnprintf(buf + len, n - len, fmt, args);
56 if (len >= n)
57 goto bad;
58 return cleanup_path(buf);
59bad:
60 strlcpy(buf, bad_path, n);
61 return buf;
62}
63
64char *perf_pathdup(const char *fmt, ...)
65{
66 char path[PATH_MAX];
67 va_list args;
68 va_start(args, fmt);
69 (void)perf_vsnpath(path, sizeof(path), fmt, args);
70 va_end(args);
71 return xstrdup(path);
72}
73
74char *mkpath(const char *fmt, ...) 44char *mkpath(const char *fmt, ...)
75{ 45{
76 va_list args; 46 va_list args;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 93996ec4bbe3..8319fbb08636 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2179,7 +2179,7 @@ static int perf_probe_event__sprintf(const char *group, const char *event,
2179 strbuf_addf(result, " in %s", module); 2179 strbuf_addf(result, " in %s", module);
2180 2180
2181 if (pev->nargs > 0) { 2181 if (pev->nargs > 0) {
2182 strbuf_addstr(result, " with"); 2182 strbuf_add(result, " with", 5);
2183 for (i = 0; i < pev->nargs; i++) { 2183 for (i = 0; i < pev->nargs; i++) {
2184 ret = synthesize_perf_probe_arg(&pev->args[i], 2184 ret = synthesize_perf_probe_arg(&pev->args[i],
2185 buf, 128); 2185 buf, 128);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index ba926c30f8cd..e54e7b011577 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -114,49 +114,44 @@ int init_probe_symbol_maps(bool user_only);
114void exit_probe_symbol_maps(void); 114void exit_probe_symbol_maps(void);
115 115
116/* Command string to events */ 116/* Command string to events */
117extern int parse_perf_probe_command(const char *cmd, 117int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev);
118 struct perf_probe_event *pev); 118int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev);
119extern int parse_probe_trace_command(const char *cmd,
120 struct probe_trace_event *tev);
121 119
122/* Events to command string */ 120/* Events to command string */
123extern char *synthesize_perf_probe_command(struct perf_probe_event *pev); 121char *synthesize_perf_probe_command(struct perf_probe_event *pev);
124extern char *synthesize_probe_trace_command(struct probe_trace_event *tev); 122char *synthesize_probe_trace_command(struct probe_trace_event *tev);
125extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, 123int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len);
126 size_t len);
127 124
128/* Check the perf_probe_event needs debuginfo */ 125/* Check the perf_probe_event needs debuginfo */
129extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev); 126bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
130 127
131/* Release event contents */ 128/* Release event contents */
132extern void clear_perf_probe_event(struct perf_probe_event *pev); 129void clear_perf_probe_event(struct perf_probe_event *pev);
133extern void clear_probe_trace_event(struct probe_trace_event *tev); 130void clear_probe_trace_event(struct probe_trace_event *tev);
134 131
135/* Command string to line-range */ 132/* Command string to line-range */
136extern int parse_line_range_desc(const char *cmd, struct line_range *lr); 133int parse_line_range_desc(const char *cmd, struct line_range *lr);
137 134
138/* Release line range members */ 135/* Release line range members */
139extern void line_range__clear(struct line_range *lr); 136void line_range__clear(struct line_range *lr);
140 137
141/* Initialize line range */ 138/* Initialize line range */
142extern int line_range__init(struct line_range *lr); 139int line_range__init(struct line_range *lr);
143 140
144extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs); 141int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);
145extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs); 142int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
146extern int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs); 143int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
147extern void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs); 144void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
148extern int del_perf_probe_events(struct strfilter *filter); 145int del_perf_probe_events(struct strfilter *filter);
149 146
150extern int show_perf_probe_event(const char *group, const char *event, 147int show_perf_probe_event(const char *group, const char *event,
151 struct perf_probe_event *pev, 148 struct perf_probe_event *pev,
152 const char *module, bool use_stdout); 149 const char *module, bool use_stdout);
153extern int show_perf_probe_events(struct strfilter *filter); 150int show_perf_probe_events(struct strfilter *filter);
154extern int show_line_range(struct line_range *lr, const char *module, 151int show_line_range(struct line_range *lr, const char *module, bool user);
155 bool user); 152int show_available_vars(struct perf_probe_event *pevs, int npevs,
156extern int show_available_vars(struct perf_probe_event *pevs, int npevs, 153 struct strfilter *filter);
157 struct strfilter *filter); 154int show_available_funcs(const char *module, struct strfilter *filter, bool user);
158extern int show_available_funcs(const char *module, struct strfilter *filter,
159 bool user);
160bool arch__prefers_symtab(void); 155bool arch__prefers_symtab(void);
161void arch__fix_tev_from_maps(struct perf_probe_event *pev, 156void arch__fix_tev_from_maps(struct perf_probe_event *pev,
162 struct probe_trace_event *tev, struct map *map); 157 struct probe_trace_event *tev, struct map *map);
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 4ce5c5e18f48..b3bd0fba0237 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1314,18 +1314,18 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
1314 if (probe_conf.show_location_range) { 1314 if (probe_conf.show_location_range) {
1315 if (!externs) { 1315 if (!externs) {
1316 if (ret) 1316 if (ret)
1317 strbuf_addf(&buf, "[INV]\t"); 1317 strbuf_add(&buf, "[INV]\t", 6);
1318 else 1318 else
1319 strbuf_addf(&buf, "[VAL]\t"); 1319 strbuf_add(&buf, "[VAL]\t", 6);
1320 } else 1320 } else
1321 strbuf_addf(&buf, "[EXT]\t"); 1321 strbuf_add(&buf, "[EXT]\t", 6);
1322 } 1322 }
1323 1323
1324 ret2 = die_get_varname(die_mem, &buf); 1324 ret2 = die_get_varname(die_mem, &buf);
1325 1325
1326 if (!ret2 && probe_conf.show_location_range && 1326 if (!ret2 && probe_conf.show_location_range &&
1327 !externs) { 1327 !externs) {
1328 strbuf_addf(&buf, "\t"); 1328 strbuf_addch(&buf, '\t');
1329 ret2 = die_get_var_range(&af->pf.sp_die, 1329 ret2 = die_get_var_range(&af->pf.sp_die,
1330 die_mem, &buf); 1330 die_mem, &buf);
1331 } 1331 }
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 0aec7704e395..51137fccb9c8 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -34,27 +34,25 @@ struct debuginfo {
34}; 34};
35 35
36/* This also tries to open distro debuginfo */ 36/* This also tries to open distro debuginfo */
37extern struct debuginfo *debuginfo__new(const char *path); 37struct debuginfo *debuginfo__new(const char *path);
38extern void debuginfo__delete(struct debuginfo *dbg); 38void debuginfo__delete(struct debuginfo *dbg);
39 39
40/* Find probe_trace_events specified by perf_probe_event from debuginfo */ 40/* Find probe_trace_events specified by perf_probe_event from debuginfo */
41extern int debuginfo__find_trace_events(struct debuginfo *dbg, 41int debuginfo__find_trace_events(struct debuginfo *dbg,
42 struct perf_probe_event *pev, 42 struct perf_probe_event *pev,
43 struct probe_trace_event **tevs); 43 struct probe_trace_event **tevs);
44 44
45/* Find a perf_probe_point from debuginfo */ 45/* Find a perf_probe_point from debuginfo */
46extern int debuginfo__find_probe_point(struct debuginfo *dbg, 46int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
47 unsigned long addr, 47 struct perf_probe_point *ppt);
48 struct perf_probe_point *ppt);
49 48
50/* Find a line range */ 49/* Find a line range */
51extern int debuginfo__find_line_range(struct debuginfo *dbg, 50int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
52 struct line_range *lr);
53 51
54/* Find available variables */ 52/* Find available variables */
55extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, 53int debuginfo__find_available_vars_at(struct debuginfo *dbg,
56 struct perf_probe_event *pev, 54 struct perf_probe_event *pev,
57 struct variable_list **vls); 55 struct variable_list **vls);
58 56
59/* Find a src file from a DWARF tag path */ 57/* Find a src file from a DWARF tag path */
60int get_real_path(const char *raw_path, const char *comp_dir, 58int get_real_path(const char *raw_path, const char *comp_dir,
diff --git a/tools/perf/util/quote.h b/tools/perf/util/quote.h
index 172889ea234f..3340c9c4a6ca 100644
--- a/tools/perf/util/quote.h
+++ b/tools/perf/util/quote.h
@@ -24,6 +24,6 @@
24 * sq_quote() in a real application. 24 * sq_quote() in a real application.
25 */ 25 */
26 26
27extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); 27void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
28 28
29#endif /* __PERF_QUOTE_H */ 29#endif /* __PERF_QUOTE_H */
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 60b3593d210d..4abd85c6346d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1107,12 +1107,11 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
1107 union perf_event *event, 1107 union perf_event *event,
1108 struct perf_sample *sample) 1108 struct perf_sample *sample)
1109{ 1109{
1110 const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1111 struct machine *machine; 1110 struct machine *machine;
1112 1111
1113 if (perf_guest && 1112 if (perf_guest &&
1114 ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || 1113 ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
1115 (cpumode == PERF_RECORD_MISC_GUEST_USER))) { 1114 (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) {
1116 u32 pid; 1115 u32 pid;
1117 1116
1118 if (event->header.type == PERF_RECORD_MMAP 1117 if (event->header.type == PERF_RECORD_MMAP
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 93fa136b0025..47966a1618c7 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2225,7 +2225,7 @@ int hpp_dimension__add_output(unsigned col)
2225} 2225}
2226 2226
2227static int sort_dimension__add(struct perf_hpp_list *list, const char *tok, 2227static int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
2228 struct perf_evlist *evlist __maybe_unused, 2228 struct perf_evlist *evlist,
2229 int level) 2229 int level)
2230{ 2230{
2231 unsigned int i; 2231 unsigned int i;
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index b33ffb2af2cf..fdb71961143e 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -152,8 +152,7 @@ static const char *get_ratio_color(enum grc_type type, double ratio)
152} 152}
153 153
154static void print_stalled_cycles_frontend(int cpu, 154static void print_stalled_cycles_frontend(int cpu,
155 struct perf_evsel *evsel 155 struct perf_evsel *evsel, double avg,
156 __maybe_unused, double avg,
157 struct perf_stat_output_ctx *out) 156 struct perf_stat_output_ctx *out)
158{ 157{
159 double total, ratio = 0.0; 158 double total, ratio = 0.0;
@@ -175,8 +174,7 @@ static void print_stalled_cycles_frontend(int cpu,
175} 174}
176 175
177static void print_stalled_cycles_backend(int cpu, 176static void print_stalled_cycles_backend(int cpu,
178 struct perf_evsel *evsel 177 struct perf_evsel *evsel, double avg,
179 __maybe_unused, double avg,
180 struct perf_stat_output_ctx *out) 178 struct perf_stat_output_ctx *out)
181{ 179{
182 double total, ratio = 0.0; 180 double total, ratio = 0.0;
@@ -194,7 +192,7 @@ static void print_stalled_cycles_backend(int cpu,
194} 192}
195 193
196static void print_branch_misses(int cpu, 194static void print_branch_misses(int cpu,
197 struct perf_evsel *evsel __maybe_unused, 195 struct perf_evsel *evsel,
198 double avg, 196 double avg,
199 struct perf_stat_output_ctx *out) 197 struct perf_stat_output_ctx *out)
200{ 198{
@@ -213,7 +211,7 @@ static void print_branch_misses(int cpu,
213} 211}
214 212
215static void print_l1_dcache_misses(int cpu, 213static void print_l1_dcache_misses(int cpu,
216 struct perf_evsel *evsel __maybe_unused, 214 struct perf_evsel *evsel,
217 double avg, 215 double avg,
218 struct perf_stat_output_ctx *out) 216 struct perf_stat_output_ctx *out)
219{ 217{
@@ -232,7 +230,7 @@ static void print_l1_dcache_misses(int cpu,
232} 230}
233 231
234static void print_l1_icache_misses(int cpu, 232static void print_l1_icache_misses(int cpu,
235 struct perf_evsel *evsel __maybe_unused, 233 struct perf_evsel *evsel,
236 double avg, 234 double avg,
237 struct perf_stat_output_ctx *out) 235 struct perf_stat_output_ctx *out)
238{ 236{
@@ -250,7 +248,7 @@ static void print_l1_icache_misses(int cpu,
250} 248}
251 249
252static void print_dtlb_cache_misses(int cpu, 250static void print_dtlb_cache_misses(int cpu,
253 struct perf_evsel *evsel __maybe_unused, 251 struct perf_evsel *evsel,
254 double avg, 252 double avg,
255 struct perf_stat_output_ctx *out) 253 struct perf_stat_output_ctx *out)
256{ 254{
@@ -268,7 +266,7 @@ static void print_dtlb_cache_misses(int cpu,
268} 266}
269 267
270static void print_itlb_cache_misses(int cpu, 268static void print_itlb_cache_misses(int cpu,
271 struct perf_evsel *evsel __maybe_unused, 269 struct perf_evsel *evsel,
272 double avg, 270 double avg,
273 struct perf_stat_output_ctx *out) 271 struct perf_stat_output_ctx *out)
274{ 272{
@@ -286,7 +284,7 @@ static void print_itlb_cache_misses(int cpu,
286} 284}
287 285
288static void print_ll_cache_misses(int cpu, 286static void print_ll_cache_misses(int cpu,
289 struct perf_evsel *evsel __maybe_unused, 287 struct perf_evsel *evsel,
290 double avg, 288 double avg,
291 struct perf_stat_output_ctx *out) 289 struct perf_stat_output_ctx *out)
292{ 290{
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index d3d279275432..8fb73295ec34 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -51,6 +51,13 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
51 ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); 51 ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc);
52} 52}
53 53
54void strbuf_addch(struct strbuf *sb, int c)
55{
56 strbuf_grow(sb, 1);
57 sb->buf[sb->len++] = c;
58 sb->buf[sb->len] = '\0';
59}
60
54void strbuf_add(struct strbuf *sb, const void *data, size_t len) 61void strbuf_add(struct strbuf *sb, const void *data, size_t len)
55{ 62{
56 strbuf_grow(sb, len); 63 strbuf_grow(sb, len);
@@ -58,7 +65,7 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len)
58 strbuf_setlen(sb, sb->len + len); 65 strbuf_setlen(sb, sb->len + len);
59} 66}
60 67
61void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap) 68static void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
62{ 69{
63 int len; 70 int len;
64 va_list ap_saved; 71 va_list ap_saved;
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h
index 7a32c838884d..ab9be0fbbd40 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/perf/util/strbuf.h
@@ -51,16 +51,16 @@ struct strbuf {
51#define STRBUF_INIT { 0, 0, strbuf_slopbuf } 51#define STRBUF_INIT { 0, 0, strbuf_slopbuf }
52 52
53/*----- strbuf life cycle -----*/ 53/*----- strbuf life cycle -----*/
54extern void strbuf_init(struct strbuf *buf, ssize_t hint); 54void strbuf_init(struct strbuf *buf, ssize_t hint);
55extern void strbuf_release(struct strbuf *); 55void strbuf_release(struct strbuf *buf);
56extern char *strbuf_detach(struct strbuf *, size_t *); 56char *strbuf_detach(struct strbuf *buf, size_t *);
57 57
58/*----- strbuf size related -----*/ 58/*----- strbuf size related -----*/
59static inline ssize_t strbuf_avail(const struct strbuf *sb) { 59static inline ssize_t strbuf_avail(const struct strbuf *sb) {
60 return sb->alloc ? sb->alloc - sb->len - 1 : 0; 60 return sb->alloc ? sb->alloc - sb->len - 1 : 0;
61} 61}
62 62
63extern void strbuf_grow(struct strbuf *, size_t); 63void strbuf_grow(struct strbuf *buf, size_t);
64 64
65static inline void strbuf_setlen(struct strbuf *sb, size_t len) { 65static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
66 if (!sb->alloc) 66 if (!sb->alloc)
@@ -71,22 +71,17 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
71} 71}
72 72
73/*----- add data in your buffer -----*/ 73/*----- add data in your buffer -----*/
74static inline void strbuf_addch(struct strbuf *sb, int c) { 74void strbuf_addch(struct strbuf *sb, int c);
75 strbuf_grow(sb, 1);
76 sb->buf[sb->len++] = c;
77 sb->buf[sb->len] = '\0';
78}
79 75
80extern void strbuf_add(struct strbuf *, const void *, size_t); 76void strbuf_add(struct strbuf *buf, const void *, size_t);
81static inline void strbuf_addstr(struct strbuf *sb, const char *s) { 77static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
82 strbuf_add(sb, s, strlen(s)); 78 strbuf_add(sb, s, strlen(s));
83} 79}
84 80
85__attribute__((format(printf,2,3))) 81__attribute__((format(printf,2,3)))
86extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); 82void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
87extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);
88 83
89/* XXX: if read fails, any partial read is undone */ 84/* XXX: if read fails, any partial read is undone */
90extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); 85ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
91 86
92#endif /* __PERF_STRBUF_H */ 87#endif /* __PERF_STRBUF_H */
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index 9292a5291445..946fdf2db97c 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -3,32 +3,31 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5 5
6extern void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end); 6void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
7extern void svg_ubox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges); 7void svg_ubox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
8extern void svg_lbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges); 8void svg_lbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
9extern void svg_fbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges); 9void svg_fbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
10extern void svg_box(int Yslot, u64 start, u64 end, const char *type); 10void svg_box(int Yslot, u64 start, u64 end, const char *type);
11extern void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace); 11void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace);
12extern void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace); 12void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace);
13extern void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace); 13void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace);
14extern void svg_cpu_box(int cpu, u64 max_frequency, u64 turbo_frequency); 14void svg_cpu_box(int cpu, u64 max_frequency, u64 turbo_frequency);
15 15
16 16
17extern void svg_process(int cpu, u64 start, u64 end, int pid, const char *name, const char *backtrace); 17void svg_process(int cpu, u64 start, u64 end, int pid, const char *name, const char *backtrace);
18extern void svg_cstate(int cpu, u64 start, u64 end, int type); 18void svg_cstate(int cpu, u64 start, u64 end, int type);
19extern void svg_pstate(int cpu, u64 start, u64 end, u64 freq); 19void svg_pstate(int cpu, u64 start, u64 end, u64 freq);
20 20
21 21
22extern void svg_time_grid(double min_thickness); 22void svg_time_grid(double min_thickness);
23extern void svg_io_legenda(void); 23void svg_io_legenda(void);
24extern void svg_legenda(void); 24void svg_legenda(void);
25extern void svg_wakeline(u64 start, int row1, int row2, const char *backtrace); 25void svg_wakeline(u64 start, int row1, int row2, const char *backtrace);
26extern void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2, const char *backtrace); 26void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2, const char *backtrace);
27extern void svg_interrupt(u64 start, int row, const char *backtrace); 27void svg_interrupt(u64 start, int row, const char *backtrace);
28extern void svg_text(int Yslot, u64 start, const char *text); 28void svg_text(int Yslot, u64 start, const char *text);
29extern void svg_close(void); 29void svg_close(void);
30extern int svg_build_topology_map(char *sib_core, int sib_core_nr, 30int svg_build_topology_map(char *sib_core, int sib_core_nr, char *sib_thr, int sib_thr_nr);
31 char *sib_thr, int sib_thr_nr);
32 31
33extern int svg_page_width; 32extern int svg_page_width;
34extern u64 svg_highlight; 33extern u64 svg_highlight;
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index b1dd68f358fc..bc229a74c6a9 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -793,6 +793,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
793 uint32_t idx; 793 uint32_t idx;
794 GElf_Ehdr ehdr; 794 GElf_Ehdr ehdr;
795 GElf_Shdr shdr; 795 GElf_Shdr shdr;
796 GElf_Shdr tshdr;
796 Elf_Data *syms, *opddata = NULL; 797 Elf_Data *syms, *opddata = NULL;
797 GElf_Sym sym; 798 GElf_Sym sym;
798 Elf_Scn *sec, *sec_strndx; 799 Elf_Scn *sec, *sec_strndx;
@@ -832,6 +833,9 @@ int dso__load_sym(struct dso *dso, struct map *map,
832 sec = syms_ss->symtab; 833 sec = syms_ss->symtab;
833 shdr = syms_ss->symshdr; 834 shdr = syms_ss->symshdr;
834 835
836 if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL))
837 dso->text_offset = tshdr.sh_addr - tshdr.sh_offset;
838
835 if (runtime_ss->opdsec) 839 if (runtime_ss->opdsec)
836 opddata = elf_rawdata(runtime_ss->opdsec, NULL); 840 opddata = elf_rawdata(runtime_ss->opdsec, NULL);
837 841
@@ -880,12 +884,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
880 * Handle any relocation of vdso necessary because older kernels 884 * Handle any relocation of vdso necessary because older kernels
881 * attempted to prelink vdso to its virtual address. 885 * attempted to prelink vdso to its virtual address.
882 */ 886 */
883 if (dso__is_vdso(dso)) { 887 if (dso__is_vdso(dso))
884 GElf_Shdr tshdr; 888 map->reloc = map->start - dso->text_offset;
885
886 if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL))
887 map->reloc = map->start - tshdr.sh_addr + tshdr.sh_offset;
888 }
889 889
890 dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap); 890 dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
891 /* 891 /*
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index a937053a0ae0..c8b7544d9267 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -34,8 +34,8 @@
34#endif 34#endif
35 35
36#ifdef HAVE_LIBELF_SUPPORT 36#ifdef HAVE_LIBELF_SUPPORT
37extern Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, 37Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
38 GElf_Shdr *shp, const char *name, size_t *idx); 38 GElf_Shdr *shp, const char *name, size_t *idx);
39#endif 39#endif
40 40
41#ifndef DMGL_PARAMS 41#ifndef DMGL_PARAMS
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c
index 6adfa18cdd4e..996046a66fe5 100644
--- a/tools/perf/util/usage.c
+++ b/tools/perf/util/usage.c
@@ -41,15 +41,9 @@ static void warn_builtin(const char *warn, va_list params)
41/* If we are in a dlopen()ed .so write to a global variable would segfault 41/* If we are in a dlopen()ed .so write to a global variable would segfault
42 * (ugh), so keep things static. */ 42 * (ugh), so keep things static. */
43static void (*usage_routine)(const char *err) NORETURN = usage_builtin; 43static void (*usage_routine)(const char *err) NORETURN = usage_builtin;
44static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
45static void (*error_routine)(const char *err, va_list params) = error_builtin; 44static void (*error_routine)(const char *err, va_list params) = error_builtin;
46static void (*warn_routine)(const char *err, va_list params) = warn_builtin; 45static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
47 46
48void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN)
49{
50 die_routine = routine;
51}
52
53void set_warning_routine(void (*routine)(const char *err, va_list params)) 47void set_warning_routine(void (*routine)(const char *err, va_list params))
54{ 48{
55 warn_routine = routine; 49 warn_routine = routine;
@@ -65,7 +59,7 @@ void die(const char *err, ...)
65 va_list params; 59 va_list params;
66 60
67 va_start(params, err); 61 va_start(params, err);
68 die_routine(err, params); 62 die_builtin(err, params);
69 va_end(params); 63 va_end(params);
70} 64}
71 65
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index d0d50cef8b2a..8298d607c738 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -133,25 +133,15 @@ extern char buildid_dir[];
133#define PERF_GTK_DSO "libperf-gtk.so" 133#define PERF_GTK_DSO "libperf-gtk.so"
134 134
135/* General helper functions */ 135/* General helper functions */
136extern void usage(const char *err) NORETURN; 136void usage(const char *err) NORETURN;
137extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 137void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
138extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); 138int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
139extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); 139void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
140 140
141#include "../../../include/linux/stringify.h" 141void set_warning_routine(void (*routine)(const char *err, va_list params));
142 142
143#define DIE_IF(cnd) \ 143int prefixcmp(const char *str, const char *prefix);
144 do { if (cnd) \ 144void set_buildid_dir(const char *dir);
145 die(" at (" __FILE__ ":" __stringify(__LINE__) "): " \
146 __stringify(cnd) "\n"); \
147 } while (0)
148
149
150extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
151extern void set_warning_routine(void (*routine)(const char *err, va_list params));
152
153extern int prefixcmp(const char *str, const char *prefix);
154extern void set_buildid_dir(const char *dir);
155 145
156#ifdef __GLIBC_PREREQ 146#ifdef __GLIBC_PREREQ
157#if __GLIBC_PREREQ(2, 1) 147#if __GLIBC_PREREQ(2, 1)
@@ -172,8 +162,7 @@ static inline char *gitstrchrnul(const char *s, int c)
172/* 162/*
173 * Wrappers: 163 * Wrappers:
174 */ 164 */
175extern char *xstrdup(const char *str); 165void *xrealloc(void *ptr, size_t size) __attribute__((weak));
176extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
177 166
178 167
179static inline void *zalloc(size_t size) 168static inline void *zalloc(size_t size)
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c
index 19f15b650703..5f1a07c4b87b 100644
--- a/tools/perf/util/wrapper.c
+++ b/tools/perf/util/wrapper.c
@@ -12,18 +12,6 @@ static inline void release_pack_memory(size_t size __maybe_unused,
12{ 12{
13} 13}
14 14
15char *xstrdup(const char *str)
16{
17 char *ret = strdup(str);
18 if (!ret) {
19 release_pack_memory(strlen(str) + 1, -1);
20 ret = strdup(str);
21 if (!ret)
22 die("Out of memory, strdup failed");
23 }
24 return ret;
25}
26
27void *xrealloc(void *ptr, size_t size) 15void *xrealloc(void *ptr, size_t size)
28{ 16{
29 void *ret = realloc(ptr, size); 17 void *ret = realloc(ptr, size);