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 | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 36 | #include <linux/bitops.h> |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 37 | #include "event.h" |
| 38 | #include "debug.h" |
Masami Hiramatsu | 074fc0e | 2009-10-16 20:08:01 -0400 | [diff] [blame] | 39 | #include "util.h" |
Chase Douglas | 9ed7e1b | 2010-06-14 15:26:30 -0400 | [diff] [blame] | 40 | #include "symbol.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 41 | #include "probe-finder.h" |
| 42 | |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 43 | /* Kprobe tracer basic type is up to u64 */ |
| 44 | #define MAX_BASIC_TYPE_BITS 64 |
| 45 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 46 | /* Line number list operations */ |
| 47 | |
| 48 | /* Add a line to line number list */ |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 49 | static int line_list__add_line(struct list_head *head, int line) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 50 | { |
| 51 | struct line_node *ln; |
| 52 | struct list_head *p; |
| 53 | |
| 54 | /* Reverse search, because new line will be the last one */ |
| 55 | list_for_each_entry_reverse(ln, head, list) { |
| 56 | if (ln->line < line) { |
| 57 | p = &ln->list; |
| 58 | goto found; |
| 59 | } else if (ln->line == line) /* Already exist */ |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 60 | return 1; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 61 | } |
| 62 | /* List is empty, or the smallest entry */ |
| 63 | p = head; |
| 64 | found: |
| 65 | pr_debug("line list: add a line %u\n", line); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 66 | ln = zalloc(sizeof(struct line_node)); |
| 67 | if (ln == NULL) |
| 68 | return -ENOMEM; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 69 | ln->line = line; |
| 70 | INIT_LIST_HEAD(&ln->list); |
| 71 | list_add(&ln->list, p); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 72 | return 0; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* Check if the line in line number list */ |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 76 | static int line_list__has_line(struct list_head *head, int line) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 77 | { |
| 78 | struct line_node *ln; |
| 79 | |
| 80 | /* Reverse search, because new line will be the last one */ |
| 81 | list_for_each_entry(ln, head, list) |
| 82 | if (ln->line == line) |
| 83 | return 1; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /* Init line number list */ |
| 89 | static void line_list__init(struct list_head *head) |
| 90 | { |
| 91 | INIT_LIST_HEAD(head); |
| 92 | } |
| 93 | |
| 94 | /* Free line number list */ |
| 95 | static void line_list__free(struct list_head *head) |
| 96 | { |
| 97 | struct line_node *ln; |
| 98 | while (!list_empty(head)) { |
| 99 | ln = list_first_entry(head, struct line_node, list); |
| 100 | list_del(&ln->list); |
| 101 | free(ln); |
| 102 | } |
| 103 | } |
| 104 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 105 | /* Dwarf FL wrappers */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 106 | static char *debuginfo_path; /* Currently dummy */ |
| 107 | |
| 108 | static const Dwfl_Callbacks offline_callbacks = { |
| 109 | .find_debuginfo = dwfl_standard_find_debuginfo, |
| 110 | .debuginfo_path = &debuginfo_path, |
| 111 | |
| 112 | .section_address = dwfl_offline_section_address, |
| 113 | |
| 114 | /* We use this table for core files too. */ |
| 115 | .find_elf = dwfl_build_id_find_elf, |
| 116 | }; |
| 117 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 118 | /* Get a Dwarf from offline image */ |
| 119 | static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias) |
| 120 | { |
| 121 | Dwfl_Module *mod; |
| 122 | Dwarf *dbg = NULL; |
| 123 | |
| 124 | if (!dwflp) |
| 125 | return NULL; |
| 126 | |
| 127 | *dwflp = dwfl_begin(&offline_callbacks); |
| 128 | if (!*dwflp) |
| 129 | return NULL; |
| 130 | |
| 131 | mod = dwfl_report_offline(*dwflp, "", "", fd); |
| 132 | if (!mod) |
| 133 | goto error; |
| 134 | |
| 135 | dbg = dwfl_module_getdwarf(mod, bias); |
| 136 | if (!dbg) { |
| 137 | error: |
| 138 | dwfl_end(*dwflp); |
| 139 | *dwflp = NULL; |
| 140 | } |
| 141 | return dbg; |
| 142 | } |
| 143 | |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 144 | #if _ELFUTILS_PREREQ(0, 148) |
| 145 | /* This method is buggy if elfutils is older than 0.148 */ |
| 146 | static int __linux_kernel_find_elf(Dwfl_Module *mod, |
| 147 | void **userdata, |
| 148 | const char *module_name, |
| 149 | Dwarf_Addr base, |
| 150 | char **file_name, Elf **elfp) |
| 151 | { |
| 152 | int fd; |
| 153 | const char *path = kernel_get_module_path(module_name); |
| 154 | |
| 155 | pr_debug2("Use file %s for %s\n", path, module_name); |
| 156 | if (path) { |
| 157 | fd = open(path, O_RDONLY); |
| 158 | if (fd >= 0) { |
| 159 | *file_name = strdup(path); |
| 160 | return fd; |
| 161 | } |
| 162 | } |
| 163 | /* If failed, try to call standard method */ |
| 164 | return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base, |
| 165 | file_name, elfp); |
| 166 | } |
| 167 | |
| 168 | static const Dwfl_Callbacks kernel_callbacks = { |
| 169 | .find_debuginfo = dwfl_standard_find_debuginfo, |
| 170 | .debuginfo_path = &debuginfo_path, |
| 171 | |
| 172 | .find_elf = __linux_kernel_find_elf, |
| 173 | .section_address = dwfl_linux_kernel_module_section_address, |
| 174 | }; |
| 175 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 176 | /* Get a Dwarf from live kernel image */ |
| 177 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp, |
| 178 | Dwarf_Addr *bias) |
| 179 | { |
| 180 | Dwarf *dbg; |
| 181 | |
| 182 | if (!dwflp) |
| 183 | return NULL; |
| 184 | |
| 185 | *dwflp = dwfl_begin(&kernel_callbacks); |
| 186 | if (!*dwflp) |
| 187 | return NULL; |
| 188 | |
| 189 | /* Load the kernel dwarves: Don't care the result here */ |
| 190 | dwfl_linux_kernel_report_kernel(*dwflp); |
| 191 | dwfl_linux_kernel_report_modules(*dwflp); |
| 192 | |
| 193 | dbg = dwfl_addrdwarf(*dwflp, addr, bias); |
| 194 | /* Here, check whether we could get a real dwarf */ |
| 195 | if (!dbg) { |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 196 | pr_debug("Failed to find kernel dwarf at %lx\n", |
| 197 | (unsigned long)addr); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 198 | dwfl_end(*dwflp); |
| 199 | *dwflp = NULL; |
| 200 | } |
| 201 | return dbg; |
| 202 | } |
Masami Hiramatsu | 3b4694d | 2010-12-17 22:12:18 +0900 | [diff] [blame] | 203 | #else |
| 204 | /* With older elfutils, this just support kernel module... */ |
| 205 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr __used, Dwfl **dwflp, |
| 206 | Dwarf_Addr *bias) |
| 207 | { |
| 208 | int fd; |
| 209 | const char *path = kernel_get_module_path("kernel"); |
| 210 | |
| 211 | if (!path) { |
| 212 | pr_err("Failed to find vmlinux path\n"); |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | pr_debug2("Use file %s for debuginfo\n", path); |
| 217 | fd = open(path, O_RDONLY); |
| 218 | if (fd < 0) |
| 219 | return NULL; |
| 220 | |
| 221 | return dwfl_init_offline_dwarf(fd, dwflp, bias); |
| 222 | } |
| 223 | #endif |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 224 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 225 | /* |
| 226 | * Probe finder related functions |
| 227 | */ |
| 228 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 229 | static struct probe_trace_arg_ref *alloc_trace_arg_ref(long offs) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 230 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 231 | struct probe_trace_arg_ref *ref; |
| 232 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 233 | if (ref != NULL) |
| 234 | ref->offset = offs; |
| 235 | return ref; |
| 236 | } |
| 237 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 238 | /* |
| 239 | * Convert a location into trace_arg. |
| 240 | * If tvar == NULL, this just checks variable can be converted. |
| 241 | */ |
| 242 | static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, |
| 243 | Dwarf_Op *fb_ops, |
| 244 | struct probe_trace_arg *tvar) |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 245 | { |
| 246 | Dwarf_Attribute attr; |
| 247 | Dwarf_Op *op; |
| 248 | size_t nops; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 249 | unsigned int regn; |
| 250 | Dwarf_Word offs = 0; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 251 | bool ref = false; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 252 | const char *regs; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 253 | int ret; |
| 254 | |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 255 | if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL) |
| 256 | goto static_var; |
| 257 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 258 | /* TODO: handle more than 1 exprs */ |
| 259 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 260 | dwarf_getlocation_addr(&attr, addr, &op, &nops, 1) <= 0 || |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 261 | nops == 0) { |
| 262 | /* TODO: Support const_value */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 263 | return -ENOENT; |
| 264 | } |
| 265 | |
| 266 | if (op->atom == DW_OP_addr) { |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 267 | static_var: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 268 | if (!tvar) |
| 269 | return 0; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 270 | /* Static variables on memory (not stack), make @varname */ |
| 271 | ret = strlen(dwarf_diename(vr_die)); |
| 272 | tvar->value = zalloc(ret + 2); |
| 273 | if (tvar->value == NULL) |
| 274 | return -ENOMEM; |
| 275 | snprintf(tvar->value, ret + 2, "@%s", dwarf_diename(vr_die)); |
| 276 | tvar->ref = alloc_trace_arg_ref((long)offs); |
| 277 | if (tvar->ref == NULL) |
| 278 | return -ENOMEM; |
| 279 | return 0; |
| 280 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 281 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 282 | /* If this is based on frame buffer, set the offset */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 283 | if (op->atom == DW_OP_fbreg) { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 284 | if (fb_ops == NULL) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 285 | return -ENOTSUP; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 286 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 287 | offs = op->number; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 288 | op = &fb_ops[0]; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 289 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 290 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 291 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { |
| 292 | regn = op->atom - DW_OP_breg0; |
| 293 | offs += op->number; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 294 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 295 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { |
| 296 | regn = op->atom - DW_OP_reg0; |
| 297 | } else if (op->atom == DW_OP_bregx) { |
| 298 | regn = op->number; |
| 299 | offs += op->number2; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 300 | ref = true; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 301 | } else if (op->atom == DW_OP_regx) { |
| 302 | regn = op->number; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 303 | } else { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 304 | pr_debug("DW_OP %x is not supported.\n", op->atom); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 305 | return -ENOTSUP; |
| 306 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 307 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 308 | if (!tvar) |
| 309 | return 0; |
| 310 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 311 | regs = get_arch_regstr(regn); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 312 | if (!regs) { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 313 | /* This should be a bug in DWARF or this tool */ |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 314 | pr_warning("Mapping for the register number %u " |
| 315 | "missing on this architecture.\n", regn); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 316 | return -ERANGE; |
| 317 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 318 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 319 | tvar->value = strdup(regs); |
| 320 | if (tvar->value == NULL) |
| 321 | return -ENOMEM; |
| 322 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 323 | if (ref) { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 324 | tvar->ref = alloc_trace_arg_ref((long)offs); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 325 | if (tvar->ref == NULL) |
| 326 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 327 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 328 | return 0; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 331 | #define BYTES_TO_BITS(nb) ((nb) * BITS_PER_LONG / sizeof(long)) |
| 332 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 333 | static int convert_variable_type(Dwarf_Die *vr_die, |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 334 | struct probe_trace_arg *tvar, |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 335 | const char *cast) |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 336 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 337 | struct probe_trace_arg_ref **ref_ptr = &tvar->ref; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 338 | Dwarf_Die type; |
| 339 | char buf[16]; |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 340 | int bsize, boffs, total; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 341 | int ret; |
| 342 | |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 343 | /* TODO: check all types */ |
| 344 | if (cast && strcmp(cast, "string") != 0) { |
| 345 | /* Non string type is OK */ |
| 346 | tvar->type = strdup(cast); |
| 347 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 348 | } |
| 349 | |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 350 | bsize = dwarf_bitsize(vr_die); |
| 351 | if (bsize > 0) { |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 352 | /* This is a bitfield */ |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 353 | boffs = dwarf_bitoffset(vr_die); |
| 354 | total = dwarf_bytesize(vr_die); |
| 355 | if (boffs < 0 || total < 0) |
| 356 | return -ENOENT; |
| 357 | ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs, |
| 358 | BYTES_TO_BITS(total)); |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 359 | goto formatted; |
| 360 | } |
| 361 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 362 | if (die_get_real_type(vr_die, &type) == NULL) { |
| 363 | pr_warning("Failed to get a type information of %s.\n", |
| 364 | dwarf_diename(vr_die)); |
| 365 | return -ENOENT; |
| 366 | } |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 367 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 368 | pr_debug("%s type is %s.\n", |
| 369 | dwarf_diename(vr_die), dwarf_diename(&type)); |
| 370 | |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 371 | if (cast && strcmp(cast, "string") == 0) { /* String type */ |
| 372 | ret = dwarf_tag(&type); |
| 373 | if (ret != DW_TAG_pointer_type && |
| 374 | ret != DW_TAG_array_type) { |
| 375 | pr_warning("Failed to cast into string: " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 376 | "%s(%s) is not a pointer nor array.\n", |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 377 | dwarf_diename(vr_die), dwarf_diename(&type)); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | if (ret == DW_TAG_pointer_type) { |
| 381 | if (die_get_real_type(&type, &type) == NULL) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 382 | pr_warning("Failed to get a type" |
| 383 | " information.\n"); |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 384 | return -ENOENT; |
| 385 | } |
| 386 | while (*ref_ptr) |
| 387 | ref_ptr = &(*ref_ptr)->next; |
| 388 | /* Add new reference with offset +0 */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 389 | *ref_ptr = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 390 | if (*ref_ptr == NULL) { |
| 391 | pr_warning("Out of memory error\n"); |
| 392 | return -ENOMEM; |
| 393 | } |
| 394 | } |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 395 | if (!die_compare_name(&type, "char") && |
| 396 | !die_compare_name(&type, "unsigned char")) { |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 397 | pr_warning("Failed to cast into string: " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 398 | "%s is not (unsigned) char *.\n", |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 399 | dwarf_diename(vr_die)); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | tvar->type = strdup(cast); |
| 403 | return (tvar->type == NULL) ? -ENOMEM : 0; |
| 404 | } |
| 405 | |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 406 | ret = dwarf_bytesize(&type); |
| 407 | if (ret <= 0) |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 408 | /* No size ... try to use default type */ |
| 409 | return 0; |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 410 | ret = BYTES_TO_BITS(ret); |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 411 | |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 412 | /* Check the bitwidth */ |
| 413 | if (ret > MAX_BASIC_TYPE_BITS) { |
| 414 | pr_info("%s exceeds max-bitwidth. Cut down to %d bits.\n", |
| 415 | dwarf_diename(&type), MAX_BASIC_TYPE_BITS); |
| 416 | ret = MAX_BASIC_TYPE_BITS; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 417 | } |
Masami Hiramatsu | 124bb83 | 2011-02-04 21:52:11 +0900 | [diff] [blame] | 418 | ret = snprintf(buf, 16, "%c%d", |
| 419 | die_is_signed_type(&type) ? 's' : 'u', ret); |
| 420 | |
| 421 | formatted: |
| 422 | if (ret < 0 || ret >= 16) { |
| 423 | if (ret >= 16) |
| 424 | ret = -E2BIG; |
| 425 | pr_warning("Failed to convert variable type: %s\n", |
| 426 | strerror(-ret)); |
| 427 | return ret; |
| 428 | } |
| 429 | tvar->type = strdup(buf); |
| 430 | if (tvar->type == NULL) |
| 431 | return -ENOMEM; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 432 | return 0; |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 435 | static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 436 | struct perf_probe_arg_field *field, |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 437 | struct probe_trace_arg_ref **ref_ptr, |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 438 | Dwarf_Die *die_mem) |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 439 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 440 | struct probe_trace_arg_ref *ref = *ref_ptr; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 441 | Dwarf_Die type; |
| 442 | Dwarf_Word offs; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 443 | int ret, tag; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 444 | |
| 445 | pr_debug("converting %s in %s\n", field->name, varname); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 446 | if (die_get_real_type(vr_die, &type) == NULL) { |
| 447 | pr_warning("Failed to get the type of %s.\n", varname); |
| 448 | return -ENOENT; |
| 449 | } |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 450 | pr_debug2("Var real type: (%x)\n", (unsigned)dwarf_dieoffset(&type)); |
| 451 | tag = dwarf_tag(&type); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 452 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 453 | if (field->name[0] == '[' && |
| 454 | (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)) { |
| 455 | if (field->next) |
| 456 | /* Save original type for next field */ |
| 457 | memcpy(die_mem, &type, sizeof(*die_mem)); |
| 458 | /* Get the type of this array */ |
| 459 | if (die_get_real_type(&type, &type) == NULL) { |
| 460 | pr_warning("Failed to get the type of %s.\n", varname); |
| 461 | return -ENOENT; |
| 462 | } |
| 463 | pr_debug2("Array real type: (%x)\n", |
| 464 | (unsigned)dwarf_dieoffset(&type)); |
| 465 | if (tag == DW_TAG_pointer_type) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 466 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 467 | if (ref == NULL) |
| 468 | return -ENOMEM; |
| 469 | if (*ref_ptr) |
| 470 | (*ref_ptr)->next = ref; |
| 471 | else |
| 472 | *ref_ptr = ref; |
| 473 | } |
Masami Hiramatsu | bcfc082 | 2011-06-27 16:27:21 +0900 | [diff] [blame] | 474 | ref->offset += dwarf_bytesize(&type) * field->index; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 475 | if (!field->next) |
| 476 | /* Save vr_die for converting types */ |
| 477 | memcpy(die_mem, vr_die, sizeof(*die_mem)); |
| 478 | goto next; |
| 479 | } else if (tag == DW_TAG_pointer_type) { |
| 480 | /* Check the pointer and dereference */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 481 | if (!field->ref) { |
| 482 | pr_err("Semantic error: %s must be referred by '->'\n", |
| 483 | field->name); |
| 484 | return -EINVAL; |
| 485 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 486 | /* Get the type pointed by this pointer */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 487 | if (die_get_real_type(&type, &type) == NULL) { |
| 488 | pr_warning("Failed to get the type of %s.\n", varname); |
| 489 | return -ENOENT; |
| 490 | } |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 491 | /* Verify it is a data structure */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 492 | if (dwarf_tag(&type) != DW_TAG_structure_type) { |
| 493 | pr_warning("%s is not a data structure.\n", varname); |
| 494 | return -EINVAL; |
| 495 | } |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 496 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 497 | ref = zalloc(sizeof(struct probe_trace_arg_ref)); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 498 | if (ref == NULL) |
| 499 | return -ENOMEM; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 500 | if (*ref_ptr) |
| 501 | (*ref_ptr)->next = ref; |
| 502 | else |
| 503 | *ref_ptr = ref; |
| 504 | } else { |
Masami Hiramatsu | 12e5a7a | 2010-04-02 12:50:53 -0400 | [diff] [blame] | 505 | /* Verify it is a data structure */ |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 506 | if (tag != DW_TAG_structure_type) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 507 | pr_warning("%s is not a data structure.\n", varname); |
| 508 | return -EINVAL; |
| 509 | } |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 510 | if (field->name[0] == '[') { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 511 | pr_err("Semantic error: %s is not a pointor" |
| 512 | " nor array.\n", varname); |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 513 | return -EINVAL; |
| 514 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 515 | if (field->ref) { |
| 516 | pr_err("Semantic error: %s must be referred by '.'\n", |
| 517 | field->name); |
| 518 | return -EINVAL; |
| 519 | } |
| 520 | if (!ref) { |
| 521 | pr_warning("Structure on a register is not " |
| 522 | "supported yet.\n"); |
| 523 | return -ENOTSUP; |
| 524 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 527 | if (die_find_member(&type, field->name, die_mem) == NULL) { |
| 528 | pr_warning("%s(tyep:%s) has no member %s.\n", varname, |
| 529 | dwarf_diename(&type), field->name); |
| 530 | return -EINVAL; |
| 531 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 532 | |
| 533 | /* Get the offset of the field */ |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 534 | ret = die_get_data_member_location(die_mem, &offs); |
| 535 | if (ret < 0) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 536 | pr_warning("Failed to get the offset of %s.\n", field->name); |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 537 | return ret; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 538 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 539 | ref->offset += (long)offs; |
| 540 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 541 | next: |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 542 | /* Converting next field */ |
| 543 | if (field->next) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 544 | return convert_variable_fields(die_mem, field->name, |
Masami Hiramatsu | de1439d | 2010-04-14 17:44:00 -0300 | [diff] [blame] | 545 | field->next, &ref, die_mem); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 546 | else |
| 547 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 550 | /* Show a variables in kprobe event format */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 551 | static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 552 | { |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 553 | Dwarf_Die die_mem; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 554 | int ret; |
| 555 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 556 | pr_debug("Converting variable %s into trace event.\n", |
| 557 | dwarf_diename(vr_die)); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 558 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 559 | ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops, |
| 560 | pf->tvar); |
| 561 | if (ret == -ENOENT) |
| 562 | pr_err("Failed to find the location of %s at this address.\n" |
| 563 | " Perhaps, it has been optimized out.\n", pf->pvar->var); |
| 564 | else if (ret == -ENOTSUP) |
| 565 | pr_err("Sorry, we don't support this variable location yet.\n"); |
| 566 | else if (pf->pvar->field) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 567 | ret = convert_variable_fields(vr_die, pf->pvar->var, |
| 568 | pf->pvar->field, &pf->tvar->ref, |
| 569 | &die_mem); |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 570 | vr_die = &die_mem; |
| 571 | } |
Masami Hiramatsu | 73317b9 | 2010-05-19 15:57:35 -0400 | [diff] [blame] | 572 | if (ret == 0) |
| 573 | ret = convert_variable_type(vr_die, pf->tvar, pf->pvar->type); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 574 | /* *expr will be cached in libdw. Don't free it. */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 575 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 576 | } |
| 577 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 578 | /* Find a variable in a subprogram die */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 579 | static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 580 | { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 581 | Dwarf_Die vr_die, *scopes; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 582 | char buf[32], *ptr; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 583 | int ret, nscopes; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 584 | |
Masami Hiramatsu | 367e94c | 2010-08-27 20:38:59 +0900 | [diff] [blame] | 585 | if (!is_c_varname(pf->pvar->var)) { |
| 586 | /* Copy raw parameters */ |
| 587 | pf->tvar->value = strdup(pf->pvar->var); |
| 588 | if (pf->tvar->value == NULL) |
| 589 | return -ENOMEM; |
| 590 | if (pf->pvar->type) { |
| 591 | pf->tvar->type = strdup(pf->pvar->type); |
| 592 | if (pf->tvar->type == NULL) |
| 593 | return -ENOMEM; |
| 594 | } |
| 595 | if (pf->pvar->name) { |
| 596 | pf->tvar->name = strdup(pf->pvar->name); |
| 597 | if (pf->tvar->name == NULL) |
| 598 | return -ENOMEM; |
| 599 | } else |
| 600 | pf->tvar->name = NULL; |
| 601 | return 0; |
| 602 | } |
| 603 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 604 | if (pf->pvar->name) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 605 | pf->tvar->name = strdup(pf->pvar->name); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 606 | else { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 607 | ret = synthesize_perf_probe_arg(pf->pvar, buf, 32); |
| 608 | if (ret < 0) |
| 609 | return ret; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 610 | ptr = strchr(buf, ':'); /* Change type separator to _ */ |
| 611 | if (ptr) |
| 612 | *ptr = '_'; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 613 | pf->tvar->name = strdup(buf); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 614 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 615 | if (pf->tvar->name == NULL) |
| 616 | return -ENOMEM; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 617 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 618 | pr_debug("Searching '%s' variable in context.\n", |
| 619 | pf->pvar->var); |
| 620 | /* Search child die for local variables and parameters. */ |
Masami Hiramatsu | 378eeaa | 2010-10-21 19:13:09 +0900 | [diff] [blame] | 621 | 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] | 622 | ret = convert_variable(&vr_die, pf); |
| 623 | else { |
| 624 | /* Search upper class */ |
| 625 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 626 | while (nscopes-- > 1) { |
| 627 | pr_debug("Searching variables in %s\n", |
| 628 | dwarf_diename(&scopes[nscopes])); |
| 629 | /* We should check this scope, so give dummy address */ |
| 630 | if (die_find_variable_at(&scopes[nscopes], |
| 631 | pf->pvar->var, 0, |
| 632 | &vr_die)) { |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 633 | ret = convert_variable(&vr_die, pf); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 634 | goto found; |
| 635 | } |
| 636 | } |
| 637 | if (scopes) |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 638 | free(scopes); |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 639 | ret = -ENOENT; |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 640 | } |
Masami Hiramatsu | 632941c | 2010-10-21 19:13:16 +0900 | [diff] [blame] | 641 | found: |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 642 | if (ret < 0) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 643 | pr_warning("Failed to find '%s' in this function.\n", |
| 644 | pf->pvar->var); |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 645 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 646 | } |
| 647 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 648 | /* Convert subprogram DIE to trace point */ |
| 649 | static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr, |
| 650 | bool retprobe, struct probe_trace_point *tp) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 651 | { |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 652 | Dwarf_Addr eaddr; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 653 | const char *name; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 654 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 655 | /* Copy the name of probe point */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 656 | name = dwarf_diename(sp_die); |
| 657 | if (name) { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 658 | if (dwarf_entrypc(sp_die, &eaddr) != 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 659 | pr_warning("Failed to get entry address of %s\n", |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 660 | dwarf_diename(sp_die)); |
| 661 | return -ENOENT; |
| 662 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 663 | tp->symbol = strdup(name); |
| 664 | if (tp->symbol == NULL) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 665 | return -ENOMEM; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 666 | tp->offset = (unsigned long)(paddr - eaddr); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 667 | } else |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 668 | /* This function has no name. */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 669 | tp->offset = (unsigned long)paddr; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 670 | |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 671 | /* Return probe must be on the head of a subprogram */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 672 | if (retprobe) { |
| 673 | if (eaddr != paddr) { |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 674 | pr_warning("Return probe must be on the head of" |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 675 | " a real function.\n"); |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 676 | return -EINVAL; |
| 677 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 678 | tp->retprobe = true; |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 679 | } |
| 680 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | /* Call probe_finder callback with real subprogram DIE */ |
| 685 | static int call_probe_finder(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 686 | { |
| 687 | Dwarf_Die die_mem; |
| 688 | Dwarf_Attribute fb_attr; |
| 689 | size_t nops; |
| 690 | int ret; |
| 691 | |
| 692 | /* If no real subprogram, find a real one */ |
| 693 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { |
Masami Hiramatsu | e0d153c | 2011-06-27 16:27:27 +0900 | [diff] [blame^] | 694 | sp_die = die_find_realfunc(&pf->cu_die, pf->addr, &die_mem); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 695 | if (!sp_die) { |
| 696 | pr_warning("Failed to find probe point in any " |
| 697 | "functions.\n"); |
| 698 | return -ENOENT; |
| 699 | } |
| 700 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 701 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 702 | /* Get the frame base attribute/ops */ |
| 703 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); |
Masami Hiramatsu | d0cb4260f | 2010-03-15 13:02:35 -0400 | [diff] [blame] | 704 | 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] | 705 | if (ret <= 0 || nops == 0) { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 706 | pf->fb_ops = NULL; |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 707 | #if _ELFUTILS_PREREQ(0, 142) |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 708 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
| 709 | pf->cfi != NULL) { |
| 710 | Dwarf_Frame *frame; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 711 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || |
| 712 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 713 | pr_warning("Failed to get call frame on 0x%jx\n", |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 714 | (uintmax_t)pf->addr); |
| 715 | return -ENOENT; |
| 716 | } |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 717 | #endif |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 718 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 719 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 720 | /* Call finder's callback handler */ |
| 721 | ret = pf->callback(sp_die, pf); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 722 | |
| 723 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ |
| 724 | pf->fb_ops = NULL; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 725 | |
| 726 | return ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 727 | } |
| 728 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 729 | static int probe_point_line_walker(const char *fname, int lineno, |
| 730 | Dwarf_Addr addr, void *data) |
| 731 | { |
| 732 | struct probe_finder *pf = data; |
| 733 | int ret; |
| 734 | |
| 735 | if (lineno != pf->lno || strtailcmp(fname, pf->fname) != 0) |
| 736 | return 0; |
| 737 | |
| 738 | pf->addr = addr; |
| 739 | ret = call_probe_finder(NULL, pf); |
| 740 | |
| 741 | /* Continue if no error, because the line will be in inline function */ |
Arnaldo Carvalho de Melo | fbee632 | 2011-02-21 13:23:57 -0300 | [diff] [blame] | 742 | return ret < 0 ? ret : 0; |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 743 | } |
| 744 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 745 | /* Find probe point from its line number */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 746 | static int find_probe_point_by_line(struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 747 | { |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 748 | return die_walk_lines(&pf->cu_die, probe_point_line_walker, pf); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 749 | } |
| 750 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 751 | /* Find lines which match lazy pattern */ |
| 752 | static int find_lazy_match_lines(struct list_head *head, |
| 753 | const char *fname, const char *pat) |
| 754 | { |
Franck Bui-Huu | f50c216 | 2011-01-13 11:18:30 +0100 | [diff] [blame] | 755 | FILE *fp; |
| 756 | char *line = NULL; |
| 757 | size_t line_len; |
| 758 | ssize_t len; |
| 759 | int count = 0, linenum = 1; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 760 | |
Franck Bui-Huu | f50c216 | 2011-01-13 11:18:30 +0100 | [diff] [blame] | 761 | fp = fopen(fname, "r"); |
| 762 | if (!fp) { |
| 763 | pr_warning("Failed to open %s: %s\n", fname, strerror(errno)); |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 764 | return -errno; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Franck Bui-Huu | f50c216 | 2011-01-13 11:18:30 +0100 | [diff] [blame] | 767 | while ((len = getline(&line, &line_len, fp)) > 0) { |
| 768 | |
| 769 | if (line[len - 1] == '\n') |
| 770 | line[len - 1] = '\0'; |
| 771 | |
| 772 | if (strlazymatch(line, pat)) { |
| 773 | line_list__add_line(head, linenum); |
| 774 | count++; |
| 775 | } |
| 776 | linenum++; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 777 | } |
Arnaldo Carvalho de Melo | b448c4b | 2010-05-18 23:04:28 -0300 | [diff] [blame] | 778 | |
Franck Bui-Huu | f50c216 | 2011-01-13 11:18:30 +0100 | [diff] [blame] | 779 | if (ferror(fp)) |
| 780 | count = -errno; |
| 781 | free(line); |
| 782 | fclose(fp); |
| 783 | |
| 784 | if (count == 0) |
| 785 | pr_debug("No matched lines found in %s.\n", fname); |
| 786 | return count; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 787 | } |
| 788 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 789 | static int probe_point_lazy_walker(const char *fname, int lineno, |
| 790 | Dwarf_Addr addr, void *data) |
| 791 | { |
| 792 | struct probe_finder *pf = data; |
| 793 | int ret; |
| 794 | |
| 795 | if (!line_list__has_line(&pf->lcache, lineno) || |
| 796 | strtailcmp(fname, pf->fname) != 0) |
| 797 | return 0; |
| 798 | |
| 799 | pr_debug("Probe line found: line:%d addr:0x%llx\n", |
| 800 | lineno, (unsigned long long)addr); |
| 801 | pf->addr = addr; |
| 802 | ret = call_probe_finder(NULL, pf); |
| 803 | |
| 804 | /* |
| 805 | * Continue if no error, because the lazy pattern will match |
| 806 | * to other lines |
| 807 | */ |
Ingo Molnar | 5e814dd | 2011-03-15 20:51:09 +0100 | [diff] [blame] | 808 | return ret < 0 ? ret : 0; |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 809 | } |
| 810 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 811 | /* Find probe points from lazy pattern */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 812 | 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] | 813 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 814 | int ret = 0; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 815 | |
| 816 | if (list_empty(&pf->lcache)) { |
| 817 | /* Matching lazy line pattern */ |
| 818 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 819 | pf->pev->point.lazy_line); |
Franck Bui-Huu | f50c216 | 2011-01-13 11:18:30 +0100 | [diff] [blame] | 820 | if (ret <= 0) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 821 | return ret; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 822 | } |
| 823 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 824 | return die_walk_lines(sp_die, probe_point_lazy_walker, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 825 | } |
| 826 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 827 | /* Callback parameter with return value */ |
| 828 | struct dwarf_callback_param { |
| 829 | void *data; |
| 830 | int retval; |
| 831 | }; |
| 832 | |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 833 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 834 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 835 | struct dwarf_callback_param *param = data; |
| 836 | struct probe_finder *pf = param->data; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 837 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 838 | Dwarf_Addr addr; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 839 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 840 | if (pp->lazy_line) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 841 | param->retval = find_probe_point_lazy(in_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 842 | else { |
| 843 | /* Get probe address */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 844 | if (dwarf_entrypc(in_die, &addr) != 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 845 | pr_warning("Failed to get entry address of %s.\n", |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 846 | dwarf_diename(in_die)); |
| 847 | param->retval = -ENOENT; |
| 848 | return DWARF_CB_ABORT; |
| 849 | } |
| 850 | pf->addr = addr; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 851 | pf->addr += pp->offset; |
| 852 | pr_debug("found inline addr: 0x%jx\n", |
| 853 | (uintmax_t)pf->addr); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 854 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 855 | param->retval = call_probe_finder(in_die, pf); |
Masami Hiramatsu | 5d1ee04 | 2010-04-21 15:56:32 -0400 | [diff] [blame] | 856 | if (param->retval < 0) |
| 857 | return DWARF_CB_ABORT; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 858 | } |
| 859 | |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 860 | return DWARF_CB_OK; |
| 861 | } |
| 862 | |
| 863 | /* Search function from function name */ |
| 864 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) |
| 865 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 866 | struct dwarf_callback_param *param = data; |
| 867 | struct probe_finder *pf = param->data; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 868 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 869 | |
| 870 | /* Check tag and diename */ |
| 871 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 872 | !die_compare_name(sp_die, pp->function)) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 873 | return DWARF_CB_OK; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 874 | |
Masami Hiramatsu | 7d21635 | 2011-03-30 18:25:41 +0900 | [diff] [blame] | 875 | /* Check declared file */ |
| 876 | if (pp->file && strtailcmp(pp->file, dwarf_decl_file(sp_die))) |
| 877 | return DWARF_CB_OK; |
| 878 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 879 | pf->fname = dwarf_decl_file(sp_die); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 880 | if (pp->line) { /* Function relative line */ |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 881 | dwarf_decl_line(sp_die, &pf->lno); |
| 882 | pf->lno += pp->line; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 883 | param->retval = find_probe_point_by_line(pf); |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 884 | } else if (!dwarf_func_inline(sp_die)) { |
| 885 | /* Real function */ |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 886 | if (pp->lazy_line) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 887 | param->retval = find_probe_point_lazy(sp_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 888 | else { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 889 | if (dwarf_entrypc(sp_die, &pf->addr) != 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 890 | pr_warning("Failed to get entry address of " |
| 891 | "%s.\n", dwarf_diename(sp_die)); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 892 | param->retval = -ENOENT; |
| 893 | return DWARF_CB_ABORT; |
| 894 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 895 | pf->addr += pp->offset; |
| 896 | /* TODO: Check the address in this function */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 897 | param->retval = call_probe_finder(sp_die, pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 898 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 899 | } else { |
| 900 | struct dwarf_callback_param _param = {.data = (void *)pf, |
| 901 | .retval = 0}; |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 902 | /* Inlined function: search instances */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 903 | dwarf_func_inline_instances(sp_die, probe_point_inline_cb, |
| 904 | &_param); |
| 905 | param->retval = _param.retval; |
| 906 | } |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 907 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 908 | return DWARF_CB_ABORT; /* Exit; no same symbol in this CU. */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 909 | } |
| 910 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 911 | static int find_probe_point_by_func(struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 912 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 913 | struct dwarf_callback_param _param = {.data = (void *)pf, |
| 914 | .retval = 0}; |
| 915 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0); |
| 916 | return _param.retval; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 917 | } |
| 918 | |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 919 | struct pubname_callback_param { |
| 920 | char *function; |
| 921 | char *file; |
| 922 | Dwarf_Die *cu_die; |
| 923 | Dwarf_Die *sp_die; |
| 924 | int found; |
| 925 | }; |
| 926 | |
| 927 | static int pubname_search_cb(Dwarf *dbg, Dwarf_Global *gl, void *data) |
| 928 | { |
| 929 | struct pubname_callback_param *param = data; |
| 930 | |
| 931 | if (dwarf_offdie(dbg, gl->die_offset, param->sp_die)) { |
| 932 | if (dwarf_tag(param->sp_die) != DW_TAG_subprogram) |
| 933 | return DWARF_CB_OK; |
| 934 | |
| 935 | if (die_compare_name(param->sp_die, param->function)) { |
| 936 | if (!dwarf_offdie(dbg, gl->cu_offset, param->cu_die)) |
| 937 | return DWARF_CB_OK; |
| 938 | |
| 939 | if (param->file && |
| 940 | strtailcmp(param->file, dwarf_decl_file(param->sp_die))) |
| 941 | return DWARF_CB_OK; |
| 942 | |
| 943 | param->found = 1; |
| 944 | return DWARF_CB_ABORT; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | return DWARF_CB_OK; |
| 949 | } |
| 950 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 951 | /* Find probe points from debuginfo */ |
| 952 | static int find_probes(int fd, struct probe_finder *pf) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 953 | { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 954 | struct perf_probe_point *pp = &pf->pev->point; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 955 | Dwarf_Off off, noff; |
| 956 | size_t cuhl; |
| 957 | Dwarf_Die *diep; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 958 | Dwarf *dbg = NULL; |
| 959 | Dwfl *dwfl; |
| 960 | Dwarf_Addr bias; /* Currently ignored */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 961 | int ret = 0; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 962 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 963 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 964 | if (!dbg) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 965 | pr_warning("No debug information found in the vmlinux - " |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 966 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
Masami Hiramatsu | f0c4801 | 2011-03-30 18:25:47 +0900 | [diff] [blame] | 967 | close(fd); /* Without dwfl_end(), fd isn't closed. */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 968 | return -EBADF; |
| 969 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 970 | |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 971 | #if _ELFUTILS_PREREQ(0, 142) |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 972 | /* Get the call frame information from this dwarf */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 973 | pf->cfi = dwarf_getcfi(dbg); |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 974 | #endif |
Masami Hiramatsu | a34a985 | 2010-04-12 13:17:29 -0400 | [diff] [blame] | 975 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 976 | off = 0; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 977 | line_list__init(&pf->lcache); |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 978 | |
| 979 | /* Fastpath: lookup by function name from .debug_pubnames section */ |
| 980 | if (pp->function) { |
| 981 | struct pubname_callback_param pubname_param = { |
| 982 | .function = pp->function, |
| 983 | .file = pp->file, |
| 984 | .cu_die = &pf->cu_die, |
| 985 | .sp_die = &pf->sp_die, |
Lin Ming | 2b348a7 | 2011-04-29 08:41:57 +0000 | [diff] [blame] | 986 | .found = 0, |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 987 | }; |
| 988 | struct dwarf_callback_param probe_param = { |
| 989 | .data = pf, |
| 990 | }; |
| 991 | |
| 992 | dwarf_getpubnames(dbg, pubname_search_cb, &pubname_param, 0); |
| 993 | if (pubname_param.found) { |
| 994 | ret = probe_point_search_cb(&pf->sp_die, &probe_param); |
| 995 | if (ret) |
| 996 | goto found; |
| 997 | } |
| 998 | } |
| 999 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1000 | /* Loop on CUs (Compilation Unit) */ |
Arnaldo Carvalho de Melo | 8635bf6 | 2011-02-22 06:56:18 -0300 | [diff] [blame] | 1001 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL)) { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1002 | /* Get the DIE(Debugging Information Entry) of this CU */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1003 | diep = dwarf_offdie(dbg, off + cuhl, &pf->cu_die); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1004 | if (!diep) |
| 1005 | continue; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1006 | |
| 1007 | /* Check if target file is included. */ |
| 1008 | if (pp->file) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1009 | pf->fname = cu_find_realpath(&pf->cu_die, pp->file); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1010 | else |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1011 | pf->fname = NULL; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1012 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1013 | if (!pp->file || pf->fname) { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1014 | if (pp->function) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1015 | ret = find_probe_point_by_func(pf); |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1016 | else if (pp->lazy_line) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1017 | ret = find_probe_point_lazy(NULL, pf); |
Masami Hiramatsu | b0ef073 | 2009-10-27 16:43:19 -0400 | [diff] [blame] | 1018 | else { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1019 | pf->lno = pp->line; |
| 1020 | ret = find_probe_point_by_line(pf); |
Masami Hiramatsu | b0ef073 | 2009-10-27 16:43:19 -0400 | [diff] [blame] | 1021 | } |
Arnaldo Carvalho de Melo | 8635bf6 | 2011-02-22 06:56:18 -0300 | [diff] [blame] | 1022 | if (ret < 0) |
Arnaldo Carvalho de Melo | fbee632 | 2011-02-21 13:23:57 -0300 | [diff] [blame] | 1023 | break; |
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 | off = noff; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1026 | } |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 1027 | |
| 1028 | found: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1029 | line_list__free(&pf->lcache); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1030 | if (dwfl) |
| 1031 | dwfl_end(dwfl); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1032 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1033 | return ret; |
| 1034 | } |
| 1035 | |
| 1036 | /* Add a found probe point into trace event list */ |
| 1037 | static int add_probe_trace_event(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 1038 | { |
| 1039 | struct trace_event_finder *tf = |
| 1040 | container_of(pf, struct trace_event_finder, pf); |
| 1041 | struct probe_trace_event *tev; |
| 1042 | int ret, i; |
| 1043 | |
| 1044 | /* Check number of tevs */ |
| 1045 | if (tf->ntevs == tf->max_tevs) { |
| 1046 | pr_warning("Too many( > %d) probe point found.\n", |
| 1047 | tf->max_tevs); |
| 1048 | return -ERANGE; |
| 1049 | } |
| 1050 | tev = &tf->tevs[tf->ntevs++]; |
| 1051 | |
| 1052 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, |
| 1053 | &tev->point); |
| 1054 | if (ret < 0) |
| 1055 | return ret; |
| 1056 | |
| 1057 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, |
| 1058 | tev->point.offset); |
| 1059 | |
| 1060 | /* Find each argument */ |
| 1061 | tev->nargs = pf->pev->nargs; |
| 1062 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
| 1063 | if (tev->args == NULL) |
| 1064 | return -ENOMEM; |
| 1065 | for (i = 0; i < pf->pev->nargs; i++) { |
| 1066 | pf->pvar = &pf->pev->args[i]; |
| 1067 | pf->tvar = &tev->args[i]; |
| 1068 | ret = find_variable(sp_die, pf); |
| 1069 | if (ret != 0) |
| 1070 | return ret; |
| 1071 | } |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
| 1077 | int find_probe_trace_events(int fd, struct perf_probe_event *pev, |
| 1078 | struct probe_trace_event **tevs, int max_tevs) |
| 1079 | { |
| 1080 | struct trace_event_finder tf = { |
| 1081 | .pf = {.pev = pev, .callback = add_probe_trace_event}, |
| 1082 | .max_tevs = max_tevs}; |
| 1083 | int ret; |
| 1084 | |
| 1085 | /* Allocate result tevs array */ |
| 1086 | *tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs); |
| 1087 | if (*tevs == NULL) |
| 1088 | return -ENOMEM; |
| 1089 | |
| 1090 | tf.tevs = *tevs; |
| 1091 | tf.ntevs = 0; |
| 1092 | |
| 1093 | ret = find_probes(fd, &tf.pf); |
| 1094 | if (ret < 0) { |
| 1095 | free(*tevs); |
| 1096 | *tevs = NULL; |
| 1097 | return ret; |
| 1098 | } |
| 1099 | |
| 1100 | return (ret < 0) ? ret : tf.ntevs; |
| 1101 | } |
| 1102 | |
| 1103 | #define MAX_VAR_LEN 64 |
| 1104 | |
| 1105 | /* Collect available variables in this scope */ |
| 1106 | static int collect_variables_cb(Dwarf_Die *die_mem, void *data) |
| 1107 | { |
| 1108 | struct available_var_finder *af = data; |
| 1109 | struct variable_list *vl; |
| 1110 | char buf[MAX_VAR_LEN]; |
| 1111 | int tag, ret; |
| 1112 | |
| 1113 | vl = &af->vls[af->nvls - 1]; |
| 1114 | |
| 1115 | tag = dwarf_tag(die_mem); |
| 1116 | if (tag == DW_TAG_formal_parameter || |
| 1117 | tag == DW_TAG_variable) { |
| 1118 | ret = convert_variable_location(die_mem, af->pf.addr, |
| 1119 | af->pf.fb_ops, NULL); |
| 1120 | if (ret == 0) { |
| 1121 | ret = die_get_varname(die_mem, buf, MAX_VAR_LEN); |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1122 | pr_debug2("Add new var: %s\n", buf); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1123 | if (ret > 0) |
| 1124 | strlist__add(vl->vars, buf); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1128 | if (af->child && dwarf_haspc(die_mem, af->pf.addr)) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1129 | return DIE_FIND_CB_CONTINUE; |
| 1130 | else |
| 1131 | return DIE_FIND_CB_SIBLING; |
| 1132 | } |
| 1133 | |
| 1134 | /* Add a found vars into available variables list */ |
| 1135 | static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 1136 | { |
| 1137 | struct available_var_finder *af = |
| 1138 | container_of(pf, struct available_var_finder, pf); |
| 1139 | struct variable_list *vl; |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1140 | Dwarf_Die die_mem, *scopes = NULL; |
| 1141 | int ret, nscopes; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1142 | |
| 1143 | /* Check number of tevs */ |
| 1144 | if (af->nvls == af->max_vls) { |
| 1145 | pr_warning("Too many( > %d) probe point found.\n", af->max_vls); |
| 1146 | return -ERANGE; |
| 1147 | } |
| 1148 | vl = &af->vls[af->nvls++]; |
| 1149 | |
| 1150 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, |
| 1151 | &vl->point); |
| 1152 | if (ret < 0) |
| 1153 | return ret; |
| 1154 | |
| 1155 | pr_debug("Probe point found: %s+%lu\n", vl->point.symbol, |
| 1156 | vl->point.offset); |
| 1157 | |
| 1158 | /* Find local variables */ |
| 1159 | vl->vars = strlist__new(true, NULL); |
| 1160 | if (vl->vars == NULL) |
| 1161 | return -ENOMEM; |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1162 | af->child = true; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1163 | die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem); |
| 1164 | |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1165 | /* Find external variables */ |
| 1166 | if (!af->externs) |
| 1167 | goto out; |
| 1168 | /* Don't need to search child DIE for externs. */ |
| 1169 | af->child = false; |
| 1170 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
| 1171 | while (nscopes-- > 1) |
| 1172 | die_find_child(&scopes[nscopes], collect_variables_cb, |
| 1173 | (void *)af, &die_mem); |
| 1174 | if (scopes) |
| 1175 | free(scopes); |
| 1176 | |
| 1177 | out: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1178 | if (strlist__empty(vl->vars)) { |
| 1179 | strlist__delete(vl->vars); |
| 1180 | vl->vars = NULL; |
| 1181 | } |
| 1182 | |
| 1183 | return ret; |
| 1184 | } |
| 1185 | |
| 1186 | /* Find available variables at given probe point */ |
| 1187 | int find_available_vars_at(int fd, struct perf_probe_event *pev, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1188 | struct variable_list **vls, int max_vls, |
| 1189 | bool externs) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1190 | { |
| 1191 | struct available_var_finder af = { |
| 1192 | .pf = {.pev = pev, .callback = add_available_vars}, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 1193 | .max_vls = max_vls, .externs = externs}; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 1194 | int ret; |
| 1195 | |
| 1196 | /* Allocate result vls array */ |
| 1197 | *vls = zalloc(sizeof(struct variable_list) * max_vls); |
| 1198 | if (*vls == NULL) |
| 1199 | return -ENOMEM; |
| 1200 | |
| 1201 | af.vls = *vls; |
| 1202 | af.nvls = 0; |
| 1203 | |
| 1204 | ret = find_probes(fd, &af.pf); |
| 1205 | if (ret < 0) { |
| 1206 | /* Free vlist for error */ |
| 1207 | while (af.nvls--) { |
| 1208 | if (af.vls[af.nvls].point.symbol) |
| 1209 | free(af.vls[af.nvls].point.symbol); |
| 1210 | if (af.vls[af.nvls].vars) |
| 1211 | strlist__delete(af.vls[af.nvls].vars); |
| 1212 | } |
| 1213 | free(af.vls); |
| 1214 | *vls = NULL; |
| 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | return (ret < 0) ? ret : af.nvls; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1219 | } |
| 1220 | |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1221 | /* Reverse search */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1222 | 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] | 1223 | { |
| 1224 | Dwarf_Die cudie, spdie, indie; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1225 | Dwarf *dbg = NULL; |
| 1226 | Dwfl *dwfl = NULL; |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1227 | Dwarf_Addr _addr, baseaddr, bias = 0; |
| 1228 | const char *fname = NULL, *func = NULL, *tmp; |
| 1229 | int baseline = 0, lineno = 0, ret = 0; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1230 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1231 | /* Open the live linux kernel */ |
| 1232 | dbg = dwfl_init_live_kernel_dwarf(addr, &dwfl, &bias); |
| 1233 | if (!dbg) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1234 | pr_warning("No debug information found in the vmlinux - " |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1235 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
| 1236 | ret = -EINVAL; |
| 1237 | goto end; |
| 1238 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1239 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1240 | /* Adjust address with bias */ |
| 1241 | addr += bias; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1242 | /* Find cu die */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1243 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr - bias, &cudie)) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1244 | pr_warning("Failed to find debug information for address %lx\n", |
| 1245 | addr); |
Masami Hiramatsu | 75ec5a2 | 2010-04-02 12:50:59 -0400 | [diff] [blame] | 1246 | ret = -EINVAL; |
| 1247 | goto end; |
| 1248 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1249 | |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1250 | /* Find a corresponding line (filename and lineno) */ |
| 1251 | cu_find_lineinfo(&cudie, addr, &fname, &lineno); |
| 1252 | /* Don't care whether it failed or not */ |
| 1253 | |
| 1254 | /* Find a corresponding function (name, baseline and baseaddr) */ |
Masami Hiramatsu | e0d153c | 2011-06-27 16:27:27 +0900 | [diff] [blame^] | 1255 | if (die_find_realfunc(&cudie, (Dwarf_Addr)addr, &spdie)) { |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1256 | /* Get function entry information */ |
| 1257 | tmp = dwarf_diename(&spdie); |
| 1258 | if (!tmp || |
| 1259 | dwarf_entrypc(&spdie, &baseaddr) != 0 || |
| 1260 | dwarf_decl_line(&spdie, &baseline) != 0) |
| 1261 | goto post; |
| 1262 | func = tmp; |
| 1263 | |
| 1264 | if (addr == (unsigned long)baseaddr) |
| 1265 | /* Function entry - Relative line number is 0 */ |
| 1266 | lineno = baseline; |
| 1267 | else if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr, |
| 1268 | &indie)) { |
| 1269 | if (dwarf_entrypc(&indie, &_addr) == 0 && |
| 1270 | _addr == addr) |
| 1271 | /* |
| 1272 | * addr is at an inline function entry. |
| 1273 | * In this case, lineno should be the call-site |
| 1274 | * line number. |
| 1275 | */ |
| 1276 | lineno = die_get_call_lineno(&indie); |
| 1277 | else { |
| 1278 | /* |
| 1279 | * addr is in an inline function body. |
| 1280 | * Since lineno points one of the lines |
| 1281 | * of the inline function, baseline should |
| 1282 | * be the entry line of the inline function. |
| 1283 | */ |
| 1284 | tmp = dwarf_diename(&indie); |
| 1285 | if (tmp && |
| 1286 | dwarf_decl_line(&spdie, &baseline) == 0) |
| 1287 | func = tmp; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1288 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1292 | post: |
| 1293 | /* Make a relative line number or an offset */ |
| 1294 | if (lineno) |
| 1295 | ppt->line = lineno - baseline; |
| 1296 | else if (func) |
| 1297 | ppt->offset = addr - (unsigned long)baseaddr; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1298 | |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1299 | /* Duplicate strings */ |
| 1300 | if (func) { |
| 1301 | ppt->function = strdup(func); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1302 | if (ppt->function == NULL) { |
| 1303 | ret = -ENOMEM; |
| 1304 | goto end; |
| 1305 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1306 | } |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1307 | if (fname) { |
| 1308 | ppt->file = strdup(fname); |
| 1309 | if (ppt->file == NULL) { |
| 1310 | if (ppt->function) { |
| 1311 | free(ppt->function); |
| 1312 | ppt->function = NULL; |
| 1313 | } |
| 1314 | ret = -ENOMEM; |
| 1315 | goto end; |
| 1316 | } |
| 1317 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1318 | end: |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1319 | if (dwfl) |
| 1320 | dwfl_end(dwfl); |
Masami Hiramatsu | 1d46ea2 | 2011-03-30 18:26:05 +0900 | [diff] [blame] | 1321 | if (ret == 0 && (fname || func)) |
| 1322 | ret = 1; /* Found a point */ |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1323 | return ret; |
| 1324 | } |
| 1325 | |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1326 | /* Add a line and store the src path */ |
| 1327 | static int line_range_add_line(const char *src, unsigned int lineno, |
| 1328 | struct line_range *lr) |
| 1329 | { |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1330 | /* Copy source path */ |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1331 | if (!lr->path) { |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1332 | lr->path = strdup(src); |
| 1333 | if (lr->path == NULL) |
| 1334 | return -ENOMEM; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1335 | } |
| 1336 | return line_list__add_line(&lr->line_list, lineno); |
| 1337 | } |
| 1338 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1339 | static int line_range_walk_cb(const char *fname, int lineno, |
| 1340 | Dwarf_Addr addr __used, |
| 1341 | void *data) |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1342 | { |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1343 | struct line_finder *lf = data; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1344 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1345 | if ((strtailcmp(fname, lf->fname) != 0) || |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1346 | (lf->lno_s > lineno || lf->lno_e < lineno)) |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1347 | return 0; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1348 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1349 | if (line_range_add_line(fname, lineno, lf->lr) < 0) |
| 1350 | return -EINVAL; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1351 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1352 | return 0; |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1353 | } |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1354 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1355 | /* Find line range from its line number */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1356 | 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] | 1357 | { |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1358 | int ret; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1359 | |
Masami Hiramatsu | 4cc9cec | 2011-01-13 21:45:58 +0900 | [diff] [blame] | 1360 | ret = die_walk_lines(sp_die ?: &lf->cu_die, line_range_walk_cb, lf); |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1361 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1362 | /* Update status */ |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1363 | if (ret >= 0) |
| 1364 | if (!list_empty(&lf->lr->line_list)) |
| 1365 | ret = lf->found = 1; |
| 1366 | else |
| 1367 | ret = 0; /* Lines are not found */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1368 | else { |
| 1369 | free(lf->lr->path); |
| 1370 | lf->lr->path = NULL; |
| 1371 | } |
Masami Hiramatsu | f6c903f | 2010-04-14 18:40:07 -0400 | [diff] [blame] | 1372 | return ret; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1373 | } |
| 1374 | |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1375 | static int line_range_inline_cb(Dwarf_Die *in_die, void *data) |
| 1376 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1377 | struct dwarf_callback_param *param = data; |
| 1378 | |
| 1379 | param->retval = find_line_range_by_line(in_die, param->data); |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1380 | return DWARF_CB_ABORT; /* No need to find other instances */ |
| 1381 | } |
| 1382 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1383 | /* Search function from function name */ |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1384 | static int line_range_search_cb(Dwarf_Die *sp_die, void *data) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1385 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1386 | struct dwarf_callback_param *param = data; |
| 1387 | struct line_finder *lf = param->data; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1388 | struct line_range *lr = lf->lr; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1389 | |
Masami Hiramatsu | 7d21635 | 2011-03-30 18:25:41 +0900 | [diff] [blame] | 1390 | /* Check declared file */ |
| 1391 | if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die))) |
| 1392 | return DWARF_CB_OK; |
| 1393 | |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1394 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && |
Masami Hiramatsu | 8217563 | 2010-07-09 18:29:17 +0900 | [diff] [blame] | 1395 | die_compare_name(sp_die, lr->function)) { |
Masami Hiramatsu | e92b85e | 2010-02-25 08:35:50 -0500 | [diff] [blame] | 1396 | lf->fname = dwarf_decl_file(sp_die); |
| 1397 | dwarf_decl_line(sp_die, &lr->offset); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1398 | pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1399 | lf->lno_s = lr->offset + lr->start; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1400 | if (lf->lno_s < 0) /* Overflow */ |
| 1401 | lf->lno_s = INT_MAX; |
| 1402 | lf->lno_e = lr->offset + lr->end; |
| 1403 | if (lf->lno_e < 0) /* Overflow */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1404 | lf->lno_e = INT_MAX; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1405 | 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] | 1406 | lr->start = lf->lno_s; |
| 1407 | lr->end = lf->lno_e; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1408 | if (dwarf_func_inline(sp_die)) { |
| 1409 | struct dwarf_callback_param _param; |
| 1410 | _param.data = (void *)lf; |
| 1411 | _param.retval = 0; |
Masami Hiramatsu | 161a26b | 2010-02-25 08:35:57 -0500 | [diff] [blame] | 1412 | dwarf_func_inline_instances(sp_die, |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1413 | line_range_inline_cb, |
| 1414 | &_param); |
| 1415 | param->retval = _param.retval; |
| 1416 | } else |
| 1417 | param->retval = find_line_range_by_line(sp_die, lf); |
| 1418 | return DWARF_CB_ABORT; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1419 | } |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1420 | return DWARF_CB_OK; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1421 | } |
| 1422 | |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1423 | static int find_line_range_by_func(struct line_finder *lf) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1424 | { |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1425 | struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0}; |
| 1426 | dwarf_getfuncs(&lf->cu_die, line_range_search_cb, ¶m, 0); |
| 1427 | return param.retval; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | int find_line_range(int fd, struct line_range *lr) |
| 1431 | { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1432 | struct line_finder lf = {.lr = lr, .found = 0}; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1433 | int ret = 0; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1434 | Dwarf_Off off = 0, noff; |
| 1435 | size_t cuhl; |
| 1436 | Dwarf_Die *diep; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1437 | Dwarf *dbg = NULL; |
| 1438 | Dwfl *dwfl; |
| 1439 | Dwarf_Addr bias; /* Currently ignored */ |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 1440 | const char *comp_dir; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1441 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1442 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1443 | if (!dbg) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1444 | pr_warning("No debug information found in the vmlinux - " |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1445 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
Masami Hiramatsu | f0c4801 | 2011-03-30 18:25:47 +0900 | [diff] [blame] | 1446 | close(fd); /* Without dwfl_end(), fd isn't closed. */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1447 | return -EBADF; |
| 1448 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1449 | |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 1450 | /* Fastpath: lookup by function name from .debug_pubnames section */ |
| 1451 | if (lr->function) { |
| 1452 | struct pubname_callback_param pubname_param = { |
| 1453 | .function = lr->function, .file = lr->file, |
| 1454 | .cu_die = &lf.cu_die, .sp_die = &lf.sp_die, .found = 0}; |
| 1455 | struct dwarf_callback_param line_range_param = { |
| 1456 | .data = (void *)&lf, .retval = 0}; |
| 1457 | |
| 1458 | dwarf_getpubnames(dbg, pubname_search_cb, &pubname_param, 0); |
| 1459 | if (pubname_param.found) { |
| 1460 | line_range_search_cb(&lf.sp_die, &line_range_param); |
| 1461 | if (lf.found) |
| 1462 | goto found; |
| 1463 | } |
| 1464 | } |
| 1465 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1466 | /* Loop on CUs (Compilation Unit) */ |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1467 | while (!lf.found && ret >= 0) { |
| 1468 | if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1469 | break; |
| 1470 | |
| 1471 | /* Get the DIE(Debugging Information Entry) of this CU */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1472 | diep = dwarf_offdie(dbg, off + cuhl, &lf.cu_die); |
| 1473 | if (!diep) |
| 1474 | continue; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1475 | |
| 1476 | /* Check if target file is included. */ |
| 1477 | if (lr->file) |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1478 | lf.fname = cu_find_realpath(&lf.cu_die, lr->file); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1479 | else |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1480 | lf.fname = 0; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1481 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1482 | if (!lr->file || lf.fname) { |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1483 | if (lr->function) |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1484 | ret = find_line_range_by_func(&lf); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1485 | else { |
| 1486 | lf.lno_s = lr->start; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1487 | lf.lno_e = lr->end; |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1488 | ret = find_line_range_by_line(NULL, &lf); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1489 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1490 | } |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 1491 | off = noff; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1492 | } |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 1493 | |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 1494 | found: |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 1495 | /* Store comp_dir */ |
| 1496 | if (lf.found) { |
| 1497 | comp_dir = cu_get_comp_dir(&lf.cu_die); |
| 1498 | if (comp_dir) { |
| 1499 | lr->comp_dir = strdup(comp_dir); |
| 1500 | if (!lr->comp_dir) |
| 1501 | ret = -ENOMEM; |
| 1502 | } |
| 1503 | } |
| 1504 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 1505 | pr_debug("path: %s\n", lr->path); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1506 | dwfl_end(dwfl); |
Masami Hiramatsu | b55a87a | 2010-04-12 13:17:35 -0400 | [diff] [blame] | 1507 | return (ret < 0) ? ret : lf.found; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1508 | } |
| 1509 | |