From patchwork Mon Mar 30 17:13:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lirong Yuan X-Patchwork-Id: 11466097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C28B92C for ; Mon, 30 Mar 2020 17:14:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 604BB20578 for ; Mon, 30 Mar 2020 17:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aq5QaIAR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 604BB20578 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIy00-0005al-Gt for patchwork-qemu-devel@patchwork.kernel.org; Mon, 30 Mar 2020 13:14:56 -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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This allows gdb to access the target’s 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 *gdb_ctx, void *user_ctx) g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+"); } +#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 = true; @@ -2186,6 +2192,48 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) gdbserver_state.str_buf->len, true); } +#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 = gdb_ctx->params[0].val_ul; + len = gdb_ctx->params[1].val_ul; + + ts = gdbserver_state.c_cpu->opaque; + saved_auxv = ts->info->saved_auxv; + auxv_len = ts->info->auxv_len; + mem = (const char *)(saved_auxv + offset); + + if (offset >= auxv_len) { + put_packet("E22"); + return; + } + + if (len > (MAX_PACKET_LENGTH - 5) / 2) { + len = (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[] = { .cmd_startswith = 1, .schema = "s:l,l0" }, +#ifdef CONFIG_USER_ONLY + { + .handler = handle_query_xfer_auxv, + .cmd = "Xfer:auxv:read:", + .cmd_startswith = 1, + .schema = "l,l0" + }, +#endif { .handler = handle_query_attached, .cmd = "Attached:",