public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] Modify %M directive to support variable width.
@ 2009-04-24 10:42 Wenji Huang
  2009-04-24 15:27 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Wenji Huang @ 2009-04-24 10:42 UTC (permalink / raw)
  To: systemtap; +Cc: Wenji Huang

This patch will make %M directive dump the variable width
buffer in hex format instead of returning uint64_t number
as before.

* runtime/vsprintf.c: Modify %M directive.
* stap.1.in: Update description.
* testsuite/systemtap.printf/memory1.stp: Add test case.
---
 runtime/vsprintf.c                     |   31 ++++++++++++++++++++-----------
 stap.1.in                              |    2 +-
 testsuite/systemtap.printf/memory1.stp |   14 ++++++++++++++
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c
index 38ab0e2..549f209 100644
--- a/runtime/vsprintf.c
+++ b/runtime/vsprintf.c
@@ -361,18 +361,16 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
                             else
                               len = 1;
 
+                            if (*fmt_copy == 'M')
+                               len = len * 2; /* hex dump print size */
+
                             if (!(flags & STP_LEFT)) {
                               while (len < field_width--) {
                                 num_bytes++;
                               }
                             }
-                            if (*fmt_copy == 'M') {
-                              num_bytes += number_size((unsigned long) *(uint64_t *) s,
-                                  16, field_width, len, flags);
-                            }
-                            else {
-                              num_bytes += len;
-                            }
+
+                            num_bytes += len;
 
                             while (len < field_width--) {
                               num_bytes++;
@@ -636,16 +634,27 @@ static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 			  len = 1;
 
 			if (!(flags & STP_LEFT)) {
-				while (len < field_width--) {
+                                int actlen = len;
+                                if (*fmt == 'M')
+                                    actlen = len * 2;
+                                while (actlen < field_width--) {
 					if (str <= end)
 						*str = ' ';
 					++str;
 				}
 			}
 			if (*fmt == 'M') {
-			  str = number(str, str + len - 1 < end ? str + len - 1 : end,
-			      (unsigned long) *(uint64_t *) s,
-			      16, field_width, len, flags);
+				const char _stp_hex_asc[] = "0123456789abcdef";
+				int j;
+				#define _stp_hex_asc_lo(x)   _stp_hex_asc[((x) & 0x0f)]
+				#define _stp_hex_asc_hi(x)   _stp_hex_asc[((x) & 0xf0) >> 4]
+			        for (i = 0, j = 0; i < len; i++) {
+			               *str = _stp_hex_asc_hi(*s);
+				       str++;
+			               *str = _stp_hex_asc_lo(*s);
+				       str++; s++;
+			         }
+				len = len * 2; /* the actual length */
 			}
 			else {
                                 for (i = 0; i < len; ++i) {
diff --git a/stap.1.in b/stap.1.in
index aed473d..a8609d6 100644
--- a/stap.1.in
+++ b/stap.1.in
@@ -674,7 +674,7 @@ Signed decimal.
 Safely reads kernel memory at the given address, outputs its content.  The precision specifier determines the number of bytes to read.  Default is 1 byte.
 .TP
 %M
-Same as %m, but outputs in hexadecimal.  The precision specifier determines the number of hexadecimal digits to output.  Default is 1 digit.
+Same as %m, but outputs in hexadecimal.  The minimal size of output is double the precision specifier.
 .TP
 %o
 Unsigned octal.
diff --git a/testsuite/systemtap.printf/memory1.stp b/testsuite/systemtap.printf/memory1.stp
index f9cbf60..93a4edf 100644
--- a/testsuite/systemtap.printf/memory1.stp
+++ b/testsuite/systemtap.printf/memory1.stp
@@ -113,6 +113,20 @@ probe syscall.open {
 		success = 0;
 	}
 
+	expected_16_actual = sprintf ("  %x%x%x%x%x%x",
+				      chrofstr(filename, 0),
+				      chrofstr(filename, 1),
+				      chrofstr(filename, 2),
+				      chrofstr(filename, 3),
+				      chrofstr(filename, 4),
+				      chrofstr(filename, 5));
+        testName = "%M dynamic width larger than dynamic precision";
+        result = sprintf ("%*.*M", 14, 6, $filename);
+	if (result != expected_16_actual) {
+		printf ("Test %s failed\n", testName);
+		success = 0;
+	}
+
 	if (success)
 	   print ("Test passed\n");
 
-- 
1.5.6

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/3] Modify %M directive to support variable width.
  2009-04-24 10:42 [PATCH 2/3] Modify %M directive to support variable width Wenji Huang
@ 2009-04-24 15:27 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2009-04-24 15:27 UTC (permalink / raw)
  To: Wenji Huang; +Cc: systemtap

Wenji Huang wrote:
> diff --git a/testsuite/systemtap.printf/memory1.stp b/testsuite/systemtap.printf/memory1.stp
> index f9cbf60..93a4edf 100644
> --- a/testsuite/systemtap.printf/memory1.stp
> +++ b/testsuite/systemtap.printf/memory1.stp
> @@ -113,6 +113,20 @@ probe syscall.open {
>  		success = 0;
>  	}
>  
> +	expected_16_actual = sprintf ("  %x%x%x%x%x%x",
> +				      chrofstr(filename, 0),
> +				      chrofstr(filename, 1),
> +				      chrofstr(filename, 2),
> +				      chrofstr(filename, 3),
> +				      chrofstr(filename, 4),
> +				      chrofstr(filename, 5));

Hmm, these should be %02x?

Thanks,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-24 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-24 10:42 [PATCH 2/3] Modify %M directive to support variable width Wenji Huang
2009-04-24 15:27 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).