All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v9 00/18] xenctx: Many changes.
@ 2014-04-02 16:03 Don Slutz
  2014-04-02 16:03 ` [PATCH v9 01/18] xenctx: clean up usage output Don Slutz
                   ` (18 more replies)
  0 siblings, 19 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

Add more functionality to xenctx.

Fix some bugs.

Change from v8 to v9:

  Dropped:
    v8 #17 "xenctx: Allow output for offline vcpu when"
    v8 #20 "xenctx: Ensure errno is not zero on error in"

  Ian Campbell & George Dunlap
    #3 "xenctx: Add -n (--display-stack-pages) option to":
       Re-work commit message.


  Ian Campbell
    #4 "xenctx: Add command line options -b":
       Acked-by
       Drop extra if
    #5 "xenctx: Add command line option -D":
       Acked-by
    #9 "xenctx: Add output of stack address to Call and":
       Acked-by
    #10 "xenctx: Add -m (--memory) <maddr> option to dump":
       Acked-by
    #11 "xenctx: Add error output if --all-vcpus (-C) and":
       Acked-by
       Moved hunk from #12 that should have been here.
       Added : to error message
    #12 "xenctx: Add -d (--dump-as-stack) <daddr> option to":
       Acked-by
       Moved hunk to #11 that should have been here.
       Added : to error message
    #13 "xenctx: change is_kernel_text() into kernel_addr().":
      Revert to v5.
      Initalize kernel_end to a good value.
      Add __bss_stop to be same as _end.
      Changed -k to act like it's usage.
      Add check for kernel_start & kernel_end as last test.
    #14 "xenctx: Add conversion of more registers to symbols":
      Acked-by
      s/convert/conversion/ in $subject
    #17 "xenctx: Add 16 bit output":
      Adjust commit message.
      Change global guest_word_size to 2 if !guest_protected_mode
      Fix test for == 4 to != 8 where needed
    #18 "xenctx: Fix print_ctx_32on64's print_special call":
      Acked-by


Change from v7 to v8:

  Moved v5 #17 "xenctx: Fixup options checking"
  and renamed to
      #11 "xenctx: Add error output if --all-vcpus (-C) and":
          New commit message
          make the new copy const.

  Added:
    #18: "xenctx: Add 16 bit output"
  Bug fix add:
    #19: "xenctx: Fix print_ctx_32on64's print_special call."
    #20: "xenctx: Ensure errno is not zero on error in
           xc_translate_foreign_address()"

  Changed:
    #4 "xenctx: Add command line options -b":
       Commit message adjusted.
       More CODING_STYLE changes.
       INT_MAX was too big.
    #13 "xenctx: change is_kernel_text() into kernel_addr().":
        Added more to commit message.
        Added some basic linux kernel module reporting.
        Moved kernel_end into define tree in case no symbol found.
        At some point __bss_stop was added and _end was dropped. Both
        mean end of named kernel data.
    #17 "xenctx: Allow output for offline vcpu when":        
        Also change xc_translate_foreign_address() to work.


  Ian Campbell
    #1 "xenctx: clean up usage output":
       Acked-by
    #3 "xenctx: Add -n (--display-stack-pages) option to":
       Reworked comment.
       multiple_pages => nr_stack_pages
  me: Changed usage output.
  me: Added range checking of option.
    #5 "xenctx: Add command line option -D":
       Add "...exceeds 80 characters..." to commit message
    #6 "xenctx: Add command line option -t":
       Acked-by
       Add "...exceeds 80 characters..." to commit message
    #9 "xenctx: Add output of stack address to Call and"
       Was: "xenctx: Add command line option -T (--tag-trace)"
       Drop option.
       Add new routine: print_stack_addr
    #10 "xenctx: Add -m (--memory) <maddr> option to dump":
        Add "Moved xenctx because.." to commit message
        Changed init of sopts to only have one copy of common options.
        Make common code into routine,
  me: Fixed bug with extra set bits on small widths.
    #15 "xenctx: Add output of vcpu value and state for":
       Acked-by
  me: Removed extra {}
    #16 "xenctx: Fix handling of !guest_protected_mode":
        A little more in the commit message.

Change from v6 to v7:
  Jan Beulich:
    #13: "xenctx: Add convert of more registers to symbols":
      Move reg_is_addr_mask to an x86-specific section.

Change from v5 to v6:
  Jan Beulich:
    #13: "xenctx: Add convert of more registers to symbols":
      Move reg_is_addr_mask to a common static.

Change from v4 to v5:
  Jan Beulich:
    #13 "xenctx: Add convert of more registers to symbols":
       Add reg_is_addr_mask.
    #14 "xenctx: Add output of vcpu value and state for":
       Change vcpu=3 to vcpu3. Drop online.

  George Dunlap:
    #1 "xenctx: clean up usage output":
       Reviewed-by
    #2 "xenctx: Clean up stack trace when hypercall_page not":
       Acked-by
    #3 "xenctx: Add -n (--display-stack-pages) option to":
       Adjust option to -n, --display-stack-pages.  Adjust usage message.
    #4 "xenctx: Add command line options -b":
       Add defaults to disply. Accept MAX for -l.
    #5 "xenctx: Add command line option -D":
       Add comment, move printf.
    #6 "xenctx: Add command line option -t":
       Reviewed-by
    #7 "xenctx: Change print_symbol to do the space before.":
       Acked-by
    #8 "xenctx: More info on failed to map page.":
       Acked-by
    #9 "xenctx: Add command line option -T (--tag-trace)":
       Adjust option name, usage.
    #10 "xenctx: Add -m (--memory) <maddr> option to dump":
        Remove extra #ifndef.  Make common routine print_lines().

  Added
    #16 "xenctx: Allow output for offline vcpu when"
    #17 "xenctx: Fixup options checking."


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 (18):
  xenctx: clean up usage output
  xenctx: Clean up stack trace when hypercall_page not in symbol table
  xenctx: Add -n (--display-stack-pages) option to output larger stack
  xenctx: Add command line options -b (--bytes-per-line) and -l
    (--lines)
  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 output of stack address to Call and Stack Trace.
  xenctx: Add -m (--memory) <maddr> option to dump memory at maddr.
  xenctx: Add error output if --all-vcpus (-C) and [VCPU] are both
    specified.
  xenctx: Add -d (--dump-as-stack) <daddr> option to dump memory at
    daddr as a stack.
  xenctx: change is_kernel_text() into kernel_addr().
  xenctx: Add conversion of more registers to symbols
  xenctx: Add output of vcpu value and state for --all-vcpus
  xenctx: Fix handling of !guest_protected_mode
  xenctx: Add 16 bit output
  xenctx: Fix print_ctx_32on64's print_special call.

 tools/xentrace/xenctx.c | 570 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 473 insertions(+), 97 deletions(-)

-- 
1.8.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v9 01/18] xenctx: clean up usage output
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 02/18] xenctx: Clean up stack trace when hypercall_page not in symbol table Don Slutz
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

Fix usage formatting to be all the same.

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

