Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include "arm64-frame-pointer-unwind-support.h"
0003 #include "callchain.h"
0004 #include "event.h"
0005 #include "perf_regs.h" // SMPL_REG_MASK
0006 #include "unwind.h"
0007 
0008 #define perf_event_arm_regs perf_event_arm64_regs
0009 #include "../../arch/arm64/include/uapi/asm/perf_regs.h"
0010 #undef perf_event_arm_regs
0011 
0012 struct entries {
0013     u64 stack[2];
0014     size_t length;
0015 };
0016 
0017 static bool get_leaf_frame_caller_enabled(struct perf_sample *sample)
0018 {
0019     return callchain_param.record_mode == CALLCHAIN_FP && sample->user_regs.regs
0020         && sample->user_regs.mask & SMPL_REG_MASK(PERF_REG_ARM64_LR);
0021 }
0022 
0023 static int add_entry(struct unwind_entry *entry, void *arg)
0024 {
0025     struct entries *entries = arg;
0026 
0027     entries->stack[entries->length++] = entry->ip;
0028     return 0;
0029 }
0030 
0031 u64 get_leaf_frame_caller_aarch64(struct perf_sample *sample, struct thread *thread, int usr_idx)
0032 {
0033     int ret;
0034     struct entries entries = {};
0035     struct regs_dump old_regs = sample->user_regs;
0036 
0037     if (!get_leaf_frame_caller_enabled(sample))
0038         return 0;
0039 
0040     /*
0041      * If PC and SP are not recorded, get the value of PC from the stack
0042      * and set its mask. SP is not used when doing the unwinding but it
0043      * still needs to be set to prevent failures.
0044      */
0045 
0046     if (!(sample->user_regs.mask & SMPL_REG_MASK(PERF_REG_ARM64_PC))) {
0047         sample->user_regs.cache_mask |= SMPL_REG_MASK(PERF_REG_ARM64_PC);
0048         sample->user_regs.cache_regs[PERF_REG_ARM64_PC] = sample->callchain->ips[usr_idx+1];
0049     }
0050 
0051     if (!(sample->user_regs.mask & SMPL_REG_MASK(PERF_REG_ARM64_SP))) {
0052         sample->user_regs.cache_mask |= SMPL_REG_MASK(PERF_REG_ARM64_SP);
0053         sample->user_regs.cache_regs[PERF_REG_ARM64_SP] = 0;
0054     }
0055 
0056     ret = unwind__get_entries(add_entry, &entries, thread, sample, 2, true);
0057     sample->user_regs = old_regs;
0058 
0059     if (ret || entries.length != 2)
0060         return ret;
0061 
0062     return callchain_param.order == ORDER_CALLER ? entries.stack[0] : entries.stack[1];
0063 }