dwarf-unwind.c 1.3 KB

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