|
|
b1dca6 |
commit 533dd2acf7eefa969fb770fa782b20519bd4bc0f
|
|
|
b1dca6 |
Author: H.J. Lu <hjl.tools@gmail.com>
|
|
|
b1dca6 |
Date: Tue Jun 9 12:15:01 2020 -0700
|
|
|
b1dca6 |
|
|
|
b1dca6 |
Add "%d" support to _dl_debug_vdprintf
|
|
|
b1dca6 |
|
|
|
b1dca6 |
"%d" will be used to print out signed value.
|
|
|
b1dca6 |
|
|
|
b1dca6 |
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
|
|
|
b1dca6 |
index 2eb81eeb0231368d..3f28de3ee9d68368 100644
|
|
|
b1dca6 |
--- a/elf/dl-misc.c
|
|
|
b1dca6 |
+++ b/elf/dl-misc.c
|
|
|
b1dca6 |
@@ -167,6 +167,7 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
|
|
|
b1dca6 |
switch (*fmt)
|
|
|
b1dca6 |
{
|
|
|
b1dca6 |
/* Integer formatting. */
|
|
|
b1dca6 |
+ case 'd':
|
|
|
b1dca6 |
case 'u':
|
|
|
b1dca6 |
case 'x':
|
|
|
b1dca6 |
{
|
|
|
b1dca6 |
@@ -179,11 +180,34 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
|
|
|
b1dca6 |
#else
|
|
|
b1dca6 |
unsigned long int num = va_arg (arg, unsigned int);
|
|
|
b1dca6 |
#endif
|
|
|
b1dca6 |
+ bool negative = false;
|
|
|
b1dca6 |
+ if (*fmt == 'd')
|
|
|
b1dca6 |
+ {
|
|
|
b1dca6 |
+#if LONG_MAX != INT_MAX
|
|
|
b1dca6 |
+ if (long_mod)
|
|
|
b1dca6 |
+ {
|
|
|
b1dca6 |
+ if ((long int) num < 0)
|
|
|
b1dca6 |
+ negative = true;
|
|
|
b1dca6 |
+ }
|
|
|
b1dca6 |
+ else
|
|
|
b1dca6 |
+ {
|
|
|
b1dca6 |
+ if ((int) num < 0)
|
|
|
b1dca6 |
+ {
|
|
|
b1dca6 |
+ num = (unsigned int) num;
|
|
|
b1dca6 |
+ negative = true;
|
|
|
b1dca6 |
+ }
|
|
|
b1dca6 |
+ }
|
|
|
b1dca6 |
+#else
|
|
|
b1dca6 |
+ if ((int) num < 0)
|
|
|
b1dca6 |
+ negative = true;
|
|
|
b1dca6 |
+#endif
|
|
|
b1dca6 |
+ }
|
|
|
b1dca6 |
+
|
|
|
b1dca6 |
/* We use alloca() to allocate the buffer with the most
|
|
|
b1dca6 |
pessimistic guess for the size. Using alloca() allows
|
|
|
b1dca6 |
having more than one integer formatting in a call. */
|
|
|
b1dca6 |
- char *buf = (char *) alloca (3 * sizeof (unsigned long int));
|
|
|
b1dca6 |
- char *endp = &buf[3 * sizeof (unsigned long int)];
|
|
|
b1dca6 |
+ char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
|
|
|
b1dca6 |
+ char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
|
|
|
b1dca6 |
char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
|
|
|
b1dca6 |
|
|
|
b1dca6 |
/* Pad to the width the user specified. */
|
|
|
b1dca6 |
@@ -191,6 +215,9 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
|
|
|
b1dca6 |
while (endp - cp < width)
|
|
|
b1dca6 |
*--cp = fill;
|
|
|
b1dca6 |
|
|
|
b1dca6 |
+ if (negative)
|
|
|
b1dca6 |
+ *--cp = '-';
|
|
|
b1dca6 |
+
|
|
|
b1dca6 |
iov[niov].iov_base = cp;
|
|
|
b1dca6 |
iov[niov].iov_len = endp - cp;
|
|
|
b1dca6 |
++niov;
|