gmon_io.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* gmon_io.c - Input and output from/to gmon.out files.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "gprof.h"
  17. #include "binary-io.h"
  18. #include "search_list.h"
  19. #include "source.h"
  20. #include "symtab.h"
  21. #include "cg_arcs.h"
  22. #include "basic_blocks.h"
  23. #include "corefile.h"
  24. #include "call_graph.h"
  25. #include "gmon_io.h"
  26. #include "gmon_out.h"
  27. #include "gmon.h" /* Fetch header for old format. */
  28. #include "hertz.h"
  29. #include "hist.h"
  30. #include "libiberty.h"
  31. enum gmon_ptr_size {
  32. ptr_32bit,
  33. ptr_64bit
  34. };
  35. enum gmon_ptr_signedness {
  36. ptr_signed,
  37. ptr_unsigned
  38. };
  39. static enum gmon_ptr_size gmon_get_ptr_size (void);
  40. static enum gmon_ptr_signedness gmon_get_ptr_signedness (void);
  41. #ifdef BFD_HOST_U_64_BIT
  42. static int gmon_io_read_64 (FILE *, BFD_HOST_U_64_BIT *);
  43. static int gmon_io_write_64 (FILE *, BFD_HOST_U_64_BIT);
  44. #endif
  45. static int gmon_read_raw_arc
  46. (FILE *, bfd_vma *, bfd_vma *, unsigned long *);
  47. static int gmon_write_raw_arc
  48. (FILE *, bfd_vma, bfd_vma, unsigned long);
  49. int gmon_input = 0;
  50. int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */
  51. static enum gmon_ptr_size
  52. gmon_get_ptr_size (void)
  53. {
  54. int size;
  55. /* Pick best size for pointers. Start with the ELF size, and if not
  56. elf go with the architecture's address size. */
  57. size = bfd_get_arch_size (core_bfd);
  58. if (size == -1)
  59. size = bfd_arch_bits_per_address (core_bfd);
  60. switch (size)
  61. {
  62. case 32:
  63. return ptr_32bit;
  64. case 64:
  65. return ptr_64bit;
  66. default:
  67. fprintf (stderr, _("%s: address size has unexpected value of %u\n"),
  68. whoami, size);
  69. done (1);
  70. }
  71. }
  72. static enum gmon_ptr_signedness
  73. gmon_get_ptr_signedness (void)
  74. {
  75. int sext;
  76. /* Figure out whether to sign extend. If BFD doesn't know, assume no. */
  77. sext = bfd_get_sign_extend_vma (core_bfd);
  78. if (sext == -1)
  79. return ptr_unsigned;
  80. return (sext ? ptr_signed : ptr_unsigned);
  81. }
  82. int
  83. gmon_io_read_32 (FILE *ifp, unsigned int *valp)
  84. {
  85. char buf[4];
  86. if (fread (buf, 1, 4, ifp) != 4)
  87. return 1;
  88. *valp = bfd_get_32 (core_bfd, buf);
  89. return 0;
  90. }
  91. #ifdef BFD_HOST_U_64_BIT
  92. static int
  93. gmon_io_read_64 (FILE *ifp, BFD_HOST_U_64_BIT *valp)
  94. {
  95. char buf[8];
  96. if (fread (buf, 1, 8, ifp) != 8)
  97. return 1;
  98. *valp = bfd_get_64 (core_bfd, buf);
  99. return 0;
  100. }
  101. #endif
  102. int
  103. gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
  104. {
  105. unsigned int val32;
  106. #ifdef BFD_HOST_U_64_BIT
  107. BFD_HOST_U_64_BIT val64;
  108. #endif
  109. switch (gmon_get_ptr_size ())
  110. {
  111. case ptr_32bit:
  112. if (gmon_io_read_32 (ifp, &val32))
  113. return 1;
  114. if (gmon_get_ptr_signedness () == ptr_signed)
  115. *valp = (int) val32;
  116. else
  117. *valp = val32;
  118. break;
  119. #ifdef BFD_HOST_U_64_BIT
  120. case ptr_64bit:
  121. if (gmon_io_read_64 (ifp, &val64))
  122. return 1;
  123. #ifdef BFD_HOST_64_BIT
  124. if (gmon_get_ptr_signedness () == ptr_signed)
  125. *valp = (BFD_HOST_64_BIT) val64;
  126. else
  127. #endif
  128. *valp = val64;
  129. break;
  130. #endif
  131. }
  132. return 0;
  133. }
  134. int
  135. gmon_io_read (FILE *ifp, char *buf, size_t n)
  136. {
  137. if (fread (buf, 1, n, ifp) != n)
  138. return 1;
  139. return 0;
  140. }
  141. int
  142. gmon_io_write_32 (FILE *ofp, unsigned int val)
  143. {
  144. char buf[4];
  145. bfd_put_32 (core_bfd, (bfd_vma) val, buf);
  146. if (fwrite (buf, 1, 4, ofp) != 4)
  147. return 1;
  148. return 0;
  149. }
  150. #ifdef BFD_HOST_U_64_BIT
  151. static int
  152. gmon_io_write_64 (FILE *ofp, BFD_HOST_U_64_BIT val)
  153. {
  154. char buf[8];
  155. bfd_put_64 (core_bfd, (bfd_vma) val, buf);
  156. if (fwrite (buf, 1, 8, ofp) != 8)
  157. return 1;
  158. return 0;
  159. }
  160. #endif
  161. int
  162. gmon_io_write_vma (FILE *ofp, bfd_vma val)
  163. {
  164. switch (gmon_get_ptr_size ())
  165. {
  166. case ptr_32bit:
  167. if (gmon_io_write_32 (ofp, (unsigned int) val))
  168. return 1;
  169. break;
  170. #ifdef BFD_HOST_U_64_BIT
  171. case ptr_64bit:
  172. if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) val))
  173. return 1;
  174. break;
  175. #endif
  176. }
  177. return 0;
  178. }
  179. int
  180. gmon_io_write_8 (FILE *ofp, unsigned int val)
  181. {
  182. char buf[1];
  183. bfd_put_8 (core_bfd, val, buf);
  184. if (fwrite (buf, 1, 1, ofp) != 1)
  185. return 1;
  186. return 0;
  187. }
  188. int
  189. gmon_io_write (FILE *ofp, char *buf, size_t n)
  190. {
  191. if (fwrite (buf, 1, n, ofp) != n)
  192. return 1;
  193. return 0;
  194. }
  195. static int
  196. gmon_read_raw_arc (FILE *ifp, bfd_vma *fpc, bfd_vma *spc, unsigned long *cnt)
  197. {
  198. #ifdef BFD_HOST_U_64_BIT
  199. BFD_HOST_U_64_BIT cnt64;
  200. #endif
  201. unsigned int cnt32;
  202. if (gmon_io_read_vma (ifp, fpc)
  203. || gmon_io_read_vma (ifp, spc))
  204. return 1;
  205. switch (gmon_get_ptr_size ())
  206. {
  207. case ptr_32bit:
  208. if (gmon_io_read_32 (ifp, &cnt32))
  209. return 1;
  210. *cnt = cnt32;
  211. break;
  212. #ifdef BFD_HOST_U_64_BIT
  213. case ptr_64bit:
  214. if (gmon_io_read_64 (ifp, &cnt64))
  215. return 1;
  216. *cnt = cnt64;
  217. break;
  218. #endif
  219. default:
  220. return 1;
  221. }
  222. return 0;
  223. }
  224. static int
  225. gmon_write_raw_arc (FILE *ofp, bfd_vma fpc, bfd_vma spc, unsigned long cnt)
  226. {
  227. if (gmon_io_write_vma (ofp, fpc)
  228. || gmon_io_write_vma (ofp, spc))
  229. return 1;
  230. switch (gmon_get_ptr_size ())
  231. {
  232. case ptr_32bit:
  233. if (gmon_io_write_32 (ofp, (unsigned int) cnt))
  234. return 1;
  235. break;
  236. #ifdef BFD_HOST_U_64_BIT
  237. case ptr_64bit:
  238. if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) cnt))
  239. return 1;
  240. break;
  241. #endif
  242. }
  243. return 0;
  244. }
  245. void
  246. gmon_out_read (const char *filename)
  247. {
  248. FILE *ifp;
  249. struct gmon_hdr ghdr;
  250. unsigned char tag;
  251. int nhist = 0, narcs = 0, nbbs = 0;
  252. /* Open gmon.out file. */
  253. if (strcmp (filename, "-") == 0)
  254. {
  255. ifp = stdin;
  256. SET_BINARY (fileno (stdin));
  257. }
  258. else
  259. {
  260. ifp = fopen (filename, FOPEN_RB);
  261. if (!ifp)
  262. {
  263. perror (filename);
  264. done (1);
  265. }
  266. }
  267. if (fread (&ghdr, sizeof (struct gmon_hdr), 1, ifp) != 1)
  268. {
  269. fprintf (stderr, _("%s: file too short to be a gmon file\n"),
  270. filename);
  271. done (1);
  272. }
  273. if ((file_format == FF_MAGIC)
  274. || (file_format == FF_AUTO && !strncmp (&ghdr.cookie[0], GMON_MAGIC, 4)))
  275. {
  276. if (file_format == FF_MAGIC && strncmp (&ghdr.cookie[0], GMON_MAGIC, 4))
  277. {
  278. fprintf (stderr, _("%s: file `%s' has bad magic cookie\n"),
  279. whoami, filename);
  280. done (1);
  281. }
  282. /* Right magic, so it's probably really a new gmon.out file. */
  283. gmon_file_version = bfd_get_32 (core_bfd, (bfd_byte *) ghdr.version);
  284. if (gmon_file_version != GMON_VERSION && gmon_file_version != 0)
  285. {
  286. fprintf (stderr,
  287. _("%s: file `%s' has unsupported version %d\n"),
  288. whoami, filename, gmon_file_version);
  289. done (1);
  290. }
  291. /* Read in all the records. */
  292. while (fread (&tag, sizeof (tag), 1, ifp) == 1)
  293. {
  294. switch (tag)
  295. {
  296. case GMON_TAG_TIME_HIST:
  297. ++nhist;
  298. gmon_input |= INPUT_HISTOGRAM;
  299. hist_read_rec (ifp, filename);
  300. break;
  301. case GMON_TAG_CG_ARC:
  302. ++narcs;
  303. gmon_input |= INPUT_CALL_GRAPH;
  304. cg_read_rec (ifp, filename);
  305. break;
  306. case GMON_TAG_BB_COUNT:
  307. ++nbbs;
  308. gmon_input |= INPUT_BB_COUNTS;
  309. bb_read_rec (ifp, filename);
  310. break;
  311. default:
  312. fprintf (stderr,
  313. _("%s: %s: found bad tag %d (file corrupted?)\n"),
  314. whoami, filename, tag);
  315. done (1);
  316. }
  317. }
  318. }
  319. else if (file_format == FF_AUTO
  320. || file_format == FF_BSD
  321. || file_format == FF_BSD44)
  322. {
  323. struct hdr
  324. {
  325. bfd_vma low_pc;
  326. bfd_vma high_pc;
  327. unsigned int ncnt;
  328. };
  329. unsigned int i;
  330. int samp_bytes, header_size = 0;
  331. unsigned long count;
  332. bfd_vma from_pc, self_pc;
  333. UNIT raw_bin_count;
  334. struct hdr tmp;
  335. unsigned int version;
  336. unsigned int hist_num_bins;
  337. /* Information from a gmon.out file is in two parts: an array of
  338. sampling hits within pc ranges, and the arcs. */
  339. gmon_input = INPUT_HISTOGRAM | INPUT_CALL_GRAPH;
  340. /* This fseek() ought to work even on stdin as long as it's
  341. not an interactive device (heck, is there anybody who would
  342. want to type in a gmon.out at the terminal?). */
  343. if (fseek (ifp, 0, SEEK_SET) < 0)
  344. {
  345. perror (filename);
  346. done (1);
  347. }
  348. /* The beginning of the old BSD header and the 4.4BSD header
  349. are the same: lowpc, highpc, ncnt */
  350. if (gmon_io_read_vma (ifp, &tmp.low_pc)
  351. || gmon_io_read_vma (ifp, &tmp.high_pc)
  352. || gmon_io_read_32 (ifp, &tmp.ncnt))
  353. {
  354. bad_gmon_file:
  355. fprintf (stderr, _("%s: file too short to be a gmon file\n"),
  356. filename);
  357. done (1);
  358. }
  359. /* Check to see if this a 4.4BSD-style header. */
  360. if (gmon_io_read_32 (ifp, &version))
  361. goto bad_gmon_file;
  362. if (version == GMONVERSION)
  363. {
  364. unsigned int profrate;
  365. /* 4.4BSD format header. */
  366. if (gmon_io_read_32 (ifp, &profrate))
  367. goto bad_gmon_file;
  368. if (!histograms)
  369. hz = profrate;
  370. else if (hz != (int) profrate)
  371. {
  372. fprintf (stderr,
  373. _("%s: profiling rate incompatible with first gmon file\n"),
  374. filename);
  375. done (1);
  376. }
  377. switch (gmon_get_ptr_size ())
  378. {
  379. case ptr_32bit:
  380. header_size = GMON_HDRSIZE_BSD44_32;
  381. break;
  382. case ptr_64bit:
  383. header_size = GMON_HDRSIZE_BSD44_64;
  384. break;
  385. }
  386. }
  387. else
  388. {
  389. /* Old style BSD format. */
  390. if (file_format == FF_BSD44)
  391. {
  392. fprintf (stderr, _("%s: file `%s' has bad magic cookie\n"),
  393. whoami, filename);
  394. done (1);
  395. }
  396. switch (gmon_get_ptr_size ())
  397. {
  398. case ptr_32bit:
  399. header_size = GMON_HDRSIZE_OLDBSD_32;
  400. break;
  401. case ptr_64bit:
  402. header_size = GMON_HDRSIZE_OLDBSD_64;
  403. break;
  404. }
  405. }
  406. /* Position the file to after the header. */
  407. if (fseek (ifp, header_size, SEEK_SET) < 0)
  408. {
  409. perror (filename);
  410. done (1);
  411. }
  412. samp_bytes = tmp.ncnt - header_size;
  413. hist_num_bins = samp_bytes / sizeof (UNIT);
  414. if (histograms && (tmp.low_pc != histograms->lowpc
  415. || tmp.high_pc != histograms->highpc
  416. || (hist_num_bins != histograms->num_bins)))
  417. {
  418. fprintf (stderr, _("%s: incompatible with first gmon file\n"),
  419. filename);
  420. done (1);
  421. }
  422. if (!histograms)
  423. {
  424. num_histograms = 1;
  425. histograms = (struct histogram *) xmalloc (sizeof (struct histogram));
  426. histograms->lowpc = tmp.low_pc;
  427. histograms->highpc = tmp.high_pc;
  428. histograms->num_bins = hist_num_bins;
  429. hist_scale = (double)((tmp.high_pc - tmp.low_pc) / sizeof (UNIT))
  430. / hist_num_bins;
  431. histograms->sample = (int *) xmalloc (hist_num_bins * sizeof (int));
  432. memset (histograms->sample, 0,
  433. hist_num_bins * sizeof (int));
  434. }
  435. DBG (SAMPLEDEBUG,
  436. printf ("[gmon_out_read] lowpc 0x%lx highpc 0x%lx ncnt %d\n",
  437. (unsigned long) tmp.low_pc, (unsigned long) tmp.high_pc,
  438. tmp.ncnt);
  439. printf ("[gmon_out_read] samp_bytes %d hist_num_bins %d\n",
  440. samp_bytes, hist_num_bins));
  441. /* Make sure that we have sensible values. */
  442. if (samp_bytes < 0 || histograms->lowpc > histograms->highpc)
  443. {
  444. fprintf (stderr,
  445. _("%s: file '%s' does not appear to be in gmon.out format\n"),
  446. whoami, filename);
  447. done (1);
  448. }
  449. if (hist_num_bins)
  450. ++nhist;
  451. for (i = 0; i < hist_num_bins; ++i)
  452. {
  453. if (fread (raw_bin_count, sizeof (raw_bin_count), 1, ifp) != 1)
  454. {
  455. fprintf (stderr,
  456. _("%s: unexpected EOF after reading %d/%d bins\n"),
  457. whoami, --i, hist_num_bins);
  458. done (1);
  459. }
  460. histograms->sample[i]
  461. += bfd_get_16 (core_bfd, (bfd_byte *) raw_bin_count);
  462. }
  463. /* The rest of the file consists of a bunch of
  464. <from,self,count> tuples. */
  465. while (gmon_read_raw_arc (ifp, &from_pc, &self_pc, &count) == 0)
  466. {
  467. ++narcs;
  468. DBG (SAMPLEDEBUG,
  469. printf ("[gmon_out_read] frompc 0x%lx selfpc 0x%lx count %lu\n",
  470. (unsigned long) from_pc, (unsigned long) self_pc, count));
  471. /* Add this arc. */
  472. cg_tally (from_pc, self_pc, count);
  473. }
  474. if (hz == HZ_WRONG)
  475. {
  476. /* How many ticks per second? If we can't tell, report
  477. time in ticks. */
  478. hz = hertz ();
  479. if (hz == HZ_WRONG)
  480. {
  481. hz = 1;
  482. fprintf (stderr, _("time is in ticks, not seconds\n"));
  483. }
  484. }
  485. }
  486. else
  487. {
  488. fprintf (stderr, _("%s: don't know how to deal with file format %d\n"),
  489. whoami, file_format);
  490. done (1);
  491. }
  492. if (ifp != stdin)
  493. fclose (ifp);
  494. if (output_style & STYLE_GMON_INFO)
  495. {
  496. printf (_("File `%s' (version %d) contains:\n"),
  497. filename, gmon_file_version);
  498. printf (nhist == 1 ?
  499. _("\t%d histogram record\n") :
  500. _("\t%d histogram records\n"), nhist);
  501. printf (narcs == 1 ?
  502. _("\t%d call-graph record\n") :
  503. _("\t%d call-graph records\n"), narcs);
  504. printf (nbbs == 1 ?
  505. _("\t%d basic-block count record\n") :
  506. _("\t%d basic-block count records\n"), nbbs);
  507. first_output = false;
  508. }
  509. }
  510. void
  511. gmon_out_write (const char *filename)
  512. {
  513. FILE *ofp;
  514. struct gmon_hdr ghdr;
  515. ofp = fopen (filename, FOPEN_WB);
  516. if (!ofp)
  517. {
  518. perror (filename);
  519. done (1);
  520. }
  521. if (file_format == FF_AUTO || file_format == FF_MAGIC)
  522. {
  523. /* Write gmon header. */
  524. memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
  525. bfd_put_32 (core_bfd, (bfd_vma) GMON_VERSION, (bfd_byte *) ghdr.version);
  526. if (fwrite (&ghdr, sizeof (ghdr), 1, ofp) != 1)
  527. {
  528. perror (filename);
  529. done (1);
  530. }
  531. /* Write execution time histogram if we have one. */
  532. if (gmon_input & INPUT_HISTOGRAM)
  533. hist_write_hist (ofp, filename);
  534. /* Write call graph arcs if we have any. */
  535. if (gmon_input & INPUT_CALL_GRAPH)
  536. cg_write_arcs (ofp, filename);
  537. /* Write basic-block info if we have it. */
  538. if (gmon_input & INPUT_BB_COUNTS)
  539. bb_write_blocks (ofp, filename);
  540. }
  541. else if (file_format == FF_BSD || file_format == FF_BSD44)
  542. {
  543. UNIT raw_bin_count;
  544. unsigned int i, hdrsize;
  545. unsigned padsize;
  546. char pad[3*4];
  547. Arc *arc;
  548. Sym *sym;
  549. memset (pad, 0, sizeof (pad));
  550. hdrsize = 0;
  551. /* Decide how large the header will be. Use the 4.4BSD format
  552. header if explicitly specified, or if the profiling rate is
  553. non-standard. Otherwise, use the old BSD format. */
  554. if (file_format == FF_BSD44
  555. || hz != hertz())
  556. {
  557. padsize = 3*4;
  558. switch (gmon_get_ptr_size ())
  559. {
  560. case ptr_32bit:
  561. hdrsize = GMON_HDRSIZE_BSD44_32;
  562. break;
  563. case ptr_64bit:
  564. hdrsize = GMON_HDRSIZE_BSD44_64;
  565. break;
  566. }
  567. }
  568. else
  569. {
  570. padsize = 0;
  571. switch (gmon_get_ptr_size ())
  572. {
  573. case ptr_32bit:
  574. hdrsize = GMON_HDRSIZE_OLDBSD_32;
  575. break;
  576. case ptr_64bit:
  577. hdrsize = GMON_HDRSIZE_OLDBSD_64;
  578. /* FIXME: Checking host compiler defines here means that we can't
  579. use a cross gprof alpha OSF. */
  580. #if defined(__alpha__) && defined (__osf__)
  581. padsize = 4;
  582. #endif
  583. break;
  584. }
  585. }
  586. /* Write the parts of the headers that are common to both the
  587. old BSD and 4.4BSD formats. */
  588. if (gmon_io_write_vma (ofp, histograms->lowpc)
  589. || gmon_io_write_vma (ofp, histograms->highpc)
  590. || gmon_io_write_32 (ofp, histograms->num_bins
  591. * sizeof (UNIT) + hdrsize))
  592. {
  593. perror (filename);
  594. done (1);
  595. }
  596. /* Write out the 4.4BSD header bits, if that's what we're using. */
  597. if (file_format == FF_BSD44
  598. || hz != hertz())
  599. {
  600. if (gmon_io_write_32 (ofp, GMONVERSION)
  601. || gmon_io_write_32 (ofp, (unsigned int) hz))
  602. {
  603. perror (filename);
  604. done (1);
  605. }
  606. }
  607. /* Now write out any necessary padding after the meaningful
  608. header bits. */
  609. if (padsize != 0
  610. && fwrite (pad, 1, padsize, ofp) != padsize)
  611. {
  612. perror (filename);
  613. done (1);
  614. }
  615. /* Dump the samples. */
  616. for (i = 0; i < histograms->num_bins; ++i)
  617. {
  618. bfd_put_16 (core_bfd, (bfd_vma) histograms->sample[i],
  619. (bfd_byte *) &raw_bin_count[0]);
  620. if (fwrite (&raw_bin_count[0], sizeof (raw_bin_count), 1, ofp) != 1)
  621. {
  622. perror (filename);
  623. done (1);
  624. }
  625. }
  626. /* Dump the normalized raw arc information. */
  627. for (sym = symtab.base; sym < symtab.limit; ++sym)
  628. {
  629. for (arc = sym->cg.children; arc; arc = arc->next_child)
  630. {
  631. if (gmon_write_raw_arc (ofp, arc->parent->addr,
  632. arc->child->addr, arc->count))
  633. {
  634. perror (filename);
  635. done (1);
  636. }
  637. DBG (SAMPLEDEBUG,
  638. printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %lu\n",
  639. (unsigned long) arc->parent->addr,
  640. (unsigned long) arc->child->addr, arc->count));
  641. }
  642. }
  643. fclose (ofp);
  644. }
  645. else
  646. {
  647. fprintf (stderr, _("%s: don't know how to deal with file format %d\n"),
  648. whoami, file_format);
  649. done (1);
  650. }
  651. }