Commit 804b3606 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar

perf probe: Use elfutils-libdw for analyzing debuginfo

Newer gcc introduces newer & richer debuginfo, and only libdw
in elfutils project can support it. So perf probe moves onto
elfutils-libdw from libdwarf.

Changes in v3:
 - Cast Dwarf_Addr/Dwarf_Word to uintmax_t for printf-formats.
 - Recover a sign-prefix which was removed in v2 by mistake.

Changes in v2:
 - Fix a type-casting bug in Makefile.
 - Cast Dwarf_Addr/Dwarf_Word to unsigned long long for printf-formats.
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Ulrich Drepper <drepper@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
LKML-Reference: <20100225133542.6725.34724.stgit@localhost6.localdomain6>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 81cb8aa3
...@@ -500,12 +500,12 @@ else ...@@ -500,12 +500,12 @@ else
msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]);
endif endif
ifneq ($(shell sh -c "(echo '\#ifndef _MIPS_SZLONG'; echo '\#define _MIPS_SZLONG 0'; echo '\#endif'; echo '\#include <dwarf.h>'; echo '\#include <libdwarf.h>'; echo 'int main(void) { Dwarf_Debug dbg; Dwarf_Error err; Dwarf_Ranges *rng; dwarf_init(0, DW_DLC_READ, 0, 0, &dbg, &err); dwarf_get_ranges(dbg, 0, &rng, 0, 0, &err); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/libdwarf -ldwarf -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
msg := $(warning No libdwarf.h found or old libdwarf.h found, disables dwarf support. Please install libdwarf-dev/libdwarf-devel >= 20081231); msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev);
BASIC_CFLAGS += -DNO_LIBDWARF BASIC_CFLAGS += -DNO_DWARF_SUPPORT
else else
BASIC_CFLAGS += -I/usr/include/libdwarf BASIC_CFLAGS += -I/usr/include/elfutils
EXTLIBS += -lelf -ldwarf EXTLIBS += -lelf -ldw
LIB_OBJS += util/probe-finder.o LIB_OBJS += util/probe-finder.o
endif endif
......
...@@ -128,7 +128,7 @@ static void evaluate_probe_point(struct probe_point *pp) ...@@ -128,7 +128,7 @@ static void evaluate_probe_point(struct probe_point *pp)
pp->function); pp->function);
} }
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
static int open_vmlinux(void) static int open_vmlinux(void)
{ {
if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) { if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) {
...@@ -156,7 +156,7 @@ static const char * const probe_usage[] = { ...@@ -156,7 +156,7 @@ static const char * const probe_usage[] = {
"perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]",
"perf probe [<options>] --del '[GROUP:]EVENT' ...", "perf probe [<options>] --del '[GROUP:]EVENT' ...",
"perf probe --list", "perf probe --list",
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
"perf probe --line 'LINEDESC'", "perf probe --line 'LINEDESC'",
#endif #endif
NULL NULL
...@@ -165,7 +165,7 @@ static const char * const probe_usage[] = { ...@@ -165,7 +165,7 @@ static const char * const probe_usage[] = {
static const struct option options[] = { static const struct option options[] = {
OPT_BOOLEAN('v', "verbose", &verbose, OPT_BOOLEAN('v', "verbose", &verbose,
"be more verbose (show parsed arguments, etc)"), "be more verbose (show parsed arguments, etc)"),
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
"file", "vmlinux pathname"), "file", "vmlinux pathname"),
#endif #endif
...@@ -174,7 +174,7 @@ static const struct option options[] = { ...@@ -174,7 +174,7 @@ static const struct option options[] = {
OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
opt_del_probe_event), opt_del_probe_event),
OPT_CALLBACK('a', "add", NULL, OPT_CALLBACK('a', "add", NULL,
#ifdef NO_LIBDWARF #ifdef NO_DWARF_SUPPORT
"[EVENT=]FUNC[+OFFS|%return] [ARG ...]", "[EVENT=]FUNC[+OFFS|%return] [ARG ...]",
#else #else
"[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]", "[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]",
...@@ -185,7 +185,7 @@ static const struct option options[] = { ...@@ -185,7 +185,7 @@ static const struct option options[] = {
"\t\tFUNC:\tFunction name\n" "\t\tFUNC:\tFunction name\n"
"\t\tOFFS:\tOffset from function entry (in byte)\n" "\t\tOFFS:\tOffset from function entry (in byte)\n"
"\t\t%return:\tPut the probe at function return\n" "\t\t%return:\tPut the probe at function return\n"
#ifdef NO_LIBDWARF #ifdef NO_DWARF_SUPPORT
"\t\tARG:\tProbe argument (only \n" "\t\tARG:\tProbe argument (only \n"
#else #else
"\t\tSRC:\tSource code path\n" "\t\tSRC:\tSource code path\n"
...@@ -197,7 +197,7 @@ static const struct option options[] = { ...@@ -197,7 +197,7 @@ static const struct option options[] = {
opt_add_probe_event), opt_add_probe_event),
OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events" OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events"
" with existing name"), " with existing name"),
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
OPT_CALLBACK('L', "line", NULL, OPT_CALLBACK('L', "line", NULL,
"FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]",
"Show source code lines.", opt_show_lines), "Show source code lines.", opt_show_lines),
...@@ -225,7 +225,7 @@ static void init_vmlinux(void) ...@@ -225,7 +225,7 @@ static void init_vmlinux(void)
int cmd_probe(int argc, const char **argv, const char *prefix __used) int cmd_probe(int argc, const char **argv, const char *prefix __used)
{ {
int i, ret; int i, ret;
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
int fd; int fd;
#endif #endif
struct probe_point *pp; struct probe_point *pp;
...@@ -261,7 +261,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -261,7 +261,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
return 0; return 0;
} }
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
if (session.show_lines) { if (session.show_lines) {
if (session.nr_probe != 0 || session.dellist) { if (session.nr_probe != 0 || session.dellist) {
pr_warning(" Error: Don't use --line with" pr_warning(" Error: Don't use --line with"
...@@ -292,9 +292,9 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -292,9 +292,9 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
init_vmlinux(); init_vmlinux();
if (session.need_dwarf) if (session.need_dwarf)
#ifdef NO_LIBDWARF #ifdef NO_DWARF_SUPPORT
die("Debuginfo-analysis is not supported"); die("Debuginfo-analysis is not supported");
#else /* !NO_LIBDWARF */ #else /* !NO_DWARF_SUPPORT */
pr_debug("Some probes require debuginfo.\n"); pr_debug("Some probes require debuginfo.\n");
fd = open_vmlinux(); fd = open_vmlinux();
...@@ -335,7 +335,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -335,7 +335,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
close(fd); close(fd);
end_dwarf: end_dwarf:
#endif /* !NO_LIBDWARF */ #endif /* !NO_DWARF_SUPPORT */
/* Synthesize probes without dwarf */ /* Synthesize probes without dwarf */
for (i = 0; i < session.nr_probe; i++) { for (i = 0; i < session.nr_probe; i++) {
......
This diff is collapsed.
#ifndef _PROBE_FINDER_H #ifndef _PROBE_FINDER_H
#define _PROBE_FINDER_H #define _PROBE_FINDER_H
#include <stdbool.h>
#include "util.h" #include "util.h"
#define MAX_PATH_LEN 256 #define MAX_PATH_LEN 256
...@@ -46,53 +47,48 @@ struct line_range { ...@@ -46,53 +47,48 @@ struct line_range {
char *function; /* Function name */ char *function; /* Function name */
unsigned int start; /* Start line number */ unsigned int start; /* Start line number */
unsigned int end; /* End line number */ unsigned int end; /* End line number */
unsigned int offset; /* Start line offset */ int offset; /* Start line offset */
char *path; /* Real path name */ char *path; /* Real path name */
struct list_head line_list; /* Visible lines */ struct list_head line_list; /* Visible lines */
}; };
#ifndef NO_LIBDWARF #ifndef NO_DWARF_SUPPORT
extern int find_probe_point(int fd, struct probe_point *pp); extern int find_probe_point(int fd, struct probe_point *pp);
extern int find_line_range(int fd, struct line_range *lr); extern int find_line_range(int fd, struct line_range *lr);
/* Workaround for undefined _MIPS_SZLONG bug in libdwarf.h: */
#ifndef _MIPS_SZLONG
# define _MIPS_SZLONG 0
#endif
#include <dwarf.h> #include <dwarf.h>
#include <libdwarf.h> #include <libdw.h>
struct probe_finder { struct probe_finder {
struct probe_point *pp; /* Target probe point */ struct probe_point *pp; /* Target probe point */
/* For function searching */ /* For function searching */
Dwarf_Addr addr; /* Address */ Dwarf_Addr addr; /* Address */
Dwarf_Unsigned fno; /* File number */ const char *fname; /* File name */
Dwarf_Unsigned lno; /* Line number */ int lno; /* Line number */
Dwarf_Off inl_offs; /* Inline offset */ void *origin; /* Inline origin addr */
Dwarf_Die cu_die; /* Current CU */ Dwarf_Die cu_die; /* Current CU */
/* For variable searching */ /* For variable searching */
Dwarf_Addr cu_base; /* Current CU base address */ Dwarf_Op *fb_ops; /* Frame base attribute */
Dwarf_Locdesc fbloc; /* Location of Current Frame Base */ Dwarf_Addr cu_base; /* Current CU base address */
const char *var; /* Current variable name */ const char *var; /* Current variable name */
char *buf; /* Current output buffer */ char *buf; /* Current output buffer */
int len; /* Length of output buffer */ int len; /* Length of output buffer */
}; };
struct line_finder { struct line_finder {
struct line_range *lr; /* Target line range */ struct line_range *lr; /* Target line range */
Dwarf_Unsigned fno; /* File number */ const char *fname; /* File name */
Dwarf_Unsigned lno_s; /* Start line number */ int lno_s; /* Start line number */
Dwarf_Unsigned lno_e; /* End line number */ int lno_e; /* End line number */
Dwarf_Addr addr_s; /* Start address */ Dwarf_Addr addr_s; /* Start address */
Dwarf_Addr addr_e; /* End address */ Dwarf_Addr addr_e; /* End address */
Dwarf_Die cu_die; /* Current CU */ Dwarf_Die cu_die; /* Current CU */
int found; int found;
}; };
#endif /* NO_LIBDWARF */ #endif /* NO_DWARF_SUPPORT */
#endif /*_PROBE_FINDER_H */ #endif /*_PROBE_FINDER_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment