probe-finder.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. /*
  2. * probe-finder.c : C expression to kprobe event converter
  3. *
  4. * Written by Masami Hiramatsu <mhiramat@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. *
  20. */
  21. #include <sys/utsname.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <fcntl.h>
  25. #include <errno.h>
  26. #include <stdio.h>
  27. #include <unistd.h>
  28. #include <getopt.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <stdarg.h>
  32. #include <ctype.h>
  33. #include <dwarf-regs.h>
  34. #include "string.h"
  35. #include "event.h"
  36. #include "debug.h"
  37. #include "util.h"
  38. #include "probe-finder.h"
  39. /* Kprobe tracer basic type is up to u64 */
  40. #define MAX_BASIC_TYPE_BITS 64
  41. /*
  42. * Compare the tail of two strings.
  43. * Return 0 if whole of either string is same as another's tail part.
  44. */
  45. static int strtailcmp(const char *s1, const char *s2)
  46. {
  47. int i1 = strlen(s1);
  48. int i2 = strlen(s2);
  49. while (--i1 >= 0 && --i2 >= 0) {
  50. if (s1[i1] != s2[i2])
  51. return s1[i1] - s2[i2];
  52. }
  53. return 0;
  54. }
  55. /* Line number list operations */
  56. /* Add a line to line number list */
  57. static int line_list__add_line(struct list_head *head, int line)
  58. {
  59. struct line_node *ln;
  60. struct list_head *p;
  61. /* Reverse search, because new line will be the last one */
  62. list_for_each_entry_reverse(ln, head, list) {
  63. if (ln->line < line) {
  64. p = &ln->list;
  65. goto found;
  66. } else if (ln->line == line) /* Already exist */
  67. return 1;
  68. }
  69. /* List is empty, or the smallest entry */
  70. p = head;
  71. found:
  72. pr_debug("line list: add a line %u\n", line);
  73. ln = zalloc(sizeof(struct line_node));
  74. if (ln == NULL)
  75. return -ENOMEM;
  76. ln->line = line;
  77. INIT_LIST_HEAD(&ln->list);
  78. list_add(&ln->list, p);
  79. return 0;
  80. }
  81. /* Check if the line in line number list */
  82. static int line_list__has_line(struct list_head *head, int line)
  83. {
  84. struct line_node *ln;
  85. /* Reverse search, because new line will be the last one */
  86. list_for_each_entry(ln, head, list)
  87. if (ln->line == line)
  88. return 1;
  89. return 0;
  90. }
  91. /* Init line number list */
  92. static void line_list__init(struct list_head *head)
  93. {
  94. INIT_LIST_HEAD(head);
  95. }
  96. /* Free line number list */
  97. static void line_list__free(struct list_head *head)
  98. {
  99. struct line_node *ln;
  100. while (!list_empty(head)) {
  101. ln = list_first_entry(head, struct line_node, list);
  102. list_del(&ln->list);
  103. free(ln);
  104. }
  105. }
  106. /* Dwarf wrappers */
  107. /* Find the realpath of the target file. */
  108. static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
  109. {
  110. Dwarf_Files *files;
  111. size_t nfiles, i;
  112. const char *src = NULL;
  113. int ret;
  114. if (!fname)
  115. return NULL;
  116. ret = dwarf_getsrcfiles(cu_die, &files, &nfiles);
  117. if (ret != 0)
  118. return NULL;
  119. for (i = 0; i < nfiles; i++) {
  120. src = dwarf_filesrc(files, i, NULL, NULL);
  121. if (strtailcmp(src, fname) == 0)
  122. break;
  123. }
  124. if (i == nfiles)
  125. return NULL;
  126. return src;
  127. }
  128. /* Compare diename and tname */
  129. static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
  130. {
  131. const char *name;
  132. name = dwarf_diename(dw_die);
  133. return name ? strcmp(tname, name) : -1;
  134. }
  135. /* Get type die, but skip qualifiers and typedef */
  136. static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
  137. {
  138. Dwarf_Attribute attr;
  139. int tag;
  140. do {
  141. if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL ||
  142. dwarf_formref_die(&attr, die_mem) == NULL)
  143. return NULL;
  144. tag = dwarf_tag(die_mem);
  145. vr_die = die_mem;
  146. } while (tag == DW_TAG_const_type ||
  147. tag == DW_TAG_restrict_type ||
  148. tag == DW_TAG_volatile_type ||
  149. tag == DW_TAG_shared_type ||
  150. tag == DW_TAG_typedef);
  151. return die_mem;
  152. }
  153. static bool die_is_signed_type(Dwarf_Die *tp_die)
  154. {
  155. Dwarf_Attribute attr;
  156. Dwarf_Word ret;
  157. if (dwarf_attr(tp_die, DW_AT_encoding, &attr) == NULL ||
  158. dwarf_formudata(&attr, &ret) != 0)
  159. return false;
  160. return (ret == DW_ATE_signed_char || ret == DW_ATE_signed ||
  161. ret == DW_ATE_signed_fixed);
  162. }
  163. static int die_get_byte_size(Dwarf_Die *tp_die)
  164. {
  165. Dwarf_Attribute attr;
  166. Dwarf_Word ret;
  167. if (dwarf_attr(tp_die, DW_AT_byte_size, &attr) == NULL ||
  168. dwarf_formudata(&attr, &ret) != 0)
  169. return 0;
  170. return (int)ret;
  171. }
  172. /* Get data_member_location offset */
  173. static int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)
  174. {
  175. Dwarf_Attribute attr;
  176. Dwarf_Op *expr;
  177. size_t nexpr;
  178. int ret;
  179. if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL)
  180. return -ENOENT;
  181. if (dwarf_formudata(&attr, offs) != 0) {
  182. /* DW_AT_data_member_location should be DW_OP_plus_uconst */
  183. ret = dwarf_getlocation(&attr, &expr, &nexpr);
  184. if (ret < 0 || nexpr == 0)
  185. return -ENOENT;
  186. if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) {
  187. pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n",
  188. expr[0].atom, nexpr);
  189. return -ENOTSUP;
  190. }
  191. *offs = (Dwarf_Word)expr[0].number;
  192. }
  193. return 0;
  194. }
  195. /* Return values for die_find callbacks */
  196. enum {
  197. DIE_FIND_CB_FOUND = 0, /* End of Search */
  198. DIE_FIND_CB_CHILD = 1, /* Search only children */
  199. DIE_FIND_CB_SIBLING = 2, /* Search only siblings */
  200. DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */
  201. };
  202. /* Search a child die */
  203. static Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
  204. int (*callback)(Dwarf_Die *, void *),
  205. void *data, Dwarf_Die *die_mem)
  206. {
  207. Dwarf_Die child_die;
  208. int ret;
  209. ret = dwarf_child(rt_die, die_mem);
  210. if (ret != 0)
  211. return NULL;
  212. do {
  213. ret = callback(die_mem, data);
  214. if (ret == DIE_FIND_CB_FOUND)
  215. return die_mem;
  216. if ((ret & DIE_FIND_CB_CHILD) &&
  217. die_find_child(die_mem, callback, data, &child_die)) {
  218. memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
  219. return die_mem;
  220. }
  221. } while ((ret & DIE_FIND_CB_SIBLING) &&
  222. dwarf_siblingof(die_mem, die_mem) == 0);
  223. return NULL;
  224. }
  225. struct __addr_die_search_param {
  226. Dwarf_Addr addr;
  227. Dwarf_Die *die_mem;
  228. };
  229. static int __die_search_func_cb(Dwarf_Die *fn_die, void *data)
  230. {
  231. struct __addr_die_search_param *ad = data;
  232. if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
  233. dwarf_haspc(fn_die, ad->addr)) {
  234. memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die));
  235. return DWARF_CB_ABORT;
  236. }
  237. return DWARF_CB_OK;
  238. }
  239. /* Search a real subprogram including this line, */
  240. static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
  241. Dwarf_Die *die_mem)
  242. {
  243. struct __addr_die_search_param ad;
  244. ad.addr = addr;
  245. ad.die_mem = die_mem;
  246. /* dwarf_getscopes can't find subprogram. */
  247. if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0))
  248. return NULL;
  249. else
  250. return die_mem;
  251. }
  252. /* die_find callback for inline function search */
  253. static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
  254. {
  255. Dwarf_Addr *addr = data;
  256. if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
  257. dwarf_haspc(die_mem, *addr))
  258. return DIE_FIND_CB_FOUND;
  259. return DIE_FIND_CB_CONTINUE;
  260. }
  261. /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
  262. static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
  263. Dwarf_Die *die_mem)
  264. {
  265. return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
  266. }
  267. static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
  268. {
  269. const char *name = data;
  270. int tag;
  271. tag = dwarf_tag(die_mem);
  272. if ((tag == DW_TAG_formal_parameter ||
  273. tag == DW_TAG_variable) &&
  274. (die_compare_name(die_mem, name) == 0))
  275. return DIE_FIND_CB_FOUND;
  276. return DIE_FIND_CB_CONTINUE;
  277. }
  278. /* Find a variable called 'name' */
  279. static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name,
  280. Dwarf_Die *die_mem)
  281. {
  282. return die_find_child(sp_die, __die_find_variable_cb, (void *)name,
  283. die_mem);
  284. }
  285. static int __die_find_member_cb(Dwarf_Die *die_mem, void *data)
  286. {
  287. const char *name = data;
  288. if ((dwarf_tag(die_mem) == DW_TAG_member) &&
  289. (die_compare_name(die_mem, name) == 0))
  290. return DIE_FIND_CB_FOUND;
  291. return DIE_FIND_CB_SIBLING;
  292. }
  293. /* Find a member called 'name' */
  294. static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
  295. Dwarf_Die *die_mem)
  296. {
  297. return die_find_child(st_die, __die_find_member_cb, (void *)name,
  298. die_mem);
  299. }
  300. /*
  301. * Probe finder related functions
  302. */
  303. /* Show a location */
  304. static int convert_location(Dwarf_Op *op, struct probe_finder *pf)
  305. {
  306. unsigned int regn;
  307. Dwarf_Word offs = 0;
  308. bool ref = false;
  309. const char *regs;
  310. struct kprobe_trace_arg *tvar = pf->tvar;
  311. /* If this is based on frame buffer, set the offset */
  312. if (op->atom == DW_OP_fbreg) {
  313. if (pf->fb_ops == NULL) {
  314. pr_warning("The attribute of frame base is not "
  315. "supported.\n");
  316. return -ENOTSUP;
  317. }
  318. ref = true;
  319. offs = op->number;
  320. op = &pf->fb_ops[0];
  321. }
  322. if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) {
  323. regn = op->atom - DW_OP_breg0;
  324. offs += op->number;
  325. ref = true;
  326. } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) {
  327. regn = op->atom - DW_OP_reg0;
  328. } else if (op->atom == DW_OP_bregx) {
  329. regn = op->number;
  330. offs += op->number2;
  331. ref = true;
  332. } else if (op->atom == DW_OP_regx) {
  333. regn = op->number;
  334. } else {
  335. pr_warning("DW_OP %x is not supported.\n", op->atom);
  336. return -ENOTSUP;
  337. }
  338. regs = get_arch_regstr(regn);
  339. if (!regs) {
  340. pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn);
  341. return -ERANGE;
  342. }
  343. tvar->value = strdup(regs);
  344. if (tvar->value == NULL)
  345. return -ENOMEM;
  346. if (ref) {
  347. tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
  348. if (tvar->ref == NULL)
  349. return -ENOMEM;
  350. tvar->ref->offset = (long)offs;
  351. }
  352. return 0;
  353. }
  354. static int convert_variable_type(Dwarf_Die *vr_die,
  355. struct kprobe_trace_arg *targ)
  356. {
  357. Dwarf_Die type;
  358. char buf[16];
  359. int ret;
  360. if (die_get_real_type(vr_die, &type) == NULL) {
  361. pr_warning("Failed to get a type information of %s.\n",
  362. dwarf_diename(vr_die));
  363. return -ENOENT;
  364. }
  365. ret = die_get_byte_size(&type) * 8;
  366. if (ret) {
  367. /* Check the bitwidth */
  368. if (ret > MAX_BASIC_TYPE_BITS) {
  369. pr_info("%s exceeds max-bitwidth."
  370. " Cut down to %d bits.\n",
  371. dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
  372. ret = MAX_BASIC_TYPE_BITS;
  373. }
  374. ret = snprintf(buf, 16, "%c%d",
  375. die_is_signed_type(&type) ? 's' : 'u', ret);
  376. if (ret < 0 || ret >= 16) {
  377. if (ret >= 16)
  378. ret = -E2BIG;
  379. pr_warning("Failed to convert variable type: %s\n",
  380. strerror(-ret));
  381. return ret;
  382. }
  383. targ->type = strdup(buf);
  384. if (targ->type == NULL)
  385. return -ENOMEM;
  386. }
  387. return 0;
  388. }
  389. static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
  390. struct perf_probe_arg_field *field,
  391. struct kprobe_trace_arg_ref **ref_ptr,
  392. Dwarf_Die *die_mem)
  393. {
  394. struct kprobe_trace_arg_ref *ref = *ref_ptr;
  395. Dwarf_Die type;
  396. Dwarf_Word offs;
  397. int ret;
  398. pr_debug("converting %s in %s\n", field->name, varname);
  399. if (die_get_real_type(vr_die, &type) == NULL) {
  400. pr_warning("Failed to get the type of %s.\n", varname);
  401. return -ENOENT;
  402. }
  403. /* Check the pointer and dereference */
  404. if (dwarf_tag(&type) == DW_TAG_pointer_type) {
  405. if (!field->ref) {
  406. pr_err("Semantic error: %s must be referred by '->'\n",
  407. field->name);
  408. return -EINVAL;
  409. }
  410. /* Get the type pointed by this pointer */
  411. if (die_get_real_type(&type, &type) == NULL) {
  412. pr_warning("Failed to get the type of %s.\n", varname);
  413. return -ENOENT;
  414. }
  415. /* Verify it is a data structure */
  416. if (dwarf_tag(&type) != DW_TAG_structure_type) {
  417. pr_warning("%s is not a data structure.\n", varname);
  418. return -EINVAL;
  419. }
  420. ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
  421. if (ref == NULL)
  422. return -ENOMEM;
  423. if (*ref_ptr)
  424. (*ref_ptr)->next = ref;
  425. else
  426. *ref_ptr = ref;
  427. } else {
  428. /* Verify it is a data structure */
  429. if (dwarf_tag(&type) != DW_TAG_structure_type) {
  430. pr_warning("%s is not a data structure.\n", varname);
  431. return -EINVAL;
  432. }
  433. if (field->ref) {
  434. pr_err("Semantic error: %s must be referred by '.'\n",
  435. field->name);
  436. return -EINVAL;
  437. }
  438. if (!ref) {
  439. pr_warning("Structure on a register is not "
  440. "supported yet.\n");
  441. return -ENOTSUP;
  442. }
  443. }
  444. if (die_find_member(&type, field->name, die_mem) == NULL) {
  445. pr_warning("%s(tyep:%s) has no member %s.\n", varname,
  446. dwarf_diename(&type), field->name);
  447. return -EINVAL;
  448. }
  449. /* Get the offset of the field */
  450. ret = die_get_data_member_location(die_mem, &offs);
  451. if (ret < 0) {
  452. pr_warning("Failed to get the offset of %s.\n", field->name);
  453. return ret;
  454. }
  455. ref->offset += (long)offs;
  456. /* Converting next field */
  457. if (field->next)
  458. return convert_variable_fields(die_mem, field->name,
  459. field->next, &ref, die_mem);
  460. else
  461. return 0;
  462. }
  463. /* Show a variables in kprobe event format */
  464. static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
  465. {
  466. Dwarf_Attribute attr;
  467. Dwarf_Die die_mem;
  468. Dwarf_Op *expr;
  469. size_t nexpr;
  470. int ret;
  471. if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
  472. goto error;
  473. /* TODO: handle more than 1 exprs */
  474. ret = dwarf_getlocation_addr(&attr, pf->addr, &expr, &nexpr, 1);
  475. if (ret <= 0 || nexpr == 0)
  476. goto error;
  477. ret = convert_location(expr, pf);
  478. if (ret == 0 && pf->pvar->field) {
  479. ret = convert_variable_fields(vr_die, pf->pvar->var,
  480. pf->pvar->field, &pf->tvar->ref,
  481. &die_mem);
  482. vr_die = &die_mem;
  483. }
  484. if (ret == 0) {
  485. if (pf->pvar->type) {
  486. pf->tvar->type = strdup(pf->pvar->type);
  487. if (pf->tvar->type == NULL)
  488. ret = -ENOMEM;
  489. } else
  490. ret = convert_variable_type(vr_die, pf->tvar);
  491. }
  492. /* *expr will be cached in libdw. Don't free it. */
  493. return ret;
  494. error:
  495. /* TODO: Support const_value */
  496. pr_err("Failed to find the location of %s at this address.\n"
  497. " Perhaps, it has been optimized out.\n", pf->pvar->var);
  498. return -ENOENT;
  499. }
  500. /* Find a variable in a subprogram die */
  501. static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
  502. {
  503. Dwarf_Die vr_die;
  504. char buf[32], *ptr;
  505. int ret;
  506. /* TODO: Support arrays */
  507. if (pf->pvar->name)
  508. pf->tvar->name = strdup(pf->pvar->name);
  509. else {
  510. ret = synthesize_perf_probe_arg(pf->pvar, buf, 32);
  511. if (ret < 0)
  512. return ret;
  513. ptr = strchr(buf, ':'); /* Change type separator to _ */
  514. if (ptr)
  515. *ptr = '_';
  516. pf->tvar->name = strdup(buf);
  517. }
  518. if (pf->tvar->name == NULL)
  519. return -ENOMEM;
  520. if (!is_c_varname(pf->pvar->var)) {
  521. /* Copy raw parameters */
  522. pf->tvar->value = strdup(pf->pvar->var);
  523. if (pf->tvar->value == NULL)
  524. return -ENOMEM;
  525. else
  526. return 0;
  527. }
  528. pr_debug("Searching '%s' variable in context.\n",
  529. pf->pvar->var);
  530. /* Search child die for local variables and parameters. */
  531. if (!die_find_variable(sp_die, pf->pvar->var, &vr_die)) {
  532. pr_warning("Failed to find '%s' in this function.\n",
  533. pf->pvar->var);
  534. return -ENOENT;
  535. }
  536. return convert_variable(&vr_die, pf);
  537. }
  538. /* Show a probe point to output buffer */
  539. static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
  540. {
  541. struct kprobe_trace_event *tev;
  542. Dwarf_Addr eaddr;
  543. Dwarf_Die die_mem;
  544. const char *name;
  545. int ret, i;
  546. Dwarf_Attribute fb_attr;
  547. size_t nops;
  548. if (pf->ntevs == pf->max_tevs) {
  549. pr_warning("Too many( > %d) probe point found.\n",
  550. pf->max_tevs);
  551. return -ERANGE;
  552. }
  553. tev = &pf->tevs[pf->ntevs++];
  554. /* If no real subprogram, find a real one */
  555. if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) {
  556. sp_die = die_find_real_subprogram(&pf->cu_die,
  557. pf->addr, &die_mem);
  558. if (!sp_die) {
  559. pr_warning("Failed to find probe point in any "
  560. "functions.\n");
  561. return -ENOENT;
  562. }
  563. }
  564. /* Copy the name of probe point */
  565. name = dwarf_diename(sp_die);
  566. if (name) {
  567. if (dwarf_entrypc(sp_die, &eaddr) != 0) {
  568. pr_warning("Failed to get entry pc of %s\n",
  569. dwarf_diename(sp_die));
  570. return -ENOENT;
  571. }
  572. tev->point.symbol = strdup(name);
  573. if (tev->point.symbol == NULL)
  574. return -ENOMEM;
  575. tev->point.offset = (unsigned long)(pf->addr - eaddr);
  576. } else
  577. /* This function has no name. */
  578. tev->point.offset = (unsigned long)pf->addr;
  579. pr_debug("Probe point found: %s+%lu\n", tev->point.symbol,
  580. tev->point.offset);
  581. /* Get the frame base attribute/ops */
  582. dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
  583. ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
  584. if (ret <= 0 || nops == 0) {
  585. pf->fb_ops = NULL;
  586. #if _ELFUTILS_PREREQ(0, 142)
  587. } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
  588. pf->cfi != NULL) {
  589. Dwarf_Frame *frame;
  590. if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 ||
  591. dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) {
  592. pr_warning("Failed to get CFA on 0x%jx\n",
  593. (uintmax_t)pf->addr);
  594. return -ENOENT;
  595. }
  596. #endif
  597. }
  598. /* Find each argument */
  599. tev->nargs = pf->pev->nargs;
  600. tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
  601. if (tev->args == NULL)
  602. return -ENOMEM;
  603. for (i = 0; i < pf->pev->nargs; i++) {
  604. pf->pvar = &pf->pev->args[i];
  605. pf->tvar = &tev->args[i];
  606. ret = find_variable(sp_die, pf);
  607. if (ret != 0)
  608. return ret;
  609. }
  610. /* *pf->fb_ops will be cached in libdw. Don't free it. */
  611. pf->fb_ops = NULL;
  612. return 0;
  613. }
  614. /* Find probe point from its line number */
  615. static int find_probe_point_by_line(struct probe_finder *pf)
  616. {
  617. Dwarf_Lines *lines;
  618. Dwarf_Line *line;
  619. size_t nlines, i;
  620. Dwarf_Addr addr;
  621. int lineno;
  622. int ret = 0;
  623. if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) {
  624. pr_warning("No source lines found in this CU.\n");
  625. return -ENOENT;
  626. }
  627. for (i = 0; i < nlines && ret == 0; i++) {
  628. line = dwarf_onesrcline(lines, i);
  629. if (dwarf_lineno(line, &lineno) != 0 ||
  630. lineno != pf->lno)
  631. continue;
  632. /* TODO: Get fileno from line, but how? */
  633. if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
  634. continue;
  635. if (dwarf_lineaddr(line, &addr) != 0) {
  636. pr_warning("Failed to get the address of the line.\n");
  637. return -ENOENT;
  638. }
  639. pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n",
  640. (int)i, lineno, (uintmax_t)addr);
  641. pf->addr = addr;
  642. ret = convert_probe_point(NULL, pf);
  643. /* Continuing, because target line might be inlined. */
  644. }
  645. return ret;
  646. }
  647. /* Find lines which match lazy pattern */
  648. static int find_lazy_match_lines(struct list_head *head,
  649. const char *fname, const char *pat)
  650. {
  651. char *fbuf, *p1, *p2;
  652. int fd, ret, line, nlines = 0;
  653. struct stat st;
  654. fd = open(fname, O_RDONLY);
  655. if (fd < 0) {
  656. pr_warning("Failed to open %s: %s\n", fname, strerror(-fd));
  657. return fd;
  658. }
  659. ret = fstat(fd, &st);
  660. if (ret < 0) {
  661. pr_warning("Failed to get the size of %s: %s\n",
  662. fname, strerror(errno));
  663. return ret;
  664. }
  665. fbuf = xmalloc(st.st_size + 2);
  666. ret = read(fd, fbuf, st.st_size);
  667. if (ret < 0) {
  668. pr_warning("Failed to read %s: %s\n", fname, strerror(errno));
  669. return ret;
  670. }
  671. close(fd);
  672. fbuf[st.st_size] = '\n'; /* Dummy line */
  673. fbuf[st.st_size + 1] = '\0';
  674. p1 = fbuf;
  675. line = 1;
  676. while ((p2 = strchr(p1, '\n')) != NULL) {
  677. *p2 = '\0';
  678. if (strlazymatch(p1, pat)) {
  679. line_list__add_line(head, line);
  680. nlines++;
  681. }
  682. line++;
  683. p1 = p2 + 1;
  684. }
  685. free(fbuf);
  686. return nlines;
  687. }
  688. /* Find probe points from lazy pattern */
  689. static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
  690. {
  691. Dwarf_Lines *lines;
  692. Dwarf_Line *line;
  693. size_t nlines, i;
  694. Dwarf_Addr addr;
  695. Dwarf_Die die_mem;
  696. int lineno;
  697. int ret = 0;
  698. if (list_empty(&pf->lcache)) {
  699. /* Matching lazy line pattern */
  700. ret = find_lazy_match_lines(&pf->lcache, pf->fname,
  701. pf->pev->point.lazy_line);
  702. if (ret == 0) {
  703. pr_debug("No matched lines found in %s.\n", pf->fname);
  704. return 0;
  705. } else if (ret < 0)
  706. return ret;
  707. }
  708. if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) {
  709. pr_warning("No source lines found in this CU.\n");
  710. return -ENOENT;
  711. }
  712. for (i = 0; i < nlines && ret >= 0; i++) {
  713. line = dwarf_onesrcline(lines, i);
  714. if (dwarf_lineno(line, &lineno) != 0 ||
  715. !line_list__has_line(&pf->lcache, lineno))
  716. continue;
  717. /* TODO: Get fileno from line, but how? */
  718. if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
  719. continue;
  720. if (dwarf_lineaddr(line, &addr) != 0) {
  721. pr_debug("Failed to get the address of line %d.\n",
  722. lineno);
  723. continue;
  724. }
  725. if (sp_die) {
  726. /* Address filtering 1: does sp_die include addr? */
  727. if (!dwarf_haspc(sp_die, addr))
  728. continue;
  729. /* Address filtering 2: No child include addr? */
  730. if (die_find_inlinefunc(sp_die, addr, &die_mem))
  731. continue;
  732. }
  733. pr_debug("Probe line found: line[%d]:%d addr:0x%llx\n",
  734. (int)i, lineno, (unsigned long long)addr);
  735. pf->addr = addr;
  736. ret = convert_probe_point(sp_die, pf);
  737. /* Continuing, because target line might be inlined. */
  738. }
  739. /* TODO: deallocate lines, but how? */
  740. return ret;
  741. }
  742. /* Callback parameter with return value */
  743. struct dwarf_callback_param {
  744. void *data;
  745. int retval;
  746. };
  747. static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
  748. {
  749. struct dwarf_callback_param *param = data;
  750. struct probe_finder *pf = param->data;
  751. struct perf_probe_point *pp = &pf->pev->point;
  752. Dwarf_Addr addr;
  753. if (pp->lazy_line)
  754. param->retval = find_probe_point_lazy(in_die, pf);
  755. else {
  756. /* Get probe address */
  757. if (dwarf_entrypc(in_die, &addr) != 0) {
  758. pr_warning("Failed to get entry pc of %s.\n",
  759. dwarf_diename(in_die));
  760. param->retval = -ENOENT;
  761. return DWARF_CB_ABORT;
  762. }
  763. pf->addr = addr;
  764. pf->addr += pp->offset;
  765. pr_debug("found inline addr: 0x%jx\n",
  766. (uintmax_t)pf->addr);
  767. param->retval = convert_probe_point(in_die, pf);
  768. if (param->retval < 0)
  769. return DWARF_CB_ABORT;
  770. }
  771. return DWARF_CB_OK;
  772. }
  773. /* Search function from function name */
  774. static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
  775. {
  776. struct dwarf_callback_param *param = data;
  777. struct probe_finder *pf = param->data;
  778. struct perf_probe_point *pp = &pf->pev->point;
  779. /* Check tag and diename */
  780. if (dwarf_tag(sp_die) != DW_TAG_subprogram ||
  781. die_compare_name(sp_die, pp->function) != 0)
  782. return DWARF_CB_OK;
  783. pf->fname = dwarf_decl_file(sp_die);
  784. if (pp->line) { /* Function relative line */
  785. dwarf_decl_line(sp_die, &pf->lno);
  786. pf->lno += pp->line;
  787. param->retval = find_probe_point_by_line(pf);
  788. } else if (!dwarf_func_inline(sp_die)) {
  789. /* Real function */
  790. if (pp->lazy_line)
  791. param->retval = find_probe_point_lazy(sp_die, pf);
  792. else {
  793. if (dwarf_entrypc(sp_die, &pf->addr) != 0) {
  794. pr_warning("Failed to get entry pc of %s.\n",
  795. dwarf_diename(sp_die));
  796. param->retval = -ENOENT;
  797. return DWARF_CB_ABORT;
  798. }
  799. pf->addr += pp->offset;
  800. /* TODO: Check the address in this function */
  801. param->retval = convert_probe_point(sp_die, pf);
  802. }
  803. } else {
  804. struct dwarf_callback_param _param = {.data = (void *)pf,
  805. .retval = 0};
  806. /* Inlined function: search instances */
  807. dwarf_func_inline_instances(sp_die, probe_point_inline_cb,
  808. &_param);
  809. param->retval = _param.retval;
  810. }
  811. return DWARF_CB_ABORT; /* Exit; no same symbol in this CU. */
  812. }
  813. static int find_probe_point_by_func(struct probe_finder *pf)
  814. {
  815. struct dwarf_callback_param _param = {.data = (void *)pf,
  816. .retval = 0};
  817. dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0);
  818. return _param.retval;
  819. }
  820. /* Find kprobe_trace_events specified by perf_probe_event from debuginfo */
  821. int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
  822. struct kprobe_trace_event **tevs, int max_tevs)
  823. {
  824. struct probe_finder pf = {.pev = pev, .max_tevs = max_tevs};
  825. struct perf_probe_point *pp = &pev->point;
  826. Dwarf_Off off, noff;
  827. size_t cuhl;
  828. Dwarf_Die *diep;
  829. Dwarf *dbg;
  830. int ret = 0;
  831. pf.tevs = zalloc(sizeof(struct kprobe_trace_event) * max_tevs);
  832. if (pf.tevs == NULL)
  833. return -ENOMEM;
  834. *tevs = pf.tevs;
  835. pf.ntevs = 0;
  836. dbg = dwarf_begin(fd, DWARF_C_READ);
  837. if (!dbg) {
  838. pr_warning("No dwarf info found in the vmlinux - "
  839. "please rebuild with CONFIG_DEBUG_INFO=y.\n");
  840. return -EBADF;
  841. }
  842. #if _ELFUTILS_PREREQ(0, 142)
  843. /* Get the call frame information from this dwarf */
  844. pf.cfi = dwarf_getcfi(dbg);
  845. #endif
  846. off = 0;
  847. line_list__init(&pf.lcache);
  848. /* Loop on CUs (Compilation Unit) */
  849. while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) &&
  850. ret >= 0) {
  851. /* Get the DIE(Debugging Information Entry) of this CU */
  852. diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die);
  853. if (!diep)
  854. continue;
  855. /* Check if target file is included. */
  856. if (pp->file)
  857. pf.fname = cu_find_realpath(&pf.cu_die, pp->file);
  858. else
  859. pf.fname = NULL;
  860. if (!pp->file || pf.fname) {
  861. if (pp->function)
  862. ret = find_probe_point_by_func(&pf);
  863. else if (pp->lazy_line)
  864. ret = find_probe_point_lazy(NULL, &pf);
  865. else {
  866. pf.lno = pp->line;
  867. ret = find_probe_point_by_line(&pf);
  868. }
  869. }
  870. off = noff;
  871. }
  872. line_list__free(&pf.lcache);
  873. dwarf_end(dbg);
  874. return (ret < 0) ? ret : pf.ntevs;
  875. }
  876. /* Reverse search */
  877. int find_perf_probe_point(int fd, unsigned long addr,
  878. struct perf_probe_point *ppt)
  879. {
  880. Dwarf_Die cudie, spdie, indie;
  881. Dwarf *dbg;
  882. Dwarf_Line *line;
  883. Dwarf_Addr laddr, eaddr;
  884. const char *tmp;
  885. int lineno, ret = 0;
  886. bool found = false;
  887. dbg = dwarf_begin(fd, DWARF_C_READ);
  888. if (!dbg)
  889. return -EBADF;
  890. /* Find cu die */
  891. if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) {
  892. ret = -EINVAL;
  893. goto end;
  894. }
  895. /* Find a corresponding line */
  896. line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr);
  897. if (line) {
  898. if (dwarf_lineaddr(line, &laddr) == 0 &&
  899. (Dwarf_Addr)addr == laddr &&
  900. dwarf_lineno(line, &lineno) == 0) {
  901. tmp = dwarf_linesrc(line, NULL, NULL);
  902. if (tmp) {
  903. ppt->line = lineno;
  904. ppt->file = strdup(tmp);
  905. if (ppt->file == NULL) {
  906. ret = -ENOMEM;
  907. goto end;
  908. }
  909. found = true;
  910. }
  911. }
  912. }
  913. /* Find a corresponding function */
  914. if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) {
  915. tmp = dwarf_diename(&spdie);
  916. if (!tmp || dwarf_entrypc(&spdie, &eaddr) != 0)
  917. goto end;
  918. if (ppt->line) {
  919. if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr,
  920. &indie)) {
  921. /* addr in an inline function */
  922. tmp = dwarf_diename(&indie);
  923. if (!tmp)
  924. goto end;
  925. ret = dwarf_decl_line(&indie, &lineno);
  926. } else {
  927. if (eaddr == addr) { /* Function entry */
  928. lineno = ppt->line;
  929. ret = 0;
  930. } else
  931. ret = dwarf_decl_line(&spdie, &lineno);
  932. }
  933. if (ret == 0) {
  934. /* Make a relative line number */
  935. ppt->line -= lineno;
  936. goto found;
  937. }
  938. }
  939. /* We don't have a line number, let's use offset */
  940. ppt->offset = addr - (unsigned long)eaddr;
  941. found:
  942. ppt->function = strdup(tmp);
  943. if (ppt->function == NULL) {
  944. ret = -ENOMEM;
  945. goto end;
  946. }
  947. found = true;
  948. }
  949. end:
  950. dwarf_end(dbg);
  951. if (ret >= 0)
  952. ret = found ? 1 : 0;
  953. return ret;
  954. }
  955. /* Add a line and store the src path */
  956. static int line_range_add_line(const char *src, unsigned int lineno,
  957. struct line_range *lr)
  958. {
  959. /* Copy real path */
  960. if (!lr->path) {
  961. lr->path = strdup(src);
  962. if (lr->path == NULL)
  963. return -ENOMEM;
  964. }
  965. return line_list__add_line(&lr->line_list, lineno);
  966. }
  967. /* Search function declaration lines */
  968. static int line_range_funcdecl_cb(Dwarf_Die *sp_die, void *data)
  969. {
  970. struct dwarf_callback_param *param = data;
  971. struct line_finder *lf = param->data;
  972. const char *src;
  973. int lineno;
  974. src = dwarf_decl_file(sp_die);
  975. if (src && strtailcmp(src, lf->fname) != 0)
  976. return DWARF_CB_OK;
  977. if (dwarf_decl_line(sp_die, &lineno) != 0 ||
  978. (lf->lno_s > lineno || lf->lno_e < lineno))
  979. return DWARF_CB_OK;
  980. param->retval = line_range_add_line(src, lineno, lf->lr);
  981. if (param->retval < 0)
  982. return DWARF_CB_ABORT;
  983. return DWARF_CB_OK;
  984. }
  985. static int find_line_range_func_decl_lines(struct line_finder *lf)
  986. {
  987. struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0};
  988. dwarf_getfuncs(&lf->cu_die, line_range_funcdecl_cb, &param, 0);
  989. return param.retval;
  990. }
  991. /* Find line range from its line number */
  992. static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
  993. {
  994. Dwarf_Lines *lines;
  995. Dwarf_Line *line;
  996. size_t nlines, i;
  997. Dwarf_Addr addr;
  998. int lineno, ret = 0;
  999. const char *src;
  1000. Dwarf_Die die_mem;
  1001. line_list__init(&lf->lr->line_list);
  1002. if (dwarf_getsrclines(&lf->cu_die, &lines, &nlines) != 0) {
  1003. pr_warning("No source lines found in this CU.\n");
  1004. return -ENOENT;
  1005. }
  1006. /* Search probable lines on lines list */
  1007. for (i = 0; i < nlines; i++) {
  1008. line = dwarf_onesrcline(lines, i);
  1009. if (dwarf_lineno(line, &lineno) != 0 ||
  1010. (lf->lno_s > lineno || lf->lno_e < lineno))
  1011. continue;
  1012. if (sp_die) {
  1013. /* Address filtering 1: does sp_die include addr? */
  1014. if (dwarf_lineaddr(line, &addr) != 0 ||
  1015. !dwarf_haspc(sp_die, addr))
  1016. continue;
  1017. /* Address filtering 2: No child include addr? */
  1018. if (die_find_inlinefunc(sp_die, addr, &die_mem))
  1019. continue;
  1020. }
  1021. /* TODO: Get fileno from line, but how? */
  1022. src = dwarf_linesrc(line, NULL, NULL);
  1023. if (strtailcmp(src, lf->fname) != 0)
  1024. continue;
  1025. ret = line_range_add_line(src, lineno, lf->lr);
  1026. if (ret < 0)
  1027. return ret;
  1028. }
  1029. /*
  1030. * Dwarf lines doesn't include function declarations. We have to
  1031. * check functions list or given function.
  1032. */
  1033. if (sp_die) {
  1034. src = dwarf_decl_file(sp_die);
  1035. if (src && dwarf_decl_line(sp_die, &lineno) == 0 &&
  1036. (lf->lno_s <= lineno && lf->lno_e >= lineno))
  1037. ret = line_range_add_line(src, lineno, lf->lr);
  1038. } else
  1039. ret = find_line_range_func_decl_lines(lf);
  1040. /* Update status */
  1041. if (ret >= 0)
  1042. if (!list_empty(&lf->lr->line_list))
  1043. ret = lf->found = 1;
  1044. else
  1045. ret = 0; /* Lines are not found */
  1046. else {
  1047. free(lf->lr->path);
  1048. lf->lr->path = NULL;
  1049. }
  1050. return ret;
  1051. }
  1052. static int line_range_inline_cb(Dwarf_Die *in_die, void *data)
  1053. {
  1054. struct dwarf_callback_param *param = data;
  1055. param->retval = find_line_range_by_line(in_die, param->data);
  1056. return DWARF_CB_ABORT; /* No need to find other instances */
  1057. }
  1058. /* Search function from function name */
  1059. static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
  1060. {
  1061. struct dwarf_callback_param *param = data;
  1062. struct line_finder *lf = param->data;
  1063. struct line_range *lr = lf->lr;
  1064. if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
  1065. die_compare_name(sp_die, lr->function) == 0) {
  1066. lf->fname = dwarf_decl_file(sp_die);
  1067. dwarf_decl_line(sp_die, &lr->offset);
  1068. pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
  1069. lf->lno_s = lr->offset + lr->start;
  1070. if (lf->lno_s < 0) /* Overflow */
  1071. lf->lno_s = INT_MAX;
  1072. lf->lno_e = lr->offset + lr->end;
  1073. if (lf->lno_e < 0) /* Overflow */
  1074. lf->lno_e = INT_MAX;
  1075. pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e);
  1076. lr->start = lf->lno_s;
  1077. lr->end = lf->lno_e;
  1078. if (dwarf_func_inline(sp_die)) {
  1079. struct dwarf_callback_param _param;
  1080. _param.data = (void *)lf;
  1081. _param.retval = 0;
  1082. dwarf_func_inline_instances(sp_die,
  1083. line_range_inline_cb,
  1084. &_param);
  1085. param->retval = _param.retval;
  1086. } else
  1087. param->retval = find_line_range_by_line(sp_die, lf);
  1088. return DWARF_CB_ABORT;
  1089. }
  1090. return DWARF_CB_OK;
  1091. }
  1092. static int find_line_range_by_func(struct line_finder *lf)
  1093. {
  1094. struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0};
  1095. dwarf_getfuncs(&lf->cu_die, line_range_search_cb, &param, 0);
  1096. return param.retval;
  1097. }
  1098. int find_line_range(int fd, struct line_range *lr)
  1099. {
  1100. struct line_finder lf = {.lr = lr, .found = 0};
  1101. int ret = 0;
  1102. Dwarf_Off off = 0, noff;
  1103. size_t cuhl;
  1104. Dwarf_Die *diep;
  1105. Dwarf *dbg;
  1106. dbg = dwarf_begin(fd, DWARF_C_READ);
  1107. if (!dbg) {
  1108. pr_warning("No dwarf info found in the vmlinux - "
  1109. "please rebuild with CONFIG_DEBUG_INFO=y.\n");
  1110. return -EBADF;
  1111. }
  1112. /* Loop on CUs (Compilation Unit) */
  1113. while (!lf.found && ret >= 0) {
  1114. if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0)
  1115. break;
  1116. /* Get the DIE(Debugging Information Entry) of this CU */
  1117. diep = dwarf_offdie(dbg, off + cuhl, &lf.cu_die);
  1118. if (!diep)
  1119. continue;
  1120. /* Check if target file is included. */
  1121. if (lr->file)
  1122. lf.fname = cu_find_realpath(&lf.cu_die, lr->file);
  1123. else
  1124. lf.fname = 0;
  1125. if (!lr->file || lf.fname) {
  1126. if (lr->function)
  1127. ret = find_line_range_by_func(&lf);
  1128. else {
  1129. lf.lno_s = lr->start;
  1130. lf.lno_e = lr->end;
  1131. ret = find_line_range_by_line(NULL, &lf);
  1132. }
  1133. }
  1134. off = noff;
  1135. }
  1136. pr_debug("path: %lx\n", (unsigned long)lr->path);
  1137. dwarf_end(dbg);
  1138. return (ret < 0) ? ret : lf.found;
  1139. }