117
117
struct rb_node *nd;
118
118
struct map_groups *grp = &machine.kmaps;
120
/* A file path -- this is an offline module */
121
if (module && strchr(module, '/'))
122
return machine__new_module(&machine, 0, module);
121
125
module = "kernel";
172
176
#ifdef DWARF_SUPPORT
173
static int open_vmlinux(const char *module)
177
/* Open new debuginfo of given module */
178
static struct debuginfo *open_debuginfo(const char *module)
175
const char *path = kernel_get_module_path(module);
177
pr_err("Failed to find path of %s module.\n",
182
/* A file path -- this is an offline module */
183
if (module && strchr(module, '/'))
186
path = kernel_get_module_path(module);
189
pr_err("Failed to find path of %s module.\n",
181
pr_debug("Try to open %s\n", path);
182
return open(path, O_RDONLY);
194
return debuginfo__new(path);
195
207
int ret = -ENOENT;
208
struct debuginfo *dinfo;
197
210
sym = __find_kernel_function_by_name(tp->symbol, &map);
199
212
addr = map->unmap_ip(map, sym->start + tp->offset);
200
213
pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol,
201
214
tp->offset, addr);
202
ret = find_perf_probe_point((unsigned long)addr, pp);
216
dinfo = debuginfo__new_online_kernel(addr);
218
ret = debuginfo__find_probe_point(dinfo,
219
(unsigned long)addr, pp);
220
debuginfo__delete(dinfo);
222
pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n",
205
228
pr_debug("Failed to find corresponding probes from "
240
static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
241
int ntevs, const char *module)
249
tmp = strrchr(module, '/');
251
/* This is a module path -- get the module name */
252
module = strdup(tmp + 1);
255
tmp = strchr(module, '.');
258
tmp = (char *)module; /* For free() */
261
for (i = 0; i < ntevs; i++) {
262
tevs[i].point.module = strdup(module);
263
if (!tevs[i].point.module) {
217
275
/* Try to find perf_probe_event with debuginfo */
218
276
static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
219
struct probe_trace_event **tevs,
220
int max_tevs, const char *module)
277
struct probe_trace_event **tevs,
278
int max_tevs, const char *module)
222
280
bool need_dwarf = perf_probe_event_need_dwarf(pev);
281
struct debuginfo *dinfo = open_debuginfo(module);
225
fd = open_vmlinux(module);
227
285
if (need_dwarf) {
228
286
pr_warning("Failed to open debuginfo file.\n");
231
pr_debug("Could not open vmlinux. Try to use symbols.\n");
289
pr_debug("Could not open debuginfo. Try to use symbols.\n");
235
/* Searching trace events corresponding to probe event */
236
ntevs = find_probe_trace_events(fd, pev, tevs, max_tevs);
293
/* Searching trace events corresponding to a probe event */
294
ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
296
debuginfo__delete(dinfo);
238
298
if (ntevs > 0) { /* Succeeded to find trace events */
239
299
pr_debug("find %d probe_trace_events.\n", ntevs);
301
ret = add_module_to_probe_trace_events(*tevs, ntevs,
303
return ret < 0 ? ret : ntevs;
243
306
if (ntevs == 0) { /* No error but failed to find probe point. */
383
fd = open_vmlinux(module);
447
dinfo = open_debuginfo(module);
385
449
pr_warning("Failed to open debuginfo file.\n");
389
ret = find_line_range(fd, lr);
453
ret = debuginfo__find_line_range(dinfo, lr);
454
debuginfo__delete(dinfo);
391
456
pr_warning("Specified source line is not found.\n");
451
static int show_available_vars_at(int fd, struct perf_probe_event *pev,
516
static int show_available_vars_at(struct debuginfo *dinfo,
517
struct perf_probe_event *pev,
452
518
int max_vls, struct strfilter *_filter,
464
530
pr_debug("Searching variables at %s\n", buf);
466
ret = find_available_vars_at(fd, pev, &vls, max_vls, externs);
532
ret = debuginfo__find_available_vars_at(dinfo, pev, &vls,
468
535
pr_err("Failed to find variables at %s (%d)\n", buf, ret);
504
571
int max_vls, const char *module,
505
572
struct strfilter *_filter, bool externs)
575
struct debuginfo *dinfo;
509
577
ret = init_vmlinux();
581
dinfo = open_debuginfo(module);
583
pr_warning("Failed to open debuginfo file.\n");
515
for (i = 0; i < npevs && ret >= 0; i++) {
516
fd = open_vmlinux(module);
518
pr_warning("Failed to open debug information file.\n");
522
ret = show_available_vars_at(fd, &pevs[i], max_vls, _filter,
589
for (i = 0; i < npevs && ret >= 0; i++)
590
ret = show_available_vars_at(dinfo, &pevs[i], max_vls, _filter,
593
debuginfo__delete(dinfo);
991
1060
/* Parse probe_events event into struct probe_point */
992
1061
static int parse_probe_trace_command(const char *cmd,
993
struct probe_trace_event *tev)
1062
struct probe_trace_event *tev)
995
1064
struct probe_trace_point *tp = &tev->point;
1024
1093
tp->retprobe = (pr == 'r');
1026
/* Scan function name and offset */
1027
ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol,
1095
/* Scan module name(if there), function name and offset */
1096
p = strchr(argv[1], ':');
1098
tp->module = strndup(argv[1], p - argv[1]);
1102
ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol,
1030
1105
tp->offset = 0;
1269
1344
if (buf == NULL)
1272
len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu",
1347
len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu",
1273
1348
tp->retprobe ? 'r' : 'p',
1274
1349
tev->group, tev->event,
1350
tp->module ?: "", tp->module ? ":" : "",
1275
1351
tp->symbol, tp->offset);
1729
1807
/* Convert perf_probe_event with debuginfo */
1730
1808
ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module);
1810
return ret; /* Found in debuginfo or got an error */
1734
1812
/* Allocate trace event buffer */
1735
1813
tev = *tevs = zalloc(sizeof(struct probe_trace_event));