Signed-off-by: Don Slutz <dslutz@verizon.com>
Reviewed-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 7275a00..97c6197 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -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)
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 02/18] xenctx: Clean up stack trace when hypercall_page not in symbol table
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
  2014-04-02 16:03 ` [PATCH v9 01/18] xenctx: clean up usage output Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 03/18] xenctx: Add -n (--display-stack-pages) option to output larger stack Don Slutz
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Jan Beulich

From: Don Slutz <Don@CloudSwitch.com>

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
---
 tools/xentrace/xenctx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 97c6197..42a47f3 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -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)
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 03/18] xenctx: Add -n (--display-stack-pages) option to output larger stack
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
  2014-04-02 16:03 ` [PATCH v9 01/18] xenctx: clean up usage output Don Slutz
  2014-04-02 16:03 ` [PATCH v9 02/18] xenctx: Clean up stack trace when hypercall_page not in symbol table Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 04/18] xenctx: Add command line options -b (--bytes-per-line) and -l (--lines) Don Slutz
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

Important: This is the stack size (also known as stack limit) to
display, not the configured stack size.

Note: use with caution (easy to get garbage).

Below is a pictures of a downwards growing configured 3 page stack,
and where the SP currently is.  Each box is a page.

+ pages                     -n 1    -n 2    -n 3

End of Memory
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
       |                  |
       +------------------+
...
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
MAX+3  |                  |
       +------------------+                   *
       |                  |                   |
       |                  |                   |
       |                  |                   |
       |                  |                   |
MAX+2  |                  |                   |
       +------------------+           *       |
       |                  |           |       |
       |                  |           |       |
       |                  |           |       |
       |                  |           |       |
MAX+1  |                  |           |       |
       +------------------+   *       |       |
       |                  |   |       |       |
SP --> |                  |   *       *       *
       |                  |
       |                  |
MAX    |                  |
       +------------------+
...
       +------------------+
       |                  |
       |                  |
       |                  |
       |                  |
0      |                  |
       +------------------+

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

At a different time, the SP may be in the 1st page and so "-n 3"
will display garbage.

For example:

$ xenctx -s /boot/System.map-2.6.32-279.2.1.el6.x86_64 3 1 -n 1
...
Call Trace:
                    [<ffffffff81346898>] io_serial_out+0x18 <--
ffff880032bb1310:   [<ffffffff81346f51>] serial8250_console_putchar+0x31
ffff880032bb1330:   [<ffffffff813428de>] uart_console_write+0x3e
ffff880032bb1338:   [<ffffffff8100bc0e>] apic_timer_interrupt+0xe
ffff880032bb1370:   [<ffffffff813472ad>] serial8250_console_write+0xbd
ffff880032bb13c0:   [<ffffffff8106b8f5>] __call_console_drivers+0x75
ffff880032bb13f0:   [<ffffffff8106b95a>] _call_console_drivers+0x4a
ffff880032bb1410:   [<ffffffff8106be6e>] release_console_sem+0x4e
ffff880032bb1450:   [<ffffffff8106c628>] vprintk+0x248
ffff880032bb14f0:   [<ffffffff814fd363>] printk+0x41


$ xenctx -s /boot/System.map-2.6.32-279.2.1.el6.x86_64 3 1 -n 2
...
Call Trace:
                    [<ffffffff81346898>] io_serial_out+0x18 <--
ffff880032bb1310:   [<ffffffff81346f51>] serial8250_console_putchar+0x31
ffff880032bb1330:   [<ffffffff813428de>] uart_console_write+0x3e
ffff880032bb1338:   [<ffffffff8100bc0e>] apic_timer_interrupt+0xe
ffff880032bb1370:   [<ffffffff813472ad>] serial8250_console_write+0xbd
ffff880032bb13c0:   [<ffffffff8106b8f5>] __call_console_drivers+0x75
ffff880032bb13f0:   [<ffffffff8106b95a>] _call_console_drivers+0x4a
ffff880032bb1410:   [<ffffffff8106be6e>] release_console_sem+0x4e
ffff880032bb1450:   [<ffffffff8106c628>] vprintk+0x248
ffff880032bb14f0:   [<ffffffff814fd363>] printk+0x41


$ xenctx -s /boot/System.map-2.6.32-279.2.1.el6.x86_64 3 1 -n 3
...
Call Trace:
                    [<ffffffff81346898>] io_serial_out+0x18 <--
ffff880032bb1310:   [<ffffffff81346f51>] serial8250_console_putchar+0x31
ffff880032bb1330:   [<ffffffff813428de>] uart_console_write+0x3e
ffff880032bb1338:   [<ffffffff8100bc0e>] apic_timer_interrupt+0xe
ffff880032bb1370:   [<ffffffff813472ad>] serial8250_console_write+0xbd
ffff880032bb13c0:   [<ffffffff8106b8f5>] __call_console_drivers+0x75
ffff880032bb13f0:   [<ffffffff8106b95a>] _call_console_drivers+0x4a
ffff880032bb1410:   [<ffffffff8106be6e>] release_console_sem+0x4e
ffff880032bb1450:   [<ffffffff8106c628>] vprintk+0x248
ffff880032bb14f0:   [<ffffffff814fd363>] printk+0x41
ffff880032bb3f20:   [<ffffffff8100204c>] do_one_initcall+0x3c
ffff880032bb3f50:   [<ffffffff810b0eb1>] sys_init_module+0xe1
ffff880032bb3f80:   [<ffffffff8100b0f2>] system_call_fastpath+0x16


Signed-off-by: Don Slutz <Don@CloudSwitch.com>
---
v9:
  Re-work commit message.

 tools/xentrace/xenctx.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 42a47f3..c3c33f1 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -35,11 +35,14 @@ static struct xenctx {
     int frame_ptrs;
     int stack_trace;
     int disp_all;
+    int nr_stack_pages;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
 } xenctx;
 
+#define DEFAULT_NR_STACK_PAGES 1
+
 #if defined (__i386__) || defined (__x86_64__)
 typedef unsigned long long guest_word_t;
 #define FMT_32B_WORD "%08llx"
@@ -663,7 +666,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
     int i;
 
     stack_limit = ((stack_pointer(ctx) + XC_PAGE_SIZE)
-                   & ~((guest_word_t) XC_PAGE_SIZE - 1));
+                   & ~((guest_word_t) XC_PAGE_SIZE - 1))
+                   + (xenctx.nr_stack_pages - 1) * XC_PAGE_SIZE;
     printf("\n");
     printf("Stack:\n");
     for (i=1; i<5 && stack < stack_limit; i++) {
@@ -834,18 +838,24 @@ static void usage(void)
         kernel_start);
     printf("  -a, --all          display more registers\n");
     printf("  -C, --all-vcpus    print info for all vcpus\n");
+    printf("  -n PAGES, --display-stack-pages=PAGES\n");
+    printf("                     Display N pages from the stack pointer. (default %d)\n",
+           DEFAULT_NR_STACK_PAGES);
+    printf("                     Changes stack limit.  Note: use with caution (easy\n");
+    printf("                     to get garbage).\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SC";
+    static const char *sopts = "fs:hak:SCn:";
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
         {"frame-pointers", 0, NULL, 'f'},
         {"kernel-start", 1, NULL, 'k'},
+        {"display-stack-pages", 0, NULL, 'n'},
         {"all", 0, NULL, 'a'},
         {"all-vcpus", 0, NULL, 'C'},
         {"help", 0, NULL, 'h'},
@@ -855,6 +865,8 @@ int main(int argc, char **argv)
 
     int vcpu = 0;
 
+    xenctx.nr_stack_pages = DEFAULT_NR_STACK_PAGES;
+
     while ((ch = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
         switch(ch) {
         case 'f':
@@ -869,6 +881,16 @@ int main(int argc, char **argv)
         case 'a':
             xenctx.disp_all = 1;
             break;
+        case 'n':
+            xenctx.nr_stack_pages = strtol(optarg, NULL, 0);
+            if ( xenctx.nr_stack_pages < 1)
+            {
+                fprintf(stderr,
+                        "%s: Unsupported value(%d) for --display-stack-pages '%s'. Needs to be >= 1\n",
+                        argv[0], xenctx.nr_stack_pages, optarg);
+                exit(-1);
+            }
+            break;
         case 'C':
             xenctx.all_vcpus = 1;
             break;
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 04/18] xenctx: Add command line options -b (--bytes-per-line) and -l (--lines)
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (2 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 03/18] xenctx: Add -n (--display-stack-pages) option to output larger stack Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 05/18] xenctx: Add command line option -D (--decode-as-ascii) Don Slutz
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

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

This option allows you to change the width of the output line.  When
used with the -D option and/or -t, the output can be adjusted with
this to less then 80 columns.

  -l <lines>, --lines <lines>
                     change the number of lines output for Stack. (default 5)
                     Can be specified as MAX.  Note: Fewer lines will be output
                     if stack limit reached.

The default value show a reasonable amount of the raw stack.  The -S
option will output all of it one line at a time.  This can be used
to select something in the middle.

Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v9:
  Drop extra if

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

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index c3c33f1..814d8d8 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <inttypes.h>
 #include <getopt.h>
+#include <limits.h>
 
 #include "xenctrl.h"
 #include <xen/foreign/x86_32.h>
@@ -36,12 +37,16 @@ static struct xenctx {
     int stack_trace;
     int disp_all;
     int nr_stack_pages;
+    int bytes_per_line;
+    int lines;
     int all_vcpus;
     int self_paused;
     xc_dominfo_t dominfo;
 } xenctx;
 
 #define DEFAULT_NR_STACK_PAGES 1
+#define DEFAULT_BYTES_PER_LINE 32
+#define DEFAULT_LINES 5
 
 #if defined (__i386__) || defined (__x86_64__)
 typedef unsigned long long guest_word_t;
@@ -64,6 +69,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;
@@ -665,24 +672,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))
                    + (xenctx.nr_stack_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");
@@ -843,19 +859,30 @@ static void usage(void)
            DEFAULT_NR_STACK_PAGES);
     printf("                     Changes stack limit.  Note: use with caution (easy\n");
     printf("                     to get garbage).\n");
+    printf("  -b <bytes>, --bytes-per-line <bytes>\n");
+    printf("                     change the number of bytes per line output for Stack.\n");
+    printf("                     (default %d) Note: rounded to native size (4 or 8 bytes).\n",
+           DEFAULT_BYTES_PER_LINE);
+    printf("  -l <lines>, --lines <lines>\n");
+    printf("                     change the number of lines output for Stack. (default %d)\n",
+           DEFAULT_LINES);
+    printf("                     Can be specified as MAX.  Note: Fewer lines will be output\n");
+    printf("                     if stack limit reached.\n");
 }
 
 int main(int argc, char **argv)
 {
     int ch;
     int ret;
-    static const char *sopts = "fs:hak:SCn:";
+    static const char *sopts = "fs:hak:SCn:b: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'},
         {"display-stack-pages", 0, NULL, 'n'},
+        {"bytes-per-line", 1, NULL, 'b'},
+        {"lines", 1, NULL, 'l'},
         {"all", 0, NULL, 'a'},
         {"all-vcpus", 0, NULL, 'C'},
         {"help", 0, NULL, 'h'},
@@ -865,6 +892,8 @@ int main(int argc, char **argv)
 
     int vcpu = 0;
 
+    xenctx.bytes_per_line = DEFAULT_BYTES_PER_LINE;
+    xenctx.lines = DEFAULT_LINES;
     xenctx.nr_stack_pages = DEFAULT_NR_STACK_PAGES;
 
     while ((ch = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
@@ -891,6 +920,32 @@ int main(int argc, char **argv)
                 exit(-1);
             }
             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 '%s'. Needs to be 4 <= %d <= %d\n",
+                        argv[0], optarg, xenctx.bytes_per_line,
+                        MAX_BYTES_PER_LINE);
+                exit(-1);
+            }
+            break;
+        case 'l':
+            if ( !strcmp(optarg, "all") || !strcmp(optarg, "ALL") ||
+                 !strcmp(optarg, "max") || !strcmp(optarg, "MAX") )
+                xenctx.lines = INT_MAX - 1;
+            else
+                xenctx.lines = strtol(optarg, NULL, 0);
+            if ( xenctx.lines < 0 || xenctx.lines == INT_MAX)
+            {
+                fprintf(stderr,
+                        "%s: Unsupported value(%d) for --lines '%s'. Needs to be >= 0, < %d\n",
+                        argv[0], xenctx.lines, optarg, INT_MAX);
+                exit(-1);
+            }
+            break;
         case 'C':
             xenctx.all_vcpus = 1;
             break;
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 05/18] xenctx: Add command line option -D (--decode-as-ascii)
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (3 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 04/18] xenctx: Add command line options -b (--bytes-per-line) and -l (--lines) Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 06/18] xenctx: Add command line option -t (--tag-stack-dump) Don Slutz
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

If specified, output ascii version of stack also.

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

Here is an example:

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 06/18] xenctx: Add command line option -t (--tag-stack-dump)
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (4 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 05/18] xenctx: Add command line option -D (--decode-as-ascii) Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 07/18] xenctx: Change print_symbol to do the space before Don Slutz
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

If specified, add stack address to dump.

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

Here is an example:

Stack:
ffffffff803ddf90: ffffffff80048d19 0000000000200800 ffffffff803e7801 0000000000086800
ffffffff803ddfb0: 0000000000000000 ffffffff80430720 ffffffff803e722f 80008e000010019c
ffffffff803ddfd0: 00000000ffffffff 0000000000000000 0000000000000000 0000000000200000
ffffffff803ddff0: 0000000000000000 0000000000000000

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Reviewed-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index b5cb14f..4f58811 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -40,6 +40,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;
@@ -689,6 +690,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 )
             {
@@ -901,13 +907,15 @@ static void usage(void)
     printf("                     if stack limit reached.\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:SCn:b:l:D";
+    static const char *sopts = "fs:hak:SCn:b:l:Dt";
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
@@ -915,6 +923,7 @@ int main(int argc, char **argv)
         {"kernel-start", 1, NULL, 'k'},
         {"display-stack-pages", 0, NULL, 'n'},
         {"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'},
@@ -957,6 +966,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 ||
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 07/18] xenctx: Change print_symbol to do the space before.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (5 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 06/18] xenctx: Add command line option -t (--tag-stack-dump) Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 08/18] xenctx: More info on failed to map page Don Slutz
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Jan Beulich

From: Don Slutz <Don@CloudSwitch.com>

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
---
 tools/xentrace/xenctx.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 4f58811..52342f5 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -171,9 +171,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)
@@ -312,7 +312,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);
@@ -341,7 +341,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);
@@ -370,7 +370,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);
@@ -468,7 +468,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);
@@ -520,7 +520,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");
 
@@ -743,7 +743,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");
@@ -783,7 +783,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;
@@ -799,7 +799,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) {
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 08/18] xenctx: More info on failed to map page.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (6 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 07/18] xenctx: Change print_symbol to do the space before Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 09/18] xenctx: Add output of stack address to Call and Stack Trace Don Slutz
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Jan Beulich

From: Don Slutz <Don@CloudSwitch.com>

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
---
 tools/xentrace/xenctx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 52342f5..add0058 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -618,7 +618,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;
     }
 
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 09/18] xenctx: Add output of stack address to Call and Stack Trace.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (7 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 08/18] xenctx: More info on failed to map page Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 10/18] xenctx: Add -m (--memory) <maddr> option to dump memory at maddr Don Slutz
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index add0058..2207171 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -665,6 +665,12 @@ static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
     return 0;
 }
 
+static void print_stack_addr(guest_word_t addr, int width)
+{
+    print_stack_word(addr, width);
+    printf(": ");
+}
+
 static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
 {
     guest_word_t stack = stack_pointer(ctx);
@@ -741,7 +747,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Stack Trace:\n");
     else
         printf("Call Trace:\n");
-    printf("%c [<", xenctx.stack_trace ? '*' : ' ');
+    printf("%*s  %c [<", width*2, "", xenctx.stack_trace ? '*' : ' ');
     print_stack_word(instr_pointer(ctx), width);
     printf(">]");
 
@@ -756,9 +762,10 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                     p = map_page(ctx, vcpu, stack);
                     if (!p)
                         return -1;
+                    print_stack_addr(stack, width);
                     printf("|   ");
                     print_stack_word(read_stack_word(p, width), width);
-                    printf("   \n");
+                    printf("\n");
                     stack += width;
                 }
             } else {
@@ -770,6 +777,7 @@ 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) {
+                print_stack_addr(stack, width);
                 printf("|-- ");
                 print_stack_word(read_stack_word(p, width), width);
                 printf("\n");
@@ -781,6 +789,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
                 if (!p)
                     return -1;
                 word = read_stack_word(p, width);
+                print_stack_addr(stack, width);
                 printf("%c [<", xenctx.stack_trace ? '|' : ' ');
                 print_stack_word(word, width);
                 printf(">]");
@@ -797,12 +806,14 @@ 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)) {
+                print_stack_addr(stack, width);
                 printf("  [<");
                 print_stack_word(word, width);
                 printf(">]");
                 print_symbol(word);
                 printf("\n");
             } else if (xenctx.stack_trace) {
+                print_stack_addr(stack, width);
                 printf("    ");
                 print_stack_word(word, width);
                 printf("\n");
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 10/18] xenctx: Add -m (--memory) <maddr> option to dump memory at maddr.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (8 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 09/18] xenctx: Add output of stack address to Call and Stack Trace Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 11/18] xenctx: Add error output if --all-vcpus (-C) and [VCPU] are both specified Don Slutz
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

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.

Moved xenctx because guest_word_t is not defined where it was.

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 242 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 172 insertions(+), 70 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 2207171..ca3662e 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -30,22 +30,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 nr_stack_pages;
-    int bytes_per_line;
-    int lines;
-    int decode_as_ascii;
-    int tag_stack_dump;
-    int all_vcpus;
-    int self_paused;
-    xc_dominfo_t dominfo;
-} xenctx;
-
 #define DEFAULT_NR_STACK_PAGES 1
 #define DEFAULT_BYTES_PER_LINE 32
 #define DEFAULT_LINES 5
@@ -73,6 +57,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 nr_stack_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;
@@ -634,6 +639,45 @@ static guest_word_t read_stack_word(guest_word_t *src, int width)
     return word;
 }
 
+static guest_word_t read_mem_word(vcpu_guest_context_any_t *ctx, int vcpu,
+                                  guest_word_t virt, int width)
+{
+    if ( (virt & 7) == 0 )
+    {
+        guest_word_t *p = map_page(ctx, vcpu, virt);
+
+        if ( p )
+            return read_stack_word(p, width);
+        else
+            return -1;
+    }
+    else
+    {
+        guest_word_t word = 0;
+        char *src, *dst;
+        int i;
+
+        /* Little-endian only */
+        dst = (char *)&word;
+        for (i = 0; i < width; i++)
+        {
+            src = map_page(ctx, vcpu, virt + i);
+            if ( src )
+                *dst++ = *src;
+            else
+            {
+                guest_word_t missing = -1LL;
+
+                /* Return all ones for missing memory */
+                memcpy(dst, &missing, width - i);
+                return word;
+            }
+        }
+        return word;
+    }
+}
+#endif
+
 static void print_stack_word(guest_word_t word, int width)
 {
     if (width == 4)
@@ -642,6 +686,78 @@ static void print_stack_word(guest_word_t word, int width)
         printf(FMT_64B_WORD, word);
 }
 
+#ifndef NO_TRANSLATION
+static int print_lines(vcpu_guest_context_any_t *ctx, int vcpu, int width,
+                       guest_word_t mem_addr, guest_word_t mem_limit)
+{
+    guest_word_t mem_start = mem_addr;
+    guest_word_t word;
+    guest_word_t ascii[MAX_BYTES_PER_LINE/4];
+    int i;
+
+    for (i = 1; i < xenctx.lines + 1 && mem_addr < mem_limit; i++)
+    {
+        int j = 0;
+        int k;
+
+        if ( xenctx.tag_stack_dump )
+        {
+            print_stack_word(mem_addr, width);
+            printf(":");
+        }
+        while ( mem_addr < mem_limit &&
+                mem_addr < mem_start + i * xenctx.bytes_per_line )
+        {
+            void *p = map_page(ctx, vcpu, mem_addr);
+            if ( !p )
+                return -1;
+            word = read_mem_word(ctx, vcpu, mem_addr, width);
+            if ( xenctx.decode_as_ascii )
+                ascii[j++] = word;
+            printf(" ");
+            print_stack_word(word, width);
+            mem_addr += width;
+        }
+        if ( xenctx.decode_as_ascii )
+        {
+            /*
+             * Line up ascii output if less than bytes_per_line
+             * were printed.
+             */
+            for (k = j; k < xenctx.bytes_per_line / width; k++)
+                printf(" %*s", width * 2, "");
+            printf("  ");
+            for (k = 0; k < j; k++)
+            {
+                int l;
+                unsigned char *bytep = (unsigned char *)&ascii[k];
+
+                for (l = 0; l < width; l++)
+                {
+                    if (isprint(*bytep))
+                        printf("%c", *bytep);
+                    else
+                        printf(".");
+                    bytep++;
+                }
+            }
+        }
+        printf("\n");
+    }
+    printf("\n");
+    return 0;
+}
+
+static void print_mem(vcpu_guest_context_any_t *ctx, int vcpu, int width,
+                          guest_word_t mem_addr)
+{
+    printf("Memory (address ");
+    print_stack_word(mem_addr, width);
+    printf("):\n");
+    print_lines(ctx, vcpu, width, mem_addr,
+                mem_addr + xenctx.lines * xenctx.bytes_per_line);
+}
+
 static int print_code(vcpu_guest_context_any_t *ctx, int vcpu)
 {
     guest_word_t instr;
@@ -678,8 +794,6 @@ 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 )
         xenctx.bytes_per_line =
@@ -691,56 +805,8 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
     if ( xenctx.lines )
     {
         printf("Stack:\n");
-        for (i = 1; i < xenctx.lines + 1 && stack < stack_limit; i++)
-        {
-            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 )
-            {
-                p = map_page(ctx, vcpu, stack);
-                if ( !p )
-                    return -1;
-                word = read_stack_word(p, width);
-                if ( xenctx.decode_as_ascii )
-                    ascii[j++] = word;
-                printf(" ");
-                print_stack_word(word, width);
-                stack += width;
-            }
-            if ( xenctx.decode_as_ascii )
-            {
-                /*
-                 * Line up ascii output if less than bytes_per_line
-                 * were printed.
-                 */
-                for (k = j; k < xenctx.bytes_per_line / width; k++)
-                    printf(" %*s", width * 2, "");
-                printf("  ");
-                for (k = 0; k < j; k++)
-                {
-                    int l;
-                    unsigned char *bytep = (unsigned char *)&ascii[k];
-
-                    for (l = 0; l < width; l++)
-                    {
-                        if (isprint(*bytep))
-                            printf("%c", *bytep);
-                        else
-                            printf(".");
-                        bytep++;
-                    }
-                }
-            }
-            printf("\n");
-        }
-        printf("\n");
+        if ( print_lines(ctx, vcpu, width, stack, stack_limit) )
+            return -1;
     }
 
     if(xenctx.stack_trace)
@@ -861,6 +927,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))
@@ -920,13 +993,21 @@ 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");
+#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;
-    static const char *sopts = "fs:hak:SCn:b:l:Dt";
+    static const char *sopts = "fs:hak:SCn:b:l:Dt"
+#ifndef NO_TRANSLATION
+        "m:"
+#endif
+        ;
     static const struct option lopts[] = {
         {"stack-trace", 0, NULL, 'S'},
         {"symbol-table", 1, NULL, 's'},
@@ -935,6 +1016,9 @@ int main(int argc, char **argv)
         {"display-stack-pages", 0, NULL, 'n'},
         {"decode-as-ascii", 0, NULL, 'D'},
         {"tag-stack-dump", 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'},
@@ -945,6 +1029,7 @@ int main(int argc, char **argv)
     const char *symbol_table = NULL;
 
     int vcpu = 0;
+    int do_default = 1;
 
     xenctx.bytes_per_line = DEFAULT_BYTES_PER_LINE;
     xenctx.lines = DEFAULT_LINES;
@@ -1008,10 +1093,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);
@@ -1061,9 +1154,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) {
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 11/18] xenctx: Add error output if --all-vcpus (-C) and [VCPU] are both specified.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (9 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 10/18] xenctx: Add -m (--memory) <maddr> option to dump memory at maddr Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 12/18] xenctx: Add -d (--dump-as-stack) <daddr> option to dump memory at daddr as a stack Don Slutz
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

To do this correctly the program name must be remembered since argv
is adjusted at the end of option parsing.

Switch all uses of argv[0] to prog.

Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v9:
  Moved hunk from #12 that should have been here.
  Added : to error message

 tools/xentrace/xenctx.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index ca3662e..caa2991 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -1003,6 +1003,7 @@ int main(int argc, char **argv)
 {
     int ch;
     int ret;
+    const char *prog = argv[0];
     static const char *sopts = "fs:hak:SCn:b:l:Dt"
 #ifndef NO_TRANSLATION
         "m:"
@@ -1055,7 +1056,7 @@ int main(int argc, char **argv)
             {
                 fprintf(stderr,
                         "%s: Unsupported value(%d) for --display-stack-pages '%s'. Needs to be >= 1\n",
-                        argv[0], xenctx.nr_stack_pages, optarg);
+                        prog, xenctx.nr_stack_pages, optarg);
                 exit(-1);
             }
             break;
@@ -1072,7 +1073,7 @@ int main(int argc, char **argv)
             {
                 fprintf(stderr,
                         "%s: Unsupported value for --bytes-per-line '%s'. Needs to be 4 <= %d <= %d\n",
-                        argv[0], optarg, xenctx.bytes_per_line,
+                        prog, optarg, xenctx.bytes_per_line,
                         MAX_BYTES_PER_LINE);
                 exit(-1);
             }
@@ -1087,7 +1088,7 @@ int main(int argc, char **argv)
             {
                 fprintf(stderr,
                         "%s: Unsupported value(%d) for --lines '%s'. Needs to be >= 0, < %d\n",
-                        argv[0], xenctx.lines, optarg, INT_MAX);
+                        prog, xenctx.lines, optarg, INT_MAX);
                 exit(-1);
             }
             break;
@@ -1109,7 +1110,7 @@ int main(int argc, char **argv)
             usage();
             exit(-1);
         case '?':
-            fprintf(stderr, "%s --help for more options\n", argv[0]);
+            fprintf(stderr, "%s --help for more options\n", prog);
             exit(-1);
         }
     }
@@ -1127,8 +1128,17 @@ int main(int argc, char **argv)
             exit(-1);
     }
 
-    if (argc == 2)
+    if ( argc == 2 )
+    {
+        if ( xenctx.all_vcpus )
+        {
+            fprintf(stderr,
+                    "%s: both --all-vcpus and [VCPU] is not supported\n",
+                    prog);
+            exit(-1);
+        }
         vcpu = atoi(argv[1]);
+    }
 
     if (symbol_table)
         read_symbol_table(symbol_table);
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 12/18] xenctx: Add -d (--dump-as-stack) <daddr> option to dump memory at daddr as a stack.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (10 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 11/18] xenctx: Add error output if --all-vcpus (-C) and [VCPU] are both specified Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 13/18] xenctx: change is_kernel_text() into kernel_addr() Don Slutz
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Don Slutz,
	Ian Jackson, Don Slutz, Jan Beulich

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

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v9:
  Moved hunk to #11 that should have been here.
  Added : to error message

 tools/xentrace/xenctx.c | 66 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 50 insertions(+), 16 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index caa2991..4a424d6 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -72,7 +72,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;
@@ -775,9 +777,7 @@ 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;
 }
 
@@ -787,9 +787,10 @@ static void print_stack_addr(guest_word_t addr, int width)
     printf(": ");
 }
 
-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;
@@ -801,7 +802,6 @@ 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))
                    + (xenctx.nr_stack_pages - 1) * XC_PAGE_SIZE;
-    printf("\n");
     if ( xenctx.lines )
     {
         printf("Stack:\n");
@@ -813,12 +813,15 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width)
         printf("Stack Trace:\n");
     else
         printf("Call Trace:\n");
-    printf("%*s  %c [<", width*2, "", xenctx.stack_trace ? '*' : ' ');
-    print_stack_word(instr_pointer(ctx), width);
-    printf(">]");
+    if ( !xenctx.do_stack )
+    {
+        printf("%*s  %c [<", width*2, "", xenctx.stack_trace ? '*' : ' ');
+        print_stack_word(instr_pointer(ctx), width);
+        printf(">]");
 
-    print_symbol(instr_pointer(ctx));
-    printf(" <--\n");
+        print_symbol(instr_pointer(ctx));
+        printf(" <--\n");
+    }
     if (xenctx.frame_ptrs) {
         stack = stack_pointer(ctx);
         frame = frame_pointer(ctx);
@@ -865,12 +868,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)) {
                 print_stack_addr(stack, width);
                 printf("  [<");
@@ -933,13 +936,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
 }
@@ -996,6 +1005,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
 }
 
@@ -1006,7 +1017,7 @@ int main(int argc, char **argv)
     const char *prog = argv[0];
     static const char *sopts = "fs:hak:SCn:b:l:Dt"
 #ifndef NO_TRANSLATION
-        "m:"
+        "m:d:"
 #endif
         ;
     static const struct option lopts[] = {
@@ -1019,6 +1030,7 @@ int main(int argc, char **argv)
         {"tag-stack-dump", 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'},
@@ -1105,6 +1117,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();
@@ -1122,6 +1139,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",
+                prog);
+        exit(-1);
+    }
+#endif
+
     xenctx.domid = atoi(argv[0]);
     if (xenctx.domid==0) {
             fprintf(stderr, "cannot trace dom0\n");
@@ -1168,10 +1195,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();
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 13/18] xenctx: change is_kernel_text() into kernel_addr().
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (11 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 12/18] xenctx: Add -d (--dump-as-stack) <daddr> option to dump memory at daddr as a stack Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 14/18] xenctx: Add conversion of more registers to symbols Don Slutz
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

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.

Add both _end and __bss_stop as kernel_end.

Signed-off-by: Don Slutz <dslutz@verizon.com>
---
v9:
  Revert to v5.
  Initalize kernel_end to a good value.
  Add __bss_stop to be same as _end.
  Changed -k to act like it's usage.
  Add check for kernel_start & kernel_end as last test.

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

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 4a424d6..b9aa7c0 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -34,6 +34,15 @@
 #define DEFAULT_BYTES_PER_LINE 32
 #define DEFAULT_LINES 5
 
+/* 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"
@@ -76,6 +85,7 @@ static struct xenctx {
     int do_memory;
     int do_stack;
 #endif
+    int kernel_start_set;
     int self_paused;
     xc_dominfo_t dominfo;
 } xenctx;
@@ -87,31 +97,52 @@ struct symbol {
 } *symbol_table = NULL;
 
 guest_word_t kernel_stext, kernel_etext, kernel_sinittext, kernel_einittext, kernel_hypercallpage;
+guest_word_t kernel_text;
 
 #if defined (__i386__) || defined (__arm__)
 unsigned long long kernel_start = 0xc0000000;
+unsigned long long kernel_end = 0xffffffffULL;
 #elif defined (__x86_64__)
 unsigned long long kernel_start = 0xffffffff80000000UL;
+unsigned long long kernel_end = 0xffffffffffffffffUL;
 #elif defined (__aarch64__)
 unsigned long long kernel_start = 0xffffff8000000000UL;
+unsigned long long kernel_end = 0xffffffffffffffffULL;
 #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 )
+            return KERNEL_TEXT_ADDR;
+    } else {
+        if ( addr >= kernel_text &&
+             addr <= kernel_end )
+            return KERNEL_DATA_ADDR;
+        if ( addr >= kernel_start &&
+             addr <= kernel_end )
+            return KERNEL_TEXT_ADDR;
+    }
+    return NOT_KERNEL_ADDR;
 }
 
 #if 0
@@ -165,11 +196,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);
@@ -249,6 +280,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 || strcmp(p, "__bss_stop") == 0 )
+            kernel_end = address;
         else if (strcmp(p, "_sinittext") == 0)
             kernel_sinittext = address;
         else if (strcmp(p, "_einittext") == 0)
@@ -320,7 +355,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);
 
@@ -349,7 +384,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);
 
@@ -378,7 +413,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);
 
@@ -476,7 +511,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",
@@ -528,7 +563,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);
@@ -819,7 +854,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width,
         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) {
@@ -862,7 +897,7 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width,
                 printf("%c [<", xenctx.stack_trace ? '|' : ' ');
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
                 stack += width;
             }
@@ -874,12 +909,13 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width,
             if (!p)
                 return -1;
             word = read_mem_word(ctx, vcpu, stack, width);
-            if (is_kernel_text(word)) {
+            if ( kernel_addr(word) >= KERNEL_TEXT_ADDR )
+            {
                 print_stack_addr(stack, width);
                 printf("  [<");
                 print_stack_word(word, width);
                 printf(">]");
-                print_symbol(word);
+                print_symbol(word, KERNEL_TEXT_ADDR);
                 printf("\n");
             } else if (xenctx.stack_trace) {
                 print_stack_addr(stack, width);
@@ -946,7 +982,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;
@@ -1110,6 +1146,7 @@ int main(int argc, char **argv)
             break;
         case 'k':
             kernel_start = strtoull(optarg, NULL, 0);
+            xenctx.kernel_start_set = 1;
             break;
 #ifndef NO_TRANSLATION
         case 'm':
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 14/18] xenctx: Add conversion of more registers to symbols
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (12 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 13/18] xenctx: change is_kernel_text() into kernel_addr() Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 15/18] xenctx: Add output of vcpu value and state for --all-vcpus Don Slutz
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

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

Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v9:
  s/convert/conversion/ in $subject

 tools/xentrace/xenctx.c | 47 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index b9aa7c0..754009b 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -44,6 +44,8 @@ typedef enum type_of_addr_ {
 } type_of_addr;
 
 #if defined (__i386__) || defined (__x86_64__)
+static const uint64_t cr_reg_mask[5] = { [2] = ~UINT64_C(0) };
+static const uint64_t dr_reg_mask[8] = { [0 ... 3] = ~UINT64_C(0) };
 typedef unsigned long long guest_word_t;
 #define FMT_32B_WORD "%08llx"
 #define FMT_64B_WORD "%016llx"
@@ -336,17 +338,29 @@ static void print_flags(uint64_t flags)
     printf("\n");
 }
 
-static void print_special(void *regs, const char *name, unsigned int mask, int width)
+static void print_special(void *regs, const char *name, unsigned int mask,
+                          const uint64_t reg_is_addr_mask[], int width)
 {
     unsigned int i;
 
     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]);
+            if ( width == 4 )
+            {
+                printf("%s%u: %08"PRIx32, name, i, ((uint32_t *) regs)[i]);
+                if ( reg_is_addr_mask[i] )
+                    print_symbol(reg_is_addr_mask[i] & ((uint32_t *) regs)[i],
+                                 KERNEL_DATA_ADDR);
+            }
             else
-                printf("%s%u: %08"PRIx64"\n", name, i, ((uint64_t *) regs)[i]);
+            {
+                printf("%s%u: %016"PRIx64, name, i, ((uint64_t *) regs)[i]);
+                if ( reg_is_addr_mask[i] )
+                    print_symbol(reg_is_addr_mask[i] & ((uint64_t *) regs)[i],
+                                 KERNEL_DATA_ADDR);
+            }
+            printf("\n");
         }
 }
 
@@ -374,8 +388,8 @@ static void print_ctx_32(vcpu_guest_context_x86_32_t *ctx)
     printf(" gs:     %04x\n", regs->gs);
 
     if (xenctx.disp_all) {
-        print_special(ctx->ctrlreg, "cr", 0x1d, 4);
-        print_special(ctx->debugreg, "dr", 0xcf, 4);
+        print_special(ctx->ctrlreg, "cr", 0x1d, cr_reg_mask, 4);
+        print_special(ctx->debugreg, "dr", 0xcf, dr_reg_mask, 4);
     }
 }
 
@@ -403,8 +417,8 @@ static void print_ctx_32on64(vcpu_guest_context_x86_64_t *ctx)
     printf(" gs:     %04x\n", regs->gs);
 
     if (xenctx.disp_all) {
-        print_special(ctx->ctrlreg, "cr", 0x1d, 4);
-        print_special(ctx->debugreg, "dr", 0xcf, 4);
+        print_special(ctx->ctrlreg, "cr", 0x1d, cr_reg_mask, 4);
+        print_special(ctx->debugreg, "dr", 0xcf, dr_reg_mask, 4);
     }
 }
 
@@ -442,13 +456,22 @@ 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);
-        print_special(ctx->debugreg, "dr", 0xcf, 8);
+        print_special(ctx->ctrlreg, "cr", 0x1d, cr_reg_mask, 8);
+        print_special(ctx->debugreg, "dr", 0xcf, dr_reg_mask, 8);
     }
 }
 
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 15/18] xenctx: Add output of vcpu value and state for --all-vcpus
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (13 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 14/18] xenctx: Add conversion of more registers to symbols Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode Don Slutz
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

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

Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 754009b..8ae4f9b 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -1021,7 +1021,13 @@ static void dump_all_vcpus(void)
         if ( xc_vcpu_getinfo(xenctx.xc_handle, xenctx.domid, vcpu, &vinfo) )
             continue;
         if ( vinfo.online )
+        {
+            printf("vcpu%d:\n", vcpu);
             dump_ctx(vcpu);
+            printf("\n");
+        }
+        else
+            printf("vcpu%d offline\n\n", vcpu);
     }
 }
 
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (14 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 15/18] xenctx: Add output of vcpu value and state for --all-vcpus Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 17:26   ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 17/18] xenctx: Add 16 bit output Don Slutz
                   ` (2 subsequent siblings)
  18 siblings, 1 reply; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

