Skip to content

Commit 244afc0

Browse files
ahunter6acmel
authored andcommitted
perf dlfilter: Add srcline() to perf_dlfilter_fns
Add a function, for use by dlfilters, to return source code file name and line number. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20210627131818.810-9-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e35995e commit 244afc0

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

tools/perf/Documentation/perf-dlfilter.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ struct perf_dlfilter_fns {
125125
char **(*args)(void *ctx, int *dlargc);
126126
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
127127
const __u8 *(*insn)(void *ctx, __u32 *length);
128-
void *(*reserved[123])(void *);
128+
const char *(*srcline)(void *ctx, __u32 *line_number);
129+
void *(*reserved[122])(void *);
129130
};
130131
----
131132

@@ -140,6 +141,8 @@ before calling. Returns 0 on success, -1 otherwise.
140141

141142
'insn' returns instruction bytes and length.
142143

144+
'srcline' return source file name and line number.
145+
143146
The perf_dlfilter_al structure
144147
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145148

tools/perf/util/dlfilter.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "thread.h"
2020
#include "trace-event.h"
2121
#include "symbol.h"
22+
#include "srcline.h"
2223
#include "dlfilter.h"
2324
#include "perf_dlfilter.h"
2425

@@ -208,12 +209,39 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len)
208209
return (__u8 *)d->sample->insn;
209210
}
210211

212+
static const char *dlfilter__srcline(void *ctx, __u32 *line_no)
213+
{
214+
struct dlfilter *d = (struct dlfilter *)ctx;
215+
struct addr_location *al;
216+
unsigned int line = 0;
217+
char *srcfile = NULL;
218+
struct map *map;
219+
u64 addr;
220+
221+
if (!d->ctx_valid || !line_no)
222+
return NULL;
223+
224+
al = get_al(d);
225+
if (!al)
226+
return NULL;
227+
228+
map = al->map;
229+
addr = al->addr;
230+
231+
if (map && map->dso)
232+
srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
233+
234+
*line_no = line;
235+
return srcfile;
236+
}
237+
211238
static const struct perf_dlfilter_fns perf_dlfilter_fns = {
212239
.resolve_ip = dlfilter__resolve_ip,
213240
.resolve_addr = dlfilter__resolve_addr,
214241
.args = dlfilter__args,
215242
.resolve_address = dlfilter__resolve_address,
216243
.insn = dlfilter__insn,
244+
.srcline = dlfilter__srcline,
217245
};
218246

219247
static char *find_dlfilter(const char *file)

tools/perf/util/perf_dlfilter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ struct perf_dlfilter_fns {
9999
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
100100
/* Return instruction bytes and length */
101101
const __u8 *(*insn)(void *ctx, __u32 *length);
102+
/* Return source file name and line number */
103+
const char *(*srcline)(void *ctx, __u32 *line_number);
102104
/* Reserved */
103-
void *(*reserved[123])(void *);
105+
void *(*reserved[122])(void *);
104106
};
105107

106108
/*

0 commit comments

Comments
 (0)