From patchwork Thu May 4 15:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares Bernardino X-Patchwork-Id: 13231447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 114CEC7EE21 for ; Thu, 4 May 2023 17:35:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pucoH-0006xZ-E5; Thu, 04 May 2023 13:32:05 -0400 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 1pub1l-0003wC-Qd for qemu-devel@nongnu.org; Thu, 04 May 2023 11:37:53 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pub1e-0001D7-Vn for qemu-devel@nongnu.org; Thu, 04 May 2023 11:37:53 -0400 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 344F61TC028232; Thu, 4 May 2023 15:37:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=qcppdkim1; bh=IgQjqsG/6YfmrHCChmgLqKNcpyr8DF9bc3N7FM/pWIw=; b=RrsWmqB/SizRsdjijf1cgGfx94UPpCHyHPI2+HsamJuQGuheOcl/iJFwE4qLH7J5BE2V yyE0tRxhO9hLUAn2RPLX8iaVD+RUa4e/9d6+2iRapRvj6JDhsbGuegwFuG3ln6ZvlzFl OHS9MvSVDxUVUKkHUmI4ql4KCVQpUkQuWyLlTgdP5ITDMCgpUIzuYWySJ958dq/r7kCq FRAXWeN7J9DDDFUU1Y8GBJw2T9kyGIRRSM6wrqE9ZW9LxjRClGZ5djJ9/8yNEbTqyEXt P4tlU24e988E3+HpuqBQLEtivcE/A4heNntFVSgQpD8HuIPV2C/stFcL22q9uFYvV078 QA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qcf24g35k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 May 2023 15:37:39 +0000 Received: from pps.filterd (NALASPPMTA04.qualcomm.com [127.0.0.1]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 344FbcBS031990; Thu, 4 May 2023 15:37:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTPS id 3q8vam6h1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 May 2023 15:37:38 +0000 Received: from NALASPPMTA04.qualcomm.com (NALASPPMTA04.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 344FbcOf031977; Thu, 4 May 2023 15:37:38 GMT Received: from hu-devc-sd-u20-a-1.qualcomm.com (hu-mathbern-lv.qualcomm.com [10.47.235.147]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTPS id 344Fbbif031975 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 May 2023 15:37:38 +0000 Received: by hu-devc-sd-u20-a-1.qualcomm.com (Postfix, from userid 4229910) id 8D20370ED; Thu, 4 May 2023 12:37:37 -0300 (-03) From: Matheus Tavares Bernardino To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, bcain@quicinc.com, f4bug@amsat.org, peter.maydell@linaro.org, tsimpson@quicinc.com, philmd@linaro.org, richard.henderson@linaro.org Subject: [PATCH v3 0/6] Hexagon: add lldb support Date: Thu, 4 May 2023 12:37:30 -0300 Message-Id: X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: --TBowNG-G8kHUnmSbuVvW9FM8lC8tuA X-Proofpoint-GUID: --TBowNG-G8kHUnmSbuVvW9FM8lC8tuA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-04_10,2023-05-04_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 suspectscore=0 bulkscore=0 impostorscore=0 phishscore=0 priorityscore=1501 spamscore=0 malwarescore=0 clxscore=1015 mlxlogscore=872 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305040127 Received-SPF: pass client-ip=205.220.168.131; envelope-from=mathbern@qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_LOW=-0.7, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This series allows hexagon programs to be debugged under qemu user-mode through LLDB and qemu's gdbstub. LLDB implements the GDB remote serial protocol, so most of the necessary changes are in the Hexagon part itself. However, one fix is needed at the arch-independent side too. Changes in v3: - Patches 1 & 2: added Alex ack. - Patch 1: added missing allow_stop_reply guard to gdbstub/user.c:gdb_exit(). - Patches 3 & 5: replaced qRegisterInfo with gdb-xml. - Patch 6: Used force_sig_fault(). v2: https://lore.kernel.org/qemu-devel/cover.1681993775.git.quic_mathbern@quicinc.com/ v1: https://lore.kernel.org/qemu-devel/cover.1680808943.git.quic_mathbern@quicinc.com/ Brian Cain (1): Hexagon (gdbstub): fix p3:0 read and write via stub Matheus Tavares Bernardino (4): gdbstub: only send stop-reply packets when allowed to gdbstub: add test for untimely stop-reply packets Hexagon: add core gdbstub xml data for LLDB Hexagon (linux-user/hexagon): handle breakpoints Taylor Simpson (1): Hexagon (gdbstub): add HVX support MAINTAINERS | 1 + configs/targets/hexagon-linux-user.mak | 1 + gdbstub/internals.h | 5 + target/hexagon/internal.h | 2 + gdbstub/gdbstub.c | 37 +++++-- gdbstub/softmmu.c | 13 ++- gdbstub/user.c | 24 +++-- linux-user/hexagon/cpu_loop.c | 3 + target/hexagon/cpu.c | 9 +- target/hexagon/gdbstub.c | 84 ++++++++++++++++ gdb-xml/hexagon-core.xml | 84 ++++++++++++++++ gdb-xml/hexagon-hvx.xml | 96 +++++++++++++++++++ tests/guest-debug/run-test.py | 16 +++- .../multiarch/system/Makefile.softmmu-target | 16 +++- 14 files changed, 366 insertions(+), 25 deletions(-) create mode 100644 gdb-xml/hexagon-core.xml create mode 100644 gdb-xml/hexagon-hvx.xml Range-diff against v2: 1: b4ec188e67 ! 1: a49c0897fc gdbstub: only send stop-reply packets when allowed to @@ gdbstub/softmmu.c: void gdb_exit(int code) } ## gdbstub/user.c ## +@@ gdbstub/user.c: void gdb_exit(int code) + + trace_gdbstub_op_exiting((uint8_t)code); + +- snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); +- gdb_put_packet(buf); ++ if (gdbserver_state.allow_stop_reply) { ++ snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); ++ gdb_put_packet(buf); ++ gdbserver_state.allow_stop_reply = false; ++ } + } + + int gdb_handlesig(CPUState *cpu, int sig) @@ gdbstub/user.c: int gdb_handlesig(CPUState *cpu, int sig) if (sig != 0) { 2: a91ec99036 = 2: a30d93b9a8 gdbstub: add test for untimely stop-reply packets 3: 40aa60ee50 < -: ---------- gdbstub: add support for the qRegisterInfo query 4: 090707eea1 < -: ---------- Hexagon: support qRegisterInfo at gdbstub -: ---------- > 3: d25a3a7933 Hexagon: add core gdbstub xml data for LLDB 5: 06ed954dab ! 4: 32e7de567c Hexagon (gdbstub): fix p3:0 read and write via stub @@ Metadata ## Commit message ## Hexagon (gdbstub): fix p3:0 read and write via stub + Signed-off-by: Brian Cain Co-authored-by: Sid Manning Signed-off-by: Sid Manning - Signed-off-by: Brian Cain Co-authored-by: Matheus Tavares Bernardino Signed-off-by: Matheus Tavares Bernardino Reviewed-by: Taylor Simpson 6: 880c86bf2b ! 5: 17cb32f34d Hexagon (gdbstub): add HVX support @@ Metadata ## Commit message ## Hexagon (gdbstub): add HVX support + Signed-off-by: Taylor Simpson Co-authored-by: Brian Cain Signed-off-by: Brian Cain - Signed-off-by: Taylor Simpson Co-authored-by: Matheus Tavares Bernardino Signed-off-by: Matheus Tavares Bernardino - ## target/hexagon/gdbstub.c ## + ## configs/targets/hexagon-linux-user.mak ## +@@ + TARGET_ARCH=hexagon +-TARGET_XML_FILES=gdb-xml/hexagon-core.xml ++TARGET_XML_FILES=gdb-xml/hexagon-core.xml gdb-xml/hexagon-hvx.xml + + ## target/hexagon/internal.h ## @@ - #include "cpu.h" - #include "internal.h" + int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); + int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); ++int hexagon_hvx_gdb_read_register(CPUHexagonState *env, GByteArray *mem_buf, int n); ++int hexagon_hvx_gdb_write_register(CPUHexagonState *env, uint8_t *mem_buf, int n); + + void hexagon_debug_vreg(CPUHexagonState *env, int regnum); + void hexagon_debug_qreg(CPUHexagonState *env, int regnum); + + ## target/hexagon/cpu.c ## +@@ + #include "hw/qdev-properties.h" + #include "fpu/softfloat-helpers.h" + #include "tcg/tcg.h" ++#include "exec/gdbstub.h" + + static void hexagon_v67_cpu_init(Object *obj) + { +@@ target/hexagon/cpu.c: static void hexagon_cpu_realize(DeviceState *dev, Error **errp) + return; + } + ++ gdb_register_coprocessor(cs, hexagon_hvx_gdb_read_register, ++ hexagon_hvx_gdb_write_register, ++ NUM_VREGS + NUM_QREGS, ++ "hexagon-hvx.xml", 0); ++ + qemu_init_vcpu(cs); + cpu_reset(cs); + + + ## target/hexagon/gdbstub.c ## +@@ target/hexagon/gdbstub.c: int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) + + g_assert_not_reached(); + } ++ +static int gdb_get_vreg(CPUHexagonState *env, GByteArray *mem_buf, int n) +{ + int total = 0; @@ target/hexagon/gdbstub.c + return total; +} + - int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) - { - HexagonCPU *cpu = HEXAGON_CPU(cs); -@@ target/hexagon/gdbstub.c: int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) - if (n < TOTAL_PER_THREAD_REGS) { - return gdb_get_regl(mem_buf, env->gpr[n]); - } -+ n -= TOTAL_PER_THREAD_REGS; -+ ++int hexagon_hvx_gdb_read_register(CPUHexagonState *env, GByteArray *mem_buf, int n) ++{ + if (n < NUM_VREGS) { + return gdb_get_vreg(env, mem_buf, n); + } @@ target/hexagon/gdbstub.c: int hexagon_gdb_read_register(CPUState *cs, GByteArray + if (n < NUM_QREGS) { + return gdb_get_qreg(env, mem_buf, n); + } - - g_assert_not_reached(); - } - ++ ++ g_assert_not_reached(); ++} ++ +static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n) +{ + int i; @@ target/hexagon/gdbstub.c: int hexagon_gdb_read_register(CPUState *cs, GByteArray + return MAX_VEC_SIZE_BYTES / 8; +} + - int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) - { - HexagonCPU *cpu = HEXAGON_CPU(cs); -@@ target/hexagon/gdbstub.c: int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) - env->gpr[n] = ldtul_p(mem_buf); - return sizeof(target_ulong); - } -+ n -= TOTAL_PER_THREAD_REGS; -+ -+ if (n < NUM_VREGS) { ++int hexagon_hvx_gdb_write_register(CPUHexagonState *env, uint8_t *mem_buf, int n) ++{ ++ if (n < NUM_VREGS) { + return gdb_put_vreg(env, mem_buf, n); + } + n -= NUM_VREGS; @@ target/hexagon/gdbstub.c: int hexagon_gdb_write_register(CPUState *cs, uint8_t * + if (n < NUM_QREGS) { + return gdb_put_qreg(env, mem_buf, n); + } - - g_assert_not_reached(); - } ++ ++ g_assert_not_reached(); ++} + + ## gdb-xml/hexagon-hvx.xml (new) ## +@@ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ 7: 3ff83e45a5 ! 6: c287a129dc Hexagon (linux-user/hexagon): handle breakpoints @@ ## Metadata ## -Author: Taylor Simpson +Author: Matheus Tavares Bernardino ## Commit message ## Hexagon (linux-user/hexagon): handle breakpoints @@ Commit message This enables LLDB to work with hexagon linux-user mode through the GDB remote protocol. - Signed-off-by: Taylor Simpson + Helped-by: Richard Henderson Signed-off-by: Matheus Tavares Bernardino ## linux-user/hexagon/cpu_loop.c ## -@@ linux-user/hexagon/cpu_loop.c: void cpu_loop(CPUHexagonState *env) - target_ulong ret; - - for (;;) { -+ target_siginfo_t info; - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); @@ linux-user/hexagon/cpu_loop.c: void cpu_loop(CPUHexagonState *env) case EXCP_ATOMIC: cpu_exec_step_atomic(cs); break; + case EXCP_DEBUG: -+ info = (target_siginfo_t) { -+ .si_signo = TARGET_SIGTRAP, -+ .si_errno = 0, -+ .si_code = TARGET_TRAP_BRKPT, -+ ._sifields._sigfault._addr = 0 -+ }; -+ queue_signal(env, info.si_signo, QEMU_SI_KILL, &info); ++ force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0); + break; default: EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",