mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-28 21:45:01 +08:00
270bde1e76
'perf probe' through debuginfo__find_probes() in util/probe-finder.c checks for the functions' frame descriptions in either .eh_frame section of an ELF or the .debug_frame. The check is based on whether either one of these sections is present. Depending on distro, toolchain defaults, architetcutre, build flags, etc., CFI might be found in either .eh_frame and/or .debug_frame. Sometimes, it may happen that, .eh_frame, even if present, may not be complete and may miss some descriptions. Therefore, to be sure, to find the CFI covering an address we will always have to investigate both if available. For e.g., in powerpc, this may happen: $ gcc -g bin.c -o bin $ objdump --dwarf ./bin <1><145>: Abbrev Number: 7 (DW_TAG_subprogram) <146> DW_AT_external : 1 <146> DW_AT_name : (indirect string, offset: 0x9e): main <14a> DW_AT_decl_file : 1 <14b> DW_AT_decl_line : 39 <14c> DW_AT_prototyped : 1 <14c> DW_AT_type : <0x57> <150> DW_AT_low_pc : 0x100007b8 If the .eh_frame and .debug_frame are checked for the same binary, we will find that, .eh_frame (although present) doesn't contain a description for "main" function. But, .debug_frame has a description: 000000d8 00000024 00000000 FDE cie=00000000 pc=100007b8..10000838 DW_CFA_advance_loc: 16 to 100007c8 DW_CFA_def_cfa_offset: 144 DW_CFA_offset_extended_sf: r65 at cfa+16 ... Due to this (since, perf checks whether .eh_frame is present and goes on searching for that address inside that frame), perf is unable to process the probes: # perf probe -x ./bin main Failed to get call frame on 0x100007b8 Error: Failed to add events. To avoid this issue, we need to check both the sections (.eh_frame and .debug_frame), which is done in this patch. Note that, we can always force everything into both .eh_frame and .debug_frame by: $ gcc bin.c -fasynchronous-unwind-tables -fno-dwarf2-cfi-asm -g -o bin Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: linuxppc-dev@lists.ozlabs.org Cc: Mark Wielaard <mjw@redhat.com> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Link: http://lkml.kernel.org/r/1454426806-13974-1-git-send-email-hemant@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
120 lines
3.2 KiB
C
120 lines
3.2 KiB
C
#ifndef _PROBE_FINDER_H
|
|
#define _PROBE_FINDER_H
|
|
|
|
#include <stdbool.h>
|
|
#include "util.h"
|
|
#include "intlist.h"
|
|
#include "probe-event.h"
|
|
|
|
#define MAX_PROBE_BUFFER 1024
|
|
#define MAX_PROBES 128
|
|
#define MAX_PROBE_ARGS 128
|
|
|
|
#define PROBE_ARG_VARS "$vars"
|
|
#define PROBE_ARG_PARAMS "$params"
|
|
|
|
static inline int is_c_varname(const char *name)
|
|
{
|
|
/* TODO */
|
|
return isalpha(name[0]) || name[0] == '_';
|
|
}
|
|
|
|
#ifdef HAVE_DWARF_SUPPORT
|
|
|
|
#include "dwarf-aux.h"
|
|
|
|
/* TODO: export debuginfo data structure even if no dwarf support */
|
|
|
|
/* debug information structure */
|
|
struct debuginfo {
|
|
Dwarf *dbg;
|
|
Dwfl_Module *mod;
|
|
Dwfl *dwfl;
|
|
Dwarf_Addr bias;
|
|
};
|
|
|
|
/* This also tries to open distro debuginfo */
|
|
extern struct debuginfo *debuginfo__new(const char *path);
|
|
extern void debuginfo__delete(struct debuginfo *dbg);
|
|
|
|
/* Find probe_trace_events specified by perf_probe_event from debuginfo */
|
|
extern int debuginfo__find_trace_events(struct debuginfo *dbg,
|
|
struct perf_probe_event *pev,
|
|
struct probe_trace_event **tevs);
|
|
|
|
/* Find a perf_probe_point from debuginfo */
|
|
extern int debuginfo__find_probe_point(struct debuginfo *dbg,
|
|
unsigned long addr,
|
|
struct perf_probe_point *ppt);
|
|
|
|
/* Find a line range */
|
|
extern int debuginfo__find_line_range(struct debuginfo *dbg,
|
|
struct line_range *lr);
|
|
|
|
/* Find available variables */
|
|
extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,
|
|
struct perf_probe_event *pev,
|
|
struct variable_list **vls);
|
|
|
|
/* Find a src file from a DWARF tag path */
|
|
int get_real_path(const char *raw_path, const char *comp_dir,
|
|
char **new_path);
|
|
|
|
struct probe_finder {
|
|
struct perf_probe_event *pev; /* Target probe event */
|
|
|
|
/* Callback when a probe point is found */
|
|
int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
|
|
|
|
/* For function searching */
|
|
int lno; /* Line number */
|
|
Dwarf_Addr addr; /* Address */
|
|
const char *fname; /* Real file name */
|
|
Dwarf_Die cu_die; /* Current CU */
|
|
Dwarf_Die sp_die;
|
|
struct intlist *lcache; /* Line cache for lazy match */
|
|
|
|
/* For variable searching */
|
|
#if _ELFUTILS_PREREQ(0, 142)
|
|
/* Call Frame Information from .eh_frame */
|
|
Dwarf_CFI *cfi_eh;
|
|
/* Call Frame Information from .debug_frame */
|
|
Dwarf_CFI *cfi_dbg;
|
|
#endif
|
|
Dwarf_Op *fb_ops; /* Frame base attribute */
|
|
struct perf_probe_arg *pvar; /* Current target variable */
|
|
struct probe_trace_arg *tvar; /* Current result variable */
|
|
};
|
|
|
|
struct trace_event_finder {
|
|
struct probe_finder pf;
|
|
Dwfl_Module *mod; /* For solving symbols */
|
|
struct probe_trace_event *tevs; /* Found trace events */
|
|
int ntevs; /* Number of trace events */
|
|
int max_tevs; /* Max number of trace events */
|
|
};
|
|
|
|
struct available_var_finder {
|
|
struct probe_finder pf;
|
|
Dwfl_Module *mod; /* For solving symbols */
|
|
struct variable_list *vls; /* Found variable lists */
|
|
int nvls; /* Number of variable lists */
|
|
int max_vls; /* Max no. of variable lists */
|
|
bool child; /* Search child scopes */
|
|
};
|
|
|
|
struct line_finder {
|
|
struct line_range *lr; /* Target line range */
|
|
|
|
const char *fname; /* File name */
|
|
int lno_s; /* Start line number */
|
|
int lno_e; /* End line number */
|
|
Dwarf_Die cu_die; /* Current CU */
|
|
Dwarf_Die sp_die;
|
|
int found;
|
|
};
|
|
|
|
#endif /* HAVE_DWARF_SUPPORT */
|
|
|
|
#endif /*_PROBE_FINDER_H */
|