1 /* Cell-based print utility routines for GDB, the GNU debugger.
3 Copyright (C) 1986-2015 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/>. */
20 #include "common-defs.h"
21 #include "print-utils.h"
24 /* Temporary storage using circular buffer. */
29 /* Return the next entry in the circular buffer. */
34 static char buf
[NUMCELLS
][CELLSIZE
];
37 if (++cell
>= NUMCELLS
)
43 decimal2str (char *sign
, ULONGEST addr
, int width
)
45 /* Steal code from valprint.c:print_decimal(). Should this worry
46 about the real size of addr as the above does? */
47 unsigned long temp
[3];
48 char *str
= get_cell ();
53 temp
[i
] = addr
% (1000 * 1000 * 1000);
54 addr
/= (1000 * 1000 * 1000);
58 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
67 xsnprintf (str
, CELLSIZE
, "%s%0*lu", sign
, width
, temp
[0]);
70 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu", sign
, width
,
74 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu%09lu", sign
, width
,
75 temp
[2], temp
[1], temp
[0]);
78 internal_error (__FILE__
, __LINE__
,
79 _("failed internal consistency check"));
86 octal2str (ULONGEST addr
, int width
)
88 unsigned long temp
[3];
89 char *str
= get_cell ();
94 temp
[i
] = addr
% (0100000 * 0100000);
95 addr
/= (0100000 * 0100000);
99 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
109 xsnprintf (str
, CELLSIZE
, "%*o", width
, 0);
111 xsnprintf (str
, CELLSIZE
, "0%0*lo", width
, temp
[0]);
114 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo", width
, temp
[1], temp
[0]);
117 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo%010lo", width
,
118 temp
[2], temp
[1], temp
[0]);
121 internal_error (__FILE__
, __LINE__
,
122 _("failed internal consistency check"));
128 /* See print-utils.h. */
131 pulongest (ULONGEST u
)
133 return decimal2str ("", u
, 0);
136 /* See print-utils.h. */
142 return decimal2str ("-", -l
, 0);
144 return decimal2str ("", l
, 0);
147 /* Eliminate warning from compiler on 32-bit systems. */
148 static int thirty_two
= 32;
150 /* See print-utils.h. */
153 phex (ULONGEST l
, int sizeof_l
)
161 xsnprintf (str
, CELLSIZE
, "%08lx%08lx",
162 (unsigned long) (l
>> thirty_two
),
163 (unsigned long) (l
& 0xffffffff));
167 xsnprintf (str
, CELLSIZE
, "%08lx", (unsigned long) l
);
171 xsnprintf (str
, CELLSIZE
, "%04x", (unsigned short) (l
& 0xffff));
174 str
= phex (l
, sizeof (l
));
181 /* See print-utils.h. */
184 phex_nz (ULONGEST l
, int sizeof_l
)
192 unsigned long high
= (unsigned long) (l
>> thirty_two
);
196 xsnprintf (str
, CELLSIZE
, "%lx",
197 (unsigned long) (l
& 0xffffffff));
199 xsnprintf (str
, CELLSIZE
, "%lx%08lx", high
,
200 (unsigned long) (l
& 0xffffffff));
205 xsnprintf (str
, CELLSIZE
, "%lx", (unsigned long) l
);
209 xsnprintf (str
, CELLSIZE
, "%x", (unsigned short) (l
& 0xffff));
212 str
= phex_nz (l
, sizeof (l
));
219 /* See print-utils.h. */
222 hex_string (LONGEST num
)
224 char *result
= get_cell ();
226 xsnprintf (result
, CELLSIZE
, "0x%s", phex_nz (num
, sizeof (num
)));
230 /* See print-utils.h. */
233 hex_string_custom (LONGEST num
, int width
)
235 char *result
= get_cell ();
236 char *result_end
= result
+ CELLSIZE
- 1;
237 const char *hex
= phex_nz (num
, sizeof (num
));
238 int hex_len
= strlen (hex
);
242 if (width
+ 2 >= CELLSIZE
)
243 internal_error (__FILE__
, __LINE__
, _("\
244 hex_string_custom: insufficient space to store result"));
246 strcpy (result_end
- width
- 2, "0x");
247 memset (result_end
- width
, '0', width
);
248 strcpy (result_end
- hex_len
, hex
);
249 return result_end
- width
- 2;
252 /* See print-utils.h. */
255 int_string (LONGEST val
, int radix
, int is_signed
, int width
,
265 result
= hex_string (val
);
267 result
= hex_string_custom (val
, width
);
274 if (is_signed
&& val
< 0)
275 return decimal2str ("-", -val
, width
);
277 return decimal2str ("", val
, width
);
281 char *result
= octal2str (val
, width
);
283 if (use_c_format
|| val
== 0)
289 internal_error (__FILE__
, __LINE__
,
290 _("failed internal consistency check"));
294 /* See print-utils.h. */
297 core_addr_to_string (const CORE_ADDR addr
)
299 char *str
= get_cell ();
302 strcat (str
, phex (addr
, sizeof (addr
)));
306 /* See print-utils.h. */
309 core_addr_to_string_nz (const CORE_ADDR addr
)
311 char *str
= get_cell ();
314 strcat (str
, phex_nz (addr
, sizeof (addr
)));
318 /* See print-utils.h. */
321 host_address_to_string (const void *addr
)
323 char *str
= get_cell ();
325 xsnprintf (str
, CELLSIZE
, "0x%s", phex_nz ((uintptr_t) addr
, sizeof (addr
)));
This page took 0.036598 seconds and 4 git commands to generate.