* sysdeps/m68k/fpu/s_nextafterl.c: New file.
[glibc/pb-stable.git] / debug / pcprofiledump.c
bloba5dad71e0a7c0ebae6e9e0be357e003c08d8e9ea
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. */
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <argp.h>
28 #include <byteswap.h>
29 #include <errno.h>
30 #include <error.h>
31 #include <fcntl.h>
32 #include <inttypes.h>
33 #include <libintl.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <unistd.h>
38 #include "../version.h"
41 #ifndef _
42 # define _(Str) gettext (Str)
43 #endif
45 #ifndef N_
46 # define N_(Str) Str
47 #endif
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
71 int
72 main (int argc, char *argv[])
74 int fd;
75 int remaining;
76 int must_swap;
77 uint32_t word;
79 /* Parse and process arguments. */
80 argp_parse (&argp, argc, argv, 0, &remaining, NULL);
82 if (remaining == argc)
83 fd = STDIN_FILENO;
84 else if (remaining + 1 != argc)
86 argp_help (&argp, stdout, ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR,
87 program_invocation_short_name);
88 exit (1);
90 else
92 /* Open the given file. */
93 fd = open (argv[remaining], O_RDONLY);
95 if (fd == -1)
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);
106 if (must_swap)
107 word = bswap_32 (word);
109 /* We have two loops, one for 32 bit pointers, one for 64 bit pointers. */
110 if (word == 0xdeb00004)
112 union
114 uint32_t ptrs[2];
115 char bytes[8];
116 } pair;
118 while (1)
120 size_t len = sizeof (pair);
121 size_t n;
123 while (len > 0
124 && (n = TEMP_FAILURE_RETRY (read (fd, &pair.bytes[8 - len],
125 len))) != 0)
126 len -= n;
128 if (len != 0)
129 /* Nothing to read. */
130 break;
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)
139 union
141 uint64_t ptrs[2];
142 char bytes[16];
143 } pair;
145 while (1)
147 size_t len = sizeof (pair);
148 size_t n;
150 while (len > 0
151 && (n = TEMP_FAILURE_RETRY (read (fd, &pair.bytes[8 - len],
152 len))) != 0)
153 len -= n;
155 if (len != 0)
156 /* Nothing to read. */
157 break;
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]);
164 else
165 /* This should not happen. */
166 error (EXIT_FAILURE, 0, _("invalid pointer size"));
168 /* Clean up. */
169 close (fd);
171 return 0;
174 static char *
175 more_help (int key, const char *text, void *input)
177 switch (key)
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"));
183 default:
184 break;
186 return (char *) text;