From nobody Mon May 6 11:59:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1585588511; cv=none; d=zohomail.com; s=zohoarc; b=lVdpWqhhfwlfhR11XQuAe7YXZ3plPDl8zvGWuUi//tdOcReh5eIF7Bet6bV4XfBpihzkJGQGXbigeNU7tipnAlHqniXiD6VfUuVxtfa0KOr8Nj56WTBXnWlrRhMZGICC68t/yAYRld/QvPpHMK9Ng5X/f//N7G5hDDXHRqMROPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585588511; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=V2/yr/VBBSMjsJvpyuugUBT+oN88BgSB7L0XM+2U0UY=; b=RgHkd16ld7uOoeWPX53vuE4cdaQoZZFJZuobF4XMyLh4ofA/4VvdfTp92sLP5YMNprlaYTfjDyU7D48w4ea7Lj0K6ZLyRh8+RBWkGARaSk1pJQaYyeGqD16+GDOPEIKm2xuIO81Kdw6S9KQ9mV8RMi81Q+F1QsYQ455xQudogsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585588511825294.2641514261545; Mon, 30 Mar 2020 10:15:11 -0700 (PDT) Received: from localhost ([::1]:53472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIy0E-0005al-GE for importer@patchew.org; Mon, 30 Mar 2020 13:15:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58464) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <3pCiCXgYKCvcxtZmyhfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--yuanzi.bounces.google.com>) id 1jIxyK-0003CD-Cv for qemu-devel@nongnu.org; Mon, 30 Mar 2020 13:13:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <3pCiCXgYKCvcxtZmyhfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--yuanzi.bounces.google.com>) id 1jIxyJ-0000BK-65 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 13:13:12 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]:39300) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3pCiCXgYKCvcxtZmyhfnnfkd.bnlpdlt-cdudkmnmfmt.nqf@flex--yuanzi.bounces.google.com>) id 1jIxyI-000074-U2 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 13:13:11 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d11so13445754pll.6 for ; Mon, 30 Mar 2020 10:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=V2/yr/VBBSMjsJvpyuugUBT+oN88BgSB7L0XM+2U0UY=; b=aq5QaIARv5Yyi0jPYXtoM1OtUv0J4rBLvjVohBxRcKqKy4dVlPYtpplxIxGt28prf7 KMjfmZPo1IxahMyQ1YMlqxCn55fp1K0q6rNxy1U/TSAfDS9w2d+R1qXHfGqiy6vDUtfG 1e1LGg1c4mmBiTEUX0nT95pVPdvaRFgSxlU31lPuLVUMJZFn+6bmj/O0IEKP5CdXgEhI qHE9I2J0fWpdMjxEuxK9VdZo+nd+EXMQ+jx8NhCMmgPy2yZ4ThlLMPw4jgUx/zCyAFHf 7geql4WIhQ7ayP2s5BLy+Fa+dZfIAAwASc32dJ51lRvMnO6mvXzbPsF1pRgoIHulUZQB yTlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=V2/yr/VBBSMjsJvpyuugUBT+oN88BgSB7L0XM+2U0UY=; b=bImhV7AEP52De2cHedEYgxMrZeEpEsZlkMM7d5gEqsnH9hIDJe8E1qCm1gJaMf+tVf 8itEYTGu2JO/gqX7eLcEjBa58dTApRa4AlL38kPKzHfMi+mkhUUbOc3n5jaJ1AsyHN8l hjvnxymLAIjWfA1TLyBzONu6ppC/QGcc85SyGR9JTEDv5tHzD7UJd0kRL6+6k4rVORJ+ b9xDUVkw9GeG5IDQ7IcLAvEBXvHO4t13BohlqEclqYCEzj1/50rVE92vqRgR9LFQ6+i2 IAPvIHMmhvOv6QVDQ5P2gl7QWwYP3Ra6sy4fW7Ib6oO77ElorcFL6WqFrmzDvOtQf5Oh I+IA== X-Gm-Message-State: AGi0PuaOOZKhamg7+FYjKg2vxWBnvwcbfqbiYAZ9sTwbgVtmOcv0G0Ko wdtqA2bFlnt21UfCe2R9AnHWOd+Ts3/4a4JHN5LDHS1Pbm2pLtb7Uj7smZPKf9ZGBVRcEe6F629 AIPyTaNiiT6VIiJVKuQZB1PPVvV31rNsvM9NWktmA0o7ayvkmzSx0hp9/JcsP X-Google-Smtp-Source: APiQypJTSUXcxSr57qAhMq1a5XW5qIrIQDmdOVzh/ndFvg8yesJQRAgILLvzPPbm8SeK8K68HcNlRJfAhbE= X-Received: by 2002:a17:90a:cb0e:: with SMTP id z14mr376555pjt.156.1585588388226; Mon, 30 Mar 2020 10:13:08 -0700 (PDT) Date: Mon, 30 Mar 2020 13:13:03 -0400 Message-Id: <20200330171303.107131-1-yuanzi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH] gdbstub: add support to Xfer:auxv:read: packet From: Lirong Yuan To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, philmd@redhat.com, scw@google.com, jkz@google.com, Lirong Yuan Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::64a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) Content-Type: text/plain; charset="utf-8" This allows gdb to access the target=E2=80=99s auxiliary vector, which can be helpful for telling system libraries important details about the hardware, operating system, and process. Signed-off-by: Lirong Yuan --- gdbstub.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index 013fb1ac0f..f7a08263c6 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2125,6 +2125,12 @@ static void handle_query_supported(GdbCmdContext *gd= b_ctx, void *user_ctx) g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+"); } =20 +#ifdef CONFIG_USER_ONLY + if (gdbserver_state.c_cpu->opaque) { + g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+"); + } +#endif + if (gdb_ctx->num_params && strstr(gdb_ctx->params[0].data, "multiprocess+")) { gdbserver_state.multiprocess =3D true; @@ -2186,6 +2192,48 @@ static void handle_query_xfer_features(GdbCmdContext= *gdb_ctx, void *user_ctx) gdbserver_state.str_buf->len, true); } =20 +#ifdef CONFIG_USER_ONLY +static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + TaskState *ts; + unsigned long offset, len, saved_auxv, auxv_len; + const char *mem; + + if (gdb_ctx->num_params < 2) { + put_packet("E22"); + return; + } + + offset =3D gdb_ctx->params[0].val_ul; + len =3D gdb_ctx->params[1].val_ul; + + ts =3D gdbserver_state.c_cpu->opaque; + saved_auxv =3D ts->info->saved_auxv; + auxv_len =3D ts->info->auxv_len; + mem =3D (const char *)(saved_auxv + offset); + + if (offset >=3D auxv_len) { + put_packet("E22"); + return; + } + + if (len > (MAX_PACKET_LENGTH - 5) / 2) { + len =3D (MAX_PACKET_LENGTH - 5) / 2; + } + + if (len < auxv_len - offset) { + g_string_assign(gdbserver_state.str_buf, "m"); + memtox(gdbserver_state.str_buf, mem, len); + } else { + g_string_assign(gdbserver_state.str_buf, "l"); + memtox(gdbserver_state.str_buf, mem, auxv_len - offset); + } + + put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); +} +#endif + static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) { put_packet(GDB_ATTACHED); @@ -2291,6 +2339,14 @@ static GdbCmdParseEntry gdb_gen_query_table[] =3D { .cmd_startswith =3D 1, .schema =3D "s:l,l0" }, +#ifdef CONFIG_USER_ONLY + { + .handler =3D handle_query_xfer_auxv, + .cmd =3D "Xfer:auxv:read:", + .cmd_startswith =3D 1, + .schema =3D "l,l0" + }, +#endif { .handler =3D handle_query_attached, .cmd =3D "Attached:", --=20 2.26.0.rc2.310.g2932bb562d-goog