From patchwork Mon Dec 14 15:30:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 343554 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3094302jai; Mon, 14 Dec 2020 07:31:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4q/V6yzeGfEXoXT9xppxoYxdASwIrYac+/qiZY/SDJrabANbdh9EaoN5SK4b/YTGBz6fQ X-Received: by 2002:a25:aa88:: with SMTP id t8mr20002981ybi.292.1607959866617; Mon, 14 Dec 2020 07:31:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607959866; cv=none; d=google.com; s=arc-20160816; b=RACHTxTBV71uOHTBIqWOR3KU7ggmj6G1swp6r1zLtAwNy7jLOUrOMZFTbxjA/C4b/c zPblqJeY3dxecEjekiADxgaybJ3SMMo7DiBfvE7JfsIVxcEEgg056Bvyojip0TtzDVgu nrwtzpAvJRRWkteccmXZ5NeYchXe58E43i62h7bZd3nS6LLvUl/ovY0yNtJtAkO7pEyA OzA0Jlvk3Lr+5RJ3tobBjlqkcwR9ANW4VJYlYYOrdokPGiuC9PLqRZNAHCliO1Wp80pL fh+6DBhZBPJO9sTqkmt+ZXSX5lNLMScMfkqSNImJJODJGcPxcTep4JF86BKaA40841AZ 72Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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; bh=bXB03b69IRRD0RMhlaFUm5Vdm4BgZtmItrqWS1AnHsY=; b=zAXxtCM2z8FYDRkxUwQ+ONmiIKFSeCV16a9mfz3XpB4lrd4i30ale3y0PX3yghUd0e DqSZysNNslK6Q14ly2CGgc+FoKxc+8jCSRQwiF+bCdkyXvfhHoBInAWazoQepsXUq9aq pe6fuQEwzfXFwNdBj4bQU1sxNzQaefpaGvS9ahRHCI9rTS99Y/sgqZDzb/tKd+MVUDjx ds9zDO0E1uu47RR4CZZwtarUr+sD8Sl24pZ2LSgYeVmWr6SNhxsiTuJETlAF5uNDG2EP euCcuRPdDHG2z3EpI5v/FR91kvrdICiIufCMwAD8qm9fjyRGNJAzIvZ1q8rdzqcWCWNN z7+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dVi7Pbbk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a3si5203427ybj.35.2020.12.14.07.31.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Dec 2020 07:31:06 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dVi7Pbbk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kopoX-0007mf-SN for patch@linaro.org; Mon, 14 Dec 2020 10:31:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kopnr-0007kb-MF for qemu-devel@nongnu.org; Mon, 14 Dec 2020 10:30:23 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:35013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kopno-00066e-UP for qemu-devel@nongnu.org; Mon, 14 Dec 2020 10:30:23 -0500 Received: by mail-wr1-x433.google.com with SMTP id r3so16865450wrt.2 for ; Mon, 14 Dec 2020 07:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bXB03b69IRRD0RMhlaFUm5Vdm4BgZtmItrqWS1AnHsY=; b=dVi7PbbkiKDb1HjXH6UjjVarCGWe4nKSZyGrcWMJe/VTXfJtjQB/V6TrPj2j2hSGnu 4YfhnwOur0SSDNsMgIOlBSP0RKhz1XQm+ZtWN/lmKuSjBu3qJOaTjuIN5FtDqXCvWKtv B0rtlp8kgP3e6C7F0u9sUEqtD1i8umnCEcuViRhaYlEWKojRU/c+mvsIw2dsmvD/b/tC 5Dc1VMIY3yr+/rPpmZVZZnfkSCo+xQUx11IFw/sW9Ale5egYV3sJlYUrQCRvA369DpNw IIt2soRTYU+BqsO4no/dsPDkz9W4fy7BrhH30UeoK9EcmyLVjn5M/Ryv1ZEHSlXKAM9x 1Mgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bXB03b69IRRD0RMhlaFUm5Vdm4BgZtmItrqWS1AnHsY=; b=GYP5lkaRowa9ZzNCqmQ1u6RvQqt4bQDRLbo6nLjOeyQwGtav5tutI4A/ylITMV4IS2 9PLedMdxeclB9NdHN0lbhNOasOwAzHD4ajLQ5J8dnPy0e8EdWZfk7nP2klWrJeFaKvh4 OvSO2hejngnnEAJOhFnarsarazXYHDrrtkJdh8QzFuHTk7gy1kJQabBpwwT2p/CLdyIQ ACrK3aFecaxTHT/oqEtMYJIkCMYrqYM7BCqAK1yPjCue5PhTh1/2Yq81iTx0rOSCsSM3 DAG+tvWMFyNu03M6Gq0VJlNfAV75DF9y7IkMUpkvEySrirLMSzDYximl/haPG6/sFBoe oYwg== X-Gm-Message-State: AOAM531C74OoUNz3W4KJAPzHCs7gfISxzyPHuAzBiOlpB6GyGAmp7BT6 RPyvQD6ZwvpgO7cRf8pRi550lXaZghkQUg== X-Received: by 2002:adf:aa4a:: with SMTP id q10mr28768816wrd.276.1607959819442; Mon, 14 Dec 2020 07:30:19 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h98sm35454468wrh.69.2020.12.14.07.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 07:30:18 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EE9141FF8F; Mon, 14 Dec 2020 15:30:12 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/6] gdbstub: add support to Xfer:auxv:read: packet Date: Mon, 14 Dec 2020 15:30:09 +0000 Message-Id: <20201214153012.12723-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201214153012.12723-1-alex.bennee@linaro.org> References: <20201214153012.12723-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Lirong Yuan Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Lirong Yuan 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 [AJB: minor tweaks to test case, update MAINTAINERS] Signed-off-by: Alex Bennée Message-Id: <20200730193932.3654677-1-yuanzi@google.com> --- gdbstub.c | 54 ++++++++++++++++++ MAINTAINERS | 1 + tests/tcg/multiarch/Makefile.target | 9 ++- .../multiarch/gdbstub/test-qxfer-auxv-read.py | 57 +++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/gdbstub/test-qxfer-auxv-read.py -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/gdbstub.c b/gdbstub.c index f19f98ab1a..ec8daa002b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2172,6 +2172,12 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) ";ReverseStep+;ReverseContinue+"); } +#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; @@ -2233,6 +2239,46 @@ 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("E00"); + 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); @@ -2338,6 +2384,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:", diff --git a/MAINTAINERS b/MAINTAINERS index a83416d54c..9dedc37be4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2295,6 +2295,7 @@ R: Philippe Mathieu-Daudé S: Maintained F: gdbstub* F: gdb-xml/ +F: tests/tcg/multiarch/gdbstub/ Memory API M: Paolo Bonzini diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index cb49cc9ccb..c8cdb1e04d 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -54,7 +54,14 @@ run-gdbstub-sha1: sha1 --bin $< --test $(MULTIARCH_SRC)/gdbstub/sha1.py, \ "basic gdbstub support") -EXTRA_RUNS += run-gdbstub-sha1 +run-gdbstub-qxfer-auxv-read: sha1 + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-auxv-read.py, \ + "basic gdbstub qXfer:auxv:read support") + +EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read endif diff --git a/tests/tcg/multiarch/gdbstub/test-qxfer-auxv-read.py b/tests/tcg/multiarch/gdbstub/test-qxfer-auxv-read.py new file mode 100644 index 0000000000..d91e8fdf19 --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/test-qxfer-auxv-read.py @@ -0,0 +1,57 @@ +from __future__ import print_function +# +# Test auxiliary vector is loaded via gdbstub +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb +import sys + +failcount = 0 + +def report(cond, msg): + "Report success/fail of test" + if cond: + print ("PASS: %s" % (msg)) + else: + print ("FAIL: %s" % (msg)) + global failcount + failcount += 1 + +def run_test(): + "Run through the tests one by one" + + auxv = gdb.execute("info auxv", False, True) + report(isinstance(auxv, str), "Fetched auxv from inferior") + report(auxv.find("sha1"), "Found test binary name in auxv") + +# +# This runs as the script it sourced (via -x, via run-test.py) +# +try: + inferior = gdb.selected_inferior() + arch = inferior.architecture() + print("ATTACHED: %s" % arch.name()) +except (gdb.error, AttributeError): + print("SKIPPING (not connected)", file=sys.stderr) + exit(0) + +if gdb.parse_and_eval('$pc') == 0: + print("SKIP: PC not set") + exit(0) + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except (gdb.error): + print ("GDB Exception: %s" % (sys.exc_info()[0])) + failcount += 1 + pass + +print("All tests complete: %d failures" % failcount) +exit(failcount)