blob: e02b60770485dbfcd6800f874b7ce84b79636879 [file] [log] [blame]
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -04001/*
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
22#include <sys/utsname.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <errno.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <getopt.h>
30#include <stdlib.h>
31#include <string.h>
32#include <stdarg.h>
33#include <ctype.h>
Masami Hiramatsu074fc0e2009-10-16 20:08:01 -040034
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -050035#include "string.h"
Masami Hiramatsu89c69c02009-10-16 20:08:10 -040036#include "event.h"
37#include "debug.h"
Masami Hiramatsu074fc0e2009-10-16 20:08:01 -040038#include "util.h"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040039#include "probe-finder.h"
40
41
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040042/*
43 * Generic dwarf analysis helpers
44 */
45
46#define X86_32_MAX_REGS 8
47const char *x86_32_regs_table[X86_32_MAX_REGS] = {
48 "%ax",
49 "%cx",
50 "%dx",
51 "%bx",
52 "$stack", /* Stack address instead of %sp */
53 "%bp",
54 "%si",
55 "%di",
56};
57
58#define X86_64_MAX_REGS 16
59const char *x86_64_regs_table[X86_64_MAX_REGS] = {
60 "%ax",
61 "%dx",
62 "%cx",
63 "%bx",
64 "%si",
65 "%di",
66 "%bp",
67 "%sp",
68 "%r8",
69 "%r9",
70 "%r10",
71 "%r11",
72 "%r12",
73 "%r13",
74 "%r14",
75 "%r15",
76};
77
78/* TODO: switching by dwarf address size */
79#ifdef __x86_64__
80#define ARCH_MAX_REGS X86_64_MAX_REGS
81#define arch_regs_table x86_64_regs_table
82#else
83#define ARCH_MAX_REGS X86_32_MAX_REGS
84#define arch_regs_table x86_32_regs_table
85#endif
86
87/* Return architecture dependent register string (for kprobe-tracer) */
88static const char *get_arch_regstr(unsigned int n)
89{
90 return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
91}
92
93/*
94 * Compare the tail of two strings.
95 * Return 0 if whole of either string is same as another's tail part.
96 */
97static int strtailcmp(const char *s1, const char *s2)
98{
99 int i1 = strlen(s1);
100 int i2 = strlen(s2);
Juha Leppanend56728b2009-12-07 12:00:40 -0500101 while (--i1 >= 0 && --i2 >= 0) {
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400102 if (s1[i1] != s2[i2])
103 return s1[i1] - s2[i2];
104 }
105 return 0;
106}
107
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500108/* Line number list operations */
109
110/* Add a line to line number list */
111static void line_list__add_line(struct list_head *head, unsigned int line)
112{
113 struct line_node *ln;
114 struct list_head *p;
115
116 /* Reverse search, because new line will be the last one */
117 list_for_each_entry_reverse(ln, head, list) {
118 if (ln->line < line) {
119 p = &ln->list;
120 goto found;
121 } else if (ln->line == line) /* Already exist */
122 return ;
123 }
124 /* List is empty, or the smallest entry */
125 p = head;
126found:
127 pr_debug("line list: add a line %u\n", line);
Masami Hiramatsu31facc52010-03-16 18:05:30 -0400128 ln = xzalloc(sizeof(struct line_node));
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500129 ln->line = line;
130 INIT_LIST_HEAD(&ln->list);
131 list_add(&ln->list, p);
132}
133
134/* Check if the line in line number list */
135static int line_list__has_line(struct list_head *head, unsigned int line)
136{
137 struct line_node *ln;
138
139 /* Reverse search, because new line will be the last one */
140 list_for_each_entry(ln, head, list)
141 if (ln->line == line)
142 return 1;
143
144 return 0;
145}
146
147/* Init line number list */
148static void line_list__init(struct list_head *head)
149{
150 INIT_LIST_HEAD(head);
151}
152
153/* Free line number list */
154static void line_list__free(struct list_head *head)
155{
156 struct line_node *ln;
157 while (!list_empty(head)) {
158 ln = list_first_entry(head, struct line_node, list);
159 list_del(&ln->list);
160 free(ln);
161 }
162}
163
164/* Dwarf wrappers */
165
166/* Find the realpath of the target file. */
167static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400168{
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500169 Dwarf_Files *files;
170 size_t nfiles, i;
Arnaldo Carvalho de Meloaccd3cc2010-03-05 12:51:04 -0300171 const char *src = NULL;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400172 int ret;
173
174 if (!fname)
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500175 return NULL;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500176
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500177 ret = dwarf_getsrcfiles(cu_die, &files, &nfiles);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500178 if (ret != 0)
179 return NULL;
180
181 for (i = 0; i < nfiles; i++) {
182 src = dwarf_filesrc(files, i, NULL, NULL);
183 if (strtailcmp(src, fname) == 0)
184 break;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500185 }
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500186 return src;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500187}
188
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400189/* Compare diename and tname */
190static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
191{
192 const char *name;
193 name = dwarf_diename(dw_die);
194 DIE_IF(name == NULL);
195 return strcmp(tname, name);
196}
197
198/* Get entry pc(or low pc, 1st entry of ranges) of the die */
199static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die)
200{
201 Dwarf_Addr epc;
202 int ret;
203
204 ret = dwarf_entrypc(dw_die, &epc);
205 DIE_IF(ret == -1);
206 return epc;
207}
208
209/* Return values for die_find callbacks */
210enum {
211 DIE_FIND_CB_FOUND = 0, /* End of Search */
212 DIE_FIND_CB_CHILD = 1, /* Search only children */
213 DIE_FIND_CB_SIBLING = 2, /* Search only siblings */
214 DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */
215};
216
217/* Search a child die */
218static Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
219 int (*callback)(Dwarf_Die *, void *),
220 void *data, Dwarf_Die *die_mem)
221{
222 Dwarf_Die child_die;
223 int ret;
224
225 ret = dwarf_child(rt_die, die_mem);
226 if (ret != 0)
227 return NULL;
228
229 do {
230 ret = callback(die_mem, data);
231 if (ret == DIE_FIND_CB_FOUND)
232 return die_mem;
233
234 if ((ret & DIE_FIND_CB_CHILD) &&
235 die_find_child(die_mem, callback, data, &child_die)) {
236 memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
237 return die_mem;
238 }
239 } while ((ret & DIE_FIND_CB_SIBLING) &&
240 dwarf_siblingof(die_mem, die_mem) == 0);
241
242 return NULL;
243}
244
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500245struct __addr_die_search_param {
246 Dwarf_Addr addr;
247 Dwarf_Die *die_mem;
248};
249
250static int __die_search_func_cb(Dwarf_Die *fn_die, void *data)
251{
252 struct __addr_die_search_param *ad = data;
253
254 if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
255 dwarf_haspc(fn_die, ad->addr)) {
256 memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die));
257 return DWARF_CB_ABORT;
258 }
259 return DWARF_CB_OK;
260}
261
262/* Search a real subprogram including this line, */
Masami Hiramatsu95a3e4c2010-03-16 18:05:51 -0400263static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
264 Dwarf_Die *die_mem)
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500265{
266 struct __addr_die_search_param ad;
267 ad.addr = addr;
268 ad.die_mem = die_mem;
269 /* dwarf_getscopes can't find subprogram. */
270 if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0))
271 return NULL;
272 else
273 return die_mem;
274}
275
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400276/* die_find callback for inline function search */
277static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
278{
279 Dwarf_Addr *addr = data;
280
281 if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
282 dwarf_haspc(die_mem, *addr))
283 return DIE_FIND_CB_FOUND;
284
285 return DIE_FIND_CB_CONTINUE;
286}
287
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500288/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
Masami Hiramatsu95a3e4c2010-03-16 18:05:51 -0400289static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
290 Dwarf_Die *die_mem)
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500291{
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400292 return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500293}
294
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400295static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400296{
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400297 const char *name = data;
298 int tag;
299
300 tag = dwarf_tag(die_mem);
301 if ((tag == DW_TAG_formal_parameter ||
302 tag == DW_TAG_variable) &&
303 (die_compare_name(die_mem, name) == 0))
304 return DIE_FIND_CB_FOUND;
305
306 return DIE_FIND_CB_CONTINUE;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400307}
308
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400309/* Find a variable called 'name' */
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500310static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name,
311 Dwarf_Die *die_mem)
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500312{
Masami Hiramatsu016f2622010-03-16 18:05:58 -0400313 return die_find_child(sp_die, __die_find_variable_cb, (void *)name,
314 die_mem);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400315}
316
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400317/*
318 * Probe finder related functions
319 */
320
321/* Show a location */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400322static void convert_location(Dwarf_Op *op, struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400323{
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500324 unsigned int regn;
325 Dwarf_Word offs = 0;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400326 bool ref = false;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400327 const char *regs;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400328 struct kprobe_trace_arg *tvar = pf->tvar;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400329
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500330 /* TODO: support CFA */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400331 /* If this is based on frame buffer, set the offset */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500332 if (op->atom == DW_OP_fbreg) {
333 if (pf->fb_ops == NULL)
334 die("The attribute of frame base is not supported.\n");
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400335 ref = true;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500336 offs = op->number;
337 op = &pf->fb_ops[0];
338 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400339
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500340 if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) {
341 regn = op->atom - DW_OP_breg0;
342 offs += op->number;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400343 ref = true;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500344 } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) {
345 regn = op->atom - DW_OP_reg0;
346 } else if (op->atom == DW_OP_bregx) {
347 regn = op->number;
348 offs += op->number2;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400349 ref = true;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500350 } else if (op->atom == DW_OP_regx) {
351 regn = op->number;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400352 } else
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500353 die("DW_OP %d is not supported.", op->atom);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400354
355 regs = get_arch_regstr(regn);
356 if (!regs)
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500357 die("%u exceeds max register number.", regn);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400358
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400359 tvar->value = xstrdup(regs);
360 if (ref) {
361 tvar->ref = xzalloc(sizeof(struct kprobe_trace_arg_ref));
362 tvar->ref->offset = (long)offs;
363 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400364}
365
366/* Show a variables in kprobe event format */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400367static void convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400368{
369 Dwarf_Attribute attr;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500370 Dwarf_Op *expr;
371 size_t nexpr;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400372 int ret;
373
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500374 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400375 goto error;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500376 /* TODO: handle more than 1 exprs */
Masami Hiramatsud0cb4262010-03-15 13:02:35 -0400377 ret = dwarf_getlocation_addr(&attr, pf->addr, &expr, &nexpr, 1);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500378 if (ret <= 0 || nexpr == 0)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400379 goto error;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500380
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400381 convert_location(expr, pf);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500382 /* *expr will be cached in libdw. Don't free it. */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400383 return ;
384error:
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500385 /* TODO: Support const_value */
Masami Hiramatsu074fc0e2009-10-16 20:08:01 -0400386 die("Failed to find the location of %s at this address.\n"
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400387 " Perhaps, it has been optimized out.", pf->pvar->name);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400388}
389
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400390/* Find a variable in a subprogram die */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500391static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400392{
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500393 Dwarf_Die vr_die;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400394
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500395 /* TODO: Support struct members and arrays */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400396 if (!is_c_varname(pf->pvar->name)) {
397 /* Copy raw parameters */
398 pf->tvar->value = xstrdup(pf->pvar->name);
399 } else {
400 pf->tvar->name = xstrdup(pf->pvar->name);
401 pr_debug("Searching '%s' variable in context.\n",
402 pf->pvar->name);
403 /* Search child die for local variables and parameters. */
404 if (!die_find_variable(sp_die, pf->pvar->name, &vr_die))
405 die("Failed to find '%s' in this function.",
406 pf->pvar->name);
407 convert_variable(&vr_die, pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400408 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400409}
410
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400411/* Show a probe point to output buffer */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400412static void convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400413{
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400414 struct kprobe_trace_event *tev;
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500415 Dwarf_Addr eaddr;
416 Dwarf_Die die_mem;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500417 const char *name;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400418 int ret, i;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500419 Dwarf_Attribute fb_attr;
420 size_t nops;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400421
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400422 if (pf->ntevs == MAX_PROBES)
423 die("Too many( > %d) probe point found.\n", MAX_PROBES);
424 tev = &pf->tevs[pf->ntevs++];
425
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500426 /* If no real subprogram, find a real one */
427 if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) {
Masami Hiramatsu95a3e4c2010-03-16 18:05:51 -0400428 sp_die = die_find_real_subprogram(&pf->cu_die,
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500429 pf->addr, &die_mem);
430 if (!sp_die)
431 die("Probe point is not found in subprograms.");
432 }
433
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400434 /* Copy the name of probe point */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500435 name = dwarf_diename(sp_die);
436 if (name) {
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500437 dwarf_entrypc(sp_die, &eaddr);
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400438 tev->point.symbol = xstrdup(name);
439 tev->point.offset = (unsigned long)(pf->addr - eaddr);
440 } else
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400441 /* This function has no name. */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400442 tev->point.offset = (unsigned long)pf->addr;
443
444 pr_debug("Probe point found: %s+%lu\n", tev->point.symbol,
445 tev->point.offset);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400446
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500447 /* Get the frame base attribute/ops */
448 dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
Masami Hiramatsud0cb4262010-03-15 13:02:35 -0400449 ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500450 if (ret <= 0 || nops == 0)
451 pf->fb_ops = NULL;
452
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400453 /* Find each argument */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500454 /* TODO: use dwarf_cfi_addrframe */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400455 tev->nargs = pf->pev->nargs;
456 tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
457 for (i = 0; i < pf->pev->nargs; i++) {
458 pf->pvar = &pf->pev->args[i];
459 pf->tvar = &tev->args[i];
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400460 find_variable(sp_die, pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400461 }
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500462
463 /* *pf->fb_ops will be cached in libdw. Don't free it. */
464 pf->fb_ops = NULL;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400465}
466
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400467/* Find probe point from its line number */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500468static void find_probe_point_by_line(struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400469{
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500470 Dwarf_Lines *lines;
471 Dwarf_Line *line;
472 size_t nlines, i;
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500473 Dwarf_Addr addr;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500474 int lineno;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400475 int ret;
476
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500477 ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines);
478 DIE_IF(ret != 0);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400479
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500480 for (i = 0; i < nlines; i++) {
481 line = dwarf_onesrcline(lines, i);
482 dwarf_lineno(line, &lineno);
Masami Hiramatsub0ef0732009-10-27 16:43:19 -0400483 if (lineno != pf->lno)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400484 continue;
485
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500486 /* TODO: Get fileno from line, but how? */
487 if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
488 continue;
Masami Hiramatsub0ef0732009-10-27 16:43:19 -0400489
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500490 ret = dwarf_lineaddr(line, &addr);
491 DIE_IF(ret != 0);
492 pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n",
493 (int)i, lineno, (uintmax_t)addr);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400494 pf->addr = addr;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500495
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400496 convert_probe_point(NULL, pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400497 /* Continuing, because target line might be inlined. */
498 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400499}
500
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500501/* Find lines which match lazy pattern */
502static int find_lazy_match_lines(struct list_head *head,
503 const char *fname, const char *pat)
504{
505 char *fbuf, *p1, *p2;
506 int fd, line, nlines = 0;
507 struct stat st;
508
509 fd = open(fname, O_RDONLY);
510 if (fd < 0)
511 die("failed to open %s", fname);
512 DIE_IF(fstat(fd, &st) < 0);
Masami Hiramatsu31facc52010-03-16 18:05:30 -0400513 fbuf = xmalloc(st.st_size + 2);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500514 DIE_IF(read(fd, fbuf, st.st_size) < 0);
515 close(fd);
516 fbuf[st.st_size] = '\n'; /* Dummy line */
517 fbuf[st.st_size + 1] = '\0';
518 p1 = fbuf;
519 line = 1;
520 while ((p2 = strchr(p1, '\n')) != NULL) {
521 *p2 = '\0';
522 if (strlazymatch(p1, pat)) {
523 line_list__add_line(head, line);
524 nlines++;
525 }
526 line++;
527 p1 = p2 + 1;
528 }
529 free(fbuf);
530 return nlines;
531}
532
533/* Find probe points from lazy pattern */
534static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
535{
536 Dwarf_Lines *lines;
537 Dwarf_Line *line;
538 size_t nlines, i;
539 Dwarf_Addr addr;
540 Dwarf_Die die_mem;
541 int lineno;
542 int ret;
543
544 if (list_empty(&pf->lcache)) {
545 /* Matching lazy line pattern */
546 ret = find_lazy_match_lines(&pf->lcache, pf->fname,
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400547 pf->pev->point.lazy_line);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500548 if (ret <= 0)
549 die("No matched lines found in %s.", pf->fname);
550 }
551
552 ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines);
553 DIE_IF(ret != 0);
554 for (i = 0; i < nlines; i++) {
555 line = dwarf_onesrcline(lines, i);
556
557 dwarf_lineno(line, &lineno);
558 if (!line_list__has_line(&pf->lcache, lineno))
559 continue;
560
561 /* TODO: Get fileno from line, but how? */
562 if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
563 continue;
564
565 ret = dwarf_lineaddr(line, &addr);
566 DIE_IF(ret != 0);
567 if (sp_die) {
568 /* Address filtering 1: does sp_die include addr? */
569 if (!dwarf_haspc(sp_die, addr))
570 continue;
571 /* Address filtering 2: No child include addr? */
Masami Hiramatsu95a3e4c2010-03-16 18:05:51 -0400572 if (die_find_inlinefunc(sp_die, addr, &die_mem))
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500573 continue;
574 }
575
576 pr_debug("Probe line found: line[%d]:%d addr:0x%llx\n",
577 (int)i, lineno, (unsigned long long)addr);
578 pf->addr = addr;
579
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400580 convert_probe_point(sp_die, pf);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500581 /* Continuing, because target line might be inlined. */
582 }
583 /* TODO: deallocate lines, but how? */
584}
585
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500586static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400587{
588 struct probe_finder *pf = (struct probe_finder *)data;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400589 struct perf_probe_point *pp = &pf->pev->point;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400590
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500591 if (pp->lazy_line)
592 find_probe_point_lazy(in_die, pf);
593 else {
594 /* Get probe address */
595 pf->addr = die_get_entrypc(in_die);
596 pf->addr += pp->offset;
597 pr_debug("found inline addr: 0x%jx\n",
598 (uintmax_t)pf->addr);
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500599
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400600 convert_probe_point(in_die, pf);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500601 }
602
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500603 return DWARF_CB_OK;
604}
605
606/* Search function from function name */
607static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
608{
609 struct probe_finder *pf = (struct probe_finder *)data;
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400610 struct perf_probe_point *pp = &pf->pev->point;
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500611
612 /* Check tag and diename */
613 if (dwarf_tag(sp_die) != DW_TAG_subprogram ||
614 die_compare_name(sp_die, pp->function) != 0)
615 return 0;
616
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500617 pf->fname = dwarf_decl_file(sp_die);
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500618 if (pp->line) { /* Function relative line */
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500619 dwarf_decl_line(sp_die, &pf->lno);
620 pf->lno += pp->line;
621 find_probe_point_by_line(pf);
622 } else if (!dwarf_func_inline(sp_die)) {
623 /* Real function */
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500624 if (pp->lazy_line)
625 find_probe_point_lazy(sp_die, pf);
626 else {
627 pf->addr = die_get_entrypc(sp_die);
628 pf->addr += pp->offset;
629 /* TODO: Check the address in this function */
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400630 convert_probe_point(sp_die, pf);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500631 }
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500632 } else
633 /* Inlined function: search instances */
634 dwarf_func_inline_instances(sp_die, probe_point_inline_cb, pf);
635
636 return 1; /* Exit; no same symbol in this CU. */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400637}
638
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500639static void find_probe_point_by_func(struct probe_finder *pf)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400640{
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500641 dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, pf, 0);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400642}
643
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400644/* Find kprobe_trace_events specified by perf_probe_event from debuginfo */
645int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
646 struct kprobe_trace_event **tevs)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400647{
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400648 struct probe_finder pf = {.pev = pev};
649 struct perf_probe_point *pp = &pev->point;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500650 Dwarf_Off off, noff;
651 size_t cuhl;
652 Dwarf_Die *diep;
653 Dwarf *dbg;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400654
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400655 pf.tevs = xzalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES);
656 *tevs = pf.tevs;
657 pf.ntevs = 0;
658
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500659 dbg = dwarf_begin(fd, DWARF_C_READ);
660 if (!dbg)
Masami Hiramatsua225a1d2009-11-03 19:12:30 -0500661 return -ENOENT;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400662
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500663 off = 0;
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500664 line_list__init(&pf.lcache);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500665 /* Loop on CUs (Compilation Unit) */
666 while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400667 /* Get the DIE(Debugging Information Entry) of this CU */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500668 diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die);
669 if (!diep)
670 continue;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400671
672 /* Check if target file is included. */
673 if (pp->file)
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500674 pf.fname = cu_find_realpath(&pf.cu_die, pp->file);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500675 else
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500676 pf.fname = NULL;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400677
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500678 if (!pp->file || pf.fname) {
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400679 if (pp->function)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500680 find_probe_point_by_func(&pf);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500681 else if (pp->lazy_line)
682 find_probe_point_lazy(NULL, &pf);
Masami Hiramatsub0ef0732009-10-27 16:43:19 -0400683 else {
684 pf.lno = pp->line;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500685 find_probe_point_by_line(&pf);
Masami Hiramatsub0ef0732009-10-27 16:43:19 -0400686 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400687 }
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500688 off = noff;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400689 }
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500690 line_list__free(&pf.lcache);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500691 dwarf_end(dbg);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400692
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400693 return pf.ntevs;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400694}
695
Masami Hiramatsufb1587d2010-03-16 18:06:19 -0400696/* Reverse search */
697int find_perf_probe_point(int fd, unsigned long addr,
698 struct perf_probe_point *ppt)
699{
700 Dwarf_Die cudie, spdie, indie;
701 Dwarf *dbg;
702 Dwarf_Line *line;
703 Dwarf_Addr laddr, eaddr;
704 const char *tmp;
705 int lineno, ret = 0;
706
707 dbg = dwarf_begin(fd, DWARF_C_READ);
708 if (!dbg)
709 return -ENOENT;
710
711 /* Find cu die */
712 if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie))
713 return -EINVAL;
714
715 /* Find a corresponding line */
716 line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr);
717 if (line) {
718 dwarf_lineaddr(line, &laddr);
719 if ((Dwarf_Addr)addr == laddr) {
720 dwarf_lineno(line, &lineno);
721 ppt->line = lineno;
722
723 tmp = dwarf_linesrc(line, NULL, NULL);
724 DIE_IF(!tmp);
725 ppt->file = xstrdup(tmp);
726 ret = 1;
727 }
728 }
729
730 /* Find a corresponding function */
731 if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) {
732 tmp = dwarf_diename(&spdie);
733 if (!tmp)
734 goto end;
735
736 dwarf_entrypc(&spdie, &eaddr);
737 if (!lineno) {
738 /* We don't have a line number, let's use offset */
739 ppt->function = xstrdup(tmp);
740 ppt->offset = addr - (unsigned long)eaddr;
741 ret = 1;
742 goto end;
743 }
744 if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr, &indie)) {
745 /* addr in an inline function */
746 tmp = dwarf_diename(&indie);
747 if (!tmp)
748 goto end;
749 dwarf_decl_line(&indie, &lineno);
750 } else {
751 if (eaddr == addr) /* No offset: function entry */
752 lineno = ppt->line;
753 else
754 dwarf_decl_line(&spdie, &lineno);
755 }
756 ppt->function = xstrdup(tmp);
757 ppt->line -= lineno; /* Make a relative line number */
758 }
759
760end:
761 dwarf_end(dbg);
762 return ret;
763}
764
765
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500766/* Find line range from its line number */
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500767static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500768{
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500769 Dwarf_Lines *lines;
770 Dwarf_Line *line;
771 size_t nlines, i;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500772 Dwarf_Addr addr;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500773 int lineno;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500774 int ret;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500775 const char *src;
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500776 Dwarf_Die die_mem;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500777
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500778 line_list__init(&lf->lr->line_list);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500779 ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines);
780 DIE_IF(ret != 0);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500781
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500782 for (i = 0; i < nlines; i++) {
783 line = dwarf_onesrcline(lines, i);
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500784 ret = dwarf_lineno(line, &lineno);
785 DIE_IF(ret != 0);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500786 if (lf->lno_s > lineno || lf->lno_e < lineno)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500787 continue;
788
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500789 if (sp_die) {
790 /* Address filtering 1: does sp_die include addr? */
791 ret = dwarf_lineaddr(line, &addr);
792 DIE_IF(ret != 0);
793 if (!dwarf_haspc(sp_die, addr))
794 continue;
795
796 /* Address filtering 2: No child include addr? */
Masami Hiramatsu95a3e4c2010-03-16 18:05:51 -0400797 if (die_find_inlinefunc(sp_die, addr, &die_mem))
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500798 continue;
799 }
800
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500801 /* TODO: Get fileno from line, but how? */
802 src = dwarf_linesrc(line, NULL, NULL);
803 if (strtailcmp(src, lf->fname) != 0)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500804 continue;
805
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500806 /* Copy real path */
807 if (!lf->lr->path)
Masami Hiramatsu31facc52010-03-16 18:05:30 -0400808 lf->lr->path = xstrdup(src);
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500809 line_list__add_line(&lf->lr->line_list, (unsigned int)lineno);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500810 }
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500811 /* Update status */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500812 if (!list_empty(&lf->lr->line_list))
813 lf->found = 1;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500814 else {
815 free(lf->lr->path);
816 lf->lr->path = NULL;
817 }
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500818}
819
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500820static int line_range_inline_cb(Dwarf_Die *in_die, void *data)
821{
822 find_line_range_by_line(in_die, (struct line_finder *)data);
823 return DWARF_CB_ABORT; /* No need to find other instances */
824}
825
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500826/* Search function from function name */
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500827static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500828{
829 struct line_finder *lf = (struct line_finder *)data;
830 struct line_range *lr = lf->lr;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500831
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500832 if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
833 die_compare_name(sp_die, lr->function) == 0) {
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500834 lf->fname = dwarf_decl_file(sp_die);
835 dwarf_decl_line(sp_die, &lr->offset);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500836 pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500837 lf->lno_s = lr->offset + lr->start;
838 if (!lr->end)
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500839 lf->lno_e = INT_MAX;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500840 else
841 lf->lno_e = lr->offset + lr->end;
842 lr->start = lf->lno_s;
843 lr->end = lf->lno_e;
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500844 if (dwarf_func_inline(sp_die))
845 dwarf_func_inline_instances(sp_die,
846 line_range_inline_cb, lf);
847 else
848 find_line_range_by_line(sp_die, lf);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500849 return 1;
850 }
851 return 0;
852}
853
854static void find_line_range_by_func(struct line_finder *lf)
855{
Masami Hiramatsue92b85e2010-02-25 08:35:50 -0500856 dwarf_getfuncs(&lf->cu_die, line_range_search_cb, lf, 0);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500857}
858
859int find_line_range(int fd, struct line_range *lr)
860{
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500861 struct line_finder lf = {.lr = lr, .found = 0};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500862 int ret;
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500863 Dwarf_Off off = 0, noff;
864 size_t cuhl;
865 Dwarf_Die *diep;
866 Dwarf *dbg;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500867
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500868 dbg = dwarf_begin(fd, DWARF_C_READ);
869 if (!dbg)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500870 return -ENOENT;
871
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500872 /* Loop on CUs (Compilation Unit) */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500873 while (!lf.found) {
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500874 ret = dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL);
875 if (ret != 0)
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500876 break;
877
878 /* Get the DIE(Debugging Information Entry) of this CU */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500879 diep = dwarf_offdie(dbg, off + cuhl, &lf.cu_die);
880 if (!diep)
881 continue;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500882
883 /* Check if target file is included. */
884 if (lr->file)
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500885 lf.fname = cu_find_realpath(&lf.cu_die, lr->file);
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500886 else
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500887 lf.fname = 0;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500888
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500889 if (!lr->file || lf.fname) {
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500890 if (lr->function)
891 find_line_range_by_func(&lf);
892 else {
893 lf.lno_s = lr->start;
894 if (!lr->end)
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500895 lf.lno_e = INT_MAX;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500896 else
897 lf.lno_e = lr->end;
Masami Hiramatsu161a26b2010-02-25 08:35:57 -0500898 find_line_range_by_line(NULL, &lf);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500899 }
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500900 }
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500901 off = noff;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500902 }
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500903 pr_debug("path: %lx\n", (unsigned long)lr->path);
904 dwarf_end(dbg);
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500905 return lf.found;
906}
907