[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] tools/gdbsx: use inttypes.h instead of custom macros
Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx> --- This is on top of "tools/gdbsx: fix 'g' packet response for 64bit guests" patch. --- tools/debugger/gdbsx/gx/gx_local.c | 17 +++++----- tools/debugger/gdbsx/gx/gx_main.c | 5 +-- tools/debugger/gdbsx/xg/xg_public.h | 8 ----- tools/xenstore/xenstore_client.c | 51 +++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/tools/debugger/gdbsx/gx/gx_local.c b/tools/debugger/gdbsx/gx/gx_local.c index 33556a582d..023f5a391f 100644 --- a/tools/debugger/gdbsx/gx/gx_local.c +++ b/tools/debugger/gdbsx/gx/gx_local.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <stdint.h> #include <stdarg.h> +#include <inttypes.h> #include <errno.h> #include "gx.h" @@ -45,17 +46,17 @@ prnt_32regs(struct xg_gdb_regs32 *r32p) static void prnt_64regs(struct xg_gdb_regs64 *r64p) { - printf("rip:"XGF64" rsp:"XGF64" flags:%08x\n", r64p->rip, r64p->rsp, + printf("rip:%016"PRIx64" rsp:%016"PRIx64" flags:%08x\n", r64p->rip, r64p->rsp, r64p->eflags); - printf("rax:"XGF64" rbx:"XGF64" rcx:"XGF64"\n", r64p->rax, r64p->rbx, + printf("rax:%016"PRIx64" rbx:%016"PRIx64" rcx:%016"PRIx64"\n", r64p->rax, r64p->rbx, r64p->rcx); - printf("rdx:"XGF64" rsi:"XGF64" rdi:"XGF64"\n", r64p->rdx, r64p->rsi, + printf("rdx:%016"PRIx64" rsi:%016"PRIx64" rdi:%016"PRIx64"\n", r64p->rdx, r64p->rsi, r64p->rdi); - printf("r08:"XGF64" r09:"XGF64" r10:"XGF64"\n", r64p->r8, r64p->r9, + printf("r08:%016"PRIx64" r09:%016"PRIx64" r10:%016"PRIx64"\n", r64p->r8, r64p->r9, r64p->r10); - printf("r11:"XGF64" r12:"XGF64" r13:"XGF64"\n", r64p->r11, r64p->r12, + printf("r11:%016"PRIx64" r12:%016"PRIx64" r13:%016"PRIx64"\n", r64p->r11, r64p->r12, r64p->r13); - printf("r14:"XGF64" r15:"XGF64" rbp:"XGF64"\n", r64p->r14, r64p->r15, + printf("r14:%016"PRIx64" r15:%016"PRIx64" rbp:%016"PRIx64"\n", r64p->r14, r64p->r15, r64p->rbp); printf("cs:%08x ds:%08x fs:%08x gs:%08x\n", r64p->cs, r64p->ds, r64p->fs, r64p->gs); @@ -92,13 +93,13 @@ prnt_call_trace64(uint64_t ip, uint64_t sp) uint64_t loopmax=0, val; printf("Call Trace:\n"); - printf(" ["XGF64"]\n", ip); + printf(" [%016"PRIx64"]\n", ip); while(stack_max > 0) { if (xg_read_mem(sp, (char *)&val, sizeof(val),0) != 0) return; if (val > 0xffffffff80000000UL) { /* kernel addr */ - printf(" ["XGF64"]\n", val); + printf(" [%016"PRIx64"]\n", val); --stack_max; } sp += sizeof(sp); diff --git a/tools/debugger/gdbsx/gx/gx_main.c b/tools/debugger/gdbsx/gx/gx_main.c index 6dfa501145..15de2c3501 100644 --- a/tools/debugger/gdbsx/gx/gx_main.c +++ b/tools/debugger/gdbsx/gx/gx_main.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> +#include <inttypes.h> #include <unistd.h> #include <string.h> #include <errno.h> @@ -114,9 +115,9 @@ _do_qRcmd_req(char *remote_buf) XGTRC("buf+5:%s pgd3val:0x%llx\n", buf+5, pgd3val); if (*endp == '\0' && pgd3val > 0) { - sprintf(buf1, "pgd3val set to: "XGF64"\n", pgd3val); + sprintf(buf1, "pgd3val set to: %016"PRIx64"\n", pgd3val); } else { - sprintf(buf1, "Invalid pgd3val "XGF64"\n", pgd3val); + sprintf(buf1, "Invalid pgd3val %016"PRIx64"\n", pgd3val); pgd3val = 0; } } else { diff --git a/tools/debugger/gdbsx/xg/xg_public.h b/tools/debugger/gdbsx/xg/xg_public.h index cffb2f7532..31513c8177 100644 --- a/tools/debugger/gdbsx/xg/xg_public.h +++ b/tools/debugger/gdbsx/xg/xg_public.h @@ -21,14 +21,6 @@ #define XGTRC1(...) \ do {(xgtrc_on==2) ? (xgtrc(__FUNCTION__,__VA_ARGS__)):0;} while (0) -#if defined(__x86_64__) - #define XGFM64 "%lx" - #define XGF64 "%016lx" -#else - #define XGFM64 "%llx" - #define XGF64 "%016llx" -#endif - typedef enum { XG_GPRS=1, /* general purpose user regs */ diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c index 3d14d37e62..904204bc2d 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -68,6 +68,18 @@ output(const char *fmt, ...) { output_pos += len; } +static void +output_raw(const char *data, int len) { + if (output_pos + len > output_size) { + output_size += len + 1024; + output_buf = realloc(output_buf, output_size); + if (output_buf == NULL) + err(1, "malloc"); + } + memcpy(&output_buf[output_pos], data, len); + output_pos += len; +} + static void usage(enum mode mode, int incl_mode, const char *progname) { @@ -78,10 +90,10 @@ usage(enum mode mode, int incl_mode, const char *progname) errx(1, "Usage: %s <mode> [-h] [...]", progname); case MODE_read: mstr = incl_mode ? "read " : ""; - errx(1, "Usage: %s %s[-h] [-p] [-s] key [...]", progname, mstr); + errx(1, "Usage: %s %s[-h] [-p] [-s] [-R] key [...]", progname, mstr); case MODE_write: mstr = incl_mode ? "write " : ""; - errx(1, "Usage: %s %s[-h] [-s] key value [...]", progname, mstr); + errx(1, "Usage: %s %s[-h] [-s] [-R] key value [...]", progname, mstr); case MODE_rm: mstr = incl_mode ? "rm " : ""; errx(1, "Usage: %s %s[-h] [-s] [-t] key [...]", progname, mstr); @@ -293,7 +305,8 @@ do_watch(struct xs_handle *xsh, int max_events) static int perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh, - xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int nr_watches) + xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int nr_watches, + int raw) { switch (mode) { case MODE_ls: @@ -322,17 +335,27 @@ perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh } if (prefix) output("%s: ", argv[optind]); - output("%s\n", sanitise_value(&ebuf, val, len)); + if (raw) + output_raw(val, len); + else + output("%s\n", sanitise_value(&ebuf, val, len)); free(val); optind++; break; } case MODE_write: { char *val_spec = argv[optind + 1]; + char *val; unsigned len; - expanding_buffer_ensure(&ebuf, strlen(val_spec)+1); - unsanitise_value(ebuf.buf, &len, val_spec); - if (!xs_write(xsh, xth, argv[optind], ebuf.buf, len)) { + if (raw) { + val = val_spec; + len = strlen(val_spec); + } else { + expanding_buffer_ensure(&ebuf, strlen(val_spec)+1); + unsanitise_value(ebuf.buf, &len, val_spec); + val = ebuf.buf; + } + if (!xs_write(xsh, xth, argv[optind], val, len)) { warnx("could not write path %s", argv[optind]); return 1; } @@ -506,6 +529,7 @@ main(int argc, char **argv) int recurse = 0; int nr_watches = -1; int transaction; + int raw = 0; struct winsize ws; enum mode mode; @@ -539,10 +563,11 @@ main(int argc, char **argv) {"upto", 0, 0, 'u'}, /* MODE_chmod */ {"recurse", 0, 0, 'r'}, /* MODE_chmod */ {"number", 1, 0, 'n'}, /* MODE_watch */ + {"raw", 0, 0, 'R'}, /* MODE_read || MODE_write */ {0, 0, 0, 0} }; - c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:", + c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:R", long_options, &index); if (c == -1) break; @@ -593,6 +618,12 @@ main(int argc, char **argv) else usage(mode, switch_argv, argv[0]); break; + case 'R': + if ( mode == MODE_read || mode == MODE_write ) + raw = 1; + else + usage(mode, switch_argv, argv[0]); + break; } } @@ -646,7 +677,7 @@ again: errx(1, "couldn't start transaction"); } - ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches); + ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches, raw); if (transaction && !xs_transaction_end(xsh, xth, ret)) { if (ret == 0 && errno == EAGAIN) { @@ -657,7 +688,7 @@ again: } if (output_pos) - printf("%s", output_buf); + fwrite(output_buf, 1, output_pos, stdout); free(output_buf); free(ebuf.buf); -- 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |