From patchwork Sat Nov 2 02:56:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 840277 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp1158458wrb; Fri, 1 Nov 2024 19:58:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW14vDI5qHqk+lobMSkajHZ/KRFe3tew9i15mSK6J5YWkvgBe5IreaSNo3MVbB12Bc3iuY0fA==@linaro.org X-Google-Smtp-Source: AGHT+IH7f3YI+IjsjLFir2EX316cW3UeRwM3r3hrW7zODeZu97bQSwHd8iBBB9ljN5AHQpAAG4q+ X-Received: by 2002:a05:620a:2996:b0:7b1:55ae:a9bb with SMTP id af79cd13be357-7b1aed6f6a3mr1791487285a.13.1730516323733; Fri, 01 Nov 2024 19:58:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730516323; cv=pass; d=google.com; s=arc-20240605; b=b9FJ7jlYFR/QeMXtQ2Z+vrYcuaWaGxjKGQ46efusjB1g+Onn5cK3GAayrTuK/eiWKI XeuTMpZhCrGpvCHtrge492vFMWDgYt+Nu4xS/jk12/QyojSqyfMz/uUwlwVMJxgfljH9 P8sA4UhRQZAf9u68ux5CfayUUDKG6Jaz9sEz/N+qeUF6xyjU1OV56Hu/A8IFvInMYzYz CuuZCFUXMISUz26SiG9x1nohs0gkpgWTOmWYZa7Npmnrue4MMn24sVz008goTgTPM/DC /u791aCmy0vHZE1hGGDLWaquBa6L5OhyJ75/vn9tVP4af6HF2AdJozViFdxIqmp497OP x5PQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=y/M8LV+vonvkcoXieKZ5UXuMkIdNIqGy6GN2AoX4d8Q=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=e2jTsFkn24QTR7LwNAYaHDXtN/EJY39f6yHazyNC9F2/xZBnarj6nAJjZtbBDl/fWT SDNAqfx6N0gKKuFrpayCYLB/NoJcuImWq/8H6UryXmvkOo04IjBBteITuOOh1y7nPTXT /30CyqZmaySymLW1jJ/5xBsjYIhnFy0fUvMgvuips/SVjeJq078r/r+eX3SCN7OtVPLI g3zZWgIGe58tHHW1iMBWPzgGFICSjfm/uEgdJNyDj5GzwaC0sQQtbr+BClyIAZi/y0tS 5sh41KrXrYl1piiJdGSSk3tjcLxenECg+/PekZEFK7klWKNcspFg1/qAtG0R2Rrg7iYM sgoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dLr0g4B3; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3a81742si576302785a.349.2024.11.01.19.58.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:58:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dLr0g4B3; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E5AD3857C5F for ; Sat, 2 Nov 2024 02:58:43 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 106E5385780F for ; Sat, 2 Nov 2024 02:56:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 106E5385780F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 106E5385780F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516223; cv=none; b=sVUTHTy8tW/+AnsdEzTEyYc+V4eh8n4KDdbL1wn852LjNKLeoF7ND9Y/nMgI+Pa7e4Piy552+w/3hSPPYDyCL0OjSD1qKBsY+ncoyGfIKtxx+to+bbIGGL5tVmH5mKfWFW2SJCulEnv98j/cmw+JnqlsI3X1HadIrmon3iwqK0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516223; c=relaxed/simple; bh=4ibFN7DKdxqfsM5QEzMYRh5gjsDYRvlucWW6tsqrtGU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vXWuc30A7Tn8qR9doubSm2SGnrdbQPzC8CUmm7AZHP4u6QGPInRdN8/wFxAQU2R9b70d5upw4WpBIeTHzUIZnt/vwVc3lyvX17+hMksqavYtN6sGB3z1fvqwfCCDLqEcGXBNUw9RlxSOJ15Z5kvHvrrvMtSXuTXheUfN0MVEheo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-71e5a1c9071so2272113b3a.0 for ; Fri, 01 Nov 2024 19:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730516218; x=1731121018; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=y/M8LV+vonvkcoXieKZ5UXuMkIdNIqGy6GN2AoX4d8Q=; b=dLr0g4B3Pc1sp1cm2XpAJ6DfW6YZhLwy1rvZ7h72V8vtkomPChBrdWJuI0pUN5j2U/ has6MAw/Hk4+vr3/H6FhJVxhCVWt+uelIq8u9TFLRS6uBzIGu5EcXzLm8nBNJX2hwFWV OG7abg5IySUUtOYR4CN/3CDrnbq6YbJePHypv0pXmDXVZ3Bhr4Dz3QG3CPhKtdOGy58k wiueBU2CJ/kIvljz1qHxFIlogXW1A6i8Cx8Nni9jfR4Gc63hHH6//sT01iFQxy/pU/cl s1ASettF35VPZBP3Kzl+oI6zQFhQAhyKEADilM2LyLmwAAd17DDVAaL2xZEEBLwVkLd7 LEFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730516218; x=1731121018; 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=y/M8LV+vonvkcoXieKZ5UXuMkIdNIqGy6GN2AoX4d8Q=; b=ZMAsV/bnFNQWQbmCkbO3y1Rr8v84G4FUcqA625LjF3SqcaOEW+1aN6Iwa2SXfOo0iA d67NKSWjIAZY6WUv+u13qkPltZ2X9qUqjbr2DxBlVrQImzFVORV3VJn0RQt11PLblVo7 be93fzf28N7skIlTRhF+FXXjFJpA83TMTmeFDr6n3GPeWtqG9LpnAzEYkewqqU+3y7Ao PA78mVbk4cwqnuxVpsSj53tG6Z0Xuj9nxfs0drjvyTckQJA44KpikgKUUxSwvHnkOs2H cu6ARJa5XZfDcR/4p64tNdiW5cAIUrF5DOOQKEtuFCbQE+kixNxi0BFeyulG3L54YHEU oNXA== X-Gm-Message-State: AOJu0Yy5e00q1wrKWM/kvV4XZ8EGqbzSj5gxvmKUK6djdMtS0A+bDqfN EaN7OqVx4gWlIoBGE58CBxYNasAG3nlj5qH3ZARE6Ti+nvnWsn51+3uEgiJpiVg33496qixMBL6 x X-Received: by 2002:a05:6a00:4f93:b0:71e:55e2:2c58 with SMTP id d2e1a72fcca58-720ab3f31a7mr16409713b3a.15.1730516218018; Fri, 01 Nov 2024 19:56:58 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f214:b4dc:314a:c1ee]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e6bdcsm3365234b3a.58.2024.11.01.19.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:56:57 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH v4 06/15] gdbserver: Implement p and P packets Date: Fri, 1 Nov 2024 23:56:26 -0300 Message-ID: <20241102025635.586759-7-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241102025635.586759-1-thiago.bauermann@linaro.org> References: <20241102025635.586759-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 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~patch=linaro.org@sourceware.org GDB will need the p packet to individually request "load early" registers before using the g packet. Not sure if P is necessary, but if p is supported, why not implement P? Alternatively, to be more efficient there could be a packet where GDB can specify a list of registers it wants do load or set. Or there could be a register to request/set the expedited registers. Reviewed-By: Luis Machado --- gdbserver/regcache.cc | 44 +++++++++++++++++++++++++ gdbserver/regcache.h | 9 ++++++ gdbserver/server.cc | 75 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 6a1526246867..ec19864bd690 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -208,6 +208,50 @@ find_register_by_number (const struct target_desc *tdesc, int n) #ifndef IN_PROCESS_AGENT +static gdb::array_view register_data (const struct regcache *regcache, + int n); + +/* See regcache.h. */ + +void +register_to_string (struct regcache *regcache, int regnum, char *buf) +{ + if (regcache->register_status[regnum] == REG_VALID) + { + gdb::array_view value = register_data (regcache, regnum); + + bin2hex (value.data (), buf, value.size ()); + buf[value.size () * 2] = '\0'; + } + else + { + int len = regcache->register_size (regnum) * 2; + + memset (buf, 'x', len); + buf[len] = '\0'; + } +} + +/* See regcache.h. */ + +void +register_from_string (struct regcache *regcache, int regnum, char *buf) +{ + int len = strlen (buf); + gdb::array_view value = register_data (regcache, regnum); + int expected_len = value.size () * 2; + + if (len != expected_len) + { + warning ("Wrong sized packet for register %d (expected %d bytes, got %d)", + regnum, expected_len, len); + if (len > expected_len) + len = expected_len; + } + + hex2bin (buf, value.data (), len / 2); +} + void registers_to_string (struct regcache *regcache, char *buf) { diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index df0feca102e0..5de8fd3d127e 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -96,6 +96,15 @@ void regcache_invalidate (void); void regcache_release (void); +/* Save contents of register REGNUM to BUF as an hexadecimal string. */ + +void register_to_string (struct regcache *regcache, int regnum, char *buf); + +/* Set contents of register REGNUM from BUF, interpreted as an hexadecimal + string. */ + +void register_from_string (struct regcache *regcache, int regnum, char *buf); + /* Convert all registers to a string in the currently specified remote format. */ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 5190df4aed5f..4d075fce2359 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -4712,6 +4712,81 @@ process_serial_event (void) } } break; + case 'p': + { + require_running_or_break (cs.own_buf); + if (cs.current_traceframe >= 0) + { + write_enn (cs.own_buf); + break; + } + if (!set_desired_thread ()) + { + write_enn (cs.own_buf); + break; + } + + int i = 1, regnum = 0; + char c; + while ((c = cs.own_buf[i++]) != '\0') + { + regnum = regnum << 4; + regnum |= fromhex (c) & 0x0f; + } + + struct regcache *regcache = get_thread_regcache (current_thread, true); + + if (regnum < 0 || regnum >= regcache->tdesc->reg_defs.size ()) + { + write_enn (cs.own_buf); + break; + } + + fetch_inferior_registers (regcache, regnum); + register_to_string (regcache, regnum, cs.own_buf); + } + break; + case 'P': + { + require_running_or_break (cs.own_buf); + if (cs.current_traceframe >= 0) + { + write_enn (cs.own_buf); + break; + } + if (!set_desired_thread ()) + { + write_enn (cs.own_buf); + break; + } + if (strchr (cs.own_buf, '=') == nullptr) + { + write_enn (cs.own_buf); + break; + } + + int i = 1, regnum = 0; + char c; + while ((c = cs.own_buf[i++]) != '=') + { + regnum = regnum << 4; + regnum |= fromhex (c) & 0x0f; + } + + struct regcache *regcache = get_thread_regcache (current_thread, true); + + if (regnum < 0 || regnum >= regcache->tdesc->reg_defs.size ()) + { + write_enn (cs.own_buf); + break; + } + + register_from_string (regcache, regnum, &cs.own_buf[i]); + /* FIXME: Why doesn't the G packet need this as well? */ + store_inferior_registers (regcache, regnum); + write_ok (cs.own_buf); + } + break; case 'm': { require_running_or_break (cs.own_buf);