perf probe: Support probing on offline cross-arch binary
Support probing on offline cross-architecture binary by adding getting the target machine arch from ELF and choose correct register string for the machine. Here is an example: ----- $ perf probe --vmlinux=./vmlinux-arm --definition 'do_sys_open $params' p:probe/do_sys_open do_sys_open+0 dfd=%r5:s32 filename=%r1:u32 flags=%r6:s32 mode=%r3:u16 ----- Here, we can get probe/do_sys_open from above and append it to to the target machine's tracing/kprobe_events file in the tracefs mountput, usually /sys/kernel/debug/tracing/kprobe_events (or /sys/kernel/tracing/kprobe_events). Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/147214229717.23638.6440579792548044658.stgit@devbox [ Add definition for EM_AARCH64 to fix the build on at least centos 6, debian 7 & ubuntu 12.04.5 ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
此提交包含在:

提交者
Arnaldo Carvalho de Melo

父節點
428aff82e9
當前提交
293d5b4394
@@ -98,6 +98,7 @@ endif
|
||||
|
||||
libperf-$(CONFIG_DWARF) += probe-finder.o
|
||||
libperf-$(CONFIG_DWARF) += dwarf-aux.o
|
||||
libperf-$(CONFIG_DWARF) += dwarf-regs.o
|
||||
|
||||
libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
|
||||
libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind-local.o
|
||||
|
59
tools/perf/util/dwarf-regs.c
一般檔案
59
tools/perf/util/dwarf-regs.c
一般檔案
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
|
||||
*
|
||||
* Written by: Masami Hiramatsu <mhiramat@kernel.org>
|
||||
*/
|
||||
|
||||
#include <util.h>
|
||||
#include <debug.h>
|
||||
#include <dwarf-regs.h>
|
||||
#include <elf.h>
|
||||
|
||||
#ifndef EM_AARCH64
|
||||
#define EM_AARCH64 183 /* ARM 64 bit */
|
||||
#endif
|
||||
|
||||
/* Define const char * {arch}_register_tbl[] */
|
||||
#define DEFINE_DWARF_REGSTR_TABLE
|
||||
#include "../arch/x86/include/dwarf-regs-table.h"
|
||||
#include "../arch/arm/include/dwarf-regs-table.h"
|
||||
#include "../arch/arm64/include/dwarf-regs-table.h"
|
||||
#include "../arch/sh/include/dwarf-regs-table.h"
|
||||
#include "../arch/powerpc/include/dwarf-regs-table.h"
|
||||
#include "../arch/s390/include/dwarf-regs-table.h"
|
||||
#include "../arch/sparc/include/dwarf-regs-table.h"
|
||||
#include "../arch/xtensa/include/dwarf-regs-table.h"
|
||||
|
||||
#define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL)
|
||||
|
||||
/* Return architecture dependent register string (for kprobe-tracer) */
|
||||
const char *get_dwarf_regstr(unsigned int n, unsigned int machine)
|
||||
{
|
||||
switch (machine) {
|
||||
case EM_NONE: /* Generic arch - use host arch */
|
||||
return get_arch_regstr(n);
|
||||
case EM_386:
|
||||
return __get_dwarf_regstr(x86_32_regstr_tbl, n);
|
||||
case EM_X86_64:
|
||||
return __get_dwarf_regstr(x86_64_regstr_tbl, n);
|
||||
case EM_ARM:
|
||||
return __get_dwarf_regstr(arm_regstr_tbl, n);
|
||||
case EM_AARCH64:
|
||||
return __get_dwarf_regstr(aarch64_regstr_tbl, n);
|
||||
case EM_SH:
|
||||
return __get_dwarf_regstr(sh_regstr_tbl, n);
|
||||
case EM_S390:
|
||||
return __get_dwarf_regstr(s390_regstr_tbl, n);
|
||||
case EM_PPC:
|
||||
case EM_PPC64:
|
||||
return __get_dwarf_regstr(powerpc_regstr_tbl, n);
|
||||
case EM_SPARC:
|
||||
case EM_SPARCV9:
|
||||
return __get_dwarf_regstr(sparc_regstr_tbl, n);
|
||||
case EM_XTENSA:
|
||||
return __get_dwarf_regstr(xtensa_regstr_tbl, n);
|
||||
default:
|
||||
pr_err("ELF MACHINE %x is not supported.\n", machine);
|
||||
}
|
||||
return NULL;
|
||||
}
|
@@ -3,6 +3,12 @@
|
||||
|
||||
#ifdef HAVE_DWARF_SUPPORT
|
||||
const char *get_arch_regstr(unsigned int n);
|
||||
/*
|
||||
* get_dwarf_regstr - Returns ftrace register string from DWARF regnum
|
||||
* n: DWARF register number
|
||||
* machine: ELF machine signature (EM_*)
|
||||
*/
|
||||
const char *get_dwarf_regstr(unsigned int n, unsigned int machine);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
|
||||
|
@@ -171,6 +171,7 @@ static struct probe_trace_arg_ref *alloc_trace_arg_ref(long offs)
|
||||
*/
|
||||
static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,
|
||||
Dwarf_Op *fb_ops, Dwarf_Die *sp_die,
|
||||
unsigned int machine,
|
||||
struct probe_trace_arg *tvar)
|
||||
{
|
||||
Dwarf_Attribute attr;
|
||||
@@ -266,7 +267,7 @@ static_var:
|
||||
if (!tvar)
|
||||
return ret2;
|
||||
|
||||
regs = get_arch_regstr(regn);
|
||||
regs = get_dwarf_regstr(regn, machine);
|
||||
if (!regs) {
|
||||
/* This should be a bug in DWARF or this tool */
|
||||
pr_warning("Mapping for the register number %u "
|
||||
@@ -543,7 +544,7 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
|
||||
dwarf_diename(vr_die));
|
||||
|
||||
ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops,
|
||||
&pf->sp_die, pf->tvar);
|
||||
&pf->sp_die, pf->machine, pf->tvar);
|
||||
if (ret == -ENOENT || ret == -EINVAL) {
|
||||
pr_err("Failed to find the location of the '%s' variable at this address.\n"
|
||||
" Perhaps it has been optimized out.\n"
|
||||
@@ -1106,11 +1107,8 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
|
||||
struct probe_finder *pf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#if _ELFUTILS_PREREQ(0, 142)
|
||||
Elf *elf;
|
||||
GElf_Ehdr ehdr;
|
||||
GElf_Shdr shdr;
|
||||
|
||||
if (pf->cfi_eh || pf->cfi_dbg)
|
||||
return debuginfo__find_probe_location(dbg, pf);
|
||||
@@ -1123,11 +1121,18 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
|
||||
if (gelf_getehdr(elf, &ehdr) == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
if (elf_section_by_name(elf, &ehdr, &shdr, ".eh_frame", NULL) &&
|
||||
shdr.sh_type == SHT_PROGBITS)
|
||||
pf->cfi_eh = dwarf_getcfi_elf(elf);
|
||||
pf->machine = ehdr.e_machine;
|
||||
|
||||
pf->cfi_dbg = dwarf_getcfi(dbg->dbg);
|
||||
#if _ELFUTILS_PREREQ(0, 142)
|
||||
do {
|
||||
GElf_Shdr shdr;
|
||||
|
||||
if (elf_section_by_name(elf, &ehdr, &shdr, ".eh_frame", NULL) &&
|
||||
shdr.sh_type == SHT_PROGBITS)
|
||||
pf->cfi_eh = dwarf_getcfi_elf(elf);
|
||||
|
||||
pf->cfi_dbg = dwarf_getcfi(dbg->dbg);
|
||||
} while (0);
|
||||
#endif
|
||||
|
||||
ret = debuginfo__find_probe_location(dbg, pf);
|
||||
@@ -1155,7 +1160,7 @@ static int copy_variables_cb(Dwarf_Die *die_mem, void *data)
|
||||
(tag == DW_TAG_variable && vf->vars)) {
|
||||
if (convert_variable_location(die_mem, vf->pf->addr,
|
||||
vf->pf->fb_ops, &pf->sp_die,
|
||||
NULL) == 0) {
|
||||
pf->machine, NULL) == 0) {
|
||||
vf->args[vf->nargs].var = (char *)dwarf_diename(die_mem);
|
||||
if (vf->args[vf->nargs].var == NULL) {
|
||||
vf->ret = -ENOMEM;
|
||||
@@ -1318,7 +1323,7 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
|
||||
tag == DW_TAG_variable) {
|
||||
ret = convert_variable_location(die_mem, af->pf.addr,
|
||||
af->pf.fb_ops, &af->pf.sp_die,
|
||||
NULL);
|
||||
af->pf.machine, NULL);
|
||||
if (ret == 0 || ret == -ERANGE) {
|
||||
int ret2;
|
||||
bool externs = !af->child;
|
||||
|
@@ -80,6 +80,7 @@ struct probe_finder {
|
||||
Dwarf_CFI *cfi_dbg;
|
||||
#endif
|
||||
Dwarf_Op *fb_ops; /* Frame base attribute */
|
||||
unsigned int machine; /* Target machine arch */
|
||||
struct perf_probe_arg *pvar; /* Current target variable */
|
||||
struct probe_trace_arg *tvar; /* Current result variable */
|
||||
};
|
||||
|
新增問題並參考
封鎖使用者