probe-event.c (ac7a75d1fbe072fc5535311ecc080f10645aeba1) probe-event.c (7cd5738d0d8bb192fc86736ac7fb4a6cdb57f957)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * probe-event.c : perf-probe definition to probe_events format converter
4 *
5 * Written by Masami Hiramatsu <mhiramat@redhat.com>
6 */
7
8#include <inttypes.h>

--- 29 unchanged lines hidden (view full) ---

38#include "session.h"
39#include "string2.h"
40#include "strbuf.h"
41
42#include <subcmd/pager.h>
43#include <linux/ctype.h>
44#include <linux/zalloc.h>
45
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * probe-event.c : perf-probe definition to probe_events format converter
4 *
5 * Written by Masami Hiramatsu <mhiramat@redhat.com>
6 */
7
8#include <inttypes.h>

--- 29 unchanged lines hidden (view full) ---

38#include "session.h"
39#include "string2.h"
40#include "strbuf.h"
41
42#include <subcmd/pager.h>
43#include <linux/ctype.h>
44#include <linux/zalloc.h>
45
46#ifdef HAVE_DEBUGINFOD_SUPPORT
47#include <elfutils/debuginfod.h>
48#endif
49
46#define PERFPROBE_GROUP "probe"
47
48bool probe_event_dry_run; /* Dry run flag */
49struct probe_conf probe_conf = { .magic_num = DEFAULT_PROBE_MAGIC_NUM };
50
51#define semantic_error(msg ...) pr_err("Semantic error :" msg)
52
53int e_snprintf(char *str, size_t size, const char *format, ...)

--- 279 unchanged lines hidden (view full) ---

333 goto found;
334 }
335 pr_debug("Failed to find module %s.\n", module);
336 return -ENOENT;
337 }
338
339 map = machine__kernel_map(host_machine);
340 dso = map->dso;
50#define PERFPROBE_GROUP "probe"
51
52bool probe_event_dry_run; /* Dry run flag */
53struct probe_conf probe_conf = { .magic_num = DEFAULT_PROBE_MAGIC_NUM };
54
55#define semantic_error(msg ...) pr_err("Semantic error :" msg)
56
57int e_snprintf(char *str, size_t size, const char *format, ...)

--- 279 unchanged lines hidden (view full) ---

337 goto found;
338 }
339 pr_debug("Failed to find module %s.\n", module);
340 return -ENOENT;
341 }
342
343 map = machine__kernel_map(host_machine);
344 dso = map->dso;
345 if (!dso->has_build_id)
346 dso__read_running_kernel_build_id(dso, host_machine);
341
342 vmlinux_name = symbol_conf.vmlinux_name;
343 dso->load_errno = 0;
344 if (vmlinux_name)
345 ret = dso__load_vmlinux(dso, map, vmlinux_name, false);
346 else
347 ret = dso__load_vmlinux_path(dso, map);
348found:

--- 99 unchanged lines hidden (view full) ---

448 lr->start = result.line;
449 if (lr->end != INT_MAX)
450 lr->end = lr->start + len;
451 clear_perf_probe_point(&pp);
452 }
453 return ret;
454}
455
347
348 vmlinux_name = symbol_conf.vmlinux_name;
349 dso->load_errno = 0;
350 if (vmlinux_name)
351 ret = dso__load_vmlinux(dso, map, vmlinux_name, false);
352 else
353 ret = dso__load_vmlinux_path(dso, map);
354found:

--- 99 unchanged lines hidden (view full) ---

