trace-event-parse.c 62 KB

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