Skip to contentSkip to conversation

xenctx: Many changes.

PATCH Superseded Don Slutz 3 participants 36 messages Mar 18, 2014 – Mar 20, 2014

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

v4 cover xenctx: Many changes.

Add more functionality to xenctx.

Change from v3 to v4:
Dropped patches:
v3 #2 "xenctx: Correct check for xc_interface_open failing (prevents SIGSEGV)"
Simular code already in master
v3 #16 "MAINTAINERS: Add XENCTX maintainer"
Way too soon for this.

Most: re-sytled all adds or changes to be in CODING_STYLE.

#1 "xenctx: clean up usage output":
Changed from kaddr to KADDR.

Jan Beulich:
v3 #4 "xenctx: Add -2 (--two-pages) option to switch stack size to 8KiB"
Converted to
#3 "xenctx: Add -m (--multiple_pages) option to output larger stack"

#10 "xenctx: Add -M <maddr> option to dump memory at"
Changed from -m to -M

Added #15 "xenctx: Fix handling of !guest_protected_mode"

Dropped forever:

v1 patch #11 "xenctx: Dump registers via hvm info if available"

This was a hack to work around a bug fix that is in 4.4.0

Change from v2 to v3:
Added patches #1, #2, #5, and #16.
v3 #1 "xenctx: clean up usage output":
Move all usage cleanup into it's own patch/
v3 #2 "xenctx: Correct check for xc_interface_open failing (prevents SIGSEGV)":
Move xenctx.xc_handle out of patch v2 #9 ""
v3 #5 "xenctx: Add command line options -b and -l":
Redo to stack dump output size adjustments
into commanle line options.
v3 #16 "MAINTAINERS: Add XENCTX maintainer":
Declare this I maintain xenctx, and drop George Dunlap.

Unchanged (other then their number)
v3 #3 "xenctx: Clean up stack trace when hypercall_page not in symbol table" v3 #8 "xenctx: Change print_symbol to do the space before."
v3 #9 "xenctx: More info on failed to map page."

Mostly from Jan Beulich:
v3 #4 "xenctx: Add -2 (--two-pages) option to switch stack size to 8KiB":
* Dropped extra change about i < 10.
* Move add to usage to the end.
v3 #6 "xenctx: Add command line option -D (--decode-as-ascii)":
v3 #7 "xenctx: Add command line option -t (--tag-stack-dump)":
v3 #10 "xenctx: Add command line option -T (--tag-call-trace)":
* Add command line option to control this.
* More info in commit message.
v3 #11 "xenctx: Add -m <maddr> option to dump memory at maddr.":
* Reworked option handling to allow multiple actions to work.
* Add check for NO_TRANSLATION where needed.
* Support -b and -l.
v3 #12 "xenctx: Add -d <daddr> option to dump memory at daddr as a stack.":
* Do this patch after -m patch.
* Reworked option handling to allow multiple actions to work.
* Add check for NO_TRANSLATION where needed.
* More info in commit message.
v3 #13 "xenctx: change is_kernel_text() into kernel_addr().":
* new name is kernel_addr().
* Use kernel_start if set.
* Remove other changes.
v3 #14 "xenctx: Add convert of more registers to symbols":
* Extract just the symbol printing code from "xenctx: Dump registers via hvm info if available"
v3 #15 "xenctx: Add output of vcpu value and state for --all-vcpus":
* Extract just the vcpu printing code from "xenctx: xenctx: Add optional fCPU"

v1 patch #11 "xenctx: Dump registers via hvm info if available" has
been defered to the "merge xenctx and xen_hvmctx" patch set.

v1 patch #12 "xenctx: Add optional fCPU" has been dropped.

Change from v1 to v2:
title was: xenctx: Add an option to output more registers. Processed review comments.
Jan Beulich:
Split 1 change into 12.
Switch to enum for is_kernel_text(), renamed to is_kernel_addr(). Renamed vars like memAddr to mem_addr.
Ian Campbell:
More on is_kernel_text().

Don Slutz (15):
xenctx: clean up usage output
xenctx: Clean up stack trace when hypercall_page not in symbol table
xenctx: Add -m (--multiple_pages) option to output larger stack
xenctx: Add command line options -b and -l
xenctx: Add command line option -D (--decode-as-ascii)
xenctx: Add command line option -t (--tag-stack-dump)
xenctx: Change print_symbol to do the space before.
xenctx: More info on failed to map page.
xenctx: Add command line option -T (--tag-call-trace)
xenctx: Add -M <maddr> option to dump memory at maddr.
xenctx: Add -d <daddr> option to dump memory at daddr as a stack.
xenctx: change is_kernel_text() into kernel_addr().
xenctx: Add convert of more registers to symbols
xenctx: Add output of vcpu value and state for --all-vcpus
xenctx: Fix handling of !guest_protected_mode

 tools/xentrace/xenctx.c | 546 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 456 insertions(+), 90 deletions(-)
Signature · 1 line
1.8.4
author
#1 lore raw

PATCH v4 1/15 xenctx: clean up usage output

Fix usage formatting to be all the same.

Fix usage display of default --kernel-start for 64 bit.

---
v4 Changed from kaddr to KADDR

 tools/xentrace/xenctx.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
tools/xentrace/xenctx.c +9 -8
index 7275a00..97c6197 100644
@@ -823,15 +823,16 @@ static void usage(void)
 
     printf("options:\n");
     printf("  -f, --frame-pointers\n");
-    printf("                    assume the kernel was compiled with\n");
-    printf("                    frame pointers.\n");
+    printf("                     assume the kernel was compiled with\n");
+    printf("                     frame pointers.\n");
     printf("  -s SYMTAB, --symbol-table=SYMTAB\n");
-    printf("                    read symbol table from SYMTAB.\n");
-    printf("  -S --stack-trace  print a complete stack trace.\n");
-    printf("  -k, --kernel-start\n");
-    printf("                    set user/kernel split. (default 0xc0000000)\n");
-    printf("  -a --all          display more registers\n");
-    printf("  -C --all-vcpus    print info for all vcpus\n");
+    printf("                     read symbol table from SYMTAB.\n");
+    printf("  -S, --stack-trace  print a complete stack trace.\n");
+    printf("  -k KADDR, --kernel-start=KADDR\n");
+    printf("                     set user/kernel split. (default 0x"FMT_32B_WORD")\n",
+        kernel_start);
+    printf("  -a, --all          display more registers\n");
+    printf("  -C, --all-vcpus    print info for all vcpus\n");
 }
 
 int main(int argc, char **argv)
Signature · 1 line
1.8.4
Reviewed-by on v4 1/15
#2 lore raw

Re: [PATCH v4 01/15] xenctx: clean up usage output

Quoted 5 lines · Don Slutz

Fix usage formatting to be all the same.

Fix usage display of default --kernel-start for 64 bit.

Quoted 35 lines

---
v4 Changed from kaddr to KADDR

  tools/xentrace/xenctx.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)
tools/xentrace/xenctx.c +9 -8
index 7275a00..97c6197 100644
@@ -823,15 +823,16 @@ static void usage(void)
 
      printf("options:\n");
      printf("  -f, --frame-pointers\n");
-    printf("                    assume the kernel was compiled with\n");
-    printf("                    frame pointers.\n");
+    printf("                     assume the kernel was compiled with\n");
+    printf("                     frame pointers.\n");
      printf("  -s SYMTAB, --symbol-table=SYMTAB\n");
-    printf("                    read symbol table from SYMTAB.\n");
-    printf("  -S --stack-trace  print a complete stack trace.\n");
-    printf("  -k, --kernel-start\n");
-    printf("                    set user/kernel split. (default 0xc0000000)\n");
-    printf("  -a --all          display more registers\n");
-    printf("  -C --all-vcpus    print info for all vcpus\n");
+    printf("                     read symbol table from SYMTAB.\n");
+    printf("  -S, --stack-trace  print a complete stack trace.\n");
+    printf("  -k KADDR, --kernel-start=KADDR\n");
+    printf("                     set user/kernel split. (default 0x"FMT_32B_WORD")\n",
+        kernel_start);
+    printf("  -a, --all          display more registers\n");
+    printf("  -C, --all-vcpus    print info for all vcpus\n");
  }
 
  int main(int argc, char **argv)
author
#3 lore raw

PATCH v4 2/15 xenctx: Clean up stack trace when hypercall_page not in symbol table

In reply to Don Slutz

From: Don Slutz <[email protected]>

Before:

Call Trace:
  [<ffffffff8006b2b0>] default_idle+0x29  <--
  [<ffffffff80048d19>] cpu_idle+0x95
  [<ffffffff803e7801>] start_kernel+0x220
  [<0000000000000000>] startup_64+0x80000000
  [<ffffffff803e722f>] x86_64_start_kernel+0x22f
  [<0000000000000000>] startup_64+0x80000000
  [<0000000000000000>] startup_64+0x80000000
  [<0000000000000000>] startup_64+0x80000000
  [<0000000000000000>] startup_64+0x80000000

After:

Call Trace:
  [<ffffffff8006b2b0>] default_idle+0x29  <--
  [<ffffffff80048d19>] cpu_idle+0x95
  [<ffffffff803e7801>] start_kernel+0x220
  [<ffffffff803e722f>] x86_64_start_kernel+0x22f
---
 tools/xentrace/xenctx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/xentrace/xenctx.c +3 -2
index 97c6197..42a47f3 100644
@@ -85,8 +85,9 @@ static int is_kernel_text(guest_word_t addr)
     if (addr >= kernel_stext &&
         addr <= kernel_etext)
         return 1;
-    if (addr >= kernel_hypercallpage &&
-        addr <= kernel_hypercallpage + 4096)
+    if ( kernel_hypercallpage &&
+         (addr >= kernel_hypercallpage &&
+          addr <= kernel_hypercallpage + 4096) )
         return 1;
     if (addr >= kernel_sinittext &&
         addr <= kernel_einittext)
Signature · 1 line
1.8.4
Acked-by on v4 2/15
#4 lore raw

Re: [PATCH v4 02/15] xenctx: Clean up stack trace when hypercall_page not in symbol table

Quoted 23 lines · Don Slutz

From: Don Slutz <[email protected]>

Before:

Call Trace:
   [<ffffffff8006b2b0>] default_idle+0x29  <--
   [<ffffffff80048d19>] cpu_idle+0x95
   [<ffffffff803e7801>] start_kernel+0x220
   [<0000000000000000>] startup_64+0x80000000
   [<ffffffff803e722f>] x86_64_start_kernel+0x22f
   [<0000000000000000>] startup_64+0x80000000
   [<0000000000000000>] startup_64+0x80000000
   [<0000000000000000>] startup_64+0x80000000
   [<0000000000000000>] startup_64+0x80000000

After:

Call Trace:
   [<ffffffff8006b2b0>] default_idle+0x29  <--
   [<ffffffff80048d19>] cpu_idle+0x95
   [<ffffffff803e7801>] start_kernel+0x220
   [<ffffffff803e722f>] x86_64_start_kernel+0x22f
Quoted 3 lines
author
#5 lore raw

PATCH v4 3/15 xenctx: Add -m (--multiple_pages) option to output larger stack

In reply to Don Slutz

From: Don Slutz <[email protected]>

Important: This is the stack size to display not the configured stack size.

Using pictures (for a 3 page configured system):

       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
       |                  |
       |                  |
       |                  |
SP --> |                  |
       |                  |
       +------------------+

Display using "-m 1" since the used stack pages is 1.

       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
       |                  |
SP --> |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+

Display using "-m 2" since the used stack pages is 2.

       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
SP --> |                  |
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+

Display using "-m 3" since the used stack pages is 3.

---
v4 Converted from xenctx: Add -2 (--two-pages) option to switch stack size to 8KiB

 tools/xentrace/xenctx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +10 -1
index 42a47f3..6da38cc 100644
@@ -35,6 +35,7 @@ static struct xenctx {
     int frame_ptrs;
     int stack_trace;
     int disp_all;
+    int multiple_pages;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -664,6 +665,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
 
     stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                    & ~((guest_word_t) XC_PAGE_SIZE - 1));
+    if ( xenctx.multiple_pages > 1 )
+        stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
     printf("\n");
     printf("Stack:\n");
     for (i=1; i<5 && stack < stack_limit; i++) {
@@ -834,18 +837,21 @@ static void usage(void)
         kernel_start);
     printf("  -a, --all          display more registers\n");
     printf("  -C, --all-vcpus    print info for all vcpus\n");
