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

[Xen-devel] [PATCH v3 13/16] xenctx: change is_kernel_text() into 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 or data address.  This is currenlty not
used, but will be in the next patch.

Signed-off-by: Don Slutz <Don@xxxxxxxxxxxxxxx>
---
Changed since v2:
  * new name is kernel_addr().
  * Use kernel_start if set.
  * Remove other changes.

 tools/xentrace/xenctx.c | 67 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 19 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index ee3dcb9..23f2199 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -29,6 +29,15 @@
 #include <xen/foreign/x86_64.h>
 #include <xen/hvm/save.h>
 
+/* 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"
@@ -71,6 +80,7 @@ static struct xenctx {
     int do_memory;
     int do_stack;
 #endif
+    int kernel_start_set;
     int self_paused;
     xc_dominfo_t dominfo;
 } xenctx;
@@ -82,6 +92,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;
@@ -89,22 +100,35 @@ 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 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;
+        return KERNEL_TEXT_ADDR;
     if (kernel_hypercallpage &&
         (addr >= kernel_hypercallpage &&
          addr <= kernel_hypercallpage + 4096))
-        return 1;
+        return KERNEL_TEXT_ADDR;
     if (addr >= kernel_sinittext &&
         addr <= kernel_einittext)
-        return 1;
-    return 0;
+        return KERNEL_TEXT_ADDR;
+    if (xenctx.kernel_start_set) {
+        if (addr >= kernel_start &&
+            addr <= kernel_end)
+            return KERNEL_DATA_ADDR;
+    } else {
+        if (addr >= kernel_text &&
+            addr <= kernel_end)
+            return KERNEL_DATA_ADDR;
+    }
+    return NOT_KERNEL_ADDR;
 }
 
 #if 0
@@ -158,11 +182,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 (kernel_addr(addr) < type)
         return;
 
     s = lookup_symbol(addr);
@@ -230,6 +254,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)
@@ -301,7 +329,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);
 
@@ -330,7 +358,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);
 
@@ -359,7 +387,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);
 
@@ -457,7 +485,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",
@@ -509,7 +537,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);
@@ -805,7 +833,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
         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) {
@@ -860,7 +888,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
                 }
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
                 stack += width;
             }
@@ -872,7 +900,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
             if (!p)
                 return -1;
             word = read_mem_word(ctx, vcpu, stack, width);
-            if (is_kernel_text(word)) {
+            if (kernel_addr(word) >= KERNEL_TEXT_ADDR) {
                 if (xenctx.tag_call_trace) {
                     print_stack_word(stack, width);
                     printf(":  [<");
@@ -881,7 +909,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int 
vcpu, int width, guest
                 }
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
             } else if (xenctx.stack_trace) {
                 if (xenctx.tag_call_trace) {
@@ -953,7 +981,7 @@ static void dump_ctx(int vcpu)
 #ifndef NO_TRANSLATION
     if (print_code(&ctx, vcpu))
         return;
-    if (is_kernel_text(instr_pointer(&ctx)))
+    if (kernel_addr(instr_pointer(&ctx)) >= KERNEL_TEXT_ADDR)
         if (print_stack(&ctx, vcpu, guest_word_size, stack_pointer(&ctx)))
             return;
 #endif
@@ -1098,6 +1126,7 @@ int main(int argc, char **argv)
             break;
         case 'k':
             kernel_start = strtoull(optarg, NULL, 0);
+            xenctx.kernel_start_set = 1;
             break;
 #ifndef NO_TRANSLATION
         case 'm':
-- 
1.8.4


_______________________________________________
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®.