1 /* Dump information generated by PC profiling.
2 Copyright (C) 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This is mainly and example. It shows how programs which want to use
22 the information should read the file. */
38 #include "../version.h"
42 # define _(Str) gettext (Str)
49 /* Definitions of arguments for argp functions. */
50 static const struct argp_option options
[] =
52 { NULL
, 0, NULL
, 0, NULL
}
55 /* Short description of program. */
56 static const char doc
[] = N_("Dump information generated by PC profiling.");
58 /* Strings for arguments in help texts. */
59 static const char args_doc
[] = N_("[FILE]");
61 /* Function to print some extra text in the help message. */
62 static char *more_help (int key
, const char *text
, void *input
);
64 /* Data structure to communicate with argp functions. */
65 static struct argp argp
=
67 options
, NULL
, args_doc
, doc
, NULL
, more_help
72 main (int argc
, char *argv
[])
79 /* Parse and process arguments. */
80 argp_parse (&argp
, argc
, argv
, 0, &remaining
, NULL
);
82 if (remaining
== argc
)
84 else if (remaining
+ 1 != argc
)
86 argp_help (&argp
, stdout
, ARGP_HELP_SEE
| ARGP_HELP_EXIT_ERR
,
87 program_invocation_short_name
);
92 /* Open the given file. */
93 fd
= open (argv
[remaining
], O_RDONLY
);
96 error (EXIT_FAILURE
, errno
, _("cannot open input file"));
99 /* Read the first 4-byte word. It contains the information about
100 the word size and the endianess. */
101 if (TEMP_FAILURE_RETRY (read (fd
, &word
, 4)) != 4)
102 error (EXIT_FAILURE
, errno
, _("cannot read header"));
104 /* Check whether we have to swap the byte order. */
105 must_swap
= (word
& 0xfffffff0) == bswap_32 (0xdeb00000);
107 word
= bswap_32 (word
);
109 /* We have two loops, one for 32 bit pointers, one for 64 bit pointers. */
110 if (word
== 0xdeb00004)
120 size_t len
= sizeof (pair
);
124 && (n
= TEMP_FAILURE_RETRY (read (fd
, &pair
.bytes
[8 - len
],
129 /* Nothing to read. */
132 printf ("this = %#010" PRIx32
", caller = %#010" PRIx32
"\n",
133 must_swap
? bswap_32 (pair
.ptrs
[0]) : pair
.ptrs
[0],
134 must_swap
? bswap_32 (pair
.ptrs
[1]) : pair
.ptrs
[1]);
137 else if (word
== 0xdeb00008)
147 size_t len
= sizeof (pair
);
151 && (n
= TEMP_FAILURE_RETRY (read (fd
, &pair
.bytes
[8 - len
],
156 /* Nothing to read. */
159 printf ("this = %#018" PRIx64
", caller = %#018" PRIx64
"\n",
160 must_swap
? bswap_64 (pair
.ptrs
[0]) : pair
.ptrs
[0],
161 must_swap
? bswap_64 (pair
.ptrs
[1]) : pair
.ptrs
[1]);
165 /* This should not happen. */
166 error (EXIT_FAILURE
, 0, _("invalid pointer size"));
175 more_help (int key
, const char *text
, void *input
)
179 case ARGP_KEY_HELP_EXTRA
:
180 /* We print some extra information. */
181 return strdup (gettext ("\
182 Report bugs using the `glibcbug' script to <bugs@gnu.org>.\n"));
186 return (char *) text
;