This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

allow to print a null-terminated string when binary tracing


Currently, printf("%s",str) will not append a '\0' at the end
of str for the requirement of ascii tracing. It will make
binary trace data difficult to decode, for we cannot locate
the end of current string.

e.g.
stap -o probe.out -e 'probe kernel.function("sys_open"){ name="open";
  printf("%s%s%4b",name,user_string($filename),$flags);exit()}'

will generate:
0000000: 6f70 656e 2f65 7463 2f6c 642e 736f 2e63  open/etc/ld.so.c
0000010: 6163 6865 0000 0000 0a                   ache.....

How about allowing to append a '\0' at the end of each string?
As Martin has suggested in
http://sources.redhat.com/ml/systemtap/2006-q1/msg00284.html,
we can  use "%0s" to print a null-teminated string.

e.g.
stap -o probe.out -e 'probe kernel.function("sys_open"){ name="open";
  printf("%0s%0s%4b",name,user_string($filename),$flags);exit()}'

will generate:
0000000: 6f70 656e 002f 6574 632f 6c64 2e73 6f2e  open./etc/ld.so.
0000010: 6361 6368 6500 0000 0000 0a              cache......

Here is my patch to do this. Thanks for your comments.

diff -Nur src-20060506/runtime/vsprintf.c src.new/runtime/vsprintf.c
--- src-20060506/runtime/vsprintf.c 2006-04-28 16:36:28.000000000 -0400
+++ src.new/runtime/vsprintf.c 2006-05-08 07:38:58.000000000 -0400
@@ -275,6 +275,12 @@
*str = ' ';
++str;
}
+ if(flags & STP_ZEROPAD) {
+ if (str <= end)
+ *str = '\0';
+ ++str;
+ }
+
continue;


case 'X':



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]