probe-event.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  1. /*
  2. * probe-event.c : perf-probe definition to probe_events format 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. #include <sys/utsname.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <fcntl.h>
  25. #include <errno.h>
  26. #include <stdio.h>
  27. #include <unistd.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdarg.h>
  31. #include <limits.h>
  32. #include <elf.h>
  33. #include "util.h"
  34. #include "event.h"
  35. #include "strlist.h"
  36. #include "debug.h"
  37. #include "cache.h"
  38. #include "color.h"
  39. #include "symbol.h"
  40. #include "thread.h"
  41. #include "debugfs.h"
  42. #include "trace-event.h" /* For __unused */
  43. #include "probe-event.h"
  44. #include "probe-finder.h"
  45. #define MAX_CMDLEN 256
  46. #define MAX_PROBE_ARGS 128
  47. #define PERFPROBE_GROUP "probe"
  48. bool probe_event_dry_run; /* Dry run flag */
  49. #define semantic_error(msg ...) pr_err("Semantic error :" msg)
  50. /* If there is no space to write, returns -E2BIG. */
  51. static int e_snprintf(char *str, size_t size, const char *format, ...)
  52. __attribute__((format(printf, 3, 4)));
  53. static int e_snprintf(char *str, size_t size, const char *format, ...)
  54. {
  55. int ret;
  56. va_list ap;
  57. va_start(ap, format);
  58. ret = vsnprintf(str, size, format, ap);
  59. va_end(ap);
  60. if (ret >= (int)size)
  61. ret = -E2BIG;
  62. return ret;
  63. }
  64. static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
  65. static struct machine machine;
  66. /* Initialize symbol maps and path of vmlinux/modules */
  67. static int init_vmlinux(void)
  68. {
  69. int ret;
  70. symbol_conf.sort_by_name = true;
  71. if (symbol_conf.vmlinux_name == NULL)
  72. symbol_conf.try_vmlinux_path = true;
  73. else
  74. pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
  75. ret = symbol__init();
  76. if (ret < 0) {
  77. pr_debug("Failed to init symbol map.\n");
  78. goto out;
  79. }
  80. ret = machine__init(&machine, "", HOST_KERNEL_ID);
  81. if (ret < 0)
  82. goto out;
  83. if (machine__create_kernel_maps(&machine) < 0) {
  84. pr_debug("machine__create_kernel_maps() failed.\n");
  85. goto out;
  86. }
  87. out:
  88. if (ret < 0)
  89. pr_warning("Failed to init vmlinux path.\n");
  90. return ret;
  91. }
  92. static struct symbol *__find_kernel_function_by_name(const char *name,
  93. struct map **mapp)
  94. {
  95. return machine__find_kernel_function_by_name(&machine, name, mapp,
  96. NULL);
  97. }
  98. static struct map *kernel_get_module_map(const char *module)
  99. {
  100. struct rb_node *nd;
  101. struct map_groups *grp = &machine.kmaps;
  102. /* A file path -- this is an offline module */
  103. if (module && strchr(module, '/'))
  104. return machine__new_module(&machine, 0, module);
  105. if (!module)
  106. module = "kernel";
  107. for (nd = rb_first(&grp->maps[MAP__FUNCTION]); nd; nd = rb_next(nd)) {
  108. struct map *pos = rb_entry(nd, struct map, rb_node);
  109. if (strncmp(pos->dso->short_name + 1, module,
  110. pos->dso->short_name_len - 2) == 0) {
  111. return pos;
  112. }
  113. }
  114. return NULL;
  115. }
  116. static struct dso *kernel_get_module_dso(const char *module)
  117. {
  118. struct dso *dso;
  119. struct map *map;
  120. const char *vmlinux_name;
  121. if (module) {
  122. list_for_each_entry(dso, &machine.kernel_dsos, node) {
  123. if (strncmp(dso->short_name + 1, module,
  124. dso->short_name_len - 2) == 0)
  125. goto found;
  126. }
  127. pr_debug("Failed to find module %s.\n", module);
  128. return NULL;
  129. }
  130. map = machine.vmlinux_maps[MAP__FUNCTION];
  131. dso = map->dso;
  132. vmlinux_name = symbol_conf.vmlinux_name;
  133. if (vmlinux_name) {
  134. if (dso__load_vmlinux(dso, map, vmlinux_name, NULL) <= 0)
  135. return NULL;
  136. } else {
  137. if (dso__load_vmlinux_path(dso, map, NULL) <= 0) {
  138. pr_debug("Failed to load kernel map.\n");
  139. return NULL;
  140. }
  141. }
  142. found:
  143. return dso;
  144. }
  145. const char *kernel_get_module_path(const char *module)
  146. {
  147. struct dso *dso = kernel_get_module_dso(module);
  148. return (dso) ? dso->long_name : NULL;
  149. }
  150. #ifdef DWARF_SUPPORT
  151. /* Open new debuginfo of given module */
  152. static struct debuginfo *open_debuginfo(const char *module)
  153. {
  154. const char *path;
  155. /* A file path -- this is an offline module */
  156. if (module && strchr(module, '/'))
  157. path = module;
  158. else {
  159. path = kernel_get_module_path(module);
  160. if (!path) {
  161. pr_err("Failed to find path of %s module.\n",
  162. module ?: "kernel");
  163. return NULL;
  164. }
  165. }
  166. return debuginfo__new(path);
  167. }
  168. /*
  169. * Convert trace point to probe point with debuginfo
  170. * Currently only handles kprobes.
  171. */
  172. static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
  173. struct perf_probe_point *pp)
  174. {
  175. struct symbol *sym;
  176. struct map *map;
  177. u64 addr;
  178. int ret = -ENOENT;
  179. struct debuginfo *dinfo;
  180. sym = __find_kernel_function_by_name(tp->symbol, &map);
  181. if (sym) {
  182. addr = map->unmap_ip(map, sym->start + tp->offset);
  183. pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol,
  184. tp->offset, addr);
  185. dinfo = debuginfo__new_online_kernel(addr);
  186. if (dinfo) {
  187. ret = debuginfo__find_probe_point(dinfo,
  188. (unsigned long)addr, pp);
  189. debuginfo__delete(dinfo);
  190. } else {
  191. pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n",
  192. addr);
  193. ret = -ENOENT;
  194. }
  195. }
  196. if (ret <= 0) {
  197. pr_debug("Failed to find corresponding probes from "
  198. "debuginfo. Use kprobe event information.\n");
  199. pp->function = strdup(tp->symbol);
  200. if (pp->function == NULL)
  201. return -ENOMEM;
  202. pp->offset = tp->offset;
  203. }
  204. pp->retprobe = tp->retprobe;
  205. return 0;
  206. }
  207. static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
  208. int ntevs, const char *module)
  209. {
  210. int i, ret = 0;
  211. char *tmp;
  212. if (!module)
  213. return 0;
  214. tmp = strrchr(module, '/');
  215. if (tmp) {
  216. /* This is a module path -- get the module name */
  217. module = strdup(tmp + 1);
  218. if (!module)
  219. return -ENOMEM;
  220. tmp = strchr(module, '.');
  221. if (tmp)
  222. *tmp = '\0';
  223. tmp = (char *)module; /* For free() */
  224. }
  225. for (i = 0; i < ntevs; i++) {
  226. tevs[i].point.module = strdup(module);
  227. if (!tevs[i].point.module) {
  228. ret = -ENOMEM;
  229. break;
  230. }
  231. }
  232. if (tmp)
  233. free(tmp);
  234. return ret;
  235. }
  236. /* Try to find perf_probe_event with debuginfo */
  237. static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
  238. struct probe_trace_event **tevs,
  239. int max_tevs, const char *target)
  240. {
  241. bool need_dwarf = perf_probe_event_need_dwarf(pev);
  242. struct debuginfo *dinfo = open_debuginfo(target);
  243. int ntevs, ret = 0;
  244. if (!dinfo) {
  245. if (need_dwarf) {
  246. pr_warning("Failed to open debuginfo file.\n");
  247. return -ENOENT;
  248. }
  249. pr_debug("Could not open debuginfo. Try to use symbols.\n");
  250. return 0;
  251. }
  252. /* Searching trace events corresponding to a probe event */
  253. ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
  254. debuginfo__delete(dinfo);
  255. if (ntevs > 0) { /* Succeeded to find trace events */
  256. pr_debug("find %d probe_trace_events.\n", ntevs);
  257. if (target)
  258. ret = add_module_to_probe_trace_events(*tevs, ntevs,
  259. target);
  260. return ret < 0 ? ret : ntevs;
  261. }
  262. if (ntevs == 0) { /* No error but failed to find probe point. */
  263. pr_warning("Probe point '%s' not found.\n",
  264. synthesize_perf_probe_point(&pev->point));
  265. return -ENOENT;
  266. }
  267. /* Error path : ntevs < 0 */
  268. pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
  269. if (ntevs == -EBADF) {
  270. pr_warning("Warning: No dwarf info found in the vmlinux - "
  271. "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n");
  272. if (!need_dwarf) {
  273. pr_debug("Trying to use symbols.\n");
  274. return 0;
  275. }
  276. }
  277. return ntevs;
  278. }
  279. /*
  280. * Find a src file from a DWARF tag path. Prepend optional source path prefix
  281. * and chop off leading directories that do not exist. Result is passed back as
  282. * a newly allocated path on success.
  283. * Return 0 if file was found and readable, -errno otherwise.
  284. */
  285. static int get_real_path(const char *raw_path, const char *comp_dir,
  286. char **new_path)
  287. {
  288. const char *prefix = symbol_conf.source_prefix;
  289. if (!prefix) {
  290. if (raw_path[0] != '/' && comp_dir)
  291. /* If not an absolute path, try to use comp_dir */
  292. prefix = comp_dir;
  293. else {
  294. if (access(raw_path, R_OK) == 0) {
  295. *new_path = strdup(raw_path);
  296. return 0;
  297. } else
  298. return -errno;
  299. }
  300. }
  301. *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2));
  302. if (!*new_path)
  303. return -ENOMEM;
  304. for (;;) {
  305. sprintf(*new_path, "%s/%s", prefix, raw_path);
  306. if (access(*new_path, R_OK) == 0)
  307. return 0;
  308. if (!symbol_conf.source_prefix)
  309. /* In case of searching comp_dir, don't retry */
  310. return -errno;
  311. switch (errno) {
  312. case ENAMETOOLONG:
  313. case ENOENT:
  314. case EROFS:
  315. case EFAULT:
  316. raw_path = strchr(++raw_path, '/');
  317. if (!raw_path) {
  318. free(*new_path);
  319. *new_path = NULL;
  320. return -ENOENT;
  321. }
  322. continue;
  323. default:
  324. free(*new_path);
  325. *new_path = NULL;
  326. return -errno;
  327. }
  328. }
  329. }
  330. #define LINEBUF_SIZE 256
  331. #define NR_ADDITIONAL_LINES 2
  332. static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
  333. {
  334. char buf[LINEBUF_SIZE];
  335. const char *color = show_num ? "" : PERF_COLOR_BLUE;
  336. const char *prefix = NULL;
  337. do {
  338. if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
  339. goto error;
  340. if (skip)
  341. continue;
  342. if (!prefix) {
  343. prefix = show_num ? "%7d " : " ";
  344. color_fprintf(stdout, color, prefix, l);
  345. }
  346. color_fprintf(stdout, color, "%s", buf);
  347. } while (strchr(buf, '\n') == NULL);
  348. return 1;
  349. error:
  350. if (ferror(fp)) {
  351. pr_warning("File read error: %s\n", strerror(errno));
  352. return -1;
  353. }
  354. return 0;
  355. }
  356. static int _show_one_line(FILE *fp, int l, bool skip, bool show_num)
  357. {
  358. int rv = __show_one_line(fp, l, skip, show_num);
  359. if (rv == 0) {
  360. pr_warning("Source file is shorter than expected.\n");
  361. rv = -1;
  362. }
  363. return rv;
  364. }
  365. #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true)
  366. #define show_one_line(f,l) _show_one_line(f,l,false,false)
  367. #define skip_one_line(f,l) _show_one_line(f,l,true,false)
  368. #define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false)
  369. /*
  370. * Show line-range always requires debuginfo to find source file and
  371. * line number.
  372. */
  373. int show_line_range(struct line_range *lr, const char *module)
  374. {
  375. int l = 1;
  376. struct line_node *ln;
  377. struct debuginfo *dinfo;
  378. FILE *fp;
  379. int ret;
  380. char *tmp;
  381. /* Search a line range */
  382. ret = init_vmlinux();
  383. if (ret < 0)
  384. return ret;
  385. dinfo = open_debuginfo(module);
  386. if (!dinfo) {
  387. pr_warning("Failed to open debuginfo file.\n");
  388. return -ENOENT;
  389. }
  390. ret = debuginfo__find_line_range(dinfo, lr);
  391. debuginfo__delete(dinfo);
  392. if (ret == 0) {
  393. pr_warning("Specified source line is not found.\n");
  394. return -ENOENT;
  395. } else if (ret < 0) {
  396. pr_warning("Debuginfo analysis failed. (%d)\n", ret);
  397. return ret;
  398. }
  399. /* Convert source file path */
  400. tmp = lr->path;
  401. ret = get_real_path(tmp, lr->comp_dir, &lr->path);
  402. free(tmp); /* Free old path */
  403. if (ret < 0) {
  404. pr_warning("Failed to find source file. (%d)\n", ret);
  405. return ret;
  406. }
  407. setup_pager();
  408. if (lr->function)
  409. fprintf(stdout, "<%s@%s:%d>\n", lr->function, lr->path,
  410. lr->start - lr->offset);
  411. else
  412. fprintf(stdout, "<%s:%d>\n", lr->path, lr->start);
  413. fp = fopen(lr->path, "r");
  414. if (fp == NULL) {
  415. pr_warning("Failed to open %s: %s\n", lr->path,
  416. strerror(errno));
  417. return -errno;
  418. }
  419. /* Skip to starting line number */
  420. while (l < lr->start) {
  421. ret = skip_one_line(fp, l++);
  422. if (ret < 0)
  423. goto end;
  424. }
  425. list_for_each_entry(ln, &lr->line_list, list) {
  426. for (; ln->line > l; l++) {
  427. ret = show_one_line(fp, l - lr->offset);
  428. if (ret < 0)
  429. goto end;
  430. }
  431. ret = show_one_line_with_num(fp, l++ - lr->offset);
  432. if (ret < 0)
  433. goto end;
  434. }
  435. if (lr->end == INT_MAX)
  436. lr->end = l + NR_ADDITIONAL_LINES;
  437. while (l <= lr->end) {
  438. ret = show_one_line_or_eof(fp, l++ - lr->offset);
  439. if (ret <= 0)
  440. break;
  441. }
  442. end:
  443. fclose(fp);
  444. return ret;
  445. }
  446. static int show_available_vars_at(struct debuginfo *dinfo,
  447. struct perf_probe_event *pev,
  448. int max_vls, struct strfilter *_filter,
  449. bool externs)
  450. {
  451. char *buf;
  452. int ret, i, nvars;
  453. struct str_node *node;
  454. struct variable_list *vls = NULL, *vl;
  455. const char *var;
  456. buf = synthesize_perf_probe_point(&pev->point);
  457. if (!buf)
  458. return -EINVAL;
  459. pr_debug("Searching variables at %s\n", buf);
  460. ret = debuginfo__find_available_vars_at(dinfo, pev, &vls,
  461. max_vls, externs);
  462. if (ret <= 0) {
  463. pr_err("Failed to find variables at %s (%d)\n", buf, ret);
  464. goto end;
  465. }
  466. /* Some variables are found */
  467. fprintf(stdout, "Available variables at %s\n", buf);
  468. for (i = 0; i < ret; i++) {
  469. vl = &vls[i];
  470. /*
  471. * A probe point might be converted to
  472. * several trace points.
  473. */
  474. fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol,
  475. vl->point.offset);
  476. free(vl->point.symbol);
  477. nvars = 0;
  478. if (vl->vars) {
  479. strlist__for_each(node, vl->vars) {
  480. var = strchr(node->s, '\t') + 1;
  481. if (strfilter__compare(_filter, var)) {
  482. fprintf(stdout, "\t\t%s\n", node->s);
  483. nvars++;
  484. }
  485. }
  486. strlist__delete(vl->vars);
  487. }
  488. if (nvars == 0)
  489. fprintf(stdout, "\t\t(No matched variables)\n");
  490. }
  491. free(vls);
  492. end:
  493. free(buf);
  494. return ret;
  495. }
  496. /* Show available variables on given probe point */
  497. int show_available_vars(struct perf_probe_event *pevs, int npevs,
  498. int max_vls, const char *module,
  499. struct strfilter *_filter, bool externs)
  500. {
  501. int i, ret = 0;
  502. struct debuginfo *dinfo;
  503. ret = init_vmlinux();
  504. if (ret < 0)
  505. return ret;
  506. dinfo = open_debuginfo(module);
  507. if (!dinfo) {
  508. pr_warning("Failed to open debuginfo file.\n");
  509. return -ENOENT;
  510. }
  511. setup_pager();
  512. for (i = 0; i < npevs && ret >= 0; i++)
  513. ret = show_available_vars_at(dinfo, &pevs[i], max_vls, _filter,
  514. externs);
  515. debuginfo__delete(dinfo);
  516. return ret;
  517. }
  518. #else /* !DWARF_SUPPORT */
  519. static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
  520. struct perf_probe_point *pp)
  521. {
  522. struct symbol *sym;
  523. sym = __find_kernel_function_by_name(tp->symbol, NULL);
  524. if (!sym) {
  525. pr_err("Failed to find symbol %s in kernel.\n", tp->symbol);
  526. return -ENOENT;
  527. }
  528. pp->function = strdup(tp->symbol);
  529. if (pp->function == NULL)
  530. return -ENOMEM;
  531. pp->offset = tp->offset;
  532. pp->retprobe = tp->retprobe;
  533. return 0;
  534. }
  535. static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
  536. struct probe_trace_event **tevs __unused,
  537. int max_tevs __unused, const char *mod __unused)
  538. {
  539. if (perf_probe_event_need_dwarf(pev)) {
  540. pr_warning("Debuginfo-analysis is not supported.\n");
  541. return -ENOSYS;
  542. }
  543. return 0;
  544. }
  545. int show_line_range(struct line_range *lr __unused, const char *module __unused)
  546. {
  547. pr_warning("Debuginfo-analysis is not supported.\n");
  548. return -ENOSYS;
  549. }
  550. int show_available_vars(struct perf_probe_event *pevs __unused,
  551. int npevs __unused, int max_vls __unused,
  552. const char *module __unused,
  553. struct strfilter *filter __unused,
  554. bool externs __unused)
  555. {
  556. pr_warning("Debuginfo-analysis is not supported.\n");
  557. return -ENOSYS;
  558. }
  559. #endif
  560. static int parse_line_num(char **ptr, int *val, const char *what)
  561. {
  562. const char *start = *ptr;
  563. errno = 0;
  564. *val = strtol(*ptr, ptr, 0);
  565. if (errno || *ptr == start) {
  566. semantic_error("'%s' is not a valid number.\n", what);
  567. return -EINVAL;
  568. }
  569. return 0;
  570. }
  571. /*
  572. * Stuff 'lr' according to the line range described by 'arg'.
  573. * The line range syntax is described by:
  574. *
  575. * SRC[:SLN[+NUM|-ELN]]
  576. * FNC[@SRC][:SLN[+NUM|-ELN]]
  577. */
  578. int parse_line_range_desc(const char *arg, struct line_range *lr)
  579. {
  580. char *range, *file, *name = strdup(arg);
  581. int err;
  582. if (!name)
  583. return -ENOMEM;
  584. lr->start = 0;
  585. lr->end = INT_MAX;
  586. range = strchr(name, ':');
  587. if (range) {
  588. *range++ = '\0';
  589. err = parse_line_num(&range, &lr->start, "start line");
  590. if (err)
  591. goto err;
  592. if (*range == '+' || *range == '-') {
  593. const char c = *range++;
  594. err = parse_line_num(&range, &lr->end, "end line");
  595. if (err)
  596. goto err;
  597. if (c == '+') {
  598. lr->end += lr->start;
  599. /*
  600. * Adjust the number of lines here.
  601. * If the number of lines == 1, the
  602. * the end of line should be equal to
  603. * the start of line.
  604. */
  605. lr->end--;
  606. }
  607. }
  608. pr_debug("Line range is %d to %d\n", lr->start, lr->end);
  609. err = -EINVAL;
  610. if (lr->start > lr->end) {
  611. semantic_error("Start line must be smaller"
  612. " than end line.\n");
  613. goto err;
  614. }
  615. if (*range != '\0') {
  616. semantic_error("Tailing with invalid str '%s'.\n", range);
  617. goto err;
  618. }
  619. }
  620. file = strchr(name, '@');
  621. if (file) {
  622. *file = '\0';
  623. lr->file = strdup(++file);
  624. if (lr->file == NULL) {
  625. err = -ENOMEM;
  626. goto err;
  627. }
  628. lr->function = name;
  629. } else if (strchr(name, '.'))
  630. lr->file = name;
  631. else
  632. lr->function = name;
  633. return 0;
  634. err:
  635. free(name);
  636. return err;
  637. }
  638. /* Check the name is good for event/group */
  639. static bool check_event_name(const char *name)
  640. {
  641. if (!isalpha(*name) && *name != '_')
  642. return false;
  643. while (*++name != '\0') {
  644. if (!isalpha(*name) && !isdigit(*name) && *name != '_')
  645. return false;
  646. }
  647. return true;
  648. }
  649. /* Parse probepoint definition. */
  650. static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
  651. {
  652. struct perf_probe_point *pp = &pev->point;
  653. char *ptr, *tmp;
  654. char c, nc = 0;
  655. /*
  656. * <Syntax>
  657. * perf probe [EVENT=]SRC[:LN|;PTN]
  658. * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
  659. *
  660. * TODO:Group name support
  661. */
  662. ptr = strpbrk(arg, ";=@+%");
  663. if (ptr && *ptr == '=') { /* Event name */
  664. *ptr = '\0';
  665. tmp = ptr + 1;
  666. if (strchr(arg, ':')) {
  667. semantic_error("Group name is not supported yet.\n");
  668. return -ENOTSUP;
  669. }
  670. if (!check_event_name(arg)) {
  671. semantic_error("%s is bad for event name -it must "
  672. "follow C symbol-naming rule.\n", arg);
  673. return -EINVAL;
  674. }
  675. pev->event = strdup(arg);
  676. if (pev->event == NULL)
  677. return -ENOMEM;
  678. pev->group = NULL;
  679. arg = tmp;
  680. }
  681. ptr = strpbrk(arg, ";:+@%");
  682. if (ptr) {
  683. nc = *ptr;
  684. *ptr++ = '\0';
  685. }
  686. tmp = strdup(arg);
  687. if (tmp == NULL)
  688. return -ENOMEM;
  689. /* Check arg is function or file and copy it */
  690. if (strchr(tmp, '.')) /* File */
  691. pp->file = tmp;
  692. else /* Function */
  693. pp->function = tmp;
  694. /* Parse other options */
  695. while (ptr) {
  696. arg = ptr;
  697. c = nc;
  698. if (c == ';') { /* Lazy pattern must be the last part */
  699. pp->lazy_line = strdup(arg);
  700. if (pp->lazy_line == NULL)
  701. return -ENOMEM;
  702. break;
  703. }
  704. ptr = strpbrk(arg, ";:+@%");
  705. if (ptr) {
  706. nc = *ptr;
  707. *ptr++ = '\0';
  708. }
  709. switch (c) {
  710. case ':': /* Line number */
  711. pp->line = strtoul(arg, &tmp, 0);
  712. if (*tmp != '\0') {
  713. semantic_error("There is non-digit char"
  714. " in line number.\n");
  715. return -EINVAL;
  716. }
  717. break;
  718. case '+': /* Byte offset from a symbol */
  719. pp->offset = strtoul(arg, &tmp, 0);
  720. if (*tmp != '\0') {
  721. semantic_error("There is non-digit character"
  722. " in offset.\n");
  723. return -EINVAL;
  724. }
  725. break;
  726. case '@': /* File name */
  727. if (pp->file) {
  728. semantic_error("SRC@SRC is not allowed.\n");
  729. return -EINVAL;
  730. }
  731. pp->file = strdup(arg);
  732. if (pp->file == NULL)
  733. return -ENOMEM;
  734. break;
  735. case '%': /* Probe places */
  736. if (strcmp(arg, "return") == 0) {
  737. pp->retprobe = 1;
  738. } else { /* Others not supported yet */
  739. semantic_error("%%%s is not supported.\n", arg);
  740. return -ENOTSUP;
  741. }
  742. break;
  743. default: /* Buggy case */
  744. pr_err("This program has a bug at %s:%d.\n",
  745. __FILE__, __LINE__);
  746. return -ENOTSUP;
  747. break;
  748. }
  749. }
  750. /* Exclusion check */
  751. if (pp->lazy_line && pp->line) {
  752. semantic_error("Lazy pattern can't be used with"
  753. " line number.\n");
  754. return -EINVAL;
  755. }
  756. if (pp->lazy_line && pp->offset) {
  757. semantic_error("Lazy pattern can't be used with offset.\n");
  758. return -EINVAL;
  759. }
  760. if (pp->line && pp->offset) {
  761. semantic_error("Offset can't be used with line number.\n");
  762. return -EINVAL;
  763. }
  764. if (!pp->line && !pp->lazy_line && pp->file && !pp->function) {
  765. semantic_error("File always requires line number or "
  766. "lazy pattern.\n");
  767. return -EINVAL;
  768. }
  769. if (pp->offset && !pp->function) {
  770. semantic_error("Offset requires an entry function.\n");
  771. return -EINVAL;
  772. }
  773. if (pp->retprobe && !pp->function) {
  774. semantic_error("Return probe requires an entry function.\n");
  775. return -EINVAL;
  776. }
  777. if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) {
  778. semantic_error("Offset/Line/Lazy pattern can't be used with "
  779. "return probe.\n");
  780. return -EINVAL;
  781. }
  782. pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n",
  783. pp->function, pp->file, pp->line, pp->offset, pp->retprobe,
  784. pp->lazy_line);
  785. return 0;
  786. }
  787. /* Parse perf-probe event argument */
  788. static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
  789. {
  790. char *tmp, *goodname;
  791. struct perf_probe_arg_field **fieldp;
  792. pr_debug("parsing arg: %s into ", str);
  793. tmp = strchr(str, '=');
  794. if (tmp) {
  795. arg->name = strndup(str, tmp - str);
  796. if (arg->name == NULL)
  797. return -ENOMEM;
  798. pr_debug("name:%s ", arg->name);
  799. str = tmp + 1;
  800. }
  801. tmp = strchr(str, ':');
  802. if (tmp) { /* Type setting */
  803. *tmp = '\0';
  804. arg->type = strdup(tmp + 1);
  805. if (arg->type == NULL)
  806. return -ENOMEM;
  807. pr_debug("type:%s ", arg->type);
  808. }
  809. tmp = strpbrk(str, "-.[");
  810. if (!is_c_varname(str) || !tmp) {
  811. /* A variable, register, symbol or special value */
  812. arg->var = strdup(str);
  813. if (arg->var == NULL)
  814. return -ENOMEM;
  815. pr_debug("%s\n", arg->var);
  816. return 0;
  817. }
  818. /* Structure fields or array element */
  819. arg->var = strndup(str, tmp - str);
  820. if (arg->var == NULL)
  821. return -ENOMEM;
  822. goodname = arg->var;
  823. pr_debug("%s, ", arg->var);
  824. fieldp = &arg->field;
  825. do {
  826. *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
  827. if (*fieldp == NULL)
  828. return -ENOMEM;
  829. if (*tmp == '[') { /* Array */
  830. str = tmp;
  831. (*fieldp)->index = strtol(str + 1, &tmp, 0);
  832. (*fieldp)->ref = true;
  833. if (*tmp != ']' || tmp == str + 1) {
  834. semantic_error("Array index must be a"
  835. " number.\n");
  836. return -EINVAL;
  837. }
  838. tmp++;
  839. if (*tmp == '\0')
  840. tmp = NULL;
  841. } else { /* Structure */
  842. if (*tmp == '.') {
  843. str = tmp + 1;
  844. (*fieldp)->ref = false;
  845. } else if (tmp[1] == '>') {
  846. str = tmp + 2;
  847. (*fieldp)->ref = true;
  848. } else {
  849. semantic_error("Argument parse error: %s\n",
  850. str);
  851. return -EINVAL;
  852. }
  853. tmp = strpbrk(str, "-.[");
  854. }
  855. if (tmp) {
  856. (*fieldp)->name = strndup(str, tmp - str);
  857. if ((*fieldp)->name == NULL)
  858. return -ENOMEM;
  859. if (*str != '[')
  860. goodname = (*fieldp)->name;
  861. pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref);
  862. fieldp = &(*fieldp)->next;
  863. }
  864. } while (tmp);
  865. (*fieldp)->name = strdup(str);
  866. if ((*fieldp)->name == NULL)
  867. return -ENOMEM;
  868. if (*str != '[')
  869. goodname = (*fieldp)->name;
  870. pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref);
  871. /* If no name is specified, set the last field name (not array index)*/
  872. if (!arg->name) {
  873. arg->name = strdup(goodname);
  874. if (arg->name == NULL)
  875. return -ENOMEM;
  876. }
  877. return 0;
  878. }
  879. /* Parse perf-probe event command */
  880. int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
  881. {
  882. char **argv;
  883. int argc, i, ret = 0;
  884. argv = argv_split(cmd, &argc);
  885. if (!argv) {
  886. pr_debug("Failed to split arguments.\n");
  887. return -ENOMEM;
  888. }
  889. if (argc - 1 > MAX_PROBE_ARGS) {
  890. semantic_error("Too many probe arguments (%d).\n", argc - 1);
  891. ret = -ERANGE;
  892. goto out;
  893. }
  894. /* Parse probe point */
  895. ret = parse_perf_probe_point(argv[0], pev);
  896. if (ret < 0)
  897. goto out;
  898. /* Copy arguments and ensure return probe has no C argument */
  899. pev->nargs = argc - 1;
  900. pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
  901. if (pev->args == NULL) {
  902. ret = -ENOMEM;
  903. goto out;
  904. }
  905. for (i = 0; i < pev->nargs && ret >= 0; i++) {
  906. ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
  907. if (ret >= 0 &&
  908. is_c_varname(pev->args[i].var) && pev->point.retprobe) {
  909. semantic_error("You can't specify local variable for"
  910. " kretprobe.\n");
  911. ret = -EINVAL;
  912. }
  913. }
  914. out:
  915. argv_free(argv);
  916. return ret;
  917. }
  918. /* Return true if this perf_probe_event requires debuginfo */
  919. bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
  920. {
  921. int i;
  922. if (pev->point.file || pev->point.line || pev->point.lazy_line)
  923. return true;
  924. for (i = 0; i < pev->nargs; i++)
  925. if (is_c_varname(pev->args[i].var))
  926. return true;
  927. return false;
  928. }
  929. /* Parse probe_events event into struct probe_point */
  930. static int parse_probe_trace_command(const char *cmd,
  931. struct probe_trace_event *tev)
  932. {
  933. struct probe_trace_point *tp = &tev->point;
  934. char pr;
  935. char *p;
  936. int ret, i, argc;
  937. char **argv;
  938. pr_debug("Parsing probe_events: %s\n", cmd);
  939. argv = argv_split(cmd, &argc);
  940. if (!argv) {
  941. pr_debug("Failed to split arguments.\n");
  942. return -ENOMEM;
  943. }
  944. if (argc < 2) {
  945. semantic_error("Too few probe arguments.\n");
  946. ret = -ERANGE;
  947. goto out;
  948. }
  949. /* Scan event and group name. */
  950. ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
  951. &pr, (float *)(void *)&tev->group,
  952. (float *)(void *)&tev->event);
  953. if (ret != 3) {
  954. semantic_error("Failed to parse event name: %s\n", argv[0]);
  955. ret = -EINVAL;
  956. goto out;
  957. }
  958. pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr);
  959. tp->retprobe = (pr == 'r');
  960. /* Scan module name(if there), function name and offset */
  961. p = strchr(argv[1], ':');
  962. if (p) {
  963. tp->module = strndup(argv[1], p - argv[1]);
  964. p++;
  965. } else
  966. p = argv[1];
  967. ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol,
  968. &tp->offset);
  969. if (ret == 1)
  970. tp->offset = 0;
  971. tev->nargs = argc - 2;
  972. tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
  973. if (tev->args == NULL) {
  974. ret = -ENOMEM;
  975. goto out;
  976. }
  977. for (i = 0; i < tev->nargs; i++) {
  978. p = strchr(argv[i + 2], '=');
  979. if (p) /* We don't need which register is assigned. */
  980. *p++ = '\0';
  981. else
  982. p = argv[i + 2];
  983. tev->args[i].name = strdup(argv[i + 2]);
  984. /* TODO: parse regs and offset */
  985. tev->args[i].value = strdup(p);
  986. if (tev->args[i].name == NULL || tev->args[i].value == NULL) {
  987. ret = -ENOMEM;
  988. goto out;
  989. }
  990. }
  991. ret = 0;
  992. out:
  993. argv_free(argv);
  994. return ret;
  995. }
  996. /* Compose only probe arg */
  997. int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
  998. {
  999. struct perf_probe_arg_field *field = pa->field;
  1000. int ret;
  1001. char *tmp = buf;
  1002. if (pa->name && pa->var)
  1003. ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
  1004. else
  1005. ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
  1006. if (ret <= 0)
  1007. goto error;
  1008. tmp += ret;
  1009. len -= ret;
  1010. while (field) {
  1011. if (field->name[0] == '[')
  1012. ret = e_snprintf(tmp, len, "%s", field->name);
  1013. else
  1014. ret = e_snprintf(tmp, len, "%s%s",
  1015. field->ref ? "->" : ".", field->name);
  1016. if (ret <= 0)
  1017. goto error;
  1018. tmp += ret;
  1019. len -= ret;
  1020. field = field->next;
  1021. }
  1022. if (pa->type) {
  1023. ret = e_snprintf(tmp, len, ":%s", pa->type);
  1024. if (ret <= 0)
  1025. goto error;
  1026. tmp += ret;
  1027. len -= ret;
  1028. }
  1029. return tmp - buf;
  1030. error:
  1031. pr_debug("Failed to synthesize perf probe argument: %s\n",
  1032. strerror(-ret));
  1033. return ret;
  1034. }
  1035. /* Compose only probe point (not argument) */
  1036. static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
  1037. {
  1038. char *buf, *tmp;
  1039. char offs[32] = "", line[32] = "", file[32] = "";
  1040. int ret, len;
  1041. buf = zalloc(MAX_CMDLEN);
  1042. if (buf == NULL) {
  1043. ret = -ENOMEM;
  1044. goto error;
  1045. }
  1046. if (pp->offset) {
  1047. ret = e_snprintf(offs, 32, "+%lu", pp->offset);
  1048. if (ret <= 0)
  1049. goto error;
  1050. }
  1051. if (pp->line) {
  1052. ret = e_snprintf(line, 32, ":%d", pp->line);
  1053. if (ret <= 0)
  1054. goto error;
  1055. }
  1056. if (pp->file) {
  1057. tmp = pp->file;
  1058. len = strlen(tmp);
  1059. if (len > 30) {
  1060. tmp = strchr(pp->file + len - 30, '/');
  1061. tmp = tmp ? tmp + 1 : pp->file + len - 30;
  1062. }
  1063. ret = e_snprintf(file, 32, "@%s", tmp);
  1064. if (ret <= 0)
  1065. goto error;
  1066. }
  1067. if (pp->function)
  1068. ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
  1069. offs, pp->retprobe ? "%return" : "", line,
  1070. file);
  1071. else
  1072. ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
  1073. if (ret <= 0)
  1074. goto error;
  1075. return buf;
  1076. error:
  1077. pr_debug("Failed to synthesize perf probe point: %s\n",
  1078. strerror(-ret));
  1079. if (buf)
  1080. free(buf);
  1081. return NULL;
  1082. }
  1083. #if 0
  1084. char *synthesize_perf_probe_command(struct perf_probe_event *pev)
  1085. {
  1086. char *buf;
  1087. int i, len, ret;
  1088. buf = synthesize_perf_probe_point(&pev->point);
  1089. if (!buf)
  1090. return NULL;
  1091. len = strlen(buf);
  1092. for (i = 0; i < pev->nargs; i++) {
  1093. ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
  1094. pev->args[i].name);
  1095. if (ret <= 0) {
  1096. free(buf);
  1097. return NULL;
  1098. }
  1099. len += ret;
  1100. }
  1101. return buf;
  1102. }
  1103. #endif
  1104. static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
  1105. char **buf, size_t *buflen,
  1106. int depth)
  1107. {
  1108. int ret;
  1109. if (ref->next) {
  1110. depth = __synthesize_probe_trace_arg_ref(ref->next, buf,
  1111. buflen, depth + 1);
  1112. if (depth < 0)
  1113. goto out;
  1114. }
  1115. ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
  1116. if (ret < 0)
  1117. depth = ret;
  1118. else {
  1119. *buf += ret;
  1120. *buflen -= ret;
  1121. }
  1122. out:
  1123. return depth;
  1124. }
  1125. static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
  1126. char *buf, size_t buflen)
  1127. {
  1128. struct probe_trace_arg_ref *ref = arg->ref;
  1129. int ret, depth = 0;
  1130. char *tmp = buf;
  1131. /* Argument name or separator */
  1132. if (arg->name)
  1133. ret = e_snprintf(buf, buflen, " %s=", arg->name);
  1134. else
  1135. ret = e_snprintf(buf, buflen, " ");
  1136. if (ret < 0)
  1137. return ret;
  1138. buf += ret;
  1139. buflen -= ret;
  1140. /* Special case: @XXX */
  1141. if (arg->value[0] == '@' && arg->ref)
  1142. ref = ref->next;
  1143. /* Dereferencing arguments */
  1144. if (ref) {
  1145. depth = __synthesize_probe_trace_arg_ref(ref, &buf,
  1146. &buflen, 1);
  1147. if (depth < 0)
  1148. return depth;
  1149. }
  1150. /* Print argument value */
  1151. if (arg->value[0] == '@' && arg->ref)
  1152. ret = e_snprintf(buf, buflen, "%s%+ld", arg->value,
  1153. arg->ref->offset);
  1154. else
  1155. ret = e_snprintf(buf, buflen, "%s", arg->value);
  1156. if (ret < 0)
  1157. return ret;
  1158. buf += ret;
  1159. buflen -= ret;
  1160. /* Closing */
  1161. while (depth--) {
  1162. ret = e_snprintf(buf, buflen, ")");
  1163. if (ret < 0)
  1164. return ret;
  1165. buf += ret;
  1166. buflen -= ret;
  1167. }
  1168. /* Print argument type */
  1169. if (arg->type) {
  1170. ret = e_snprintf(buf, buflen, ":%s", arg->type);
  1171. if (ret <= 0)
  1172. return ret;
  1173. buf += ret;
  1174. }
  1175. return buf - tmp;
  1176. }
  1177. char *synthesize_probe_trace_command(struct probe_trace_event *tev)
  1178. {
  1179. struct probe_trace_point *tp = &tev->point;
  1180. char *buf;
  1181. int i, len, ret;
  1182. buf = zalloc(MAX_CMDLEN);
  1183. if (buf == NULL)
  1184. return NULL;
  1185. len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu",
  1186. tp->retprobe ? 'r' : 'p',
  1187. tev->group, tev->event,
  1188. tp->module ?: "", tp->module ? ":" : "",
  1189. tp->symbol, tp->offset);
  1190. if (len <= 0)
  1191. goto error;
  1192. for (i = 0; i < tev->nargs; i++) {
  1193. ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
  1194. MAX_CMDLEN - len);
  1195. if (ret <= 0)
  1196. goto error;
  1197. len += ret;
  1198. }
  1199. return buf;
  1200. error:
  1201. free(buf);
  1202. return NULL;
  1203. }
  1204. static int convert_to_perf_probe_event(struct probe_trace_event *tev,
  1205. struct perf_probe_event *pev)
  1206. {
  1207. char buf[64] = "";
  1208. int i, ret;
  1209. /* Convert event/group name */
  1210. pev->event = strdup(tev->event);
  1211. pev->group = strdup(tev->group);
  1212. if (pev->event == NULL || pev->group == NULL)
  1213. return -ENOMEM;
  1214. /* Convert trace_point to probe_point */
  1215. ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point);
  1216. if (ret < 0)
  1217. return ret;
  1218. /* Convert trace_arg to probe_arg */
  1219. pev->nargs = tev->nargs;
  1220. pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
  1221. if (pev->args == NULL)
  1222. return -ENOMEM;
  1223. for (i = 0; i < tev->nargs && ret >= 0; i++) {
  1224. if (tev->args[i].name)
  1225. pev->args[i].name = strdup(tev->args[i].name);
  1226. else {
  1227. ret = synthesize_probe_trace_arg(&tev->args[i],
  1228. buf, 64);
  1229. pev->args[i].name = strdup(buf);
  1230. }
  1231. if (pev->args[i].name == NULL && ret >= 0)
  1232. ret = -ENOMEM;
  1233. }
  1234. if (ret < 0)
  1235. clear_perf_probe_event(pev);
  1236. return ret;
  1237. }
  1238. void clear_perf_probe_event(struct perf_probe_event *pev)
  1239. {
  1240. struct perf_probe_point *pp = &pev->point;
  1241. struct perf_probe_arg_field *field, *next;
  1242. int i;
  1243. if (pev->event)
  1244. free(pev->event);
  1245. if (pev->group)
  1246. free(pev->group);
  1247. if (pp->file)
  1248. free(pp->file);
  1249. if (pp->function)
  1250. free(pp->function);
  1251. if (pp->lazy_line)
  1252. free(pp->lazy_line);
  1253. for (i = 0; i < pev->nargs; i++) {
  1254. if (pev->args[i].name)
  1255. free(pev->args[i].name);
  1256. if (pev->args[i].var)
  1257. free(pev->args[i].var);
  1258. if (pev->args[i].type)
  1259. free(pev->args[i].type);
  1260. field = pev->args[i].field;
  1261. while (field) {
  1262. next = field->next;
  1263. if (field->name)
  1264. free(field->name);
  1265. free(field);
  1266. field = next;
  1267. }
  1268. }
  1269. if (pev->args)
  1270. free(pev->args);
  1271. memset(pev, 0, sizeof(*pev));
  1272. }
  1273. static void clear_probe_trace_event(struct probe_trace_event *tev)
  1274. {
  1275. struct probe_trace_arg_ref *ref, *next;
  1276. int i;
  1277. if (tev->event)
  1278. free(tev->event);
  1279. if (tev->group)
  1280. free(tev->group);
  1281. if (tev->point.symbol)
  1282. free(tev->point.symbol);
  1283. if (tev->point.module)
  1284. free(tev->point.module);
  1285. for (i = 0; i < tev->nargs; i++) {
  1286. if (tev->args[i].name)
  1287. free(tev->args[i].name);
  1288. if (tev->args[i].value)
  1289. free(tev->args[i].value);
  1290. if (tev->args[i].type)
  1291. free(tev->args[i].type);
  1292. ref = tev->args[i].ref;
  1293. while (ref) {
  1294. next = ref->next;
  1295. free(ref);
  1296. ref = next;
  1297. }
  1298. }
  1299. if (tev->args)
  1300. free(tev->args);
  1301. memset(tev, 0, sizeof(*tev));
  1302. }
  1303. static int open_kprobe_events(bool readwrite)
  1304. {
  1305. char buf[PATH_MAX];
  1306. const char *__debugfs;
  1307. int ret;
  1308. __debugfs = debugfs_find_mountpoint();
  1309. if (__debugfs == NULL) {
  1310. pr_warning("Debugfs is not mounted.\n");
  1311. return -ENOENT;
  1312. }
  1313. ret = e_snprintf(buf, PATH_MAX, "%stracing/kprobe_events", __debugfs);
  1314. if (ret >= 0) {
  1315. pr_debug("Opening %s write=%d\n", buf, readwrite);
  1316. if (readwrite && !probe_event_dry_run)
  1317. ret = open(buf, O_RDWR, O_APPEND);
  1318. else
  1319. ret = open(buf, O_RDONLY, 0);
  1320. }
  1321. if (ret < 0) {
  1322. if (errno == ENOENT)
  1323. pr_warning("kprobe_events file does not exist - please"
  1324. " rebuild kernel with CONFIG_KPROBE_EVENT.\n");
  1325. else
  1326. pr_warning("Failed to open kprobe_events file: %s\n",
  1327. strerror(errno));
  1328. }
  1329. return ret;
  1330. }
  1331. /* Get raw string list of current kprobe_events */
  1332. static struct strlist *get_probe_trace_command_rawlist(int fd)
  1333. {
  1334. int ret, idx;
  1335. FILE *fp;
  1336. char buf[MAX_CMDLEN];
  1337. char *p;
  1338. struct strlist *sl;
  1339. sl = strlist__new(true, NULL);
  1340. fp = fdopen(dup(fd), "r");
  1341. while (!feof(fp)) {
  1342. p = fgets(buf, MAX_CMDLEN, fp);
  1343. if (!p)
  1344. break;
  1345. idx = strlen(p) - 1;
  1346. if (p[idx] == '\n')
  1347. p[idx] = '\0';
  1348. ret = strlist__add(sl, buf);
  1349. if (ret < 0) {
  1350. pr_debug("strlist__add failed: %s\n", strerror(-ret));
  1351. strlist__delete(sl);
  1352. return NULL;
  1353. }
  1354. }
  1355. fclose(fp);
  1356. return sl;
  1357. }
  1358. /* Show an event */
  1359. static int show_perf_probe_event(struct perf_probe_event *pev)
  1360. {
  1361. int i, ret;
  1362. char buf[128];
  1363. char *place;
  1364. /* Synthesize only event probe point */
  1365. place = synthesize_perf_probe_point(&pev->point);
  1366. if (!place)
  1367. return -EINVAL;
  1368. ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
  1369. if (ret < 0)
  1370. return ret;
  1371. printf(" %-20s (on %s", buf, place);
  1372. if (pev->nargs > 0) {
  1373. printf(" with");
  1374. for (i = 0; i < pev->nargs; i++) {
  1375. ret = synthesize_perf_probe_arg(&pev->args[i],
  1376. buf, 128);
  1377. if (ret < 0)
  1378. break;
  1379. printf(" %s", buf);
  1380. }
  1381. }
  1382. printf(")\n");
  1383. free(place);
  1384. return ret;
  1385. }
  1386. /* List up current perf-probe events */
  1387. int show_perf_probe_events(void)
  1388. {
  1389. int fd, ret;
  1390. struct probe_trace_event tev;
  1391. struct perf_probe_event pev;
  1392. struct strlist *rawlist;
  1393. struct str_node *ent;
  1394. setup_pager();
  1395. ret = init_vmlinux();
  1396. if (ret < 0)
  1397. return ret;
  1398. memset(&tev, 0, sizeof(tev));
  1399. memset(&pev, 0, sizeof(pev));
  1400. fd = open_kprobe_events(false);
  1401. if (fd < 0)
  1402. return fd;
  1403. rawlist = get_probe_trace_command_rawlist(fd);
  1404. close(fd);
  1405. if (!rawlist)
  1406. return -ENOENT;
  1407. strlist__for_each(ent, rawlist) {
  1408. ret = parse_probe_trace_command(ent->s, &tev);
  1409. if (ret >= 0) {
  1410. ret = convert_to_perf_probe_event(&tev, &pev);
  1411. if (ret >= 0)
  1412. ret = show_perf_probe_event(&pev);
  1413. }
  1414. clear_perf_probe_event(&pev);
  1415. clear_probe_trace_event(&tev);
  1416. if (ret < 0)
  1417. break;
  1418. }
  1419. strlist__delete(rawlist);
  1420. return ret;
  1421. }
  1422. /* Get current perf-probe event names */
  1423. static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
  1424. {
  1425. char buf[128];
  1426. struct strlist *sl, *rawlist;
  1427. struct str_node *ent;
  1428. struct probe_trace_event tev;
  1429. int ret = 0;
  1430. memset(&tev, 0, sizeof(tev));
  1431. rawlist = get_probe_trace_command_rawlist(fd);
  1432. sl = strlist__new(true, NULL);
  1433. strlist__for_each(ent, rawlist) {
  1434. ret = parse_probe_trace_command(ent->s, &tev);
  1435. if (ret < 0)
  1436. break;
  1437. if (include_group) {
  1438. ret = e_snprintf(buf, 128, "%s:%s", tev.group,
  1439. tev.event);
  1440. if (ret >= 0)
  1441. ret = strlist__add(sl, buf);
  1442. } else
  1443. ret = strlist__add(sl, tev.event);
  1444. clear_probe_trace_event(&tev);
  1445. if (ret < 0)
  1446. break;
  1447. }
  1448. strlist__delete(rawlist);
  1449. if (ret < 0) {
  1450. strlist__delete(sl);
  1451. return NULL;
  1452. }
  1453. return sl;
  1454. }
  1455. static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
  1456. {
  1457. int ret = 0;
  1458. char *buf = synthesize_probe_trace_command(tev);
  1459. if (!buf) {
  1460. pr_debug("Failed to synthesize probe trace event.\n");
  1461. return -EINVAL;
  1462. }
  1463. pr_debug("Writing event: %s\n", buf);
  1464. if (!probe_event_dry_run) {
  1465. ret = write(fd, buf, strlen(buf));
  1466. if (ret <= 0)
  1467. pr_warning("Failed to write event: %s\n",
  1468. strerror(errno));
  1469. }
  1470. free(buf);
  1471. return ret;
  1472. }
  1473. static int get_new_event_name(char *buf, size_t len, const char *base,
  1474. struct strlist *namelist, bool allow_suffix)
  1475. {
  1476. int i, ret;
  1477. /* Try no suffix */
  1478. ret = e_snprintf(buf, len, "%s", base);
  1479. if (ret < 0) {
  1480. pr_debug("snprintf() failed: %s\n", strerror(-ret));
  1481. return ret;
  1482. }
  1483. if (!strlist__has_entry(namelist, buf))
  1484. return 0;
  1485. if (!allow_suffix) {
  1486. pr_warning("Error: event \"%s\" already exists. "
  1487. "(Use -f to force duplicates.)\n", base);
  1488. return -EEXIST;
  1489. }
  1490. /* Try to add suffix */
  1491. for (i = 1; i < MAX_EVENT_INDEX; i++) {
  1492. ret = e_snprintf(buf, len, "%s_%d", base, i);
  1493. if (ret < 0) {
  1494. pr_debug("snprintf() failed: %s\n", strerror(-ret));
  1495. return ret;
  1496. }
  1497. if (!strlist__has_entry(namelist, buf))
  1498. break;
  1499. }
  1500. if (i == MAX_EVENT_INDEX) {
  1501. pr_warning("Too many events are on the same function.\n");
  1502. ret = -ERANGE;
  1503. }
  1504. return ret;
  1505. }
  1506. static int __add_probe_trace_events(struct perf_probe_event *pev,
  1507. struct probe_trace_event *tevs,
  1508. int ntevs, bool allow_suffix)
  1509. {
  1510. int i, fd, ret;
  1511. struct probe_trace_event *tev = NULL;
  1512. char buf[64];
  1513. const char *event, *group;
  1514. struct strlist *namelist;
  1515. fd = open_kprobe_events(true);
  1516. if (fd < 0)
  1517. return fd;
  1518. /* Get current event names */
  1519. namelist = get_probe_trace_event_names(fd, false);
  1520. if (!namelist) {
  1521. pr_debug("Failed to get current event list.\n");
  1522. return -EIO;
  1523. }
  1524. ret = 0;
  1525. printf("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
  1526. for (i = 0; i < ntevs; i++) {
  1527. tev = &tevs[i];
  1528. if (pev->event)
  1529. event = pev->event;
  1530. else
  1531. if (pev->point.function)
  1532. event = pev->point.function;
  1533. else
  1534. event = tev->point.symbol;
  1535. if (pev->group)
  1536. group = pev->group;
  1537. else
  1538. group = PERFPROBE_GROUP;
  1539. /* Get an unused new event name */
  1540. ret = get_new_event_name(buf, 64, event,
  1541. namelist, allow_suffix);
  1542. if (ret < 0)
  1543. break;
  1544. event = buf;
  1545. tev->event = strdup(event);
  1546. tev->group = strdup(group);
  1547. if (tev->event == NULL || tev->group == NULL) {
  1548. ret = -ENOMEM;
  1549. break;
  1550. }
  1551. ret = write_probe_trace_event(fd, tev);
  1552. if (ret < 0)
  1553. break;
  1554. /* Add added event name to namelist */
  1555. strlist__add(namelist, event);
  1556. /* Trick here - save current event/group */
  1557. event = pev->event;
  1558. group = pev->group;
  1559. pev->event = tev->event;
  1560. pev->group = tev->group;
  1561. show_perf_probe_event(pev);
  1562. /* Trick here - restore current event/group */
  1563. pev->event = (char *)event;
  1564. pev->group = (char *)group;
  1565. /*
  1566. * Probes after the first probe which comes from same
  1567. * user input are always allowed to add suffix, because
  1568. * there might be several addresses corresponding to
  1569. * one code line.
  1570. */
  1571. allow_suffix = true;
  1572. }
  1573. if (ret >= 0) {
  1574. /* Show how to use the event. */
  1575. printf("\nYou can now use it in all perf tools, such as:\n\n");
  1576. printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
  1577. tev->event);
  1578. }
  1579. strlist__delete(namelist);
  1580. close(fd);
  1581. return ret;
  1582. }
  1583. static int convert_to_probe_trace_events(struct perf_probe_event *pev,
  1584. struct probe_trace_event **tevs,
  1585. int max_tevs, const char *target)
  1586. {
  1587. struct symbol *sym;
  1588. int ret = 0, i;
  1589. struct probe_trace_event *tev;
  1590. /* Convert perf_probe_event with debuginfo */
  1591. ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target);
  1592. if (ret != 0)
  1593. return ret; /* Found in debuginfo or got an error */
  1594. /* Allocate trace event buffer */
  1595. tev = *tevs = zalloc(sizeof(struct probe_trace_event));
  1596. if (tev == NULL)
  1597. return -ENOMEM;
  1598. /* Copy parameters */
  1599. tev->point.symbol = strdup(pev->point.function);
  1600. if (tev->point.symbol == NULL) {
  1601. ret = -ENOMEM;
  1602. goto error;
  1603. }
  1604. if (target) {
  1605. tev->point.module = strdup(target);
  1606. if (tev->point.module == NULL) {
  1607. ret = -ENOMEM;
  1608. goto error;
  1609. }
  1610. }
  1611. tev->point.offset = pev->point.offset;
  1612. tev->point.retprobe = pev->point.retprobe;
  1613. tev->nargs = pev->nargs;
  1614. if (tev->nargs) {
  1615. tev->args = zalloc(sizeof(struct probe_trace_arg)
  1616. * tev->nargs);
  1617. if (tev->args == NULL) {
  1618. ret = -ENOMEM;
  1619. goto error;
  1620. }
  1621. for (i = 0; i < tev->nargs; i++) {
  1622. if (pev->args[i].name) {
  1623. tev->args[i].name = strdup(pev->args[i].name);
  1624. if (tev->args[i].name == NULL) {
  1625. ret = -ENOMEM;
  1626. goto error;
  1627. }
  1628. }
  1629. tev->args[i].value = strdup(pev->args[i].var);
  1630. if (tev->args[i].value == NULL) {
  1631. ret = -ENOMEM;
  1632. goto error;
  1633. }
  1634. if (pev->args[i].type) {
  1635. tev->args[i].type = strdup(pev->args[i].type);
  1636. if (tev->args[i].type == NULL) {
  1637. ret = -ENOMEM;
  1638. goto error;
  1639. }
  1640. }
  1641. }
  1642. }
  1643. /* Currently just checking function name from symbol map */
  1644. sym = __find_kernel_function_by_name(tev->point.symbol, NULL);
  1645. if (!sym) {
  1646. pr_warning("Kernel symbol \'%s\' not found.\n",
  1647. tev->point.symbol);
  1648. ret = -ENOENT;
  1649. goto error;
  1650. } else if (tev->point.offset > sym->end - sym->start) {
  1651. pr_warning("Offset specified is greater than size of %s\n",
  1652. tev->point.symbol);
  1653. ret = -ENOENT;
  1654. goto error;
  1655. }
  1656. return 1;
  1657. error:
  1658. clear_probe_trace_event(tev);
  1659. free(tev);
  1660. *tevs = NULL;
  1661. return ret;
  1662. }
  1663. struct __event_package {
  1664. struct perf_probe_event *pev;
  1665. struct probe_trace_event *tevs;
  1666. int ntevs;
  1667. };
  1668. int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
  1669. int max_tevs, const char *target, bool force_add)
  1670. {
  1671. int i, j, ret;
  1672. struct __event_package *pkgs;
  1673. pkgs = zalloc(sizeof(struct __event_package) * npevs);
  1674. if (pkgs == NULL)
  1675. return -ENOMEM;
  1676. /* Init vmlinux path */
  1677. ret = init_vmlinux();
  1678. if (ret < 0) {
  1679. free(pkgs);
  1680. return ret;
  1681. }
  1682. /* Loop 1: convert all events */
  1683. for (i = 0; i < npevs; i++) {
  1684. pkgs[i].pev = &pevs[i];
  1685. /* Convert with or without debuginfo */
  1686. ret = convert_to_probe_trace_events(pkgs[i].pev,
  1687. &pkgs[i].tevs,
  1688. max_tevs,
  1689. target);
  1690. if (ret < 0)
  1691. goto end;
  1692. pkgs[i].ntevs = ret;
  1693. }
  1694. /* Loop 2: add all events */
  1695. for (i = 0; i < npevs; i++) {
  1696. ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
  1697. pkgs[i].ntevs, force_add);
  1698. if (ret < 0)
  1699. break;
  1700. }
  1701. end:
  1702. /* Loop 3: cleanup and free trace events */
  1703. for (i = 0; i < npevs; i++) {
  1704. for (j = 0; j < pkgs[i].ntevs; j++)
  1705. clear_probe_trace_event(&pkgs[i].tevs[j]);
  1706. free(pkgs[i].tevs);
  1707. }
  1708. free(pkgs);
  1709. return ret;
  1710. }
  1711. static int __del_trace_probe_event(int fd, struct str_node *ent)
  1712. {
  1713. char *p;
  1714. char buf[128];
  1715. int ret;
  1716. /* Convert from perf-probe event to trace-probe event */
  1717. ret = e_snprintf(buf, 128, "-:%s", ent->s);
  1718. if (ret < 0)
  1719. goto error;
  1720. p = strchr(buf + 2, ':');
  1721. if (!p) {
  1722. pr_debug("Internal error: %s should have ':' but not.\n",
  1723. ent->s);
  1724. ret = -ENOTSUP;
  1725. goto error;
  1726. }
  1727. *p = '/';
  1728. pr_debug("Writing event: %s\n", buf);
  1729. ret = write(fd, buf, strlen(buf));
  1730. if (ret < 0) {
  1731. ret = -errno;
  1732. goto error;
  1733. }
  1734. printf("Removed event: %s\n", ent->s);
  1735. return 0;
  1736. error:
  1737. pr_warning("Failed to delete event: %s\n", strerror(-ret));
  1738. return ret;
  1739. }
  1740. static int del_trace_probe_event(int fd, const char *group,
  1741. const char *event, struct strlist *namelist)
  1742. {
  1743. char buf[128];
  1744. struct str_node *ent, *n;
  1745. int found = 0, ret = 0;
  1746. ret = e_snprintf(buf, 128, "%s:%s", group, event);
  1747. if (ret < 0) {
  1748. pr_err("Failed to copy event.\n");
  1749. return ret;
  1750. }
  1751. if (strpbrk(buf, "*?")) { /* Glob-exp */
  1752. strlist__for_each_safe(ent, n, namelist)
  1753. if (strglobmatch(ent->s, buf)) {
  1754. found++;
  1755. ret = __del_trace_probe_event(fd, ent);
  1756. if (ret < 0)
  1757. break;
  1758. strlist__remove(namelist, ent);
  1759. }
  1760. } else {
  1761. ent = strlist__find(namelist, buf);
  1762. if (ent) {
  1763. found++;
  1764. ret = __del_trace_probe_event(fd, ent);
  1765. if (ret >= 0)
  1766. strlist__remove(namelist, ent);
  1767. }
  1768. }
  1769. if (found == 0 && ret >= 0)
  1770. pr_info("Info: Event \"%s\" does not exist.\n", buf);
  1771. return ret;
  1772. }
  1773. int del_perf_probe_events(struct strlist *dellist)
  1774. {
  1775. int fd, ret = 0;
  1776. const char *group, *event;
  1777. char *p, *str;
  1778. struct str_node *ent;
  1779. struct strlist *namelist;
  1780. fd = open_kprobe_events(true);
  1781. if (fd < 0)
  1782. return fd;
  1783. /* Get current event names */
  1784. namelist = get_probe_trace_event_names(fd, true);
  1785. if (namelist == NULL)
  1786. return -EINVAL;
  1787. strlist__for_each(ent, dellist) {
  1788. str = strdup(ent->s);
  1789. if (str == NULL) {
  1790. ret = -ENOMEM;
  1791. break;
  1792. }
  1793. pr_debug("Parsing: %s\n", str);
  1794. p = strchr(str, ':');
  1795. if (p) {
  1796. group = str;
  1797. *p = '\0';
  1798. event = p + 1;
  1799. } else {
  1800. group = "*";
  1801. event = str;
  1802. }
  1803. pr_debug("Group: %s, Event: %s\n", group, event);
  1804. ret = del_trace_probe_event(fd, group, event, namelist);
  1805. free(str);
  1806. if (ret < 0)
  1807. break;
  1808. }
  1809. strlist__delete(namelist);
  1810. close(fd);
  1811. return ret;
  1812. }
  1813. /* TODO: don't use a global variable for filter ... */
  1814. static struct strfilter *available_func_filter;
  1815. /*
  1816. * If a symbol corresponds to a function with global binding and
  1817. * matches filter return 0. For all others return 1.
  1818. */
  1819. static int filter_available_functions(struct map *map __unused,
  1820. struct symbol *sym)
  1821. {
  1822. if (sym->binding == STB_GLOBAL &&
  1823. strfilter__compare(available_func_filter, sym->name))
  1824. return 0;
  1825. return 1;
  1826. }
  1827. int show_available_funcs(const char *target, struct strfilter *_filter)
  1828. {
  1829. struct map *map;
  1830. int ret;
  1831. setup_pager();
  1832. ret = init_vmlinux();
  1833. if (ret < 0)
  1834. return ret;
  1835. map = kernel_get_module_map(target);
  1836. if (!map) {
  1837. pr_err("Failed to find %s map.\n", (target) ? : "kernel");
  1838. return -EINVAL;
  1839. }
  1840. available_func_filter = _filter;
  1841. if (map__load(map, filter_available_functions)) {
  1842. pr_err("Failed to load map.\n");
  1843. return -EINVAL;
  1844. }
  1845. if (!dso__sorted_by_name(map->dso, map->type))
  1846. dso__sort_by_name(map->dso, map->type);
  1847. dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
  1848. return 0;
  1849. }