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