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"
22 /* Temporary storage using circular buffer. */
27 /* Return the next entry in the circular buffer. */
32 static char buf
[NUMCELLS
][CELLSIZE
];
35 if (++cell
>= NUMCELLS
)
41 decimal2str (char *sign
, ULONGEST addr
, int width
)
43 /* Steal code from valprint.c:print_decimal(). Should this worry
44 about the real size of addr as the above does? */
45 unsigned long temp
[3];
46 char *str
= get_cell ();
51 temp
[i
] = addr
% (1000 * 1000 * 1000);
52 addr
/= (1000 * 1000 * 1000);
56 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
65 xsnprintf (str
, CELLSIZE
, "%s%0*lu", sign
, width
, temp
[0]);
68 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu", sign
, width
,
72 xsnprintf (str
, CELLSIZE
, "%s%0*lu%09lu%09lu", sign
, width
,
73 temp
[2], temp
[1], temp
[0]);
76 internal_error (__FILE__
, __LINE__
,
77 _("failed internal consistency check"));
84 octal2str (ULONGEST addr
, int width
)
86 unsigned long temp
[3];
87 char *str
= get_cell ();
92 temp
[i
] = addr
% (0100000 * 0100000);
93 addr
/= (0100000 * 0100000);
97 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
107 xsnprintf (str
, CELLSIZE
, "%*o", width
, 0);
109 xsnprintf (str
, CELLSIZE
, "0%0*lo", width
, temp
[0]);
112 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo", width
, temp
[1], temp
[0]);
115 xsnprintf (str
, CELLSIZE
, "0%0*lo%010lo%010lo", width
,
116 temp
[2], temp
[1], temp
[0]);
119 internal_error (__FILE__
, __LINE__
,
120 _("failed internal consistency check"));
126 /* See print-utils.h. */
129 pulongest (ULONGEST u
)
131 return decimal2str ("", u
, 0);
134 /* See print-utils.h. */
140 return decimal2str ("-", -l
, 0);
142 return decimal2str ("", l
, 0);
145 /* Eliminate warning from compiler on 32-bit systems. */
146 static int thirty_two
= 32;
148 /* See print-utils.h. */
151 phex (ULONGEST l
, int sizeof_l
)
159 xsnprintf (str
, CELLSIZE
, "%08lx%08lx",
160 (unsigned long) (l
>> thirty_two
),
161 (unsigned long) (l
& 0xffffffff));
165 xsnprintf (str
, CELLSIZE
, "%08lx", (unsigned long) l
);
169 xsnprintf (str
, CELLSIZE
, "%04x", (unsigned short) (l
& 0xffff));
172 str
= phex (l
, sizeof (l
));
179 /* See print-utils.h. */
182 phex_nz (ULONGEST l
, int sizeof_l
)
190 unsigned long high
= (unsigned long) (l
>> thirty_two
);
194 xsnprintf (str
, CELLSIZE
, "%lx",
195 (unsigned long) (l
& 0xffffffff));
197 xsnprintf (str
, CELLSIZE
, "%lx%08lx", high
,
198 (unsigned long) (l
& 0xffffffff));
203 xsnprintf (str
, CELLSIZE
, "%lx", (unsigned long) l
);
207 xsnprintf (str
, CELLSIZE
, "%x", (unsigned short) (l
& 0xffff));
210 str
= phex_nz (l
, sizeof (l
));
217 /* See print-utils.h. */
220 hex_string (LONGEST num
)
222 char *result
= get_cell ();
224 xsnprintf (result
, CELLSIZE
, "0x%s", phex_nz (num
, sizeof (num
)));
228 /* See print-utils.h. */
231 hex_string_custom (LONGEST num
, int width
)
233 char *result
= get_cell ();
234 char *result_end
= result
+ CELLSIZE
- 1;
235 const char *hex
= phex_nz (num
, sizeof (num
));
236 int hex_len
= strlen (hex
);
240 if (width
+ 2 >= CELLSIZE
)
241 internal_error (__FILE__
, __LINE__
, _("\
242 hex_string_custom: insufficient space to store result"));
244 strcpy (result_end
- width
- 2, "0x");
245 memset (result_end
- width
, '0', width
);
246 strcpy (result_end
- hex_len
, hex
);
247 return result_end
- width
- 2;
250 /* See print-utils.h. */
253 int_string (LONGEST val
, int radix
, int is_signed
, int width
,
263 result
= hex_string (val
);
265 result
= hex_string_custom (val
, width
);
272 if (is_signed
&& val
< 0)
273 return decimal2str ("-", -val
, width
);
275 return decimal2str ("", val
, width
);
279 char *result
= octal2str (val
, width
);
281 if (use_c_format
|| val
== 0)
287 internal_error (__FILE__
, __LINE__
,
288 _("failed internal consistency check"));
292 /* See print-utils.h. */
295 core_addr_to_string (const CORE_ADDR addr
)
297 char *str
= get_cell ();
300 strcat (str
, phex (addr
, sizeof (addr
)));
304 /* See print-utils.h. */
307 core_addr_to_string_nz (const CORE_ADDR addr
)
309 char *str
= get_cell ();
312 strcat (str
, phex_nz (addr
, sizeof (addr
)));
316 /* See print-utils.h. */
319 host_address_to_string (const void *addr
)
321 char *str
= get_cell ();
323 xsnprintf (str
, CELLSIZE
, "0x%s", phex_nz ((uintptr_t) addr
, sizeof (addr
)));
This page took 0.035447 seconds and 4 git commands to generate.