kdump improvements

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

kdump improvements

Cédric Berger-2
Hi,

I'm working with a binary protocol on the serial port,
and while ktrace -ti is very cool to display I/O data,
the default kdump c-string output is awful and unparseable
with non-ascii data.

This patchlet add -x and -X options to kdump to display
hex data instead or in addition to the c-string output.

Cedric


diff -u kdump.orig/kdump.1 kdump/kdump.1
--- kdump.orig/kdump.1 Fri May  5 10:28:12 2006
+++ kdump/kdump.1 Fri May  5 11:31:29 2006
@@ -104,6 +104,10 @@
 option of
 .Xr ktrace 1
 for the definitions of the flags.
+.It Fl x
+Display I/O data in hexadecimal.
+.It Fl X
+Display I/O data in hexadecimal in addition to the standard c-string output.
 .El
 .Sh FILES
 .Bl -tag -width ktrace.out -compact
diff -u kdump.orig/kdump.c kdump/kdump.c
--- kdump.orig/kdump.c Fri May  5 10:29:31 2006
+++ kdump/kdump.c Fri May  5 12:41:35 2006
@@ -65,7 +65,7 @@
 #include "kdump.h"
 #include "extern.h"
 
-int timestamp, decimal, fancy = 1, tail, maxdata;
+int timestamp, decimal, iohex, fancy = 1, tail, maxdata;
 char *tracefile = DEF_TRACEFILE;
 struct ktr_header ktr_header;
 pid_t pid = -1;
@@ -173,7 +173,7 @@
 
  current = &emulations[0]; /* native */
 
- while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:")) != -1)
+ while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1)
  switch (ch) {
  case 'e':
  setemul(optarg);
@@ -207,6 +207,12 @@
  if (trpoints < 0)
  errx(1, "unknown trace point in %s", optarg);
  break;
+ case 'x':
+ iohex = 1;
+ break;
+ case 'X':
+ iohex = 2;
+ break;
  default:
  usage();
  }
