From 9c1f84c9b46c1442649077d340224fa05ced63e3 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 2 May 2025 22:10:53 +0200 Subject: [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 --- gdbsupport/print-utils.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gdbsupport/print-utils.cc') diff --git a/gdbsupport/print-utils.cc b/gdbsupport/print-utils.cc index 84a7485..a798713 100644 --- a/gdbsupport/print-utils.cc +++ b/gdbsupport/print-utils.cc @@ -145,7 +145,7 @@ static int thirty_two = 32; /* See print-utils.h. */ const char * -phex (ULONGEST l, int sizeof_l) +phex_ulongest (ULONGEST l, int sizeof_l) { char *str; @@ -170,7 +170,7 @@ phex (ULONGEST l, int sizeof_l) xsnprintf (str, PRINT_CELL_SIZE, "%02x", (unsigned short) (l & 0xff)); break; default: - return phex (l, sizeof (l)); + return phex (l); break; } @@ -180,7 +180,7 @@ phex (ULONGEST l, int sizeof_l) /* See print-utils.h. */ const char * -phex_nz (ULONGEST l, int sizeof_l) +phex_nz_ulongest (ULONGEST l, int sizeof_l) { char *str; @@ -212,7 +212,7 @@ phex_nz (ULONGEST l, int sizeof_l) xsnprintf (str, PRINT_CELL_SIZE, "%x", (unsigned short) (l & 0xff)); break; default: - return phex_nz (l, sizeof (l)); + return phex_nz (l); break; } @@ -226,7 +226,7 @@ hex_string (LONGEST num) { char *result = get_print_cell (); - xsnprintf (result, PRINT_CELL_SIZE, "0x%s", phex_nz (num, sizeof (num))); + xsnprintf (result, PRINT_CELL_SIZE, "0x%s", phex_nz (num)); return result; } @@ -237,7 +237,7 @@ hex_string_custom (LONGEST num, int width) { char *result = get_print_cell (); char *result_end = result + PRINT_CELL_SIZE - 1; - const char *hex = phex_nz (num, sizeof (num)); + const char *hex = phex_nz (num); int hex_len = strlen (hex); if (hex_len > width) @@ -305,7 +305,7 @@ core_addr_to_string (const CORE_ADDR addr) char *str = get_print_cell (); strcpy (str, "0x"); - strcat (str, phex (addr, sizeof (addr))); + strcat (str, phex (addr)); return str; } @@ -317,7 +317,7 @@ core_addr_to_string_nz (const CORE_ADDR addr) char *str = get_print_cell (); strcpy (str, "0x"); - strcat (str, phex_nz (addr, sizeof (addr))); + strcat (str, phex_nz (addr)); return str; } -- cgit v1.1