trace-event-parse.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172
  1. /*
  2. * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
  3. *
  4. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  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; version 2 of the License (not later!)
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. *
  21. * The parts for function graph printing was taken and modified from the
  22. * Linux Kernel that were written by Frederic Weisbecker.
  23. */
  24. #define _GNU_SOURCE
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <errno.h>
  30. #undef _GNU_SOURCE
  31. #include "../perf.h"
  32. #include "util.h"
  33. #include "trace-event.h"
  34. int header_page_ts_offset;
  35. int header_page_ts_size;
  36. int header_page_size_offset;
  37. int header_page_size_size;
  38. int header_page_overwrite_offset;
  39. int header_page_overwrite_size;
  40. int header_page_data_offset;
  41. int header_page_data_size;
  42. bool latency_format;
  43. static char *input_buf;
  44. static unsigned long long input_buf_ptr;
  45. static unsigned long long input_buf_siz;
  46. static int cpus;
  47. static int long_size;
  48. static int is_flag_field;
  49. static int is_symbolic_field;
  50. static struct format_field *
  51. find_any_field(struct event *event, const char *name);
  52. static void init_input_buf(char *buf, unsigned long long size)
  53. {
  54. input_buf = buf;
  55. input_buf_siz = size;
  56. input_buf_ptr = 0;
  57. }
  58. struct cmdline {
  59. char *comm;
  60. int pid;
  61. };
  62. static struct cmdline *cmdlines;
  63. static int cmdline_count;
  64. static int cmdline_cmp(const void *a, const void *b)
  65. {
  66. const struct cmdline *ca = a;
  67. const struct cmdline *cb = b;
  68. if (ca->pid < cb->pid)
  69. return -1;
  70. if (ca->pid > cb->pid)
  71. return 1;
  72. return 0;
  73. }
  74. void parse_cmdlines(char *file, int size __unused)
  75. {
  76. struct cmdline_list {
  77. struct cmdline_list *next;
  78. char *comm;
  79. int pid;
  80. } *list = NULL, *item;
  81. char *line;
  82. char *next = NULL;
  83. int i;
  84. line = strtok_r(file, "\n", &next);
  85. while (line) {
  86. item = malloc_or_die(sizeof(*item));
  87. sscanf(line, "%d %as", &item->pid,
  88. (float *)(void *)&item->comm); /* workaround gcc warning */
  89. item->next = list;
  90. list = item;
  91. line = strtok_r(NULL, "\n", &next);
  92. cmdline_count++;
  93. }
  94. cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
  95. i = 0;
  96. while (list) {
  97. cmdlines[i].pid = list->pid;
  98. cmdlines[i].comm = list->comm;
  99. i++;
  100. item = list;
  101. list = list->next;
  102. free(item);
  103. }
  104. qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
  105. }
  106. static struct func_map {
  107. unsigned long long addr;
  108. char *func;
  109. char *mod;
  110. } *func_list;
  111. static unsigned int func_count;
  112. static int func_cmp(const void *a, const void *b)
  113. {
  114. const struct func_map *fa = a;
  115. const struct func_map *fb = b;
  116. if (fa->addr < fb->addr)
  117. return -1;
  118. if (fa->addr > fb->addr)
  119. return 1;
  120. return 0;
  121. }
  122. void parse_proc_kallsyms(char *file, unsigned int size __unused)
  123. {
  124. struct func_list {
  125. struct func_list *next;
  126. unsigned long long addr;
  127. char *func;
  128. char *mod;
  129. } *list = NULL, *item;
  130. char *line;
  131. char *next = NULL;
  132. char *addr_str;
  133. char ch;
  134. int ret __used;
  135. int i;
  136. line = strtok_r(file, "\n", &next);
  137. while (line) {
  138. item = malloc_or_die(sizeof(*item));
  139. item->mod = NULL;
  140. ret = sscanf(line, "%as %c %as\t[%as",
  141. (float *)(void *)&addr_str, /* workaround gcc warning */
  142. &ch,
  143. (float *)(void *)&item->func,
  144. (float *)(void *)&item->mod);
  145. item->addr = strtoull(addr_str, NULL, 16);
  146. free(addr_str);
  147. /* truncate the extra ']' */
  148. if (item->mod)
  149. item->mod[strlen(item->mod) - 1] = 0;
  150. item->next = list;
  151. list = item;
  152. line = strtok_r(NULL, "\n", &next);
  153. func_count++;
  154. }
  155. func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
  156. i = 0;
  157. while (list) {
  158. func_list[i].func = list->func;
  159. func_list[i].addr = list->addr;
  160. func_list[i].mod = list->mod;
  161. i++;
  162. item = list;
  163. list = list->next;
  164. free(item);
  165. }
  166. qsort(func_list, func_count, sizeof(*func_list), func_cmp);
  167. /*
  168. * Add a special record at the end.
  169. */
  170. func_list[func_count].func = NULL;
  171. func_list[func_count].addr = 0;
  172. func_list[func_count].mod = NULL;
  173. }
  174. /*
  175. * We are searching for a record in between, not an exact
  176. * match.
  177. */
  178. static int func_bcmp(const void *a, const void *b)
  179. {
  180. const struct func_map *fa = a;
  181. const struct func_map *fb = b;
  182. if ((fa->addr == fb->addr) ||
  183. (fa->addr > fb->addr &&
  184. fa->addr < (fb+1)->addr))
  185. return 0;
  186. if (fa->addr < fb->addr)
  187. return -1;
  188. return 1;
  189. }
  190. static struct func_map *find_func(unsigned long long addr)
  191. {
  192. struct func_map *func;
  193. struct func_map key;
  194. key.addr = addr;
  195. func = bsearch(&key, func_list, func_count, sizeof(*func_list),
  196. func_bcmp);
  197. return func;
  198. }
  199. void print_funcs(void)
  200. {
  201. int i;
  202. for (i = 0; i < (int)func_count; i++) {
  203. printf("%016llx %s",
  204. func_list[i].addr,
  205. func_list[i].func);
  206. if (func_list[i].mod)
  207. printf(" [%s]\n", func_list[i].mod);
  208. else
  209. printf("\n");
  210. }
  211. }
  212. static struct printk_map {
  213. unsigned long long addr;
  214. char *printk;
  215. } *printk_list;
  216. static unsigned int printk_count;
  217. static int printk_cmp(const void *a, const void *b)
  218. {
  219. const struct func_map *fa = a;
  220. const struct func_map *fb = b;
  221. if (fa->addr < fb->addr)
  222. return -1;
  223. if (fa->addr > fb->addr)
  224. return 1;
  225. return 0;
  226. }
  227. static struct printk_map *find_printk(unsigned long long addr)
  228. {
  229. struct printk_map *printk;
  230. struct printk_map key;
  231. key.addr = addr;
  232. printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
  233. printk_cmp);
  234. return printk;
  235. }
  236. void parse_ftrace_printk(char *file, unsigned int size __unused)
  237. {
  238. struct printk_list {
  239. struct printk_list *next;
  240. unsigned long long addr;
  241. char *printk;
  242. } *list = NULL, *item;
  243. char *line;
  244. char *next = NULL;
  245. char *addr_str;
  246. int i;
  247. line = strtok_r(file, "\n", &next);
  248. while (line) {
  249. addr_str = strsep(&line, ":");
  250. if (!line) {
  251. warning("error parsing print strings");
  252. break;
  253. }
  254. item = malloc_or_die(sizeof(*item));
  255. item->addr = strtoull(addr_str, NULL, 16);
  256. /* fmt still has a space, skip it */
  257. item->printk = strdup(line+1);
  258. item->next = list;
  259. list = item;
  260. line = strtok_r(NULL, "\n", &next);
  261. printk_count++;
  262. }
  263. printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
  264. i = 0;
  265. while (list) {
  266. printk_list[i].printk = list->printk;
  267. printk_list[i].addr = list->addr;
  268. i++;
  269. item = list;
  270. list = list->next;
  271. free(item);
  272. }
  273. qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
  274. }
  275. void print_printk(void)
  276. {
  277. int i;
  278. for (i = 0; i < (int)printk_count; i++) {
  279. printf("%016llx %s\n",
  280. printk_list[i].addr,
  281. printk_list[i].printk);
  282. }
  283. }
  284. static struct event *alloc_event(void)
  285. {
  286. struct event *event;
  287. event = malloc_or_die(sizeof(*event));
  288. memset(event, 0, sizeof(*event));
  289. return event;
  290. }
  291. enum event_type {
  292. EVENT_ERROR,
  293. EVENT_NONE,
  294. EVENT_SPACE,
  295. EVENT_NEWLINE,
  296. EVENT_OP,
  297. EVENT_DELIM,
  298. EVENT_ITEM,
  299. EVENT_DQUOTE,
  300. EVENT_SQUOTE,
  301. };
  302. static struct event *event_list;
  303. static void add_event(struct event *event)
  304. {
  305. event->next = event_list;
  306. event_list = event;
  307. }
  308. static int event_item_type(enum event_type type)
  309. {
  310. switch (type) {
  311. case EVENT_ITEM ... EVENT_SQUOTE:
  312. return 1;
  313. case EVENT_ERROR ... EVENT_DELIM:
  314. default:
  315. return 0;
  316. }
  317. }
  318. static void free_arg(struct print_arg *arg)
  319. {
  320. if (!arg)
  321. return;
  322. switch (arg->type) {
  323. case PRINT_ATOM:
  324. if (arg->atom.atom)
  325. free(arg->atom.atom);
  326. break;
  327. case PRINT_NULL:
  328. case PRINT_FIELD ... PRINT_OP:
  329. default:
  330. /* todo */
  331. break;
  332. }
  333. free(arg);
  334. }
  335. static enum event_type get_type(int ch)
  336. {
  337. if (ch == '\n')
  338. return EVENT_NEWLINE;
  339. if (isspace(ch))
  340. return EVENT_SPACE;
  341. if (isalnum(ch) || ch == '_')
  342. return EVENT_ITEM;
  343. if (ch == '\'')
  344. return EVENT_SQUOTE;
  345. if (ch == '"')
  346. return EVENT_DQUOTE;
  347. if (!isprint(ch))
  348. return EVENT_NONE;
  349. if (ch == '(' || ch == ')' || ch == ',')
  350. return EVENT_DELIM;
  351. return EVENT_OP;
  352. }
  353. static int __read_char(void)
  354. {
  355. if (input_buf_ptr >= input_buf_siz)
  356. return -1;
  357. return input_buf[input_buf_ptr++];
  358. }
  359. static int __peek_char(void)
  360. {
  361. if (input_buf_ptr >= input_buf_siz)
  362. return -1;
  363. return input_buf[input_buf_ptr];
  364. }
  365. static enum event_type __read_token(char **tok)
  366. {
  367. char buf[BUFSIZ];
  368. int ch, last_ch, quote_ch, next_ch;
  369. int i = 0;
  370. int tok_size = 0;
  371. enum event_type type;
  372. *tok = NULL;
  373. ch = __read_char();
  374. if (ch < 0)
  375. return EVENT_NONE;
  376. type = get_type(ch);
  377. if (type == EVENT_NONE)
  378. return type;
  379. buf[i++] = ch;
  380. switch (type) {
  381. case EVENT_NEWLINE:
  382. case EVENT_DELIM:
  383. *tok = malloc_or_die(2);
  384. (*tok)[0] = ch;
  385. (*tok)[1] = 0;
  386. return type;
  387. case EVENT_OP:
  388. switch (ch) {
  389. case '-':
  390. next_ch = __peek_char();
  391. if (next_ch == '>') {
  392. buf[i++] = __read_char();
  393. break;
  394. }
  395. /* fall through */
  396. case '+':
  397. case '|':
  398. case '&':
  399. case '>':
  400. case '<':
  401. last_ch = ch;
  402. ch = __peek_char();
  403. if (ch != last_ch)
  404. goto test_equal;
  405. buf[i++] = __read_char();
  406. switch (last_ch) {
  407. case '>':
  408. case '<':
  409. goto test_equal;
  410. default:
  411. break;
  412. }
  413. break;
  414. case '!':
  415. case '=':
  416. goto test_equal;
  417. default: /* what should we do instead? */
  418. break;
  419. }
  420. buf[i] = 0;
  421. *tok = strdup(buf);
  422. return type;
  423. test_equal:
  424. ch = __peek_char();
  425. if (ch == '=')
  426. buf[i++] = __read_char();
  427. break;
  428. case EVENT_DQUOTE:
  429. case EVENT_SQUOTE:
  430. /* don't keep quotes */
  431. i--;
  432. quote_ch = ch;
  433. last_ch = 0;
  434. do {
  435. if (i == (BUFSIZ - 1)) {
  436. buf[i] = 0;
  437. if (*tok) {
  438. *tok = realloc(*tok, tok_size + BUFSIZ);
  439. if (!*tok)
  440. return EVENT_NONE;
  441. strcat(*tok, buf);
  442. } else
  443. *tok = strdup(buf);
  444. if (!*tok)
  445. return EVENT_NONE;
  446. tok_size += BUFSIZ;
  447. i = 0;
  448. }
  449. last_ch = ch;
  450. ch = __read_char();
  451. buf[i++] = ch;
  452. /* the '\' '\' will cancel itself */
  453. if (ch == '\\' && last_ch == '\\')
  454. last_ch = 0;
  455. } while (ch != quote_ch || last_ch == '\\');
  456. /* remove the last quote */
  457. i--;
  458. goto out;
  459. case EVENT_ERROR ... EVENT_SPACE:
  460. case EVENT_ITEM:
  461. default:
  462. break;
  463. }
  464. while (get_type(__peek_char()) == type) {
  465. if (i == (BUFSIZ - 1)) {
  466. buf[i] = 0;
  467. if (*tok) {
  468. *tok = realloc(*tok, tok_size + BUFSIZ);
  469. if (!*tok)
  470. return EVENT_NONE;
  471. strcat(*tok, buf);
  472. } else
  473. *tok = strdup(buf);
  474. if (!*tok)
  475. return EVENT_NONE;
  476. tok_size += BUFSIZ;
  477. i = 0;
  478. }
  479. ch = __read_char();
  480. buf[i++] = ch;
  481. }
  482. out:
  483. buf[i] = 0;
  484. if (*tok) {
  485. *tok = realloc(*tok, tok_size + i);
  486. if (!*tok)
  487. return EVENT_NONE;
  488. strcat(*tok, buf);
  489. } else
  490. *tok = strdup(buf);
  491. if (!*tok)
  492. return EVENT_NONE;
  493. return type;
  494. }
  495. static void free_token(char *tok)
  496. {
  497. if (tok)
  498. free(tok);
  499. }
  500. static enum event_type read_token(char **tok)
  501. {
  502. enum event_type type;
  503. for (;;) {
  504. type = __read_token(tok);
  505. if (type != EVENT_SPACE)
  506. return type;
  507. free_token(*tok);
  508. }
  509. /* not reached */
  510. return EVENT_NONE;
  511. }
  512. /* no newline */
  513. static enum event_type read_token_item(char **tok)
  514. {
  515. enum event_type type;
  516. for (;;) {
  517. type = __read_token(tok);
  518. if (type != EVENT_SPACE && type != EVENT_NEWLINE)
  519. return type;
  520. free_token(*tok);
  521. }
  522. /* not reached */
  523. return EVENT_NONE;
  524. }
  525. static int test_type(enum event_type type, enum event_type expect)
  526. {
  527. if (type != expect) {
  528. warning("Error: expected type %d but read %d",
  529. expect, type);
  530. return -1;
  531. }
  532. return 0;
  533. }
  534. static int __test_type_token(enum event_type type, char *token,
  535. enum event_type expect, const char *expect_tok,
  536. bool warn)
  537. {
  538. if (type != expect) {
  539. if (warn)
  540. warning("Error: expected type %d but read %d",
  541. expect, type);
  542. return -1;
  543. }
  544. if (strcmp(token, expect_tok) != 0) {
  545. if (warn)
  546. warning("Error: expected '%s' but read '%s'",
  547. expect_tok, token);
  548. return -1;
  549. }
  550. return 0;
  551. }
  552. static int test_type_token(enum event_type type, char *token,
  553. enum event_type expect, const char *expect_tok)
  554. {
  555. return __test_type_token(type, token, expect, expect_tok, true);
  556. }
  557. static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
  558. {
  559. enum event_type type;
  560. if (newline_ok)
  561. type = read_token(tok);
  562. else
  563. type = read_token_item(tok);
  564. return test_type(type, expect);
  565. }
  566. static int read_expect_type(enum event_type expect, char **tok)
  567. {
  568. return __read_expect_type(expect, tok, 1);
  569. }
  570. static int __read_expected(enum event_type expect, const char *str,
  571. int newline_ok, bool warn)
  572. {
  573. enum event_type type;
  574. char *token;
  575. int ret;
  576. if (newline_ok)
  577. type = read_token(&token);
  578. else
  579. type = read_token_item(&token);
  580. ret = __test_type_token(type, token, expect, str, warn);
  581. free_token(token);
  582. return ret;
  583. }
  584. static int read_expected(enum event_type expect, const char *str)
  585. {
  586. return __read_expected(expect, str, 1, true);
  587. }
  588. static int read_expected_item(enum event_type expect, const char *str)
  589. {
  590. return __read_expected(expect, str, 0, true);
  591. }
  592. static char *event_read_name(void)
  593. {
  594. char *token;
  595. if (read_expected(EVENT_ITEM, "name") < 0)
  596. return NULL;
  597. if (read_expected(EVENT_OP, ":") < 0)
  598. return NULL;
  599. if (read_expect_type(EVENT_ITEM, &token) < 0)
  600. goto fail;
  601. return token;
  602. fail:
  603. free_token(token);
  604. return NULL;
  605. }
  606. static int event_read_id(void)
  607. {
  608. char *token;
  609. int id;
  610. if (read_expected_item(EVENT_ITEM, "ID") < 0)
  611. return -1;
  612. if (read_expected(EVENT_OP, ":") < 0)
  613. return -1;
  614. if (read_expect_type(EVENT_ITEM, &token) < 0)
  615. goto fail;
  616. id = strtoul(token, NULL, 0);
  617. free_token(token);
  618. return id;
  619. fail:
  620. free_token(token);
  621. return -1;
  622. }
  623. static int field_is_string(struct format_field *field)
  624. {
  625. if ((field->flags & FIELD_IS_ARRAY) &&
  626. (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
  627. !strstr(field->type, "s8")))
  628. return 1;
  629. return 0;
  630. }
  631. static int field_is_dynamic(struct format_field *field)
  632. {
  633. if (!strncmp(field->type, "__data_loc", 10))
  634. return 1;
  635. return 0;
  636. }
  637. static int event_read_fields(struct event *event, struct format_field **fields)
  638. {
  639. struct format_field *field = NULL;
  640. enum event_type type;
  641. char *token;
  642. char *last_token;
  643. int count = 0;
  644. do {
  645. type = read_token(&token);
  646. if (type == EVENT_NEWLINE) {
  647. free_token(token);
  648. return count;
  649. }
  650. count++;
  651. if (test_type_token(type, token, EVENT_ITEM, "field"))
  652. goto fail;
  653. free_token(token);
  654. type = read_token(&token);
  655. /*
  656. * The ftrace fields may still use the "special" name.
  657. * Just ignore it.
  658. */
  659. if (event->flags & EVENT_FL_ISFTRACE &&
  660. type == EVENT_ITEM && strcmp(token, "special") == 0) {
  661. free_token(token);
  662. type = read_token(&token);
  663. }
  664. if (test_type_token(type, token, EVENT_OP, ":") < 0)
  665. return -1;
  666. if (read_expect_type(EVENT_ITEM, &token) < 0)
  667. goto fail;
  668. last_token = token;
  669. field = malloc_or_die(sizeof(*field));
  670. memset(field, 0, sizeof(*field));
  671. /* read the rest of the type */
  672. for (;;) {
  673. type = read_token(&token);
  674. if (type == EVENT_ITEM ||
  675. (type == EVENT_OP && strcmp(token, "*") == 0) ||
  676. /*
  677. * Some of the ftrace fields are broken and have
  678. * an illegal "." in them.
  679. */
  680. (event->flags & EVENT_FL_ISFTRACE &&
  681. type == EVENT_OP && strcmp(token, ".") == 0)) {
  682. if (strcmp(token, "*") == 0)
  683. field->flags |= FIELD_IS_POINTER;
  684. if (field->type) {
  685. field->type = realloc(field->type,
  686. strlen(field->type) +
  687. strlen(last_token) + 2);
  688. strcat(field->type, " ");
  689. strcat(field->type, last_token);
  690. } else
  691. field->type = last_token;
  692. last_token = token;
  693. continue;
  694. }
  695. break;
  696. }
  697. if (!field->type) {
  698. die("no type found");
  699. goto fail;
  700. }
  701. field->name = last_token;
  702. if (test_type(type, EVENT_OP))
  703. goto fail;
  704. if (strcmp(token, "[") == 0) {
  705. enum event_type last_type = type;
  706. char *brackets = token;
  707. int len;
  708. field->flags |= FIELD_IS_ARRAY;
  709. type = read_token(&token);
  710. while (strcmp(token, "]") != 0) {
  711. if (last_type == EVENT_ITEM &&
  712. type == EVENT_ITEM)
  713. len = 2;
  714. else
  715. len = 1;
  716. last_type = type;
  717. brackets = realloc(brackets,
  718. strlen(brackets) +
  719. strlen(token) + len);
  720. if (len == 2)
  721. strcat(brackets, " ");
  722. strcat(brackets, token);
  723. free_token(token);
  724. type = read_token(&token);
  725. if (type == EVENT_NONE) {
  726. die("failed to find token");
  727. goto fail;
  728. }
  729. }
  730. free_token(token);
  731. brackets = realloc(brackets, strlen(brackets) + 2);
  732. strcat(brackets, "]");
  733. /* add brackets to type */
  734. type = read_token(&token);
  735. /*
  736. * If the next token is not an OP, then it is of
  737. * the format: type [] item;
  738. */
  739. if (type == EVENT_ITEM) {
  740. field->type = realloc(field->type,
  741. strlen(field->type) +
  742. strlen(field->name) +
  743. strlen(brackets) + 2);
  744. strcat(field->type, " ");
  745. strcat(field->type, field->name);
  746. free_token(field->name);
  747. strcat(field->type, brackets);
  748. field->name = token;
  749. type = read_token(&token);
  750. } else {
  751. field->type = realloc(field->type,
  752. strlen(field->type) +
  753. strlen(brackets) + 1);
  754. strcat(field->type, brackets);
  755. }
  756. free(brackets);
  757. }
  758. if (field_is_string(field)) {
  759. field->flags |= FIELD_IS_STRING;
  760. if (field_is_dynamic(field))
  761. field->flags |= FIELD_IS_DYNAMIC;
  762. }
  763. if (test_type_token(type, token, EVENT_OP, ";"))
  764. goto fail;
  765. free_token(token);
  766. if (read_expected(EVENT_ITEM, "offset") < 0)
  767. goto fail_expect;
  768. if (read_expected(EVENT_OP, ":") < 0)
  769. goto fail_expect;
  770. if (read_expect_type(EVENT_ITEM, &token))
  771. goto fail;
  772. field->offset = strtoul(token, NULL, 0);
  773. free_token(token);
  774. if (read_expected(EVENT_OP, ";") < 0)
  775. goto fail_expect;
  776. if (read_expected(EVENT_ITEM, "size") < 0)
  777. goto fail_expect;
  778. if (read_expected(EVENT_OP, ":") < 0)
  779. goto fail_expect;
  780. if (read_expect_type(EVENT_ITEM, &token))
  781. goto fail;
  782. field->size = strtoul(token, NULL, 0);
  783. free_token(token);
  784. if (read_expected(EVENT_OP, ";") < 0)
  785. goto fail_expect;
  786. type = read_token(&token);
  787. if (type != EVENT_NEWLINE) {
  788. /* newer versions of the kernel have a "signed" type */
  789. if (test_type_token(type, token, EVENT_ITEM, "signed"))
  790. goto fail;
  791. free_token(token);
  792. if (read_expected(EVENT_OP, ":") < 0)
  793. goto fail_expect;
  794. if (read_expect_type(EVENT_ITEM, &token))
  795. goto fail;
  796. if (strtoul(token, NULL, 0))
  797. field->flags |= FIELD_IS_SIGNED;
  798. free_token(token);
  799. if (read_expected(EVENT_OP, ";") < 0)
  800. goto fail_expect;
  801. if (read_expect_type(EVENT_NEWLINE, &token))
  802. goto fail;
  803. }
  804. free_token(token);
  805. *fields = field;
  806. fields = &field->next;
  807. } while (1);
  808. return 0;
  809. fail:
  810. free_token(token);
  811. fail_expect:
  812. if (field)
  813. free(field);
  814. return -1;
  815. }
  816. static int event_read_format(struct event *event)
  817. {
  818. char *token;
  819. int ret;
  820. if (read_expected_item(EVENT_ITEM, "format") < 0)
  821. return -1;
  822. if (read_expected(EVENT_OP, ":") < 0)
  823. return -1;
  824. if (read_expect_type(EVENT_NEWLINE, &token))
  825. goto fail;
  826. free_token(token);
  827. ret = event_read_fields(event, &event->format.common_fields);
  828. if (ret < 0)
  829. return ret;
  830. event->format.nr_common = ret;
  831. ret = event_read_fields(event, &event->format.fields);
  832. if (ret < 0)
  833. return ret;
  834. event->format.nr_fields = ret;
  835. return 0;
  836. fail:
  837. free_token(token);
  838. return -1;
  839. }
  840. enum event_type
  841. process_arg_token(struct event *event, struct print_arg *arg,
  842. char **tok, enum event_type type);
  843. static enum event_type
  844. process_arg(struct event *event, struct print_arg *arg, char **tok)
  845. {
  846. enum event_type type;
  847. char *token;
  848. type = read_token(&token);
  849. *tok = token;
  850. return process_arg_token(event, arg, tok, type);
  851. }
  852. static enum event_type
  853. process_cond(struct event *event, struct print_arg *top, char **tok)
  854. {
  855. struct print_arg *arg, *left, *right;
  856. enum event_type type;
  857. char *token = NULL;
  858. arg = malloc_or_die(sizeof(*arg));
  859. memset(arg, 0, sizeof(*arg));
  860. left = malloc_or_die(sizeof(*left));
  861. right = malloc_or_die(sizeof(*right));
  862. arg->type = PRINT_OP;
  863. arg->op.left = left;
  864. arg->op.right = right;
  865. *tok = NULL;
  866. type = process_arg(event, left, &token);
  867. if (test_type_token(type, token, EVENT_OP, ":"))
  868. goto out_free;
  869. arg->op.op = token;
  870. type = process_arg(event, right, &token);
  871. top->op.right = arg;
  872. *tok = token;
  873. return type;
  874. out_free:
  875. free_token(*tok);
  876. free(right);
  877. free(left);
  878. free_arg(arg);
  879. return EVENT_ERROR;
  880. }
  881. static enum event_type
  882. process_array(struct event *event, struct print_arg *top, char **tok)
  883. {
  884. struct print_arg *arg;
  885. enum event_type type;
  886. char *token = NULL;
  887. arg = malloc_or_die(sizeof(*arg));
  888. memset(arg, 0, sizeof(*arg));
  889. *tok = NULL;
  890. type = process_arg(event, arg, &token);
  891. if (test_type_token(type, token, EVENT_OP, "]"))
  892. goto out_free;
  893. top->op.right = arg;
  894. free_token(token);
  895. type = read_token_item(&token);
  896. *tok = token;
  897. return type;
  898. out_free:
  899. free_token(*tok);
  900. free_arg(arg);
  901. return EVENT_ERROR;
  902. }
  903. static int get_op_prio(char *op)
  904. {
  905. if (!op[1]) {
  906. switch (op[0]) {
  907. case '*':
  908. case '/':
  909. case '%':
  910. return 6;
  911. case '+':
  912. case '-':
  913. return 7;
  914. /* '>>' and '<<' are 8 */
  915. case '<':
  916. case '>':
  917. return 9;
  918. /* '==' and '!=' are 10 */
  919. case '&':
  920. return 11;
  921. case '^':
  922. return 12;
  923. case '|':
  924. return 13;
  925. case '?':
  926. return 16;
  927. default:
  928. die("unknown op '%c'", op[0]);
  929. return -1;
  930. }
  931. } else {
  932. if (strcmp(op, "++") == 0 ||
  933. strcmp(op, "--") == 0) {
  934. return 3;
  935. } else if (strcmp(op, ">>") == 0 ||
  936. strcmp(op, "<<") == 0) {
  937. return 8;
  938. } else if (strcmp(op, ">=") == 0 ||
  939. strcmp(op, "<=") == 0) {
  940. return 9;
  941. } else if (strcmp(op, "==") == 0 ||
  942. strcmp(op, "!=") == 0) {
  943. return 10;
  944. } else if (strcmp(op, "&&") == 0) {
  945. return 14;
  946. } else if (strcmp(op, "||") == 0) {
  947. return 15;
  948. } else {
  949. die("unknown op '%s'", op);
  950. return -1;
  951. }
  952. }
  953. }
  954. static void set_op_prio(struct print_arg *arg)
  955. {
  956. /* single ops are the greatest */
  957. if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
  958. arg->op.prio = 0;
  959. return;
  960. }
  961. arg->op.prio = get_op_prio(arg->op.op);
  962. }
  963. static enum event_type
  964. process_op(struct event *event, struct print_arg *arg, char **tok)
  965. {
  966. struct print_arg *left, *right = NULL;
  967. enum event_type type;
  968. char *token;
  969. /* the op is passed in via tok */
  970. token = *tok;
  971. if (arg->type == PRINT_OP && !arg->op.left) {
  972. /* handle single op */
  973. if (token[1]) {
  974. die("bad op token %s", token);
  975. return EVENT_ERROR;
  976. }
  977. switch (token[0]) {
  978. case '!':
  979. case '+':
  980. case '-':
  981. break;
  982. default:
  983. die("bad op token %s", token);
  984. return EVENT_ERROR;
  985. }
  986. /* make an empty left */
  987. left = malloc_or_die(sizeof(*left));
  988. left->type = PRINT_NULL;
  989. arg->op.left = left;
  990. right = malloc_or_die(sizeof(*right));
  991. arg->op.right = right;
  992. type = process_arg(event, right, tok);
  993. } else if (strcmp(token, "?") == 0) {
  994. left = malloc_or_die(sizeof(*left));
  995. /* copy the top arg to the left */
  996. *left = *arg;
  997. arg->type = PRINT_OP;
  998. arg->op.op = token;
  999. arg->op.left = left;
  1000. arg->op.prio = 0;
  1001. type = process_cond(event, arg, tok);
  1002. } else if (strcmp(token, ">>") == 0 ||
  1003. strcmp(token, "<<") == 0 ||
  1004. strcmp(token, "&") == 0 ||
  1005. strcmp(token, "|") == 0 ||
  1006. strcmp(token, "&&") == 0 ||
  1007. strcmp(token, "||") == 0 ||
  1008. strcmp(token, "-") == 0 ||
  1009. strcmp(token, "+") == 0 ||
  1010. strcmp(token, "*") == 0 ||
  1011. strcmp(token, "^") == 0 ||
  1012. strcmp(token, "/") == 0 ||
  1013. strcmp(token, "<") == 0 ||
  1014. strcmp(token, ">") == 0 ||
  1015. strcmp(token, "==") == 0 ||
  1016. strcmp(token, "!=") == 0) {
  1017. left = malloc_or_die(sizeof(*left));
  1018. /* copy the top arg to the left */
  1019. *left = *arg;
  1020. arg->type = PRINT_OP;
  1021. arg->op.op = token;
  1022. arg->op.left = left;
  1023. set_op_prio(arg);
  1024. right = malloc_or_die(sizeof(*right));
  1025. type = read_token_item(&token);
  1026. *tok = token;
  1027. /* could just be a type pointer */
  1028. if ((strcmp(arg->op.op, "*") == 0) &&
  1029. type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
  1030. if (left->type != PRINT_ATOM)
  1031. die("bad pointer type");
  1032. left->atom.atom = realloc(left->atom.atom,
  1033. sizeof(left->atom.atom) + 3);
  1034. strcat(left->atom.atom, " *");
  1035. *arg = *left;
  1036. free(arg);
  1037. return type;
  1038. }
  1039. type = process_arg_token(event, right, tok, type);
  1040. arg->op.right = right;
  1041. } else if (strcmp(token, "[") == 0) {
  1042. left = malloc_or_die(sizeof(*left));
  1043. *left = *arg;
  1044. arg->type = PRINT_OP;
  1045. arg->op.op = token;
  1046. arg->op.left = left;
  1047. arg->op.prio = 0;
  1048. type = process_array(event, arg, tok);
  1049. } else {
  1050. warning("unknown op '%s'", token);
  1051. event->flags |= EVENT_FL_FAILED;
  1052. /* the arg is now the left side */
  1053. return EVENT_NONE;
  1054. }
  1055. if (type == EVENT_OP) {
  1056. int prio;
  1057. /* higher prios need to be closer to the root */
  1058. prio = get_op_prio(*tok);
  1059. if (prio > arg->op.prio)
  1060. return process_op(event, arg, tok);
  1061. return process_op(event, right, tok);
  1062. }
  1063. return type;
  1064. }
  1065. static enum event_type
  1066. process_entry(struct event *event __unused, struct print_arg *arg,
  1067. char **tok)
  1068. {
  1069. enum event_type type;
  1070. char *field;
  1071. char *token;
  1072. if (read_expected(EVENT_OP, "->") < 0)
  1073. return EVENT_ERROR;
  1074. if (read_expect_type(EVENT_ITEM, &token) < 0)
  1075. goto fail;
  1076. field = token;
  1077. arg->type = PRINT_FIELD;
  1078. arg->field.name = field;
  1079. if (is_flag_field) {
  1080. arg->field.field = find_any_field(event, arg->field.name);
  1081. arg->field.field->flags |= FIELD_IS_FLAG;
  1082. is_flag_field = 0;
  1083. } else if (is_symbolic_field) {
  1084. arg->field.field = find_any_field(event, arg->field.name);
  1085. arg->field.field->flags |= FIELD_IS_SYMBOLIC;
  1086. is_symbolic_field = 0;
  1087. }
  1088. type = read_token(&token);
  1089. *tok = token;
  1090. return type;
  1091. fail:
  1092. free_token(token);
  1093. return EVENT_ERROR;
  1094. }
  1095. static char *arg_eval (struct print_arg *arg);
  1096. static long long arg_num_eval(struct print_arg *arg)
  1097. {
  1098. long long left, right;
  1099. long long val = 0;
  1100. switch (arg->type) {
  1101. case PRINT_ATOM:
  1102. val = strtoll(arg->atom.atom, NULL, 0);
  1103. break;
  1104. case PRINT_TYPE:
  1105. val = arg_num_eval(arg->typecast.item);
  1106. break;
  1107. case PRINT_OP:
  1108. switch (arg->op.op[0]) {
  1109. case '|':
  1110. left = arg_num_eval(arg->op.left);
  1111. right = arg_num_eval(arg->op.right);
  1112. if (arg->op.op[1])
  1113. val = left || right;
  1114. else
  1115. val = left | right;
  1116. break;
  1117. case '&':
  1118. left = arg_num_eval(arg->op.left);
  1119. right = arg_num_eval(arg->op.right);
  1120. if (arg->op.op[1])
  1121. val = left && right;
  1122. else
  1123. val = left & right;
  1124. break;
  1125. case '<':
  1126. left = arg_num_eval(arg->op.left);
  1127. right = arg_num_eval(arg->op.right);
  1128. switch (arg->op.op[1]) {
  1129. case 0:
  1130. val = left < right;
  1131. break;
  1132. case '<':
  1133. val = left << right;
  1134. break;
  1135. case '=':
  1136. val = left <= right;
  1137. break;
  1138. default:
  1139. die("unknown op '%s'", arg->op.op);
  1140. }
  1141. break;
  1142. case '>':
  1143. left = arg_num_eval(arg->op.left);
  1144. right = arg_num_eval(arg->op.right);
  1145. switch (arg->op.op[1]) {
  1146. case 0:
  1147. val = left > right;
  1148. break;
  1149. case '>':
  1150. val = left >> right;
  1151. break;
  1152. case '=':
  1153. val = left >= right;
  1154. break;
  1155. default:
  1156. die("unknown op '%s'", arg->op.op);
  1157. }
  1158. break;
  1159. case '=':
  1160. left = arg_num_eval(arg->op.left);
  1161. right = arg_num_eval(arg->op.right);
  1162. if (arg->op.op[1] != '=')
  1163. die("unknown op '%s'", arg->op.op);
  1164. val = left == right;
  1165. break;
  1166. case '!':
  1167. left = arg_num_eval(arg->op.left);
  1168. right = arg_num_eval(arg->op.right);
  1169. switch (arg->op.op[1]) {
  1170. case '=':
  1171. val = left != right;
  1172. break;
  1173. default:
  1174. die("unknown op '%s'", arg->op.op);
  1175. }
  1176. break;
  1177. default:
  1178. die("unknown op '%s'", arg->op.op);
  1179. }
  1180. break;
  1181. case PRINT_NULL:
  1182. case PRINT_FIELD ... PRINT_SYMBOL:
  1183. case PRINT_STRING:
  1184. default:
  1185. die("invalid eval type %d", arg->type);
  1186. }
  1187. return val;
  1188. }
  1189. static char *arg_eval (struct print_arg *arg)
  1190. {
  1191. long long val;
  1192. static char buf[20];
  1193. switch (arg->type) {
  1194. case PRINT_ATOM:
  1195. return arg->atom.atom;
  1196. case PRINT_TYPE:
  1197. return arg_eval(arg->typecast.item);
  1198. case PRINT_OP:
  1199. val = arg_num_eval(arg);
  1200. sprintf(buf, "%lld", val);
  1201. return buf;
  1202. case PRINT_NULL:
  1203. case PRINT_FIELD ... PRINT_SYMBOL:
  1204. case PRINT_STRING:
  1205. default:
  1206. die("invalid eval type %d", arg->type);
  1207. break;
  1208. }
  1209. return NULL;
  1210. }
  1211. static enum event_type
  1212. process_fields(struct event *event, struct print_flag_sym **list, char **tok)
  1213. {
  1214. enum event_type type;
  1215. struct print_arg *arg = NULL;
  1216. struct print_flag_sym *field;
  1217. char *token = NULL;
  1218. char *value;
  1219. do {
  1220. free_token(token);
  1221. type = read_token_item(&token);
  1222. if (test_type_token(type, token, EVENT_OP, "{"))
  1223. break;
  1224. arg = malloc_or_die(sizeof(*arg));
  1225. free_token(token);
  1226. type = process_arg(event, arg, &token);
  1227. if (test_type_token(type, token, EVENT_DELIM, ","))
  1228. goto out_free;
  1229. field = malloc_or_die(sizeof(*field));
  1230. memset(field, 0, sizeof(*field));
  1231. value = arg_eval(arg);
  1232. field->value = strdup(value);
  1233. free_token(token);
  1234. type = process_arg(event, arg, &token);
  1235. if (test_type_token(type, token, EVENT_OP, "}"))
  1236. goto out_free;
  1237. value = arg_eval(arg);
  1238. field->str = strdup(value);
  1239. free_arg(arg);
  1240. arg = NULL;
  1241. *list = field;
  1242. list = &field->next;
  1243. free_token(token);
  1244. type = read_token_item(&token);
  1245. } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
  1246. *tok = token;
  1247. return type;
  1248. out_free:
  1249. free_arg(arg);
  1250. free_token(token);
  1251. return EVENT_ERROR;
  1252. }
  1253. static enum event_type
  1254. process_flags(struct event *event, struct print_arg *arg, char **tok)
  1255. {
  1256. struct print_arg *field;
  1257. enum event_type type;
  1258. char *token;
  1259. memset(arg, 0, sizeof(*arg));
  1260. arg->type = PRINT_FLAGS;
  1261. if (read_expected_item(EVENT_DELIM, "(") < 0)
  1262. return EVENT_ERROR;
  1263. field = malloc_or_die(sizeof(*field));
  1264. type = process_arg(event, field, &token);
  1265. if (test_type_token(type, token, EVENT_DELIM, ","))
  1266. goto out_free;
  1267. arg->flags.field = field;
  1268. type = read_token_item(&token);
  1269. if (event_item_type(type)) {
  1270. arg->flags.delim = token;
  1271. type = read_token_item(&token);
  1272. }
  1273. if (test_type_token(type, token, EVENT_DELIM, ","))
  1274. goto out_free;
  1275. type = process_fields(event, &arg->flags.flags, &token);
  1276. if (test_type_token(type, token, EVENT_DELIM, ")"))
  1277. goto out_free;
  1278. free_token(token);
  1279. type = read_token_item(tok);
  1280. return type;
  1281. out_free:
  1282. free_token(token);
  1283. return EVENT_ERROR;
  1284. }
  1285. static enum event_type
  1286. process_symbols(struct event *event, struct print_arg *arg, char **tok)
  1287. {
  1288. struct print_arg *field;
  1289. enum event_type type;
  1290. char *token;
  1291. memset(arg, 0, sizeof(*arg));
  1292. arg->type = PRINT_SYMBOL;
  1293. if (read_expected_item(EVENT_DELIM, "(") < 0)
  1294. return EVENT_ERROR;
  1295. field = malloc_or_die(sizeof(*field));
  1296. type = process_arg(event, field, &token);
  1297. if (test_type_token(type, token, EVENT_DELIM, ","))
  1298. goto out_free;
  1299. arg->symbol.field = field;
  1300. type = process_fields(event, &arg->symbol.symbols, &token);
  1301. if (test_type_token(type, token, EVENT_DELIM, ")"))
  1302. goto out_free;
  1303. free_token(token);
  1304. type = read_token_item(tok);
  1305. return type;
  1306. out_free:
  1307. free_token(token);
  1308. return EVENT_ERROR;
  1309. }
  1310. static enum event_type
  1311. process_paren(struct event *event, struct print_arg *arg, char **tok)
  1312. {
  1313. struct print_arg *item_arg;
  1314. enum event_type type;
  1315. char *token;
  1316. type = process_arg(event, arg, &token);
  1317. if (type == EVENT_ERROR)
  1318. return EVENT_ERROR;
  1319. if (type == EVENT_OP)
  1320. type = process_op(event, arg, &token);
  1321. if (type == EVENT_ERROR)
  1322. return EVENT_ERROR;
  1323. if (test_type_token(type, token, EVENT_DELIM, ")")) {
  1324. free_token(token);
  1325. return EVENT_ERROR;
  1326. }
  1327. free_token(token);
  1328. type = read_token_item(&token);
  1329. /*
  1330. * If the next token is an item or another open paren, then
  1331. * this was a typecast.
  1332. */
  1333. if (event_item_type(type) ||
  1334. (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
  1335. /* make this a typecast and contine */
  1336. /* prevous must be an atom */
  1337. if (arg->type != PRINT_ATOM)
  1338. die("previous needed to be PRINT_ATOM");
  1339. item_arg = malloc_or_die(sizeof(*item_arg));
  1340. arg->type = PRINT_TYPE;
  1341. arg->typecast.type = arg->atom.atom;
  1342. arg->typecast.item = item_arg;
  1343. type = process_arg_token(event, item_arg, &token, type);
  1344. }
  1345. *tok = token;
  1346. return type;
  1347. }
  1348. static enum event_type
  1349. process_str(struct event *event __unused, struct print_arg *arg, char **tok)
  1350. {
  1351. enum event_type type;
  1352. char *token;
  1353. if (read_expected(EVENT_DELIM, "(") < 0)
  1354. return EVENT_ERROR;
  1355. if (read_expect_type(EVENT_ITEM, &token) < 0)
  1356. goto fail;
  1357. arg->type = PRINT_STRING;
  1358. arg->string.string = token;
  1359. arg->string.offset = -1;
  1360. if (read_expected(EVENT_DELIM, ")") < 0)
  1361. return EVENT_ERROR;
  1362. type = read_token(&token);
  1363. *tok = token;
  1364. return type;
  1365. fail:
  1366. free_token(token);
  1367. return EVENT_ERROR;
  1368. }
  1369. enum event_type
  1370. process_arg_token(struct event *event, struct print_arg *arg,
  1371. char **tok, enum event_type type)
  1372. {
  1373. char *token;
  1374. char *atom;
  1375. token = *tok;
  1376. switch (type) {
  1377. case EVENT_ITEM:
  1378. if (strcmp(token, "REC") == 0) {
  1379. free_token(token);
  1380. type = process_entry(event, arg, &token);
  1381. } else if (strcmp(token, "__print_flags") == 0) {
  1382. free_token(token);
  1383. is_flag_field = 1;
  1384. type = process_flags(event, arg, &token);
  1385. } else if (strcmp(token, "__print_symbolic") == 0) {
  1386. free_token(token);
  1387. is_symbolic_field = 1;
  1388. type = process_symbols(event, arg, &token);
  1389. } else if (strcmp(token, "__get_str") == 0) {
  1390. free_token(token);
  1391. type = process_str(event, arg, &token);
  1392. } else {
  1393. atom = token;
  1394. /* test the next token */
  1395. type = read_token_item(&token);
  1396. /* atoms can be more than one token long */
  1397. while (type == EVENT_ITEM) {
  1398. atom = realloc(atom, strlen(atom) + strlen(token) + 2);
  1399. strcat(atom, " ");
  1400. strcat(atom, token);
  1401. free_token(token);
  1402. type = read_token_item(&token);
  1403. }
  1404. /* todo, test for function */
  1405. arg->type = PRINT_ATOM;
  1406. arg->atom.atom = atom;
  1407. }
  1408. break;
  1409. case EVENT_DQUOTE:
  1410. case EVENT_SQUOTE:
  1411. arg->type = PRINT_ATOM;
  1412. arg->atom.atom = token;
  1413. type = read_token_item(&token);
  1414. break;
  1415. case EVENT_DELIM:
  1416. if (strcmp(token, "(") == 0) {
  1417. free_token(token);
  1418. type = process_paren(event, arg, &token);
  1419. break;
  1420. }
  1421. case EVENT_OP:
  1422. /* handle single ops */
  1423. arg->type = PRINT_OP;
  1424. arg->op.op = token;
  1425. arg->op.left = NULL;
  1426. type = process_op(event, arg, &token);
  1427. break;
  1428. case EVENT_ERROR ... EVENT_NEWLINE:
  1429. default:
  1430. die("unexpected type %d", type);
  1431. }
  1432. *tok = token;
  1433. return type;
  1434. }
  1435. static int event_read_print_args(struct event *event, struct print_arg **list)
  1436. {
  1437. enum event_type type = EVENT_ERROR;
  1438. struct print_arg *arg;
  1439. char *token;
  1440. int args = 0;
  1441. do {
  1442. if (type == EVENT_NEWLINE) {
  1443. free_token(token);
  1444. type = read_token_item(&token);
  1445. continue;
  1446. }
  1447. arg = malloc_or_die(sizeof(*arg));
  1448. memset(arg, 0, sizeof(*arg));
  1449. type = process_arg(event, arg, &token);
  1450. if (type == EVENT_ERROR) {
  1451. free_arg(arg);
  1452. return -1;
  1453. }
  1454. *list = arg;
  1455. args++;
  1456. if (type == EVENT_OP) {
  1457. type = process_op(event, arg, &token);
  1458. list = &arg->next;
  1459. continue;
  1460. }
  1461. if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
  1462. free_token(token);
  1463. *list = arg;
  1464. list = &arg->next;
  1465. continue;
  1466. }
  1467. break;
  1468. } while (type != EVENT_NONE);
  1469. if (type != EVENT_NONE)
  1470. free_token(token);
  1471. return args;
  1472. }
  1473. static int event_read_print(struct event *event)
  1474. {
  1475. enum event_type type;
  1476. char *token;
  1477. int ret;
  1478. if (read_expected_item(EVENT_ITEM, "print") < 0)
  1479. return -1;
  1480. if (read_expected(EVENT_ITEM, "fmt") < 0)
  1481. return -1;
  1482. if (read_expected(EVENT_OP, ":") < 0)
  1483. return -1;
  1484. if (read_expect_type(EVENT_DQUOTE, &token) < 0)
  1485. goto fail;
  1486. concat:
  1487. event->print_fmt.format = token;
  1488. event->print_fmt.args = NULL;
  1489. /* ok to have no arg */
  1490. type = read_token_item(&token);
  1491. if (type == EVENT_NONE)
  1492. return 0;
  1493. /* Handle concatination of print lines */
  1494. if (type == EVENT_DQUOTE) {
  1495. char *cat;
  1496. cat = malloc_or_die(strlen(event->print_fmt.format) +
  1497. strlen(token) + 1);
  1498. strcpy(cat, event->print_fmt.format);
  1499. strcat(cat, token);
  1500. free_token(token);
  1501. free_token(event->print_fmt.format);
  1502. event->print_fmt.format = NULL;
  1503. token = cat;
  1504. goto concat;
  1505. }
  1506. if (test_type_token(type, token, EVENT_DELIM, ","))
  1507. goto fail;
  1508. free_token(token);
  1509. ret = event_read_print_args(event, &event->print_fmt.args);
  1510. if (ret < 0)
  1511. return -1;
  1512. return ret;
  1513. fail:
  1514. free_token(token);
  1515. return -1;
  1516. }
  1517. static struct format_field *
  1518. find_common_field(struct event *event, const char *name)
  1519. {
  1520. struct format_field *format;
  1521. for (format = event->format.common_fields;
  1522. format; format = format->next) {
  1523. if (strcmp(format->name, name) == 0)
  1524. break;
  1525. }
  1526. return format;
  1527. }
  1528. static struct format_field *
  1529. find_field(struct event *event, const char *name)
  1530. {
  1531. struct format_field *format;
  1532. for (format = event->format.fields;
  1533. format; format = format->next) {
  1534. if (strcmp(format->name, name) == 0)
  1535. break;
  1536. }
  1537. return format;
  1538. }
  1539. static struct format_field *
  1540. find_any_field(struct event *event, const char *name)
  1541. {
  1542. struct format_field *format;
  1543. format = find_common_field(event, name);
  1544. if (format)
  1545. return format;
  1546. return find_field(event, name);
  1547. }
  1548. unsigned long long read_size(void *ptr, int size)
  1549. {
  1550. switch (size) {
  1551. case 1:
  1552. return *(unsigned char *)ptr;
  1553. case 2:
  1554. return data2host2(ptr);
  1555. case 4:
  1556. return data2host4(ptr);
  1557. case 8:
  1558. return data2host8(ptr);
  1559. default:
  1560. /* BUG! */
  1561. return 0;
  1562. }
  1563. }
  1564. unsigned long long
  1565. raw_field_value(struct event *event, const char *name, void *data)
  1566. {
  1567. struct format_field *field;
  1568. field = find_any_field(event, name);
  1569. if (!field)
  1570. return 0ULL;
  1571. return read_size(data + field->offset, field->size);
  1572. }
  1573. void *raw_field_ptr(struct event *event, const char *name, void *data)
  1574. {
  1575. struct format_field *field;
  1576. field = find_any_field(event, name);
  1577. if (!field)
  1578. return NULL;
  1579. if (field->flags & FIELD_IS_DYNAMIC) {
  1580. int offset;
  1581. offset = *(int *)(data + field->offset);
  1582. offset &= 0xffff;
  1583. return data + offset;
  1584. }
  1585. return data + field->offset;
  1586. }
  1587. static int get_common_info(const char *type, int *offset, int *size)
  1588. {
  1589. struct event *event;
  1590. struct format_field *field;
  1591. /*
  1592. * All events should have the same common elements.
  1593. * Pick any event to find where the type is;
  1594. */
  1595. if (!event_list)
  1596. die("no event_list!");
  1597. event = event_list;
  1598. field = find_common_field(event, type);
  1599. if (!field)
  1600. die("field '%s' not found", type);
  1601. *offset = field->offset;
  1602. *size = field->size;
  1603. return 0;
  1604. }
  1605. static int __parse_common(void *data, int *size, int *offset,
  1606. const char *name)
  1607. {
  1608. int ret;
  1609. if (!*size) {
  1610. ret = get_common_info(name, offset, size);
  1611. if (ret < 0)
  1612. return ret;
  1613. }
  1614. return read_size(data + *offset, *size);
  1615. }
  1616. int trace_parse_common_type(void *data)
  1617. {
  1618. static int type_offset;
  1619. static int type_size;
  1620. return __parse_common(data, &type_size, &type_offset,
  1621. "common_type");
  1622. }
  1623. int trace_parse_common_pid(void *data)
  1624. {
  1625. static int pid_offset;
  1626. static int pid_size;
  1627. return __parse_common(data, &pid_size, &pid_offset,
  1628. "common_pid");
  1629. }
  1630. int parse_common_pc(void *data)
  1631. {
  1632. static int pc_offset;
  1633. static int pc_size;
  1634. return __parse_common(data, &pc_size, &pc_offset,
  1635. "common_preempt_count");
  1636. }
  1637. int parse_common_flags(void *data)
  1638. {
  1639. static int flags_offset;
  1640. static int flags_size;
  1641. return __parse_common(data, &flags_size, &flags_offset,
  1642. "common_flags");
  1643. }
  1644. int parse_common_lock_depth(void *data)
  1645. {
  1646. static int ld_offset;
  1647. static int ld_size;
  1648. int ret;
  1649. ret = __parse_common(data, &ld_size, &ld_offset,
  1650. "common_lock_depth");
  1651. if (ret < 0)
  1652. return -1;
  1653. return ret;
  1654. }
  1655. struct event *trace_find_event(int id)
  1656. {
  1657. struct event *event;
  1658. for (event = event_list; event; event = event->next) {
  1659. if (event->id == id)
  1660. break;
  1661. }
  1662. return event;
  1663. }
  1664. struct event *trace_find_next_event(struct event *event)
  1665. {
  1666. if (!event)
  1667. return event_list;
  1668. return event->next;
  1669. }
  1670. static unsigned long long eval_num_arg(void *data, int size,
  1671. struct event *event, struct print_arg *arg)
  1672. {
  1673. unsigned long long val = 0;
  1674. unsigned long long left, right;
  1675. struct print_arg *larg;
  1676. switch (arg->type) {
  1677. case PRINT_NULL:
  1678. /* ?? */
  1679. return 0;
  1680. case PRINT_ATOM:
  1681. return strtoull(arg->atom.atom, NULL, 0);
  1682. case PRINT_FIELD:
  1683. if (!arg->field.field) {
  1684. arg->field.field = find_any_field(event, arg->field.name);
  1685. if (!arg->field.field)
  1686. die("field %s not found", arg->field.name);
  1687. }
  1688. /* must be a number */
  1689. val = read_size(data + arg->field.field->offset,
  1690. arg->field.field->size);
  1691. break;
  1692. case PRINT_FLAGS:
  1693. case PRINT_SYMBOL:
  1694. break;
  1695. case PRINT_TYPE:
  1696. return eval_num_arg(data, size, event, arg->typecast.item);
  1697. case PRINT_STRING:
  1698. return 0;
  1699. break;
  1700. case PRINT_OP:
  1701. if (strcmp(arg->op.op, "[") == 0) {
  1702. /*
  1703. * Arrays are special, since we don't want
  1704. * to read the arg as is.
  1705. */
  1706. if (arg->op.left->type != PRINT_FIELD)
  1707. goto default_op; /* oops, all bets off */
  1708. larg = arg->op.left;
  1709. if (!larg->field.field) {
  1710. larg->field.field =
  1711. find_any_field(event, larg->field.name);
  1712. if (!larg->field.field)
  1713. die("field %s not found", larg->field.name);
  1714. }
  1715. right = eval_num_arg(data, size, event, arg->op.right);
  1716. val = read_size(data + larg->field.field->offset +
  1717. right * long_size, long_size);
  1718. break;
  1719. }
  1720. default_op:
  1721. left = eval_num_arg(data, size, event, arg->op.left);
  1722. right = eval_num_arg(data, size, event, arg->op.right);
  1723. switch (arg->op.op[0]) {
  1724. case '|':
  1725. if (arg->op.op[1])
  1726. val = left || right;
  1727. else
  1728. val = left | right;
  1729. break;
  1730. case '&':
  1731. if (arg->op.op[1])
  1732. val = left && right;
  1733. else
  1734. val = left & right;
  1735. break;
  1736. case '<':
  1737. switch (arg->op.op[1]) {
  1738. case 0:
  1739. val = left < right;
  1740. break;
  1741. case '<':
  1742. val = left << right;
  1743. break;
  1744. case '=':
  1745. val = left <= right;
  1746. break;
  1747. default:
  1748. die("unknown op '%s'", arg->op.op);
  1749. }
  1750. break;
  1751. case '>':
  1752. switch (arg->op.op[1]) {
  1753. case 0:
  1754. val = left > right;
  1755. break;
  1756. case '>':
  1757. val = left >> right;
  1758. break;
  1759. case '=':
  1760. val = left >= right;
  1761. break;
  1762. default:
  1763. die("unknown op '%s'", arg->op.op);
  1764. }
  1765. break;
  1766. case '=':
  1767. if (arg->op.op[1] != '=')
  1768. die("unknown op '%s'", arg->op.op);
  1769. val = left == right;
  1770. break;
  1771. case '-':
  1772. val = left - right;
  1773. break;
  1774. case '+':
  1775. val = left + right;
  1776. break;
  1777. default:
  1778. die("unknown op '%s'", arg->op.op);
  1779. }
  1780. break;
  1781. default: /* not sure what to do there */
  1782. return 0;
  1783. }
  1784. return val;
  1785. }
  1786. struct flag {
  1787. const char *name;
  1788. unsigned long long value;
  1789. };
  1790. static const struct flag flags[] = {
  1791. { "HI_SOFTIRQ", 0 },
  1792. { "TIMER_SOFTIRQ", 1 },
  1793. { "NET_TX_SOFTIRQ", 2 },
  1794. { "NET_RX_SOFTIRQ", 3 },
  1795. { "BLOCK_SOFTIRQ", 4 },
  1796. { "BLOCK_IOPOLL_SOFTIRQ", 5 },
  1797. { "TASKLET_SOFTIRQ", 6 },
  1798. { "SCHED_SOFTIRQ", 7 },
  1799. { "HRTIMER_SOFTIRQ", 8 },
  1800. { "RCU_SOFTIRQ", 9 },
  1801. { "HRTIMER_NORESTART", 0 },
  1802. { "HRTIMER_RESTART", 1 },
  1803. };
  1804. unsigned long long eval_flag(const char *flag)
  1805. {
  1806. int i;
  1807. /*
  1808. * Some flags in the format files do not get converted.
  1809. * If the flag is not numeric, see if it is something that
  1810. * we already know about.
  1811. */
  1812. if (isdigit(flag[0]))
  1813. return strtoull(flag, NULL, 0);
  1814. for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
  1815. if (strcmp(flags[i].name, flag) == 0)
  1816. return flags[i].value;
  1817. return 0;
  1818. }
  1819. static void print_str_arg(void *data, int size,
  1820. struct event *event, struct print_arg *arg)
  1821. {
  1822. struct print_flag_sym *flag;
  1823. unsigned long long val, fval;
  1824. char *str;
  1825. int print;
  1826. switch (arg->type) {
  1827. case PRINT_NULL:
  1828. /* ?? */
  1829. return;
  1830. case PRINT_ATOM:
  1831. printf("%s", arg->atom.atom);
  1832. return;
  1833. case PRINT_FIELD:
  1834. if (!arg->field.field) {
  1835. arg->field.field = find_any_field(event, arg->field.name);
  1836. if (!arg->field.field)
  1837. die("field %s not found", arg->field.name);
  1838. }
  1839. str = malloc_or_die(arg->field.field->size + 1);
  1840. memcpy(str, data + arg->field.field->offset,
  1841. arg->field.field->size);
  1842. str[arg->field.field->size] = 0;
  1843. printf("%s", str);
  1844. free(str);
  1845. break;
  1846. case PRINT_FLAGS:
  1847. val = eval_num_arg(data, size, event, arg->flags.field);
  1848. print = 0;
  1849. for (flag = arg->flags.flags; flag; flag = flag->next) {
  1850. fval = eval_flag(flag->value);
  1851. if (!val && !fval) {
  1852. printf("%s", flag->str);
  1853. break;
  1854. }
  1855. if (fval && (val & fval) == fval) {
  1856. if (print && arg->flags.delim)
  1857. printf("%s", arg->flags.delim);
  1858. printf("%s", flag->str);
  1859. print = 1;
  1860. val &= ~fval;
  1861. }
  1862. }
  1863. break;
  1864. case PRINT_SYMBOL:
  1865. val = eval_num_arg(data, size, event, arg->symbol.field);
  1866. for (flag = arg->symbol.symbols; flag; flag = flag->next) {
  1867. fval = eval_flag(flag->value);
  1868. if (val == fval) {
  1869. printf("%s", flag->str);
  1870. break;
  1871. }
  1872. }
  1873. break;
  1874. case PRINT_TYPE:
  1875. break;
  1876. case PRINT_STRING: {
  1877. int str_offset;
  1878. if (arg->string.offset == -1) {
  1879. struct format_field *f;
  1880. f = find_any_field(event, arg->string.string);
  1881. arg->string.offset = f->offset;
  1882. }
  1883. str_offset = *(int *)(data + arg->string.offset);
  1884. str_offset &= 0xffff;
  1885. printf("%s", ((char *)data) + str_offset);
  1886. break;
  1887. }
  1888. case PRINT_OP:
  1889. /*
  1890. * The only op for string should be ? :
  1891. */
  1892. if (arg->op.op[0] != '?')
  1893. return;
  1894. val = eval_num_arg(data, size, event, arg->op.left);
  1895. if (val)
  1896. print_str_arg(data, size, event, arg->op.right->op.left);
  1897. else
  1898. print_str_arg(data, size, event, arg->op.right->op.right);
  1899. break;
  1900. default:
  1901. /* well... */
  1902. break;
  1903. }
  1904. }
  1905. static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
  1906. {
  1907. static struct format_field *field, *ip_field;
  1908. struct print_arg *args, *arg, **next;
  1909. unsigned long long ip, val;
  1910. char *ptr;
  1911. void *bptr;
  1912. if (!field) {
  1913. field = find_field(event, "buf");
  1914. if (!field)
  1915. die("can't find buffer field for binary printk");
  1916. ip_field = find_field(event, "ip");
  1917. if (!ip_field)
  1918. die("can't find ip field for binary printk");
  1919. }
  1920. ip = read_size(data + ip_field->offset, ip_field->size);
  1921. /*
  1922. * The first arg is the IP pointer.
  1923. */
  1924. args = malloc_or_die(sizeof(*args));
  1925. arg = args;
  1926. arg->next = NULL;
  1927. next = &arg->next;
  1928. arg->type = PRINT_ATOM;
  1929. arg->atom.atom = malloc_or_die(32);
  1930. sprintf(arg->atom.atom, "%lld", ip);
  1931. /* skip the first "%pf : " */
  1932. for (ptr = fmt + 6, bptr = data + field->offset;
  1933. bptr < data + size && *ptr; ptr++) {
  1934. int ls = 0;
  1935. if (*ptr == '%') {
  1936. process_again:
  1937. ptr++;
  1938. switch (*ptr) {
  1939. case '%':
  1940. break;
  1941. case 'l':
  1942. ls++;
  1943. goto process_again;
  1944. case 'L':
  1945. ls = 2;
  1946. goto process_again;
  1947. case '0' ... '9':
  1948. goto process_again;
  1949. case 'p':
  1950. ls = 1;
  1951. /* fall through */
  1952. case 'd':
  1953. case 'u':
  1954. case 'x':
  1955. case 'i':
  1956. /* the pointers are always 4 bytes aligned */
  1957. bptr = (void *)(((unsigned long)bptr + 3) &
  1958. ~3);
  1959. switch (ls) {
  1960. case 0:
  1961. case 1:
  1962. ls = long_size;
  1963. break;
  1964. case 2:
  1965. ls = 8;
  1966. default:
  1967. break;
  1968. }
  1969. val = read_size(bptr, ls);
  1970. bptr += ls;
  1971. arg = malloc_or_die(sizeof(*arg));
  1972. arg->next = NULL;
  1973. arg->type = PRINT_ATOM;
  1974. arg->atom.atom = malloc_or_die(32);
  1975. sprintf(arg->atom.atom, "%lld", val);
  1976. *next = arg;
  1977. next = &arg->next;
  1978. break;
  1979. case 's':
  1980. arg = malloc_or_die(sizeof(*arg));
  1981. arg->next = NULL;
  1982. arg->type = PRINT_STRING;
  1983. arg->string.string = strdup(bptr);
  1984. bptr += strlen(bptr) + 1;
  1985. *next = arg;
  1986. next = &arg->next;
  1987. default:
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. return args;
  1993. }
  1994. static void free_args(struct print_arg *args)
  1995. {
  1996. struct print_arg *next;
  1997. while (args) {
  1998. next = args->next;
  1999. if (args->type == PRINT_ATOM)
  2000. free(args->atom.atom);
  2001. else
  2002. free(args->string.string);
  2003. free(args);
  2004. args = next;
  2005. }
  2006. }
  2007. static char *get_bprint_format(void *data, int size __unused, struct event *event)
  2008. {
  2009. unsigned long long addr;
  2010. static struct format_field *field;
  2011. struct printk_map *printk;
  2012. char *format;
  2013. char *p;
  2014. if (!field) {
  2015. field = find_field(event, "fmt");
  2016. if (!field)
  2017. die("can't find format field for binary printk");
  2018. printf("field->offset = %d size=%d\n", field->offset, field->size);
  2019. }
  2020. addr = read_size(data + field->offset, field->size);
  2021. printk = find_printk(addr);
  2022. if (!printk) {
  2023. format = malloc_or_die(45);
  2024. sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
  2025. addr);
  2026. return format;
  2027. }
  2028. p = printk->printk;
  2029. /* Remove any quotes. */
  2030. if (*p == '"')
  2031. p++;
  2032. format = malloc_or_die(strlen(p) + 10);
  2033. sprintf(format, "%s : %s", "%pf", p);
  2034. /* remove ending quotes and new line since we will add one too */
  2035. p = format + strlen(format) - 1;
  2036. if (*p == '"')
  2037. *p = 0;
  2038. p -= 2;
  2039. if (strcmp(p, "\\n") == 0)
  2040. *p = 0;
  2041. return format;
  2042. }
  2043. static void pretty_print(void *data, int size, struct event *event)
  2044. {
  2045. struct print_fmt *print_fmt = &event->print_fmt;
  2046. struct print_arg *arg = print_fmt->args;
  2047. struct print_arg *args = NULL;
  2048. const char *ptr = print_fmt->format;
  2049. unsigned long long val;
  2050. struct func_map *func;
  2051. const char *saveptr;
  2052. char *bprint_fmt = NULL;
  2053. char format[32];
  2054. int show_func;
  2055. int len;
  2056. int ls;
  2057. if (event->flags & EVENT_FL_ISFUNC)
  2058. ptr = " %pF <-- %pF";
  2059. if (event->flags & EVENT_FL_ISBPRINT) {
  2060. bprint_fmt = get_bprint_format(data, size, event);
  2061. args = make_bprint_args(bprint_fmt, data, size, event);
  2062. arg = args;
  2063. ptr = bprint_fmt;
  2064. }
  2065. for (; *ptr; ptr++) {
  2066. ls = 0;
  2067. if (*ptr == '\\') {
  2068. ptr++;
  2069. switch (*ptr) {
  2070. case 'n':
  2071. printf("\n");
  2072. break;
  2073. case 't':
  2074. printf("\t");
  2075. break;
  2076. case 'r':
  2077. printf("\r");
  2078. break;
  2079. case '\\':
  2080. printf("\\");
  2081. break;
  2082. default:
  2083. printf("%c", *ptr);
  2084. break;
  2085. }
  2086. } else if (*ptr == '%') {
  2087. saveptr = ptr;
  2088. show_func = 0;
  2089. cont_process:
  2090. ptr++;
  2091. switch (*ptr) {
  2092. case '%':
  2093. printf("%%");
  2094. break;
  2095. case 'l':
  2096. ls++;
  2097. goto cont_process;
  2098. case 'L':
  2099. ls = 2;
  2100. goto cont_process;
  2101. case 'z':
  2102. case 'Z':
  2103. case '0' ... '9':
  2104. goto cont_process;
  2105. case 'p':
  2106. if (long_size == 4)
  2107. ls = 1;
  2108. else
  2109. ls = 2;
  2110. if (*(ptr+1) == 'F' ||
  2111. *(ptr+1) == 'f') {
  2112. ptr++;
  2113. show_func = *ptr;
  2114. }
  2115. /* fall through */
  2116. case 'd':
  2117. case 'i':
  2118. case 'x':
  2119. case 'X':
  2120. case 'u':
  2121. if (!arg)
  2122. die("no argument match");
  2123. len = ((unsigned long)ptr + 1) -
  2124. (unsigned long)saveptr;
  2125. /* should never happen */
  2126. if (len > 32)
  2127. die("bad format!");
  2128. memcpy(format, saveptr, len);
  2129. format[len] = 0;
  2130. val = eval_num_arg(data, size, event, arg);
  2131. arg = arg->next;
  2132. if (show_func) {
  2133. func = find_func(val);
  2134. if (func) {
  2135. printf("%s", func->func);
  2136. if (show_func == 'F')
  2137. printf("+0x%llx",
  2138. val - func->addr);
  2139. break;
  2140. }
  2141. }
  2142. switch (ls) {
  2143. case 0:
  2144. printf(format, (int)val);
  2145. break;
  2146. case 1:
  2147. printf(format, (long)val);
  2148. break;
  2149. case 2:
  2150. printf(format, (long long)val);
  2151. break;
  2152. default:
  2153. die("bad count (%d)", ls);
  2154. }
  2155. break;
  2156. case 's':
  2157. if (!arg)
  2158. die("no matching argument");
  2159. print_str_arg(data, size, event, arg);
  2160. arg = arg->next;
  2161. break;
  2162. default:
  2163. printf(">%c<", *ptr);
  2164. }
  2165. } else
  2166. printf("%c", *ptr);
  2167. }
  2168. if (args) {
  2169. free_args(args);
  2170. free(bprint_fmt);
  2171. }
  2172. }
  2173. static inline int log10_cpu(int nb)
  2174. {
  2175. if (nb / 100)
  2176. return 3;
  2177. if (nb / 10)
  2178. return 2;
  2179. return 1;
  2180. }
  2181. static void print_lat_fmt(void *data, int size __unused)
  2182. {
  2183. unsigned int lat_flags;
  2184. unsigned int pc;
  2185. int lock_depth;
  2186. int hardirq;
  2187. int softirq;
  2188. lat_flags = parse_common_flags(data);
  2189. pc = parse_common_pc(data);
  2190. lock_depth = parse_common_lock_depth(data);
  2191. hardirq = lat_flags & TRACE_FLAG_HARDIRQ;
  2192. softirq = lat_flags & TRACE_FLAG_SOFTIRQ;
  2193. printf("%c%c%c",
  2194. (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  2195. (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
  2196. 'X' : '.',
  2197. (lat_flags & TRACE_FLAG_NEED_RESCHED) ?
  2198. 'N' : '.',
  2199. (hardirq && softirq) ? 'H' :
  2200. hardirq ? 'h' : softirq ? 's' : '.');
  2201. if (pc)
  2202. printf("%x", pc);
  2203. else
  2204. printf(".");
  2205. if (lock_depth < 0)
  2206. printf(".");
  2207. else
  2208. printf("%d", lock_depth);
  2209. }
  2210. #define TRACE_GRAPH_INDENT 2
  2211. static struct record *
  2212. get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
  2213. struct record *next)
  2214. {
  2215. struct format_field *field;
  2216. struct event *event;
  2217. unsigned long val;
  2218. int type;
  2219. int pid;
  2220. type = trace_parse_common_type(next->data);
  2221. event = trace_find_event(type);
  2222. if (!event)
  2223. return NULL;
  2224. if (!(event->flags & EVENT_FL_ISFUNCRET))
  2225. return NULL;
  2226. pid = trace_parse_common_pid(next->data);
  2227. field = find_field(event, "func");
  2228. if (!field)
  2229. die("function return does not have field func");
  2230. val = read_size(next->data + field->offset, field->size);
  2231. if (cur_pid != pid || cur_func != val)
  2232. return NULL;
  2233. /* this is a leaf, now advance the iterator */
  2234. return trace_read_data(cpu);
  2235. }
  2236. /* Signal a overhead of time execution to the output */
  2237. static void print_graph_overhead(unsigned long long duration)
  2238. {
  2239. /* Non nested entry or return */
  2240. if (duration == ~0ULL)
  2241. return (void)printf(" ");
  2242. /* Duration exceeded 100 msecs */
  2243. if (duration > 100000ULL)
  2244. return (void)printf("! ");
  2245. /* Duration exceeded 10 msecs */
  2246. if (duration > 10000ULL)
  2247. return (void)printf("+ ");
  2248. printf(" ");
  2249. }
  2250. static void print_graph_duration(unsigned long long duration)
  2251. {
  2252. unsigned long usecs = duration / 1000;
  2253. unsigned long nsecs_rem = duration % 1000;
  2254. /* log10(ULONG_MAX) + '\0' */
  2255. char msecs_str[21];
  2256. char nsecs_str[5];
  2257. int len;
  2258. int i;
  2259. sprintf(msecs_str, "%lu", usecs);
  2260. /* Print msecs */
  2261. len = printf("%lu", usecs);
  2262. /* Print nsecs (we don't want to exceed 7 numbers) */
  2263. if (len < 7) {
  2264. snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
  2265. len += printf(".%s", nsecs_str);
  2266. }
  2267. printf(" us ");
  2268. /* Print remaining spaces to fit the row's width */
  2269. for (i = len; i < 7; i++)
  2270. printf(" ");
  2271. printf("| ");
  2272. }
  2273. static void
  2274. print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
  2275. {
  2276. unsigned long long rettime, calltime;
  2277. unsigned long long duration, depth;
  2278. unsigned long long val;
  2279. struct format_field *field;
  2280. struct func_map *func;
  2281. struct event *ret_event;
  2282. int type;
  2283. int i;
  2284. type = trace_parse_common_type(ret_rec->data);
  2285. ret_event = trace_find_event(type);
  2286. field = find_field(ret_event, "rettime");
  2287. if (!field)
  2288. die("can't find rettime in return graph");
  2289. rettime = read_size(ret_rec->data + field->offset, field->size);
  2290. field = find_field(ret_event, "calltime");
  2291. if (!field)
  2292. die("can't find rettime in return graph");
  2293. calltime = read_size(ret_rec->data + field->offset, field->size);
  2294. duration = rettime - calltime;
  2295. /* Overhead */
  2296. print_graph_overhead(duration);
  2297. /* Duration */
  2298. print_graph_duration(duration);
  2299. field = find_field(event, "depth");
  2300. if (!field)
  2301. die("can't find depth in entry graph");
  2302. depth = read_size(data + field->offset, field->size);
  2303. /* Function */
  2304. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2305. printf(" ");
  2306. field = find_field(event, "func");
  2307. if (!field)
  2308. die("can't find func in entry graph");
  2309. val = read_size(data + field->offset, field->size);
  2310. func = find_func(val);
  2311. if (func)
  2312. printf("%s();", func->func);
  2313. else
  2314. printf("%llx();", val);
  2315. }
  2316. static void print_graph_nested(struct event *event, void *data)
  2317. {
  2318. struct format_field *field;
  2319. unsigned long long depth;
  2320. unsigned long long val;
  2321. struct func_map *func;
  2322. int i;
  2323. /* No overhead */
  2324. print_graph_overhead(-1);
  2325. /* No time */
  2326. printf(" | ");
  2327. field = find_field(event, "depth");
  2328. if (!field)
  2329. die("can't find depth in entry graph");
  2330. depth = read_size(data + field->offset, field->size);
  2331. /* Function */
  2332. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2333. printf(" ");
  2334. field = find_field(event, "func");
  2335. if (!field)
  2336. die("can't find func in entry graph");
  2337. val = read_size(data + field->offset, field->size);
  2338. func = find_func(val);
  2339. if (func)
  2340. printf("%s() {", func->func);
  2341. else
  2342. printf("%llx() {", val);
  2343. }
  2344. static void
  2345. pretty_print_func_ent(void *data, int size, struct event *event,
  2346. int cpu, int pid, const char *comm __unused,
  2347. unsigned long secs, unsigned long usecs)
  2348. {
  2349. struct format_field *field;
  2350. struct record *rec;
  2351. void *copy_data;
  2352. unsigned long val;
  2353. printf("%5lu.%06lu | ", secs, usecs);
  2354. printf(" | ");
  2355. if (latency_format) {
  2356. print_lat_fmt(data, size);
  2357. printf(" | ");
  2358. }
  2359. field = find_field(event, "func");
  2360. if (!field)
  2361. die("function entry does not have func field");
  2362. val = read_size(data + field->offset, field->size);
  2363. /*
  2364. * peek_data may unmap the data pointer. Copy it first.
  2365. */
  2366. copy_data = malloc_or_die(size);
  2367. memcpy(copy_data, data, size);
  2368. data = copy_data;
  2369. rec = trace_peek_data(cpu);
  2370. if (rec) {
  2371. rec = get_return_for_leaf(cpu, pid, val, rec);
  2372. if (rec) {
  2373. print_graph_entry_leaf(event, data, rec);
  2374. goto out_free;
  2375. }
  2376. }
  2377. print_graph_nested(event, data);
  2378. out_free:
  2379. free(data);
  2380. }
  2381. static void
  2382. pretty_print_func_ret(void *data, int size __unused, struct event *event,
  2383. int cpu __unused, int pid __unused, const char *comm __unused,
  2384. unsigned long secs, unsigned long usecs)
  2385. {
  2386. unsigned long long rettime, calltime;
  2387. unsigned long long duration, depth;
  2388. struct format_field *field;
  2389. int i;
  2390. printf("%5lu.%06lu | ", secs, usecs);
  2391. printf(" | ");
  2392. if (latency_format) {
  2393. print_lat_fmt(data, size);
  2394. printf(" | ");
  2395. }
  2396. field = find_field(event, "rettime");
  2397. if (!field)
  2398. die("can't find rettime in return graph");
  2399. rettime = read_size(data + field->offset, field->size);
  2400. field = find_field(event, "calltime");
  2401. if (!field)
  2402. die("can't find calltime in return graph");
  2403. calltime = read_size(data + field->offset, field->size);
  2404. duration = rettime - calltime;
  2405. /* Overhead */
  2406. print_graph_overhead(duration);
  2407. /* Duration */
  2408. print_graph_duration(duration);
  2409. field = find_field(event, "depth");
  2410. if (!field)
  2411. die("can't find depth in entry graph");
  2412. depth = read_size(data + field->offset, field->size);
  2413. /* Function */
  2414. for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
  2415. printf(" ");
  2416. printf("}");
  2417. }
  2418. static void
  2419. pretty_print_func_graph(void *data, int size, struct event *event,
  2420. int cpu, int pid, const char *comm,
  2421. unsigned long secs, unsigned long usecs)
  2422. {
  2423. if (event->flags & EVENT_FL_ISFUNCENT)
  2424. pretty_print_func_ent(data, size, event,
  2425. cpu, pid, comm, secs, usecs);
  2426. else if (event->flags & EVENT_FL_ISFUNCRET)
  2427. pretty_print_func_ret(data, size, event,
  2428. cpu, pid, comm, secs, usecs);
  2429. printf("\n");
  2430. }
  2431. void print_event(int cpu, void *data, int size, unsigned long long nsecs,
  2432. char *comm)
  2433. {
  2434. struct event *event;
  2435. unsigned long secs;
  2436. unsigned long usecs;
  2437. int type;
  2438. int pid;
  2439. secs = nsecs / NSECS_PER_SEC;
  2440. nsecs -= secs * NSECS_PER_SEC;
  2441. usecs = nsecs / NSECS_PER_USEC;
  2442. type = trace_parse_common_type(data);
  2443. event = trace_find_event(type);
  2444. if (!event) {
  2445. warning("ug! no event found for type %d", type);
  2446. return;
  2447. }
  2448. pid = trace_parse_common_pid(data);
  2449. if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
  2450. return pretty_print_func_graph(data, size, event, cpu,
  2451. pid, comm, secs, usecs);
  2452. if (latency_format) {
  2453. printf("%8.8s-%-5d %3d",
  2454. comm, pid, cpu);
  2455. print_lat_fmt(data, size);
  2456. } else
  2457. printf("%16s-%-5d [%03d]", comm, pid, cpu);
  2458. printf(" %5lu.%06lu: %s: ", secs, usecs, event->name);
  2459. if (event->flags & EVENT_FL_FAILED) {
  2460. printf("EVENT '%s' FAILED TO PARSE\n",
  2461. event->name);
  2462. return;
  2463. }
  2464. pretty_print(data, size, event);
  2465. printf("\n");
  2466. }
  2467. static void print_fields(struct print_flag_sym *field)
  2468. {
  2469. printf("{ %s, %s }", field->value, field->str);
  2470. if (field->next) {
  2471. printf(", ");
  2472. print_fields(field->next);
  2473. }
  2474. }
  2475. static void print_args(struct print_arg *args)
  2476. {
  2477. int print_paren = 1;
  2478. switch (args->type) {
  2479. case PRINT_NULL:
  2480. printf("null");
  2481. break;
  2482. case PRINT_ATOM:
  2483. printf("%s", args->atom.atom);
  2484. break;
  2485. case PRINT_FIELD:
  2486. printf("REC->%s", args->field.name);
  2487. break;
  2488. case PRINT_FLAGS:
  2489. printf("__print_flags(");
  2490. print_args(args->flags.field);
  2491. printf(", %s, ", args->flags.delim);
  2492. print_fields(args->flags.flags);
  2493. printf(")");
  2494. break;
  2495. case PRINT_SYMBOL:
  2496. printf("__print_symbolic(");
  2497. print_args(args->symbol.field);
  2498. printf(", ");
  2499. print_fields(args->symbol.symbols);
  2500. printf(")");
  2501. break;
  2502. case PRINT_STRING:
  2503. printf("__get_str(%s)", args->string.string);
  2504. break;
  2505. case PRINT_TYPE:
  2506. printf("(%s)", args->typecast.type);
  2507. print_args(args->typecast.item);
  2508. break;
  2509. case PRINT_OP:
  2510. if (strcmp(args->op.op, ":") == 0)
  2511. print_paren = 0;
  2512. if (print_paren)
  2513. printf("(");
  2514. print_args(args->op.left);
  2515. printf(" %s ", args->op.op);
  2516. print_args(args->op.right);
  2517. if (print_paren)
  2518. printf(")");
  2519. break;
  2520. default:
  2521. /* we should warn... */
  2522. return;
  2523. }
  2524. if (args->next) {
  2525. printf("\n");
  2526. print_args(args->next);
  2527. }
  2528. }
  2529. int parse_ftrace_file(char *buf, unsigned long size)
  2530. {
  2531. struct format_field *field;
  2532. struct print_arg *arg, **list;
  2533. struct event *event;
  2534. int ret;
  2535. init_input_buf(buf, size);
  2536. event = alloc_event();
  2537. if (!event)
  2538. return -ENOMEM;
  2539. event->flags |= EVENT_FL_ISFTRACE;
  2540. event->name = event_read_name();
  2541. if (!event->name)
  2542. die("failed to read ftrace event name");
  2543. if (strcmp(event->name, "function") == 0)
  2544. event->flags |= EVENT_FL_ISFUNC;
  2545. else if (strcmp(event->name, "funcgraph_entry") == 0)
  2546. event->flags |= EVENT_FL_ISFUNCENT;
  2547. else if (strcmp(event->name, "funcgraph_exit") == 0)
  2548. event->flags |= EVENT_FL_ISFUNCRET;
  2549. else if (strcmp(event->name, "bprint") == 0)
  2550. event->flags |= EVENT_FL_ISBPRINT;
  2551. event->id = event_read_id();
  2552. if (event->id < 0)
  2553. die("failed to read ftrace event id");
  2554. add_event(event);
  2555. ret = event_read_format(event);
  2556. if (ret < 0)
  2557. die("failed to read ftrace event format");
  2558. ret = event_read_print(event);
  2559. if (ret < 0)
  2560. die("failed to read ftrace event print fmt");
  2561. /* New ftrace handles args */
  2562. if (ret > 0)
  2563. return 0;
  2564. /*
  2565. * The arguments for ftrace files are parsed by the fields.
  2566. * Set up the fields as their arguments.
  2567. */
  2568. list = &event->print_fmt.args;
  2569. for (field = event->format.fields; field; field = field->next) {
  2570. arg = malloc_or_die(sizeof(*arg));
  2571. memset(arg, 0, sizeof(*arg));
  2572. *list = arg;
  2573. list = &arg->next;
  2574. arg->type = PRINT_FIELD;
  2575. arg->field.name = field->name;
  2576. arg->field.field = field;
  2577. }
  2578. return 0;
  2579. }
  2580. int parse_event_file(char *buf, unsigned long size, char *sys)
  2581. {
  2582. struct event *event;
  2583. int ret;
  2584. init_input_buf(buf, size);
  2585. event = alloc_event();
  2586. if (!event)
  2587. return -ENOMEM;
  2588. event->name = event_read_name();
  2589. if (!event->name)
  2590. die("failed to read event name");
  2591. event->id = event_read_id();
  2592. if (event->id < 0)
  2593. die("failed to read event id");
  2594. ret = event_read_format(event);
  2595. if (ret < 0) {
  2596. warning("failed to read event format for %s", event->name);
  2597. goto event_failed;
  2598. }
  2599. ret = event_read_print(event);
  2600. if (ret < 0) {
  2601. warning("failed to read event print fmt for %s", event->name);
  2602. goto event_failed;
  2603. }
  2604. event->system = strdup(sys);
  2605. #define PRINT_ARGS 0
  2606. if (PRINT_ARGS && event->print_fmt.args)
  2607. print_args(event->print_fmt.args);
  2608. add_event(event);
  2609. return 0;
  2610. event_failed:
  2611. event->flags |= EVENT_FL_FAILED;
  2612. /* still add it even if it failed */
  2613. add_event(event);
  2614. return -1;
  2615. }
  2616. void parse_set_info(int nr_cpus, int long_sz)
  2617. {
  2618. cpus = nr_cpus;
  2619. long_size = long_sz;
  2620. }
  2621. int common_pc(struct scripting_context *context)
  2622. {
  2623. return parse_common_pc(context->event_data);
  2624. }
  2625. int common_flags(struct scripting_context *context)
  2626. {
  2627. return parse_common_flags(context->event_data);
  2628. }
  2629. int common_lock_depth(struct scripting_context *context)
  2630. {
  2631. return parse_common_lock_depth(context->event_data);
  2632. }