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

[Xen-devel] [PATCH v2 10/12] xenctx: change is_kernel_text() into is_kernel_addr().



From: Don Slutz <Don@xxxxxxxxxxxxxxx>

A new enum has been added to allow the caller to determine if this
kernel address is a text on data address.  This is currenlty not
used, but will be in the next patch.

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

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index d6f8482..6ec9c74 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -41,6 +41,15 @@ static struct xenctx {
     xc_dominfo_t dominfo;
 } xenctx;
 
+/* Note: the order of these matter.
+ * NOT_KERNEL_ADDR must be < both KERNEL_DATA_ADDR and KERNEL_TEXT_ADDR.
+ * KERNEL_DATA_ADDR must be < KERNEL_TEXT_ADDR. */
+typedef enum type_of_addr_ {
+    NOT_KERNEL_ADDR,
+    KERNEL_DATA_ADDR,
+    KERNEL_TEXT_ADDR,
+} type_of_addr;
+
 #if defined (__i386__) || defined (__x86_64__)
 typedef unsigned long long guest_word_t;
 #define FMT_32B_WORD "%08llx"
@@ -69,6 +78,7 @@ struct symbol {
 } *symbol_table = NULL;
 
 guest_word_t kernel_stext, kernel_etext, kernel_sinittext, kernel_einittext, 
kernel_hypercallpage;
+guest_word_t kernel_text, kernel_end;
 
 #if defined (__i386__)
 unsigned long long kernel_start = 0xc0000000;
@@ -76,22 +86,28 @@ unsigned long long kernel_start = 0xc0000000;
 unsigned long long kernel_start = 0xffffffff80000000UL;
 #endif
 
-static int is_kernel_text(guest_word_t addr)
+static type_of_addr is_kernel_addr(guest_word_t addr)
 {
-    if (symbol_table == NULL)
-        return (addr > kernel_start);
+    if (symbol_table == NULL) {
+        if (addr > kernel_start)
+            return KERNEL_TEXT_ADDR;
+        else
+            return NOT_KERNEL_ADDR;
+    }
 
     if (addr >= kernel_stext &&
         addr <= kernel_etext)
-        return 1;
-    if (kernel_hypercallpage &&
-        (addr >= kernel_hypercallpage &&
-         addr <= kernel_hypercallpage + 4096))
-        return 1;
+        return KERNEL_TEXT_ADDR;
+    if (kernel_hypercallpage && (addr >= kernel_hypercallpage &&
+                                 addr <= kernel_hypercallpage + 4096))
+        return KERNEL_TEXT_ADDR;
     if (addr >= kernel_sinittext &&
         addr <= kernel_einittext)
-        return 1;
-    return 0;
+        return KERNEL_TEXT_ADDR;
+    if (addr >= kernel_text &&
+        addr <= kernel_end)
+        return KERNEL_DATA_ADDR;
+    return NOT_KERNEL_ADDR;
 }
 
 #if 0
@@ -145,11 +161,11 @@ static struct symbol *lookup_symbol(guest_word_t address)
     return s->next && s->next->address <= address ? s->next : s;
 }
 
