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> |
Ian Munsie | cd932c5 | 2010-04-20 16:58:32 +1000 | [diff] [blame] | 34 | #include <dwarf-regs.h> |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 35 | |
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" |
Chase Douglas | 9ed7e1b | 2010-06-14 15:26:30 -0400 | [diff] [blame] | 39 | #include "symbol.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 40 | #include "probe-finder.h" |
| 41 | |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 42 | /* Kprobe tracer basic type is up to u64 */ |
| 43 | #define MAX_BASIC_TYPE_BITS 64 |
| 44 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 45 | /* |
| 46 | * Compare the tail of two strings. |
| 47 | * Return 0 if whole of either string is same as another's tail part. |
| 48 | */ |
| 49 | static int strtailcmp(const char *s1, const char *s2) |
| 50 | { |
| 51 | int i1 = strlen(s1); |
| 52 | int i2 = strlen(s2); |
Juha Leppanen | d56728b | 2009-12-07 12:00:40 -0500 | [diff] [blame] | 53 | while (--i1 >= 0 && --i2 >= 0) { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 54 | if (s1[i1] != s2[i2]) |
| 55 | return s1[i1] - s2[i2]; |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 60 | /* Line number list operations */ |
| 61 | |
| 62 | /* Add a line to line number list */ |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 63 | static int line_list__add_line(struct list_head *head, int line) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 64 | { |
| 65 | struct line_node *ln; |
| 66 | struct list_head *p; |
| 67 | |
| 68 | /* Reverse search, because new line will be the last one */ |
| 69 | list_for_each_entry_reverse(ln, head, list) { |
| 70 | if (ln->line < line) { |
| 71 | p = &ln->list; |
| 72 | goto found; |
| 73 | } else if (ln->line == line) /* Already exist */ |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 74 | return 1; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 75 | } |
| 76 | /* List is empty, or the smallest entry */ |
| 77 | p = head; |
| 78 | found: |
| 79 | pr_debug("line list: add a line %u\n", line); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 80 | ln = zalloc(sizeof(struct line_node)); |
| 81 | if (ln == NULL) |
| 82 | return -ENOMEM; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 83 | ln->line = line; |
| 84 | INIT_LIST_HEAD(&ln->list); |
| 85 | list_add(&ln->list, p); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 86 | return 0; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Check if the line in line number list */ |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 90 | static int line_list__has_line(struct list_head *head, int line) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 91 | { |
| 92 | struct line_node *ln; |
| 93 | |
| 94 | /* Reverse search, because new line will be the last one */ |
| 95 | list_for_each_entry(ln, head, list) |
| 96 | if (ln->line == line) |
| 97 | return 1; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /* Init line number list */ |
| 103 | static void line_list__init(struct list_head *head) |
| 104 | { |
| 105 | INIT_LIST_HEAD(head); |
| 106 | } |
| 107 | |
| 108 | /* Free line number list */ |
| 109 | static void line_list__free(struct list_head *head) |
| 110 | { |
| 111 | struct line_node *ln; |
| 112 | while (!list_empty(head)) { |
| 113 | ln = list_first_entry(head, struct line_node, list); |
| 114 | list_del(&ln->list); |
| 115 | free(ln); |
| 116 | } |
| 117 | } |
| 118 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 119 | /* Dwarf FL wrappers */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 120 | static char *debuginfo_path; /* Currently dummy */ |
| 121 | |
| 122 | static const Dwfl_Callbacks offline_callbacks = { |
| 123 | .find_debuginfo = dwfl_standard_find_debuginfo, |
| 124 | .debuginfo_path = &debuginfo_path, |
| 125 | |
| 126 | .section_address = dwfl_offline_section_address, |
| 127 | |
| 128 | /* We use this table for core files too. */ |
| 129 | .find_elf = dwfl_build_id_find_elf, |
| 130 | }; |
| 131 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 132 | /* Get a Dwarf from offline image */ |
| 133 | static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias) |
| 134 | { |
| 135 | Dwfl_Module *mod; |
| 136 | Dwarf *dbg = NULL; |
| 137 | |
| 138 | if (!dwflp) |
| 139 | return NULL; |
| 140 | |
| 141 | *dwflp = dwfl_begin(&offline_callbacks); |
| 142 | if (!*dwflp) |
| 143 | return NULL; |
| 144 | |
| 145 | mod = dwfl_report_offline(*dwflp, "", "", fd); |
| 146 | if (!mod) |
| 147 | goto error; |
| 148 | |
| 149 | dbg = dwfl_module_getdwarf(mod, bias); |
| 150 | if (!dbg) { |
| 151 | error: |
| 152 | dwfl_end(*dwflp); |
| 153 | *dwflp = NULL; |
| 154 | } |
| 155 | return dbg; |
| 156 | } |
| 157 | |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 158 | #if _ELFUTILS_PREREQ(0, 148) |
| 159 | /* This method is buggy if elfutils is older than 0.148 */ |
| 160 | static int __linux_kernel_find_elf(Dwfl_Module *mod, |
| 161 | void **userdata, |
| 162 | const char *module_name, |
| 163 | Dwarf_Addr base, |
| 164 | char **file_name, Elf **elfp) |
| 165 | { |
| 166 | int fd; |
| 167 | const char *path = kernel_get_module_path(module_name); |
| 168 | |
| 169 | pr_debug2("Use file %s for %s\n", path, module_name); |
| 170 | if (path) { |
| 171 | fd = open(path, O_RDONLY); |
| 172 | if (fd >= 0) { |
| 173 | *file_name = strdup(path); |
| 174 | return fd; |
| 175 | } |
| 176 | } |
| 177 | /* If failed, try to call standard method */ |
| 178 | return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base, |
| 179 | file_name, elfp); |
| 180 | } |
| 181 | |
| 182 | static const Dwfl_Callbacks kernel_callbacks = { |
| 183 | .find_debuginfo = dwfl_standard_find_debuginfo, |
| 184 | .debuginfo_path = &debuginfo_path, |
| 185 | |
| 186 | .find_elf = __linux_kernel_find_elf, |
| 187 | .section_address = dwfl_linux_kernel_module_section_address, |
| 188 | }; |
| 189 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 190 | /* Get a Dwarf from live kernel image */ |
| 191 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp, |
| 192 | Dwarf_Addr *bias) |
| 193 | { |
| 194 | Dwarf *dbg; |
| 195 | |
| 196 | if (!dwflp) |
| 197 | return NULL; |
| 198 | |
| 199 | *dwflp = dwfl_begin(&kernel_callbacks); |
| 200 | if (!*dwflp) |
| 201 | return NULL; |
| 202 | |
| 203 | /* Load the kernel dwarves: Don't care the result here */ |
| 204 | dwfl_linux_kernel_report_kernel(*dwflp); |
| 205 | dwfl_linux_kernel_report_modules(*dwflp); |
| 206 | |
| 207 | dbg = dwfl_addrdwarf(*dwflp, addr, bias); |
| 208 | /* Here, check whether we could get a real dwarf */ |
| 209 | if (!dbg) { |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 210 | pr_debug("Failed to find kernel dwarf at %lx\n", |
| 211 | (unsigned long)addr); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 212 | dwfl_end(*dwflp); |
| 213 | *dwflp = NULL; |
| 214 | } |
| 215 | return dbg; |
| 216 | } |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 217 | #else |
| 218 | /* With older elfutils, this just support kernel module... */ |
| 219 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr __used, Dwfl **dwflp, |
| 220 | Dwarf_Addr *bias) |
| 221 | { |
| 222 | int fd; |
| 223 | const char *path = kernel_get_module_path("kernel"); |
| 224 | |
| 225 | if (!path) { |
| 226 | pr_err("Failed to find vmlinux path\n"); |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | pr_debug2("Use file %s for debuginfo\n", path); |
| 231 | fd = open(path, O_RDONLY); |
| 232 | if (fd < 0) |
| 233 | return NULL; |
| 234 | |
| 235 | return dwfl_init_offline_dwarf(fd, dwflp, bias); |
| 236 | } |
| 237 | #endif |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 238 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 239 | /* Dwarf wrappers */ |
| 240 | |
| 241 | /* Find the realpath of the target file. */ |
| 242 | 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] | 243 | { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 244 | Dwarf_Files *files; |
| 245 | size_t nfiles, i; |
Arnaldo Carvalho de Melo | accd3cc | 2010-03-05 12:51:04 -0300 | [diff] [blame] | 246 | const char *src = NULL; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 247 | int ret; |
| 248 | |
| 249 | if (!fname) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 250 | return NULL; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 251 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 252 | ret = dwarf_getsrcfiles(cu_die, &files, &nfiles); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 253 | if (ret != 0) |
| 254 | return NULL; |
| 255 | |
| 256 | for (i = 0; i < nfiles; i++) { |
| 257 | src = dwarf_filesrc(files, i, NULL, NULL); |
| 258 | if (strtailcmp(src, fname) == 0) |
| 259 | break; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 260 | } |
Masami Hiramatsu | c9e3858 | 2010-04-02 12:50:45 -0400 | [diff] [blame] | 261 | if (i == nfiles) |
| 262 | return NULL; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 263 | return src; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 264 | } |
| 265 | |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 266 | /* Get DW_AT_comp_dir (should be NULL with older gcc) */ |
| 267 | static const char *cu_get_comp_dir(Dwarf_Die *cu_die) |
| 268 | { |
| 269 | Dwarf_Attribute attr; |
| 270 | if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL) |
| 271 | return NULL; |
| 272 | return dwarf_formstring(&attr); |
| 273 | } |
| 274 | |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 275 | /* Compare diename and tname */ |
| 276 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) |
| 277 | { |
| 278 | const char *name; |
| 279 | name = dwarf_diename(dw_die); |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 280 | return name ? (strcmp(tname, name) == 0) : false; |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Masami Hiramatsu | 4046b8b | 2010-10-21 19:13:02 +0900 | [diff] [blame] | 283 | /* Get type die */ |
| 284 | static Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) |
| 285 | { |
| 286 | Dwarf_Attribute attr; |
| 287 | |
| 288 | if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) && |
| 289 | dwarf_formref_die(&attr, die_mem)) |
| 290 | return die_mem; |
| 291 | else |
| 292 | return NULL; |
| 293 | } |
| 294 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 295 | /* Get a type die, but skip qualifiers */ |
| 296 | static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 297 | { |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 298 | int tag; |
| 299 | |
| 300 | do { |
Masami Hiramatsu | 4046b8b | 2010-10-21 19:13:02 +0900 | [diff] [blame] | 301 | vr_die = die_get_type(vr_die, die_mem); |
| 302 | if (!vr_die) |
| 303 | break; |
| 304 | tag = dwarf_tag(vr_die); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 305 | } while (tag == DW_TAG_const_type || |
| 306 | tag == DW_TAG_restrict_type || |
| 307 | tag == DW_TAG_volatile_type || |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 308 | tag == DW_TAG_shared_type); |
| 309 | |
| 310 | return vr_die; |
| 311 | } |
| 312 | |
| 313 | /* Get a type die, but skip qualifiers and typedef */ |
| 314 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) |
| 315 | { |
| 316 | do { |
| 317 | vr_die = __die_get_real_type(vr_die, die_mem); |
| 318 | } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 319 | |
Masami Hiramatsu | 4046b8b | 2010-10-21 19:13:02 +0900 | [diff] [blame] | 320 | return vr_die; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 323 | static bool die_is_signed_type(Dwarf_Die *tp_die) |
| 324 | { |
| 325 | Dwarf_Attribute attr; |
| 326 | Dwarf_Word ret; |
| 327 | |
| 328 | if (dwarf_attr(tp_die, DW_AT_encoding, &attr) == NULL || |
| 329 | dwarf_formudata(&attr, &ret) != 0) |
| 330 | return false; |
| 331 | |
| 332 | return (ret == DW_ATE_signed_char || ret == DW_ATE_signed || |
| 333 | ret == DW_ATE_signed_fixed); |
| 334 | } |
| 335 | |
| 336 | static int die_get_byte_size(Dwarf_Die *tp_die) |
| 337 | { |
| 338 | Dwarf_Attribute attr; |
| 339 | Dwarf_Word ret; |
| 340 | |
| 341 | if (dwarf_attr(tp_die, DW_AT_byte_size, &attr) == NULL || |
| 342 | dwarf_formudata(&attr, &ret) != 0) |
| 343 | return 0; |
| 344 | |
| 345 | return (int)ret; |
| 346 | } |
| 347 | |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 348 | /* Get data_member_location offset */ |
| 349 | static int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs) |
| 350 | { |
| 351 | Dwarf_Attribute attr; |
| 352 | Dwarf_Op *expr; |
| 353 | size_t nexpr; |
| 354 | int ret; |
| 355 | |
| 356 | if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL) |
| 357 | return -ENOENT; |
| 358 | |
| 359 | if (dwarf_formudata(&attr, offs) != 0) { |
| 360 | /* DW_AT_data_member_location should be DW_OP_plus_uconst */ |
| 361 | ret = dwarf_getlocation(&attr, &expr, &nexpr); |
| 362 | if (ret < 0 || nexpr == 0) |
| 363 | return -ENOENT; |
| 364 | |
| 365 | if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) { |
| 366 | pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n", |
| 367 | expr[0].atom, nexpr); |
| 368 | return -ENOTSUP; |
| 369 | } |
| 370 | *offs = (Dwarf_Word)expr[0].number; |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 375 | /* Return values for die_find callbacks */ |
| 376 | enum { |
| 377 | DIE_FIND_CB_FOUND = 0, /* End of Search */ |
| 378 | DIE_FIND_CB_CHILD = 1, /* Search only children */ |
| 379 | DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ |
| 380 | DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ |
| 381 | }; |
| 382 | |
| 383 | /* Search a child die */ |
| 384 | static Dwarf_Die *die_find_child(Dwarf_Die *rt_die, |
| 385 | int (*callback)(Dwarf_Die *, void *), |
| 386 | void *data, Dwarf_Die *die_mem) |
| 387 | { |
| 388 | Dwarf_Die child_die; |
| 389 | int ret; |
| 390 | |
| 391 | ret = dwarf_child(rt_die, die_mem); |
| 392 | if (ret != 0) |
| 393 | return NULL; |
| 394 | |
| 395 | do { |
| 396 | ret = callback(die_mem, data); |
| 397 | if (ret == DIE_FIND_CB_FOUND) |
| 398 | return die_mem; |
| 399 | |
| 400 | if ((ret & DIE_FIND_CB_CHILD) && |
| 401 | die_find_child(die_mem, callback, data, &child_die)) { |
| 402 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); |
| 403 | return die_mem; |
| 404 | } |
| 405 | } while ((ret & DIE_FIND_CB_SIBLING) && |
| 406 | dwarf_siblingof(die_mem, die_mem) == 0); |
| 407 | |
| 408 | return NULL; |
| 409 | } |
| 410 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 411 | struct __addr_die_search_param { |
| 412 | Dwarf_Addr addr; |
| 413 | Dwarf_Die *die_mem; |
| 414 | }; |
| 415 | |
| 416 | static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) |
| 417 | { |
| 418 | struct __addr_die_search_param *ad = data; |
| 419 | |
| 420 | if (dwarf_tag(fn_die) == DW_TAG_subprogram && |
| 421 | dwarf_haspc(fn_die, ad->addr)) { |
| 422 | memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); |
| 423 | return DWARF_CB_ABORT; |
| 424 | } |
| 425 | return DWARF_CB_OK; |
| 426 | } |
| 427 | |
| 428 | /* Search a real subprogram including this line, */ |
Masami Hiramatsu | 95a3e4c | 2010-03-16 18:05:51 -0400 | [diff] [blame] | 429 | static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, |
| 430 | Dwarf_Die *die_mem) |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 431 | { |
| 432 | struct __addr_die_search_param ad; |
| 433 | ad.addr = addr; |
| 434 | ad.die_mem = die_mem; |
| 435 | /* dwarf_getscopes can't find subprogram. */ |
| 436 | if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0)) |
| 437 | return NULL; |
| 438 | else |
| 439 | return die_mem; |
| 440 | } |
| 441 | |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 442 | /* die_find callback for inline function search */ |
| 443 | static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) |
| 444 | { |
| 445 | Dwarf_Addr *addr = data; |
| 446 | |
| 447 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && |
| 448 | dwarf_haspc(die_mem, *addr)) |
| 449 | return DIE_FIND_CB_FOUND; |
| 450 | |
| 451 | return DIE_FIND_CB_CONTINUE; |
| 452 | } |
| 453 | |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 454 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ |
Masami Hiramatsu | 95a3e4c | 2010-03-16 18:05:51 -0400 | [diff] [blame] | 455 | static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, |
| 456 | Dwarf_Die *die_mem) |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 457 | { |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 458 | 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] | 459 | } |
| 460 | |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 461 | struct __find_variable_param { |
| 462 | const char *name; |
| 463 | Dwarf_Addr addr; |
| 464 | }; |
| 465 | |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 466 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 467 | { |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 468 | struct __find_variable_param *fvp = data; |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 469 | int tag; |
| 470 | |
| 471 | tag = dwarf_tag(die_mem); |
| 472 | if ((tag == DW_TAG_formal_parameter || |
| 473 | tag == DW_TAG_variable) && |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 474 | die_compare_name(die_mem, fvp->name)) |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 475 | return DIE_FIND_CB_FOUND; |
| 476 | |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 477 | if (dwarf_haspc(die_mem, fvp->addr)) |
| 478 | return DIE_FIND_CB_CONTINUE; |
| 479 | else |
| 480 | return DIE_FIND_CB_SIBLING; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 483 | /* Find a variable called 'name' at given address */ |
| 484 | static Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, |
| 485 | Dwarf_Addr addr, Dwarf_Die *die_mem) |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 486 | { |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 487 | struct __find_variable_param fvp = { .name = name, .addr = addr}; |
| 488 | |
| 489 | return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp, |
Masami Hiramatsu | 016f262 | 2010-03-16 18:05:58 -0400 | [diff] [blame] | 490 | die_mem); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 493 | static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) |
| 494 | { |
| 495 | const char *name = data; |
| 496 | |
| 497 | if ((dwarf_tag(die_mem) == DW_TAG_member) && |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 498 | die_compare_name(die_mem, name)) |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 499 | return DIE_FIND_CB_FOUND; |
| 500 | |
| 501 | return DIE_FIND_CB_SIBLING; |
| 502 | } |
| 503 | |
| 504 | /* Find a member called 'name' */ |
| 505 | static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, |
| 506 | Dwarf_Die *die_mem) |
| 507 | { |
| 508 | return die_find_child(st_die, __die_find_member_cb, (void *)name, |
| 509 | die_mem); |
| 510 | } |
| 511 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 512 | /* Get the name of given variable DIE */ |
| 513 | static int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) |
| 514 | { |
| 515 | Dwarf_Die type; |
| 516 | int tag, ret, ret2; |
| 517 | const char *tmp = ""; |
| 518 | |
| 519 | if (__die_get_real_type(vr_die, &type) == NULL) |
| 520 | return -ENOENT; |
| 521 | |
| 522 | tag = dwarf_tag(&type); |
| 523 | if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type) |
| 524 | tmp = "*"; |
| 525 | else if (tag == DW_TAG_subroutine_type) { |
| 526 | /* Function pointer */ |
| 527 | ret = snprintf(buf, len, "(function_type)"); |
| 528 | return (ret >= len) ? -E2BIG : ret; |
| 529 | } else { |
| 530 | if (!dwarf_diename(&type)) |
| 531 | return -ENOENT; |
| 532 | if (tag == DW_TAG_union_type) |
| 533 | tmp = "union "; |
| 534 | else if (tag == DW_TAG_structure_type) |
| 535 | tmp = "struct "; |
| 536 | /* Write a base name */ |
| 537 | ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type)); |
| 538 | return (ret >= len) ? -E2BIG : ret; |
| 539 | } |
| 540 | ret = die_get_typename(&type, buf, len); |
| 541 | if (ret > 0) { |
| 542 | ret2 = snprintf(buf + ret, len - ret, "%s", tmp); |
| 543 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; |
| 544 | } |
| 545 | return ret; |
| 546 | } |
| 547 | |
| 548 | /* Get the name and type of given variable DIE, stored as "type\tname" */ |
| 549 | static int die_get_varname(Dwarf_Die *vr_die, char *buf, int len) |
| 550 | { |
| 551 | int ret, ret2; |
| 552 | |
| 553 | ret = die_get_typename(vr_die, buf, len); |
| 554 | if (ret < 0) { |
| 555 | pr_debug("Failed to get type, make it unknown.\n"); |
| 556 | ret = snprintf(buf, len, "(unknown_type)"); |
| 557 | } |
| 558 | if (ret > 0) { |
| 559 | ret2 = snprintf(buf + ret, len - ret, "\t%s", |
| 560 | dwarf_diename(vr_die)); |
| 561 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; |
| 562 | } |
| 563 | return ret; |
| 564 | } |
| 565 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 566 | /* |
| 567 | * Probe finder related functions |
| 568 | */ |
| 569 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 570 | static struct probe_trace_arg_ref *alloc_trace_arg_ref(long offs) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 571 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 572 | struct probe_trace_arg_ref *ref; |
| 573 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 574 | if (ref != NULL) |
| 575 | ref->offset = offs; |
| 576 | return ref; |
| 577 | } |
| 578 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 579 | /* |
| 580 | * Convert a location into trace_arg. |
| 581 | * If tvar == NULL, this just checks variable can be converted. |
| 582 | */ |
| 583 | static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, |
| 584 | Dwarf_Op *fb_ops, |
| 585 | struct probe_trace_arg *tvar) |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 586 | { |
| 587 | Dwarf_Attribute attr; |
| 588 | Dwarf_Op *op; |
| 589 | size_t nops; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 590 | unsigned int regn; |
| 591 | Dwarf_Word offs = 0; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 592 | bool ref = false; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 593 | const char *regs; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 594 | int ret; |
| 595 | |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 596 | if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL) |
| 597 | goto static_var; |
| 598 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 599 | /* TODO: handle more than 1 exprs */ |
| 600 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 601 | dwarf_getlocation_addr(&attr, addr, &op, &nops, 1) <= 0 || |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 602 | nops == 0) { |
| 603 | /* TODO: Support const_value */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 604 | return -ENOENT; |
| 605 | } |
| 606 | |
| 607 | if (op->atom == DW_OP_addr) { |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 608 | static_var: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 609 | if (!tvar) |
| 610 | return 0; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 611 | /* Static variables on memory (not stack), make @varname */ |
| 612 | ret = strlen(dwarf_diename(vr_die)); |
| 613 | tvar->value = zalloc(ret + 2); |
| 614 | if (tvar->value == NULL) |
| 615 | return -ENOMEM; |
| 616 | snprintf(tvar->value, ret + 2, "@%s", dwarf_diename(vr_die)); |
| 617 | tvar->ref = alloc_trace_arg_ref((long)offs); |
| 618 | if (tvar->ref == NULL) |
| 619 | return -ENOMEM; |
| 620 | return 0; |
| 621 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 622 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 623 | /* If this is based on frame buffer, set the offset */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 624 | if (op->atom == DW_OP_fbreg) { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 625 | if (fb_ops == NULL) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 626 | return -ENOTSUP; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 627 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 628 | offs = op->number; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 629 | op = &fb_ops[0]; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 630 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 631 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 632 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { |
| 633 | regn = op->atom - DW_OP_breg0; |
| 634 | offs += op->number; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 635 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 636 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { |
| 637 | regn = op->atom - DW_OP_reg0; |
| 638 | } else if (op->atom == DW_OP_bregx) { |
| 639 | regn = op->number; |
| 640 | offs += op->number2; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 641 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 642 | } else if (op->atom == DW_OP_regx) { |
| 643 | regn = op->number; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 644 | } else { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 645 | pr_debug("DW_OP %x is not supported.\n", op->atom); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 646 | return -ENOTSUP; |
| 647 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 648 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 649 | if (!tvar) |
| 650 | return 0; |
| 651 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 652 | regs = get_arch_regstr(regn); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 653 | if (!regs) { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 654 | /* This should be a bug in DWARF or this tool */ |
| 655 | pr_warning("Mapping for DWARF register number %u " |
| 656 | "missing on this architecture.", regn); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 657 | return -ERANGE; |
| 658 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 659 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 660 | tvar->value = strdup(regs); |
| 661 | if (tvar->value == NULL) |
| 662 | return -ENOMEM; |
| 663 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 664 | if (ref) { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 665 | tvar->ref = alloc_trace_arg_ref((long)offs); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 666 | if (tvar->ref == NULL) |
| 667 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 668 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 669 | return 0; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 672 | static int convert_variable_type(Dwarf_Die *vr_die, |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 673 | struct probe_trace_arg *tvar, |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 674 | const char *cast) |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 675 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 676 | struct probe_trace_arg_ref **ref_ptr = &tvar->ref; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 677 | Dwarf_Die type; |
| 678 | char buf[16]; |
| 679 | int ret; |
| 680 | |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 681 | /* TODO: check all types */ |
| 682 | if (cast && strcmp(cast, "string") != 0) { |
| 683 | /* Non string type is OK */ |
| 684 | tvar->type = strdup(cast); |
| 685 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 686 | } |
| 687 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 688 | if (die_get_real_type(vr_die, &type) == NULL) { |
| 689 | pr_warning("Failed to get a type information of %s.\n", |
| 690 | dwarf_diename(vr_die)); |
| 691 | return -ENOENT; |
| 692 | } |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 693 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 694 | pr_debug("%s type is %s.\n", |
| 695 | dwarf_diename(vr_die), dwarf_diename(&type)); |
| 696 | |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 697 | if (cast && strcmp(cast, "string") == 0) { /* String type */ |
| 698 | ret = dwarf_tag(&type); |
| 699 | if (ret != DW_TAG_pointer_type && |
| 700 | ret != DW_TAG_array_type) { |
| 701 | pr_warning("Failed to cast into string: " |
| 702 | "%s(%s) is not a pointer nor array.", |
| 703 | dwarf_diename(vr_die), dwarf_diename(&type)); |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | if (ret == DW_TAG_pointer_type) { |
| 707 | if (die_get_real_type(&type, &type) == NULL) { |
| 708 | pr_warning("Failed to get a type information."); |
| 709 | return -ENOENT; |
| 710 | } |
| 711 | while (*ref_ptr) |
| 712 | ref_ptr = &(*ref_ptr)->next; |
| 713 | /* Add new reference with offset +0 */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 714 | *ref_ptr = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 715 | if (*ref_ptr == NULL) { |
| 716 | pr_warning("Out of memory error\n"); |
| 717 | return -ENOMEM; |
| 718 | } |
| 719 | } |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 720 | if (!die_compare_name(&type, "char") && |
| 721 | !die_compare_name(&type, "unsigned char")) { |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 722 | pr_warning("Failed to cast into string: " |
| 723 | "%s is not (unsigned) char *.", |
| 724 | dwarf_diename(vr_die)); |
| 725 | return -EINVAL; |
| 726 | } |
| 727 | tvar->type = strdup(cast); |
| 728 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 729 | } |
| 730 | |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 731 | ret = die_get_byte_size(&type) * 8; |
| 732 | if (ret) { |
| 733 | /* Check the bitwidth */ |
| 734 | if (ret > MAX_BASIC_TYPE_BITS) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 735 | pr_info("%s exceeds max-bitwidth." |
| 736 | " Cut down to %d bits.\n", |
| 737 | dwarf_diename(&type), MAX_BASIC_TYPE_BITS); |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 738 | ret = MAX_BASIC_TYPE_BITS; |
| 739 | } |
| 740 | |
| 741 | ret = snprintf(buf, 16, "%c%d", |
| 742 | die_is_signed_type(&type) ? 's' : 'u', ret); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 743 | if (ret < 0 || ret >= 16) { |
| 744 | if (ret >= 16) |
| 745 | ret = -E2BIG; |
| 746 | pr_warning("Failed to convert variable type: %s\n", |
| 747 | strerror(-ret)); |
| 748 | return ret; |
| 749 | } |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 750 | tvar->type = strdup(buf); |
| 751 | if (tvar->type == NULL) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 752 | return -ENOMEM; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 753 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 754 | return 0; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 755 | } |
| 756 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 757 | static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 758 | struct perf_probe_arg_field *field, |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 759 | struct probe_trace_arg_ref **ref_ptr, |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 760 | Dwarf_Die *die_mem) |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 761 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 762 | struct probe_trace_arg_ref *ref = *ref_ptr; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 763 | Dwarf_Die type; |
| 764 | Dwarf_Word offs; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 765 | int ret, tag; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 766 | |
| 767 | pr_debug("converting %s in %s\n", field->name, varname); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 768 | if (die_get_real_type(vr_die, &type) == NULL) { |
| 769 | pr_warning("Failed to get the type of %s.\n", varname); |
| 770 | return -ENOENT; |
| 771 | } |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 772 | pr_debug2("Var real type: (%x)\n", (unsigned)dwarf_dieoffset(&type)); |
| 773 | tag = dwarf_tag(&type); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 774 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 775 | if (field->name[0] == '[' && |
| 776 | (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)) { |
| 777 | if (field->next) |
| 778 | /* Save original type for next field */ |
| 779 | memcpy(die_mem, &type, sizeof(*die_mem)); |
| 780 | /* Get the type of this array */ |
| 781 | if (die_get_real_type(&type, &type) == NULL) { |
| 782 | pr_warning("Failed to get the type of %s.\n", varname); |
| 783 | return -ENOENT; |
| 784 | } |
| 785 | pr_debug2("Array real type: (%x)\n", |
| 786 | (unsigned)dwarf_dieoffset(&type)); |
| 787 | if (tag == DW_TAG_pointer_type) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 788 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 789 | if (ref == NULL) |
| 790 | return -ENOMEM; |
| 791 | if (*ref_ptr) |
| 792 | (*ref_ptr)->next = ref; |
| 793 | else |
| 794 | *ref_ptr = ref; |
| 795 | } |
| 796 | ref->offset += die_get_byte_size(&type) * field->index; |
| 797 | if (!field->next) |
| 798 | /* Save vr_die for converting types */ |
| 799 | memcpy(die_mem, vr_die, sizeof(*die_mem)); |
| 800 | goto next; |
| 801 | } else if (tag == DW_TAG_pointer_type) { |
| 802 | /* Check the pointer and dereference */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 803 | if (!field->ref) { |
| 804 | pr_err("Semantic error: %s must be referred by '->'\n", |
| 805 | field->name); |
| 806 | return -EINVAL; |
| 807 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 808 | /* Get the type pointed by this pointer */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 809 | if (die_get_real_type(&type, &type) == NULL) { |
| 810 | pr_warning("Failed to get the type of %s.\n", varname); |
| 811 | return -ENOENT; |
| 812 | } |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 813 | /* Verify it is a data structure */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 814 | if (dwarf_tag(&type) != DW_TAG_structure_type) { |
| 815 | pr_warning("%s is not a data structure.\n", varname); |
| 816 | return -EINVAL; |
| 817 | } |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 818 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 819 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 820 | if (ref == NULL) |
| 821 | return -ENOMEM; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 822 | if (*ref_ptr) |
| 823 | (*ref_ptr)->next = ref; |
| 824 | else |
| 825 | *ref_ptr = ref; |
| 826 | } else { |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 827 | /* Verify it is a data structure */ |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 828 | if (tag != DW_TAG_structure_type) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 829 | pr_warning("%s is not a data structure.\n", varname); |
| 830 | return -EINVAL; |
| 831 | } |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 832 | if (field->name[0] == '[') { |
| 833 | pr_err("Semantic error: %s is not a pointor nor array.", |
| 834 | varname); |
| 835 | return -EINVAL; |
| 836 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 837 | if (field->ref) { |
| 838 | pr_err("Semantic error: %s must be referred by '.'\n", |
| 839 | field->name); |
| 840 | return -EINVAL; |
| 841 | } |
| 842 | if (!ref) { |
| 843 | pr_warning("Structure on a register is not " |
| 844 | "supported yet.\n"); |
| 845 | return -ENOTSUP; |
| 846 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 847 | } |
| 848 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 849 | if (die_find_member(&type, field->name, die_mem) == NULL) { |
| 850 | pr_warning("%s(tyep:%s) has no member %s.\n", varname, |
| 851 | dwarf_diename(&type), field->name); |
| 852 | return -EINVAL; |
| 853 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 854 | |
| 855 | /* Get the offset of the field */ |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 856 | ret = die_get_data_member_location(die_mem, &offs); |
| 857 | if (ret < 0) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 858 | pr_warning("Failed to get the offset of %s.\n", field->name); |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 859 | return ret; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 860 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 861 | ref->offset += (long)offs; |
| 862 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 863 | next: |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 864 | /* Converting next field */ |
| 865 | if (field->next) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 866 | return convert_variable_fields(die_mem, field->name, |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 867 | field->next, &ref, die_mem); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 868 | else |
| 869 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 872 | /* Show a variables in kprobe event format */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 873 | static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 874 | { |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 875 | Dwarf_Die die_mem; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 876 | int ret; |
| 877 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 878 | pr_debug("Converting variable %s into trace event.\n", |
| 879 | dwarf_diename(vr_die)); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 880 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 881 | ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops, |
| 882 | pf->tvar); |
| 883 | if (ret == -ENOENT) |
| 884 | pr_err("Failed to find the location of %s at this address.\n" |
| 885 | " Perhaps, it has been optimized out.\n", pf->pvar->var); |
| 886 | else if (ret == -ENOTSUP) |
| 887 | pr_err("Sorry, we don't support this variable location yet.\n"); |
| 888 | else if (pf->pvar->field) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 889 | ret = convert_variable_fields(vr_die, pf->pvar->var, |
| 890 | pf->pvar->field, &pf->tvar->ref, |
| 891 | &die_mem); |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 892 | vr_die = &die_mem; |
| 893 | } |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 894 | if (ret == 0) |
| 895 | ret = convert_variable_type(vr_die, pf->tvar, pf->pvar->type); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 896 | /* *expr will be cached in libdw. Don't free it. */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 897 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 898 | } |
| 899 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 900 | /* Find a variable in a subprogram die */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 901 | static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 902 | { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 903 | Dwarf_Die vr_die, *scopes; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 904 | char buf[32], *ptr; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 905 | int ret, nscopes; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 906 | |
Masami Hiramatsu | 367e94c | 2010-08-27 20:38:59 +0900 | [diff] [blame] | 907 | if (!is_c_varname(pf->pvar->var)) { |
| 908 | /* Copy raw parameters */ |
| 909 | pf->tvar->value = strdup(pf->pvar->var); |
| 910 | if (pf->tvar->value == NULL) |
| 911 | return -ENOMEM; |
| 912 | if (pf->pvar->type) { |
| 913 | pf->tvar->type = strdup(pf->pvar->type); |
| 914 | if (pf->tvar->type == NULL) |
| 915 | return -ENOMEM; |
| 916 | } |
| 917 | if (pf->pvar->name) { |
| 918 | pf->tvar->name = strdup(pf->pvar->name); |
| 919 | if (pf->tvar->name == NULL) |
| 920 | return -ENOMEM; |
| 921 | } else |
| 922 | pf->tvar->name = NULL; |
| 923 | return 0; |
| 924 | } |
| 925 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 926 | if (pf->pvar->name) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 927 | pf->tvar->name = strdup(pf->pvar->name); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 928 | else { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 929 | ret = synthesize_perf_probe_arg(pf->pvar, buf, 32); |
| 930 | if (ret < 0) |
| 931 | return ret; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 932 | ptr = strchr(buf, ':'); /* Change type separator to _ */ |
| 933 | if (ptr) |
| 934 | *ptr = '_'; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 935 | pf->tvar->name = strdup(buf); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 936 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 937 | if (pf->tvar->name == NULL) |
| 938 | return -ENOMEM; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 939 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 940 | pr_debug("Searching '%s' variable in context.\n", |
| 941 | pf->pvar->var); |
| 942 | /* Search child die for local variables and parameters. */ |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 943 | if (die_find_variable_at(sp_die, pf->pvar->var, pf->addr, &vr_die)) |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 944 | ret = convert_variable(&vr_die, pf); |
| 945 | else { |
| 946 | /* Search upper class */ |
| 947 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 948 | while (nscopes-- > 1) { |
| 949 | pr_debug("Searching variables in %s\n", |
| 950 | dwarf_diename(&scopes[nscopes])); |
| 951 | /* We should check this scope, so give dummy address */ |
| 952 | if (die_find_variable_at(&scopes[nscopes], |
| 953 | pf->pvar->var, 0, |
| 954 | &vr_die)) { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 955 | ret = convert_variable(&vr_die, pf); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 956 | goto found; |
| 957 | } |
| 958 | } |
| 959 | if (scopes) |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 960 | free(scopes); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 961 | ret = -ENOENT; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 962 | } |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 963 | found: |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 964 | if (ret < 0) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 965 | pr_warning("Failed to find '%s' in this function.\n", |
| 966 | pf->pvar->var); |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 967 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 968 | } |
| 969 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 970 | /* Convert subprogram DIE to trace point */ |
| 971 | static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr, |
| 972 | bool retprobe, struct probe_trace_point *tp) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 973 | { |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 974 | Dwarf_Addr eaddr; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 975 | const char *name; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 976 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 977 | /* Copy the name of probe point */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 978 | name = dwarf_diename(sp_die); |
| 979 | if (name) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 980 | if (dwarf_entrypc(sp_die, &eaddr) != 0) { |
| 981 | pr_warning("Failed to get entry pc of %s\n", |
| 982 | dwarf_diename(sp_die)); |
| 983 | return -ENOENT; |
| 984 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 985 | tp->symbol = strdup(name); |
| 986 | if (tp->symbol == NULL) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 987 | return -ENOMEM; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 988 | tp->offset = (unsigned long)(paddr - eaddr); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 989 | } else |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 990 | /* This function has no name. */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 991 | tp->offset = (unsigned long)paddr; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 992 | |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 993 | /* Return probe must be on the head of a subprogram */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 994 | if (retprobe) { |
| 995 | if (eaddr != paddr) { |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 996 | pr_warning("Return probe must be on the head of" |
| 997 | " a real function\n"); |
| 998 | return -EINVAL; |
| 999 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1000 | tp->retprobe = true; |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 1001 | } |
| 1002 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | /* Call probe_finder callback with real subprogram DIE */ |
| 1007 | static int call_probe_finder(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 1008 | { |
| 1009 | Dwarf_Die die_mem; |
| 1010 | Dwarf_Attribute fb_attr; |
| 1011 | size_t nops; |
| 1012 | int ret; |
| 1013 | |
| 1014 | /* If no real subprogram, find a real one */ |
| 1015 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { |
| 1016 | sp_die = die_find_real_subprogram(&pf->cu_die, |
| 1017 | pf->addr, &die_mem); |
| 1018 | if (!sp_die) { |
| 1019 | pr_warning("Failed to find probe point in any " |
| 1020 | "functions.\n"); |
| 1021 | return -ENOENT; |
| 1022 | } |
| 1023 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1024 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1025 | /* Get the frame base attribute/ops */ |
| 1026 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); |
Masami Hiramatsu | d0cb426 | 2010-03-15 13:02:35 -0400 | [diff] [blame] | 1027 | 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] | 1028 | if (ret <= 0 || nops == 0) { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1029 | pf->fb_ops = NULL; |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 1030 | #if _ELFUTILS_PREREQ(0, 142) |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 1031 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
| 1032 | pf->cfi != NULL) { |
| 1033 | Dwarf_Frame *frame; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1034 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || |
| 1035 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { |
| 1036 | pr_warning("Failed to get CFA on 0x%jx\n", |
| 1037 | (uintmax_t)pf->addr); |
| 1038 | return -ENOENT; |
| 1039 | } |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 1040 | #endif |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 1041 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1042 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1043 | /* Call finder's callback handler */ |
| 1044 | ret = pf->callback(sp_die, pf); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1045 | |
| 1046 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ |
| 1047 | pf->fb_ops = NULL; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1048 | |
| 1049 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1052 | /* Find probe point from its line number */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1053 | static int find_probe_point_by_line(struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1054 | { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1055 | Dwarf_Lines *lines; |
| 1056 | Dwarf_Line *line; |
| 1057 | size_t nlines, i; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1058 | Dwarf_Addr addr; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1059 | int lineno; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1060 | int ret = 0; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1061 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1062 | if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) { |
| 1063 | pr_warning("No source lines found in this CU.\n"); |
| 1064 | return -ENOENT; |
| 1065 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1066 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1067 | for (i = 0; i < nlines && ret == 0; i++) { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1068 | line = dwarf_onesrcline(lines, i); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1069 | if (dwarf_lineno(line, &lineno) != 0 || |
| 1070 | lineno != pf->lno) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1071 | continue; |
| 1072 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1073 | /* TODO: Get fileno from line, but how? */ |
| 1074 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) |
| 1075 | continue; |
Masami Hiramatsu | b0ef073 | 2009-10-27 16:43:19 -0400 | [diff] [blame] | 1076 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1077 | if (dwarf_lineaddr(line, &addr) != 0) { |
| 1078 | pr_warning("Failed to get the address of the line.\n"); |
| 1079 | return -ENOENT; |
| 1080 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1081 | pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n", |
| 1082 | (int)i, lineno, (uintmax_t)addr); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1083 | pf->addr = addr; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1084 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1085 | ret = call_probe_finder(NULL, pf); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1086 | /* Continuing, because target line might be inlined. */ |
| 1087 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1088 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1091 | /* Find lines which match lazy pattern */ |
| 1092 | static int find_lazy_match_lines(struct list_head *head, |
| 1093 | const char *fname, const char *pat) |
| 1094 | { |
| 1095 | char *fbuf, *p1, *p2; |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1096 | int fd, line, nlines = -1; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1097 | struct stat st; |
| 1098 | |
| 1099 | fd = open(fname, O_RDONLY); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1100 | if (fd < 0) { |
| 1101 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1102 | return -errno; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1105 | if (fstat(fd, &st) < 0) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1106 | pr_warning("Failed to get the size of %s: %s\n", |
| 1107 | fname, strerror(errno)); |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1108 | nlines = -errno; |
| 1109 | goto out_close; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1110 | } |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1111 | |
| 1112 | nlines = -ENOMEM; |
| 1113 | fbuf = malloc(st.st_size + 2); |
| 1114 | if (fbuf == NULL) |
| 1115 | goto out_close; |
| 1116 | if (read(fd, fbuf, st.st_size) < 0) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1117 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1118 | nlines = -errno; |
| 1119 | goto out_free_fbuf; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1120 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1121 | fbuf[st.st_size] = '\n'; /* Dummy line */ |
| 1122 | fbuf[st.st_size + 1] = '\0'; |
| 1123 | p1 = fbuf; |
| 1124 | line = 1; |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1125 | nlines = 0; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1126 | while ((p2 = strchr(p1, '\n')) != NULL) { |
| 1127 | *p2 = '\0'; |
| 1128 | if (strlazymatch(p1, pat)) { |
| 1129 | line_list__add_line(head, line); |
| 1130 | nlines++; |
| 1131 | } |
| 1132 | line++; |
| 1133 | p1 = p2 + 1; |
| 1134 | } |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1135 | out_free_fbuf: |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1136 | free(fbuf); |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 1137 | out_close: |
| 1138 | close(fd); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1139 | return nlines; |
| 1140 | } |
| 1141 | |
| 1142 | /* Find probe points from lazy pattern */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1143 | 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] | 1144 | { |
| 1145 | Dwarf_Lines *lines; |
| 1146 | Dwarf_Line *line; |
| 1147 | size_t nlines, i; |
| 1148 | Dwarf_Addr addr; |
| 1149 | Dwarf_Die die_mem; |
| 1150 | int lineno; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1151 | int ret = 0; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1152 | |
| 1153 | if (list_empty(&pf->lcache)) { |
| 1154 | /* Matching lazy line pattern */ |
| 1155 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1156 | pf->pev->point.lazy_line); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1157 | if (ret == 0) { |
| 1158 | pr_debug("No matched lines found in %s.\n", pf->fname); |
| 1159 | return 0; |
| 1160 | } else if (ret < 0) |
| 1161 | return ret; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1164 | if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) { |
| 1165 | pr_warning("No source lines found in this CU.\n"); |
| 1166 | return -ENOENT; |
| 1167 | } |
| 1168 | |
| 1169 | for (i = 0; i < nlines && ret >= 0; i++) { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1170 | line = dwarf_onesrcline(lines, i); |
| 1171 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1172 | if (dwarf_lineno(line, &lineno) != 0 || |
| 1173 | !line_list__has_line(&pf->lcache, lineno)) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1174 | continue; |
| 1175 | |
| 1176 | /* TODO: Get fileno from line, but how? */ |
| 1177 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) |
| 1178 | continue; |
| 1179 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1180 | if (dwarf_lineaddr(line, &addr) != 0) { |
| 1181 | pr_debug("Failed to get the address of line %d.\n", |
| 1182 | lineno); |
| 1183 | continue; |
| 1184 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1185 | if (sp_die) { |
| 1186 | /* Address filtering 1: does sp_die include addr? */ |
| 1187 | if (!dwarf_haspc(sp_die, addr)) |
| 1188 | continue; |
| 1189 | /* Address filtering 2: No child include addr? */ |
Masami Hiramatsu | 95a3e4c | 2010-03-16 18:05:51 -0400 | [diff] [blame] | 1190 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1191 | continue; |
| 1192 | } |
| 1193 | |
| 1194 | pr_debug("Probe line found: line[%d]:%d addr:0x%llx\n", |
| 1195 | (int)i, lineno, (unsigned long long)addr); |
| 1196 | pf->addr = addr; |
| 1197 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1198 | ret = call_probe_finder(sp_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1199 | /* Continuing, because target line might be inlined. */ |
| 1200 | } |
| 1201 | /* TODO: deallocate lines, but how? */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1202 | return ret; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1203 | } |
| 1204 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1205 | /* Callback parameter with return value */ |
| 1206 | struct dwarf_callback_param { |
| 1207 | void *data; |
| 1208 | int retval; |
| 1209 | }; |
| 1210 | |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1211 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1212 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1213 | struct dwarf_callback_param *param = data; |
| 1214 | struct probe_finder *pf = param->data; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1215 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1216 | Dwarf_Addr addr; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1217 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1218 | if (pp->lazy_line) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1219 | param->retval = find_probe_point_lazy(in_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1220 | else { |
| 1221 | /* Get probe address */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1222 | if (dwarf_entrypc(in_die, &addr) != 0) { |
| 1223 | pr_warning("Failed to get entry pc of %s.\n", |
| 1224 | dwarf_diename(in_die)); |
| 1225 | param->retval = -ENOENT; |
| 1226 | return DWARF_CB_ABORT; |
| 1227 | } |
| 1228 | pf->addr = addr; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1229 | pf->addr += pp->offset; |
| 1230 | pr_debug("found inline addr: 0x%jx\n", |
| 1231 | (uintmax_t)pf->addr); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1232 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1233 | param->retval = call_probe_finder(in_die, pf); |
Masami Hiramatsu | 5d1ee04 | 2010-04-21 15:56:32 -0400 | [diff] [blame] | 1234 | if (param->retval < 0) |
| 1235 | return DWARF_CB_ABORT; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1236 | } |
| 1237 | |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1238 | return DWARF_CB_OK; |
| 1239 | } |
| 1240 | |
| 1241 | /* Search function from function name */ |
| 1242 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) |
| 1243 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1244 | struct dwarf_callback_param *param = data; |
| 1245 | struct probe_finder *pf = param->data; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1246 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1247 | |
| 1248 | /* Check tag and diename */ |
| 1249 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 1250 | !die_compare_name(sp_die, pp->function)) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1251 | return DWARF_CB_OK; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1252 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1253 | pf->fname = dwarf_decl_file(sp_die); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1254 | if (pp->line) { /* Function relative line */ |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1255 | dwarf_decl_line(sp_die, &pf->lno); |
| 1256 | pf->lno += pp->line; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1257 | param->retval = find_probe_point_by_line(pf); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1258 | } else if (!dwarf_func_inline(sp_die)) { |
| 1259 | /* Real function */ |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1260 | if (pp->lazy_line) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1261 | param->retval = find_probe_point_lazy(sp_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1262 | else { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1263 | if (dwarf_entrypc(sp_die, &pf->addr) != 0) { |
| 1264 | pr_warning("Failed to get entry pc of %s.\n", |
| 1265 | dwarf_diename(sp_die)); |
| 1266 | param->retval = -ENOENT; |
| 1267 | return DWARF_CB_ABORT; |
| 1268 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1269 | pf->addr += pp->offset; |
| 1270 | /* TODO: Check the address in this function */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1271 | param->retval = call_probe_finder(sp_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1272 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1273 | } else { |
| 1274 | struct dwarf_callback_param _param = {.data = (void *)pf, |
| 1275 | .retval = 0}; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1276 | /* Inlined function: search instances */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1277 | dwarf_func_inline_instances(sp_die, probe_point_inline_cb, |
| 1278 | &_param); |
| 1279 | param->retval = _param.retval; |
| 1280 | } |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1281 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1282 | return DWARF_CB_ABORT; /* Exit; no same symbol in this CU. */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1285 | static int find_probe_point_by_func(struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1286 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1287 | struct dwarf_callback_param _param = {.data = (void *)pf, |
| 1288 | .retval = 0}; |
| 1289 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0); |
| 1290 | return _param.retval; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1293 | /* Find probe points from debuginfo */ |
| 1294 | static int find_probes(int fd, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1295 | { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1296 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1297 | Dwarf_Off off, noff; |
| 1298 | size_t cuhl; |
| 1299 | Dwarf_Die *diep; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1300 | Dwarf *dbg = NULL; |
| 1301 | Dwfl *dwfl; |
| 1302 | Dwarf_Addr bias; /* Currently ignored */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1303 | int ret = 0; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1304 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1305 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1306 | if (!dbg) { |
| 1307 | pr_warning("No dwarf info found in the vmlinux - " |
| 1308 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
| 1309 | return -EBADF; |
| 1310 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1311 | |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 1312 | #if _ELFUTILS_PREREQ(0, 142) |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 1313 | /* Get the call frame information from this dwarf */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1314 | pf->cfi = dwarf_getcfi(dbg); |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 1315 | #endif |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 1316 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1317 | off = 0; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1318 | line_list__init(&pf->lcache); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1319 | /* Loop on CUs (Compilation Unit) */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1320 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) && |
| 1321 | ret >= 0) { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1322 | /* Get the DIE(Debugging Information Entry) of this CU */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1323 | diep = dwarf_offdie(dbg, off + cuhl, &pf->cu_die); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1324 | if (!diep) |
| 1325 | continue; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1326 | |
| 1327 | /* Check if target file is included. */ |
| 1328 | if (pp->file) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1329 | pf->fname = cu_find_realpath(&pf->cu_die, pp->file); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1330 | else |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1331 | pf->fname = NULL; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1332 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1333 | if (!pp->file || pf->fname) { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1334 | if (pp->function) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1335 | ret = find_probe_point_by_func(pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1336 | else if (pp->lazy_line) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1337 | ret = find_probe_point_lazy(NULL, pf); |
Masami Hiramatsu | b0ef073 | 2009-10-27 16:43:19 -0400 | [diff] [blame] | 1338 | else { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1339 | pf->lno = pp->line; |
| 1340 | ret = find_probe_point_by_line(pf); |
Masami Hiramatsu | b0ef073 | 2009-10-27 16:43:19 -0400 | [diff] [blame] | 1341 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1342 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1343 | off = noff; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1344 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1345 | line_list__free(&pf->lcache); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1346 | if (dwfl) |
| 1347 | dwfl_end(dwfl); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1348 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1349 | return ret; |
| 1350 | } |
| 1351 | |
| 1352 | /* Add a found probe point into trace event list */ |
| 1353 | static int add_probe_trace_event(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 1354 | { |
| 1355 | struct trace_event_finder *tf = |
| 1356 | container_of(pf, struct trace_event_finder, pf); |
| 1357 | struct probe_trace_event *tev; |
| 1358 | int ret, i; |
| 1359 | |
| 1360 | /* Check number of tevs */ |
| 1361 | if (tf->ntevs == tf->max_tevs) { |
| 1362 | pr_warning("Too many( > %d) probe point found.\n", |
| 1363 | tf->max_tevs); |
| 1364 | return -ERANGE; |
| 1365 | } |
| 1366 | tev = &tf->tevs[tf->ntevs++]; |
| 1367 | |
| 1368 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, |
| 1369 | &tev->point); |
| 1370 | if (ret < 0) |
| 1371 | return ret; |
| 1372 | |
| 1373 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, |
| 1374 | tev->point.offset); |
| 1375 | |
| 1376 | /* Find each argument */ |
| 1377 | tev->nargs = pf->pev->nargs; |
| 1378 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
| 1379 | if (tev->args == NULL) |
| 1380 | return -ENOMEM; |
| 1381 | for (i = 0; i < pf->pev->nargs; i++) { |
| 1382 | pf->pvar = &pf->pev->args[i]; |
| 1383 | pf->tvar = &tev->args[i]; |
| 1384 | ret = find_variable(sp_die, pf); |
| 1385 | if (ret != 0) |
| 1386 | return ret; |
| 1387 | } |
| 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
| 1392 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
| 1393 | int find_probe_trace_events(int fd, struct perf_probe_event *pev, |
| 1394 | struct probe_trace_event **tevs, int max_tevs) |
| 1395 | { |
| 1396 | struct trace_event_finder tf = { |
| 1397 | .pf = {.pev = pev, .callback = add_probe_trace_event}, |
| 1398 | .max_tevs = max_tevs}; |
| 1399 | int ret; |
| 1400 | |
| 1401 | /* Allocate result tevs array */ |
| 1402 | *tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs); |
| 1403 | if (*tevs == NULL) |
| 1404 | return -ENOMEM; |
| 1405 | |
| 1406 | tf.tevs = *tevs; |
| 1407 | tf.ntevs = 0; |
| 1408 | |
| 1409 | ret = find_probes(fd, &tf.pf); |
| 1410 | if (ret < 0) { |
| 1411 | free(*tevs); |
| 1412 | *tevs = NULL; |
| 1413 | return ret; |
| 1414 | } |
| 1415 | |
| 1416 | return (ret < 0) ? ret : tf.ntevs; |
| 1417 | } |
| 1418 | |
| 1419 | #define MAX_VAR_LEN 64 |
| 1420 | |
| 1421 | /* Collect available variables in this scope */ |
| 1422 | static int collect_variables_cb(Dwarf_Die *die_mem, void *data) |
| 1423 | { |
| 1424 | struct available_var_finder *af = data; |
| 1425 | struct variable_list *vl; |
| 1426 | char buf[MAX_VAR_LEN]; |
| 1427 | int tag, ret; |
| 1428 | |
| 1429 | vl = &af->vls[af->nvls - 1]; |
| 1430 | |
| 1431 | tag = dwarf_tag(die_mem); |
| 1432 | if (tag == DW_TAG_formal_parameter || |
| 1433 | tag == DW_TAG_variable) { |
| 1434 | ret = convert_variable_location(die_mem, af->pf.addr, |
| 1435 | af->pf.fb_ops, NULL); |
| 1436 | if (ret == 0) { |
| 1437 | ret = die_get_varname(die_mem, buf, MAX_VAR_LEN); |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1438 | pr_debug2("Add new var: %s\n", buf); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1439 | if (ret > 0) |
| 1440 | strlist__add(vl->vars, buf); |
| 1441 | } |
| 1442 | } |
| 1443 | |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1444 | if (af->child && dwarf_haspc(die_mem, af->pf.addr)) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1445 | return DIE_FIND_CB_CONTINUE; |
| 1446 | else |
| 1447 | return DIE_FIND_CB_SIBLING; |
| 1448 | } |
| 1449 | |
| 1450 | /* Add a found vars into available variables list */ |
| 1451 | static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 1452 | { |
| 1453 | struct available_var_finder *af = |
| 1454 | container_of(pf, struct available_var_finder, pf); |
| 1455 | struct variable_list *vl; |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1456 | Dwarf_Die die_mem, *scopes = NULL; |
| 1457 | int ret, nscopes; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1458 | |
| 1459 | /* Check number of tevs */ |
| 1460 | if (af->nvls == af->max_vls) { |
| 1461 | pr_warning("Too many( > %d) probe point found.\n", af->max_vls); |
| 1462 | return -ERANGE; |
| 1463 | } |
| 1464 | vl = &af->vls[af->nvls++]; |
| 1465 | |
| 1466 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, |
| 1467 | &vl->point); |
| 1468 | if (ret < 0) |
| 1469 | return ret; |
| 1470 | |
| 1471 | pr_debug("Probe point found: %s+%lu\n", vl->point.symbol, |
| 1472 | vl->point.offset); |
| 1473 | |
| 1474 | /* Find local variables */ |
| 1475 | vl->vars = strlist__new(true, NULL); |
| 1476 | if (vl->vars == NULL) |
| 1477 | return -ENOMEM; |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1478 | af->child = true; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1479 | die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem); |
| 1480 | |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1481 | /* Find external variables */ |
| 1482 | if (!af->externs) |
| 1483 | goto out; |
| 1484 | /* Don't need to search child DIE for externs. */ |
| 1485 | af->child = false; |
| 1486 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
| 1487 | while (nscopes-- > 1) |
| 1488 | die_find_child(&scopes[nscopes], collect_variables_cb, |
| 1489 | (void *)af, &die_mem); |
| 1490 | if (scopes) |
| 1491 | free(scopes); |
| 1492 | |
| 1493 | out: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1494 | if (strlist__empty(vl->vars)) { |
| 1495 | strlist__delete(vl->vars); |
| 1496 | vl->vars = NULL; |
| 1497 | } |
| 1498 | |
| 1499 | return ret; |
| 1500 | } |
| 1501 | |
| 1502 | /* Find available variables at given probe point */ |
| 1503 | int find_available_vars_at(int fd, struct perf_probe_event *pev, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1504 | struct variable_list **vls, int max_vls, |
| 1505 | bool externs) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1506 | { |
| 1507 | struct available_var_finder af = { |
| 1508 | .pf = {.pev = pev, .callback = add_available_vars}, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1509 | .max_vls = max_vls, .externs = externs}; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1510 | int ret; |
| 1511 | |
| 1512 | /* Allocate result vls array */ |
| 1513 | *vls = zalloc(sizeof(struct variable_list) * max_vls); |
| 1514 | if (*vls == NULL) |
| 1515 | return -ENOMEM; |
| 1516 | |
| 1517 | af.vls = *vls; |
| 1518 | af.nvls = 0; |
| 1519 | |
| 1520 | ret = find_probes(fd, &af.pf); |
| 1521 | if (ret < 0) { |
| 1522 | /* Free vlist for error */ |
| 1523 | while (af.nvls--) { |
| 1524 | if (af.vls[af.nvls].point.symbol) |
| 1525 | free(af.vls[af.nvls].point.symbol); |
| 1526 | if (af.vls[af.nvls].vars) |
| 1527 | strlist__delete(af.vls[af.nvls].vars); |
| 1528 | } |
| 1529 | free(af.vls); |
| 1530 | *vls = NULL; |
| 1531 | return ret; |
| 1532 | } |
| 1533 | |
| 1534 | return (ret < 0) ? ret : af.nvls; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1537 | /* Reverse search */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1538 | int find_perf_probe_point(unsigned long addr, struct perf_probe_point *ppt) |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1539 | { |
| 1540 | Dwarf_Die cudie, spdie, indie; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1541 | Dwarf *dbg = NULL; |
| 1542 | Dwfl *dwfl = NULL; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1543 | Dwarf_Line *line; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1544 | Dwarf_Addr laddr, eaddr, bias = 0; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1545 | const char *tmp; |
| 1546 | int lineno, ret = 0; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1547 | bool found = false; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1548 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1549 | /* Open the live linux kernel */ |
| 1550 | dbg = dwfl_init_live_kernel_dwarf(addr, &dwfl, &bias); |
| 1551 | if (!dbg) { |
| 1552 | pr_warning("No dwarf info found in the vmlinux - " |
| 1553 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
| 1554 | ret = -EINVAL; |
| 1555 | goto end; |
| 1556 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1557 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1558 | /* Adjust address with bias */ |
| 1559 | addr += bias; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1560 | /* Find cu die */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1561 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr - bias, &cudie)) { |
| 1562 | pr_warning("No CU DIE is found at %lx\n", addr); |
Masami Hiramatsu | 75ec5a2 | 2010-04-02 12:50:59 -0400 | [diff] [blame] | 1563 | ret = -EINVAL; |
| 1564 | goto end; |
| 1565 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1566 | |
| 1567 | /* Find a corresponding line */ |
| 1568 | line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr); |
| 1569 | if (line) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1570 | if (dwarf_lineaddr(line, &laddr) == 0 && |
| 1571 | (Dwarf_Addr)addr == laddr && |
| 1572 | dwarf_lineno(line, &lineno) == 0) { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1573 | tmp = dwarf_linesrc(line, NULL, NULL); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1574 | if (tmp) { |
| 1575 | ppt->line = lineno; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1576 | ppt->file = strdup(tmp); |
| 1577 | if (ppt->file == NULL) { |
| 1578 | ret = -ENOMEM; |
| 1579 | goto end; |
| 1580 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1581 | found = true; |
| 1582 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | /* Find a corresponding function */ |
| 1587 | if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) { |
| 1588 | tmp = dwarf_diename(&spdie); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1589 | if (!tmp || dwarf_entrypc(&spdie, &eaddr) != 0) |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1590 | goto end; |
| 1591 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1592 | if (ppt->line) { |
| 1593 | if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr, |
| 1594 | &indie)) { |
| 1595 | /* addr in an inline function */ |
| 1596 | tmp = dwarf_diename(&indie); |
| 1597 | if (!tmp) |
| 1598 | goto end; |
| 1599 | ret = dwarf_decl_line(&indie, &lineno); |
| 1600 | } else { |
| 1601 | if (eaddr == addr) { /* Function entry */ |
| 1602 | lineno = ppt->line; |
| 1603 | ret = 0; |
| 1604 | } else |
| 1605 | ret = dwarf_decl_line(&spdie, &lineno); |
| 1606 | } |
| 1607 | if (ret == 0) { |
| 1608 | /* Make a relative line number */ |
| 1609 | ppt->line -= lineno; |
| 1610 | goto found; |
| 1611 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1612 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1613 | /* We don't have a line number, let's use offset */ |
| 1614 | ppt->offset = addr - (unsigned long)eaddr; |
| 1615 | found: |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1616 | ppt->function = strdup(tmp); |
| 1617 | if (ppt->function == NULL) { |
| 1618 | ret = -ENOMEM; |
| 1619 | goto end; |
| 1620 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1621 | found = true; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | end: |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1625 | if (dwfl) |
| 1626 | dwfl_end(dwfl); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1627 | if (ret >= 0) |
| 1628 | ret = found ? 1 : 0; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1629 | return ret; |
| 1630 | } |
| 1631 | |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1632 | /* Add a line and store the src path */ |
| 1633 | static int line_range_add_line(const char *src, unsigned int lineno, |
| 1634 | struct line_range *lr) |
| 1635 | { |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1636 | /* Copy source path */ |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1637 | if (!lr->path) { |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1638 | lr->path = strdup(src); |
| 1639 | if (lr->path == NULL) |
| 1640 | return -ENOMEM; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1641 | } |
| 1642 | return line_list__add_line(&lr->line_list, lineno); |
| 1643 | } |
| 1644 | |
| 1645 | /* Search function declaration lines */ |
| 1646 | static int line_range_funcdecl_cb(Dwarf_Die *sp_die, void *data) |
| 1647 | { |
| 1648 | struct dwarf_callback_param *param = data; |
| 1649 | struct line_finder *lf = param->data; |
| 1650 | const char *src; |
| 1651 | int lineno; |
| 1652 | |
| 1653 | src = dwarf_decl_file(sp_die); |
| 1654 | if (src && strtailcmp(src, lf->fname) != 0) |
| 1655 | return DWARF_CB_OK; |
| 1656 | |
| 1657 | if (dwarf_decl_line(sp_die, &lineno) != 0 || |
| 1658 | (lf->lno_s > lineno || lf->lno_e < lineno)) |
| 1659 | return DWARF_CB_OK; |
| 1660 | |
| 1661 | param->retval = line_range_add_line(src, lineno, lf->lr); |
Masami Hiramatsu | 5d1ee04 | 2010-04-21 15:56:32 -0400 | [diff] [blame] | 1662 | if (param->retval < 0) |
| 1663 | return DWARF_CB_ABORT; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1664 | return DWARF_CB_OK; |
| 1665 | } |
| 1666 | |
| 1667 | static int find_line_range_func_decl_lines(struct line_finder *lf) |
| 1668 | { |
| 1669 | struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0}; |
| 1670 | dwarf_getfuncs(&lf->cu_die, line_range_funcdecl_cb, ¶m, 0); |
| 1671 | return param.retval; |
| 1672 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1673 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1674 | /* Find line range from its line number */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1675 | 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] | 1676 | { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1677 | Dwarf_Lines *lines; |
| 1678 | Dwarf_Line *line; |
| 1679 | size_t nlines, i; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1680 | Dwarf_Addr addr; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1681 | int lineno, ret = 0; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1682 | const char *src; |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1683 | Dwarf_Die die_mem; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1684 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1685 | line_list__init(&lf->lr->line_list); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1686 | if (dwarf_getsrclines(&lf->cu_die, &lines, &nlines) != 0) { |
| 1687 | pr_warning("No source lines found in this CU.\n"); |
| 1688 | return -ENOENT; |
| 1689 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1690 | |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1691 | /* Search probable lines on lines list */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1692 | for (i = 0; i < nlines; i++) { |
| 1693 | line = dwarf_onesrcline(lines, i); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1694 | if (dwarf_lineno(line, &lineno) != 0 || |
| 1695 | (lf->lno_s > lineno || lf->lno_e < lineno)) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1696 | continue; |
| 1697 | |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1698 | if (sp_die) { |
| 1699 | /* Address filtering 1: does sp_die include addr? */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1700 | if (dwarf_lineaddr(line, &addr) != 0 || |
| 1701 | !dwarf_haspc(sp_die, addr)) |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1702 | continue; |
| 1703 | |
| 1704 | /* Address filtering 2: No child include addr? */ |
Masami Hiramatsu | 95a3e4c | 2010-03-16 18:05:51 -0400 | [diff] [blame] | 1705 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1706 | continue; |
| 1707 | } |
| 1708 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1709 | /* TODO: Get fileno from line, but how? */ |
| 1710 | src = dwarf_linesrc(line, NULL, NULL); |
| 1711 | if (strtailcmp(src, lf->fname) != 0) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1712 | continue; |
| 1713 | |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1714 | ret = line_range_add_line(src, lineno, lf->lr); |
| 1715 | if (ret < 0) |
| 1716 | return ret; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1717 | } |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1718 | |
| 1719 | /* |
| 1720 | * Dwarf lines doesn't include function declarations. We have to |
| 1721 | * check functions list or given function. |
| 1722 | */ |
| 1723 | if (sp_die) { |
| 1724 | src = dwarf_decl_file(sp_die); |
| 1725 | if (src && dwarf_decl_line(sp_die, &lineno) == 0 && |
| 1726 | (lf->lno_s <= lineno && lf->lno_e >= lineno)) |
| 1727 | ret = line_range_add_line(src, lineno, lf->lr); |
| 1728 | } else |
| 1729 | ret = find_line_range_func_decl_lines(lf); |
| 1730 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1731 | /* Update status */ |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1732 | if (ret >= 0) |
| 1733 | if (!list_empty(&lf->lr->line_list)) |
| 1734 | ret = lf->found = 1; |
| 1735 | else |
| 1736 | ret = 0; /* Lines are not found */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1737 | else { |
| 1738 | free(lf->lr->path); |
| 1739 | lf->lr->path = NULL; |
| 1740 | } |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1741 | return ret; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1742 | } |
| 1743 | |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1744 | static int line_range_inline_cb(Dwarf_Die *in_die, void *data) |
| 1745 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1746 | struct dwarf_callback_param *param = data; |
| 1747 | |
| 1748 | param->retval = find_line_range_by_line(in_die, param->data); |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1749 | return DWARF_CB_ABORT; /* No need to find other instances */ |
| 1750 | } |
| 1751 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1752 | /* Search function from function name */ |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1753 | static int line_range_search_cb(Dwarf_Die *sp_die, void *data) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1754 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1755 | struct dwarf_callback_param *param = data; |
| 1756 | struct line_finder *lf = param->data; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1757 | struct line_range *lr = lf->lr; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1758 | |
Arnaldo Carvalho de Melo | 66a301c3 | 2010-10-23 15:12:29 -0200 | [diff] [blame] | 1759 | pr_debug("find (%llx) %s\n", |
| 1760 | (unsigned long long)dwarf_dieoffset(sp_die), |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1761 | dwarf_diename(sp_die)); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1762 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 1763 | die_compare_name(sp_die, lr->function)) { |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1764 | lf->fname = dwarf_decl_file(sp_die); |
| 1765 | dwarf_decl_line(sp_die, &lr->offset); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1766 | pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1767 | lf->lno_s = lr->offset + lr->start; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1768 | if (lf->lno_s < 0) /* Overflow */ |
| 1769 | lf->lno_s = INT_MAX; |
| 1770 | lf->lno_e = lr->offset + lr->end; |
| 1771 | if (lf->lno_e < 0) /* Overflow */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1772 | lf->lno_e = INT_MAX; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1773 | pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1774 | lr->start = lf->lno_s; |
| 1775 | lr->end = lf->lno_e; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1776 | if (dwarf_func_inline(sp_die)) { |
| 1777 | struct dwarf_callback_param _param; |
| 1778 | _param.data = (void *)lf; |
| 1779 | _param.retval = 0; |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1780 | dwarf_func_inline_instances(sp_die, |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1781 | line_range_inline_cb, |
| 1782 | &_param); |
| 1783 | param->retval = _param.retval; |
| 1784 | } else |
| 1785 | param->retval = find_line_range_by_line(sp_die, lf); |
| 1786 | return DWARF_CB_ABORT; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1787 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1788 | return DWARF_CB_OK; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1789 | } |
| 1790 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1791 | static int find_line_range_by_func(struct line_finder *lf) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1792 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1793 | struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0}; |
| 1794 | dwarf_getfuncs(&lf->cu_die, line_range_search_cb, ¶m, 0); |
| 1795 | return param.retval; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | int find_line_range(int fd, struct line_range *lr) |
| 1799 | { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1800 | struct line_finder lf = {.lr = lr, .found = 0}; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1801 | int ret = 0; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1802 | Dwarf_Off off = 0, noff; |
| 1803 | size_t cuhl; |
| 1804 | Dwarf_Die *diep; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1805 | Dwarf *dbg = NULL; |
| 1806 | Dwfl *dwfl; |
| 1807 | Dwarf_Addr bias; /* Currently ignored */ |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 1808 | const char *comp_dir; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1809 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1810 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1811 | if (!dbg) { |
| 1812 | pr_warning("No dwarf info found in the vmlinux - " |
| 1813 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
| 1814 | return -EBADF; |
| 1815 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1816 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1817 | /* Loop on CUs (Compilation Unit) */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1818 | while (!lf.found && ret >= 0) { |
| 1819 | if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1820 | break; |
| 1821 | |
| 1822 | /* Get the DIE(Debugging Information Entry) of this CU */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1823 | diep = dwarf_offdie(dbg, off + cuhl, &lf.cu_die); |
| 1824 | if (!diep) |
| 1825 | continue; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1826 | |
| 1827 | /* Check if target file is included. */ |
| 1828 | if (lr->file) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1829 | lf.fname = cu_find_realpath(&lf.cu_die, lr->file); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1830 | else |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1831 | lf.fname = 0; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1832 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1833 | if (!lr->file || lf.fname) { |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1834 | if (lr->function) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1835 | ret = find_line_range_by_func(&lf); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1836 | else { |
| 1837 | lf.lno_s = lr->start; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1838 | lf.lno_e = lr->end; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1839 | ret = find_line_range_by_line(NULL, &lf); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1840 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1841 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1842 | off = noff; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1843 | } |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 1844 | |
| 1845 | /* Store comp_dir */ |
| 1846 | if (lf.found) { |
| 1847 | comp_dir = cu_get_comp_dir(&lf.cu_die); |
| 1848 | if (comp_dir) { |
| 1849 | lr->comp_dir = strdup(comp_dir); |
| 1850 | if (!lr->comp_dir) |
| 1851 | ret = -ENOMEM; |
| 1852 | } |
| 1853 | } |
| 1854 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1855 | pr_debug("path: %s\n", lr->path); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1856 | dwfl_end(dwfl); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1857 | return (ret < 0) ? ret : lf.found; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1858 | } |
| 1859 | |