Start with adding the code to the 64 bit path that the 32 bit path
has.

Next disable the "Stack Trace" or "Call Trace".

Finally allow stack dump.

Signed-off-by: Don Slutz <dslutz@verizon.com>
---
 tools/xentrace/xenctx.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 8ae4f9b..6a07981 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -498,8 +498,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;
 }
 
@@ -514,8 +519,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;
 }
 
@@ -867,6 +877,9 @@ static int print_stack(vcpu_guest_context_any_t *ctx, int vcpu, int width,
             return -1;
     }
 
+    if ( !guest_protected_mode )
+        return 0;
+
     if(xenctx.stack_trace)
         printf("Stack Trace:\n");
     else
@@ -1005,7 +1018,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;
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 17/18] xenctx: Add 16 bit output
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (15 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-02 16:03 ` [PATCH v9 18/18] xenctx: Fix print_ctx_32on64's print_special call Don Slutz
  2014-04-03 16:24 ` [PATCH v9 00/18] xenctx: Many changes Ian Campbell
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

This output happens on !guest_protected_mode.  The cpu is in 16 bit
mode in this case.

For example:

$ xenctx 4
cs:eip: f000:0000d61b
flags: 00000002 nz
ss:esp: 0000:00001fee
eax: 0000ffc2   ebx: 00000049   ecx: 00000049   edx: ffffffff
esi: 00000000   edi: 00000010   ebp: 00001ff0
 ds:     e000    es:     0040    fs:     0000    gs:     0000
Code (instr addr 000fd61b)
04 67 66 8b 70 08 67 66 8b 68 0c 67 66 8b 58 10 67 66 8b 50 14 <67> 66 8b 48 18 67 8e 40 02 67 ff

Stack:
 8e30 0000 0246 812f 0000 0206 80e7 0080 0080

$ xenctx 4 -d 0x00001fee -m 0x00001fee -l 1
Memory (address 1fee):
 8e30 0000 0246 812f 0000 0206 80e7 0080 0080 c2c2 c2c2 c2c2 c2c2 c2c2 c2c2 c2c2

Stack:
 8e30 0000 0246 812f 0000 0206 80e7 0080 0080

Signed-off-by: Don Slutz <dslutz@verizon.com>
---
v9:
  Adjust commit message.
  Change global guest_word_size to 2 if !guest_protected_mode
  Fix test for == 4 to != 8 where needed

 tools/xentrace/xenctx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 6a07981..e3b7084 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -47,6 +47,7 @@ typedef enum type_of_addr_ {
 static const uint64_t cr_reg_mask[5] = { [2] = ~UINT64_C(0) };
 static const uint64_t dr_reg_mask[8] = { [0 ... 3] = ~UINT64_C(0) };
 typedef unsigned long long guest_word_t;
+#define FMT_16B_WORD "%04llx"
 #define FMT_32B_WORD "%08llx"
 #define FMT_64B_WORD "%016llx"
 /* Word-length of the guest's own data structures */
@@ -479,7 +480,7 @@ static void print_ctx(vcpu_guest_context_any_t *ctx)
 {
     if (ctxt_word_size == 4)
         print_ctx_32(&ctx->x32);
-    else if (guest_word_size == 4)
+    else if (guest_word_size != 8)
         print_ctx_32on64(&ctx->x64);
     else
         print_ctx_64(&ctx->x64);
@@ -750,7 +751,9 @@ static guest_word_t read_mem_word(vcpu_guest_context_any_t *ctx, int vcpu,
 
 static void print_stack_word(guest_word_t word, int width)
 {
-    if (width == 4)
+    if (width == 2)
+        printf(FMT_16B_WORD, word);
+    else if (width == 4)
         printf(FMT_32B_WORD, word);
     else
         printf(FMT_64B_WORD, word);
@@ -986,8 +989,9 @@ static void dump_ctx(int vcpu)
                 perror("xc_domain_hvm_getcontext_partial");
                 return;
             }
-            guest_word_size = (cpuctx.msr_efer & 0x400) ? 8 : 4;
             guest_protected_mode = (cpuctx.cr0 & CR0_PE);
+            guest_word_size = (cpuctx.msr_efer & 0x400) ? 8 :
+                guest_protected_mode ? 4 : 2;
             /* HVM guest context records are always host-sized */
             if (xc_version(xenctx.xc_handle, XENVER_capabilities, &xen_caps) != 0) {
                 perror("xc_version");
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v9 18/18] xenctx: Fix print_ctx_32on64's print_special call.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (16 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 17/18] xenctx: Add 16 bit output Don Slutz
@ 2014-04-02 16:03 ` Don Slutz
  2014-04-03 16:24 ` [PATCH v9 00/18] xenctx: Many changes Ian Campbell
  18 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 16:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, George Dunlap, Ian Jackson,
	Don Slutz, Jan Beulich

print_special() uses the width argument to both select output format
and array size.  So by passing 4 it expects an array of uint32_t.
But an array of uint64_t is passed.

So copy and mask the registers to 32 bits.

Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index e3b7084..24dbba1 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -418,8 +418,15 @@ static void print_ctx_32on64(vcpu_guest_context_x86_64_t *ctx)
     printf(" gs:     %04x\n", regs->gs);
 
     if (xenctx.disp_all) {
-        print_special(ctx->ctrlreg, "cr", 0x1d, cr_reg_mask, 4);
-        print_special(ctx->debugreg, "dr", 0xcf, dr_reg_mask, 4);
+        uint32_t tmp_regs[8];
+        int i;
+
+        for (i = 0; i < 5; i++)
+            tmp_regs[i] = ctx->ctrlreg[i];
+        print_special(tmp_regs, "cr", 0x1d, cr_reg_mask, 4);
+        for (i = 0; i < 8; i++)
+            tmp_regs[i] = ctx->debugreg[i];
+        print_special(tmp_regs, "dr", 0xcf, dr_reg_mask, 4);
     }
 }
 
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode
  2014-04-02 16:03 ` [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode Don Slutz
@ 2014-04-02 17:26   ` Don Slutz
  0 siblings, 0 replies; 23+ messages in thread
From: Don Slutz @ 2014-04-02 17:26 UTC (permalink / raw)
  To: Don Slutz, xen-devel
  Cc: George Dunlap, Ian Jackson, Ian Campbell, Jan Beulich,
	Stefano Stabellini

On 04/02/14 12:03, Don Slutz wrote:
> Start with adding the code to the 64 bit path that the 32 bit path
> has.
>
>

(from "[PATCH v8 16/20]")

>> I.E. the context is in 64, the guest is not.
>
> Ah, I missed that thanks.
>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>


Do to local e-mail issues, the acked-by did not come in till after I sent this. :(

    -Don Slutz

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v9 00/18] xenctx: Many changes.
  2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
                   ` (17 preceding siblings ...)
  2014-04-02 16:03 ` [PATCH v9 18/18] xenctx: Fix print_ctx_32on64's print_special call Don Slutz
@ 2014-04-03 16:24 ` Ian Campbell
  2014-04-03 23:27   ` Don Slutz
  18 siblings, 1 reply; 23+ messages in thread
From: Ian Campbell @ 2014-04-03 16:24 UTC (permalink / raw)
  To: Don Slutz
  Cc: George Dunlap, Stefano Stabellini, Ian Jackson, Jan Beulich, xen-devel

On Wed, 2014-04-02 at 12:03 -0400, Don Slutz wrote:
> Add more functionality to xenctx.

I had acked and was just about to apply but unfortunately this doesn't
build on ARM:

        xenctx.c: In function ‘print_stack_word’:
        xenctx.c:762:16: error: ‘FMT_16B_WORD’ undeclared (first use in this function)
        xenctx.c:762:16: note: each undeclared identifier is reported only once for each function it appears in
        
ARM doesn't have any 16-bit modes so I suppose you could use #ifdef
FMT_16B_WORD or just define it for ARM and arm64, %04llx would be
correct for both I think.

        xenctx.c: At top level:
        xenctx.c:759:13: error: ‘print_stack_word’ defined but not used [-Werror=unused-function]

There is an #endif from a NO_TRANSLATION right before print_stack_word
and an #ifndef NO_TRANSLATION right after, so I think you can just
remove them and incorporate print_stack_word into one big NO_TRANSLATION
region.

On arm64 there is an additional one compared with arm32:

        xenctx.c: In function 'usage':
        xenctx.c:1074:9: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'long long unsigned int' [-Werror=format=]
                 kernel_start);
                 ^
        
kernel_addr is an unsigned long long but FMT_64B_WORD is a %#lx on
aarch64. I think this is wrong on aarch64 and the patch below makes it
right, I think, so if you insert that at the start of your series this
one should go away.

Unfortunately that last one was from the first patch in the series or
I'd have committed at least some of it.

Building arm stuff is more faff than I would ask a non-ARM developer to
go through, if you want to then [0] is the place to look, otherwise feel
free to make a best effort by inspection and I'll try building v10 for
you.

[0] http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/CrossCompiling

Ian.

8<----------------------------------------

From 1f6bd5e1157d99a1b075d9386410d5a59eb85d69 Mon Sep 17 00:00:00 2001
From: Ian Campbell <ian.campbell@citrix.com>
Date: Thu, 3 Apr 2014 17:13:00 +0100
Subject: [PATCH] xenctx: Correct FMT_??B_WORD for arm64.

These should all be unsigned long long to match various variables used
in the
code, same as x86_64.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/xentrace/xenctx.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 7275a00..47712ab 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -57,8 +57,8 @@ typedef uint64_t guest_word_t;
 #elif defined(__aarch64__)
 #define NO_TRANSLATION
 typedef uint64_t guest_word_t;
-#define FMT_32B_WORD "%08lx"
-#define FMT_64B_WORD "%016lx"
+#define FMT_32B_WORD "%08llx"
+#define FMT_64B_WORD "%016llx"
 #endif
 
 struct symbol {
-- 
1.7.10.4




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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v9 00/18] xenctx: Many changes.
  2014-04-03 16:24 ` [PATCH v9 00/18] xenctx: Many changes Ian Campbell
@ 2014-04-03 23:27   ` Don Slutz
  2014-04-04  8:34     ` Ian Campbell
  0 siblings, 1 reply; 23+ messages in thread
From: Don Slutz @ 2014-04-03 23:27 UTC (permalink / raw)
  To: Ian Campbell, Don Slutz
  Cc: George Dunlap, Stefano Stabellini, Ian Jackson, Jan Beulich, xen-devel

On 04/03/14 12:24, Ian Campbell wrote:
> On Wed, 2014-04-02 at 12:03 -0400, Don Slutz wrote:
>> Add more functionality to xenctx.
>
>
> Building arm stuff is more faff than I would ask a non-ARM developer to
> go through, if you want to then [0] is the place to look, otherwise feel
> free to make a best effort by inspection and I'll try building v10 for
> you.

I have have done the "best effort by inspection".  v10 posted

    -Don Slutz
> [0] http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/CrossCompiling
>
> Ian.
>
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v9 00/18] xenctx: Many changes.
  2014-04-03 23:27   ` Don Slutz
@ 2014-04-04  8:34     ` Ian Campbell
  0 siblings, 0 replies; 23+ messages in thread
From: Ian Campbell @ 2014-04-04  8:34 UTC (permalink / raw)
  To: Don Slutz
  Cc: George Dunlap, Stefano Stabellini, Ian Jackson, Jan Beulich, xen-devel

On Thu, 2014-04-03 at 19:27 -0400, Don Slutz wrote:
> On 04/03/14 12:24, Ian Campbell wrote:
> > On Wed, 2014-04-02 at 12:03 -0400, Don Slutz wrote:
> >> Add more functionality to xenctx.
> >
> >
> > Building arm stuff is more faff than I would ask a non-ARM developer to
> > go through, if you want to then [0] is the place to look, otherwise feel
> > free to make a best effort by inspection and I'll try building v10 for
> > you.
> 
> I have have done the "best effort by inspection".  v10 posted

Thank!

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2014-04-04  8:34 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-02 16:03 [PATCH v9 00/18] xenctx: Many changes Don Slutz
2014-04-02 16:03 ` [PATCH v9 01/18] xenctx: clean up usage output Don Slutz
2014-04-02 16:03 ` [PATCH v9 02/18] xenctx: Clean up stack trace when hypercall_page not in symbol table Don Slutz
2014-04-02 16:03 ` [PATCH v9 03/18] xenctx: Add -n (--display-stack-pages) option to output larger stack Don Slutz
2014-04-02 16:03 ` [PATCH v9 04/18] xenctx: Add command line options -b (--bytes-per-line) and -l (--lines) Don Slutz
2014-04-02 16:03 ` [PATCH v9 05/18] xenctx: Add command line option -D (--decode-as-ascii) Don Slutz
2014-04-02 16:03 ` [PATCH v9 06/18] xenctx: Add command line option -t (--tag-stack-dump) Don Slutz
2014-04-02 16:03 ` [PATCH v9 07/18] xenctx: Change print_symbol to do the space before Don Slutz
2014-04-02 16:03 ` [PATCH v9 08/18] xenctx: More info on failed to map page Don Slutz
2014-04-02 16:03 ` [PATCH v9 09/18] xenctx: Add output of stack address to Call and Stack Trace Don Slutz
2014-04-02 16:03 ` [PATCH v9 10/18] xenctx: Add -m (--memory) <maddr> option to dump memory at maddr Don Slutz
2014-04-02 16:03 ` [PATCH v9 11/18] xenctx: Add error output if --all-vcpus (-C) and [VCPU] are both specified Don Slutz
2014-04-02 16:03 ` [PATCH v9 12/18] xenctx: Add -d (--dump-as-stack) <daddr> option to dump memory at daddr as a stack Don Slutz
2014-04-02 16:03 ` [PATCH v9 13/18] xenctx: change is_kernel_text() into kernel_addr() Don Slutz
2014-04-02 16:03 ` [PATCH v9 14/18] xenctx: Add conversion of more registers to symbols Don Slutz
2014-04-02 16:03 ` [PATCH v9 15/18] xenctx: Add output of vcpu value and state for --all-vcpus Don Slutz
2014-04-02 16:03 ` [PATCH v9 16/18] xenctx: Fix handling of !guest_protected_mode Don Slutz
2014-04-02 17:26   ` Don Slutz
2014-04-02 16:03 ` [PATCH v9 17/18] xenctx: Add 16 bit output Don Slutz
2014-04-02 16:03 ` [PATCH v9 18/18] xenctx: Fix print_ctx_32on64's print_special call Don Slutz
2014-04-03 16:24 ` [PATCH v9 00/18] xenctx: Many changes Ian Campbell
2014-04-03 23:27   ` Don Slutz
2014-04-04  8:34     ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.