From patchwork Tue Mar 29 15:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610683 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=Cfo6QKu0; 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 4KSYst1h3xz9sFk for ; Wed, 30 Mar 2022 02:49:53 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYss5pFMz2yPL for ; Wed, 30 Mar 2022 02:49:53 +1100 (AEDT) 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=Cfo6QKu0; 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::42b; helo=mail-pf1-x42b.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=Cfo6QKu0; dkim-atps=neutral Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 4KSYsk6XbLz2xt7 for ; Wed, 30 Mar 2022 02:49:45 +1100 (AEDT) Received: by mail-pf1-x42b.google.com with SMTP id h19so15260209pfv.1 for ; Tue, 29 Mar 2022 08:49:45 -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=Z40uAbi8uZLUFUcjZa+A3QmdwMBu2pb3bj0ENdzitrg=; b=Cfo6QKu09rye26BvS0YiqXNpl9/YfsALr572HOdUGmke4x2G0AUi8gbCPXecxBnct4 Ns1osiOezcNnEiAFI7XUIxbNtXAShoQC4CkCfiJxkDmmp5kY/5kc0SOXR8WB1DcErhu8 eV9aJpy/ldPv/Errfs55/2Y7uccuryqQXuLz/Ayp8FUlf5HyCmqh0s7xtLVtg3sKKUi2 Tc4cQenq4mb59hcCwv/ylUOlHrAZnpgNfVPvPPEIWvA8bBA4dG+qGBcwbJtJR3WVzrmj H3N/BJU9j+4qXtUoWcaG+rp1+8kFWQ0KwN5kVmWfyF9kPU/64A44kTolSjqhTFg2fuM0 bbaA== 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=Z40uAbi8uZLUFUcjZa+A3QmdwMBu2pb3bj0ENdzitrg=; b=hTEHG4St9d4a84rPee9+E4Ih00YOgcInGHXiArdKysk0D2gSE1QDYtcCqP6Tw0PsHl 0TKGnQgiqnW8QzrluL1Bf7TY8pZhYNwE62o6JncdPONQhPTudtKZKgdFNpeMjZ2n3TQd BAwgKQJ9aq+dqiRMA3Zv8qZjd3AD/izX/ZfEzM0A+9eplJkgiLiFl33hFniiCKg5/BcL S8vG/jlXlIa94KaU/aoihLKmgmysMQqndcG6UG4vZAFskhfG3xmGp5l5/+oE0g0rKIyK 5uLdhvxHkGV2szqMGyWDUvmSE+vq7lv76/qt1FRaDNw2/EW/1Xc2iA3qIy4JH/It58SK Ma7g== X-Gm-Message-State: AOAM533PRTRvJpXezwH9IIBCeE32atwln1v7tk6kSFNhNk+PSL2MpMly igXsztijZkNVeswD04ko1U+ScQzAv9o= X-Google-Smtp-Source: ABdhPJx7AVBkX0SQjGESqDT5hmih6kksZmM/iZv4hq3+9vvMItNuwy6XY08GKUtfORC4T/Yq+ppQww== X-Received: by 2002:a63:3e8d:0:b0:398:5222:3a3 with SMTP id l135-20020a633e8d000000b00398522203a3mr2485207pga.561.1648568983438; Tue, 29 Mar 2022 08:49:43 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:43 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:54 +1000 Message-Id: <20220329154931.493851-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 01/38] gdbserver: fix put_mem command parsing 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" The 'M' gdb command (put_mem) should not match characters after the 'M' which are not part of the first hex number matching. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 2 +- src/gdb_parser_precompile.c | 248 ++++++++++++++++++------------------ 2 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 6259b96..868e31c 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -60,7 +60,7 @@ ',' xdigit+ $hex_digit %push); - put_mem = ('M' any* @{cmd = PUT_MEM;} + put_mem = ('M' @{cmd = PUT_MEM;} xdigit+ $hex_digit %push ',' xdigit+ $hex_digit %push diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index 715cdd7..505e102 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -5,10 +5,10 @@ #include #include -#include "pdbgproxy.h" +#include "src/pdbgproxy.h" -#line 105 "src/gdb_parser.rl" +#line 108 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -29,160 +29,156 @@ static const char _gdb_actions[] = { 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 + 1, 2, 17, 1, 2, 18, 1, 2, + 19, 0, 3, 1, 19, 0 }; -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 unsigned char _gdb_key_offsets[] = { + 0, 0, 2, 14, 15, 21, 27, 30, + 38, 46, 53, 60, 61, 68, 76, 83, + 91, 98, 106, 111, 113, 115, 117, 119, + 121, 123, 125, 127, 134, 136, 138, 140, + 142, 144, 146, 148, 150, 152, 153, 155, + 157, 159, 161, 163, 165, 167, 169, 171, + 173, 175, 177, 179, 181, 184, 187, 188, + 189, 191 }; 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, + 3, 36, 35, 43, 45, 63, 68, 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, 48, 57, 65, 70, 97, 102, 35, 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, 48, 57, 65, + 70, 97, 102, 35, 58, 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 + 97, 102, 35, 44, 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, + 0, 2, 12, 1, 0, 0, 3, 2, + 2, 1, 1, 1, 1, 2, 1, 2, + 1, 2, 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, 1, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 3, 3, - 1, 1, 2, 3 + 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, + 3, 3, 3, 0, 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, 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 + 0, 0, 3, 16, 18, 22, 26, 30, + 36, 42, 47, 52, 54, 59, 65, 70, + 76, 81, 87, 93, 96, 99, 102, 105, + 108, 111, 114, 117, 122, 125, 128, 131, + 134, 137, 140, 143, 146, 149, 151, 154, + 157, 160, 163, 166, 169, 172, 175, 178, + 181, 184, 187, 190, 193, 197, 201, 203, + 205, 208 }; 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 + 8, 9, 10, 11, 12, 13, 14, 3, + 4, 3, 15, 15, 15, 16, 17, 17, + 17, 16, 19, 20, 21, 18, 1, 2, + 22, 22, 22, 0, 1, 2, 17, 17, + 17, 0, 4, 23, 23, 23, 3, 24, + 23, 23, 23, 3, 4, 25, 4, 26, + 26, 26, 3, 4, 27, 26, 26, 26, + 3, 4, 28, 28, 28, 3, 4, 29, + 28, 28, 28, 3, 4, 30, 30, 30, + 3, 4, 29, 30, 30, 30, 3, 4, + 31, 32, 33, 34, 3, 4, 35, 3, + 4, 36, 3, 4, 37, 3, 4, 38, + 3, 4, 39, 3, 4, 40, 3, 4, + 41, 3, 4, 42, 3, 4, 43, 43, + 43, 3, 4, 44, 3, 4, 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, 4, + 54, 3, 4, 55, 3, 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, 69, 3, 4, 70, 71, + 3, 4, 72, 4, 73, 1, 2, 0, + 19, 20, 21, 18, 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 + 1, 2, 2, 3, 4, 57, 3, 9, + 11, 12, 3, 16, 9, 18, 48, 5, + 0, 56, 6, 2, 7, 2, 8, 10, + 4, 11, 13, 14, 15, 9, 17, 19, + 3, 28, 38, 20, 21, 22, 23, 24, + 25, 26, 27, 27, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 37, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 3, + 49, 50, 51, 52, 53, 3, 54, 55, + 54, 55 }; 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 + 0, 63, 1, 3, 0, 3, 33, 39, + 3, 24, 27, 21, 30, 3, 3, 7, + 0, 18, 3, 66, 0, 9, 7, 15, + 5, 36, 15, 12, 15, 12, 15, 3, + 45, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 42, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 48, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 51, + 3, 3, 3, 3, 3, 54, 3, 3, + 57, 60 }; -static const int gdb_start = 58; -static const int gdb_first_final = 58; +static const int gdb_start = 56; +static const int gdb_first_final = 56; static const int gdb_error = 0; -static const int gdb_en_main = 58; +static const int gdb_en_main = 56; -#line 116 "src/gdb_parser.rl" +#line 119 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 181 "src/gdb_parser.c" +#line 177 "src/gdb_parser.c" { cs = gdb_start; } -#line 120 "src/gdb_parser.rl" +#line 123 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -193,7 +189,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len + 1; -#line 197 "src/gdb_parser.c" +#line 193 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -349,35 +345,39 @@ _match: {cmd = SET_THREAD;} break; case 11: -#line 80 "src/gdb_parser.rl" - {rsp = "1";} +#line 79 "src/gdb_parser.rl" + {cmd = DISCONNECT;} break; case 12: -#line 81 "src/gdb_parser.rl" - {rsp = "QC1";} +#line 83 "src/gdb_parser.rl" + {rsp = "1";} break; case 13: -#line 82 "src/gdb_parser.rl" - {rsp = "multiprocess+;vContSupported+";} +#line 84 "src/gdb_parser.rl" + {rsp = "QC1";} break; case 14: -#line 83 "src/gdb_parser.rl" - {rsp = "m1l";} +#line 85 "src/gdb_parser.rl" + {rsp = "multiprocess+;vContSupported+";} break; case 15: #line 86 "src/gdb_parser.rl" - {rsp = "vCont;c;C;s;S";} + {rsp = "m1l";} break; case 16: -#line 87 "src/gdb_parser.rl" - {cmd = V_CONTC;} +#line 89 "src/gdb_parser.rl" + {rsp = "vCont;c;C;s;S";} break; case 17: -#line 88 "src/gdb_parser.rl" - {cmd = V_CONTS;} +#line 90 "src/gdb_parser.rl" + {cmd = V_CONTC;} break; case 18: -#line 90 "src/gdb_parser.rl" +#line 91 "src/gdb_parser.rl" + {cmd = V_CONTS;} + break; + case 19: +#line 93 "src/gdb_parser.rl" {command_callbacks[INTERRUPT](stack, priv);} break; #line 384 "src/gdb_parser.c" @@ -393,7 +393,7 @@ _again: _out: {} } -#line 130 "src/gdb_parser.rl" +#line 133 "src/gdb_parser.rl" return 0; } From patchwork Tue Mar 29 15:48:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610684 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=O3FmLVHl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYst6pCCz9sG8 for ; Wed, 30 Mar 2022 02:49:54 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYst5qg8z2xvF for ; Wed, 30 Mar 2022 02:49:54 +1100 (AEDT) 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=O3FmLVHl; 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::529; helo=mail-pg1-x529.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=O3FmLVHl; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 4KSYsl5MjXz2xYG for ; Wed, 30 Mar 2022 02:49:47 +1100 (AEDT) Received: by mail-pg1-x529.google.com with SMTP id q19so15182484pgm.6 for ; Tue, 29 Mar 2022 08:49:47 -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=6xe69WyHxH24SiQtjMoI23eaFO31g3rwAA0sBZbaBEs=; b=O3FmLVHlWtjBwc93xUwPNB4gN9psgp2iCEhHA8Q11fBTjL9QK/A8lBvgfb/AkLZupd 01ClkW254qpizi7ZJuc3mZcqeJIjfu9ZChsnyRDARf6Zhq2Antml+Mnrr+V6tIjoSQI0 ADbdGOEBHRZtcX5wzr88bLxS5QFTfwH9P1SORz6m4bx/JdkjiHFDR0Wxda4zvsW7fdZ9 2PZis1JHO7Dj4yyzawK4FHH+CYt1Z89oPAuQtFJjLtMk6WLNleR6hQvq7x4hmDhJDvya 0BXXomhgJD0KutbT+hARGdGWfMB7Ql+c8Jd46tY4vtp0Nm9NfFVe6hTi2itrXS5sxVF1 hGDQ== 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=6xe69WyHxH24SiQtjMoI23eaFO31g3rwAA0sBZbaBEs=; b=dY0UBWQ1Zp6AZRdhCbW1Itjh4LkuvR0RUQ1XJAZ9rvUXUu/oKannVd+L6o+4sSWRYS Qs63d6yeI6PjXK3dK1icXN+5TqEF6p9bXQ5ZNvLKvnTUIUAcn22Wi1+t6DKkf+nOCs5g QZl5i8n1bthM88bQYpz7ddpxc6XQlzFCz8jOqbloW+6prcwydGLeKPdJtGYsdszY3t2J ana9jkG5KUW/FGpIYeKyRr2BOI6rgjHAJkxbAJxdSF/tYXI4QEt6TqrIOzyg+UBErryf oC+WsJiHR9npW7W84lwAd05OXReDHdDlbCRusVeYKYCx7q683ccC7mMKyWSCeAl84h3l czoA== X-Gm-Message-State: AOAM533CmDcoFDwJIYjRLW0v1YA4005Y3qFMOXZaL/F3DZtruYNmmUaB 0L4f45mT0NIRSwulrfIX2dXIG+74QFg= X-Google-Smtp-Source: ABdhPJzUP2lzfq0Z9mDls9XqAEGQug5IQw3vItK2Gq60fAnGi7iNvYqPlfnUL7MJBwdkkuNLM+ypKg== X-Received: by 2002:a63:1063:0:b0:382:adf9:e0c9 with SMTP id 35-20020a631063000000b00382adf9e0c9mr2393200pgq.508.1648568985404; Tue, 29 Mar 2022 08:49:45 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:45 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:55 +1000 Message-Id: <20220329154931.493851-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 02/38] libpdbg: fix p9chip and p10chip thread_stop 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" Have p9 and p10 thread_stop return 1 on failure, and have them set thread->status to the status used when checking for quiesce, rather than sampling it again on the way out. This seems to improve some intermittent condition on POWER9 where a thread was stopped successfuly but the subsequent status read finds it no longer quiesced. Signed-off-by: Nicholas Piggin --- libpdbg/p10chip.c | 8 ++++---- libpdbg/p9chip.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libpdbg/p10chip.c b/libpdbg/p10chip.c index e0d9ee2..70481f1 100644 --- a/libpdbg/p10chip.c +++ b/libpdbg/p10chip.c @@ -154,14 +154,14 @@ static int p10_thread_stop(struct thread *thread) int i = 0; thread_write(thread, P10_DIRECT_CONTROL, PPC_BIT(7 + 8*thread->id)); - while (!(thread->state(thread).quiesced)) { + do { usleep(1000); if (i++ > RAS_STATUS_TIMEOUT) { PR_ERROR("Unable to quiesce thread\n"); - break; + return 1; } - } - thread->status = thread->state(thread); + thread->status = thread->state(thread); + } while (!thread->status.quiesced); return 0; } diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 9fddaf6..0ac5354 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -157,14 +157,14 @@ static int p9_thread_stop(struct thread *thread) int i = 0; thread_write(thread, P9_DIRECT_CONTROL, PPC_BIT(7 + 8*thread->id)); - while (!(thread->state(thread).quiesced)) { + do { usleep(1000); if (i++ > RAS_STATUS_TIMEOUT) { PR_ERROR("Unable to quiesce thread\n"); - break; + return 1; } - } - thread->status = thread->state(thread); + thread->status = thread->state(thread); + } while (!thread->status.quiesced); return 0; } From patchwork Tue Mar 29 15:48:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610685 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=RM3lQzMO; 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 4KSYsw08C5z9sFk for ; Wed, 30 Mar 2022 02:49:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYsv5rv3z2yJ9 for ; Wed, 30 Mar 2022 02:49:55 +1100 (AEDT) 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=RM3lQzMO; 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::42a; helo=mail-pf1-x42a.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=RM3lQzMO; dkim-atps=neutral Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (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 4KSYsn4bDZz2xYG for ; Wed, 30 Mar 2022 02:49:49 +1100 (AEDT) Received: by mail-pf1-x42a.google.com with SMTP id t2so16236302pfj.10 for ; Tue, 29 Mar 2022 08:49:49 -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=znawAqR4jsCXDe/vxPPhxP/VTOVIS6fqlYlj45YgmMk=; b=RM3lQzMOSYTae0ho+AfJFAzBEBY0QAdK3SXi6oLIKzmkXCRa1lZN1RX4VXTX5YEo5m twb8rN6ylf6MU9CrBVQC2hjpKS4YQnu5JWw3BCB8denP7hPc0vrD1n/oSx0wW/GgdwLp BzqWd0EgL+p2qV8+hl+NZhT1WonUsiftzpOP67q6/I4wBzEDvHvm6O4Rh/gZrsPAj5Kg r0u8K4WCs90Ty6gw68ZdGyam57HYpBMu/+SveU3vp1W4jTH1n9pfjcRHDPqy86suSfoF ZwTNXmSg77qln0lqAPZlGONOyw3CgLvCvr+TLHMlBQjaZrOOodSFq2DNNO9QyjcXDrvg TQrQ== 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=znawAqR4jsCXDe/vxPPhxP/VTOVIS6fqlYlj45YgmMk=; b=7CxFhyFKslkOE2IrB59uSFniYtAJsrE9AhL17FuGRZ5ayA6+AVzkHA8OU7qkMGpHEf g6LhaxE7G5GgzD6jbu5FjH3aTLI2fb80JdEoaup2SWjS3RPH49Xpr91cnr1+ENKdkUi1 8kJNSIqXYHI/vLjwm2XH/tXLPR9kf1q+tVVlOGb971lLWelPatGsVQ0F/s2b2LSTabkW RXE7w2xdNiQaCUR9y3rqFHWoCX9vOuAzhoDDwr8GO9MPS6dPZhlXcCG9W3rSO2zyYxoM sl+gl5iLTjL0u16A9BvDoWQAzFpPlEl6OxxdYXc/imsFTfdUed+x00xiE7QFOx56hjLq Qe1w== X-Gm-Message-State: AOAM532D/6Fib0TO8n7y4Ti5AlchGNiOLEBqDimzZDtqB2noUSep3OKu 5F5kXPXF4iuCzXLDhfek7X38VoffLjE= X-Google-Smtp-Source: ABdhPJzlpBPBTf23zUegktpOVZK8vWFTVws7UQEm59FAGdADUTJ5hKuZ16qcCqTo/0KZbHA6Gt73yw== X-Received: by 2002:a63:806:0:b0:381:1497:c4e9 with SMTP id 6-20020a630806000000b003811497c4e9mr2517357pgi.123.1648568987315; Tue, 29 Mar 2022 08:49:47 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:47 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:56 +1000 Message-Id: <20220329154931.493851-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 03/38] gdbserver: update gdb_parser_precompile.c, rename detach command 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" gdb_parser_precompile.c had not been updated since adding support for the detach command, resulting in client error messages like this: Detaching from program: /home/npiggin/images/vmlinux, process 42000 Remote doesn't know how to detach The command handler should not be named disconnect, because that is a different concept in gdb (disconnect leaves the target in the same state, detach ends the debugging session). Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 4 ++-- src/gdb_parser_precompile.c | 2 +- src/pdbgproxy.c | 6 +++--- src/pdbgproxy.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 868e31c..629a091 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -76,7 +76,7 @@ set_thread = ('H' any* @{cmd = SET_THREAD;}); - disconnect = ('D' @{cmd = DISCONNECT;} + detach = ('D' @{cmd = DETACH;} xdigit+ $hex_digit %push); # TODO: We don't actually listen to what's supported @@ -94,7 +94,7 @@ 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 ); + v_contq | v_contc | v_conts | put_mem | detach ); cmd = ((commands & ^'#'*) | ^'#'*) $crc ('#' xdigit{2} $hex_digit @end); diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index 505e102..f787a29 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -346,7 +346,7 @@ _match: break; case 11: #line 79 "src/gdb_parser.rl" - {cmd = DISCONNECT;} + {cmd = DETACH;} break; case 12: #line 83 "src/gdb_parser.rl" diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index bb7c7b3..3e27ba0 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -95,9 +95,9 @@ static void stop_reason(uint64_t *stack, void *priv) send_response(fd, TRAP); } -static void disconnect(uint64_t *stack, void *priv) +static void detach(uint64_t *stack, void *priv) { - PR_INFO("Terminating connection with client. pid %16" PRIi64 "\n", stack[0]); + PR_INFO("Detach debug session with client. pid %16" PRIi64 "\n", stack[0]); send_response(fd, OK); } @@ -416,7 +416,7 @@ command_cb callbacks[LAST_CMD + 1] = { v_conts, put_mem, interrupt, - disconnect, + detach, NULL}; int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h index 1fe67f2..1910fdb 100644 --- a/src/pdbgproxy.h +++ b/src/pdbgproxy.h @@ -3,7 +3,7 @@ enum gdb_command {NONE, GET_GPRS, GET_SPR, GET_MEM, STOP_REASON, SET_THREAD, V_CONTC, V_CONTS, - PUT_MEM, INTERRUPT, DISCONNECT, LAST_CMD}; + PUT_MEM, INTERRUPT, DETACH, LAST_CMD}; typedef void (*command_cb)(uint64_t *stack, void *priv); void parser_init(command_cb *callbacks); From patchwork Tue Mar 29 15:48:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610686 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=O8w6K7R3; 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 4KSYsw60zNz9sG8 for ; Wed, 30 Mar 2022 02:49:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYsw4dYJz2yHB for ; Wed, 30 Mar 2022 02:49:56 +1100 (AEDT) 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=O8w6K7R3; 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::632; helo=mail-pl1-x632.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=O8w6K7R3; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 4KSYsq6FSPz2yJ9 for ; Wed, 30 Mar 2022 02:49:51 +1100 (AEDT) Received: by mail-pl1-x632.google.com with SMTP id j13so17995209plj.8 for ; Tue, 29 Mar 2022 08:49:51 -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=UWBRYArM5kXg3RGNg17Z/y4D7gowbw5irNUKi1eHr04=; b=O8w6K7R32SGgLk7mPxDAuZxHS85sQB/6wDCvRuEmd4QsxWz5a3hxkxn4tYxcq9Jlz6 lwbs3FAd2xpbU1zO5dLtA7hrdhmcR/ikajSZwvfj0Pvw6bLbxNX6My+0KwP8PVSCY46u HJCpUSTGuFfd5P8SNHZ7W0x72RPExFu5bUWMcYQ4OP/akeY3orPYAxe+orN4sT/BXUoC IIQScus7vWA1vakR55Y5f+JD/Qz1QsQwVezBHh4OjQSj7J/ZZXhcfb9xjrXPgA7THLAP OqDtzgcB/4gTDTs4RuU9v2Jq+7BGJat3oGUtYDkYaAFohwnJCNnflJSsDy3sxi3cKzMI BVUA== 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=UWBRYArM5kXg3RGNg17Z/y4D7gowbw5irNUKi1eHr04=; b=zGK72Msy8Nxdrp6Es3uZALEcHXY02MQqN2jnku4Jl620iqL/ZeHthZW7V7JZtpXpmc HfHrqXghfoF4dFeaWVN9xiJYzvRB1AW/Di9j7afFYuHdBffj/1jiPsscHt8vXe4Ki+JE IV4hKszi3gd6fFPTy26ANY4Ps5XaUW7a7DLpMDYM0/+/GuPh5H54N72tFseNFSqegq9a sAxooWK/1v8TLql92ISScspyLJprPxxOn3jICoLRSi61RUc47KQOeCI7eHfAwdEM5VuV wlzMyPcAU+ZX+jw58fRxjnL21M0Lm/iDhoSlwbEno4oKSLwPmfmSCeNtO7ly9+0OyRD+ k6fA== X-Gm-Message-State: AOAM531gUbkqmTgVI4qiy2cHoXHqB8HtgY3HZp+/n9BzDWt8UPIGuBmI UosMVgNDzzQitAWy37aCFLNZA2DV6ho= X-Google-Smtp-Source: ABdhPJyEd1WsLp7mZj43O+IKcFZ6gWMXGcqu4rpwUtNWKTQobFebTAE88vrYqiwldCc3e8q7FUyhqQ== X-Received: by 2002:a17:90b:4f86:b0:1c9:b52d:9713 with SMTP id qe6-20020a17090b4f8600b001c9b52d9713mr239670pjb.98.1648568989510; Tue, 29 Mar 2022 08:49:49 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:49 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:57 +1000 Message-Id: <20220329154931.493851-5-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 04/38] gdbserver: include argument in command line help text 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" Include argument in command line help text. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 3da15cc..7d4ce7a 100644 --- a/src/main.c +++ b/src/main.c @@ -118,7 +118,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" }, + { "gdbserver ", "", "Start a gdb server listening on " }, { "istep", " |0", "Execute istep on SBE" }, { "geti2c", " ", "Read n bytes from i2c device" }, { "puti2c", " ", "Write a value to i2c device" }, From patchwork Tue Mar 29 15:48:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610687 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=KBQWwSC0; 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 4KSYsx6QHbz9sFk for ; Wed, 30 Mar 2022 02:49:57 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYsx5gHLz2xr9 for ; Wed, 30 Mar 2022 02:49:57 +1100 (AEDT) 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=KBQWwSC0; 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::633; helo=mail-pl1-x633.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=KBQWwSC0; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 4KSYss3zFfz2yHL for ; Wed, 30 Mar 2022 02:49:53 +1100 (AEDT) Received: by mail-pl1-x633.google.com with SMTP id x2so17999498plm.7 for ; Tue, 29 Mar 2022 08:49:53 -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=Nqc1hV8sroqYY3LXRavi9ojXRyAExVBS213cLoDoBqg=; b=KBQWwSC0Y4EtaTC7Ys2qYc11kzcdLzysztC8Jjenbi1iNkNm4qN6rVc/1f/3Kv8M4c Q6IQxkff3gTVwKK9cm4IWrv+cbeLufru4EqIFw3gow4dXZ0Q4+5NToSVc+4WUhXtMxd0 AJTSST5vXOfH27rGKbDbPoffT9gC97TRWat5YqXsKXsw/yM8sQkYJRQTK3j1J869QLxS RRd5P98l82zbM5eqJkBQsNCEbJ5ff/p7nrnBJ4fruyjgyqz0yTYfRewAhR37C4ZNZX+f 3pMr8DdYVmXFifhWFrIEsRMHh8JKgz3VlIRpeI7dsGAEfWI24GntRi8G4BjPoDazd73o SoAA== 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=Nqc1hV8sroqYY3LXRavi9ojXRyAExVBS213cLoDoBqg=; b=3uX74tRN+l3qrJWDF4xPcAwoacaqPXkZfGFZHjXG2jLX4ytTidSloy2zWPB2ruj9ne VF3WGPgWcMy5xTaaoiYMffZktDWdNzzwJUluJCQcOJki5mk6vPWUNEtY4vZ5fVcH4QK4 6nywo+oVB0z5hdAOGtmIWdaKaD0Sa9Hyhyp+J2u/5Uu8fTgdkZOTLpM8ftPHkHnY3qAp s5fHW9+vokx2BU13q28s8bmcSQpaiM178RDHeO+8ubywHqQRC7TxfEn84dSc/R3qFIpI v5ZGOvhNewtSpaSKvHwxagSVGl2dfI6eCR7FzRkdnMRIcbvpMqLDzZKSVIre0Vue7Je6 VkJg== X-Gm-Message-State: AOAM533kI9Q9AVd8GL9miYhsABfczOd/LNT+iyt39w19xl5qyubwx0SB BQGRdETqc58DotR09lJxPtKIe3LbQS0= X-Google-Smtp-Source: ABdhPJx38qEuIqnlYyLFp34YkqFl6PbQ+q7M2uxo9PiGHS3GB6axO9oAN5ZWzFMY9AgriRERDX2Z6A== X-Received: by 2002:a17:90b:4d11:b0:1c7:4c81:2996 with SMTP id mw17-20020a17090b4d1100b001c74c812996mr239825pjb.170.1648568991435; Tue, 29 Mar 2022 08:49:51 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:51 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:58 +1000 Message-Id: <20220329154931.493851-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 05/38] gdbserver: Document problem and workaround for client remote timeouts 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" gdbserver does not robustly deal with the gdb client timing out and re-sending packets. Signed-off-by: Nicholas Piggin --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 316976e..be26dc1 100644 --- a/README.md +++ b/README.md @@ -546,6 +546,13 @@ $ gdb Debugging info: (gdb) set debug remote 10 +Long-running operations or high latency links: +The gdb client timeout defaults to 2 seconds after which it re-transmits +commands. The gdb server does not deal with this robustly today and this +can cause hangs and other unexpected results. If gdb client stops +responding, behaves strangely or complains about bad or unexpected remote +packets, try increasing the timeout. E.g., +(gdb) set remotetimeout 60 Notes: 1. DON'T RUN PDBG OVER FSI WHILE HOSTBOOT IS RUNNING. Weird things seem to From patchwork Tue Mar 29 15:48:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610688 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=W9qqkuAh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYsy5xSmz9sFk for ; Wed, 30 Mar 2022 02:49:58 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYsy53jCz2yR4 for ; Wed, 30 Mar 2022 02:49:58 +1100 (AEDT) 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=W9qqkuAh; 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::42e; helo=mail-pf1-x42e.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=W9qqkuAh; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 4KSYsv6rJsz2yLX for ; Wed, 30 Mar 2022 02:49:55 +1100 (AEDT) Received: by mail-pf1-x42e.google.com with SMTP id z16so16251593pfh.3 for ; Tue, 29 Mar 2022 08:49:55 -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=im8d+AivmsUr33EGeK6FMma+lN/mrvBBI2iZTdUXka0=; b=W9qqkuAhDPaVkEFHOB3MKwwegVfLZXtmagL4zBJzwVXinfHKr8mezEfXwxQrM8AO50 3+ovY+T9de9js5ZloMm30bZGmnvGFbETFNLe6aMw6rlFdCA1uvyAWimqakp+JfAOdVoB 4zm96YwUwljCAC9obmWDQy3gfVmxdLd1/RPS7HDlV7X2/3+W0whBUi9YE79iSAh2tNOO oetba3isEO2eLiN4K54l8DMKdp/2zTsvJ3FnCEByQGsLNZF5ypaXYV8sM8GGNsHiRToB VQFqORooN8AJiZdPYuLGPrtlNOtxEjG2OREgBJl9QqM29XTd1G58L36hUEUqJCvqnD/d k4zQ== 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=im8d+AivmsUr33EGeK6FMma+lN/mrvBBI2iZTdUXka0=; b=7z+ParSucQnVljteowuwmyVX8LEZkS6KpDGJKBXcNwzTU2eewbo1fcAxXeD5MEmhzA uJk57pPfrkWtcv3nTz0eNWmn1KaF+pkugFv1IogzFghXNRWHNgJoYy63aFNsFe8cd9dR xsZuDu/LU19vAE7C/jBMw86bPPTlYB2F0E7zTNUJ6BFwctxflaHE2QYOmot/pW5KGnsj iTS1hbTCsBHyAQs90iP3yVhA8irASMohvYTCvf/dlVx9kquS9sFiPQ0txs3/1VJs3ojn akVBhsy628oLY1AxQwPud4RvyQ/DLXz9h40wdcd9b4YPwn+qd84guNtZffVUHkhwnY5I aRJw== X-Gm-Message-State: AOAM531hh2lq69C4zU0tZgfyb6XQOgQozYZz+vmTb1xWZ6NGF51dx3WE 6R5v0lLudBxjsFYuk4SQ4t6oiM8Rw1s= X-Google-Smtp-Source: ABdhPJwqZY/HDx4jNL6oSfjK3UrBVOfUFUZlP6R5jE46vf5qAvPCW+rPLmA0WIwZf3WdHErdFARRYA== X-Received: by 2002:a05:6a00:1da2:b0:4fa:f803:ddd1 with SMTP id z34-20020a056a001da200b004faf803ddd1mr25028551pfw.53.1648568993752; Tue, 29 Mar 2022 08:49:53 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:53 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:48:59 +1000 Message-Id: <20220329154931.493851-7-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 06/38] gdbserver: print some client/server 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: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Rather than silently listening this gives some idea things are working. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 3e27ba0..e32f518 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -448,6 +448,8 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ return -1; } + printf("gdbserver: listening on port %d\n", port); + FD_ZERO(&active_fd_set); FD_SET(sock, &active_fd_set); @@ -463,17 +465,29 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ for (i = 0; i < FD_SETSIZE; i++) { if (FD_ISSET(i, &read_fd_set)) { if (i == sock) { + char host[NI_MAXHOST]; + struct sockaddr saddr; + socklen_t slen; int new; - new = accept(sock, NULL, NULL); + + new = accept(sock, &saddr, &slen); if (new < 0) { perror(__FUNCTION__); return -1; } - if (fd > 0) + if (getnameinfo(&saddr, slen, + host, sizeof(host), + NULL, 0, + NI_NUMERICHOST) == 0) { + printf("gdbserver: connection from gdb client %s\n", host); + } + + if (fd > 0) { /* It only makes sense to accept a single client */ + printf("gdbserver: another client already connected\n"); close(new); - else { + } else { create_client(new); FD_SET(new, &active_fd_set); } @@ -481,6 +495,7 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ if (read_from_client(i) < 0) { destroy_client(i); FD_CLR(i, &active_fd_set); + printf("gdbserver: ended connection with gdb client\n"); } } } From patchwork Tue Mar 29 15:49:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610689 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=QmTwg0PQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYt14vwSz9sFk for ; Wed, 30 Mar 2022 02:50:01 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt14Ttvz2xvv for ; Wed, 30 Mar 2022 02:50:01 +1100 (AEDT) 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=QmTwg0PQ; 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::42d; helo=mail-pf1-x42d.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=QmTwg0PQ; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 4KSYsy33Wzz2yR4 for ; Wed, 30 Mar 2022 02:49:58 +1100 (AEDT) Received: by mail-pf1-x42d.google.com with SMTP id t5so16262072pfg.4 for ; Tue, 29 Mar 2022 08:49:58 -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=7L/WP+N5xIZ2DTr1VV7mKvK3ERmRRxLOHJH30MW6PtU=; b=QmTwg0PQAXVF8K3TfLoU3QaPDJPpZKLWWQf0KNBnT2rUy9X9gITqRtZRcdRxfdCxDa t9bqVn6/3Ze8UUbhUOOcHKmccSuteqgL8LKKs0y2TM6NCQBOfmojA2kHyKUffIDBlTcT bkhbW+T83SAqsYuc8idaByQqIlHKUWH1e3MIEXDgJng74UFia7nRJQ3KPk507yhpUSIT SEksmQTduAEnGJI+vUxp6uskPKi8AHJhR7o9CdahEqbZSq/aYcCBwJEQeboqTkn0tmAL 2T4WN6WNaFjKH0FtRwBbyFWwAXqGYMyMi4EW4kAcksoTwhJy2bDLHuz4z63mOHpWh8ux UJew== 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=7L/WP+N5xIZ2DTr1VV7mKvK3ERmRRxLOHJH30MW6PtU=; b=AVo8TarqTPvuXX1ulXABLRafka36srVgg3boi0rX/sT0jX5xUUMP5YG3EkRMbG4/sx wfPJ/KNeRFjyx2d4BBJyIC8b9JLW01MQpKB0qoVWxUM3PJoQQ1EUUPbClHSKtsXwwyyc HVl2RYodo0m9GvOuabiNEwQ4hxefRk8UL00UTTm25qRP8mKIhSTukG1q61fArUZx2083 Hr0irByaEUyrPb675u+1+BYYG4xWkShbcSxi0skWcyqM5WG+Y9GciSdVl98BKcG5PRdF fTJmiyTaUAZwQjOHjxWK8GYLFeTESF1LS1F7HI5Jw7RHG9LnY1BEoT8fFeYVOMCqZd7M YslA== X-Gm-Message-State: AOAM533GiAmZygCA+XYegfK1+RWTywVpLHcZ94Bp9ucUQREQTzWKKqRV m/Hzp6x/3+n6vt03b4iIogYyX0Xf4no= X-Google-Smtp-Source: ABdhPJxOjE4VCrB+NPHrUA50Tm8m1IVCWYGZwTqNwBcq+E6Hqg0zh0ZeJcdNzrCGauoEkPKGPUf/8w== X-Received: by 2002:aa7:8893:0:b0:4fb:10e1:8976 with SMTP id z19-20020aa78893000000b004fb10e18976mr21500627pfe.36.1648568996208; Tue, 29 Mar 2022 08:49:56 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:55 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:00 +1000 Message-Id: <20220329154931.493851-8-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 07/38] gdbserver: Make command static 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" The command array is local, make it static. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index e32f518..5a8b5f9 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -405,7 +405,7 @@ static int read_from_client(int fd) return 0; } -command_cb callbacks[LAST_CMD + 1] = { +static command_cb callbacks[LAST_CMD + 1] = { cmd_default, get_gprs, get_spr, From patchwork Tue Mar 29 15:49:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610690 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=Qhp7+j95; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYt25Zskz9sFk for ; Wed, 30 Mar 2022 02:50:02 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt24R2hz2yMK for ; Wed, 30 Mar 2022 02:50:02 +1100 (AEDT) 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=Qhp7+j95; 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::62e; helo=mail-pl1-x62e.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=Qhp7+j95; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 4KSYt03gYpz2xYG for ; Wed, 30 Mar 2022 02:50:00 +1100 (AEDT) Received: by mail-pl1-x62e.google.com with SMTP id n18so17988730plg.5 for ; Tue, 29 Mar 2022 08:50:00 -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=rFsFUBiix5V2jhgKSIfZqDP+GQGBrg59SzIQLk0qU4o=; b=Qhp7+j95X/t53/7ICxOCHjMkEJkBMCU1fTXO5/lO2VYlstAJfYVD/FVK57jNLlXIqF b3Dg9kVjqQPqhkE1FYSXzSOrwBsHBx5lCZ0ihrEHXycGSOgSpn4X2I4Zy9ONeRO1LfHd 7OuogvclI5qTf72GlHt5JdrMDba7k2BCA9//ZqYmUzlz70Kyj2H+NOc3i+b0vBc+Lzx2 w76yyBnATmsG7qdQvNsnZitoq2PnZS2HFg9yRHrJZSQfZuFGyI2Rp3ItnXIU24jvbKuh X1wzYW+v9CUQfjvhoQEG5tnb1pjmnIlRRFIcq593FFwzLlRPblxzUpx/O/XvGYWCbMx+ snBA== 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=rFsFUBiix5V2jhgKSIfZqDP+GQGBrg59SzIQLk0qU4o=; b=V+2VKz5SHsd07eyZMBKlK6fBvhP8wBMYpl0QsIrhkjpyxsFgxBalJIdbnR8A8hLNoc 0MLAJB3dCOWrCE87bCrlKvY0WX7R0uFaDX5oT3xAQIhAb+HfLxQwqqCcBwzyddOGbZwl OLsCuvlv2XMPR5TJHYwbNd1Q6pPyyxb12lQm9AwEFozEsevKwFpj2i9eUrTUWv92614J HNBb86TeVN1x4lBdbCWk5P1paYSb/HL4QAGqFNh+RCKcifyOQMtjAV3M4oEgMcrVCamq YcHI9qXGqS6VXI5rS/mssBNPRtFWDrVxB3UX+q9KtSqCy7+3/FDyE1AC2kVeYq1eCxww 8irA== X-Gm-Message-State: AOAM533cdZeF685cW15D0bipynbLYkFrI9fJzH6y4vS3QjCL7JM8HFw+ y2hyhq4Z7NDLV6IEoDAZLG9wYdCOaTk= X-Google-Smtp-Source: ABdhPJyx33QD3ldaZ03sQy5SA+sAfyYvDKutUOXMAQYVPlFUdRDoFuwPvbTj5CCWqkRZnN6GmvZDxw== X-Received: by 2002:a17:902:ca13:b0:155:cea6:65b3 with SMTP id w19-20020a170902ca1300b00155cea665b3mr25181783pld.144.1648568998263; Tue, 29 Mar 2022 08:49:58 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:49:57 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:01 +1000 Message-Id: <20220329154931.493851-9-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 08/38] gdbserver: use standard compatibility test calls 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" p10.dts.m4 defines compatible = "ibm,power-thread", "ibm,power10-thread" which fails to match on a basic strcmp. Aside, find_driver in hwunit.c looks like the only other place that does a strcmp on compatible. I wonder if that should be changed as well? Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 5a8b5f9..906ed2f 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -532,8 +532,8 @@ static int gdbserver(uint16_t port) // // Temporary until I can get this working a bit smoother on p9 - if (strcmp(thread->compatible, "ibm,power8-thread")) { - PR_ERROR("GDBSERVER is only tested on POWER8\n"); + if (!pdbg_target_compatible(thread, "ibm,power8-thread")) { + PR_ERROR("GDBSERVER is only available on POWER8\n"); return -1; } From patchwork Tue Mar 29 15:49:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610691 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=fMrEK+lP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYt549SHz9sFk for ; Wed, 30 Mar 2022 02:50:05 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt53Rwlz2yHB for ; Wed, 30 Mar 2022 02:50:05 +1100 (AEDT) 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=fMrEK+lP; 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::629; helo=mail-pl1-x629.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=fMrEK+lP; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 4KSYt25bhrz2yMf for ; Wed, 30 Mar 2022 02:50:02 +1100 (AEDT) Received: by mail-pl1-x629.google.com with SMTP id i11so6715151plg.12 for ; Tue, 29 Mar 2022 08:50:02 -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=bceLJN7ktN9LqZd4Rgv2LwLHyETl4iqyA79zcOf++QM=; b=fMrEK+lPQVPcLn9opxAz2vGNdIwj4fi2oycEYnJ2F4LNZnrvMSM9vT7TjRTqXTdAx0 2gc/Xq6XbDX0YiRuYtenGk1Dyo/VUV2rPEIvhXn43ywS7E7oEgeYGxDnoa+sL2FP0y3Y 9kZxuTffXF3vbob438jpXwYp9QpPIahp+euZtoVbVX9ml12u6Sqvdh/0dUNpWQbXWlym W9ZMUP5U+c4bqIst7fzfHWYYHdmi3oOAjFftjiw4ZMNqWVopb91WUwTjMf0/hvLV4iBW WdwkdEL98K82jG3NnN3ylWvsnyNYnFPvEM7cUklbpWy/I4fY7EDIAHlCA+el2+/eMtCU ji+w== 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=bceLJN7ktN9LqZd4Rgv2LwLHyETl4iqyA79zcOf++QM=; b=nf9xdU1SbgH/aghJ662gsyl5acMsmIcSgODvXIde4x/ROn0VeLoMaRb6W2hgCkc0Lb VNj4seaqTjtTzQBwwP0FJKrx1j+X3d8iB56cJokIJ4yjzUJ+aoBZbDNeIAB+rQwoe3nJ qrBKkL9lvvVz1gQ4GH23/OYmFlMVQXMVct9TK6npBfX1uQ8hv0mIlvqke2GzGEfQBOBL lPzwE/LQL4gpqWoaVtlQ03gmaUJc7BLFosBT+gj/VON+rQ0vzpfFzn/6iB4LREME+F2f fz05RRIP/hGLGV7JwS7yvOc+A4ZoS+tzOWu1DIShqV2l07PA3yzsXYIcQ2CyXTk0PueN 8Stw== X-Gm-Message-State: AOAM532jzNJMUea1gKcNRR+0jp01Xv5zXPQCOKO6Cio9EhnRqzHO6qtx IqW9KeZACmzYHFYsSR3lGlRtcxpLQR0= X-Google-Smtp-Source: ABdhPJwmXbodo7f3EuOopGsSa0pTar08QLZh9Xs/Rij3ZM66Q4gVYuqSVsHVAADFq3h6rjbrV9J/qQ== X-Received: by 2002:a17:902:cec8:b0:154:6dd6:255d with SMTP id d8-20020a170902cec800b001546dd6255dmr31532265plg.62.1648569000529; Tue, 29 Mar 2022 08:50:00 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:00 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:02 +1000 Message-Id: <20220329154931.493851-10-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 09/38] gdbserver: fix read buffer overflow 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" buffer gets NUL terminated so read must return max of size - 1. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 906ed2f..4c6327f 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -385,10 +385,10 @@ static void destroy_client(int dead_fd) static int read_from_client(int fd) { - char buffer[BUFFER_SIZE + 1]; + char buffer[BUFFER_SIZE]; int nbytes; - nbytes = read(fd, buffer, sizeof(buffer)); + nbytes = read(fd, buffer, sizeof(buffer) - 1); if (nbytes < 0) { perror(__FUNCTION__); return -1; From patchwork Tue Mar 29 15:49:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610692 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=Z2CXlW6K; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYt73VWJz9sFk for ; Wed, 30 Mar 2022 02:50:07 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt731lyz2xBK for ; Wed, 30 Mar 2022 02:50:07 +1100 (AEDT) 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=Z2CXlW6K; 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::62b; helo=mail-pl1-x62b.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=Z2CXlW6K; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 4KSYt458zZz2xBK for ; Wed, 30 Mar 2022 02:50:04 +1100 (AEDT) Received: by mail-pl1-x62b.google.com with SMTP id i11so6715264plg.12 for ; Tue, 29 Mar 2022 08:50:04 -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=xANBNAGcezeme0LOA2ZQBIoH/LrUoKn7Lw5gNP0G1E8=; b=Z2CXlW6KXErk9iBq7hLqlutf/wQWInwGv7ECqPUTVV3ButmnVuC3KXhFVOnVSH5oiN H7IWamag0N8qy5m38M5KlKqalYmNJIk0QiPlmWZyQgV2Pe0l9/YPx//cYm9GqqpXfsRu OSciepAWrU95DFGkU1S27Nx02gBSz475QOFhXdssbqGK/WkDC+XIa2GRKacqd/NeteyO tLCLrfqh+Ti8DRRpEPsnIloIeeN1obNP3RVp/T83vgtzrqug16ny5/tnKeqLS2rpe07z fcIAqOHmQZZPQJxCje3HWTIfFDHAbzJ1dn/lQrUIgbUlumrBnBRRCB5HCqtE1x+z5RQ1 LgQg== 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=xANBNAGcezeme0LOA2ZQBIoH/LrUoKn7Lw5gNP0G1E8=; b=Yq7MVoO7S9EJkFCGtm/Yn4NBsdVVUXn1CUTnnP8IIMjoRcLT9sH9ICUjjGXmLTefIv w5MJNdyvbtBzN/lAxDy77Pw5WB8i8uQsArLExW6xzsPyuWH03SGk9ZYPO5xwe0wVLSLK nelKUrQ/sWSZo0iog9KPmM+7/4H8TsovHcj0M5jrY/2CsdfqPzHtzOhbkoNpTLFqErBM ieo/sgvkvoG9vYJmqHAQ8KTT/cdgwWCI5MECow66byOZJypWmEN3503Pi/SzR4mMkp3r 8cqQM+E9hWkpdD4Pd0S7Ggh51VEl/KUoqvv5IphjR5MnieKKA25EcC3By9/ZulOJ+0nn ycNg== X-Gm-Message-State: AOAM532k541K4hwh2pBgeOXjGSk5Fko5WN6z/9RRjMuBcQsFTlFx3bt9 yVWXESou5SGsPtI46MuQkzHbjd9CRzM= X-Google-Smtp-Source: ABdhPJwJNxJr1+x4S3tpj7+/DTjuams1VqaWyJvSSF7ExrcQUoK3fQiy31rqvqJU7KJAo77Pq+u+Aw== X-Received: by 2002:a17:902:ce08:b0:153:8d90:a109 with SMTP id k8-20020a170902ce0800b001538d90a109mr30681238plg.157.1648569002415; Tue, 29 Mar 2022 08:50:02 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:02 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:03 +1000 Message-Id: <20220329154931.493851-11-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 10/38] gdbserver: reduce PR_INFO noise 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" Printing the first byte of the received packet in hex on its own line is not very useful and clutters debug output. We print the full received packet anyway which is generally quite readable. Remove the first byte info line, and replace it with a debug line that contains the entire hex string as hex bytes. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4c6327f..9e5e7d8 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -396,9 +396,15 @@ static int read_from_client(int fd) PR_INFO("0 bytes\n"); return -1; } else { + int i; + buffer[nbytes] = '\0'; - PR_INFO("%x\n", buffer[0]); PR_INFO("Recv: %s\n", buffer); + pdbg_log(PDBG_DEBUG, " hex: "); + for (i = 0; i < nbytes; i++) + pdbg_log(PDBG_DEBUG, "%02x ", buffer[i]); + pdbg_log(PDBG_DEBUG, "\n"); + parse_buffer(buffer, nbytes, &fd); } From patchwork Tue Mar 29 15:49:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610693 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=fSOVtAqU; 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 4KSYt8509vz9sFk for ; Wed, 30 Mar 2022 02:50:08 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt83crZz2yJ5 for ; Wed, 30 Mar 2022 02:50:08 +1100 (AEDT) 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=fSOVtAqU; 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::632; helo=mail-pl1-x632.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=fSOVtAqU; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 4KSYt60TNgz2xr9 for ; Wed, 30 Mar 2022 02:50:06 +1100 (AEDT) Received: by mail-pl1-x632.google.com with SMTP id f10so7659817plr.6 for ; Tue, 29 Mar 2022 08:50:05 -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=i9k4DWVGb/MmzaFdC5D9OzoWnfTirgUUpyc3DNlRM+A=; b=fSOVtAqUmwxK9Rl9Mk5k7JvzUqtQphsE4beFnCZhGrB1dcVidQtm0Sl5keF3gsSnIQ 1PiqB8APyxW3BfdY2QH5Y0vmGI/rsPiEi4Mtk69MK1ZNWB3UTWdlhWtGohp9fLLMReHT hs7cjKTKX3B/sNu+xVelay0qaYVY5o5aVOI4Jupw3xBJrSKiYhvNETNg2yxaZjhYQXCj aUTVS6x5rpXzsW0CQ4ZQcG2xOtyIwmM899mxZVdKJ3LeFpdaAD9O0fu4/TVoQ5uIoU5U STgT1z+d+HFDJe5O/V+vBSZ2j0ZhdvfhlIN2tqaIkibmz0AcCRZP6sBx77A/M62RxX7E V1Qw== 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=i9k4DWVGb/MmzaFdC5D9OzoWnfTirgUUpyc3DNlRM+A=; b=v2a9biYzVXyK01jcOhNjJGlcNSe5wmHPZRaSHEqJ+SqF49ArS8w1/CRi32NC2h19DE MSdRt1BGLPUtiGSkRBYeVrAx3bEGlD8rLq1MQ2xSo6YoX7Qte0PTKYxo2tZdSWcmlfS3 GDPhvD7E/VC798+UdWzKT8kjLWD2jpxLdj2dFNyOyt73TzknhKPHkp0lbKJ0mpC/vmzB YaGViPyFmuLtI0nBQ3K5CavXLYiTSIneLV2NBEjYqwmD9F2oxt7Lt7rt6kn+Xf0NM6XX k3+Isomsop0tH99l9uKiWfsShh6jAv2zLbNn38T0phMhK5yPPub6K5HYStCO8nTCTIww 4QXQ== X-Gm-Message-State: AOAM530H5QNTUOQjiuPd7CGk6iAn95VoWjDyRXlnQ8n3w0DhLZXleD5q zR9RMcnTTSYhFmqkjIu1wTbguf7LHIo= X-Google-Smtp-Source: ABdhPJwIFd92ElYEVG7yQZxRzlshTZj+s3gFYxuLd7cqNTtdGH1f8flCVdomykr77ageMvygF7Onfw== X-Received: by 2002:a17:90a:8a05:b0:1c6:e527:c613 with SMTP id w5-20020a17090a8a0500b001c6e527c613mr205370pjn.143.1648569004329; Tue, 29 Mar 2022 08:50:04 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:04 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:04 +1000 Message-Id: <20220329154931.493851-12-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 11/38] gdbserver: fix interrupt double stop reason response 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" The interrupt command sends a stop reason (TRAP) response, then the main loop notices that the thread was stopped and also sends a stop reason response. Prevent the second response by having the interrupt handler move the state to IDLE. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 9e5e7d8..1668126 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -320,11 +320,20 @@ static void v_contc(uint64_t *stack, void *priv) static void interrupt(uint64_t *stack, void *priv) { - PR_INFO("Interrupt\n"); + struct thread_state status; + + PR_INFO("Interrupt from gdb client\n"); + thread_stop(thread_target); - send_response(fd, TRAP); - return; + status = thread_status(thread_target); + if (!(status.quiesced)) { + PR_ERROR("Could not quiesce thread\n"); + return; + } + state = IDLE; + poll_interval = VCONT_POLL_DELAY; + send_response(fd, TRAP); } static void poll(void) From patchwork Tue Mar 29 15:49:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610694 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=YgHK2X21; 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 4KSYtC4RvJz9sFk for ; Wed, 30 Mar 2022 02:50:11 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtC3M26z2yHt for ; Wed, 30 Mar 2022 02:50:11 +1100 (AEDT) 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=YgHK2X21; 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::52a; helo=mail-pg1-x52a.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=YgHK2X21; dkim-atps=neutral Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) (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 4KSYt84GrRz2xvW for ; Wed, 30 Mar 2022 02:50:08 +1100 (AEDT) Received: by mail-pg1-x52a.google.com with SMTP id t4so12112266pgc.1 for ; Tue, 29 Mar 2022 08:50:08 -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=mxOPp0hWtq3q4pMh7FIDwn9oHGtXHbmu896O/A8YW+k=; b=YgHK2X21co+95n0eeIiK8Y09CO62r5Zls/JVC5a1J353/LBizhcoe5zrqC6FVTqPyo bDPfrn8pwpGU9ReGXPO0Afwhhkp3MYnF1O6cBHvNUxiqbrZhxVhUBR8waEPoeqGP0xwD IOYS0gryQ27lA5LlBaaDS81p5n44V4V2ioI5Q/hfqQCYdIpga0kv+r6uohNTC49ctM1c P6kPXZAeGOxrNJtfQlSUSYI+fhiHJ8Rx+r14JjuFub4HPGcXe+QmxcoL2tVIx3Aw8xEg P4SEpUj2SGEaj7/g6I3Rcu/3W5Fw+dJFBGGmFFlgYWpVmVHfrfK9u8nfBZCFA0nJHY1l Bqaw== 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=mxOPp0hWtq3q4pMh7FIDwn9oHGtXHbmu896O/A8YW+k=; b=VrGxLLMEHWOOx4JkcDjkrbZub8M9qTlkcBA+sSMog3o69m9lEAaaa4N4t4tB8s/DDf +3MiCFV1jSLUUTTESkWxZchjxCFb/rdTNbJQSA6+k7rHXOdRTeJhvq/ciOG3NMNRFxaw xNI29GvoIEXt0ElpiIGNrLJXz0cr7GnyHKAVidOE8N5s7LGEjbgTxOHHUSxh0PnljajR 84VJSWovR8rmFvEhFrf1F3G/74yh7twNDL/NuQdaHJbD8Ywd/feEL3z0uX88L/m8l33c RepSKKDp8GZB71wQmMrdoyTdbB4DbGoiy3Z7XRn0xVx0LyLXTsBExfa+6WvOw1IhxL+i Q2Mw== X-Gm-Message-State: AOAM530mMnw/vQzUillFs/x3s2vS2xCrzSLlkyIuUGRxHqo7OfDp89mq FpFdism9BE0mkocXTxy0YELNGPHoyTk= X-Google-Smtp-Source: ABdhPJw8ALLif/nYqy5hPcwJSerFqoE1ESOrRC91N1PwzE2NumVbUta599gjoszrZ2OGcGJaNgey2w== X-Received: by 2002:a63:9502:0:b0:386:3916:ca8e with SMTP id p2-20020a639502000000b003863916ca8emr2413295pgd.357.1648569006519; Tue, 29 Mar 2022 08:50:06 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:06 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:05 +1000 Message-Id: <20220329154931.493851-13-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 12/38] libpdbg: thread_regs don't print regs 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" The gdbserver uses thread_getregs to send data to the client, printing to console is noisy. Push the printing into callers that want it. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- libpdbg/chip.c | 2 -- libpdbg/thread.c | 7 +------ src/thread.c | 2 ++ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/libpdbg/chip.c b/libpdbg/chip.c index 79aeb35..6cbf48b 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -380,8 +380,6 @@ int ram_getregs(struct thread *thread, struct thread_regs *regs) CHECK_ERR(thread->ram_destroy(thread)); - thread_print_regs(regs); - return 0; } diff --git a/libpdbg/thread.c b/libpdbg/thread.c index 4a7523c..78a59b8 100644 --- a/libpdbg/thread.c +++ b/libpdbg/thread.c @@ -371,7 +371,6 @@ void thread_print_regs(struct thread_regs *regs) int thread_getregs(struct pdbg_target *target, struct thread_regs *regs) { struct thread *thread; - int err; assert(pdbg_target_is_class(target, "thread")); @@ -385,11 +384,7 @@ int thread_getregs(struct pdbg_target *target, struct thread_regs *regs) return -1; } - err = thread->getregs(thread, regs); - if (!err) - thread_print_regs(regs); - - return err; + return thread->getregs(thread, regs); } int thread_getgpr(struct pdbg_target *target, int gpr, uint64_t *value) diff --git a/src/thread.c b/src/thread.c index 8ddf4ae..76909d6 100644 --- a/src/thread.c +++ b/src/thread.c @@ -362,6 +362,8 @@ static int thread_regs_print(struct reg_flags flags) if (thread_getregs(thread, ®s)) continue; + thread_print_regs(®s); + if (flags.do_backtrace) { struct pdbg_target *adu; From patchwork Tue Mar 29 15:49: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: 1610695 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=NyMQNKwn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtF2knzz9sFk for ; Wed, 30 Mar 2022 02:50:13 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtF1zFPz2yJ5 for ; Wed, 30 Mar 2022 02:50:13 +1100 (AEDT) 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=NyMQNKwn; 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::62f; helo=mail-pl1-x62f.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=NyMQNKwn; dkim-atps=neutral Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 4KSYtC0nYZz2xfP for ; Wed, 30 Mar 2022 02:50:11 +1100 (AEDT) Received: by mail-pl1-x62f.google.com with SMTP id y6so15465203plg.2 for ; Tue, 29 Mar 2022 08:50:10 -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=4+dTcEfmpdH/3SyYIj/BMhVrtNQpCXYmoa6/8ZUzZcY=; b=NyMQNKwnq2jODOAaoGbqP5QjiP5J9Tjx/Yye88uBJmxp8AY4mF7VxT1Ytvtn5EAsXu gzShEkBwMG6lWOrnPD6Wev0phBCbcuf1uDPI+Q06qZf73S5QVZ6YhuFd4mxTkg+nQq8h 3FW3pJpH8F93bUkHYthCQiA0fnwADR/18Lu4gm1T6ImXi47dA1j0LRtMKWlwMIhpcH38 eA00v45usVwKwUj9/o5pLYoa14RAXA13xUIzX4P2rLwGP+lOcy6PtSNQgX97rw0szrht dlvBcTytcEvoFVA/GxptREvkUNLOFYbuZWFdV+qHsYHU+mFGVmzJEyBWwBufDL+NlAzm V69Q== 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=4+dTcEfmpdH/3SyYIj/BMhVrtNQpCXYmoa6/8ZUzZcY=; b=686uMVRxgmzEtxeKSac8WglbHwUZu1MT//a7RrSESe3khQw94wRCfX0SmMq89njkpD NEQRCYZcTMT3Pc3NtdnddjmIJw+4l5DsuHUY4r+FZcD6/FmIjO2u0c7fmVmEhHCWioEQ +vPeR8j/BWOjGzw82hXlBrapW6Ky2MvGh3d/Fc69wsdy3H4nN39eyK7p37cuw2/KZre5 X+cmC5XHNfC8Abj/CaHDVnpB0psnFe9rIofCl4e1NIdjt+mHFO/JhPN1pWUfES1iSdpq 5YGD3aplVxTjrHaK94jHciKLPQpAfdUxk6GNBHKOGzYD0RXolXF/gvPGtRRk9pS4UMYI futQ== X-Gm-Message-State: AOAM5310udVMN5cXRb8kZ8vt/5ewAtXSlKMlbFfLZLG/2g3zLtHVllXJ smYI3abgDW2BMteZfkdRDNCWtZqLvfo= X-Google-Smtp-Source: ABdhPJztpIEvAZA3sD40sGJgmJVN5TlM8nwDuJr9asc72s9Q0xeNSrcX0K61N7jNGUhjPvuZCA4pUA== X-Received: by 2002:a17:90b:2486:b0:1bc:9d6a:f22 with SMTP id nt6-20020a17090b248600b001bc9d6a0f22mr196599pjb.211.1648569008509; Tue, 29 Mar 2022 08:50:08 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:08 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:06 +1000 Message-Id: <20220329154931.493851-14-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 13/38] gdbserver: lexer fixes 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" The lexer is coded in a funny way that ignores all packets that don't match a command or interrupt to start with, and then expects a command or ack/nack following an interrupt. This results in leading ack/nack not being matched as such which is fine because they're ignored but makes things confusing. But it also results in command errors for the command following an interrupt. All this complexity and problems seems to have arisen because the trailing NUL termination is passed in to the buffer which has made everything more complicated. Fix this by not passing in the trailing NUL, and rewriting the lexer so it always matches one of a command, interrupt, ack, or nack at the high level. Command / crc reset is done at entry to the command state. Some additional checks and debugging messages are added. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 56 +++++-- src/gdb_parser_precompile.c | 314 +++++++++++++++++++----------------- 2 files changed, 209 insertions(+), 161 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 629a091..72a907c 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -1,9 +1,11 @@ -#include +#include #include +#include #include #include #include "src/pdbgproxy.h" +#include "debug.h" %%{ machine gdb; @@ -14,6 +16,7 @@ data = stack; memset(stack, 0, sizeof(stack)); crc = 0; + PR_INFO("RAGEL: CRC reset\n"); } action crc { @@ -39,10 +42,10 @@ action end { /* *data should point to the CRC */ if (crc != *data) { - printf("CRC error\n"); + printf("CRC error cmd %d\n", cmd); send_nack(priv); } else { - printf("Cmd %d\n", cmd); + PR_INFO("Cmd %d\n", cmd); send_ack(priv); /* Push the response onto the stack */ @@ -51,7 +54,8 @@ else *data = 0; - command_callbacks[cmd](stack, priv); + if (command_callbacks) + command_callbacks[cmd](stack, priv); } } @@ -82,28 +86,29 @@ # 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+";}); + 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;}); + unknown = (any*); - interrupt = (3 @{command_callbacks[INTERRUPT](stack, priv);}); + interrupt = (3 @{ if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");}); 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 | detach ); + v_contq | v_contc | v_conts | put_mem | detach | unknown ); - cmd = ((commands & ^'#'*) | ^'#'*) $crc - ('#' xdigit{2} $hex_digit @end); + cmd = (('$' ((commands & ^'#'*) >reset $crc) + ('#' xdigit{2} $hex_digit @end)) >{PR_INFO("RAGEL:cmd\n");}); # We ignore ACK/NACK for the moment - ack = ('+'); - nack = ('-'); + ack = ('+' >{PR_INFO("RAGEL:ack\n");}); + nack = ('-' >{PR_INFO("RAGEL:nack\n");}); - main := (( ^('$' | interrupt)*('$' | interrupt) @reset) (cmd | ack | nack))*; + main := (cmd | interrupt | ack | nack)*; }%% @@ -113,7 +118,7 @@ static char *rsp; static uint8_t crc; static int cs; -command_cb *command_callbacks; +static command_cb *command_callbacks; %%write data; @@ -127,20 +132,39 @@ void parser_init(command_cb *callbacks) int parse_buffer(char *buf, size_t len, void *priv) { char *p = buf; - char *pe = p + len + 1; + char *pe = p + len; %%write exec; + if (cs == gdb_error) { + printf("parse error\n"); + return -1; + } + return 0; } #if 0 +void send_nack(void *priv) +{ + printf("Send: -\n"); +} + +void send_ack(void *priv) +{ + printf("Send: +\n"); +} + int main(int argc, char **argv) { parser_init(NULL); - if (argc > 1) - parse_buffer(argv[1], strlen(argv[1]), NULL); + if (argc > 1) { + int i; + for (i = 1; i < argc; i++) + parse_buffer(argv[i], strlen(argv[i]), NULL); + } + return 0; } #endif diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index f787a29..d8dc9c3 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -1,14 +1,16 @@ #line 1 "src/gdb_parser.rl" -#include +#include #include +#include #include #include #include "src/pdbgproxy.h" +#include "debug.h" -#line 108 "src/gdb_parser.rl" +#line 113 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -17,168 +19,157 @@ static char *rsp; static uint8_t crc; static int cs; -command_cb *command_callbacks; +static command_cb *command_callbacks; -#line 24 "src/gdb_parser.c" +#line 26 "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, + 3, 1, 14, 1, 19, 1, 20, 1, + 21, 1, 22, 2, 0, 1, 2, 2, + 1, 2, 3, 1, 2, 3, 4, 2, + 10, 1, 2, 12, 1, 2, 13, 1, 2, 14, 1, 2, 15, 1, 2, 16, - 1, 2, 17, 1, 2, 18, 1, 2, - 19, 0, 3, 1, 19, 0 + 1, 2, 17, 1, 2, 18, 1, 3, + 0, 5, 1, 3, 0, 6, 1, 3, + 0, 7, 1, 3, 0, 8, 1, 3, + 0, 9, 1, 3, 0, 11, 1 }; static const unsigned char _gdb_key_offsets[] = { - 0, 0, 2, 14, 15, 21, 27, 30, - 38, 46, 53, 60, 61, 68, 76, 83, - 91, 98, 106, 111, 113, 115, 117, 119, - 121, 123, 125, 127, 134, 136, 138, 140, - 142, 144, 146, 148, 150, 152, 153, 155, - 157, 159, 161, 163, 165, 167, 169, 171, - 173, 175, 177, 179, 181, 184, 187, 188, - 189, 191 + 0, 0, 10, 11, 17, 23, 30, 37, + 38, 45, 53, 60, 68, 75, 83, 88, + 90, 92, 94, 96, 98, 100, 102, 104, + 111, 113, 115, 117, 119, 121, 123, 125, + 127, 129, 130, 132, 134, 136, 138, 140, + 142, 144, 146, 148, 150, 152, 154, 156, + 158, 161, 164, 165, 166 }; static const char _gdb_trans_keys[] = { - 3, 36, 35, 43, 45, 63, 68, 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, + 35, 63, 68, 72, 77, 103, 109, 112, + 113, 118, 35, 48, 57, 65, 70, 97, + 102, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, 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, 35, 48, 57, - 65, 70, 97, 102, 35, 44, 48, 57, + 65, 70, 97, 102, 35, 58, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, - 70, 97, 102, 35, 58, 48, 57, 65, - 70, 97, 102, 35, 48, 57, 65, 70, - 97, 102, 35, 44, 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 + 70, 97, 102, 35, 44, 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, + 43, 45, 0 }; static const char _gdb_single_lengths[] = { - 0, 2, 12, 1, 0, 0, 3, 2, - 2, 1, 1, 1, 1, 2, 1, 2, - 1, 2, 5, 2, 2, 2, 2, 2, - 2, 2, 2, 1, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 1, 2, 2, + 0, 10, 1, 0, 0, 1, 1, 1, + 1, 2, 1, 2, 1, 2, 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, - 2, 2, 2, 2, 3, 3, 1, 1, - 2, 3 + 3, 3, 1, 1, 4 }; static const char _gdb_range_lengths[] = { - 0, 0, 0, 0, 3, 3, 0, 3, - 3, 3, 3, 0, 3, 3, 3, 3, - 3, 3, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 0, + 0, 0, 0, 3, 3, 3, 3, 0, + 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, 0 }; -static const short _gdb_index_offsets[] = { - 0, 0, 3, 16, 18, 22, 26, 30, - 36, 42, 47, 52, 54, 59, 65, 70, - 76, 81, 87, 93, 96, 99, 102, 105, - 108, 111, 114, 117, 122, 125, 128, 131, - 134, 137, 140, 143, 146, 149, 151, 154, - 157, 160, 163, 166, 169, 172, 175, 178, - 181, 184, 187, 190, 193, 197, 201, 203, - 205, 208 +static const unsigned char _gdb_index_offsets[] = { + 0, 0, 11, 13, 17, 21, 26, 31, + 33, 38, 44, 49, 55, 60, 66, 72, + 75, 78, 81, 84, 87, 90, 93, 96, + 101, 104, 107, 110, 113, 116, 119, 122, + 125, 128, 130, 133, 136, 139, 142, 145, + 148, 151, 154, 157, 160, 163, 166, 169, + 172, 176, 180, 182, 184 }; static const char _gdb_indicies[] = { - 1, 2, 0, 4, 5, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 3, - 4, 3, 15, 15, 15, 16, 17, 17, - 17, 16, 19, 20, 21, 18, 1, 2, - 22, 22, 22, 0, 1, 2, 17, 17, - 17, 0, 4, 23, 23, 23, 3, 24, - 23, 23, 23, 3, 4, 25, 4, 26, - 26, 26, 3, 4, 27, 26, 26, 26, - 3, 4, 28, 28, 28, 3, 4, 29, - 28, 28, 28, 3, 4, 30, 30, 30, - 3, 4, 29, 30, 30, 30, 3, 4, - 31, 32, 33, 34, 3, 4, 35, 3, - 4, 36, 3, 4, 37, 3, 4, 38, - 3, 4, 39, 3, 4, 40, 3, 4, - 41, 3, 4, 42, 3, 4, 43, 43, - 43, 3, 4, 44, 3, 4, 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, 4, - 54, 3, 4, 55, 3, 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, 69, 3, 4, 70, 71, - 3, 4, 72, 4, 73, 1, 2, 0, - 19, 20, 21, 18, 0 + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 0, 12, 11, 13, 13, 13, + 14, 15, 15, 15, 14, 12, 16, 16, + 16, 11, 17, 16, 16, 16, 11, 12, + 18, 12, 19, 19, 19, 11, 12, 20, + 19, 19, 19, 11, 12, 21, 21, 21, + 11, 12, 22, 21, 21, 21, 11, 12, + 23, 23, 23, 11, 12, 22, 23, 23, + 23, 11, 12, 24, 25, 26, 27, 11, + 12, 28, 11, 12, 29, 11, 12, 30, + 11, 12, 31, 11, 12, 32, 11, 12, + 33, 11, 12, 34, 11, 12, 35, 11, + 12, 36, 36, 36, 11, 12, 37, 11, + 12, 38, 11, 12, 39, 11, 12, 40, + 11, 12, 41, 11, 12, 42, 11, 12, + 43, 11, 12, 44, 11, 12, 45, 11, + 47, 46, 12, 48, 11, 12, 49, 11, + 12, 50, 11, 12, 51, 11, 12, 52, + 11, 12, 53, 11, 12, 54, 11, 12, + 55, 11, 12, 56, 11, 12, 57, 11, + 12, 58, 11, 12, 59, 11, 12, 60, + 11, 12, 61, 11, 12, 62, 63, 11, + 12, 64, 65, 11, 12, 66, 12, 67, + 68, 69, 70, 71, 14, 0 }; static const char _gdb_trans_targs[] = { - 1, 2, 2, 3, 4, 57, 3, 9, - 11, 12, 3, 16, 9, 18, 48, 5, - 0, 56, 6, 2, 7, 2, 8, 10, - 4, 11, 13, 14, 15, 9, 17, 19, - 3, 28, 38, 20, 21, 22, 23, 24, - 25, 26, 27, 27, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 37, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 3, - 49, 50, 51, 52, 53, 3, 54, 55, - 54, 55 + 2, 3, 2, 5, 7, 8, 2, 12, + 5, 14, 44, 2, 3, 4, 0, 52, + 6, 3, 7, 9, 10, 11, 5, 13, + 15, 2, 24, 34, 16, 17, 18, 19, + 20, 21, 22, 23, 23, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 2, 3, + 35, 36, 37, 38, 39, 40, 41, 42, + 43, 2, 45, 46, 47, 48, 49, 2, + 50, 51, 50, 51, 52, 1, 52, 52 }; static const char _gdb_trans_actions[] = { - 0, 63, 1, 3, 0, 3, 33, 39, - 3, 24, 27, 21, 30, 3, 3, 7, - 0, 18, 3, 66, 0, 9, 7, 15, - 5, 36, 15, 12, 15, 12, 15, 3, - 45, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 42, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 48, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 51, - 3, 3, 3, 3, 3, 54, 3, 3, - 57, 60 + 19, 1, 71, 75, 19, 59, 63, 55, + 67, 19, 19, 3, 0, 7, 0, 28, + 25, 5, 31, 25, 22, 25, 22, 25, + 3, 37, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 34, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 40, 9, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 43, 3, 3, 3, 3, 3, 46, + 3, 3, 49, 52, 11, 13, 15, 17 }; -static const int gdb_start = 56; -static const int gdb_first_final = 56; +static const int gdb_start = 52; +static const int gdb_first_final = 52; static const int gdb_error = 0; -static const int gdb_en_main = 56; +static const int gdb_en_main = 52; -#line 119 "src/gdb_parser.rl" +#line 124 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 177 "src/gdb_parser.c" +#line 168 "src/gdb_parser.c" { cs = gdb_start; } -#line 123 "src/gdb_parser.rl" +#line 128 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -186,10 +177,10 @@ void parser_init(command_cb *callbacks) int parse_buffer(char *buf, size_t len, void *priv) { char *p = buf; - char *pe = p + len + 1; + char *pe = p + len; -#line 193 "src/gdb_parser.c" +#line 184 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -264,30 +255,31 @@ _match: switch ( *_acts++ ) { case 0: -#line 11 "src/gdb_parser.rl" +#line 13 "src/gdb_parser.rl" { cmd = 0; rsp = NULL; data = stack; memset(stack, 0, sizeof(stack)); crc = 0; + PR_INFO("RAGEL: CRC reset\n"); } break; case 1: -#line 19 "src/gdb_parser.rl" +#line 22 "src/gdb_parser.rl" { crc += *p; } break; case 2: -#line 23 "src/gdb_parser.rl" +#line 26 "src/gdb_parser.rl" { data++; assert(data < &stack[10]); } break; case 3: -#line 28 "src/gdb_parser.rl" +#line 31 "src/gdb_parser.rl" { *data *= 16; @@ -300,14 +292,14 @@ _match: } break; case 4: -#line 39 "src/gdb_parser.rl" +#line 42 "src/gdb_parser.rl" { /* *data should point to the CRC */ if (crc != *data) { - printf("CRC error\n"); + printf("CRC error cmd %d\n", cmd); send_nack(priv); } else { - printf("Cmd %d\n", cmd); + PR_INFO("Cmd %d\n", cmd); send_ack(priv); /* Push the response onto the stack */ @@ -316,71 +308,84 @@ _match: else *data = 0; - command_callbacks[cmd](stack, priv); + if (command_callbacks) + command_callbacks[cmd](stack, priv); } } break; case 5: -#line 58 "src/gdb_parser.rl" +#line 62 "src/gdb_parser.rl" {cmd = GET_MEM;} break; case 6: -#line 63 "src/gdb_parser.rl" +#line 67 "src/gdb_parser.rl" {cmd = PUT_MEM;} break; case 7: -#line 70 "src/gdb_parser.rl" +#line 74 "src/gdb_parser.rl" {cmd = GET_GPRS;} break; case 8: -#line 72 "src/gdb_parser.rl" +#line 76 "src/gdb_parser.rl" {cmd = GET_SPR;} break; case 9: -#line 75 "src/gdb_parser.rl" +#line 79 "src/gdb_parser.rl" {cmd = STOP_REASON;} break; case 10: -#line 77 "src/gdb_parser.rl" +#line 81 "src/gdb_parser.rl" {cmd = SET_THREAD;} break; case 11: -#line 79 "src/gdb_parser.rl" +#line 83 "src/gdb_parser.rl" {cmd = DETACH;} break; case 12: -#line 83 "src/gdb_parser.rl" +#line 87 "src/gdb_parser.rl" {rsp = "1";} break; case 13: -#line 84 "src/gdb_parser.rl" +#line 88 "src/gdb_parser.rl" {rsp = "QC1";} break; case 14: -#line 85 "src/gdb_parser.rl" +#line 89 "src/gdb_parser.rl" {rsp = "multiprocess+;vContSupported+";} break; case 15: -#line 86 "src/gdb_parser.rl" +#line 90 "src/gdb_parser.rl" {rsp = "m1l";} break; case 16: -#line 89 "src/gdb_parser.rl" +#line 93 "src/gdb_parser.rl" {rsp = "vCont;c;C;s;S";} break; case 17: -#line 90 "src/gdb_parser.rl" +#line 94 "src/gdb_parser.rl" {cmd = V_CONTC;} break; case 18: -#line 91 "src/gdb_parser.rl" +#line 95 "src/gdb_parser.rl" {cmd = V_CONTS;} break; case 19: -#line 93 "src/gdb_parser.rl" - {command_callbacks[INTERRUPT](stack, priv);} +#line 98 "src/gdb_parser.rl" + { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; -#line 384 "src/gdb_parser.c" + case 20: +#line 105 "src/gdb_parser.rl" + {PR_INFO("RAGEL:cmd\n");} + break; + case 21: +#line 108 "src/gdb_parser.rl" + {PR_INFO("RAGEL:ack\n");} + break; + case 22: +#line 109 "src/gdb_parser.rl" + {PR_INFO("RAGEL:nack\n");} + break; +#line 389 "src/gdb_parser.c" } } @@ -393,18 +398,37 @@ _again: _out: {} } -#line 133 "src/gdb_parser.rl" +#line 138 "src/gdb_parser.rl" + + if (cs == gdb_error) { + printf("parse error\n"); + return -1; + } return 0; } #if 0 +void send_nack(void *priv) +{ + printf("Send: -\n"); +} + +void send_ack(void *priv) +{ + printf("Send: +\n"); +} + int main(int argc, char **argv) { parser_init(NULL); - if (argc > 1) - parse_buffer(argv[1], strlen(argv[1]), NULL); + if (argc > 1) { + int i; + for (i = 1; i < argc; i++) + parse_buffer(argv[i], strlen(argv[i]), NULL); + } + return 0; } #endif From patchwork Tue Mar 29 15:49:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610696 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=GwK8SL0r; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtJ4B5jz9sFk for ; Wed, 30 Mar 2022 02:50:16 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtJ3jQvz2yHD for ; Wed, 30 Mar 2022 02:50:16 +1100 (AEDT) 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=GwK8SL0r; 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::1036; helo=mail-pj1-x1036.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=GwK8SL0r; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 4KSYtF1q2xz2yHt for ; Wed, 30 Mar 2022 02:50:13 +1100 (AEDT) Received: by mail-pj1-x1036.google.com with SMTP id h23-20020a17090a051700b001c9c1dd3acbso3294729pjh.3 for ; Tue, 29 Mar 2022 08:50:13 -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=QNnjpc9JtvKjPtOBNSM6kOTFGFYMlKhz7hw2Y7sPAPw=; b=GwK8SL0rT8YZNpG8DOGkcO2ItOEk1x91cPKSxJvEPjWP7dTJnRYeXQTGwdu5z0PeC/ giTEbZ0DO4goRq6yIM/AvwHlbYff2+DW1agfT5ryK0KwXMcWh0BN3cLrDFJRCrfctmS7 XABuKPJCYZWSs53kP/8XB4p/VVVcDkiI5Y/RtLVUhx9LBO/ptUVTnF1P8SMlOVf3Ej6Y WmNCCsNEtoirnc9Mgu2/oXuZ+g1TeEcusan3sVDeIL1wO+TGiKZdpwnyutBlL3+qHpfq EsOm2NStAKZ2SoeEiH8tfD+PmWBmF0mj6L+EPD++Dzcnd/ljV5INwofHknSgUnWoWPrD XOOQ== 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=QNnjpc9JtvKjPtOBNSM6kOTFGFYMlKhz7hw2Y7sPAPw=; b=UQLAOxIm1W6pTLGwRn1lSFo5KXZYWoPJhz/D744JHrMjmbgugC2Tfeo79eOveq9eqz YAUl185rkZKugD2NrdPISNg402XMBmh4gwmnkuAhCqmcNvf4o0Yn/yDCVtu5MfvILeXS Q3wQWEcONumpgdYNGK7GmnnNBcEhznAkOj5CM8XDH2givKeXXBYJfZCJd/VIMFfqrlSg EA6QoD9Hq8jVniOJE+v3543aLVjUB5vuS8By4CB4uklxhVCoEsb89J7zK4BApMBomI1L 8ZYeDhhbMwclS4NceYvPS4fAe5jrAgRLAVm7rYXZTbtGx+asNCH5Y+GRJiEH/XxP60Qh 3bkw== X-Gm-Message-State: AOAM530Ocm5nUu7I5GlaoSSC9plLr9/GHEc2Rz8/iYdp5RPPGPkjKwpZ D5oCa0l/yUFSzmxWkUPg4rd0aa8/XfU= X-Google-Smtp-Source: ABdhPJwxr5/cCBLApsmXE2Q6XoePS9AZDxssHk3Ohse8oewS3+ZT6M57/hU7eVJQflfT8aHavXLcIA== X-Received: by 2002:a17:90a:930b:b0:1bf:ac1f:6585 with SMTP id p11-20020a17090a930b00b001bfac1f6585mr242356pjo.88.1648569010530; Tue, 29 Mar 2022 08:50:10 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:10 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:07 +1000 Message-Id: <20220329154931.493851-15-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 14/38] gdbserver: put_mem handle arbitrary lengths 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" Allow put_mem to handle arbitrary lengths > 4, and also avoid endian complexities by having the handler allocate a buffer to store the stream of bytes into. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 31 +++- src/gdb_parser_precompile.c | 293 ++++++++++++++++++++---------------- src/pdbgproxy.c | 13 +- 3 files changed, 202 insertions(+), 135 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 72a907c..020f10d 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -39,6 +40,24 @@ *data += *p - 'A' + 10; } + action mem_hex_digit { + uint8_t *d; + uint64_t idx = mem_data_i / 2; /* 2 chars per byte */ + + assert(idx < mem_data_length); + d = &mem_data[idx]; + + *d <<= 4; + if (*p >= '0' && *p <= '9') + *d += *p - '0'; + else if (*p >= 'a' && *p <= 'f') + *d += *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + *d += *p - 'A' + 10; + + mem_data_i++; + } + action end { /* *data should point to the CRC */ if (crc != *data) { @@ -69,7 +88,14 @@ ',' xdigit+ $hex_digit %push ':' - xdigit+ $hex_digit %push); + @{ mem_data_length = *(data - 1); + mem_data = calloc(1, mem_data_length); // handler frees + *data = (unsigned long)mem_data; + data++; + assert(data < &stack[10]); + mem_data_i = 0; + } + xdigit+ $mem_hex_digit); get_gprs = ('g' @{cmd = GET_GPRS;}); @@ -114,6 +140,9 @@ static enum gdb_command cmd = NONE; static uint64_t stack[10], *data = stack; +static uint8_t *mem_data; +static uint64_t mem_data_length; +static uint64_t mem_data_i; static char *rsp; static uint8_t crc; static int cs; diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index d8dc9c3..553af1a 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -2,6 +2,7 @@ #line 1 "src/gdb_parser.rl" #include #include +#include #include #include #include @@ -10,11 +11,14 @@ #include "debug.h" -#line 113 "src/gdb_parser.rl" +#line 139 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; static uint64_t stack[10], *data = stack; +static uint8_t *mem_data; +static uint64_t mem_data_length; +static uint64_t mem_data_i; static char *rsp; static uint8_t crc; static int cs; @@ -22,28 +26,29 @@ static int cs; static command_cb *command_callbacks; -#line 26 "src/gdb_parser.c" +#line 30 "src/gdb_parser.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 14, 1, 19, 1, 20, 1, - 21, 1, 22, 2, 0, 1, 2, 2, - 1, 2, 3, 1, 2, 3, 4, 2, - 10, 1, 2, 12, 1, 2, 13, 1, - 2, 14, 1, 2, 15, 1, 2, 16, - 1, 2, 17, 1, 2, 18, 1, 3, - 0, 5, 1, 3, 0, 6, 1, 3, - 0, 7, 1, 3, 0, 8, 1, 3, - 0, 9, 1, 3, 0, 11, 1 + 3, 1, 16, 1, 21, 1, 22, 1, + 23, 1, 24, 2, 0, 1, 2, 2, + 1, 2, 3, 1, 2, 3, 5, 2, + 4, 1, 2, 12, 1, 2, 14, 1, + 2, 15, 1, 2, 16, 1, 2, 17, + 1, 2, 18, 1, 2, 19, 1, 2, + 20, 1, 3, 0, 6, 1, 3, 0, + 7, 1, 3, 0, 9, 1, 3, 0, + 10, 1, 3, 0, 11, 1, 3, 0, + 13, 1, 3, 2, 8, 1 }; static const unsigned char _gdb_key_offsets[] = { 0, 0, 10, 11, 17, 23, 30, 37, - 38, 45, 53, 60, 68, 75, 83, 88, - 90, 92, 94, 96, 98, 100, 102, 104, - 111, 113, 115, 117, 119, 121, 123, 125, - 127, 129, 130, 132, 134, 136, 138, 140, - 142, 144, 146, 148, 150, 152, 154, 156, - 158, 161, 164, 165, 166 + 38, 45, 53, 60, 68, 75, 82, 90, + 95, 97, 99, 101, 103, 105, 107, 109, + 111, 118, 120, 122, 124, 126, 128, 130, + 132, 134, 136, 137, 139, 141, 143, 145, + 147, 149, 151, 153, 155, 157, 159, 161, + 163, 165, 168, 171, 172, 173 }; static const char _gdb_trans_keys[] = { @@ -56,49 +61,50 @@ static const char _gdb_trans_keys[] = { 57, 65, 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, 58, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, - 70, 97, 102, 35, 44, 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, - 43, 45, 0 + 70, 97, 102, 35, 48, 57, 65, 70, + 97, 102, 35, 44, 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, 43, + 45, 0 }; static const char _gdb_single_lengths[] = { 0, 10, 1, 0, 0, 1, 1, 1, - 1, 2, 1, 2, 1, 2, 5, 2, - 2, 2, 2, 2, 2, 2, 2, 1, + 1, 2, 1, 2, 1, 1, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 1, 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, - 3, 3, 1, 1, 4 + 2, 3, 3, 1, 1, 4 }; static const char _gdb_range_lengths[] = { 0, 0, 0, 3, 3, 3, 3, 0, - 3, 3, 3, 3, 3, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0 }; static const unsigned char _gdb_index_offsets[] = { 0, 0, 11, 13, 17, 21, 26, 31, - 33, 38, 44, 49, 55, 60, 66, 72, - 75, 78, 81, 84, 87, 90, 93, 96, - 101, 104, 107, 110, 113, 116, 119, 122, - 125, 128, 130, 133, 136, 139, 142, 145, - 148, 151, 154, 157, 160, 163, 166, 169, - 172, 176, 180, 182, 184 + 33, 38, 44, 49, 55, 60, 65, 71, + 77, 80, 83, 86, 89, 92, 95, 98, + 101, 106, 109, 112, 115, 118, 121, 124, + 127, 130, 133, 135, 138, 141, 144, 147, + 150, 153, 156, 159, 162, 165, 168, 171, + 174, 177, 181, 185, 187, 189 }; static const char _gdb_indicies[] = { @@ -109,67 +115,70 @@ static const char _gdb_indicies[] = { 18, 12, 19, 19, 19, 11, 12, 20, 19, 19, 19, 11, 12, 21, 21, 21, 11, 12, 22, 21, 21, 21, 11, 12, - 23, 23, 23, 11, 12, 22, 23, 23, - 23, 11, 12, 24, 25, 26, 27, 11, - 12, 28, 11, 12, 29, 11, 12, 30, - 11, 12, 31, 11, 12, 32, 11, 12, - 33, 11, 12, 34, 11, 12, 35, 11, - 12, 36, 36, 36, 11, 12, 37, 11, - 12, 38, 11, 12, 39, 11, 12, 40, - 11, 12, 41, 11, 12, 42, 11, 12, - 43, 11, 12, 44, 11, 12, 45, 11, - 47, 46, 12, 48, 11, 12, 49, 11, - 12, 50, 11, 12, 51, 11, 12, 52, - 11, 12, 53, 11, 12, 54, 11, 12, - 55, 11, 12, 56, 11, 12, 57, 11, - 12, 58, 11, 12, 59, 11, 12, 60, - 11, 12, 61, 11, 12, 62, 63, 11, - 12, 64, 65, 11, 12, 66, 12, 67, - 68, 69, 70, 71, 14, 0 + 23, 23, 23, 11, 12, 24, 24, 24, + 11, 12, 25, 24, 24, 24, 11, 12, + 26, 27, 28, 29, 11, 12, 30, 11, + 12, 31, 11, 12, 32, 11, 12, 33, + 11, 12, 34, 11, 12, 35, 11, 12, + 36, 11, 12, 37, 11, 12, 38, 38, + 38, 11, 12, 39, 11, 12, 40, 11, + 12, 41, 11, 12, 42, 11, 12, 43, + 11, 12, 44, 11, 12, 45, 11, 12, + 46, 11, 12, 47, 11, 49, 48, 12, + 50, 11, 12, 51, 11, 12, 52, 11, + 12, 53, 11, 12, 54, 11, 12, 55, + 11, 12, 56, 11, 12, 57, 11, 12, + 58, 11, 12, 59, 11, 12, 60, 11, + 12, 61, 11, 12, 62, 11, 12, 63, + 11, 12, 64, 65, 11, 12, 66, 67, + 11, 12, 68, 12, 69, 70, 71, 72, + 73, 14, 0 }; static const char _gdb_trans_targs[] = { - 2, 3, 2, 5, 7, 8, 2, 12, - 5, 14, 44, 2, 3, 4, 0, 52, - 6, 3, 7, 9, 10, 11, 5, 13, - 15, 2, 24, 34, 16, 17, 18, 19, - 20, 21, 22, 23, 23, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 2, 3, - 35, 36, 37, 38, 39, 40, 41, 42, - 43, 2, 45, 46, 47, 48, 49, 2, - 50, 51, 50, 51, 52, 1, 52, 52 + 2, 3, 2, 5, 7, 8, 2, 13, + 5, 15, 45, 2, 3, 4, 0, 53, + 6, 3, 7, 9, 10, 11, 12, 12, + 14, 5, 16, 2, 25, 35, 17, 18, + 19, 20, 21, 22, 23, 24, 24, 26, + 27, 28, 29, 30, 31, 32, 33, 34, + 2, 3, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 2, 46, 47, 48, 49, + 50, 2, 51, 52, 51, 52, 53, 1, + 53, 53 }; static const char _gdb_trans_actions[] = { - 19, 1, 71, 75, 19, 59, 63, 55, - 67, 19, 19, 3, 0, 7, 0, 28, - 25, 5, 31, 25, 22, 25, 22, 25, - 3, 37, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 34, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 40, 9, + 19, 1, 74, 78, 19, 62, 66, 58, + 70, 19, 19, 3, 0, 7, 0, 28, + 25, 5, 34, 25, 22, 25, 82, 31, + 25, 22, 3, 40, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 37, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 43, 3, 3, 3, 3, 3, 46, - 3, 3, 49, 52, 11, 13, 15, 17 + 43, 9, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 46, 3, 3, 3, 3, + 3, 49, 3, 3, 52, 55, 11, 13, + 15, 17 }; -static const int gdb_start = 52; -static const int gdb_first_final = 52; +static const int gdb_start = 53; +static const int gdb_first_final = 53; static const int gdb_error = 0; -static const int gdb_en_main = 52; +static const int gdb_en_main = 53; -#line 124 "src/gdb_parser.rl" +#line 153 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 168 "src/gdb_parser.c" +#line 177 "src/gdb_parser.c" { cs = gdb_start; } -#line 128 "src/gdb_parser.rl" +#line 157 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -180,7 +189,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len; -#line 184 "src/gdb_parser.c" +#line 193 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -255,7 +264,7 @@ _match: switch ( *_acts++ ) { case 0: -#line 13 "src/gdb_parser.rl" +#line 14 "src/gdb_parser.rl" { cmd = 0; rsp = NULL; @@ -266,20 +275,20 @@ _match: } break; case 1: -#line 22 "src/gdb_parser.rl" +#line 23 "src/gdb_parser.rl" { crc += *p; } break; case 2: -#line 26 "src/gdb_parser.rl" +#line 27 "src/gdb_parser.rl" { data++; assert(data < &stack[10]); } break; case 3: -#line 31 "src/gdb_parser.rl" +#line 32 "src/gdb_parser.rl" { *data *= 16; @@ -292,7 +301,27 @@ _match: } break; case 4: -#line 42 "src/gdb_parser.rl" +#line 43 "src/gdb_parser.rl" + { + uint8_t *d; + uint64_t idx = mem_data_i / 2; /* 2 chars per byte */ + + assert(idx < mem_data_length); + d = &mem_data[idx]; + + *d <<= 4; + if (*p >= '0' && *p <= '9') + *d += *p - '0'; + else if (*p >= 'a' && *p <= 'f') + *d += *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + *d += *p - 'A' + 10; + + mem_data_i++; + } + break; + case 5: +#line 61 "src/gdb_parser.rl" { /* *data should point to the CRC */ if (crc != *data) { @@ -313,79 +342,89 @@ _match: } } break; - case 5: -#line 62 "src/gdb_parser.rl" + case 6: +#line 81 "src/gdb_parser.rl" {cmd = GET_MEM;} break; - case 6: -#line 67 "src/gdb_parser.rl" + case 7: +#line 86 "src/gdb_parser.rl" {cmd = PUT_MEM;} break; - case 7: -#line 74 "src/gdb_parser.rl" + case 8: +#line 91 "src/gdb_parser.rl" + { mem_data_length = *(data - 1); + mem_data = calloc(1, mem_data_length); // handler frees + *data = (unsigned long)mem_data; + data++; + assert(data < &stack[10]); + mem_data_i = 0; + } + break; + case 9: +#line 100 "src/gdb_parser.rl" {cmd = GET_GPRS;} break; - case 8: -#line 76 "src/gdb_parser.rl" + case 10: +#line 102 "src/gdb_parser.rl" {cmd = GET_SPR;} break; - case 9: -#line 79 "src/gdb_parser.rl" + case 11: +#line 105 "src/gdb_parser.rl" {cmd = STOP_REASON;} break; - case 10: -#line 81 "src/gdb_parser.rl" + case 12: +#line 107 "src/gdb_parser.rl" {cmd = SET_THREAD;} break; - case 11: -#line 83 "src/gdb_parser.rl" + case 13: +#line 109 "src/gdb_parser.rl" {cmd = DETACH;} break; - case 12: -#line 87 "src/gdb_parser.rl" + case 14: +#line 113 "src/gdb_parser.rl" {rsp = "1";} break; - case 13: -#line 88 "src/gdb_parser.rl" + case 15: +#line 114 "src/gdb_parser.rl" {rsp = "QC1";} break; - case 14: -#line 89 "src/gdb_parser.rl" + case 16: +#line 115 "src/gdb_parser.rl" {rsp = "multiprocess+;vContSupported+";} break; - case 15: -#line 90 "src/gdb_parser.rl" + case 17: +#line 116 "src/gdb_parser.rl" {rsp = "m1l";} break; - case 16: -#line 93 "src/gdb_parser.rl" + case 18: +#line 119 "src/gdb_parser.rl" {rsp = "vCont;c;C;s;S";} break; - case 17: -#line 94 "src/gdb_parser.rl" + case 19: +#line 120 "src/gdb_parser.rl" {cmd = V_CONTC;} break; - case 18: -#line 95 "src/gdb_parser.rl" + case 20: +#line 121 "src/gdb_parser.rl" {cmd = V_CONTS;} break; - case 19: -#line 98 "src/gdb_parser.rl" + case 21: +#line 124 "src/gdb_parser.rl" { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; - case 20: -#line 105 "src/gdb_parser.rl" + case 22: +#line 131 "src/gdb_parser.rl" {PR_INFO("RAGEL:cmd\n");} break; - case 21: -#line 108 "src/gdb_parser.rl" + case 23: +#line 134 "src/gdb_parser.rl" {PR_INFO("RAGEL:ack\n");} break; - case 22: -#line 109 "src/gdb_parser.rl" + case 24: +#line 135 "src/gdb_parser.rl" {PR_INFO("RAGEL:nack\n");} break; -#line 389 "src/gdb_parser.c" +#line 428 "src/gdb_parser.c" } } @@ -398,7 +437,7 @@ _again: _out: {} } -#line 138 "src/gdb_parser.rl" +#line 167 "src/gdb_parser.rl" if (cs == gdb_error) { printf("parse error\n"); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1668126..dfd00a9 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -253,6 +253,7 @@ static void put_mem(uint64_t *stack, void *priv) uint64_t addr, len; uint8_t *data; uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; + uint8_t gdb_break_opcode[] = {0x7d, 0x82, 0x10, 0x08}; int err = 0; struct thread *thread = target_to_thread(thread_target); @@ -263,7 +264,7 @@ static void put_mem(uint64_t *stack, void *priv) addr = stack[0]; len = stack[1]; - data = (uint8_t *) &stack[2]; + data = (uint8_t *)(unsigned long)stack[2]; addr = get_real_addr(addr); if (addr == -1UL) { @@ -272,8 +273,7 @@ static void put_mem(uint64_t *stack, void *priv) goto out; } - - if (len == 4 && stack[2] == 0x0810827d) { + if (len == 4 && !memcmp(data, gdb_break_opcode, 4)) { /* 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 @@ -287,10 +287,7 @@ static void put_mem(uint64_t *stack, void *priv) /* Need to enable the attn instruction in HID0 */ if (thread->enable_attn(thread)) 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 (mem_write(adu_target, addr, data, len, 0, false)) { PR_ERROR("Unable to write memory\n"); @@ -298,6 +295,8 @@ static void put_mem(uint64_t *stack, void *priv) } out: + free(data); // allocated by gdb_parser.rl + if (err) send_response(fd, ERROR(EPERM)); else From patchwork Tue Mar 29 15:49:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610697 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=lbPpZWYN; 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 4KSYtL3jS3z9sFk for ; Wed, 30 Mar 2022 02:50:18 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtL2HtSz2yJ9 for ; Wed, 30 Mar 2022 02:50:18 +1100 (AEDT) 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=lbPpZWYN; 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::1030; helo=mail-pj1-x1030.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=lbPpZWYN; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 4KSYtH3Qfxz2xvW for ; Wed, 30 Mar 2022 02:50:15 +1100 (AEDT) Received: by mail-pj1-x1030.google.com with SMTP id o3-20020a17090a3d4300b001c6bc749227so3305830pjf.1 for ; Tue, 29 Mar 2022 08:50:15 -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=hEOYf/Cfy5tj9EdYA9jKPl8oMZieeQOY8J3lL1XtWjM=; b=lbPpZWYNkGl3JQ6jWwqo0e42ULu5hbp1Y8yY0VG4lmcltq1V3m260DeWW92PZVe1Fx tsv/E/8NnxQM0CUVAetx5Cmg0na4CiWmNGTj5gGjTYT+UofcYI5vliZs3oG5Ano7IY8K JizYvXwP0IcRIiCbrKANdC7k9ASS3YIk+SWnzo9S0yevaTHkja4P7FtX5Djufi+zZ1jT hoMzTph7Nsa602Uq9mSR1qJLK0VlvvyPIf22o24BZaco3zrVGKCfk9/ytnWsEFO5ANuh bIN2wO6L9jrYg89HIxiZUvqtCSf/qVtbsePcNpKMKoCFaqVB7S14VZGnWwR2rvo/ASuy 91JQ== 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=hEOYf/Cfy5tj9EdYA9jKPl8oMZieeQOY8J3lL1XtWjM=; b=xeW7tFwv652X07N5/nf98stvdunTCPeBf1f0h0A5cV0SQLXx+vn2hV3u2JwO/evnnB OQTTaN/d4lQOcMayCfViG3P/aXOYjxiE3Gsz29EGmUfkrJf7FRV30T3NXwaOfiyIjk8I pJ/puLhezNjaThhbzJOBsxFixCCUC6yoGJBVmb0IfGE+ubnnpMTaQ6scjFJa/2I12iOB ltTf2KsPlER6Z68ZEkPdW/VmW2fRs4Gd/a/tYPLWrdviQo9m4GUBCXRQoPEMZ5zkXvs7 TA573swjcf3d7MvyQxLsKz9Vf0R2nVokJzFqF8tNAMBT/LrKxmSSDnmXWhDsynElaKwD ZMkg== X-Gm-Message-State: AOAM5338eMKVC+v4JO/zuBnQSGKsIRvDbDG9OdhBQTaQ7crK6rH64Dlf D7Yg/vUhwbVfYUgsnetLI3wQYlxyZkA= X-Google-Smtp-Source: ABdhPJzXN98kS99OSx0mPnYySaid4ZcQLL9bumuhIC1b5l6y87ne8jSEWX3zDPWc+katgK8cXMQcXA== X-Received: by 2002:a17:902:c944:b0:154:38b8:aa46 with SMTP id i4-20020a170902c94400b0015438b8aa46mr31209380pla.144.1648569012737; Tue, 29 Mar 2022 08:50:12 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:12 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:08 +1000 Message-Id: <20220329154931.493851-16-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 15/38] gdbserver: implement NoAckMode 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" This removes a bunch of synchronous round-trips and makes things significantly faster when attached to a high latency link. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 14 +- src/gdb_parser_precompile.c | 291 ++++++++++++++++++++---------------- 2 files changed, 170 insertions(+), 135 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 020f10d..e49d56d 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -62,10 +62,12 @@ /* *data should point to the CRC */ if (crc != *data) { printf("CRC error cmd %d\n", cmd); - send_nack(priv); + if (ack_mode) + send_nack(priv); } else { PR_INFO("Cmd %d\n", cmd); - send_ack(priv); + if (ack_mode) + send_ack(priv); /* Push the response onto the stack */ if (rsp) @@ -112,8 +114,9 @@ # 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+";}); + q_supported = ('qSupported:' any* >{rsp = "multiprocess+;vContSupported+;QStartNoAckMode+"; ack_mode = true;}); qf_threadinfo = ('qfThreadInfo' @{rsp = "m1l";}); + q_start_noack = ('QStartNoAckMode' @{rsp = "OK"; send_ack(priv); ack_mode = false;}); # vCont packet parsing v_contq = ('vCont?' @{rsp = "vCont;c;C;s;S";}); @@ -125,7 +128,8 @@ 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 | detach | unknown ); + q_start_noack | v_contq | v_contc | v_conts | put_mem | + detach | unknown ); cmd = (('$' ((commands & ^'#'*) >reset $crc) ('#' xdigit{2} $hex_digit @end)) >{PR_INFO("RAGEL:cmd\n");}); @@ -149,6 +153,8 @@ static int cs; static command_cb *command_callbacks; +static bool ack_mode = true; + %%write data; void parser_init(command_cb *callbacks) diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index 553af1a..ba63fac 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -11,7 +11,7 @@ #include "debug.h" -#line 139 "src/gdb_parser.rl" +#line 143 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -25,160 +25,183 @@ static int cs; static command_cb *command_callbacks; +static bool ack_mode = true; + -#line 30 "src/gdb_parser.c" +#line 32 "src/gdb_parser.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 16, 1, 21, 1, 22, 1, - 23, 1, 24, 2, 0, 1, 2, 2, + 3, 1, 16, 1, 22, 1, 23, 1, + 24, 1, 25, 2, 0, 1, 2, 2, 1, 2, 3, 1, 2, 3, 5, 2, 4, 1, 2, 12, 1, 2, 14, 1, 2, 15, 1, 2, 16, 1, 2, 17, 1, 2, 18, 1, 2, 19, 1, 2, - 20, 1, 3, 0, 6, 1, 3, 0, - 7, 1, 3, 0, 9, 1, 3, 0, - 10, 1, 3, 0, 11, 1, 3, 0, - 13, 1, 3, 2, 8, 1 + 20, 1, 2, 21, 1, 3, 0, 6, + 1, 3, 0, 7, 1, 3, 0, 9, + 1, 3, 0, 10, 1, 3, 0, 11, + 1, 3, 0, 13, 1, 3, 2, 8, + 1 }; static const unsigned char _gdb_key_offsets[] = { - 0, 0, 10, 11, 17, 23, 30, 37, - 38, 45, 53, 60, 68, 75, 82, 90, - 95, 97, 99, 101, 103, 105, 107, 109, - 111, 118, 120, 122, 124, 126, 128, 130, - 132, 134, 136, 137, 139, 141, 143, 145, - 147, 149, 151, 153, 155, 157, 159, 161, - 163, 165, 168, 171, 172, 173 + 0, 0, 11, 12, 18, 24, 31, 38, + 39, 46, 54, 61, 69, 76, 78, 80, + 82, 84, 86, 88, 90, 92, 94, 96, + 98, 100, 102, 104, 111, 119, 124, 126, + 128, 130, 132, 134, 136, 138, 140, 147, + 149, 151, 153, 155, 157, 159, 161, 163, + 165, 166, 168, 170, 172, 174, 176, 178, + 180, 182, 184, 186, 188, 190, 192, 194, + 197, 200, 201, 202 }; static const char _gdb_trans_keys[] = { - 35, 63, 68, 72, 77, 103, 109, 112, - 113, 118, 35, 48, 57, 65, 70, 97, - 102, 48, 57, 65, 70, 97, 102, 35, + 35, 63, 68, 72, 77, 81, 103, 109, + 112, 113, 118, 35, 48, 57, 65, 70, + 97, 102, 48, 57, 65, 70, 97, 102, + 35, 48, 57, 65, 70, 97, 102, 35, + 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, 35, 48, - 57, 65, 70, 97, 102, 35, 44, 48, + 57, 65, 70, 97, 102, 35, 58, 48, 57, 65, 70, 97, 102, 35, 48, 57, - 65, 70, 97, 102, 35, 58, 48, 57, - 65, 70, 97, 102, 35, 48, 57, 65, - 70, 97, 102, 35, 48, 57, 65, 70, - 97, 102, 35, 44, 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, 43, - 45, 0 + 65, 70, 97, 102, 35, 83, 35, 116, + 35, 97, 35, 114, 35, 116, 35, 78, + 35, 111, 35, 65, 35, 99, 35, 107, + 35, 77, 35, 111, 35, 100, 35, 101, + 35, 48, 57, 65, 70, 97, 102, 35, + 44, 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, 43, 45, 0 }; static const char _gdb_single_lengths[] = { - 0, 10, 1, 0, 0, 1, 1, 1, - 1, 2, 1, 2, 1, 1, 2, 5, + 0, 11, 1, 0, 0, 1, 1, 1, + 1, 2, 1, 2, 1, 2, 2, 2, 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, 1, 2, 5, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 3, 3, 1, 1, 4 + 1, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 3, + 3, 1, 1, 4 }; static const char _gdb_range_lengths[] = { 0, 0, 0, 3, 3, 3, 3, 0, - 3, 3, 3, 3, 3, 3, 3, 0, + 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 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, 0, + 0, 0, 0, 0 }; -static const unsigned char _gdb_index_offsets[] = { - 0, 0, 11, 13, 17, 21, 26, 31, - 33, 38, 44, 49, 55, 60, 65, 71, - 77, 80, 83, 86, 89, 92, 95, 98, - 101, 106, 109, 112, 115, 118, 121, 124, - 127, 130, 133, 135, 138, 141, 144, 147, - 150, 153, 156, 159, 162, 165, 168, 171, - 174, 177, 181, 185, 187, 189 +static const short _gdb_index_offsets[] = { + 0, 0, 12, 14, 18, 22, 27, 32, + 34, 39, 45, 50, 56, 61, 64, 67, + 70, 73, 76, 79, 82, 85, 88, 91, + 94, 97, 100, 103, 108, 114, 120, 123, + 126, 129, 132, 135, 138, 141, 144, 149, + 152, 155, 158, 161, 164, 167, 170, 173, + 176, 178, 181, 184, 187, 190, 193, 196, + 199, 202, 205, 208, 211, 214, 217, 220, + 224, 228, 230, 232 }; static const char _gdb_indicies[] = { 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 0, 12, 11, 13, 13, 13, - 14, 15, 15, 15, 14, 12, 16, 16, - 16, 11, 17, 16, 16, 16, 11, 12, - 18, 12, 19, 19, 19, 11, 12, 20, - 19, 19, 19, 11, 12, 21, 21, 21, - 11, 12, 22, 21, 21, 21, 11, 12, - 23, 23, 23, 11, 12, 24, 24, 24, - 11, 12, 25, 24, 24, 24, 11, 12, - 26, 27, 28, 29, 11, 12, 30, 11, - 12, 31, 11, 12, 32, 11, 12, 33, - 11, 12, 34, 11, 12, 35, 11, 12, - 36, 11, 12, 37, 11, 12, 38, 38, - 38, 11, 12, 39, 11, 12, 40, 11, - 12, 41, 11, 12, 42, 11, 12, 43, - 11, 12, 44, 11, 12, 45, 11, 12, - 46, 11, 12, 47, 11, 49, 48, 12, - 50, 11, 12, 51, 11, 12, 52, 11, - 12, 53, 11, 12, 54, 11, 12, 55, - 11, 12, 56, 11, 12, 57, 11, 12, - 58, 11, 12, 59, 11, 12, 60, 11, - 12, 61, 11, 12, 62, 11, 12, 63, - 11, 12, 64, 65, 11, 12, 66, 67, - 11, 12, 68, 12, 69, 70, 71, 72, - 73, 14, 0 + 9, 10, 11, 0, 13, 12, 14, 14, + 14, 15, 16, 16, 16, 15, 13, 17, + 17, 17, 12, 18, 17, 17, 17, 12, + 13, 19, 13, 20, 20, 20, 12, 13, + 21, 20, 20, 20, 12, 13, 22, 22, + 22, 12, 13, 23, 22, 22, 22, 12, + 13, 24, 24, 24, 12, 13, 25, 12, + 13, 26, 12, 13, 27, 12, 13, 28, + 12, 13, 29, 12, 13, 30, 12, 13, + 31, 12, 13, 32, 12, 13, 33, 12, + 13, 34, 12, 13, 35, 12, 13, 36, + 12, 13, 37, 12, 13, 38, 12, 13, + 39, 39, 39, 12, 13, 40, 39, 39, + 39, 12, 13, 41, 42, 43, 44, 12, + 13, 45, 12, 13, 46, 12, 13, 47, + 12, 13, 48, 12, 13, 49, 12, 13, + 50, 12, 13, 51, 12, 13, 52, 12, + 13, 53, 53, 53, 12, 13, 54, 12, + 13, 55, 12, 13, 56, 12, 13, 57, + 12, 13, 58, 12, 13, 59, 12, 13, + 60, 12, 13, 61, 12, 13, 62, 12, + 64, 63, 13, 65, 12, 13, 66, 12, + 13, 67, 12, 13, 68, 12, 13, 69, + 12, 13, 70, 12, 13, 71, 12, 13, + 72, 12, 13, 73, 12, 13, 74, 12, + 13, 75, 12, 13, 76, 12, 13, 77, + 12, 13, 78, 12, 13, 79, 80, 12, + 13, 81, 82, 12, 13, 83, 13, 84, + 85, 86, 87, 88, 15, 0 }; static const char _gdb_trans_targs[] = { - 2, 3, 2, 5, 7, 8, 2, 13, - 5, 15, 45, 2, 3, 4, 0, 53, - 6, 3, 7, 9, 10, 11, 12, 12, - 14, 5, 16, 2, 25, 35, 17, 18, - 19, 20, 21, 22, 23, 24, 24, 26, - 27, 28, 29, 30, 31, 32, 33, 34, - 2, 3, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 2, 46, 47, 48, 49, - 50, 2, 51, 52, 51, 52, 53, 1, - 53, 53 + 2, 3, 2, 5, 7, 8, 13, 2, + 27, 5, 29, 59, 2, 3, 4, 0, + 67, 6, 3, 7, 9, 10, 11, 12, + 12, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 2, 28, + 5, 30, 2, 39, 49, 31, 32, 33, + 34, 35, 36, 37, 38, 38, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 2, + 3, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 2, 60, 61, 62, 63, 64, + 2, 65, 66, 65, 66, 67, 1, 67, + 67 }; static const char _gdb_trans_actions[] = { - 19, 1, 74, 78, 19, 62, 66, 58, - 70, 19, 19, 3, 0, 7, 0, 28, - 25, 5, 34, 25, 22, 25, 82, 31, - 25, 22, 3, 40, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 37, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 43, 9, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 46, 3, 3, 3, 3, - 3, 49, 3, 3, 52, 55, 11, 13, - 15, 17 + 19, 1, 77, 81, 19, 65, 19, 69, + 61, 73, 19, 19, 3, 0, 7, 0, + 28, 25, 5, 34, 25, 22, 25, 85, + 31, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 49, 25, + 22, 3, 40, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 37, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 43, + 9, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 46, 3, 3, 3, 3, 3, + 52, 3, 3, 55, 58, 11, 13, 15, + 17 }; -static const int gdb_start = 53; -static const int gdb_first_final = 53; +static const int gdb_start = 67; +static const int gdb_first_final = 67; static const int gdb_error = 0; -static const int gdb_en_main = 53; +static const int gdb_en_main = 67; -#line 153 "src/gdb_parser.rl" +#line 159 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 177 "src/gdb_parser.c" +#line 200 "src/gdb_parser.c" { cs = gdb_start; } -#line 157 "src/gdb_parser.rl" +#line 163 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -189,7 +212,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len; -#line 193 "src/gdb_parser.c" +#line 216 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -326,10 +349,12 @@ _match: /* *data should point to the CRC */ if (crc != *data) { printf("CRC error cmd %d\n", cmd); - send_nack(priv); + if (ack_mode) + send_nack(priv); } else { PR_INFO("Cmd %d\n", cmd); - send_ack(priv); + if (ack_mode) + send_ack(priv); /* Push the response onto the stack */ if (rsp) @@ -343,15 +368,15 @@ _match: } break; case 6: -#line 81 "src/gdb_parser.rl" +#line 83 "src/gdb_parser.rl" {cmd = GET_MEM;} break; case 7: -#line 86 "src/gdb_parser.rl" +#line 88 "src/gdb_parser.rl" {cmd = PUT_MEM;} break; case 8: -#line 91 "src/gdb_parser.rl" +#line 93 "src/gdb_parser.rl" { mem_data_length = *(data - 1); mem_data = calloc(1, mem_data_length); // handler frees *data = (unsigned long)mem_data; @@ -361,70 +386,74 @@ _match: } break; case 9: -#line 100 "src/gdb_parser.rl" +#line 102 "src/gdb_parser.rl" {cmd = GET_GPRS;} break; case 10: -#line 102 "src/gdb_parser.rl" +#line 104 "src/gdb_parser.rl" {cmd = GET_SPR;} break; case 11: -#line 105 "src/gdb_parser.rl" +#line 107 "src/gdb_parser.rl" {cmd = STOP_REASON;} break; case 12: -#line 107 "src/gdb_parser.rl" +#line 109 "src/gdb_parser.rl" {cmd = SET_THREAD;} break; case 13: -#line 109 "src/gdb_parser.rl" +#line 111 "src/gdb_parser.rl" {cmd = DETACH;} break; case 14: -#line 113 "src/gdb_parser.rl" +#line 115 "src/gdb_parser.rl" {rsp = "1";} break; case 15: -#line 114 "src/gdb_parser.rl" +#line 116 "src/gdb_parser.rl" {rsp = "QC1";} break; case 16: -#line 115 "src/gdb_parser.rl" - {rsp = "multiprocess+;vContSupported+";} +#line 117 "src/gdb_parser.rl" + {rsp = "multiprocess+;vContSupported+;QStartNoAckMode+"; ack_mode = true;} break; case 17: -#line 116 "src/gdb_parser.rl" +#line 118 "src/gdb_parser.rl" {rsp = "m1l";} break; case 18: #line 119 "src/gdb_parser.rl" - {rsp = "vCont;c;C;s;S";} + {rsp = "OK"; send_ack(priv); ack_mode = false;} break; case 19: -#line 120 "src/gdb_parser.rl" - {cmd = V_CONTC;} +#line 122 "src/gdb_parser.rl" + {rsp = "vCont;c;C;s;S";} break; case 20: -#line 121 "src/gdb_parser.rl" - {cmd = V_CONTS;} +#line 123 "src/gdb_parser.rl" + {cmd = V_CONTC;} break; case 21: #line 124 "src/gdb_parser.rl" - { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} + {cmd = V_CONTS;} break; case 22: -#line 131 "src/gdb_parser.rl" - {PR_INFO("RAGEL:cmd\n");} +#line 127 "src/gdb_parser.rl" + { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; case 23: -#line 134 "src/gdb_parser.rl" - {PR_INFO("RAGEL:ack\n");} +#line 135 "src/gdb_parser.rl" + {PR_INFO("RAGEL:cmd\n");} break; case 24: -#line 135 "src/gdb_parser.rl" +#line 138 "src/gdb_parser.rl" + {PR_INFO("RAGEL:ack\n");} + break; + case 25: +#line 139 "src/gdb_parser.rl" {PR_INFO("RAGEL:nack\n");} break; -#line 428 "src/gdb_parser.c" +#line 457 "src/gdb_parser.c" } } @@ -437,7 +466,7 @@ _again: _out: {} } -#line 167 "src/gdb_parser.rl" +#line 173 "src/gdb_parser.rl" if (cs == gdb_error) { printf("parse error\n"); From patchwork Tue Mar 29 15:49:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610698 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=o4IU8Xwa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtM4l12z9sFk for ; Wed, 30 Mar 2022 02:50:19 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtM3gtSz2xvF for ; Wed, 30 Mar 2022 02:50:19 +1100 (AEDT) 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=o4IU8Xwa; 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::433; helo=mail-pf1-x433.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=o4IU8Xwa; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 4KSYtK2qMzz2xy3 for ; Wed, 30 Mar 2022 02:50:17 +1100 (AEDT) Received: by mail-pf1-x433.google.com with SMTP id u22so16253658pfg.6 for ; Tue, 29 Mar 2022 08:50:17 -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=BcwkrbrP7TqExCViK0h3asOLLgzPtX/+16heB40BBkQ=; b=o4IU8Xwa1dwH/ObXBONcx0ilRg/n3UlnlHL74T1AHE4nDpbk4je8KAnTUysQABU6GH 9vhiwRFuJyK2ppctXi1i74xbenr6FBxtP+/zJgRGNdZxPsTkaNj809gZGG8Kj51ChuOY IwYMujSl88tl7trBupMqXbgqCEksN6GpKTUsVarQ08yw3n4sbQNUqGfAfvOrXFC+pPfF JMIIelemdqlXbdTiHpSqpf2OT4m4IhXpFXtoQFV8d8DlS/PHzjhopG0XuBPD00Padack S8/qpNR3Bv34OVz1o3uRPXKXW0zxdSxaeW1wl1N3V4eTi0cgdLq5jd6vKURf7GBVE1OQ l0Lg== 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=BcwkrbrP7TqExCViK0h3asOLLgzPtX/+16heB40BBkQ=; b=G+zsK5Si6qkdq5IAB1EY5CleyVSO87qKJkSJp447tuq4X5nV8Q4pueYIlFd2rkBHYS +K87RkRmqFcbbh9T8KfnLa7sKZNc2WrA1lhBxSjKsNSXrOX2s351DQgCe+dCrErDRu3I oF4kzBqLXDaZU0h4QzW1R/GOBDAVDBCjZCBp/4k8z/6FHVpJhRPbDkqxt9BzNJxcQfii mM1f0M9JmwUzX1SxVeZNjeKDv4kbvR2V3d0fc/HdVCQ4ihwxujU4gfqAm55TEdsGE+TH 6Dm3Qxt+LBjdAsnWtwVAKDn98BXFxiYv5QVsv2UQU74/5lE14GK+1TlGBTO5GzzYWDgA MHoA== X-Gm-Message-State: AOAM5311AmsIsbjKGMADr9FarGpBwxBwfJ2TZz4CXT6NOknP1oxJgDb8 c7EtYfZ8TIWhtcGFAlznipel19IY31g= X-Google-Smtp-Source: ABdhPJzhsbTQFSUtb6b3ledWamJWbcKg5SzJaweH2WXUiSSpI7PQgNDBOFc7lYYOt+H30PXpQpZJ2Q== X-Received: by 2002:a63:5024:0:b0:380:83f7:1603 with SMTP id e36-20020a635024000000b0038083f71603mr2394681pgb.289.1648569014731; Tue, 29 Mar 2022 08:50:14 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:14 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:09 +1000 Message-Id: <20220329154931.493851-17-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 16/38] libpdbg: Remove enable_attn target command 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" enable_attn is only used by gdbserver and it can be implemented with existing target register access. Move it to gdbserver. Signed-off-by: Nicholas Piggin --- libpdbg/hwunit.h | 1 - libpdbg/p8chip.c | 31 ------------------------------- src/pdbgproxy.c | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index 4662aec..2ce41db 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -155,7 +155,6 @@ struct thread { int (*ram_setup)(struct thread *); int (*ram_instruction)(struct thread *, uint64_t opcode, uint64_t *scratch); int (*ram_destroy)(struct thread *); - int (*enable_attn)(struct thread *); int (*getmem)(struct thread *, uint64_t, uint64_t *); int (*getregs)(struct thread *, struct thread_regs *regs); diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index 92e18cc..5b2a90a 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -611,36 +611,6 @@ static int p8_get_hid0(struct pdbg_target *chip, uint64_t *value) return 0; } -static int p8_put_hid0(struct pdbg_target *chip, uint64_t value) -{ - CHECK_ERR(pib_write(chip, HID0_REG, value)); - return 0; -} - -static int p8_enable_attn(struct thread *thread) -{ - struct pdbg_target *core; - uint64_t hid0; - - core = pdbg_target_require_parent("core", &thread->target); - - /* Need to enable the attn instruction in HID0 */ - if (p8_get_hid0(core, &hid0)) { - PR_ERROR("Unable to get HID0\n"); - return 1; - } - PR_INFO("HID0 was 0x%"PRIx64 " \n", hid0); - - hid0 |= EN_ATTN; - - PR_INFO("writing 0x%"PRIx64 " to HID0\n", hid0); - if (p8_put_hid0(core, hid0)) { - PR_ERROR("Unable to set HID0\n"); - return 1; - } - return 0; -} - static struct thread p8_thread = { .target = { .name = "POWER8 Thread", @@ -657,7 +627,6 @@ static struct thread p8_thread = { .ram_setup = p8_ram_setup, .ram_instruction = p8_ram_instruction, .ram_destroy = p8_ram_destroy, - .enable_attn = p8_enable_attn, .getmem = ram_getmem, .getregs = ram_getregs, .getgpr = ram_getgpr, diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index dfd00a9..3e27644 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -24,6 +24,7 @@ #include "optcmd.h" #include "debug.h" #include "path.h" +#include "sprs.h" #ifndef DISABLE_GDBSERVER @@ -101,6 +102,35 @@ static void detach(uint64_t *stack, void *priv) send_response(fd, OK); } +#define POWER8_HID_ENABLE_ATTN PPC_BIT(31) + +static int set_attn(bool enable) +{ + uint64_t hid; + + if (thread_getspr(thread_target, SPR_HID, &hid)) + return -1; + + if (pdbg_target_compatible(thread_target, "ibm,power8-thread")) { + if (enable) { + if (hid & POWER8_HID_ENABLE_ATTN) + return 0; + hid |= POWER8_HID_ENABLE_ATTN; + } else { + if (!(hid & POWER8_HID_ENABLE_ATTN)) + return 0; + hid &= ~POWER8_HID_ENABLE_ATTN; + } + } else { + return -1; + } + + if (thread_putspr(thread_target, SPR_HID, hid)) + return -1; + + return 0; +} + /* 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) @@ -255,7 +285,6 @@ static void put_mem(uint64_t *stack, void *priv) uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; uint8_t gdb_break_opcode[] = {0x7d, 0x82, 0x10, 0x08}; int err = 0; - struct thread *thread = target_to_thread(thread_target); if (littleendian) { attn_opcode[1] = 0x02; @@ -285,8 +314,10 @@ static void put_mem(uint64_t *stack, void *priv) data = attn_opcode; /* Need to enable the attn instruction in HID0 */ - if (thread->enable_attn(thread)) + if (set_attn(true)) { + err = 2; goto out; + } } if (mem_write(adu_target, addr, data, len, 0, false)) { From patchwork Tue Mar 29 15:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610699 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=aOAQI6fX; 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 4KSYtP5Ktjz9sFk for ; Wed, 30 Mar 2022 02:50:21 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtP4FQ1z2yPJ for ; Wed, 30 Mar 2022 02:50:21 +1100 (AEDT) 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=aOAQI6fX; 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::52b; helo=mail-pg1-x52b.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=aOAQI6fX; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 4KSYtM2nK0z2yQ6 for ; Wed, 30 Mar 2022 02:50:19 +1100 (AEDT) Received: by mail-pg1-x52b.google.com with SMTP id k14so15207187pga.0 for ; Tue, 29 Mar 2022 08:50:19 -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=GbyATik5cMuoz+eAqajDwOW6a+DVeUzH+vI9iwqoEZk=; b=aOAQI6fXj+din/mqBFvifa1o8LXBYZ0uLtjhWPEUyT60jdph+lDabjKqctYgQ+hRhC xCt3xEKh/+L2uHQEbxS6/SN83tILRXeAsL5N5Hgrkz0nkDJMNXLXes49bzt35THbMDOk H4nh7KTx/Fc3vynO2/tNcnzjOh4NVKsy5E/Iyt9Av6qSyRgDGfY9K4gqQIW/b4Hbrg1D W8Pxw/zgX27JysL8vRWRQrrdUmip0ZqeHAabdOJ+Mw2t+D3ZnUVBQHsnUOODxuY3Kl9M RXslbp4khCrbH7qPGfQMnvBtK/QC5rKFB1fi5j3KkQAjBLyd2IHbssSGbIp195eNlC1V mTVA== 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=GbyATik5cMuoz+eAqajDwOW6a+DVeUzH+vI9iwqoEZk=; b=I+M3QZkAW9hCFUkZQWBKUUqvj82jKbr/wVibyK0mFMpTNgL3Qf6FTTjUx5RNgoxvEF FPXghKK6SSVPKILjwTGrBw/nIzYVqAgSs5dyMH3LPrQdu5EWM/BzT2J3tDjrSXnZU/zs PAPJ+uDwiTRE3RG2O2NaYehM3H8RLtHQ/PQZ7pFLxD9BrD1LA+GECP8w865rFK+8wyGV vzOs/r/HmRFQizZOaHxO7C6ruk1FtCYRegmZ4847dHDLVB2NykIzhA3lu6pd8a1Pxb5B 7Sy3tTQjsItvOOx4ZoObE+fZgoKLYae0evK+SJLIUXryW6VmwDsTqGkLvghyyFgYBTV6 Zb7Q== X-Gm-Message-State: AOAM5303ZUJyBhc2l7sqnObW8HRhgWWmc7+lNwdadewk6eycvY+tE59o +i5cx1rM3yotA92QPhJPET+WGAf76qs= X-Google-Smtp-Source: ABdhPJx7VWzf4wr8os54ANRnT2lYT0pxun2dHXHbgKv38fSAeCnjzD7U+qEJlHPVH6jybt4skkfGfQ== X-Received: by 2002:a63:8ac3:0:b0:398:9e2b:b85 with SMTP id y186-20020a638ac3000000b003989e2b0b85mr418601pgd.32.1648569016704; Tue, 29 Mar 2022 08:50:16 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:16 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:10 +1000 Message-Id: <20220329154931.493851-18-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 17/38] gdbserver: disable attn after breaking 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" Rather than leave attn enabled, disable it when breaking to idle state if it was enabled. This helps prevent attn from getting left on after the debugger is detached or when no breakpoints are enabled. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 3e27644..99238df 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -382,6 +382,8 @@ static void poll(void) if (!(status.quiesced)) break; + set_attn(false); + state = IDLE; poll_interval = VCONT_POLL_DELAY; if (!(status.active)) { From patchwork Tue Mar 29 15:49:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610700 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=VIdZuw/e; 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 4KSYtR5V7Yz9sFk for ; Wed, 30 Mar 2022 02:50:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtR4PrFz2xBK for ; Wed, 30 Mar 2022 02:50:23 +1100 (AEDT) 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=VIdZuw/e; 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::432; helo=mail-pf1-x432.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=VIdZuw/e; dkim-atps=neutral Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 4KSYtP2VPHz2yPJ for ; Wed, 30 Mar 2022 02:50:21 +1100 (AEDT) Received: by mail-pf1-x432.google.com with SMTP id b15so16267652pfm.5 for ; Tue, 29 Mar 2022 08:50:21 -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=B+ATvcgUNhjnxkpyeg3VitPSeeh2st6s7fl7rjMIUdQ=; b=VIdZuw/ekDBkCijg8R37M7l2pYebvm/DS5bkDAH3oBUCDdd9lWxVwjBcJi4EXVuFxT XwBCErnZqp87FKghK3Mx8y9wKd6yCE9H1XIvzDH9i45u4WxrpRCHCI9sas/F4vdDDTBH Nb8XL7/x8xusDzFumchUvWMtTGGmAT0fL5bt0QBVFa87GcNnsgxxm9drxi8jsSSSNikc D12UQPh/cHkqaYvRp2/YQhl3g9U0CjGZPgG5qTRm9yBl8+c8P0rcntYQitUFVy3hvBLr BgFM0I+4m3uyhdrPdVPtug3t7TZLoP34J6U8nuvZqmCQWJopyVVvzHuhOB1cmyOnnvia Q4dQ== 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=B+ATvcgUNhjnxkpyeg3VitPSeeh2st6s7fl7rjMIUdQ=; b=WWwo/Y/5PhaDgVKnV9kbCjiBzcGEX/hufenGWAr60k34JcIiDRLUrfiOO0VcmZZ5V8 uzypAPS7N5IbDhHMetnK1ujkdOTP0U48RgWxsffxJHqF6PD81FiX0wePG+12ykT0las3 gYR7rcnp4KZM/IFYoDRrFdd6n88NEGHwAyNMAXIJwjFuVa78HlhnkITnS699dfXMsQ56 9ItDWqN9liVLrUf3Ee5wn4ROfh0GP6mvgLKk6WNYFJ0fjYkjvZX/Zp9WEdogRJEnlAiY 1r/AeJTodVUcVPLzOlbOgxQPRx/RI9k8o5CVqrtlX1gYNLPuFOJZYDXE8lk/loU3C5Re yNjg== X-Gm-Message-State: AOAM530dp/YMeonvTMVO+Y0LJBw4mMySGSPgPhP+Rhb9EmDWBs40RyFf Pefb8KkgA7WvendHgK2dZB56EYl18qU= X-Google-Smtp-Source: ABdhPJzZapc/7LhKgb8+ztQIxC4hBxQIyh0jM91Z0HkSeiLWCec+fRRbWu/T6bJfvX2k3ZHSNIXUsQ== X-Received: by 2002:a63:656:0:b0:385:f723:5245 with SMTP id 83-20020a630656000000b00385f7235245mr2479093pgg.496.1648569018736; Tue, 29 Mar 2022 08:50:18 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:18 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:11 +1000 Message-Id: <20220329154931.493851-19-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 18/38] gdbserver: use read-modify-write for put_mem that is not 8-byte aligned 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" Not all targets have memory access that can support arbitrary byte writes. Use RMW for put_mem commands that are not 8-byte aligned. These helpers should possibly be moved into core code and this should really either be done in the target accessor, or at least an alignment capability should be exposed to the caller. But for now this will allow sbefifo mem ops to work to set breakpoints (which requires 4-byte writes). Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 99238df..c7cab28 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -229,6 +230,86 @@ static uint64_t get_real_addr(uint64_t addr) return addr; } +/* + * TODO: Move write_memory and read_memory into libpdbg helper and advertise + * alignment requirement of a target, or have the back-ends use it directly + * (latter may have the problem that implicit R-M-W is undesirable at very low + * level operations if we only wanted to write). + */ + +/* WARNING: _a *MUST* be a power of two */ +#define ALIGN_UP(_v, _a) (((_v) + (_a) - 1) & ~((_a) - 1)) +#define ALIGN_DOWN(_v, _a) ((_v) & ~((_a) - 1)) + +static int write_memory(uint64_t addr, uint64_t len, void *buf, size_t align) +{ + uint64_t start_addr, end_addr; + void *tmpbuf = NULL; + void *src; + int err = 0; + + start_addr = ALIGN_DOWN(addr, align); + end_addr = ALIGN_UP(addr + len, align); + + if (addr != start_addr || (addr + len) != end_addr) { + tmpbuf = malloc(end_addr - start_addr); + if (mem_read(adu_target, start_addr, tmpbuf, end_addr - start_addr, 0, false)) { + PR_ERROR("Unable to read memory for RMW\n"); + err = -1; + goto out; + } + memcpy(tmpbuf + (addr - start_addr), buf, len); + src = tmpbuf; + } else { + src = buf; + } + + if (mem_write(adu_target, start_addr, src, end_addr - start_addr, 0, false)) { + PR_ERROR("Unable to write memory\n"); + err = -1; + } + +out: + if (tmpbuf) + free(tmpbuf); + + return err; +} + +static int read_memory(uint64_t addr, uint64_t len, void *buf, size_t align) +{ + uint64_t start_addr, end_addr; + void *tmpbuf = NULL; + void *dst; + int err = 0; + + start_addr = ALIGN_DOWN(addr, align); + end_addr = ALIGN_UP(addr + len, align); + + if (addr != start_addr || (addr + len) != end_addr) { + tmpbuf = malloc(end_addr - start_addr); + dst = tmpbuf; + } else { + dst = buf; + } + + if (mem_read(adu_target, start_addr, dst, end_addr - start_addr, 0, false)) { + PR_ERROR("Unable to read memory\n"); + err = -1; + goto out; + } + + if (addr != start_addr || (addr + len) != end_addr) + memcpy(buf, tmpbuf + (addr - start_addr), len); + +out: + if (tmpbuf) + free(tmpbuf); + + return err; +} + + static void get_mem(uint64_t *stack, void *priv) { uint64_t addr, len, linear_map; @@ -252,7 +333,7 @@ static void get_mem(uint64_t *stack, void *priv) linear_map = get_real_addr(addr); if (linear_map != -1UL) { - if (mem_read(adu_target, linear_map, (uint8_t *) data, len, 0, false)) { + if (read_memory(linear_map, len, data, 1)) { PR_ERROR("Unable to read memory\n"); err = 1; } @@ -320,7 +401,7 @@ static void put_mem(uint64_t *stack, void *priv) } } - if (mem_write(adu_target, addr, data, len, 0, false)) { + if (write_memory(addr, len, data, 8)) { PR_ERROR("Unable to write memory\n"); err = 3; } From patchwork Tue Mar 29 15:49:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610701 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=YUhYOrqp; 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 4KSYtT5Fnyz9sFk for ; Wed, 30 Mar 2022 02:50:25 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtT44zCz2xvv for ; Wed, 30 Mar 2022 02:50:25 +1100 (AEDT) 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=YUhYOrqp; 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::530; helo=mail-pg1-x530.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=YUhYOrqp; dkim-atps=neutral Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 4KSYtR1XwBz2yJ9 for ; Wed, 30 Mar 2022 02:50:23 +1100 (AEDT) Received: by mail-pg1-x530.google.com with SMTP id k14so15207341pga.0 for ; Tue, 29 Mar 2022 08:50:23 -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=Chwc6sjTUvNe4ItNCrKZA6/Xah3CQDXFtfN02z2EHaY=; b=YUhYOrqpLCPLPeJZ91TJQxYuYvjBEjh99b9+rZ+OJKwsN6rUQFLa6fMHlxKSNBPGTU KjflryThnx1e9TUT2XSIjVYo5sZlFQmL7yrW55MYULZYN6wrb9ZfbT+LX10O6VgbzwYb QEGjK461w7QKyPKyoN3BYJW9T5MkzbNsxaEV1zkRU1s/EnL1FMtGwAfdoAyvxMUqFamy /sZ0ljtxBaE4p0ti2kECYmKi87gkR5Y3dejnV8z1A34BtKpIeYC5X3V6QRNMe6cDALef EKhlGebvn3P92WWYlpdqLaYVYd2D0fCV7HWCG/QPFLR9OZbbWpjQgjEvYnCFXPDkSbRn +Qbg== 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=Chwc6sjTUvNe4ItNCrKZA6/Xah3CQDXFtfN02z2EHaY=; b=tPnTxSpzR/5H5cDn3l32UdRI7mmNyMprlj+WqsbW/XrAC9h2C7/F3NII9Mn4e3AS2X WXmbiyeSY2aCgqJIbMW6fmfiS6fOba/f/aqtdm7qgE7lPjFJbxbPZmiCzyUfeuZU6V6s jai7MZ6Ua7yRw+R6P78SXXpPjzhH5q104wRhN6HRnhBt23ExzDfuFp23it0HNDwzOvhi pBuwgt7RRRTO/CdjJfMqWdQXocfPQEP/rxWUH+jEO8nwFr4Ka/vPcVdxAYJzYilV9kAC 18XrguQJpk0+ao4x1MLAMW0XtxutoeD3Dy4fk6tpuBb/Rx/wFbGs7Wc4I6qBzCzksd35 DCQA== X-Gm-Message-State: AOAM533l6RAyuFsvDU0KxVcI9xu9agmic3/b8evKLk39zPGOW4rKwfjA Vd2V/xD/eiW47ZmSNqK61+OLg41Q6M0= X-Google-Smtp-Source: ABdhPJxJgIfHerk2ooDVUjFmXgpiXc+zEqPCiktPBMWdx6Vrt4XIvh2UcMd4See+4tj0KrjIFF6g0w== X-Received: by 2002:a63:d149:0:b0:384:b288:8704 with SMTP id c9-20020a63d149000000b00384b2888704mr2416211pgj.112.1648569020717; Tue, 29 Mar 2022 08:50:20 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:20 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:12 +1000 Message-Id: <20220329154931.493851-20-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 19/38] gdbserver: enable POWER9 support 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" POWER9 has a strange problem with attn, but otherwise gdbserver works well. Enable it. Signed-off-by: Nicholas Piggin --- README.md | 14 +++++++++++--- src/pdbgproxy.c | 29 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index be26dc1..5c5c05d 100644 --- a/README.md +++ b/README.md @@ -527,8 +527,9 @@ There are also low level htm commands which can also be used: - `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. +At the moment gdbserver is only supported on P8 and P9. + +Memory access can only be performed on kernel memory. To run a gdbserver on a P8 machine from a BMC running openbmc: @@ -540,7 +541,7 @@ $ ./pdbg -d p8 -p0 -c11 -t0 gdbserver 44 On your local machine: $ gdb -(gdb) set architecture powerpc:common64 +(gdb) set architecture powerpc:common64 (gdb) target remote palm5-bmc:44 Debugging info: @@ -559,6 +560,13 @@ Notes: 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). +3. The kernel HARDLOCKUP watchdog can interact badly with GDBSERVER (and all +pdbg direct controls for that matter). Disabling it before debugging is a +good idea. +4. Idle states have often had problems with pdbg direct controls. If things are +misbehaving, booting Linux with powersave=off is the first thing to try. +5. attn instructions seem to cause host hangs on POWER9. gdb breakpoints should +not be used. ## Submitting patches diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c7cab28..b3bf5bd 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -105,6 +105,9 @@ static void detach(uint64_t *stack, void *priv) #define POWER8_HID_ENABLE_ATTN PPC_BIT(31) +#define POWER9_HID_ENABLE_ATTN PPC_BIT(3) +#define POWER9_HID_FLUSH_ICACHE PPC_BIT(2) + static int set_attn(bool enable) { uint64_t hid; @@ -122,6 +125,17 @@ static int set_attn(bool enable) return 0; hid &= ~POWER8_HID_ENABLE_ATTN; } + } else if (pdbg_target_compatible(thread_target, "ibm,power9-thread")) { + if (enable) { + if (hid & POWER9_HID_ENABLE_ATTN) + return 0; + hid |= POWER9_HID_ENABLE_ATTN; + } else { + if (!(hid & POWER9_HID_ENABLE_ATTN)) + return 0; + hid &= ~POWER9_HID_ENABLE_ATTN; + } + hid |= POWER9_HID_FLUSH_ICACHE; } else { return -1; } @@ -658,13 +672,20 @@ static int gdbserver(uint16_t port) return 0; } - // - // Temporary until I can get this working a bit smoother on p9 - if (!pdbg_target_compatible(thread, "ibm,power8-thread")) { - PR_ERROR("GDBSERVER is only available on POWER8\n"); + if (!pdbg_target_compatible(thread, "ibm,power8-thread") && + !pdbg_target_compatible(thread, "ibm,power9-thread")) { + PR_ERROR("GDBSERVER is only available on POWER8 and POWER9\n"); return -1; } + if (pdbg_target_compatible(thread, "ibm,power9-thread")) { + /* + * XXX: If we advertise no swbreak support on POWER9 does + * that prevent the client using them? + */ + PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); + } + /* Check endianess in MSR */ rc = thread_getmsr(thread, &msr); if (rc) { From patchwork Tue Mar 29 15:49:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610702 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=MdU05ej/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtW4wQCz9sFk for ; Wed, 30 Mar 2022 02:50:27 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtW42pRz2yMS for ; Wed, 30 Mar 2022 02:50:27 +1100 (AEDT) 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=MdU05ej/; 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::636; helo=mail-pl1-x636.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=MdU05ej/; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 4KSYtT24lSz2yJ5 for ; Wed, 30 Mar 2022 02:50:25 +1100 (AEDT) Received: by mail-pl1-x636.google.com with SMTP id p17so18005542plo.9 for ; Tue, 29 Mar 2022 08:50:25 -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=Ublmn9OTvKUCE6QBlC3rW0VSwPOIHLKbrWtvZ2S8WJI=; b=MdU05ej/TpRHkI6Nk7IAc85fjBrQ9z4uv8A6SQS+mxEyK1k0JtV0byR1ZwWqAoS52W Ab/EYY6QS3G35OX1ZcwWv6zyW9OE3tsXDhtpApjzHe71SUoAhoKYeI6arvQAZsBYzX0X JUpumZkmt3bRD+8yvIZnRFvGw5+8VWA+v5zjB9MVk0MvcDP+1XQ6240K3mErF5M2aSuT M6zmCgCzKF4FOYGqlx916yA+/T04ndAMAW1EjlP1pUJeUaUkRFM+lE3o5M1efc9ivMq0 eCYUZLUnHR6NZKDDLCq0BsarQWHDfs4ZElq5Hcn69taoFgfQJGzBUyLM0ie/ow8fdIiE cJ3w== 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=Ublmn9OTvKUCE6QBlC3rW0VSwPOIHLKbrWtvZ2S8WJI=; b=pkAG6iuGZzmOAGM2OBRMB4AysP84EWl5UTMx+4lX7IxgeKmqovITlYfMGt0iL3iT0h ut6hGHpzhrd5/aIfqe70fc+ix/8+jxUH8bPKXyMaX8WW6g+ncDq2SYvNMWHuCl/0zNuR Vv2fCo9J2WX7nlSeO5Snlm+itsk+k3AWUFfCO9Ld5lBpRnCiXuabQfOsmUXl9WxxeA2g eT9hRU9yoUpMQ5G53xPQCKPBqD7QLyFejvOD5cn1bw0SdPlN8TrztR6Un0hnz6Ft12Pa iVfv/2NsjJi0vtpB18d4Fbcj1EzSw5jQzJtPUMMrEHQVQeJOn02Lj7SYsLrKXcW5v8go ihqQ== X-Gm-Message-State: AOAM530trSV99hkWwi23HKkwOEaqqRxtQth6h24Gk7asx5/DM/Bm/O46 Qdefb/IuQuYwCaWx5fvzFRfCevv40t0= X-Google-Smtp-Source: ABdhPJwzI5dBrC2vtfXxMoVPGc8cyYZmOlNJ6NXv0Bw1oQ2ObX99i+pgNSTVhSUzisYRvSE8i8DzTA== X-Received: by 2002:a17:90b:4f86:b0:1c9:b52d:9713 with SMTP id qe6-20020a17090b4f8600b001c9b52d9713mr241800pjb.98.1648569023035; Tue, 29 Mar 2022 08:50:23 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:22 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:13 +1000 Message-Id: <20220329154931.493851-21-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 20/38] gdbserver: Add POWER10 support 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" Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- README.md | 2 +- src/pdbgproxy.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5c5c05d..0faa1bf 100644 --- a/README.md +++ b/README.md @@ -527,7 +527,7 @@ There are also low level htm commands which can also be used: - `dump` will dump the trace to a file. ### GDBSERVER -At the moment gdbserver is only supported on P8 and P9. +At the moment gdbserver is only supported on P8 and P9 and P10. Memory access can only be performed on kernel memory. diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index b3bf5bd..eddf813 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -108,6 +108,9 @@ static void detach(uint64_t *stack, void *priv) #define POWER9_HID_ENABLE_ATTN PPC_BIT(3) #define POWER9_HID_FLUSH_ICACHE PPC_BIT(2) +#define POWER10_HID_ENABLE_ATTN PPC_BIT(3) +#define POWER10_HID_FLUSH_ICACHE PPC_BIT(2) + static int set_attn(bool enable) { uint64_t hid; @@ -136,6 +139,17 @@ static int set_attn(bool enable) hid &= ~POWER9_HID_ENABLE_ATTN; } hid |= POWER9_HID_FLUSH_ICACHE; + } else if (pdbg_target_compatible(thread_target, "ibm,power10-thread")) { + if (enable) { + if (hid & POWER10_HID_ENABLE_ATTN) + return 0; + hid |= POWER10_HID_ENABLE_ATTN; + } else { + if (!(hid & POWER10_HID_ENABLE_ATTN)) + return 0; + hid &= ~POWER10_HID_ENABLE_ATTN; + } + hid |= POWER10_HID_FLUSH_ICACHE; } else { return -1; } @@ -673,8 +687,9 @@ static int gdbserver(uint16_t port) } if (!pdbg_target_compatible(thread, "ibm,power8-thread") && - !pdbg_target_compatible(thread, "ibm,power9-thread")) { - PR_ERROR("GDBSERVER is only available on POWER8 and POWER9\n"); + !pdbg_target_compatible(thread, "ibm,power9-thread") && + !pdbg_target_compatible(thread, "ibm,power10-thread")) { + PR_ERROR("GDBSERVER is only available on POWER8,9,10\n"); return -1; } From patchwork Tue Mar 29 15:49:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610703 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=Xcd8UqJ8; 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 4KSYtY4DSvz9sFk for ; Wed, 30 Mar 2022 02:50:29 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtY38Vxz2xYG for ; Wed, 30 Mar 2022 02:50:29 +1100 (AEDT) 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=Xcd8UqJ8; 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::1029; helo=mail-pj1-x1029.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=Xcd8UqJ8; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 4KSYtW0DRJz2xt7 for ; Wed, 30 Mar 2022 02:50:26 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so2253077pjb.3 for ; Tue, 29 Mar 2022 08:50:26 -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=TZa7tBfB6PQSoqJPKL7ERqHT9SJ+2kyqJnETyyxcFCw=; b=Xcd8UqJ8CjJhfTRFoooAANwjvIkC5gy/o0hGe7ENDZXz4smZorMf3eOPUIM6OvzMIY 2oKWZvc2PGC1GmD1ORHC6S2UZtT1pqDTN/IubiBpZbHWgA2L3JIGOlu7j1JsvFUC6L2A yyYem3G5qkKjFpuOiK6ROUQmeeZtM2Dv1m3SdGYlisI7X2pgtfA/GWiwZIBn+lhfXoVj 6R4Uvr9497Rjnk5UhLwxyC+7eanvMQXL/IRBkMBvCZnxG3U75r7018SZLSghbIB1L6Td Gy5JTxMIHVRbe5VvfupfoU2V+FgjCAsMFXulHCpl5lSaXvFwGIHgs3F6OnemQgJz17uI MpTA== 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=TZa7tBfB6PQSoqJPKL7ERqHT9SJ+2kyqJnETyyxcFCw=; b=7BZ1tBElXb4DNvOarb29KjsLhP23QyJ77EKHtU9PK1MrPCNBXUl+eM1ZOj8hY9x7Wh kfMbdzJAl3YyTvvnohn5ldpi1j70f5N0htgD/9Wr3tBwYur0GeAXikMPJ9v+Zl4WsxlU wbFXp87VhQ1LnUC5EJCwubG3dnmF9/QTZ/rdNY1WAAHCUE2wkV+jHkljoHhTEOCx6PSZ O0ylctHfny+JlMfqMn3aHVDxhrgrpR59CepomEf4GAP8568EG75qgtZyaTTsZwpoUh3M YcVurX/q5+/2Ru8e0QOEoUhpK05fN24FVtSUuU4ZzpCc+p4A1LjokkpJ3I0VTdGLqHiQ riuQ== X-Gm-Message-State: AOAM532IRtPApVNJGKC6s8eyozHr48pwu/Y7Z3nPSIseAHQKzK6yRk/6 l6qAzbYnzQUXrkg69wydmRCNuAXzXY0= X-Google-Smtp-Source: ABdhPJwPqqJ3bCF639vCcE++tseXABEygNx3qc+kh0QJhv8dTMEaLc1h68sj3Oqjg6N3pciuU3z0lQ== X-Received: by 2002:a17:903:3051:b0:156:2d03:3434 with SMTP id u17-20020a170903305100b001562d033434mr3829941pla.101.1648569024959; Tue, 29 Mar 2022 08:50:24 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:24 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:14 +1000 Message-Id: <20220329154931.493851-22-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 21/38] gdbserver: check for attn using the SPATTN register 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" When POWER9/10 execute an attn instruction, they set a bit in the SPATTN instruction and quiesce the thread. This bit can be checked to confirm the thread hit an attn instruction, rather than assuming based on the thread being quiesced. This also clears the SPATTN bit which clears the exception condition that seems to be involved with the IPOLL interrupt storm and lock up (although this does not fix POWER9). Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 79 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index eddf813..1843517 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -457,6 +457,59 @@ static void v_contc(uint64_t *stack, void *priv) poll_interval = 1; } +#define P9_SPATTN_AND 0x20010A98 +#define P9_SPATTN 0x20010A99 + +#define P10_SPATTN_AND 0x20028498 +#define P10_SPATTN 0x20028499 + +static bool thread_check_attn(struct pdbg_target *target) +{ + struct thread *thread = target_to_thread(target); + struct pdbg_target *core; + uint64_t spattn; + + if (pdbg_target_compatible(target, "ibm,power8-thread")) { + return true; /* XXX */ + } else if (pdbg_target_compatible(target, "ibm,power9-thread")) { + core = pdbg_target_require_parent("core", target); + if (pib_read(core, P9_SPATTN, &spattn)) { + PR_ERROR("SPATTN read failed\n"); + return false; + } + + if (spattn & PPC_BIT(1 + 4*thread->id)) { + uint64_t mask = ~PPC_BIT(1 + 4*thread->id); + + if (pib_write(core, P9_SPATTN_AND, mask)) { + PR_ERROR("SPATTN clear failed\n"); + return false; + } + + return true; + } + } else if (pdbg_target_compatible(target, "ibm,power10-thread")) { + core = pdbg_target_require_parent("core", target); + if (pib_read(core, P10_SPATTN, &spattn)) { + PR_ERROR("SPATTN read failed\n"); + return false; + } + + if (spattn & PPC_BIT(1 + 4*thread->id)) { + uint64_t mask = ~PPC_BIT(1 + 4*thread->id); + + if (pib_write(core, P10_SPATTN_AND, mask)) { + PR_ERROR("SPATTN clear failed\n"); + return false; + } + + return true; + } + } + + return false; +} + static void interrupt(uint64_t *stack, void *priv) { struct thread_state status; @@ -477,7 +530,6 @@ static void interrupt(uint64_t *stack, void *priv) static void poll(void) { - uint64_t nia; struct thread_state status; thread_target->probe(thread_target); @@ -495,17 +547,22 @@ static void poll(void) 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 (thread_getnia(thread_target, &nia)) - PR_ERROR("Error during getnia\n"); - if (thread_putnia(thread_target, nia - 4)) - PR_ERROR("Error during putnia\n"); + if (thread_check_attn(thread_target)) { + uint64_t nia; + + if (!(status.active)) { + PR_ERROR("Thread inactive after trap\n"); + send_response(fd, ERROR(EPERM)); + return; + } + + /* Restore NIA */ + if (thread_getnia(thread_target, &nia)) + PR_ERROR("Error during getnia\n"); + if (thread_putnia(thread_target, nia - 4)) + PR_ERROR("Error during putnia\n"); + } send_response(fd, TRAP); break; } From patchwork Tue Mar 29 15:49:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610704 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=nwZk8zgU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtb4MtDz9sFk for ; Wed, 30 Mar 2022 02:50:31 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtb3SC0z2y7V for ; Wed, 30 Mar 2022 02:50:31 +1100 (AEDT) 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=nwZk8zgU; 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::102c; helo=mail-pj1-x102c.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=nwZk8zgU; dkim-atps=neutral Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) (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 4KSYtY20JCz2yHB for ; Wed, 30 Mar 2022 02:50:29 +1100 (AEDT) Received: by mail-pj1-x102c.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so2253144pjb.3 for ; Tue, 29 Mar 2022 08:50:29 -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=2Vs3d0+ooCHI5JNMyR7Iu3dpsUGxg8c1vpE7uKkQI/U=; b=nwZk8zgUN9vpfyM5uGVTLeoyevHUbTdOKcYtKLp2VxtU7dW3GtTKoYx0GVkAXO6krY 0b08veL/1t3zTYQJbqlRd7mPrjDuEjxvt+aBQNxEWwoPJERfBUzuPhSqjX7+MQifANRg 9nnMtxEIri/K82eGCNFiVObaqnxcDjECkeYJB9Yhpz2rBLMzTE3lzOyjNOI2X7H2/s2V O+zt0s86YSMMVXdNBlVdPkN8PconwsliHcrMaz32fq7VMpuVhOcDvR8vj7uzxelNMGSJ 1xGci2lQQ7wdjhBS2ICQSgzIQNoM7puccdGFEWMM5RV27CLFxo0/DEzRQ1XRcfm5fWhr aAYA== 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=2Vs3d0+ooCHI5JNMyR7Iu3dpsUGxg8c1vpE7uKkQI/U=; b=T5fxaksHnN1NxYws7zJRawpQhX1DCHcKZXnsQ6G9Dwo0fP1/Z55aatqz6po9JNGRkA dcjvLnH/PUgQZTmU52/fSfWdD1O93zD1EyvJdQewDEpPuWsnTPkneuw8bJM97BmlXa+E xBsIMXaTVyHizngdQ41eYrS5gsD6bNiwu2AjPu2SZ7W2ds1cg5OM5qI95P8TVbfjockg cN2cDxIxgvQxb2xETjKq1zrhRqcMBeLnMGIlYkx23KInbqt4F1oG0tfvnSZWzLETubGg sLSR4iYzfVOGfbjqi825EQxRfPMbcdYeLM/J3/6KmFkGEOS+i6WaRXtfRXL4umQVmEyJ 8wcw== X-Gm-Message-State: AOAM531HXYomIYT+5WOG+2Z6h9FSS6uSd+VIIMv/Kk5L+aDCg2Lpvpj4 yTJrW17FYsazvZLXjUyzxIz6P3y64k4= X-Google-Smtp-Source: ABdhPJzRnFWc+1Ovo1PWTovVJb9ClHx5rqkHhER5pHDQSna6O9nXieu4Bps2lZDy/QByJA386ZGWEQ== X-Received: by 2002:a17:903:18c:b0:154:9ee:ced3 with SMTP id z12-20020a170903018c00b0015409eeced3mr30962120plg.170.1648569026932; Tue, 29 Mar 2022 08:50:26 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:26 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:15 +1000 Message-Id: <20220329154931.493851-23-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 22/38] gdbserver: test endian when it is required 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" Rather than testing endian once at start-up, test it when a breakpoint is being installed. This may give a bit better chance of the correct endian being used if a processor switches endian after the gdbserver is started. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1843517..29ba52a 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -47,7 +47,6 @@ static struct pdbg_target *adu_target; 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; @@ -395,11 +394,6 @@ static void put_mem(uint64_t *stack, void *priv) uint8_t gdb_break_opcode[] = {0x7d, 0x82, 0x10, 0x08}; int err = 0; - if (littleendian) { - attn_opcode[1] = 0x02; - attn_opcode[2] = 0x00; - } - addr = stack[0]; len = stack[1]; data = (uint8_t *)(unsigned long)stack[2]; @@ -412,6 +406,19 @@ static void put_mem(uint64_t *stack, void *priv) } if (len == 4 && !memcmp(data, gdb_break_opcode, 4)) { + uint64_t msr; + + /* Check endianess in MSR */ + err = thread_getmsr(thread_target, &msr); + if (err) { + PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); + goto out; + } + if (msr & 1) { /* little endian */ + attn_opcode[1] = 0x02; + attn_opcode[2] = 0x00; + } + /* 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 @@ -419,6 +426,7 @@ static void put_mem(uint64_t *stack, void *priv) * * 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; @@ -723,8 +731,6 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ static int gdbserver(uint16_t port) { struct pdbg_target *target, *adu, *thread = NULL; - uint64_t msr; - int rc; for_each_path_target_class("thread", target) { if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) @@ -758,14 +764,6 @@ static int gdbserver(uint16_t port) PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); } - /* Check endianess in MSR */ - rc = thread_getmsr(thread, &msr); - if (rc) { - PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); - return 1; - } - littleendian = 0x01 & msr; - /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) From patchwork Tue Mar 29 15:49:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610705 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=H6auZwy2; 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 4KSYtd4RXyz9sFk for ; Wed, 30 Mar 2022 02:50:33 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtd3NSXz2xvv for ; Wed, 30 Mar 2022 02:50:33 +1100 (AEDT) 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=H6auZwy2; 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::535; helo=mail-pg1-x535.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=H6auZwy2; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 4KSYtb1gRYz2yJ5 for ; Wed, 30 Mar 2022 02:50:31 +1100 (AEDT) Received: by mail-pg1-x535.google.com with SMTP id l129so6659406pga.3 for ; Tue, 29 Mar 2022 08:50:31 -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=UAO+OTcidRidhDB4oXSvLRYcPMOZGfrqd/q2NuiEqZE=; b=H6auZwy2yRds4I4jSbcAZ9z9CEG35GxeS+bGnisWpP41pof+hUmJaeMzv/y6+LwZ32 okItn534IyJwVl2Ke8wyIrcFwSYGGLlC9WE+Gh9CJBeNz+rpry6D2/EFLzNHznX2j3iO nH9fdBYAirJ+2a2OX8D3fa5JsTueLKKViO8g0XcFDQHO+2UeOU5DUbo5L3UNJ+rV32jv fVYAEjSemd8/syrPhZJXTFUyucAYQ8dbtgg7141+aU3p7FahTZn6CAo/8152Vw0HVhSL 6IBH0v5aHdWC/MXbzFvZYmR/CCCHaKtog+kBW+8vDDWot+jrE7j71qFURWjvdHq+AbHB xaUg== 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=UAO+OTcidRidhDB4oXSvLRYcPMOZGfrqd/q2NuiEqZE=; b=HISnfStwc7j/F+r5i68aK2o1t2NCuc2NBuIKaw8OD1+iokJ6hGuKFHtkdBVgccWG2r WbHqEvBeQiRevvdS3lCm1hUOWIgv5Udn4ylPlopWBHAVrARo2gK97UED8xk1LapqOdHi VWvaocNbaPyhYyIbLSaNkjT3GfkQxwrxW1ZFNY6dVWexPC7548iZEvBlR6YyztvN7tnu FcN5ONbIVaKusThwIjcYWN0hiegygBZJqMsLpG/Fi/EtAVnzrlPPHEd7P6q2f1sKdUnB zOfjyquFGvzV6fzk/KtUK2dO2y5sFoMEp+XrHpAJSsvpFes/KjZe4vmBDUeyP/UhlxtD 8m/Q== X-Gm-Message-State: AOAM531OYeHmHH6wEzS+z/LQeoxiupMZHWuBYccvX3qCiltqfOafqBKe cU9ChcMIuhz7XBQOd9nx1L+d/8uZDNs= X-Google-Smtp-Source: ABdhPJxe5+0SL43YVxqmI/ol4HfcJIPOOZFYNG0v0SO1NyhnunBzu+OXXWmYyQ203BetHTC9JpzG2A== X-Received: by 2002:a63:1a04:0:b0:381:edc8:66b1 with SMTP id a4-20020a631a04000000b00381edc866b1mr2430663pga.131.1648569028841; Tue, 29 Mar 2022 08:50:28 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:28 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:16 +1000 Message-Id: <20220329154931.493851-24-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 23/38] gdbserver: catch ctrl-C 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" This allows gdbserver to clean up the host state gracefully after a SIGINT. It will become more important with later patches. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 29ba52a..b09cf5f 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -640,12 +641,28 @@ static command_cb callbacks[LAST_CMD + 1] = { detach, NULL}; -int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) +static volatile bool gdbserver_running = true; + +static void SIGINT_handler(int sig) +{ + gdbserver_running = false; +} + +static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) { int sock, i; + struct sigaction sa; struct sockaddr_in name; fd_set active_fd_set, read_fd_set; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIGINT_handler; + sa.sa_flags = SA_RESETHAND; + if (sigaction(SIGINT, &sa, NULL) == -1) { + perror("sigaction"); + return -1; + } + parser_init(callbacks); thread_target = thread; adu_target = adu; @@ -674,7 +691,7 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ FD_ZERO(&active_fd_set); FD_SET(sock, &active_fd_set); - while (1) { + while (gdbserver_running) { read_fd_set = active_fd_set; timeout.tv_sec = 0; timeout.tv_usec = poll_interval; @@ -725,6 +742,8 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ poll(); } + printf("gdbserver: got ctrl-C, cleaning up (second ctrl-C to kill immediately).\n"); + return 1; } @@ -776,6 +795,7 @@ static int gdbserver(uint16_t port) } gdbserver_start(thread, adu, port); + return 0; } #else From patchwork Tue Mar 29 15:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610706 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=VONoYym3; 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 4KSYtg42s3z9sFk for ; Wed, 30 Mar 2022 02:50:35 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtg2ltzz2yJQ for ; Wed, 30 Mar 2022 02:50:35 +1100 (AEDT) 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=VONoYym3; 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::102d; helo=mail-pj1-x102d.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=VONoYym3; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 4KSYtd1L51z2yJ5 for ; Wed, 30 Mar 2022 02:50:33 +1100 (AEDT) Received: by mail-pj1-x102d.google.com with SMTP id mp6-20020a17090b190600b001c6841b8a52so2241106pjb.5 for ; Tue, 29 Mar 2022 08:50:33 -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=qB2cIT/3K12VV2Hlu9wWnwQTIHpm5NV2kPN4UAltVAU=; b=VONoYym3xLWpsp25szaU9YdnJZEFaKdSLCpuR6oo9xpUBbsdF1qjH1eEdidWP6pkSN sNhSbjfAAgKYS0bxnuXDqBYkn0If+pOepaXQxcHHFtoJOdno50xb4Yb6P0hVdgeArdj1 KVbMrVOFGW0giHKMW6j6K8olWT3YgKunKxChf8XP64H9DKhGqzq1+5o1mRRdyXM7qZmM kwxBdIRgd6RkVEroUeAj4lZtqhdCQUZ4zX9mXEbPaZgiwBFPLUv1N+fyrSgu96WQ6PbR lr4eOI3lv1O7WxA45INQC/t/ySpX64hn1kr2VNKy+0x4ueeDnQi4nzXAFkXG5+30vU9a y/fg== 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=qB2cIT/3K12VV2Hlu9wWnwQTIHpm5NV2kPN4UAltVAU=; b=eAO/UgxtpPM8ry7iVMvaC6Xgr+a1ueN+OAfj1nd85EgUsAtf1l/k7QeCfSc4K9nn3/ uQjlXL3qPG6g7SpyHeRnbKj61vggLArBn65YG6T8XWyrfg00ERu2Xnd00QVktdJbZzHG 0gvpEnfN+JanFjCmWz5WIhEzNjElQXCB01wZdoDJo9q5AAxCLBdUlkd1MRV2mdw1Fw41 ofWKwCOaoQGziaoHLOjgjOuQ3jW7o1fN/jtt5/R0Tuw67nl7P/3S7C4GAxiOd8JMjt0Y 3YaX59imYClIL/fdV4lbFavOCi8jCMUbdr/f19F2qM4rOt3NlsmuJQB6zHPMLSHr+9B3 G6Ig== X-Gm-Message-State: AOAM5316S2LvZFrlKd9SLSFPKgcNHH33Go9kQirc2UXxbE3jdFFa8Kgk MC8GeuPANK84SvQRSwmStlWeIQjjcsw= X-Google-Smtp-Source: ABdhPJwWKOoTQNVrYxIULAKWjpx4RTg7MNSSGFobaGDLnW+rfdeSz1wvCPnBSnD1HAtdhQDfVVbOLw== X-Received: by 2002:a17:902:cec8:b0:154:6dd6:255d with SMTP id d8-20020a170902cec800b001546dd6255dmr31534064plg.62.1648569030749; Tue, 29 Mar 2022 08:50:30 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:30 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:17 +1000 Message-Id: <20220329154931.493851-25-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 24/38] gdbserver: return more registers 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" Returning all default registers prevents the client from re-requesting them every time you run `info r`. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index b09cf5f..6fa3c6d 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -183,10 +183,10 @@ static void get_spr(uint64_t *stack, void *priv) { char data[REG_DATA_SIZE]; uint64_t value; + uint32_t value32; switch (stack[0]) { case 0x40: - /* Get PC/NIA */ if (thread_getnia(thread_target, &value)) PR_ERROR("Error reading NIA\n"); snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); @@ -194,7 +194,6 @@ static void get_spr(uint64_t *stack, void *priv) break; case 0x41: - /* Get MSR */ if (thread_getmsr(thread_target, &value)) PR_ERROR("Error reading MSR\n"); snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); @@ -202,35 +201,54 @@ static void get_spr(uint64_t *stack, void *priv) break; case 0x42: - /* Get CR */ - if (thread_getcr(thread_target, (uint32_t *)&value)) + if (thread_getcr(thread_target, &value32)) PR_ERROR("Error reading CR \n"); - snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh((uint64_t)value32)); send_response(fd, data); break; case 0x43: - /* Get LR */ - if (thread_getspr(thread_target, 8, &value)) + if (thread_getspr(thread_target, SPR_LR, &value)) PR_ERROR("Error reading LR\n"); snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); send_response(fd, data); break; case 0x44: - /* Get CTR */ - if (thread_getspr(thread_target, 9, &value)) + if (thread_getspr(thread_target, SPR_CTR, &value)) PR_ERROR("Error reading CTR\n"); snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(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"); + /* + * Not all XER register bits may be recoverable with RAM + * mode accesses, so this may be not entirely accurate. + */ + if (thread_getspr(thread_target, SPR_XER, &value)) + PR_ERROR("Error reading XER\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); + send_response(fd, data); + break; + + case 0x46: + if (thread_getspr(thread_target, SPR_FPSCR, &value)) + PR_ERROR("Error reading FPSCR\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); + send_response(fd, data); + break; + case 0x67: + if (thread_getspr(thread_target, SPR_VSCR, &value)) + PR_ERROR("Error reading VSCR\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); + send_response(fd, data); + break; + case 0x68: + if (thread_getspr(thread_target, SPR_VRSAVE, &value)) + PR_ERROR("Error reading VRSAVE\n"); + snprintf(data, REG_DATA_SIZE, "%016" PRIx64 , be64toh(value)); + send_response(fd, data); break; default: From patchwork Tue Mar 29 15:49:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610707 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=RRe6RKAI; 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 4KSYth3rTtz9sFk for ; Wed, 30 Mar 2022 02:50:36 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYth2lz2z2xvS for ; Wed, 30 Mar 2022 02:50:36 +1100 (AEDT) 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=RRe6RKAI; 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::62d; helo=mail-pl1-x62d.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=RRe6RKAI; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 4KSYtf6RTnz2xYG for ; Wed, 30 Mar 2022 02:50:34 +1100 (AEDT) Received: by mail-pl1-x62d.google.com with SMTP id f10so7661263plr.6 for ; Tue, 29 Mar 2022 08:50:34 -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=ZOjEwgm7KBQ08m4j6j5gWx/RC4pGprhF2SMRoNtDg10=; b=RRe6RKAIkOviFzs65ncojl2VqOBPp18OP9E7q9ahMSvJW1MgTVSZYSTES4OA9CgQWm H2+5iVpLX7ULjHZJEJcNdUxsY5SDrwtCSxMUYAlZYD+7COVNaPPwiuFrVfCHAEQ9j7Mf Fcik7qqlSpKRrBUIeWaDLlOD082QRjWaw5Zcpxxq4ZiF+pHX/cBUdmzXm7NBiMdXBPWc jtDXJmNTf78435EOQFE08yaGrDbbtx69wpjaL/IMdewfnhAE6RkuPslxWnLNFDH5/62L BFnAyTR8N+Cwo15qQJVI6WcZeiV8Hevcy4OTDX5Rc8stu7Ny7cbrasYB8t2y0RxYIAO/ jPWQ== 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=ZOjEwgm7KBQ08m4j6j5gWx/RC4pGprhF2SMRoNtDg10=; b=iTppq8p71bIdpeXMZjwJMI1x7pAwlamhfI00886yMRGq8W8urn8uCQrVkVthlDI8I5 G6VkJTXoWYpUZnVRhtZ8aEdmaoX6Jim93V5Sh3xeBMttTgLnHANsUJxos92hPZar9vMV e9r/CwTE0pDw+WwNfkJOr+TBUCq8924oaRTqPzmNJ5tEO3hfaRkaBqhPf4dQPU45IfKo G+anhg17iqA+yXyvW8jx135+K8VlfJPwL75kOMRBV0/lcEcEBaGoJ36Bd2hgcTkZ3mw5 jpD1k5PKFejo0sCXck3S4QLq/qm0CsnkUa0BqPyfomAG46IF4Dhu7RwgaRKaFTG0mWfB FCzQ== X-Gm-Message-State: AOAM532jQKDUPvJdQXkCV6R4/WX1X6baD2VDeroKAZQuToSpWJ2MVUTX qxr29Hf6NwkMa0s5gDHEqBTcJ01ghXM= X-Google-Smtp-Source: ABdhPJxwqhhyN35GuOS0DFWwRsLI2Z6r8/v5m5py0z+lkUhqF5UGeL9lv1U3jjGPkgt+iKqwEeK1ow== X-Received: by 2002:a17:90a:8595:b0:1bf:4592:a819 with SMTP id m21-20020a17090a859500b001bf4592a819mr204364pjn.183.1648569032652; Tue, 29 Mar 2022 08:50:32 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:32 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:18 +1000 Message-Id: <20220329154931.493851-26-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 25/38] gdbserver: initial thread support 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" Add a command-specific pointer to the struct thread that gdbserver can use, so it doesn't have to build its own structure of threads. Initially keep the PIR value in here, as a demonstration. Later PIR will be used to identify threads to the gdb client, and more data will be added to the gdb_thread structure to support debugging multiple threads. Signed-off-by: Nicholas Piggin --- libpdbg/hwunit.h | 1 + src/pdbgproxy.c | 66 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index 2ce41db..563b581 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -139,6 +139,7 @@ struct core { struct thread { struct pdbg_target target; struct thread_state status; + void *gdbserver_priv; int id; struct thread_state (*state)(struct thread *); int (*step)(struct thread *, int); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 6fa3c6d..c5e439d 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -51,6 +51,11 @@ static int fd = -1; enum client_state {IDLE, SIGNAL_WAIT}; static enum client_state state = IDLE; +/* Attached to thread->gdbserver_priv */ +struct gdb_thread { + uint64_t pir; +}; + static void destroy_client(int dead_fd); static uint8_t gdbcrc(char *data) @@ -666,7 +671,7 @@ static void SIGINT_handler(int sig) gdbserver_running = false; } -static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) +static int gdbserver_start(struct pdbg_target *adu, uint16_t port) { int sock, i; struct sigaction sa; @@ -682,7 +687,6 @@ static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, } parser_init(callbacks); - thread_target = thread; adu_target = adu; sock = socket(PF_INET, SOCK_STREAM, 0); @@ -767,33 +771,40 @@ static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, static int gdbserver(uint16_t port) { - struct pdbg_target *target, *adu, *thread = NULL; + struct pdbg_target *target, *adu, *first_target = NULL; for_each_path_target_class("thread", target) { - if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - if (!thread) { - thread = target; + if (!pdbg_target_compatible(target, "ibm,power8-thread") && + !pdbg_target_compatible(target, "ibm,power9-thread") && + !pdbg_target_compatible(target, "ibm,power10-thread")) { + PR_ERROR("GDBSERVER is only available on POWER8,9,10\n"); + return -1; + } + + gdb_thread = malloc(sizeof(struct gdb_thread)); + memset(gdb_thread, 0, sizeof(*gdb_thread)); + thread->gdbserver_priv = gdb_thread; + + if (!first_target) { + first_target = target; } else { fprintf(stderr, "GDB server cannot be run on multiple threads at once.\n"); return 0; } } - if (!thread) { + if (!first_target) { fprintf(stderr, "No thread selected\n"); return 0; } - if (!pdbg_target_compatible(thread, "ibm,power8-thread") && - !pdbg_target_compatible(thread, "ibm,power9-thread") && - !pdbg_target_compatible(thread, "ibm,power10-thread")) { - PR_ERROR("GDBSERVER is only available on POWER8,9,10\n"); - return -1; - } - - if (pdbg_target_compatible(thread, "ibm,power9-thread")) { + if (pdbg_target_compatible(first_target, "ibm,power9-thread")) { /* * XXX: If we advertise no swbreak support on POWER9 does * that prevent the client using them? @@ -801,6 +812,29 @@ static int gdbserver(uint16_t port) PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); } + thread_target = first_target; + + 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 (thread_getspr(target, SPR_PIR, &gdb_thread->pir)) { + PR_ERROR("Error reading PIR. Are all thread in the target cores quiesced?\n"); + return 0; + } + + if (gdb_thread->pir & ~0xffffULL) { + /* This limit is just due to some string array sizes */ + PR_ERROR("PIR exceeds 16-bits."); + return 0; + } + } + /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) @@ -812,7 +846,7 @@ static int gdbserver(uint16_t port) return 0; } - gdbserver_start(thread, adu, port); + gdbserver_start(adu, port); return 0; } From patchwork Tue Mar 29 15:49:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610708 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=DG94UFgd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtl4YbCz9sFk for ; Wed, 30 Mar 2022 02:50:39 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtl3j90z2xfP for ; Wed, 30 Mar 2022 02:50:39 +1100 (AEDT) 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=DG94UFgd; 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::102b; helo=mail-pj1-x102b.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=DG94UFgd; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 4KSYth60yzz2yPT for ; Wed, 30 Mar 2022 02:50:36 +1100 (AEDT) Received: by mail-pj1-x102b.google.com with SMTP id jx9so17891193pjb.5 for ; Tue, 29 Mar 2022 08:50:36 -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=nVOLJb6QTwcEgAHI72cbLlI/IOugjAl6OzcnLkjMjAI=; b=DG94UFgdMfMPsSHV9HtRsqqZMdDGElfUvRwnpGP9AFlmIBEKr8SCT4kMT4vvNOZfYd 2TTjbjKs90DWuxKwF71SdKWq9yUV+qxo9I3w/66I+7I7rdAl625+yZy3CHY3s2/XRMfp lYOr2B8PDRVaArfYPUU77RuRGBRZeS/l8SQ4hGEGRvt49zRUTRjsUfeo+dwpb/9/64yu o4Xz7mg93Ad2J5W+nhK31a9qJHgwb5dyyj5zMxwqIIksQ0tKZUZNhdvPvmoXT9c+wBeV CQwkeQ2P06PKFo/PQLj6ccspSPNhx7LJYkXY7N6YNV8jQQON6CvOCDdWxhDJ0qyULUwT VHSA== 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=nVOLJb6QTwcEgAHI72cbLlI/IOugjAl6OzcnLkjMjAI=; b=0EVeCkgddgvtt/7ewoy9Lvq3EpAbrsyXzFuEVcGkh+hJPwbtSiYTyX6MJG5bp59nQk OifTprgQCj10JIaOhbAOw9zFP7XtsZ9ensF5IeUs1v11wpP8xknWP1UuO1f8RYE4R1uq lOybSm45Smd1Vfw/V3YR814KYsaqIZT6YavzBSLpnEJcx5No2NhvfgXx5wkJON+pQMMz 8r5PbpTdmuuOWW05pWkT4O16SnkNEx05cFb6rxvUxV8/HBV6HQxwtOyQv2ysSeIeysvn S3ooUYhWEoGGo1SM2tzpdB/Yevs8fzl6771qNREMunKLSVWvrWInA2CJ+Z7UzFeUK0qF OR6Q== X-Gm-Message-State: AOAM530RJBWj0RAKpdW5HAweBBpp9MiGpuHrNGE9adMmVRI8rSi4+A/q l2BFJPhPKXzgru832q04ybYT1ENQXjA= X-Google-Smtp-Source: ABdhPJxMnbhCZDPzm1enudRXVMXOdcTcbb0yGeGtlLvi94QbPux73awOe/SZepKLjalLf4Dc5/A5Ig== X-Received: by 2002:a17:90b:38d2:b0:1c7:1326:ec98 with SMTP id nn18-20020a17090b38d200b001c71326ec98mr252665pjb.18.1648569034547; Tue, 29 Mar 2022 08:50:34 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:34 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:19 +1000 Message-Id: <20220329154931.493851-27-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 26/38] gdbserver: track attn enablement by breakpoints 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" attn-enabled is a per-core property that host software (e.g., skiboot) may change. gdbserver should not disable attn if it was found to be enabled. There are still unavoidable races where the host could change between gdbserver wanting it enabled and disabled. This also moves set_attn to iterate all targets in preparation for multi-threaded debugging. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c5e439d..756feb5 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -54,6 +54,7 @@ static enum client_state state = IDLE; /* Attached to thread->gdbserver_priv */ struct gdb_thread { uint64_t pir; + bool attn_set; }; static void destroy_client(int dead_fd); @@ -116,39 +117,49 @@ static void detach(uint64_t *stack, void *priv) #define POWER10_HID_ENABLE_ATTN PPC_BIT(3) #define POWER10_HID_FLUSH_ICACHE PPC_BIT(2) -static int set_attn(bool enable) +static int thread_set_attn(struct pdbg_target *target, bool enable) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; uint64_t hid; - if (thread_getspr(thread_target, SPR_HID, &hid)) + if (!enable && !gdb_thread->attn_set) { + /* Don't clear attn if we didn't enable it */ + return 0; + } + + if (thread_getspr(target, SPR_HID, &hid)) return -1; - if (pdbg_target_compatible(thread_target, "ibm,power8-thread")) { + if (pdbg_target_compatible(target, "ibm,power8-thread")) { if (enable) { if (hid & POWER8_HID_ENABLE_ATTN) return 0; hid |= POWER8_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER8_HID_ENABLE_ATTN)) return 0; hid &= ~POWER8_HID_ENABLE_ATTN; } - } else if (pdbg_target_compatible(thread_target, "ibm,power9-thread")) { + } else if (pdbg_target_compatible(target, "ibm,power9-thread")) { if (enable) { if (hid & POWER9_HID_ENABLE_ATTN) return 0; hid |= POWER9_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER9_HID_ENABLE_ATTN)) return 0; hid &= ~POWER9_HID_ENABLE_ATTN; } hid |= POWER9_HID_FLUSH_ICACHE; - } else if (pdbg_target_compatible(thread_target, "ibm,power10-thread")) { + } else if (pdbg_target_compatible(target, "ibm,power10-thread")) { if (enable) { if (hid & POWER10_HID_ENABLE_ATTN) return 0; hid |= POWER10_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER10_HID_ENABLE_ATTN)) return 0; @@ -159,12 +170,29 @@ static int set_attn(bool enable) return -1; } - if (thread_putspr(thread_target, SPR_HID, hid)) + if (thread_putspr(target, SPR_HID, hid)) return -1; return 0; } +static int set_attn(bool enable) +{ + struct pdbg_target *target; + int err = 0; + + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + err = thread_set_attn(target, enable); + if (err) + break; + } + + return err; +} + /* 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) From patchwork Tue Mar 29 15:49:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610709 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=gxSqrC7F; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtn4tnxz9sFk for ; Wed, 30 Mar 2022 02:50:41 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtn4628z2yMS for ; Wed, 30 Mar 2022 02:50:41 +1100 (AEDT) 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=gxSqrC7F; 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::629; helo=mail-pl1-x629.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=gxSqrC7F; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 4KSYtk4B5Nz2xYG for ; Wed, 30 Mar 2022 02:50:38 +1100 (AEDT) Received: by mail-pl1-x629.google.com with SMTP id f10so7661472plr.6 for ; Tue, 29 Mar 2022 08:50:38 -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=FrBF2+umIvI0bo9y7wtc/f5f0Fv98b4j9lDcJAb1Zhs=; b=gxSqrC7F4kQNO/hgRTOnYzY66TQY6w2y7wfyTutMo0tFWkDGgqxVysSq2BpeZItdAh 1KWwshxWbPkc/5caiCgOjPwNj+OVi1p8AFMA62MW2daABfITNYY4GapxwfgQYjUE6m65 +0P+Nbf1KlxYHOj4/Lq1lY4AUhXz3HFxDnzrwWUR8WBWn3xkGQ87Np4RCUDv3iLHB0kT ZRYEBf8zvxmNzEXw3E4feA3gfSamjdnLhkFtNW9tj6sHokRGsYMiKIUDHO3fOis7HVNw 9KfU02F8zDBVCqPxQUc/w2pXe7z7kKnVgu60JO6lzV5no5qrCyyYqt414WXkb/YZyKjL fAgg== 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=FrBF2+umIvI0bo9y7wtc/f5f0Fv98b4j9lDcJAb1Zhs=; b=fOSRpB3GM4xdjSns/H0+5W+K4JKvOPvDluu55VYx3+pINGyfe+o3yTn3FPp/pAb0rR FqY0TWx/X7Nv/1S2gtqN3s4x30b4jmm8589fam4A+czSoaDuVOt09Ypfy7pk/a8E2lVQ 21iJvpplJOzvr81DCXv4Qn9XsSkHOLx4Qs4mfWdSuE87zli0zayXl6SPcrbIf6qRVX5T A9d0596oz7lCmxoMgJghYNiCyxVH1FOXszOUVw9cNVshCqDe4w2UGjv91Dp3Pi6HcLVK hxUXyqiPPM0z+7Nrr8qH2X/61lojlM5Bcwxg4q1aGQwxBDSnZWo6Oc1FCj6/jh37uUpB 6mKA== X-Gm-Message-State: AOAM530iTc1qr8KoE8KnTZ1Grh1D9QIyIn/L9JYO8Hx3nGfTFWorR0hw 6H8HvlQcWPs3mVoxdnJIDzj3Hv+V8SQ= X-Google-Smtp-Source: ABdhPJwF+u24nke15AbhMmFE+8alhKTB6L9+Taq1ZpHkXipJw0b42AqCpJIxmE2mgaJHG1lfKfSK8Q== X-Received: by 2002:a17:90a:8a05:b0:1c6:e527:c613 with SMTP id w5-20020a17090a8a0500b001c6e527c613mr207538pjn.143.1648569036513; Tue, 29 Mar 2022 08:50:36 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:36 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:20 +1000 Message-Id: <20220329154931.493851-28-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 27/38] gdbserver: implement get_thread / set_thread commands 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" Using the PIR for a thread identifier, implement get_thread and set_thread gdb commands. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 8 +- src/gdb_parser_precompile.c | 301 +++++++++++++++++++----------------- src/pdbgproxy.c | 36 ++++- src/pdbgproxy.h | 2 +- 4 files changed, 199 insertions(+), 148 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index e49d56d..dc1275c 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -106,8 +106,6 @@ stop_reason = ('?' @{cmd = STOP_REASON;}); - set_thread = ('H' any* @{cmd = SET_THREAD;}); - detach = ('D' @{cmd = DETACH;} xdigit+ $hex_digit %push); @@ -118,6 +116,10 @@ qf_threadinfo = ('qfThreadInfo' @{rsp = "m1l";}); q_start_noack = ('QStartNoAckMode' @{rsp = "OK"; send_ack(priv); ack_mode = false;}); + # thread info + get_thread = ('qC' @{cmd = GET_THREAD;}); + set_thread = ('Hg' ('p' xdigit+ '.')+ xdigit+ $hex_digit %push @{cmd = SET_THREAD;}); + # vCont packet parsing v_contq = ('vCont?' @{rsp = "vCont;c;C;s;S";}); v_contc = ('vCont;c' any* @{cmd = V_CONTC;}); @@ -126,7 +128,7 @@ interrupt = (3 @{ if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");}); - commands = (get_mem | get_gprs | get_spr | stop_reason | set_thread | + commands = (get_mem | get_gprs | get_spr | stop_reason | get_thread | set_thread | q_attached | q_C | q_supported | qf_threadinfo | q_C | q_start_noack | v_contq | v_contc | v_conts | put_mem | detach | unknown ); diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index ba63fac..f09c0f9 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -11,7 +11,7 @@ #include "debug.h" -#line 143 "src/gdb_parser.rl" +#line 145 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -31,29 +31,30 @@ static bool ack_mode = true; #line 32 "src/gdb_parser.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 16, 1, 22, 1, 23, 1, - 24, 1, 25, 2, 0, 1, 2, 2, + 3, 1, 15, 1, 23, 1, 24, 1, + 25, 1, 26, 2, 0, 1, 2, 2, 1, 2, 3, 1, 2, 3, 5, 2, - 4, 1, 2, 12, 1, 2, 14, 1, - 2, 15, 1, 2, 16, 1, 2, 17, - 1, 2, 18, 1, 2, 19, 1, 2, - 20, 1, 2, 21, 1, 3, 0, 6, - 1, 3, 0, 7, 1, 3, 0, 9, - 1, 3, 0, 10, 1, 3, 0, 11, - 1, 3, 0, 13, 1, 3, 2, 8, - 1 + 4, 1, 2, 13, 1, 2, 15, 1, + 2, 16, 1, 2, 17, 1, 2, 20, + 1, 2, 21, 1, 2, 22, 1, 3, + 0, 6, 1, 3, 0, 7, 1, 3, + 0, 9, 1, 3, 0, 10, 1, 3, + 0, 11, 1, 3, 0, 12, 1, 3, + 2, 8, 1, 3, 3, 19, 1, 3, + 18, 14, 1 }; static const unsigned char _gdb_key_offsets[] = { 0, 0, 11, 12, 18, 24, 31, 38, - 39, 46, 54, 61, 69, 76, 78, 80, - 82, 84, 86, 88, 90, 92, 94, 96, - 98, 100, 102, 104, 111, 119, 124, 126, - 128, 130, 132, 134, 136, 138, 140, 147, - 149, 151, 153, 155, 157, 159, 161, 163, - 165, 166, 168, 170, 172, 174, 176, 178, - 180, 182, 184, 186, 188, 190, 192, 194, - 197, 200, 201, 202 + 40, 42, 49, 57, 65, 72, 79, 87, + 94, 102, 109, 111, 113, 115, 117, 119, + 121, 123, 125, 127, 129, 131, 133, 135, + 137, 144, 152, 157, 159, 161, 163, 165, + 167, 169, 171, 173, 180, 182, 184, 186, + 188, 190, 192, 194, 196, 198, 199, 201, + 203, 205, 207, 209, 211, 213, 215, 217, + 219, 221, 223, 225, 227, 230, 233, 234, + 235 }; static const char _gdb_trans_keys[] = { @@ -61,64 +62,71 @@ static const char _gdb_trans_keys[] = { 112, 113, 118, 35, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, - 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, 58, 48, - 57, 65, 70, 97, 102, 35, 48, 57, - 65, 70, 97, 102, 35, 83, 35, 116, - 35, 97, 35, 114, 35, 116, 35, 78, - 35, 111, 35, 65, 35, 99, 35, 107, - 35, 77, 35, 111, 35, 100, 35, 101, + 48, 57, 65, 70, 97, 102, 35, 103, + 35, 112, 35, 48, 57, 65, 70, 97, + 102, 35, 46, 48, 57, 65, 70, 97, + 102, 35, 112, 48, 57, 65, 70, 97, + 102, 35, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, 44, 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, 43, 45, 0 + 48, 57, 65, 70, 97, 102, 35, 58, + 48, 57, 65, 70, 97, 102, 35, 48, + 57, 65, 70, 97, 102, 35, 83, 35, + 116, 35, 97, 35, 114, 35, 116, 35, + 78, 35, 111, 35, 65, 35, 99, 35, + 107, 35, 77, 35, 111, 35, 100, 35, + 101, 35, 48, 57, 65, 70, 97, 102, + 35, 44, 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, 43, 45, 0 }; static const char _gdb_single_lengths[] = { - 0, 11, 1, 0, 0, 1, 1, 1, - 1, 2, 1, 2, 1, 2, 2, 2, + 0, 11, 1, 0, 0, 1, 1, 2, + 2, 1, 2, 2, 1, 1, 2, 1, + 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 1, 2, 5, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, + 1, 2, 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, - 1, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 3, - 3, 1, 1, 4 + 2, 2, 2, 2, 3, 3, 1, 1, + 4 }; static const char _gdb_range_lengths[] = { 0, 0, 0, 3, 3, 3, 3, 0, - 3, 3, 3, 3, 3, 0, 0, 0, + 0, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 3, 3, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 3, 0, + 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, 0, 0 + 0 }; static const short _gdb_index_offsets[] = { 0, 0, 12, 14, 18, 22, 27, 32, - 34, 39, 45, 50, 56, 61, 64, 67, - 70, 73, 76, 79, 82, 85, 88, 91, - 94, 97, 100, 103, 108, 114, 120, 123, - 126, 129, 132, 135, 138, 141, 144, 149, - 152, 155, 158, 161, 164, 167, 170, 173, - 176, 178, 181, 184, 187, 190, 193, 196, - 199, 202, 205, 208, 211, 214, 217, 220, - 224, 228, 230, 232 + 35, 38, 43, 49, 55, 60, 65, 71, + 76, 82, 87, 90, 93, 96, 99, 102, + 105, 108, 111, 114, 117, 120, 123, 126, + 129, 134, 140, 146, 149, 152, 155, 158, + 161, 164, 167, 170, 175, 178, 181, 184, + 187, 190, 193, 196, 199, 202, 204, 207, + 210, 213, 216, 219, 222, 225, 228, 231, + 234, 237, 240, 243, 246, 250, 254, 256, + 258 }; static const char _gdb_indicies[] = { @@ -126,82 +134,85 @@ static const char _gdb_indicies[] = { 9, 10, 11, 0, 13, 12, 14, 14, 14, 15, 16, 16, 16, 15, 13, 17, 17, 17, 12, 18, 17, 17, 17, 12, - 13, 19, 13, 20, 20, 20, 12, 13, - 21, 20, 20, 20, 12, 13, 22, 22, - 22, 12, 13, 23, 22, 22, 22, 12, - 13, 24, 24, 24, 12, 13, 25, 12, - 13, 26, 12, 13, 27, 12, 13, 28, - 12, 13, 29, 12, 13, 30, 12, 13, - 31, 12, 13, 32, 12, 13, 33, 12, - 13, 34, 12, 13, 35, 12, 13, 36, - 12, 13, 37, 12, 13, 38, 12, 13, - 39, 39, 39, 12, 13, 40, 39, 39, - 39, 12, 13, 41, 42, 43, 44, 12, - 13, 45, 12, 13, 46, 12, 13, 47, - 12, 13, 48, 12, 13, 49, 12, 13, - 50, 12, 13, 51, 12, 13, 52, 12, - 13, 53, 53, 53, 12, 13, 54, 12, - 13, 55, 12, 13, 56, 12, 13, 57, - 12, 13, 58, 12, 13, 59, 12, 13, - 60, 12, 13, 61, 12, 13, 62, 12, - 64, 63, 13, 65, 12, 13, 66, 12, - 13, 67, 12, 13, 68, 12, 13, 69, - 12, 13, 70, 12, 13, 71, 12, 13, - 72, 12, 13, 73, 12, 13, 74, 12, - 13, 75, 12, 13, 76, 12, 13, 77, - 12, 13, 78, 12, 13, 79, 80, 12, - 13, 81, 82, 12, 13, 83, 13, 84, - 85, 86, 87, 88, 15, 0 + 13, 19, 12, 13, 20, 12, 13, 21, + 21, 21, 12, 13, 22, 21, 21, 21, + 12, 13, 20, 23, 23, 23, 12, 18, + 23, 23, 23, 12, 13, 24, 24, 24, + 12, 13, 25, 24, 24, 24, 12, 13, + 26, 26, 26, 12, 13, 27, 26, 26, + 26, 12, 13, 28, 28, 28, 12, 13, + 29, 12, 13, 30, 12, 13, 31, 12, + 13, 32, 12, 13, 33, 12, 13, 34, + 12, 13, 35, 12, 13, 36, 12, 13, + 37, 12, 13, 38, 12, 13, 39, 12, + 13, 40, 12, 13, 41, 12, 13, 42, + 12, 13, 43, 43, 43, 12, 13, 44, + 43, 43, 43, 12, 13, 45, 46, 47, + 48, 12, 13, 49, 12, 13, 50, 12, + 13, 51, 12, 13, 52, 12, 13, 53, + 12, 13, 54, 12, 13, 55, 12, 13, + 56, 12, 13, 57, 57, 57, 12, 13, + 58, 12, 13, 59, 12, 13, 60, 12, + 13, 61, 12, 13, 62, 12, 13, 63, + 12, 13, 64, 12, 13, 65, 12, 13, + 66, 12, 68, 67, 13, 69, 12, 13, + 70, 12, 13, 71, 12, 13, 72, 12, + 13, 73, 12, 13, 74, 12, 13, 75, + 12, 13, 76, 12, 13, 77, 12, 13, + 78, 12, 13, 79, 12, 13, 80, 12, + 13, 81, 12, 13, 82, 12, 13, 83, + 84, 12, 13, 85, 86, 12, 13, 87, + 13, 88, 89, 90, 91, 92, 15, 0 }; static const char _gdb_trans_targs[] = { - 2, 3, 2, 5, 7, 8, 13, 2, - 27, 5, 29, 59, 2, 3, 4, 0, - 67, 6, 3, 7, 9, 10, 11, 12, - 12, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 2, 28, - 5, 30, 2, 39, 49, 31, 32, 33, - 34, 35, 36, 37, 38, 38, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 2, - 3, 50, 51, 52, 53, 54, 55, 56, - 57, 58, 2, 60, 61, 62, 63, 64, - 2, 65, 66, 65, 66, 67, 1, 67, - 67 + 2, 3, 2, 5, 7, 13, 18, 2, + 32, 5, 34, 64, 2, 3, 4, 0, + 72, 6, 3, 8, 9, 10, 11, 12, + 14, 15, 16, 17, 17, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 2, 33, 5, 35, 2, 44, + 54, 36, 37, 38, 39, 40, 41, 42, + 43, 43, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 2, 3, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 2, 65, + 66, 67, 68, 69, 2, 70, 71, 70, + 71, 72, 1, 72, 72 }; static const char _gdb_trans_actions[] = { - 19, 1, 77, 81, 19, 65, 19, 69, - 61, 73, 19, 19, 3, 0, 7, 0, - 28, 25, 5, 34, 25, 22, 25, 85, - 31, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 49, 25, - 22, 3, 40, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 37, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 43, - 9, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 46, 3, 3, 3, 3, 3, - 52, 3, 3, 55, 58, 11, 13, 15, - 17 + 19, 1, 71, 75, 19, 59, 19, 63, + 55, 67, 19, 19, 3, 0, 7, 0, + 28, 25, 5, 3, 3, 3, 3, 83, + 25, 22, 25, 79, 31, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 43, 25, 22, 3, 87, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 34, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 37, 9, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 40, 3, + 3, 3, 3, 3, 46, 3, 3, 49, + 52, 11, 13, 15, 17 }; -static const int gdb_start = 67; -static const int gdb_first_final = 67; +static const int gdb_start = 72; +static const int gdb_first_final = 72; static const int gdb_error = 0; -static const int gdb_en_main = 67; +static const int gdb_en_main = 72; -#line 159 "src/gdb_parser.rl" +#line 161 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 200 "src/gdb_parser.c" +#line 211 "src/gdb_parser.c" { cs = gdb_start; } -#line 163 "src/gdb_parser.rl" +#line 165 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -212,7 +223,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len; -#line 216 "src/gdb_parser.c" +#line 227 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -399,61 +410,65 @@ _match: break; case 12: #line 109 "src/gdb_parser.rl" - {cmd = SET_THREAD;} + {cmd = DETACH;} break; case 13: -#line 111 "src/gdb_parser.rl" - {cmd = DETACH;} +#line 113 "src/gdb_parser.rl" + {rsp = "1";} break; case 14: -#line 115 "src/gdb_parser.rl" - {rsp = "1";} +#line 114 "src/gdb_parser.rl" + {rsp = "QC1";} break; case 15: -#line 116 "src/gdb_parser.rl" - {rsp = "QC1";} +#line 115 "src/gdb_parser.rl" + {rsp = "multiprocess+;vContSupported+;QStartNoAckMode+"; ack_mode = true;} break; case 16: -#line 117 "src/gdb_parser.rl" - {rsp = "multiprocess+;vContSupported+;QStartNoAckMode+"; ack_mode = true;} +#line 116 "src/gdb_parser.rl" + {rsp = "m1l";} break; case 17: -#line 118 "src/gdb_parser.rl" - {rsp = "m1l";} +#line 117 "src/gdb_parser.rl" + {rsp = "OK"; send_ack(priv); ack_mode = false;} break; case 18: -#line 119 "src/gdb_parser.rl" - {rsp = "OK"; send_ack(priv); ack_mode = false;} +#line 120 "src/gdb_parser.rl" + {cmd = GET_THREAD;} break; case 19: -#line 122 "src/gdb_parser.rl" - {rsp = "vCont;c;C;s;S";} +#line 121 "src/gdb_parser.rl" + {cmd = SET_THREAD;} break; case 20: -#line 123 "src/gdb_parser.rl" - {cmd = V_CONTC;} +#line 124 "src/gdb_parser.rl" + {rsp = "vCont;c;C;s;S";} break; case 21: -#line 124 "src/gdb_parser.rl" - {cmd = V_CONTS;} +#line 125 "src/gdb_parser.rl" + {cmd = V_CONTC;} break; case 22: -#line 127 "src/gdb_parser.rl" - { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} +#line 126 "src/gdb_parser.rl" + {cmd = V_CONTS;} break; case 23: -#line 135 "src/gdb_parser.rl" - {PR_INFO("RAGEL:cmd\n");} +#line 129 "src/gdb_parser.rl" + { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; case 24: -#line 138 "src/gdb_parser.rl" - {PR_INFO("RAGEL:ack\n");} +#line 137 "src/gdb_parser.rl" + {PR_INFO("RAGEL:cmd\n");} break; case 25: -#line 139 "src/gdb_parser.rl" +#line 140 "src/gdb_parser.rl" + {PR_INFO("RAGEL:ack\n");} + break; + case 26: +#line 141 "src/gdb_parser.rl" {PR_INFO("RAGEL:nack\n");} break; -#line 457 "src/gdb_parser.c" +#line 472 "src/gdb_parser.c" } } @@ -466,7 +481,7 @@ _again: _out: {} } -#line 173 "src/gdb_parser.rl" +#line 175 "src/gdb_parser.rl" if (cs == gdb_error) { printf("parse error\n"); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 756feb5..1d33352 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -93,9 +93,42 @@ void send_ack(void *priv) send(fd, ACK, 1, 0); } +static void get_thread(uint64_t *stack, void *priv) +{ + struct thread *thread = target_to_thread(thread_target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + char data[3+4+2+1]; /* 'QCp' + 4 hex digits + '.0' + NUL */ + + snprintf(data, sizeof(data), "QC%04" PRIx64, gdb_thread->pir); + + PR_INFO("get_thread pir=%llx\n", gdb_thread->pir); + + send_response(fd, data); +} + static void set_thread(uint64_t *stack, void *priv) { - send_response(fd, OK); + struct pdbg_target *target; + uint64_t pir = stack[0]; + + PR_INFO("set_thread pir=%llx\n", pir); + + 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->pir == pir) { + thread_target = target; + send_response(fd, OK); + return; + } + } + send_response(fd, ERROR(EEXIST)); } static void stop_reason(uint64_t *stack, void *priv) @@ -684,6 +717,7 @@ static command_cb callbacks[LAST_CMD + 1] = { get_spr, get_mem, stop_reason, + get_thread, set_thread, v_contc, v_conts, diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h index 1910fdb..2005083 100644 --- a/src/pdbgproxy.h +++ b/src/pdbgproxy.h @@ -2,7 +2,7 @@ #define __PDBGPROXY_H enum gdb_command {NONE, GET_GPRS, GET_SPR, GET_MEM, - STOP_REASON, SET_THREAD, V_CONTC, V_CONTS, + STOP_REASON, GET_THREAD, SET_THREAD, V_CONTC, V_CONTS, PUT_MEM, INTERRUPT, DETACH, LAST_CMD}; typedef void (*command_cb)(uint64_t *stack, void *priv); From patchwork Tue Mar 29 15:49:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610710 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=DBRVe348; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtp5jNZz9sFk for ; Wed, 30 Mar 2022 02:50:42 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtp5JYSz2xvv for ; Wed, 30 Mar 2022 02:50:42 +1100 (AEDT) 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=DBRVe348; 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::1030; helo=mail-pj1-x1030.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=DBRVe348; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 4KSYtm1xd6z2xYG for ; Wed, 30 Mar 2022 02:50:40 +1100 (AEDT) Received: by mail-pj1-x1030.google.com with SMTP id c15-20020a17090a8d0f00b001c9c81d9648so3301075pjo.2 for ; Tue, 29 Mar 2022 08:50:40 -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=Ysa/KajnIhWbb/5x6hOkJWcBzofCOl4nfc6EudIC/H0=; b=DBRVe348O9Je0EQE+tu8s0KICu0QtxKnzjY+SUKF3yagOn146BPq1fZ/tkBTaX6gr/ 0PWfLWd4qfrbI7cgh8EWzbHGizMqDNomypHN/NU2L12ZzfcZ/PWxzQoTvFbSmCBhGCIa YK2kP93zL92HZzcRUxLLPdZOj/BjkVANufD5DwfpzkDqoh4khJlQFHm0ZrexfbQTjWBv Au4oL/N2M347o9fgurXLXS3kaVQQyBl904MJ3fY0f16BW4jvHhX1WlE1ajrZtRLNVU9j pxCM3pKsO5B5HFxquTO9Bv65bEWR02MOaEK7hz2Jad/V0ynq2Og1tMQheLnAY39jtnI3 FDzA== 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=Ysa/KajnIhWbb/5x6hOkJWcBzofCOl4nfc6EudIC/H0=; b=GAEtFsKk4aSXTx3q3CQLNTs2t8TK9FxVzkc1sEHYzgAXuY0yVL8WEu6y4kq8dFnlfb EDU0uGybjj3vSyCIFxaOKsqlVYy/BlfwD9VKfKXhHNcJxSgyH4Kyid82tfdUfhUoEmWh ETP1qBdZ8cD72vt0dD9wmnUngrdidBcqvlpF/ARwslkwaPhnF/kRNS8oeYxDpuuuNUTR luo+2vUHCqLzAiM9PVC+Y9QzTXMSjhajF55xugMw/lXEy7C0WD7Cr5qvBB2TQ71JN+UO WkdnbJwjGpjwPieF+rF35QDatpYA0HXqF+k0asX+6P5VdcHA5zLW3fZBJJD0AXKm/cKi p0DQ== X-Gm-Message-State: AOAM532/riFjlpm4lpRFoW97J1/pl4iA9K6Hh8bhF4lIOxdzFn7jJ7MJ hPxSDkciqX9sQd3tqEhhdPLWp5YcY4o= X-Google-Smtp-Source: ABdhPJyZh31iufvukPM8D3wX0AFyKG5deKRm+0XFjZtr4yVmvWwggff1ymQNmSuwGlWzT9hLpHT6eg== X-Received: by 2002:a17:902:e551:b0:154:48d5:4210 with SMTP id n17-20020a170902e55100b0015448d54210mr31123722plf.2.1648569038440; Tue, 29 Mar 2022 08:50:38 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:38 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:21 +1000 Message-Id: <20220329154931.493851-29-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 28/38] gdbserver: add multi-threaded start/stop helper functions 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" Prepare for multi threaded debugging (in gdb's "all-stop" mode) by providing helpers that stop and start all target threads. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1d33352..139b29e 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -43,6 +43,7 @@ #define TEST_SKIBOOT_ADDR 0x40000000 +static bool all_stopped = true; /* must be started with targets stopped */ static struct pdbg_target *thread_target = NULL; static struct pdbg_target *adu_target; static struct timeval timeout; @@ -542,10 +543,50 @@ static void v_conts(uint64_t *stack, void *priv) send_response(fd, TRAP); } +static void __start_all(void) +{ + struct pdbg_target *target; + + if (!all_stopped) + PR_ERROR("starting while not all stopped\n"); + + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + + all_stopped = false; +} + +static void start_all(void) +{ + struct pdbg_target *target; + + for_each_path_target_class("thread", target) { + struct thread_state status; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + target->probe(target); + status = thread_status(target); + if (!status.quiesced) + PR_ERROR("starting thread not quiesced\n"); + } + + __start_all(); +} + #define VCONT_POLL_DELAY 100000 static void v_contc(uint64_t *stack, void *priv) { - thread_start(thread_target); + start_all(); + state = SIGNAL_WAIT; poll_interval = 1; } @@ -603,13 +644,55 @@ static bool thread_check_attn(struct pdbg_target *target) return false; } +static void __stop_all(void) +{ + struct pdbg_target *target; + + if (all_stopped) + PR_ERROR("stopping while all stopped\n"); + + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (thread_stop(target)) { + PR_ERROR("Could not stop thread %s\n", + pdbg_target_path(target)); + /* How to fix? */ + } + } + + all_stopped = true; +} + +static void stop_all(void) +{ + struct pdbg_target *target; + + __stop_all(); + + for_each_path_target_class("thread", target) { + struct thread_state status; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + target->probe(target); + status = thread_status(target); + if (!status.quiesced) { + PR_ERROR("Could not quiesce thread\n"); + /* How to fix? */ + } + } +} + static void interrupt(uint64_t *stack, void *priv) { struct thread_state status; PR_INFO("Interrupt from gdb client\n"); - thread_stop(thread_target); + stop_all(); status = thread_status(thread_target); if (!(status.quiesced)) { From patchwork Tue Mar 29 15:49:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610711 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=QqE7s5qH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtr5x3wz9sFk for ; Wed, 30 Mar 2022 02:50:44 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtr5Rwrz2xBK for ; Wed, 30 Mar 2022 02:50:44 +1100 (AEDT) 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=QqE7s5qH; 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::62a; helo=mail-pl1-x62a.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=QqE7s5qH; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 4KSYtp19cpz2yJQ for ; Wed, 30 Mar 2022 02:50:42 +1100 (AEDT) Received: by mail-pl1-x62a.google.com with SMTP id i11so18039780plr.1 for ; Tue, 29 Mar 2022 08:50:42 -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=oZpMib/GIUYvVKRjtCGrdWvB2vEcG8hIKKgZ+PcM9jI=; b=QqE7s5qHAsotFIHEaTJWiJRBDpu+CFJkl9EOA/UBFsocX1zOJVUt9B+ySe6pMTxN6A FKIqM1ksdlAAl+HM26ODHkzfKQvnFv7iC0wFjN9POdR7f9kGP/FKAQNApQX86NqZ9kgV VLT2+1G+axIwqZRcZOU78sR9urwIETaAQC7uovMsut9RaZ0+f61HDPpgsPdwUOe1Ssju zJdQa79mcRqX0hL8AMCk6V0D9tdAZjAZnyN/rT7kQsV0DJFf5GkXIN04y2ArEQAiu7kg fpEFCw/4Qz/c1Z+pjZiNyuROcwYi8ZDpqqzF/E12Rru21lm+3FKD9U4bjpiIUajY5vHa b2UQ== 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=oZpMib/GIUYvVKRjtCGrdWvB2vEcG8hIKKgZ+PcM9jI=; b=LtPkDB0UeuC2UK/9CYI5OaJ32jVDj9dgNqDaeQ+MaT8Witw0EJw2Ko4dqQjR6egpsf bqDxEHJ0KqXdERyg21lercg9V7TKN+QQp2V/oIcdKVx4aoeItOxTSolsqnueEb0s+HNi kYiMmlbBPIxDpr4RXyqInw68WwlC2zLoZDNSrvPKbW3SVwhtoxj3ffPkKfBqVKCpHld/ ZVGz0BnA0vYXku5Ni9DM3kg2Gnx3kKJAsh9kk55wmi2PooVkocylomyttPrZriUZ+ohy mHYQ9d4cQI5utYs43N90Zp4QMgK1zs35ubYzx9gZhZbqV+6zRi7vDpUKATontq1Ztbov qH/A== X-Gm-Message-State: AOAM530ApAygxsMMKzc7rXobBhLpjI6siDCw8nghfiZDLEl58YkeYhLr 7WSx4KRztKK77HrVfRY38Sb2wZ2BPv4= X-Google-Smtp-Source: ABdhPJwqzu+1eak9Efov0jRILxwVqcjOa01LtcAxD6R1E1cK27ygZfA8Xlwy1jZDP/LkZ3HjfTc7cA== X-Received: by 2002:a17:902:c944:b0:154:38b8:aa46 with SMTP id i4-20020a170902c94400b0015438b8aa46mr31211039pla.144.1648569040389; Tue, 29 Mar 2022 08:50:40 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:40 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:22 +1000 Message-Id: <20220329154931.493851-30-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 29/38] gdbserver: tidy poll() 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" Remove the pointless case statement and reduce indentation. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 139b29e..d34a64e 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -708,40 +708,36 @@ static void poll(void) { struct thread_state status; + if (state != SIGNAL_WAIT) + return; + thread_target->probe(thread_target); status = thread_status(thread_target); - switch (state) { - case IDLE: - break; - - case SIGNAL_WAIT: - if (!(status.quiesced)) - break; - - set_attn(false); + if (!(status.quiesced)) + return; - state = IDLE; - poll_interval = VCONT_POLL_DELAY; + set_attn(false); - if (thread_check_attn(thread_target)) { - uint64_t nia; + state = IDLE; + poll_interval = VCONT_POLL_DELAY; - if (!(status.active)) { - PR_ERROR("Thread inactive after trap\n"); - send_response(fd, ERROR(EPERM)); - return; - } + if (thread_check_attn(thread_target)) { + uint64_t nia; - /* Restore NIA */ - if (thread_getnia(thread_target, &nia)) - PR_ERROR("Error during getnia\n"); - if (thread_putnia(thread_target, nia - 4)) - PR_ERROR("Error during putnia\n"); + if (!(status.active)) { + PR_ERROR("Thread inactive after trap\n"); + send_response(fd, ERROR(EPERM)); + return; } - send_response(fd, TRAP); - break; + + /* Restore NIA */ + if (thread_getnia(thread_target, &nia)) + PR_ERROR("Error during getnia\n"); + if (thread_putnia(thread_target, nia - 4)) + PR_ERROR("Error during putnia\n"); } + send_response(fd, TRAP); } static void cmd_default(uint64_t *stack, void *priv) From patchwork Tue Mar 29 15:49:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610712 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=QbD06s6y; 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 4KSYtv6TPkz9sFk for ; Wed, 30 Mar 2022 02:50:47 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtv5m1sz2xr9 for ; Wed, 30 Mar 2022 02:50:47 +1100 (AEDT) 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=QbD06s6y; 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::102a; helo=mail-pj1-x102a.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=QbD06s6y; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 4KSYts2NZ9z2yJ9 for ; Wed, 30 Mar 2022 02:50:45 +1100 (AEDT) Received: by mail-pj1-x102a.google.com with SMTP id c15-20020a17090a8d0f00b001c9c81d9648so3301345pjo.2 for ; Tue, 29 Mar 2022 08:50:45 -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=8wAjPBSNENfkBg+ko5FEz/wanvCvKHmRg3z9TEbSaOg=; b=QbD06s6yfr186NXUp6QLaO3F26F3euEQBHbzmz3Wj0jBSXevN9QxVSukwtCqJajwtG btiEIhXiFXaKwMHpPvWqFinl7f2D5xpJA+Wj0o1Eor1bPf+mrkV5XTBVTejfsrLBUaIV THtqxp6clc7C7oTKGYboLYIZ/mgccgsCxg0w9NIsnNYufIxyJ34zoe0/GUeWE8eu6NvN 3EY/vykGFd4o3glZ5nifkqb0GdCl2oTvtA7BZNbutbEg0LgfPCIZ3iik1GlZB+wdf8Kc iFEh7Dk6hg3nMx1E52LLK0wN3E563n5n8tnYUeDxhE56oKgdy58pzmDEBd/NhTlOgwJw YZZQ== 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=8wAjPBSNENfkBg+ko5FEz/wanvCvKHmRg3z9TEbSaOg=; b=EwppL0zw6iGc9f8GDTCx3WvVzYV8+bszEhqQRE/66jxfFYmxOgmghf1M8HMrVhGtLP OLaMwdH0o0JgZtxnUNiMxgberXQ+gEYqH7myx0Lf6MpbYgy3ZQguz24CWJRpuN2accKD 04s5czQe2NdOxwUCHA7kSgVOySECw4x8s9vWGrAsoVE3hiQm82xfhSEqIm+zN/1FbOdK rNUfrfMqefWlB4mTsoyp+eYIjrH5KH/o2UGRlE5qNcnmqFv8vVembHncYYF85ebmLTBy 1XgY2+z5bZ/RbJyM0cabhqOvyIQtfR6F2DMZilxiljt+o+qxsKZuawsQAm8rVvGOpPPQ YYEQ== X-Gm-Message-State: AOAM532pr6o3WPIjMjJMy+J2QXsJZPx4Y0FccgyY9gUYlNNa/FtURg7/ 6UqoBWKu3AybGrvw32lCuq+C2v3imLo= X-Google-Smtp-Source: ABdhPJx6ycoUSPoGCC3BcIdH2VafMtUEiNcCU3FD8yyDOujG5vGABoObP/3FBug9vxFo2Wmu/iydow== X-Received: by 2002:a17:902:c242:b0:154:4f3f:ec6a with SMTP id 2-20020a170902c24200b001544f3fec6amr30476637plg.121.1648569042293; Tue, 29 Mar 2022 08:50:42 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:42 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:23 +1000 Message-Id: <20220329154931.493851-31-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 30/38] gdbserver: multi-thread polling and stop-reason 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" Rework poll() and the stop reason code to support multi-threaded debugging. - Make poll() iterate over all target threads to check whether any are stopped. - If any are found stopped, stop the rest. Poll SPATTN for all target threads. This provides the basis for "all-stop" threaded debugging mode, which is what seems to work best for bare metal debugging. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index d34a64e..db80b6a 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -683,60 +683,73 @@ static void stop_all(void) PR_ERROR("Could not quiesce thread\n"); /* How to fix? */ } + + if (thread_check_attn(target)) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + uint64_t nia; + + PR_INFO("thread pir=%llx hit attn\n", gdb_thread->pir); + + if (!(status.active)) + PR_ERROR("Error thread inactive after trap\n"); + /* Restore NIA to before break */ + if (thread_getnia(target, &nia)) + PR_ERROR("Error during getnia\n"); + if (thread_putnia(target, nia - 4)) + PR_ERROR("Error during putnia\n"); + } } } static void interrupt(uint64_t *stack, void *priv) { - struct thread_state status; - PR_INFO("Interrupt from gdb client\n"); + if (state != IDLE) { + stop_all(); - stop_all(); - - status = thread_status(thread_target); - if (!(status.quiesced)) { - PR_ERROR("Could not quiesce thread\n"); - return; + state = IDLE; + poll_interval = VCONT_POLL_DELAY; } - state = IDLE; - poll_interval = VCONT_POLL_DELAY; + send_response(fd, TRAP); } -static void poll(void) +static bool poll_threads(void) { - struct thread_state status; + struct pdbg_target *target; + + for_each_path_target_class("thread", target) { + struct thread_state status; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + target->probe(target); + status = thread_status(target); + if (status.quiesced) + return true; + } + return false; +} + +static void poll(void) +{ if (state != SIGNAL_WAIT) return; - thread_target->probe(thread_target); - status = thread_status(thread_target); - - if (!(status.quiesced)) + if (!poll_threads()) return; + /* Something hit a breakpoint */ + + stop_all(); + set_attn(false); state = IDLE; poll_interval = VCONT_POLL_DELAY; - if (thread_check_attn(thread_target)) { - uint64_t nia; - - if (!(status.active)) { - PR_ERROR("Thread inactive after trap\n"); - send_response(fd, ERROR(EPERM)); - return; - } - - /* Restore NIA */ - if (thread_getnia(thread_target, &nia)) - PR_ERROR("Error during getnia\n"); - if (thread_putnia(thread_target, nia - 4)) - PR_ERROR("Error during putnia\n"); - } send_response(fd, TRAP); } From patchwork Tue Mar 29 15:49:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610713 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=TZVdfCxQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtx09P5z9sFk for ; Wed, 30 Mar 2022 02:50:49 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtw684Sz2xYG for ; Wed, 30 Mar 2022 02:50:48 +1100 (AEDT) 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=TZVdfCxQ; 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::52b; helo=mail-pg1-x52b.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=TZVdfCxQ; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 4KSYtt20z7z2xtQ for ; Wed, 30 Mar 2022 02:50:46 +1100 (AEDT) Received: by mail-pg1-x52b.google.com with SMTP id s72so15178325pgc.5 for ; Tue, 29 Mar 2022 08:50:46 -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=WkQDCZr0hQ7FvYlKGJb/dzUOSXDXmSxeADLgh10rnFg=; b=TZVdfCxQB9wPDDVUBN0btwsRZxBgif6LL56MvcnpvjWWA7EHwHsWsrC/LSvtv4Pb0Q uyU4Y+mnz4a3A5ugKycUYxVTYjQxatBPcOkT5H6RfjRISM8C9cvoeGm+WrZB6/hCk6i8 CLEuDgY0t5V4vIDMoPBrHev0rr6emWK4S9NeJ394azToob2VYfVVW7wBxOzsfl2f+aLH qsdVvikY55VJcHyE5vYLlgDo/kI090svgbrV4zT6uRtD7rgu7OxVoMVEiiEnbb5A+QfH VDsyedJ0Yn77qJJC73jVNrLn8xmcfDRdCYY64Osvi6Kj1pOIe/46YaSOp3GSeZFcn1pB wlvw== 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=WkQDCZr0hQ7FvYlKGJb/dzUOSXDXmSxeADLgh10rnFg=; b=0ytPtNOTtGAllfM2V274wVNWo4ezbwDH0UKoaFn6pWmVP3FDopjZp0uV8C9HSE0/BD s6k23P8BXBwION1X02dxTws6MZnhFcHRbnzmUsMKoOj/MyVeWd44wL7pccDgTjY/c5mH DoyWLfucj2NZfDHEL/HPeW+20H9vs8/pqU/8a+447dfAdiUyNdKa7H8Jxr0vO0NO1UKC KamWwoZTc+Isc3VGCK34RFiCQdMVKRDqnzP1yvvRExHRFHA0dgLjZ5yTrfbXyd0xzN5e 7KpTSq+K438To7WNAqnlwzTGmZZ3Rg/V/Cvjku/E01OCC/zZQ6gCp9Xbaq7aSe9z/brJ 99DQ== X-Gm-Message-State: AOAM531xF0FBcCTs0QdoFgvZ/y2SiBnCruPfmNQTPN7v2cToobuoyhMa DdqhGrixqdN7LlI3wMado4mMaqdbdU4= X-Google-Smtp-Source: ABdhPJxOj1im9mwz0ih0zdJZ5UMrK0Kok89hlQpnzyThUytUOoP/e8FTG673KdjiZcRqRXyFR77peg== X-Received: by 2002:a63:3d4b:0:b0:386:322:ff8c with SMTP id k72-20020a633d4b000000b003860322ff8cmr2460503pga.385.1648569044253; Tue, 29 Mar 2022 08:50:44 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:44 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:24 +1000 Message-Id: <20220329154931.493851-32-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 31/38] 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 db80b6a..fca728f 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=%llx 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) From patchwork Tue Mar 29 15:49:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610714 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=ApQiNGdr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtz0Sm9z9sFk for ; Wed, 30 Mar 2022 02:50:51 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYty6SYrz2yHt for ; Wed, 30 Mar 2022 02:50:50 +1100 (AEDT) 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=ApQiNGdr; 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::62b; helo=mail-pl1-x62b.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=ApQiNGdr; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 4KSYtw4Dxfz2xYG for ; Wed, 30 Mar 2022 02:50:48 +1100 (AEDT) Received: by mail-pl1-x62b.google.com with SMTP id y6so15467161plg.2 for ; Tue, 29 Mar 2022 08:50:48 -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=2/5aih4LMSMGbN41IByqkg1G2HQLtnOsRqu27ZcmeoE=; b=ApQiNGdrgDLCmhpDRPugfxQm8WUMA57rC9FFnmZHcGtWqg0TgJQy7myUx/ZfocpLZY yLU6Jirp8/7r2r+vzQX7pUwIVbRufyXajSm47OmSwqNz/yJ+MQsz4NTnJL8gfVMWI0Be AaET8ZZ6cGcb6uRtUqKFRKQhJhiyNUIFUXd9Lo1HCsBuoRjRdz+r2IiPiFZy1YEAi2j0 D7i4q7Et9dSgiWhgdRWfmhgigNAUgd1i5kTZr/aAOrxnTBWDcslHkI+JbA659xDq1TpU jx1smtv9wmTGDOETHJUMvMMncHmV+SeAROe2MGHJsArSDl2lBemdZNGrhmwCVVxL0F8Z 9TPA== 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=2/5aih4LMSMGbN41IByqkg1G2HQLtnOsRqu27ZcmeoE=; b=awSgxFj6dFuO31NSR17BWCqp3otU1pj3XbSRKWe5dW6SxI/a9XPgveL4clJpzoMPGt 21+jmZZtloFQu8zhfUK5EWbwJpb6kEo+RUxIJzzwKYPkEcYKcF3u+QGknNzCJgqlW3TY Phsqon2mr7p/9WqmwJC4sMGLSp88sOvBWaoX4dg42fk4AZiqmlkOPZXxkOOwrT/MdEFF wSSRfQi5mDzBNtkCMo4G8peCyIL524Jc0y9fVMYonFsLTcpM/x1ODLWu23mF3SuvapwN QuQvgz/dYzYyMmaPtpil0lNTU2mc1aQ83/dBs9qhgBVMGcHqauivHYUhU7YK6ZAHtiNM rbNg== X-Gm-Message-State: AOAM532sQp6zJsdIe1ndsS2m3uCL2uBK4CwdTviyUFTMGYWf1VHcoZyw iFMmXniPFisjoa6VU7vSyUvQvzXsPFc= X-Google-Smtp-Source: ABdhPJzLTLvSBF4Ac07j4MJzvCRo7K23T9YXSlFbJctW+wgkDAduF9xPXpidNy2CZkAQ6bECEZGxuw== X-Received: by 2002:a17:90a:930b:b0:1bf:ac1f:6585 with SMTP id p11-20020a17090a930b00b001bfac1f6585mr244766pjo.88.1648569046291; Tue, 29 Mar 2022 08:50:46 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:46 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:25 +1000 Message-Id: <20220329154931.493851-33-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 32/38] gdbserver: multithread debugging support 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" This implements the threadinfo gdb commands, and removes the restriction of a single target. Signed-off-by: Nicholas Piggin --- README.md | 17 +- src/gdb_parser.rl | 16 +- src/gdb_parser_precompile.c | 328 +++++++++++++++++++----------------- src/pdbgproxy.c | 66 +++++++- src/pdbgproxy.h | 10 +- 5 files changed, 267 insertions(+), 170 deletions(-) diff --git a/README.md b/README.md index 0faa1bf..19ac561 100644 --- a/README.md +++ b/README.md @@ -531,13 +531,20 @@ At the moment gdbserver is only supported on P8 and P9 and P10. Memory access can only be performed on kernel memory. -To run a gdbserver on a P8 machine from a BMC running openbmc: +To run a gdbserver on a machine from a BMC running OpenBMC: -Stop all the threads of the core you want to look at -$ ./pdbg -d p8 -c11 -a stop +Stop all the threads of the core(s) you want to look at. Ideally all +threads in the machine should be debugged: -Run gdbserver on thread 0 of core 11, accessible through port 44 -$ ./pdbg -d p8 -p0 -c11 -t0 gdbserver 44 +$ ./pdbg -a stop + +Run gdbserver on the target threads, accessible through port 44 +$ ./pdbg -a gdbserver 44 + +The thread-id tid is set to the PIR of the corresponding thread, the +hard_smp_processor_id. Be warned, "info threads" or other gdb operations +that iterate over all threads may be very slow when debugging a lot +of threads, especially over slow remote links. On your local machine: $ gdb diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index dc1275c..abb361a 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -111,14 +111,15 @@ # 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+;QStartNoAckMode+"; ack_mode = true;}); - qf_threadinfo = ('qfThreadInfo' @{rsp = "m1l";}); + q_supported = ('qSupported:' any* >{rsp = "multiprocess+;swbreak+;hwbreak-;qRelocInsn-;vContSupported+;QThreadEvents-;no-resumed-;QStartNoAckMode+"; ack_mode = true;}); q_start_noack = ('QStartNoAckMode' @{rsp = "OK"; send_ack(priv); ack_mode = false;}); # thread info + is_alive = ('T' ('p' xdigit+ '.')+ xdigit+ @{rsp = "OK";}); get_thread = ('qC' @{cmd = GET_THREAD;}); set_thread = ('Hg' ('p' xdigit+ '.')+ xdigit+ $hex_digit %push @{cmd = SET_THREAD;}); + qf_threadinfo = ('qfThreadInfo' @{cmd = QF_THREADINFO;}); + qs_threadinfo = ('qsThreadInfo' @{cmd = QS_THREADINFO;}); # vCont packet parsing v_contq = ('vCont?' @{rsp = "vCont;c;C;s;S";}); @@ -128,9 +129,12 @@ interrupt = (3 @{ if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");}); - commands = (get_mem | get_gprs | get_spr | stop_reason | get_thread | set_thread | - q_attached | q_C | q_supported | qf_threadinfo | q_C | - q_start_noack | v_contq | v_contc | v_conts | put_mem | + commands = (get_gprs | get_spr | + q_attached | q_supported | q_start_noack | + stop_reason | is_alive | get_thread | set_thread | + v_contq | v_contc | v_conts | + qf_threadinfo | qs_threadinfo | + get_mem | put_mem | detach | unknown ); cmd = (('$' ((commands & ^'#'*) >reset $crc) diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index f09c0f9..97cdae2 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -11,7 +11,7 @@ #include "debug.h" -#line 145 "src/gdb_parser.rl" +#line 149 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -31,76 +31,86 @@ static bool ack_mode = true; #line 32 "src/gdb_parser.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 15, 1, 23, 1, 24, 1, - 25, 1, 26, 2, 0, 1, 2, 2, + 3, 1, 14, 1, 24, 1, 25, 1, + 26, 1, 27, 2, 0, 1, 2, 2, 1, 2, 3, 1, 2, 3, 5, 2, - 4, 1, 2, 13, 1, 2, 15, 1, - 2, 16, 1, 2, 17, 1, 2, 20, - 1, 2, 21, 1, 2, 22, 1, 3, - 0, 6, 1, 3, 0, 7, 1, 3, - 0, 9, 1, 3, 0, 10, 1, 3, - 0, 11, 1, 3, 0, 12, 1, 3, - 2, 8, 1, 3, 3, 19, 1, 3, - 18, 14, 1 + 4, 1, 2, 13, 1, 2, 14, 1, + 2, 15, 1, 2, 16, 1, 2, 17, + 1, 2, 19, 1, 2, 20, 1, 2, + 21, 1, 2, 22, 1, 2, 23, 1, + 3, 0, 6, 1, 3, 0, 7, 1, + 3, 0, 9, 1, 3, 0, 10, 1, + 3, 0, 11, 1, 3, 0, 12, 1, + 3, 2, 8, 1, 3, 3, 18, 1 + }; -static const unsigned char _gdb_key_offsets[] = { - 0, 0, 11, 12, 18, 24, 31, 38, - 40, 42, 49, 57, 65, 72, 79, 87, - 94, 102, 109, 111, 113, 115, 117, 119, - 121, 123, 125, 127, 129, 131, 133, 135, - 137, 144, 152, 157, 159, 161, 163, 165, - 167, 169, 171, 173, 180, 182, 184, 186, - 188, 190, 192, 194, 196, 198, 199, 201, - 203, 205, 207, 209, 211, 213, 215, 217, - 219, 221, 223, 225, 227, 230, 233, 234, - 235 +static const short _gdb_key_offsets[] = { + 0, 0, 12, 13, 19, 25, 32, 39, + 41, 43, 50, 58, 66, 73, 80, 88, + 95, 103, 110, 112, 114, 116, 118, 120, + 122, 124, 126, 128, 130, 132, 134, 136, + 138, 140, 147, 155, 163, 170, 177, 185, + 191, 193, 195, 197, 199, 201, 203, 205, + 207, 214, 216, 218, 220, 222, 224, 226, + 228, 230, 232, 233, 235, 237, 239, 241, + 243, 245, 247, 249, 251, 253, 255, 257, + 259, 261, 263, 265, 267, 269, 271, 273, + 275, 277, 279, 281, 284, 287, 288, 289 }; static const char _gdb_trans_keys[] = { - 35, 63, 68, 72, 77, 81, 103, 109, - 112, 113, 118, 35, 48, 57, 65, 70, - 97, 102, 48, 57, 65, 70, 97, 102, - 35, 48, 57, 65, 70, 97, 102, 35, - 48, 57, 65, 70, 97, 102, 35, 103, - 35, 112, 35, 48, 57, 65, 70, 97, - 102, 35, 46, 48, 57, 65, 70, 97, - 102, 35, 112, 48, 57, 65, 70, 97, + 35, 63, 68, 72, 77, 81, 84, 103, + 109, 112, 113, 118, 35, 48, 57, 65, + 70, 97, 102, 48, 57, 65, 70, 97, 102, 35, 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, 58, - 48, 57, 65, 70, 97, 102, 35, 48, - 57, 65, 70, 97, 102, 35, 83, 35, - 116, 35, 97, 35, 114, 35, 116, 35, - 78, 35, 111, 35, 65, 35, 99, 35, - 107, 35, 77, 35, 111, 35, 100, 35, - 101, 35, 48, 57, 65, 70, 97, 102, + 103, 35, 112, 35, 48, 57, 65, 70, + 97, 102, 35, 46, 48, 57, 65, 70, + 97, 102, 35, 112, 48, 57, 65, 70, + 97, 102, 35, 48, 57, 65, 70, 97, + 102, 35, 48, 57, 65, 70, 97, 102, 35, 44, 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, 43, 45, 0 + 35, 48, 57, 65, 70, 97, 102, 35, + 58, 48, 57, 65, 70, 97, 102, 35, + 48, 57, 65, 70, 97, 102, 35, 83, + 35, 116, 35, 97, 35, 114, 35, 116, + 35, 78, 35, 111, 35, 65, 35, 99, + 35, 107, 35, 77, 35, 111, 35, 100, + 35, 101, 35, 112, 35, 48, 57, 65, + 70, 97, 102, 35, 46, 48, 57, 65, + 70, 97, 102, 35, 112, 48, 57, 65, + 70, 97, 102, 35, 48, 57, 65, 70, + 97, 102, 35, 48, 57, 65, 70, 97, + 102, 35, 44, 48, 57, 65, 70, 97, + 102, 35, 65, 67, 83, 102, 115, 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, 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, 43, 45, 0 }; static const char _gdb_single_lengths[] = { - 0, 11, 1, 0, 0, 1, 1, 2, + 0, 12, 1, 0, 0, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 1, 2, 5, 2, 2, 2, 2, 2, - 2, 2, 2, 1, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 1, 2, 2, + 2, 1, 2, 2, 1, 1, 2, 6, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 3, 3, 1, 1, - 4 + 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, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 3, 1, 1, 4 }; static const char _gdb_range_lengths[] = { @@ -108,111 +118,125 @@ static const char _gdb_range_lengths[] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 3, 3, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 0, + 0, 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, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; static const short _gdb_index_offsets[] = { - 0, 0, 12, 14, 18, 22, 27, 32, - 35, 38, 43, 49, 55, 60, 65, 71, - 76, 82, 87, 90, 93, 96, 99, 102, - 105, 108, 111, 114, 117, 120, 123, 126, - 129, 134, 140, 146, 149, 152, 155, 158, - 161, 164, 167, 170, 175, 178, 181, 184, - 187, 190, 193, 196, 199, 202, 204, 207, - 210, 213, 216, 219, 222, 225, 228, 231, - 234, 237, 240, 243, 246, 250, 254, 256, - 258 + 0, 0, 13, 15, 19, 23, 28, 33, + 36, 39, 44, 50, 56, 61, 66, 72, + 77, 83, 88, 91, 94, 97, 100, 103, + 106, 109, 112, 115, 118, 121, 124, 127, + 130, 133, 138, 144, 150, 155, 160, 166, + 173, 176, 179, 182, 185, 188, 191, 194, + 197, 202, 205, 208, 211, 214, 217, 220, + 223, 226, 229, 231, 234, 237, 240, 243, + 246, 249, 252, 255, 258, 261, 264, 267, + 270, 273, 276, 279, 282, 285, 288, 291, + 294, 297, 300, 303, 307, 311, 313, 315 }; static const char _gdb_indicies[] = { 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 0, 13, 12, 14, 14, - 14, 15, 16, 16, 16, 15, 13, 17, - 17, 17, 12, 18, 17, 17, 17, 12, - 13, 19, 12, 13, 20, 12, 13, 21, - 21, 21, 12, 13, 22, 21, 21, 21, - 12, 13, 20, 23, 23, 23, 12, 18, - 23, 23, 23, 12, 13, 24, 24, 24, - 12, 13, 25, 24, 24, 24, 12, 13, - 26, 26, 26, 12, 13, 27, 26, 26, - 26, 12, 13, 28, 28, 28, 12, 13, - 29, 12, 13, 30, 12, 13, 31, 12, - 13, 32, 12, 13, 33, 12, 13, 34, - 12, 13, 35, 12, 13, 36, 12, 13, - 37, 12, 13, 38, 12, 13, 39, 12, - 13, 40, 12, 13, 41, 12, 13, 42, - 12, 13, 43, 43, 43, 12, 13, 44, - 43, 43, 43, 12, 13, 45, 46, 47, - 48, 12, 13, 49, 12, 13, 50, 12, - 13, 51, 12, 13, 52, 12, 13, 53, - 12, 13, 54, 12, 13, 55, 12, 13, - 56, 12, 13, 57, 57, 57, 12, 13, - 58, 12, 13, 59, 12, 13, 60, 12, - 13, 61, 12, 13, 62, 12, 13, 63, - 12, 13, 64, 12, 13, 65, 12, 13, - 66, 12, 68, 67, 13, 69, 12, 13, - 70, 12, 13, 71, 12, 13, 72, 12, - 13, 73, 12, 13, 74, 12, 13, 75, - 12, 13, 76, 12, 13, 77, 12, 13, - 78, 12, 13, 79, 12, 13, 80, 12, - 13, 81, 12, 13, 82, 12, 13, 83, - 84, 12, 13, 85, 86, 12, 13, 87, - 13, 88, 89, 90, 91, 92, 15, 0 + 9, 10, 11, 12, 0, 14, 13, 15, + 15, 15, 16, 17, 17, 17, 16, 14, + 18, 18, 18, 13, 19, 18, 18, 18, + 13, 14, 20, 13, 14, 21, 13, 14, + 22, 22, 22, 13, 14, 23, 22, 22, + 22, 13, 14, 21, 24, 24, 24, 13, + 19, 24, 24, 24, 13, 14, 25, 25, + 25, 13, 14, 26, 25, 25, 25, 13, + 14, 27, 27, 27, 13, 14, 28, 27, + 27, 27, 13, 14, 29, 29, 29, 13, + 14, 30, 13, 14, 31, 13, 14, 32, + 13, 14, 33, 13, 14, 34, 13, 14, + 35, 13, 14, 36, 13, 14, 37, 13, + 14, 38, 13, 14, 39, 13, 14, 40, + 13, 14, 41, 13, 14, 42, 13, 14, + 43, 13, 14, 44, 13, 14, 45, 45, + 45, 13, 14, 46, 45, 45, 45, 13, + 14, 44, 47, 47, 47, 13, 14, 47, + 47, 47, 13, 14, 48, 48, 48, 13, + 14, 49, 48, 48, 48, 13, 14, 50, + 51, 52, 53, 54, 13, 14, 55, 13, + 14, 56, 13, 14, 57, 13, 14, 58, + 13, 14, 59, 13, 14, 60, 13, 14, + 61, 13, 14, 62, 13, 14, 63, 63, + 63, 13, 14, 64, 13, 14, 65, 13, + 14, 66, 13, 14, 67, 13, 14, 68, + 13, 14, 69, 13, 14, 70, 13, 14, + 71, 13, 14, 72, 13, 74, 73, 14, + 75, 13, 14, 76, 13, 14, 77, 13, + 14, 78, 13, 14, 79, 13, 14, 80, + 13, 14, 81, 13, 14, 82, 13, 14, + 83, 13, 14, 84, 13, 14, 85, 13, + 14, 86, 13, 14, 87, 13, 14, 88, + 13, 14, 89, 13, 14, 90, 13, 14, + 91, 13, 14, 92, 13, 14, 93, 13, + 14, 94, 13, 14, 95, 13, 14, 96, + 13, 14, 97, 13, 14, 98, 13, 14, + 99, 100, 13, 14, 101, 102, 13, 14, + 103, 14, 104, 105, 106, 107, 108, 16, + 0 }; static const char _gdb_trans_targs[] = { - 2, 3, 2, 5, 7, 13, 18, 2, - 32, 5, 34, 64, 2, 3, 4, 0, - 72, 6, 3, 8, 9, 10, 11, 12, - 14, 15, 16, 17, 17, 19, 20, 21, - 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 2, 33, 5, 35, 2, 44, - 54, 36, 37, 38, 39, 40, 41, 42, - 43, 43, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 2, 3, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 2, 65, - 66, 67, 68, 69, 2, 70, 71, 70, - 71, 72, 1, 72, 72 + 2, 3, 2, 5, 7, 13, 18, 32, + 2, 37, 5, 39, 79, 2, 3, 4, + 0, 87, 6, 3, 8, 9, 10, 11, + 12, 14, 15, 16, 17, 17, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 2, 33, 34, 35, 36, + 38, 5, 40, 2, 49, 59, 69, 41, + 42, 43, 44, 45, 46, 47, 48, 48, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 2, 3, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 2, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 2, 80, + 81, 82, 83, 84, 2, 85, 86, 85, + 86, 87, 1, 87, 87 }; static const char _gdb_trans_actions[] = { - 19, 1, 71, 75, 19, 59, 19, 63, - 55, 67, 19, 19, 3, 0, 7, 0, - 28, 25, 5, 3, 3, 3, 3, 83, - 25, 22, 25, 79, 31, 3, 3, 3, + 19, 1, 80, 84, 19, 68, 19, 19, + 72, 64, 76, 19, 19, 3, 0, 7, + 0, 28, 25, 5, 3, 3, 3, 3, + 92, 25, 22, 25, 88, 31, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 43, 25, 22, 3, 87, 3, + 3, 3, 3, 40, 3, 3, 3, 43, + 25, 22, 3, 46, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 34, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 34, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 37, 9, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 40, 3, - 3, 3, 3, 3, 46, 3, 3, 49, - 52, 11, 13, 15, 17 + 3, 37, 9, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 49, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 52, 3, + 3, 3, 3, 3, 55, 3, 3, 58, + 61, 11, 13, 15, 17 }; -static const int gdb_start = 72; -static const int gdb_first_final = 72; +static const int gdb_start = 87; +static const int gdb_first_final = 87; static const int gdb_error = 0; -static const int gdb_en_main = 72; +static const int gdb_en_main = 87; -#line 161 "src/gdb_parser.rl" +#line 165 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 211 "src/gdb_parser.c" +#line 235 "src/gdb_parser.c" { cs = gdb_start; } -#line 165 "src/gdb_parser.rl" +#line 169 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -223,7 +247,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len; -#line 227 "src/gdb_parser.c" +#line 251 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -418,57 +442,61 @@ _match: break; case 14: #line 114 "src/gdb_parser.rl" - {rsp = "QC1";} + {rsp = "multiprocess+;swbreak+;hwbreak-;qRelocInsn-;vContSupported+;QThreadEvents-;no-resumed-;QStartNoAckMode+"; ack_mode = true;} break; case 15: #line 115 "src/gdb_parser.rl" - {rsp = "multiprocess+;vContSupported+;QStartNoAckMode+"; ack_mode = true;} + {rsp = "OK"; send_ack(priv); ack_mode = false;} break; case 16: -#line 116 "src/gdb_parser.rl" - {rsp = "m1l";} +#line 118 "src/gdb_parser.rl" + {rsp = "OK";} break; case 17: -#line 117 "src/gdb_parser.rl" - {rsp = "OK"; send_ack(priv); ack_mode = false;} +#line 119 "src/gdb_parser.rl" + {cmd = GET_THREAD;} break; case 18: #line 120 "src/gdb_parser.rl" - {cmd = GET_THREAD;} + {cmd = SET_THREAD;} break; case 19: #line 121 "src/gdb_parser.rl" - {cmd = SET_THREAD;} + {cmd = QF_THREADINFO;} break; case 20: -#line 124 "src/gdb_parser.rl" - {rsp = "vCont;c;C;s;S";} +#line 122 "src/gdb_parser.rl" + {cmd = QS_THREADINFO;} break; case 21: #line 125 "src/gdb_parser.rl" - {cmd = V_CONTC;} + {rsp = "vCont;c;C;s;S";} break; case 22: #line 126 "src/gdb_parser.rl" - {cmd = V_CONTS;} + {cmd = V_CONTC;} break; case 23: -#line 129 "src/gdb_parser.rl" - { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} +#line 127 "src/gdb_parser.rl" + {cmd = V_CONTS;} break; case 24: -#line 137 "src/gdb_parser.rl" - {PR_INFO("RAGEL:cmd\n");} +#line 130 "src/gdb_parser.rl" + { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; case 25: -#line 140 "src/gdb_parser.rl" - {PR_INFO("RAGEL:ack\n");} +#line 141 "src/gdb_parser.rl" + {PR_INFO("RAGEL:cmd\n");} break; case 26: -#line 141 "src/gdb_parser.rl" +#line 144 "src/gdb_parser.rl" + {PR_INFO("RAGEL:ack\n");} + break; + case 27: +#line 145 "src/gdb_parser.rl" {PR_INFO("RAGEL:nack\n");} break; -#line 472 "src/gdb_parser.c" +#line 500 "src/gdb_parser.c" } } @@ -481,7 +509,7 @@ _again: _out: {} } -#line 175 "src/gdb_parser.rl" +#line 179 "src/gdb_parser.rl" if (cs == gdb_error) { printf("parse error\n"); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index fca728f..e9d11af 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -142,6 +142,58 @@ static void set_thread(uint64_t *stack, void *priv) send_response(fd, ERROR(EEXIST)); } +static int threadinfo_iterator; + +static void qs_threadinfo(uint64_t *stack, void *priv) +{ + struct pdbg_target *target; + char data[MAX_RESP_LEN] = "m"; + size_t s = 1; + int iter = 0; + bool found = false; + + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!found && iter < threadinfo_iterator) { + iter++; + continue; + } + + found = true; + + if (iter == threadinfo_iterator) + s += snprintf(data + s, sizeof(data) - s, + "%04" PRIx64, gdb_thread->pir); + else + s += snprintf(data + s, sizeof(data) - s, + ",%04" PRIx64, gdb_thread->pir); + threadinfo_iterator++; + + if (sizeof(data) - s < 9) /* comma, 7 digits, NUL */ + break; + + } + + PR_INFO("qf_threadinfo %s\n", data); + + if (s > 1) + send_response(fd, data); + else + send_response(fd, "l"); +} + +static void qf_threadinfo(uint64_t *stack, void *priv) +{ + threadinfo_iterator = 0; + + qs_threadinfo(stack, priv); +} + static void send_stop_for_thread(struct pdbg_target *target) { struct thread *thread = target_to_thread(target); @@ -880,12 +932,14 @@ static command_cb callbacks[LAST_CMD + 1] = { cmd_default, get_gprs, get_spr, - get_mem, stop_reason, get_thread, set_thread, v_contc, v_conts, + qf_threadinfo, + qs_threadinfo, + get_mem, put_mem, interrupt, detach, @@ -1018,12 +1072,8 @@ static int gdbserver(uint16_t port) memset(gdb_thread, 0, sizeof(*gdb_thread)); thread->gdbserver_priv = gdb_thread; - if (!first_target) { + if (!first_target) first_target = target; - } else { - fprintf(stderr, "GDB server cannot be run on multiple threads at once.\n"); - return 0; - } } if (!first_target) { @@ -1039,6 +1089,10 @@ static int gdbserver(uint16_t port) PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); } + if (!path_target_all_selected("thread", NULL)) { + PR_WARNING("GDBSERVER works best when targeting all threads (-a)\n"); + } + thread_target = first_target; for_each_path_target_class("thread", target) { diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h index 2005083..cafd4cb 100644 --- a/src/pdbgproxy.h +++ b/src/pdbgproxy.h @@ -1,9 +1,13 @@ #ifndef __PDBGPROXY_H #define __PDBGPROXY_H -enum gdb_command {NONE, GET_GPRS, GET_SPR, GET_MEM, - STOP_REASON, GET_THREAD, SET_THREAD, V_CONTC, V_CONTS, - PUT_MEM, INTERRUPT, DETACH, LAST_CMD}; +enum gdb_command {NONE, GET_GPRS, GET_SPR, + STOP_REASON, GET_THREAD, SET_THREAD, + V_CONTC, V_CONTS, + QF_THREADINFO, QS_THREADINFO, + GET_MEM, PUT_MEM, + INTERRUPT, DETACH, LAST_CMD}; + typedef void (*command_cb)(uint64_t *stack, void *priv); void parser_init(command_cb *callbacks); From patchwork Tue Mar 29 15:49:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610715 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=HdWzV1kI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYv14QpKz9sFk for ; Wed, 30 Mar 2022 02:50:53 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv10ffYz2yKQ for ; Wed, 30 Mar 2022 02:50:53 +1100 (AEDT) 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=HdWzV1kI; 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::42b; helo=mail-pf1-x42b.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=HdWzV1kI; dkim-atps=neutral Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 4KSYty2N8kz2yHB for ; Wed, 30 Mar 2022 02:50:50 +1100 (AEDT) Received: by mail-pf1-x42b.google.com with SMTP id b13so14376496pfv.0 for ; Tue, 29 Mar 2022 08:50:50 -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=pW+C0DqPNyhiIMu8OVzT9y1XjksrY7jLAHeJOiPFCtA=; b=HdWzV1kIqM1QJHkiZVAPw3YKTxjhK76mLBR6kP0tx4XdfNQum/nOxu896dOAuaxiqi n6H2LtNWIWPq2T4eNF5QA+8jnemG1rrUR+BgA8oj1cDtxSmpAQv026JFR1s16GnGw+L+ 0ojRJENYo5ZMRNw3BXjz98HJnOOENR7UHoCl8tvzbl4IRKU9qtdSM8EJaeG16agQi+lq 2qhPvQFpVzmtVHeNSc/IrpmtkH+ke8yTYe9x97e2xkOxE7gca6xHRLO805jaPtfNTr+Q oCz9dlk+UOMv4c0/63KA5ib6swYpT5kDjB1pEljgxUUbg/m+X7zT5ro3RHvSR+kQ0hld h/iA== 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=pW+C0DqPNyhiIMu8OVzT9y1XjksrY7jLAHeJOiPFCtA=; b=V4GHaRJEG2dGmCBBdU/W8gUrAvi1Ar1bbVcDDm4eITe/c4YBnuo8ilTfsjnAwTW7hb pfM+8k9QPOhO+k/f30IEUVF3IXtZdJ1aE5XqhsXOSNd6YdC8ugxrqwkTITLWHytJ2yF5 b5c4cHMILzdglLsXq9jZmGcyRzmX9c2914g33bWwQU6e6xOtOCgmhiuCXXutjeaqE6yB E6xNcVYSGrJ5Mg7FiNZ3ibkI0JwjhLP0JMSLYDJbxToMeoftBIhW4lTt0OBlXzqaBMUT J1kwvGCt0Wlvgfu36TMwRNer/3bfS7iOR5uDaGK9hG82q2W3up6EQHmWO4PmvKrtNvTz J+HA== X-Gm-Message-State: AOAM531N9PcZJr9/lxQXm9ENbl2llBn+9CpdKx0EJZZFcD3h2uDW54HV fTh+gnWHo17ttWYiZwWMuwg/GBZqtyY= X-Google-Smtp-Source: ABdhPJyKqEcHWQY8OzjiSfZBqpqrFYT+AOfvaOYPDeUhZfkYbmDFNsTOEdxFfzSPCOEqb4m+DI536Q== X-Received: by 2002:a63:f412:0:b0:381:28f:85dd with SMTP id g18-20020a63f412000000b00381028f85ddmr2467675pgi.319.1648569048252; Tue, 29 Mar 2022 08:50:48 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:47 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:26 +1000 Message-Id: <20220329154931.493851-34-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 33/38] gdbserver: allow gdbserver to start with targets running 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" Rather than having to stop and start threads independently, allow gdbserver to stop and start its targets as necessary. Manually quiesced targets may still be debugged. This just makes it a bit more user friendly. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index e9d11af..3ffa9e2 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -51,7 +51,7 @@ #define TEST_SKIBOOT_ADDR 0x40000000 -static bool all_stopped = true; /* must be started with targets stopped */ +static bool all_stopped = false; static struct pdbg_target *thread_target = NULL; static struct pdbg_target *adu_target; static struct timeval timeout; @@ -222,9 +222,13 @@ static void stop_reason(uint64_t *stack, void *priv) send_stop_for_thread(thread_target); } +static void start_all(void); + static void detach(uint64_t *stack, void *priv) { PR_INFO("Detach debug session with client. pid %16" PRIi64 "\n", stack[0]); + start_all(); + send_response(fd, OK); } @@ -891,6 +895,8 @@ static void create_client(int new_fd) { PR_INFO("Client connected\n"); fd = new_fd; + if (!all_stopped) + stop_all(); } static void destroy_client(int dead_fd) @@ -1095,27 +1101,38 @@ static int gdbserver(uint16_t port) thread_target = first_target; + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (thread_stop(target)) { + PR_ERROR("Could not stop thread %s\n", + pdbg_target_path(target)); + return -1; + } + } + for_each_path_target_class("thread", target) { struct thread *thread = target_to_thread(target); - struct gdb_thread *gdb_thread; + struct gdb_thread *gdb_thread = thread->gdbserver_priv; if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - gdb_thread = thread->gdbserver_priv; - if (thread_getspr(target, SPR_PIR, &gdb_thread->pir)) { PR_ERROR("Error reading PIR. Are all thread in the target cores quiesced?\n"); - return 0; + goto out; } if (gdb_thread->pir & ~0xffffULL) { /* This limit is just due to some string array sizes */ PR_ERROR("PIR exceeds 16-bits."); - return 0; + goto out; } } + start_all(); + /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) @@ -1124,11 +1141,15 @@ static int gdbserver(uint16_t port) if (!adu) { fprintf(stderr, "No ADU found\n"); - return 0; + goto out; } gdbserver_start(adu, port); +out: + if (all_stopped) + __start_all(); + return 0; } #else From patchwork Tue Mar 29 15:49:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610716 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=JS7kSBUp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYv427nNz9sFk for ; Wed, 30 Mar 2022 02:50:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv410Fgz2yKQ for ; Wed, 30 Mar 2022 02:50:56 +1100 (AEDT) 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=JS7kSBUp; 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::62d; helo=mail-pl1-x62d.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=JS7kSBUp; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 4KSYv00PMbz2xtQ for ; Wed, 30 Mar 2022 02:50:52 +1100 (AEDT) Received: by mail-pl1-x62d.google.com with SMTP id c23so18041122plo.0 for ; Tue, 29 Mar 2022 08:50:51 -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=Eunaa4Vzd8JSzBdYnN/z5/932RI+6Hj0WrQ7myg+e9I=; b=JS7kSBUp1HTojuEUhKV22aam3uUgdTAUullUGfN3cVwiWE1HAV7zCCwslclcrrnuck d7369uThSbGWawTz6YByOKrr1AMm4CnwfZaaXHSRJSD4/zmioiuMR+uzVuQrtif/Z3Kq XDwIJ6aYbhZyu/IA694ryml+2hJB8aOe+V+Ls2fUgKWm9s5j07Q81s/vjTx8lkesIwdJ KZrWxPZtU+kHXKVzpJd8OPEJwYG7CpOf7Oi7Jo9KAKPDVg5juPwJE1d4VibCH2krijNc w4MBW2hyM30zXq4ZwuR6UQIwmMcP50IMNfidknBvygsmHhoXmfkU8VeigESfOsq4aDjo MItw== 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=Eunaa4Vzd8JSzBdYnN/z5/932RI+6Hj0WrQ7myg+e9I=; b=R1GOvZ78JNbgTrZYorIfYs5n5rhYvN+748Vgy2iO/NLUhIRhgIkAbvZ566/vR+IjMn /mSyjH8wB+SjIy2f7+gh9Hv9LvGZiDP4QhLt9b6B1FyDx/dc0xkTSPLOJKavHQKJll77 wtjFIvVBrIG9JbMeS/o+Yd+tI1z5w6VsogF2CXeo+aag69CrUYXJJiCl4DPeJIdp74gc 69+7LdpMh27eF9gvwmu+6A60u9WDmpd26nF4KaekOojY91Z0zHSocnWowlmElo+vgTtM PUGyx8A8DFZIRNni4FlZRC1KWJKObeGlr2zPtixUyVHHGWj5cBSTL5hwbzvvmUNr563B WLNA== X-Gm-Message-State: AOAM533MvSx2dvKhZS6U0lYLTsAm02kaF6LIK6s26Qaj7rf1ulNnQAVf q6PTrL7ckE/DDiyvv11e8iPdzeqBuB0= X-Google-Smtp-Source: ABdhPJywZF/Qxl7HoDVlOQzyNKz3axCYM5H3C/mnFCt29hwPWjMKlbQKKd8hhn4AS4Lqj6T1xMQEQg== X-Received: by 2002:a17:90b:4a46:b0:1c7:3b81:fc6 with SMTP id lb6-20020a17090b4a4600b001c73b810fc6mr191438pjb.243.1648569050220; Tue, 29 Mar 2022 08:50:50 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:49 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:27 +1000 Message-Id: <20220329154931.493851-35-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 34/38] gdbserver: better deal with threads initially stopped 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" Better deal with threads that are quiesced when gdbserver starts. Record and clear SPATTN register to determine whether any had hit attn, and prevent subsequent stop from getting a false positive on SPATTN. Switch target thread to the first one that had hit an attn or been stopped when gdbserver starts up, if any. Don't resume initially-stopped threads unless a client attaches and directs them to. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 90 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 3ffa9e2..7dc0555 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -64,6 +64,7 @@ static enum client_state state = IDLE; struct gdb_thread { uint64_t pir; bool attn_set; + bool initial_stopped; bool stop_attn; bool stop_ctrlc; }; @@ -1058,11 +1059,15 @@ static int gdbserver_start(struct pdbg_target *adu, uint16_t port) static int gdbserver(uint16_t port) { - struct pdbg_target *target, *adu, *first_target = NULL; + struct pdbg_target *target, *adu; + struct pdbg_target *first_target = NULL; + struct pdbg_target *first_stopped_target = NULL; + struct pdbg_target *first_attn_target = NULL; 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) continue; @@ -1080,6 +1085,13 @@ static int gdbserver(uint16_t port) if (!first_target) first_target = target; + + status = thread_status(target); + if (status.quiesced) { + if (!first_stopped_target) + first_stopped_target = target; + gdb_thread->initial_stopped = true; + } } if (!first_target) { @@ -1099,16 +1111,19 @@ static int gdbserver(uint16_t port) PR_WARNING("GDBSERVER works best when targeting all threads (-a)\n"); } - thread_target = first_target; - for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - if (thread_stop(target)) { - PR_ERROR("Could not stop thread %s\n", - pdbg_target_path(target)); - return -1; + if (!gdb_thread->initial_stopped) { + if (thread_stop(target)) { + PR_ERROR("Could not stop thread %s\n", + pdbg_target_path(target)); + return -1; + } } } @@ -1129,9 +1144,46 @@ static int gdbserver(uint16_t port) PR_ERROR("PIR exceeds 16-bits."); goto out; } + + if (thread_check_attn(target)) { + PR_INFO("thread pir=%llx hit attn\n", gdb_thread->pir); + + if (!first_attn_target) + first_attn_target = target; + gdb_thread->stop_attn = true; + if (!gdb_thread->initial_stopped) { + PR_WARNING("thread pir=%llx hit attn but was not stopped\n", gdb_thread->pir); + gdb_thread->initial_stopped = true; + } + } } - start_all(); + /* Target attn as a priority, then any stopped, then first */ + if (first_attn_target) + thread_target = first_target; + else if (first_stopped_target) + thread_target = first_stopped_target; + else + thread_target = first_target; + + /* + * Resume threads now, except those that were initially stopped, + * leave them so the client can inspect them. + */ + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!gdb_thread->initial_stopped) { + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + } /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { @@ -1147,8 +1199,26 @@ static int gdbserver(uint16_t port) gdbserver_start(adu, port); out: - if (all_stopped) - __start_all(); + if (!all_stopped) + stop_all(); + + /* + * Only resume those which were not initially stopped + */ + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!gdb_thread->initial_stopped) { + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + } return 0; } From patchwork Tue Mar 29 15:49:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610717 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=Ntc23Kiw; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYv52mmQz9sFk for ; Wed, 30 Mar 2022 02:50:57 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv51tgbz2yNF for ; Wed, 30 Mar 2022 02:50:57 +1100 (AEDT) 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=Ntc23Kiw; 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::62e; helo=mail-pl1-x62e.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=Ntc23Kiw; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 4KSYv21gbYz2xYG for ; Wed, 30 Mar 2022 02:50:54 +1100 (AEDT) Received: by mail-pl1-x62e.google.com with SMTP id i11so18040331plr.1 for ; Tue, 29 Mar 2022 08:50:54 -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=tpNJJEIm06PYfVGgnVzpK1YVYgMiU+HShYrg3LBBVDg=; b=Ntc23KiwEe04Ud/oYU9jTAd25fVSQCm0AjHkCtUY5D2xmo2VHnN5ZsCKBVX8vQ3Evi uNuRZ0buVMrRWNZAT6yNKnyREM1tX+PKtw+CzSxOQdiq+3VN86zbONxmrBR7Zw99EOrI O+esvj+EMDRFfw6unG8+l9oHKZL4hqMbr6k5l5O9dcQ1rBbHurTq6aB4qJ7eevOj2MXa YqRugz6L1Q/bY2vNEWmB6FmlgJom9p6QiwH4dIVgpudDE8jnZfxE5gWV0UwMEJghIacg Hw0KuvhhJibEOdkjBYhISJBhE6uBGDm6x6VFOV5CoRP2C0P0Gp368Yvj1A78U/9BEIjy D+4A== 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=tpNJJEIm06PYfVGgnVzpK1YVYgMiU+HShYrg3LBBVDg=; b=BAwufCIj1Qsq5KU2WjqAewWa5I+qXximM4vpxrxB6aKGlGbbWnGr0bvplD+hUTHDur iejrzyqXkY5E38aHcpyUrrwpZV5vPadzFe6hAoHqCkWfI+94k2EIkjR8Zc/n2UdLSORy Me29qaSzNQqJJSTlm/JL5fPH3+GA8MltkCgl0AgKiIlGif9p06pm1IrQrelArWX8T9x8 mrlUOtTtP4yMZTTatf4vQedPHYt4tgOfWXgJlx2ZLwhV//5uCNftnJVzEMK4Tczv9Iz9 m3zykC5UjHXrVBIed9PZSgTgQ7yuuxAV1h3Q66it2eypx2Oij3hE4Cwei5O3g/Q5sfJN luXg== X-Gm-Message-State: AOAM533CF/PGufGXaoz308uefN5NFEBt6ZYpz7jMy3B0h954AfpDjNeb XVea6adpbN8FYAzzQnE6oCnG7Xsnids= X-Google-Smtp-Source: ABdhPJxP0eAFfNzCRJtFKUcTYxn5XCi8QH5bFd4h6yeSCI0uP4nQnRi3f5RNfJNmwg7EHKAEc9LADA== X-Received: by 2002:a17:90a:bb0e:b0:1c7:e8bf:5561 with SMTP id u14-20020a17090abb0e00b001c7e8bf5561mr256987pjr.18.1648569052242; Tue, 29 Mar 2022 08:50:52 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:52 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:28 +1000 Message-Id: <20220329154931.493851-36-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 35/38] gdbserver: send regs with stop reason 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" This reduces round-trip time getting registers after stopping. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 7dc0555..b34dec5 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -202,7 +202,11 @@ static void send_stop_for_thread(struct pdbg_target *target) uint64_t pir = gdb_thread->pir; char data[MAX_RESP_LEN]; size_t s = 0; + struct thread_regs regs; + uint64_t value; + uint32_t value32; int sig; + int i; if (gdb_thread->stop_attn) sig = 5; /* TRAP */ @@ -213,6 +217,39 @@ static void send_stop_for_thread(struct pdbg_target *target) s += snprintf(data + s, sizeof(data) - s, "T%02uthread:%04" PRIx64 ";%s", sig, pir, sig == 5 ? "swbreak:;" : ""); + if (thread_getregs(target, ®s)) + PR_ERROR("Error reading gprs\n"); + + for (i = 0; i < 32; i++) + s += snprintf(data + s, sizeof(data) - s, "%x:%016" PRIx64 ";", i, be64toh(regs.gprs[i])); + + thread_getnia(target, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%016" PRIx64 ";", 0x40, be64toh(value)); + + thread_getmsr(target, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%016" PRIx64 ";", 0x41, be64toh(value)); + + thread_getcr(target, &value32); + s += snprintf(data + s, sizeof(data) - s, "%x:%08" PRIx32 ";", 0x42, be32toh(value32)); + + thread_getspr(target, SPR_LR, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%016" PRIx64 ";", 0x43, be64toh(value)); + + thread_getspr(target, SPR_CTR, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%016" PRIx64 ";", 0x44, be64toh(value)); + + thread_getspr(target, SPR_XER, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%08" PRIx32 ";", 0x45, be32toh(value)); + + thread_getspr(target, SPR_FPSCR, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%08" PRIx32 ";", 0x46, be32toh(value)); + + thread_getspr(target, SPR_VSCR, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%08" PRIx32 ";", 0x67, be32toh(value)); + + thread_getspr(target, SPR_VRSAVE, &value); + s += snprintf(data + s, sizeof(data) - s, "%x:%08" PRIx32 ";", 0x68, be32toh(value)); + send_response(fd, data); } From patchwork Tue Mar 29 15:49:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610718 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=fo8dPnQ8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYv73l89z9sFk for ; Wed, 30 Mar 2022 02:50:59 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv73HNWz2yKQ for ; Wed, 30 Mar 2022 02:50:59 +1100 (AEDT) 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=fo8dPnQ8; 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::1033; helo=mail-pj1-x1033.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=fo8dPnQ8; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 4KSYv46ZYPz2yMK for ; Wed, 30 Mar 2022 02:50:56 +1100 (AEDT) Received: by mail-pj1-x1033.google.com with SMTP id d30so867526pjk.0 for ; Tue, 29 Mar 2022 08:50:56 -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=Ql/LPCbzifr/dU2BJ170ylKNC+7QE0rrzpv34bkqmPY=; b=fo8dPnQ8AIuQagg+ulpibhFnBjV7yur1G7IP6eRyk7xCZTWeinVfyLqXpmo/L4Ii8a 4Z513VofZ5OMCAyfNl2T1ngQEEqAJD/HVunpvXYXf/eaU86OGeAcllnGJmucegmFtXFR vM+BkvdfKPhnr33LECZvv8IYjw99Togw2zv0Yj5rExqgDBND/hhmdEa4uhatY86Q7LtR baInMijRpKdJBBeyNuB5IG9vYzYCS6hAQSr9D+ImXXFAzjyF6aUCnQ0nPLDGhAnFrQaV cL+TiQcCoLhkC1IVut4oxsuLdAD9hbFT6D/d1uuHkdukPW3GTYN6xM5VyRTB7949VTij nWkg== 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=Ql/LPCbzifr/dU2BJ170ylKNC+7QE0rrzpv34bkqmPY=; b=Fg1as4LlO5oP0ZpgsdUbf6PG5SjFxIfzya9rAJEpn/4tDTHGHh+OCZ5U8se0do0pwQ WBL8561X0zcMp9TkaQuNYmXTYIDrQEIcIDdnxZj88KANTGNpgtbQyPKoYMRDxtju+iz6 tBeDzWwzZ3U75RXxmuLEqkT+p7T5GSNRFQp335U6ELtuxeDrlHF6FvE4N1FRFekRWYN7 sHRf8KZVlUW41OtIIajbaxeh5OJXZZpUWd5Xe6GW2c7etKDnTdUlg7DcltxiJgkHTYxN 4i8IoInjyIPbuZbBYV6OpiK9oWLMPZ+gsIJGp9tOaHKRIJm8xR8XJ3ZwYIgphgZqP3yA 2cVg== X-Gm-Message-State: AOAM533UG289jxc3jpQWgFa4sOao2SkDiSUIyvZ2IrQnNDva6U4By9eK SxOau8JYkax+QrirWFY/7u2bd/1L9Bk= X-Google-Smtp-Source: ABdhPJyF7mQ+XF5GcPofPno/tRnk0Ypc4LiPLl2Jxsu6gAMxBY+le5INDHQ7VgwmVWILoxBJUYOpyA== X-Received: by 2002:a17:903:22c2:b0:154:565b:b273 with SMTP id y2-20020a17090322c200b00154565bb273mr31475378plg.115.1648569054341; Tue, 29 Mar 2022 08:50:54 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:54 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:29 +1000 Message-Id: <20220329154931.493851-37-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 36/38] gdbserver: use thread_stop_all() / thread_start_all() 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" This could (marginally) improve stop/start latency when targeting all threads. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index b34dec5..687f766 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -686,13 +686,19 @@ static void __start_all(void) if (!all_stopped) PR_ERROR("starting while not all stopped\n"); - for_each_path_target_class("thread", target) { - if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) - continue; + if (path_target_all_selected("thread", NULL)) { + if (thread_start_all()) { + PR_ERROR("Could not start threads\n"); + } + } else { + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; - if (thread_start(target)) { - PR_ERROR("Could not start thread %s\n", - pdbg_target_path(target)); + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } } } @@ -706,16 +712,10 @@ static void start_all(void) 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) continue; - target->probe(target); - status = thread_status(target); - if (!status.quiesced) - PR_ERROR("starting thread not quiesced\n"); - gdb_thread = thread->gdbserver_priv; gdb_thread->stop_attn = false; @@ -794,14 +794,20 @@ static void __stop_all(void) if (all_stopped) PR_ERROR("stopping while all stopped\n"); - for_each_path_target_class("thread", target) { - if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) - continue; + if (path_target_all_selected("thread", NULL)) { + if (thread_stop_all()) { + PR_ERROR("Could not stop threads\n"); + } + } else { + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; - if (thread_stop(target)) { - PR_ERROR("Could not stop thread %s\n", - pdbg_target_path(target)); - /* How to fix? */ + if (thread_stop(target)) { + PR_ERROR("Could not stop thread %s\n", + pdbg_target_path(target)); + /* How to fix? */ + } } } From patchwork Tue Mar 29 15:49:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610719 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=YYPkL8sl; 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 4KSYv93CC8z9sFk for ; Wed, 30 Mar 2022 02:51:01 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv92RYTz2xtT for ; Wed, 30 Mar 2022 02:51:01 +1100 (AEDT) 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=YYPkL8sl; 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::1029; helo=mail-pj1-x1029.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=YYPkL8sl; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 4KSYv63zQYz2yHB for ; Wed, 30 Mar 2022 02:50:58 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id d30so867626pjk.0 for ; Tue, 29 Mar 2022 08:50:58 -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=W9cAZDfOJs27KEAa+sTStUtS4QsFLYSPasaCCP3S0kQ=; b=YYPkL8slrbZV7KAyDui2VLfVw9mFFfZsMdfZ5DjLIeqcT/JRrWXWmame9fQ4WTn5sb jGeSHaSDjNHJJiRLPrM0EfgQ7dVDv4zKShfE1LhsDdxNgWX1BlFBcAcyyloSrEBGZmEZ FqjRf1D6G/IXvjrjwABtgG1zlnnGbB/UwhA2hJJrG9qC9Sq363ghhx6/kgetstSdkL/6 ynFP2rsLVKnHvscr0pcG0WDFt0Euwd+lgA4csaFL2TAf/iWugWSQGy5vm2GNXPLtLe8n Qvc4DA5o1I1ZikOmqMLqUEUvBS97xQ0ljSSkSvXVmaQiRZufrQJ1WLIQltYwJroPXcpw Kx/Q== 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=W9cAZDfOJs27KEAa+sTStUtS4QsFLYSPasaCCP3S0kQ=; b=XAmNRcHOGod13HTII9xXpPS5RKvcjgjJ/1uz3tJmsHu0zCsteZeSERebQMxdKUuzah A4npLy5jDOiTVoW17HJGDbxeHxYR50O+6FYY6VBuOZoNlpVLZhxePNP0sf832wQdJRNf nq5j/lEFfKepraoekF8EyNDtLB4l84cxiPJnJSjZkrxNWEoWMbDItz4uJSq5QcsEsPns vRLC0c4o6BvH7++sNzneDLX88udTmXKoZQTHqzboSN8CblMH/nx8su3w/CM1i6mPEJx/ qWa1rx1tPKXwBkPy2MHKb4HFb/0JmYF1Rwg0KTeItUob+vXq5XrI1KL163hfWTucvNOg A1gA== X-Gm-Message-State: AOAM533384yzDHnnuom8PXqYj+NiqAdBztyqgyDZTqN0rgeNkPxOd3zb 4qFz48jSkEuCBGJe0tYB6JhOQPzD8V4= X-Google-Smtp-Source: ABdhPJzzOu38hPgVsCpEwzO0xhKBBBbAu9djY+W8g51MGVCd4FPOPaXSw4L+29R35NkZXyxhjgyHIw== X-Received: by 2002:a17:903:3051:b0:156:2d03:3434 with SMTP id u17-20020a170903305100b001562d033434mr3831738pla.101.1648569056379; Tue, 29 Mar 2022 08:50:56 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:56 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:30 +1000 Message-Id: <20220329154931.493851-38-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 37/38] gdbserver: handle gdb breakpoint commands 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" Handle the z/Z breakpoint clear/set gdb commands and maintain the list of breakpoints in the server. This allows breakpoint matching to distinguish between attn in host software, and avoids the problematic gdb break op logic in put_mem. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 5 + src/gdb_parser_precompile.c | 343 ++++++++++++++++++++---------------- src/pdbgproxy.c | 214 +++++++++++++++++++++- src/pdbgproxy.h | 1 + 4 files changed, 401 insertions(+), 162 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index abb361a..4404833 100644 --- a/src/gdb_parser.rl +++ b/src/gdb_parser.rl @@ -121,6 +121,10 @@ qf_threadinfo = ('qfThreadInfo' @{cmd = QF_THREADINFO;}); qs_threadinfo = ('qsThreadInfo' @{cmd = QS_THREADINFO;}); + # breakpoints + set_break = ('Z0,' xdigit+ $hex_digit %push ',4' @{cmd = SET_BREAK;}); + clear_break = ('z0,' xdigit+ $hex_digit %push ',4' @{cmd = CLEAR_BREAK;}); + # vCont packet parsing v_contq = ('vCont?' @{rsp = "vCont;c;C;s;S";}); v_contc = ('vCont;c' any* @{cmd = V_CONTC;}); @@ -135,6 +139,7 @@ v_contq | v_contc | v_conts | qf_threadinfo | qs_threadinfo | get_mem | put_mem | + set_break | clear_break | detach | unknown ); cmd = (('$' ((commands & ^'#'*) >reset $crc) diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index 97cdae2..68502ac 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -11,7 +11,7 @@ #include "debug.h" -#line 149 "src/gdb_parser.rl" +#line 154 "src/gdb_parser.rl" static enum gdb_command cmd = NONE; @@ -31,86 +31,96 @@ static bool ack_mode = true; #line 32 "src/gdb_parser.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 14, 1, 24, 1, 25, 1, - 26, 1, 27, 2, 0, 1, 2, 2, + 3, 1, 14, 1, 26, 1, 27, 1, + 28, 1, 29, 2, 0, 1, 2, 2, 1, 2, 3, 1, 2, 3, 5, 2, 4, 1, 2, 13, 1, 2, 14, 1, 2, 15, 1, 2, 16, 1, 2, 17, 1, 2, 19, 1, 2, 20, 1, 2, 21, 1, 2, 22, 1, 2, 23, 1, - 3, 0, 6, 1, 3, 0, 7, 1, - 3, 0, 9, 1, 3, 0, 10, 1, - 3, 0, 11, 1, 3, 0, 12, 1, - 3, 2, 8, 1, 3, 3, 18, 1 - + 2, 24, 1, 2, 25, 1, 3, 0, + 6, 1, 3, 0, 7, 1, 3, 0, + 9, 1, 3, 0, 10, 1, 3, 0, + 11, 1, 3, 0, 12, 1, 3, 2, + 8, 1, 3, 3, 18, 1 }; static const short _gdb_key_offsets[] = { - 0, 0, 12, 13, 19, 25, 32, 39, - 41, 43, 50, 58, 66, 73, 80, 88, - 95, 103, 110, 112, 114, 116, 118, 120, - 122, 124, 126, 128, 130, 132, 134, 136, - 138, 140, 147, 155, 163, 170, 177, 185, - 191, 193, 195, 197, 199, 201, 203, 205, - 207, 214, 216, 218, 220, 222, 224, 226, - 228, 230, 232, 233, 235, 237, 239, 241, - 243, 245, 247, 249, 251, 253, 255, 257, - 259, 261, 263, 265, 267, 269, 271, 273, - 275, 277, 279, 281, 284, 287, 288, 289 + 0, 0, 14, 15, 21, 27, 34, 41, + 43, 45, 52, 60, 68, 75, 82, 90, + 97, 105, 112, 114, 116, 118, 120, 122, + 124, 126, 128, 130, 132, 134, 136, 138, + 140, 142, 149, 157, 165, 172, 174, 176, + 183, 191, 193, 200, 208, 214, 216, 218, + 220, 222, 224, 226, 228, 230, 237, 239, + 241, 243, 245, 247, 249, 251, 253, 255, + 256, 258, 260, 262, 264, 266, 268, 270, + 272, 274, 276, 278, 280, 282, 284, 286, + 288, 290, 292, 294, 296, 298, 300, 302, + 304, 307, 310, 311, 312, 314, 316, 323, + 331, 333 }; static const char _gdb_trans_keys[] = { - 35, 63, 68, 72, 77, 81, 84, 103, - 109, 112, 113, 118, 35, 48, 57, 65, - 70, 97, 102, 48, 57, 65, 70, 97, - 102, 35, 48, 57, 65, 70, 97, 102, - 35, 48, 57, 65, 70, 97, 102, 35, - 103, 35, 112, 35, 48, 57, 65, 70, - 97, 102, 35, 46, 48, 57, 65, 70, - 97, 102, 35, 112, 48, 57, 65, 70, + 35, 63, 68, 72, 77, 81, 84, 90, + 103, 109, 112, 113, 118, 122, 35, 48, + 57, 65, 70, 97, 102, 48, 57, 65, + 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, 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, - 58, 48, 57, 65, 70, 97, 102, 35, - 48, 57, 65, 70, 97, 102, 35, 83, - 35, 116, 35, 97, 35, 114, 35, 116, - 35, 78, 35, 111, 35, 65, 35, 99, - 35, 107, 35, 77, 35, 111, 35, 100, - 35, 101, 35, 112, 35, 48, 57, 65, - 70, 97, 102, 35, 46, 48, 57, 65, - 70, 97, 102, 35, 112, 48, 57, 65, + 102, 35, 103, 35, 112, 35, 48, 57, + 65, 70, 97, 102, 35, 46, 48, 57, + 65, 70, 97, 102, 35, 112, 48, 57, + 65, 70, 97, 102, 35, 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, 65, 67, 83, 102, 115, 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, 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, 43, 45, 0 + 102, 35, 58, 48, 57, 65, 70, 97, + 102, 35, 48, 57, 65, 70, 97, 102, + 35, 83, 35, 116, 35, 97, 35, 114, + 35, 116, 35, 78, 35, 111, 35, 65, + 35, 99, 35, 107, 35, 77, 35, 111, + 35, 100, 35, 101, 35, 112, 35, 48, + 57, 65, 70, 97, 102, 35, 46, 48, + 57, 65, 70, 97, 102, 35, 112, 48, + 57, 65, 70, 97, 102, 35, 48, 57, + 65, 70, 97, 102, 35, 48, 35, 44, + 35, 48, 57, 65, 70, 97, 102, 35, + 44, 48, 57, 65, 70, 97, 102, 35, + 52, 35, 48, 57, 65, 70, 97, 102, + 35, 44, 48, 57, 65, 70, 97, 102, + 35, 65, 67, 83, 102, 115, 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, 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, + 35, 48, 35, 44, 35, 48, 57, 65, + 70, 97, 102, 35, 44, 48, 57, 65, + 70, 97, 102, 35, 52, 3, 36, 43, + 45, 0 }; static const char _gdb_single_lengths[] = { - 0, 12, 1, 0, 0, 1, 1, 2, + 0, 14, 1, 0, 0, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 1, 2, 2, 1, 1, 2, 6, + 2, 1, 2, 2, 1, 2, 2, 1, + 2, 2, 1, 2, 6, 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, - 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, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 3, 3, 1, 1, 4 + 3, 3, 1, 1, 2, 2, 1, 2, + 2, 4 }; static const char _gdb_range_lengths[] = { @@ -118,125 +128,138 @@ static const char _gdb_range_lengths[] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 3, 3, 3, 3, 3, 0, + 0, 3, 3, 3, 3, 0, 0, 3, + 3, 0, 3, 3, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 3, 0, 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, 0, - 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 3, 3, + 0, 0 }; static const short _gdb_index_offsets[] = { - 0, 0, 13, 15, 19, 23, 28, 33, - 36, 39, 44, 50, 56, 61, 66, 72, - 77, 83, 88, 91, 94, 97, 100, 103, - 106, 109, 112, 115, 118, 121, 124, 127, - 130, 133, 138, 144, 150, 155, 160, 166, - 173, 176, 179, 182, 185, 188, 191, 194, - 197, 202, 205, 208, 211, 214, 217, 220, - 223, 226, 229, 231, 234, 237, 240, 243, - 246, 249, 252, 255, 258, 261, 264, 267, - 270, 273, 276, 279, 282, 285, 288, 291, - 294, 297, 300, 303, 307, 311, 313, 315 + 0, 0, 15, 17, 21, 25, 30, 35, + 38, 41, 46, 52, 58, 63, 68, 74, + 79, 85, 90, 93, 96, 99, 102, 105, + 108, 111, 114, 117, 120, 123, 126, 129, + 132, 135, 140, 146, 152, 157, 160, 163, + 168, 174, 177, 182, 188, 195, 198, 201, + 204, 207, 210, 213, 216, 219, 224, 227, + 230, 233, 236, 239, 242, 245, 248, 251, + 253, 256, 259, 262, 265, 268, 271, 274, + 277, 280, 283, 286, 289, 292, 295, 298, + 301, 304, 307, 310, 313, 316, 319, 322, + 325, 329, 333, 335, 337, 340, 343, 348, + 354, 357 }; static const char _gdb_indicies[] = { 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 0, 14, 13, 15, - 15, 15, 16, 17, 17, 17, 16, 14, - 18, 18, 18, 13, 19, 18, 18, 18, - 13, 14, 20, 13, 14, 21, 13, 14, - 22, 22, 22, 13, 14, 23, 22, 22, - 22, 13, 14, 21, 24, 24, 24, 13, - 19, 24, 24, 24, 13, 14, 25, 25, - 25, 13, 14, 26, 25, 25, 25, 13, - 14, 27, 27, 27, 13, 14, 28, 27, - 27, 27, 13, 14, 29, 29, 29, 13, - 14, 30, 13, 14, 31, 13, 14, 32, - 13, 14, 33, 13, 14, 34, 13, 14, - 35, 13, 14, 36, 13, 14, 37, 13, - 14, 38, 13, 14, 39, 13, 14, 40, - 13, 14, 41, 13, 14, 42, 13, 14, - 43, 13, 14, 44, 13, 14, 45, 45, - 45, 13, 14, 46, 45, 45, 45, 13, - 14, 44, 47, 47, 47, 13, 14, 47, - 47, 47, 13, 14, 48, 48, 48, 13, - 14, 49, 48, 48, 48, 13, 14, 50, - 51, 52, 53, 54, 13, 14, 55, 13, - 14, 56, 13, 14, 57, 13, 14, 58, - 13, 14, 59, 13, 14, 60, 13, 14, - 61, 13, 14, 62, 13, 14, 63, 63, - 63, 13, 14, 64, 13, 14, 65, 13, - 14, 66, 13, 14, 67, 13, 14, 68, - 13, 14, 69, 13, 14, 70, 13, 14, - 71, 13, 14, 72, 13, 74, 73, 14, - 75, 13, 14, 76, 13, 14, 77, 13, - 14, 78, 13, 14, 79, 13, 14, 80, - 13, 14, 81, 13, 14, 82, 13, 14, - 83, 13, 14, 84, 13, 14, 85, 13, - 14, 86, 13, 14, 87, 13, 14, 88, - 13, 14, 89, 13, 14, 90, 13, 14, - 91, 13, 14, 92, 13, 14, 93, 13, - 14, 94, 13, 14, 95, 13, 14, 96, - 13, 14, 97, 13, 14, 98, 13, 14, - 99, 100, 13, 14, 101, 102, 13, 14, - 103, 14, 104, 105, 106, 107, 108, 16, - 0 + 9, 10, 11, 12, 13, 14, 0, 16, + 15, 17, 17, 17, 18, 19, 19, 19, + 18, 16, 20, 20, 20, 15, 21, 20, + 20, 20, 15, 16, 22, 15, 16, 23, + 15, 16, 24, 24, 24, 15, 16, 25, + 24, 24, 24, 15, 16, 23, 26, 26, + 26, 15, 21, 26, 26, 26, 15, 16, + 27, 27, 27, 15, 16, 28, 27, 27, + 27, 15, 16, 29, 29, 29, 15, 16, + 30, 29, 29, 29, 15, 16, 31, 31, + 31, 15, 16, 32, 15, 16, 33, 15, + 16, 34, 15, 16, 35, 15, 16, 36, + 15, 16, 37, 15, 16, 38, 15, 16, + 39, 15, 16, 40, 15, 16, 41, 15, + 16, 42, 15, 16, 43, 15, 16, 44, + 15, 16, 45, 15, 16, 46, 15, 16, + 47, 47, 47, 15, 16, 48, 47, 47, + 47, 15, 16, 46, 49, 49, 49, 15, + 16, 49, 49, 49, 15, 16, 50, 15, + 16, 51, 15, 16, 52, 52, 52, 15, + 16, 53, 52, 52, 52, 15, 16, 54, + 15, 16, 55, 55, 55, 15, 16, 56, + 55, 55, 55, 15, 16, 57, 58, 59, + 60, 61, 15, 16, 62, 15, 16, 63, + 15, 16, 64, 15, 16, 65, 15, 16, + 66, 15, 16, 67, 15, 16, 68, 15, + 16, 69, 15, 16, 70, 70, 70, 15, + 16, 71, 15, 16, 72, 15, 16, 73, + 15, 16, 74, 15, 16, 75, 15, 16, + 76, 15, 16, 77, 15, 16, 78, 15, + 16, 79, 15, 81, 80, 16, 82, 15, + 16, 83, 15, 16, 84, 15, 16, 85, + 15, 16, 86, 15, 16, 87, 15, 16, + 88, 15, 16, 89, 15, 16, 90, 15, + 16, 91, 15, 16, 92, 15, 16, 93, + 15, 16, 94, 15, 16, 95, 15, 16, + 96, 15, 16, 97, 15, 16, 98, 15, + 16, 99, 15, 16, 100, 15, 16, 101, + 15, 16, 102, 15, 16, 103, 15, 16, + 104, 15, 16, 105, 15, 16, 106, 107, + 15, 16, 108, 109, 15, 16, 110, 16, + 111, 16, 112, 15, 16, 113, 15, 16, + 114, 114, 114, 15, 16, 115, 114, 114, + 114, 15, 16, 116, 15, 117, 118, 119, + 120, 18, 0 }; static const char _gdb_trans_targs[] = { 2, 3, 2, 5, 7, 13, 18, 32, - 2, 37, 5, 39, 79, 2, 3, 4, - 0, 87, 6, 3, 8, 9, 10, 11, - 12, 14, 15, 16, 17, 17, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 2, 33, 34, 35, 36, - 38, 5, 40, 2, 49, 59, 69, 41, - 42, 43, 44, 45, 46, 47, 48, 48, - 50, 51, 52, 53, 54, 55, 56, 57, - 58, 2, 3, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 2, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 2, 80, - 81, 82, 83, 84, 2, 85, 86, 85, - 86, 87, 1, 87, 87 + 37, 2, 42, 5, 44, 84, 92, 2, + 3, 4, 0, 97, 6, 3, 8, 9, + 10, 11, 12, 14, 15, 16, 17, 17, + 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 2, 33, 34, + 35, 36, 38, 39, 40, 41, 2, 43, + 5, 45, 2, 54, 64, 74, 46, 47, + 48, 49, 50, 51, 52, 53, 53, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 2, 3, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 2, 75, 76, 77, 78, + 79, 80, 81, 82, 83, 2, 85, 86, + 87, 88, 89, 2, 90, 91, 90, 91, + 93, 94, 95, 96, 2, 97, 1, 97, + 97 }; static const char _gdb_trans_actions[] = { - 19, 1, 80, 84, 19, 68, 19, 19, - 72, 64, 76, 19, 19, 3, 0, 7, - 0, 28, 25, 5, 3, 3, 3, 3, - 92, 25, 22, 25, 88, 31, 3, 3, + 19, 1, 86, 90, 19, 74, 19, 19, + 19, 78, 70, 82, 19, 19, 19, 3, + 0, 7, 0, 28, 25, 5, 3, 3, + 3, 3, 98, 25, 22, 25, 94, 31, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 40, 3, 3, 3, 43, - 25, 22, 3, 46, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 34, + 3, 3, 3, 3, 3, 40, 3, 3, + 3, 43, 3, 3, 25, 22, 55, 25, + 22, 3, 46, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 34, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 37, 9, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 49, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 52, 3, - 3, 3, 3, 3, 55, 3, 3, 58, - 61, 11, 13, 15, 17 + 37, 9, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 49, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 52, 3, 3, + 3, 3, 3, 61, 3, 3, 64, 67, + 3, 3, 25, 22, 58, 11, 13, 15, + 17 }; -static const int gdb_start = 87; -static const int gdb_first_final = 87; +static const int gdb_start = 97; +static const int gdb_first_final = 97; static const int gdb_error = 0; -static const int gdb_en_main = 87; +static const int gdb_en_main = 97; -#line 165 "src/gdb_parser.rl" +#line 170 "src/gdb_parser.rl" void parser_init(command_cb *callbacks) { -#line 235 "src/gdb_parser.c" +#line 258 "src/gdb_parser.c" { cs = gdb_start; } -#line 169 "src/gdb_parser.rl" +#line 174 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -247,7 +270,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len; -#line 251 "src/gdb_parser.c" +#line 274 "src/gdb_parser.c" { int _klen; unsigned int _trans; @@ -470,33 +493,41 @@ _match: break; case 21: #line 125 "src/gdb_parser.rl" - {rsp = "vCont;c;C;s;S";} + {cmd = SET_BREAK;} break; case 22: #line 126 "src/gdb_parser.rl" - {cmd = V_CONTC;} + {cmd = CLEAR_BREAK;} break; case 23: -#line 127 "src/gdb_parser.rl" - {cmd = V_CONTS;} +#line 129 "src/gdb_parser.rl" + {rsp = "vCont;c;C;s;S";} break; case 24: #line 130 "src/gdb_parser.rl" - { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} + {cmd = V_CONTC;} break; case 25: -#line 141 "src/gdb_parser.rl" - {PR_INFO("RAGEL:cmd\n");} +#line 131 "src/gdb_parser.rl" + {cmd = V_CONTS;} break; case 26: -#line 144 "src/gdb_parser.rl" - {PR_INFO("RAGEL:ack\n");} +#line 134 "src/gdb_parser.rl" + { if (command_callbacks) command_callbacks[INTERRUPT](stack, priv); PR_INFO("RAGEL:interrupt\n");} break; case 27: -#line 145 "src/gdb_parser.rl" +#line 146 "src/gdb_parser.rl" + {PR_INFO("RAGEL:cmd\n");} + break; + case 28: +#line 149 "src/gdb_parser.rl" + {PR_INFO("RAGEL:ack\n");} + break; + case 29: +#line 150 "src/gdb_parser.rl" {PR_INFO("RAGEL:nack\n");} break; -#line 500 "src/gdb_parser.c" +#line 531 "src/gdb_parser.c" } } @@ -509,7 +540,7 @@ _again: _out: {} } -#line 179 "src/gdb_parser.rl" +#line 184 "src/gdb_parser.rl" if (cs == gdb_error) { printf("parse error\n"); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 687f766..c257361 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -664,6 +664,192 @@ out: send_response(fd, OK); } +#define MAX_BPS 64 +static uint64_t bps[MAX_BPS]; +static uint32_t saved_insn[MAX_BPS]; +static int nr_bps = 0; + +static int set_bp(uint64_t addr) +{ + int i; + + if (nr_bps == MAX_BPS) + return -1; + + if (addr == -1ULL) + return -1; + + for (i = 0; i < MAX_BPS; i++) { + if (bps[i] == -1ULL) { + bps[i] = addr; + nr_bps++; + return 0; + } + } + + return -1; +} + +static int clear_bp(uint64_t addr) +{ + int i; + + if (nr_bps == 0) + return -1; + + if (addr == -1ULL) + return -1; + + for (i = 0; i < MAX_BPS; i++) { + if (bps[i] == addr) { + bps[i] = -1ULL; + nr_bps--; + return 0; + } + } + + return -1; +} + +static int get_insn(uint64_t addr, uint32_t *insn) +{ + uint64_t linear_map; + + linear_map = get_real_addr(addr); + if (linear_map != -1UL) { + if (read_memory(linear_map, 4, insn, 1)) { + PR_ERROR("Unable to read memory\n"); + return -1; + } + } else { + /* Virtual address */ + return -1; + } + + return 0; +} + +static int put_insn(uint64_t addr, uint32_t insn) +{ + uint64_t linear_map; + + linear_map = get_real_addr(addr); + if (linear_map != -1UL) { + if (write_memory(linear_map, 4, &insn, 8)) { + PR_ERROR("Unable to write memory\n"); + return -1; + } + } else { + /* Virtual address */ + return -1; + } + + return 0; +} + +static void init_breakpoints(void) +{ + int i; + + for (i = 0; i < MAX_BPS; i++) + bps[i] = -1ULL; +} + +static bool match_breakpoint(uint64_t addr) +{ + int i; + + if (nr_bps == 0) + return false; + + for (i = 0; i < MAX_BPS; i++) { + if (bps[i] == addr) + return true; + } + + return false; +} + +static int install_breakpoints(void) +{ + uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; + uint32_t *attn = (uint32_t *)&attn_opcode[0]; + uint64_t msr; + int i; + + if (!nr_bps) + return 0; + + /* Check endianess in MSR */ + if (thread_getmsr(thread_target, &msr)) { + PR_ERROR("Couldn't read the MSR to set breakpoint endian"); + return -1; + } + + if (msr & 1) /* currently little endian */ + *attn = bswap_32(*attn); + + for (i = 0; i < MAX_BPS; i++) { + if (bps[i] == -1ULL) + continue; + if (get_insn(bps[i], &saved_insn[i])) + continue; /* XXX: handle properly */ + if (put_insn(bps[i], *attn)) + continue; /* XXX: handle properly */ + } + + set_attn(true); + + return 0; +} + +static int uninstall_breakpoints(void) +{ + int i; + + if (!nr_bps) + return 0; + + for (i = 0; i < MAX_BPS; i++) { + if (bps[i] == -1ULL) + continue; + if (put_insn(bps[i], saved_insn[i])) + continue; /* XXX: handle properly */ + + } + + set_attn(false); + + return 0; +} + + +static void set_break(uint64_t *stack, void *priv) +{ + uint64_t addr; + + /* stack[0] is the address */ + addr = stack[0]; + + if (!set_bp(addr)) + send_response(fd, OK); + else + send_response(fd, ERROR(ENOMEM)); +} + +static void clear_break(uint64_t *stack, void *priv) +{ + uint64_t addr; + + /* stack[0] is the address */ + addr = stack[0]; + + if (!clear_bp(addr)) + send_response(fd, OK); + else + send_response(fd, ERROR(ENOENT)); +} + static void v_conts(uint64_t *stack, void *priv) { struct thread *thread = target_to_thread(thread_target); @@ -709,6 +895,8 @@ static void start_all(void) { struct pdbg_target *target; + install_breakpoints(); + for_each_path_target_class("thread", target) { struct thread *thread = target_to_thread(target); struct gdb_thread *gdb_thread; @@ -843,14 +1031,26 @@ static void stop_all(void) gdb_thread->stop_attn = true; if (!(status.active)) - PR_ERROR("Error thread inactive after trap\n"); - /* Restore NIA to before break */ + PR_ERROR("Error thread inactive after attn\n"); + if (thread_getnia(target, &nia)) PR_ERROR("Error during getnia\n"); - if (thread_putnia(target, nia - 4)) - PR_ERROR("Error during putnia\n"); + + /* + * If we hit a non-breakpoint attn we still want to + * switch to that thread, but we don't rewind the nip + * so as to advance over the attn. + */ + if (match_breakpoint(nia - 4)) { + PR_INFO("thread pir=%llx attn is breakpoint\n", gdb_thread->pir); + /* Restore NIA to breakpoint address */ + if (thread_putnia(target, nia - 4)) + PR_ERROR("Error during putnia\n"); + } } } + + uninstall_breakpoints(); } static void interrupt(uint64_t *stack, void *priv) @@ -918,8 +1118,6 @@ static void poll(void) } } - set_attn(false); - state = IDLE; poll_interval = VCONT_POLL_DELAY; @@ -991,6 +1189,8 @@ static command_cb callbacks[LAST_CMD + 1] = { qs_threadinfo, get_mem, put_mem, + set_break, + clear_break, interrupt, detach, NULL}; @@ -1107,6 +1307,8 @@ static int gdbserver(uint16_t port) struct pdbg_target *first_stopped_target = NULL; struct pdbg_target *first_attn_target = NULL; + init_breakpoints(); + for_each_path_target_class("thread", target) { struct thread *thread = target_to_thread(target); struct gdb_thread *gdb_thread; diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h index cafd4cb..6a89444 100644 --- a/src/pdbgproxy.h +++ b/src/pdbgproxy.h @@ -6,6 +6,7 @@ enum gdb_command {NONE, GET_GPRS, GET_SPR, V_CONTC, V_CONTS, QF_THREADINFO, QS_THREADINFO, GET_MEM, PUT_MEM, + SET_BREAK, CLEAR_BREAK, INTERRUPT, DETACH, LAST_CMD}; typedef void (*command_cb)(uint64_t *stack, void *priv); From patchwork Tue Mar 29 15:49:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610720 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=BoET/a9+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYvB33l1z9sFk for ; Wed, 30 Mar 2022 02:51:02 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYvB2D8Kz2xvv for ; Wed, 30 Mar 2022 02:51:02 +1100 (AEDT) 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=BoET/a9+; 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::1036; helo=mail-pj1-x1036.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=BoET/a9+; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 4KSYv814pxz2xfP for ; Wed, 30 Mar 2022 02:51:00 +1100 (AEDT) Received: by mail-pj1-x1036.google.com with SMTP id o3-20020a17090a3d4300b001c6bc749227so3308427pjf.1 for ; Tue, 29 Mar 2022 08:51:00 -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=3p590vNkPmwGGmVyewt9nVSJJxUU1xdowYrQdntA/IU=; b=BoET/a9+RkyLM8W7vlouxyZjknLvvjycmq25KTbuaR0esFqzLVTr8WZrK3i/7/Ynkl 8Rb3nIFbpPJVa6qIuaDDtrZkwjXzokWi10WnqIZj8fRhstYoj2YicBtnUGbhz//tpN5e ErPQUwRRYlXzsdbfb6RYAZrteVZa1/5UsLdYo4KbnYZbWihcA2B1ct1chq2hEfA1/PR+ 0BmO2IWGynoSaxeI3/Uukw+X2dnk0KNqnvi6QRmFVMbHXnsUxDjY7Lhy4QnA/T7rDj5T 1l3lOu+b0PeW/nTRK+GClCC3fL1poCHjM/U84AG4r01yNfSCwd4wHsOPSo6KnMIT1MjV ITNQ== 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=3p590vNkPmwGGmVyewt9nVSJJxUU1xdowYrQdntA/IU=; b=YwI9Q5TuMK6WMP15m/6aQwcrm52NC9xqudVvOccu6czbIYNd5Fq2BfKC01/QSqr8wy Z/8GpfwoC8BtHvvrrASOuIIpbQ7BW/9Mbar3abyLyacBv77MMVH7Z8v2cCluH7R1pqq3 23NP09MMwqYg1b85c4MYvW8hiFIirwXfQ0IBcxfaA4SOSsk5NPqPp6D0hZpFmHwmwuG6 IV5Hw/AV2o5ZMm0PsO2rjsorqOZ7ygAQvfOIVwUh2Ei9zn3Ttq+chQGpSM2QxBIsHNvj /CD1B7UGQE/2KqikQXdIBrI0sdJKvUbcVYAd8hYZlafwj89nchbbiZ6qY5nljXevU8Tq IfCA== X-Gm-Message-State: AOAM53317kXrGz+aeRsDsqEnCwNjmy9HYbVigOsOg8X+b/ZZ43TM1X8z nEQ4q0rYXFVOXJF9fv+uBlMsdEfGBYw= X-Google-Smtp-Source: ABdhPJxjdNzWkeNJBCAtMSQdKjORovpDKnPNa0xTWA/L0pWkcPZWthBonNMQ3wC0P//z6iV+6pgRZQ== X-Received: by 2002:a17:903:18c:b0:154:9ee:ced3 with SMTP id z12-20020a170903018c00b0015409eeced3mr30963900plg.170.1648569058338; Tue, 29 Mar 2022 08:50:58 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:58 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:31 +1000 Message-Id: <20220329154931.493851-39-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 38/38] gdbserver: remove fallback breakpoint support in put_mem 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" With breakpoint ops implemented, gdb does not need to write its break op directly, which allows that hackly logic to be removed. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c257361..f4b592e 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -603,8 +603,6 @@ static void put_mem(uint64_t *stack, void *priv) { uint64_t addr, len; uint8_t *data; - uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; - uint8_t gdb_break_opcode[] = {0x7d, 0x82, 0x10, 0x08}; int err = 0; addr = stack[0]; @@ -618,38 +616,6 @@ static void put_mem(uint64_t *stack, void *priv) goto out; } - if (len == 4 && !memcmp(data, gdb_break_opcode, 4)) { - uint64_t msr; - - /* Check endianess in MSR */ - err = thread_getmsr(thread_target, &msr); - if (err) { - PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); - goto out; - } - if (msr & 1) { /* little endian */ - attn_opcode[1] = 0x02; - attn_opcode[2] = 0x00; - } - - /* 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 (set_attn(true)) { - err = 2; - goto out; - } - } - if (write_memory(addr, len, data, 8)) { PR_ERROR("Unable to write memory\n"); err = 3;