Skip to content

Commit ec4c00f

Browse files
ahunter6acmel
authored andcommitted
perf dlfilter: Add object_code() to perf_dlfilter_fns
Add a function, for use by dlfilters, to read object code. 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-11-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 6495e76 commit ec4c00f

3 files changed

Lines changed: 41 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
@@ -127,7 +127,8 @@ struct perf_dlfilter_fns {
127127
const __u8 *(*insn)(void *ctx, __u32 *length);
128128
const char *(*srcline)(void *ctx, __u32 *line_number);
129129
struct perf_event_attr *(*attr)(void *ctx);
130-
void *(*reserved[121])(void *);
130+
__s32 (*object_code)(void *ctx, __u64 ip, void *buf, __u32 len);
131+
void *(*reserved[120])(void *);
131132
};
132133
----
133134

@@ -146,6 +147,8 @@ before calling. Returns 0 on success, -1 otherwise.
146147

147148
'attr' returns perf_event_attr, refer <linux/perf_event.h>.
148149

150+
'object_code' reads object code and returns the number of bytes read.
151+
149152
The perf_dlfilter_al structure
150153
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151154

tools/perf/util/dlfilter.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,39 @@ static struct perf_event_attr *dlfilter__attr(void *ctx)
245245
return &d->evsel->core.attr;
246246
}
247247

248+
static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
249+
{
250+
struct dlfilter *d = (struct dlfilter *)ctx;
251+
struct addr_location *al;
252+
struct addr_location a;
253+
struct map *map;
254+
u64 offset;
255+
256+
if (!d->ctx_valid)
257+
return -1;
258+
259+
al = get_al(d);
260+
if (!al)
261+
return -1;
262+
263+
map = al->map;
264+
265+
if (map && ip >= map->start && ip < map->end &&
266+
machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
267+
goto have_map;
268+
269+
thread__find_map_fb(al->thread, d->sample->cpumode, ip, &a);
270+
if (!a.map)
271+
return -1;
272+
273+
map = a.map;
274+
have_map:
275+
offset = map->map_ip(map, ip);
276+
if (ip + len >= map->end)
277+
len = map->end - ip;
278+
return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
279+
}
280+
248281
static const struct perf_dlfilter_fns perf_dlfilter_fns = {
249282
.resolve_ip = dlfilter__resolve_ip,
250283
.resolve_addr = dlfilter__resolve_addr,
@@ -253,6 +286,7 @@ static const struct perf_dlfilter_fns perf_dlfilter_fns = {
253286
.insn = dlfilter__insn,
254287
.srcline = dlfilter__srcline,
255288
.attr = dlfilter__attr,
289+
.object_code = dlfilter__object_code,
256290
};
257291

258292
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
@@ -103,8 +103,10 @@ struct perf_dlfilter_fns {
103103
const char *(*srcline)(void *ctx, __u32 *line_number);
104104
/* Return perf_event_attr, refer <linux/perf_event.h> */
105105
struct perf_event_attr *(*attr)(void *ctx);
106+
/* Read object code, return numbers of bytes read */
107+
__s32 (*object_code)(void *ctx, __u64 ip, void *buf, __u32 len);
106108
/* Reserved */
107-
void *(*reserved[121])(void *);
109+
void *(*reserved[120])(void *);
108110
};
109111

110112
/*

0 commit comments

Comments
 (0)