From patchwork Mon Feb 12 20:01:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 85625 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25399385841B for ; Mon, 12 Feb 2024 20:02:38 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id 89C6B3858408 for ; Mon, 12 Feb 2024 20:02:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89C6B3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 89C6B3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768126; cv=none; b=l7lhY99oymua6Cz//u1cikETLPIkNWwdLTBGrv6jcIJOAYUgTh5eAyZrEp0Zeb4aNRPgq4EDUdJ7V1d/Y4JwagPwddUUdOOJyYZ/WZM0iC9oqowggPaA2YS+tIp2zgjAkXU8JSbNz0jDg6OmkXfU8ZfFIsa4ilEkJjsehic/hbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768126; c=relaxed/simple; bh=npKzAsmaw3x6tTGTgMR75Y5cKY+DZE7n4pDmo5uQxpM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Rrj3wdb4adoyNej2u/JYcP9JJWPHxfc/bBCka35bFLje5AaPEyAOZDRYgPrMgZ3ctSFuKd4R4FOtckop8hkheFW+izUL6rAG5lDyF9MjOY2PVGJmXI0PJdePC4jQ+XcgcqK0XwqbBlgBujH7KFRS4azPdcfPrGQ/xfWo7lHksmE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-33b65b2e43eso2591589f8f.1 for ; Mon, 12 Feb 2024 12:02:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707768122; x=1708372922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MTunuHjteKGK+MDkUrXHDgFED6l2f8cD60d695yhjEc=; b=SvsjPW589SGjopBHrNYi5JN8ZNU93jCIGoWR25DBvGMbw/sQEBFIx2/ZO60Ov9ogRP 6qQJqairFEmdspPK9oh1I8+DWYRhVk0q6VBxR0Xgu7F6DF2xoMQZpda0e7YCWbIsbZUY tP+iShUiA8l5Njh7h6ixFpChVUriSW0Qon0pPj8Jfogb3/q1PhFdtPpHAKB2WMmmwTC9 e/1QtBZ61f9y4dsDGf2WcN/g0URHI1+iOTH3kr5Q1fc6BB+a3ulzUNUH7pn37mLKVygV ekxd7O7+tDLaGobSxXcJefhAl6R7FFmHLnoRGemsi8yHcP3L/6r2rOP1sLa0Kxp1zjQI nE9g== X-Gm-Message-State: AOJu0YxORYJxuHTZFfOop+B9Tt79zVryfCoE9OKVIcKMwR2UDwOYeKik +4ALKa4vGIKSa3T+S8Cnkb/r7S+6ACsxewzIOcu+P12g82ntJqBt7oRMwffeayc= X-Google-Smtp-Source: AGHT+IFn2i/MQE3wY//X7SoBAkBIJnI//NJBZEPKzxfUsq3Zb7/APDWHQUom+FVTq93BafE2unuKNA== X-Received: by 2002:adf:f9cd:0:b0:33b:8782:b526 with SMTP id w13-20020adff9cd000000b0033b8782b526mr1490643wrr.59.1707768121957; Mon, 12 Feb 2024 12:02:01 -0800 (PST) Received: from localhost ([2001:8a0:f923:4f00:6d21:130f:e0dc:ea4b]) by smtp.gmail.com with UTF8SMTPSA id y8-20020a5d4708000000b0033b507b0abdsm7590001wrq.32.2024.02.12.12.02.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 12:02:01 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/3] Improve vRun error reporting Date: Mon, 12 Feb 2024 20:01:52 +0000 Message-ID: <20240212200153.882582-3-pedro@palves.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212200153.882582-1-pedro@palves.net> References: <20240212200153.882582-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org After the previous commit, if starting the inferior process with "run" (vRun packet) fails, GDBserver reports an error using the "E." verbose error packet. On the GDB side, however, GDB doesn't yet do anything with verbose error strings when handling vRun errors. This commit fixes that. This makes remote debugging output the same as native output, when possible, another small step in the "local/remote parity" project. E.g., before, against GNU/Linux GDBserver: (gdb) run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox Running ".../gdb.base/run-fail-twice/run-fail-twice.nox" on the remote target failed After, against GNU/Linux GDBserver (same as native): (gdb) run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox During startup program exited with code 126. Change-Id: Ib386f267522603f554b52a885b15229c9639e870 --- gdb/remote.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index b58dbd4cb66..dca5add260a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2400,6 +2400,19 @@ add_packet_config_cmd (const unsigned int which_packet, const char *name, } } +/* Strings that starts with "E.", are verbose error messages, like + "E.ERROR_MESSAGE". If BUF is such an error message, return a + pointer to message after the period. Otherwise return NULL. */ + +static const char * +verbose_error_message (const char *buf) +{ + if (buf[0] == 'E' && buf[1] == '.') + return buf + 2; + else + return nullptr; +} + static enum packet_result packet_check_result (const char *buf) { @@ -2415,7 +2428,7 @@ packet_check_result (const char *buf) /* Always treat "E." as an error. This will be used for more verbose error messages, such as E.memtypes. */ - if (buf[0] == 'E' && buf[1] == '.') + if (verbose_error_message (buf) != nullptr) return PACKET_ERROR; /* The packet may or may not be OK. Just assume it is. */ @@ -10502,7 +10515,13 @@ remote_target::extended_remote_run (const std::string &args) case PACKET_UNKNOWN: return -1; case PACKET_ERROR: - if (remote_exec_file[0] == '\0') + /* If we have a verbose error message, print just that. This + makes remote debugging output the same as native output, when + possible. */ + if (const char *msg = verbose_error_message (rs->buf.data ()); + msg != nullptr) + error (("%s"), msg); + else if (remote_exec_file[0] == '\0') error (_("Running the default executable on the remote target failed; " "try \"set remote exec-file\"?")); else