diff --git a/api/samples/opcodes.c b/api/samples/opcodes.c index 86827d20719..1249ef7ca64 100644 --- a/api/samples/opcodes.c +++ b/api/samples/opcodes.c @@ -203,6 +203,8 @@ get_count_isa_idx(void *drcontext) case DR_ISA_ARM_THUMB: return ISA_ARM_THUMB; #elif defined(AARCH64) case DR_ISA_ARM_A64: return ISA_ARM_A64; +#elif defined(RISCV64) + case DR_ISA_RV64IMAFDC: return ISA_RV64IMAFDC; #endif default: DR_ASSERT(false); /* NYI */ } diff --git a/core/unix/os_public.h b/core/unix/os_public.h index 193dfcb6471..84899bcec88 100644 --- a/core/unix/os_public.h +++ b/core/unix/os_public.h @@ -205,7 +205,17 @@ typedef kernel_sigcontext_t sigcontext_t; # define SC_SYSNUM_REG SC_R7 # define SC_RETURN_REG SC_R0 #elif defined(RISCV64) +# define SC_XIP SC_FIELD(sc_regs.pc) +# define SC_RA SC_FIELD(sc_regs.ra) +# define SC_XSP SC_FIELD(sc_regs.sp) +# define SC_GP SC_FIELD(sc_regs.gp) # define SC_TP SC_FIELD(sc_regs.tp) +# define SC_T0 SC_FIELD(sc_regs.t0) +# define SC_T1 SC_FIELD(sc_regs.t1) +# define SC_T2 SC_FIELD(sc_regs.t2) +# define SC_S0 SC_FIELD(sc_regs.s0) +# define SC_FP SC_FIELD(sc_regs.s0) +# define SC_S1 SC_FIELD(sc_regs.s1) # define SC_A0 SC_FIELD(sc_regs.a0) # define SC_A1 SC_FIELD(sc_regs.a1) # define SC_A2 SC_FIELD(sc_regs.a2) @@ -214,11 +224,20 @@ typedef kernel_sigcontext_t sigcontext_t; # define SC_A5 SC_FIELD(sc_regs.a5) # define SC_A6 SC_FIELD(sc_regs.a6) # define SC_A7 SC_FIELD(sc_regs.a7) -# define SC_FP SC_FIELD(sc_regs.s0) +# define SC_S2 SC_FIELD(sc_regs.s2) +# define SC_S3 SC_FIELD(sc_regs.s3) +# define SC_S4 SC_FIELD(sc_regs.s4) +# define SC_S5 SC_FIELD(sc_regs.s5) +# define SC_S6 SC_FIELD(sc_regs.s6) +# define SC_S7 SC_FIELD(sc_regs.s7) +# define SC_S8 SC_FIELD(sc_regs.s8) +# define SC_S9 SC_FIELD(sc_regs.s9) +# define SC_S10 SC_FIELD(sc_regs.s10) # define SC_S11 SC_FIELD(sc_regs.s11) -# define SC_RA SC_FIELD(sc_regs.ra) -# define SC_XIP SC_FIELD(sc_regs.pc) -# define SC_XSP SC_FIELD(sc_regs.sp) +# define SC_T3 SC_FIELD(sc_regs.t3) +# define SC_T4 SC_FIELD(sc_regs.t4) +# define SC_T5 SC_FIELD(sc_regs.t5) +# define SC_T6 SC_FIELD(sc_regs.t6) # define SC_SYSNUM_REG SC_A7 # define SC_RETURN_REG SC_A0 #endif /* X86/ARM */ diff --git a/ext/drcallstack/drcallstack.c b/ext/drcallstack/drcallstack.c index 6812b7d1a88..03c8cb67b48 100644 --- a/ext/drcallstack/drcallstack.c +++ b/ext/drcallstack/drcallstack.c @@ -125,6 +125,13 @@ drcallstack_init_walk(dr_mcontext_t *mc, DR_PARAM_OUT drcallstack_walk_t **walk_ # elif defined(ARM) /* libunwind defines its own struct of 16 regs. */ memcpy(&walk->uc.regs[0], &mc->r0, 16 * sizeof(walk->uc.regs[0])); +# elif defined(RISCV64) + /* unw_context_t is an alias of ucontext_t. */ + sigcontext_t *sc = SIGCXT_FROM_UCXT(&walk->uc); + sc->SC_XIP = (ptr_uint_t)mc->pc; + /* x1..x31 is in the same order with no padding. */ + memcpy(&sc->SC_RA, &mc->ra, 31 * sizeof(sc->SC_RA)); + sc->SC_XSP = mc->xsp; # else return DRCALLSTACK_ERROR_FEATURE_NOT_AVAILABLE; # endif diff --git a/suite/tests/CMakeLists.txt b/suite/tests/CMakeLists.txt index 5b5d316baed..77723d43877 100644 --- a/suite/tests/CMakeLists.txt +++ b/suite/tests/CMakeLists.txt @@ -3585,7 +3585,7 @@ if (BUILD_SAMPLES) samples/${sample}_repstr "-log_to_stderr" "" "") endif () elseif (sample STREQUAL "callstack") - set(sample.${sample}_expectbase "sample.callstack.control_flags") + set(sample.${sample}_expectbase "sample.callstack") endif() endforeach () endif (NOT ANDROID) @@ -6204,6 +6204,7 @@ if (RISCV64) code_api|sample.inscount.cleancall code_api|sample.inscount.prof-pcs.cleancall code_api|sample.opcode_count + code_api|sample.opcodes code_api|sample.signal code_api|sample.stl_test code_api|sample.syscall diff --git a/suite/tests/common/sample.callstack.control_flags.templatex b/suite/tests/common/sample.callstack.templatex similarity index 79% rename from suite/tests/common/sample.callstack.control_flags.templatex rename to suite/tests/common/sample.callstack.templatex index 5c5d58f8633..2cedf77eae2 100644 --- a/suite/tests/common/sample.callstack.control_flags.templatex +++ b/suite/tests/common/sample.callstack.templatex @@ -1,7 +1,9 @@ wrapping .*malloc malloc called from: .* -#ifdef AARCHXX +#if defined(RISCV64) +Hello world! +#elif defined(AARCHXX) OK 1 N OK 0 N OK 1 Z