[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 09/12] xenctx: Add -m <maddr> option to dump memory at maddr.



From: Don Slutz <Don@xxxxxxxxxxxxxxx>

Signed-off-by: Don Slutz <Don@xxxxxxxxxxxxxxx>
---
 tools/xentrace/xenctx.c |  126 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 109 insertions(+), 17 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 233f537..d6f8482 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -609,6 +609,33 @@ static guest_word_t read_stack_word(guest_word_t *src, int 
width)
     return word;
 }
 
+static guest_word_t read_mem_word(vcpu_guest_context_any_t *ctx, int vcpu, 
guest_word_t virt, int width)
+{
+    if ((virt & 7) == 0) {
+        guest_word_t *p = map_page(ctx, vcpu, virt);
+
+        if (p)
+            return read_stack_word(p, width);
+        else
+            return -1;
+    } else {
+        guest_word_t word = -1;
+        char *src, *dst;
+        int i;
+
+        dst = (char*)&word;
+        for(i = 0; i < width; i++) {
+            src = map_page(ctx, vcpu, virt + i);
+            if (src)
+                *dst++ = *src;
+            else
+                return word;
+        }
+        return word;
+    }
+}
+
+
 static void print_stack_word(guest_word_t word, int width)
 {
     if (width == 4)
@@ -617,6 +644,58 @@ static void print_stack_word(guest_word_t word, int width)
         printf(FMT_64B_WORD, word);
 }
 
+#define BYTES_PER_LINE 16
+
+static void print_mem(vcpu_guest_context_any_t *ctx, int vcpu, int width, 
guest_word_t mem_addr)
+{
+    guest_word_t instr;
+    guest_word_t instr_start;
+    guest_word_t word;
+    guest_word_t ascii[BYTES_PER_LINE/4];
+    unsigned char *bytep;
+    int i;
+
+    instr_start = mem_addr;
+    instr = mem_addr;
+    printf("Memory (addr %08llx)\n", instr);
+    for (i=1; i<10; i++) {
+        int j = 0;
+        int k;
+
+        print_stack_word(instr, width);
+        printf(":");
+        while(instr < instr_start + i*BYTES_PER_LINE) {
+            void *p = map_page(ctx, vcpu, instr);
+            if (!p)
+                return;
+            word = read_mem_word(ctx, vcpu, instr, width);
+            ascii[j++] = word;
+            printf(" ");
+            print_stack_word(word, width);
+            instr += width;
+        }
+        printf("  ");
+        for (k = j; k < BYTES_PER_LINE/width; k++)
+            printf("%s ", width == 8
+                   ? "                "
+                   : "        ");
+        for (k = 0; k < j; k++) {
+            int l;
+
+            bytep = (unsigned char*)&ascii[k];
+            for (l = 0; l < width; l++) {
+                if ((*bytep < 127) && (*bytep >= 32))
+                    printf("%c", *bytep);
+                else
+                    printf(".");
+                bytep++;
+            }
+        }
+        printf("\n");
+    }
+    printf("\n");
+}
+
 static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
 {
     guest_word_t instr;
@@ -640,8 +719,6 @@ static int print_code(vcpu_guest_context_any_t *ctx, int 
vcpu)
     return 0;
 }
 
-#define BYTES_PER_LINE 16
-
 static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width, 
guest_word_t stk_addr)
 {
     guest_word_t stk_addr_start = stack_pointer(ctx);
@@ -787,7 +864,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
 }
 #endif
 
-static void dump_ctx(int vcpu, guest_word_t stk_addr)
+static void dump_ctx(int vcpu, guest_word_t mem_addr, guest_word_t stk_addr)
 {
     vcpu_guest_context_any_t ctx;
 
@@ -826,21 +903,29 @@ static void dump_ctx(int vcpu, guest_word_t stk_addr)
     }
 #endif
 
