Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <string.h>
0003 #include "perf_regs.h"
0004 #include "thread.h"
0005 #include "map.h"
0006 #include "maps.h"
0007 #include "event.h"
0008 #include "debug.h"
0009 #include "tests/tests.h"
0010 
0011 #define STACK_SIZE 8192
0012 
0013 static int sample_ustack(struct perf_sample *sample,
0014              struct thread *thread, u64 *regs)
0015 {
0016     struct stack_dump *stack = &sample->user_stack;
0017     struct map *map;
0018     unsigned long sp;
0019     u64 stack_size, *buf;
0020 
0021     buf = malloc(STACK_SIZE);
0022     if (!buf) {
0023         pr_debug("failed to allocate sample uregs data\n");
0024         return -1;
0025     }
0026 
0027     sp = (unsigned long) regs[PERF_REG_ARM_SP];
0028 
0029     map = maps__find(thread->maps, (u64)sp);
0030     if (!map) {
0031         pr_debug("failed to get stack map\n");
0032         free(buf);
0033         return -1;
0034     }
0035 
0036     stack_size = map->end - sp;
0037     stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
0038 
0039     memcpy(buf, (void *) sp, stack_size);
0040     stack->data = (char *) buf;
0041     stack->size = stack_size;
0042     return 0;
0043 }
0044 
0045 int test__arch_unwind_sample(struct perf_sample *sample,
0046                  struct thread *thread)
0047 {
0048     struct regs_dump *regs = &sample->user_regs;
0049     u64 *buf;
0050 
0051     buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
0052     if (!buf) {
0053         pr_debug("failed to allocate sample uregs data\n");
0054         return -1;
0055     }
0056 
0057     perf_regs_load(buf);
0058     regs->abi  = PERF_SAMPLE_REGS_ABI;
0059     regs->regs = buf;
0060     regs->mask = PERF_REGS_MASK;
0061 
0062     return sample_ustack(sample, thread, buf);
0063 }