Path: blob/master/tools/perf/arch/arm64/tests/dwarf-unwind.c
26288 views
// SPDX-License-Identifier: GPL-2.01#include <string.h>2#include "perf_regs.h"3#include "thread.h"4#include "map.h"5#include "maps.h"6#include "event.h"7#include "debug.h"8#include "tests/tests.h"910#define STACK_SIZE 81921112static int sample_ustack(struct perf_sample *sample,13struct thread *thread, u64 *regs)14{15struct stack_dump *stack = &sample->user_stack;16struct map *map;17unsigned long sp;18u64 stack_size, *buf;1920buf = malloc(STACK_SIZE);21if (!buf) {22pr_debug("failed to allocate sample uregs data\n");23return -1;24}2526sp = (unsigned long) regs[PERF_REG_ARM64_SP];2728map = maps__find(thread__maps(thread), (u64)sp);29if (!map) {30pr_debug("failed to get stack map\n");31free(buf);32return -1;33}3435stack_size = map__end(map) - sp;36stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;3738memcpy(buf, (void *) sp, stack_size);39stack->data = (char *) buf;40stack->size = stack_size;41return 0;42}4344int test__arch_unwind_sample(struct perf_sample *sample,45struct thread *thread)46{47struct regs_dump *regs = perf_sample__user_regs(sample);48u64 *buf;4950buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);51if (!buf) {52pr_debug("failed to allocate sample uregs data\n");53return -1;54}5556perf_regs_load(buf);57regs->abi = PERF_SAMPLE_REGS_ABI;58regs->regs = buf;59regs->mask = PERF_REGS_MASK;6061return sample_ustack(sample, thread, buf);62}636465