From patchwork Sun Mar 3 19:26:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 777649 Delivered-To: patch@linaro.org Received: by 2002:a5d:4b84:0:b0:33d:f458:43ce with SMTP id b4csp223011wrt; Sun, 3 Mar 2024 11:27:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXc8K+BnD/AZK6VHFXwqON6J/LGq9qP5L8T+IAw49KPSj3piHQsX8wOWEwZsoaXiEVlADCCc1lPjbjd657Ta+Y2 X-Google-Smtp-Source: AGHT+IEc80nfJDtqw9MiLDSXP4FHFQQfEJB+qm32qij7XuLu2MNs6L9tjVZtiV2a/JZWQ7I7Vy/L X-Received: by 2002:a05:6359:4589:b0:17c:d10:722c with SMTP id no9-20020a056359458900b0017c0d10722cmr5787974rwb.1.1709494044491; Sun, 03 Mar 2024 11:27:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709494044; cv=none; d=google.com; s=arc-20160816; b=R7YGlH/4U+6OL5nEDrd6Bts+1z2PLjWgaOy0LPzi6ttiunusz6JAYdTMN0IA8Pl8yy NwjnjssItejwgtPdtjfPRC+PDIGSdtpJEh5qlw82xWf3h9eymHwo6oXTEa3RL0X2oId5 7sdvmd6tZDYkaAQkvpnnHPRdkFAmjkZD3iACguCbeWzSDo4Qn9k7SDZNHQyYPhIueAfR jl83R9B90oft6eO3mGc4rioDF1WKXWYh9ETgD/wY9G1d4XlCNQqbyU30EiMNsP58CNNU 6hcV5zu5rSckEu4meEDY8KCqQnCv5/8xMZ0ULYR+hbj5FBp/EONRqMy/Jv1Dw+WKXJ8j jzrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=d5m9mhIK8JyytOQksDR6IYtiA11v8ohv/oTiKgv5/GE=; fh=kLvOV699bJQJ1aB4dJ9+Hf3L1BkcJSedSEwod57mP/g=; b=f/MPnFca+6VT/aBtb7wc7F6AdqGcCfD25CzHusk6ADJyQDBN+29giQXlrwGvhLKlJn sJucLSxv7o93cmoR670+92/QC/z7GbyhW2IX92/6w7j1xz4mtyx+nxuM2rfNQPJf4e2B zFy7f0uK0yCTwl6w+haPFpD4fanEiWCM5M55TEDDQDkDoi4SVWy9PloHH1YPv7Zx6qQ4 U5gdf2cNA7QHsWnNsQQBp4qIYlJjliuZ9fuIOVGmPbuYtZguSh4HCgUMKse+ZGltoiCb 5iD/yTuR1rVfcerwp7o7QAOsyPug9UyFLQKB+L2htZp30OcRJDak/Qiv6Y0D5rTLCHDQ UA7A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LcEAtvvt; 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=pass (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 kj15-20020a056214528f00b0068cba3feed6si8041321qvb.507.2024.03.03.11.27.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Mar 2024 11:27:24 -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=pass header.i=@linaro.org header.s=google header.b=LcEAtvvt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgrTv-00048X-5G; Sun, 03 Mar 2024 14:26:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgrTt-000489-Vx for qemu-devel@nongnu.org; Sun, 03 Mar 2024 14:26:42 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgrTs-00031B-8W for qemu-devel@nongnu.org; Sun, 03 Mar 2024 14:26:41 -0500 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e56da425b5so2694310b3a.0 for ; Sun, 03 Mar 2024 11:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709493993; x=1710098793; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=d5m9mhIK8JyytOQksDR6IYtiA11v8ohv/oTiKgv5/GE=; b=LcEAtvvtjtxtzXyVKdfDGlwecnBh8mGkOTSfVdZEGG5+Ce8Uz+xkExtn1OfcPI8SbK iWIfczPueDO1NNGJ54BV/tyJ/L2Ic+FBP3HdhQZfqQueQtecgcBg7VdMG8XK3g6mtSUU I1oE/wm0agjS7pnX357wX5V+nPn5K8Gb/JfVuFnmKVY0GqTdQQdhy+4qIqvNthLIZ1Ur Pu1UPP0Ad4Sk7F8dvEnSNop9cNOLU99PazuHyeZDyOaKkf27trpeCUhxUDh6e8tIND4S ZzRpE+5PNA1nEj3WMEvjfNqt6ZVhg7ygukAq2JS4dM7lXq9LyaM/Q3N9rLqPTMz8vjyW w/lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709493993; x=1710098793; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d5m9mhIK8JyytOQksDR6IYtiA11v8ohv/oTiKgv5/GE=; b=TQdyKL9eEwm+3vMSutSf+6FHxUlz4SASPu7WuzOMeSwMgsrdf+tPp9QoAwQBy46+jP LzVht4A/gaBt/NJj9vSiNwnvlUPnKSXWRXLSOI5M/kmwQBLunaqWVh32CIhDLfnKBSvt Eywzz4VzaHi7bNMCzIgTik/nX0R5UN4cJBCwi7h04ouccQN2n0mFwOBT4n3taEYOF+GI kp4Fw3UvFq/ivlWx+yQt+pxMc/Eekqj4jOPRaF+evxqXZHq8KNcq6tfOsBWRoBy0D6+z NC4N7FzzSYHFHJQKi3H6Nu/E+0qUEzEfJ4UWDUZ/51imVlz3nN6WimJg/dvew5pfny9U f+eg== X-Gm-Message-State: AOJu0YwbCqbgio6S5LFL8Q8vxDiEW/rZerscDChQnSChZUaUeRgHWTzD cnjpNFwnJ7TYLWC2oPKLeqKK8xrfyWeBQVBK1F9KmSS6FU9EIgq8NhiGBy1Z1eRoNtCbtqPQUxO Z X-Received: by 2002:a05:6a00:1915:b0:6e5:75cd:eff0 with SMTP id y21-20020a056a00191500b006e575cdeff0mr7141652pfi.31.1709493992604; Sun, 03 Mar 2024 11:26:32 -0800 (PST) Received: from amd.. ([2804:7f0:b401:120f:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id du6-20020a056a002b4600b006e5933a0da9sm5941287pfb.165.2024.03.03.11.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 11:26:32 -0800 (PST) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH 1/2] gdbstub: Add Xfer:siginfo:read stub Date: Sun, 3 Mar 2024 19:26:09 +0000 Message-Id: <20240303192610.498490-1-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add stub to handle Xfer:siginfo:read query that requests the machine's siginfo data. This is used when GDB users execute 'print $_siginfo' and when the machine stops due to a signal, like on a SIGSEGV. The information in siginfo allows GDB to determine further details on the signal, like the fault address/insn when the SIGSEGV is caught. The siginfo is also used by GDB to find out the si_code automatically and show additional info to the user in some cases. This is only a QEMU user mode and Linux-only feature. Signed-off-by: Gustavo Romero --- gdbstub/gdbstub.c | 9 +++++++++ gdbstub/internals.h | 1 + gdbstub/user-target.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 2909bc8c69..54c1f6fb3c 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1650,7 +1650,10 @@ static void handle_query_supported(GArray *params, void *user_ctx) if (gdbserver_state.c_cpu->opaque) { g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+"); } + g_string_append(gdbserver_state.str_buf, ";QCatchSyscalls+"); + + g_string_append(gdbserver_state.str_buf, ";qXfer:siginfo:read+"); #endif g_string_append(gdbserver_state.str_buf, ";qXfer:exec-file:read+"); #endif @@ -1799,6 +1802,12 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { .cmd_startswith = 1, .schema = "l,l0" }, + { + .handler = gdb_handle_query_xfer_siginfo, + .cmd = "Xfer:siginfo:read::", + .cmd_startswith = 1, + .schema = "l,l0" + }, #endif { .handler = gdb_handle_query_xfer_exec_file, diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 56b7c13b75..fcfe7c2d26 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -190,6 +190,7 @@ typedef union GdbCmdVariant { void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx); /*user */ void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */ void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */ void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */ diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index b7d4c37cd8..3a4cf96622 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -284,6 +284,37 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx) gdb_put_packet_binary(gdbserver_state.str_buf->str, gdbserver_state.str_buf->len, true); } + +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx) +{ + TaskState *ts; + unsigned long offset, len; + target_siginfo_t tmp_siginfo; + uint8_t *siginfo_offset; + + offset = get_param(params, 0)->val_ul; + len = get_param(params, 1)->val_ul; + + if (offset + len > sizeof(target_siginfo_t)) { + /* Invalid offset and/or requested length. */ + gdb_put_packet("E01"); + return; + } + + ts = gdbserver_state.c_cpu->opaque; + + /* Filter out si_type from si_code. See comment in siginfo_noswap(). */ + tmp_siginfo = ts->sync_signal.info; + tmp_siginfo.si_code = sextract32(tmp_siginfo.si_code, 0, 16); + + siginfo_offset = (uint8_t *)&tmp_siginfo + offset; + + /* Reply */ + g_string_assign(gdbserver_state.str_buf, "l"); + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len); + gdb_put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); +} #endif static const char *get_filename_param(GArray *params, int i)