Skip to content

Commit e35995e

Browse files
ahunter6acmel
authored andcommitted
perf dlfilter: Add insn() to perf_dlfilter_fns
Add a function, for use by dlfilters, to return instruction bytes. 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-8-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent f645744 commit e35995e

3 files changed

Lines changed: 39 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
@@ -124,7 +124,8 @@ struct perf_dlfilter_fns {
124124
const struct perf_dlfilter_al *(*resolve_addr)(void *ctx);
125125
char **(*args)(void *ctx, int *dlargc);
126126
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
127-
void *(*reserved[124])(void *);
127+
const __u8 *(*insn)(void *ctx, __u32 *length);
128+
void *(*reserved[123])(void *);
128129
};
129130
----
130131

@@ -137,6 +138,8 @@ struct perf_dlfilter_fns {
137138
'resolve_address' provides information about 'address'. al->size must be set
138139
before calling. Returns 0 on success, -1 otherwise.
139140

141+
'insn' returns instruction bytes and length.
142+
140143
The perf_dlfilter_al structure
141144
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142145

tools/perf/util/dlfilter.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "dso.h"
1818
#include "map.h"
1919
#include "thread.h"
20+
#include "trace-event.h"
2021
#include "symbol.h"
2122
#include "dlfilter.h"
2223
#include "perf_dlfilter.h"
@@ -177,11 +178,42 @@ static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf
177178
return 0;
178179
}
179180

181+
static const __u8 *dlfilter__insn(void *ctx, __u32 *len)
182+
{
183+
struct dlfilter *d = (struct dlfilter *)ctx;
184+
185+
if (!len)
186+
return NULL;
187+
188+
*len = 0;
189+
190+
if (!d->ctx_valid)
191+
return NULL;
192+
193+
if (d->sample->ip && !d->sample->insn_len) {
194+
struct addr_location *al = d->al;
195+
196+
if (!al->thread && machine__resolve(d->machine, al, d->sample) < 0)
197+
return NULL;
198+
199+
if (al->thread->maps && al->thread->maps->machine)
200+
script_fetch_insn(d->sample, al->thread, al->thread->maps->machine);
201+
}
202+
203+
if (!d->sample->insn_len)
204+
return NULL;
205+
206+
*len = d->sample->insn_len;
207+
208+
return (__u8 *)d->sample->insn;
209+
}
210+
180211
static const struct perf_dlfilter_fns perf_dlfilter_fns = {
181212
.resolve_ip = dlfilter__resolve_ip,
182213
.resolve_addr = dlfilter__resolve_addr,
183214
.args = dlfilter__args,
184215
.resolve_address = dlfilter__resolve_address,
216+
.insn = dlfilter__insn,
185217
};
186218

187219
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
@@ -97,8 +97,10 @@ struct perf_dlfilter_fns {
9797
* calling). Returns 0 on success, -1 otherwise.
9898
*/
9999
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
100+
/* Return instruction bytes and length */
101+
const __u8 *(*insn)(void *ctx, __u32 *length);
100102
/* Reserved */
101-
void *(*reserved[124])(void *);
103+
void *(*reserved[123])(void *);
102104
};
103105

104106
/*

0 commit comments

Comments
 (0)