1 /* Cell-based print utility routines for GDB, the GNU debugger.
3 Copyright (C) 1986-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "print-utils.h"
29 /* Temporary storage using circular buffer. */
34 /* Return the next entry in the circular buffer. */
39 static char buf
[NUMCELLS
][CELLSIZE
];
42 if (++cell
>= NUMCELLS
)
48 decimal2str (char *sign
, ULONGEST addr
, int width
)
50 /* Steal code from valprint.c:print_decimal(). Should this worry
51 about the real size of addr as the above does? */
52 unsigned long temp
[3];
53 char *str
= get_cell ();
58 temp
[i
] = addr
% (1000 * 1000 * 1000);
59 addr
/= (1000 * 1000 * 1000);
63 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
72 xsnprintf (str
, CELLSIZE
, "%s%0*lu", sign
, width
, temp
[0]);
75 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu", sign
, width
,
79 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu%09lu", sign
, width
,
80 temp
[2], temp
[1], temp
[0]);
83 internal_error (__FILE__
, __LINE__
,
84 _("failed internal consistency check"));
91 octal2str (ULONGEST addr
, int width
)
93 unsigned long temp
[3];
94 char *str
= get_cell ();
99 temp
[i
] = addr
% (0100000 * 0100000);
100 addr
/= (0100000 * 0100000);
104 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
114 xsnprintf (str
, CELLSIZE
, "%*o", width
, 0);
116 xsnprintf (str
, CELLSIZE
, "0%0*lo", width
, temp
[0]);
119 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo", width
, temp
[1], temp
[0]);
122 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo%010lo", width
,
123 temp
[2], temp
[1], temp
[0]);
126 internal_error (__FILE__
, __LINE__
,
127 _("failed internal consistency check"));
133 /* See print-utils.h. */
136 pulongest (ULONGEST u
)
138 return decimal2str ("", u
, 0);
141 /* See print-utils.h. */
147 return decimal2str ("-", -l
, 0);
149 return decimal2str ("", l
, 0);
152 /* Eliminate warning from compiler on 32-bit systems. */
153 static int thirty_two
= 32;
155 /* See print-utils.h. */
158 phex (ULONGEST l
, int sizeof_l
)
166 xsnprintf (str
, CELLSIZE
, "%08lx%08lx",
167 (unsigned long) (l
>> thirty_two
),
168 (unsigned long) (l
& 0xffffffff));
172 xsnprintf (str
, CELLSIZE
, "%08lx", (unsigned long) l
);
176 xsnprintf (str
, CELLSIZE
, "%04x", (unsigned short) (l
& 0xffff));
179 str
= phex (l
, sizeof (l
));
186 /* See print-utils.h. */
189 phex_nz (ULONGEST l
, int sizeof_l
)
197 unsigned long high
= (unsigned long) (l
>> thirty_two
);
201 xsnprintf (str
, CELLSIZE
, "%lx",
202 (unsigned long) (l
& 0xffffffff));
204 xsnprintf (str
, CELLSIZE
, "%lx%08lx", high
,
205 (unsigned long) (l
& 0xffffffff));
210 xsnprintf (str
, CELLSIZE
, "%lx", (unsigned long) l
);
214 xsnprintf (str
, CELLSIZE
, "%x", (unsigned short) (l
& 0xffff));
217 str
= phex_nz (l
, sizeof (l
));
224 /* See print-utils.h. */
227 hex_string (LONGEST num
)
229 char *result
= get_cell ();
231 xsnprintf (result
, CELLSIZE
, "0x%s", phex_nz (num
, sizeof (num
)));
235 /* See print-utils.h. */
238 hex_string_custom (LONGEST num
, int width
)
240 char *result
= get_cell ();
241 char *result_end
= result
+ CELLSIZE
- 1;
242 const char *hex
= phex_nz (num
, sizeof (num
));
243 int hex_len
= strlen (hex
);
247 if (width
+ 2 >= CELLSIZE
)
248 internal_error (__FILE__
, __LINE__
, _("\
249 hex_string_custom: insufficient space to store result"));
251 strcpy (result_end
- width
- 2, "0x");
252 memset (result_end
- width
, '0', width
);
253 strcpy (result_end
- hex_len
, hex
);
254 return result_end
- width
- 2;
257 /* See print-utils.h. */
260 int_string (LONGEST val
, int radix
, int is_signed
, int width
,
270 result
= hex_string (val
);
272 result
= hex_string_custom (val
, width
);
279 if (is_signed
&& val
< 0)
280 return decimal2str ("-", -val
, width
);
282 return decimal2str ("", val
, width
);
286 char *result
= octal2str (val
, width
);
288 if (use_c_format
|| val
== 0)
294 internal_error (__FILE__
, __LINE__
,
295 _("failed internal consistency check"));
299 /* See print-utils.h. */
302 core_addr_to_string (const CORE_ADDR addr
)
304 char *str
= get_cell ();
307 strcat (str
, phex (addr
, sizeof (addr
)));
311 /* See print-utils.h. */
314 core_addr_to_string_nz (const CORE_ADDR addr
)
316 char *str
= get_cell ();
319 strcat (str
, phex_nz (addr
, sizeof (addr
)));
323 /* See print-utils.h. */
326 host_address_to_string (const void *addr
)
328 char *str
= get_cell ();
330 xsnprintf (str
, CELLSIZE
, "0x%s", phex_nz ((uintptr_t) addr
, sizeof (addr
)));
This page took 0.051494 seconds and 5 git commands to generate.