@@ -512,7 +518,7 @@
 ktrgenio(struct ktr_genio *ktr, int len)
 {
  char *dp = (char *)ktr + sizeof (struct ktr_genio);
- int datalen = len - sizeof (struct ktr_genio);
+ int i, datalen = len - sizeof (struct ktr_genio);
  static int screenwidth = 0;
  int col = 0, width;
  char visbuf[5], *cp;
@@ -530,6 +536,24 @@
  ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
  if (maxdata && datalen > maxdata)
  datalen = maxdata;
+ if (iohex && datalen > 0) {
+ putchar('\t');
+ col = 8;
+ for (i = 0; i < datalen; i++) {
+ printf("%02x", dp[i] & 0xff);
+ col += 3;
+ if (i < datalen - 1) {
+ if (col + 3 > screenwidth) {
+ printf("\n\t");
+ col = 8;
+ } else
+ putchar(' ');
+ }
+ }
+ putchar('\n');
+ if (iohex == 1)
+ return;
+ }
  (void)printf("       \"");
  col = 8;
  for (; datalen > 0; datalen--, dp++) {
@@ -605,7 +629,7 @@
 
  extern char *__progname;
  fprintf(stderr, "usage: %s "
-    "[-dnlRT] [-e emulation] [-p pid] [-f trfile] [-m maxdata] "
+    "[-dnlRTxX] [-e emulation] [-p pid] [-f trfile] [-m maxdata] "
     "[-t [ceinsw]]\n", __progname);
  exit(1);
 }

Reply | Threaded
Open this post in threaded view
|

Re: kdump improvements

Michael Shalayeff-2
On Fri, May 05, 2006 at 12:46:47PM +0200, [hidden email] wrote:
> Hi,
>
> I'm working with a binary protocol on the serial port,
> and while ktrace -ti is very cool to display I/O data,
> the default kdump c-string output is awful and unparseable
> with non-ascii data.
>
> This patchlet add -x and -X options to kdump to display
> hex data instead or in addition to the c-string output.

i think -X is totally confusing.
would noyt it make more sense to make -X
produce tcpdump-like output instead?

> diff -u kdump.orig/kdump.1 kdump/kdump.1
> --- kdump.orig/kdump.1 Fri May  5 10:28:12 2006
> +++ kdump/kdump.1 Fri May  5 11:31:29 2006
> @@ -104,6 +104,10 @@
>  option of
>  .Xr ktrace 1
>  for the definitions of the flags.
> +.It Fl x
> +Display I/O data in hexadecimal.
> +.It Fl X
> +Display I/O data in hexadecimal in addition to the standard c-string output.
>  .El
>  .Sh FILES
>  .Bl -tag -width ktrace.out -compact
> diff -u kdump.orig/kdump.c kdump/kdump.c
> --- kdump.orig/kdump.c Fri May  5 10:29:31 2006
> +++ kdump/kdump.c Fri May  5 12:41:35 2006
> @@ -65,7 +65,7 @@
>  #include "kdump.h"
>  #include "extern.h"
>  
> -int timestamp, decimal, fancy = 1, tail, maxdata;
> +int timestamp, decimal, iohex, fancy = 1, tail, maxdata;
>  char *tracefile = DEF_TRACEFILE;
>  struct ktr_header ktr_header;
>  pid_t pid = -1;
> @@ -173,7 +173,7 @@
>  
>   current = &emulations[0]; /* native */
>  
> - while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:")) != -1)
> + while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1)
>   switch (ch) {
>   case 'e':
>   setemul(optarg);
> @@ -207,6 +207,12 @@
>   if (trpoints < 0)
>   errx(1, "unknown trace point in %s", optarg);
>   break;
> + case 'x':
> + iohex = 1;
> + break;
> + case 'X':
> + iohex = 2;
> + break;
>   default:
>   usage();
>   }
> @@ -512,7 +518,7 @@
>  ktrgenio(struct ktr_genio *ktr, int len)
>  {
>   char *dp = (char *)ktr + sizeof (struct ktr_genio);
> - int datalen = len - sizeof (struct ktr_genio);
> + int i, datalen = len - sizeof (struct ktr_genio);
>   static int screenwidth = 0;
>   int col = 0, width;
>   char visbuf[5], *cp;
> @@ -530,6 +536,24 @@
>   ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
>   if (maxdata && datalen > maxdata)
>   datalen = maxdata;
> + if (iohex && datalen > 0) {
> + putchar('\t');
> + col = 8;
> + for (i = 0; i < datalen; i++) {
> + printf("%02x", dp[i] & 0xff);
> + col += 3;
> + if (i < datalen - 1) {
> + if (col + 3 > screenwidth) {
> + printf("\n\t");
> + col = 8;
> + } else
> + putchar(' ');
> + }
> + }
> + putchar('\n');
> + if (iohex == 1)
> + return;
> + }
>   (void)printf("       \"");
>   col = 8;
>   for (; datalen > 0; datalen--, dp++) {
> @@ -605,7 +629,7 @@
>  
>   extern char *__progname;
>   fprintf(stderr, "usage: %s "
> -    "[-dnlRT] [-e emulation] [-p pid] [-f trfile] [-m maxdata] "
> +    "[-dnlRTxX] [-e emulation] [-p pid] [-f trfile] [-m maxdata] "
>      "[-t [ceinsw]]\n", __progname);
>   exit(1);
>  }
>

--
    paranoic mickey       (my employers have changed but, the name has remained)

Reply | Threaded
Open this post in threaded view
|

Re: kdump improvements

Cédric Berger-2
mickey wrote:

> On Fri, May 05, 2006 at 12:46:47PM +0200, [hidden email] wrote:
>> Hi,
>>
>> I'm working with a binary protocol on the serial port,
>> and while ktrace -ti is very cool to display I/O data,
>> the default kdump c-string output is awful and unparseable
>> with non-ascii data.
>>
>> This patchlet add -x and -X options to kdump to display
>> hex data instead or in addition to the c-string output.
>
> i think -X is totally confusing.
> would noyt it make more sense to make -X
> produce tcpdump-like output instead?

Yeah, I agree with you. Actually, I wanted first to implement
it with the binary part on the left and the text part on the
right but it was non-trivial to reuse the current c-ascii code,
and I was getting lazy. Is that what you want? I'll try to see
what I can steal from tcpdump...

I can deduce from that e-mail that you like the -x part, correct?

Cedric

Reply | Threaded
Open this post in threaded view
|

Re: kdump improvements

Michael Shalayeff-2
On Sun, May 07, 2006 at 09:00:43PM +0200, C?dric Berger wrote:

> mickey wrote:
> >On Fri, May 05, 2006 at 12:46:47PM +0200, [hidden email] wrote:
> >>Hi,
> >>
> >>I'm working with a binary protocol on the serial port,
> >>and while ktrace -ti is very cool to display I/O data,
> >>the default kdump c-string output is awful and unparseable
> >>with non-ascii data.
> >>
> >>This patchlet add -x and -X options to kdump to display
> >>hex data instead or in addition to the c-string output.
> >
> >i think -X is totally confusing.
> >would noyt it make more sense to make -X
> >produce tcpdump-like output instead?
>
> Yeah, I agree with you. Actually, I wanted first to implement
> it with the binary part on the left and the text part on the
> right but it was non-trivial to reuse the current c-ascii code,
> and I was getting lazy. Is that what you want? I'll try to see
> what I can steal from tcpdump...
>
> I can deduce from that e-mail that you like the -x part, correct?

yeah i'm down w/ the -x part.
think the -X can be done separately later if you cannot
pull it right now from tcpdump or whatever...
as well it would make sense to make those functions for other pieces
such as dumping sysctl() args and stuff in the future...

cu
--
    paranoic mickey       (my employers have changed but, the name has remained)