454 lr->start = result.line;
455 if (lr->end != INT_MAX)
456 lr->end = lr->start + len;
457 clear_perf_probe_point(&pp);
458 }
459 return ret;
460}
461
462#ifdef HAVE_DEBUGINFOD_SUPPORT
463static struct debuginfo *open_from_debuginfod(struct dso *dso, struct nsinfo *nsi,
464 bool silent)
465{
466 debuginfod_client *c = debuginfod_begin();
467 char sbuild_id[SBUILD_ID_SIZE + 1];
468 struct debuginfo *ret = NULL;
469 struct nscookie nsc;
470 char *path;
471 int fd;
472
473 if (!c)
474 return NULL;
475
476 build_id__sprintf(dso->build_id, BUILD_ID_SIZE, sbuild_id);
477 fd = debuginfod_find_debuginfo(c, (const unsigned char *)sbuild_id,
478 0, &path);
479 if (fd >= 0)
480 close(fd);
481 debuginfod_end(c);
482 if (fd < 0) {
483 if (!silent)
484 pr_debug("Failed to find debuginfo in debuginfod.\n");
485 return NULL;
486 }
487 if (!silent)
488 pr_debug("Load debuginfo from debuginfod (%s)\n", path);
489
490 nsinfo__mountns_enter(nsi, &nsc);
491 ret = debuginfo__new((const char *)path);
492 nsinfo__mountns_exit(&nsc);
493 return ret;
494}
495#else
496static inline
497struct debuginfo *open_from_debuginfod(struct dso *dso __maybe_unused,
498 struct nsinfo *nsi __maybe_unused,
499 bool silent __maybe_unused)
500{
501 return NULL;
502}
503#endif
504
456/* Open new debuginfo of given module */
457static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi,
458 bool silent)
459{
460 const char *path = module;
461 char reason[STRERR_BUFSIZE];
462 struct debuginfo *ret = NULL;
463 struct dso *dso = NULL;
464 struct nscookie nsc;
465 int err;
466
467 if (!module || !strchr(module, '/')) {
468 err = kernel_get_module_dso(module, &dso);
469 if (err < 0) {
470 if (!dso || dso->load_errno == 0) {
471 if (!str_error_r(-err, reason, STRERR_BUFSIZE))
472 strcpy(reason, "(unknown)");
473 } else
474 dso__strerror_load(dso, reason, STRERR_BUFSIZE);
505/* Open new debuginfo of given module */
506static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi,
507 bool silent)
508{
509 const char *path = module;
510 char reason[STRERR_BUFSIZE];
511 struct debuginfo *ret = NULL;
512 struct dso *dso = NULL;
513 struct nscookie nsc;
514 int err;
515
516 if (!module || !strchr(module, '/')) {
517 err = kernel_get_module_dso(module, &dso);
518 if (err < 0) {
519 if (!dso || dso->load_errno == 0) {
520 if (!str_error_r(-err, reason, STRERR_BUFSIZE))
521 strcpy(reason, "(unknown)");
522 } else
523 dso__strerror_load(dso, reason, STRERR_BUFSIZE);
524 if (dso)
525 ret = open_from_debuginfod(dso, nsi, silent);
526 if (ret)
527 return ret;
475 if (!silent) {
476 if (module)
477 pr_err("Module %s is not loaded, please specify its full path name.\n", module);
478 else
479 pr_err("Failed to find the path for the kernel: %s\n", reason);
480 }
481 return NULL;
482 }

--- 471 unchanged lines hidden (view full) ---

954{
955 int l = 1;
956 struct int_node *ln;
957 struct debuginfo *dinfo;
958 FILE *fp;
959 int ret;
960 char *tmp;
961 char sbuf[STRERR_BUFSIZE];
528 if (!silent) {
529 if (module)
530 pr_err("Module %s is not loaded, please specify its full path name.\n", module);
531 else
532 pr_err("Failed to find the path for the kernel: %s\n", reason);
533 }
534 return NULL;
535 }

--- 471 unchanged lines hidden (view full) ---

1007{
1008 int l = 1;
1009 struct int_node *ln;
1010 struct debuginfo *dinfo;
1011 FILE *fp;
1012 int ret;
1013 char *tmp;
1014 char sbuf[STRERR_BUFSIZE];
1015 char sbuild_id[SBUILD_ID_SIZE] = "";
962
963 /* Search a line range */
964 dinfo = open_debuginfo(module, NULL, false);
965 if (!dinfo)
966 return -ENOENT;
967
968 ret = debuginfo__find_line_range(dinfo, lr);
969 if (!ret) { /* Not found, retry with an alternative */
970 ret = get_alternative_line_range(dinfo, lr, module, user);
971 if (!ret)
972 ret = debuginfo__find_line_range(dinfo, lr);
973 }
1016
1017 /* Search a line range */
1018 dinfo = open_debuginfo(module, NULL, false);
1019 if (!dinfo)
1020 return -ENOENT;
1021
1022 ret = debuginfo__find_line_range(dinfo, lr);
1023 if (!ret) { /* Not found, retry with an alternative */
1024 ret = get_alternative_line_range(dinfo, lr, module, user);
1025 if (!ret)
1026 ret = debuginfo__find_line_range(dinfo, lr);
1027 }
1028 if (dinfo->build_id)
1029 build_id__sprintf(dinfo->build_id, BUILD_ID_SIZE, sbuild_id);
974 debuginfo__delete(dinfo);
975 if (ret == 0 || ret == -ENOENT) {
976 pr_warning("Specified source line is not found.\n");
977 return -ENOENT;
978 } else if (ret < 0) {
979 pr_warning("Debuginfo analysis failed.\n");
980 return ret;
981 }
982
983 /* Convert source file path */
984 tmp = lr->path;
1030 debuginfo__delete(dinfo);
1031 if (ret == 0 || ret == -ENOENT) {
1032 pr_warning("Specified source line is not found.\n");
1033 return -ENOENT;
1034 } else if (ret < 0) {
1035 pr_warning("Debuginfo analysis failed.\n");
1036 return ret;
1037 }
1038
1039 /* Convert source file path */
1040 tmp = lr->path;
985 ret = get_real_path(tmp, lr->comp_dir, &lr->path);
1041 ret = find_source_path(tmp, sbuild_id, lr->comp_dir, &lr->path);
986
987 /* Free old path when new path is assigned */
988 if (tmp != lr->path)
989 free(tmp);
990
991 if (ret < 0) {
992 pr_warning("Failed to find source file path.\n");
993 return ret;

--- 2617 unchanged lines hidden ---
1042
1043 /* Free old path when new path is assigned */
1044 if (tmp != lr->path)
1045 free(tmp);
1046
1047 if (ret < 0) {
1048 pr_warning("Failed to find source file path.\n");
1049 return ret;

--- 2617 unchanged lines hidden ---