-static void print_symbol(guest_word_t addr)
+static void print_symbol(guest_word_t addr, type_of_addr type)
 {
     struct symbol *s;
 
-    if (!is_kernel_text(addr))
+    if (is_kernel_addr(addr) < type)
         return;
 
     s = lookup_symbol(addr);
@@ -217,6 +233,10 @@ static void read_symbol_table(const char *symtab)
             kernel_stext = symbol->address;
         else if (strcmp(symbol->name, "_etext") == 0)
             kernel_etext = symbol->address;
+        else if (strcmp(symbol->name, "_text") == 0)
+            kernel_text = symbol->address;
+        else if (strcmp(symbol->name, "_end") == 0)
+            kernel_end = symbol->address;
         else if (strcmp(symbol->name, "_sinittext") == 0)
             kernel_sinittext = symbol->address;
         else if (strcmp(symbol->name, "_einittext") == 0)
@@ -288,7 +308,7 @@ static void print_ctx_32(vcpu_guest_context_x86_32_t *ctx)
     struct cpu_user_regs_x86_32 *regs = &ctx->user_regs;
 
     printf("cs:eip: %04x:%08x", regs->cs, regs->eip);
-    print_symbol(regs->eip);
+    print_symbol(regs->eip, KERNEL_TEXT_ADDR);
     print_flags(regs->eflags);
     printf("ss:esp: %04x:%08x\n", regs->ss, regs->esp);
 
@@ -317,7 +337,7 @@ static void print_ctx_32on64(vcpu_guest_context_x86_64_t 
*ctx)
     struct cpu_user_regs_x86_64 *regs = &ctx->user_regs;
 
     printf("cs:eip: %04x:%08x", regs->cs, (uint32_t)regs->eip);
-    print_symbol((uint32_t)regs->eip);
+    print_symbol((uint32_t)regs->eip, KERNEL_TEXT_ADDR);
     print_flags((uint32_t)regs->eflags);
     printf("ss:esp: %04x:%08x\n", regs->ss, (uint32_t)regs->esp);
 
@@ -346,7 +366,7 @@ static void print_ctx_64(vcpu_guest_context_x86_64_t *ctx)
     struct cpu_user_regs_x86_64 *regs = &ctx->user_regs;
 
     printf("rip: %016"PRIx64, regs->rip);
-    print_symbol(regs->rip);
+    print_symbol(regs->rip, KERNEL_TEXT_ADDR);
     print_flags(regs->rflags);
     printf("rsp: %016"PRIx64"\n", regs->rsp);
 
@@ -444,7 +464,7 @@ static void print_ctx_32(vcpu_guest_context_t *ctx)
     vcpu_guest_core_regs_t *regs = &ctx->user_regs;
 
     printf("PC:       %08"PRIx32, regs->pc32);
-    print_symbol(regs->pc32);
+    print_symbol(regs->pc32, KERNEL_TEXT_ADDR);
     printf("\n");
     printf("CPSR:     %08"PRIx32"\n", regs->cpsr);
     printf("USR:               SP:%08"PRIx32" LR:%08"PRIx32"\n",
@@ -496,7 +516,7 @@ static void print_ctx_64(vcpu_guest_context_t *ctx)
     vcpu_guest_core_regs_t *regs = &ctx->user_regs;
 
     printf("PC:       %016"PRIx64, regs->pc64);
-    print_symbol(regs->pc64);
+    print_symbol(regs->pc64, KERNEL_TEXT_ADDR);
     printf("\n");
 
     printf("LR:       %016"PRIx64"zn", regs->x30);
@@ -749,7 +769,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
             void *p = map_page(ctx, vcpu, stack);
             if (!p)
                 return -1;
-            word = read_stack_word(p, width);
+            word = read_mem_word(ctx, vcpu, stack, width);
             ascii[j++] = word;
             printf(" ");
             print_stack_word(word, width);
@@ -787,7 +807,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
         printf("%c [<", xenctx.stack_trace ? '*' : ' ');
         print_stack_word(instr_pointer(ctx), width);
         printf(">]");
-        print_symbol(instr_pointer(ctx));
+        print_symbol(instr_pointer(ctx), KERNEL_TEXT_ADDR);
         printf(" <--\n");
     }
     if (xenctx.frame_ptrs) {
@@ -818,7 +838,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
             if (xenctx.stack_trace) {
                 print_stack_word(stack, width);
                 printf(": |-- ");
-                print_stack_word(read_stack_word(p, width), width);
+                print_stack_word(frame, width);
                 printf("\n");
             }
             stack += width;
@@ -832,7 +852,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
                 printf(": %c [<", xenctx.stack_trace ? '|' : ' ');
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
                 stack += width;
             }
@@ -843,13 +863,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
             void *p = map_page(ctx, vcpu, stack);
             if (!p)
                 return -1;
-            word = read_stack_word(p, width);
-            if (is_kernel_text(word)) {
+            word = read_mem_word(ctx, vcpu, stack, width);
+            if (is_kernel_addr(word) >= KERNEL_TEXT_ADDR) {
                 print_stack_word(stack, width);
                 printf(":  [<");
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
             } else if (xenctx.stack_trace) {
                 print_stack_word(stack, width);
@@ -916,7 +936,7 @@ static void dump_ctx(int vcpu, guest_word_t mem_addr, 
guest_word_t stk_addr)
 #ifndef NO_TRANSLATION
         if (!stk_addr) {
             print_code(&ctx, vcpu);
-            if (is_kernel_text(instr_pointer(&ctx)))
+            if (is_kernel_addr(instr_pointer(&ctx)) >= KERNEL_TEXT_ADDR)
                 print_stack(&ctx, vcpu, guest_word_size, stk_addr);
         } else {
             print_stack(&ctx, vcpu, guest_word_size, stk_addr);
-- 
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®.