mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-27 17:40:49 +00:00
[gdbsupport] Reimplement phex and phex_nz as templates
Gdbsupport functions phex and phex_nz have a parameter sizeof_l:
...
extern const char *phex (ULONGEST l, int sizeof_l);
extern const char *phex_nz (ULONGEST l, int sizeof_l);
...
and a lot of calls use:
...
phex (l, sizeof (l))
...
Make this easier by reimplementing the functions as a template, allowing us to
simply write:
...
phex (l)
...
Simplify existing code using:
...
$ find gdb* -type f \
| xargs sed -i 's/phex (\([^,]*\), sizeof (\1))/phex (\1)/'
$ find gdb* -type f \
| xargs sed -i 's/phex_nz (\([^,]*\), sizeof (\1))/phex_nz (\1)/'
...
and manually review:
...
$ find gdb* -type f | xargs grep "phex (.*, sizeof.*)"
$ find gdb* -type f | xargs grep "phex_nz (.*, sizeof.*)"
...
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
@@ -34,15 +34,35 @@ extern const char *pulongest (ULONGEST u);
|
||||
|
||||
extern const char *plongest (LONGEST l);
|
||||
|
||||
/* Convert a ULONGEST into a HEX string, like %lx, with leading zeros.
|
||||
/* Convert L (of type ULONGEST) into a hex string, like %lx, with leading
|
||||
zeros. The result is stored in a circular static buffer, NUMCELLS
|
||||
deep. */
|
||||
|
||||
extern const char *phex_ulongest (ULONGEST l, int sizeof_l);
|
||||
|
||||
/* Convert L into a HEX string, like %lx, with leading zeros.
|
||||
The result is stored in a circular static buffer, NUMCELLS deep. */
|
||||
|
||||
extern const char *phex (ULONGEST l, int sizeof_l);
|
||||
template<typename T>
|
||||
const char *phex (T l, int sizeof_l = sizeof (T))
|
||||
{
|
||||
return phex_ulongest (l, sizeof_l);
|
||||
}
|
||||
|
||||
/* Convert a ULONGEST into a HEX string, like %lx, without leading zeros.
|
||||
The result is stored in a circular static buffer, NUMCELLS deep. */
|
||||
/* Convert L (of type ULONGEST) into a hex string, like %lx, without leading
|
||||
zeros. The result is stored in a circular static buffer, NUMCELLS
|
||||
deep. */
|
||||
|
||||
extern const char *phex_nz (ULONGEST l, int sizeof_l);
|
||||
extern const char *phex_nz_ulongest (ULONGEST l, int sizeof_l);
|
||||
|
||||
/* Convert L into a hex string, like %lx, without leading zeros.
|
||||
The result is stored in a circular static buffer, NUMCELLS deep. */
|
||||
|
||||
template<typename T>
|
||||
const char *phex_nz (T l, int sizeof_l = sizeof (T))
|
||||
{
|
||||
return phex_nz_ulongest (l, sizeof_l);
|
||||
}
|
||||
|
||||
/* Converts a LONGEST to a C-format hexadecimal literal and stores it
|
||||
in a static string. Returns a pointer to this string. */
|
||||
|
||||
Reference in New Issue
Block a user