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"
31 /* Temporary storage using circular buffer. */
36 /* Return the next entry in the circular buffer. */
41 static char buf
[NUMCELLS
][CELLSIZE
];
44 if (++cell
>= NUMCELLS
)
50 decimal2str (char *sign
, ULONGEST addr
, int width
)
52 /* Steal code from valprint.c:print_decimal(). Should this worry
53 about the real size of addr as the above does? */
54 unsigned long temp
[3];
55 char *str
= get_cell ();
60 temp
[i
] = addr
% (1000 * 1000 * 1000);
61 addr
/= (1000 * 1000 * 1000);
65 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
74 xsnprintf (str
, CELLSIZE
, "%s%0*lu", sign
, width
, temp
[0]);
77 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu", sign
, width
,
81 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu%09lu", sign
, width
,
82 temp
[2], temp
[1], temp
[0]);
85 internal_error (__FILE__
, __LINE__
,
86 _("failed internal consistency check"));
93 octal2str (ULONGEST addr
, int width
)
95 unsigned long temp
[3];
96 char *str
= get_cell ();
101 temp
[i
] = addr
% (0100000 * 0100000);
102 addr
/= (0100000 * 0100000);
106 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
116 xsnprintf (str
, CELLSIZE
, "%*o", width
, 0);
118 xsnprintf (str
, CELLSIZE
, "0%0*lo", width
, temp
[0]);
121 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo", width
, temp
[1], temp
[0]);
124 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo%010lo", width
,
125 temp
[2], temp
[1], temp
[0]);
128 internal_error (__FILE__
, __LINE__
,
129 _("failed internal consistency check"));
135 /* See print-utils.h. */
138 pulongest (ULONGEST u
)
140 return decimal2str ("", u
, 0);
143 /* See print-utils.h. */
149 return decimal2str ("-", -l
, 0);
151 return decimal2str ("", l
, 0);
154 /* Eliminate warning from compiler on 32-bit systems. */
155 static int thirty_two
= 32;
157 /* See print-utils.h. */
160 phex (ULONGEST l
, int sizeof_l
)
168 xsnprintf (str
, CELLSIZE
, "%08lx%08lx",
169 (unsigned long) (l
>> thirty_two
),
170 (unsigned long) (l
& 0xffffffff));
174 xsnprintf (str
, CELLSIZE
, "%08lx", (unsigned long) l
);
178 xsnprintf (str
, CELLSIZE
, "%04x", (unsigned short) (l
& 0xffff));
181 str
= phex (l
, sizeof (l
));
188 /* See print-utils.h. */
191 phex_nz (ULONGEST l
, int sizeof_l
)
199 unsigned long high
= (unsigned long) (l
>> thirty_two
);
203 xsnprintf (str
, CELLSIZE
, "%lx",
204 (unsigned long) (l
& 0xffffffff));
206 xsnprintf (str
, CELLSIZE
, "%lx%08lx", high
,
207 (unsigned long) (l
& 0xffffffff));
212 xsnprintf (str
, CELLSIZE
, "%lx", (unsigned long) l
);
216 xsnprintf (str
, CELLSIZE
, "%x", (unsigned short) (l
& 0xffff));
219 str
= phex_nz (l
, sizeof (l
));
226 /* See print-utils.h. */
229 hex_string (LONGEST num
)
231 char *result
= get_cell ();
233 xsnprintf (result
, CELLSIZE
, "0x%s", phex_nz (num
, sizeof (num
)));
237 /* See print-utils.h. */
240 hex_string_custom (LONGEST num
, int width
)
242 char *result
= get_cell ();
243 char *result_end
= result
+ CELLSIZE
- 1;
244 const char *hex
= phex_nz (num
, sizeof (num
));
245 int hex_len
= strlen (hex
);
249 if (width
+ 2 >= CELLSIZE
)
250 internal_error (__FILE__
, __LINE__
, _("\
251 hex_string_custom: insufficient space to store result"));
253 strcpy (result_end
- width
- 2, "0x");
254 memset (result_end
- width
, '0', width
);
255 strcpy (result_end
- hex_len
, hex
);
256 return result_end
- width
- 2;
259 /* See print-utils.h. */
262 int_string (LONGEST val
, int radix
, int is_signed
, int width
,
272 result
= hex_string (val
);
274 result
= hex_string_custom (val
, width
);
281 if (is_signed
&& val
< 0)
282 return decimal2str ("-", -val
, width
);
284 return decimal2str ("", val
, width
);
288 char *result
= octal2str (val
, width
);
290 if (use_c_format
|| val
== 0)
296 internal_error (__FILE__
, __LINE__
,
297 _("failed internal consistency check"));
301 /* See print-utils.h. */
304 core_addr_to_string (const CORE_ADDR addr
)
306 char *str
= get_cell ();
309 strcat (str
, phex (addr
, sizeof (addr
)));
313 /* See print-utils.h. */
316 core_addr_to_string_nz (const CORE_ADDR addr
)
318 char *str
= get_cell ();
321 strcat (str
, phex_nz (addr
, sizeof (addr
)));
325 /* See print-utils.h. */
328 host_address_to_string (const void *addr
)
330 char *str
= get_cell ();
332 xsnprintf (str
, CELLSIZE
, "0x%s", phex_nz ((uintptr_t) addr
, sizeof (addr
)));
This page took 0.037625 seconds and 4 git commands to generate.