dwarf-unwind.c 1.3 KB

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