dwarf-unwind.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <string.h>
  3. #include "perf_regs.h"
  4. #include "thread.h"
  5. #include "map.h"
  6. #include "event.h"
  7. #include "debug.h"
  8. #include "tests/tests.h"
  9. #define STACK_SIZE 8192
  10. static int sample_ustack(struct perf_sample *sample,
  11. struct thread *thread, u64 *regs)
  12. {
  13. struct stack_dump *stack = &sample->user_stack;
  14. struct map *map;
  15. unsigned long sp;
  16. u64 stack_size, *buf;
  17. buf = malloc(STACK_SIZE);
  18. if (!buf) {
  19. pr_debug("failed to allocate sample uregs data\n");
  20. return -1;
  21. }
  22. sp = (unsigned long) regs[PERF_REG_ARM_SP];
  23. map = map_groups__find(thread->mg, (u64)sp);
  24. if (!map) {
  25. pr_debug("failed to get stack map\n");
  26. free(buf);
  27. return -1;
  28. }
  29. stack_size = map->end - sp;
  30. stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
  31. memcpy(buf, (void *) sp, stack_size);
  32. stack->data = (char *) buf;
  33. stack->size = stack_size;
  34. return 0;
  35. }
  36. int test__arch_unwind_sample(struct perf_sample *sample,
  37. struct thread *thread)
  38. {
  39. struct regs_dump *regs = &sample->user_regs;
  40. u64 *buf;
  41. buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
  42. if (!buf) {
  43. pr_debug("failed to allocate sample uregs data\n");
  44. return -1;
  45. }
  46. perf_regs_load(buf);
  47. regs->abi = PERF_SAMPLE_REGS_ABI;
  48. regs->regs = buf;
  49. regs->mask = PERF_REGS_MASK;
  50. return sample_ustack(sample, thread, buf);
  51. }