diff options
| author | Ingo Molnar <mingo@elte.hu> | 2011-07-21 03:32:40 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2011-07-21 03:32:40 -0400 |
| commit | 40bcea7bbe8fe452a2d272e2ffd3dea281eec9ff (patch) | |
| tree | aedb6d02e53e3cf84cc32fd81db84032cee205e1 | |
| parent | 492f73a303b488ffd67097b2351d54aa6e6c7c73 (diff) | |
| parent | 14a8fd7ceea6915c613746203d6e9a2bf273f16c (diff) | |
Merge branch 'tip/perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace into perf/core
26 files changed, 1663 insertions, 1003 deletions
diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt index c83bd6b4e6e8..d0d0bb9e3e25 100644 --- a/Documentation/trace/kprobetrace.txt +++ b/Documentation/trace/kprobetrace.txt | |||
| @@ -22,14 +22,15 @@ current_tracer. Instead of that, add probe points via | |||
| 22 | 22 | ||
| 23 | Synopsis of kprobe_events | 23 | Synopsis of kprobe_events |
| 24 | ------------------------- | 24 | ------------------------- |
| 25 | p[:[GRP/]EVENT] SYMBOL[+offs]|MEMADDR [FETCHARGS] : Set a probe | 25 | p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe |
| 26 | r[:[GRP/]EVENT] SYMBOL[+0] [FETCHARGS] : Set a return probe | 26 | r[:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe |
| 27 | -:[GRP/]EVENT : Clear a probe | 27 | -:[GRP/]EVENT : Clear a probe |
| 28 | 28 | ||
| 29 | GRP : Group name. If omitted, use "kprobes" for it. | 29 | GRP : Group name. If omitted, use "kprobes" for it. |
| 30 | EVENT : Event name. If omitted, the event name is generated | 30 | EVENT : Event name. If omitted, the event name is generated |
| 31 | based on SYMBOL+offs or MEMADDR. | 31 | based on SYM+offs or MEMADDR. |
| 32 | SYMBOL[+offs] : Symbol+offset where the probe is inserted. | 32 | MOD : Module name which has given SYM. |
| 33 | SYM[+offs] : Symbol+offset where the probe is inserted. | ||
| 33 | MEMADDR : Address where the probe is inserted. | 34 | MEMADDR : Address where the probe is inserted. |
| 34 | 35 | ||
| 35 | FETCHARGS : Arguments. Each probe can have up to 128 args. | 36 | FETCHARGS : Arguments. Each probe can have up to 128 args. |
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h index 56fd9e3abbda..4d86c86178f2 100644 --- a/arch/x86/include/asm/perf_event_p4.h +++ b/arch/x86/include/asm/perf_event_p4.h | |||
| @@ -102,6 +102,14 @@ | |||
| 102 | #define P4_CONFIG_HT (1ULL << P4_CONFIG_HT_SHIFT) | 102 | #define P4_CONFIG_HT (1ULL << P4_CONFIG_HT_SHIFT) |
| 103 | 103 | ||
| 104 | /* | 104 | /* |
| 105 | * If an event has alias it should be marked | ||
| 106 | * with a special bit. (Don't forget to check | ||
| 107 | * P4_PEBS_CONFIG_MASK and related bits on | ||
| 108 | * modification.) | ||
| 109 | */ | ||
| 110 | #define P4_CONFIG_ALIASABLE (1 << 9) | ||
| 111 | |||
| 112 | /* | ||
| 105 | * The bits we allow to pass for RAW events | 113 | * The bits we allow to pass for RAW events |
| 106 | */ | 114 | */ |
| 107 | #define P4_CONFIG_MASK_ESCR \ | 115 | #define P4_CONFIG_MASK_ESCR \ |
| @@ -123,6 +131,31 @@ | |||
| 123 | (p4_config_pack_escr(P4_CONFIG_MASK_ESCR)) | \ | 131 | (p4_config_pack_escr(P4_CONFIG_MASK_ESCR)) | \ |
| 124 | (p4_config_pack_cccr(P4_CONFIG_MASK_CCCR)) | 132 | (p4_config_pack_cccr(P4_CONFIG_MASK_CCCR)) |
| 125 | 133 | ||
| 134 | /* | ||
| 135 | * In case of event aliasing we need to preserve some | ||
| 136 | * caller bits otherwise the mapping won't be complete. | ||
| 137 | */ | ||
| 138 | #define P4_CONFIG_EVENT_ALIAS_MASK \ | ||
| 139 | (p4_config_pack_escr(P4_CONFIG_MASK_ESCR) | \ | ||
| 140 | p4_config_pack_cccr(P4_CCCR_EDGE | \ | ||
| 141 | P4_CCCR_THRESHOLD_MASK | \ | ||
| 142 | P4_CCCR_COMPLEMENT | \ | ||
| 143 | P4_CCCR_COMPARE)) | ||
| 144 | |||
| 145 | #define P4_CONFIG_EVENT_ALIAS_IMMUTABLE_BITS \ | ||
| 146 | ((P4_CONFIG_HT) | \ | ||
| 147 | p4_config_pack_escr(P4_ESCR_T0_OS | \ | ||
| 148 | P4_ESCR_T0_USR | \ | ||
| 149 | P4_ESCR_T1_OS | \ | ||
| 150 | P4_ESCR_T1_USR) | \ | ||
| 151 | p4_config_pack_cccr(P4_CCCR_OVF | \ | ||
| 152 | P4_CCCR_CASCADE | \ | ||
| 153 | P4_CCCR_FORCE_OVF | \ | ||
| 154 | P4_CCCR_THREAD_ANY | \ | ||
| 155 | P4_CCCR_OVF_PMI_T0 | \ | ||
| 156 | P4_CCCR_OVF_PMI_T1 | \ | ||
| 157 | P4_CONFIG_ALIASABLE)) | ||
| 158 | |||
| 126 | static inline bool p4_is_event_cascaded(u64 config) | 159 | static inline bool p4_is_event_cascaded(u64 config) |
| 127 | { | 160 | { |
| 128 | u32 cccr = p4_config_unpack_cccr(config); | 161 | u32 cccr = p4_config_unpack_cccr(config); |
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index c53d433c3dde..b7a010fce8c3 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
| @@ -274,7 +274,6 @@ struct x86_pmu { | |||
| 274 | void (*enable_all)(int added); | 274 | void (*enable_all)(int added); |
| 275 | void (*enable)(struct perf_event *); | 275 | void (*enable)(struct perf_event *); |
| 276 | void (*disable)(struct perf_event *); | 276 | void (*disable)(struct perf_event *); |
| 277 | void (*hw_watchdog_set_attr)(struct perf_event_attr *attr); | ||
| 278 | int (*hw_config)(struct perf_event *event); | 277 | int (*hw_config)(struct perf_event *event); |
| 279 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); | 278 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); |
| 280 | unsigned eventsel; | 279 | unsigned eventsel; |
| @@ -360,12 +359,6 @@ static u64 __read_mostly hw_cache_extra_regs | |||
| 360 | [PERF_COUNT_HW_CACHE_OP_MAX] | 359 | [PERF_COUNT_HW_CACHE_OP_MAX] |
| 361 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | 360 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; |
| 362 | 361 | ||
| 363 | void hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr) | ||
| 364 | { | ||
| 365 | if (x86_pmu.hw_watchdog_set_attr) | ||
| 366 | x86_pmu.hw_watchdog_set_attr(wd_attr); | ||
| 367 | } | ||
| 368 | |||
| 369 | /* | 362 | /* |
| 370 | * Propagate event elapsed time into the generic event. | 363 | * Propagate event elapsed time into the generic event. |
| 371 | * Can only be executed on the CPU where the event is active. | 364 | * Can only be executed on the CPU where the event is active. |
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c index fb901c5080f7..8b7a0c306784 100644 --- a/arch/x86/kernel/cpu/perf_event_p4.c +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
| @@ -570,11 +570,92 @@ static __initconst const u64 p4_hw_cache_event_ids | |||
| 570 | }, | 570 | }, |
| 571 | }; | 571 | }; |
| 572 | 572 | ||
| 573 | /* | ||
| 574 | * Because of Netburst being quite restricted in now | ||
| 575 | * many same events can run simultaneously, we use | ||
| 576 | * event aliases, ie different events which have the | ||
| 577 | * same functionallity but use non-intersected resources | ||
| 578 | * (ESCR/CCCR/couter registers). This allow us to run | ||
| 579 | * two or more semi-same events together. It is done | ||
| 580 | * transparently to a user space. | ||
| 581 | * | ||
| 582 | * Never set any cusom internal bits such as P4_CONFIG_HT, | ||
| 583 | * P4_CONFIG_ALIASABLE or bits for P4_PEBS_METRIC, they are | ||
| 584 | * either up-to-dated automatically either not appliable | ||
| 585 | * at all. | ||
| 586 | * | ||
| 587 | * And be really carefull choosing aliases! | ||
| 588 | */ | ||
| 589 | struct p4_event_alias { | ||
| 590 | u64 orig; | ||
| 591 | u64 alter; | ||
| 592 | } p4_event_aliases[] = { | ||
| 593 | { | ||
| 594 | /* | ||
| 595 | * Non-halted cycles can be substituted with | ||
| 596 | * non-sleeping cycles (see Intel SDM Vol3b for | ||
| 597 | * details). | ||
| 598 | */ | ||
| 599 | .orig = | ||
| 600 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) | | ||
| 601 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)), | ||
| 602 | .alter = | ||
| 603 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT) | | ||
| 604 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0)| | ||
| 605 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1)| | ||
| 606 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2)| | ||
| 607 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3)| | ||
| 608 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) | | ||
| 609 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) | | ||
| 610 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) | | ||
| 611 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3))| | ||
| 612 | p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT | | ||
| 613 | P4_CCCR_COMPARE), | ||
| 614 | }, | ||
| 615 | }; | ||
| 616 | |||
| 617 | static u64 p4_get_alias_event(u64 config) | ||
| 618 | { | ||
| 619 | u64 config_match; | ||
| 620 | int i; | ||
| 621 | |||
| 622 | /* | ||
| 623 | * Probably we're lucky and don't have to do | ||
| 624 | * matching over all config bits. | ||
| 625 | */ | ||
| 626 | if (!(config & P4_CONFIG_ALIASABLE)) | ||
| 627 | return 0; | ||
| 628 | |||
| 629 | config_match = config & P4_CONFIG_EVENT_ALIAS_MASK; | ||
| 630 | |||
| 631 | /* | ||
| 632 | * If an event was previously swapped to the alter config | ||
| 633 | * we should swap it back otherwise contnention on registers | ||
| 634 | * will return back. | ||
| 635 | */ | ||
| 636 | for (i = 0; i < ARRAY_SIZE(p4_event_aliases); i++) { | ||
| 637 | if (config_match == p4_event_aliases[i].orig) { | ||
| 638 | config_match = p4_event_aliases[i].alter; | ||
| 639 | break; | ||
| 640 | } else if (config_match == p4_event_aliases[i].alter) { | ||
| 641 | config_match = p4_event_aliases[i].orig; | ||
| 642 | break; | ||
| 643 | } | ||
| 644 | } | ||
| 645 | |||
| 646 | if (i >= ARRAY_SIZE(p4_event_aliases)) | ||
| 647 | return 0; | ||
| 648 | |||
| 649 | return config_match | | ||
| 650 | (config & P4_CONFIG_EVENT_ALIAS_IMMUTABLE_BITS); | ||
| 651 | } | ||
| 652 | |||
| 573 | static u64 p4_general_events[PERF_COUNT_HW_MAX] = { | 653 | static u64 p4_general_events[PERF_COUNT_HW_MAX] = { |
| 574 | /* non-halted CPU clocks */ | 654 | /* non-halted CPU clocks */ |
| 575 | [PERF_COUNT_HW_CPU_CYCLES] = | 655 | [PERF_COUNT_HW_CPU_CYCLES] = |
| 576 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) | | 656 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) | |
| 577 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)), | 657 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)) | |
| 658 | P4_CONFIG_ALIASABLE, | ||
| 578 | 659 | ||
| 579 | /* | 660 | /* |
| 580 | * retired instructions | 661 | * retired instructions |
| @@ -719,31 +800,6 @@ static int p4_validate_raw_event(struct perf_event *event) | |||
| 719 | return 0; | 800 | return 0; |
| 720 | } | 801 | } |
| 721 | 802 | ||
| 722 | static void p4_hw_watchdog_set_attr(struct perf_event_attr *wd_attr) | ||
| 723 | { | ||
| 724 | /* | ||
| 725 | * Watchdog ticks are special on Netburst, we use | ||
| 726 | * that named "non-sleeping" ticks as recommended | ||
| 727 | * by Intel SDM Vol3b. | ||
| 728 | */ | ||
| 729 | WARN_ON_ONCE(wd_attr->type != PERF_TYPE_HARDWARE || | ||
| 730 | wd_attr->config != PERF_COUNT_HW_CPU_CYCLES); | ||
| 731 | |||
| 732 | wd_attr->type = PERF_TYPE_RAW; | ||
| 733 | wd_attr->config = | ||
| 734 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT) | | ||
| 735 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0) | | ||
| 736 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1) | | ||
| 737 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2) | | ||
| 738 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3) | | ||
| 739 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) | | ||
| 740 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) | | ||
| 741 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) | | ||
| 742 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3)) | | ||
| 743 | p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT | | ||
| 744 | P4_CCCR_COMPARE); | ||
| 745 | } | ||
| 746 | |||
| 747 | static int p4_hw_config(struct perf_event *event) | 803 | static int p4_hw_config(struct perf_event *event) |
| 748 | { | 804 | { |
| 749 | int cpu = get_cpu(); | 805 | int cpu = get_cpu(); |
| @@ -1159,6 +1215,8 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign | |||
| 1159 | struct p4_event_bind *bind; | 1215 | struct p4_event_bind *bind; |
| 1160 | unsigned int i, thread, num; | 1216 | unsigned int i, thread, num; |
| 1161 | int cntr_idx, escr_idx; | 1217 | int cntr_idx, escr_idx; |
| 1218 | u64 config_alias; | ||
| 1219 | int pass; | ||
| 1162 | 1220 | ||
| 1163 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); | 1221 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); |
| 1164 | bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE); | 1222 | bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE); |
| @@ -1167,6 +1225,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign | |||
| 1167 | 1225 | ||
| 1168 | hwc = &cpuc->event_list[i]->hw; | 1226 | hwc = &cpuc->event_list[i]->hw; |
| 1169 | thread = p4_ht_thread(cpu); | 1227 | thread = p4_ht_thread(cpu); |
| 1228 | pass = 0; | ||
| 1229 | |||
| 1230 | again: | ||
| 1231 | /* | ||
| 1232 | * Aliases are swappable so we may hit circular | ||
| 1233 | * lock if both original config and alias need | ||
| 1234 | * resources (MSR registers) which already busy. | ||
| 1235 | */ | ||
| 1236 | if (pass > 2) | ||
| 1237 | goto done; | ||
| 1238 | |||
| 1170 | bind = p4_config_get_bind(hwc->config); | 1239 | bind = p4_config_get_bind(hwc->config); |
| 1171 | escr_idx = p4_get_escr_idx(bind->escr_msr[thread]); | 1240 | escr_idx = p4_get_escr_idx(bind->escr_msr[thread]); |
| 1172 | if (unlikely(escr_idx == -1)) | 1241 | if (unlikely(escr_idx == -1)) |
| @@ -1180,8 +1249,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign | |||
| 1180 | } | 1249 | } |
| 1181 | 1250 | ||
| 1182 | cntr_idx = p4_next_cntr(thread, used_mask, bind); | 1251 | cntr_idx = p4_next_cntr(thread, used_mask, bind); |
| 1183 | if (cntr_idx == -1 || test_bit(escr_idx, escr_mask)) | 1252 | if (cntr_idx == -1 || test_bit(escr_idx, escr_mask)) { |
| 1184 | goto done; | 1253 | /* |
| 1254 | * Probably an event alias is still available. | ||
| 1255 | */ | ||
| 1256 | config_alias = p4_get_alias_event(hwc->config); | ||
| 1257 | if (!config_alias) | ||
| 1258 | goto done; | ||
| 1259 | hwc->config = config_alias; | ||
| 1260 | pass++; | ||
| 1261 | goto again; | ||
| 1262 | } | ||
| 1185 | 1263 | ||
| 1186 | p4_pmu_swap_config_ts(hwc, cpu); | 1264 | p4_pmu_swap_config_ts(hwc, cpu); |
| 1187 | if (assign) | 1265 | if (assign) |
| @@ -1218,7 +1296,6 @@ static __initconst const struct x86_pmu p4_pmu = { | |||
| 1218 | .cntval_bits = ARCH_P4_CNTRVAL_BITS, | 1296 | .cntval_bits = ARCH_P4_CNTRVAL_BITS, |
| 1219 | .cntval_mask = ARCH_P4_CNTRVAL_MASK, | 1297 | .cntval_mask = ARCH_P4_CNTRVAL_MASK, |
| 1220 | .max_period = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1, | 1298 | .max_period = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1, |
| 1221 | .hw_watchdog_set_attr = p4_hw_watchdog_set_attr, | ||
| 1222 | .hw_config = p4_hw_config, | 1299 | .hw_config = p4_hw_config, |
| 1223 | .schedule_events = p4_pmu_schedule_events, | 1300 | .schedule_events = p4_pmu_schedule_events, |
| 1224 | /* | 1301 | /* |
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index b1e69eefc203..96efa6794ea5 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h | |||
| @@ -76,6 +76,7 @@ struct trace_iterator { | |||
| 76 | struct trace_entry *ent; | 76 | struct trace_entry *ent; |
| 77 | unsigned long lost_events; | 77 | unsigned long lost_events; |
| 78 | int leftover; | 78 | int leftover; |
| 79 | int ent_size; | ||
| 79 | int cpu; | 80 | int cpu; |
| 80 | u64 ts; | 81 | u64 ts; |
| 81 | 82 | ||
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 77981813a1e7..b30fd54eb985 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
| @@ -1255,19 +1255,29 @@ static int __kprobes in_kprobes_functions(unsigned long addr) | |||
| 1255 | /* | 1255 | /* |
| 1256 | * If we have a symbol_name argument, look it up and add the offset field | 1256 | * If we have a symbol_name argument, look it up and add the offset field |
| 1257 | * to it. This way, we can specify a relative address to a symbol. | 1257 | * to it. This way, we can specify a relative address to a symbol. |
| 1258 | * This returns encoded errors if it fails to look up symbol or invalid | ||
| 1259 | * combination of parameters. | ||
| 1258 | */ | 1260 | */ |
| 1259 | static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p) | 1261 | static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p) |
| 1260 | { | 1262 | { |
| 1261 | kprobe_opcode_t *addr = p->addr; | 1263 | kprobe_opcode_t *addr = p->addr; |
| 1264 | |||
| 1265 | if ((p->symbol_name && p->addr) || | ||
| 1266 | (!p->symbol_name && !p->addr)) | ||
| 1267 | goto invalid; | ||
| 1268 | |||
| 1262 | if (p->symbol_name) { | 1269 | if (p->symbol_name) { |
| 1263 | if (addr) | ||
| 1264 | return NULL; | ||
| 1265 | kprobe_lookup_name(p->symbol_name, addr); | 1270 | kprobe_lookup_name(p->symbol_name, addr); |
| 1271 | if (!addr) | ||
| 1272 | return ERR_PTR(-ENOENT); | ||
| 1266 | } | 1273 | } |
| 1267 | 1274 | ||
| 1268 | if (!addr) | 1275 | addr = (kprobe_opcode_t *)(((char *)addr) + p->offset); |
| 1269 | return NULL; | 1276 | if (addr) |
| 1270 | return (kprobe_opcode_t *)(((char *)addr) + p->offset); | 1277 | return addr; |
| 1278 | |||
| 1279 | invalid: | ||
| 1280 | return ERR_PTR(-EINVAL); | ||
| 1271 | } | 1281 | } |
| 1272 | 1282 | ||
| 1273 | /* Check passed kprobe is valid and return kprobe in kprobe_table. */ | 1283 | /* Check passed kprobe is valid and return kprobe in kprobe_table. */ |
| @@ -1311,8 +1321,8 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
| 1311 | kprobe_opcode_t *addr; | 1321 | kprobe_opcode_t *addr; |
| 1312 | 1322 | ||
| 1313 | addr = kprobe_addr(p); | 1323 | addr = kprobe_addr(p); |
| 1314 | if (!addr) | 1324 | if (IS_ERR(addr)) |
| 1315 | return -EINVAL; | 1325 | return PTR_ERR(addr); |
| 1316 | p->addr = addr; | 1326 | p->addr = addr; |
| 1317 | 1327 | ||
| 1318 | ret = check_kprobe_rereg(p); | 1328 | ret = check_kprobe_rereg(p); |
| @@ -1335,6 +1345,8 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
| 1335 | */ | 1345 | */ |
| 1336 | probed_mod = __module_text_address((unsigned long) p->addr); | 1346 | probed_mod = __module_text_address((unsigned long) p->addr); |
| 1337 | if (probed_mod) { | 1347 | if (probed_mod) { |
| 1348 | /* Return -ENOENT if fail. */ | ||
| 1349 | ret = -ENOENT; | ||
| 1338 | /* | 1350 | /* |
| 1339 | * We must hold a refcount of the probed module while updating | 1351 | * We must hold a refcount of the probed module while updating |
| 1340 | * its code to prohibit unexpected unloading. | 1352 | * its code to prohibit unexpected unloading. |
| @@ -1351,6 +1363,7 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
| 1351 | module_put(probed_mod); | 1363 | module_put(probed_mod); |
| 1352 | goto fail_with_jump_label; | 1364 | goto fail_with_jump_label; |
| 1353 | } | 1365 | } |
| 1366 | /* ret will be updated by following code */ | ||
| 1354 | } | 1367 | } |
| 1355 | preempt_enable(); | 1368 | preempt_enable(); |
| 1356 | jump_label_unlock(); | 1369 | jump_label_unlock(); |
| @@ -1399,7 +1412,7 @@ out: | |||
| 1399 | fail_with_jump_label: | 1412 | fail_with_jump_label: |
| 1400 | preempt_enable(); | 1413 | preempt_enable(); |
| 1401 | jump_label_unlock(); | 1414 | jump_label_unlock(); |
| 1402 | return -EINVAL; | 1415 | return ret; |
| 1403 | } | 1416 | } |
| 1404 | EXPORT_SYMBOL_GPL(register_kprobe); | 1417 | EXPORT_SYMBOL_GPL(register_kprobe); |
| 1405 | 1418 | ||
| @@ -1686,8 +1699,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp) | |||
| 1686 | 1699 | ||
| 1687 | if (kretprobe_blacklist_size) { | 1700 | if (kretprobe_blacklist_size) { |
| 1688 | addr = kprobe_addr(&rp->kp); | 1701 | addr = kprobe_addr(&rp->kp); |
| 1689 | if (!addr) | 1702 | if (IS_ERR(addr)) |
| 1690 | return -EINVAL; | 1703 | return PTR_ERR(addr); |
| 1691 | 1704 | ||
| 1692 | for (i = 0; kretprobe_blacklist[i].name != NULL; i++) { | 1705 | for (i = 0; kretprobe_blacklist[i].name != NULL; i++) { |
| 1693 | if (kretprobe_blacklist[i].addr == addr) | 1706 | if (kretprobe_blacklist[i].addr == addr) |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index a0e246e2cee3..c3e4575e7829 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
| @@ -88,6 +88,7 @@ static struct ftrace_ops ftrace_list_end __read_mostly = { | |||
| 88 | static struct ftrace_ops *ftrace_global_list __read_mostly = &ftrace_list_end; | 88 | static struct ftrace_ops *ftrace_global_list __read_mostly = &ftrace_list_end; |
| 89 | static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end; | 89 | static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end; |
| 90 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; | 90 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; |
| 91 | static ftrace_func_t __ftrace_trace_function_delay __read_mostly = ftrace_stub; | ||
| 91 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; | 92 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; |
| 92 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; | 93 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; |
| 93 | static struct ftrace_ops global_ops; | 94 | static struct ftrace_ops global_ops; |
| @@ -146,9 +147,11 @@ void clear_ftrace_function(void) | |||
| 146 | { | 147 | { |
| 147 | ftrace_trace_function = ftrace_stub; | 148 | ftrace_trace_function = ftrace_stub; |
| 148 | __ftrace_trace_function = ftrace_stub; | 149 | __ftrace_trace_function = ftrace_stub; |
| 150 | __ftrace_trace_function_delay = ftrace_stub; | ||
| 149 | ftrace_pid_function = ftrace_stub; | 151 | ftrace_pid_function = ftrace_stub; |
| 150 | } | 152 | } |
| 151 | 153 | ||
| 154 | #undef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
| 152 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | 155 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 153 | /* | 156 | /* |
| 154 | * For those archs that do not test ftrace_trace_stop in their | 157 | * For those archs that do not test ftrace_trace_stop in their |
| @@ -208,7 +211,12 @@ static void update_ftrace_function(void) | |||
| 208 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | 211 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 209 | ftrace_trace_function = func; | 212 | ftrace_trace_function = func; |
| 210 | #else | 213 | #else |
| 214 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
| 215 | /* do not update till all functions have been modified */ | ||
| 216 | __ftrace_trace_function_delay = func; | ||
| 217 | #else | ||
| 211 | __ftrace_trace_function = func; | 218 | __ftrace_trace_function = func; |
| 219 | #endif | ||
| 212 | ftrace_trace_function = ftrace_test_stop_func; | 220 | ftrace_trace_function = ftrace_test_stop_func; |
| 213 | #endif | 221 | #endif |
| 214 | } | 222 | } |
| @@ -1170,8 +1178,14 @@ alloc_and_copy_ftrace_hash(int size_bits, struct ftrace_hash *hash) | |||
| 1170 | return NULL; | 1178 | return NULL; |
| 1171 | } | 1179 | } |
| 1172 | 1180 | ||
| 1181 | static void | ||
| 1182 | ftrace_hash_rec_disable(struct ftrace_ops *ops, int filter_hash); | ||
| 1183 | static void | ||
| 1184 | ftrace_hash_rec_enable(struct ftrace_ops *ops, int filter_hash); | ||
| 1185 | |||
| 1173 | static int | 1186 | static int |
| 1174 | ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) | 1187 | ftrace_hash_move(struct ftrace_ops *ops, int enable, |
| 1188 | struct ftrace_hash **dst, struct ftrace_hash *src) | ||
| 1175 | { | 1189 | { |
| 1176 | struct ftrace_func_entry *entry; | 1190 | struct ftrace_func_entry *entry; |
| 1177 | struct hlist_node *tp, *tn; | 1191 | struct hlist_node *tp, *tn; |
| @@ -1181,9 +1195,16 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) | |||
| 1181 | unsigned long key; | 1195 | unsigned long key; |
| 1182 | int size = src->count; | 1196 | int size = src->count; |
| 1183 | int bits = 0; | 1197 | int bits = 0; |
| 1198 | int ret; | ||
| 1184 | int i; | 1199 | int i; |
| 1185 | 1200 | ||
| 1186 | /* | 1201 | /* |
| 1202 | * Remove the current set, update the hash and add | ||
| 1203 | * them back. | ||
| 1204 | */ | ||
| 1205 | ftrace_hash_rec_disable(ops, enable); | ||
| 1206 | |||
| 1207 | /* | ||
| 1187 | * If the new source is empty, just free dst and assign it | 1208 | * If the new source is empty, just free dst and assign it |
| 1188 | * the empty_hash. | 1209 | * the empty_hash. |
| 1189 | */ | 1210 | */ |
| @@ -1203,9 +1224,10 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) | |||
| 1203 | if (bits > FTRACE_HASH_MAX_BITS) | 1224 | if (bits > FTRACE_HASH_MAX_BITS) |
| 1204 | bits = FTRACE_HASH_MAX_BITS; | 1225 | bits = FTRACE_HASH_MAX_BITS; |
| 1205 | 1226 | ||
| 1227 | ret = -ENOMEM; | ||
| 1206 | new_hash = alloc_ftrace_hash(bits); | 1228 | new_hash = alloc_ftrace_hash(bits); |
| 1207 | if (!new_hash) | 1229 | if (!new_hash) |
| 1208 | return -ENOMEM; | 1230 | goto out; |
| 1209 | 1231 | ||
| 1210 | size = 1 << src->size_bits; | 1232 | size = 1 << src->size_bits; |
| 1211 | for (i = 0; i < size; i++) { | 1233 | for (i = 0; i < size; i++) { |
| @@ -1224,7 +1246,16 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) | |||
| 1224 | rcu_assign_pointer(*dst, new_hash); | 1246 | rcu_assign_pointer(*dst, new_hash); |
| 1225 | free_ftrace_hash_rcu(old_hash); | 1247 | free_ftrace_hash_rcu(old_hash); |
| 1226 | 1248 | ||
| 1227 | return 0; | 1249 | ret = 0; |
| 1250 | out: | ||
| 1251 | /* | ||
| 1252 | * Enable regardless of ret: | ||
| 1253 | * On success, we enable the new hash. | ||
| 1254 | * On failure, we re-enable the original hash. | ||
| 1255 | */ | ||
| 1256 | ftrace_hash_rec_enable(ops, enable); | ||
| 1257 | |||
| 1258 | return ret; | ||
| 1228 | } | 1259 | } |
| 1229 | 1260 | ||
| 1230 | /* | 1261 | /* |
| @@ -1584,6 +1615,12 @@ static int __ftrace_modify_code(void *data) | |||
| 1584 | { | 1615 | { |
| 1585 | int *command = data; | 1616 | int *command = data; |
| 1586 | 1617 | ||
| 1618 | /* | ||
| 1619 | * Do not call function tracer while we update the code. | ||
| 1620 | * We are in stop machine, no worrying about races. | ||
| 1621 | */ | ||
| 1622 | function_trace_stop++; | ||
| 1623 | |||
| 1587 | if (*command & FTRACE_ENABLE_CALLS) | 1624 | if (*command & FTRACE_ENABLE_CALLS) |
| 1588 | ftrace_replace_code(1); | 1625 | ftrace_replace_code(1); |
| 1589 | else if (*command & FTRACE_DISABLE_CALLS) | 1626 | else if (*command & FTRACE_DISABLE_CALLS) |
| @@ -1597,6 +1634,18 @@ static int __ftrace_modify_code(void *data) | |||
| 1597 | else if (*command & FTRACE_STOP_FUNC_RET) | 1634 | else if (*command & FTRACE_STOP_FUNC_RET) |
| 1598 | ftrace_disable_ftrace_graph_caller(); | 1635 | ftrace_disable_ftrace_graph_caller(); |
| 1599 | 1636 | ||
| 1637 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
| 1638 | /* | ||
| 1639 | * For archs that call ftrace_test_stop_func(), we must | ||
| 1640 | * wait till after we update all the function callers | ||
| 1641 | * before we update the callback. This keeps different | ||
| 1642 | * ops that record different functions from corrupting | ||
| 1643 | * each other. | ||
| 1644 | */ | ||
| 1645 | __ftrace_trace_function = __ftrace_trace_function_delay; | ||
| 1646 | #endif | ||
| 1647 | function_trace_stop--; | ||
| 1648 | |||
| 1600 | return 0; | 1649 | return 0; |
| 1601 | } | 1650 | } |
| 1602 | 1651 | ||
| @@ -2865,7 +2914,11 @@ ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len, | |||
| 2865 | ftrace_match_records(hash, buf, len); | 2914 | ftrace_match_records(hash, buf, len); |
| 2866 | 2915 | ||
| 2867 | mutex_lock(&ftrace_lock); | 2916 | mutex_lock(&ftrace_lock); |
| 2868 | ret = ftrace_hash_move(orig_hash, hash); | 2917 | ret = ftrace_hash_move(ops, enable, orig_hash, hash); |
| 2918 | if (!ret && ops->flags & FTRACE_OPS_FL_ENABLED | ||
| 2919 | && ftrace_enabled) | ||
| 2920 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); | ||
| 2921 | |||
| 2869 | mutex_unlock(&ftrace_lock); | 2922 | mutex_unlock(&ftrace_lock); |
| 2870 | 2923 | ||
| 2871 | mutex_unlock(&ftrace_regex_lock); | 2924 | mutex_unlock(&ftrace_regex_lock); |
| @@ -3048,18 +3101,12 @@ ftrace_regex_release(struct inode *inode, struct file *file) | |||
| 3048 | orig_hash = &iter->ops->notrace_hash; | 3101 | orig_hash = &iter->ops->notrace_hash; |
| 3049 | 3102 | ||
| 3050 | mutex_lock(&ftrace_lock); | 3103 | mutex_lock(&ftrace_lock); |
| 3051 | /* | 3104 | ret = ftrace_hash_move(iter->ops, filter_hash, |
| 3052 | * Remove the current set, update the hash and add | 3105 | orig_hash, iter->hash); |
| 3053 | * them back. | 3106 | if (!ret && (iter->ops->flags & FTRACE_OPS_FL_ENABLED) |
| 3054 | */ | 3107 | && ftrace_enabled) |
| 3055 | ftrace_hash_rec_disable(iter->ops, filter_hash); | 3108 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
| 3056 | ret = ftrace_hash_move(orig_hash, iter->hash); | 3109 | |
| 3057 | if (!ret) { | ||
| 3058 | ftrace_hash_rec_enable(iter->ops, filter_hash); | ||
| 3059 | if (iter->ops->flags & FTRACE_OPS_FL_ENABLED | ||
| 3060 | && ftrace_enabled) | ||
| 3061 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); | ||
| 3062 | } | ||
| 3063 | mutex_unlock(&ftrace_lock); | 3110 | mutex_unlock(&ftrace_lock); |
| 3064 | } | 3111 | } |
| 3065 | free_ftrace_hash(iter->hash); | 3112 | free_ftrace_hash(iter->hash); |
| @@ -3338,7 +3385,7 @@ static int ftrace_process_locs(struct module *mod, | |||
| 3338 | { | 3385 | { |
| 3339 | unsigned long *p; | 3386 | unsigned long *p; |
| 3340 | unsigned long addr; | 3387 | unsigned long addr; |
| 3341 | unsigned long flags; | 3388 | unsigned long flags = 0; /* Shut up gcc */ |
| 3342 | 3389 | ||
| 3343 | mutex_lock(&ftrace_lock); | 3390 | mutex_lock(&ftrace_lock); |
| 3344 | p = start; | 3391 | p = start; |
| @@ -3356,12 +3403,18 @@ static int ftrace_process_locs(struct module *mod, | |||
| 3356 | } | 3403 | } |
| 3357 | 3404 | ||
| 3358 | /* | 3405 | /* |
| 3359 | * Disable interrupts to prevent interrupts from executing | 3406 | * We only need to disable interrupts on start up |
| 3360 | * code that is being modified. | 3407 | * because we are modifying code that an interrupt |
| 3408 | * may execute, and the modification is not atomic. | ||
| 3409 | * But for modules, nothing runs the code we modify | ||
| 3410 | * until we are finished with it, and there's no | ||
| 3411 | * reason to cause large interrupt latencies while we do it. | ||
| 3361 | */ | 3412 | */ |
| 3362 | local_irq_save(flags); | 3413 | if (!mod) |
| 3414 | local_irq_save(flags); | ||
| 3363 | ftrace_update_code(mod); | 3415 | ftrace_update_code(mod); |
| 3364 | local_irq_restore(flags); | 3416 | if (!mod) |
| 3417 | local_irq_restore(flags); | ||
| 3365 | mutex_unlock(&ftrace_lock); | 3418 | mutex_unlock(&ftrace_lock); |
| 3366 | 3419 | ||
| 3367 | return 0; | 3420 | return 0; |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index d9c16123f6e2..e5df02c69b1d 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -1248,6 +1248,15 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data, | |||
| 1248 | } | 1248 | } |
| 1249 | 1249 | ||
| 1250 | #ifdef CONFIG_STACKTRACE | 1250 | #ifdef CONFIG_STACKTRACE |
| 1251 | |||
| 1252 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) | ||
| 1253 | struct ftrace_stack { | ||
| 1254 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; | ||
| 1255 | }; | ||
| 1256 | |||
| 1257 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); | ||
| 1258 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); | ||
| 1259 | |||
| 1251 | static void __ftrace_trace_stack(struct ring_buffer *buffer, | 1260 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
| 1252 | unsigned long flags, | 1261 | unsigned long flags, |
| 1253 | int skip, int pc, struct pt_regs *regs) | 1262 | int skip, int pc, struct pt_regs *regs) |
| @@ -1256,25 +1265,77 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer, | |||
| 1256 | struct ring_buffer_event *event; | 1265 | struct ring_buffer_event *event; |
| 1257 | struct stack_entry *entry; | 1266 | struct stack_entry *entry; |
| 1258 | struct stack_trace trace; | 1267 | struct stack_trace trace; |
| 1268 | int use_stack; | ||
| 1269 | int size = FTRACE_STACK_ENTRIES; | ||
| 1270 | |||
| 1271 | trace.nr_entries = 0; | ||
| 1272 | trace.skip = skip; | ||
| 1273 | |||
| 1274 | /* | ||
| 1275 | * Since events can happen in NMIs there's no safe way to | ||
| 1276 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt | ||
| 1277 | * or NMI comes in, it will just have to use the default | ||
| 1278 | * FTRACE_STACK_SIZE. | ||
| 1279 | */ | ||
| 1280 | preempt_disable_notrace(); | ||
| 1281 | |||
| 1282 | use_stack = ++__get_cpu_var(ftrace_stack_reserve); | ||
| 1283 | /* | ||
| 1284 | * We don't need any atomic variables, just a barrier. | ||
| 1285 | * If an interrupt comes in, we don't care, because it would | ||
| 1286 | * have exited and put the counter back to what we want. | ||
| 1287 | * We just need a barrier to keep gcc from moving things | ||
| 1288 | * around. | ||
| 1289 | */ | ||
| 1290 | barrier(); | ||
| 1291 | if (use_stack == 1) { | ||
| 1292 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; | ||
| 1293 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; | ||
| 1294 | |||
| 1295 | if (regs) | ||
| 1296 | save_stack_trace_regs(regs, &trace); | ||
| 1297 | else | ||
| 1298 | save_stack_trace(&trace); | ||
| 1299 | |||
| 1300 | if (trace.nr_entries > size) | ||
| 1301 | size = trace.nr_entries; | ||
| 1302 | } else | ||
| 1303 | /* From now on, use_stack is a boolean */ | ||
| 1304 | use_stack = 0; | ||
| 1305 | |||
| 1306 | size *= sizeof(unsigned long); | ||
| 1259 | 1307 | ||
| 1260 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, | 1308 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1261 | sizeof(*entry), flags, pc); | 1309 | sizeof(*entry) + size, flags, pc); |
| 1262 | if (!event) | 1310 | if (!event) |
| 1263 | return; | 1311 | goto out; |
| 1264 | entry = ring_buffer_event_data(event); | 1312 | entry = ring_buffer_event_data(event); |
| 1265 | memset(&entry->caller, 0, sizeof(entry->caller)); | ||
| 1266 | 1313 | ||
| 1267 | trace.nr_entries = 0; | 1314 | memset(&entry->caller, 0, size); |
| 1268 | trace.max_entries = FTRACE_STACK_ENTRIES; | 1315 | |
| 1269 | trace.skip = skip; | 1316 | if (use_stack) |
| 1270 | trace.entries = entry->caller; | 1317 | memcpy(&entry->caller, trace.entries, |
| 1318 | trace.nr_entries * sizeof(unsigned long)); | ||
| 1319 | else { | ||
| 1320 | trace.max_entries = FTRACE_STACK_ENTRIES; | ||
| 1321 | trace.entries = entry->caller; | ||
| 1322 | if (regs) | ||
| 1323 | save_stack_trace_regs(regs, &trace); | ||
| 1324 | else | ||
| 1325 | save_stack_trace(&trace); | ||
| 1326 | } | ||
| 1327 | |||
| 1328 | entry->size = trace.nr_entries; | ||
| 1271 | 1329 | ||
| 1272 | if (regs) | ||
| 1273 | save_stack_trace_regs(regs, &trace); | ||
| 1274 | else | ||
| 1275 | save_stack_trace(&trace); | ||
| 1276 | if (!filter_check_discard(call, entry, buffer, event)) | 1330 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1277 | ring_buffer_unlock_commit(buffer, event); | 1331 | ring_buffer_unlock_commit(buffer, event); |
| 1332 | |||
| 1333 | out: | ||
| 1334 | /* Again, don't let gcc optimize things here */ | ||
| 1335 | barrier(); | ||
| 1336 | __get_cpu_var(ftrace_stack_reserve)--; | ||
| 1337 | preempt_enable_notrace(); | ||
| 1338 | |||
| 1278 | } | 1339 | } |
| 1279 | 1340 | ||
| 1280 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, | 1341 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| @@ -1562,7 +1623,12 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, | |||
| 1562 | 1623 | ||
| 1563 | ftrace_enable_cpu(); | 1624 | ftrace_enable_cpu(); |
| 1564 | 1625 | ||
| 1565 | return event ? ring_buffer_event_data(event) : NULL; | 1626 | if (event) { |
| 1627 | iter->ent_size = ring_buffer_event_length(event); | ||
| 1628 | return ring_buffer_event_data(event); | ||
| 1629 | } | ||
| 1630 | iter->ent_size = 0; | ||
| 1631 | return NULL; | ||
| 1566 | } | 1632 | } |
| 1567 | 1633 | ||
| 1568 | static struct trace_entry * | 1634 | static struct trace_entry * |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 30a94c26dcb3..3f381d0b20a8 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -278,6 +278,29 @@ struct tracer { | |||
| 278 | }; | 278 | }; |
| 279 | 279 | ||
| 280 | 280 | ||
| 281 | /* Only current can touch trace_recursion */ | ||
| 282 | #define trace_recursion_inc() do { (current)->trace_recursion++; } while (0) | ||
| 283 | #define trace_recursion_dec() do { (current)->trace_recursion--; } while (0) | ||
| 284 | |||
| 285 | /* Ring buffer has the 10 LSB bits to count */ | ||
| 286 | #define trace_recursion_buffer() ((current)->trace_recursion & 0x3ff) | ||
| 287 | |||
| 288 | /* for function tracing recursion */ | ||
| 289 | #define TRACE_INTERNAL_BIT (1<<11) | ||
| 290 | #define TRACE_GLOBAL_BIT (1<<12) | ||
| 291 | /* | ||
| 292 | * Abuse of the trace_recursion. | ||
| 293 | * As we need a way to maintain state if we are tracing the function | ||
| 294 | * graph in irq because we want to trace a particular function that | ||
| 295 | * was called in irq context but we have irq tracing off. Since this | ||
| 296 | * can only be modified by current, we can reuse trace_recursion. | ||
| 297 | */ | ||
| 298 | #define TRACE_IRQ_BIT (1<<13) | ||
| 299 | |||
| 300 | #define trace_recursion_set(bit) do { (current)->trace_recursion |= (bit); } while (0) | ||
| 301 | #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(bit); } while (0) | ||
| 302 | #define trace_recursion_test(bit) ((current)->trace_recursion & (bit)) | ||
| 303 | |||
| 281 | #define TRACE_PIPE_ALL_CPU -1 | 304 | #define TRACE_PIPE_ALL_CPU -1 |
| 282 | 305 | ||
| 283 | int tracer_init(struct tracer *t, struct trace_array *tr); | 306 | int tracer_init(struct tracer *t, struct trace_array *tr); |
| @@ -516,8 +539,18 @@ static inline int ftrace_graph_addr(unsigned long addr) | |||
| 516 | return 1; | 539 | return 1; |
| 517 | 540 | ||
| 518 | for (i = 0; i < ftrace_graph_count; i++) { | 541 | for (i = 0; i < ftrace_graph_count; i++) { |
| 519 | if (addr == ftrace_graph_funcs[i]) | 542 | if (addr == ftrace_graph_funcs[i]) { |
| 543 | /* | ||
| 544 | * If no irqs are to be traced, but a set_graph_function | ||
| 545 | * is set, and called by an interrupt handler, we still | ||
| 546 | * want to trace it. | ||
| 547 | */ | ||
| 548 | if (in_irq()) | ||
| 549 | trace_recursion_set(TRACE_IRQ_BIT); | ||
| 550 | else | ||
| 551 | trace_recursion_clear(TRACE_IRQ_BIT); | ||
| 520 | return 1; | 552 | return 1; |
| 553 | } | ||
| 521 | } | 554 | } |
| 522 | 555 | ||
| 523 | return 0; | 556 | return 0; |
| @@ -795,19 +828,4 @@ extern const char *__stop___trace_bprintk_fmt[]; | |||
| 795 | FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print)) | 828 | FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print)) |
| 796 | #include "trace_entries.h" | 829 | #include "trace_entries.h" |
| 797 | 830 | ||
| 798 | /* Only current can touch trace_recursion */ | ||
| 799 | #define trace_recursion_inc() do { (current)->trace_recursion++; } while (0) | ||
| 800 | #define trace_recursion_dec() do { (current)->trace_recursion--; } while (0) | ||
| 801 | |||
| 802 | /* Ring buffer has the 10 LSB bits to count */ | ||
| 803 | #define trace_recursion_buffer() ((current)->trace_recursion & 0x3ff) | ||
| 804 | |||
| 805 | /* for function tracing recursion */ | ||
| 806 | #define TRACE_INTERNAL_BIT (1<<11) | ||
| 807 | #define TRACE_GLOBAL_BIT (1<<12) | ||
| 808 | |||
| 809 | #define trace_recursion_set(bit) do { (current)->trace_recursion |= (bit); } while (0) | ||
| 810 | #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(bit); } while (0) | ||
| 811 | #define trace_recursion_test(bit) ((current)->trace_recursion & (bit)) | ||
| 812 | |||
| 813 | #endif /* _LINUX_KERNEL_TRACE_H */ | 831 | #endif /* _LINUX_KERNEL_TRACE_H */ |
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index e32744c84d94..93365907f219 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h | |||
| @@ -161,7 +161,8 @@ FTRACE_ENTRY(kernel_stack, stack_entry, | |||
| 161 | TRACE_STACK, | 161 | TRACE_STACK, |
| 162 | 162 | ||
| 163 | F_STRUCT( | 163 | F_STRUCT( |
| 164 | __array( unsigned long, caller, FTRACE_STACK_ENTRIES ) | 164 | __field( int, size ) |
| 165 | __dynamic_array(unsigned long, caller ) | ||
| 165 | ), | 166 | ), |
| 166 | 167 | ||
| 167 | F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n" | 168 | F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n" |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index e8d6bb55d719..a7d2a4c653d8 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
| @@ -227,7 +227,7 @@ int __trace_graph_entry(struct trace_array *tr, | |||
| 227 | 227 | ||
| 228 | static inline int ftrace_graph_ignore_irqs(void) | 228 | static inline int ftrace_graph_ignore_irqs(void) |
| 229 | { | 229 | { |
| 230 | if (!ftrace_graph_skip_irqs) | 230 | if (!ftrace_graph_skip_irqs || trace_recursion_test(TRACE_IRQ_BIT)) |
| 231 | return 0; | 231 | return 0; |
| 232 | 232 | ||
| 233 | return in_irq(); | 233 | return in_irq(); |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 7db7b68c6c37..5fb3697bf0e5 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
| @@ -343,6 +343,14 @@ DEFINE_BASIC_FETCH_FUNCS(deref) | |||
| 343 | DEFINE_FETCH_deref(string) | 343 | DEFINE_FETCH_deref(string) |
| 344 | DEFINE_FETCH_deref(string_size) | 344 | DEFINE_FETCH_deref(string_size) |
| 345 | 345 | ||
| 346 | static __kprobes void update_deref_fetch_param(struct deref_fetch_param *data) | ||
| 347 | { | ||
| 348 | if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) | ||
| 349 | update_deref_fetch_param(data->orig.data); | ||
| 350 | else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn)) | ||
| 351 | update_symbol_cache(data->orig.data); | ||
| 352 | } | ||
| 353 | |||
| 346 | static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) | 354 | static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) |
| 347 | { | 355 | { |
| 348 | if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) | 356 | if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) |
| @@ -377,6 +385,19 @@ DEFINE_BASIC_FETCH_FUNCS(bitfield) | |||
| 377 | #define fetch_bitfield_string_size NULL | 385 | #define fetch_bitfield_string_size NULL |
| 378 | 386 | ||
| 379 | static __kprobes void | 387 | static __kprobes void |
| 388 | update_bitfield_fetch_param(struct bitfield_fetch_param *data) | ||
| 389 | { | ||
| 390 | /* | ||
| 391 | * Don't check the bitfield itself, because this must be the | ||
| 392 | * last fetch function. | ||
| 393 | */ | ||
| 394 | if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) | ||
| 395 | update_deref_fetch_param(data->orig.data); | ||
| 396 | else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn)) | ||
| 397 | update_symbol_cache(data->orig.data); | ||
| 398 | } | ||
| 399 | |||
| 400 | static __kprobes void | ||
| 380 | free_bitfield_fetch_param(struct bitfield_fetch_param *data) | 401 | free_bitfield_fetch_param(struct bitfield_fetch_param *data) |
| 381 | { | 402 | { |
| 382 | /* | 403 | /* |
| @@ -389,6 +410,7 @@ free_bitfield_fetch_param(struct bitfield_fetch_param *data) | |||
| 389 | free_symbol_cache(data->orig.data); | 410 | free_symbol_cache(data->orig.data); |
| 390 | kfree(data); | 411 | kfree(data); |
| 391 | } | 412 | } |
| 413 | |||
| 392 | /* Default (unsigned long) fetch type */ | 414 | /* Default (unsigned long) fetch type */ |
| 393 | #define __DEFAULT_FETCH_TYPE(t) u##t | 415 | #define __DEFAULT_FETCH_TYPE(t) u##t |
| 394 | #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) | 416 | #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) |
| @@ -536,6 +558,7 @@ struct probe_arg { | |||
| 536 | /* Flags for trace_probe */ | 558 | /* Flags for trace_probe */ |
| 537 | #define TP_FLAG_TRACE 1 | 559 | #define TP_FLAG_TRACE 1 |
| 538 | #define TP_FLAG_PROFILE 2 | 560 | #define TP_FLAG_PROFILE 2 |
| 561 | #define TP_FLAG_REGISTERED 4 | ||
| 539 | 562 | ||
| 540 | struct trace_probe { | 563 | struct trace_probe { |
| 541 | struct list_head list; | 564 | struct list_head list; |
| @@ -555,16 +578,49 @@ struct trace_probe { | |||
| 555 | (sizeof(struct probe_arg) * (n))) | 578 | (sizeof(struct probe_arg) * (n))) |
| 556 | 579 | ||
| 557 | 580 | ||
| 558 | static __kprobes int probe_is_return(struct trace_probe *tp) | 581 | static __kprobes int trace_probe_is_return(struct trace_probe *tp) |
| 559 | { | 582 | { |
| 560 | return tp->rp.handler != NULL; | 583 | return tp->rp.handler != NULL; |
| 561 | } | 584 | } |
| 562 | 585 | ||
| 563 | static __kprobes const char *probe_symbol(struct trace_probe *tp) | 586 | static __kprobes const char *trace_probe_symbol(struct trace_probe *tp) |
| 564 | { | 587 | { |
| 565 | return tp->symbol ? tp->symbol : "unknown"; | 588 | return tp->symbol ? tp->symbol : "unknown"; |
| 566 | } | 589 | } |
| 567 | 590 | ||
| 591 | static __kprobes unsigned long trace_probe_offset(struct trace_probe *tp) | ||
| 592 | { | ||
| 593 | return tp->rp.kp.offset; | ||
| 594 | } | ||
| 595 | |||
| 596 | static __kprobes bool trace_probe_is_enabled(struct trace_probe *tp) | ||
| 597 | { | ||
| 598 | return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE)); | ||
| 599 | } | ||
| 600 | |||
| 601 | static __kprobes bool trace_probe_is_registered(struct trace_probe *tp) | ||
| 602 | { | ||
| 603 | return !!(tp->flags & TP_FLAG_REGISTERED); | ||
| 604 | } | ||
| 605 | |||
| 606 | static __kprobes bool trace_probe_has_gone(struct trace_probe *tp) | ||
| 607 | { | ||
| 608 | return !!(kprobe_gone(&tp->rp.kp)); | ||
| 609 | } | ||
| 610 | |||
| 611 | static __kprobes bool trace_probe_within_module(struct trace_probe *tp, | ||
| 612 | struct module *mod) | ||
| 613 | { | ||
| 614 | int len = strlen(mod->name); | ||
| 615 | const char *name = trace_probe_symbol(tp); | ||
| 616 | return strncmp(mod->name, name, len) == 0 && name[len] == ':'; | ||
| 617 | } | ||
| 618 | |||
| 619 | static __kprobes bool trace_probe_is_on_module(struct trace_probe *tp) | ||
| 620 | { | ||
| 621 | return !!strchr(trace_probe_symbol(tp), ':'); | ||
| 622 | } | ||
| 623 | |||
| 568 | static int register_probe_event(struct trace_probe *tp); | 624 | static int register_probe_event(struct trace_probe *tp); |
| 569 | static void unregister_probe_event(struct trace_probe *tp); | 625 | static void unregister_probe_event(struct trace_probe *tp); |
| 570 | 626 | ||
| @@ -646,6 +702,16 @@ error: | |||
| 646 | return ERR_PTR(ret); | 702 | return ERR_PTR(ret); |
| 647 | } | 703 | } |
| 648 | 704 | ||
| 705 | static void update_probe_arg(struct probe_arg *arg) | ||
| 706 | { | ||
| 707 | if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn)) | ||
| 708 | update_bitfield_fetch_param(arg->fetch.data); | ||
| 709 | else if (CHECK_FETCH_FUNCS(deref, arg->fetch.fn)) | ||
| 710 | update_deref_fetch_param(arg->fetch.data); | ||
| 711 | else if (CHECK_FETCH_FUNCS(symbol, arg->fetch.fn)) | ||
| 712 | update_symbol_cache(arg->fetch.data); | ||
| 713 | } | ||
| 714 | |||
| 649 | static void free_probe_arg(struct probe_arg *arg) | 715 | static void free_probe_arg(struct probe_arg *arg) |
| 650 | { | 716 | { |
| 651 | if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn)) | 717 | if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn)) |
| @@ -671,7 +737,7 @@ static void free_trace_probe(struct trace_probe *tp) | |||
| 671 | kfree(tp); | 737 | kfree(tp); |
| 672 | } | 738 | } |
| 673 | 739 | ||
| 674 | static struct trace_probe *find_probe_event(const char *event, | 740 | static struct trace_probe *find_trace_probe(const char *event, |
| 675 | const char *group) | 741 | const char *group) |
| 676 | { | 742 | { |
| 677 | struct trace_probe *tp; | 743 | struct trace_probe *tp; |
| @@ -683,13 +749,96 @@ static struct trace_probe *find_probe_event(const char *event, | |||
| 683 | return NULL; | 749 | return NULL; |
| 684 | } | 750 | } |
| 685 | 751 | ||
| 752 | /* Enable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */ | ||
| 753 | static int enable_trace_probe(struct trace_probe *tp, int flag) | ||
| 754 | { | ||
| 755 | int ret = 0; | ||
| 756 | |||
| 757 | tp->flags |= flag; | ||
| 758 | if (trace_probe_is_enabled(tp) && trace_probe_is_registered(tp) && | ||
| 759 | !trace_probe_has_gone(tp)) { | ||
| 760 | if (trace_probe_is_return(tp)) | ||
| 761 | ret = enable_kretprobe(&tp->rp); | ||
| 762 | else | ||
| 763 | ret = enable_kprobe(&tp->rp.kp); | ||
| 764 | } | ||
| 765 | |||
| 766 | return ret; | ||
| 767 | } | ||
| 768 | |||
| 769 | /* Disable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */ | ||
| 770 | static void disable_trace_probe(struct trace_probe *tp, int flag) | ||
| 771 | { | ||
| 772 | tp->flags &= ~flag; | ||
| 773 | if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) { | ||
| 774 | if (trace_probe_is_return(tp)) | ||
| 775 | disable_kretprobe(&tp->rp); | ||
| 776 | else | ||
| 777 | disable_kprobe(&tp->rp.kp); | ||
| 778 | } | ||
| 779 | } | ||
| 780 | |||
| 781 | /* Internal register function - just handle k*probes and flags */ | ||
| 782 | static int __register_trace_probe(struct trace_probe *tp) | ||
| 783 | { | ||
| 784 | int i, ret; | ||
| 785 | |||
| 786 | if (trace_probe_is_registered(tp)) | ||
| 787 | return -EINVAL; | ||
| 788 | |||
| 789 | for (i = 0; i < tp->nr_args; i++) | ||
| 790 | update_probe_arg(&tp->args[i]); | ||
| 791 | |||
| 792 | /* Set/clear disabled flag according to tp->flag */ | ||
| 793 | if (trace_probe_is_enabled(tp)) | ||
| 794 | tp->rp.kp.flags &= ~KPROBE_FLAG_DISABLED; | ||
| 795 | else | ||
| 796 | tp->rp.kp.flags |= KPROBE_FLAG_DISABLED; | ||
| 797 | |||
| 798 | if (trace_probe_is_return(tp)) | ||
| 799 | ret = register_kretprobe(&tp->rp); | ||
| 800 | else | ||
| 801 | ret = register_kprobe(&tp->rp.kp); | ||
| 802 | |||
| 803 | if (ret == 0) | ||
| 804 | tp->flags |= TP_FLAG_REGISTERED; | ||
| 805 | else { | ||
| 806 | pr_warning("Could not insert probe at %s+%lu: %d\n", | ||
| 807 | trace_probe_symbol(tp), trace_probe_offset(tp), ret); | ||
| 808 | if (ret == -ENOENT && trace_probe_is_on_module(tp)) { | ||
| 809 | pr_warning("This probe might be able to register after" | ||
| 810 | "target module is loaded. Continue.\n"); | ||
| 811 | ret = 0; | ||
| 812 | } else if (ret == -EILSEQ) { | ||
| 813 | pr_warning("Probing address(0x%p) is not an " | ||
| 814 | "instruction boundary.\n", | ||
| 815 | tp->rp.kp.addr); | ||
| 816 | ret = -EINVAL; | ||
| 817 | } | ||
| 818 | } | ||
| 819 | |||
| 820 | return ret; | ||
| 821 | } | ||
| 822 | |||
| 823 | /* Internal unregister function - just handle k*probes and flags */ | ||
| 824 | static void __unregister_trace_probe(struct trace_probe *tp) | ||
| 825 | { | ||
| 826 | if (trace_probe_is_registered(tp)) { | ||
| 827 | if (trace_probe_is_return(tp)) | ||
| 828 | unregister_kretprobe(&tp->rp); | ||
| 829 | else | ||
| 830 | unregister_kprobe(&tp->rp.kp); | ||
| 831 | tp->flags &= ~TP_FLAG_REGISTERED; | ||
| 832 | /* Cleanup kprobe for reuse */ | ||
| 833 | if (tp->rp.kp.symbol_name) | ||
| 834 | tp->rp.kp.addr = NULL; | ||
| 835 | } | ||
| 836 | } | ||
| 837 | |||
| 686 | /* Unregister a trace_probe and probe_event: call with locking probe_lock */ | 838 | /* Unregister a trace_probe and probe_event: call with locking probe_lock */ |
| 687 | static void unregister_trace_probe(struct trace_probe *tp) | 839 | static void unregister_trace_probe(struct trace_probe *tp) |
| 688 | { | 840 | { |
| 689 | if (probe_is_return(tp)) | 841 | __unregister_trace_probe(tp); |
| 690 | unregister_kretprobe(&tp->rp); | ||
| 691 | else | ||
| 692 | unregister_kprobe(&tp->rp.kp); | ||
| 693 | list_del(&tp->list); | 842 | list_del(&tp->list); |
| 694 | unregister_probe_event(tp); | 843 | unregister_probe_event(tp); |
| 695 | } | 844 | } |
| @@ -702,41 +851,65 @@ static int register_trace_probe(struct trace_probe *tp) | |||
| 702 | 851 | ||
| 703 | mutex_lock(&probe_lock); | 852 | mutex_lock(&probe_lock); |
| 704 | 853 | ||
| 705 | /* register as an event */ | 854 | /* Delete old (same name) event if exist */ |
| 706 | old_tp = find_probe_event(tp->call.name, tp->call.class->system); | 855 | old_tp = find_trace_probe(tp->call.name, tp->call.class->system); |
| 707 | if (old_tp) { | 856 | if (old_tp) { |
| 708 | /* delete old event */ | ||
| 709 | unregister_trace_probe(old_tp); | 857 | unregister_trace_probe(old_tp); |
| 710 | free_trace_probe(old_tp); | 858 | free_trace_probe(old_tp); |
| 711 | } | 859 | } |
| 860 | |||
| 861 | /* Register new event */ | ||
| 712 | ret = register_probe_event(tp); | 862 | ret = register_probe_event(tp); |
| 713 | if (ret) { | 863 | if (ret) { |
| 714 | pr_warning("Failed to register probe event(%d)\n", ret); | 864 | pr_warning("Failed to register probe event(%d)\n", ret); |
| 715 | goto end; | 865 | goto end; |
| 716 | } | 866 | } |
| 717 | 867 | ||
| 718 | tp->rp.kp.flags |= KPROBE_FLAG_DISABLED; | 868 | /* Register k*probe */ |
| 719 | if (probe_is_return(tp)) | 869 | ret = __register_trace_probe(tp); |
| 720 | ret = register_kretprobe(&tp->rp); | 870 | if (ret < 0) |
| 721 | else | ||
| 722 | ret = register_kprobe(&tp->rp.kp); | ||
| 723 | |||
| 724 | if (ret) { | ||
| 725 | pr_warning("Could not insert probe(%d)\n", ret); | ||
| 726 | if (ret == -EILSEQ) { | ||
| 727 | pr_warning("Probing address(0x%p) is not an " | ||
| 728 | "instruction boundary.\n", | ||
| 729 | tp->rp.kp.addr); | ||
| 730 | ret = -EINVAL; | ||
| 731 | } | ||
| 732 | unregister_probe_event(tp); | 871 | unregister_probe_event(tp); |
| 733 | } else | 872 | else |
| 734 | list_add_tail(&tp->list, &probe_list); | 873 | list_add_tail(&tp->list, &probe_list); |
| 874 | |||
| 735 | end: | 875 | end: |
| 736 | mutex_unlock(&probe_lock); | 876 | mutex_unlock(&probe_lock); |
| 737 | return ret; | 877 | return ret; |
| 738 | } | 878 | } |
| 739 | 879 | ||
| 880 | /* Module notifier call back, checking event on the module */ | ||
| 881 | static int trace_probe_module_callback(struct notifier_block *nb, | ||
| 882 | unsigned long val, void *data) | ||
| 883 | { | ||
| 884 | struct module *mod = data; | ||
| 885 | struct trace_probe *tp; | ||
| 886 | int ret; | ||
| 887 | |||
| 888 | if (val != MODULE_STATE_COMING) | ||
| 889 | return NOTIFY_DONE; | ||
| 890 | |||
| 891 | /* Update probes on coming module */ | ||
| 892 | mutex_lock(&probe_lock); | ||
| 893 | list_for_each_entry(tp, &probe_list, list) { | ||
| 894 | if (trace_probe_within_module(tp, mod)) { | ||
| 895 | __unregister_trace_probe(tp); | ||
| 896 | ret = __register_trace_probe(tp); | ||
| 897 | if (ret) | ||
| 898 | pr_warning("Failed to re-register probe %s on" | ||
| 899 | "%s: %d\n", | ||
| 900 | tp->call.name, mod->name, ret); | ||
| 901 | } | ||
| 902 | } | ||
| 903 | mutex_unlock(&probe_lock); | ||
| 904 | |||
| 905 | return NOTIFY_DONE; | ||
| 906 | } | ||
| 907 | |||
| 908 | static struct notifier_block trace_probe_module_nb = { | ||
| 909 | .notifier_call = trace_probe_module_callback, | ||
| 910 | .priority = 1 /* Invoked after kprobe module callback */ | ||
| 911 | }; | ||
| 912 | |||
| 740 | /* Split symbol and offset. */ | 913 | /* Split symbol and offset. */ |
| 741 | static int split_symbol_offset(char *symbol, unsigned long *offset) | 914 | static int split_symbol_offset(char *symbol, unsigned long *offset) |
| 742 | { | 915 | { |
| @@ -962,8 +1135,8 @@ static int create_trace_probe(int argc, char **argv) | |||
| 962 | { | 1135 | { |
| 963 | /* | 1136 | /* |
| 964 | * Argument syntax: | 1137 | * Argument syntax: |
| 965 | * - Add kprobe: p[:[GRP/]EVENT] KSYM[+OFFS]|KADDR [FETCHARGS] | 1138 | * - Add kprobe: p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS] |
| 966 | * - Add kretprobe: r[:[GRP/]EVENT] KSYM[+0] [FETCHARGS] | 1139 | * - Add kretprobe: r[:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS] |
| 967 | * Fetch args: | 1140 | * Fetch args: |
| 968 | * $retval : fetch return value | 1141 | * $retval : fetch return value |
| 969 | * $stack : fetch stack address | 1142 | * $stack : fetch stack address |
| @@ -1025,7 +1198,7 @@ static int create_trace_probe(int argc, char **argv) | |||
| 1025 | return -EINVAL; | 1198 | return -EINVAL; |
| 1026 | } | 1199 | } |
| 1027 | mutex_lock(&probe_lock); | 1200 | mutex_lock(&probe_lock); |
| 1028 | tp = find_probe_event(event, group); | 1201 | tp = find_trace_probe(event, group); |
| 1029 | if (!tp) { | 1202 | if (!tp) { |
| 1030 | mutex_unlock(&probe_lock); | 1203 | mutex_unlock(&probe_lock); |
| 1031 | pr_info("Event %s/%s doesn't exist.\n", group, event); | 1204 | pr_info("Event %s/%s doesn't exist.\n", group, event); |
| @@ -1144,7 +1317,7 @@ error: | |||
| 1144 | return ret; | 1317 | return ret; |
| 1145 | } | 1318 | } |
| 1146 | 1319 | ||
| 1147 | static void cleanup_all_probes(void) | 1320 | static void release_all_trace_probes(void) |
| 1148 | { | 1321 | { |
| 1149 | struct trace_probe *tp; | 1322 | struct trace_probe *tp; |
| 1150 | 1323 | ||
| @@ -1158,7 +1331,6 @@ static void cleanup_all_probes(void) | |||
| 1158 | mutex_unlock(&probe_lock); | 1331 | mutex_unlock(&probe_lock); |
| 1159 | } | 1332 | } |
| 1160 | 1333 | ||
| 1161 | |||
| 1162 | /* Probes listing interfaces */ | 1334 | /* Probes listing interfaces */ |
| 1163 | static void *probes_seq_start(struct seq_file *m, loff_t *pos) | 1335 | static void *probes_seq_start(struct seq_file *m, loff_t *pos) |
| 1164 | { | 1336 | { |
| @@ -1181,15 +1353,16 @@ static int probes_seq_show(struct seq_file *m, void *v) | |||
| 1181 | struct trace_probe *tp = v; | 1353 | struct trace_probe *tp = v; |
| 1182 | int i; | 1354 | int i; |
| 1183 | 1355 | ||
| 1184 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); | 1356 | seq_printf(m, "%c", trace_probe_is_return(tp) ? 'r' : 'p'); |
| 1185 | seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name); | 1357 | seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name); |
| 1186 | 1358 | ||
| 1187 | if (!tp->symbol) | 1359 | if (!tp->symbol) |
| 1188 | seq_printf(m, " 0x%p", tp->rp.kp.addr); | 1360 | seq_printf(m, " 0x%p", tp->rp.kp.addr); |
| 1189 | else if (tp->rp.kp.offset) | 1361 | else if (tp->rp.kp.offset) |
| 1190 | seq_printf(m, " %s+%u", probe_symbol(tp), tp->rp.kp.offset); | 1362 | seq_printf(m, " %s+%u", trace_probe_symbol(tp), |
| 1363 | tp->rp.kp.offset); | ||
| 1191 | else | 1364 | else |
| 1192 | seq_printf(m, " %s", probe_symbol(tp)); | 1365 | seq_printf(m, " %s", trace_probe_symbol(tp)); |
| 1193 | 1366 | ||
| 1194 | for (i = 0; i < tp->nr_args; i++) | 1367 | for (i = 0; i < tp->nr_args; i++) |
| 1195 | seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm); | 1368 | seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm); |
| @@ -1209,7 +1382,7 @@ static int probes_open(struct inode *inode, struct file *file) | |||
| 1209 | { | 1382 | { |
| 1210 | if ((file->f_mode & FMODE_WRITE) && | 1383 | if ((file->f_mode & FMODE_WRITE) && |
| 1211 | (file->f_flags & O_TRUNC)) | 1384 | (file->f_flags & O_TRUNC)) |
| 1212 | cleanup_all_probes(); | 1385 | release_all_trace_probes(); |
| 1213 | 1386 | ||
| 1214 | return seq_open(file, &probes_seq_op); | 1387 | return seq_open(file, &probes_seq_op); |
| 1215 | } | 1388 | } |
| @@ -1513,30 +1686,6 @@ partial: | |||
| 1513 | return TRACE_TYPE_PARTIAL_LINE; | 1686 | return TRACE_TYPE_PARTIAL_LINE; |
| 1514 | } | 1687 | } |
| 1515 | 1688 | ||
| 1516 | static int probe_event_enable(struct ftrace_event_call *call) | ||
| 1517 | { | ||
| 1518 | struct trace_probe *tp = (struct trace_probe *)call->data; | ||
| 1519 | |||
| 1520 | tp->flags |= TP_FLAG_TRACE; | ||
| 1521 | if (probe_is_return(tp)) | ||
| 1522 | return enable_kretprobe(&tp->rp); | ||
| 1523 | else | ||
| 1524 | return enable_kprobe(&tp->rp.kp); | ||
| 1525 | } | ||
| 1526 | |||
| 1527 | static void probe_event_disable(struct ftrace_event_call *call) | ||
| 1528 | { | ||
| 1529 | struct trace_probe *tp = (struct trace_probe *)call->data; | ||
| 1530 | |||
| 1531 | tp->flags &= ~TP_FLAG_TRACE; | ||
| 1532 | if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) { | ||
| 1533 | if (probe_is_return(tp)) | ||
| 1534 | disable_kretprobe(&tp->rp); | ||
| 1535 | else | ||
| 1536 | disable_kprobe(&tp->rp.kp); | ||
| 1537 | } | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | #undef DEFINE_FIELD | 1689 | #undef DEFINE_FIELD |
| 1541 | #define DEFINE_FIELD(type, item, name, is_signed) \ | 1690 | #define DEFINE_FIELD(type, item, name, is_signed) \ |
| 1542 | do { \ | 1691 | do { \ |
| @@ -1598,7 +1747,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len) | |||
| 1598 | 1747 | ||
| 1599 | const char *fmt, *arg; | 1748 | const char *fmt, *arg; |
| 1600 | 1749 | ||
| 1601 | if (!probe_is_return(tp)) { | 1750 | if (!trace_probe_is_return(tp)) { |
| 1602 | fmt = "(%lx)"; | 1751 | fmt = "(%lx)"; |
| 1603 | arg = "REC->" FIELD_STRING_IP; | 1752 | arg = "REC->" FIELD_STRING_IP; |
| 1604 | } else { | 1753 | } else { |
| @@ -1715,49 +1864,25 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
| 1715 | head = this_cpu_ptr(call->perf_events); | 1864 | head = this_cpu_ptr(call->perf_events); |
| 1716 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); | 1865 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); |
| 1717 | } | 1866 | } |
| 1718 | |||
| 1719 | static int probe_perf_enable(struct ftrace_event_call *call) | ||
| 1720 | { | ||
| 1721 | struct trace_probe *tp = (struct trace_probe *)call->data; | ||
| 1722 | |||
| 1723 | tp->flags |= TP_FLAG_PROFILE; | ||
| 1724 | |||
| 1725 | if (probe_is_return(tp)) | ||
| 1726 | return enable_kretprobe(&tp->rp); | ||
| 1727 | else | ||
| 1728 | return enable_kprobe(&tp->rp.kp); | ||
| 1729 | } | ||
| 1730 | |||
| 1731 | static void probe_perf_disable(struct ftrace_event_call *call) | ||
| 1732 | { | ||
| 1733 | struct trace_probe *tp = (struct trace_probe *)call->data; | ||
| 1734 | |||
| 1735 | tp->flags &= ~TP_FLAG_PROFILE; | ||
| 1736 | |||
| 1737 | if (!(tp->flags & TP_FLAG_TRACE)) { | ||
| 1738 | if (probe_is_return(tp)) | ||
| 1739 | disable_kretprobe(&tp->rp); | ||
| 1740 | else | ||
| 1741 | disable_kprobe(&tp->rp.kp); | ||
| 1742 | } | ||
| 1743 | } | ||
| 1744 | #endif /* CONFIG_PERF_EVENTS */ | 1867 | #endif /* CONFIG_PERF_EVENTS */ |
| 1745 | 1868 | ||
| 1746 | static __kprobes | 1869 | static __kprobes |
| 1747 | int kprobe_register(struct ftrace_event_call *event, enum trace_reg type) | 1870 | int kprobe_register(struct ftrace_event_call *event, enum trace_reg type) |
| 1748 | { | 1871 | { |
| 1872 | struct trace_probe *tp = (struct trace_probe *)event->data; | ||
| 1873 | |||
| 1749 | switch (type) { | 1874 | switch (type) { |
| 1750 | case TRACE_REG_REGISTER: | 1875 | case TRACE_REG_REGISTER: |
| 1751 | return probe_event_enable(event); | 1876 | return enable_trace_probe(tp, TP_FLAG_TRACE); |
| 1752 | case TRACE_REG_UNREGISTER: | 1877 | case TRACE_REG_UNREGISTER: |
| 1753 | probe_event_disable(event); | 1878 | disable_trace_probe(tp, TP_FLAG_TRACE); |
| 1754 | return 0; | 1879 | return 0; |
| 1755 | 1880 | ||
| 1756 | #ifdef CONFIG_PERF_EVENTS | 1881 | #ifdef CONFIG_PERF_EVENTS |
| 1757 | case TRACE_REG_PERF_REGISTER: | 1882 | case TRACE_REG_PERF_REGISTER: |
| 1758 | return probe_perf_enable(event); | 1883 | return enable_trace_probe(tp, TP_FLAG_PROFILE); |
| 1759 | case TRACE_REG_PERF_UNREGISTER: | 1884 | case TRACE_REG_PERF_UNREGISTER: |
| 1760 | probe_perf_disable(event); | 1885 | disable_trace_probe(tp, TP_FLAG_PROFILE); |
| 1761 | return 0; | 1886 | return 0; |
| 1762 | #endif | 1887 | #endif |
| 1763 | } | 1888 | } |
| @@ -1807,7 +1932,7 @@ static int register_probe_event(struct trace_probe *tp) | |||
| 1807 | 1932 | ||
| 1808 | /* Initialize ftrace_event_call */ | 1933 | /* Initialize ftrace_event_call */ |
| 1809 | INIT_LIST_HEAD(&call->class->fields); | 1934 | INIT_LIST_HEAD(&call->class->fields); |
| 1810 | if (probe_is_return(tp)) { | 1935 | if (trace_probe_is_return(tp)) { |
| 1811 | call->event.funcs = &kretprobe_funcs; | 1936 | call->event.funcs = &kretprobe_funcs; |
| 1812 | call->class->define_fields = kretprobe_event_define_fields; | 1937 | call->class->define_fields = kretprobe_event_define_fields; |
| 1813 | } else { | 1938 | } else { |
| @@ -1846,6 +1971,9 @@ static __init int init_kprobe_trace(void) | |||
| 1846 | struct dentry *d_tracer; | 1971 | struct dentry *d_tracer; |
| 1847 | struct dentry *entry; | 1972 | struct dentry *entry; |
| 1848 | 1973 | ||
| 1974 | if (register_module_notifier(&trace_probe_module_nb)) | ||
| 1975 | return -EINVAL; | ||
| 1976 | |||
| 1849 | d_tracer = tracing_init_dentry(); | 1977 | d_tracer = tracing_init_dentry(); |
| 1850 | if (!d_tracer) | 1978 | if (!d_tracer) |
| 1851 | return 0; | 1979 | return 0; |
| @@ -1899,12 +2027,12 @@ static __init int kprobe_trace_self_tests_init(void) | |||
| 1899 | warn++; | 2027 | warn++; |
| 1900 | } else { | 2028 | } else { |
| 1901 | /* Enable trace point */ | 2029 | /* Enable trace point */ |
| 1902 | tp = find_probe_event("testprobe", KPROBE_EVENT_SYSTEM); | 2030 | tp = find_trace_probe("testprobe", KPROBE_EVENT_SYSTEM); |
| 1903 | if (WARN_ON_ONCE(tp == NULL)) { | 2031 | if (WARN_ON_ONCE(tp == NULL)) { |
| 1904 | pr_warning("error on getting new probe.\n"); | 2032 | pr_warning("error on getting new probe.\n"); |
| 1905 | warn++; | 2033 | warn++; |
| 1906 | } else | 2034 | } else |
| 1907 | probe_event_enable(&tp->call); | 2035 | enable_trace_probe(tp, TP_FLAG_TRACE); |
| 1908 | } | 2036 | } |
| 1909 | 2037 | ||
| 1910 | ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target " | 2038 | ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target " |
| @@ -1914,12 +2042,12 @@ static __init int kprobe_trace_self_tests_init(void) | |||
| 1914 | warn++; | 2042 | warn++; |
| 1915 | } else { | 2043 | } else { |
| 1916 | /* Enable trace point */ | 2044 | /* Enable trace point */ |
| 1917 | tp = find_probe_event("testprobe2", KPROBE_EVENT_SYSTEM); | 2045 | tp = find_trace_probe("testprobe2", KPROBE_EVENT_SYSTEM); |
| 1918 | if (WARN_ON_ONCE(tp == NULL)) { | 2046 | if (WARN_ON_ONCE(tp == NULL)) { |
| 1919 | pr_warning("error on getting new probe.\n"); | 2047 | pr_warning("error on getting new probe.\n"); |
| 1920 | warn++; | 2048 | warn++; |
| 1921 | } else | 2049 | } else |
| 1922 | probe_event_enable(&tp->call); | 2050 | enable_trace_probe(tp, TP_FLAG_TRACE); |
| 1923 | } | 2051 | } |
| 1924 | 2052 | ||
| 1925 | if (warn) | 2053 | if (warn) |
| @@ -1940,7 +2068,7 @@ static __init int kprobe_trace_self_tests_init(void) | |||
| 1940 | } | 2068 | } |
| 1941 | 2069 | ||
| 1942 | end: | 2070 | end: |
| 1943 | cleanup_all_probes(); | 2071 | release_all_trace_probes(); |
| 1944 | if (warn) | 2072 | if (warn) |
| 1945 | pr_cont("NG: Some tests are failed. Please check them.\n"); | 2073 | pr_cont("NG: Some tests are failed. Please check them.\n"); |
| 1946 | else | 2074 | else |
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index e37de492a9e1..51999309a6cf 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
| @@ -1107,19 +1107,20 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, | |||
| 1107 | { | 1107 | { |
| 1108 | struct stack_entry *field; | 1108 | struct stack_entry *field; |
| 1109 | struct trace_seq *s = &iter->seq; | 1109 | struct trace_seq *s = &iter->seq; |
| 1110 | int i; | 1110 | unsigned long *p; |
| 1111 | unsigned long *end; | ||
| 1111 | 1112 | ||
| 1112 | trace_assign_type(field, iter->ent); | 1113 | trace_assign_type(field, iter->ent); |
| 1114 | end = (unsigned long *)((long)iter->ent + iter->ent_size); | ||
| 1113 | 1115 | ||
| 1114 | if (!trace_seq_puts(s, "<stack trace>\n")) | 1116 | if (!trace_seq_puts(s, "<stack trace>\n")) |
| 1115 | goto partial; | 1117 | goto partial; |
| 1116 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | 1118 | |
| 1117 | if (!field->caller[i] || (field->caller[i] == ULONG_MAX)) | 1119 | for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) { |
| 1118 | break; | ||
| 1119 | if (!trace_seq_puts(s, " => ")) | 1120 | if (!trace_seq_puts(s, " => ")) |
| 1120 | goto partial; | 1121 | goto partial; |
| 1121 | 1122 | ||
| 1122 | if (!seq_print_ip_sym(s, field->caller[i], flags)) | 1123 | if (!seq_print_ip_sym(s, *p, flags)) |
| 1123 | goto partial; | 1124 | goto partial; |
| 1124 | if (!trace_seq_puts(s, "\n")) | 1125 | if (!trace_seq_puts(s, "\n")) |
| 1125 | goto partial; | 1126 | goto partial; |
diff --git a/kernel/watchdog.c b/kernel/watchdog.c index a933e3a0398b..36491cd5b7d4 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c | |||
| @@ -200,7 +200,6 @@ static int is_softlockup(unsigned long touch_ts) | |||
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | #ifdef CONFIG_HARDLOCKUP_DETECTOR | 202 | #ifdef CONFIG_HARDLOCKUP_DETECTOR |
| 203 | void __weak hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr) { } | ||
| 204 | 203 | ||
| 205 | static struct perf_event_attr wd_hw_attr = { | 204 | static struct perf_event_attr wd_hw_attr = { |
| 206 | .type = PERF_TYPE_HARDWARE, | 205 | .type = PERF_TYPE_HARDWARE, |
| @@ -372,7 +371,6 @@ static int watchdog_nmi_enable(int cpu) | |||
| 372 | 371 | ||
| 373 | wd_attr = &wd_hw_attr; | 372 | wd_attr = &wd_hw_attr; |
| 374 | wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh); | 373 | wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh); |
| 375 | hw_nmi_watchdog_set_attr(wd_attr); | ||
| 376 | 374 | ||
| 377 | /* Try to register using hardware perf events */ | 375 | /* Try to register using hardware perf events */ |
| 378 | event = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback, NULL); | 376 | event = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback, NULL); |
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 02bafce4b341..2780d9ce48bf 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
| @@ -34,9 +34,11 @@ OPTIONS | |||
| 34 | Specify vmlinux path which has debuginfo (Dwarf binary). | 34 | Specify vmlinux path which has debuginfo (Dwarf binary). |
| 35 | 35 | ||
| 36 | -m:: | 36 | -m:: |
| 37 | --module=MODNAME:: | 37 | --module=MODNAME|PATH:: |
| 38 | Specify module name in which perf-probe searches probe points | 38 | Specify module name in which perf-probe searches probe points |
| 39 | or lines. | 39 | or lines. If a path of module file is passed, perf-probe |
| 40 | treat it as an offline module (this means you can add a probe on | ||
| 41 | a module which has not been loaded yet). | ||
| 40 | 42 | ||
| 41 | -s:: | 43 | -s:: |
| 42 | --source=PATH:: | 44 | --source=PATH:: |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 940257b5774e..d0861bbd1d94 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
| @@ -279,6 +279,7 @@ LIB_H += util/thread.h | |||
| 279 | LIB_H += util/thread_map.h | 279 | LIB_H += util/thread_map.h |
| 280 | LIB_H += util/trace-event.h | 280 | LIB_H += util/trace-event.h |
| 281 | LIB_H += util/probe-finder.h | 281 | LIB_H += util/probe-finder.h |
| 282 | LIB_H += util/dwarf-aux.h | ||
| 282 | LIB_H += util/probe-event.h | 283 | LIB_H += util/probe-event.h |
| 283 | LIB_H += util/pstack.h | 284 | LIB_H += util/pstack.h |
| 284 | LIB_H += util/cpumap.h | 285 | LIB_H += util/cpumap.h |
| @@ -435,6 +436,7 @@ else | |||
| 435 | BASIC_CFLAGS += -DDWARF_SUPPORT | 436 | BASIC_CFLAGS += -DDWARF_SUPPORT |
| 436 | EXTLIBS += -lelf -ldw | 437 | EXTLIBS += -lelf -ldw |
| 437 | LIB_OBJS += $(OUTPUT)util/probe-finder.o | 438 | LIB_OBJS += $(OUTPUT)util/probe-finder.o |
| 439 | LIB_OBJS += $(OUTPUT)util/dwarf-aux.o | ||
| 438 | endif # PERF_HAVE_DWARF_REGS | 440 | endif # PERF_HAVE_DWARF_REGS |
| 439 | endif # NO_DWARF | 441 | endif # NO_DWARF |
| 440 | 442 | ||
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 2c0e64d0b4aa..5f2a5c7046df 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
| @@ -242,7 +242,8 @@ static const struct option options[] = { | |||
| 242 | OPT_STRING('s', "source", &symbol_conf.source_prefix, | 242 | OPT_STRING('s', "source", &symbol_conf.source_prefix, |
| 243 | "directory", "path to kernel source"), | 243 | "directory", "path to kernel source"), |
| 244 | OPT_STRING('m', "module", ¶ms.target_module, | 244 | OPT_STRING('m', "module", ¶ms.target_module, |
| 245 | "modname", "target module name"), | 245 | "modname|path", |
| 246 | "target module name (for online) or path (for offline)"), | ||
| 246 | #endif | 247 | #endif |
| 247 | OPT__DRY_RUN(&probe_event_dry_run), | 248 | OPT__DRY_RUN(&probe_event_dry_run), |
| 248 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, | 249 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, |
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c new file mode 100644 index 000000000000..fddf40f30d3e --- /dev/null +++ b/tools/perf/util/dwarf-aux.c | |||
| @@ -0,0 +1,663 @@ | |||
| 1 | /* | ||
| 2 | * dwarf-aux.c : libdw auxiliary interfaces | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <stdbool.h> | ||
| 21 | #include "util.h" | ||
| 22 | #include "debug.h" | ||
| 23 | #include "dwarf-aux.h" | ||
| 24 | |||
| 25 | /** | ||
| 26 | * cu_find_realpath - Find the realpath of the target file | ||
| 27 | * @cu_die: A DIE(dwarf information entry) of CU(compilation Unit) | ||
| 28 | * @fname: The tail filename of the target file | ||
| 29 | * | ||
| 30 | * Find the real(long) path of @fname in @cu_die. | ||
| 31 | */ | ||
| 32 | const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname) | ||
| 33 | { | ||
| 34 | Dwarf_Files *files; | ||
| 35 | size_t nfiles, i; | ||
| 36 | const char *src = NULL; | ||
| 37 | int ret; | ||
| 38 | |||
| 39 | if (!fname) | ||
| 40 | return NULL; | ||
| 41 | |||
| 42 | ret = dwarf_getsrcfiles(cu_die, &files, &nfiles); | ||
| 43 | if (ret != 0) | ||
| 44 | return NULL; | ||
| 45 | |||
| 46 | for (i = 0; i < nfiles; i++) { | ||
| 47 | src = dwarf_filesrc(files, i, NULL, NULL); | ||
| 48 | if (strtailcmp(src, fname) == 0) | ||
| 49 | break; | ||
| 50 | } | ||
| 51 | if (i == nfiles) | ||
| 52 | return NULL; | ||
| 53 | return src; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * cu_get_comp_dir - Get the path of compilation directory | ||
| 58 | * @cu_die: a CU DIE | ||
| 59 | * | ||
| 60 | * Get the path of compilation directory of given @cu_die. | ||
| 61 | * Since this depends on DW_AT_comp_dir, older gcc will not | ||
| 62 | * embedded it. In that case, this returns NULL. | ||
| 63 | */ | ||
| 64 | const char *cu_get_comp_dir(Dwarf_Die *cu_die) | ||
| 65 | { | ||
| 66 | Dwarf_Attribute attr; | ||
| 67 | if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL) | ||
| 68 | return NULL; | ||
| 69 | return dwarf_formstring(&attr); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * cu_find_lineinfo - Get a line number and file name for given address | ||
| 74 | * @cu_die: a CU DIE | ||
| 75 | * @addr: An address | ||
| 76 | * @fname: a pointer which returns the file name string | ||
| 77 | * @lineno: a pointer which returns the line number | ||
| 78 | * | ||
| 79 | * Find a line number and file name for @addr in @cu_die. | ||
| 80 | */ | ||
| 81 | int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr, | ||
| 82 | const char **fname, int *lineno) | ||
| 83 | { | ||
| 84 | Dwarf_Line *line; | ||
| 85 | Dwarf_Addr laddr; | ||
| 86 | |||
| 87 | line = dwarf_getsrc_die(cu_die, (Dwarf_Addr)addr); | ||
| 88 | if (line && dwarf_lineaddr(line, &laddr) == 0 && | ||
| 89 | addr == (unsigned long)laddr && dwarf_lineno(line, lineno) == 0) { | ||
| 90 | *fname = dwarf_linesrc(line, NULL, NULL); | ||
| 91 | if (!*fname) | ||
| 92 | /* line number is useless without filename */ | ||
| 93 | *lineno = 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | return *lineno ?: -ENOENT; | ||
| 97 | } | ||
| 98 | |||
| 99 | /** | ||
| 100 | * die_compare_name - Compare diename and tname | ||
| 101 | * @dw_die: a DIE | ||
| 102 | * @tname: a string of target name | ||
| 103 | * | ||
| 104 | * Compare the name of @dw_die and @tname. Return false if @dw_die has no name. | ||
| 105 | */ | ||
| 106 | bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | ||
| 107 | { | ||
| 108 | const char *name; | ||
| 109 | name = dwarf_diename(dw_die); | ||
| 110 | return name ? (strcmp(tname, name) == 0) : false; | ||
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * die_get_call_lineno - Get callsite line number of inline-function instance | ||
| 115 | * @in_die: a DIE of an inlined function instance | ||
| 116 | * | ||
| 117 | * Get call-site line number of @in_die. This means from where the inline | ||
| 118 | * function is called. | ||
| 119 | */ | ||
| 120 | int die_get_call_lineno(Dwarf_Die *in_die) | ||
| 121 | { | ||
| 122 | Dwarf_Attribute attr; | ||
| 123 | Dwarf_Word ret; | ||
| 124 | |||
| 125 | if (!dwarf_attr(in_die, DW_AT_call_line, &attr)) | ||
| 126 | return -ENOENT; | ||
| 127 | |||
| 128 | dwarf_formudata(&attr, &ret); | ||
| 129 | return (int)ret; | ||
| 130 | } | ||
| 131 | |||
| 132 | /** | ||
| 133 | * die_get_type - Get type DIE | ||
| 134 | * @vr_die: a DIE of a variable | ||
| 135 | * @die_mem: where to store a type DIE | ||
| 136 | * | ||
| 137 | * Get a DIE of the type of given variable (@vr_die), and store | ||
| 138 | * it to die_mem. Return NULL if fails to get a type DIE. | ||
| 139 | */ | ||
| 140 | Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 141 | { | ||
| 142 | Dwarf_Attribute attr; | ||
| 143 | |||
| 144 | if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) && | ||
| 145 | dwarf_formref_die(&attr, die_mem)) | ||
| 146 | return die_mem; | ||
| 147 | else | ||
| 148 | return NULL; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* Get a type die, but skip qualifiers */ | ||
| 152 | static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 153 | { | ||
| 154 | int tag; | ||
| 155 | |||
| 156 | do { | ||
| 157 | vr_die = die_get_type(vr_die, die_mem); | ||
| 158 | if (!vr_die) | ||
| 159 | break; | ||
| 160 | tag = dwarf_tag(vr_die); | ||
| 161 | } while (tag == DW_TAG_const_type || | ||
| 162 | tag == DW_TAG_restrict_type || | ||
| 163 | tag == DW_TAG_volatile_type || | ||
| 164 | tag == DW_TAG_shared_type); | ||
| 165 | |||
| 166 | return vr_die; | ||
| 167 | } | ||
| 168 | |||
| 169 | /** | ||
| 170 | * die_get_real_type - Get a type die, but skip qualifiers and typedef | ||
| 171 | * @vr_die: a DIE of a variable | ||
| 172 | * @die_mem: where to store a type DIE | ||
| 173 | * | ||
| 174 | * Get a DIE of the type of given variable (@vr_die), and store | ||
| 175 | * it to die_mem. Return NULL if fails to get a type DIE. | ||
| 176 | * If the type is qualifiers (e.g. const) or typedef, this skips it | ||
| 177 | * and tries to find real type (structure or basic types, e.g. int). | ||
| 178 | */ | ||
| 179 | Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 180 | { | ||
| 181 | do { | ||
| 182 | vr_die = __die_get_real_type(vr_die, die_mem); | ||
| 183 | } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef); | ||
| 184 | |||
| 185 | return vr_die; | ||
| 186 | } | ||
| 187 | |||
| 188 | /* Get attribute and translate it as a udata */ | ||
| 189 | static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, | ||
| 190 | Dwarf_Word *result) | ||
| 191 | { | ||
| 192 | Dwarf_Attribute attr; | ||
| 193 | |||
| 194 | if (dwarf_attr(tp_die, attr_name, &attr) == NULL || | ||
| 195 | dwarf_formudata(&attr, result) != 0) | ||
| 196 | return -ENOENT; | ||
| 197 | |||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 201 | /** | ||
| 202 | * die_is_signed_type - Check whether a type DIE is signed or not | ||
| 203 | * @tp_die: a DIE of a type | ||
| 204 | * | ||
| 205 | * Get the encoding of @tp_die and return true if the encoding | ||
| 206 | * is signed. | ||
| 207 | */ | ||
| 208 | bool die_is_signed_type(Dwarf_Die *tp_die) | ||
| 209 | { | ||
| 210 | Dwarf_Word ret; | ||
| 211 | |||
| 212 | if (die_get_attr_udata(tp_die, DW_AT_encoding, &ret)) | ||
| 213 | return false; | ||
| 214 | |||
| 215 | return (ret == DW_ATE_signed_char || ret == DW_ATE_signed || | ||
| 216 | ret == DW_ATE_signed_fixed); | ||
| 217 | } | ||
| 218 | |||
| 219 | /** | ||
| 220 | * die_get_data_member_location - Get the data-member offset | ||
| 221 | * @mb_die: a DIE of a member of a data structure | ||
| 222 | * @offs: The offset of the member in the data structure | ||
| 223 | * | ||
| 224 | * Get the offset of @mb_die in the data structure including @mb_die, and | ||
| 225 | * stores result offset to @offs. If any error occurs this returns errno. | ||
| 226 | */ | ||
| 227 | int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs) | ||
| 228 | { | ||
| 229 | Dwarf_Attribute attr; | ||
| 230 | Dwarf_Op *expr; | ||
| 231 | size_t nexpr; | ||
| 232 | int ret; | ||
| 233 | |||
| 234 | if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL) | ||
| 235 | return -ENOENT; | ||
| 236 | |||
| 237 | if (dwarf_formudata(&attr, offs) != 0) { | ||
| 238 | /* DW_AT_data_member_location should be DW_OP_plus_uconst */ | ||
| 239 | ret = dwarf_getlocation(&attr, &expr, &nexpr); | ||
| 240 | if (ret < 0 || nexpr == 0) | ||
| 241 | return -ENOENT; | ||
| 242 | |||
| 243 | if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) { | ||
| 244 | pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n", | ||
| 245 | expr[0].atom, nexpr); | ||
| 246 | return -ENOTSUP; | ||
| 247 | } | ||
| 248 | *offs = (Dwarf_Word)expr[0].number; | ||
| 249 | } | ||
| 250 | return 0; | ||
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | * die_find_child - Generic DIE search function in DIE tree | ||
| 255 | * @rt_die: a root DIE | ||
| 256 | * @callback: a callback function | ||
| 257 | * @data: a user data passed to the callback function | ||
| 258 | * @die_mem: a buffer for result DIE | ||
| 259 | * | ||
| 260 | * Trace DIE tree from @rt_die and call @callback for each child DIE. | ||
| 261 | * If @callback returns DIE_FIND_CB_END, this stores the DIE into | ||
| 262 | * @die_mem and returns it. If @callback returns DIE_FIND_CB_CONTINUE, | ||
| 263 | * this continues to trace the tree. Optionally, @callback can return | ||
| 264 | * DIE_FIND_CB_CHILD and DIE_FIND_CB_SIBLING, those means trace only | ||
| 265 | * the children and trace only the siblings respectively. | ||
| 266 | * Returns NULL if @callback can't find any appropriate DIE. | ||
| 267 | */ | ||
| 268 | Dwarf_Die *die_find_child(Dwarf_Die *rt_die, | ||
| 269 | int (*callback)(Dwarf_Die *, void *), | ||
| 270 | void *data, Dwarf_Die *die_mem) | ||
| 271 | { | ||
| 272 | Dwarf_Die child_die; | ||
| 273 | int ret; | ||
| 274 | |||
| 275 | ret = dwarf_child(rt_die, die_mem); | ||
| 276 | if (ret != 0) | ||
| 277 | return NULL; | ||
| 278 | |||
| 279 | do { | ||
| 280 | ret = callback(die_mem, data); | ||
| 281 | if (ret == DIE_FIND_CB_END) | ||
| 282 | return die_mem; | ||
| 283 | |||
| 284 | if ((ret & DIE_FIND_CB_CHILD) && | ||
| 285 | die_find_child(die_mem, callback, data, &child_die)) { | ||
| 286 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
| 287 | return die_mem; | ||
| 288 | } | ||
| 289 | } while ((ret & DIE_FIND_CB_SIBLING) && | ||
| 290 | dwarf_siblingof(die_mem, die_mem) == 0); | ||
| 291 | |||
| 292 | return NULL; | ||
| 293 | } | ||
| 294 | |||
| 295 | struct __addr_die_search_param { | ||
| 296 | Dwarf_Addr addr; | ||
| 297 | Dwarf_Die *die_mem; | ||
| 298 | }; | ||
| 299 | |||
| 300 | /* die_find callback for non-inlined function search */ | ||
| 301 | static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) | ||
| 302 | { | ||
| 303 | struct __addr_die_search_param *ad = data; | ||
| 304 | |||
| 305 | if (dwarf_tag(fn_die) == DW_TAG_subprogram && | ||
| 306 | dwarf_haspc(fn_die, ad->addr)) { | ||
| 307 | memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); | ||
| 308 | return DWARF_CB_ABORT; | ||
| 309 | } | ||
| 310 | return DWARF_CB_OK; | ||
| 311 | } | ||
| 312 | |||
| 313 | /** | ||
| 314 | * die_find_realfunc - Search a non-inlined function at given address | ||
| 315 | * @cu_die: a CU DIE which including @addr | ||
| 316 | * @addr: target address | ||
| 317 | * @die_mem: a buffer for result DIE | ||
| 318 | * | ||
| 319 | * Search a non-inlined function DIE which includes @addr. Stores the | ||
| 320 | * DIE to @die_mem and returns it if found. Returns NULl if failed. | ||
| 321 | */ | ||
| 322 | Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, | ||
| 323 | Dwarf_Die *die_mem) | ||
| 324 | { | ||
| 325 | struct __addr_die_search_param ad; | ||
| 326 | ad.addr = addr; | ||
| 327 | ad.die_mem = die_mem; | ||
| 328 | /* dwarf_getscopes can't find subprogram. */ | ||
| 329 | if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0)) | ||
| 330 | return NULL; | ||
| 331 | else | ||
| 332 | return die_mem; | ||
| 333 | } | ||
| 334 | |||
| 335 | /* die_find callback for inline function search */ | ||
| 336 | static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) | ||
| 337 | { | ||
| 338 | Dwarf_Addr *addr = data; | ||
| 339 | |||
| 340 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && | ||
| 341 | dwarf_haspc(die_mem, *addr)) | ||
| 342 | return DIE_FIND_CB_END; | ||
| 343 | |||
| 344 | return DIE_FIND_CB_CONTINUE; | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * die_find_inlinefunc - Search an inlined function at given address | ||
| 349 | * @cu_die: a CU DIE which including @addr | ||
| 350 | * @addr: target address | ||
| 351 | * @die_mem: a buffer for result DIE | ||
| 352 | * | ||
| 353 | * Search an inlined function DIE which includes @addr. Stores the | ||
| 354 | * DIE to @die_mem and returns it if found. Returns NULl if failed. | ||
| 355 | * If several inlined functions are expanded recursively, this trace | ||
| 356 | * it and returns deepest one. | ||
| 357 | */ | ||
| 358 | Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | ||
| 359 | Dwarf_Die *die_mem) | ||
| 360 | { | ||
| 361 | Dwarf_Die tmp_die; | ||
| 362 | |||
| 363 | sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr, &tmp_die); | ||
| 364 | if (!sp_die) | ||
| 365 | return NULL; | ||
| 366 | |||
| 367 | /* Inlined function could be recursive. Trace it until fail */ | ||
| 368 | while (sp_die) { | ||
| 369 | memcpy(die_mem, sp_die, sizeof(Dwarf_Die)); | ||
| 370 | sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr, | ||
| 371 | &tmp_die); | ||
| 372 | } | ||
| 373 | |||
| 374 | return die_mem; | ||
| 375 | } | ||
| 376 | |||
| 377 | /* Line walker internal parameters */ | ||
| 378 | struct __line_walk_param { | ||
| 379 | const char *fname; | ||
| 380 | line_walk_callback_t callback; | ||
| 381 | void *data; | ||
| 382 | int retval; | ||
| 383 | }; | ||
| 384 | |||
| 385 | static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data) | ||
| 386 | { | ||
| 387 | struct __line_walk_param *lw = data; | ||
| 388 | Dwarf_Addr addr; | ||
| 389 | int lineno; | ||
| 390 | |||
| 391 | if (dwarf_tag(in_die) == DW_TAG_inlined_subroutine) { | ||
| 392 | lineno = die_get_call_lineno(in_die); | ||
| 393 | if (lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) { | ||
| 394 | lw->retval = lw->callback(lw->fname, lineno, addr, | ||
| 395 | lw->data); | ||
| 396 | if (lw->retval != 0) | ||
| 397 | return DIE_FIND_CB_END; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | return DIE_FIND_CB_SIBLING; | ||
| 401 | } | ||
| 402 | |||
| 403 | /* Walk on lines of blocks included in given DIE */ | ||
| 404 | static int __die_walk_funclines(Dwarf_Die *sp_die, | ||
| 405 | line_walk_callback_t callback, void *data) | ||
| 406 | { | ||
| 407 | struct __line_walk_param lw = { | ||
| 408 | .callback = callback, | ||
| 409 | .data = data, | ||
| 410 | .retval = 0, | ||
| 411 | }; | ||
| 412 | Dwarf_Die die_mem; | ||
| 413 | Dwarf_Addr addr; | ||
| 414 | int lineno; | ||
| 415 | |||
| 416 | /* Handle function declaration line */ | ||
| 417 | lw.fname = dwarf_decl_file(sp_die); | ||
| 418 | if (lw.fname && dwarf_decl_line(sp_die, &lineno) == 0 && | ||
| 419 | dwarf_entrypc(sp_die, &addr) == 0) { | ||
| 420 | lw.retval = callback(lw.fname, lineno, addr, data); | ||
| 421 | if (lw.retval != 0) | ||
| 422 | goto done; | ||
| 423 | } | ||
| 424 | die_find_child(sp_die, __die_walk_funclines_cb, &lw, &die_mem); | ||
| 425 | done: | ||
| 426 | return lw.retval; | ||
| 427 | } | ||
| 428 | |||
| 429 | static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data) | ||
| 430 | { | ||
| 431 | struct __line_walk_param *lw = data; | ||
| 432 | |||
| 433 | lw->retval = __die_walk_funclines(sp_die, lw->callback, lw->data); | ||
| 434 | if (lw->retval != 0) | ||
| 435 | return DWARF_CB_ABORT; | ||
| 436 | |||
| 437 | return DWARF_CB_OK; | ||
| 438 | } | ||
| 439 | |||
| 440 | /** | ||
| 441 | * die_walk_lines - Walk on lines inside given DIE | ||
| 442 | * @rt_die: a root DIE (CU or subprogram) | ||
| 443 | * @callback: callback routine | ||
| 444 | * @data: user data | ||
| 445 | * | ||
| 446 | * Walk on all lines inside given @rt_die and call @callback on each line. | ||
| 447 | * If the @rt_die is a function, walk only on the lines inside the function, | ||
| 448 | * otherwise @rt_die must be a CU DIE. | ||
| 449 | * Note that this walks not only dwarf line list, but also function entries | ||
| 450 | * and inline call-site. | ||
| 451 | */ | ||
| 452 | int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data) | ||
| 453 | { | ||
| 454 | Dwarf_Lines *lines; | ||
| 455 | Dwarf_Line *line; | ||
| 456 | Dwarf_Addr addr; | ||
| 457 | const char *fname; | ||
| 458 | int lineno, ret = 0; | ||
| 459 | Dwarf_Die die_mem, *cu_die; | ||
| 460 | size_t nlines, i; | ||
| 461 | |||
| 462 | /* Get the CU die */ | ||
| 463 | if (dwarf_tag(rt_die) == DW_TAG_subprogram) | ||
| 464 | cu_die = dwarf_diecu(rt_die, &die_mem, NULL, NULL); | ||
| 465 | else | ||
| 466 | cu_die = rt_die; | ||
| 467 | if (!cu_die) { | ||
| 468 | pr_debug2("Failed to get CU from subprogram\n"); | ||
| 469 | return -EINVAL; | ||
| 470 | } | ||
| 471 | |||
| 472 | /* Get lines list in the CU */ | ||
| 473 | if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0) { | ||
| 474 | pr_debug2("Failed to get source lines on this CU.\n"); | ||
| 475 | return -ENOENT; | ||
| 476 | } | ||
| 477 | pr_debug2("Get %zd lines from this CU\n", nlines); | ||
| 478 | |||
| 479 | /* Walk on the lines on lines list */ | ||
| 480 | for (i = 0; i < nlines; i++) { | ||
| 481 | line = dwarf_onesrcline(lines, i); | ||
| 482 | if (line == NULL || | ||
| 483 | dwarf_lineno(line, &lineno) != 0 || | ||
| 484 | dwarf_lineaddr(line, &addr) != 0) { | ||
| 485 | pr_debug2("Failed to get line info. " | ||
| 486 | "Possible error in debuginfo.\n"); | ||
| 487 | continue; | ||
| 488 | } | ||
| 489 | /* Filter lines based on address */ | ||
| 490 | if (rt_die != cu_die) | ||
| 491 | /* | ||
| 492 | * Address filtering | ||
| 493 | * The line is included in given function, and | ||
| 494 | * no inline block includes it. | ||
| 495 | */ | ||
| 496 | if (!dwarf_haspc(rt_die, addr) || | ||
| 497 | die_find_inlinefunc(rt_die, addr, &die_mem)) | ||
| 498 | continue; | ||
| 499 | /* Get source line */ | ||
| 500 | fname = dwarf_linesrc(line, NULL, NULL); | ||
| 501 | |||
| 502 | ret = callback(fname, lineno, addr, data); | ||
| 503 | if (ret != 0) | ||
| 504 | return ret; | ||
| 505 | } | ||
| 506 | |||
| 507 | /* | ||
| 508 | * Dwarf lines doesn't include function declarations and inlined | ||
| 509 | * subroutines. We have to check functions list or given function. | ||
| 510 | */ | ||
| 511 | if (rt_die != cu_die) | ||
| 512 | ret = __die_walk_funclines(rt_die, callback, data); | ||
| 513 | else { | ||
| 514 | struct __line_walk_param param = { | ||
| 515 | .callback = callback, | ||
| 516 | .data = data, | ||
| 517 | .retval = 0, | ||
| 518 | }; | ||
| 519 | dwarf_getfuncs(cu_die, __die_walk_culines_cb, ¶m, 0); | ||
| 520 | ret = param.retval; | ||
| 521 | } | ||
| 522 | |||
| 523 | return ret; | ||
| 524 | } | ||
| 525 | |||
| 526 | struct __find_variable_param { | ||
| 527 | const char *name; | ||
| 528 | Dwarf_Addr addr; | ||
| 529 | }; | ||
| 530 | |||
| 531 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) | ||
| 532 | { | ||
| 533 | struct __find_variable_param *fvp = data; | ||
| 534 | int tag; | ||
| 535 | |||
| 536 | tag = dwarf_tag(die_mem); | ||
| 537 | if ((tag == DW_TAG_formal_parameter || | ||
| 538 | tag == DW_TAG_variable) && | ||
| 539 | die_compare_name(die_mem, fvp->name)) | ||
| 540 | return DIE_FIND_CB_END; | ||
| 541 | |||
| 542 | if (dwarf_haspc(die_mem, fvp->addr)) | ||
| 543 | return DIE_FIND_CB_CONTINUE; | ||
| 544 | else | ||
| 545 | return DIE_FIND_CB_SIBLING; | ||
| 546 | } | ||
| 547 | |||
| 548 | /** | ||
| 549 | * die_find_variable_at - Find a given name variable at given address | ||
| 550 | * @sp_die: a function DIE | ||
| 551 | * @name: variable name | ||
| 552 | * @addr: address | ||
| 553 | * @die_mem: a buffer for result DIE | ||
| 554 | * | ||
| 555 | * Find a variable DIE called @name at @addr in @sp_die. | ||
| 556 | */ | ||
| 557 | Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, | ||
| 558 | Dwarf_Addr addr, Dwarf_Die *die_mem) | ||
| 559 | { | ||
| 560 | struct __find_variable_param fvp = { .name = name, .addr = addr}; | ||
| 561 | |||
| 562 | return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp, | ||
| 563 | die_mem); | ||
| 564 | } | ||
| 565 | |||
| 566 | static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) | ||
| 567 | { | ||
| 568 | const char *name = data; | ||
| 569 | |||
| 570 | if ((dwarf_tag(die_mem) == DW_TAG_member) && | ||
| 571 | die_compare_name(die_mem, name)) | ||
| 572 | return DIE_FIND_CB_END; | ||
| 573 | |||
| 574 | return DIE_FIND_CB_SIBLING; | ||
| 575 | } | ||
| 576 | |||
| 577 | /** | ||
| 578 | * die_find_member - Find a given name member in a data structure | ||
| 579 | * @st_die: a data structure type DIE | ||
| 580 | * @name: member name | ||
| 581 | * @die_mem: a buffer for result DIE | ||
| 582 | * | ||
| 583 | * Find a member DIE called @name in @st_die. | ||
| 584 | */ | ||
| 585 | Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | ||
| 586 | Dwarf_Die *die_mem) | ||
| 587 | { | ||
| 588 | return die_find_child(st_die, __die_find_member_cb, (void *)name, | ||
| 589 | die_mem); | ||
| 590 | } | ||
| 591 | |||
| 592 | /** | ||
| 593 | * die_get_typename - Get the name of given variable DIE | ||
| 594 | * @vr_die: a variable DIE | ||
| 595 | * @buf: a buffer for result type name | ||
| 596 | * @len: a max-length of @buf | ||
| 597 | * | ||
| 598 | * Get the name of @vr_die and stores it to @buf. Return the actual length | ||
| 599 | * of type name if succeeded. Return -E2BIG if @len is not enough long, and | ||
| 600 | * Return -ENOENT if failed to find type name. | ||
| 601 | * Note that the result will stores typedef name if possible, and stores | ||
| 602 | * "*(function_type)" if the type is a function pointer. | ||
| 603 | */ | ||
| 604 | int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) | ||
| 605 | { | ||
| 606 | Dwarf_Die type; | ||
| 607 | int tag, ret, ret2; | ||
| 608 | const char *tmp = ""; | ||
| 609 | |||
| 610 | if (__die_get_real_type(vr_die, &type) == NULL) | ||
| 611 | return -ENOENT; | ||
| 612 | |||
| 613 | tag = dwarf_tag(&type); | ||
| 614 | if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type) | ||
| 615 | tmp = "*"; | ||
| 616 | else if (tag == DW_TAG_subroutine_type) { | ||
| 617 | /* Function pointer */ | ||
| 618 | ret = snprintf(buf, len, "(function_type)"); | ||
| 619 | return (ret >= len) ? -E2BIG : ret; | ||
| 620 | } else { | ||
| 621 | if (!dwarf_diename(&type)) | ||
| 622 | return -ENOENT; | ||
| 623 | if (tag == DW_TAG_union_type) | ||
| 624 | tmp = "union "; | ||
| 625 | else if (tag == DW_TAG_structure_type) | ||
| 626 | tmp = "struct "; | ||
| 627 | /* Write a base name */ | ||
| 628 | ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type)); | ||
| 629 | return (ret >= len) ? -E2BIG : ret; | ||
| 630 | } | ||
| 631 | ret = die_get_typename(&type, buf, len); | ||
| 632 | if (ret > 0) { | ||
| 633 | ret2 = snprintf(buf + ret, len - ret, "%s", tmp); | ||
| 634 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
| 635 | } | ||
| 636 | return ret; | ||
| 637 | } | ||
| 638 | |||
| 639 | /** | ||
| 640 | * die_get_varname - Get the name and type of given variable DIE | ||
| 641 | * @vr_die: a variable DIE | ||
| 642 | * @buf: a buffer for type and variable name | ||
| 643 | * @len: the max-length of @buf | ||
| 644 | * | ||
| 645 | * Get the name and type of @vr_die and stores it in @buf as "type\tname". | ||
| 646 | */ | ||
| 647 | int die_get_varname(Dwarf_Die *vr_die, char *buf, int len) | ||
| 648 | { | ||
| 649 | int ret, ret2; | ||
| 650 | |||
| 651 | ret = die_get_typename(vr_die, buf, len); | ||
| 652 | if (ret < 0) { | ||
| 653 | pr_debug("Failed to get type, make it unknown.\n"); | ||
| 654 | ret = snprintf(buf, len, "(unknown_type)"); | ||
| 655 | } | ||
| 656 | if (ret > 0) { | ||
| 657 | ret2 = snprintf(buf + ret, len - ret, "\t%s", | ||
| 658 | dwarf_diename(vr_die)); | ||
| 659 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
| 660 | } | ||
| 661 | return ret; | ||
| 662 | } | ||
| 663 | |||
diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h new file mode 100644 index 000000000000..bc3b21167e70 --- /dev/null +++ b/tools/perf/util/dwarf-aux.h | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | #ifndef _DWARF_AUX_H | ||
| 2 | #define _DWARF_AUX_H | ||
| 3 | /* | ||
| 4 | * dwarf-aux.h : libdw auxiliary interfaces | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <dwarf.h> | ||
| 23 | #include <elfutils/libdw.h> | ||
| 24 | #include <elfutils/libdwfl.h> | ||
| 25 | #include <elfutils/version.h> | ||
| 26 | |||
| 27 | /* Find the realpath of the target file */ | ||
| 28 | extern const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname); | ||
| 29 | |||
| 30 | /* Get DW_AT_comp_dir (should be NULL with older gcc) */ | ||
| 31 | extern const char *cu_get_comp_dir(Dwarf_Die *cu_die); | ||
| 32 | |||
| 33 | /* Get a line number and file name for given address */ | ||
| 34 | extern int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr, | ||
| 35 | const char **fname, int *lineno); | ||
| 36 | |||
| 37 | /* Compare diename and tname */ | ||
| 38 | extern bool die_compare_name(Dwarf_Die *dw_die, const char *tname); | ||
| 39 | |||
| 40 | /* Get callsite line number of inline-function instance */ | ||
| 41 | extern int die_get_call_lineno(Dwarf_Die *in_die); | ||
| 42 | |||
| 43 | /* Get type die */ | ||
| 44 | extern Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); | ||
| 45 | |||
| 46 | /* Get a type die, but skip qualifiers and typedef */ | ||
| 47 | extern Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); | ||
| 48 | |||
| 49 | /* Check whether the DIE is signed or not */ | ||
| 50 | extern bool die_is_signed_type(Dwarf_Die *tp_die); | ||
| 51 | |||
| 52 | /* Get data_member_location offset */ | ||
| 53 | extern int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs); | ||
| 54 | |||
| 55 | /* Return values for die_find_child() callbacks */ | ||
| 56 | enum { | ||
| 57 | DIE_FIND_CB_END = 0, /* End of Search */ | ||
| 58 | DIE_FIND_CB_CHILD = 1, /* Search only children */ | ||
| 59 | DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ | ||
| 60 | DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ | ||
| 61 | }; | ||
| 62 | |||
| 63 | /* Search child DIEs */ | ||
| 64 | extern Dwarf_Die *die_find_child(Dwarf_Die *rt_die, | ||
| 65 | int (*callback)(Dwarf_Die *, void *), | ||
| 66 | void *data, Dwarf_Die *die_mem); | ||
| 67 | |||
| 68 | /* Search a non-inlined function including given address */ | ||
| 69 | extern Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, | ||
| 70 | Dwarf_Die *die_mem); | ||
| 71 | |||
| 72 | /* Search an inlined function including given address */ | ||
| 73 | extern Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | ||
| 74 | Dwarf_Die *die_mem); | ||
| 75 | |||
| 76 | /* Walker on lines (Note: line number will not be sorted) */ | ||
| 77 | typedef int (* line_walk_callback_t) (const char *fname, int lineno, | ||
| 78 | Dwarf_Addr addr, void *data); | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Walk on lines inside given DIE. If the DIE is a subprogram, walk only on | ||
| 82 | * the lines inside the subprogram, otherwise the DIE must be a CU DIE. | ||
| 83 | */ | ||
| 84 | extern int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, | ||
| 85 | void *data); | ||
| 86 | |||
| 87 | /* Find a variable called 'name' at given address */ | ||
| 88 | extern Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, | ||
| 89 | Dwarf_Addr addr, Dwarf_Die *die_mem); | ||
| 90 | |||
| 91 | /* Find a member called 'name' */ | ||
| 92 | extern Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | ||
| 93 | Dwarf_Die *die_mem); | ||
| 94 | |||
| 95 | /* Get the name of given variable DIE */ | ||
| 96 | extern int die_get_typename(Dwarf_Die *vr_die, char *buf, int len); | ||
| 97 | |||
| 98 | /* Get the name and type of given variable DIE, stored as "type\tname" */ | ||
| 99 | extern int die_get_varname(Dwarf_Die *vr_die, char *buf, int len); | ||
| 100 | #endif | ||
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index f0223166e761..b82d54fa2c56 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -117,6 +117,10 @@ static struct map *kernel_get_module_map(const char *module) | |||
| 117 | struct rb_node *nd; | 117 | struct rb_node *nd; |
| 118 | struct map_groups *grp = &machine.kmaps; | 118 | struct map_groups *grp = &machine.kmaps; |
| 119 | 119 | ||
| 120 | /* A file path -- this is an offline module */ | ||
| 121 | if (module && strchr(module, '/')) | ||
| 122 | return machine__new_module(&machine, 0, module); | ||
| 123 | |||
| 120 | if (!module) | 124 | if (!module) |
| 121 | module = "kernel"; | 125 | module = "kernel"; |
| 122 | 126 | ||
| @@ -170,16 +174,24 @@ const char *kernel_get_module_path(const char *module) | |||
| 170 | } | 174 | } |
| 171 | 175 | ||
| 172 | #ifdef DWARF_SUPPORT | 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) | ||
| 174 | { | 179 | { |
| 175 | const char *path = kernel_get_module_path(module); | 180 | const char *path; |
| 176 | if (!path) { | 181 | |
| 177 | pr_err("Failed to find path of %s module.\n", | 182 | /* A file path -- this is an offline module */ |
| 178 | module ?: "kernel"); | 183 | if (module && strchr(module, '/')) |
| 179 | return -ENOENT; | 184 | path = module; |
| 185 | else { | ||
| 186 | path = kernel_get_module_path(module); | ||
| 187 | |||
| 188 | if (!path) { | ||
| 189 | pr_err("Failed to find path of %s module.\n", | ||
| 190 | module ?: "kernel"); | ||
| 191 | return NULL; | ||
| 192 | } | ||
| 180 | } | 193 | } |
| 181 | pr_debug("Try to open %s\n", path); | 194 | return debuginfo__new(path); |
| 182 | return open(path, O_RDONLY); | ||
| 183 | } | 195 | } |
| 184 | 196 | ||
| 185 | /* | 197 | /* |
| @@ -193,13 +205,24 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | |||
| 193 | struct map *map; | 205 | struct map *map; |
| 194 | u64 addr; | 206 | u64 addr; |
| 195 | int ret = -ENOENT; | 207 | int ret = -ENOENT; |
| 208 | struct debuginfo *dinfo; | ||
| 196 | 209 | ||
| 197 | sym = __find_kernel_function_by_name(tp->symbol, &map); | 210 | sym = __find_kernel_function_by_name(tp->symbol, &map); |
| 198 | if (sym) { | 211 | if (sym) { |
| 199 | addr = map->unmap_ip(map, sym->start + tp->offset); | 212 | addr = map->unmap_ip(map, sym->start + tp->offset); |
| 200 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, | 213 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, |
| 201 | tp->offset, addr); | 214 | tp->offset, addr); |
| 202 | ret = find_perf_probe_point((unsigned long)addr, pp); | 215 | |
| 216 | dinfo = debuginfo__new_online_kernel(addr); | ||
| 217 | if (dinfo) { | ||
| 218 | ret = debuginfo__find_probe_point(dinfo, | ||
| 219 | (unsigned long)addr, pp); | ||
| 220 | debuginfo__delete(dinfo); | ||
| 221 | } else { | ||
| 222 | pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n", | ||
| 223 | addr); | ||
| 224 | ret = -ENOENT; | ||
| 225 | } | ||
| 203 | } | 226 | } |
| 204 | if (ret <= 0) { | 227 | if (ret <= 0) { |
| 205 | pr_debug("Failed to find corresponding probes from " | 228 | pr_debug("Failed to find corresponding probes from " |
| @@ -214,30 +237,70 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | |||
| 214 | return 0; | 237 | return 0; |
| 215 | } | 238 | } |
| 216 | 239 | ||
| 240 | static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, | ||
| 241 | int ntevs, const char *module) | ||
| 242 | { | ||
| 243 | int i, ret = 0; | ||
| 244 | char *tmp; | ||
| 245 | |||
| 246 | if (!module) | ||
| 247 | return 0; | ||
| 248 | |||
| 249 | tmp = strrchr(module, '/'); | ||
| 250 | if (tmp) { | ||
| 251 | /* This is a module path -- get the module name */ | ||
| 252 | module = strdup(tmp + 1); | ||
| 253 | if (!module) | ||
| 254 | return -ENOMEM; | ||
| 255 | tmp = strchr(module, '.'); | ||
| 256 | if (tmp) | ||
| 257 | *tmp = '\0'; | ||
| 258 | tmp = (char *)module; /* For free() */ | ||
| 259 | } | ||
| 260 | |||
| 261 | for (i = 0; i < ntevs; i++) { | ||
| 262 | tevs[i].point.module = strdup(module); | ||
| 263 | if (!tevs[i].point.module) { | ||
| 264 | ret = -ENOMEM; | ||
| 265 | break; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | if (tmp) | ||
| 270 | free(tmp); | ||
| 271 | |||
| 272 | return ret; | ||
| 273 | } | ||
| 274 | |||
| 217 | /* Try to find perf_probe_event with debuginfo */ | 275 | /* Try to find perf_probe_event with debuginfo */ |
| 218 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | 276 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
| 219 | struct probe_trace_event **tevs, | 277 | struct probe_trace_event **tevs, |
| 220 | int max_tevs, const char *module) | 278 | int max_tevs, const char *module) |
| 221 | { | 279 | { |
| 222 | bool need_dwarf = perf_probe_event_need_dwarf(pev); | 280 | bool need_dwarf = perf_probe_event_need_dwarf(pev); |
| 223 | int fd, ntevs; | 281 | struct debuginfo *dinfo = open_debuginfo(module); |
| 282 | int ntevs, ret = 0; | ||
| 224 | 283 | ||
| 225 | fd = open_vmlinux(module); | 284 | if (!dinfo) { |
| 226 | if (fd < 0) { | ||
| 227 | if (need_dwarf) { | 285 | if (need_dwarf) { |
| 228 | pr_warning("Failed to open debuginfo file.\n"); | 286 | pr_warning("Failed to open debuginfo file.\n"); |
| 229 | return fd; | 287 | return -ENOENT; |
| 230 | } | 288 | } |
| 231 | pr_debug("Could not open vmlinux. Try to use symbols.\n"); | 289 | pr_debug("Could not open debuginfo. Try to use symbols.\n"); |
| 232 | return 0; | 290 | return 0; |
| 233 | } | 291 | } |
| 234 | 292 | ||
| 235 | /* Searching trace events corresponding to probe event */ | 293 | /* Searching trace events corresponding to a probe event */ |
| 236 | ntevs = find_probe_trace_events(fd, pev, tevs, max_tevs); | 294 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs); |
| 295 | |||
| 296 | debuginfo__delete(dinfo); | ||
| 237 | 297 | ||
| 238 | if (ntevs > 0) { /* Succeeded to find trace events */ | 298 | if (ntevs > 0) { /* Succeeded to find trace events */ |
| 239 | pr_debug("find %d probe_trace_events.\n", ntevs); | 299 | pr_debug("find %d probe_trace_events.\n", ntevs); |
| 240 | return ntevs; | 300 | if (module) |
| 301 | ret = add_module_to_probe_trace_events(*tevs, ntevs, | ||
| 302 | module); | ||
| 303 | return ret < 0 ? ret : ntevs; | ||
| 241 | } | 304 | } |
| 242 | 305 | ||
| 243 | if (ntevs == 0) { /* No error but failed to find probe point. */ | 306 | if (ntevs == 0) { /* No error but failed to find probe point. */ |
| @@ -371,8 +434,9 @@ int show_line_range(struct line_range *lr, const char *module) | |||
| 371 | { | 434 | { |
| 372 | int l = 1; | 435 | int l = 1; |
| 373 | struct line_node *ln; | 436 | struct line_node *ln; |
| 437 | struct debuginfo *dinfo; | ||
| 374 | FILE *fp; | 438 | FILE *fp; |
| 375 | int fd, ret; | 439 | int ret; |
| 376 | char *tmp; | 440 | char *tmp; |
| 377 | 441 | ||
| 378 | /* Search a line range */ | 442 | /* Search a line range */ |
| @@ -380,13 +444,14 @@ int show_line_range(struct line_range *lr, const char *module) | |||
| 380 | if (ret < 0) | 444 | if (ret < 0) |
| 381 | return ret; | 445 | return ret; |
| 382 | 446 | ||
| 383 | fd = open_vmlinux(module); | 447 | dinfo = open_debuginfo(module); |
| 384 | if (fd < 0) { | 448 | if (!dinfo) { |
| 385 | pr_warning("Failed to open debuginfo file.\n"); | 449 | pr_warning("Failed to open debuginfo file.\n"); |
| 386 | return fd; | 450 | return -ENOENT; |
| 387 | } | 451 | } |
| 388 | 452 | ||
| 389 | ret = find_line_range(fd, lr); | 453 | ret = debuginfo__find_line_range(dinfo, lr); |
| 454 | debuginfo__delete(dinfo); | ||
| 390 | if (ret == 0) { | 455 | if (ret == 0) { |
| 391 | pr_warning("Specified source line is not found.\n"); | 456 | pr_warning("Specified source line is not found.\n"); |
| 392 | return -ENOENT; | 457 | return -ENOENT; |
| @@ -448,7 +513,8 @@ end: | |||
| 448 | return ret; | 513 | return ret; |
| 449 | } | 514 | } |
| 450 | 515 | ||
| 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 | int max_vls, struct strfilter *_filter, | 518 | int max_vls, struct strfilter *_filter, |
| 453 | bool externs) | 519 | bool externs) |
| 454 | { | 520 | { |
| @@ -463,7 +529,8 @@ static int show_available_vars_at(int fd, struct perf_probe_event *pev, | |||
| 463 | return -EINVAL; | 529 | return -EINVAL; |
| 464 | pr_debug("Searching variables at %s\n", buf); | 530 | pr_debug("Searching variables at %s\n", buf); |
| 465 | 531 | ||
| 466 | ret = find_available_vars_at(fd, pev, &vls, max_vls, externs); | 532 | ret = debuginfo__find_available_vars_at(dinfo, pev, &vls, |
| 533 | max_vls, externs); | ||
| 467 | if (ret <= 0) { | 534 | if (ret <= 0) { |
| 468 | pr_err("Failed to find variables at %s (%d)\n", buf, ret); | 535 | pr_err("Failed to find variables at %s (%d)\n", buf, ret); |
| 469 | goto end; | 536 | goto end; |
| @@ -504,24 +571,26 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs, | |||
| 504 | int max_vls, const char *module, | 571 | int max_vls, const char *module, |
| 505 | struct strfilter *_filter, bool externs) | 572 | struct strfilter *_filter, bool externs) |
| 506 | { | 573 | { |
| 507 | int i, fd, ret = 0; | 574 | int i, ret = 0; |
| 575 | struct debuginfo *dinfo; | ||
| 508 | 576 | ||
| 509 | ret = init_vmlinux(); | 577 | ret = init_vmlinux(); |
| 510 | if (ret < 0) | 578 | if (ret < 0) |
| 511 | return ret; | 579 | return ret; |
| 512 | 580 | ||
| 581 | dinfo = open_debuginfo(module); | ||
| 582 | if (!dinfo) { | ||
| 583 | pr_warning("Failed to open debuginfo file.\n"); | ||
| 584 | return -ENOENT; | ||
| 585 | } | ||
| 586 | |||
| 513 | setup_pager(); | 587 | setup_pager(); |
| 514 | 588 | ||
| 515 | for (i = 0; i < npevs && ret >= 0; i++) { | 589 | for (i = 0; i < npevs && ret >= 0; i++) |
| 516 | fd = open_vmlinux(module); | 590 | ret = show_available_vars_at(dinfo, &pevs[i], max_vls, _filter, |
| 517 | if (fd < 0) { | ||
| 518 | pr_warning("Failed to open debug information file.\n"); | ||
| 519 | ret = fd; | ||
| 520 | break; | ||
| 521 | } | ||
| 522 | ret = show_available_vars_at(fd, &pevs[i], max_vls, _filter, | ||
| 523 | externs); | 591 | externs); |
| 524 | } | 592 | |
| 593 | debuginfo__delete(dinfo); | ||
| 525 | return ret; | 594 | return ret; |
| 526 | } | 595 | } |
| 527 | 596 | ||
| @@ -990,7 +1059,7 @@ bool perf_probe_event_need_dwarf(struct perf_probe_event *pev) | |||
| 990 | 1059 | ||
| 991 | /* Parse probe_events event into struct probe_point */ | 1060 | /* Parse probe_events event into struct probe_point */ |
| 992 | static int parse_probe_trace_command(const char *cmd, | 1061 | static int parse_probe_trace_command(const char *cmd, |
| 993 | struct probe_trace_event *tev) | 1062 | struct probe_trace_event *tev) |
| 994 | { | 1063 | { |
| 995 | struct probe_trace_point *tp = &tev->point; | 1064 | struct probe_trace_point *tp = &tev->point; |
| 996 | char pr; | 1065 | char pr; |
| @@ -1023,8 +1092,14 @@ static int parse_probe_trace_command(const char *cmd, | |||
| 1023 | 1092 | ||
| 1024 | tp->retprobe = (pr == 'r'); | 1093 | tp->retprobe = (pr == 'r'); |
| 1025 | 1094 | ||
| 1026 | /* Scan function name and offset */ | 1095 | /* Scan module name(if there), function name and offset */ |
| 1027 | ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol, | 1096 | p = strchr(argv[1], ':'); |
| 1097 | if (p) { | ||
| 1098 | tp->module = strndup(argv[1], p - argv[1]); | ||
| 1099 | p++; | ||
| 1100 | } else | ||
| 1101 | p = argv[1]; | ||
| 1102 | ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol, | ||
| 1028 | &tp->offset); | 1103 | &tp->offset); |
| 1029 | if (ret == 1) | 1104 | if (ret == 1) |
| 1030 | tp->offset = 0; | 1105 | tp->offset = 0; |
| @@ -1269,9 +1344,10 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev) | |||
| 1269 | if (buf == NULL) | 1344 | if (buf == NULL) |
| 1270 | return NULL; | 1345 | return NULL; |
| 1271 | 1346 | ||
| 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 | tp->retprobe ? 'r' : 'p', | 1348 | tp->retprobe ? 'r' : 'p', |
| 1274 | tev->group, tev->event, | 1349 | tev->group, tev->event, |
| 1350 | tp->module ?: "", tp->module ? ":" : "", | ||
| 1275 | tp->symbol, tp->offset); | 1351 | tp->symbol, tp->offset); |
| 1276 | if (len <= 0) | 1352 | if (len <= 0) |
| 1277 | goto error; | 1353 | goto error; |
| @@ -1378,6 +1454,8 @@ static void clear_probe_trace_event(struct probe_trace_event *tev) | |||
| 1378 | free(tev->group); | 1454 | free(tev->group); |
| 1379 | if (tev->point.symbol) | 1455 | if (tev->point.symbol) |
| 1380 | free(tev->point.symbol); | 1456 | free(tev->point.symbol); |
| 1457 | if (tev->point.module) | ||
| 1458 | free(tev->point.module); | ||
| 1381 | for (i = 0; i < tev->nargs; i++) { | 1459 | for (i = 0; i < tev->nargs; i++) { |
| 1382 | if (tev->args[i].name) | 1460 | if (tev->args[i].name) |
| 1383 | free(tev->args[i].name); | 1461 | free(tev->args[i].name); |
| @@ -1729,7 +1807,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, | |||
| 1729 | /* Convert perf_probe_event with debuginfo */ | 1807 | /* Convert perf_probe_event with debuginfo */ |
| 1730 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module); | 1808 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module); |
| 1731 | if (ret != 0) | 1809 | if (ret != 0) |
| 1732 | return ret; | 1810 | return ret; /* Found in debuginfo or got an error */ |
| 1733 | 1811 | ||
| 1734 | /* Allocate trace event buffer */ | 1812 | /* Allocate trace event buffer */ |
| 1735 | tev = *tevs = zalloc(sizeof(struct probe_trace_event)); | 1813 | tev = *tevs = zalloc(sizeof(struct probe_trace_event)); |
| @@ -1742,6 +1820,11 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, | |||
| 1742 | ret = -ENOMEM; | 1820 | ret = -ENOMEM; |
| 1743 | goto error; | 1821 | goto error; |
| 1744 | } | 1822 | } |
| 1823 | tev->point.module = strdup(module); | ||
| 1824 | if (tev->point.module == NULL) { | ||
| 1825 | ret = -ENOMEM; | ||
| 1826 | goto error; | ||
| 1827 | } | ||
| 1745 | tev->point.offset = pev->point.offset; | 1828 | tev->point.offset = pev->point.offset; |
| 1746 | tev->point.retprobe = pev->point.retprobe; | 1829 | tev->point.retprobe = pev->point.retprobe; |
| 1747 | tev->nargs = pev->nargs; | 1830 | tev->nargs = pev->nargs; |
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 3434fc9d79d5..a7dee835f49c 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
| @@ -10,6 +10,7 @@ extern bool probe_event_dry_run; | |||
| 10 | /* kprobe-tracer tracing point */ | 10 | /* kprobe-tracer tracing point */ |
| 11 | struct probe_trace_point { | 11 | struct probe_trace_point { |
| 12 | char *symbol; /* Base symbol */ | 12 | char *symbol; /* Base symbol */ |
| 13 | char *module; /* Module name */ | ||
| 13 | unsigned long offset; /* Offset from symbol */ | 14 | unsigned long offset; /* Offset from symbol */ |
| 14 | bool retprobe; /* Return probe flag */ | 15 | bool retprobe; /* Return probe flag */ |
| 15 | }; | 16 | }; |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 3b9d0b800d5c..3e44a3e36519 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
| @@ -43,21 +43,6 @@ | |||
| 43 | /* Kprobe tracer basic type is up to u64 */ | 43 | /* Kprobe tracer basic type is up to u64 */ |
| 44 | #define MAX_BASIC_TYPE_BITS 64 | 44 | #define MAX_BASIC_TYPE_BITS 64 |
| 45 | 45 | ||
| 46 | /* | ||
| 47 | * Compare the tail of two strings. | ||
| 48 | * Return 0 if whole of either string is same as another's tail part. | ||
| 49 | */ | ||
| 50 | static int strtailcmp(const char *s1, const char *s2) | ||
| 51 | { | ||
| 52 | int i1 = strlen(s1); | ||
| 53 | int i2 = strlen(s2); | ||
| 54 | while (--i1 >= 0 && --i2 >= 0) { | ||
| 55 | if (s1[i1] != s2[i2]) | ||
| 56 | return s1[i1] - s2[i2]; | ||
| 57 | } | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* Line number list operations */ | 46 | /* Line number list operations */ |
| 62 | 47 | ||
| 63 | /* Add a line to line number list */ | 48 | /* Add a line to line number list */ |
| @@ -131,29 +116,37 @@ static const Dwfl_Callbacks offline_callbacks = { | |||
| 131 | }; | 116 | }; |
| 132 | 117 | ||
| 133 | /* Get a Dwarf from offline image */ | 118 | /* Get a Dwarf from offline image */ |
| 134 | static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias) | 119 | static int debuginfo__init_offline_dwarf(struct debuginfo *self, |
| 120 | const char *path) | ||
| 135 | { | 121 | { |
| 136 | Dwfl_Module *mod; | 122 | Dwfl_Module *mod; |
| 137 | Dwarf *dbg = NULL; | 123 | int fd; |
| 138 | 124 | ||
| 139 | if (!dwflp) | 125 | fd = open(path, O_RDONLY); |
| 140 | return NULL; | 126 | if (fd < 0) |
| 127 | return fd; | ||
| 141 | 128 | ||
| 142 | *dwflp = dwfl_begin(&offline_callbacks); | 129 | self->dwfl = dwfl_begin(&offline_callbacks); |
| 143 | if (!*dwflp) | 130 | if (!self->dwfl) |
| 144 | return NULL; | 131 | goto error; |
| 145 | 132 | ||
| 146 | mod = dwfl_report_offline(*dwflp, "", "", fd); | 133 | mod = dwfl_report_offline(self->dwfl, "", "", fd); |
| 147 | if (!mod) | 134 | if (!mod) |
| 148 | goto error; | 135 | goto error; |
| 149 | 136 | ||
| 150 | dbg = dwfl_module_getdwarf(mod, bias); | 137 | self->dbg = dwfl_module_getdwarf(mod, &self->bias); |
| 151 | if (!dbg) { | 138 | if (!self->dbg) |
| 139 | goto error; | ||
| 140 | |||
| 141 | return 0; | ||
| 152 | error: | 142 | error: |
| 153 | dwfl_end(*dwflp); | 143 | if (self->dwfl) |
| 154 | *dwflp = NULL; | 144 | dwfl_end(self->dwfl); |
| 155 | } | 145 | else |
| 156 | return dbg; | 146 | close(fd); |
| 147 | memset(self, 0, sizeof(*self)); | ||
| 148 | |||
| 149 | return -ENOENT; | ||
| 157 | } | 150 | } |
| 158 | 151 | ||
| 159 | #if _ELFUTILS_PREREQ(0, 148) | 152 | #if _ELFUTILS_PREREQ(0, 148) |
| @@ -189,597 +182,81 @@ static const Dwfl_Callbacks kernel_callbacks = { | |||
| 189 | }; | 182 | }; |
| 190 | 183 | ||
| 191 | /* Get a Dwarf from live kernel image */ | 184 | /* Get a Dwarf from live kernel image */ |
| 192 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp, | 185 | static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self, |
| 193 | Dwarf_Addr *bias) | 186 | Dwarf_Addr addr) |
| 194 | { | 187 | { |
| 195 | Dwarf *dbg; | 188 | self->dwfl = dwfl_begin(&kernel_callbacks); |
| 196 | 189 | if (!self->dwfl) | |
| 197 | if (!dwflp) | 190 | return -EINVAL; |
| 198 | return NULL; | ||
| 199 | |||
| 200 | *dwflp = dwfl_begin(&kernel_callbacks); | ||
| 201 | if (!*dwflp) | ||
| 202 | return NULL; | ||
| 203 | 191 | ||
| 204 | /* Load the kernel dwarves: Don't care the result here */ | 192 | /* Load the kernel dwarves: Don't care the result here */ |
| 205 | dwfl_linux_kernel_report_kernel(*dwflp); | 193 | dwfl_linux_kernel_report_kernel(self->dwfl); |
| 206 | dwfl_linux_kernel_report_modules(*dwflp); | 194 | dwfl_linux_kernel_report_modules(self->dwfl); |
| 207 | 195 | ||
| 208 | dbg = dwfl_addrdwarf(*dwflp, addr, bias); | 196 | self->dbg = dwfl_addrdwarf(self->dwfl, addr, &self->bias); |
| 209 | /* Here, check whether we could get a real dwarf */ | 197 | /* Here, check whether we could get a real dwarf */ |
| 210 | if (!dbg) { | 198 | if (!self->dbg) { |
| 211 | pr_debug("Failed to find kernel dwarf at %lx\n", | 199 | pr_debug("Failed to find kernel dwarf at %lx\n", |
| 212 | (unsigned long)addr); | 200 | (unsigned long)addr); |
| 213 | dwfl_end(*dwflp); | 201 | dwfl_end(self->dwfl); |
| 214 | *dwflp = NULL; | 202 | memset(self, 0, sizeof(*self)); |
| 203 | return -ENOENT; | ||
| 215 | } | 204 | } |
| 216 | return dbg; | 205 | |
| 206 | return 0; | ||
| 217 | } | 207 | } |
| 218 | #else | 208 | #else |
| 219 | /* With older elfutils, this just support kernel module... */ | 209 | /* With older elfutils, this just support kernel module... */ |
| 220 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr __used, Dwfl **dwflp, | 210 | static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self, |
| 221 | Dwarf_Addr *bias) | 211 | Dwarf_Addr addr __used) |
| 222 | { | 212 | { |
| 223 | int fd; | ||
| 224 | const char *path = kernel_get_module_path("kernel"); | 213 | const char *path = kernel_get_module_path("kernel"); |
| 225 | 214 | ||
| 226 | if (!path) { | 215 | if (!path) { |
| 227 | pr_err("Failed to find vmlinux path\n"); | 216 | pr_err("Failed to find vmlinux path\n"); |
| 228 | return NULL; | 217 | return -ENOENT; |
| 229 | } | 218 | } |
| 230 | 219 | ||
| 231 | pr_debug2("Use file %s for debuginfo\n", path); | 220 | pr_debug2("Use file %s for debuginfo\n", path); |
| 232 | fd = open(path, O_RDONLY); | 221 | return debuginfo__init_offline_dwarf(self, path); |
| 233 | if (fd < 0) | ||
| 234 | return NULL; | ||
| 235 | |||
| 236 | return dwfl_init_offline_dwarf(fd, dwflp, bias); | ||
| 237 | } | 222 | } |
| 238 | #endif | 223 | #endif |
| 239 | 224 | ||
| 240 | /* Dwarf wrappers */ | 225 | struct debuginfo *debuginfo__new(const char *path) |
| 241 | |||
| 242 | /* Find the realpath of the target file. */ | ||
| 243 | static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname) | ||
| 244 | { | ||
| 245 | Dwarf_Files *files; | ||
| 246 | size_t nfiles, i; | ||
| 247 | const char *src = NULL; | ||
| 248 | int ret; | ||
| 249 | |||
| 250 | if (!fname) | ||
| 251 | return NULL; | ||
| 252 | |||
| 253 | ret = dwarf_getsrcfiles(cu_die, &files, &nfiles); | ||
| 254 | if (ret != 0) | ||
| 255 | return NULL; | ||
| 256 | |||
| 257 | for (i = 0; i < nfiles; i++) { | ||
| 258 | src = dwarf_filesrc(files, i, NULL, NULL); | ||
| 259 | if (strtailcmp(src, fname) == 0) | ||
| 260 | break; | ||
| 261 | } | ||
| 262 | if (i == nfiles) | ||
| 263 | return NULL; | ||
| 264 | return src; | ||
| 265 | } | ||
| 266 | |||
| 267 | /* Get DW_AT_comp_dir (should be NULL with older gcc) */ | ||
| 268 | static const char *cu_get_comp_dir(Dwarf_Die *cu_die) | ||
| 269 | { | ||
| 270 | Dwarf_Attribute attr; | ||
| 271 | if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL) | ||
| 272 | return NULL; | ||
| 273 | return dwarf_formstring(&attr); | ||
| 274 | } | ||
| 275 | |||
| 276 | /* Get a line number and file name for given address */ | ||
| 277 | static int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr, | ||
| 278 | const char **fname, int *lineno) | ||
| 279 | { | ||
| 280 | Dwarf_Line *line; | ||
| 281 | Dwarf_Addr laddr; | ||
| 282 | |||
| 283 | line = dwarf_getsrc_die(cudie, (Dwarf_Addr)addr); | ||
| 284 | if (line && dwarf_lineaddr(line, &laddr) == 0 && | ||
| 285 | addr == (unsigned long)laddr && dwarf_lineno(line, lineno) == 0) { | ||
| 286 | *fname = dwarf_linesrc(line, NULL, NULL); | ||
| 287 | if (!*fname) | ||
| 288 | /* line number is useless without filename */ | ||
| 289 | *lineno = 0; | ||
| 290 | } | ||
| 291 | |||
| 292 | return *lineno ?: -ENOENT; | ||
| 293 | } | ||
| 294 | |||
| 295 | /* Compare diename and tname */ | ||
| 296 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | ||
| 297 | { | ||
| 298 | const char *name; | ||
| 299 | name = dwarf_diename(dw_die); | ||
| 300 | return name ? (strcmp(tname, name) == 0) : false; | ||
| 301 | } | ||
| 302 | |||
| 303 | /* Get callsite line number of inline-function instance */ | ||
| 304 | static int die_get_call_lineno(Dwarf_Die *in_die) | ||
| 305 | { | ||
| 306 | Dwarf_Attribute attr; | ||
| 307 | Dwarf_Word ret; | ||
| 308 | |||
| 309 | if (!dwarf_attr(in_die, DW_AT_call_line, &attr)) | ||
| 310 | return -ENOENT; | ||
| 311 | |||
| 312 | dwarf_formudata(&attr, &ret); | ||
| 313 | return (int)ret; | ||
| 314 | } | ||
| 315 | |||
| 316 | /* Get type die */ | ||
| 317 | static Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 318 | { | ||
| 319 | Dwarf_Attribute attr; | ||
| 320 | |||
| 321 | if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) && | ||
| 322 | dwarf_formref_die(&attr, die_mem)) | ||
| 323 | return die_mem; | ||
| 324 | else | ||
| 325 | return NULL; | ||
| 326 | } | ||
| 327 | |||
| 328 | /* Get a type die, but skip qualifiers */ | ||
| 329 | static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 330 | { | ||
| 331 | int tag; | ||
| 332 | |||
| 333 | do { | ||
| 334 | vr_die = die_get_type(vr_die, die_mem); | ||
| 335 | if (!vr_die) | ||
| 336 | break; | ||
| 337 | tag = dwarf_tag(vr_die); | ||
| 338 | } while (tag == DW_TAG_const_type || | ||
| 339 | tag == DW_TAG_restrict_type || | ||
| 340 | tag == DW_TAG_volatile_type || | ||
| 341 | tag == DW_TAG_shared_type); | ||
| 342 | |||
| 343 | return vr_die; | ||
| 344 | } | ||
| 345 | |||
| 346 | /* Get a type die, but skip qualifiers and typedef */ | ||
| 347 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
| 348 | { | ||
| 349 | do { | ||
| 350 | vr_die = __die_get_real_type(vr_die, die_mem); | ||
| 351 | } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef); | ||
| 352 | |||
| 353 | return vr_die; | ||
| 354 | } | ||
| 355 | |||
| 356 | static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, | ||
| 357 | Dwarf_Word *result) | ||
| 358 | { | ||
| 359 | Dwarf_Attribute attr; | ||
| 360 | |||
| 361 | if (dwarf_attr(tp_die, attr_name, &attr) == NULL || | ||
| 362 | dwarf_formudata(&attr, result) != 0) | ||
| 363 | return -ENOENT; | ||
| 364 | |||
| 365 | return 0; | ||
| 366 | } | ||
| 367 | |||
| 368 | static bool die_is_signed_type(Dwarf_Die *tp_die) | ||
| 369 | { | ||
| 370 | Dwarf_Word ret; | ||
| 371 | |||
| 372 | if (die_get_attr_udata(tp_die, DW_AT_encoding, &ret)) | ||
| 373 | return false; | ||
| 374 | |||
| 375 | return (ret == DW_ATE_signed_char || ret == DW_ATE_signed || | ||
| 376 | ret == DW_ATE_signed_fixed); | ||
| 377 | } | ||
| 378 | |||
| 379 | static int die_get_byte_size(Dwarf_Die *tp_die) | ||
| 380 | { | ||
| 381 | Dwarf_Word ret; | ||
| 382 | |||
| 383 | if (die_get_attr_udata(tp_die, DW_AT_byte_size, &ret)) | ||
| 384 | return 0; | ||
| 385 | |||
| 386 | return (int)ret; | ||
| 387 | } | ||
| 388 | |||
| 389 | static int die_get_bit_size(Dwarf_Die *tp_die) | ||
| 390 | { | ||
| 391 | Dwarf_Word ret; | ||
| 392 | |||
| 393 | if (die_get_attr_udata(tp_die, DW_AT_bit_size, &ret)) | ||
| 394 | return 0; | ||
| 395 | |||
| 396 | return (int)ret; | ||
| 397 | } | ||
| 398 | |||
| 399 | static int die_get_bit_offset(Dwarf_Die *tp_die) | ||
| 400 | { | ||
| 401 | Dwarf_Word ret; | ||
| 402 | |||
| 403 | if (die_get_attr_udata(tp_die, DW_AT_bit_offset, &ret)) | ||
| 404 | return 0; | ||
| 405 | |||
| 406 | return (int)ret; | ||
| 407 | } | ||
| 408 | |||
| 409 | /* Get data_member_location offset */ | ||
| 410 | static int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs) | ||
| 411 | { | ||
| 412 | Dwarf_Attribute attr; | ||
| 413 | Dwarf_Op *expr; | ||
| 414 | size_t nexpr; | ||
| 415 | int ret; | ||
| 416 | |||
| 417 | if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL) | ||
| 418 | return -ENOENT; | ||
| 419 | |||
| 420 | if (dwarf_formudata(&attr, offs) != 0) { | ||
| 421 | /* DW_AT_data_member_location should be DW_OP_plus_uconst */ | ||
| 422 | ret = dwarf_getlocation(&attr, &expr, &nexpr); | ||
| 423 | if (ret < 0 || nexpr == 0) | ||
| 424 | return -ENOENT; | ||
| 425 | |||
| 426 | if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) { | ||
| 427 | pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n", | ||
| 428 | expr[0].atom, nexpr); | ||
| 429 | return -ENOTSUP; | ||
| 430 | } | ||
| 431 | *offs = (Dwarf_Word)expr[0].number; | ||
| 432 | } | ||
| 433 | return 0; | ||
| 434 | } | ||
| 435 | |||
| 436 | /* Return values for die_find callbacks */ | ||
| 437 | enum { | ||
| 438 | DIE_FIND_CB_FOUND = 0, /* End of Search */ | ||
| 439 | DIE_FIND_CB_CHILD = 1, /* Search only children */ | ||
| 440 | DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ | ||
| 441 | DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ | ||
| 442 | }; | ||
| 443 | |||
| 444 | /* Search a child die */ | ||
| 445 | static Dwarf_Die *die_find_child(Dwarf_Die *rt_die, | ||
| 446 | int (*callback)(Dwarf_Die *, void *), | ||
| 447 | void *data, Dwarf_Die *die_mem) | ||
| 448 | { | 226 | { |
| 449 | Dwarf_Die child_die; | 227 | struct debuginfo *self = zalloc(sizeof(struct debuginfo)); |
| 450 | int ret; | 228 | if (!self) |
| 451 | |||
| 452 | ret = dwarf_child(rt_die, die_mem); | ||
| 453 | if (ret != 0) | ||
| 454 | return NULL; | 229 | return NULL; |
| 455 | 230 | ||
| 456 | do { | 231 | if (debuginfo__init_offline_dwarf(self, path) < 0) { |
| 457 | ret = callback(die_mem, data); | 232 | free(self); |
| 458 | if (ret == DIE_FIND_CB_FOUND) | 233 | self = NULL; |
| 459 | return die_mem; | ||
| 460 | |||
| 461 | if ((ret & DIE_FIND_CB_CHILD) && | ||
| 462 | die_find_child(die_mem, callback, data, &child_die)) { | ||
| 463 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
| 464 | return die_mem; | ||
| 465 | } | ||
| 466 | } while ((ret & DIE_FIND_CB_SIBLING) && | ||
| 467 | dwarf_siblingof(die_mem, die_mem) == 0); | ||
| 468 | |||
| 469 | return NULL; | ||
| 470 | } | ||
| 471 | |||
| 472 | struct __addr_die_search_param { | ||
| 473 | Dwarf_Addr addr; | ||
| 474 | Dwarf_Die *die_mem; | ||
| 475 | }; | ||
| 476 | |||
| 477 | static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) | ||
| 478 | { | ||
| 479 | struct __addr_die_search_param *ad = data; | ||
| 480 | |||
| 481 | if (dwarf_tag(fn_die) == DW_TAG_subprogram && | ||
| 482 | dwarf_haspc(fn_die, ad->addr)) { | ||
| 483 | memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); | ||
| 484 | return DWARF_CB_ABORT; | ||
| 485 | } | 234 | } |
| 486 | return DWARF_CB_OK; | ||
| 487 | } | ||
| 488 | |||
| 489 | /* Search a real subprogram including this line, */ | ||
| 490 | static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, | ||
| 491 | Dwarf_Die *die_mem) | ||
| 492 | { | ||
| 493 | struct __addr_die_search_param ad; | ||
| 494 | ad.addr = addr; | ||
| 495 | ad.die_mem = die_mem; | ||
| 496 | /* dwarf_getscopes can't find subprogram. */ | ||
| 497 | if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0)) | ||
| 498 | return NULL; | ||
| 499 | else | ||
| 500 | return die_mem; | ||
| 501 | } | ||
| 502 | |||
| 503 | /* die_find callback for inline function search */ | ||
| 504 | static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) | ||
| 505 | { | ||
| 506 | Dwarf_Addr *addr = data; | ||
| 507 | |||
| 508 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && | ||
| 509 | dwarf_haspc(die_mem, *addr)) | ||
| 510 | return DIE_FIND_CB_FOUND; | ||
| 511 | 235 | ||
| 512 | return DIE_FIND_CB_CONTINUE; | 236 | return self; |
| 513 | } | 237 | } |
| 514 | 238 | ||
| 515 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ | 239 | struct debuginfo *debuginfo__new_online_kernel(unsigned long addr) |
| 516 | static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | ||
| 517 | Dwarf_Die *die_mem) | ||
| 518 | { | 240 | { |
| 519 | Dwarf_Die tmp_die; | 241 | struct debuginfo *self = zalloc(sizeof(struct debuginfo)); |
| 520 | 242 | if (!self) | |
| 521 | sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr, &tmp_die); | ||
| 522 | if (!sp_die) | ||
| 523 | return NULL; | 243 | return NULL; |
| 524 | 244 | ||
| 525 | /* Inlined function could be recursive. Trace it until fail */ | 245 | if (debuginfo__init_online_kernel_dwarf(self, (Dwarf_Addr)addr) < 0) { |
| 526 | while (sp_die) { | 246 | free(self); |
| 527 | memcpy(die_mem, sp_die, sizeof(Dwarf_Die)); | 247 | self = NULL; |
| 528 | sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr, | ||
| 529 | &tmp_die); | ||
| 530 | } | ||
| 531 | |||
| 532 | return die_mem; | ||
| 533 | } | ||
| 534 | |||
| 535 | /* Walker on lines (Note: line number will not be sorted) */ | ||
| 536 | typedef int (* line_walk_handler_t) (const char *fname, int lineno, | ||
| 537 | Dwarf_Addr addr, void *data); | ||
| 538 | |||
| 539 | struct __line_walk_param { | ||
| 540 | const char *fname; | ||
| 541 | line_walk_handler_t handler; | ||
| 542 | void *data; | ||
| 543 | int retval; | ||
| 544 | }; | ||
| 545 | |||
| 546 | static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data) | ||
| 547 | { | ||
| 548 | struct __line_walk_param *lw = data; | ||
| 549 | Dwarf_Addr addr; | ||
| 550 | int lineno; | ||
| 551 | |||
| 552 | if (dwarf_tag(in_die) == DW_TAG_inlined_subroutine) { | ||
| 553 | lineno = die_get_call_lineno(in_die); | ||
| 554 | if (lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) { | ||
| 555 | lw->retval = lw->handler(lw->fname, lineno, addr, | ||
| 556 | lw->data); | ||
| 557 | if (lw->retval != 0) | ||
| 558 | return DIE_FIND_CB_FOUND; | ||
| 559 | } | ||
| 560 | } | ||
| 561 | return DIE_FIND_CB_SIBLING; | ||
| 562 | } | ||
| 563 | |||
| 564 | /* Walk on lines of blocks included in given DIE */ | ||
| 565 | static int __die_walk_funclines(Dwarf_Die *sp_die, | ||
| 566 | line_walk_handler_t handler, void *data) | ||
| 567 | { | ||
| 568 | struct __line_walk_param lw = { | ||
| 569 | .handler = handler, | ||
| 570 | .data = data, | ||
| 571 | .retval = 0, | ||
| 572 | }; | ||
| 573 | Dwarf_Die die_mem; | ||
| 574 | Dwarf_Addr addr; | ||
| 575 | int lineno; | ||
| 576 | |||
| 577 | /* Handle function declaration line */ | ||
| 578 | lw.fname = dwarf_decl_file(sp_die); | ||
| 579 | if (lw.fname && dwarf_decl_line(sp_die, &lineno) == 0 && | ||
| 580 | dwarf_entrypc(sp_die, &addr) == 0) { | ||
| 581 | lw.retval = handler(lw.fname, lineno, addr, data); | ||
| 582 | if (lw.retval != 0) | ||
| 583 | goto done; | ||
| 584 | } | ||
| 585 | die_find_child(sp_die, __die_walk_funclines_cb, &lw, &die_mem); | ||
| 586 | done: | ||
| 587 | return lw.retval; | ||
| 588 | } | ||
| 589 | |||
| 590 | static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data) | ||
| 591 | { | ||
| 592 | struct __line_walk_param *lw = data; | ||
| 593 | |||
| 594 | lw->retval = __die_walk_funclines(sp_die, lw->handler, lw->data); | ||
| 595 | if (lw->retval != 0) | ||
| 596 | return DWARF_CB_ABORT; | ||
| 597 | |||
| 598 | return DWARF_CB_OK; | ||
| 599 | } | ||
| 600 | |||
| 601 | /* | ||
| 602 | * Walk on lines inside given PDIE. If the PDIE is subprogram, walk only on | ||
| 603 | * the lines inside the subprogram, otherwise PDIE must be a CU DIE. | ||
| 604 | */ | ||
| 605 | static int die_walk_lines(Dwarf_Die *pdie, line_walk_handler_t handler, | ||
| 606 | void *data) | ||
| 607 | { | ||
| 608 | Dwarf_Lines *lines; | ||
| 609 | Dwarf_Line *line; | ||
| 610 | Dwarf_Addr addr; | ||
| 611 | const char *fname; | ||
| 612 | int lineno, ret = 0; | ||
| 613 | Dwarf_Die die_mem, *cu_die; | ||
| 614 | size_t nlines, i; | ||
| 615 | |||
| 616 | /* Get the CU die */ | ||
| 617 | if (dwarf_tag(pdie) == DW_TAG_subprogram) | ||
| 618 | cu_die = dwarf_diecu(pdie, &die_mem, NULL, NULL); | ||
| 619 | else | ||
| 620 | cu_die = pdie; | ||
| 621 | if (!cu_die) { | ||
| 622 | pr_debug2("Failed to get CU from subprogram\n"); | ||
| 623 | return -EINVAL; | ||
| 624 | } | ||
| 625 | |||
| 626 | /* Get lines list in the CU */ | ||
| 627 | if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0) { | ||
| 628 | pr_debug2("Failed to get source lines on this CU.\n"); | ||
| 629 | return -ENOENT; | ||
| 630 | } | ||
| 631 | pr_debug2("Get %zd lines from this CU\n", nlines); | ||
| 632 | |||
| 633 | /* Walk on the lines on lines list */ | ||
| 634 | for (i = 0; i < nlines; i++) { | ||
| 635 | line = dwarf_onesrcline(lines, i); | ||
| 636 | if (line == NULL || | ||
| 637 | dwarf_lineno(line, &lineno) != 0 || | ||
| 638 | dwarf_lineaddr(line, &addr) != 0) { | ||
| 639 | pr_debug2("Failed to get line info. " | ||
| 640 | "Possible error in debuginfo.\n"); | ||
| 641 | continue; | ||
| 642 | } | ||
| 643 | /* Filter lines based on address */ | ||
| 644 | if (pdie != cu_die) | ||
| 645 | /* | ||
| 646 | * Address filtering | ||
| 647 | * The line is included in given function, and | ||
| 648 | * no inline block includes it. | ||
| 649 | */ | ||
| 650 | if (!dwarf_haspc(pdie, addr) || | ||
| 651 | die_find_inlinefunc(pdie, addr, &die_mem)) | ||
| 652 | continue; | ||
| 653 | /* Get source line */ | ||
| 654 | fname = dwarf_linesrc(line, NULL, NULL); | ||
| 655 | |||
| 656 | ret = handler(fname, lineno, addr, data); | ||
| 657 | if (ret != 0) | ||
| 658 | return ret; | ||
| 659 | } | ||
| 660 | |||
| 661 | /* | ||
| 662 | * Dwarf lines doesn't include function declarations and inlined | ||
| 663 | * subroutines. We have to check functions list or given function. | ||
| 664 | */ | ||
| 665 | if (pdie != cu_die) | ||
| 666 | ret = __die_walk_funclines(pdie, handler, data); | ||
| 667 | else { | ||
| 668 | struct __line_walk_param param = { | ||
| 669 | .handler = handler, | ||
| 670 | .data = data, | ||
| 671 | .retval = 0, | ||
| 672 | }; | ||
| 673 | dwarf_getfuncs(cu_die, __die_walk_culines_cb, ¶m, 0); | ||
| 674 | ret = param.retval; | ||
| 675 | } | 248 | } |
| 676 | 249 | ||
| 677 | return ret; | 250 | return self; |
| 678 | } | ||
| 679 | |||
| 680 | struct __find_variable_param { | ||
| 681 | const char *name; | ||
| 682 | Dwarf_Addr addr; | ||
| 683 | }; | ||
| 684 | |||
| 685 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) | ||
| 686 | { | ||
| 687 | struct __find_variable_param *fvp = data; | ||
| 688 | int tag; | ||
| 689 | |||
| 690 | tag = dwarf_tag(die_mem); | ||
| 691 | if ((tag == DW_TAG_formal_parameter || | ||
| 692 | tag == DW_TAG_variable) && | ||
| 693 | die_compare_name(die_mem, fvp->name)) | ||
| 694 | return DIE_FIND_CB_FOUND; | ||
| 695 | |||
| 696 | if (dwarf_haspc(die_mem, fvp->addr)) | ||
| 697 | return DIE_FIND_CB_CONTINUE; | ||
| 698 | else | ||
| 699 | return DIE_FIND_CB_SIBLING; | ||
| 700 | } | ||
| 701 | |||
| 702 | /* Find a variable called 'name' at given address */ | ||
| 703 | static Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, | ||
| 704 | Dwarf_Addr addr, Dwarf_Die *die_mem) | ||
| 705 | { | ||
| 706 | struct __find_variable_param fvp = { .name = name, .addr = addr}; | ||
| 707 | |||
| 708 | return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp, | ||
| 709 | die_mem); | ||
| 710 | } | ||
| 711 | |||
| 712 | static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) | ||
| 713 | { | ||
| 714 | const char *name = data; | ||
| 715 | |||
| 716 | if ((dwarf_tag(die_mem) == DW_TAG_member) && | ||
| 717 | die_compare_name(die_mem, name)) | ||
| 718 | return DIE_FIND_CB_FOUND; | ||
| 719 | |||
| 720 | return DIE_FIND_CB_SIBLING; | ||
| 721 | } | ||
| 722 | |||
| 723 | /* Find a member called 'name' */ | ||
| 724 | static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | ||
| 725 | Dwarf_Die *die_mem) | ||
| 726 | { | ||
| 727 | return die_find_child(st_die, __die_find_member_cb, (void *)name, | ||
| 728 | die_mem); | ||
| 729 | } | ||
| 730 | |||
| 731 | /* Get the name of given variable DIE */ | ||
| 732 | static int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) | ||
| 733 | { | ||
| 734 | Dwarf_Die type; | ||
| 735 | int tag, ret, ret2; | ||
| 736 | const char *tmp = ""; | ||
| 737 | |||
| 738 | if (__die_get_real_type(vr_die, &type) == NULL) | ||
| 739 | return -ENOENT; | ||
| 740 | |||
| 741 | tag = dwarf_tag(&type); | ||
| 742 | if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type) | ||
| 743 | tmp = "*"; | ||
| 744 | else if (tag == DW_TAG_subroutine_type) { | ||
| 745 | /* Function pointer */ | ||
| 746 | ret = snprintf(buf, len, "(function_type)"); | ||
| 747 | return (ret >= len) ? -E2BIG : ret; | ||
| 748 | } else { | ||
| 749 | if (!dwarf_diename(&type)) | ||
| 750 | return -ENOENT; | ||
| 751 | if (tag == DW_TAG_union_type) | ||
| 752 | tmp = "union "; | ||
| 753 | else if (tag == DW_TAG_structure_type) | ||
| 754 | tmp = "struct "; | ||
| 755 | /* Write a base name */ | ||
| 756 | ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type)); | ||
| 757 | return (ret >= len) ? -E2BIG : ret; | ||
| 758 | } | ||
| 759 | ret = die_get_typename(&type, buf, len); | ||
| 760 | if (ret > 0) { | ||
| 761 | ret2 = snprintf(buf + ret, len - ret, "%s", tmp); | ||
| 762 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
| 763 | } | ||
| 764 | return ret; | ||
| 765 | } | 251 | } |
| 766 | 252 | ||
| 767 | /* Get the name and type of given variable DIE, stored as "type\tname" */ | 253 | void debuginfo__delete(struct debuginfo *self) |
| 768 | static int die_get_varname(Dwarf_Die *vr_die, char *buf, int len) | ||
| 769 | { | 254 | { |
| 770 | int ret, ret2; | 255 | if (self) { |
| 771 | 256 | if (self->dwfl) | |
| 772 | ret = die_get_typename(vr_die, buf, len); | 257 | dwfl_end(self->dwfl); |
| 773 | if (ret < 0) { | 258 | free(self); |
| 774 | pr_debug("Failed to get type, make it unknown.\n"); | ||
| 775 | ret = snprintf(buf, len, "(unknown_type)"); | ||
| 776 | } | 259 | } |
| 777 | if (ret > 0) { | ||
| 778 | ret2 = snprintf(buf + ret, len - ret, "\t%s", | ||
| 779 | dwarf_diename(vr_die)); | ||
| 780 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
| 781 | } | ||
| 782 | return ret; | ||
| 783 | } | 260 | } |
| 784 | 261 | ||
| 785 | /* | 262 | /* |
| @@ -897,6 +374,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, | |||
| 897 | struct probe_trace_arg_ref **ref_ptr = &tvar->ref; | 374 | struct probe_trace_arg_ref **ref_ptr = &tvar->ref; |
| 898 | Dwarf_Die type; | 375 | Dwarf_Die type; |
| 899 | char buf[16]; | 376 | char buf[16]; |
| 377 | int bsize, boffs, total; | ||
| 900 | int ret; | 378 | int ret; |
| 901 | 379 | ||
| 902 | /* TODO: check all types */ | 380 | /* TODO: check all types */ |
| @@ -906,11 +384,15 @@ static int convert_variable_type(Dwarf_Die *vr_die, | |||
| 906 | return (tvar->type == NULL) ? -ENOMEM : 0; | 384 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 907 | } | 385 | } |
| 908 | 386 | ||
| 909 | if (die_get_bit_size(vr_die) != 0) { | 387 | bsize = dwarf_bitsize(vr_die); |
| 388 | if (bsize > 0) { | ||
| 910 | /* This is a bitfield */ | 389 | /* This is a bitfield */ |
| 911 | ret = snprintf(buf, 16, "b%d@%d/%zd", die_get_bit_size(vr_die), | 390 | boffs = dwarf_bitoffset(vr_die); |
| 912 | die_get_bit_offset(vr_die), | 391 | total = dwarf_bytesize(vr_die); |
| 913 | BYTES_TO_BITS(die_get_byte_size(vr_die))); | 392 | if (boffs < 0 || total < 0) |
| 393 | return -ENOENT; | ||
| 394 | ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs, | ||
| 395 | BYTES_TO_BITS(total)); | ||
| 914 | goto formatted; | 396 | goto formatted; |
| 915 | } | 397 | } |
| 916 | 398 | ||
| @@ -958,10 +440,11 @@ static int convert_variable_type(Dwarf_Die *vr_die, | |||
| 958 | return (tvar->type == NULL) ? -ENOMEM : 0; | 440 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 959 | } | 441 | } |
| 960 | 442 | ||
| 961 | ret = BYTES_TO_BITS(die_get_byte_size(&type)); | 443 | ret = dwarf_bytesize(&type); |
| 962 | if (!ret) | 444 | if (ret <= 0) |
| 963 | /* No size ... try to use default type */ | 445 | /* No size ... try to use default type */ |
| 964 | return 0; | 446 | return 0; |
| 447 | ret = BYTES_TO_BITS(ret); | ||
| 965 | 448 | ||
| 966 | /* Check the bitwidth */ | 449 | /* Check the bitwidth */ |
| 967 | if (ret > MAX_BASIC_TYPE_BITS) { | 450 | if (ret > MAX_BASIC_TYPE_BITS) { |
| @@ -1025,7 +508,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
| 1025 | else | 508 | else |
| 1026 | *ref_ptr = ref; | 509 | *ref_ptr = ref; |
| 1027 | } | 510 | } |
| 1028 | ref->offset += die_get_byte_size(&type) * field->index; | 511 | ref->offset += dwarf_bytesize(&type) * field->index; |
| 1029 | if (!field->next) | 512 | if (!field->next) |
| 1030 | /* Save vr_die for converting types */ | 513 | /* Save vr_die for converting types */ |
| 1031 | memcpy(die_mem, vr_die, sizeof(*die_mem)); | 514 | memcpy(die_mem, vr_die, sizeof(*die_mem)); |
| @@ -1245,8 +728,7 @@ static int call_probe_finder(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
| 1245 | 728 | ||
| 1246 | /* If no real subprogram, find a real one */ | 729 | /* If no real subprogram, find a real one */ |
| 1247 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { | 730 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { |
| 1248 | sp_die = die_find_real_subprogram(&pf->cu_die, | 731 | sp_die = die_find_realfunc(&pf->cu_die, pf->addr, &die_mem); |
| 1249 | pf->addr, &die_mem); | ||
| 1250 | if (!sp_die) { | 732 | if (!sp_die) { |
| 1251 | pr_warning("Failed to find probe point in any " | 733 | pr_warning("Failed to find probe point in any " |
| 1252 | "functions.\n"); | 734 | "functions.\n"); |
| @@ -1504,28 +986,18 @@ static int pubname_search_cb(Dwarf *dbg, Dwarf_Global *gl, void *data) | |||
| 1504 | } | 986 | } |
| 1505 | 987 | ||
| 1506 | /* Find probe points from debuginfo */ | 988 | /* Find probe points from debuginfo */ |
| 1507 | static int find_probes(int fd, struct probe_finder *pf) | 989 | static int debuginfo__find_probes(struct debuginfo *self, |
| 990 | struct probe_finder *pf) | ||
| 1508 | { | 991 | { |
| 1509 | struct perf_probe_point *pp = &pf->pev->point; | 992 | struct perf_probe_point *pp = &pf->pev->point; |
| 1510 | Dwarf_Off off, noff; | 993 | Dwarf_Off off, noff; |
| 1511 | size_t cuhl; | 994 | size_t cuhl; |
| 1512 | Dwarf_Die *diep; | 995 | Dwarf_Die *diep; |
| 1513 | Dwarf *dbg = NULL; | ||
| 1514 | Dwfl *dwfl; | ||
| 1515 | Dwarf_Addr bias; /* Currently ignored */ | ||
| 1516 | int ret = 0; | 996 | int ret = 0; |
| 1517 | 997 | ||
| 1518 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); | ||
| 1519 | if (!dbg) { | ||
| 1520 | pr_warning("No debug information found in the vmlinux - " | ||
| 1521 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
| 1522 | close(fd); /* Without dwfl_end(), fd isn't closed. */ | ||
| 1523 | return -EBADF; | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | #if _ELFUTILS_PREREQ(0, 142) | 998 | #if _ELFUTILS_PREREQ(0, 142) |
| 1527 | /* Get the call frame information from this dwarf */ | 999 | /* Get the call frame information from this dwarf */ |
| 1528 | pf->cfi = dwarf_getcfi(dbg); | 1000 | pf->cfi = dwarf_getcfi(self->dbg); |
| 1529 | #endif | 1001 | #endif |
| 1530 | 1002 | ||
| 1531 | off = 0; | 1003 | off = 0; |
| @@ -1544,7 +1016,8 @@ static int find_probes(int fd, struct probe_finder *pf) | |||
| 1544 | .data = pf, | 1016 | .data = pf, |
| 1545 | }; | 1017 | }; |
| 1546 | 1018 | ||
| 1547 | dwarf_getpubnames(dbg, pubname_search_cb, &pubname_param, 0); | 1019 | dwarf_getpubnames(self->dbg, pubname_search_cb, |
| 1020 | &pubname_param, 0); | ||
| 1548 | if (pubname_param.found) { | 1021 | if (pubname_param.found) { |
| 1549 | ret = probe_point_search_cb(&pf->sp_die, &probe_param); | 1022 | ret = probe_point_search_cb(&pf->sp_die, &probe_param); |
| 1550 | if (ret) | 1023 | if (ret) |
| @@ -1553,9 +1026,9 @@ static int find_probes(int fd, struct probe_finder *pf) | |||
| 1553 | } | 1026 | } |
| 1554 | 1027 | ||
| 1555 | /* Loop on CUs (Compilation Unit) */ | 1028 | /* Loop on CUs (Compilation Unit) */ |
| 1556 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL)) { | 1029 | while (!dwarf_nextcu(self->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) { |
| 1557 | /* Get the DIE(Debugging Information Entry) of this CU */ | 1030 | /* Get the DIE(Debugging Information Entry) of this CU */ |
| 1558 | diep = dwarf_offdie(dbg, off + cuhl, &pf->cu_die); | 1031 | diep = dwarf_offdie(self->dbg, off + cuhl, &pf->cu_die); |
| 1559 | if (!diep) | 1032 | if (!diep) |
| 1560 | continue; | 1033 | continue; |
| 1561 | 1034 | ||
| @@ -1582,8 +1055,6 @@ static int find_probes(int fd, struct probe_finder *pf) | |||
| 1582 | 1055 | ||
| 1583 | found: | 1056 | found: |
| 1584 | line_list__free(&pf->lcache); | 1057 | line_list__free(&pf->lcache); |
| 1585 | if (dwfl) | ||
| 1586 | dwfl_end(dwfl); | ||
| 1587 | 1058 | ||
| 1588 | return ret; | 1059 | return ret; |
| 1589 | } | 1060 | } |
| @@ -1629,8 +1100,9 @@ static int add_probe_trace_event(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
| 1629 | } | 1100 | } |
| 1630 | 1101 | ||
| 1631 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ | 1102 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
| 1632 | int find_probe_trace_events(int fd, struct perf_probe_event *pev, | 1103 | int debuginfo__find_trace_events(struct debuginfo *self, |
| 1633 | struct probe_trace_event **tevs, int max_tevs) | 1104 | struct perf_probe_event *pev, |
| 1105 | struct probe_trace_event **tevs, int max_tevs) | ||
| 1634 | { | 1106 | { |
| 1635 | struct trace_event_finder tf = { | 1107 | struct trace_event_finder tf = { |
| 1636 | .pf = {.pev = pev, .callback = add_probe_trace_event}, | 1108 | .pf = {.pev = pev, .callback = add_probe_trace_event}, |
| @@ -1645,7 +1117,7 @@ int find_probe_trace_events(int fd, struct perf_probe_event *pev, | |||
| 1645 | tf.tevs = *tevs; | 1117 | tf.tevs = *tevs; |
| 1646 | tf.ntevs = 0; | 1118 | tf.ntevs = 0; |
| 1647 | 1119 | ||
| 1648 | ret = find_probes(fd, &tf.pf); | 1120 | ret = debuginfo__find_probes(self, &tf.pf); |
| 1649 | if (ret < 0) { | 1121 | if (ret < 0) { |
| 1650 | free(*tevs); | 1122 | free(*tevs); |
| 1651 | *tevs = NULL; | 1123 | *tevs = NULL; |
| @@ -1739,9 +1211,10 @@ out: | |||
| 1739 | } | 1211 | } |
| 1740 | 1212 | ||
| 1741 | /* Find available variables at given probe point */ | 1213 | /* Find available variables at given probe point */ |
| 1742 | int find_available_vars_at(int fd, struct perf_probe_event *pev, | 1214 | int debuginfo__find_available_vars_at(struct debuginfo *self, |
| 1743 | struct variable_list **vls, int max_vls, | 1215 | struct perf_probe_event *pev, |
| 1744 | bool externs) | 1216 | struct variable_list **vls, |
| 1217 | int max_vls, bool externs) | ||
| 1745 | { | 1218 | { |
| 1746 | struct available_var_finder af = { | 1219 | struct available_var_finder af = { |
| 1747 | .pf = {.pev = pev, .callback = add_available_vars}, | 1220 | .pf = {.pev = pev, .callback = add_available_vars}, |
| @@ -1756,7 +1229,7 @@ int find_available_vars_at(int fd, struct perf_probe_event *pev, | |||
| 1756 | af.vls = *vls; | 1229 | af.vls = *vls; |
| 1757 | af.nvls = 0; | 1230 | af.nvls = 0; |
| 1758 | 1231 | ||
| 1759 | ret = find_probes(fd, &af.pf); | 1232 | ret = debuginfo__find_probes(self, &af.pf); |
| 1760 | if (ret < 0) { | 1233 | if (ret < 0) { |
| 1761 | /* Free vlist for error */ | 1234 | /* Free vlist for error */ |
| 1762 | while (af.nvls--) { | 1235 | while (af.nvls--) { |
| @@ -1774,28 +1247,19 @@ int find_available_vars_at(int fd, struct perf_probe_event *pev, | |||
| 1774 | } | 1247 | } |
| 1775 | 1248 | ||
| 1776 | /* Reverse search */ | 1249 | /* Reverse search */ |
| 1777 | int find_perf_probe_point(unsigned long addr, struct perf_probe_point *ppt) | 1250 | int debuginfo__find_probe_point(struct debuginfo *self, unsigned long addr, |
| 1251 | struct perf_probe_point *ppt) | ||
| 1778 | { | 1252 | { |
| 1779 | Dwarf_Die cudie, spdie, indie; | 1253 | Dwarf_Die cudie, spdie, indie; |
| 1780 | Dwarf *dbg = NULL; | 1254 | Dwarf_Addr _addr, baseaddr; |
| 1781 | Dwfl *dwfl = NULL; | ||
| 1782 | Dwarf_Addr _addr, baseaddr, bias = 0; | ||
| 1783 | const char *fname = NULL, *func = NULL, *tmp; | 1255 | const char *fname = NULL, *func = NULL, *tmp; |
| 1784 | int baseline = 0, lineno = 0, ret = 0; | 1256 | int baseline = 0, lineno = 0, ret = 0; |
| 1785 | 1257 | ||
| 1786 | /* Open the live linux kernel */ | ||
| 1787 | dbg = dwfl_init_live_kernel_dwarf(addr, &dwfl, &bias); | ||
| 1788 | if (!dbg) { | ||
| 1789 | pr_warning("No debug information found in the vmlinux - " | ||
| 1790 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
| 1791 | ret = -EINVAL; | ||
| 1792 | goto end; | ||
| 1793 | } | ||
| 1794 | |||
| 1795 | /* Adjust address with bias */ | 1258 | /* Adjust address with bias */ |
| 1796 | addr += bias; | 1259 | addr += self->bias; |
| 1260 | |||
| 1797 | /* Find cu die */ | 1261 | /* Find cu die */ |
| 1798 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr - bias, &cudie)) { | 1262 | if (!dwarf_addrdie(self->dbg, (Dwarf_Addr)addr - self->bias, &cudie)) { |
| 1799 | pr_warning("Failed to find debug information for address %lx\n", | 1263 | pr_warning("Failed to find debug information for address %lx\n", |
| 1800 | addr); | 1264 | addr); |
| 1801 | ret = -EINVAL; | 1265 | ret = -EINVAL; |
| @@ -1807,7 +1271,7 @@ int find_perf_probe_point(unsigned long addr, struct perf_probe_point *ppt) | |||
| 1807 | /* Don't care whether it failed or not */ | 1271 | /* Don't care whether it failed or not */ |
| 1808 | 1272 | ||
| 1809 | /* Find a corresponding function (name, baseline and baseaddr) */ | 1273 | /* Find a corresponding function (name, baseline and baseaddr) */ |
| 1810 | if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) { | 1274 | if (die_find_realfunc(&cudie, (Dwarf_Addr)addr, &spdie)) { |
| 1811 | /* Get function entry information */ | 1275 | /* Get function entry information */ |
| 1812 | tmp = dwarf_diename(&spdie); | 1276 | tmp = dwarf_diename(&spdie); |
| 1813 | if (!tmp || | 1277 | if (!tmp || |
| @@ -1871,8 +1335,6 @@ post: | |||
| 1871 | } | 1335 | } |
| 1872 | } | 1336 | } |
| 1873 | end: | 1337 | end: |
| 1874 | if (dwfl) | ||
| 1875 | dwfl_end(dwfl); | ||
| 1876 | if (ret == 0 && (fname || func)) | 1338 | if (ret == 0 && (fname || func)) |
| 1877 | ret = 1; /* Found a point */ | 1339 | ret = 1; /* Found a point */ |
| 1878 | return ret; | 1340 | return ret; |
| @@ -1982,26 +1444,15 @@ static int find_line_range_by_func(struct line_finder *lf) | |||
| 1982 | return param.retval; | 1444 | return param.retval; |
| 1983 | } | 1445 | } |
| 1984 | 1446 | ||
| 1985 | int find_line_range(int fd, struct line_range *lr) | 1447 | int debuginfo__find_line_range(struct debuginfo *self, struct line_range *lr) |
| 1986 | { | 1448 | { |
| 1987 | struct line_finder lf = {.lr = lr, .found = 0}; | 1449 | struct line_finder lf = {.lr = lr, .found = 0}; |
| 1988 | int ret = 0; | 1450 | int ret = 0; |
| 1989 | Dwarf_Off off = 0, noff; | 1451 | Dwarf_Off off = 0, noff; |
| 1990 | size_t cuhl; | 1452 | size_t cuhl; |
| 1991 | Dwarf_Die *diep; | 1453 | Dwarf_Die *diep; |
| 1992 | Dwarf *dbg = NULL; | ||
| 1993 | Dwfl *dwfl; | ||
| 1994 | Dwarf_Addr bias; /* Currently ignored */ | ||
| 1995 | const char *comp_dir; | 1454 | const char *comp_dir; |
| 1996 | 1455 | ||
| 1997 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); | ||
| 1998 | if (!dbg) { | ||
| 1999 | pr_warning("No debug information found in the vmlinux - " | ||
| 2000 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
| 2001 | close(fd); /* Without dwfl_end(), fd isn't closed. */ | ||
| 2002 | return -EBADF; | ||
| 2003 | } | ||
| 2004 | |||
| 2005 | /* Fastpath: lookup by function name from .debug_pubnames section */ | 1456 | /* Fastpath: lookup by function name from .debug_pubnames section */ |
| 2006 | if (lr->function) { | 1457 | if (lr->function) { |
| 2007 | struct pubname_callback_param pubname_param = { | 1458 | struct pubname_callback_param pubname_param = { |
| @@ -2010,7 +1461,8 @@ int find_line_range(int fd, struct line_range *lr) | |||
| 2010 | struct dwarf_callback_param line_range_param = { | 1461 | struct dwarf_callback_param line_range_param = { |
| 2011 | .data = (void *)&lf, .retval = 0}; | 1462 | .data = (void *)&lf, .retval = 0}; |
| 2012 | 1463 | ||
| 2013 | dwarf_getpubnames(dbg, pubname_search_cb, &pubname_param, 0); | 1464 | dwarf_getpubnames(self->dbg, pubname_search_cb, |
| 1465 | &pubname_param, 0); | ||
| 2014 | if (pubname_param.found) { | 1466 | if (pubname_param.found) { |
| 2015 | line_range_search_cb(&lf.sp_die, &line_range_param); | 1467 | line_range_search_cb(&lf.sp_die, &line_range_param); |
| 2016 | if (lf.found) | 1468 | if (lf.found) |
| @@ -2020,11 +1472,12 @@ int find_line_range(int fd, struct line_range *lr) | |||
| 2020 | 1472 | ||
| 2021 | /* Loop on CUs (Compilation Unit) */ | 1473 | /* Loop on CUs (Compilation Unit) */ |
| 2022 | while (!lf.found && ret >= 0) { | 1474 | while (!lf.found && ret >= 0) { |
| 2023 | if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0) | 1475 | if (dwarf_nextcu(self->dbg, off, &noff, &cuhl, |
| 1476 | NULL, NULL, NULL) != 0) | ||
| 2024 | break; | 1477 | break; |
| 2025 | 1478 | ||
| 2026 | /* Get the DIE(Debugging Information Entry) of this CU */ | 1479 | /* Get the DIE(Debugging Information Entry) of this CU */ |
| 2027 | diep = dwarf_offdie(dbg, off + cuhl, &lf.cu_die); | 1480 | diep = dwarf_offdie(self->dbg, off + cuhl, &lf.cu_die); |
| 2028 | if (!diep) | 1481 | if (!diep) |
| 2029 | continue; | 1482 | continue; |
| 2030 | 1483 | ||
| @@ -2058,7 +1511,6 @@ found: | |||
| 2058 | } | 1511 | } |
| 2059 | 1512 | ||
| 2060 | pr_debug("path: %s\n", lr->path); | 1513 | pr_debug("path: %s\n", lr->path); |
| 2061 | dwfl_end(dwfl); | ||
| 2062 | return (ret < 0) ? ret : lf.found; | 1514 | return (ret < 0) ? ret : lf.found; |
| 2063 | } | 1515 | } |
| 2064 | 1516 | ||
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 605730a366db..c478b42a2473 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
| @@ -16,27 +16,42 @@ static inline int is_c_varname(const char *name) | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | #ifdef DWARF_SUPPORT | 18 | #ifdef DWARF_SUPPORT |
| 19 | |||
| 20 | #include "dwarf-aux.h" | ||
| 21 | |||
| 22 | /* TODO: export debuginfo data structure even if no dwarf support */ | ||
| 23 | |||
| 24 | /* debug information structure */ | ||
| 25 | struct debuginfo { | ||
| 26 | Dwarf *dbg; | ||
| 27 | Dwfl *dwfl; | ||
| 28 | Dwarf_Addr bias; | ||
| 29 | }; | ||
| 30 | |||
| 31 | extern struct debuginfo *debuginfo__new(const char *path); | ||
| 32 | extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr); | ||
| 33 | extern void debuginfo__delete(struct debuginfo *self); | ||
| 34 | |||
| 19 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ | 35 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
| 20 | extern int find_probe_trace_events(int fd, struct perf_probe_event *pev, | 36 | extern int debuginfo__find_trace_events(struct debuginfo *self, |
| 21 | struct probe_trace_event **tevs, | 37 | struct perf_probe_event *pev, |
| 22 | int max_tevs); | 38 | struct probe_trace_event **tevs, |
| 39 | int max_tevs); | ||
| 23 | 40 | ||
| 24 | /* Find a perf_probe_point from debuginfo */ | 41 | /* Find a perf_probe_point from debuginfo */ |
| 25 | extern int find_perf_probe_point(unsigned long addr, | 42 | extern int debuginfo__find_probe_point(struct debuginfo *self, |
| 26 | struct perf_probe_point *ppt); | 43 | unsigned long addr, |
| 44 | struct perf_probe_point *ppt); | ||
| 27 | 45 | ||
| 28 | /* Find a line range */ | 46 | /* Find a line range */ |
| 29 | extern int find_line_range(int fd, struct line_range *lr); | 47 | extern int debuginfo__find_line_range(struct debuginfo *self, |
| 48 | struct line_range *lr); | ||
| 30 | 49 | ||
| 31 | /* Find available variables */ | 50 | /* Find available variables */ |
| 32 | extern int find_available_vars_at(int fd, struct perf_probe_event *pev, | 51 | extern int debuginfo__find_available_vars_at(struct debuginfo *self, |
| 33 | struct variable_list **vls, int max_points, | 52 | struct perf_probe_event *pev, |
| 34 | bool externs); | 53 | struct variable_list **vls, |
| 35 | 54 | int max_points, bool externs); | |
| 36 | #include <dwarf.h> | ||
| 37 | #include <elfutils/libdw.h> | ||
| 38 | #include <elfutils/libdwfl.h> | ||
| 39 | #include <elfutils/version.h> | ||
| 40 | 55 | ||
| 41 | struct probe_finder { | 56 | struct probe_finder { |
| 42 | struct perf_probe_event *pev; /* Target probe event */ | 57 | struct perf_probe_event *pev; /* Target probe event */ |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index b9a985dadd08..d5836382ff2c 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
| @@ -294,3 +294,22 @@ bool strlazymatch(const char *str, const char *pat) | |||
| 294 | { | 294 | { |
| 295 | return __match_glob(str, pat, true); | 295 | return __match_glob(str, pat, true); |
| 296 | } | 296 | } |
| 297 | |||
| 298 | /** | ||
| 299 | * strtailcmp - Compare the tail of two strings | ||
| 300 | * @s1: 1st string to be compared | ||
| 301 | * @s2: 2nd string to be compared | ||
| 302 | * | ||
| 303 | * Return 0 if whole of either string is same as another's tail part. | ||
| 304 | */ | ||
| 305 | int strtailcmp(const char *s1, const char *s2) | ||
| 306 | { | ||
| 307 | int i1 = strlen(s1); | ||
| 308 | int i2 = strlen(s2); | ||
| 309 | while (--i1 >= 0 && --i2 >= 0) { | ||
| 310 | if (s1[i1] != s2[i2]) | ||
| 311 | return s1[i1] - s2[i2]; | ||
| 312 | } | ||
| 313 | return 0; | ||
| 314 | } | ||
| 315 | |||
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index 35729f4c40cb..3403f814ad72 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
| @@ -183,106 +183,59 @@ int bigendian(void) | |||
| 183 | return *ptr == 0x01020304; | 183 | return *ptr == 0x01020304; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | static unsigned long long copy_file_fd(int fd) | 186 | /* unfortunately, you can not stat debugfs or proc files for size */ |
| 187 | static void record_file(const char *file, size_t hdr_sz) | ||
| 187 | { | 188 | { |
| 188 | unsigned long long size = 0; | 189 | unsigned long long size = 0; |
| 189 | char buf[BUFSIZ]; | 190 | char buf[BUFSIZ], *sizep; |
| 190 | int r; | 191 | off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR); |
| 191 | 192 | int r, fd; | |
| 192 | do { | ||
| 193 | r = read(fd, buf, BUFSIZ); | ||
| 194 | if (r > 0) { | ||
| 195 | size += r; | ||
| 196 | write_or_die(buf, r); | ||
| 197 | } | ||
| 198 | } while (r > 0); | ||
| 199 | |||
| 200 | return size; | ||
| 201 | } | ||
| 202 | |||
| 203 | static unsigned long long copy_file(const char *file) | ||
| 204 | { | ||
| 205 | unsigned long long size = 0; | ||
| 206 | int fd; | ||
| 207 | 193 | ||
| 208 | fd = open(file, O_RDONLY); | 194 | fd = open(file, O_RDONLY); |
| 209 | if (fd < 0) | 195 | if (fd < 0) |
| 210 | die("Can't read '%s'", file); | 196 | die("Can't read '%s'", file); |
| 211 | size = copy_file_fd(fd); | ||
| 212 | close(fd); | ||
| 213 | 197 | ||
| 214 | return size; | 198 | /* put in zeros for file size, then fill true size later */ |
| 215 | } | 199 | write_or_die(&size, hdr_sz); |
| 216 | |||
| 217 | static unsigned long get_size_fd(int fd) | ||
| 218 | { | ||
| 219 | unsigned long long size = 0; | ||
| 220 | char buf[BUFSIZ]; | ||
| 221 | int r; | ||
| 222 | 200 | ||
| 223 | do { | 201 | do { |
| 224 | r = read(fd, buf, BUFSIZ); | 202 | r = read(fd, buf, BUFSIZ); |
| 225 | if (r > 0) | 203 | if (r > 0) { |
| 226 | size += r; | 204 | size += r; |
| 205 | write_or_die(buf, r); | ||
| 206 | } | ||
| 227 | } while (r > 0); | 207 | } while (r > 0); |
| 228 | |||
| 229 | lseek(fd, 0, SEEK_SET); | ||
| 230 | |||
| 231 | return size; | ||
| 232 | } | ||
| 233 | |||
| 234 | static unsigned long get_size(const char *file) | ||
| 235 | { | ||
| 236 | unsigned long long size = 0; | ||
| 237 | int fd; | ||
| 238 | |||
| 239 | fd = open(file, O_RDONLY); | ||
| 240 | if (fd < 0) | ||
| 241 | die("Can't read '%s'", file); | ||
| 242 | size = get_size_fd(fd); | ||
| 243 | close(fd); | 208 | close(fd); |
| 244 | 209 | ||
| 245 | return size; | 210 | /* ugh, handle big-endian hdr_size == 4 */ |
| 211 | sizep = (char*)&size; | ||
| 212 | if (bigendian()) | ||
| 213 | sizep += sizeof(u64) - hdr_sz; | ||
| 214 | |||
| 215 | if (pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) | ||
| 216 | die("writing to %s", output_file); | ||
| 246 | } | 217 | } |
| 247 | 218 | ||
| 248 | static void read_header_files(void) | 219 | static void read_header_files(void) |
| 249 | { | 220 | { |
| 250 | unsigned long long size, check_size; | ||
| 251 | char *path; | 221 | char *path; |
| 252 | int fd; | 222 | struct stat st; |
| 253 | 223 | ||
| 254 | path = get_tracing_file("events/header_page"); | 224 | path = get_tracing_file("events/header_page"); |
| 255 | fd = open(path, O_RDONLY); | 225 | if (stat(path, &st) < 0) |
| 256 | if (fd < 0) | ||
| 257 | die("can't read '%s'", path); | 226 | die("can't read '%s'", path); |
| 258 | 227 | ||
| 259 | /* unfortunately, you can not stat debugfs files for size */ | ||
| 260 | size = get_size_fd(fd); | ||
| 261 | |||
| 262 | write_or_die("header_page", 12); | 228 | write_or_die("header_page", 12); |
| 263 | write_or_die(&size, 8); | 229 | record_file(path, 8); |
| 264 | check_size = copy_file_fd(fd); | ||
| 265 | close(fd); | ||
| 266 | |||
| 267 | if (size != check_size) | ||
| 268 | die("wrong size for '%s' size=%lld read=%lld", | ||
| 269 | path, size, check_size); | ||
| 270 | put_tracing_file(path); | 230 | put_tracing_file(path); |
| 271 | 231 | ||
| 272 | path = get_tracing_file("events/header_event"); | 232 | path = get_tracing_file("events/header_event"); |
| 273 | fd = open(path, O_RDONLY); | 233 | if (stat(path, &st) < 0) |
| 274 | if (fd < 0) | ||
| 275 | die("can't read '%s'", path); | 234 | die("can't read '%s'", path); |
| 276 | 235 | ||
| 277 | size = get_size_fd(fd); | ||
| 278 | |||
| 279 | write_or_die("header_event", 13); | 236 | write_or_die("header_event", 13); |
| 280 | write_or_die(&size, 8); | 237 | record_file(path, 8); |
| 281 | check_size = copy_file_fd(fd); | ||
| 282 | if (size != check_size) | ||
| 283 | die("wrong size for '%s'", path); | ||
| 284 | put_tracing_file(path); | 238 | put_tracing_file(path); |
| 285 | close(fd); | ||
| 286 | } | 239 | } |
| 287 | 240 | ||
| 288 | static bool name_in_tp_list(char *sys, struct tracepoint_path *tps) | 241 | static bool name_in_tp_list(char *sys, struct tracepoint_path *tps) |
| @@ -298,7 +251,6 @@ static bool name_in_tp_list(char *sys, struct tracepoint_path *tps) | |||
| 298 | 251 | ||
| 299 | static void copy_event_system(const char *sys, struct tracepoint_path *tps) | 252 | static void copy_event_system(const char *sys, struct tracepoint_path *tps) |
| 300 | { | 253 | { |
| 301 | unsigned long long size, check_size; | ||
| 302 | struct dirent *dent; | 254 | struct dirent *dent; |
| 303 | struct stat st; | 255 | struct stat st; |
| 304 | char *format; | 256 | char *format; |
| @@ -338,14 +290,8 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
| 338 | sprintf(format, "%s/%s/format", sys, dent->d_name); | 290 | sprintf(format, "%s/%s/format", sys, dent->d_name); |
| 339 | ret = stat(format, &st); | 291 | ret = stat(format, &st); |
| 340 | 292 | ||
| 341 | if (ret >= 0) { | 293 | if (ret >= 0) |
| 342 | /* unfortunately, you can not stat debugfs files for size */ | 294 | record_file(format, 8); |
| 343 | size = get_size(format); | ||
| 344 | write_or_die(&size, 8); | ||
| 345 | check_size = copy_file(format); | ||
| 346 | if (size != check_size) | ||
| 347 | die("error in size of file '%s'", format); | ||
| 348 | } | ||
| 349 | 295 | ||
| 350 | free(format); | 296 | free(format); |
| 351 | } | 297 | } |
| @@ -426,7 +372,7 @@ static void read_event_files(struct tracepoint_path *tps) | |||
| 426 | 372 | ||
| 427 | static void read_proc_kallsyms(void) | 373 | static void read_proc_kallsyms(void) |
| 428 | { | 374 | { |
| 429 | unsigned int size, check_size; | 375 | unsigned int size; |
| 430 | const char *path = "/proc/kallsyms"; | 376 | const char *path = "/proc/kallsyms"; |
| 431 | struct stat st; | 377 | struct stat st; |
| 432 | int ret; | 378 | int ret; |
| @@ -438,17 +384,12 @@ static void read_proc_kallsyms(void) | |||
| 438 | write_or_die(&size, 4); | 384 | write_or_die(&size, 4); |
| 439 | return; | 385 | return; |
| 440 | } | 386 | } |
| 441 | size = get_size(path); | 387 | record_file(path, 4); |
| 442 | write_or_die(&size, 4); | ||
| 443 | check_size = copy_file(path); | ||
| 444 | if (size != check_size) | ||
| 445 | die("error in size of file '%s'", path); | ||
| 446 | |||
| 447 | } | 388 | } |
| 448 | 389 | ||
| 449 | static void read_ftrace_printk(void) | 390 | static void read_ftrace_printk(void) |
| 450 | { | 391 | { |
| 451 | unsigned int size, check_size; | 392 | unsigned int size; |
| 452 | char *path; | 393 | char *path; |
| 453 | struct stat st; | 394 | struct stat st; |
| 454 | int ret; | 395 | int ret; |
| @@ -461,11 +402,8 @@ static void read_ftrace_printk(void) | |||
| 461 | write_or_die(&size, 4); | 402 | write_or_die(&size, 4); |
| 462 | goto out; | 403 | goto out; |
| 463 | } | 404 | } |
| 464 | size = get_size(path); | 405 | record_file(path, 4); |
| 465 | write_or_die(&size, 4); | 406 | |
| 466 | check_size = copy_file(path); | ||
| 467 | if (size != check_size) | ||
| 468 | die("error in size of file '%s'", path); | ||
| 469 | out: | 407 | out: |
| 470 | put_tracing_file(path); | 408 | put_tracing_file(path); |
| 471 | } | 409 | } |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index fc784284ac8b..0128906bac88 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
| @@ -238,6 +238,7 @@ char **argv_split(const char *str, int *argcp); | |||
| 238 | void argv_free(char **argv); | 238 | void argv_free(char **argv); |
| 239 | bool strglobmatch(const char *str, const char *pat); | 239 | bool strglobmatch(const char *str, const char *pat); |
| 240 | bool strlazymatch(const char *str, const char *pat); | 240 | bool strlazymatch(const char *str, const char *pat); |
| 241 | int strtailcmp(const char *s1, const char *s2); | ||
| 241 | unsigned long convert_unit(unsigned long value, char *unit); | 242 | unsigned long convert_unit(unsigned long value, char *unit); |
| 242 | int readn(int fd, void *buf, size_t size); | 243 | int readn(int fd, void *buf, size_t size); |
| 243 | 244 | ||
