From patchwork Wed Apr 20 06:50:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kjrtm3dpYz9sG0 for ; Wed, 20 Apr 2022 16:51:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtm2BFcz2ymb for ; Wed, 20 Apr 2022 16:51:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::533; helo=mail-pg1-x533.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Kjrtk1yl5z2yZf for ; Wed, 20 Apr 2022 16:51:42 +1000 (AEST) Received: by mail-pg1-x533.google.com with SMTP id g9so774005pgc.10 for ; Tue, 19 Apr 2022 23:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HwixrS9cN5R/xnk0LQNKGdLGgQcxWSBp8HLQnSlVfHw=; b=UD5Ne4oFSK4vOL/DwEIeTcgMYIpXNLUpcpzJnPWoqMIHQKsYV3QECr9nTqpgTLe03q dAFdQt4ZgptQZFyPH4lB/cSA1rQf/MlPhew37QrNw8mRk1HreuO4ov5DhT8WzJSul2pp 69GAKIwYfaKoT4M0JGNYb8cLKJeL+1UCvOaOc5xKrLBfLNEJDZ+CoLaCKzhijhOT2cLR Fh4clCQv2NVVdHMs3tpC+eIf0pyxcNFioFVP5yb7wRzHi2FLephESQoouuRfOw+A6IrR dmeRd8SJOllx7jGomzkRf6YHxp51D8ehnsRZQLMRHJJsUaXJ+soCLBjlQ7NktqFtzloe O5xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HwixrS9cN5R/xnk0LQNKGdLGgQcxWSBp8HLQnSlVfHw=; b=UdTNGhyu0JNFA7983/W+pUle1pjTYZ2ZdSNveQquSbU/O7X1uGG4HZZjuu1hnZD9ZL wlghNURCs/Y9YpC/xKKaQxj6+n8eo3rF7VTVZEjVgQr0rCL08e8Q51rD4PJpsfc68X0x k0d4IOgbxrUgBLDkeMgjfqJ7IOzln13T8b0KYYPwlR1h3bSBsqEDDPZteVbEW8tnI8Lb DSa++nwO/n+lnsMFWCtyqFfKiw/aUKx0Go5tDQEaFGAy/x6EGSWI1PKpTlkTW4j7xBDs 2MwpWyJqAA3uOTwIt9+UnRBRmQMTOSwImSpF3ku4/PE875ocQ+0fRckvTnL22bcixqy+ XQ5w== X-Gm-Message-State: AOAM530A88oM3eqvc8YEhx1AytVERnktNeJrhMNIxy4pWU2+czNOOi3d TBtcAQVQ2uZ+nggnAIkxqVV2L+Hw5Eo8CA== X-Google-Smtp-Source: ABdhPJwnY1t3mcM4b+Mwbzdfoihtw2SNOiZp3DF3N9grrdtr4I/R0eKPwUUadlCOfPMvzXp2USOadA== X-Received: by 2002:a65:6e4d:0:b0:39d:a6ce:14dc with SMTP id be13-20020a656e4d000000b0039da6ce14dcmr18143206pgb.476.1650437500038; Tue, 19 Apr 2022 23:51:40 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:39 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:06 +1000 Message-Id: <20220420065013.222816-33-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 32/39] gdbserver: track stop reason per thread 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: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Maintain the reason why each thread has stopped, which allows in particular distinguishing between threads that encountered a trap, one that took an interrupt, from those that were stopped afterwards due to all-stop semantics. This allows sending TRAP/INT/other stop reasons as appropriate rather than always sending TRAP. While here, switch to the more capable T packet rather than S packet, which can includes the thread-id. Switch target to the thread that hit a breakpoint when stopping. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 85 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 735615c6..52f34a91 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -30,7 +30,16 @@ #ifndef DISABLE_GDBSERVER -/* Maximum packet size */ +/* + * If the client sents qSupported then it can handle unlimited length response. + * Shouldn't need more than 8k for now. If we had to handle old clients, 512 + * should be a lower limit. + */ +#define MAX_RESP_LEN 8192 + +/* + * Maximum packet size. We don't advertise this to the client (TODO). + */ #define BUFFER_SIZE 8192 /* GDB packets */ @@ -38,7 +47,6 @@ #define ACK "+" #define NACK "-" #define OK "OK" -#define TRAP "S05" #define ERROR(e) "E"STR(e) #define TEST_SKIBOOT_ADDR 0x40000000 @@ -56,6 +64,8 @@ static enum client_state state = IDLE; struct gdb_thread { uint64_t pir; bool attn_set; + bool stop_attn; + bool stop_ctrlc; }; static void destroy_client(int dead_fd); @@ -132,9 +142,32 @@ static void set_thread(uint64_t *stack, void *priv) send_response(fd, ERROR(EEXIST)); } +static void send_stop_for_thread(struct pdbg_target *target) +{ + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + uint64_t pir = gdb_thread->pir; + char data[MAX_RESP_LEN]; + size_t s = 0; + int sig; + + if (gdb_thread->stop_attn) + sig = 5; /* TRAP */ + else if (gdb_thread->stop_ctrlc) + sig = 2; /* INT */ + else + sig = 0; /* default / initial stop reason */ + + s += snprintf(data + s, sizeof(data) - s, "T%02uthread:%04" PRIx64 ";%s", sig, pir, sig == 5 ? "swbreak:;" : ""); + + send_response(fd, data); +} + static void stop_reason(uint64_t *stack, void *priv) { - send_response(fd, TRAP); + PR_INFO("stop_reason\n"); + + send_stop_for_thread(thread_target); } static void detach(uint64_t *stack, void *priv) @@ -539,8 +572,17 @@ out: static void v_conts(uint64_t *stack, void *priv) { + struct thread *thread = target_to_thread(thread_target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + PR_INFO("thread_step\n"); + thread_step(thread_target, 1); - send_response(fd, TRAP); + + gdb_thread->stop_ctrlc = false; + gdb_thread->stop_attn = false; + + send_stop_for_thread(thread_target); } static void __start_all(void) @@ -568,6 +610,8 @@ static void start_all(void) struct pdbg_target *target; for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; struct thread_state status; if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) @@ -577,6 +621,11 @@ static void start_all(void) status = thread_status(target); if (!status.quiesced) PR_ERROR("starting thread not quiesced\n"); + + gdb_thread = thread->gdbserver_priv; + + gdb_thread->stop_attn = false; + gdb_thread->stop_ctrlc = false; } __start_all(); @@ -691,6 +740,8 @@ static void stop_all(void) PR_INFO("thread pir=%"PRIx64" hit attn\n", gdb_thread->pir); + gdb_thread->stop_attn = true; + if (!(status.active)) PR_ERROR("Error thread inactive after trap\n"); /* Restore NIA to before break */ @@ -706,13 +757,18 @@ static void interrupt(uint64_t *stack, void *priv) { PR_INFO("Interrupt from gdb client\n"); if (state != IDLE) { + struct thread *thread = target_to_thread(thread_target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + stop_all(); + if (!gdb_thread->stop_attn) + gdb_thread->stop_ctrlc = true; state = IDLE; poll_interval = VCONT_POLL_DELAY; } - send_response(fd, TRAP); + send_stop_for_thread(thread_target); } static bool poll_threads(void) @@ -735,6 +791,8 @@ static bool poll_threads(void) static void poll(void) { + struct pdbg_target *target; + if (state != SIGNAL_WAIT) return; @@ -745,12 +803,27 @@ static void poll(void) stop_all(); + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + gdb_thread = thread->gdbserver_priv; + + if (gdb_thread->stop_attn) { + thread_target = target; + break; + } + } + set_attn(false); state = IDLE; poll_interval = VCONT_POLL_DELAY; - send_response(fd, TRAP); + send_stop_for_thread(thread_target); } static void cmd_default(uint64_t *stack, void *priv)