aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-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
46 files changed, 235 insertions, 364 deletions
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);