qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	qemu-devel@nongnu.org, "Lirong Yuan" <yuanzi@google.com>
Subject: [PULL 17/30] gdbstub: add support to Xfer:auxv:read: packet
Date: Fri, 15 Jan 2021 13:08:15 +0000	[thread overview]
Message-ID: <20210115130828.23968-18-alex.bennee@linaro.org> (raw)
In-Reply-To: <20210115130828.23968-1-alex.bennee@linaro.org>

From: Lirong Yuan <yuanzi@google.com>

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 <yuanzi@google.com>
[AJB: minor tweaks to test case, update MAINTAINERS]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200730193932.3654677-1-yuanzi@google.com>
Message-Id: <20210108224256.2321-7-alex.bennee@linaro.org>

diff --git a/gdbstub.c b/gdbstub.c
index d99bc0bf2e..15d3a8e1f5 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 07e4851aa4..3216387521 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2322,6 +2322,7 @@ R: Philippe Mathieu-Daudé <philmd@redhat.com>
 S: Maintained
 F: gdbstub*
 F: gdb-xml/
+F: tests/tcg/multiarch/gdbstub/
 
 Memory API
 M: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index cb49cc9ccb..1dd0f64d23 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -55,6 +55,15 @@ run-gdbstub-sha1: sha1
 	"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)
-- 
2.20.1



  parent reply	other threads:[~2021-01-15 13:18 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 13:07 [PULL 00/30] testing, gdbstub and semihosting Alex Bennée
2021-01-15 13:07 ` [PULL 01/30] tests/docker: Remove Debian 9 remnant lines Alex Bennée
2021-01-15 13:08 ` [PULL 02/30] Makefile: add GNU global tags support Alex Bennée
2021-01-15 13:08 ` [PULL 03/30] shippable.yml: Remove jobs duplicated on Gitlab-CI Alex Bennée
2021-01-15 13:08 ` [PULL 04/30] Add newline when generating Dockerfile Alex Bennée
2021-01-15 13:08 ` [PULL 05/30] Makefile: wrap ctags in quiet-command calls Alex Bennée
2021-01-18 18:36   ` Philippe Mathieu-Daudé
2021-01-19 10:00     ` Alex Bennée
2021-01-19 14:24       ` Philippe Mathieu-Daudé
2021-01-19 14:27         ` Daniel P. Berrangé
2021-01-19 14:42           ` Philippe Mathieu-Daudé
2021-01-15 13:08 ` [PULL 06/30] Makefile: wrap etags " Alex Bennée
2021-01-15 13:08 ` [PULL 07/30] Makefile: wrap cscope " Alex Bennée
2021-01-15 13:08 ` [PULL 08/30] docker: expand debian-amd64 image to include tag tools Alex Bennée
2021-01-15 13:08 ` [PULL 09/30] gitlab: move docs and tools build across from Travis Alex Bennée
2021-01-15 13:08 ` [PULL 10/30] Fix build with new yank feature by adding stubs Alex Bennée
2021-01-15 13:08 ` [PULL 11/30] gitlab: migrate the minimal tools and unit tests from Travis Alex Bennée
2021-01-15 13:08 ` [PULL 12/30] scripts/checkpatch.pl: fix git-show invocation to include diffstat Alex Bennée
2021-01-15 13:08 ` [PULL 13/30] test/guest-debug: echo QEMU command as well Alex Bennée
2021-01-15 13:08 ` [PULL 14/30] configure: gate our use of GDB to 8.3.1 or above Alex Bennée
2021-01-15 13:08 ` [PULL 15/30] Revert "tests/tcg/multiarch/Makefile.target: Disable run-gdbstub-sha1 test" Alex Bennée
2021-01-15 13:08 ` [PULL 16/30] gdbstub: implement a softmmu based test Alex Bennée
2021-01-15 13:08 ` Alex Bennée [this message]
2021-01-15 13:08 ` [PULL 18/30] gdbstub: drop CPUEnv from gdb_exit() Alex Bennée
2021-01-15 13:08 ` [PULL 19/30] gdbstub: drop gdbserver_cleanup in favour of gdb_exit Alex Bennée
2021-01-15 13:08 ` [PULL 20/30] gdbstub: ensure we clean-up when terminated Alex Bennée
2021-01-15 13:08 ` [PULL 21/30] target/arm: use official org.gnu.gdb.aarch64.sve layout for registers Alex Bennée
2021-01-19 13:38   ` Claudio Fontana
2021-01-19 13:49     ` Claudio Fontana
2021-01-19 14:50     ` Alex Bennée
2021-01-19 15:11       ` Claudio Fontana
2021-01-19 15:54         ` Alex Bennée
2021-01-19 16:19           ` Luis Machado
2021-09-21 13:55           ` Peter Maydell
2021-10-04 18:44             ` Luis Machado
2021-11-04 21:03               ` Luis Machado
2021-11-05 13:35                 ` Luis Machado
2021-11-05 16:15                   ` Alex Bennée
2021-11-05 16:29                     ` Luis Machado
2021-01-15 13:08 ` [PULL 22/30] semihosting: Move ARM semihosting code to shared directories Alex Bennée
2021-01-15 13:08 ` [PULL 23/30] semihosting: Change common-semi API to be architecture-independent Alex Bennée
2021-01-15 13:08 ` [PULL 24/30] semihosting: Change internal common-semi interfaces to use CPUState * Alex Bennée
2021-02-17 15:02   ` Peter Maydell
2021-01-15 13:08 ` [PULL 25/30] semihosting: Support SYS_HEAPINFO when env->boot_info is not set Alex Bennée
2021-01-15 13:08 ` [PULL 26/30] riscv: Add semihosting support Alex Bennée
2021-01-15 13:08 ` [PULL 27/30] riscv: Add semihosting support for user mode Alex Bennée
2021-01-15 13:08 ` [PULL 28/30] semihosting: Implement SYS_ELAPSED and SYS_TICKFREQ Alex Bennée
2021-01-15 13:08 ` [PULL 29/30] semihosting: Implement SYS_TMPNAM Alex Bennée
2021-01-15 13:08 ` [PULL 30/30] semihosting: Implement SYS_ISERROR Alex Bennée
2021-01-15 15:31 ` [PULL 00/30] testing, gdbstub and semihosting Peter Maydell
2021-01-18 12:18   ` Alex Bennée
2021-01-18 13:33     ` Philippe Mathieu-Daudé
2021-01-18 15:38       ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210115130828.23968-18-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yuanzi@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).