+    printf("  -m PAGES, --multiple-pages=PAGES\n");
+    printf("                     assume the kernel was compiled with PAGES (default 1) of stacks.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SC";
+    static const char *sopts = "fs:hak:SCm:";
     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'},
+        {"multiple-pages", 0, NULL, 'm'},
         {"all", 0, NULL, 'a'},
         {"all-vcpus", 0, NULL, 'C'},
         {"help", 0, NULL, 'h'},
@@ -869,6 +875,9 @@ int main(int argc, char **argv)
         case 'a':
             xenctx.disp_all = 1;
             break;
+        case 'm':
+            xenctx.multiple_pages = strtol(optarg, NULL, 0);
+            break;
         case 'C':
             xenctx.all_vcpus = 1;
             break;
Signature · 1 line
1.8.4
#6 lore raw

Re: [PATCH v4 03/15] xenctx: Add -m (--multiple_pages) option to output larger stack

Quoted 18 lines · Don Slutz

From: Don Slutz <[email protected]>

Important: This is the stack size to display not the configured stack size.

Using pictures (for a 3 page configured system):

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
Quoted 8 lines
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
SP --> |                  |
        |                  |
        +------------------+

Sorry, what is this a picture of? I can't make any sense out of it. Shouldn't this have only one box, the next have two, and the bottom one have three?

Quoted 85 lines

Display using "-m 1" since the used stack pages is 1.

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
SP --> |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+

Display using "-m 2" since the used stack pages is 2.

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
SP --> |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+

Display using "-m 3" since the used stack pages is 3.

---
v4 Converted from xenctx: Add -2 (--two-pages) option to switch stack size to 8KiB

  tools/xentrace/xenctx.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +5 -0
index 42a47f3..6da38cc 100644
@@ -35,6 +35,7 @@ static struct xenctx {
      int frame_ptrs;
      int stack_trace;
      int disp_all;
+    int multiple_pages;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -664,6 +665,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
 
      stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                     & ~((guest_word_t) XC_PAGE_SIZE - 1));
+    if ( xenctx.multiple_pages > 1 )
+        stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
      printf("\n");
      printf("Stack:\n");
      for (i=1; i<5 && stack < stack_limit; i++) {
@@ -834,18 +837,21 @@ static void usage(void)
          kernel_start);
      printf("  -a, --all          display more registers\n");
      printf("  -C, --all-vcpus    print info for all vcpus\n");
+    printf("  -m PAGES, --multiple-pages=PAGES\n");
+    printf("                     assume the kernel was compiled with PAGES (default 1) of stacks.\n");
  }
 
  int main(int argc, char **argv)
  {

tools/xentrace/xenctx.c static void usage(void) · line 854

Quoted 10 lines
tools/xentrace/xenctx.c +2 -1
      int ch;
      int ret;
-    static const char *sopts = "fs:hak:SC";
+    static const char *sopts = "fs:hak:SCm:";
      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'},
+        {"multiple-pages", 0, NULL, 'm'},

I think I would call the long option "kernel-stack-pages" or something like that. "Multiple pages" doesn't really convey much meaning. -m is probably a fine short option, but -n might be more memorable.

-George

author
#7 lore raw

Re: [PATCH v4 03/15] xenctx: Add -m (--multiple_pages) option to output larger stack

Quoted 28 lines · George Dunlap
Quoted 18 lines · Don Slutz

From: Don Slutz <[email protected]>

Important: This is the stack size to display not the configured stack size.

Using pictures (for a 3 page configured system):

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
Quoted 8 lines
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
SP --> |                  |
        |                  |
        +------------------+
Quoted 2 lines

Sorry, what is this a picture of? I can't make any sense out of it. Shouldn't this have only one box, the next have two, and the bottom one have three?

This is various pictures of a 3 page stack, and where the SP currently is. Each box is a page. So here the "stack limit" is the end of 1 page. In the sense of how much stack is used, you are right it is 1, 2 and then 3. This tracks with the value passed for "-m" (see next line).

Quoted 15 lines
Quoted 15 lines

Display using "-m 1" since the used stack pages is 1.

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
SP --> |                  |
        |                  |
        |                  |
        |                  |
Quoted 8 lines
Quoted 8 lines
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+

Here the stack limit is end of page + 1 full page.

Quoted 22 lines
Quoted 22 lines

Display using "-m 2" since the used stack pages is 2.

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
SP --> |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
Quoted 2 lines
Quoted 2 lines

Display using "-m 3" since the used stack pages is 3.

Here the stack limit is end of page + 2 full pages.

Quoted 28 lines
Quoted 28 lines

---
v4 Converted from xenctx: Add -2 (--two-pages) option to switch stack size to 8KiB

  tools/xentrace/xenctx.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +3 -0
index 42a47f3..6da38cc 100644
@@ -35,6 +35,7 @@ static struct xenctx {
      int frame_ptrs;
      int stack_trace;
      int disp_all;
+    int multiple_pages;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -664,6 +665,8 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
        stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                     & ~((guest_word_t) XC_PAGE_SIZE - 1));
+    if ( xenctx.multiple_pages > 1 )
+        stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
      printf("\n");
      printf("Stack:\n");
      for (i=1; i<5 && stack < stack_limit; i++) {
Quoted 8 lines

tools/xentrace/xenctx.c static void usage(void) · line 843

Quoted 8 lines
tools/xentrace/xenctx.c +2 -0
@@ -834,18 +837,21 @@ static void usage(void)
          kernel_start);
      printf("  -a, --all          display more registers\n");
      printf("  -C, --all-vcpus    print info for all vcpus\n");
+    printf("  -m PAGES, --multiple-pages=PAGES\n");
+    printf("                     assume the kernel was compiled with 
 PAGES (default 1) of stacks.\n");
  }

Opps, this needs fixing.

Quoted 13 lines

tools/xentrace/xenctx.c static void usage(void) · line 854

Quoted 12 lines
tools/xentrace/xenctx.c +2 -1
    int main(int argc, char **argv)
  {
      int ch;
      int ret;
-    static const char *sopts = "fs:hak:SC";
+    static const char *sopts = "fs:hak:SCm:";
      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'},
+        {"multiple-pages", 0, NULL, 'm'},
Quoted 2 lines

I think I would call the long option "kernel-stack-pages" or something like that. "Multiple pages" doesn't really convey much meaning. -m is probably a fine short option, but -n might be more memorable.

The issue with "kernel-stack-pages" is that it leads to configured kernel stack pages (which for the pictures above is 3). 3 is most likely not the number to use here.

A big part of this is that how a "kernel" knows where it is in the stack can be simple like for a 2 page stack, 1 page is odd, 2nd page is even. (3 pages is most likely more complex, but fence page(s) may help here.)

Maybe stack-limit-in-pages is better?

-Don Slutz

Quoted 2 lines

-George

#8 lore raw

Re: [PATCH v4 03/15] xenctx: Add -m (--multiple_pages) option to output larger stack

Quoted 29 lines · Don Slutz
Quoted 28 lines · George Dunlap
Quoted 26 lines · Don Slutz

From: Don Slutz <[email protected]>

Important: This is the stack size to display not the configured stack size.

Using pictures (for a 3 page configured system):

        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
        |                  |
        |                  |
        +------------------+
        |                  |
        |                  |
        |                  |
SP --> |                  |
        |                  |
        +------------------+
Quoted 4 lines
Quoted 2 lines

Sorry, what is this a picture of? I can't make any sense out of it. Shouldn't this have only one box, the next have two, and the bottom one have three?

This is various pictures of a 3 page stack, and where the SP currently is. Each box is a page. So here the "stack limit" is the end of 1 page. In the sense of how much stack is used, you are right it is 1, 2 and then 3. This tracks with the value passed for "-m" (see next line).

Oh, right: so you're saying that the developer running xenctx has to *guess* how many pages are currently in use? In other words, this really means, "Display N stack pages", and if you guessed too high, you'll get some pages worth of garbage.

[snip]

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

int main(int argc, char **argv)

  {
      int ch;
      int ret;
tools/xentrace/xenctx.c +2 -1
-    static const char *sopts = "fs:hak:SC";
+    static const char *sopts = "fs:hak:SCm:";
      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'},
+        {"multiple-pages", 0, NULL, 'm'},
Quoted 8 lines
Quoted 2 lines

I think I would call the long option "kernel-stack-pages" or something like that. "Multiple pages" doesn't really convey much meaning. -m is probably a fine short option, but -n might be more memorable.

The issue with "kernel-stack-pages" is that it leads to configured kernel stack pages (which for the pictures above is 3). 3 is most likely not the number to use here.

A big part of this is that how a "kernel" knows where it is in the stack can be simple like for a 2 page stack, 1 page is odd, 2nd page is even. (3 pages is most likely more complex, but fence page(s) may help here.)

Maybe stack-limit-in-pages is better?

Hmm -- "--display-stack-pages", and then say, "Display N pages from the stack pointer"?

-George

author
#9 lore raw

PATCH v4 4/15 xenctx: Add command line options -b and -l

In reply to Don Slutz

-b <bytes>, --bytes-per-line <bytes>
change the number of bytes per line output for Stack.
note: rounded to native size (4 or 8 bytes).
-l <lines>, --lines <lines>
change the number of lines output for Stack.

---
 tools/xentrace/xenctx.c | 67 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 55 insertions(+), 12 deletions(-)
tools/xentrace/xenctx.c +55 -12
index 6da38cc..62a8519 100644
@@ -36,6 +36,8 @@ static struct xenctx {
     int stack_trace;
     int disp_all;
     int multiple_pages;
+    int bytes_per_line;
+    int lines;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -62,6 +64,8 @@ typedef uint64_t guest_word_t;
 #define FMT_64B_WORD "%016lx"
 #endif
 
+#define MAX_BYTES_PER_LINE 128
+
 struct symbol {
     guest_word_t address;
     char *name;
@@ -663,25 +667,33 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
     guest_word_t *p;
     int i;
 
+    if ( width )
+        xenctx.bytes_per_line = ((xenctx.bytes_per_line + width - 1) / width) * width;
     stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                    & ~((guest_word_t) XC_PAGE_SIZE - 1));
     if ( xenctx.multiple_pages > 1 )
         stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
     printf("\n");
-    printf("Stack:\n");
-    for (i=1; i<5 && stack < stack_limit; i++) {
-        while(stack < stack_limit && stack < stack_pointer(ctx) + i*32) {
-            p = map_page(ctx, vcpu, stack);
-            if (!p)
-                return -1;
-            word = read_stack_word(p, width);
-            printf(" ");
-            print_stack_word(word, width);
-            stack += width;
+    if ( xenctx.lines )
+    {
+        printf("Stack:\n");
+        for (i = 1; i < xenctx.lines + 1 && stack < stack_limit; i++)
+        {
+            while ( stack < stack_limit &&
+                    stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
+            {
+                p = map_page(ctx, vcpu, stack);
+                if ( !p )
+                    return -1;
+                word = read_stack_word(p, width);
+                printf(" ");
+                print_stack_word(word, width);
+                stack += width;
+            }
+            printf("\n");
         }
         printf("\n");
     }
-    printf("\n");
 
     if(xenctx.stack_trace)
         printf("Stack Trace:\n");
@@ -839,19 +851,26 @@ static void usage(void)
     printf("  -C, --all-vcpus    print info for all vcpus\n");
     printf("  -m PAGES, --multiple-pages=PAGES\n");
     printf("                     assume the kernel was compiled with PAGES (default 1) of stacks.\n");
+    printf("  -b <bytes>, --bytes-per-line <bytes>\n");
+    printf("                     change the number of bytes per line output for Stack.\n");
+    printf("                     note: rounded to native size (4 or 8 bytes).\n");
+    printf("  -l <lines>, --lines <lines>\n");
+    printf("                     change the number of lines output for Stack.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCm:";
+    static const char *sopts = "fs:hak:SCmb:l:";
     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'},
         {"multiple-pages", 0, NULL, 'm'},
+        {"bytes-per-line", 1, NULL, 'b'},
+        {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
         {"all-vcpus", 0, NULL, 'C'},
         {"help", 0, NULL, 'h'},
@@ -861,6 +880,9 @@ int main(int argc, char **argv)
 
     int vcpu = 0;
 
+    xenctx.bytes_per_line = 32;
+    xenctx.lines = 5;
+
     while ((ch = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
         switch(ch) {
         case 'f':
@@ -878,6 +900,27 @@ int main(int argc, char **argv)
         case 'm':
             xenctx.multiple_pages = strtol(optarg, NULL, 0);
             break;
+        case 'b':
+            xenctx.bytes_per_line = strtol(optarg, NULL, 0);
+            if ( xenctx.bytes_per_line < 4 ||
+                 xenctx.bytes_per_line > MAX_BYTES_PER_LINE )
+            {
+                fprintf(stderr,
+                        "%s: Unsupported value for --bytes-per-line. Needs to be 4 <= <bytes> <= %d\n",
+                        argv[0], MAX_BYTES_PER_LINE);
+                exit(-1);
+            }
+            break;
+        case 'l':
+            xenctx.lines = strtol(optarg, NULL, 0);
+            if ( xenctx.lines < 0 )
+            {
+                fprintf(stderr,
+                        "%s: Unsupported value for --lines. Needs to be >= 0\n",
+                        argv[0]);
+                exit(-1);
+            }
+            break;
         case 'C':
             xenctx.all_vcpus = 1;
             break;
Signature · 1 line
1.8.4
#10 lore raw

Re: [PATCH v4 04/15] xenctx: Add command line options -b and -l

Quoted 79 lines · Don Slutz

-b <bytes>, --bytes-per-line <bytes>
change the number of bytes per line output for Stack.
note: rounded to native size (4 or 8 bytes).
-l <lines>, --lines <lines>
change the number of lines output for Stack.

---
  tools/xentrace/xenctx.c | 67 ++++++++++++++++++++++++++++++++++++++++---------
  1 file changed, 55 insertions(+), 12 deletions(-)
tools/xentrace/xenctx.c +23 -11
index 6da38cc..62a8519 100644
@@ -36,6 +36,8 @@ static struct xenctx {
      int stack_trace;
      int disp_all;
      int multiple_pages;
+    int bytes_per_line;
+    int lines;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -62,6 +64,8 @@ typedef uint64_t guest_word_t;
  #define FMT_64B_WORD "%016lx"
  #endif
 
+#define MAX_BYTES_PER_LINE 128
+
  struct symbol {
      guest_word_t address;
      char *name;
@@ -663,25 +667,33 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
      guest_word_t *p;
      int i;
 
+    if ( width )
+        xenctx.bytes_per_line = ((xenctx.bytes_per_line + width - 1) / width) * width;
      stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                     & ~((guest_word_t) XC_PAGE_SIZE - 1));
      if ( xenctx.multiple_pages > 1 )
          stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
      printf("\n");
-    printf("Stack:\n");
-    for (i=1; i<5 && stack < stack_limit; i++) {
-        while(stack < stack_limit && stack < stack_pointer(ctx) + i*32) {
-            p = map_page(ctx, vcpu, stack);
-            if (!p)
-                return -1;
-            word = read_stack_word(p, width);
-            printf(" ");
-            print_stack_word(word, width);
-            stack += width;
+    if ( xenctx.lines )
+    {
+        printf("Stack:\n");
+        for (i = 1; i < xenctx.lines + 1 && stack < stack_limit; i++)
+        {
+            while ( stack < stack_limit &&
+                    stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
+            {
+                p = map_page(ctx, vcpu, stack);
+                if ( !p )
+                    return -1;
+                word = read_stack_word(p, width);
+                printf(" ");
+                print_stack_word(word, width);
+                stack += width;
+            }
+            printf("\n");
          }
          printf("\n");
      }
-    printf("\n");
 
      if(xenctx.stack_trace)
          printf("Stack Trace:\n");

tools/xentrace/xenctx.c static void usage(void) · line 858

Quoted 8 lines
tools/xentrace/xenctx.c +5 -0
@@ -839,19 +851,26 @@ static void usage(void)
      printf("  -C, --all-vcpus    print info for all vcpus\n");
      printf("  -m PAGES, --multiple-pages=PAGES\n");
      printf("                     assume the kernel was compiled with PAGES (default 1) of stacks.\n");
+    printf("  -b <bytes>, --bytes-per-line <bytes>\n");
+    printf("                     change the number of bytes per line output for Stack.\n");
+    printf("                     note: rounded to native size (4 or 8 bytes).\n");
+    printf("  -l <lines>, --lines <lines>\n");
+    printf("                     change the number of lines output for Stack.\n");

You should probably put the default values here (32 and 5 respectively). (And they should probably be set by a #define, so that there's no risk of the defaults in the help diverging from the defaults in the code.)

Also, would it make sense to have a value for -l that means "just print everything until you hit "stack_limit"? Obviously someone could just write "-l 100000" here, but it might be nicer to have something more sensible.

That's just an idea; I think once the default values are in it can have my ack.

-George

author
#11 lore raw

Re: [PATCH v4 04/15] xenctx: Add command line options -b and -l

Quoted 89 lines · George Dunlap
Quoted 88 lines · Don Slutz

-b <bytes>, --bytes-per-line <bytes>
change the number of bytes per line output for
Stack.
note: rounded to native size (4 or 8 bytes).
-l <lines>, --lines <lines>
change the number of lines output for Stack.

---
  tools/xentrace/xenctx.c | 67 
++++++++++++++++++++++++++++++++++++++++---------
  1 file changed, 55 insertions(+), 12 deletions(-)
tools/xentrace/xenctx.c +23 -11
index 6da38cc..62a8519 100644
@@ -36,6 +36,8 @@ static struct xenctx {
      int stack_trace;
      int disp_all;
      int multiple_pages;
+    int bytes_per_line;
+    int lines;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -62,6 +64,8 @@ typedef uint64_t guest_word_t;
  #define FMT_64B_WORD "%016lx"
  #endif
  +#define MAX_BYTES_PER_LINE 128
+
  struct symbol {
      guest_word_t address;
      char *name;
@@ -663,25 +667,33 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
      guest_word_t *p;
      int i;
  +    if ( width )
+        xenctx.bytes_per_line = ((xenctx.bytes_per_line + width - 1) 
 / width) * width;
      stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
                     & ~((guest_word_t) XC_PAGE_SIZE - 1));
      if ( xenctx.multiple_pages > 1 )
          stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
      printf("\n");
-    printf("Stack:\n");
-    for (i=1; i<5 && stack < stack_limit; i++) {
-        while(stack < stack_limit && stack < stack_pointer(ctx) + 
 i*32) {
-            p = map_page(ctx, vcpu, stack);
-            if (!p)
-                return -1;
-            word = read_stack_word(p, width);
-            printf(" ");
-            print_stack_word(word, width);
-            stack += width;
+    if ( xenctx.lines )
+    {
+        printf("Stack:\n");
+        for (i = 1; i < xenctx.lines + 1 && stack < stack_limit; i++)
+        {
+            while ( stack < stack_limit &&
+                    stack < stack_pointer(ctx) + i * 
 xenctx.bytes_per_line )
+            {
+                p = map_page(ctx, vcpu, stack);
+                if ( !p )
+                    return -1;
+                word = read_stack_word(p, width);
+                printf(" ");
+                print_stack_word(word, width);
+                stack += width;
+            }
+            printf("\n");
          }
          printf("\n");
      }
-    printf("\n");
        if(xenctx.stack_trace)
          printf("Stack Trace:\n");
@@ -839,19 +851,26 @@ static void usage(void)
      printf("  -C, --all-vcpus    print info for all vcpus\n");
      printf("  -m PAGES, --multiple-pages=PAGES\n");
      printf("                     assume the kernel was compiled 
 with PAGES (default 1) of stacks.\n");
+    printf("  -b <bytes>, --bytes-per-line <bytes>\n");
+    printf("                     change the number of bytes per line 
Quoted 9 lines

tools/xentrace/xenctx.c static void usage(void) · line 862

Quoted 6 lines
tools/xentrace/xenctx.c +3 -0
 output for Stack.\n");
+    printf("                     note: rounded to native size (4 or 
 8 bytes).\n");
+    printf("  -l <lines>, --lines <lines>\n");
+    printf("                     change the number of lines output 
 for Stack.\n");

You should probably put the default values here (32 and 5 respectively). (And they should probably be set by a #define, so that there's no risk of the defaults in the help diverging from the defaults in the code.)

Will do.

Quoted 2 lines

Also, would it make sense to have a value for -l that means "just print everything until you hit "stack_limit"? Obviously someone could just write "-l 100000" here, but it might be nicer to have something more sensible.

Since it does stop on stack limit already, I will add this to the usage. I could add a check for "all", will consider it.

-Don Slutz

Quoted 4 lines

That's just an idea; I think once the default values are in it can have my ack.

-George

author
#12 lore raw

PATCH v4 5/15 xenctx: Add command line option -D (--decode-as-ascii)

In reply to Don Slutz

If specified, output ascii version of stack also.

Here is an example:

Stack:
 ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800  .......... ......x>......h......
 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c  ........ .C...../r>.............
 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000  .......................... .....
 0000000000000000 0000000000000000                                    ................
---
 tools/xentrace/xenctx.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +34 -1
index 62a8519..850e091 100644
@@ -38,6 +38,7 @@ static struct xenctx {
     int multiple_pages;
     int bytes_per_line;
     int lines;
+    int decode_as_ascii;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -665,6 +666,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 )
@@ -679,6 +681,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 )
             {
@@ -686,10 +691,32 @@ 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;
             }
+            printf("  ");
+            if ( xenctx.decode_as_ascii )
+            {
+                for (k = j; k < xenctx.bytes_per_line / width; k++)
+                    printf(" %*s", width*2, "");
+                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");
@@ -856,19 +883,22 @@ static void usage(void)
     printf("                     note: rounded to native size (4 or 8 bytes).\n");
     printf("  -l <lines>, --lines <lines>\n");
     printf("                     change the number of lines output for Stack.\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:SCmb:l:";
+    static const char *sopts = "fs:hak:SCmb: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'},
         {"multiple-pages", 0, NULL, 'm'},
+        {"decode-as-ascii", 0, NULL, 'D'},
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
@@ -900,6 +930,9 @@ int main(int argc, char **argv)
         case 'm':
             xenctx.multiple_pages = strtol(optarg, NULL, 0);
             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 ||
Signature · 1 line
1.8.4
#13 lore raw

Re: [PATCH v4 05/15] xenctx: Add command line option -D (--decode-as-ascii)

Quoted 50 lines · Don Slutz

If specified, output ascii version of stack also.

Here is an example:

Stack:
  ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800  .......... ......x>......h......
  0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c  ........ .C...../r>.............
  00000000ffffffff 0000000000000000 0000000000000000 0000000000200000  .......................... .....
  0000000000000000 0000000000000000                                    ................
---
  tools/xentrace/xenctx.c | 35 ++++++++++++++++++++++++++++++++++-
  1 file changed, 34 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +6 -0
index 62a8519..850e091 100644
@@ -38,6 +38,7 @@ static struct xenctx {
      int multiple_pages;
      int bytes_per_line;
      int lines;
+    int decode_as_ascii;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -665,6 +666,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 )
@@ -679,6 +681,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 )
              {
@@ -686,10 +691,32 @@ 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 )

tools/xentrace/xenctx.c static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width) · line 704

Quoted 10 lines
tools/xentrace/xenctx.c +6 -0
+                    ascii[j++] = word;
                  printf(" ");
                  print_stack_word(word, width);
                  stack += width;
              }
+            printf("  ");
+            if ( xenctx.decode_as_ascii )
+            {
+                for (k = j; k < xenctx.bytes_per_line / width; k++)
+                    printf(" %*s", width*2, "");

It might be nice to have a comment here explaining what this is doing: maybe, "Line up ascii output if less than bytes_per_line were printed."

Also, the printf(" ") line above should probably go under this for loop. It goes here logically, and it avoids printing trailing whitespace if decode_as_ascii is false.

-George

author
#14 lore raw

Re: [PATCH v4 05/15] xenctx: Add command line option -D (--decode-as-ascii)

Quoted 61 lines · George Dunlap
Quoted 60 lines · Don Slutz

If specified, output ascii version of stack also.

Here is an example:

Stack:
  ffffffff80048d19 0000000000200800 ffffffff803e7801 

0000000000086800 .......... ......x>......h......
0000000000000000 ffffffff80430720 ffffffff803e722f
80008e000010019c ........ .C...../r>.............
00000000ffffffff 0000000000000000 0000000000000000
0000000000200000 .......................... .....
0000000000000000 0000000000000000 ................

---
  tools/xentrace/xenctx.c | 35 ++++++++++++++++++++++++++++++++++-
  1 file changed, 34 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +5 -0
index 62a8519..850e091 100644
@@ -38,6 +38,7 @@ static struct xenctx {
      int multiple_pages;
      int bytes_per_line;
      int lines;
+    int decode_as_ascii;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -665,6 +666,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 )
@@ -679,6 +681,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 )

              {
tools/xentrace/xenctx.c +2 -0
@@ -686,10 +691,32 @@ 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;
Quoted 9 lines

tools/xentrace/xenctx.c static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width) · line 704

Quoted 6 lines
tools/xentrace/xenctx.c +5 -0
              }
+            printf("  ");
+            if ( xenctx.decode_as_ascii )
+            {
+                for (k = j; k < xenctx.bytes_per_line / width; k++)
+                    printf(" %*s", width*2, "");

It might be nice to have a comment here explaining what this is doing: maybe, "Line up ascii output if less than bytes_per_line were printed."

Ok.

Quoted 2 lines

Also, the printf(" ") line above should probably go under this for loop. It goes here logically, and it avoids printing trailing whitespace if decode_as_ascii is false.

Will do. Thanks,
-Don Slutz

Quoted 2 lines

-George

author
#15 lore raw

PATCH v4 6/15 xenctx: Add command line option -t (--tag-stack-dump)

In reply to Don Slutz

If specified, add stack address to dump.

Here is an example:

Stack:
ffffffff803ddf90: ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800
ffffffff803ddfb0: 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c
ffffffff803ddfd0: 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000
ffffffff803ddff0: 0000000000000000 0000000000000000
---
 tools/xentrace/xenctx.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +13 -1
index 850e091..9808e55 100644
@@ -39,6 +39,7 @@ static struct xenctx {
     int bytes_per_line;
     int lines;
     int decode_as_ascii;
+    int tag_stack_dump;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -684,6 +685,11 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
             int j = 0;
             int k;
 
+            if ( xenctx.tag_stack_dump )
+            {
+                print_stack_word(stack, width);
+                printf(":");
+            }
             while ( stack < stack_limit &&
                     stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
             {
@@ -885,13 +891,15 @@ static void usage(void)
     printf("                     change the number of lines output for Stack.\n");
     printf("  -D, --decode-as-ascii\n");
     printf("                     add a decode of Stack dump as ascii.\n");
+    printf("  -t, --tag-stack-dump\n");
+    printf("                     add address on each line of Stack dump.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCmb:l:D";
+    static const char *sopts = "fs:hak:SCmb:l:Dt";
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
@@ -899,6 +907,7 @@ int main(int argc, char **argv)
         {"kernel-start", 1, NULL, 'k'},
         {"multiple-pages", 0, NULL, 'm'},
         {"decode-as-ascii", 0, NULL, 'D'},
+        {"tag-stack-dump", 0, NULL, 't'},
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
@@ -933,6 +942,9 @@ int main(int argc, char **argv)
         case 'D':
             xenctx.decode_as_ascii = 1;
             break;
+        case 't':
+            xenctx.tag_stack_dump = 1;
+            break;
         case 'b':
             xenctx.bytes_per_line = strtol(optarg, NULL, 0);
             if ( xenctx.bytes_per_line < 4 ||
Signature · 1 line
1.8.4
Reviewed-by on v4 6/15
#16 lore raw

Re: [PATCH v4 06/15] xenctx: Add command line option -t (--tag-stack-dump)

Quoted 11 lines · Don Slutz

If specified, add stack address to dump.

Here is an example:

Stack:
ffffffff803ddf90: ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800
ffffffff803ddfb0: 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c
ffffffff803ddfd0: 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000
ffffffff803ddff0: 0000000000000000 0000000000000000
Quoted 63 lines
---
  tools/xentrace/xenctx.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +13 -1
index 850e091..9808e55 100644
@@ -39,6 +39,7 @@ static struct xenctx {
      int bytes_per_line;
      int lines;
      int decode_as_ascii;
+    int tag_stack_dump;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -684,6 +685,11 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
              int j = 0;
              int k;
 
+            if ( xenctx.tag_stack_dump )
+            {
+                print_stack_word(stack, width);
+                printf(":");
+            }
              while ( stack < stack_limit &&
                      stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
              {
@@ -885,13 +891,15 @@ static void usage(void)
      printf("                     change the number of lines output for Stack.\n");
      printf("  -D, --decode-as-ascii\n");
      printf("                     add a decode of Stack dump as ascii.\n");
+    printf("  -t, --tag-stack-dump\n");
+    printf("                     add address on each line of Stack dump.\n");
  }
 
  int main(int argc, char **argv)
  {
      int ch;
      int ret;
-    static const char *sopts = "fs:hak:SCmb:l:D";
+    static const char *sopts = "fs:hak:SCmb:l:Dt";
      static const struct option lopts[] = {
          {"stack-trace", 0, NULL, 'S'},
          {"symbol-table", 1, NULL, 's'},
@@ -899,6 +907,7 @@ int main(int argc, char **argv)
          {"kernel-start", 1, NULL, 'k'},
          {"multiple-pages", 0, NULL, 'm'},
          {"decode-as-ascii", 0, NULL, 'D'},
+        {"tag-stack-dump", 0, NULL, 't'},
          {"bytes-per-line", 1, NULL, 'b'},
          {"lines", 1, NULL, 'l'},
          {"all", 0, NULL, 'a'},
@@ -933,6 +942,9 @@ int main(int argc, char **argv)
          case 'D':
              xenctx.decode_as_ascii = 1;
              break;
+        case 't':
+            xenctx.tag_stack_dump = 1;
+            break;
          case 'b':
              xenctx.bytes_per_line = strtol(optarg, NULL, 0);
              if ( xenctx.bytes_per_line < 4 ||
author
#17 lore raw

PATCH v4 7/15 xenctx: Change print_symbol to do the space before.

In reply to Don Slutz

From: Don Slutz <[email protected]>

This stops the output of an extra space at the end of the line.

---
 tools/xentrace/xenctx.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
tools/xentrace/xenctx.c +10 -10
index 9808e55..9816300 100644
@@ -166,9 +166,9 @@ static void print_symbol(guest_word_t addr)
         return;
 
     if (addr==s->address)
-        printf("%s ", s->name);
+        printf(" %s", s->name);
     else
-        printf("%s+%#x ", s->name, (unsigned int)(addr - s->address));
+        printf(" %s+%#x", s->name, (unsigned int)(addr - s->address));
 }
 
 static void read_symbol_table(const char *symtab)
@@ -307,7 +307,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);
+    printf("cs:eip: %04x:%08x", regs->cs, regs->eip);
     print_symbol(regs->eip);
     print_flags(regs->eflags);
     printf("ss:esp: %04x:%08x\n", regs->ss, regs->esp);
@@ -336,7 +336,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);
+    printf("cs:eip: %04x:%08x", regs->cs, (uint32_t)regs->eip);
     print_symbol((uint32_t)regs->eip);
     print_flags((uint32_t)regs->eflags);
     printf("ss:esp: %04x:%08x\n", regs->ss, (uint32_t)regs->esp);
@@ -365,7 +365,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);
+    printf("rip: %016"PRIx64, regs->rip);
     print_symbol(regs->rip);
     print_flags(regs->rflags);
     printf("rsp: %016"PRIx64"\n", regs->rsp);
@@ -463,7 +463,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);
+    printf("PC:       %08"PRIx32, regs->pc32);
     print_symbol(regs->pc32);
     printf("\n");
     printf("CPSR:     %08"PRIx32"\n", regs->cpsr);
@@ -515,7 +515,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);
+    printf("PC:       %016"PRIx64, regs->pc64);
     print_symbol(regs->pc64);
     printf("\n");
 
@@ -734,7 +734,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Call Trace:\n");
     printf("%c [<", xenctx.stack_trace ? '*' : ' ');
     print_stack_word(instr_pointer(ctx), width);
-    printf(">] ");
+    printf(">]");
 
     print_symbol(instr_pointer(ctx));
     printf(" <--\n");
@@ -774,7 +774,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 word = read_stack_word(p, width);
                 printf("%c [<", xenctx.stack_trace ? '|' : ' ');
                 print_stack_word(word, width);
-                printf(">] ");
+                printf(">]");
                 print_symbol(word);
                 printf("\n");
                 stack += width;
@@ -790,7 +790,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
             if (is_kernel_text(word)) {
                 printf("  [<");
                 print_stack_word(word, width);
-                printf(">] ");
+                printf(">]");
                 print_symbol(word);
                 printf("\n");
             } else if (xenctx.stack_trace) {
Signature · 1 line
1.8.4
Acked-by on v4 7/15
#18 lore raw

Re: [PATCH v4 07/15] xenctx: Change print_symbol to do the space before.

Quoted 7 lines · Don Slutz

From: Don Slutz <[email protected]>

This stops the output of an extra space at the end of the line.

Quoted 92 lines
---
  tools/xentrace/xenctx.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
tools/xentrace/xenctx.c +10 -10
index 9808e55..9816300 100644
@@ -166,9 +166,9 @@ static void print_symbol(guest_word_t addr)
          return;
 
      if (addr==s->address)
-        printf("%s ", s->name);
+        printf(" %s", s->name);
      else
-        printf("%s+%#x ", s->name, (unsigned int)(addr - s->address));
+        printf(" %s+%#x", s->name, (unsigned int)(addr - s->address));
  }
 
  static void read_symbol_table(const char *symtab)
@@ -307,7 +307,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);
+    printf("cs:eip: %04x:%08x", regs->cs, regs->eip);
      print_symbol(regs->eip);
      print_flags(regs->eflags);
      printf("ss:esp: %04x:%08x\n", regs->ss, regs->esp);
@@ -336,7 +336,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);
+    printf("cs:eip: %04x:%08x", regs->cs, (uint32_t)regs->eip);
      print_symbol((uint32_t)regs->eip);
      print_flags((uint32_t)regs->eflags);
      printf("ss:esp: %04x:%08x\n", regs->ss, (uint32_t)regs->esp);
@@ -365,7 +365,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);
+    printf("rip: %016"PRIx64, regs->rip);
      print_symbol(regs->rip);
      print_flags(regs->rflags);
      printf("rsp: %016"PRIx64"\n", regs->rsp);
@@ -463,7 +463,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);
+    printf("PC:       %08"PRIx32, regs->pc32);
      print_symbol(regs->pc32);
      printf("\n");
      printf("CPSR:     %08"PRIx32"\n", regs->cpsr);
@@ -515,7 +515,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);
+    printf("PC:       %016"PRIx64, regs->pc64);
      print_symbol(regs->pc64);
      printf("\n");
 
@@ -734,7 +734,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
          printf("Call Trace:\n");
      printf("%c [<", xenctx.stack_trace ? '*' : ' ');
      print_stack_word(instr_pointer(ctx), width);
-    printf(">] ");
+    printf(">]");
 
      print_symbol(instr_pointer(ctx));
      printf(" <--\n");
@@ -774,7 +774,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                  word = read_stack_word(p, width);
                  printf("%c [<", xenctx.stack_trace ? '|' : ' ');
                  print_stack_word(word, width);
-                printf(">] ");
+                printf(">]");
                  print_symbol(word);
                  printf("\n");
                  stack += width;
@@ -790,7 +790,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
              if (is_kernel_text(word)) {
                  printf("  [<");
                  print_stack_word(word, width);
-                printf(">] ");
+                printf(">]");
                  print_symbol(word);
                  printf("\n");
              } else if (xenctx.stack_trace) {
author
#19 lore raw

PATCH v4 8/15 xenctx: More info on failed to map page.

In reply to Don Slutz

From: Don Slutz <[email protected]>

Also output an extra new line since we may be in the middle of output.

---
 tools/xentrace/xenctx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xentrace/xenctx.c +1 -1
index 9816300..22a1704 100644
@@ -613,7 +613,7 @@ static void *map_page(vcpu_guest_context_any_t *ctx, int vcpu, guest_word_t virt
     mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid, XC_PAGE_SIZE, PROT_READ, mfn);
 
     if (mapped == NULL) {
-        fprintf(stderr, "failed to map page.\n");
+        fprintf(stderr, "\nfailed to map page for "FMT_32B_WORD".\n", virt);
         return NULL;
     }
 
Signature · 1 line
1.8.4
Acked-by on v4 8/15
#20 lore raw

Re: [PATCH v4 08/15] xenctx: More info on failed to map page.

Quoted 6 lines · Don Slutz

From: Don Slutz <[email protected]>

Also output an extra new line since we may be in the middle of output.

Quoted 17 lines
---
  tools/xentrace/xenctx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/xentrace/xenctx.c +1 -1
index 9816300..22a1704 100644
@@ -613,7 +613,7 @@ static void *map_page(vcpu_guest_context_any_t *ctx, int vcpu, guest_word_t virt
      mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid, XC_PAGE_SIZE, PROT_READ, mfn);
 
      if (mapped == NULL) {
-        fprintf(stderr, "failed to map page.\n");
+        fprintf(stderr, "\nfailed to map page for "FMT_32B_WORD".\n", virt);
          return NULL;
      }
 
author
#21 lore raw

PATCH v4 9/15 xenctx: Add command line option -T (--tag-call-trace)

In reply to Don Slutz

If specified, add stack addr to call trace.

Here is an example:

Call Trace:
                   [<ffffffff8006b2b0>] default_idle+0x29 <--
ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f

and

Stack Trace:
* [<ffffffff8006b2b0>] default_idle+0x29 <--

ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddf98:    0000000000200800
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfa8:    0000000000086800
ffffffff803ddfb0:    0000000000000000
ffffffff803ddfb8:    ffffffff80430720
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f
ffffffff803ddfc8:    80008e000010019c
ffffffff803ddfd0:    00000000ffffffff
ffffffff803ddfd8:    0000000000000000
ffffffff803ddfe0:    0000000000000000
ffffffff803ddfe8:    0000000000200000
ffffffff803ddff0:    0000000000000000
ffffffff803ddff8:    0000000000000000
---
 tools/xentrace/xenctx.c | 53 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 7 deletions(-)
tools/xentrace/xenctx.c +46 -7
index 22a1704..e5c45df 100644
@@ -40,6 +40,7 @@ static struct xenctx {
     int lines;
     int decode_as_ascii;
     int tag_stack_dump;
+    int tag_call_trace;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
@@ -732,6 +733,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Stack Trace:\n");
     else
         printf("Call Trace:\n");
+    if ( xenctx.tag_call_trace )
+        printf(" %*s", width*2, "");
     printf("%c [<", xenctx.stack_trace ? '*' : ' ');
     print_stack_word(instr_pointer(ctx), width);
     printf(">]");
@@ -747,9 +750,15 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                     p = map_page(ctx, vcpu, stack);
                     if (!p)
                         return -1;
-                    printf("|   ");
+                    if ( xenctx.tag_call_trace )
+                    {
+                        print_stack_word(stack, width);
+                        printf(": |   ");
+                    } else {
+                        printf("|   ");
+                    }
                     print_stack_word(read_stack_word(p, width), width);
-                    printf("   \n");
+                    printf("\n");
                     stack += width;
                 }
             } else {
@@ -761,7 +770,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 return -1;
             frame = read_stack_word(p, width);
             if (xenctx.stack_trace) {
-                printf("|-- ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": |-- ");
+                } else {
+                    printf("|-- ");
+                }
                 print_stack_word(read_stack_word(p, width), width);
                 printf("\n");
             }
@@ -772,7 +787,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 if (!p)
                     return -1;
                 word = read_stack_word(p, width);
-                printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": %c [<", xenctx.stack_trace ? '|' : ' ');
+                } else {
+                    printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                }
                 print_stack_word(word, width);
                 printf(">]");
                 print_symbol(word);
@@ -788,13 +809,25 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 return -1;
             word = read_stack_word(p, width);
             if (is_kernel_text(word)) {
-                printf("  [<");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":  [<");
+                } else {
+                    printf("  [<");
+                }
                 print_stack_word(word, width);
                 printf(">]");
                 print_symbol(word);
                 printf("\n");
             } else if (xenctx.stack_trace) {
-                printf("    ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":    ");
+                } else {
+                    printf("    ");
+                }
                 print_stack_word(word, width);
                 printf("\n");
             }
@@ -893,13 +926,15 @@ static void usage(void)
     printf("                     add a decode of Stack dump as ascii.\n");
     printf("  -t, --tag-stack-dump\n");
     printf("                     add address on each line of Stack dump.\n");
+    printf("  -T, --tag-call-trace\n");
+    printf("                     add address on each line of Call trace.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCmb:l:Dt";
+    static const char *sopts = "fs:hak:SCmb:l:DtT";
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
@@ -908,6 +943,7 @@ int main(int argc, char **argv)
         {"multiple-pages", 0, NULL, 'm'},
         {"decode-as-ascii", 0, NULL, 'D'},
         {"tag-stack-dump", 0, NULL, 't'},
+        {"tag-call-trace", 0, NULL, 'T'},
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
@@ -945,6 +981,9 @@ int main(int argc, char **argv)
         case 't':
             xenctx.tag_stack_dump = 1;
             break;
+        case 'T':
+            xenctx.tag_call_trace = 1;
+            break;
         case 'b':
             xenctx.bytes_per_line = strtol(optarg, NULL, 0);
             if ( xenctx.bytes_per_line < 4 ||
Signature · 1 line
1.8.4
#22 lore raw

Re: [PATCH v4 09/15] xenctx: Add command line option -T (--tag-call-trace)

Quoted 132 lines · Don Slutz

If specified, add stack addr to call trace.

Here is an example:

Call Trace:
                    [<ffffffff8006b2b0>] default_idle+0x29 <--
ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f

and

Stack Trace:
* [<ffffffff8006b2b0>] default_idle+0x29 <--

ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddf98:    0000000000200800
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfa8:    0000000000086800
ffffffff803ddfb0:    0000000000000000
ffffffff803ddfb8:    ffffffff80430720
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f
ffffffff803ddfc8:    80008e000010019c
ffffffff803ddfd0:    00000000ffffffff
ffffffff803ddfd8:    0000000000000000
ffffffff803ddfe0:    0000000000000000
ffffffff803ddfe8:    0000000000200000
ffffffff803ddff0:    0000000000000000
ffffffff803ddff8:    0000000000000000
---
  tools/xentrace/xenctx.c | 53 ++++++++++++++++++++++++++++++++++++++++++-------
  1 file changed, 46 insertions(+), 7 deletions(-)
tools/xentrace/xenctx.c +39 -6
index 22a1704..e5c45df 100644
@@ -40,6 +40,7 @@ static struct xenctx {
      int lines;
      int decode_as_ascii;
      int tag_stack_dump;
+    int tag_call_trace;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -732,6 +733,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
          printf("Stack Trace:\n");
      else
          printf("Call Trace:\n");
+    if ( xenctx.tag_call_trace )
+        printf(" %*s", width*2, "");
      printf("%c [<", xenctx.stack_trace ? '*' : ' ');
      print_stack_word(instr_pointer(ctx), width);
      printf(">]");
@@ -747,9 +750,15 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                      p = map_page(ctx, vcpu, stack);
                      if (!p)
                          return -1;
-                    printf("|   ");
+                    if ( xenctx.tag_call_trace )
+                    {
+                        print_stack_word(stack, width);
+                        printf(": |   ");
+                    } else {
+                        printf("|   ");
+                    }
                      print_stack_word(read_stack_word(p, width), width);
-                    printf("   \n");
+                    printf("\n");
                      stack += width;
                  }
              } else {
@@ -761,7 +770,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                  return -1;
              frame = read_stack_word(p, width);
              if (xenctx.stack_trace) {
-                printf("|-- ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": |-- ");
+                } else {
+                    printf("|-- ");
+                }
                  print_stack_word(read_stack_word(p, width), width);
                  printf("\n");
              }
@@ -772,7 +787,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                  if (!p)
                      return -1;
                  word = read_stack_word(p, width);
-                printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": %c [<", xenctx.stack_trace ? '|' : ' ');
+                } else {
+                    printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                }
                  print_stack_word(word, width);
                  printf(">]");
                  print_symbol(word);
@@ -788,13 +809,25 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                  return -1;
              word = read_stack_word(p, width);
              if (is_kernel_text(word)) {
-                printf("  [<");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":  [<");
+                } else {
+                    printf("  [<");
+                }
                  print_stack_word(word, width);
                  printf(">]");
                  print_symbol(word);
                  printf("\n");
              } else if (xenctx.stack_trace) {
-                printf("    ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":    ");
+                } else {
+                    printf("    ");
+                }
                  print_stack_word(word, width);
                  printf("\n");
              }

tools/xentrace/xenctx.c static void usage(void) · line 930

Quoted 5 lines
tools/xentrace/xenctx.c +2 -0
@@ -893,13 +926,15 @@ static void usage(void)
      printf("                     add a decode of Stack dump as ascii.\n");
      printf("  -t, --tag-stack-dump\n");
      printf("                     add address on each line of Stack dump.\n");
+    printf("  -T, --tag-call-trace\n");
+    printf("                     add address on each line of Call trace.\n");

Since this happens for either a call trace or a stack trace, would it make more sense to make the long version "--tag-trace", and the description say something like "add address on each line of the call or stack trace"?

-George

author
#23 lore raw

Re: [PATCH v4 09/15] xenctx: Add command line option -T (--tag-call-trace)

Quoted 142 lines · George Dunlap
Quoted 141 lines · Don Slutz

If specified, add stack addr to call trace.

Here is an example:

Call Trace:
                    [<ffffffff8006b2b0>] default_idle+0x29 <--
ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f

and

Stack Trace:
* [<ffffffff8006b2b0>] default_idle+0x29 <--

ffffffff803ddf90:  [<ffffffff80048d19>] cpu_idle+0x95
ffffffff803ddf98:    0000000000200800
ffffffff803ddfa0:  [<ffffffff803e7801>] start_kernel+0x220
ffffffff803ddfa8:    0000000000086800
ffffffff803ddfb0:    0000000000000000
ffffffff803ddfb8:    ffffffff80430720
ffffffff803ddfc0:  [<ffffffff803e722f>] x86_64_start_kernel+0x22f
ffffffff803ddfc8:    80008e000010019c
ffffffff803ddfd0:    00000000ffffffff
ffffffff803ddfd8:    0000000000000000
ffffffff803ddfe0:    0000000000000000
ffffffff803ddfe8:    0000000000200000
ffffffff803ddff0:    0000000000000000
ffffffff803ddff8:    0000000000000000
---
  tools/xentrace/xenctx.c | 53 
++++++++++++++++++++++++++++++++++++++++++-------
  1 file changed, 46 insertions(+), 7 deletions(-)
tools/xentrace/xenctx.c +3 -0
index 22a1704..e5c45df 100644
@@ -40,6 +40,7 @@ static struct xenctx {
      int lines;
      int decode_as_ascii;
      int tag_stack_dump;
+    int tag_call_trace;
      int all_vcpus;
      int self_paused;
      xc_dominfo_t dominfo;
@@ -732,6 +733,8 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
          printf("Stack Trace:\n");
      else
          printf("Call Trace:\n");
+    if ( xenctx.tag_call_trace )
+        printf(" %*s", width*2, "");
      printf("%c [<", xenctx.stack_trace ? '*' : ' ');
      print_stack_word(instr_pointer(ctx), width);
      printf(">]");
tools/xentrace/xenctx.c +8 -2
@@ -747,9 +750,15 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
                      p = map_page(ctx, vcpu, stack);
                      if (!p)
                          return -1;
-                    printf("|   ");
+                    if ( xenctx.tag_call_trace )
+                    {
+                        print_stack_word(stack, width);
+                        printf(": |   ");
+                    } else {
+                        printf("|   ");
+                    }
                      print_stack_word(read_stack_word(p, width), 
 width);
-                    printf("   \n");
+                    printf("\n");
                      stack += width;
                  }
              } else {
tools/xentrace/xenctx.c +7 -1
@@ -761,7 +770,13 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
                  return -1;
              frame = read_stack_word(p, width);
              if (xenctx.stack_trace) {
-                printf("|-- ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": |-- ");
+                } else {
+                    printf("|-- ");
+                }
                  print_stack_word(read_stack_word(p, width), width);
                  printf("\n");
              }
tools/xentrace/xenctx.c +7 -1
@@ -772,7 +787,13 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
                  if (!p)
                      return -1;
                  word = read_stack_word(p, width);
-                printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(": %c [<", xenctx.stack_trace ? '|' : ' ');
+                } else {
+                    printf("%c [<", xenctx.stack_trace ? '|' : ' ');
+                }
                  print_stack_word(word, width);
                  printf(">]");
                  print_symbol(word);
tools/xentrace/xenctx.c +14 -2
@@ -788,13 +809,25 @@ static int print_stack(vcpu_guest_context_any_t 
 *ctx, int vcpu, int width)
                  return -1;
              word = read_stack_word(p, width);
              if (is_kernel_text(word)) {
-                printf("  [<");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":  [<");
+                } else {
+                    printf("  [<");
+                }
                  print_stack_word(word, width);
                  printf(">]");
                  print_symbol(word);
                  printf("\n");
              } else if (xenctx.stack_trace) {
-                printf("    ");
+                if ( xenctx.tag_call_trace )
+                {
+                    print_stack_word(stack, width);
+                    printf(":    ");
+                } else {
+                    printf("    ");
+                }
                  print_stack_word(word, width);
                  printf("\n");
              }
tools/xentrace/xenctx.c +0 -0
@@ -893,13 +926,15 @@ static void usage(void)
      printf("                     add a decode of Stack dump as 
 ascii.\n");
Quoted 9 lines

tools/xentrace/xenctx.c static void usage(void) · line 933

Quoted 6 lines
tools/xentrace/xenctx.c +2 -0
      printf("  -t, --tag-stack-dump\n");
      printf("                     add address on each line of Stack 
 dump.\n");
+    printf("  -T, --tag-call-trace\n");
+    printf("                     add address on each line of Call 
 trace.\n");

Since this happens for either a call trace or a stack trace, would it make more sense to make the long version "--tag-trace", and the description say something like "add address on each line of the call or stack trace"?

I will change to this.

-Don Slutz

Quoted 2 lines

-George

author
#24 lore raw

PATCH v4 10/15 xenctx: Add -M <maddr> option to dump memory at maddr.

In reply to Don Slutz

Currently not supported on ARM.

New routine read_mem_word() will correctly read a word that crosses a page boundary. It will not fault if the 2nd page can not be mapped.

Here is an example:

Memory (address ffffffff803ddf90):
ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000 0000000000000000 0000000000000000 0000000000000000 00cf9b000000ffff 00af9b000000ffff 00cf93000000ffff 00cffb000000ffff 00cff3000000ffff

---
v4 Changed from -m to -M

 tools/xentrace/xenctx.c | 168 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 150 insertions(+), 18 deletions(-)
tools/xentrace/xenctx.c +150 -18
index e5c45df..e7d490e 100644
@@ -29,23 +29,6 @@
 #include <xen/foreign/x86_64.h>
 #include <xen/hvm/save.h>
 
-static struct xenctx {
-    xc_interface *xc_handle;
-    int domid;
-    int frame_ptrs;
-    int stack_trace;
-    int disp_all;
-    int multiple_pages;
-    int bytes_per_line;
-    int lines;
-    int decode_as_ascii;
-    int tag_stack_dump;
-    int tag_call_trace;
-    int all_vcpus;
-    int self_paused;
-    xc_dominfo_t dominfo;
-} xenctx;
-
 #if defined (__i386__) || defined (__x86_64__)
 typedef unsigned long long guest_word_t;
 #define FMT_32B_WORD "%08llx"
@@ -69,6 +52,27 @@ typedef uint64_t guest_word_t;
 
 #define MAX_BYTES_PER_LINE 128
 
+static struct xenctx {
+    xc_interface *xc_handle;
+    int domid;
+    int frame_ptrs;
+    int stack_trace;
+    int disp_all;
+    int multiple_pages;
+    int bytes_per_line;
+    int lines;
+    int decode_as_ascii;
+    int tag_stack_dump;
+    int tag_call_trace;
+    int all_vcpus;
+#ifndef NO_TRANSLATION
+    guest_word_t mem_addr;
+    int do_memory;
+#endif
+    int self_paused;
+    xc_dominfo_t dominfo;
+} xenctx;
+
 struct symbol {
     guest_word_t address;
     char *name;
@@ -630,6 +634,37 @@ static guest_word_t read_stack_word(guest_word_t *src, int width)
     return word;
 }
 
+#ifndef NO_TRANSLATION
+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;
+    }
+}
+#endif
+
 static void print_stack_word(guest_word_t word, int width)
 {
     if (width == 4)
@@ -638,6 +673,67 @@ static void print_stack_word(guest_word_t word, int width)
         printf(FMT_64B_WORD, word);
 }
 
+#ifndef NO_TRANSLATION
+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[MAX_BYTES_PER_LINE/4];
+    int i;
+
+    instr_start = mem_addr;
+    instr = mem_addr;
+    printf("Memory (address ");
+    print_stack_word(instr, width);
+    printf("):\n");
+    for (i = 1; i < xenctx.lines + 1; i++)
+    {
+        int j = 0;
+        int k;
+
+        if ( xenctx.tag_stack_dump )
+        {
+            print_stack_word(instr, width);
+            printf(":");
+        }
+        while ( instr < instr_start + i * xenctx.bytes_per_line )
+        {
+            void *p = map_page(ctx, vcpu, instr);
+            if ( !p )
+                return;
+            word = read_mem_word(ctx, vcpu, instr, width);
+            if ( xenctx.decode_as_ascii )
+                ascii[j++] = word;
+            printf(" ");
+            print_stack_word(word, width);
+            instr += width;
+        }
+        printf("  ");
+        if ( xenctx.decode_as_ascii )
+        {
+            for (k = j; k < xenctx.bytes_per_line / width; k++)
+                printf(" %*s", width*2, "");
+            for (k = 0; k < j; k++)
+            {
+                int l;
+                unsigned char *bytep = (unsigned char*)&ascii[k];
+
+                for (l = 0; l < width; l++)
+                {
+                    if ( (*bytep < 127) && (*bytep >= 32) )
+                        printf("%c", *bytep);
+                    else
+                        printf(".");
+                    bytep++;
+                }
+            }
+        }
+        printf("\n");
+    }
+}
+#endif
+
 static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
 {
     guest_word_t instr;
@@ -874,6 +970,13 @@ static void dump_ctx(int vcpu)
     }
 #endif
 
+#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        print_mem(&ctx, vcpu, guest_word_size, xenctx.mem_addr);
+        return;
+    }
+#endif
     print_ctx(&ctx);
 #ifndef NO_TRANSLATION
     if (print_code(&ctx, vcpu))
@@ -928,13 +1031,21 @@ static void usage(void)
     printf("                     add address on each line of Stack dump.\n");
     printf("  -T, --tag-call-trace\n");
     printf("                     add address on each line of Call trace.\n");
+#ifndef NO_TRANSLATION
+    printf("  -M maddr, --memory=maddr\n");
+    printf("                     dump memory at maddr.\n");
+#endif
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
+#ifndef NO_TRANSLATION
+    static const char *sopts = "fs:hak:SCmb:l:DtTM:";
+#else
     static const char *sopts = "fs:hak:SCmb:l:DtT";
+#endif
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
@@ -944,6 +1055,9 @@ int main(int argc, char **argv)
         {"decode-as-ascii", 0, NULL, 'D'},
         {"tag-stack-dump", 0, NULL, 't'},
         {"tag-call-trace", 0, NULL, 'T'},
+#ifndef NO_TRANSLATION
+        {"memory", 1, NULL, 'M'},
+#endif
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
@@ -954,6 +1068,7 @@ int main(int argc, char **argv)
     const char *symbol_table = NULL;
 
     int vcpu = 0;
+    int do_default = 1;
 
     xenctx.bytes_per_line = 32;
     xenctx.lines = 5;
@@ -1007,10 +1122,18 @@ int main(int argc, char **argv)
             break;
         case 'C':
             xenctx.all_vcpus = 1;
+            do_default = 0;
             break;
         case 'k':
             kernel_start = strtoull(optarg, NULL, 0);
             break;
+#ifndef NO_TRANSLATION
+        case 'M':
+            xenctx.mem_addr = strtoull(optarg, NULL, 0);
+            xenctx.do_memory = 1;
+            do_default = 0;
+            break;
+#endif
         case 'h':
             usage();
             exit(-1);
@@ -1060,9 +1183,18 @@ int main(int argc, char **argv)
         xenctx.self_paused = 1;
     }
 
+#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        dump_ctx(vcpu);
+        if (xenctx.all_vcpus)
+            printf("\n");
+    }
+    xenctx.do_memory = 0;
+#endif
     if (xenctx.all_vcpus)
         dump_all_vcpus();
-    else
+    if ( do_default )
         dump_ctx(vcpu);
 
     if (xenctx.self_paused) {
Signature · 1 line
1.8.4
#25 lore raw

Re: [PATCH v4 10/15] xenctx: Add -M <maddr> option to dump memory at maddr.

Quoted 79 lines · Don Slutz

Currently not supported on ARM.

New routine read_mem_word() will correctly read a word that crosses a page boundary. It will not fault if the 2nd page can not be mapped.

Here is an example:

Memory (address ffffffff803ddf90):
ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000 0000000000000000 0000000000000000 0000000000000000 00cf9b000000ffff 00af9b000000ffff 00cf93000000ffff 00cffb000000ffff 00cff3000000ffff

---
v4 Changed from -m to -M

  tools/xentrace/xenctx.c | 168 ++++++++++++++++++++++++++++++++++++++++++------
  1 file changed, 150 insertions(+), 18 deletions(-)
tools/xentrace/xenctx.c +21 -17
index e5c45df..e7d490e 100644
@@ -29,23 +29,6 @@
  #include <xen/foreign/x86_64.h>
  #include <xen/hvm/save.h>
 
-static struct xenctx {
-    xc_interface *xc_handle;
-    int domid;
-    int frame_ptrs;
-    int stack_trace;
-    int disp_all;
-    int multiple_pages;
-    int bytes_per_line;
-    int lines;
-    int decode_as_ascii;
-    int tag_stack_dump;
-    int tag_call_trace;
-    int all_vcpus;
-    int self_paused;
-    xc_dominfo_t dominfo;
-} xenctx;
-
  #if defined (__i386__) || defined (__x86_64__)
  typedef unsigned long long guest_word_t;
  #define FMT_32B_WORD "%08llx"
@@ -69,6 +52,27 @@ typedef uint64_t guest_word_t;
 
  #define MAX_BYTES_PER_LINE 128
 
+static struct xenctx {
+    xc_interface *xc_handle;
+    int domid;
+    int frame_ptrs;
+    int stack_trace;
+    int disp_all;
+    int multiple_pages;
+    int bytes_per_line;
+    int lines;
+    int decode_as_ascii;
+    int tag_stack_dump;
+    int tag_call_trace;
+    int all_vcpus;
+#ifndef NO_TRANSLATION
+    guest_word_t mem_addr;
+    int do_memory;
+#endif
+    int self_paused;
+    xc_dominfo_t dominfo;
+} xenctx;
+
  struct symbol {
      guest_word_t address;
      char *name;

tools/xentrace/xenctx.c static guest_word_t read_stack_word(guest_word_t *src, int width) · line 637

Quoted 4 lines
tools/xentrace/xenctx.c +1 -0
@@ -630,6 +634,37 @@ static guest_word_t read_stack_word(guest_word_t *src, int width)
      return word;
  }
 
+#ifndef NO_TRANSLATION

You seem to be nesting "#ifndef NO_TRANSLATION" here -- there's already an #ifndef up above map_page.

Quoted 84 lines
tools/xentrace/xenctx.c +77 -0
+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;
+    }
+}
+#endif
+
  static void print_stack_word(guest_word_t word, int width)
  {
      if (width == 4)
@@ -638,6 +673,67 @@ static void print_stack_word(guest_word_t word, int width)
          printf(FMT_64B_WORD, word);
  }
 
+#ifndef NO_TRANSLATION
+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[MAX_BYTES_PER_LINE/4];
+    int i;
+
+    instr_start = mem_addr;
+    instr = mem_addr;
+    printf("Memory (address ");
+    print_stack_word(instr, width);
+    printf("):\n");
+    for (i = 1; i < xenctx.lines + 1; i++)
+    {
+        int j = 0;
+        int k;
+
+        if ( xenctx.tag_stack_dump )
+        {
+            print_stack_word(instr, width);
+            printf(":");
+        }
+        while ( instr < instr_start + i * xenctx.bytes_per_line )
+        {
+            void *p = map_page(ctx, vcpu, instr);
+            if ( !p )
+                return;
+            word = read_mem_word(ctx, vcpu, instr, width);
+            if ( xenctx.decode_as_ascii )
+                ascii[j++] = word;
+            printf(" ");
+            print_stack_word(word, width);
+            instr += width;
+        }
+        printf("  ");
+        if ( xenctx.decode_as_ascii )
+        {
+            for (k = j; k < xenctx.bytes_per_line / width; k++)
+                printf(" %*s", width*2, "");
+            for (k = 0; k < j; k++)
+            {
+                int l;
+                unsigned char *bytep = (unsigned char*)&ascii[k];
+
+                for (l = 0; l < width; l++)

tools/xentrace/xenctx.c static void print_stack_word(guest_word_t word, int width) · line 732

Quoted 10 lines
tools/xentrace/xenctx.c +10 -0
+                {
+                    if ( (*bytep < 127) && (*bytep >= 32) )
+                        printf("%c", *bytep);
+                    else
+                        printf(".");
+                    bytep++;
+                }
+            }
+        }
+        printf("\n");

This inner loop seems to be an exact copy of the code in print_stack -- wouldn't it make sense to make a generic "dump memory area" function, and have both print_mem and print_stack call it?

Quoted 88 lines
tools/xentrace/xenctx.c +35 -0
+    }
+}
+#endif
+
  static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
  {
      guest_word_t instr;
@@ -874,6 +970,13 @@ static void dump_ctx(int vcpu)
      }
  #endif
 
+#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        print_mem(&ctx, vcpu, guest_word_size, xenctx.mem_addr);
+        return;
+    }
+#endif
      print_ctx(&ctx);
  #ifndef NO_TRANSLATION
      if (print_code(&ctx, vcpu))
@@ -928,13 +1031,21 @@ static void usage(void)
      printf("                     add address on each line of Stack dump.\n");
      printf("  -T, --tag-call-trace\n");
      printf("                     add address on each line of Call trace.\n");
+#ifndef NO_TRANSLATION
+    printf("  -M maddr, --memory=maddr\n");
+    printf("                     dump memory at maddr.\n");
+#endif
  }
 
  int main(int argc, char **argv)
  {
      int ch;
      int ret;
+#ifndef NO_TRANSLATION
+    static const char *sopts = "fs:hak:SCmb:l:DtTM:";
+#else
      static const char *sopts = "fs:hak:SCmb:l:DtT";
+#endif
      static const struct option lopts[] = {
          {"stack-trace", 0, NULL, 'S'},
          {"symbol-table", 1, NULL, 's'},
@@ -944,6 +1055,9 @@ int main(int argc, char **argv)
          {"decode-as-ascii", 0, NULL, 'D'},
          {"tag-stack-dump", 0, NULL, 't'},
          {"tag-call-trace", 0, NULL, 'T'},
+#ifndef NO_TRANSLATION
+        {"memory", 1, NULL, 'M'},
+#endif
          {"bytes-per-line", 1, NULL, 'b'},
          {"lines", 1, NULL, 'l'},
          {"all", 0, NULL, 'a'},
@@ -954,6 +1068,7 @@ int main(int argc, char **argv)
      const char *symbol_table = NULL;
 
      int vcpu = 0;
+    int do_default = 1;
 
      xenctx.bytes_per_line = 32;
      xenctx.lines = 5;
@@ -1007,10 +1122,18 @@ int main(int argc, char **argv)
              break;
          case 'C':
              xenctx.all_vcpus = 1;
+            do_default = 0;
              break;
          case 'k':
              kernel_start = strtoull(optarg, NULL, 0);
              break;
+#ifndef NO_TRANSLATION
+        case 'M':
+            xenctx.mem_addr = strtoull(optarg, NULL, 0);
+            xenctx.do_memory = 1;
+            do_default = 0;
+            break;
+#endif
          case 'h':
              usage();
              exit(-1);
@@ -1060,9 +1183,18 @@ int main(int argc, char **argv)
          xenctx.self_paused = 1;
      }
 
+#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        dump_ctx(vcpu);

tools/xentrace/xenctx.c int main(int argc, char **argv) · line 1198

Quoted 10 lines
tools/xentrace/xenctx.c +6 -1
+        if (xenctx.all_vcpus)
+            printf("\n");
+    }
+    xenctx.do_memory = 0;
+#endif
      if (xenctx.all_vcpus)
          dump_all_vcpus();
-    else
+    if ( do_default )
          dump_ctx(vcpu);

So after this change, you can do "xenctx -M <addr>" and get memory, "xenctx -C" and get vcpu info, or "xenctx -M <addr> -C" and get both; but you can't get the ctx with both. Would it make sense to add an option to explicitly request dump_ctx(), so that you could have any combination? (And of course default to dump_ctx() if nothing is specified?)

-George

author
#26 lore raw

Re: [PATCH v4 10/15] xenctx: Add -M <maddr> option to dump memory at maddr.

Quoted 76 lines · George Dunlap
Quoted 75 lines · Don Slutz

Currently not supported on ARM.

New routine read_mem_word() will correctly read a word that crosses a page boundary. It will not fault if the 2nd page can not be mapped.

Here is an example:

Memory (address ffffffff803ddf90):
ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000 0000000000000000 0000000000000000 0000000000000000 00cf9b000000ffff 00af9b000000ffff 00cf93000000ffff 00cffb000000ffff 00cff3000000ffff

---
v4 Changed from -m to -M

  tools/xentrace/xenctx.c | 168 
++++++++++++++++++++++++++++++++++++++++++------
  1 file changed, 150 insertions(+), 18 deletions(-)
tools/xentrace/xenctx.c +20 -16
index e5c45df..e7d490e 100644
@@ -29,23 +29,6 @@
  #include <xen/foreign/x86_64.h>
  #include <xen/hvm/save.h>
  -static struct xenctx {
-    xc_interface *xc_handle;
-    int domid;
-    int frame_ptrs;
-    int stack_trace;
-    int disp_all;
-    int multiple_pages;
-    int bytes_per_line;
-    int lines;
-    int decode_as_ascii;
-    int tag_stack_dump;
-    int tag_call_trace;
-    int all_vcpus;
-    int self_paused;
-    xc_dominfo_t dominfo;
-} xenctx;
-
  #if defined (__i386__) || defined (__x86_64__)
  typedef unsigned long long guest_word_t;
  #define FMT_32B_WORD "%08llx"
@@ -69,6 +52,27 @@ typedef uint64_t guest_word_t;
    #define MAX_BYTES_PER_LINE 128
  +static struct xenctx {
+    xc_interface *xc_handle;
+    int domid;
+    int frame_ptrs;
+    int stack_trace;
+    int disp_all;
+    int multiple_pages;
+    int bytes_per_line;
+    int lines;
+    int decode_as_ascii;
+    int tag_stack_dump;
+    int tag_call_trace;
+    int all_vcpus;
+#ifndef NO_TRANSLATION
+    guest_word_t mem_addr;
+    int do_memory;
+#endif
+    int self_paused;
+    xc_dominfo_t dominfo;
+} xenctx;
+
  struct symbol {
      guest_word_t address;
Quoted 9 lines

tools/xentrace/xenctx.c static guest_word_t read_stack_word(guest_word_t · line 637

Quoted 6 lines
tools/xentrace/xenctx.c +0 -0
      char *name;
@@ -630,6 +634,37 @@ static guest_word_t read_stack_word(guest_word_t 
 *src, int width)
      return word;
  }
  +#ifndef NO_TRANSLATION

You seem to be nesting "#ifndef NO_TRANSLATION" here -- there's already an #ifndef up above map_page.

You are right, Will remove.

Quoted 92 lines
Quoted 92 lines
tools/xentrace/xenctx.c +82 -0
+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;
+    }
+}
+#endif
+
  static void print_stack_word(guest_word_t word, int width)
  {
      if (width == 4)
@@ -638,6 +673,67 @@ static void print_stack_word(guest_word_t word, 
 int width)
          printf(FMT_64B_WORD, word);
  }
  +#ifndef NO_TRANSLATION
+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[MAX_BYTES_PER_LINE/4];
+    int i;
+
+    instr_start = mem_addr;
+    instr = mem_addr;
+    printf("Memory (address ");
+    print_stack_word(instr, width);
+    printf("):\n");
+    for (i = 1; i < xenctx.lines + 1; i++)
+    {
+        int j = 0;
+        int k;
+
+        if ( xenctx.tag_stack_dump )
+        {
+            print_stack_word(instr, width);
+            printf(":");
+        }
+        while ( instr < instr_start + i * xenctx.bytes_per_line )
+        {
+            void *p = map_page(ctx, vcpu, instr);
+            if ( !p )
+                return;
+            word = read_mem_word(ctx, vcpu, instr, width);
+            if ( xenctx.decode_as_ascii )
+                ascii[j++] = word;
+            printf(" ");
+            print_stack_word(word, width);
+            instr += width;
+        }
+        printf("  ");
+        if ( xenctx.decode_as_ascii )
+        {
+            for (k = j; k < xenctx.bytes_per_line / width; k++)
+                printf(" %*s", width*2, "");
+            for (k = 0; k < j; k++)
+            {
+                int l;
+                unsigned char *bytep = (unsigned char*)&ascii[k];
+
+                for (l = 0; l < width; l++)
+                {
+                    if ( (*bytep < 127) && (*bytep >= 32) )
+                        printf("%c", *bytep);
+                    else
+                        printf(".");
+                    bytep++;
Quoted 9 lines

tools/xentrace/xenctx.c static void print_stack_word(guest_word_t word, int width) · line 732

Quoted 4 lines
tools/xentrace/xenctx.c +4 -0
+                }
+            }
+        }
+        printf("\n");

This inner loop seems to be an exact copy of the code in print_stack -- wouldn't it make sense to make a generic "dump memory area" function, and have both print_mem and print_stack call it?

They are not quite the same. print_stack also tests for stack limit. So yes, I will make a common routine that they both use.

Quoted 89 lines
Quoted 89 lines
tools/xentrace/xenctx.c +18 -0
+    }
+}
+#endif
+
  static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
  {
      guest_word_t instr;
@@ -874,6 +970,13 @@ static void dump_ctx(int vcpu)
      }
  #endif
  +#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        print_mem(&ctx, vcpu, guest_word_size, xenctx.mem_addr);
+        return;
+    }
+#endif
      print_ctx(&ctx);
  #ifndef NO_TRANSLATION
      if (print_code(&ctx, vcpu))
@@ -928,13 +1031,21 @@ static void usage(void)
      printf("                     add address on each line of Stack 
 dump.\n");
      printf("  -T, --tag-call-trace\n");
      printf("                     add address on each line of Call 
 trace.\n");
+#ifndef NO_TRANSLATION
+    printf("  -M maddr, --memory=maddr\n");
+    printf("                     dump memory at maddr.\n");
+#endif
  }
    int main(int argc, char **argv)
  {
      int ch;
      int ret;
+#ifndef NO_TRANSLATION
+    static const char *sopts = "fs:hak:SCmb:l:DtTM:";
+#else
      static const char *sopts = "fs:hak:SCmb:l:DtT";
+#endif
      static const struct option lopts[] = {
          {"stack-trace", 0, NULL, 'S'},
          {"symbol-table", 1, NULL, 's'},
tools/xentrace/xenctx.c +19 -0
@@ -944,6 +1055,9 @@ int main(int argc, char **argv)
          {"decode-as-ascii", 0, NULL, 'D'},
          {"tag-stack-dump", 0, NULL, 't'},
          {"tag-call-trace", 0, NULL, 'T'},
+#ifndef NO_TRANSLATION
+        {"memory", 1, NULL, 'M'},
+#endif
          {"bytes-per-line", 1, NULL, 'b'},
          {"lines", 1, NULL, 'l'},
          {"all", 0, NULL, 'a'},
@@ -954,6 +1068,7 @@ int main(int argc, char **argv)
      const char *symbol_table = NULL;
        int vcpu = 0;
+    int do_default = 1;
        xenctx.bytes_per_line = 32;
      xenctx.lines = 5;
@@ -1007,10 +1122,18 @@ int main(int argc, char **argv)
              break;
          case 'C':
              xenctx.all_vcpus = 1;
+            do_default = 0;
              break;
          case 'k':
              kernel_start = strtoull(optarg, NULL, 0);
              break;
+#ifndef NO_TRANSLATION
+        case 'M':
+            xenctx.mem_addr = strtoull(optarg, NULL, 0);
+            xenctx.do_memory = 1;
+            do_default = 0;
+            break;
+#endif
          case 'h':
              usage();
              exit(-1);
@@ -1060,9 +1183,18 @@ int main(int argc, char **argv)
          xenctx.self_paused = 1;
      }
  +#ifndef NO_TRANSLATION
+    if ( xenctx.do_memory )
+    {
+        dump_ctx(vcpu);
+        if (xenctx.all_vcpus)
+            printf("\n");
+    }
+    xenctx.do_memory = 0;
Quoted 9 lines

tools/xentrace/xenctx.c int main(int argc, char **argv) · line 1198

Quoted 6 lines
tools/xentrace/xenctx.c +2 -1
+#endif
      if (xenctx.all_vcpus)
          dump_all_vcpus();
-    else
+    if ( do_default )
          dump_ctx(vcpu);

So after this change, you can do "xenctx -M <addr>" and get memory, "xenctx -C" and get vcpu info, or "xenctx -M <addr> -C" and get both; but you can't get the ctx with both. Would it make sense to add an option to explicitly request dump_ctx(), so that you could have any combination? (And of course default to dump_ctx() if nothing is specified?)

Since -C dumps the ctx for each vcpu, outputting the ctx for vcpu 0 twice (or other specified vcpu) would be strange. It would be better to report an error if both -C and a vcpu was specified.

I can either add the check to this patch, or add another patch.

-Don Slutz

-Don Slutz

Quoted 1 line

-George

author
#27 lore raw

PATCH v4 11/15 xenctx: Add -d <daddr> option to dump memory at daddr as a stack.

In reply to Don Slutz

Also switch from read_stack_word to read_mem_word since the provided address may not be aligned.

---
 tools/xentrace/xenctx.c | 77 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 55 insertions(+), 22 deletions(-)
tools/xentrace/xenctx.c +55 -22
index e7d490e..59ffb22 100644
@@ -67,7 +67,9 @@ static struct xenctx {
     int all_vcpus;
 #ifndef NO_TRANSLATION
     guest_word_t mem_addr;
+    guest_word_t stk_addr;
     int do_memory;
+    int do_stack;
 #endif
     int self_paused;
     xc_dominfo_t dominfo;
@@ -751,15 +753,13 @@ static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
         else
             printf("%02x ", *c);
     }
-    printf("\n");
-
-    printf("\n");
+    printf("\n\n\n");
     return 0;
 }
 
-static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
+static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width, guest_word_t stk_addr_start)
 {
-    guest_word_t stack = stack_pointer(ctx);
+    guest_word_t stack = stk_addr_start;
     guest_word_t stack_limit;
     guest_word_t frame;
     guest_word_t word;
@@ -769,11 +769,10 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
 
     if ( width )
         xenctx.bytes_per_line = ((xenctx.bytes_per_line + width - 1) / width) * width;
-    stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
+    stack_limit = ((stack + XC_PAGE_SIZE)
                    & ~((guest_word_t) XC_PAGE_SIZE - 1));
     if ( xenctx.multiple_pages > 1 )
         stack_limit += (xenctx.multiple_pages - 1) * XC_PAGE_SIZE;
-    printf("\n");
     if ( xenctx.lines )
     {
         printf("Stack:\n");
@@ -788,12 +787,12 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 printf(":");
             }
             while ( stack < stack_limit &&
-                    stack < stack_pointer(ctx) + i * xenctx.bytes_per_line )
+                    stack < stk_addr_start + i * xenctx.bytes_per_line )
             {
                 p = map_page(ctx, vcpu, stack);
                 if ( !p )
                     return -1;
-                word = read_stack_word(p, width);
+                word = read_mem_word(ctx, vcpu, stack, width);
                 if ( xenctx.decode_as_ascii )
                     ascii[j++] = word;
                 printf(" ");
@@ -829,14 +828,17 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Stack Trace:\n");
     else
         printf("Call Trace:\n");
-    if ( xenctx.tag_call_trace )
-        printf(" %*s", width*2, "");
-    printf("%c [<", xenctx.stack_trace ? '*' : ' ');
-    print_stack_word(instr_pointer(ctx), width);
-    printf(">]");
-
-    print_symbol(instr_pointer(ctx));
-    printf(" <--\n");
+    if ( !xenctx.do_stack )
+    {
+        if ( xenctx.tag_call_trace )
+            printf(" %*s", width*2, "");
+        printf("%c [<", xenctx.stack_trace ? '*' : ' ');
+        print_stack_word(instr_pointer(ctx), width);
+        printf(">]");
+
+        print_symbol(instr_pointer(ctx));
+        printf(" <--\n");
+    }
     if (xenctx.frame_ptrs) {
         stack = stack_pointer(ctx);
         frame = frame_pointer(ctx);
@@ -898,12 +900,12 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
             }
         }
     } else {
-        stack = stack_pointer(ctx);
+        stack = stk_addr_start;
         while(stack < stack_limit) {
             p = map_page(ctx, vcpu, stack);
             if (!p)
                 return -1;
-            word = read_stack_word(p, width);
+            word = read_mem_word(ctx, vcpu, stack, width);
             if (is_kernel_text(word)) {
                 if ( xenctx.tag_call_trace )
                 {
@@ -976,13 +978,19 @@ static void dump_ctx(int vcpu)
         print_mem(&ctx, vcpu, guest_word_size, xenctx.mem_addr);
         return;
     }
+    if ( xenctx.do_stack )
+    {
+        print_stack(&ctx, vcpu, guest_word_size, xenctx.stk_addr);
+        return;
+    }
 #endif
     print_ctx(&ctx);
 #ifndef NO_TRANSLATION
     if (print_code(&ctx, vcpu))
         return;
     if (is_kernel_text(instr_pointer(&ctx)))
-        if (print_stack(&ctx, vcpu, guest_word_size))
+        if ( print_stack(&ctx, vcpu, guest_word_size,
+                         stack_pointer(&ctx)) )
             return;
 #endif
 }
@@ -1034,6 +1042,8 @@ static void usage(void)
 #ifndef NO_TRANSLATION
     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");
 #endif
 }
 
@@ -1042,7 +1052,7 @@ int main(int argc, char **argv)
     int ch;
     int ret;
 #ifndef NO_TRANSLATION
-    static const char *sopts = "fs:hak:SCmb:l:DtTM:";
+    static const char *sopts = "fs:hak:SCmb:l:DtTM:d:";
 #else
     static const char *sopts = "fs:hak:SCmb:l:DtT";
 #endif
@@ -1057,6 +1067,7 @@ int main(int argc, char **argv)
         {"tag-call-trace", 0, NULL, 'T'},
 #ifndef NO_TRANSLATION
         {"memory", 1, NULL, 'M'},
+        {"dump-as-stack", 1, NULL, 'd'},
 #endif
         {"bytes-per-line", 1, NULL, 'b'},
         {"lines", 1, NULL, 'l'},
@@ -1133,6 +1144,11 @@ int main(int argc, char **argv)
             xenctx.do_memory = 1;
             do_default = 0;
             break;
+        case 'd':
+            xenctx.stk_addr = strtoull(optarg, NULL, 0);
+            xenctx.do_stack = 1;
+            do_default = 0;
+            break;
 #endif
         case 'h':
             usage();
@@ -1150,6 +1166,16 @@ int main(int argc, char **argv)
         exit(-1);
     }
 
+#ifndef NO_TRANSLATION
+    if ( xenctx.frame_ptrs && xenctx.do_stack )
+    {
+        fprintf(stderr,
+                "%s both --frame-pointers and --dump-as-stack is not supported\n",
+                argv[0]);
+        exit(-1);
+    }
+#endif
+
     xenctx.domid = atoi(argv[0]);
     if (xenctx.domid==0) {
             fprintf(stderr, "cannot trace dom0\n");
@@ -1187,10 +1213,17 @@ int main(int argc, char **argv)
     if ( xenctx.do_memory )
     {
         dump_ctx(vcpu);
-        if (xenctx.all_vcpus)
+        if ( xenctx.do_stack || xenctx.all_vcpus )
             printf("\n");
     }
     xenctx.do_memory = 0;
+    if ( xenctx.do_stack )
+    {
+        dump_ctx(vcpu);
+        if ( xenctx.all_vcpus )
+            printf("\n");
+    }
+    xenctx.do_stack = 0;
 #endif
     if (xenctx.all_vcpus)
         dump_all_vcpus();
Signature · 1 line
1.8.4
author
#28 lore raw

PATCH v4 12/15 xenctx: change is_kernel_text() into kernel_addr().

In reply to Don Slutz

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.

---
 tools/xentrace/xenctx.c | 70 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 51 insertions(+), 19 deletions(-)
tools/xentrace/xenctx.c +51 -19
index 59ffb22..1316522 100644
@@ -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__) || defined (__arm__)
 unsigned long long kernel_start = 0xc0000000;
@@ -91,22 +102,37 @@ unsigned long long kernel_start = 0xffffffff80000000UL;
 unsigned long long kernel_start = 0xffffff8000000000UL;
 #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
@@ -160,11 +186,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);
@@ -244,6 +270,10 @@ static void read_symbol_table(const char *symtab)
             kernel_stext = address;
         else if (strcmp(p, "_etext") == 0)
             kernel_etext = address;
+        else if ( strcmp(p, "_text") == 0 )
+            kernel_text = address;
+        else if ( strcmp(p, "_end") == 0 )
+            kernel_end = address;
         else if (strcmp(p, "_sinittext") == 0)
             kernel_sinittext = address;
         else if (strcmp(p, "_einittext") == 0)
@@ -315,7 +345,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);
 
