xenctx: Add command line option -D (--decode-as-ascii)
authorDon Slutz <dslutz@verizon.com>
Thu, 3 Apr 2014 19:06:56 +0000 (15:06 -0400)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 4 Apr 2014 08:28:06 +0000 (09:28 +0100)
If specified, output ascii version of stack also.

This is not the default because the result exceeds 80 characters per line.

Here is an example:

Stack:
 ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800  .......... ......x>......h......
 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c  ........ .C...../r>.............
 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000  .......................... .....
 0000000000000000 0000000000000000                                    ................

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/xentrace/xenctx.c

index 14330565107bcd6b6a64df8506b84b633683a2ab..82cf6b067ec54ed8ad5a91f73438f17cde04a3ef 100644 (file)
@@ -39,6 +39,7 @@ static struct xenctx {
     int nr_stack_pages;
     int bytes_per_line;
     int lines;
+    int decode_as_ascii;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -670,6 +671,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
     guest_word_t frame;
     guest_word_t word;
     guest_word_t *p;
+    guest_word_t ascii[MAX_BYTES_PER_LINE/4];
     int i;
 
     if ( width )
@@ -684,6 +686,9 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Stack:\n");
         for (i = 1; i < xenctx.lines + 1 && stack < stack_limit; i++)
         {
+            int j = 0;
+            int k;
+
             while ( stack < stack_limit &&
                     stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
             {
@@ -691,10 +696,36 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 if ( !p )
                     return -1;
                 word = read_stack_word(p, width);
+                if ( xenctx.decode_as_ascii )
+                    ascii[j++] = word;
                 printf(" ");
                 print_stack_word(word, width);
                 stack += width;
             }
+            if ( xenctx.decode_as_ascii )
+            {
+                /*
+                 * Line up ascii output if less than bytes_per_line
+                 * were printed.
+                 */
+                for (k = j; k < xenctx.bytes_per_line / width; k++)
+                    printf(" %*s", width * 2, "");
+                printf("  ");
+                for (k = 0; k < j; k++)
+                {
+                    int l;
+                    unsigned char *bytep = (unsigned char *)&ascii[k];
+
+                    for (l = 0; l < width; l++)
+                    {
+                        if (isprint(*bytep))
+                            printf("%c", *bytep);
+                        else
+                            printf(".");
+                        bytep++;
+                    }
+                }
+            }
             printf("\n");
         }
         printf("\n");
@@ -868,19 +899,22 @@ static void usage(void)
            DEFAULT_LINES);
     printf("                     Can be specified as MAX.  Note: Fewer lines will be output\n");
     printf("                     if stack limit reached.\n");
+    printf("  -D, --decode-as-ascii\n");
+    printf("                     add a decode of Stack dump as ascii.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCn:b:l:";
+    static const char *sopts = "fs:hak:SCn:b:l:D";
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
         {"frame-pointers", 0, NULL, 'f'},
         {"kernel-start", 1, NULL, 'k'},
         {"display-stack-pages", 0, NULL, 'n'},
+        {"decode-as-ascii", 0, NULL, 'D'},
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
@@ -920,6 +954,9 @@ int main(int argc, char **argv)
                 exit(-1);
             }
             break;
+        case 'D':
+            xenctx.decode_as_ascii = 1;
+            break;
         case 'b':
             xenctx.bytes_per_line = strtol(optarg, NULL, 0);
             if ( xenctx.bytes_per_line < 4 ||