From patchwork Wed Apr 20 06:49:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619328 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=TdTgzXpU; 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 4KjrsX51TNz9sG0 for ; Wed, 20 Apr 2022 16:50:40 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrsX3rsVz2ym7 for ; Wed, 20 Apr 2022 16:50:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TdTgzXpU; 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::52f; helo=mail-pg1-x52f.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=TdTgzXpU; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (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 4KjrsL4mgZz2xnM for ; Wed, 20 Apr 2022 16:50:28 +1000 (AEST) Received: by mail-pg1-x52f.google.com with SMTP id r83so800446pgr.2 for ; Tue, 19 Apr 2022 23:50:28 -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=Q4215VEPSv9gm3PPi5xMtpWAW3++hZFZysnojjZetpk=; b=TdTgzXpU+iQ9amaYmQdV9lHlBj4byNb9Drh2tcntemkEzu7mOuUfhQNrd1hlIcQIyO K9ILAPsTdRPlYtZe8ht0UKqOHEHPuNofIAV7O2kS02oTVHic2azZ8KU1zza9zcQu2/bG 39XkhsWUYmgDL2BIBWBQkl9anpDxxzPL4R3ODcn2LE7csGNy3/4dnkMYSDMSSeUWETsd G6VGBqHvz4RuLLR2Cd3Wwgiwnb5+XciFjIR9DuUZoK6xLZcNtlPzK0YMNmrw/nQ1KErs BdYBvvjR3+eNooJ+WCPN3VYKid5MLUSEv4HGEslzeFP2av5DWIhkqojeHGmKAtumgyGX lCbg== 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=Q4215VEPSv9gm3PPi5xMtpWAW3++hZFZysnojjZetpk=; b=Zualx4yYG9eS3M5NG3IaqHRIvF/mx57+LJqGrU+3FePP9pFN0a3wEVURj+QfaVYOLy 1x/eYODOYTYnApCWFe/BbhEbeh2elDFr0agArTpRGehlh27B0Qw+rUoMrE+/N+4B+GSO G7Ex/lJ1bW2n5ZVtjoX8lNlWW4XthuD4srl5ottfFEPAOTcqNEkMO3a1xQx+NDqEaGJ/ lWCOSEnRwMaPs5fdOiHSnTw7QhifHpQK+ls4r3GuHCuvm5fprr1+ukkP8jZgSsa3Q5yJ k0duG3G2P5SNrr+Ncl67zM/yI33yAc7f5gTfTHOPUdYHBHaikFhOvUbgYw/VRsajKOvT Zyag== X-Gm-Message-State: AOAM531AKn9dJuhJyFg8rG4zcqiyXcwti8fmLO2vzr584gYGgjoZuKlv MTAJpTodLoU/jQakksxN7HvCZLsL3SLYqg== X-Google-Smtp-Source: ABdhPJwLoqv3tFuZ0ogMCz7djrfrWCII+/OsNXhoHSwPJPBZmkvkfLcBFtpwdYNLTkG4fUXyDa60gg== X-Received: by 2002:a63:a902:0:b0:398:cdd3:f85e with SMTP id u2-20020a63a902000000b00398cdd3f85emr18025127pge.122.1650437425633; Tue, 19 Apr 2022 23:50:25 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:25 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:35 +1000 Message-Id: <20220420065013.222816-2-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 01/39] 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 e0d9ee21..70481f1f 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 9fddaf64..0ac53542 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 Wed Apr 20 06:49:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619326 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=PUJZuF+5; 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) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KjrsV0tfyz9sG2 for ; Wed, 20 Apr 2022 16:50:38 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrsT3ncLz2yn1 for ; Wed, 20 Apr 2022 16:50:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=PUJZuF+5; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::533; helo=mail-pg1-x533.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=PUJZuF+5; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KjrsL4ypPz2xrv for ; Wed, 20 Apr 2022 16:50:30 +1000 (AEST) Received: by mail-pg1-x533.google.com with SMTP id t13so777094pgn.8 for ; Tue, 19 Apr 2022 23:50:30 -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=OpD3Jsfg0Ql6ys1zn90v/2w+Fj+1imv+ZGuE8AIsmCs=; b=PUJZuF+5BqoofwvLrpADWNVX0G11x0ylqs4GFzvMfK+2aI/SC76KSacbh6APrfFpGH r1mv4w5/WNns9JW/37+5brT9dXtpARdbYrUvNN+DtuBH7yWvUH4OCoHcpUj21OuCmvR8 7kjcD2tkGQ3pany+AVSfuF+ef+dm3t516+sY2XpvBMHnt5IytgODINie0nQF/NOFgY+s IHz10z12DRpw/oDZKmM2mDYQC5tVoCN3qPDZyycg2jpfjPsVM9ETHT34DPolhO3+f8sH QFrdO4UAY03fu7fl4y+dwu4FIeb08OPSKQZshc1yaRrAquRSmd/XzJbUlOq8Z/7L6Ujq wU1Q== 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=OpD3Jsfg0Ql6ys1zn90v/2w+Fj+1imv+ZGuE8AIsmCs=; b=O7sls4phS2kts0PI3/idhXorz0ayVBrAXG7NRBfUjc+yRPHE7l3Trmot8ydrBpSnTg sByAN0QUBU64YAervXcChQNBebQGsY3xJs3HETi/MMcmnmvNcsFXVbF58IPBf58+l5Mb cVNpWFDrsaYdfJBFRi5XFc759MEwe+D6ImKqekO9uvvnC/NO2T3Ts0Pd6IKRtpEPBDXm lSMYO5PlNSU+vao+C/O4VIEPl8MASBRSgQsOXMhyyPngspE5d5mS5lbxk8dMwQkNn+R7 8OvwkxopO6oRyYlSoCtP1XQEw13j+K6U2b8YwyIOzxsMYEMr8T5Y6pLvmj0OIDxqjxqU BN0A== X-Gm-Message-State: AOAM531Zc59L6c4A2wvsvWUtQP9edBodSieSj/dw+Fk1YB3P5ufnDUU0 5Ud5YyY6AFHhNShvkUq8xP76WW+nI9905g== X-Google-Smtp-Source: ABdhPJyhdXaZt/tEksCtXkj7PuidHEm8/7aZtRkEH7R402IDULRKFiMQUPxRIFA4U2+RQS0kPB16Gw== X-Received: by 2002:a63:ad45:0:b0:382:2459:5bc6 with SMTP id y5-20020a63ad45000000b0038224595bc6mr18537502pgo.474.1650437427814; Tue, 19 Apr 2022 23:50:27 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:27 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:36 +1000 Message-Id: <20220420065013.222816-3-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 02/39] gdbserver: add a 'generated' make target, update gdb_parser_precompile.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" 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 Update the file to fix this. Add a 'generated' target that can recreate shipped generated files like this. Signed-off-by: Nicholas Piggin --- Makefile.am | 12 ++ README.md | 7 ++ src/gdb_parser_precompile.c | 233 ++++++++++++++++++------------------ 3 files changed, 138 insertions(+), 114 deletions(-) diff --git a/Makefile.am b/Makefile.am index 90a2ff3c..4f7cdbdf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -339,4 +339,16 @@ p9z-fsi.dts: p9z-fsi.dts.m4 p9-fsi.dtsi %.c: %.rl $(RAGEL_V)$(RAGEL) -o $@ $< +generated_targets = +if HAVE_RAGEL +generated_targets += src/gdb_parser_precompile.c + +src/gdb_parser_precompile.c: src/gdb_parser.rl FORCE + $(RAGEL_V)$(RAGEL) -o $@ $< +endif + +generated: $(generated_targets) + MOSTLYCLEANFILES = *.dtb.S *.dtb $(DT) *.dt.h p9-fsi.dtsi src/gdb_parser.c + +FORCE: diff --git a/README.md b/README.md index 316976e8..40450e43 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,13 @@ make rsync pdbg root@bmc:/usr/local/bin ``` +### Updating generated files + +Some generated files are shipped with the source to reduce the toolchain +requirement for builds. Currently src/gdb_parser.rl creates +src/gdb_parser_precompile.c so that needs to be updated if the .rl file is +changed. `make generated` to update such generated files. + ## Testing There is a test suite to perform some basic testing. The tests on the host diff --git a/src/gdb_parser_precompile.c b/src/gdb_parser_precompile.c index 715cdd7f..6012a271 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; @@ -20,7 +20,7 @@ static int cs; command_cb *command_callbacks; -#line 24 "src/gdb_parser.c" +#line 24 "src/gdb_parser_precompile.c" static const char _gdb_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 2, 1, 0, 2, 2, 1, 2, @@ -29,56 +29,56 @@ 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, 3, 6, + 2, 1, 3, 6, 3, 1 }; -static const char _gdb_key_offsets[] = { - 0, 0, 2, 13, 14, 20, 26, 29, - 37, 45, 46, 53, 61, 68, 77, 84, - 92, 99, 107, 114, 121, 126, 128, 130, - 132, 134, 136, 138, 140, 142, 149, 151, - 153, 155, 157, 159, 161, 163, 165, 167, - 168, 170, 172, 174, 176, 178, 180, 182, - 184, 186, 188, 190, 192, 194, 196, 199, - 202, 203, 204, 206 +static const unsigned char _gdb_key_offsets[] = { + 0, 0, 2, 14, 15, 21, 27, 30, + 38, 46, 53, 60, 61, 68, 76, 83, + 92, 99, 107, 114, 122, 127, 129, 131, + 133, 135, 137, 139, 141, 143, 150, 152, + 154, 156, 158, 160, 162, 164, 166, 168, + 169, 171, 173, 175, 177, 179, 181, 183, + 185, 187, 189, 191, 193, 195, 197, 200, + 203, 204, 205, 207 }; 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, 58, 48, 57, + 65, 70, 97, 102, 35, 48, 57, 65, 70, 97, 102, 35, 44, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, 70, - 97, 102, 35, 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, 3, + 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, @@ -88,7 +88,7 @@ static const char _gdb_single_lengths[] = { 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, 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, @@ -98,71 +98,72 @@ static const char _gdb_range_lengths[] = { }; 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, + 77, 82, 88, 93, 99, 105, 108, 111, + 114, 117, 120, 123, 126, 129, 134, 137, + 140, 143, 146, 149, 152, 155, 158, 161, + 163, 166, 169, 172, 175, 178, 181, 184, + 187, 190, 193, 196, 199, 202, 205, 209, + 213, 215, 217, 220 }; 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, 27, + 27, 27, 26, 4, 28, 27, 27, 27, + 26, 4, 29, 29, 29, 26, 4, 28, + 30, 29, 29, 29, 26, 4, 31, 31, + 31, 26, 24, 28, 31, 31, 31, 26, + 4, 32, 32, 32, 3, 4, 33, 32, + 32, 32, 3, 4, 34, 35, 36, 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, + 3, 4, 46, 46, 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, + 3, 4, 56, 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, 3, 4, 71, 72, + 3, 4, 73, 74, 3, 4, 75, 4, + 76, 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 + 11, 12, 3, 18, 9, 20, 50, 5, + 0, 58, 6, 2, 7, 2, 8, 10, + 4, 11, 12, 13, 14, 15, 16, 17, + 19, 9, 21, 3, 30, 40, 22, 23, + 24, 25, 26, 27, 28, 29, 29, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 39, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 3, 51, 52, 53, 54, 55, + 3, 56, 57, 56, 57 }; static const char _gdb_trans_actions[] = { - 0, 60, 1, 3, 0, 3, 33, 3, - 3, 27, 21, 30, 3, 3, 7, 0, - 18, 3, 63, 0, 9, 7, 36, 24, - 71, 67, 71, 67, 71, 5, 15, 12, - 15, 3, 42, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 39, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 45, + 0, 63, 1, 3, 0, 3, 33, 39, + 3, 3, 27, 21, 30, 3, 3, 7, + 0, 18, 3, 66, 0, 9, 7, 15, + 5, 36, 24, 74, 70, 74, 70, 74, + 15, 12, 3, 45, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 42, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 48, 3, 3, 3, 3, 3, 51, - 3, 3, 54, 57 + 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; @@ -172,17 +173,17 @@ static const int gdb_error = 0; static const int gdb_en_main = 58; -#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 182 "src/gdb_parser_precompile.c" { cs = gdb_start; } -#line 120 "src/gdb_parser.rl" +#line 123 "src/gdb_parser.rl" command_callbacks = callbacks; } @@ -193,7 +194,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len + 1; -#line 197 "src/gdb_parser.c" +#line 198 "src/gdb_parser_precompile.c" { int _klen; unsigned int _trans; @@ -349,38 +350,42 @@ _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" +#line 389 "src/gdb_parser_precompile.c" } } @@ -393,7 +398,7 @@ _again: _out: {} } -#line 130 "src/gdb_parser.rl" +#line 133 "src/gdb_parser.rl" return 0; } From patchwork Wed Apr 20 06:49:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619329 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=QAjvw12T; 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 4KjrsY4STnz9sG0 for ; Wed, 20 Apr 2022 16:50:41 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrsY3hgkz301s for ; Wed, 20 Apr 2022 16:50:41 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QAjvw12T; 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=QAjvw12T; 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 4KjrsN5zCMz2xnM for ; Wed, 20 Apr 2022 16:50:32 +1000 (AEST) Received: by mail-pg1-x52b.google.com with SMTP id x191so792681pgd.4 for ; Tue, 19 Apr 2022 23:50:32 -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=zXXHY8iTAKWb6/xj9B8LUfS10em3CNeE5Cfh9LxKrmg=; b=QAjvw12TWC2piKi0m0b3VZN+ncLh3kFaJWSuE24/wfDv66DXNWoC4E6F1zMVLTnNUU XZ2FLdVDbBQIOKD2CQNCtUVX+6xCdEAt+EBqo9hEks3o/U4zCFgRjC5ZWgIJU+Sl2RpE TP4O8M6NZ0wE4WMM4FYywT8DvjXl+9u4/RQ1qSOCoCB48lXoP3NC57x7ZqmXCtPS062b /YKua8OBXE6LE94KsOOK5um7GY4ENtZpl5mZqCO7KTkxTgChmiX84QLs62L3FZ6bQ9aF 2hoCC2HMg1UD2i1SEiuMdQWh9NjXwseCqBW9JTRAKw328XSPQk6kkto3B1loCPlLFdeD AX5w== 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=zXXHY8iTAKWb6/xj9B8LUfS10em3CNeE5Cfh9LxKrmg=; b=sqUrZWRUpbDZ7fuVGv+9t6qGR8l7EA4lwJQmKw0uNl1UGPbhlZWWSbCY9s6hAWNFmD suExFoOczets57dImZrbogFzNkjNzWXN9qY5nkPUhOQMTvShSlbVd+5nq/vv8YH8rZj8 VBmdRRd8jKXDMYLkkFLGpd2CZxRIXifaM4wVa6RL5cNEt9MLEWMCA2ugTJyb6qsbamg9 vfUvrr7RzHCYkfgFnW3nA+0MGcB4i5+gm52hMUwWagIaPG49NI57yn2r+yIIzaA4KDHl iorVvOcYZwmmujgHi0c5UGQTPjPxbnMQJFHL7koyWzPGKn6Ca/2o0m1WDJkru6SSyjfB MTaQ== X-Gm-Message-State: AOAM531fD6egHRf61he1aSQP6dYMhMNcxoC7DR3NZwYqHIAzp+hjlpEl kYgAH5rLpKJ0wlSvXDFXzVpqSx1s9G7/eg== X-Google-Smtp-Source: ABdhPJxJetjpHIVNS2lisYjS9xu7OJu19RVz0AcCJRUHKyNDHj4PXbaDLfgzIbNIvsIQRcXTmGn7Vg== X-Received: by 2002:a65:6e9a:0:b0:382:1804:35c8 with SMTP id bm26-20020a656e9a000000b00382180435c8mr18233668pgb.584.1650437430111; Tue, 19 Apr 2022 23:50:30 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:29 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:37 +1000 Message-Id: <20220420065013.222816-4-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 03/39] gdbserver: rename detach command handler 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 detach 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 6259b965..93213e4f 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 6012a271..e0df0051 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -351,7 +351,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 bb7c7b35..3e27ba02 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 1fe67f2c..1910fdba 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 Wed Apr 20 06:49:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619330 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=XsEVAW8O; 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 4KjrsZ59HSz9sG0 for ; Wed, 20 Apr 2022 16:50:42 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrsZ3mXjz3bWD for ; Wed, 20 Apr 2022 16:50:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XsEVAW8O; 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=XsEVAW8O; 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 4KjrsR0mTcz2xnM for ; Wed, 20 Apr 2022 16:50:35 +1000 (AEST) Received: by mail-pj1-x1033.google.com with SMTP id z6-20020a17090a398600b001cb9fca3210so1162693pjb.1 for ; Tue, 19 Apr 2022 23: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=AfvageHOrOHXM0EVXmYBSZjTGFGynVqeucPTabsnhyY=; b=XsEVAW8OlhjnzkvKkHSgqq8ydF/+WWpmy6I9sC0sPIh7SjAomGYVK1Wg6/MEt1VwOa 7NS6705GRCuuof7Pg7+BQHj2oVvVkga7WtWRnbLGC+5qs2mp2lWYdmHpbyDKb1ElAb27 gG1oRQuy4moo2RUXrBzRYcwghkqIFg0oyw2UuWERRHvuT3fIqBP+HhlgdBbgcYHlknxu oRHmlzF6TuWygDkxSIQZZFod6QzmQdPG81L8mTqw9o7X9XpFOrZsyimGf+ChSN5hF2dR ITh5VKKepZk9iz5jlTQHYi5wmyBtvw5XvvYA5jJizV8MJQXix1pU/3uTRnw0re3zLbYa NJfg== 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=AfvageHOrOHXM0EVXmYBSZjTGFGynVqeucPTabsnhyY=; b=Q6iXS1GWmRpH+Lwr5IBXyFigpDPwKvj0WnRw3I6NfLjJS4G9xWImdnEPguctzC/S26 y5WAEh+CNvXTBW3TvGMv1cGCzK4o5cN8edDMvviHzcMz9bh5rLlVvgXB7BgktdSYk01H OOGzGOH7pWo6nwQi5ooN9nYn4oy9wgEV8I2w9mWbo+jVH0cmEJKla90UYhl0gbPKJBLH igs+eA4GtC5Qy1C8Uwz7ty9Q3PDYELo4TLChjHfF5risZXqmJ50tZAjIIUl2mZgj37Wk TEfb+EBnN+t3TAw3Vxz2a7Ho5GA5Zs352u4OkU2qUKt1+uXQglmirEySZc9yQWJABrvN vdHQ== X-Gm-Message-State: AOAM5330lUmAZHdOZujFsRuX0GdwxQDWOLAyL4xuK3wvIqwGWkkq8bng 3s8I65pXlvJiq0HU2EBwKCMYBwLIguS1Cw== X-Google-Smtp-Source: ABdhPJxBBhLfA3c24U7I/6kPHJFpXp/JcA1hU3MULCLXIyAAfbexiEH6AXizJNMT4DSxbel6frWTpw== X-Received: by 2002:a17:90b:3810:b0:1d1:b184:1ead with SMTP id mq16-20020a17090b381000b001d1b1841eadmr2746201pjb.89.1650437432240; Tue, 19 Apr 2022 23:50:32 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:31 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:38 +1000 Message-Id: <20220420065013.222816-5-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 04/39] 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 | 139 +++++++++++++++++------------------- 2 files changed, 68 insertions(+), 73 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 93213e4f..629a091c 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 e0df0051..734b0f8b 100644 --- a/src/gdb_parser_precompile.c +++ b/src/gdb_parser_precompile.c @@ -30,19 +30,18 @@ static const char _gdb_actions[] = { 11, 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, 3, 6, - 2, 1, 3, 6, 3, 1 + 19, 0, 3, 1, 19, 0 }; static const unsigned char _gdb_key_offsets[] = { 0, 0, 2, 14, 15, 21, 27, 30, 38, 46, 53, 60, 61, 68, 76, 83, - 92, 99, 107, 114, 122, 127, 129, 131, - 133, 135, 137, 139, 141, 143, 150, 152, - 154, 156, 158, 160, 162, 164, 166, 168, - 169, 171, 173, 175, 177, 179, 181, 183, - 185, 187, 189, 191, 193, 195, 197, 200, - 203, 204, 205, 207 + 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[] = { @@ -56,9 +55,7 @@ static const char _gdb_trans_keys[] = { 65, 70, 97, 102, 35, 35, 48, 57, 65, 70, 97, 102, 35, 44, 48, 57, 65, 70, 97, 102, 35, 48, 57, 65, - 70, 97, 102, 35, 44, 58, 48, 57, - 65, 70, 97, 102, 35, 48, 57, 65, - 70, 97, 102, 35, 44, 48, 57, 65, + 70, 97, 102, 35, 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, @@ -77,35 +74,35 @@ static const char _gdb_trans_keys[] = { static const char _gdb_single_lengths[] = { 0, 2, 12, 1, 0, 0, 3, 2, - 2, 1, 1, 1, 1, 2, 1, 3, - 1, 2, 1, 2, 5, 2, 2, 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, 3, 3, 0, 3, 3, 3, 3, - 3, 3, 3, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 3, 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 }; static const short _gdb_index_offsets[] = { 0, 0, 3, 16, 18, 22, 26, 30, 36, 42, 47, 52, 54, 59, 65, 70, - 77, 82, 88, 93, 99, 105, 108, 111, - 114, 117, 120, 123, 126, 129, 134, 137, - 140, 143, 146, 149, 152, 155, 158, 161, - 163, 166, 169, 172, 175, 178, 181, 184, - 187, 190, 193, 196, 199, 202, 205, 209, - 213, 215, 217, 220 + 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[] = { @@ -115,62 +112,60 @@ static const char _gdb_indicies[] = { 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, 27, - 27, 27, 26, 4, 28, 27, 27, 27, - 26, 4, 29, 29, 29, 26, 4, 28, - 30, 29, 29, 29, 26, 4, 31, 31, - 31, 26, 24, 28, 31, 31, 31, 26, - 4, 32, 32, 32, 3, 4, 33, 32, - 32, 32, 3, 4, 34, 35, 36, 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, - 3, 4, 46, 46, 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, - 3, 4, 56, 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, 3, 4, 71, 72, - 3, 4, 73, 74, 3, 4, 75, 4, - 76, 1, 2, 0, 19, 20, 21, 18, - 0 + 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, - 11, 12, 3, 18, 9, 20, 50, 5, - 0, 58, 6, 2, 7, 2, 8, 10, - 4, 11, 12, 13, 14, 15, 16, 17, - 19, 9, 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, 63, 1, 3, 0, 3, 33, 39, - 3, 3, 27, 21, 30, 3, 3, 7, + 3, 24, 27, 21, 30, 3, 3, 7, 0, 18, 3, 66, 0, 9, 7, 15, - 5, 36, 24, 74, 70, 74, 70, 74, - 15, 12, 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 + 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 119 "src/gdb_parser.rl" @@ -178,7 +173,7 @@ static const int gdb_en_main = 58; void parser_init(command_cb *callbacks) { -#line 182 "src/gdb_parser_precompile.c" +#line 177 "src/gdb_parser_precompile.c" { cs = gdb_start; } @@ -194,7 +189,7 @@ int parse_buffer(char *buf, size_t len, void *priv) char *pe = p + len + 1; -#line 198 "src/gdb_parser_precompile.c" +#line 193 "src/gdb_parser_precompile.c" { int _klen; unsigned int _trans; @@ -385,7 +380,7 @@ _match: #line 93 "src/gdb_parser.rl" {command_callbacks[INTERRUPT](stack, priv);} break; -#line 389 "src/gdb_parser_precompile.c" +#line 384 "src/gdb_parser_precompile.c" } } From patchwork Wed Apr 20 06:49:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619331 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=mPgceGr2; 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 4Kjrsb4Xvwz9sG0 for ; Wed, 20 Apr 2022 16:50:43 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsb3Qgrz2ygB for ; Wed, 20 Apr 2022 16:50:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mPgceGr2; 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=mPgceGr2; 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 4KjrsT38Jwz2ywH for ; Wed, 20 Apr 2022 16:50:37 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id q3so984024plg.3 for ; Tue, 19 Apr 2022 23:50:37 -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=iMAmmNor0Soj8ruuWXilhuD4ulV4S+BBBUxb6lU3L3g=; b=mPgceGr2zEt7fWECTqO173trg5JZhBBxA7b5ulIKJGncEHmGmAHVagpKsqKjpijSyb Cc0+zNjecGHxUp4L/7wC2B6fOxxDBJpYcmQwc93g6rFiIErcjYs+0C49MaNSeiJzHBuT nFkH3yF5SUfbdb6rR15vNpdUD+Q7XJTvVEh5ArdXMNzOuPOkVkbqPR9h+0XRh2cjQfix uRhKXs5IPGJiAp0oi13Zg52B6xGhBDMdnfrrCo+fHA4SLZbj95Q2ZcMBSSuZ1uiYwcDN SZDwBB7Od6JQoEddXGD7eQKXYr5rUIebMo92bt5OJnR6ly3KuAVUk/6J6WawKa9/bP6p 2oWQ== 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=iMAmmNor0Soj8ruuWXilhuD4ulV4S+BBBUxb6lU3L3g=; b=jOc7/HujUKlvEHWnLP9ZHmzvBkuru5XXtV/bP+vycY/uOj4GxjXXFSaSIUV73pdhm4 GJwdwcVq5U3H6lFy/qs68cxdoeHXohtp/FFQZ5r9HHUij5W6HLVo/xnB1Wn77B/PXdtu TyjTiOIWZh8VTTJIDBLjnjPfqzhQDgQ2SRzi2IvS32cgc6o1hVEM8a08o1dkcgNKPmHQ Pv7KVXVJRA9c5mJlJ6zh5rdtVbnK2Y9rhEqpV0U8ScNG4zGdwqm2/F+yjvAHT/NNI4yC 4UV+nHEM3RRkypgj10PvrGlTy8z1YaK+s18usKsEm4CNCHzom4xdKab4uIAR2GQugR0j j4eg== X-Gm-Message-State: AOAM5330qDn7+Wpzt9Ha89dWe2efvef33mV9N/bkNvOm/T2DSJhpcRvy 6WbCSQVhcPfMVcxdkw8RqyWBNZ2p7xONBg== X-Google-Smtp-Source: ABdhPJxDk6jOymhwc9Ni2otDHIZXV9ZsBKLt3pMIC+baj4SpaHnV+ArDt0ua03OanAxweGc19PZHlA== X-Received: by 2002:a17:90b:38c4:b0:1d2:66cf:568f with SMTP id nn4-20020a17090b38c400b001d266cf568fmr2768208pjb.18.1650437434756; Tue, 19 Apr 2022 23:50:34 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:34 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:39 +1000 Message-Id: <20220420065013.222816-6-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 05/39] 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 3da15cc7..7d4ce7ac 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 Wed Apr 20 06:49:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619332 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=hD3HxQyE; 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 4Kjrsc5HQRz9sG0 for ; Wed, 20 Apr 2022 16:50:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsc4CrZz2ywH for ; Wed, 20 Apr 2022 16:50:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=hD3HxQyE; 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=hD3HxQyE; 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 4KjrsV3xp6z2ygB for ; Wed, 20 Apr 2022 16:50:38 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id s14so967395plk.8 for ; Tue, 19 Apr 2022 23: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=6O7LUgg0GmbQLO/OSYuV/emZmTFplxwBer+GYj2X/t4=; b=hD3HxQyESz30paHR4v6+7zPMZmMhLNfRft62d1j5hcGb9fgzw2KNuLk55eeiPf9uS5 u+f9d+94b4t4ERIxjHZ5piy9FMfw7aYDK1fkr3b2O2SABb+IAVB9TNvztdz1CeOMlzTF TOu/oOKnJC58D3tsFImxP7/0HdftXo9nQScgbfRQ8uGo5ujq0z8mQGNOiWmCZXS85Cpk R64bhymrN1EvlnV131bfNuqery8XguZEcpEG0uCBuNWJbsYdZwCsEK4ShgX7XOg4aCtZ x80gGu+Sz9NvgvnX+3IJd5zycudSIz0HcdqVbLTCWOaIdmg5hQL05KkUfUP+iC+OgHU0 7c5A== 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=6O7LUgg0GmbQLO/OSYuV/emZmTFplxwBer+GYj2X/t4=; b=PcHUALMUu85sg9XV8IjKAKO7r6oA0RAaptVq0fv859FUdQPDCih6EYKxMFMBA+A79F Dupkboxi43VWbNtVrx//4uTRk4KXE2KAZ6imFNwgp+rp1MUMIFQHzGsT9ixYcnP+nHw1 WlRiQ3OKJ3B39MNwSj/nCw2pwyBEAxi4fJHJIul8NV6v/7c8YDemOSlIHbyQnVkEGqEB VXC8Z/qmeDgXzysRORvRrQlE05k5yFBVP+k8/+7tcFl8PuHx2LlvqqXsaqrIjbuHl+rT MBe1bS+M1j9qL/vbwaEcH7oP0nginJ77BwSONMwVJ03nptxR2GAR9J2E1UTIs9j87rAZ k85Q== X-Gm-Message-State: AOAM531x5XpXDO9fMKWxd1NPUqxtAKU7Qn9Phx5PFxUbSZ9DQrgGrgjw G2Nt/mLKcGzEaMB+rMtTs1tSeTxft3uN8A== X-Google-Smtp-Source: ABdhPJyOwg5jtkSkxJVUF/3P/RzqIkPD0swEcs4SEiEr0AZVGqVCMStm3nd0KUPhXGoClamtRa/bJQ== X-Received: by 2002:a17:90b:3c12:b0:1cb:70ef:240a with SMTP id pb18-20020a17090b3c1200b001cb70ef240amr2671861pjb.217.1650437436849; Tue, 19 Apr 2022 23:50:36 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:36 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:40 +1000 Message-Id: <20220420065013.222816-7-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 06/39] 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 40450e43..9ece33f9 100644 --- a/README.md +++ b/README.md @@ -553,6 +553,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 Wed Apr 20 06:49:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619333 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=D0j3NRwz; 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 4Kjrsd5Kprz9sG0 for ; Wed, 20 Apr 2022 16:50:45 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsd4Dj4z2ymq for ; Wed, 20 Apr 2022 16:50:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=D0j3NRwz; 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::430; helo=mail-pf1-x430.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=D0j3NRwz; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4KjrsZ1GBWz2yn2 for ; Wed, 20 Apr 2022 16:50:42 +1000 (AEST) Received: by mail-pf1-x430.google.com with SMTP id j17so1084781pfi.9 for ; Tue, 19 Apr 2022 23:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HUk5u7gPGnP2g2hjKna7df112Qsb10meN8u6/RnxvpI=; b=D0j3NRwzPSXcu0pZeLsLnLJP2tT/yQPLmhLQa+YdU7bNQjytTExocQxH+3wloe9s9X 2bba9+cUdgLbe+Abe3JgOSO6hqHjXhyMyPAgH9n7akNOtRRKj9+5ddAJdU8tSsKxXLy2 ELDuqZQWYMXhdKNo6imUS6D/vMymhl0ykjU53b8y2dWfugqK/8O3+tV9yhMlDlAI6G2G 9e50P/gH0WIBrryUhK5uao6upaFvd8psaeN1kHFyRVGMXe/ly5WxXYaReaoTvdhKGvdp /WLnQkOnuqEbdXt3pS1jqo91TyhryHIwYpc8E8v2MvDifTjxBEpmRRTK+3LQMDueUQay oiSw== 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=HUk5u7gPGnP2g2hjKna7df112Qsb10meN8u6/RnxvpI=; b=jW6+Iy4Ynqis456F09Za0HQIpbuDDzBSKAqqVEObvdTt9R4SxbadaxQAZtqsEyjmXV mCDhhoulxoTDVccZYjx2cmD0T+nT8KglLo2ncuPk+nfYazLLG+b3QeM8XNQVI0yv2m45 QhvGb0EdwQf8cGbngBAAOpivFskHMcfClWAs51wK/Y85/HQfi6cTLDsP2E8ctORey0RE OdLlmsYen6AAeWTfIyvtOoEmp4Bh2GjzLrxx8SNAPDgwQAJi24eWMDg31xnrEraX0uvo Z6azc3EyWJNtW2I5fN35roKtPlbFDsnMu6Ap8Up4RZiRvDkZxEY2sxyHlSD1nTQKV+39 fULw== X-Gm-Message-State: AOAM533xZAafAcNy7sJP5u3cKBp4SWXTF9jMCklG2UXcDuJBd0Oi/VI3 nMNTcuUX1hEfYv8DP8QKTmI/C+bOxnhVog== X-Google-Smtp-Source: ABdhPJxAIqodp/ktbljehzhqwc/DpUrOITj060lFsP8pKplrfHlNR/Q+wM/kdBmrOB6Iy5nTSMhvzg== X-Received: by 2002:a63:4f0b:0:b0:3a9:f4ad:6c30 with SMTP id d11-20020a634f0b000000b003a9f4ad6c30mr12431871pgb.88.1650437439436; Tue, 19 Apr 2022 23:50:39 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:39 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:41 +1000 Message-Id: <20220420065013.222816-8-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 07/39] 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 3e27ba02..e32f5184 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 Wed Apr 20 06:49:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619334 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=nhbiCoIK; 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 4Kjrsf5vp3z9sG0 for ; Wed, 20 Apr 2022 16:50:46 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsf4hr0z2yWn for ; Wed, 20 Apr 2022 16:50:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=nhbiCoIK; 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=nhbiCoIK; 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 4Kjrsc4JFCz2yyG for ; Wed, 20 Apr 2022 16:50:44 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id i24so1094919pfa.7 for ; Tue, 19 Apr 2022 23:50:44 -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=A+u7iVLDIQ41FZf5vMM8eJREctPOKCkbYgQYTvfbWkU=; b=nhbiCoIK8N1yDxPVmdfxNGQGf0JMibg0+7KKoKtTJps/bHsgUpeSrra0fwfqVEcg6u GzY6SgQS0wXbmr5JTgKOrl8GsCvLUaYa9DXTtoOzFIrVf2qaTiDRuVNXErZCDHEzZajH RFrSdrhnOHlFV/pYf6Ocp8P/a9FK1E6gHZSNcoJ8ZJDU7Noq5HPQKYudjcwTxrvWW6Pp vxmvPtfbJOUCjfu1iu792WIyZcFburiQ3aMVOVYi8+ieFQmZ4+RmgBhmk8WftgTffmQF Yvj3i3Y91AYwqUEiL6KZkGhN5Maqf/HTistqoNscG5A3BiIeT1nvKMdIK8ygyudNrE72 DWVA== 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=A+u7iVLDIQ41FZf5vMM8eJREctPOKCkbYgQYTvfbWkU=; b=voP5HpKIM8YfYqC48DZo4Y7i5o2SIm+U7LSNCYQ5fLybbsj/2V8nXXAsgbhEgL6XlL MHd7Iul9ZflTPTKHv6rY9RoOGJHYk2kzQwo1hRIaNyrKbyKOw/sCWBj/uA4mnjp0o3ET iZVwAnlt4lb4mrQsDhutA5vEijg4wmKV9IYzL2+1cdSrHKQHMD89z+Ym7ThYyNWCkj1k i8sywvh7gkP/tjaP+50GIvMd2UAujYq1JqCrqXtF8yR20fW30jXzRMEtfkIcaVzYKXxi V1q1YmdsiiC2c9nel3a0WhD1fqL1Cfs52GIq0S/etxSodlfCzfcKOTPJ4dZ+jc7RJauS 3DqQ== X-Gm-Message-State: AOAM531BWgYPw0KKlig340UyXNktvzyKRUN4S8jX8+5FNDDYBP9LAlXk taOsb3kOB1dNO2kicsp8PbSWw7BgH4Gkzg== X-Google-Smtp-Source: ABdhPJyrcCC/jC7LoaPMtlR1Xs21J+T6WqulQuzLlZ3ZrplmmWrMOCPwvkJxkD/CtCRzG7lrCuiHLg== X-Received: by 2002:a63:d13:0:b0:381:f043:c627 with SMTP id c19-20020a630d13000000b00381f043c627mr18282099pgl.168.1650437442200; Tue, 19 Apr 2022 23:50:42 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:41 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:42 +1000 Message-Id: <20220420065013.222816-9-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 08/39] gdbserver: Make command callback array 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 e32f5184..5a8b5f99 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 Wed Apr 20 06:49:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619335 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=Rz4FAa3p; 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 4Kjrsj5zk2z9sG0 for ; Wed, 20 Apr 2022 16:50:49 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsj55bTz2ym7 for ; Wed, 20 Apr 2022 16:50:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Rz4FAa3p; 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::436; helo=mail-pf1-x436.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=Rz4FAa3p; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 4Kjrsf6pvPz2ynx for ; Wed, 20 Apr 2022 16:50:46 +1000 (AEST) Received: by mail-pf1-x436.google.com with SMTP id y14so320546pfe.10 for ; Tue, 19 Apr 2022 23: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=1x+QwRJZmb52R77u0JQAQrAhy5KGg6rYdb6MYPPphnE=; b=Rz4FAa3pElf+FaUXT0/bgUXhd3RfCYAd/iJBgWbbQAJlAV/Z+anEYk4i6QcPmNcuNI /Txl3utdYCtbVLw103xqDEc2M/PdfLaqj0PODCKkA2UXQiWi3T9ZfFBMozsSh/vwgz0X ibhiB9pVazDo1m9uj0fXpCANhszpuEeZH2t7hyY9MkU481nteFHc+B4YuQHRfpHGdOQd 0aOnl8ry2bkDWHRjkR80dc5qqDRujbs+B7ZWfh+HWIEG7XuJmtIdC6qJwcCW/8+BhaJh e1DVncaPIhfSK7DPhRM+Cy6mpWTrFUuU4b95qa4CTvw1pb4KfcRRCZmQOc4enukaupeX VUmQ== 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=1x+QwRJZmb52R77u0JQAQrAhy5KGg6rYdb6MYPPphnE=; b=fsNGRyB/9ykRCRcDqakhgR9J1gxmiHLR4vT1BM/qiXbOEzg1PWU6t/PIIUbsMtvnq0 q3IOdXaIzMGbnrOA3408cwKuwvqvBGMjZhsrNf75d3En+R5tOP5+9Chh0XtvXkXqDcdD XiWUgZwYQckZEFY5iGsrEU/PerzSqiHYd41xkqK3QSOKa9WgnuvqRrs9go5mcGXYEvEl 1QJAzXqPzZiNfW+ZJRXeAXQV0oWMw16njzqs2EyV7NYRmGuOoihtXVYJMfUaoWYrQODN RO5FQfsIp4My/UfPxxh0mi/NC77tkkIzU2hKgPU+uThZRHpStQkdwhgwkcZIssAaELsP jUHA== X-Gm-Message-State: AOAM532IC+jm3VgrrEhVJp70iv5I0tJosMUm2LHI6dCOgW7nYU/XSsuk gyzRVDkBXvgaEXvVuwKHpi/JhZQ4GEDqhw== X-Google-Smtp-Source: ABdhPJwtGGvXErOEUHau0lIPMRuc4/+jwK/nYPv8YsixL4DxP7Z/fsXFMgEehQkD/5uanJPKBnmyOg== X-Received: by 2002:a63:4412:0:b0:3a9:e7e1:81a6 with SMTP id r18-20020a634412000000b003a9e7e181a6mr13123978pga.532.1650437444751; Tue, 19 Apr 2022 23:50:44 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:44 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:43 +1000 Message-Id: <20220420065013.222816-10-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 09/39] 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. Use pdbg_target_compatible() for matching threads. Also document another case in hwunit.c that is using strcmp (seems to be the only other place in the tree that does). Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- libpdbg/hwunit.c | 1 + src/pdbgproxy.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c index 074ddef5..f64ec440 100644 --- a/libpdbg/hwunit.c +++ b/libpdbg/hwunit.c @@ -44,6 +44,7 @@ static const struct hw_unit_info *find_driver(enum pdbg_backend backend, p = g_hw_unit[backend][i]; target = p->hw_unit; + // XXX: should this be using pdbg_target_compatible? if (!strcmp(target->compatible, compat)) return p; } diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 5a8b5f99..906ed2f6 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 Wed Apr 20 06:49:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619336 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=Z5UzCGmC; 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 4Kjrsl6vymz9sG0 for ; Wed, 20 Apr 2022 16:50:51 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsl5mbRz2xrv for ; Wed, 20 Apr 2022 16:50:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Z5UzCGmC; 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::62c; helo=mail-pl1-x62c.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=Z5UzCGmC; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 4Kjrsk1lvCz2yh9 for ; Wed, 20 Apr 2022 16:50:50 +1000 (AEST) Received: by mail-pl1-x62c.google.com with SMTP id be5so948799plb.13 for ; Tue, 19 Apr 2022 23: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=q6R2k03qZRslQHmGH6etoGS3YLQME/fO/cnU2wP/J54=; b=Z5UzCGmCRLJViJbwUztv4TEGK/NH/dKkCu9mdC+AxxFHF84qLdJIKGfeSNsMb9LOgz KadvgLAjKbMtmeKWd0Mk77O3vpJkNr9/gTjf0Ggw2MNIKjDPM7AjVrpOB3EL8SNmX0eM bl1gA6g5kTdMwJjQZSpBkZ3HIvUdMX9+2g/q4Jpijazfq4XrDq9RzGSr2ykwZTENY1BT kKJE2az+ogtTG2pAwaxeZVZc45RwI9PpzPqM2lhN5wu46uFwyVBRqq3mPruvkftJm41y ORp45enh15BjTrgOZn1ROKDpW1A8rv0U3qKEVUSXEGwE7QegD4SjfouNoGS7XUsBUmpD tf+g== 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=q6R2k03qZRslQHmGH6etoGS3YLQME/fO/cnU2wP/J54=; b=cQ2S810f+ph1MXOYNM3wjvyUZ/oXXVEWEubjp4s7bO+1mYdOLzGKVgWlzbWiv41D3y idwUBZx0zsrso4B3yHROaELXQif99Yun+XT9EE3gduKvq+WsrYhVBlVOOyXuCqrEG1Eu xkOkwFPePVDhECcQooZdDJaIlklsiRoYpjgyqHZ/hAMCRRJsRQbqyStqcxQ8aq9L7Tid lLwZlgB74ilJVcQXuFUPkWymcxXVRovhnTu378PLvkTG1NrNdzQRANhUA/30LTWCuR3v Ny67q/b781O5v+tOtCd8vZbSs1yBSqhm+ffLzzoM1YqlycPIdgk19pgG3eA3aSi1xyE2 126Q== X-Gm-Message-State: AOAM532CLm6NSEvW4+iVLEWOVT/X/iGxA66JdjBaMpx0FGx3GwR4TPdp njfGIQkqL7JGNBwQatYRyzFHiCpHmdnH1w== X-Google-Smtp-Source: ABdhPJy7/rElufGT0sw9qjyLa+Nr3116Xt1ZJPRsjGGvgUOQgUs7L2MKFxVAhD+OLUlgxcj7/EgDeA== X-Received: by 2002:a17:902:7407:b0:159:6a:8beb with SMTP id g7-20020a170902740700b00159006a8bebmr12883414pll.168.1650437447408; Tue, 19 Apr 2022 23:50:47 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:47 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:44 +1000 Message-Id: <20220420065013.222816-11-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 10/39] 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 906ed2f6..4c6327fb 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 Wed Apr 20 06:49:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619337 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=NIohYcMe; 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 4Kjrsq09bXz9sG0 for ; Wed, 20 Apr 2022 16:50:55 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsp5pNyz2ymg for ; Wed, 20 Apr 2022 16:50:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=NIohYcMe; 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::42c; helo=mail-pf1-x42c.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=NIohYcMe; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 4Kjrsm5Fz1z2yZf for ; Wed, 20 Apr 2022 16:50:52 +1000 (AEST) Received: by mail-pf1-x42c.google.com with SMTP id a15so1074698pfv.11 for ; Tue, 19 Apr 2022 23:50:52 -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=nKk/gZRMHwNWNDODaUe50aLpbfbiB1HZCYurD9HyTLY=; b=NIohYcMe63U1MyTWLMQoI5/fCkg9IOVxkpQQnWS76l8C6yoIdy2I4ciNeRZpxYRJ1D Uo9tysMG+Q6cmxUZyh/5jDkKjLZrBhAVNKDg2iwnWjDbr64FJYdU7HM30SYc3ZgxFPjU U9IzG3562ZvMdH+hTRI2IYW8bMsfaDroHwMw24dUxxp6Jl7u2MNuH13Yy2QRzRmhow7z ERxGawVG+6r7vhfbVT6MYACgki5QQoccnYrtHJFCiahb8no+XN0rQTSeqWp2ZMIV3RDQ OIxFKrLD5vFik8C7UsVbxilU0X+lTpNmTfuYmOGKFu1MmDa0gcXB63TpDpmxi55SHBCO BcSw== 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=nKk/gZRMHwNWNDODaUe50aLpbfbiB1HZCYurD9HyTLY=; b=3DmkBDwcgyS4l+vkp7QR3yotJIZiEnJe4BPaEiLYaO3DO9Y9h1pL8PBkODm2+EJm8D 5TneE9mmBxggRVGbyCaisTc2xgAvNxGv0XoVYWENZpI5z81ONA6bVn0DpHu74oKJ5crG lgcx5NefHsIW3OYCLHoIZhMs4YVEkhoa9iKt7feMd7xzuq/Ifs2NhwGLjgE8R3N0Y+re MubSlg6vHhrUYLPdOKdZSkF4ZfkVl40Q0ivixTVnhq3HU5tm+SIxMT7lD7xOJ2AGYRj2 zW6Bcamyr0t0gaNNMSdMcen7Hq/j/cvU3KPKIJoVdqmYhjCeGA9UtOW7koQrV9klyd2b pvMg== X-Gm-Message-State: AOAM53090pJIW45DR6xci8pvm32EaDhUwkbSJzxFqWV0ZwBDITOZayTi W/0mA5N0iFaAktIMdULhghOEddydS9p0Kg== X-Google-Smtp-Source: ABdhPJxKerpumtcdtcroUq0HTab7EyjcqPQsWTq4QkCTQstB6mutiYWpozPkO/CyRFv4aJ6cI36wRQ== X-Received: by 2002:a63:a902:0:b0:398:cdd3:f85e with SMTP id u2-20020a63a902000000b00398cdd3f85emr18026318pge.122.1650437449862; Tue, 19 Apr 2022 23:50:49 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:49 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:45 +1000 Message-Id: <20220420065013.222816-12-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 11/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4c6327fb..9e5e7d80 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 Wed Apr 20 06:49:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619338 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=iCKjuszR; 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 4Kjrss0Fwdz9sG0 for ; Wed, 20 Apr 2022 16:50:57 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsr6dfGz2yn1 for ; Wed, 20 Apr 2022 16:50:56 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=iCKjuszR; 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::1031; helo=mail-pj1-x1031.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=iCKjuszR; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (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 4Kjrsp369Tz2yh9 for ; Wed, 20 Apr 2022 16:50:54 +1000 (AEST) Received: by mail-pj1-x1031.google.com with SMTP id bx5so1067409pjb.3 for ; Tue, 19 Apr 2022 23: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=UUxyziwNz4TuyrOGHpCNG3+sxYGC9S4Nqsi1P1CNy28=; b=iCKjuszRCxcBcGlavIywYUUCMG03SzgwP1nhrQ4+hiIM5NTahxrrIx/jqnN92mQdBv N/+My2Pb5FDLq5FZ0gpHV38jfuypDDRsJSbgQvEpdRJ/UD6vYJUArQkhZaw6w6xa7fHR S5KkqQUJlha34yQ48pz36NPSf1PkklVx6Gd5Yo2ri6JNVu8YkH5/RvBSIZ6budtTiyow 0LyCoscqRArUOnL5Wn2jCY4Hk3HvBJsV0vZzcox97++IgDHHQNJPBcJrAPqLXR3gCH0V qy/CsCdfn58KCRgvp/Xgmgvqe6XtLskv5iBHYkfxSSt60ODAqGvhcEhQaie1PSGWgwrV azKA== 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=UUxyziwNz4TuyrOGHpCNG3+sxYGC9S4Nqsi1P1CNy28=; b=I9hLLy9byNkXiSN3hzUmlYAh0+gaTGQbnZ1itxXraJQjrh4KDJnofKycC8TbuHv2FQ Jj2ZKGWDdFk+u3Q3pRemQDMaeu22Av7rkBVZft8nB3wM5hCmzVE/eBl5Z/pcPhEWoafD sjpPsB1qBLS3+vUb8QJCICMVXmXXP12GCTPcP38YZ1SbPOPQ5uJTPEf3itb5JrWocl3A kbO+gLqUeVu5EJOwLlLiHXKEgJFM9B3/VeukyLS4vr2u0R2fb2tvJ5mzRaGzbq/w6yx9 8d7+ZfcKBTp4LdwnikYlVQwDjRqsNL0dBK03fnojTXkUYO/yYjGSRqgXz8vx6UJRnLSK 7kjA== X-Gm-Message-State: AOAM530kIZFw9oNqldxhZFUkIqMxxT9p4Nr58zY1ZQZBkYQ60IZnjZrZ aY8D1XoSIUMgAGYFNHLYfn7teMC4rMs1Jg== X-Google-Smtp-Source: ABdhPJyUgP6poz9szKZ86fUHO6ui3Gx/4KK0Q8GvHUsCQWoRarJTaqjfOyhLBMh3GTxxnMrZnByrCA== X-Received: by 2002:a17:90a:c504:b0:1bf:6d9f:65a6 with SMTP id k4-20020a17090ac50400b001bf6d9f65a6mr2699373pjt.204.1650437452263; Tue, 19 Apr 2022 23:50:52 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:51 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:46 +1000 Message-Id: <20220420065013.222816-13-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 12/39] 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 9e5e7d80..1668126f 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 Wed Apr 20 06:49:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619339 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=qG1SkOyX; 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 4Kjrst6lK5z9sG0 for ; Wed, 20 Apr 2022 16:50:58 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrst62Wcz2ymS for ; Wed, 20 Apr 2022 16:50:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qG1SkOyX; 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=qG1SkOyX; 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 4Kjrss0P9mz2ywH for ; Wed, 20 Apr 2022 16:50:56 +1000 (AEST) Received: by mail-pf1-x433.google.com with SMTP id x80so1118350pfc.1 for ; Tue, 19 Apr 2022 23: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=BB/6NhHPJ574YxrSH8MTeH40Pvcu1XeN7aKNdYuD94g=; b=qG1SkOyX2k/B6O7X0heTcalscQnyeXvUyqMbKLIV5TW05tPHKwwbNSX7PzJYhhmE6b G6GEZXr/pn4bY8rMS5Q390Sxy5B/3rfG3Etvf/30QpwsLNfRyYQkcBycK41drGEmeF4/ jEOARSkt8hlMXI0MvVi1PQnKhPw7lrt6qKPzdg4SV1lFT/622N2EJ16GTSWsFTJIqskL KybqZBExjIV7zCTwMTTAIG2z9aTfpyiSTcJ/L18vQv/gvDuIsehc4OykpJy68Q5ACfJw XjAwlaj/d1rQgKbRdAUvg1KJh5MPIXfmthTzE4AivYz/bgQbSckVFpLtMLG4peDoczdh XZvw== 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=BB/6NhHPJ574YxrSH8MTeH40Pvcu1XeN7aKNdYuD94g=; b=PUzEhyOSCqPujn86CYjDAxLy++Sma7ux9+4s4JdHLmMOkhSw16duj0HQMaboln45ca XtAbu5kyR+yhY/ExakKBEmPcV56HaObu6ku9wo2ZEjBf4pYtW0dk9+JKyMA+ejObW0WE u2It5eN34MUWNErseUfh2LtSG8NVv7K2hBNJj2PLrtUZFR2C/08+Yf1M8FVNS7OVM+xR rsaqTaKrs9yaDrMYnvo7UhJifOI2pIGC9aCRQiC1qPyq57LB2GxDUeps6pVVWqaWcm0p ic/w6m5IXbvkX5zl7UxvaFFRpxeawuQRN5rPgDN9i7C5gsFcUuiTX8iYap3EgM+y7Kpi dOyQ== X-Gm-Message-State: AOAM532BtiuxMiWKf3suRrfrfBSJUysJ8PnxKNlr0+rFaR3bO8PwZaHW e+DtKcwm+YTD/j40ZSFKqC8FfCbtTaCaRw== X-Google-Smtp-Source: ABdhPJykPG4QrJ6HVG+r1ka7960joh7HWizsmr1PoXSoY/SReedGACRbvwSMmBnTiZTGbBz+4QYflA== X-Received: by 2002:a65:4947:0:b0:3a4:dd71:be90 with SMTP id q7-20020a654947000000b003a4dd71be90mr16957987pgs.449.1650437454815; Tue, 19 Apr 2022 23:50:54 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:54 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:47 +1000 Message-Id: <20220420065013.222816-14-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 13/39] 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 79aeb359..6cbf48b0 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 4a7523c0..78a59b8b 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 8ddf4aeb..76909d67 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 Wed Apr 20 06:49:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619340 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=hFl4gOFE; 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 4Kjrsy74kDz9sG0 for ; Wed, 20 Apr 2022 16:51:02 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsy5vW6z2ymb for ; Wed, 20 Apr 2022 16:51:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=hFl4gOFE; 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::536; helo=mail-pg1-x536.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=hFl4gOFE; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 4Kjrsw2Qnsz2xrv for ; Wed, 20 Apr 2022 16:51:00 +1000 (AEST) Received: by mail-pg1-x536.google.com with SMTP id h5so783262pgc.7 for ; Tue, 19 Apr 2022 23: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=OzRdFzNthsuwnF0J6/g208on65cu7FPCcatT8is0Zig=; b=hFl4gOFEZHlzH6Zk24BPlwd6VFiZlrqbnNS5QFtRHae5rtkUdmSXiXYz4lNpdCwhFF tpa+gKvT0PbCM4K/K+xN5y93mqDLE9KEIkQRVCS83KH4MfheYl0n9ZZQLaYiR3JeZYVt 3fjEY9xzASJ1Jcn9LrMjd0sC9af+biSDB6Te8fL2IW30nH9ohXVGL2+Ov02fHtYEGfv/ qeNjSsJU6FggLJ1ASwq/kEcrSC5cA6IySPfR4dWjS2BjtZdLXmjDtf+4jKQTof5uBXyb XBVwDXqe+g/IgxzajD3z0FeH5ql8QngGue+9fnrEcmsjFpZBqniKGZJIFioykga7AXiY 642g== 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=OzRdFzNthsuwnF0J6/g208on65cu7FPCcatT8is0Zig=; b=ktBQeb3dK8roISqlgPeWtvWgc3PtaPLbNFbeklLcHe3PS6m+RasPyQMFnJ0c214qxx ofj1zg2wP/nuhwdcU0ukWPuS/H1GFVenZhChFq6M+cQiXmlH482KIPSinYcKZQWg18yL p2Oi/C43Q7q3oVHbOYDneAkiEqC1ydUyuL/bjKhewLyhOtFLRIWlIPX513JhaEIA5oE0 5Fh4bsyoJdj/r3VflSAi9mqKS+28OOWksCQ5G0yTb5wyM4xAHC6t99PRDYC/G0h2MIGv zLNVuxME2pjwn+uDZVWzBBlGVnI6I7Sp8qIA9L6jF/B5Geaoz4nSavkAhUKyWLF+XtFe qgiQ== X-Gm-Message-State: AOAM532PMYSNfvxEtTW73QI/8S3OCAMnpzvRklTk9S4oKGxC1Mo7KNpw +8PInk+mcD3aT79PQhLVLSjKU1vgpRXWCg== X-Google-Smtp-Source: ABdhPJwZMTDdGeuyU/xNfC1Kv8OiWt9VxpgesXSAgICaGbiyhCc/8+TFY8DOwFftTxJSOtPNK2T7kQ== X-Received: by 2002:a63:1114:0:b0:3aa:30b3:dd5f with SMTP id g20-20020a631114000000b003aa30b3dd5fmr6902819pgl.222.1650437457127; Tue, 19 Apr 2022 23:50:57 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:56 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:48 +1000 Message-Id: <20220420065013.222816-15-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 14/39] 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 Reviewed-by: Joel Stanley --- 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 629a091c..72a907cf 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 734b0f8b..d5372913 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_precompile.c" +#line 26 "src/gdb_parser_precompile.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_precompile.c" +#line 168 "src/gdb_parser_precompile.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_precompile.c" +#line 184 "src/gdb_parser_precompile.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_precompile.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_precompile.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 Wed Apr 20 06:49:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619341 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=ReqH0zE7; 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 4Kjrt01QW7z9sG0 for ; Wed, 20 Apr 2022 16:51:04 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsz71hkz30BN for ; Wed, 20 Apr 2022 16:51:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ReqH0zE7; 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=ReqH0zE7; 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 4Kjrsx475sz2xrv for ; Wed, 20 Apr 2022 16:51:01 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id v12so980534plv.4 for ; Tue, 19 Apr 2022 23:51:01 -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=c/M8K7RQHRSBOj65XXZ4olGo16Nw/P/KBiG1ymgDBcM=; b=ReqH0zE7gw0vLTG2eWbJeuRm/LpkHaSrrsI9yiSN6UOsCuMG2q4z/tXPnBIKjJZCz5 PGbcBSRwzfo1ZT6+iJDd/pmM1o+kaBXSuG65W8ghMVANg+FDQmEBndBRGWxUP6Y+YMje S5YUDuiKzfjL0c7HTT1Ta9GFccCbEpr0QvxlgaLA9+GCxtHGW29b90ptpXRUXZ25sMwB Qd7CfLuFZpSAhJYiUelcII82QPkaBDocyAbNPBcygSPFNpka2tj0jE//2c+u8UxH1s3v C4UGx3IHWyZ2RWLtl0Ka13IYCfqZUn7DOJnBGnLKzfX/ZyiYn+sE1Pd6Ai9PzNibbqHN xZkA== 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=c/M8K7RQHRSBOj65XXZ4olGo16Nw/P/KBiG1ymgDBcM=; b=g79LhWNowDRPkGV4+NOqqQqwsd2yBi3B8UxvFW/+yT/a0ZCmhegBs07ALYYGTrwSt6 2Nh3M7t3WoWbzJbt8LoryhNovU0taDyj7CUk3GwoYAilnETSuUQGNUuK303WatU14gYi Wbh9yiykj72VY4Mm1SYTLEVKJA0W6do5ZxDhjbrzpH4k3sbzkkvI1SGKDKVH7yLMgp0l bP9qN4v41As7JR1uD9OqXE8og1qdtC4GM9bbDcdf0Yxv3+SQCjj3V/HmjQJZ4rmzHved hhRF0LEYMgdHEDpRY0E1T30g9P+kqkRsgVAgZl5b2AWFnf2zICYNfP2MWxXL9l4FkbeO W5TQ== X-Gm-Message-State: AOAM533tBDdrdm9Bggekm4Zfv7KQaPV3U3wrbg8OFRznM7A6+SIqlh65 1SQnpTeno59UpGmZ1YiZ8O728yLFtWHUUA== X-Google-Smtp-Source: ABdhPJzGaVM214wBWes9TU/p2zXqwfPm0X+Y3aaxdPjjwJUbMXRqmU7vKgxgXXYAzc7XBgnWihs+9A== X-Received: by 2002:a17:90b:1886:b0:1cb:8e79:8ebb with SMTP id mn6-20020a17090b188600b001cb8e798ebbmr2714410pjb.176.1650437459464; Tue, 19 Apr 2022 23:50:59 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:59 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:49 +1000 Message-Id: <20220420065013.222816-16-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 15/39] 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 by allocating a buffer to read the bytes into. This also avoids endian complexities by not interpreting the byte stream as a big-endian integer. Signed-off-by: Nicholas Piggin --- src/gdb_parser.rl | 31 +++- src/gdb_parser_precompile.c | 293 ++++++++++++++++++++---------------- src/pdbgproxy.c | 15 +- 3 files changed, 203 insertions(+), 136 deletions(-) diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl index 72a907cf..020f10d7 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 d5372913..6b9b08e2 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_precompile.c" +#line 30 "src/gdb_parser_precompile.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_precompile.c" +#line 177 "src/gdb_parser_precompile.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_precompile.c" +#line 193 "src/gdb_parser_precompile.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_precompile.c" +#line 428 "src/gdb_parser_precompile.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 1668126f..0cc33fbf 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 @@ -282,15 +282,12 @@ 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; + memcpy(data, attn_opcode, 4); /* 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 Wed Apr 20 06:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619342 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=qS1cvOOn; 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 4Kjrt317ZQz9sG0 for ; Wed, 20 Apr 2022 16:51:07 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrt3003vz2xmQ for ; Wed, 20 Apr 2022 16:51:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qS1cvOOn; 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=qS1cvOOn; 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 4Kjrt103h5z2xrv for ; Wed, 20 Apr 2022 16:51:04 +1000 (AEST) Received: by mail-pf1-x432.google.com with SMTP id z16so1107002pfh.3 for ; Tue, 19 Apr 2022 23:51: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=P1nVhYsnEAtfqutmCKcvepzi01TkFCrkFkpzoSZZDuY=; b=qS1cvOOnsZI8pFfZb9r0r2NeA/OQNoMYIRNWoYzSdyNOPk62fApkSiLDdCh+xASPaU GSVc+/yE1AadA83xDc0oRU4GSD2ZN9NTAMleY7GjyHujvm2JdG8ETJfUa9Gi3Tpf1pX3 VNozfN8pTOtSh9vH9uxKVyzp0ICnnVyZnXS1j4hPTLEBssPrb3qMyO82N4HLG2d/AsXD PRo8VO4Clo12WKCIk3dVNUdfRzVEyMs6zpnwrTeep8ld5L+tzW04yOj+u559QDmrmpD4 p8TVCSzhq6dFatxV0VG4rRTqd8fRmgT64+3C6HezK41pVXQw4KDLJwXwjGEgabN5lkPc e/AA== 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=P1nVhYsnEAtfqutmCKcvepzi01TkFCrkFkpzoSZZDuY=; b=nrFjrgFJmBAfOOnQkpxwysWM2X4HVS1AvQl4jg/G4LROOdB5vciitUSQBVxHPlW51T CuixFMYfBSzdzatb6OwZ4usho47od9NMVM0JDc3tvw684YelUtx9o4AgjItC9CQkY3Fq IIew5Ex9vaYZhq3V0tJscMWaGRQWE/oXumQukqFsxybF/QQXwU5O55xeYh416tfKMJNu IfP1MOngUpovmsvzA5PmF+OCKGM76XBynUocyMwYrw17d6GmZYwF+Vvd2FNKK5hEwfXf XbhOM0jSJLRbEzSgWGQJjsYTbX/WdG9YLjyoKFqP1pVrbq6JKky8vnPi2cFLytJSftaA 8mww== X-Gm-Message-State: AOAM533I2JsfCMCr9MHSat0KUUUhEhCxnCzMc06UB2amNjwH3++tFo8g erAABs3Y9Fago+fzuvJv+uoIFLLVKoUQ5g== X-Google-Smtp-Source: ABdhPJw/tSds0Pb5MFjXMCSp9dsC7wzPSfp7FL+p8yhHJnSYDc3F2rBV18dV4xcckputur3c5U28aQ== X-Received: by 2002:a63:f118:0:b0:3aa:2a2b:5702 with SMTP id f24-20020a63f118000000b003aa2a2b5702mr7786772pgi.127.1650437462090; Tue, 19 Apr 2022 23:51:02 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:01 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:50 +1000 Message-Id: <20220420065013.222816-17-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 16/39] 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 020f10d7..e49d56d3 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 6b9b08e2..db982092 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_precompile.c" +#line 32 "src/gdb_parser_precompile.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_precompile.c" +#line 200 "src/gdb_parser_precompile.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_precompile.c" +#line 216 "src/gdb_parser_precompile.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_precompile.c" +#line 457 "src/gdb_parser_precompile.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 Wed Apr 20 06:49:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619343 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=A6r4gdG7; 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 4Kjrt41FFyz9sG0 for ; Wed, 20 Apr 2022 16:51:08 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrt40Qrbz301s for ; Wed, 20 Apr 2022 16:51:08 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=A6r4gdG7; 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::102f; helo=mail-pj1-x102f.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=A6r4gdG7; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 4Kjrt25RJrz2yhD for ; Wed, 20 Apr 2022 16:51:06 +1000 (AEST) Received: by mail-pj1-x102f.google.com with SMTP id md4so1061044pjb.4 for ; Tue, 19 Apr 2022 23:51:06 -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=HWFQAeqrlJBFZB7ANvhsZ/UnCPXSDeqjgnwna+dMtEA=; b=A6r4gdG7JIQ+ReEoDE/RQ7QPFRQD4j9mnywne+rpzukDI04sbVQHty0WhXB0axBpzo YSV3//Rq3FgBG+3OV3MqYxrLYxXmBIaqV4vI7diU2ObJdNPEZrLXLdnEVl5h+QMx3JwJ bller/PxVmr4IPiUOi6qPUwl0CJCCc55x8fU8bTo6/NtWDeA6/lDyPc7GWrOAMej6u21 Z0aaF3Be5jj37YQuFLBj1QAoWx5le+XRL7QxSqScgAYu9oOU0zt5D3KAFH3Bq5E9aKLr pnLAtX4AyP75OG3mZhKu0frQU73pA2a39Vnaak+RjGQbmPEQMimwzILo+LdUBHQyUkiD qCfA== 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=HWFQAeqrlJBFZB7ANvhsZ/UnCPXSDeqjgnwna+dMtEA=; b=pPIhtM9en67H9/jzr/dZcTzWRxMJhcHlOh9IvJ9EE+ZO0wJyMsslVvK6d464lslcCp q4GDbqm6pV2L9douiZhnSIesDsuvCX1cQSlAKXWzXzohe4ZIv0gS41We3X97FXnpYfPq y7t3E2QDi5SzQsJFbC7bA9K6oEASRIJHHLDVAbokvkuAX6jTu04t+8N2SgAORRdUdGUu 0Y9QgWA4H0Yx0JVszbHvP/7SKqMSEIbe3by9RruYmF5+hzNNx8sih7xJSXJ9OdfI4k// rjvvGog9JdTSavER+68rTfgrAWgEwOVP/HmYikzbieMvxkgzhpUoVpeo1sVQC4MNEU26 CUvQ== X-Gm-Message-State: AOAM530DV5eWcwN4B+dkDbDu09te5YXRuH7OPm9OA/bftZ/mAuNw6yx/ zPm8DjvXWofiG/Enflwt6CI3xrSFP5p1tw== X-Google-Smtp-Source: ABdhPJy7S1aKu4WwzVI403AeTdGFt14hASOPKBFEeEQwFgmy57BJq1+yHXntepettHZ1NGR0NSM3Pg== X-Received: by 2002:a17:90b:1b45:b0:1d2:fe86:aab8 with SMTP id nv5-20020a17090b1b4500b001d2fe86aab8mr2704441pjb.180.1650437464416; Tue, 19 Apr 2022 23:51:04 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:04 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:51 +1000 Message-Id: <20220420065013.222816-18-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 17/39] 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. Implementing it for P9, P10, and sbefifo backends results in duplication and P9/P10 cases in the sbefifo backend. Arguably it should be a middle-end function in the p*chip.c files which is backend-agnostic. For now move it to gdbserver and we can look at cleaning it up later. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- 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 4662aec4..2ce41db8 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 92e18ccd..5b2a90a9 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 0cc33fbf..7267fd8a 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) memcpy(data, attn_opcode, 4); /* 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 Wed Apr 20 06:49:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619344 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=mboTBxa3; 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 4Kjrt71PGdz9sG0 for ; Wed, 20 Apr 2022 16:51:11 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrt70Zyyz2yZf for ; Wed, 20 Apr 2022 16:51:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mboTBxa3; 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=mboTBxa3; 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 4Kjrt522s5z2xKT for ; Wed, 20 Apr 2022 16:51:09 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id n18so977500plg.5 for ; Tue, 19 Apr 2022 23:51:09 -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=YtHoLXkTw6t/JlRnAsF+NpiEiduJaHC2fP51oWYDbz4=; b=mboTBxa37pfxjQZNHnLJf3jS+x49g/zs3kHv206LNL1qgkNZp2E+hW1OgfPytGx/pG vH5/50d1jxb5XihPMVUoMcQsK//mRCNNUEpcdBp3dxRBNiTn7vgHGvdQp7jQCkRXz+nI dX3qwL3ggp0kUZDuKTsX1qybmxJ9s09Sc8oHElT+YYXxHdNJ90U2fv4v7XC7purQImd/ 4qrTneUphx1+TlYT3P1dNTRdukO2R2UjV5wM9OJKHjJMBAvU5EDevcGIVb9I3Adv1I+z CWWmTjBSgEfO0k7nyVqDCQaTnJeExoc5xNgCCPCYl84uPqzSArxS9/SMeS7xvBmMA2DB YTHw== 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=YtHoLXkTw6t/JlRnAsF+NpiEiduJaHC2fP51oWYDbz4=; b=sn5X7lIR3DzUMyoGBdpui5n+5fSksn98RsQMh2YPBCgMgg2CPdxzAj4LyXBDctkZTx f8kWvaBV2ZxCnQhGQneql58cEvMqTCmp9NlCChhSIg4DzjQ6BD8nRNGg9qMqp7BBWYuw D9jcZqWI1LSkf8bxzFmOgXg9igYjxzJEKFSYzlUU/huo9YFsB9xmwvQ2QvTw8/mpzOz0 hpKF8plQIeKg1U1ZLlVWm9vIZ2i3K/w5iz7tHG5VrvMTS1c2wTPuFrCxj8appI6FrlS4 FmdU0TJerOeH5sfKpSBFjgAnfgG56K8lmdkptzi5wBLBZf2+DVsQxDN7+eRedR3vvCT2 iO8Q== X-Gm-Message-State: AOAM533L4wnE3hrKJAeupTGzcghORCG9oeE+R1u3Rp/Ay3CSNTFcES4o hH4axT7WQdhSQMn5Z0OweIS826+wnUSuGg== X-Google-Smtp-Source: ABdhPJwjQc5STeo9T+BDkJPzB27ZJSlCUXaPGyxiDcl6klZdCWo2gmGzySfKwO1yf0QZ4KYnlBx1Yw== X-Received: by 2002:a17:90b:4b01:b0:1d2:abf5:c83f with SMTP id lx1-20020a17090b4b0100b001d2abf5c83fmr2682651pjb.93.1650437466958; Tue, 19 Apr 2022 23:51:06 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:06 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:52 +1000 Message-Id: <20220420065013.222816-19-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 18/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 7267fd8a..9729eaa1 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 Wed Apr 20 06:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619346 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=GlzK+mTl; 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 4KjrtB1714z9sG0 for ; Wed, 20 Apr 2022 16:51:14 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtB0Mxzz2ymb for ; Wed, 20 Apr 2022 16:51:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=GlzK+mTl; 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::102e; helo=mail-pj1-x102e.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=GlzK+mTl; dkim-atps=neutral Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (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 4Kjrt74k87z2xrv for ; Wed, 20 Apr 2022 16:51:11 +1000 (AEST) Received: by mail-pj1-x102e.google.com with SMTP id mm4-20020a17090b358400b001cb93d8b137so4151322pjb.2 for ; Tue, 19 Apr 2022 23:51:11 -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=90Hn5oLAozidZZEUQR4uR0WOr8J/Hp6bwTzAiryuqmc=; b=GlzK+mTlYhj86R/F1TNr2Tx2Ou+dvhijQiq3SvxKgNbIHSAmUoOzsb5Hv+6wtZIQHU TK0pkzrif7C7eJCB/C5QfoUoEXkzAxjJ7/SyB9oE2ChkipRwJn81KqzhDU7QELRvTbd5 rzcSubIZkd1wO4kH+4+JhuXt5LLo4GNQ+TO3S3crWTfxmRySHRfiHoM1u7OZ9bVeXMS8 PwjzU0N5HQX9jqJhumeuZ3O5JQl3FHzoJpqWGrxIuRJG68pMs4XgsIR5npAFFyvJsE62 Cpa+rojZGkCgh/Ubq8CFYwnWYGDF0nxAMirdTOUe//eCEMXJ95zF4wByVoB02GEEYy6t +Xxg== 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=90Hn5oLAozidZZEUQR4uR0WOr8J/Hp6bwTzAiryuqmc=; b=lHpMm1nrC2bsEHKVvvHAspfk/5xzLHVsShw581RYDI5PXy0EkumzxzsBJHd1BrRN8O GQRKWrbm21aWGBfwct0xjBVCzmR4+4VDgzgfhlPwUlscYT+g4Pk1ym2lUA7L/eKMdh3E rwxcB3X71GTQeWFwTafcvD/NoSPT0t4PhRi1ex6M1VcijPLwH8R+YZY2Yf6sNukQAASF 9Ew5qnFII3YY+5vSIlygT8O6chQKR3tYCxku5wmkocVIBH86P5yRUGlcmp9+gWszWtXP eeHsZ1kz3ksFsRpOHZfr3xgz0GMF7IBKp0Z1AeB4PERbO/3jbobYXEH68QOiFeS4Z00+ JQeQ== X-Gm-Message-State: AOAM533gc8iMqM5Via2Baj7WD4A81ljGVeVZ4U/RA/f6dAQVSpJOYZuY 1UK9EGIRCxQQ/UMksaiTNAJS3Wyuer5VYA== X-Google-Smtp-Source: ABdhPJwjCHb98ROvBofvp9ED3BpahFSOSBb/tVUfFsKtvl7QffEuu5ORtTuJn72KNKm96nMFz+2teA== X-Received: by 2002:a17:902:d1cb:b0:158:a94b:965f with SMTP id g11-20020a170902d1cb00b00158a94b965fmr19044646plb.96.1650437469251; Tue, 19 Apr 2022 23:51:09 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:08 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:53 +1000 Message-Id: <20220420065013.222816-20-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 19/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 9729eaa1..4c7b4a82 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 Wed Apr 20 06:49: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: 1619347 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=RBlokyqh; 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 4KjrtC1dMyz9sG0 for ; Wed, 20 Apr 2022 16:51:15 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtC0w5Vz30Lp for ; Wed, 20 Apr 2022 16:51:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RBlokyqh; 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=RBlokyqh; 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 4Kjrt92Mkzz2xnM for ; Wed, 20 Apr 2022 16:51:13 +1000 (AEST) Received: by mail-pj1-x1033.google.com with SMTP id n33-20020a17090a5aa400b001d28f5ee3f9so1140713pji.4 for ; Tue, 19 Apr 2022 23:51: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=dMX5/Hhw3TlInkOe7vN8cVa2yytiaDFCZqvFW/Su0lk=; b=RBlokyqhl4q8tSap694+mULSskCAjA3OoZzuhVeq1spkDfGARr6uWSQ+K+ADu5jZ1y pfAigh2P5MEIBJYoOgQctgogizPKg17ocJnNXCon+G+x8yJWw91azfhWAjNnOULEZ93+ eS5zUpbzefpFDkHGoWoJQCAdpTfY49HrwAPmLWoTveYoVwahJX+lQIY7MCaycfmQsiFh vwQ6g4eZYFFUEPsHXIwuFmOdheWj6mmVkEo43NjSE1z+NSbu6Y0IsdEnf1iunoTnjuv2 5kHucy6iAHrilgIDbvHKpmljSGGg0SQuMASzoRu25ywqoBeuvyJ3fa8PL5r7L/nQWhRW RQ0g== 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=dMX5/Hhw3TlInkOe7vN8cVa2yytiaDFCZqvFW/Su0lk=; b=cWI7sMzSuWJ6t0IxIOblYrY5f+61Y0VObWoCNDSk2FIfvkkgSehXX+UceiilwvrWwM 7xftHzYjpyRctc9foOoAyOpqvmR6gUgm8lhpa1EFo7Y92LmcOrehGnM98ScD7KY4o52f Cihlh9CWp6uospqdBL1f3GvPSAm6dqjvKWZCzpoDizfa1YQ6nImL+lYLJJgublHukr5o au8tSjgRu0M/skGsXdQgnSLgNWkBR3rRGAjSi72dkaqp3tKbTvE05Xg/mKxlAl06Jbi2 Kk+G5onbUKCv53lEMX+X971Vr+AtoOZgvaVjFxzH7VEMn/bmeiG995Kp0aYq5bvWfLZV DkZg== X-Gm-Message-State: AOAM530DtKmqBntgkQEBmTjzkZyCWMmw7BJNXTH9fjoZRP6c6l4ijQfB QCEH7ffFv3qVfUtgcOzVtSo7RfYzPEiZCQ== X-Google-Smtp-Source: ABdhPJyt5F5/b6mQi46l1HavLpG2EwlNoytZv0leseGWQPbMli9W1da7na/ZQYt6rP+rijkj1fqpOg== X-Received: by 2002:a17:902:ca04:b0:158:eab9:2676 with SMTP id w4-20020a170902ca0400b00158eab92676mr18102005pld.1.1650437471476; Tue, 19 Apr 2022 23:51:11 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:11 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:54 +1000 Message-Id: <20220420065013.222816-21-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 20/39] 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 Reviewed-by: Joel Stanley --- README.md | 14 +++++++++++--- src/pdbgproxy.c | 29 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9ece33f9..ba17c613 100644 --- a/README.md +++ b/README.md @@ -534,8 +534,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: @@ -547,7 +548,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: @@ -566,6 +567,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 4c7b4a82..3028d418 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 Wed Apr 20 06:49: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: 1619348 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=T48ep1SW; 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 4KjrtH1Sk4z9sG0 for ; Wed, 20 Apr 2022 16:51:19 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtH0Qf0z2yn2 for ; Wed, 20 Apr 2022 16:51:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=T48ep1SW; 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=T48ep1SW; 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 4KjrtD4wrdz2xnM for ; Wed, 20 Apr 2022 16:51:16 +1000 (AEST) Received: by mail-pj1-x1030.google.com with SMTP id j8-20020a17090a060800b001cd4fb60dccso1159033pjj.2 for ; Tue, 19 Apr 2022 23:51:16 -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=9ur4sQK+pdQW9E03ZKrmXTGMHRiG9Dg2N8mT7YKBefc=; b=T48ep1SWD9rhcHRUfNkfdxHtJl9ey8mvxDAssGmxSAIkbK9NceM7CHwEsTPehGzppT JTLZJ/e2mNwF5Ji7ftyHgzYCF5Vaz5Jg6HWGi0tp88qvjYDI7YbIh0G3J+8UvOmMW6PQ HZd4EjoTaAVTRo4VVmtaS6w7nz6Q0tILxRlbEj5FUDs7rOMx4OG0PvZ0pDaszXH6YboT 2lvY8Sp5n/7vcDavHk7jpha6ykggP4IJ/IOLlXKKEYsgE+pera2himqimXn3M/t8YM3R blfXiLf0qWm2xRI3chBa5tnyGe92gwhaOlKsf4BEwunN9IFgEW3O6KelvVHxRzagP7OG K62A== 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=9ur4sQK+pdQW9E03ZKrmXTGMHRiG9Dg2N8mT7YKBefc=; b=VIzibIOXsmstN0NNkBEsmayKNLRTJp7kB64tqQFTmHy1Rt5h/Y8XGD4o2TqqRq9khA EaOL6yMp0zVCGls8lxMz1U/qaydb59Mcj7SMcgxSbhEdjpkmtxqcCaaK3FUzMb62KI3r jWQFA7nALhcxwf2rKBNT6nLqocBCUM21dEgGIK1dh9f7fZm0kj7kAWbiLVox8pJEm92p DOET9Rb0Dw/o3EqDWtiZh2F4xrui5aGMIIcbUdM7hvUusRB26eTorSwGCEacS449/vPc grq5UjHh+OxNl+k3tYG0BoqhACdXNATdzmZRmcqx58OFgHmUu0rrYX+JQLZ+efAmxEii 6dvA== X-Gm-Message-State: AOAM533XwC8frYKRmHgyA/o43cH1ZCwwoPQFawrVEym1Bu6CIGJMZjmF ifOtAQTa1uORYsizrqVCPtYtv1DTwWOzDw== X-Google-Smtp-Source: ABdhPJxGL8AXwruG5vVRPufoPBc5OCDBsgAlFvyftoHczYcuKg+hF3HkGFHKxu4szc+eQ1UhfVNgpg== X-Received: by 2002:a17:90a:b10d:b0:1cb:a19b:1610 with SMTP id z13-20020a17090ab10d00b001cba19b1610mr2741207pjq.138.1650437474068; Tue, 19 Apr 2022 23:51:14 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:13 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:55 +1000 Message-Id: <20220420065013.222816-22-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 21/39] 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 ba17c613..c3447c35 100644 --- a/README.md +++ b/README.md @@ -534,7 +534,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 3028d418..23971c25 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 Wed Apr 20 06:49: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: 1619349 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=peUIapYf; 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 4KjrtK0BnHz9sG0 for ; Wed, 20 Apr 2022 16:51:21 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtJ68fQz30BN for ; Wed, 20 Apr 2022 16:51:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=peUIapYf; 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::434; helo=mail-pf1-x434.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=peUIapYf; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 4KjrtG5qhxz2yjS for ; Wed, 20 Apr 2022 16:51:18 +1000 (AEST) Received: by mail-pf1-x434.google.com with SMTP id a15so1075487pfv.11 for ; Tue, 19 Apr 2022 23:51:18 -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=U7rAf3Li/Y/CSPmM29+PsAgSOnr5cCqKx+EL6tAbx2o=; b=peUIapYf9H0GKEAIVfkqm1u8A4Tv0bxEw2OALvHIqKA8MVjSjI1y6v6qJnMllzseqX 0CucwZ3Ett6njCW5qh7+tTcTuiwBTKlq3zY17ygTeuo2U03+G3o25MSyTB8Y9DJ4bf3H IlK0nEx1tL558IBUH8pUQMijyyZQU8Ag03269tnO4lfSz4aaBYPC6cSwucspvu0HMr8j OxH3BeuiEWb0PB/Rwcy8VWy033G1Dsn0HKwNZHv1FeyokeQLlXsdZvGraTaD7c2t+8WO CDLOvYxMshLJhc40jcT2LadP9kn2/tc3cu60KUKhDxWpXvgAIc2v2aF56iavS+X/Em9k ezpQ== 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=U7rAf3Li/Y/CSPmM29+PsAgSOnr5cCqKx+EL6tAbx2o=; b=bQyv5xzpegaiCqdQzac9b0xC9SkAUsExDrm32U+avSV3AMnoqP6BIgv4Hzj7xX7pXM xLQYB6gJJlmd0zNv3fhS7eWrlII3WowYwmdKZVRXbNdcOvpo9pU72Cdlm/n43ltZD65J jCXTaG/rPLjynMKaKwSoMw7wDkCfsKdmzm1TSSPB0PiGWqR5uRSZFgyH5Xyr2fSg/AAD /HqQit6QZ3V1/iXRUyKGinc8XOjuMKZy+K6n4mMAuKEO9ySbm9+KC62DIJroKofQeZ+S 7A40TeLkWJTccNgpDF8AdJJeeSAd5cHwLKTIA3MrqMzRDf8hwiGgu1fiVe5wFWMFWd7k o7SQ== X-Gm-Message-State: AOAM531hwxsKgGPOpik5fd4RDKB+Zx+5FNe0C5ftsYjmR5Fpushrxx+p 2GyR3dYaeqPudtqU1kCdZcfKmpfHezhaAw== X-Google-Smtp-Source: ABdhPJzp6M9DEgaOaWr8/W5N+Q9QbNzxG1LykFcJRD1sLrQJURxLXF5A9AVVaDd/vTgnZyZG+YUHYg== X-Received: by 2002:a62:fb0f:0:b0:4f2:6d3f:5ffb with SMTP id x15-20020a62fb0f000000b004f26d3f5ffbmr21524240pfm.55.1650437476434; Tue, 19 Apr 2022 23:51:16 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:16 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:56 +1000 Message-Id: <20220420065013.222816-23-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 22/39] 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 register and quiesce the thread. This bit can be checked to confirm the thread hit an attn instruction, rather than assuming a thread was quiesced because of attn. This makes the gdb breakpoint code more robust in the presence of other direct controls (e.g., host-based direct controls from OPAL). This change also clears the SPATTN bit which clears the exception condition that raises the IPOLL global interrupt. That interrupt seems to be involved with the IPOLL interrupt storm and lock-up on POWER9 (although this does not fix it). Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 79 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 23971c25..d7ceac8d 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 Wed Apr 20 06:49: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: 1619350 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=IjJ7uBP3; 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 4KjrtL1gKGz9sG0 for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtL0Fp4z301s for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=IjJ7uBP3; 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=IjJ7uBP3; 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 4KjrtJ3SmYz2xmQ for ; Wed, 20 Apr 2022 16:51:20 +1000 (AEST) Received: by mail-pj1-x1033.google.com with SMTP id md20-20020a17090b23d400b001cb70ef790dso4133105pjb.5 for ; Tue, 19 Apr 2022 23:51:20 -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=K49LXvLNHXhkBntNkST5z/kJam4sc9snCqXnda0c+l8=; b=IjJ7uBP3+WSsvxWOZg0UWCczXSba9l4PEp9rfq9blyA1Z0SzqKXP/Vepx/b/o5STII IcczDRn5HH2xye6/UBWn3sLLSKjvYINFqUfIIbk+mIVYS91iAMcz5WXMHTkbq0knp3K/ pHAkJvqc7XbQ4DAwR/zP49AyhqqKPdJIHsxPLQ0Y+gfcVFc5xt9MnERv/fHIzgvId5od BTmOVC5xvMBa0Pap1OQfG7JjHPDLriRnuR9+0Fi10gganuTELPgPH3pvnb/QYKVNZOt5 kUKF7IpugsLITKJ1E2ykFPoH8DVxlILzQxZ/RrEtq6Mekag/t25y8i9L5Ye3CzDU6f2B b72w== 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=K49LXvLNHXhkBntNkST5z/kJam4sc9snCqXnda0c+l8=; b=lO8YiVGYHDOPpei7PS/bnLH4MlsJUhMtk6D3W8dK7VkeIX4g/ZNvaRhx4ia+h/FvDj xsYhhUwiZJ4Ri2d5FmPq28GOCMPO1ROvusbxA64PlsYY7GW2j9Uf7HoswWMPp7+VFW9F dAW3tpFZT/tgG8k/DPYh4pO7DdVZU3nflU76VyWV4c2AlMF+DIi30gzo6JULiiorIEJR KCRYxOxbsnJQfg+2imD+SyCNhJ0DvSKzo/4JTMNuvS0ndJyBdyD5pmmGiZS30VOYCjFk m1Ctz/peYyXNYpCokATcE7/6uvUWGT0H0WaM7HYSblTF4Uqu8EzOQel4lgumuEx/2+1c UQxg== X-Gm-Message-State: AOAM53133MPUYM9iVDEuTINbnWZSkf7ZVYIoKQyAy51cB6MnEcE5erby pI4qNA+6oErQehX29sqELPdafRdAxcdBng== X-Google-Smtp-Source: ABdhPJy4IROdywEj6/XqWWpsOZuIP6gKeBVXEBMOkt9CGRLxvwLA2DQkOhJjgPynxibT7VaUAdYIpw== X-Received: by 2002:a17:90b:38c4:b0:1d2:66cf:568f with SMTP id nn4-20020a17090b38c400b001d266cf568fmr2770706pjb.18.1650437478728; Tue, 19 Apr 2022 23:51:18 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:18 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:57 +1000 Message-Id: <20220420065013.222816-24-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 23/39] gdbserver: breakpoint instruction test current host 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, because a processor can switch endian asynchronously and at any time (e.g., after the gdbserver has started). We don't support endian-agnostic breakpoints unfortunately because bswap32(attn) is an illegal instruction. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index d7ceac8d..4572c689 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"); memcpy(data, attn_opcode, 4); @@ -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 Wed Apr 20 06:49: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: 1619351 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=D1QYEDYz; 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 4KjrtP2VH7z9sG0 for ; Wed, 20 Apr 2022 16:51:25 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtP1Qqrz2yn2 for ; Wed, 20 Apr 2022 16:51:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=D1QYEDYz; 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=D1QYEDYz; 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 4KjrtL61Fhz2yn2 for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id 12so950638pll.12 for ; Tue, 19 Apr 2022 23:51:22 -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=SM0LwWTdLbU0ls+OYpiOTf1ONeyi95kxZLireRQvXbI=; b=D1QYEDYzaPwIXNSEXvpfhbjPGtcDPAamYb8ZRMJzy51O48Pqk8IKg69hkvy7Ilu1pY 7IkrWxfhsy/87BO+oVsPOU6v52yWM9vct5weRtysjoSWhO44s0U+gG3F3pdZvkvn6IaE KfQgEHT5NYQN4apYMlpDiOncqqfk/vyB4qRaT2uxvv68VBWXW6ny+Yhh3865OXqUwPNg 9OGHfax/D+tnbCvuKvtGDgU53Py3L2JR13ZezW1Ksls3dKHuiLcOy6IQeraSNNjKJJPC +XnJhL0TB4CsO7311FNbTpYhmNLGlxj6creGdSIq1YuDtIX6NMFYXkKDd5Ef+IJFHMr1 ZdDQ== 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=SM0LwWTdLbU0ls+OYpiOTf1ONeyi95kxZLireRQvXbI=; b=aMfg7f49h9YgCjJ4o5xp0L/mmmHIpmRIfw2QMZMl0E83Wx4u5G/ckiotcVGSKSRhFB 3IyirNTL6Peez0zfpZGwr5pORRTY3bzMsYWX3VHu3fmjC8j4/KQXJd07INo2JQqEczCo hfNTc3g3JxbTcnR1JD1sIEiK/rE7QhaGhEYM0bA+TOPZ3KlIKlDyhkEB7T4WP7hrlvMm MmnNRAonTMu1495gN8//HDJZSTACxIkqZ5YMaeikFcdaUmDbXD3rbStepMVdTS35m9KH 1+JsnMlv3g04iAsgTmlE9scropLG3DtH8xb8b3Nemcu7xaVX3+Bke10FFW56tb9RPkDn SC4g== X-Gm-Message-State: AOAM532VH9FuZAmEFPPyfpvc76CHElmIbVBny6TWO1ECuZz3rWAwmIFV 7iVwTzBA7zEANLqKRBXkoLeomwe1CLAMyw== X-Google-Smtp-Source: ABdhPJz5xsEFXBhBW1kWMkPlusfklWGPxiaGyeu3UxjsVkjKeydETx6AFdzqFiGMt5uwnbuciHZ8dg== X-Received: by 2002:a17:90a:2809:b0:1cb:99a8:ffcd with SMTP id e9-20020a17090a280900b001cb99a8ffcdmr2732916pjd.7.1650437481140; Tue, 19 Apr 2022 23:51:21 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:20 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:58 +1000 Message-Id: <20220420065013.222816-25-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 24/39] gdbserver: catch ctrl-C to clean up host state 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. Later patches will add more host state cleanup. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4572c689..ef8aa479 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 | SA_NODEFER; + 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 Wed Apr 20 06:49: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: 1619352 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=L4w6zjRW; 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 4KjrtR2R1Jz9sG0 for ; Wed, 20 Apr 2022 16:51:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtR1f37z2ymb for ; Wed, 20 Apr 2022 16:51:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=L4w6zjRW; 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=L4w6zjRW; 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 4KjrtP1Cwyz2yn1 for ; Wed, 20 Apr 2022 16:51:25 +1000 (AEST) Received: by mail-pf1-x433.google.com with SMTP id n22so1143921pfa.0 for ; Tue, 19 Apr 2022 23:51: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=nAlwd5K2WMbOHIhQby1lFykLL3PUhgVgvg4Dc5cXix0=; b=L4w6zjRW64tE698T44QwN+TOB2a5Otk8t+uZ+fA6WZc7haxhL7+8N4kSLeoHyoIfw4 ILx+dnbVd6IgYmC/2ZQC1LwDL6CyepPXAne7uZSM/fwxxcFzwv0/Yx7iKprmoDI/JNzo cFPIRlg69tl0Pd6OnfL9E6m6EHzxhPm+NUTfPaf9OKFnbX+i6RC+5WXS33M+1OkkjfLA RT+AD8WHSR+jOyKanmEaLq3QkNkyUpV6RhU8xTEBAMhIi+Q0R8DuIz91U3smFmpmCH99 hJv4pb0zmtpVmIsT6lAdXfNp8lXsOnqbpB0tDUFEMR5CHt+RkzodlxCiYibzzW9kRAVu gDXg== 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=nAlwd5K2WMbOHIhQby1lFykLL3PUhgVgvg4Dc5cXix0=; b=5VVsJiV9nmXpYSvWlLpJSTtEl4d73N/PxX2Drah+DKCjDNUdP7QAUx41CyUKn2ZGCm u+NmiA6THfAwTGCEvJrLXtImXWtRzmuh8ER6QEjObkDc/Z1dtUYzzUyM65tyocUFDHJe oIJMJvYvWhZam7T1qgmL9uvfGvdwl9KRNjwnemadoSXpdoA5lcRuQy8Ou5m85ExFWLF3 o4xnz7j3vaSlEXbpziSpw39CLER86NJQYOKp2yaR3FEozQCvIsR0NW0Yf0NqA/q6rl0H ST3sllEq2UYA6oqqGf7xBqUEVXU6Ju3TEv4rDFz8/CnknYFC/+oEI5NFMdXihw9sbpIg e99w== X-Gm-Message-State: AOAM531SU29qWwmVPQCRYKb/FZt7/TUunsorHUAcrm47QgsR1v0bcvXw JjryPlgWoxpzNfNZr8rjE/erRHg3j8YQdQ== X-Google-Smtp-Source: ABdhPJzMQsPyJEb7FL12jZQnH0LoGf54hfrvPdFtr6ALzSmvTdNhsYOXM+3EC0y3y9K8F1mfmqesbQ== X-Received: by 2002:a63:4d64:0:b0:39d:5e6e:242d with SMTP id n36-20020a634d64000000b0039d5e6e242dmr18083513pgl.32.1650437483372; Tue, 19 Apr 2022 23:51:23 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:23 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:59 +1000 Message-Id: <20220420065013.222816-26-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 25/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index ef8aa479..393b37bf 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 Wed Apr 20 06:50: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: 1619353 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=e87OzjLi; 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 4KjrtT3mDRz9sG0 for ; Wed, 20 Apr 2022 16:51:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtT2fdcz2ymg for ; Wed, 20 Apr 2022 16:51:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=e87OzjLi; 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::430; helo=mail-pf1-x430.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=e87OzjLi; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4KjrtR2Sdmz30Dp for ; Wed, 20 Apr 2022 16:51:27 +1000 (AEST) Received: by mail-pf1-x430.google.com with SMTP id i24so1096226pfa.7 for ; Tue, 19 Apr 2022 23:51:27 -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=yhXjfMDXjOopI6H4+0u4FDFR9/203BdHbQ7yqhKx0Gc=; b=e87OzjLingBbIEIswJ7NytctXcxdEz3KWxZE56lA/20qIN2jYI78kiflrglOxht9Eh fllFXQZUJGluQFei72iotCPBczqGgZ1wL6x3qg03JEscElnSPBgqkcjKi8gcaJSiQTlI XNLdMt5orcd+1nMGGrV5qG1bZA+cgmyhSo99OTjytWqJDF5cKFeTWE65QjE5lYrLund1 aVQsEZ0CoNvpzrFCPVFgy6HpGQ6gIGdkKpruX+NYPLlAXRUHoo3wCr+I41wqOkLV7BMW 7ajMlX3p/BTDUS/KSnXk73OeU7rdLA7SmKiVFEcNpuE86bVMmjUm6neF325tPRONuxwH PX/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=yhXjfMDXjOopI6H4+0u4FDFR9/203BdHbQ7yqhKx0Gc=; b=Rq0B2zsP+hhygQ6PlvMLumJfvtjEHIpxQbbz+DRxZMSiSccft2ZuMrcWIartUTXSiS 5U6TfkvXsERwq7do1IrMZJoDctkCsK3FMDxLPORCmDLasOu4SYrewaoWPYvm+F+TwIzZ N9FcoWRPzWUF8iZO6iO8Onr0Dw5xI/eNUVs6dOankepvFQL+18ZTqOZrounuaOynwGfu cGK89FVLH0LqEn2bn+jQ51KQx4hr7ZHak4hOhiTRiPGpBtMD8GCvcgOu24oJe8FEIcRe U5lygi+hblR5LQ9Z1mUwlYWFKAbcZJAR8SDjrt3MqRV5MPPQVVnlpCfjQS+X4ZCNMSSu W7bQ== X-Gm-Message-State: AOAM53205qibXPG6FPRBVMJmD5C1CRL7sq/JVdQN6/LU0L8SEVq8vnRv xX4gLNK5jJjOCpMhG4QPV85Srp6xQ2S6vw== X-Google-Smtp-Source: ABdhPJz//zAO9u6tcx5yDtE5M84+soxaSAh2uytOVQot2N/6B86AiJ2gBU5uI1u+q/ILN/HIC8pb4g== X-Received: by 2002:a63:4412:0:b0:3a9:e7e1:81a6 with SMTP id r18-20020a634412000000b003a9e7e181a6mr13125802pga.532.1650437485534; Tue, 19 Apr 2022 23:51:25 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:25 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:00 +1000 Message-Id: <20220420065013.222816-27-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 26/39] 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 Reviewed-by: Joel Stanley --- 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 2ce41db8..563b5812 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 393b37bf..b8ee2a06 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 Wed Apr 20 06:50: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: 1619354 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=O5VxDD5J; 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 4KjrtY48Nnz9sG0 for ; Wed, 20 Apr 2022 16:51:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtY327Xz2yn2 for ; Wed, 20 Apr 2022 16:51:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=O5VxDD5J; 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=O5VxDD5J; 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 4KjrtV5wvpz2xrv for ; Wed, 20 Apr 2022 16:51:30 +1000 (AEST) Received: by mail-pj1-x1029.google.com with SMTP id j8-20020a17090a060800b001cd4fb60dccso1159501pjj.2 for ; Tue, 19 Apr 2022 23:51:30 -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=OpNGnNkesvWC7X6J3CQoHsEQ77BKvlbvuMXrjHXhdc0=; b=O5VxDD5JgGlrV1XfLt8ihYnD2X8EUG30eYTh+oOUUr+Q2shKM2CFN0EW4VGPDVYIq3 BGiosSw38tgxrGNs9hLqrCRUeUsg4Z9VGZMnYewXpzQplkM+w17Ng43I26hZYqPzr8SF BLMHi2BydjY3LWgK1tZ5YR+Tg4fE2/rV2hKwC5iWErbL5W5Gjx55VpxTNwTNVFzCLTLB d8hRrXbQM/vBGHXw6igtnpkFRNu1LWUb6fD+6aJ3qEqQ2vCqRKF4NBQhyNIKZbQu6Qk6 ZUPsdkos0G+sxg2jUZwuLS1G2gL7rgu2MsL4OcWb5nLnWXqkYArV+n6vLocNAKSg0RCS IRnQ== 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=OpNGnNkesvWC7X6J3CQoHsEQ77BKvlbvuMXrjHXhdc0=; b=ybJyep/Nk5FDvOQUAn0lTLzTr61AtPh2JeFXQ2It2xVKRs07r0zEmu3luLzpxIr2Sb 1f/ZKbFjdYWbXlbL2PQbOOL/SVBCjy/RqSk96f6ZtoxjnXdkmrdRb9efxoenhqVifD/J OTCiAxo9UZSpQhWJaAh1tSCdM1Vow9d3d2hR3hIYWusX4Hd14kKToF+/F5nLxY5J9/hO DPT32FWSb5E6+fPQnC55dX2mKOPGDqLXL5h0v15Dts/5a+YetflT2l+xabR2GX1i+a5P o9QKTRM6u0KULGU5dPvafrqal8uSqE4DregOhSETFtILBIk2ILEsqWf5AP7NRlcyWAwl XV1w== X-Gm-Message-State: AOAM533IELEO+Gx2XAvUPRMoFvfIU43ct2S0y/vx5Vmp6w6yV0rqodle h4ja/JfOqdziAXZoJwYegXDCYk067fgT3Q== X-Google-Smtp-Source: ABdhPJxf0ZqZvnS+ekKO3i09lnsa2t75RPYni2cRn9VCu30Yd8c/JhXurFhj+X3pZaGvrLjkiD2TyA== X-Received: by 2002:a17:902:cacb:b0:158:694f:23ff with SMTP id y11-20020a170902cacb00b00158694f23ffmr19418574pld.119.1650437487656; Tue, 19 Apr 2022 23:51:27 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:27 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:01 +1000 Message-Id: <20220420065013.222816-28-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 27/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index b8ee2a06..d0da1f37 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 Wed Apr 20 06:50: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: 1619355 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=EoD/nqqX; 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 4Kjrtb2R51z9sG0 for ; Wed, 20 Apr 2022 16:51:35 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtb1hNDz3bWD for ; Wed, 20 Apr 2022 16:51:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=EoD/nqqX; 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=EoD/nqqX; 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 4KjrtY19Hyz2ymS for ; Wed, 20 Apr 2022 16:51:33 +1000 (AEST) Received: by mail-pl1-x62d.google.com with SMTP id s17so965345plg.9 for ; Tue, 19 Apr 2022 23:51:32 -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=LblFiSb2m/hJGu7toV4HT01HbbTytiMK5xQzVYrY12M=; b=EoD/nqqXmy35Nm5iVnZp4qbJREnTuoTGDih3blJlyzCxCg2JwE9jZUWFYeX5M1Gvm0 pv7bQ4AchP1c116p88/dJKKN5jqE8cNT36zQaBMc1XOmNfHGtr+G7n815dLT3bWFI22O pmeIgctNtUWd0JmdeesNVXutGwSlElvZyChJtdQnMFrboUVey3I4hbq2bwHhp1bNaV9D 76PzhfVp+ET1fjVRsOhD84NHTO2vUaqXP8f9HPHOS4/dawNPt7jLhZLTTW/lE0BpdRET Fim5i2Ug5gwff2rpU8UzOET5bP8wIlosnCetAjiOwei9sexPKVkItGxCtOPzoccqc8bN 3AdQ== 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=LblFiSb2m/hJGu7toV4HT01HbbTytiMK5xQzVYrY12M=; b=J46DInOFXmxs4OLfloVGkC6yZM/tri2n6H6N17RX4q53yrWIeZP9BpGFBAJuxRaEFF NDP1kOlb5LDJdqI6Uo0T1U1A4ZXmFBIzrEZMedbtgDp2OMwuQLY/bErE8CpHX/2Oe20N Ag0EB/DPbWlAb5UzU/aov/xEsHSmSfH19JqN4oOPk73iWHaCDyYOABVUM+XH4Y9pLZIO 6NgeME2UIeSzseT1BSGsuWqZnUHFzIvu6nWDaJXZbs9gt2UPjKZLTHlARjn5A37QyzPO hgNvBnv8QbbkV0NpMi/MFfEiZRxAQAmM3Rk2wi0phWKug64mlG9TzDsFgm45P0e12ldK 8XSQ== X-Gm-Message-State: AOAM532WPsheibG8B7Mn9TR2TlasJS/nL2is7y1x+fadLnqO3PscfMyP MzO8K6OPFLdG97yn86+DTPD5WmcI/bLaVg== X-Google-Smtp-Source: ABdhPJyo8UEW6PsEx96fJsmkhc1dd7m82G6mpkyFLekw7DN5AaqixYb/GSs+GAu9UMujMlgh4LXaxQ== X-Received: by 2002:a17:902:aa8e:b0:158:e94b:7c92 with SMTP id d14-20020a170902aa8e00b00158e94b7c92mr18306772plr.126.1650437490571; Tue, 19 Apr 2022 23:51:30 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:29 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:02 +1000 Message-Id: <20220420065013.222816-29-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 28/39] gdbproxy: 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 Reviewed-by: Joel Stanley --- 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 e49d56d3..dc1275c3 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 db982092..567f1dd6 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_precompile.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_precompile.c" +#line 211 "src/gdb_parser_precompile.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_precompile.c" +#line 227 "src/gdb_parser_precompile.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_precompile.c" +#line 472 "src/gdb_parser_precompile.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 d0da1f37..4f30ede2 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=%"PRIx64"\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=%"PRIx64"\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 1910fdba..2005083d 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 Wed Apr 20 06:50: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: 1619356 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=ilGjPmab; 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 4Kjrtd2Y9Mz9sG0 for ; Wed, 20 Apr 2022 16:51:37 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtd23LVz2ymS for ; Wed, 20 Apr 2022 16:51:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ilGjPmab; 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::102f; helo=mail-pj1-x102f.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=ilGjPmab; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 4Kjrtb0vGHz3bWD for ; Wed, 20 Apr 2022 16:51:35 +1000 (AEST) Received: by mail-pj1-x102f.google.com with SMTP id n11-20020a17090a73cb00b001d1d3a7116bso3203291pjk.0 for ; Tue, 19 Apr 2022 23:51:35 -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=chKZfXqK+7phN61hWpaLEBfrcjZ3D/jRKTK542dIDQU=; b=ilGjPmabzuiJdNbvLlAriEnryZT7KFbdyZqQ4ZZAQxrQrWyZqDGj7UUspo8pUsOx2u ktW03BcRkrS6+aT1Rg4QYmWRGhlQThI3Q1lrhRGp5TORkOIpBOx1EwSa0WkPzh2JWECD gB2VJmi6Z6CQrnk8MwXKoQsPPt9g7uL+cJBMSxLSn1qxDhUVIHhThb9XQCBW/Fxygbhb F84QT5H/pqV2ViYKVmmaMQH1xT4eeTOkPHlL/hsZ0GqnSFc7FRLahkJDlNGp793XCU+8 px4QhRgwK/ev2H6j9xroskp1EqnKr/D/pGMi2l760GX0ZmdeHlz+HVbr1LOSvDmQZV0H dugA== 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=chKZfXqK+7phN61hWpaLEBfrcjZ3D/jRKTK542dIDQU=; b=DFnUjTAQLdLv6ymJ/54HJ+zMIk30VIT1fIQBChfdH1ToRvHJ7AQeCpM0I9CozSLJOt ZcL5MAIl9LyRGWsYBHvT3aOPWvGRfJxTjJNowja1w50r+ehuK+Yj7t03EjAKnj0Zmz7o mxxtgiOPLdjH1IvCglcFU64CTy4X7H9bhDHUsfIGtv9H9SnidX/N/RKEp3n1sSlovJZT i3B/5SUU7KW0nk3kCsmufBJ2towugG6Vu8xNstYSPxATbovJWclzJN6UpFcxrokQkqI9 8VHdzW3McEd2PS8vZ751uLNvzd/T7dvn7kReeOH76leqDgSGFlda7GLy/98xPfoj78fI II8A== X-Gm-Message-State: AOAM532kk1/yyn4psgoybZh1CwQDnmbSACeYIF/qeY3vj7oyqHABXOTo 4kWW2E+ZAcCecP4iQyWb/XAF+nQP+5qEEg== X-Google-Smtp-Source: ABdhPJy9yakx4InNrl7gwmCxFXOzpwzl7gsWGl/ufvfDrM3SOuRrpcdN4Z+bzRXGULh/o9pok66w3A== X-Received: by 2002:a17:903:2302:b0:158:cef1:79b9 with SMTP id d2-20020a170903230200b00158cef179b9mr19607859plh.64.1650437493051; Tue, 19 Apr 2022 23:51:33 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:32 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:03 +1000 Message-Id: <20220420065013.222816-30-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 29/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4f30ede2..01419108 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 Wed Apr 20 06:50: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: 1619357 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=XLB/m/T/; 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 4Kjrtg3nsKz9sG0 for ; Wed, 20 Apr 2022 16:51:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtg1HqWz2yZf for ; Wed, 20 Apr 2022 16:51:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XLB/m/T/; 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=XLB/m/T/; 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 4Kjrtd3N0hz2ymS for ; Wed, 20 Apr 2022 16:51:37 +1000 (AEST) Received: by mail-pf1-x42b.google.com with SMTP id a15so1076030pfv.11 for ; Tue, 19 Apr 2022 23:51:37 -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=oaQ5pJ3MjXwsMBH/CpDWzxXs3EJwynKNDVbiID0LuDY=; b=XLB/m/T/LztuFleWco5nqo5OtCQLMuDz037KAE5x/4lSXQfqOCR6xPNjp5/uOGltAo 0Bq/WWXxWH/QHc/LFpM/xAnrMN+JCCfZPYt4Grl0s8AXVjpfhVIBBDo/ibbi5cdLzBNb 7H3a8O3HcIOTXa8MZjbMBWG4FQBxSI0SSRTB2Q9bMq2MHJSYwcJ3CCzmfGcZ/ECF613X AUA9mJM18V9uW0YjJ7X05bdLjhcMovwoDjdmL6xCBOOppkmrfqtD+IEzjpcS3xK7+00G vP8wMrf42vTZkA/77Hfpi4AB+a02KngNsZRvPsIs+LbyAZTkEyWG+W1+V32VUWPOJWQ9 x0bQ== 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=oaQ5pJ3MjXwsMBH/CpDWzxXs3EJwynKNDVbiID0LuDY=; b=jwvFw5M38XSUpg+fAZXtIFFwwzTXE2w+IYjf/en0x9t5h1pUTav3QCoUQvfRkxlxLm WIvnfY0s3HUMVDPmbr0VG+yeyxkqkDtkVxeaT/OZGWIyb0z8okT+diINeXsSAtd/JBEw oiuJvhYOXkjRk+lWy0i0QDFWnuo+QSomUCNhCxple4ozS/YnSMRDElCmxXP6T0U2sQFx CM5RatrPGQKoe3oybJ/mblqDmb/cAby9Pgv4L4aU0fDJilElMrImaB+PRHdhUlmtcjnk pfGyiucU+EGj5LaoKqDBKN1lzDoYv+b54BwcKjsxQG3IKdsYR1PdGDQmjp1RImsmrGZo pHWg== X-Gm-Message-State: AOAM532WMvFb4dK9ui0CJpQ+L7zbbGNOodX2kDAVP+QRujNm6Ev0lTGX 7U1Pnkk7NvTN8z+YbJV7gjejvq8dwEhhHg== X-Google-Smtp-Source: ABdhPJzcu15cdHJYIUObgnha2Ew8Xw2vPkTR/4HplQmMgQpNF2ttR8ZMCmyuXSThH2W/BAdXqZhluA== X-Received: by 2002:a05:6a00:22d3:b0:50a:9709:fbfc with SMTP id f19-20020a056a0022d300b0050a9709fbfcmr6363601pfj.74.1650437495437; Tue, 19 Apr 2022 23:51:35 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:35 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:04 +1000 Message-Id: <20220420065013.222816-31-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 30/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 01419108..c5870091 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 Wed Apr 20 06:50: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: 1619358 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=AkEe2wkB; 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 4Kjrtk375jz9sG0 for ; Wed, 20 Apr 2022 16:51:42 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtk2HyNz2ypZ for ; Wed, 20 Apr 2022 16:51:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=AkEe2wkB; 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::635; helo=mail-pl1-x635.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=AkEe2wkB; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 4Kjrtg6DzMz2ymS for ; Wed, 20 Apr 2022 16:51:39 +1000 (AEST) Received: by mail-pl1-x635.google.com with SMTP id n8so992096plh.1 for ; Tue, 19 Apr 2022 23:51:39 -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=Dai1NOCkH03lRB7FKGaxe8ZEgUrVEVxXdzx28mpJ44k=; b=AkEe2wkBpgnN6iQ67RyxmMlEBeQicFLRd6Una1NfZSghGZTgOO7Xe71V/hOkNW2BEl 4gFiLbsocSrP2PA237XJdepHN/Af0PvCpk7ylAfStli9MXhAYDxzIA/VnUz+Nj325kum YKSQz7tstcOn2mwenEyzCARio60SqX7gz+FCmvRIof/RfQU14yswWoMDDv00lkla3HOe /rDM+wF/6iU4RLQFvqKEwvUhhdGrlOUtGKjnLb8qrba+A7EQwJc1uUjxwCV8TNlgXivp fv/3NdUU4ZuVTzdKP9lP+zP1N9POYQiR3lix910KznWAQHDuL4CTT6Wh9IASuCEC0grb S/eg== 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=Dai1NOCkH03lRB7FKGaxe8ZEgUrVEVxXdzx28mpJ44k=; b=qmphaui8HBoBNlBd+8VZde6BqakhLgJs5eg4dUTp0Ism1sVXppKxWPd5y1ApBGcA+e 63J8IvmXcCa8vD7B5XkWKPva8rp5Uk67YKdpAPiEv1mH28O01SBB3VoCRqbeCEAlAya4 8S1HFAP3tIYyrUCmTJk079e53d2mHv5emxYLS3PX/gBghuqdTDz1CJMhE7b6P9BZLzUR EKWnMrOQT8kuoO1d5Oz31WSsc2MS0d7dEZFEJAdThVyZDTb5wgha3QnxJ23mSXSEWX9S k5JmiXV37OPNrHMHThy0e9exabQdy3lJ+Og+Qp7s3lOT+i/V+KMkWI7RzUw/NTNbIUAu /wyw== X-Gm-Message-State: AOAM532CcmsZgYnhOELCYc5NiOuh2h4z0SQm15GysYQOvcrOML7CMk+3 1A9DOkMqA4IL/cN9Rm5Z7GulM5p215z7Ng== X-Google-Smtp-Source: ABdhPJzD/OOYXlQTCrR2EZzpzdpCPjIXJ7uoUeW9YQrK2hcLmpYP03GXpWTBm2EgpbPqMWfnahgAAA== X-Received: by 2002:a17:902:8487:b0:158:f82d:e39e with SMTP id c7-20020a170902848700b00158f82de39emr14533435plo.52.1650437497543; Tue, 19 Apr 2022 23:51:37 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:37 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:05 +1000 Message-Id: <20220420065013.222816-32-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 31/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c5870091..735615c6 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=%"PRIx64" 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 Wed Apr 20 06:50:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kjrtm3dpYz9sG0 for ; Wed, 20 Apr 2022 16:51:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtm2BFcz2ymb for ; Wed, 20 Apr 2022 16:51:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::533; helo=mail-pg1-x533.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UD5Ne4oF; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Kjrtk1yl5z2yZf for ; Wed, 20 Apr 2022 16:51:42 +1000 (AEST) Received: by mail-pg1-x533.google.com with SMTP id g9so774005pgc.10 for ; Tue, 19 Apr 2022 23:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HwixrS9cN5R/xnk0LQNKGdLGgQcxWSBp8HLQnSlVfHw=; b=UD5Ne4oFSK4vOL/DwEIeTcgMYIpXNLUpcpzJnPWoqMIHQKsYV3QECr9nTqpgTLe03q dAFdQt4ZgptQZFyPH4lB/cSA1rQf/MlPhew37QrNw8mRk1HreuO4ov5DhT8WzJSul2pp 69GAKIwYfaKoT4M0JGNYb8cLKJeL+1UCvOaOc5xKrLBfLNEJDZ+CoLaCKzhijhOT2cLR Fh4clCQv2NVVdHMs3tpC+eIf0pyxcNFioFVP5yb7wRzHi2FLephESQoouuRfOw+A6IrR dmeRd8SJOllx7jGomzkRf6YHxp51D8ehnsRZQLMRHJJsUaXJ+soCLBjlQ7NktqFtzloe O5xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HwixrS9cN5R/xnk0LQNKGdLGgQcxWSBp8HLQnSlVfHw=; b=UdTNGhyu0JNFA7983/W+pUle1pjTYZ2ZdSNveQquSbU/O7X1uGG4HZZjuu1hnZD9ZL wlghNURCs/Y9YpC/xKKaQxj6+n8eo3rF7VTVZEjVgQr0rCL08e8Q51rD4PJpsfc68X0x k0d4IOgbxrUgBLDkeMgjfqJ7IOzln13T8b0KYYPwlR1h3bSBsqEDDPZteVbEW8tnI8Lb DSa++nwO/n+lnsMFWCtyqFfKiw/aUKx0Go5tDQEaFGAy/x6EGSWI1PKpTlkTW4j7xBDs 2MwpWyJqAA3uOTwIt9+UnRBRmQMTOSwImSpF3ku4/PE875ocQ+0fRckvTnL22bcixqy+ XQ5w== X-Gm-Message-State: AOAM530A88oM3eqvc8YEhx1AytVERnktNeJrhMNIxy4pWU2+czNOOi3d TBtcAQVQ2uZ+nggnAIkxqVV2L+Hw5Eo8CA== X-Google-Smtp-Source: ABdhPJwnY1t3mcM4b+Mwbzdfoihtw2SNOiZp3DF3N9grrdtr4I/R0eKPwUUadlCOfPMvzXp2USOadA== X-Received: by 2002:a65:6e4d:0:b0:39d:a6ce:14dc with SMTP id be13-20020a656e4d000000b0039da6ce14dcmr18143206pgb.476.1650437500038; Tue, 19 Apr 2022 23:51:40 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:39 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:06 +1000 Message-Id: <20220420065013.222816-33-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 32/39] gdbserver: track stop reason per thread X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Maintain the reason why each thread has stopped, which allows in particular distinguishing between threads that encountered a trap, one that took an interrupt, from those that were stopped afterwards due to all-stop semantics. This allows sending TRAP/INT/other stop reasons as appropriate rather than always sending TRAP. While here, switch to the more capable T packet rather than S packet, which can includes the thread-id. Switch target to the thread that hit a breakpoint when stopping. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 85 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 735615c6..52f34a91 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -30,7 +30,16 @@ #ifndef DISABLE_GDBSERVER -/* Maximum packet size */ +/* + * If the client sents qSupported then it can handle unlimited length response. + * Shouldn't need more than 8k for now. If we had to handle old clients, 512 + * should be a lower limit. + */ +#define MAX_RESP_LEN 8192 + +/* + * Maximum packet size. We don't advertise this to the client (TODO). + */ #define BUFFER_SIZE 8192 /* GDB packets */ @@ -38,7 +47,6 @@ #define ACK "+" #define NACK "-" #define OK "OK" -#define TRAP "S05" #define ERROR(e) "E"STR(e) #define TEST_SKIBOOT_ADDR 0x40000000 @@ -56,6 +64,8 @@ static enum client_state state = IDLE; struct gdb_thread { uint64_t pir; bool attn_set; + bool stop_attn; + bool stop_ctrlc; }; static void destroy_client(int dead_fd); @@ -132,9 +142,32 @@ static void set_thread(uint64_t *stack, void *priv) send_response(fd, ERROR(EEXIST)); } +static void send_stop_for_thread(struct pdbg_target *target) +{ + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + uint64_t pir = gdb_thread->pir; + char data[MAX_RESP_LEN]; + size_t s = 0; + int sig; + + if (gdb_thread->stop_attn) + sig = 5; /* TRAP */ + else if (gdb_thread->stop_ctrlc) + sig = 2; /* INT */ + else + sig = 0; /* default / initial stop reason */ + + s += snprintf(data + s, sizeof(data) - s, "T%02uthread:%04" PRIx64 ";%s", sig, pir, sig == 5 ? "swbreak:;" : ""); + + send_response(fd, data); +} + static void stop_reason(uint64_t *stack, void *priv) { - send_response(fd, TRAP); + PR_INFO("stop_reason\n"); + + send_stop_for_thread(thread_target); } static void detach(uint64_t *stack, void *priv) @@ -539,8 +572,17 @@ out: static void v_conts(uint64_t *stack, void *priv) { + struct thread *thread = target_to_thread(thread_target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + PR_INFO("thread_step\n"); + thread_step(thread_target, 1); - send_response(fd, TRAP); + + gdb_thread->stop_ctrlc = false; + gdb_thread->stop_attn = false; + + send_stop_for_thread(thread_target); } static void __start_all(void) @@ -568,6 +610,8 @@ static void start_all(void) struct pdbg_target *target; for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; struct thread_state status; if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) @@ -577,6 +621,11 @@ static void start_all(void) status = thread_status(target); if (!status.quiesced) PR_ERROR("starting thread not quiesced\n"); + + gdb_thread = thread->gdbserver_priv; + + gdb_thread->stop_attn = false; + gdb_thread->stop_ctrlc = false; } __start_all(); @@ -691,6 +740,8 @@ static void stop_all(void) PR_INFO("thread pir=%"PRIx64" hit attn\n", gdb_thread->pir); + gdb_thread->stop_attn = true; + if (!(status.active)) PR_ERROR("Error thread inactive after trap\n"); /* Restore NIA to before break */ @@ -706,13 +757,18 @@ static void interrupt(uint64_t *stack, void *priv) { PR_INFO("Interrupt from gdb client\n"); if (state != IDLE) { + struct thread *thread = target_to_thread(thread_target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + stop_all(); + if (!gdb_thread->stop_attn) + gdb_thread->stop_ctrlc = true; state = IDLE; poll_interval = VCONT_POLL_DELAY; } - send_response(fd, TRAP); + send_stop_for_thread(thread_target); } static bool poll_threads(void) @@ -735,6 +791,8 @@ static bool poll_threads(void) static void poll(void) { + struct pdbg_target *target; + if (state != SIGNAL_WAIT) return; @@ -745,12 +803,27 @@ static void poll(void) stop_all(); + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + gdb_thread = thread->gdbserver_priv; + + if (gdb_thread->stop_attn) { + thread_target = target; + break; + } + } + set_attn(false); state = IDLE; poll_interval = VCONT_POLL_DELAY; - send_response(fd, TRAP); + send_stop_for_thread(thread_target); } static void cmd_default(uint64_t *stack, void *priv) From patchwork Wed Apr 20 06:50: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: 1619360 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=lbdShobh; 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 4Kjrtq4LJBz9sG0 for ; Wed, 20 Apr 2022 16:51:47 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtq3T34z2ypD for ; Wed, 20 Apr 2022 16:51:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=lbdShobh; 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=lbdShobh; 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 4Kjrtn0lvPz2ym7 for ; Wed, 20 Apr 2022 16:51:44 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id d15so959976pll.10 for ; Tue, 19 Apr 2022 23:51:44 -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=hW2eztXR/57so4WPicdnBFzvo80HEKsY1onTVcB6e9g=; b=lbdShobhtme2KxktayAzujcdA3XLL1vQXtQ6mrSAQraHCyJ3ItTpFvhHD03vkA/ttY yZD7Aem3/d13SaLEVfvPScN+MtxRLLDaum1zNKL4VQi7J2WBGg78u+d6w3xdlXSs0Zvj MHpVVAgp6YedvwwoeULHxaZpQvlwONjsrVOhYt2447BtZ9hL9fQKLC8Co2PmEZpLzY6w g1yENfFj4Kh1mtid8usDSzixWueDScbJZlYtceUYteRuY86g0fta9VzRc3M3Nwz81SkI yRkVJilUSHCNyGWl4ASAtW/uCU3iYIp0GtLB7J7Ikrx2JRLglUjPtDTYS27M78e29s5A nhWw== 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=hW2eztXR/57so4WPicdnBFzvo80HEKsY1onTVcB6e9g=; b=wmldmMY4jO7BriDqsnqVuOdZLUOzJDCFV1yVVkS9q6leHxh1eiJAAvb8ILmQEG2IIy eptNy4CsEVGOC6NYHzgZunVtfulwFLunCK8np/iAuZhEkM0GsJooABxEWoOyBHmdubvj 7jN986oey730VTPN9ysmW63ACQV/7Cgi72tMG7/DMwMkWZRv/dziRJTmlJt+8NKmwSIH WKSsKO7G0UIKgomwu8pmIWG6efudeStg9/fim0JyWhakIeWA54wgr8JaIvkic0z3eeRf vAMzSdkoJK70KmHK7aMZCIkYAK77dYq0jdVz/G2i+C2DXpJl2mLp0mYtiNIEYGohCGgd QiVQ== X-Gm-Message-State: AOAM530/TOHcytPV6PtSHa2Zx4fscfmkKcjmtHFLua4nJ/yFkQBjnydL jrqaZ2ULzSyuDnfBc2g61smJAIwWKR6UTw== X-Google-Smtp-Source: ABdhPJzQF4svlIo5JqJBHrY/dYaoa0yfAoNkUmRo5obKD4mgKG3DDpXpIvqdBoYavpxEgBSBNf5UIg== X-Received: by 2002:a17:902:a3c9:b0:158:d83f:c436 with SMTP id q9-20020a170902a3c900b00158d83fc436mr19458938plb.162.1650437502334; Tue, 19 Apr 2022 23:51:42 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:42 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:07 +1000 Message-Id: <20220420065013.222816-34-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 33/39] 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 Reviewed-by: Joel Stanley --- 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 c3447c35..778269a6 100644 --- a/README.md +++ b/README.md @@ -538,13 +538,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 dc1275c3..abb361ae 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 567f1dd6..13c89c9a 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_precompile.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_precompile.c" +#line 235 "src/gdb_parser_precompile.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_precompile.c" +#line 251 "src/gdb_parser_precompile.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_precompile.c" +#line 500 "src/gdb_parser_precompile.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 52f34a91..1d24e68a 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 2005083d..cafd4cbc 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 Wed Apr 20 06:50: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: 1619361 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=poTovAQV; 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 4Kjrtw3481z9sG0 for ; Wed, 20 Apr 2022 16:51:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtw2HRKz301s for ; Wed, 20 Apr 2022 16:51:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=poTovAQV; 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::634; helo=mail-pl1-x634.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=poTovAQV; dkim-atps=neutral Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 4Kjrtq1LSYz2xKT for ; Wed, 20 Apr 2022 16:51:47 +1000 (AEST) Received: by mail-pl1-x634.google.com with SMTP id b7so989756plh.2 for ; Tue, 19 Apr 2022 23:51: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=HfKdVkf5c24tbhHrApJ8CYiIZZe9981/R7Oj8NEyens=; b=poTovAQV+DogORp7j7Y778IHrdKjab68DtqSkELL0pQrC4oDwFiYLQojxaIP7fO3Pk R74xQcD2RwzGq1Md6d+TP20kL4Ss3XxMpX2SUO2ZIT77ZYS4I5kXOejlEOhonzn1qAAq WD2lkpdnDn9wPkj4hlrVeuOM3FzCcXV66LCBlDcHU9PsCHoaMpXRlU5JFWnrM/OYb6AL hAoPUP0itBhdllbnE8zcn1ainRbBjj07qZxucYIwb4GyevA8xD+zVpB8PIERh5yacdgK 5VOkkEV1RgAN/i5PbHjpyeda1Lqn3J5C0leiwJw5O3UakXtmcmuFcTu9+S+MBXg/TqhV BCtw== 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=HfKdVkf5c24tbhHrApJ8CYiIZZe9981/R7Oj8NEyens=; b=zJBmS0Zv2igwzQUyJlk2bDIxL1la92MR/ujAMVrcj52ZPJ9ocDS5oerbfk8HCdgzkq HnXncx9mEx3dOYuh/lECKu4P8oRZL9qaqbZepGf+zHZOt/W14pRmq+fJxFUEVHJnE7SN 6U0u2SP5q5Vrci/VDXO8ZIC0mPXLlACPch+jSikzR3z1ROyyVjtZSlhGCmC+tVHjHEgX i8lCSQw8aZwlYdy4zNQ0jnmTWIWvhqh0ShI415esxTPaUW4IFwpMcW5ZCLTYSPynlxKy s9SGzFiUkdbnpyDhvWthzROu1oFCtBr8l5Igh1FaJgRmxLL5E6AW77j0McIGUPyJ58WC pTUg== X-Gm-Message-State: AOAM532cuPtZ00uLtsG5GCaBDPxQMSSxtCnLVla2C/DaGhMsUCCGoffd gYiPRBk0OFzX4l6Fsf9nIknD7uO9Sn6miA== X-Google-Smtp-Source: ABdhPJxdJ7U1hX+xOehcC0IMfyzMv1ubA1mSAhwyuxZ9tODd4uVqISE0k0HWeoY82sK2cs0u59nRmA== X-Received: by 2002:a17:902:7244:b0:158:41d3:b79b with SMTP id c4-20020a170902724400b0015841d3b79bmr19573149pll.50.1650437504526; Tue, 19 Apr 2022 23:51:44 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:44 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:08 +1000 Message-Id: <20220420065013.222816-35-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 34/39] 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 1d24e68a..642cbe61 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 Wed Apr 20 06:50: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: 1619362 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=mIVIVPUd; 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 4Kjrtx3HK7z9sG0 for ; Wed, 20 Apr 2022 16:51:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtx1pmvz3bXg for ; Wed, 20 Apr 2022 16:51:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mIVIVPUd; 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=mIVIVPUd; 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 4Kjrts4TpCz2xKT for ; Wed, 20 Apr 2022 16:51:49 +1000 (AEST) Received: by mail-pl1-x636.google.com with SMTP id j8so956708pll.11 for ; Tue, 19 Apr 2022 23:51: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=Pn/jdyaR2D+3+0upBW7MJGbVbirVz3dwzMZ9CHgIjVA=; b=mIVIVPUdl1Yt3P19JslJmvgUBi76tUzKGXubrX5Zjvqp1M3MRJGm+2WpDa3cxE54D9 mLqzG0A9Dq7dKNpzRs4aseIlqdaz/RkBz0aNO7z+v34amVgvdi/4W+cCbEUUE4GJgvL+ jNv2UqdxMeC6S6atnnhQjEsWKOFkPRfQj/+EbyTg63i+Cpp5HX1QXB0Zd7gJcd2GpUzC bidMd9u1EKPNooDD8WndNNQEAEFqBuGffxEVhsfQ+LQTDQH7ZX1wSXJD/zkK2aRWZtdd mKXNq83ocVW4se8xNIewb4oD44P/n+0eznm4x3PddUmdFWyNqO3DgwozhsNaWhiZQoUj NLWw== 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=Pn/jdyaR2D+3+0upBW7MJGbVbirVz3dwzMZ9CHgIjVA=; b=JJoZKG86irb0/ZsM/FoPc24Uq+ornEVpZfVuT3x9et9jNExhUoS6jpd18Gh9XqSq2B nDnpjXpRZjAjKNuu3d6tW4EdiAPNo4fbYLqGhtBpin43+ZYGNf55Pt3+o31kRZpLeotX OEubXcVD+Te/xAoVj1wnNVKbdmgZYIhtXojoVRBeZkhOHLZ88rUcDxZ2VM+fK5n7Qs/A N/oGF+tF6qj20XJDjqGCpV1htepEscwfumosdwMALJeXpOrPmOZrYKD3iNHJQZFFWPGt pghPX0YGl49ToIIeJYwY8fdeSVg8vaeLE3oiD7qbjLeBH+mtFVylH40FnOWiDG5A40c4 rlEQ== X-Gm-Message-State: AOAM5308f44xRjlPoXDnVtjD1U2h21h76G4hPr8wZzJNLLqmmS6r0mNQ aCQlH92ugYiQT8MRVp/1G0Uxa2oxhvpblw== X-Google-Smtp-Source: ABdhPJwl38l/V7QdJ+ccOsXb/nHeJvY4ryWe0RivEBcRPvKpdlYf9IHZgqOa00Mikt9FjG1fuzfXgw== X-Received: by 2002:a17:902:d488:b0:158:e7d1:fc16 with SMTP id c8-20020a170902d48800b00158e7d1fc16mr19196200plg.171.1650437506834; Tue, 19 Apr 2022 23:51:46 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:46 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:09 +1000 Message-Id: <20220420065013.222816-36-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 35/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 90 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 642cbe61..6b9bdf90 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=%"PRIx64" 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=%"PRIx64" 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 Wed Apr 20 06:50: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: 1619363 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=VcFEhRdC; 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 4Kjrty37Rwz9sG0 for ; Wed, 20 Apr 2022 16:51:54 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrty210wz2yn2 for ; Wed, 20 Apr 2022 16:51:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VcFEhRdC; 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::42c; helo=mail-pf1-x42c.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=VcFEhRdC; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 4Kjrtv1lx8z2xKT for ; Wed, 20 Apr 2022 16:51:51 +1000 (AEST) Received: by mail-pf1-x42c.google.com with SMTP id b15so1104534pfm.5 for ; Tue, 19 Apr 2022 23:51: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=mJ4jaj4OaMBOd/HMo4RFcrdg+m/WGmjloNOiqpL7Akc=; b=VcFEhRdC4al7Uu3tgG92ZUz1YVpHGhoknXMKLW5nhxmL8MAnsSuoF1vBfDy0r54w2/ ZpflYdEgv0A6pzyePtSiQeLASi4jBlrsCLvXx9J58ZUC2kod30ZhuBfB9AkomZIO85bZ cx4BL3NQEtyiAcFDt1chRpMyIbMRV+tsUBSkPeyQPQPheWW0kJ8FdizKlclaWlsGD7KP 8atEP9tNp9ozZQ+4Zmfnn9SuIaicrdRWzbe8H3mxZZ6W25rtGl0ZLRLH/Pgc/BWDTlWU CMyEXKDQ/CIWghYe04nHnPmXmtAKBvF3vcvSgESZ1NUgwUDp/w6NMJVpUj+uWKRWLzia iNjg== 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=mJ4jaj4OaMBOd/HMo4RFcrdg+m/WGmjloNOiqpL7Akc=; b=FvEm40kkRU2o4Gfl9tlT3s6idJvH5XLgm9eCjaTYReyayTqGQR0BP8Biidut237ctw H0/+he3FEuGXOdcB3KkfyR7tVZoaxwqCG1ETpw+fRlgklvIgAmWVPLU111q4UKKWpCdy 7ioqS7Na0amEEp8lKoFJPoOk8A12FFSZdfPvt0BdgDCQePqNbpn5iJVGi58Hrr4AzddV UaMHXq93eSJOohZRbkaz89sPQTiJhKUduP51e/r6G1N9EcM06hDr2XqYIsfjx4S6tBvX EpVHCEeMxwejgggIupINQ/8L6m3ANqGWR29qAvbEdZWO40oyofZOoQ8BQYL2fPZv6S4K uxAQ== X-Gm-Message-State: AOAM531KaOBIAibUWCyHm5N6ABdff16PNw8EZFsoMYrZs8nBjGUJ27UN AtlYx9uZL4LBEDc5sYywtu1UHAZHtE7f6w== X-Google-Smtp-Source: ABdhPJwz9yipPAPJDkI7oBmw0Aiod1lLYVnkCkrtl/dIGDWIvMMYB8GDdXGislkOI3osVetzTnQEHQ== X-Received: by 2002:a65:6bd6:0:b0:39d:4f85:9ecf with SMTP id e22-20020a656bd6000000b0039d4f859ecfmr18386776pgw.336.1650437509039; Tue, 19 Apr 2022 23:51:49 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:48 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:10 +1000 Message-Id: <20220420065013.222816-37-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 36/39] 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" The gdb protocol allows sending register values of the stopped thread with the stop-reason packet. This reduces round-trips because the client doesn't have to get registers after stopping. This is a significant win because getting registers requires multiple commands so it saves about 10 commands (round-trips). Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 6b9bdf90..d50121c0 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 Wed Apr 20 06:50: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: 1619364 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=gciOUEpL; 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 4Kjrv05gxGz9sG0 for ; Wed, 20 Apr 2022 16:51:56 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrv02kWfz2yZf for ; Wed, 20 Apr 2022 16:51:56 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=gciOUEpL; 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::1032; helo=mail-pj1-x1032.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=gciOUEpL; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 4Kjrty0RCMz3bY3 for ; Wed, 20 Apr 2022 16:51:53 +1000 (AEST) Received: by mail-pj1-x1032.google.com with SMTP id ll10so1061092pjb.5 for ; Tue, 19 Apr 2022 23:51: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=JAR3pPLHTTTy5iRdJnSB5MS1m8axmLNDMrGUtOeT9RA=; b=gciOUEpLJHQ9j0ByMERG/pU9MV/e+ZTnvd6Tw1qKcFScrKaXGKBG5q8plXBVUL65pQ G2Vr7+33kls/y/YGgjmM0R/1Ius/fGOKOrIHdPavN1iXOAYtWhqp5orlqpKKQf5+PT5j zQaeoOq6McDzo/zMKarRurPS6I0vb/LbQsA7fXUhRcP8yDbmi4KWXNUTTCA9NnI5K8bQ d0QPTnO9ATX/9t3jlQq+Qkqrem/GHcT60Urv0f92mqZhi8BJQG7Lejydcnn+5MsP9j5V 86dT9eZj8xzlya8axr3VaCrAdydFcGNRcZN8vGL2I15eVumJ2pkKKtOOosFJotcLSL17 xroQ== 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=JAR3pPLHTTTy5iRdJnSB5MS1m8axmLNDMrGUtOeT9RA=; b=uM/IPWNXyy0NGIZVvREoCCCLKIfZJNFD2G6F2QH1xjdly8euNaQ5QnjDkUFtnIHGjI DOlzYQrcd19bCys2pfw9I/760XdcQQwSttSwHMZcUDLl1+sicZM2gi0ZJtYBLDfRZBkd gQOfmH+3jkU0WpWloPdAjgLnoCoQwQ/kHOyQcaI86ORxFHXEGIOvlGOueGnOroNXy+UG kgnWXKOT/Tg7L4LG+ijmSaueSilSKWgHAeMCUmAYdT/3O/qOTursOdss1J57afDTwyMh BxoVbcACmMSxhv2qnULoOawDhOQ9UdgoWvZ7KMRODOx/2ddhDEAfjxSV4VPqR8AXg3Nc IItA== X-Gm-Message-State: AOAM532jq0Zp23CiK5+bhTGXhUYKC5VrxAFBfATi8NV+KKF8MPsMBlz3 2E+8/gD/7uazLiU2WYgfyhVewz06yvltpg== X-Google-Smtp-Source: ABdhPJzp6+GmiMuXHkM9xyy6T3fa44PVEmGx0zr2zXClg0KNINZFWoJoFwov7SZ/qMeb8cgxldev+A== X-Received: by 2002:a17:903:1248:b0:151:9708:d586 with SMTP id u8-20020a170903124800b001519708d586mr19153852plh.15.1650437511274; Tue, 19 Apr 2022 23:51:51 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:50 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:11 +1000 Message-Id: <20220420065013.222816-38-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 37/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index d50121c0..e81dba40 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 Wed Apr 20 06:50: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: 1619365 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=H2Ub13Gv; 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 4Kjrv573Gcz9sG0 for ; Wed, 20 Apr 2022 16:52:01 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrv5459jz3050 for ; Wed, 20 Apr 2022 16:52:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=H2Ub13Gv; 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::52e; helo=mail-pg1-x52e.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=H2Ub13Gv; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 4Kjrv05SsGz2ym7 for ; Wed, 20 Apr 2022 16:51:56 +1000 (AEST) Received: by mail-pg1-x52e.google.com with SMTP id q19so786348pgm.6 for ; Tue, 19 Apr 2022 23:51: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=Ad5fPTGeR8LlSPok1qn2Qplf95jY/6msOK0twMX5hBg=; b=H2Ub13GvNmCLL1CMfh14RnM4aQYxCzWP+x1TcnKmAsb96XvkT/WX6tuY0xHi2HmZZJ zCCH3igevnSIOIdiHcJarsuzCYwxoy3KwNES5U3LB4V5E2I5ky2Y7YxqkTl6y3YsCQAx 5WAaFe9xdCN5pUcoXOKRc2uAulBTG6L0sJDPGK7KJ88CxgOj5uIjr649ws+wOLl0dRg0 Gu0IPels4FPHTPe+AOnJYmc8/etAKfCcE1MtwTXLY8dq3pJou3OAbOIzsXDrZW3OtYww kp0Lu8hO7TIyrzMJoUZH/hI790jY4w2vHKQoJzBy3ZIBWpwcMMAfxByaruwppSwbjeAe gSpg== 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=Ad5fPTGeR8LlSPok1qn2Qplf95jY/6msOK0twMX5hBg=; b=kMQIR509K4SwL4O3mmuK/4CDLIRLQDzGye1A8wyeC5ixIz7obX0yKcshZZ351P5hNa UdDfbG7i+PHoOPrEo9NPZ8KKyttW5AfZvgaBD6D8bJLDtdkj3n+zH7a468XNuiczIrhB r5EQ6zU+di5eMewchtCVaULUSzygV85+wR7CqFLhpowf1Y5tI/cg4G9KW3k63XxGgYQO A5MW0IzdDGEar5Sa+tT0b0ZGnnH7V/BBKN7cS1kSaQEUr2AzzpZlHtj2i0P7gnqTvHwe 2IG/Z10JQ3GqnB8w7u6/WwUvM6Mke8GwW8kRCqMYya5c4ni6PGhNKwvCzBcLDCFoCRKz diIQ== X-Gm-Message-State: AOAM533v3d+5x/iw6IUpruARdvn/OursQCA4VJQaRZ1+13dipVRRYdP8 KKyNAkvktEfcmKmtammjtugJxEEv2B/gMw== X-Google-Smtp-Source: ABdhPJyspNVVcwdmstHbbLUGdMCAaYnMqrFWX2d6T7Jy6rbTsZoePrVLOKOr5X3PvRRhlRvtvIHZqQ== X-Received: by 2002:a65:56cb:0:b0:378:82ed:d74 with SMTP id w11-20020a6556cb000000b0037882ed0d74mr18125157pgs.491.1650437513578; Tue, 19 Apr 2022 23:51:53 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:53 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:12 +1000 Message-Id: <20220420065013.222816-39-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 38/39] 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 abb361ae..44048332 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 13c89c9a..d2eeb61c 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_precompile.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_precompile.c" +#line 258 "src/gdb_parser_precompile.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_precompile.c" +#line 274 "src/gdb_parser_precompile.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_precompile.c" +#line 531 "src/gdb_parser_precompile.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 e81dba40..cc73a36d 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=%"PRIx64" 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 cafd4cbc..6a89444f 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 Wed Apr 20 06:50: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: 1619366 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=h8CTAlYn; 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 4Kjrv65r6Mz9sG0 for ; Wed, 20 Apr 2022 16:52:02 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrv650mFz3bXg for ; Wed, 20 Apr 2022 16:52:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=h8CTAlYn; 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::52d; helo=mail-pg1-x52d.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=h8CTAlYn; dkim-atps=neutral Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 4Kjrv16ZmHz2ym7 for ; Wed, 20 Apr 2022 16:51:57 +1000 (AEST) Received: by mail-pg1-x52d.google.com with SMTP id q12so764712pgj.13 for ; Tue, 19 Apr 2022 23:51:57 -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=J9VsGIBe8KCPpVBsSbC6xzBHKxHnwZUw+RARbf24C1I=; b=h8CTAlYnrQpxT9tIV7L1eaQf1SPFz/EQdKkMazhs202DcxFhX3mgkHozWtnkMh/JZz 4ZS8iito98cPNLvAHH+jKkvbR8NdWsee9zRwdmerQ++/Gi0yWgGCIrr087x2jIb8Jd1D cOy57IpdlkqciTQdVVMm/tNYna1B+L9g+SYzLw3mwi7sASH4fw2U6uHAcZkh+cxqTQWE ls0qrsfXXGBVe9DsCIYfOpCmrGZHGICDn6A8u+3+ocw19hWocccuFNYZ7xMVv1wOSVWs 5LrxOAmVauo7qynWaztuOSl57o1sfvGpG1QGBMmILp76AXXJ7aTGR+ZR0H6+dklCH2O8 z1/A== 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=J9VsGIBe8KCPpVBsSbC6xzBHKxHnwZUw+RARbf24C1I=; b=hPoCrpeywxF2jIu9cY7Lfx7k81jTMy5UST84HRTA2wvmbars8IBs+WgXjUkEygLBjC Y7szfpiW1vARxALmOKlMUThMCTe8eoVoLwcJnCBeHqMMgQ6zCr9cvMhOQSrog8Y39u9c 1vg0OfM361lDUjS2lGq2pbMX5T+KQHMd6XTfuPaSvnAmrNnRd2AlemmsnYUkhejX1zAg 4V1lWx15vos+0txrt/2MPicVRh5EVWJaD6KxWHwzqjVttQ69o7nb7+op2dNJJ4TdFhG8 Ia8zLqKvxf5wo5rYHGXHGVCH+XfqD21En3EP1IT6HAoVRa6Isg00h9r9dbkqQfBkLt+/ XpkQ== X-Gm-Message-State: AOAM5330BHrlMmTxPDbjqGXRqB9tPqQTQarRnkMdqEVC8mdAugn57tC8 UCEoY14EUS0Tp8ARRUMNZWw0+/ns3h46PA== X-Google-Smtp-Source: ABdhPJyTqOm/8/GzzwiUZC8pueh4VKcUoDuBkHSgy9hJwodAp45XecXCQXhbo2qpoUncuJVgi/trfw== X-Received: by 2002:a63:450d:0:b0:3a8:f2ed:1aa5 with SMTP id s13-20020a63450d000000b003a8f2ed1aa5mr14997567pga.367.1650437515738; Tue, 19 Apr 2022 23:51:55 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:55 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:13 +1000 Message-Id: <20220420065013.222816-40-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 39/39] 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 using memory-ops. Remove the breakpoint logic from the memory-write command. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index cc73a36d..13b72408 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"); - memcpy(data, attn_opcode, 4); - - /* 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;