From patchwork Fri Nov 2 00:46:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 992157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mNhR24jYz9sDr for ; Fri, 2 Nov 2018 11:47:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t0gmuC7M"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42mNhQ2CSSzDqRM for ; Fri, 2 Nov 2018 11:47:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t0gmuC7M"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t0gmuC7M"; dkim-atps=neutral Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42mNgr0BnHzF31k for ; Fri, 2 Nov 2018 11:47:03 +1100 (AEDT) Received: by mail-pg1-x542.google.com with SMTP id q5-v6so176236pgv.0 for ; Thu, 01 Nov 2018 17:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pbdrzYYlj2EmyhMSYeCOkd56dZh0iByLs1AKQ53WV+8=; b=t0gmuC7Mw4ZKYoFqP8Whz1VWy7UNOtddek7zR2kiVeEIoFKxNf/9V8nRI0OF2bTDG1 B312HzJL2Am2GRd3tzIvA5n5Yws1pYhrN87HAyA00MzGzQGINEj1VvAZKcfgB0XJIfpc /v6Q5uO+EvKtYlN9nvywU1HkiVW0dmiGhLPQv3tHwYTGghUZ+/WYT2YJ/eyfXv+N2YbU yJ9zTGm3r6nAVgu9JZAXi7epkxNC0VOzUHx+PN/FBxz1lrW6AF8rEvS1mLHM8Q+bji8v keaWQRa3GTiV/Py8cf0jHeum4ygihdK/aEdQNnwq1BW7gl2ONAXcKuxBBiP9L5qrRPay dbDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pbdrzYYlj2EmyhMSYeCOkd56dZh0iByLs1AKQ53WV+8=; b=otlhDc5U80PVxQpizVrLMJBfLhVkXitRriLXFWUmDdvTotZTQNPELQSn3zXH6FgfZq LK++zE4hSOOG/sTct1F1FlPwFz+KYRK8Fuiq7PDPw2xGFeTanG+HF+UOjYP8wissydWy bmZ7V3Ff5/bJxIc9ew9iupRWDc8vds2SC39tVvUCYf6gQcHr0fQi3JYqiHobYeS7R8Kq CyDN9hDKnZpJzJyMUNQnG8YfVa4g34XHWwQsdLM9iZgm6nhZcORZ9GxdsS3UyD6NS8oR EmnqFZBFUB5pZh921YBQMzxcc73QKGFoVFkU3NUOaZFb8NUQbATqvbDoVQtKJlB2bYiV 5ujw== X-Gm-Message-State: AGRZ1gJJkJER3ST7UZF4sflY74E6eSQioHAgpnj9IGFF/tLuRxSx2L9W cC0Kg+mVhrTAgq5xBIv8QGvZxxfa X-Google-Smtp-Source: AJdET5exZdsn//sElgtSSnwDJxpqatV1t9WolbgJzNI+bcvlExr1w15nf4rLzAqpxSF1IoSbx1n2kQ== X-Received: by 2002:a62:2f44:: with SMTP id v65-v6mr9696514pfv.235.1541119621506; Thu, 01 Nov 2018 17:47:01 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id d29-v6sm53736243pgm.56.2018.11.01.17.46.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 17:47:00 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Fri, 2 Nov 2018 11:46:41 +1100 Message-Id: <20181102004644.23047-2-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181102004644.23047-1-rashmica.g@gmail.com> References: <20181102004644.23047-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v4 1/4] pdbg/gdbserver: Add in basic skeleton for a gdbserver on p8 X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: npiggin@gmail.com MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" I have changed a few bits here and there but this patch is largely authored by Alistair Popple. From: Alistair Popple Signed-off-by: Rashmica Gupta --- .gitignore | 1 + Makefile.am | 13 +- configure.ac | 3 + libpdbg/libpdbg.h | 1 + libpdbg/operations.h | 3 - libpdbg/target.h | 1 + src/gdb_parser.rl | 146 ++++++++++++ src/main.c | 6 +- src/pdbgproxy.c | 547 +++++++++++++++++++++++++++++++++++++++++++ src/pdbgproxy.h | 13 + 10 files changed, 727 insertions(+), 7 deletions(-) create mode 100644 src/gdb_parser.rl create mode 100644 src/pdbgproxy.c create mode 100644 src/pdbgproxy.h diff --git a/.gitignore b/.gitignore index c25b053..79f1ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ optcmd_test *.trs *.log test-driver +src/gdb_parser.c diff --git a/Makefile.am b/Makefile.am index 0d451d3..fb2b812 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,7 +83,9 @@ pdbg_SOURCES = \ src/optcmd.h \ src/options.h \ src/parsers.h \ - src/progress.h + src/progress.h \ + src/pdbgproxy.c \ + src/gdb_parser.c src/main.c: $(DT_headers) @@ -194,6 +196,10 @@ GEN_V = $(GEN_V_$(V)) GEN_V_ = $(GEN_V_$(AM_DEFAULT_VERBOSITY)) GEN_V_0 = @echo " GEN " $@; +RAGEL_V = $(RAGEL_V_$(V)) +RAGEL_V_ = $(RAGEL_V_$(AM_DEFAULT_VERBOSITY)) +RAGEL_V_0 = @echo " RAGEL " $@; + %.dts: %.dts.m4 $(M4_V)$(M4) -I$(dir $<) $< | $(DTC) -I dts -O dts > $@ @@ -214,4 +220,7 @@ p9z-fsi.dts: p9z-fsi.dts.m4 p9-fsi.dtsi %.dtb.o: %.dtb $(AM_V_CC)$(CC) -c $(srcdir)/template.S -DSYMBOL_PREFIX=$(shell echo $@ | tr '.-' '_') -DFILENAME=\"$<\" -o $@ -MOSTLYCLEANFILES = *.dtb *.dts *.dt.h p9-fsi.dtsi +%.c: %.rl + $(RAGEL_V)$(RAGEL) -o $@ $< + +MOSTLYCLEANFILES = *.dtb *.dts *.dt.h p9-fsi.dtsi src/gdb_parser.c diff --git a/configure.ac b/configure.ac index e6939e0..05c002e 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,9 @@ if test x"$ac_cv_path_DTC" = x ; then fi AC_SUBST([DTC]) +AC_PATH_PROG([RAGEL], [ragel]) +AC_SUBST([RAGEL]) + AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index c54e852..1977c75 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -139,6 +139,7 @@ struct thread_regs { }; int ram_putmsr(struct pdbg_target *target, uint64_t val); +int ram_getmem(struct pdbg_target *thread, uint64_t addr, uint64_t *value); int ram_putnia(struct pdbg_target *target, uint64_t val); int ram_putspr(struct pdbg_target *target, int spr, uint64_t val); int ram_putgpr(struct pdbg_target *target, int spr, uint64_t val); diff --git a/libpdbg/operations.h b/libpdbg/operations.h index 4a6db2f..dc5042a 100644 --- a/libpdbg/operations.h +++ b/libpdbg/operations.h @@ -70,9 +70,6 @@ #define MXSPR_SPR(opcode) (((opcode >> 16) & 0x1f) | ((opcode >> 6) & 0x3e0)) -/* GDB server functionality */ -int gdbserver_start(uint16_t port); - enum fsi_system_type {FSI_SYSTEM_P8, FSI_SYSTEM_P9W, FSI_SYSTEM_P9R, FSI_SYSTEM_P9Z}; enum chip_type get_chip_type(uint64_t chip_id); diff --git a/libpdbg/target.h b/libpdbg/target.h index c8da048..d1a6aec 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -165,4 +165,5 @@ struct chiplet { int (*getring)(struct chiplet *, uint64_t, int64_t, uint32_t[]); }; #define target_to_chiplet(x) container_of(x, struct chiplet, target) + #endif diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl new file mode 100644 index 0000000..6259b96 --- /dev/null +++ b/src/gdb_parser.rl @@ -0,0 +1,146 @@ +#include +#include +#include +#include + +#include "src/pdbgproxy.h" + +%%{ + machine gdb; + + action reset { + cmd = 0; + rsp = NULL; + data = stack; + memset(stack, 0, sizeof(stack)); + crc = 0; + } + + action crc { + crc += *p; + } + + action push { + data++; + assert(data < &stack[10]); + } + + action hex_digit { + *data *= 16; + + if (*p >= '0' && *p <= '9') + *data += *p - '0'; + else if (*p >= 'a' && *p <= 'f') + *data += *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + *data += *p - 'A' + 10; + } + + action end { + /* *data should point to the CRC */ + if (crc != *data) { + printf("CRC error\n"); + send_nack(priv); + } else { + printf("Cmd %d\n", cmd); + send_ack(priv); + + /* Push the response onto the stack */ + if (rsp) + *data = (uintptr_t)rsp; + else + *data = 0; + + command_callbacks[cmd](stack, priv); + } + } + + get_mem = ('m' @{cmd = GET_MEM;} + xdigit+ $hex_digit %push + ',' + xdigit+ $hex_digit %push); + + put_mem = ('M' any* @{cmd = PUT_MEM;} + xdigit+ $hex_digit %push + ',' + xdigit+ $hex_digit %push + ':' + xdigit+ $hex_digit %push); + + get_gprs = ('g' @{cmd = GET_GPRS;}); + + get_spr = ('p' @{cmd = GET_SPR;} + xdigit+ $hex_digit %push); + + stop_reason = ('?' @{cmd = STOP_REASON;}); + + set_thread = ('H' any* @{cmd = SET_THREAD;}); + + disconnect = ('D' @{cmd = DISCONNECT;} + xdigit+ $hex_digit %push); + + # TODO: We don't actually listen to what's supported + q_attached = ('qAttached:' xdigit* @{rsp = "1";}); + q_C = ('qC' @{rsp = "QC1";}); + q_supported = ('qSupported:' any* @{rsp = "multiprocess+;vContSupported+";}); + qf_threadinfo = ('qfThreadInfo' @{rsp = "m1l";}); + + # vCont packet parsing + v_contq = ('vCont?' @{rsp = "vCont;c;C;s;S";}); + v_contc = ('vCont;c' any* @{cmd = V_CONTC;}); + v_conts = ('vCont;s' any* @{cmd = V_CONTS;}); + + interrupt = (3 @{command_callbacks[INTERRUPT](stack, priv);}); + + commands = (get_mem | get_gprs | get_spr | stop_reason | set_thread | + q_attached | q_C | q_supported | qf_threadinfo | q_C | + v_contq | v_contc | v_conts | put_mem | disconnect ); + + cmd = ((commands & ^'#'*) | ^'#'*) $crc + ('#' xdigit{2} $hex_digit @end); + + # We ignore ACK/NACK for the moment + ack = ('+'); + nack = ('-'); + + main := (( ^('$' | interrupt)*('$' | interrupt) @reset) (cmd | ack | nack))*; + +}%% + +static enum gdb_command cmd = NONE; +static uint64_t stack[10], *data = stack; +static char *rsp; +static uint8_t crc; +static int cs; + +command_cb *command_callbacks; + +%%write data; + +void parser_init(command_cb *callbacks) +{ + %%write init; + + command_callbacks = callbacks; +} + +int parse_buffer(char *buf, size_t len, void *priv) +{ + char *p = buf; + char *pe = p + len + 1; + + %%write exec; + + return 0; +} + +#if 0 +int main(int argc, char **argv) +{ + parser_init(NULL); + + if (argc > 1) + parse_buffer(argv[1], strlen(argv[1]), NULL); + return 0; +} +#endif diff --git a/src/main.c b/src/main.c index 4966d51..8ee0e38 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ #include "options.h" #include "optcmd.h" #include "progress.h" +#include "pdbgproxy.h" #define PR_ERROR(x, args...) \ pdbg_log(PDBG_ERROR, x, ##args) @@ -88,7 +89,7 @@ extern struct optcmd_cmd optcmd_getring, optcmd_start, optcmd_stop, optcmd_step, optcmd_threadstatus, optcmd_sreset, optcmd_regs, optcmd_probe, optcmd_getmem, optcmd_putmem, optcmd_getxer, optcmd_putxer, - optcmd_getcr, optcmd_putcr; + optcmd_getcr, optcmd_putcr, optcmd_gdbserver; static struct optcmd_cmd *cmds[] = { &optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam, @@ -97,7 +98,7 @@ static struct optcmd_cmd *cmds[] = { &optcmd_getring, &optcmd_start, &optcmd_stop, &optcmd_step, &optcmd_threadstatus, &optcmd_sreset, &optcmd_regs, &optcmd_probe, &optcmd_getmem, &optcmd_putmem, &optcmd_getxer, &optcmd_putxer, - &optcmd_getcr, &optcmd_putcr, + &optcmd_getcr, &optcmd_putcr, &optcmd_gdbserver, }; /* Purely for printing usage text. We could integrate printing argument and flag @@ -136,6 +137,7 @@ static struct action actions[] = { { "threadstatus", "", "Print the status of a thread" }, { "sreset", "", "Reset" }, { "regs", "[--backtrace]", "State (optionally display backtrace)" }, + { "gdbserver", "", "Start a gdb server" }, }; static void print_usage(char *pname) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c new file mode 100644 index 0000000..5ccadfc --- /dev/null +++ b/src/pdbgproxy.c @@ -0,0 +1,547 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "pdbgproxy.h" +#include "main.h" +#include "optcmd.h" +#include "debug.h" +#include "chip.h" + +/* Maximum packet size */ +#define BUFFER_SIZE 8192 + +/* GDB packets */ +#define STR(e) "e" +#define ACK "+" +#define NACK "-" +#define OK "OK" +#define TRAP "S05" +#define ERROR(e) "E"STR(e) + +#define TEST_SKIBOOT_ADDR 0x40000000 + +static struct pdbg_target *thread_target = NULL; +static struct timeval timeout; +static int poll_interval = 100; +static int fd = -1; +static int littleendian = 1; +enum client_state {IDLE, SIGNAL_WAIT}; +static enum client_state state = IDLE; + +static void destroy_client(int dead_fd); + +static uint8_t gdbcrc(char *data) +{ + uint8_t crc = 0; + int i; + + for (i = 0; i < strlen(data); i++) + crc += data[i]; + + return crc; +} + +static void send_response(int fd, char *response) +{ + int len; + char *result; + + len = asprintf(&result, "$%s#%02x", response, gdbcrc(response)); + PR_INFO("Send: %s\n", result); + send(fd, result, len, 0); + free(result); +} + +void send_nack(void *priv) +{ + PR_INFO("Send: -\n"); + send(fd, NACK, 1, 0); +} + +void send_ack(void *priv) +{ + PR_INFO("Send: +\n"); + send(fd, ACK, 1, 0); +} + +static void set_thread(uint64_t *stack, void *priv) +{ + send_response(fd, OK); +} + +static void stop_reason(uint64_t *stack, void *priv) +{ + send_response(fd, TRAP); +} + +static void disconnect(uint64_t *stack, void *priv) +{ + PR_INFO("Terminating connection with client. pid %16" PRIi64 "\n", stack[0]); + send_response(fd, OK); +} + +/* 32 registers represented as 16 char hex numbers with null-termination */ +#define REG_DATA_SIZE (32*16+1) +static void get_gprs(uint64_t *stack, void *priv) +{ + char data[REG_DATA_SIZE] = ""; + struct thread_regs regs; + int i; + + if(ram_state_thread(thread_target, ®s)) + PR_ERROR("Error reading gprs\n"); + + for (i = 0; i < 32; i++) { + PR_INFO("r%d = 0x%016" PRIx64 "\n", i, regs.gprs[i]); + snprintf(data + i*16, 17, "%016" PRIx64 , __builtin_bswap64(regs.gprs[i])); + } + + send_response(fd, data); +} + +static void get_spr(uint64_t *stack, void *priv) +{ + char data[REG_DATA_SIZE]; + uint64_t value; + + switch (stack[0]) { + case 0x40: + /* Get PC/NIA */ + if (ram_getnia(thread_target, &value)) + PR_ERROR("Error reading NIA\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , __builtin_bswap64(value)); + send_response(fd, data); + break; + + case 0x41: + /* Get MSR */ + if (ram_getmsr(thread_target, &value)) + PR_ERROR("Error reading MSR\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , __builtin_bswap64(value)); + send_response(fd, data); + break; + + case 0x42: + /* Get CR */ + if (ram_getcr(thread_target, (uint32_t *)&value)) + PR_ERROR("Error reading CR \n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , __builtin_bswap64(value)); + send_response(fd, data); + break; + + case 0x43: + /* Get LR */ + if (ram_getspr(thread_target, 8, &value)) + PR_ERROR("Error reading LR\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , __builtin_bswap64(value)); + send_response(fd, data); + break; + + case 0x44: + /* Get CTR */ + if (ram_getspr(thread_target, 9, &value)) + PR_ERROR("Error reading CTR\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , __builtin_bswap64(value)); + send_response(fd, data); + break; + + case 0x45: + /* We can't get the whole XER register in RAM mode as part of it + * is in latches that we need to stop the clocks to get. Probably + * not helpful to only return part of a register in a debugger so + * return unavailable. */ + send_response(fd, "xxxxxxxxxxxxxxxx"); + break; + + default: + send_response(fd, "xxxxxxxxxxxxxxxx"); + break; + } +} + +#define MAX_DATA 0x1000 + +/* Returns a real address to use with adu_getmem or -1UL if we + * couldn't determine a real address. At the moment we only deal with + * kernel linear mapping but in future we could walk that page + * tables. */ +static uint64_t get_real_addr(uint64_t addr) +{ + if (GETFIELD(PPC_BITMASK(0, 3), addr) == 0xc) + /* Assume all 0xc... addresses are part of the linux linear map */ + addr &= ~PPC_BITMASK(0, 1); + else if (addr < TEST_SKIBOOT_ADDR) + return addr; + else + addr = -1UL; + + return addr; +} + +static void get_mem(uint64_t *stack, void *priv) +{ + struct pdbg_target *adu; + uint64_t addr, len, linear_map; + int i, err = 0; + uint64_t data[MAX_DATA/sizeof(uint64_t)]; + char result[2*MAX_DATA]; + + /* stack[0] is the address and stack[1] is the length */ + addr = stack[0]; + len = stack[1]; + + pdbg_for_each_class_target("adu", adu) { + if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) + break; + } + + if (adu == NULL) { + PR_ERROR("ADU NOT FOUND\n"); + err=3; + goto out; + } + + if (len > MAX_DATA) { + PR_INFO("Too much memory requested, truncating\n"); + len = MAX_DATA; + } + + if (!addr) { + err = 2; + goto out; + } + + linear_map = get_real_addr(addr); + if (linear_map != -1UL) { + if (adu_getmem(adu, linear_map, (uint8_t *) data, len)) { + PR_ERROR("Unable to read memory\n"); + err = 1; + } + } else { + /* Virtual address */ + for (i = 0; i < len; i += sizeof(uint64_t)) { + if (ram_getmem(thread_target, addr, &data[i/sizeof(uint64_t)])) { + PR_ERROR("Fault reading memory\n"); + err = 2; + break; + } + } + } + +out: + if (!err) + for (i = 0; i < len; i ++) { + sprintf(&result[i*2], "%02x", *(((uint8_t *) data) + i)); + } + else + sprintf(result, "E%02x", err); + + send_response(fd, result); +} + +static void put_mem(uint64_t *stack, void *priv) +{ + struct pdbg_target *adu; + uint64_t addr, len; + uint8_t *data; + uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; + int err = 0; + struct thread *thread = target_to_thread(thread_target); + + if (littleendian) { + attn_opcode[1] = 0x02; + attn_opcode[2] = 0x00; + } + + addr = stack[0]; + len = stack[1]; + data = (uint8_t *) &stack[2]; + + pdbg_for_each_class_target("adu", adu) { + if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) + break; + } + + if (adu == NULL) { + PR_ERROR("ADU NOT FOUND\n"); + err=3; + goto out; + } + + addr = get_real_addr(addr); + if (addr == -1UL) { + PR_ERROR("TODO: No virtual address support for putmem\n"); + err = 1; + goto out; + } + + + if (len == 4 && stack[2] == 0x0810827d) { + /* According to linux-ppc-low.c gdb only uses this + * op-code for sw break points so we replace it with + * the correct attn opcode which is what we need for + * breakpoints. + * + * TODO: Upstream a patch to gdb so that it uses the + * right opcode for baremetal debug. */ + PR_INFO("Breakpoint opcode detected, replacing with attn\n"); + data = attn_opcode; + + /* Need to enable the attn instruction in HID0 */ + if (thread->enable_attn(thread_target)) + goto out; + } else + stack[2] = __builtin_bswap64(stack[2]) >> 32; + + PR_INFO("put_mem 0x%016" PRIx64 " = 0x%016" PRIx64 "\n", addr, stack[2]); + + if (adu_putmem(adu, addr, data, len)) { + PR_ERROR("Unable to write memory\n"); + err = 3; + } + +out: + if (err) + send_response(fd, ERROR(EPERM)); + else + send_response(fd, OK); +} + +static void v_conts(uint64_t *stack, void *priv) +{ + ram_step_thread(thread_target, 1); + send_response(fd, TRAP); +} + +#define VCONT_POLL_DELAY 100000 +static void v_contc(uint64_t *stack, void *priv) +{ + ram_start_thread(thread_target); + state = SIGNAL_WAIT; + poll_interval = 1; +} + +static void interrupt(uint64_t *stack, void *priv) +{ + PR_INFO("Interrupt\n"); + ram_stop_thread(thread_target); + send_response(fd, TRAP); + + return; +} + +static void poll(void) +{ + uint64_t nia; + struct thread_state status; + + thread_target->probe(thread_target); + status = thread_status(thread_target); + + switch (state) { + case IDLE: + break; + + case SIGNAL_WAIT: + if (!(status.quiesced)) + break; + + state = IDLE; + poll_interval = VCONT_POLL_DELAY; + if (!(status.active)) { + PR_ERROR("Thread inactive after trap\n"); + send_response(fd, ERROR(EPERM)); + return; + } + + /* Restore NIA */ + if (ram_getnia(thread_target, &nia)) + PR_ERROR("Error during getnia\n"); + if (ram_putnia(thread_target, nia - 4)) + PR_ERROR("Error during putnia\n"); + send_response(fd, TRAP); + break; + } +} + +static void cmd_default(uint64_t *stack, void *priv) +{ + uintptr_t tmp = stack[0]; + if (stack[0]) { + send_response(fd, (char *) tmp); + } else + send_response(fd, ""); +} + +static void create_client(int new_fd) +{ + PR_INFO("Client connected\n"); + fd = new_fd; +} + +static void destroy_client(int dead_fd) +{ + PR_INFO("Client disconnected\n"); + close(dead_fd); + fd = -1; +} + +static int read_from_client(int fd) +{ + char buffer[BUFFER_SIZE + 1]; + int nbytes; + + nbytes = read(fd, buffer, sizeof(buffer)); + if (nbytes < 0) { + perror(__FUNCTION__); + return -1; + } else if (nbytes == 0) { + PR_INFO("0 bytes\n"); + return -1; + } else { + buffer[nbytes] = '\0'; + PR_INFO("%x\n", buffer[0]); + PR_INFO("Recv: %s\n", buffer); + parse_buffer(buffer, nbytes, &fd); + } + + return 0; +} + +command_cb callbacks[LAST_CMD + 1] = { + cmd_default, + get_gprs, + get_spr, + get_mem, + stop_reason, + set_thread, + v_contc, + v_conts, + put_mem, + interrupt, + disconnect, + NULL}; + +int gdbserver_start(struct pdbg_target *target, uint16_t port) +{ + int sock, i; + struct sockaddr_in name; + fd_set active_fd_set, read_fd_set; + + parser_init(callbacks); + thread_target = target; + + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) { + perror(__FUNCTION__); + return -1; + } + + name.sin_family = AF_INET; + name.sin_port = htons(port); + name.sin_addr.s_addr = htonl(INADDR_ANY); + if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) { + perror(__FUNCTION__); + return -1; + } + + if (listen(sock, 1) < 0) { + perror(__FUNCTION__); + return -1; + } + + FD_ZERO(&active_fd_set); + FD_SET(sock, &active_fd_set); + + while (1) { + read_fd_set = active_fd_set; + timeout.tv_sec = 0; + timeout.tv_usec = poll_interval; + if (select(FD_SETSIZE, &read_fd_set, NULL, NULL, &timeout) < 0) { + perror(__FUNCTION__); + return -1; + } + + for (i = 0; i < FD_SETSIZE; i++) { + if (FD_ISSET(i, &read_fd_set)) { + if (i == sock) { + int new; + new = accept(sock, NULL, NULL); + if (new < 0) { + perror(__FUNCTION__); + return -1; + } + + if (fd > 0) + /* It only makes sense to accept a single client */ + close(new); + else { + create_client(new); + FD_SET(new, &active_fd_set); + } + } else { + if (read_from_client(i) < 0) { + destroy_client(i); + FD_CLR(i, &active_fd_set); + } + } + } + } + + poll(); + } + + return 1; +} + +static int gdbserver(uint16_t port) +{ + struct pdbg_target *target = NULL; + uint64_t msr; + int rc; + + for_each_class_target("thread", target) { + if (!target_selected(target)) + continue; + if (pdbg_target_probe(target) == PDBG_TARGET_ENABLED) + break; + } + if (!target->class) + return -1; + assert(!strcmp(target->class, "thread")); + // Temporary until I can get this working a bit smoother on p9 + if (strcmp(target->compatible, "ibm,power8-thread")) { + PR_ERROR("GDBSERVER is only tested on POWER8\n"); + return -1; + } + + /* Check endianess in MSR */ + rc = ram_getmsr(target, &msr); + if (rc) { + PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); + return 1; + } + littleendian = 0x01 & msr; + + gdbserver_start(target, port); + return 0; +} +OPTCMD_DEFINE_CMD_WITH_ARGS(gdbserver, gdbserver, (DATA16)); diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h new file mode 100644 index 0000000..1fe67f2 --- /dev/null +++ b/src/pdbgproxy.h @@ -0,0 +1,13 @@ +#ifndef __PDBGPROXY_H +#define __PDBGPROXY_H + +enum gdb_command {NONE, GET_GPRS, GET_SPR, GET_MEM, + STOP_REASON, SET_THREAD, V_CONTC, V_CONTS, + PUT_MEM, INTERRUPT, DISCONNECT, LAST_CMD}; +typedef void (*command_cb)(uint64_t *stack, void *priv); + +void parser_init(command_cb *callbacks); +int parse_buffer(char *buf, size_t len, void *priv); +void send_nack(void *priv); +void send_ack(void *priv); +#endif From patchwork Fri Nov 2 00:46:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 992158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mNhV0dchz9sMr for ; Fri, 2 Nov 2018 11:47:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BU3drlHv"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42mNhT5rnMzF31R for ; Fri, 2 Nov 2018 11:47:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BU3drlHv"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::543; helo=mail-pg1-x543.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BU3drlHv"; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42mNgv3ndgzF31W for ; Fri, 2 Nov 2018 11:47:07 +1100 (AEDT) Received: by mail-pg1-x543.google.com with SMTP id q5-v6so176299pgv.0 for ; Thu, 01 Nov 2018 17:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0miq0Ev84xSy6ni3aVldPv/pmgkDozp7j1Bznv9NJ+0=; b=BU3drlHv0vhFJTjsYcldLz6zKQA43zjb3BV9afQrsEqEocoXEz+PtErJ+dx0N0lfB4 gPlzZ//hdI+WwPoZ12ly8Zo2k5Y48SSRp62aDFUeoXHUt4jjdvQOiQz8D4Zu8iUL4wK8 S3GUbclLvriiw2Cr2yJvcxy85XXIMXecq/fUQqdRtdpTR+Ev3yr34qx4St4ZbQfm8Dfs ddeQsF/Ld9GnGX8H1SHZZ6rehS8rz1k7xIZh9cApMX5LZHv5BDA51daxyd5pYRrlaRVd xUuDvFmbI+VDF1BaSE7F671C46J3H6Yn4Vw+PxFYbgtowcfVAba5iovfFQcsHK/MbRIs BFIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0miq0Ev84xSy6ni3aVldPv/pmgkDozp7j1Bznv9NJ+0=; b=gmOvYkbZ7CiPEIsDYmYF7ad1Snb9g9pn8ayoxbSBk4n21x8fVrLHIOZlppZWBBk/zo 4TP242i9dgCIv78znurOeXlhCaJ8pfkQm08DTW8DPEMF2ZDORAYKzkdXeWe16ZRpOX8a 2LuKJE6NMCODJdh+PYbL6iNsd2DyWB1xGDMIBY3jBBNDaWDnww2judCKwP6f7nfEr+GR kRsp6JYzoEdYqZlM82r2Vtgxd9QiiKVVbdGWaE24b/ghs9I+b70egZC1mU5+38K5xV+4 ZAwZetCG+7QTYFSlT1ksTW2wHUj/Z2gJKVfjiF0gbbeBjxBMKFogd3PpL/eVL7W1gsIc /qFg== X-Gm-Message-State: AGRZ1gJ6JHE5WRAwWweBhn9TR3qnSxkHR/upkGyAFYzdGbPa11VPNlXK bL/uSvjQgXBxOSEHyD/dOoxdMnl9 X-Google-Smtp-Source: AJdET5cPyflI32xQPILqVKbD27j7IRZUuTlhnfnD00qF6URtuP79Bo0s3v/KjxFxd1USeCUJomJMUQ== X-Received: by 2002:a63:4745:: with SMTP id w5mr9260185pgk.377.1541119625196; Thu, 01 Nov 2018 17:47:05 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id d29-v6sm53736243pgm.56.2018.11.01.17.47.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 17:47:04 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Fri, 2 Nov 2018 11:46:42 +1100 Message-Id: <20181102004644.23047-3-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181102004644.23047-1-rashmica.g@gmail.com> References: <20181102004644.23047-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v4 2/4] pdbg/gdbserver: Make ragel optional X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: npiggin@gmail.com MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" From: Alistair Popple Add in the generated c file so if the build system doesn't have ragel gdbserver can still be built. Signed-off-by: Rashmica Gupta --- Makefile.am | 6 + configure.ac | 1 + src/gdb_parser_precompile.c | 410 ++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+) create mode 100644 src/gdb_parser_precompile.c diff --git a/Makefile.am b/Makefile.am index fb2b812..5a9d239 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,12 @@ DT_headers = $(DT:.dts=.dt.h) optcmd_test_SOURCES = src/optcmd.c src/parsers.c src/tests/optcmd_test.c optcmd_test_CFLAGS = -Wall -g +if HAVE_RAGEL +extra_sources = src/gdb_parser.c +else +extra_sources = src/gdb_parser_precompile.c +endif + pdbg_SOURCES = \ src/main.c \ src/cfam.c \ diff --git a/configure.ac b/configure.ac index 05c002e..0fbf8ae 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,7 @@ AC_SUBST([DTC]) AC_PATH_PROG([RAGEL], [ragel]) AC_SUBST([RAGEL]) +AM_CONDITIONAL([HAVE_RAGEL], [test x"$ac_cv_path_RAGEL" != "x"]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c new file mode 100644 index 0000000..715cdd7 --- /dev/null +++ b/src/gdb_parser_precompile.c @@ -0,0 +1,410 @@ + +#line 1 "src/gdb_parser.rl" +#include +#include +#include +#include + +#include "pdbgproxy.h" + + +#line 105 "src/gdb_parser.rl" + + +static enum gdb_command cmd = NONE; +static uint64_t stack[10], *data = stack; +static char *rsp; +static uint8_t crc; +static int cs; + +command_cb *command_callbacks; + + +#line 24 "src/gdb_parser.c" +static const char _gdb_actions[] = { + 0, 1, 0, 1, 1, 1, 2, 1, + 3, 2, 1, 0, 2, 2, 1, 2, + 3, 1, 2, 3, 4, 2, 5, 1, + 2, 6, 1, 2, 7, 1, 2, 8, + 1, 2, 9, 1, 2, 10, 1, 2, + 11, 1, 2, 12, 1, 2, 13, 1, + 2, 14, 1, 2, 15, 1, 2, 16, + 1, 2, 17, 1, 2, 18, 0, 3, + 1, 18, 0, 3, 6, 2, 1, 3, + 6, 3, 1 +}; + +static const char _gdb_key_offsets[] = { + 0, 0, 2, 13, 14, 20, 26, 29, + 37, 45, 46, 53, 61, 68, 77, 84, + 92, 99, 107, 114, 121, 126, 128, 130, + 132, 134, 136, 138, 140, 142, 149, 151, + 153, 155, 157, 159, 161, 163, 165, 167, + 168, 170, 172, 174, 176, 178, 180, 182, + 184, 186, 188, 190, 192, 194, 196, 199, + 202, 203, 204, 206 +}; + +static const char _gdb_trans_keys[] = { + 3, 36, 35, 43, 45, 63, 72, 77, + 103, 109, 112, 113, 118, 35, 48, 57, + 65, 70, 97, 102, 48, 57, 65, 70, + 97, 102, 3, 35, 36, 3, 36, 48, + 57, 65, 70, 97, 102, 3, 36, 48, + 57, 65, 70, 97, 102, 35, 35, 48, + 57, 65, 70, 97, 102, 35, 44, 48, + 57, 65, 70, 97, 102, 35, 48, 57, + 65, 70, 97, 102, 35, 44, 58, 48, + 57, 65, 70, 97, 102, 35, 48, 57, + 65, 70, 97, 102, 35, 44, 48, 57, + 65, 70, 97, 102, 35, 48, 57, 65, + 70, 97, 102, 35, 44, 48, 57, 65, + 70, 97, 102, 35, 48, 57, 65, 70, + 97, 102, 35, 48, 57, 65, 70, 97, + 102, 35, 65, 67, 83, 102, 35, 116, + 35, 116, 35, 97, 35, 99, 35, 104, + 35, 101, 35, 100, 35, 58, 35, 48, + 57, 65, 70, 97, 102, 35, 117, 35, + 112, 35, 112, 35, 111, 35, 114, 35, + 116, 35, 101, 35, 100, 35, 58, 35, + 35, 84, 35, 104, 35, 114, 35, 101, + 35, 97, 35, 100, 35, 73, 35, 110, + 35, 102, 35, 111, 35, 67, 35, 111, + 35, 110, 35, 116, 35, 59, 63, 35, + 99, 115, 35, 35, 3, 36, 3, 35, + 36, 0 +}; + +static const char _gdb_single_lengths[] = { + 0, 2, 11, 1, 0, 0, 3, 2, + 2, 1, 1, 2, 1, 3, 1, 2, + 1, 2, 1, 1, 5, 2, 2, 2, + 2, 2, 2, 2, 2, 1, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 1, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, + 1, 1, 2, 3 +}; + +static const char _gdb_range_lengths[] = { + 0, 0, 0, 0, 3, 3, 0, 3, + 3, 0, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; + +static const short _gdb_index_offsets[] = { + 0, 0, 3, 15, 17, 21, 25, 29, + 35, 41, 43, 48, 54, 59, 66, 71, + 77, 82, 88, 93, 98, 104, 107, 110, + 113, 116, 119, 122, 125, 128, 133, 136, + 139, 142, 145, 148, 151, 154, 157, 160, + 162, 165, 168, 171, 174, 177, 180, 183, + 186, 189, 192, 195, 198, 201, 204, 208, + 212, 214, 216, 219 +}; + +static const char _gdb_indicies[] = { + 1, 2, 0, 4, 5, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 3, 4, + 3, 14, 14, 14, 15, 16, 16, 16, + 15, 18, 19, 20, 17, 1, 2, 21, + 21, 21, 0, 1, 2, 16, 16, 16, + 0, 4, 22, 4, 24, 24, 24, 23, + 4, 25, 24, 24, 24, 23, 4, 26, + 26, 26, 23, 4, 25, 27, 26, 26, + 26, 23, 4, 28, 28, 28, 23, 29, + 25, 28, 28, 28, 23, 4, 30, 30, + 30, 3, 4, 31, 30, 30, 30, 3, + 4, 32, 32, 32, 3, 29, 32, 32, + 32, 3, 4, 33, 34, 35, 36, 3, + 4, 37, 3, 4, 38, 3, 4, 39, + 3, 4, 40, 3, 4, 41, 3, 4, + 42, 3, 4, 43, 3, 4, 44, 3, + 4, 45, 45, 45, 3, 4, 46, 3, + 4, 47, 3, 4, 48, 3, 4, 49, + 3, 4, 50, 3, 4, 51, 3, 4, + 52, 3, 4, 53, 3, 4, 54, 3, + 4, 55, 4, 56, 3, 4, 57, 3, + 4, 58, 3, 4, 59, 3, 4, 60, + 3, 4, 61, 3, 4, 62, 3, 4, + 63, 3, 4, 64, 3, 4, 65, 3, + 4, 66, 3, 4, 67, 3, 4, 68, + 3, 4, 69, 3, 4, 70, 71, 3, + 4, 72, 73, 3, 4, 74, 4, 75, + 1, 2, 0, 18, 19, 20, 17, 0 +}; + +static const char _gdb_trans_targs[] = { + 1, 2, 2, 3, 4, 59, 3, 9, + 10, 3, 16, 18, 20, 50, 5, 0, + 58, 6, 2, 7, 2, 8, 9, 10, + 11, 12, 13, 14, 15, 4, 17, 18, + 19, 21, 3, 30, 40, 22, 23, 24, + 25, 26, 27, 28, 29, 29, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 39, + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 3, 51, 52, 53, 54, 55, 3, + 56, 57, 56, 57 +}; + +static const char _gdb_trans_actions[] = { + 0, 60, 1, 3, 0, 3, 33, 3, + 3, 27, 21, 30, 3, 3, 7, 0, + 18, 3, 63, 0, 9, 7, 36, 24, + 71, 67, 71, 67, 71, 5, 15, 12, + 15, 3, 42, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 39, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 45, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 48, 3, 3, 3, 3, 3, 51, + 3, 3, 54, 57 +}; + +static const int gdb_start = 58; +static const int gdb_first_final = 58; +static const int gdb_error = 0; + +static const int gdb_en_main = 58; + + +#line 116 "src/gdb_parser.rl" + +void parser_init(command_cb *callbacks) +{ + +#line 181 "src/gdb_parser.c" + { + cs = gdb_start; + } + +#line 120 "src/gdb_parser.rl" + + command_callbacks = callbacks; +} + +int parse_buffer(char *buf, size_t len, void *priv) +{ + char *p = buf; + char *pe = p + len + 1; + + +#line 197 "src/gdb_parser.c" + { + int _klen; + unsigned int _trans; + const char *_acts; + unsigned int _nacts; + const char *_keys; + + if ( p == pe ) + goto _test_eof; + if ( cs == 0 ) + goto _out; +_resume: + _keys = _gdb_trans_keys + _gdb_key_offsets[cs]; + _trans = _gdb_index_offsets[cs]; + + _klen = _gdb_single_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + _klen - 1; + while (1) { + if ( _upper < _lower ) + break; + + _mid = _lower + ((_upper-_lower) >> 1); + if ( (*p) < *_mid ) + _upper = _mid - 1; + else if ( (*p) > *_mid ) + _lower = _mid + 1; + else { + _trans += (unsigned int)(_mid - _keys); + goto _match; + } + } + _keys += _klen; + _trans += _klen; + } + + _klen = _gdb_range_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + (_klen<<1) - 2; + while (1) { + if ( _upper < _lower ) + break; + + _mid = _lower + (((_upper-_lower) >> 1) & ~1); + if ( (*p) < _mid[0] ) + _upper = _mid - 2; + else if ( (*p) > _mid[1] ) + _lower = _mid + 2; + else { + _trans += (unsigned int)((_mid - _keys)>>1); + goto _match; + } + } + _trans += _klen; + } + +_match: + _trans = _gdb_indicies[_trans]; + cs = _gdb_trans_targs[_trans]; + + if ( _gdb_trans_actions[_trans] == 0 ) + goto _again; + + _acts = _gdb_actions + _gdb_trans_actions[_trans]; + _nacts = (unsigned int) *_acts++; + while ( _nacts-- > 0 ) + { + switch ( *_acts++ ) + { + case 0: +#line 11 "src/gdb_parser.rl" + { + cmd = 0; + rsp = NULL; + data = stack; + memset(stack, 0, sizeof(stack)); + crc = 0; + } + break; + case 1: +#line 19 "src/gdb_parser.rl" + { + crc += *p; + } + break; + case 2: +#line 23 "src/gdb_parser.rl" + { + data++; + assert(data < &stack[10]); + } + break; + case 3: +#line 28 "src/gdb_parser.rl" + { + *data *= 16; + + if (*p >= '0' && *p <= '9') + *data += *p - '0'; + else if (*p >= 'a' && *p <= 'f') + *data += *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + *data += *p - 'A' + 10; + } + break; + case 4: +#line 39 "src/gdb_parser.rl" + { + /* *data should point to the CRC */ + if (crc != *data) { + printf("CRC error\n"); + send_nack(priv); + } else { + printf("Cmd %d\n", cmd); + send_ack(priv); + + /* Push the response onto the stack */ + if (rsp) + *data = (uintptr_t)rsp; + else + *data = 0; + + command_callbacks[cmd](stack, priv); + } + } + break; + case 5: +#line 58 "src/gdb_parser.rl" + {cmd = GET_MEM;} + break; + case 6: +#line 63 "src/gdb_parser.rl" + {cmd = PUT_MEM;} + break; + case 7: +#line 70 "src/gdb_parser.rl" + {cmd = GET_GPRS;} + break; + case 8: +#line 72 "src/gdb_parser.rl" + {cmd = GET_SPR;} + break; + case 9: +#line 75 "src/gdb_parser.rl" + {cmd = STOP_REASON;} + break; + case 10: +#line 77 "src/gdb_parser.rl" + {cmd = SET_THREAD;} + break; + case 11: +#line 80 "src/gdb_parser.rl" + {rsp = "1";} + break; + case 12: +#line 81 "src/gdb_parser.rl" + {rsp = "QC1";} + break; + case 13: +#line 82 "src/gdb_parser.rl" + {rsp = "multiprocess+;vContSupported+";} + break; + case 14: +#line 83 "src/gdb_parser.rl" + {rsp = "m1l";} + break; + case 15: +#line 86 "src/gdb_parser.rl" + {rsp = "vCont;c;C;s;S";} + break; + case 16: +#line 87 "src/gdb_parser.rl" + {cmd = V_CONTC;} + break; + case 17: +#line 88 "src/gdb_parser.rl" + {cmd = V_CONTS;} + break; + case 18: +#line 90 "src/gdb_parser.rl" + {command_callbacks[INTERRUPT](stack, priv);} + break; +#line 384 "src/gdb_parser.c" + } + } + +_again: + if ( cs == 0 ) + goto _out; + if ( ++p != pe ) + goto _resume; + _test_eof: {} + _out: {} + } + +#line 130 "src/gdb_parser.rl" + + return 0; +} + +#if 0 +int main(int argc, char **argv) +{ + parser_init(NULL); + + if (argc > 1) + parse_buffer(argv[1], strlen(argv[1]), NULL); + return 0; +} +#endif From patchwork Fri Nov 2 00:46:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 992159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mNhY0hbqz9sML for ; Fri, 2 Nov 2018 11:47:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LYt9pB8V"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42mNhX5tz9zF31F for ; Fri, 2 Nov 2018 11:47:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LYt9pB8V"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::642; helo=mail-pl1-x642.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LYt9pB8V"; dkim-atps=neutral Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42mNgy0rQSzDrJs for ; Fri, 2 Nov 2018 11:47:10 +1100 (AEDT) Received: by mail-pl1-x642.google.com with SMTP id g59-v6so150707plb.10 for ; Thu, 01 Nov 2018 17:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bXi4JWXynpOgoFVAFsaYBvnZzfui1cf1QOV4I6dEi7I=; b=LYt9pB8V4Eoh4q2VdGiX0U0ruOkGcjxm+drE63gEpNV8slFisXVST7JzE0uv3V6lPE mnsZJO7/MGZzTDe1Z3kdKy8/VcYKDAnc7XtL/iFitJe4wmjJx53rBwTFL7zg4919aOF/ NoeMLB4qCyVJbsxShfY2j93N8TEwX/sDEpFimtmuF1krZjmQ5thGNoBJ5u3I2rUPwpza y756NOh49YHES8SHX8yM8R2WdUioe4HUyAz0dnpZhNrY2ScZ0cBKD0J3DsSE3ROPWj5E p9TNVZfM69E+GsxK/gI3bOl7VfYvpYs280YFxo+HrMLhZAHY7v0zR6SbYlr4SBlXA8/0 Bydg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bXi4JWXynpOgoFVAFsaYBvnZzfui1cf1QOV4I6dEi7I=; b=RVt8xngP3OHaAeRgRikkEuyTegjYCiaKtRk0wh/w9N66oPyOTi+Ya+rgrNvAGN+zv8 lcokj4hhWBPyH8fb4GeRNHPST+Bl64cSoUwXtY29i/HfNFxgozBukdfDPk0kYAsIKVd1 0d8N405BnBAFi9+7f5AcQRMHi6HhWliGuTToHyQyIi8DoosjFFn0pttE0vihSYhUaZoV DZLFB5xtAdsZIjAADb1J9Cf0D+CBsyGUEfNz1Wwn/sypNji7pSRnLV9O2wrhDD2u7jfT pftaOh6+Jw6/Q1TjH7DqVDWzU1S/3JWhDFHGDyHhDeUPEoiz7iz/FKv5fF+m//I7QVey qM+A== X-Gm-Message-State: AGRZ1gI0CZ6I+C/WV5RsifQfiQl45Zlf+vYnjd23TfyrhM3BZ9xISL32 v4wjdWmO0rln9GMZW0FtEtJhsN/X X-Google-Smtp-Source: AJdET5c1Mx68R7rA863MBPLkCxbF1l/z3cAuzWm7qjjbAcrfuvRd4yhTRiqGEIBEZnRChyYY9s+spg== X-Received: by 2002:a17:902:7847:: with SMTP id e7-v6mr9758201pln.104.1541119628330; Thu, 01 Nov 2018 17:47:08 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id d29-v6sm53736243pgm.56.2018.11.01.17.47.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 17:47:07 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Fri, 2 Nov 2018 11:46:43 +1100 Message-Id: <20181102004644.23047-4-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181102004644.23047-1-rashmica.g@gmail.com> References: <20181102004644.23047-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v4 3/4] pdbg/gdbserver: Make gdbserver optional X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: npiggin@gmail.com MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Rashmica Gupta --- Makefile.am | 21 +++++++++++---------- configure.ac | 6 ++++++ src/pdbgproxy.c | 9 +++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5a9d239..e83f21f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,14 +84,17 @@ pdbg_SOURCES = \ src/parsers.c \ src/optcmd.c \ src/options_@ARCH@.c \ - src/htm.h \ - src/main.h \ - src/optcmd.h \ - src/options.h \ - src/parsers.h \ - src/progress.h \ - src/pdbgproxy.c \ - src/gdb_parser.c + src/pdbgproxy.c + +pdbg_CFLAGS = -I$(top_srcdir)/libpdbg -Wall -Werror -DGIT_SHA1=\"${GIT_SHA1}\" \ + $(ARCH_FLAGS) + +if GDBSERVER +pdbg_SOURCES += \ + $(extra_sources) +else +pdbg_CFLAGS += -DDISABLE_GDBSERVER +endif src/main.c: $(DT_headers) @@ -99,8 +102,6 @@ pdbg_LDADD = $(DT_objects) libpdbg.la libccan.a \ -L.libs -lrt pdbg_LDFLAGS = -Wl,--whole-archive,-lpdbg,--no-whole-archive -pdbg_CFLAGS = -I$(top_srcdir)/libpdbg -Wall -Werror -DGIT_SHA1=\"${GIT_SHA1}\" \ - $(ARCH_FLAGS) lib_LTLIBRARIES = libpdbg.la libfdt.la diff --git a/configure.ac b/configure.ac index 0fbf8ae..a52e1ed 100644 --- a/configure.ac +++ b/configure.ac @@ -36,4 +36,10 @@ AC_SUBST([ARCH]) AM_CONDITIONAL([TARGET_ARM], [test x"$ARCH" = "xarm"]) AM_CONDITIONAL([TARGET_PPC], [test x"$ARCH" = "xppc"]) +AC_ARG_ENABLE(gdbserver, +AC_HELP_STRING([--disable-gdbserver], [disables building the gdbserver]), +want_gdbserver=false, +want_gdbserver=true) +AM_CONDITIONAL([GDBSERVER], [test x$want_gdbserver = xtrue]) + AC_OUTPUT diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 5ccadfc..8415fea 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -25,6 +25,8 @@ #include "debug.h" #include "chip.h" +#ifndef DISABLE_GDBSERVER + /* Maximum packet size */ #define BUFFER_SIZE 8192 @@ -544,4 +546,11 @@ static int gdbserver(uint16_t port) gdbserver_start(target, port); return 0; } +#else + +static int gdbserver(uint16_t port) +{ + return 0; +} +#endif OPTCMD_DEFINE_CMD_WITH_ARGS(gdbserver, gdbserver, (DATA16)); From patchwork Fri Nov 2 00:46:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 992160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mNhb3Cphz9sDr for ; Fri, 2 Nov 2018 11:47:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lPIeoETL"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42mNhb13rfzF31S for ; Fri, 2 Nov 2018 11:47:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lPIeoETL"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lPIeoETL"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42mNh15SrGzF31F for ; Fri, 2 Nov 2018 11:47:13 +1100 (AEDT) Received: by mail-pf1-x441.google.com with SMTP id h4-v6so159010pfi.10 for ; Thu, 01 Nov 2018 17:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q49pGBC9F74QnbuU6GXEM5tIFMODH91lMF2YgWvLF5M=; b=lPIeoETL7rcwWlDBCJNxpFZHE0FC3XBEtXEItAe+gqDmcR0QyY3UiKRNNC/Qi1FKMN wV6FDufu7OiIixg+UFehvFT9EEYjeLxe/lGGDEG9ylO+XzKbcWSaGnPszNkfpPD1iSO+ pv/CPIqVrzriwLALwUFO3VKEhOqjB24saG2hiFY2gnZu88NgCKKiWBLTdpM2U0yJUyi7 JRJTiOdsw0CtPC/5pjl83kU+5HH/+ieRqxakWiQ+4OlrZBZfvXucDYwah9JVDv521Uwk uTlvTVwA/Wj/ORld/b+NPXU3jws5aL1w482O/ek50FUGn/Ao+Jc/lTFX4+6EBCoUm75M zcnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q49pGBC9F74QnbuU6GXEM5tIFMODH91lMF2YgWvLF5M=; b=Fl+/S5Ys+4BWTVQqWzv+Tu/hDSOodm01Dq23h9brj/RO4dkcmSywpxtYnNqd+bCGDn ppi1Dj/6cbftlDzt4hLSEqJ2DOsrWi+awoaKYmS1w/1hq+pTd2hLVU5ffPkcnmwx6iMO aWKhUHsY+a6UJXmLOpuHsdeJbC/stguGfc1lTvT5H+KNO4xKFzsWOf3mmlME6c9W+4d7 5viST+3rTOspSqOqiToImdYIKgcIfe6lFoHqauQFWFWQY3Cl8+44OI8WP1GCRT0hgI76 34/Ves50qwh2F4Y9L6b1LHKWeeDaML1IEgeu+E+qf5iOzIuDGdpviCOWJuD3HeQ65w+t QNZg== X-Gm-Message-State: AGRZ1gLTAS45o1npOOjSqAvcPwRxqZE2mlCSfA4+abMXB2fdA2v+wVWH Cipa4yHwelg7qs+3Ba4d+2AmCkC2 X-Google-Smtp-Source: AJdET5cp43kUtrR8K7v/KZJNWdCnxmwiIWdyjH3tjEb1VSqAmHbvtL7f94p4fRY5E/t4Ny8txL6VNA== X-Received: by 2002:a62:93d5:: with SMTP id r82-v6mr6444723pfk.55.1541119632027; Thu, 01 Nov 2018 17:47:12 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id d29-v6sm53736243pgm.56.2018.11.01.17.47.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 17:47:11 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Fri, 2 Nov 2018 11:46:44 +1100 Message-Id: <20181102004644.23047-5-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181102004644.23047-1-rashmica.g@gmail.com> References: <20181102004644.23047-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v4 4/4] README: Add some gdbserver info X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: npiggin@gmail.com MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Rashmica Gupta --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 878e6d3..dcbbbe3 100644 --- a/README.md +++ b/README.md @@ -365,3 +365,29 @@ There are also low level htm commands which can also be used: - `stop` will still stop the trace and de-configure the hardware. - `dump` will dump the trace to a file. +### GDBSERVER +At the moment gdbserver is only supported on P8 while the cores are in the +kernel. + +To run a gdbserver on a P8 machine from a BMC running openbmc: + +Stop all the threads of the core you want to look at +$ ./pdbg -d p8 -c11 -a stop + +Run gdbserver on thread 0 of core 11, accessible through port 44 +$ ./pdbg -d p8 -p0 -c11 -t0 gdbserver 44 + +On your local machine: +$ gdb +(gdb) set architecture powerpc:common64 +(gdb) target remote palm5-bmc:44 + +Debugging info: +(gdb) set debug remote 10 + + +Notes: +1. DON'T RUN PDBG OVER FSI WHILE HOSTBOOT IS RUNNING. Weird things seem to +happen. +2. If you want to view the kernel call trace then run gdb on the vmlinux that +the host is running (the kernel needs to be compiled with debug symbols).