unwind-libunwind-local.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * Post mortem Dwarf CFI based unwinding on top of regs and stack dumps.
  3. *
  4. * Lots of this code have been borrowed or heavily inspired from parts of
  5. * the libunwind 0.99 code which are (amongst other contributors I may have
  6. * forgotten):
  7. *
  8. * Copyright (C) 2002-2007 Hewlett-Packard Co
  9. * Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  10. *
  11. * And the bugs have been added by:
  12. *
  13. * Copyright (C) 2010, Frederic Weisbecker <fweisbec@gmail.com>
  14. * Copyright (C) 2012, Jiri Olsa <jolsa@redhat.com>
  15. *
  16. */
  17. #include <elf.h>
  18. #include <gelf.h>
  19. #include <fcntl.h>
  20. #include <string.h>
  21. #include <unistd.h>
  22. #include <sys/mman.h>
  23. #include <linux/list.h>
  24. #ifndef REMOTE_UNWIND_LIBUNWIND
  25. #include <libunwind.h>
  26. #include <libunwind-ptrace.h>
  27. #endif
  28. #include "callchain.h"
  29. #include "thread.h"
  30. #include "session.h"
  31. #include "perf_regs.h"
  32. #include "unwind.h"
  33. #include "symbol.h"
  34. #include "util.h"
  35. #include "debug.h"
  36. #include "asm/bug.h"
  37. extern int
  38. UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
  39. unw_word_t ip,
  40. unw_dyn_info_t *di,
  41. unw_proc_info_t *pi,
  42. int need_unwind_info, void *arg);
  43. #define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table)
  44. extern int
  45. UNW_OBJ(dwarf_find_debug_frame) (int found, unw_dyn_info_t *di_debug,
  46. unw_word_t ip,
  47. unw_word_t segbase,
  48. const char *obj_name, unw_word_t start,
  49. unw_word_t end);
  50. #define dwarf_find_debug_frame UNW_OBJ(dwarf_find_debug_frame)
  51. #define DW_EH_PE_FORMAT_MASK 0x0f /* format of the encoded value */
  52. #define DW_EH_PE_APPL_MASK 0x70 /* how the value is to be applied */
  53. /* Pointer-encoding formats: */
  54. #define DW_EH_PE_omit 0xff
  55. #define DW_EH_PE_ptr 0x00 /* pointer-sized unsigned value */
  56. #define DW_EH_PE_udata4 0x03 /* unsigned 32-bit value */
  57. #define DW_EH_PE_udata8 0x04 /* unsigned 64-bit value */
  58. #define DW_EH_PE_sdata4 0x0b /* signed 32-bit value */
  59. #define DW_EH_PE_sdata8 0x0c /* signed 64-bit value */
  60. /* Pointer-encoding application: */
  61. #define DW_EH_PE_absptr 0x00 /* absolute value */
  62. #define DW_EH_PE_pcrel 0x10 /* rel. to addr. of encoded value */
  63. /*
  64. * The following are not documented by LSB v1.3, yet they are used by
  65. * GCC, presumably they aren't documented by LSB since they aren't
  66. * used on Linux:
  67. */
  68. #define DW_EH_PE_funcrel 0x40 /* start-of-procedure-relative */
  69. #define DW_EH_PE_aligned 0x50 /* aligned pointer */
  70. /* Flags intentionaly not handled, since they're not needed:
  71. * #define DW_EH_PE_indirect 0x80
  72. * #define DW_EH_PE_uleb128 0x01
  73. * #define DW_EH_PE_udata2 0x02
  74. * #define DW_EH_PE_sleb128 0x09
  75. * #define DW_EH_PE_sdata2 0x0a
  76. * #define DW_EH_PE_textrel 0x20
  77. * #define DW_EH_PE_datarel 0x30
  78. */
  79. struct unwind_info {
  80. struct perf_sample *sample;
  81. struct machine *machine;
  82. struct thread *thread;
  83. };
  84. #define dw_read(ptr, type, end) ({ \
  85. type *__p = (type *) ptr; \
  86. type __v; \
  87. if ((__p + 1) > (type *) end) \
  88. return -EINVAL; \
  89. __v = *__p++; \
  90. ptr = (typeof(ptr)) __p; \
  91. __v; \
  92. })
  93. static int __dw_read_encoded_value(u8 **p, u8 *end, u64 *val,
  94. u8 encoding)
  95. {
  96. u8 *cur = *p;
  97. *val = 0;
  98. switch (encoding) {
  99. case DW_EH_PE_omit:
  100. *val = 0;
  101. goto out;
  102. case DW_EH_PE_ptr:
  103. *val = dw_read(cur, unsigned long, end);
  104. goto out;
  105. default:
  106. break;
  107. }
  108. switch (encoding & DW_EH_PE_APPL_MASK) {
  109. case DW_EH_PE_absptr:
  110. break;
  111. case DW_EH_PE_pcrel:
  112. *val = (unsigned long) cur;
  113. break;
  114. default:
  115. return -EINVAL;
  116. }
  117. if ((encoding & 0x07) == 0x00)
  118. encoding |= DW_EH_PE_udata4;
  119. switch (encoding & DW_EH_PE_FORMAT_MASK) {
  120. case DW_EH_PE_sdata4:
  121. *val += dw_read(cur, s32, end);
  122. break;
  123. case DW_EH_PE_udata4:
  124. *val += dw_read(cur, u32, end);
  125. break;
  126. case DW_EH_PE_sdata8:
  127. *val += dw_read(cur, s64, end);
  128. break;
  129. case DW_EH_PE_udata8:
  130. *val += dw_read(cur, u64, end);
  131. break;
  132. default:
  133. return -EINVAL;
  134. }
  135. out:
  136. *p = cur;
  137. return 0;
  138. }
  139. #define dw_read_encoded_value(ptr, end, enc) ({ \
  140. u64 __v; \
  141. if (__dw_read_encoded_value(&ptr, end, &__v, enc)) { \
  142. return -EINVAL; \
  143. } \
  144. __v; \
  145. })
  146. static u64 elf_section_offset(int fd, const char *name)
  147. {
  148. Elf *elf;
  149. GElf_Ehdr ehdr;
  150. GElf_Shdr shdr;
  151. u64 offset = 0;
  152. elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
  153. if (elf == NULL)
  154. return 0;
  155. do {
  156. if (gelf_getehdr(elf, &ehdr) == NULL)
  157. break;
  158. if (!elf_section_by_name(elf, &ehdr, &shdr, name, NULL))
  159. break;
  160. offset = shdr.sh_offset;
  161. } while (0);
  162. elf_end(elf);
  163. return offset;
  164. }
  165. #ifndef NO_LIBUNWIND_DEBUG_FRAME
  166. static int elf_is_exec(int fd, const char *name)
  167. {
  168. Elf *elf;
  169. GElf_Ehdr ehdr;
  170. int retval = 0;
  171. elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
  172. if (elf == NULL)
  173. return 0;
  174. if (gelf_getehdr(elf, &ehdr) == NULL)
  175. goto out;
  176. retval = (ehdr.e_type == ET_EXEC);
  177. out:
  178. elf_end(elf);
  179. pr_debug("unwind: elf_is_exec(%s): %d\n", name, retval);
  180. return retval;
  181. }
  182. #endif
  183. struct table_entry {
  184. u32 start_ip_offset;
  185. u32 fde_offset;
  186. };
  187. struct eh_frame_hdr {
  188. unsigned char version;
  189. unsigned char eh_frame_ptr_enc;
  190. unsigned char fde_count_enc;
  191. unsigned char table_enc;
  192. /*
  193. * The rest of the header is variable-length and consists of the
  194. * following members:
  195. *
  196. * encoded_t eh_frame_ptr;
  197. * encoded_t fde_count;
  198. */
  199. /* A single encoded pointer should not be more than 8 bytes. */
  200. u64 enc[2];
  201. /*
  202. * struct {
  203. * encoded_t start_ip;
  204. * encoded_t fde_addr;
  205. * } binary_search_table[fde_count];
  206. */
  207. char data[0];
  208. } __packed;
  209. static int unwind_spec_ehframe(struct dso *dso, struct machine *machine,
  210. u64 offset, u64 *table_data, u64 *segbase,
  211. u64 *fde_count)
  212. {
  213. struct eh_frame_hdr hdr;
  214. u8 *enc = (u8 *) &hdr.enc;
  215. u8 *end = (u8 *) &hdr.data;
  216. ssize_t r;
  217. r = dso__data_read_offset(dso, machine, offset,
  218. (u8 *) &hdr, sizeof(hdr));
  219. if (r != sizeof(hdr))
  220. return -EINVAL;
  221. /* We dont need eh_frame_ptr, just skip it. */
  222. dw_read_encoded_value(enc, end, hdr.eh_frame_ptr_enc);
  223. *fde_count = dw_read_encoded_value(enc, end, hdr.fde_count_enc);
  224. *segbase = offset;
  225. *table_data = (enc - (u8 *) &hdr) + offset;
  226. return 0;
  227. }
  228. static int read_unwind_spec_eh_frame(struct dso *dso, struct machine *machine,
  229. u64 *table_data, u64 *segbase,
  230. u64 *fde_count)
  231. {
  232. int ret = -EINVAL, fd;
  233. u64 offset = dso->data.eh_frame_hdr_offset;
  234. if (offset == 0) {
  235. fd = dso__data_get_fd(dso, machine);
  236. if (fd < 0)
  237. return -EINVAL;
  238. /* Check the .eh_frame section for unwinding info */
  239. offset = elf_section_offset(fd, ".eh_frame_hdr");
  240. dso->data.eh_frame_hdr_offset = offset;
  241. dso__data_put_fd(dso);
  242. }
  243. if (offset)
  244. ret = unwind_spec_ehframe(dso, machine, offset,
  245. table_data, segbase,
  246. fde_count);
  247. return ret;
  248. }
  249. #ifndef NO_LIBUNWIND_DEBUG_FRAME
  250. static int read_unwind_spec_debug_frame(struct dso *dso,
  251. struct machine *machine, u64 *offset)
  252. {
  253. int fd;
  254. u64 ofs = dso->data.debug_frame_offset;
  255. if (ofs == 0) {
  256. fd = dso__data_get_fd(dso, machine);
  257. if (fd < 0)
  258. return -EINVAL;
  259. /* Check the .debug_frame section for unwinding info */
  260. ofs = elf_section_offset(fd, ".debug_frame");
  261. dso->data.debug_frame_offset = ofs;
  262. dso__data_put_fd(dso);
  263. }
  264. *offset = ofs;
  265. if (*offset)
  266. return 0;
  267. return -EINVAL;
  268. }
  269. #endif
  270. static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
  271. {
  272. struct addr_location al;
  273. thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
  274. MAP__FUNCTION, ip, &al);
  275. if (!al.map) {
  276. /*
  277. * We've seen cases (softice) where DWARF unwinder went
  278. * through non executable mmaps, which we need to lookup
  279. * in MAP__VARIABLE tree.
  280. */
  281. thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
  282. MAP__VARIABLE, ip, &al);
  283. }
  284. return al.map;
  285. }
  286. static int
  287. find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
  288. int need_unwind_info, void *arg)
  289. {
  290. struct unwind_info *ui = arg;
  291. struct map *map;
  292. unw_dyn_info_t di;
  293. u64 table_data, segbase, fde_count;
  294. int ret = -EINVAL;
  295. map = find_map(ip, ui);
  296. if (!map || !map->dso)
  297. return -EINVAL;
  298. pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
  299. /* Check the .eh_frame section for unwinding info */
  300. if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
  301. &table_data, &segbase, &fde_count)) {
  302. memset(&di, 0, sizeof(di));
  303. di.format = UNW_INFO_FORMAT_REMOTE_TABLE;
  304. di.start_ip = map->start;
  305. di.end_ip = map->end;
  306. di.u.rti.segbase = map->start + segbase;
  307. di.u.rti.table_data = map->start + table_data;
  308. di.u.rti.table_len = fde_count * sizeof(struct table_entry)
  309. / sizeof(unw_word_t);
  310. ret = dwarf_search_unwind_table(as, ip, &di, pi,
  311. need_unwind_info, arg);
  312. }
  313. #ifndef NO_LIBUNWIND_DEBUG_FRAME
  314. /* Check the .debug_frame section for unwinding info */
  315. if (ret < 0 &&
  316. !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
  317. int fd = dso__data_get_fd(map->dso, ui->machine);
  318. int is_exec = elf_is_exec(fd, map->dso->name);
  319. unw_word_t base = is_exec ? 0 : map->start;
  320. const char *symfile;
  321. if (fd >= 0)
  322. dso__data_put_fd(map->dso);
  323. symfile = map->dso->symsrc_filename ?: map->dso->name;
  324. memset(&di, 0, sizeof(di));
  325. if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
  326. map->start, map->end))
  327. return dwarf_search_unwind_table(as, ip, &di, pi,
  328. need_unwind_info, arg);
  329. }
  330. #endif
  331. return ret;
  332. }
  333. static int access_fpreg(unw_addr_space_t __maybe_unused as,
  334. unw_regnum_t __maybe_unused num,
  335. unw_fpreg_t __maybe_unused *val,
  336. int __maybe_unused __write,
  337. void __maybe_unused *arg)
  338. {
  339. pr_err("unwind: access_fpreg unsupported\n");
  340. return -UNW_EINVAL;
  341. }
  342. static int get_dyn_info_list_addr(unw_addr_space_t __maybe_unused as,
  343. unw_word_t __maybe_unused *dil_addr,
  344. void __maybe_unused *arg)
  345. {
  346. return -UNW_ENOINFO;
  347. }
  348. static int resume(unw_addr_space_t __maybe_unused as,
  349. unw_cursor_t __maybe_unused *cu,
  350. void __maybe_unused *arg)
  351. {
  352. pr_err("unwind: resume unsupported\n");
  353. return -UNW_EINVAL;
  354. }
  355. static int
  356. get_proc_name(unw_addr_space_t __maybe_unused as,
  357. unw_word_t __maybe_unused addr,
  358. char __maybe_unused *bufp, size_t __maybe_unused buf_len,
  359. unw_word_t __maybe_unused *offp, void __maybe_unused *arg)
  360. {
  361. pr_err("unwind: get_proc_name unsupported\n");
  362. return -UNW_EINVAL;
  363. }
  364. static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
  365. unw_word_t *data)
  366. {
  367. struct map *map;
  368. ssize_t size;
  369. map = find_map(addr, ui);
  370. if (!map) {
  371. pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
  372. return -1;
  373. }
  374. if (!map->dso)
  375. return -1;
  376. size = dso__data_read_addr(map->dso, map, ui->machine,
  377. addr, (u8 *) data, sizeof(*data));
  378. return !(size == sizeof(*data));
  379. }
  380. static int access_mem(unw_addr_space_t __maybe_unused as,
  381. unw_word_t addr, unw_word_t *valp,
  382. int __write, void *arg)
  383. {
  384. struct unwind_info *ui = arg;
  385. struct stack_dump *stack = &ui->sample->user_stack;
  386. u64 start, end;
  387. int offset;
  388. int ret;
  389. /* Don't support write, probably not needed. */
  390. if (__write || !stack || !ui->sample->user_regs.regs) {
  391. *valp = 0;
  392. return 0;
  393. }
  394. ret = perf_reg_value(&start, &ui->sample->user_regs,
  395. LIBUNWIND__ARCH_REG_SP);
  396. if (ret)
  397. return ret;
  398. end = start + stack->size;
  399. /* Check overflow. */
  400. if (addr + sizeof(unw_word_t) < addr)
  401. return -EINVAL;
  402. if (addr < start || addr + sizeof(unw_word_t) >= end) {
  403. ret = access_dso_mem(ui, addr, valp);
  404. if (ret) {
  405. pr_debug("unwind: access_mem %p not inside range"
  406. " 0x%" PRIx64 "-0x%" PRIx64 "\n",
  407. (void *) (uintptr_t) addr, start, end);
  408. *valp = 0;
  409. return ret;
  410. }
  411. return 0;
  412. }
  413. offset = addr - start;
  414. *valp = *(unw_word_t *)&stack->data[offset];
  415. pr_debug("unwind: access_mem addr %p val %lx, offset %d\n",
  416. (void *) (uintptr_t) addr, (unsigned long)*valp, offset);
  417. return 0;
  418. }
  419. static int access_reg(unw_addr_space_t __maybe_unused as,
  420. unw_regnum_t regnum, unw_word_t *valp,
  421. int __write, void *arg)
  422. {
  423. struct unwind_info *ui = arg;
  424. int id, ret;
  425. u64 val;
  426. /* Don't support write, I suspect we don't need it. */
  427. if (__write) {
  428. pr_err("unwind: access_reg w %d\n", regnum);
  429. return 0;
  430. }
  431. if (!ui->sample->user_regs.regs) {
  432. *valp = 0;
  433. return 0;
  434. }
  435. id = LIBUNWIND__ARCH_REG_ID(regnum);
  436. if (id < 0)
  437. return -EINVAL;
  438. ret = perf_reg_value(&val, &ui->sample->user_regs, id);
  439. if (ret) {
  440. pr_err("unwind: can't read reg %d\n", regnum);
  441. return ret;
  442. }
  443. *valp = (unw_word_t) val;
  444. pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp);
  445. return 0;
  446. }
  447. static void put_unwind_info(unw_addr_space_t __maybe_unused as,
  448. unw_proc_info_t *pi __maybe_unused,
  449. void *arg __maybe_unused)
  450. {
  451. pr_debug("unwind: put_unwind_info called\n");
  452. }
  453. static int entry(u64 ip, struct thread *thread,
  454. unwind_entry_cb_t cb, void *arg)
  455. {
  456. struct unwind_entry e;
  457. struct addr_location al;
  458. thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
  459. MAP__FUNCTION, ip, &al);
  460. e.ip = al.addr;
  461. e.map = al.map;
  462. e.sym = al.sym;
  463. pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
  464. al.sym ? al.sym->name : "''",
  465. ip,
  466. al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
  467. return cb(&e, arg);
  468. }
  469. static void display_error(int err)
  470. {
  471. switch (err) {
  472. case UNW_EINVAL:
  473. pr_err("unwind: Only supports local.\n");
  474. break;
  475. case UNW_EUNSPEC:
  476. pr_err("unwind: Unspecified error.\n");
  477. break;
  478. case UNW_EBADREG:
  479. pr_err("unwind: Register unavailable.\n");
  480. break;
  481. default:
  482. break;
  483. }
  484. }
  485. static unw_accessors_t accessors = {
  486. .find_proc_info = find_proc_info,
  487. .put_unwind_info = put_unwind_info,
  488. .get_dyn_info_list_addr = get_dyn_info_list_addr,
  489. .access_mem = access_mem,
  490. .access_reg = access_reg,
  491. .access_fpreg = access_fpreg,
  492. .resume = resume,
  493. .get_proc_name = get_proc_name,
  494. };
  495. static int _unwind__prepare_access(struct thread *thread)
  496. {
  497. if (callchain_param.record_mode != CALLCHAIN_DWARF)
  498. return 0;
  499. thread->addr_space = unw_create_addr_space(&accessors, 0);
  500. if (!thread->addr_space) {
  501. pr_err("unwind: Can't create unwind address space.\n");
  502. return -ENOMEM;
  503. }
  504. unw_set_caching_policy(thread->addr_space, UNW_CACHE_GLOBAL);
  505. return 0;
  506. }
  507. static void _unwind__flush_access(struct thread *thread)
  508. {
  509. if (callchain_param.record_mode != CALLCHAIN_DWARF)
  510. return;
  511. unw_flush_cache(thread->addr_space, 0, 0);
  512. }
  513. static void _unwind__finish_access(struct thread *thread)
  514. {
  515. if (callchain_param.record_mode != CALLCHAIN_DWARF)
  516. return;
  517. unw_destroy_addr_space(thread->addr_space);
  518. }
  519. static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
  520. void *arg, int max_stack)
  521. {
  522. u64 val;
  523. unw_word_t ips[max_stack];
  524. unw_addr_space_t addr_space;
  525. unw_cursor_t c;
  526. int ret, i = 0;
  527. ret = perf_reg_value(&val, &ui->sample->user_regs,
  528. LIBUNWIND__ARCH_REG_IP);
  529. if (ret)
  530. return ret;
  531. ips[i++] = (unw_word_t) val;
  532. /*
  533. * If we need more than one entry, do the DWARF
  534. * unwind itself.
  535. */
  536. if (max_stack - 1 > 0) {
  537. WARN_ONCE(!ui->thread, "WARNING: ui->thread is NULL");
  538. addr_space = ui->thread->addr_space;
  539. if (addr_space == NULL)
  540. return -1;
  541. ret = unw_init_remote(&c, addr_space, ui);
  542. if (ret)
  543. display_error(ret);
  544. while (!ret && (unw_step(&c) > 0) && i < max_stack) {
  545. unw_get_reg(&c, UNW_REG_IP, &ips[i]);
  546. /*
  547. * Decrement the IP for any non-activation frames.
  548. * this is required to properly find the srcline
  549. * for caller frames.
  550. * See also the documentation for dwfl_frame_pc(),
  551. * which this code tries to replicate.
  552. */
  553. if (unw_is_signal_frame(&c) <= 0)
  554. --ips[i];
  555. ++i;
  556. }
  557. max_stack = i;
  558. }
  559. /*
  560. * Display what we got based on the order setup.
  561. */
  562. for (i = 0; i < max_stack && !ret; i++) {
  563. int j = i;
  564. if (callchain_param.order == ORDER_CALLER)
  565. j = max_stack - i - 1;
  566. ret = ips[j] ? entry(ips[j], ui->thread, cb, arg) : 0;
  567. }
  568. return ret;
  569. }
  570. static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,
  571. struct thread *thread,
  572. struct perf_sample *data, int max_stack)
  573. {
  574. struct unwind_info ui = {
  575. .sample = data,
  576. .thread = thread,
  577. .machine = thread->mg->machine,
  578. };
  579. if (!data->user_regs.regs)
  580. return -EINVAL;
  581. if (max_stack <= 0)
  582. return -EINVAL;
  583. return get_entries(&ui, cb, arg, max_stack);
  584. }
  585. static struct unwind_libunwind_ops
  586. _unwind_libunwind_ops = {
  587. .prepare_access = _unwind__prepare_access,
  588. .flush_access = _unwind__flush_access,
  589. .finish_access = _unwind__finish_access,
  590. .get_entries = _unwind__get_entries,
  591. };
  592. #ifndef REMOTE_UNWIND_LIBUNWIND
  593. struct unwind_libunwind_ops *
  594. local_unwind_libunwind_ops = &_unwind_libunwind_ops;
  595. #endif