probe-finder.c (cf6eb489e5c04c8f8d5fd7bf90b8346c987688bc) probe-finder.c (fb8c5a56c7ddbc2b0d2ee7a8da60fe1355f75141)
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

--- 1298 unchanged lines hidden (view full) ---

1307
1308 tag = dwarf_tag(die_mem);
1309 if (tag == DW_TAG_formal_parameter ||
1310 tag == DW_TAG_variable) {
1311 ret = convert_variable_location(die_mem, af->pf.addr,
1312 af->pf.fb_ops, NULL);
1313 if (ret == 0) {
1314 ret = die_get_varname(die_mem, buf, MAX_VAR_LEN);
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

--- 1298 unchanged lines hidden (view full) ---

1307
1308 tag = dwarf_tag(die_mem);
1309 if (tag == DW_TAG_formal_parameter ||
1310 tag == DW_TAG_variable) {
1311 ret = convert_variable_location(die_mem, af->pf.addr,
1312 af->pf.fb_ops, NULL);
1313 if (ret == 0) {
1314 ret = die_get_varname(die_mem, buf, MAX_VAR_LEN);
1315 pr_debug2("Add new var: %s\n", buf);
1315 if (ret > 0)
1316 strlist__add(vl->vars, buf);
1317 }
1318 }
1319
1316 if (ret > 0)
1317 strlist__add(vl->vars, buf);
1318 }
1319 }
1320
1320 if (dwarf_haspc(die_mem, af->pf.addr))
1321 if (af->child && dwarf_haspc(die_mem, af->pf.addr))
1321 return DIE_FIND_CB_CONTINUE;
1322 else
1323 return DIE_FIND_CB_SIBLING;
1324}
1325
1326/* Add a found vars into available variables list */
1327static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf)
1328{
1329 struct available_var_finder *af =
1330 container_of(pf, struct available_var_finder, pf);
1331 struct variable_list *vl;
1322 return DIE_FIND_CB_CONTINUE;
1323 else
1324 return DIE_FIND_CB_SIBLING;
1325}
1326
1327/* Add a found vars into available variables list */
1328static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf)
1329{
1330 struct available_var_finder *af =
1331 container_of(pf, struct available_var_finder, pf);
1332 struct variable_list *vl;
1332 Dwarf_Die die_mem;
1333 int ret;
1333 Dwarf_Die die_mem, *scopes = NULL;
1334 int ret, nscopes;
1334
1335 /* Check number of tevs */
1336 if (af->nvls == af->max_vls) {
1337 pr_warning("Too many( > %d) probe point found.\n", af->max_vls);
1338 return -ERANGE;
1339 }
1340 vl = &af->vls[af->nvls++];
1341

--- 4 unchanged lines hidden (view full) ---

1346
1347 pr_debug("Probe point found: %s+%lu\n", vl->point.symbol,
1348 vl->point.offset);
1349
1350 /* Find local variables */
1351 vl->vars = strlist__new(true, NULL);
1352 if (vl->vars == NULL)
1353 return -ENOMEM;
1335
1336 /* Check number of tevs */
1337 if (af->nvls == af->max_vls) {
1338 pr_warning("Too many( > %d) probe point found.\n", af->max_vls);
1339 return -ERANGE;
1340 }
1341 vl = &af->vls[af->nvls++];
1342

--- 4 unchanged lines hidden (view full) ---

1347
1348 pr_debug("Probe point found: %s+%lu\n", vl->point.symbol,
1349 vl->point.offset);
1350
1351 /* Find local variables */
1352 vl->vars = strlist__new(true, NULL);
1353 if (vl->vars == NULL)
1354 return -ENOMEM;
1355 af->child = true;
1354 die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem);
1355
1356 die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem);
1357
1358 /* Find external variables */
1359 if (!af->externs)
1360 goto out;
1361 /* Don't need to search child DIE for externs. */
1362 af->child = false;
1363 nscopes = dwarf_getscopes_die(sp_die, &scopes);
1364 while (nscopes-- > 1)
1365 die_find_child(&scopes[nscopes], collect_variables_cb,
1366 (void *)af, &die_mem);
1367 if (scopes)
1368 free(scopes);
1369
1370out:
1356 if (strlist__empty(vl->vars)) {
1357 strlist__delete(vl->vars);
1358 vl->vars = NULL;
1359 }
1360
1361 return ret;
1362}
1363
1364/* Find available variables at given probe point */
1365int find_available_vars_at(int fd, struct perf_probe_event *pev,
1371 if (strlist__empty(vl->vars)) {
1372 strlist__delete(vl->vars);
1373 vl->vars = NULL;
1374 }
1375
1376 return ret;
1377}
1378
1379/* Find available variables at given probe point */
1380int find_available_vars_at(int fd, struct perf_probe_event *pev,
1366 struct variable_list **vls, int max_vls)
1381 struct variable_list **vls, int max_vls,
1382 bool externs)
1367{
1368 struct available_var_finder af = {
1369 .pf = {.pev = pev, .callback = add_available_vars},
1383{
1384 struct available_var_finder af = {
1385 .pf = {.pev = pev, .callback = add_available_vars},
1370 .max_vls = max_vls};
1386 .max_vls = max_vls, .externs = externs};
1371 int ret;
1372
1373 /* Allocate result vls array */
1374 *vls = zalloc(sizeof(struct variable_list) * max_vls);
1375 if (*vls == NULL)
1376 return -ENOMEM;
1377
1378 af.vls = *vls;

--- 329 unchanged lines hidden ---
1387 int ret;
1388
1389 /* Allocate result vls array */
1390 *vls = zalloc(sizeof(struct variable_list) * max_vls);
1391 if (*vls == NULL)
1392 return -ENOMEM;
1393
1394 af.vls = *vls;

--- 329 unchanged lines hidden ---