-    if (!stk_addr) {
-        print_ctx(&ctx);
-    }
+    if (mem_addr) {
+        print_mem(&ctx, vcpu, guest_word_size, mem_addr);
 #ifndef NO_TRANSLATION
-    if (!stk_addr) {
-        print_code(&ctx, vcpu);
-        if (is_kernel_text(instr_pointer(&ctx)))
+        if (stk_addr)
             print_stack(&ctx, vcpu, guest_word_size, stk_addr);
+#endif
     } else {
-        print_stack(&ctx, vcpu, guest_word_size, stk_addr);
-    }
+        if (!stk_addr) {
+            print_ctx(&ctx);
+        }
+#ifndef NO_TRANSLATION
+        if (!stk_addr) {
+            print_code(&ctx, vcpu);
+            if (is_kernel_text(instr_pointer(&ctx)))
+                print_stack(&ctx, vcpu, guest_word_size, stk_addr);
+        } else {
+            print_stack(&ctx, vcpu, guest_word_size, stk_addr);
+        }
 #endif
+    }
 }
 
-static void dump_all_vcpus(guest_word_t stk_addr)
+static void dump_all_vcpus(guest_word_t mem_addr, guest_word_t stk_addr)
 {
     xc_vcpuinfo_t vinfo;
     int vcpu;
@@ -849,7 +934,7 @@ static void dump_all_vcpus(guest_word_t stk_addr)
         if ( xc_vcpu_getinfo(xenctx.xc_handle, xenctx.domid, vcpu, &vinfo) )
             continue;
         if ( vinfo.online )
-            dump_ctx(vcpu, stk_addr);
+            dump_ctx(vcpu, mem_addr, stk_addr);
     }
 }
 
@@ -868,6 +953,8 @@ static void usage(void)
     printf("  -S, --stack-trace print a complete stack trace.\n");
     printf("  -k kaddr, --kernel-start=kaddr\n");
     printf("                    set user/kernel split at kaddr. (default 
0xc0000000)\n");
+    printf("  -m maddr, --memory=maddr\n");
+    printf("                    dump memory at maddr.\n");
     printf("  -d daddr, --dump-as-stack=daddr\n");
     printf("                    dump memory as a stack at daddr.\n");
     printf("  -a, --all         display more registers\n");
@@ -879,13 +966,14 @@ int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCd:2";
+    static const char *sopts = "fs:hak:SCm:d:2";
     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'},
         {"two-pages", 0, NULL, '2'},
+        {"memory", 1, NULL, 'm'},
         {"dump-as-stack", 1, NULL, 'd'},
         {"all", 0, NULL, 'a'},
         {"all-vcpus", 0, NULL, 'C'},
@@ -893,6 +981,7 @@ int main(int argc, char **argv)
         {0, 0, 0, 0}
     };
     const char *symbol_table = NULL;
+    guest_word_t mem_addr = 0;
     guest_word_t stk_addr = 0;
 
     int vcpu = 0;
@@ -920,6 +1009,9 @@ int main(int argc, char **argv)
         case 'k':
             kernel_start = strtoull(optarg, NULL, 0);
             break;
+        case 'm':
+            mem_addr = strtoull(optarg, NULL, 0);
+            break;
         case 'd':
             stk_addr = strtoull(optarg, NULL, 0);
             break;
@@ -952,7 +1044,7 @@ int main(int argc, char **argv)
         read_symbol_table(symbol_table);
 
     xenctx.xc_handle = xc_interface_open(0,0,0); /* for accessing control 
interface */
-    if (xenctx.xc_handle < 0) {
+    if (!xenctx.xc_handle) {
         perror("xc_interface_open");
         exit(-1);
     }
@@ -973,9 +1065,9 @@ int main(int argc, char **argv)
     }
 
     if (xenctx.all_vcpus)
-        dump_all_vcpus(stk_addr);
+        dump_all_vcpus(mem_addr, stk_addr);
     else
-        dump_ctx(vcpu, stk_addr);
+        dump_ctx(vcpu, mem_addr, stk_addr);
 
     if (xenctx.self_paused) {
         ret = xc_domain_unpause(xenctx.xc_handle, xenctx.domid);
-- 
1.7.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.