@@ -344,7 +374,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);
 
@@ -373,7 +403,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);
 
@@ -471,7 +501,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",
@@ -523,7 +553,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"\n", regs->x30);
@@ -836,7 +866,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) {
@@ -894,7 +924,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;
             }
@@ -906,7 +936,8 @@ 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);
@@ -916,7 +947,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 )
@@ -988,7 +1019,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;
@@ -1137,6 +1168,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':
Signature · 1 line
1.8.4
author
#29 lore raw

PATCH v4 13/15 xenctx: Add convert of more registers to symbols

In reply to Don Slutz

For example can change:
gs: 0000 @ ffffffff803ac000/0000000000000000
to
gs: 0000 @ ffffffff803ac000/0000000000000000 boot_cpu_pda/

---
 tools/xentrace/xenctx.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
tools/xentrace/xenctx.c +18 -6
index 1316522..10acfda 100644
@@ -333,10 +333,14 @@ static void print_special(void *regs, const char *name, unsigned int mask, int w
     printf("\n");
     for (i = 0; mask; mask >>= 1, ++i)
         if (mask & 1) {
-            if (width == 4)
-                printf("%s%u: %08"PRIx32"\n", name, i, ((uint32_t *) regs)[i]);
-            else
-                printf("%s%u: %08"PRIx64"\n", name, i, ((uint64_t *) regs)[i]);
+            if (width == 4) {
+                printf("%s%u: %08"PRIx32, name, i, ((uint32_t *) regs)[i]);
+                print_symbol(((uint32_t *) regs)[i], KERNEL_DATA_ADDR);
+            } else {
+                printf("%s%u: %016"PRIx64, name, i, ((uint64_t *) regs)[i]);
+                print_symbol(((uint64_t *) regs)[i], KERNEL_DATA_ADDR);
+            }
+            printf("\n");
         }
 }
 
