dwarf-aux.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /*
  2. * dwarf-aux.c : libdw auxiliary interfaces
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. */
  19. #include <stdbool.h>
  20. #include "util.h"
  21. #include "debug.h"
  22. #include "dwarf-aux.h"
  23. /**
  24. * cu_find_realpath - Find the realpath of the target file
  25. * @cu_die: A DIE(dwarf information entry) of CU(compilation Unit)
  26. * @fname: The tail filename of the target file
  27. *
  28. * Find the real(long) path of @fname in @cu_die.
  29. */
  30. const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
  31. {
  32. Dwarf_Files *files;
  33. size_t nfiles, i;
  34. const char *src = NULL;
  35. int ret;
  36. if (!fname)
  37. return NULL;
  38. ret = dwarf_getsrcfiles(cu_die, &files, &nfiles);
  39. if (ret != 0)
  40. return NULL;
  41. for (i = 0; i < nfiles; i++) {
  42. src = dwarf_filesrc(files, i, NULL, NULL);
  43. if (strtailcmp(src, fname) == 0)
  44. break;
  45. }
  46. if (i == nfiles)
  47. return NULL;
  48. return src;
  49. }
  50. /**
  51. * cu_get_comp_dir - Get the path of compilation directory
  52. * @cu_die: a CU DIE
  53. *
  54. * Get the path of compilation directory of given @cu_die.
  55. * Since this depends on DW_AT_comp_dir, older gcc will not
  56. * embedded it. In that case, this returns NULL.
  57. */
  58. const char *cu_get_comp_dir(Dwarf_Die *cu_die)
  59. {
  60. Dwarf_Attribute attr;
  61. if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL)
  62. return NULL;
  63. return dwarf_formstring(&attr);
  64. }
  65. /**
  66. * cu_find_lineinfo - Get a line number and file name for given address
  67. * @cu_die: a CU DIE
  68. * @addr: An address
  69. * @fname: a pointer which returns the file name string
  70. * @lineno: a pointer which returns the line number
  71. *
  72. * Find a line number and file name for @addr in @cu_die.
  73. */
  74. int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr,
  75. const char **fname, int *lineno)
  76. {
  77. Dwarf_Line *line;
  78. Dwarf_Addr laddr;
  79. line = dwarf_getsrc_die(cu_die, (Dwarf_Addr)addr);
  80. if (line && dwarf_lineaddr(line, &laddr) == 0 &&
  81. addr == (unsigned long)laddr && dwarf_lineno(line, lineno) == 0) {
  82. *fname = dwarf_linesrc(line, NULL, NULL);
  83. if (!*fname)
  84. /* line number is useless without filename */
  85. *lineno = 0;
  86. }
  87. return *lineno ?: -ENOENT;
  88. }
  89. static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data);
  90. /**
  91. * cu_walk_functions_at - Walk on function DIEs at given address
  92. * @cu_die: A CU DIE
  93. * @addr: An address
  94. * @callback: A callback which called with found DIEs
  95. * @data: A user data
  96. *
  97. * Walk on function DIEs at given @addr in @cu_die. Passed DIEs
  98. * should be subprogram or inlined-subroutines.
  99. */
  100. int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
  101. int (*callback)(Dwarf_Die *, void *), void *data)
  102. {
  103. Dwarf_Die die_mem;
  104. Dwarf_Die *sc_die;
  105. int ret = -ENOENT;
  106. /* Inlined function could be recursive. Trace it until fail */
  107. for (sc_die = die_find_realfunc(cu_die, addr, &die_mem);
  108. sc_die != NULL;
  109. sc_die = die_find_child(sc_die, __die_find_inline_cb, &addr,
  110. &die_mem)) {
  111. ret = callback(sc_die, data);
  112. if (ret)
  113. break;
  114. }
  115. return ret;
  116. }
  117. /**
  118. * die_get_linkage_name - Get the linkage name of the object
  119. * @dw_die: A DIE of the object
  120. *
  121. * Get the linkage name attiribute of given @dw_die.
  122. * For C++ binary, the linkage name will be the mangled symbol.
  123. */
  124. const char *die_get_linkage_name(Dwarf_Die *dw_die)
  125. {
  126. Dwarf_Attribute attr;
  127. if (dwarf_attr_integrate(dw_die, DW_AT_linkage_name, &attr) == NULL)
  128. return NULL;
  129. return dwarf_formstring(&attr);
  130. }
  131. /**
  132. * die_compare_name - Compare diename and tname
  133. * @dw_die: a DIE
  134. * @tname: a string of target name
  135. *
  136. * Compare the name of @dw_die and @tname. Return false if @dw_die has no name.
  137. */
  138. bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
  139. {
  140. const char *name;
  141. name = dwarf_diename(dw_die);
  142. return name ? (strcmp(tname, name) == 0) : false;
  143. }
  144. /**
  145. * die_match_name - Match diename/linkage name and glob
  146. * @dw_die: a DIE
  147. * @glob: a string of target glob pattern
  148. *
  149. * Glob matching the name of @dw_die and @glob. Return false if matching fail.
  150. * This also match linkage name.
  151. */
  152. bool die_match_name(Dwarf_Die *dw_die, const char *glob)
  153. {
  154. const char *name;
  155. name = dwarf_diename(dw_die);
  156. if (name && strglobmatch(name, glob))
  157. return true;
  158. /* fall back to check linkage name */
  159. name = die_get_linkage_name(dw_die);
  160. if (name && strglobmatch(name, glob))
  161. return true;
  162. return false;
  163. }
  164. /**
  165. * die_get_call_lineno - Get callsite line number of inline-function instance
  166. * @in_die: a DIE of an inlined function instance
  167. *
  168. * Get call-site line number of @in_die. This means from where the inline
  169. * function is called.
  170. */
  171. int die_get_call_lineno(Dwarf_Die *in_die)
  172. {
  173. Dwarf_Attribute attr;
  174. Dwarf_Word ret;
  175. if (!dwarf_attr(in_die, DW_AT_call_line, &attr))
  176. return -ENOENT;
  177. dwarf_formudata(&attr, &ret);
  178. return (int)ret;
  179. }
  180. /**
  181. * die_get_type - Get type DIE
  182. * @vr_die: a DIE of a variable
  183. * @die_mem: where to store a type DIE
  184. *
  185. * Get a DIE of the type of given variable (@vr_die), and store
  186. * it to die_mem. Return NULL if fails to get a type DIE.
  187. */
  188. Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
  189. {
  190. Dwarf_Attribute attr;
  191. if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) &&
  192. dwarf_formref_die(&attr, die_mem))
  193. return die_mem;
  194. else
  195. return NULL;
  196. }
  197. /* Get a type die, but skip qualifiers */
  198. static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
  199. {
  200. int tag;
  201. do {
  202. vr_die = die_get_type(vr_die, die_mem);
  203. if (!vr_die)
  204. break;
  205. tag = dwarf_tag(vr_die);
  206. } while (tag == DW_TAG_const_type ||
  207. tag == DW_TAG_restrict_type ||
  208. tag == DW_TAG_volatile_type ||
  209. tag == DW_TAG_shared_type);
  210. return vr_die;
  211. }
  212. /**
  213. * die_get_real_type - Get a type die, but skip qualifiers and typedef
  214. * @vr_die: a DIE of a variable
  215. * @die_mem: where to store a type DIE
  216. *
  217. * Get a DIE of the type of given variable (@vr_die), and store
  218. * it to die_mem. Return NULL if fails to get a type DIE.
  219. * If the type is qualifiers (e.g. const) or typedef, this skips it
  220. * and tries to find real type (structure or basic types, e.g. int).
  221. */
  222. Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
  223. {
  224. do {
  225. vr_die = __die_get_real_type(vr_die, die_mem);
  226. } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef);
  227. return vr_die;
  228. }
  229. /* Get attribute and translate it as a udata */
  230. static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name,
  231. Dwarf_Word *result)
  232. {
  233. Dwarf_Attribute attr;
  234. if (dwarf_attr(tp_die, attr_name, &attr) == NULL ||
  235. dwarf_formudata(&attr, result) != 0)
  236. return -ENOENT;
  237. return 0;
  238. }
  239. /* Get attribute and translate it as a sdata */
  240. static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name,
  241. Dwarf_Sword *result)
  242. {
  243. Dwarf_Attribute attr;
  244. if (dwarf_attr(tp_die, attr_name, &attr) == NULL ||
  245. dwarf_formsdata(&attr, result) != 0)
  246. return -ENOENT;
  247. return 0;
  248. }
  249. /**
  250. * die_is_signed_type - Check whether a type DIE is signed or not
  251. * @tp_die: a DIE of a type
  252. *
  253. * Get the encoding of @tp_die and return true if the encoding
  254. * is signed.
  255. */
  256. bool die_is_signed_type(Dwarf_Die *tp_die)
  257. {
  258. Dwarf_Word ret;
  259. if (die_get_attr_udata(tp_die, DW_AT_encoding, &ret))
  260. return false;
  261. return (ret == DW_ATE_signed_char || ret == DW_ATE_signed ||
  262. ret == DW_ATE_signed_fixed);
  263. }
  264. /**
  265. * die_is_func_def - Ensure that this DIE is a subprogram and definition
  266. * @dw_die: a DIE
  267. *
  268. * Ensure that this DIE is a subprogram and NOT a declaration. This
  269. * returns true if @dw_die is a function definition.
  270. **/
  271. bool die_is_func_def(Dwarf_Die *dw_die)
  272. {
  273. Dwarf_Attribute attr;
  274. return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
  275. dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
  276. }
  277. /**
  278. * die_is_func_instance - Ensure that this DIE is an instance of a subprogram
  279. * @dw_die: a DIE
  280. *
  281. * Ensure that this DIE is an instance (which has an entry address).
  282. * This returns true if @dw_die is a function instance. If not, you need to
  283. * call die_walk_instances() to find actual instances.
  284. **/
  285. bool die_is_func_instance(Dwarf_Die *dw_die)
  286. {
  287. Dwarf_Addr tmp;
  288. /* Actually gcc optimizes non-inline as like as inlined */
  289. return !dwarf_func_inline(dw_die) && dwarf_entrypc(dw_die, &tmp) == 0;
  290. }
  291. /**
  292. * die_get_data_member_location - Get the data-member offset
  293. * @mb_die: a DIE of a member of a data structure
  294. * @offs: The offset of the member in the data structure
  295. *
  296. * Get the offset of @mb_die in the data structure including @mb_die, and
  297. * stores result offset to @offs. If any error occurs this returns errno.
  298. */
  299. int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)
  300. {
  301. Dwarf_Attribute attr;
  302. Dwarf_Op *expr;
  303. size_t nexpr;
  304. int ret;
  305. if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL)
  306. return -ENOENT;
  307. if (dwarf_formudata(&attr, offs) != 0) {
  308. /* DW_AT_data_member_location should be DW_OP_plus_uconst */
  309. ret = dwarf_getlocation(&attr, &expr, &nexpr);
  310. if (ret < 0 || nexpr == 0)
  311. return -ENOENT;
  312. if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) {
  313. pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n",
  314. expr[0].atom, nexpr);
  315. return -ENOTSUP;
  316. }
  317. *offs = (Dwarf_Word)expr[0].number;
  318. }
  319. return 0;
  320. }
  321. /* Get the call file index number in CU DIE */
  322. static int die_get_call_fileno(Dwarf_Die *in_die)
  323. {
  324. Dwarf_Sword idx;
  325. if (die_get_attr_sdata(in_die, DW_AT_call_file, &idx) == 0)
  326. return (int)idx;
  327. else
  328. return -ENOENT;
  329. }
  330. /* Get the declared file index number in CU DIE */
  331. static int die_get_decl_fileno(Dwarf_Die *pdie)
  332. {
  333. Dwarf_Sword idx;
  334. if (die_get_attr_sdata(pdie, DW_AT_decl_file, &idx) == 0)
  335. return (int)idx;
  336. else
  337. return -ENOENT;
  338. }
  339. /**
  340. * die_get_call_file - Get callsite file name of inlined function instance
  341. * @in_die: a DIE of an inlined function instance
  342. *
  343. * Get call-site file name of @in_die. This means from which file the inline
  344. * function is called.
  345. */
  346. const char *die_get_call_file(Dwarf_Die *in_die)
  347. {
  348. Dwarf_Die cu_die;
  349. Dwarf_Files *files;
  350. int idx;
  351. idx = die_get_call_fileno(in_die);
  352. if (idx < 0 || !dwarf_diecu(in_die, &cu_die, NULL, NULL) ||
  353. dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
  354. return NULL;
  355. return dwarf_filesrc(files, idx, NULL, NULL);
  356. }
  357. /**
  358. * die_find_child - Generic DIE search function in DIE tree
  359. * @rt_die: a root DIE
  360. * @callback: a callback function
  361. * @data: a user data passed to the callback function
  362. * @die_mem: a buffer for result DIE
  363. *
  364. * Trace DIE tree from @rt_die and call @callback for each child DIE.
  365. * If @callback returns DIE_FIND_CB_END, this stores the DIE into
  366. * @die_mem and returns it. If @callback returns DIE_FIND_CB_CONTINUE,
  367. * this continues to trace the tree. Optionally, @callback can return
  368. * DIE_FIND_CB_CHILD and DIE_FIND_CB_SIBLING, those means trace only
  369. * the children and trace only the siblings respectively.
  370. * Returns NULL if @callback can't find any appropriate DIE.
  371. */
  372. Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
  373. int (*callback)(Dwarf_Die *, void *),
  374. void *data, Dwarf_Die *die_mem)
  375. {
  376. Dwarf_Die child_die;
  377. int ret;
  378. ret = dwarf_child(rt_die, die_mem);
  379. if (ret != 0)
  380. return NULL;
  381. do {
  382. ret = callback(die_mem, data);
  383. if (ret == DIE_FIND_CB_END)
  384. return die_mem;
  385. if ((ret & DIE_FIND_CB_CHILD) &&
  386. die_find_child(die_mem, callback, data, &child_die)) {
  387. memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
  388. return die_mem;
  389. }
  390. } while ((ret & DIE_FIND_CB_SIBLING) &&
  391. dwarf_siblingof(die_mem, die_mem) == 0);
  392. return NULL;
  393. }
  394. struct __addr_die_search_param {
  395. Dwarf_Addr addr;
  396. Dwarf_Die *die_mem;
  397. };
  398. static int __die_search_func_tail_cb(Dwarf_Die *fn_die, void *data)
  399. {
  400. struct __addr_die_search_param *ad = data;
  401. Dwarf_Addr addr = 0;
  402. if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
  403. !dwarf_highpc(fn_die, &addr) &&
  404. addr == ad->addr) {
  405. memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die));
  406. return DWARF_CB_ABORT;
  407. }
  408. return DWARF_CB_OK;
  409. }
  410. /**
  411. * die_find_tailfunc - Search for a non-inlined function with tail call at
  412. * given address
  413. * @cu_die: a CU DIE which including @addr
  414. * @addr: target address
  415. * @die_mem: a buffer for result DIE
  416. *
  417. * Search for a non-inlined function DIE with tail call at @addr. Stores the
  418. * DIE to @die_mem and returns it if found. Returns NULL if failed.
  419. */
  420. Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
  421. Dwarf_Die *die_mem)
  422. {
  423. struct __addr_die_search_param ad;
  424. ad.addr = addr;
  425. ad.die_mem = die_mem;
  426. /* dwarf_getscopes can't find subprogram. */
  427. if (!dwarf_getfuncs(cu_die, __die_search_func_tail_cb, &ad, 0))
  428. return NULL;
  429. else
  430. return die_mem;
  431. }
  432. /* die_find callback for non-inlined function search */
  433. static int __die_search_func_cb(Dwarf_Die *fn_die, void *data)
  434. {
  435. struct __addr_die_search_param *ad = data;
  436. /*
  437. * Since a declaration entry doesn't has given pc, this always returns
  438. * function definition entry.
  439. */
  440. if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
  441. dwarf_haspc(fn_die, ad->addr)) {
  442. memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die));
  443. return DWARF_CB_ABORT;
  444. }
  445. return DWARF_CB_OK;
  446. }
  447. /**
  448. * die_find_realfunc - Search a non-inlined function at given address
  449. * @cu_die: a CU DIE which including @addr
  450. * @addr: target address
  451. * @die_mem: a buffer for result DIE
  452. *
  453. * Search a non-inlined function DIE which includes @addr. Stores the
  454. * DIE to @die_mem and returns it if found. Returns NULL if failed.
  455. */
  456. Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
  457. Dwarf_Die *die_mem)
  458. {
  459. struct __addr_die_search_param ad;
  460. ad.addr = addr;
  461. ad.die_mem = die_mem;
  462. /* dwarf_getscopes can't find subprogram. */
  463. if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0))
  464. return NULL;
  465. else
  466. return die_mem;
  467. }
  468. /* die_find callback for inline function search */
  469. static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
  470. {
  471. Dwarf_Addr *addr = data;
  472. if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
  473. dwarf_haspc(die_mem, *addr))
  474. return DIE_FIND_CB_END;
  475. return DIE_FIND_CB_CONTINUE;
  476. }
  477. /**
  478. * die_find_top_inlinefunc - Search the top inlined function at given address
  479. * @sp_die: a subprogram DIE which including @addr
  480. * @addr: target address
  481. * @die_mem: a buffer for result DIE
  482. *
  483. * Search an inlined function DIE which includes @addr. Stores the
  484. * DIE to @die_mem and returns it if found. Returns NULL if failed.
  485. * Even if several inlined functions are expanded recursively, this
  486. * doesn't trace it down, and returns the topmost one.
  487. */
  488. Dwarf_Die *die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
  489. Dwarf_Die *die_mem)
  490. {
  491. return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
  492. }
  493. /**
  494. * die_find_inlinefunc - Search an inlined function at given address
  495. * @sp_die: a subprogram DIE which including @addr
  496. * @addr: target address
  497. * @die_mem: a buffer for result DIE
  498. *
  499. * Search an inlined function DIE which includes @addr. Stores the
  500. * DIE to @die_mem and returns it if found. Returns NULL if failed.
  501. * If several inlined functions are expanded recursively, this trace
  502. * it down and returns deepest one.
  503. */
  504. Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
  505. Dwarf_Die *die_mem)
  506. {
  507. Dwarf_Die tmp_die;
  508. sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr, &tmp_die);
  509. if (!sp_die)
  510. return NULL;
  511. /* Inlined function could be recursive. Trace it until fail */
  512. while (sp_die) {
  513. memcpy(die_mem, sp_die, sizeof(Dwarf_Die));
  514. sp_die = die_find_child(sp_die, __die_find_inline_cb, &addr,
  515. &tmp_die);
  516. }
  517. return die_mem;
  518. }
  519. struct __instance_walk_param {
  520. void *addr;
  521. int (*callback)(Dwarf_Die *, void *);
  522. void *data;
  523. int retval;
  524. };
  525. static int __die_walk_instances_cb(Dwarf_Die *inst, void *data)
  526. {
  527. struct __instance_walk_param *iwp = data;
  528. Dwarf_Attribute attr_mem;
  529. Dwarf_Die origin_mem;
  530. Dwarf_Attribute *attr;
  531. Dwarf_Die *origin;
  532. int tmp;
  533. attr = dwarf_attr(inst, DW_AT_abstract_origin, &attr_mem);
  534. if (attr == NULL)
  535. return DIE_FIND_CB_CONTINUE;
  536. origin = dwarf_formref_die(attr, &origin_mem);
  537. if (origin == NULL || origin->addr != iwp->addr)
  538. return DIE_FIND_CB_CONTINUE;
  539. /* Ignore redundant instances */
  540. if (dwarf_tag(inst) == DW_TAG_inlined_subroutine) {
  541. dwarf_decl_line(origin, &tmp);
  542. if (die_get_call_lineno(inst) == tmp) {
  543. tmp = die_get_decl_fileno(origin);
  544. if (die_get_call_fileno(inst) == tmp)
  545. return DIE_FIND_CB_CONTINUE;
  546. }
  547. }
  548. iwp->retval = iwp->callback(inst, iwp->data);
  549. return (iwp->retval) ? DIE_FIND_CB_END : DIE_FIND_CB_CONTINUE;
  550. }
  551. /**
  552. * die_walk_instances - Walk on instances of given DIE
  553. * @or_die: an abstract original DIE
  554. * @callback: a callback function which is called with instance DIE
  555. * @data: user data
  556. *
  557. * Walk on the instances of give @in_die. @in_die must be an inlined function
  558. * declartion. This returns the return value of @callback if it returns
  559. * non-zero value, or -ENOENT if there is no instance.
  560. */
  561. int die_walk_instances(Dwarf_Die *or_die, int (*callback)(Dwarf_Die *, void *),
  562. void *data)
  563. {
  564. Dwarf_Die cu_die;
  565. Dwarf_Die die_mem;
  566. struct __instance_walk_param iwp = {
  567. .addr = or_die->addr,
  568. .callback = callback,
  569. .data = data,
  570. .retval = -ENOENT,
  571. };
  572. if (dwarf_diecu(or_die, &cu_die, NULL, NULL) == NULL)
  573. return -ENOENT;
  574. die_find_child(&cu_die, __die_walk_instances_cb, &iwp, &die_mem);
  575. return iwp.retval;
  576. }
  577. /* Line walker internal parameters */
  578. struct __line_walk_param {
  579. bool recursive;
  580. line_walk_callback_t callback;
  581. void *data;
  582. int retval;
  583. };
  584. static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data)
  585. {
  586. struct __line_walk_param *lw = data;
  587. Dwarf_Addr addr = 0;
  588. const char *fname;
  589. int lineno;
  590. if (dwarf_tag(in_die) == DW_TAG_inlined_subroutine) {
  591. fname = die_get_call_file(in_die);
  592. lineno = die_get_call_lineno(in_die);
  593. if (fname && lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) {
  594. lw->retval = lw->callback(fname, lineno, addr, lw->data);
  595. if (lw->retval != 0)
  596. return DIE_FIND_CB_END;
  597. }
  598. }
  599. if (!lw->recursive)
  600. /* Don't need to search recursively */
  601. return DIE_FIND_CB_SIBLING;
  602. if (addr) {
  603. fname = dwarf_decl_file(in_die);
  604. if (fname && dwarf_decl_line(in_die, &lineno) == 0) {
  605. lw->retval = lw->callback(fname, lineno, addr, lw->data);
  606. if (lw->retval != 0)
  607. return DIE_FIND_CB_END;
  608. }
  609. }
  610. /* Continue to search nested inlined function call-sites */
  611. return DIE_FIND_CB_CONTINUE;
  612. }
  613. /* Walk on lines of blocks included in given DIE */
  614. static int __die_walk_funclines(Dwarf_Die *sp_die, bool recursive,
  615. line_walk_callback_t callback, void *data)
  616. {
  617. struct __line_walk_param lw = {
  618. .recursive = recursive,
  619. .callback = callback,
  620. .data = data,
  621. .retval = 0,
  622. };
  623. Dwarf_Die die_mem;
  624. Dwarf_Addr addr;
  625. const char *fname;
  626. int lineno;
  627. /* Handle function declaration line */
  628. fname = dwarf_decl_file(sp_die);
  629. if (fname && dwarf_decl_line(sp_die, &lineno) == 0 &&
  630. dwarf_entrypc(sp_die, &addr) == 0) {
  631. lw.retval = callback(fname, lineno, addr, data);
  632. if (lw.retval != 0)
  633. goto done;
  634. }
  635. die_find_child(sp_die, __die_walk_funclines_cb, &lw, &die_mem);
  636. done:
  637. return lw.retval;
  638. }
  639. static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data)
  640. {
  641. struct __line_walk_param *lw = data;
  642. lw->retval = __die_walk_funclines(sp_die, true, lw->callback, lw->data);
  643. if (lw->retval != 0)
  644. return DWARF_CB_ABORT;
  645. return DWARF_CB_OK;
  646. }
  647. /**
  648. * die_walk_lines - Walk on lines inside given DIE
  649. * @rt_die: a root DIE (CU, subprogram or inlined_subroutine)
  650. * @callback: callback routine
  651. * @data: user data
  652. *
  653. * Walk on all lines inside given @rt_die and call @callback on each line.
  654. * If the @rt_die is a function, walk only on the lines inside the function,
  655. * otherwise @rt_die must be a CU DIE.
  656. * Note that this walks not only dwarf line list, but also function entries
  657. * and inline call-site.
  658. */
  659. int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)
  660. {
  661. Dwarf_Lines *lines;
  662. Dwarf_Line *line;
  663. Dwarf_Addr addr;
  664. const char *fname, *decf = NULL;
  665. int lineno, ret = 0;
  666. int decl = 0, inl;
  667. Dwarf_Die die_mem, *cu_die;
  668. size_t nlines, i;
  669. /* Get the CU die */
  670. if (dwarf_tag(rt_die) != DW_TAG_compile_unit) {
  671. cu_die = dwarf_diecu(rt_die, &die_mem, NULL, NULL);
  672. dwarf_decl_line(rt_die, &decl);
  673. decf = dwarf_decl_file(rt_die);
  674. } else
  675. cu_die = rt_die;
  676. if (!cu_die) {
  677. pr_debug2("Failed to get CU from given DIE.\n");
  678. return -EINVAL;
  679. }
  680. /* Get lines list in the CU */
  681. if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0) {
  682. pr_debug2("Failed to get source lines on this CU.\n");
  683. return -ENOENT;
  684. }
  685. pr_debug2("Get %zd lines from this CU\n", nlines);
  686. /* Walk on the lines on lines list */
  687. for (i = 0; i < nlines; i++) {
  688. line = dwarf_onesrcline(lines, i);
  689. if (line == NULL ||
  690. dwarf_lineno(line, &lineno) != 0 ||
  691. dwarf_lineaddr(line, &addr) != 0) {
  692. pr_debug2("Failed to get line info. "
  693. "Possible error in debuginfo.\n");
  694. continue;
  695. }
  696. /* Filter lines based on address */
  697. if (rt_die != cu_die) {
  698. /*
  699. * Address filtering
  700. * The line is included in given function, and
  701. * no inline block includes it.
  702. */
  703. if (!dwarf_haspc(rt_die, addr))
  704. continue;
  705. if (die_find_inlinefunc(rt_die, addr, &die_mem)) {
  706. dwarf_decl_line(&die_mem, &inl);
  707. if (inl != decl ||
  708. decf != dwarf_decl_file(&die_mem))
  709. continue;
  710. }
  711. }
  712. /* Get source line */
  713. fname = dwarf_linesrc(line, NULL, NULL);
  714. ret = callback(fname, lineno, addr, data);
  715. if (ret != 0)
  716. return ret;
  717. }
  718. /*
  719. * Dwarf lines doesn't include function declarations and inlined
  720. * subroutines. We have to check functions list or given function.
  721. */
  722. if (rt_die != cu_die)
  723. /*
  724. * Don't need walk functions recursively, because nested
  725. * inlined functions don't have lines of the specified DIE.
  726. */
  727. ret = __die_walk_funclines(rt_die, false, callback, data);
  728. else {
  729. struct __line_walk_param param = {
  730. .callback = callback,
  731. .data = data,
  732. .retval = 0,
  733. };
  734. dwarf_getfuncs(cu_die, __die_walk_culines_cb, &param, 0);
  735. ret = param.retval;
  736. }
  737. return ret;
  738. }
  739. struct __find_variable_param {
  740. const char *name;
  741. Dwarf_Addr addr;
  742. };
  743. static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
  744. {
  745. struct __find_variable_param *fvp = data;
  746. Dwarf_Attribute attr;
  747. int tag;
  748. tag = dwarf_tag(die_mem);
  749. if ((tag == DW_TAG_formal_parameter ||
  750. tag == DW_TAG_variable) &&
  751. die_compare_name(die_mem, fvp->name) &&
  752. /* Does the DIE have location information or external instance? */
  753. (dwarf_attr(die_mem, DW_AT_external, &attr) ||
  754. dwarf_attr(die_mem, DW_AT_location, &attr)))
  755. return DIE_FIND_CB_END;
  756. if (dwarf_haspc(die_mem, fvp->addr))
  757. return DIE_FIND_CB_CONTINUE;
  758. else
  759. return DIE_FIND_CB_SIBLING;
  760. }
  761. /**
  762. * die_find_variable_at - Find a given name variable at given address
  763. * @sp_die: a function DIE
  764. * @name: variable name
  765. * @addr: address
  766. * @die_mem: a buffer for result DIE
  767. *
  768. * Find a variable DIE called @name at @addr in @sp_die.
  769. */
  770. Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name,
  771. Dwarf_Addr addr, Dwarf_Die *die_mem)
  772. {
  773. struct __find_variable_param fvp = { .name = name, .addr = addr};
  774. return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp,
  775. die_mem);
  776. }
  777. static int __die_find_member_cb(Dwarf_Die *die_mem, void *data)
  778. {
  779. const char *name = data;
  780. if (dwarf_tag(die_mem) == DW_TAG_member) {
  781. if (die_compare_name(die_mem, name))
  782. return DIE_FIND_CB_END;
  783. else if (!dwarf_diename(die_mem)) { /* Unnamed structure */
  784. Dwarf_Die type_die, tmp_die;
  785. if (die_get_type(die_mem, &type_die) &&
  786. die_find_member(&type_die, name, &tmp_die))
  787. return DIE_FIND_CB_END;
  788. }
  789. }
  790. return DIE_FIND_CB_SIBLING;
  791. }
  792. /**
  793. * die_find_member - Find a given name member in a data structure
  794. * @st_die: a data structure type DIE
  795. * @name: member name
  796. * @die_mem: a buffer for result DIE
  797. *
  798. * Find a member DIE called @name in @st_die.
  799. */
  800. Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
  801. Dwarf_Die *die_mem)
  802. {
  803. return die_find_child(st_die, __die_find_member_cb, (void *)name,
  804. die_mem);
  805. }
  806. /**
  807. * die_get_typename - Get the name of given variable DIE
  808. * @vr_die: a variable DIE
  809. * @buf: a strbuf for result type name
  810. *
  811. * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
  812. * and Return -ENOENT if failed to find type name.
  813. * Note that the result will stores typedef name if possible, and stores
  814. * "*(function_type)" if the type is a function pointer.
  815. */
  816. int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
  817. {
  818. Dwarf_Die type;
  819. int tag, ret;
  820. const char *tmp = "";
  821. if (__die_get_real_type(vr_die, &type) == NULL)
  822. return -ENOENT;
  823. tag = dwarf_tag(&type);
  824. if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
  825. tmp = "*";
  826. else if (tag == DW_TAG_subroutine_type) {
  827. /* Function pointer */
  828. return strbuf_add(buf, "(function_type)", 15);
  829. } else {
  830. if (!dwarf_diename(&type))
  831. return -ENOENT;
  832. if (tag == DW_TAG_union_type)
  833. tmp = "union ";
  834. else if (tag == DW_TAG_structure_type)
  835. tmp = "struct ";
  836. else if (tag == DW_TAG_enumeration_type)
  837. tmp = "enum ";
  838. /* Write a base name */
  839. return strbuf_addf(buf, "%s%s", tmp, dwarf_diename(&type));
  840. }
  841. ret = die_get_typename(&type, buf);
  842. return ret ? ret : strbuf_addstr(buf, tmp);
  843. }
  844. /**
  845. * die_get_varname - Get the name and type of given variable DIE
  846. * @vr_die: a variable DIE
  847. * @buf: a strbuf for type and variable name
  848. *
  849. * Get the name and type of @vr_die and stores it in @buf as "type\tname".
  850. */
  851. int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
  852. {
  853. int ret;
  854. ret = die_get_typename(vr_die, buf);
  855. if (ret < 0) {
  856. pr_debug("Failed to get type, make it unknown.\n");
  857. ret = strbuf_add(buf, " (unknown_type)", 14);
  858. }
  859. return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
  860. }
  861. #ifdef HAVE_DWARF_GETLOCATIONS
  862. /**
  863. * die_get_var_innermost_scope - Get innermost scope range of given variable DIE
  864. * @sp_die: a subprogram DIE
  865. * @vr_die: a variable DIE
  866. * @buf: a strbuf for variable byte offset range
  867. *
  868. * Get the innermost scope range of @vr_die and stores it in @buf as
  869. * "@<function_name+[NN-NN,NN-NN]>".
  870. */
  871. static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,
  872. struct strbuf *buf)
  873. {
  874. Dwarf_Die *scopes;
  875. int count;
  876. size_t offset = 0;
  877. Dwarf_Addr base;
  878. Dwarf_Addr start, end;
  879. Dwarf_Addr entry;
  880. int ret;
  881. bool first = true;
  882. const char *name;
  883. ret = dwarf_entrypc(sp_die, &entry);
  884. if (ret)
  885. return ret;
  886. name = dwarf_diename(sp_die);
  887. if (!name)
  888. return -ENOENT;
  889. count = dwarf_getscopes_die(vr_die, &scopes);
  890. /* (*SCOPES)[1] is the DIE for the scope containing that scope */
  891. if (count <= 1) {
  892. ret = -EINVAL;
  893. goto out;
  894. }
  895. while ((offset = dwarf_ranges(&scopes[1], offset, &base,
  896. &start, &end)) > 0) {
  897. start -= entry;
  898. end -= entry;
  899. if (first) {
  900. ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
  901. name, start, end);
  902. first = false;
  903. } else {
  904. ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
  905. start, end);
  906. }
  907. if (ret < 0)
  908. goto out;
  909. }
  910. if (!first)
  911. ret = strbuf_add(buf, "]>", 2);
  912. out:
  913. free(scopes);
  914. return ret;
  915. }
  916. /**
  917. * die_get_var_range - Get byte offset range of given variable DIE
  918. * @sp_die: a subprogram DIE
  919. * @vr_die: a variable DIE
  920. * @buf: a strbuf for type and variable name and byte offset range
  921. *
  922. * Get the byte offset range of @vr_die and stores it in @buf as
  923. * "@<function_name+[NN-NN,NN-NN]>".
  924. */
  925. int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)
  926. {
  927. int ret = 0;
  928. Dwarf_Addr base;
  929. Dwarf_Addr start, end;
  930. Dwarf_Addr entry;
  931. Dwarf_Op *op;
  932. size_t nops;
  933. size_t offset = 0;
  934. Dwarf_Attribute attr;
  935. bool first = true;
  936. const char *name;
  937. ret = dwarf_entrypc(sp_die, &entry);
  938. if (ret)
  939. return ret;
  940. name = dwarf_diename(sp_die);
  941. if (!name)
  942. return -ENOENT;
  943. if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
  944. return -EINVAL;
  945. while ((offset = dwarf_getlocations(&attr, offset, &base,
  946. &start, &end, &op, &nops)) > 0) {
  947. if (start == 0) {
  948. /* Single Location Descriptions */
  949. ret = die_get_var_innermost_scope(sp_die, vr_die, buf);
  950. goto out;
  951. }
  952. /* Location Lists */
  953. start -= entry;
  954. end -= entry;
  955. if (first) {
  956. ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64,
  957. name, start, end);
  958. first = false;
  959. } else {
  960. ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64,
  961. start, end);
  962. }
  963. if (ret < 0)
  964. goto out;
  965. }
  966. if (!first)
  967. ret = strbuf_add(buf, "]>", 2);
  968. out:
  969. return ret;
  970. }
  971. #else
  972. int die_get_var_range(Dwarf_Die *sp_die __maybe_unused,
  973. Dwarf_Die *vr_die __maybe_unused,
  974. struct strbuf *buf __maybe_unused)
  975. {
  976. return -ENOTSUP;
  977. }
  978. #endif
  979. /*
  980. * die_has_loclist - Check if DW_AT_location of @vr_die is a location list
  981. * @vr_die: a variable DIE
  982. */
  983. static bool die_has_loclist(Dwarf_Die *vr_die)
  984. {
  985. Dwarf_Attribute loc;
  986. int tag = dwarf_tag(vr_die);
  987. if (tag != DW_TAG_formal_parameter &&
  988. tag != DW_TAG_variable)
  989. return false;
  990. return (dwarf_attr_integrate(vr_die, DW_AT_location, &loc) &&
  991. dwarf_whatform(&loc) == DW_FORM_sec_offset);
  992. }
  993. /*
  994. * die_is_optimized_target - Check if target program is compiled with
  995. * optimization
  996. * @cu_die: a CU DIE
  997. *
  998. * For any object in given CU whose DW_AT_location is a location list,
  999. * target program is compiled with optimization. This is applicable to
  1000. * clang as well.
  1001. */
  1002. bool die_is_optimized_target(Dwarf_Die *cu_die)
  1003. {
  1004. Dwarf_Die tmp_die;
  1005. if (die_has_loclist(cu_die))
  1006. return true;
  1007. if (!dwarf_child(cu_die, &tmp_die) &&
  1008. die_is_optimized_target(&tmp_die))
  1009. return true;
  1010. if (!dwarf_siblingof(cu_die, &tmp_die) &&
  1011. die_is_optimized_target(&tmp_die))
  1012. return true;
  1013. return false;
  1014. }
  1015. /*
  1016. * die_search_idx - Search index of given line address
  1017. * @lines: Line records of single CU
  1018. * @nr_lines: Number of @lines
  1019. * @addr: address we are looking for
  1020. * @idx: index to be set by this function (return value)
  1021. *
  1022. * Search for @addr by looping over every lines of CU. If address
  1023. * matches, set index of that line in @idx. Note that single source
  1024. * line can have multiple line records. i.e. single source line can
  1025. * have multiple index.
  1026. */
  1027. static bool die_search_idx(Dwarf_Lines *lines, unsigned long nr_lines,
  1028. Dwarf_Addr addr, unsigned long *idx)
  1029. {
  1030. unsigned long i;
  1031. Dwarf_Addr tmp;
  1032. for (i = 0; i < nr_lines; i++) {
  1033. if (dwarf_lineaddr(dwarf_onesrcline(lines, i), &tmp))
  1034. return false;
  1035. if (tmp == addr) {
  1036. *idx = i;
  1037. return true;
  1038. }
  1039. }
  1040. return false;
  1041. }
  1042. /*
  1043. * die_get_postprologue_addr - Search next address after function prologue
  1044. * @entrypc_idx: entrypc index
  1045. * @lines: Line records of single CU
  1046. * @nr_lines: Number of @lines
  1047. * @hignpc: high PC address of function
  1048. * @postprologue_addr: Next address after function prologue (return value)
  1049. *
  1050. * Look for prologue-end marker. If there is no explicit marker, return
  1051. * address of next line record or next source line.
  1052. */
  1053. static bool die_get_postprologue_addr(unsigned long entrypc_idx,
  1054. Dwarf_Lines *lines,
  1055. unsigned long nr_lines,
  1056. Dwarf_Addr highpc,
  1057. Dwarf_Addr *postprologue_addr)
  1058. {
  1059. unsigned long i;
  1060. int entrypc_lno, lno;
  1061. Dwarf_Line *line;
  1062. Dwarf_Addr addr;
  1063. bool p_end;
  1064. /* entrypc_lno is actual source line number */
  1065. line = dwarf_onesrcline(lines, entrypc_idx);
  1066. if (dwarf_lineno(line, &entrypc_lno))
  1067. return false;
  1068. for (i = entrypc_idx; i < nr_lines; i++) {
  1069. line = dwarf_onesrcline(lines, i);
  1070. if (dwarf_lineaddr(line, &addr) ||
  1071. dwarf_lineno(line, &lno) ||
  1072. dwarf_lineprologueend(line, &p_end))
  1073. return false;
  1074. /* highpc is exclusive. [entrypc,highpc) */
  1075. if (addr >= highpc)
  1076. break;
  1077. /* clang supports prologue-end marker */
  1078. if (p_end)
  1079. break;
  1080. /* Actual next line in source */
  1081. if (lno != entrypc_lno)
  1082. break;
  1083. /*
  1084. * Single source line can have multiple line records.
  1085. * For Example,
  1086. * void foo() { printf("hello\n"); }
  1087. * contains two line records. One points to declaration and
  1088. * other points to printf() line. Variable 'lno' won't get
  1089. * incremented in this case but 'i' will.
  1090. */
  1091. if (i != entrypc_idx)
  1092. break;
  1093. }
  1094. dwarf_lineaddr(line, postprologue_addr);
  1095. if (*postprologue_addr >= highpc)
  1096. dwarf_lineaddr(dwarf_onesrcline(lines, i - 1),
  1097. postprologue_addr);
  1098. return true;
  1099. }
  1100. /*
  1101. * die_skip_prologue - Use next address after prologue as probe location
  1102. * @sp_die: a subprogram DIE
  1103. * @cu_die: a CU DIE
  1104. * @entrypc: entrypc of the function
  1105. *
  1106. * Function prologue prepares stack and registers before executing function
  1107. * logic. When target program is compiled without optimization, function
  1108. * parameter information is only valid after prologue. When we probe entrypc
  1109. * of the function, and try to record function parameter, it contains
  1110. * garbage value.
  1111. */
  1112. void die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die,
  1113. Dwarf_Addr *entrypc)
  1114. {
  1115. size_t nr_lines = 0;
  1116. unsigned long entrypc_idx = 0;
  1117. Dwarf_Lines *lines = NULL;
  1118. Dwarf_Addr postprologue_addr;
  1119. Dwarf_Addr highpc;
  1120. if (dwarf_highpc(sp_die, &highpc))
  1121. return;
  1122. if (dwarf_getsrclines(cu_die, &lines, &nr_lines))
  1123. return;
  1124. if (!die_search_idx(lines, nr_lines, *entrypc, &entrypc_idx))
  1125. return;
  1126. if (!die_get_postprologue_addr(entrypc_idx, lines, nr_lines,
  1127. highpc, &postprologue_addr))
  1128. return;
  1129. *entrypc = postprologue_addr;
  1130. }