@@ -432,9 +436,17 @@ static void print_ctx_64(vcpu_guest_context_x86_64_t *ctx)
     printf(" ds: %04x\t", regs->ds);
     printf(" es: %04x\n", regs->es);
 
-    printf(" fs: %04x @ %016"PRIx64"\n", regs->fs, ctx->fs_base);
-    printf(" gs: %04x @ %016"PRIx64"/%016"PRIx64"\n", regs->gs,
+    printf(" fs: %04x @ %016"PRIx64, regs->fs, ctx->fs_base);
+    print_symbol(ctx->fs_base, KERNEL_DATA_ADDR);
+    printf("\n");
+    printf(" gs: %04x @ %016"PRIx64"/%016"PRIx64, regs->gs,
            ctx->gs_base_kernel, ctx->gs_base_user);
+    if (symbol_table) {
+        print_symbol(ctx->gs_base_kernel, KERNEL_DATA_ADDR);
+        printf("/");
+        print_symbol(ctx->gs_base_user, KERNEL_DATA_ADDR);
+    }
+    printf("\n");
 
     if (xenctx.disp_all) {
         print_special(ctx->ctrlreg, "cr", 0x1d, 8);
Signature · 1 line
1.8.4
#30 lore raw

Re: [PATCH v4 13/15] xenctx: Add convert of more registers to symbols

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Don Slutz
tools/xentrace/xenctx.c +0 -2
@@ -333,10 +333,14 @@ static void print_special(void *regs, const char *name, unsigned int mask, int w
     printf("\n");
     for (i = 0; mask; mask >>= 1, ++i)
         if (mask & 1) {
-            if (width == 4)
-                printf("%s%u: %08"PRIx32"\n", name, i, ((uint32_t *) regs)[i]);

tools/xentrace/xenctx.c static void print_special(void *regs, const char *name, unsigned int mask, int w · line 343

Quoted 10 lines
tools/xentrace/xenctx.c +8 -2
-            else
-                printf("%s%u: %08"PRIx64"\n", name, i, ((uint64_t *) regs)[i]);
+            if (width == 4) {
+                printf("%s%u: %08"PRIx32, name, i, ((uint32_t *) regs)[i]);
+                print_symbol(((uint32_t *) regs)[i], KERNEL_DATA_ADDR);
+            } else {
+                printf("%s%u: %016"PRIx64, name, i, ((uint64_t *) regs)[i]);
+                print_symbol(((uint64_t *) regs)[i], KERNEL_DATA_ADDR);
+            }
+            printf("\n");

I don't think this is reasonable for all special registers, and hence I think you ought to pass in a flag indicating whether the register is holding some sort of address (which may become further complicated if only part of a register forms an address, so maybe passing in a mask would be even better, with the mask being zero indicating that this isn't an address at all).

Jan

author
#31 lore raw

Re: [PATCH v4 13/15] xenctx: Add convert of more registers to symbols

Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Don Slutz
tools/xentrace/xenctx.c +6 -4
@@ -333,10 +333,14 @@ static void print_special(void *regs, const char *name, unsigned int mask, int w
      printf("\n");
      for (i = 0; mask; mask >>= 1, ++i)
          if (mask & 1) {
-            if (width == 4)
-                printf("%s%u: %08"PRIx32"\n", name, i, ((uint32_t *) regs)[i]);
-            else
-                printf("%s%u: %08"PRIx64"\n", name, i, ((uint64_t *) regs)[i]);
+            if (width == 4) {
+                printf("%s%u: %08"PRIx32, name, i, ((uint32_t *) regs)[i]);
+                print_symbol(((uint32_t *) regs)[i], KERNEL_DATA_ADDR);
+            } else {
+                printf("%s%u: %016"PRIx64, name, i, ((uint64_t *) regs)[i]);
+                print_symbol(((uint64_t *) regs)[i], KERNEL_DATA_ADDR);
Quoted 8 lines

tools/xentrace/xenctx.c static void print_special(void *regs, const char *name, unsigned int mask, int w · line 343

Quoted 2 lines
tools/xentrace/xenctx.c +2 -0
+            }
+            printf("\n");

I don't think this is reasonable for all special registers, and hence I think you ought to pass in a flag indicating whether the register is holding some sort of address (which may become further complicated if only part of a register forms an address, so maybe passing in a mask would be even better, with the mask being zero indicating that this isn't an address at all).

Ok, I think I get this, will rework.
-Don Slutz

Quoted 2 lines

Jan

author
#32 lore raw

PATCH v4 14/15 xenctx: Add output of vcpu value and state for --all-vcpus

In reply to Don Slutz

This makes it easier to know which vcpu the registers belong to and when not all vcpus are online, which vcpu it is.

---
 tools/xentrace/xenctx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +6 -1
index 10acfda..9335f2a 100644
@@ -1046,8 +1046,13 @@ static void dump_all_vcpus(void)
     {
         if ( xc_vcpu_getinfo(xenctx.xc_handle, xenctx.domid, vcpu, &vinfo) )
             continue;
-        if ( vinfo.online )
+        if ( vinfo.online ) {
+            printf("vcpu=%d online\n", vcpu);
             dump_ctx(vcpu);
+            printf("\n");
+        } else {
+            printf("vcpu=%d offline\n\n", vcpu);
+        }
     }
 }
 
Signature · 1 line
1.8.4
#33 lore raw

Re: [PATCH v4 14/15] xenctx: Add output of vcpu value and state for --all-vcpus

tools/xentrace/xenctx.c static void dump_all_vcpus(void) · line 1050

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Don Slutz
tools/xentrace/xenctx.c +2 -1
@@ -1046,8 +1046,13 @@ static void dump_all_vcpus(void)
     {
         if ( xc_vcpu_getinfo(xenctx.xc_handle, xenctx.domid, vcpu, &vinfo) )
             continue;
-        if ( vinfo.online )
+        if ( vinfo.online ) {
+            printf("vcpu=%d online\n", vcpu);

I'd drop the "=" here (and below), and omit the "online" (but keep the "offline" below), perhaps in favor of a ":".

Jan

author
#34 lore raw

Re: [PATCH v4 14/15] xenctx: Add output of vcpu value and state for --all-vcpus

Quoted 12 lines · Jan Beulich

tools/xentrace/xenctx.c static void dump_all_vcpus(void) · line 1050

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Don Slutz
tools/xentrace/xenctx.c +2 -1
@@ -1046,8 +1046,13 @@ static void dump_all_vcpus(void)
      {
          if ( xc_vcpu_getinfo(xenctx.xc_handle, xenctx.domid, vcpu, &vinfo) )
              continue;
-        if ( vinfo.online )
+        if ( vinfo.online ) {
+            printf("vcpu=%d online\n", vcpu);

I'd drop the "=" here (and below), and omit the "online" (but keep the "offline" below), perhaps in favor of a ":".

Will do.

-Don Slutz

Quoted 2 lines

Jan

author
#35 lore raw

PATCH v4 15/15 xenctx: Fix handling of !guest_protected_mode

In reply to Don Slutz

This includes that the stack pointer is valid.

---
 tools/xentrace/xenctx.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/xentrace/xenctx.c +15 -1
index 9335f2a..d0779b1 100644
@@ -477,8 +477,13 @@ static guest_word_t instr_pointer(vcpu_guest_context_any_t *ctx)
             r += ctx->x32.user_regs.cs << NONPROT_MODE_SEGMENT_SHIFT;
     }
     else
+    {
         r = ctx->x64.user_regs.rip;
 
+        if ( !guest_protected_mode )
+            r += ctx->x64.user_regs.cs << NONPROT_MODE_SEGMENT_SHIFT;
+    }
+
     return r;
 }
 
@@ -493,8 +498,13 @@ static guest_word_t stack_pointer(vcpu_guest_context_any_t *ctx)
             r += ctx->x32.user_regs.ss << NONPROT_MODE_SEGMENT_SHIFT;
     }
     else
+    {
         r = ctx->x64.user_regs.rsp;
 
+        if ( !guest_protected_mode )
+            r += ctx->x64.user_regs.ss << NONPROT_MODE_SEGMENT_SHIFT;
+    }
+
     return r;
 }
 
@@ -866,6 +876,9 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width, guest
         printf("\n");
     }
 
+    if ( !guest_protected_mode )
+        return 0;
+
     if(xenctx.stack_trace)
         printf("Stack Trace:\n");
     else
@@ -1031,7 +1044,8 @@ static void dump_ctx(int vcpu)
 #ifndef NO_TRANSLATION
     if (print_code(&ctx, vcpu))
         return;
-    if ( kernel_addr(instr_pointer(&ctx)) >= KERNEL_TEXT_ADDR )
+    if ( !guest_protected_mode ||
+         kernel_addr(instr_pointer(&ctx)) >= KERNEL_TEXT_ADDR )
         if ( print_stack(&ctx, vcpu, guest_word_size,
                          stack_pointer(&ctx)) )
             return;
Signature · 1 line
1.8.4