From 4ebcb6f7f0c9b2ac695864095f402fe9eb52b55c Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Tue, 9 Apr 2024 15:43:00 +0800 Subject: [PATCH] i#3544 RV64: Port sample.memtrace_simple to RISC-V --- api/samples/memtrace_simple.c | 2 +- core/ir/instr.h | 2 +- core/ir/riscv64/decode.c | 4 +--- core/ir/riscv64/instr.c | 5 ++--- suite/tests/CMakeLists.txt | 10 ++++++++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/api/samples/memtrace_simple.c b/api/samples/memtrace_simple.c index 55dd7e7e5bd..662f3995a47 100644 --- a/api/samples/memtrace_simple.c +++ b/api/samples/memtrace_simple.c @@ -338,7 +338,7 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *wher * Using a fault to handle a full buffer should be more robust, and the * forthcoming buffer filling API (i#513) will provide that. */ - IF_AARCHXX_ELSE(!instr_is_exclusive_store(instr_operands), true)) + IF_AARCHXX_OR_RISCV64_ELSE(!instr_is_exclusive_store(instr_operands), true)) dr_insert_clean_call(drcontext, bb, where, (void *)clean_call, false, 0); return DR_EMIT_DEFAULT; diff --git a/core/ir/instr.h b/core/ir/instr.h index de35fd1b3d1..4e3e31c10e5 100644 --- a/core/ir/instr.h +++ b/core/ir/instr.h @@ -691,7 +691,7 @@ instr_compute_vector_address(instr_t *instr, priv_mcontext_t *mc, size_t mc_size uint instr_branch_type(instr_t *cti_instr); -#ifdef AARCH64 +#if defined(AARCH64) || defined(RISCV64) const char * get_opcode_name(int opc); #endif diff --git a/core/ir/riscv64/decode.c b/core/ir/riscv64/decode.c index 4677e16bda8..32f751761de 100644 --- a/core/ir/riscv64/decode.c +++ b/core/ir/riscv64/decode.c @@ -178,9 +178,7 @@ DR_API const char * decode_opcode_name(int opcode) { - /* FIXME i#3544: Not implemented */ - ASSERT_NOT_IMPLEMENTED(false); - return NULL; + return get_opcode_name(opcode); } opnd_size_t diff --git a/core/ir/riscv64/instr.c b/core/ir/riscv64/instr.c index 31e3a3882af..4aad9b4fcce 100644 --- a/core/ir/riscv64/instr.c +++ b/core/ir/riscv64/instr.c @@ -33,6 +33,7 @@ #include "../globals.h" #include "instr.h" #include "encode_api.h" +#include "codec.h" /* XXX i#6690: currently only RISCV64 is supported for instruction encoding. * We want to add support for RISCV64 decoding and synthetic ISA encoding as well. @@ -148,9 +149,7 @@ instr_branch_type(instr_t *cti_instr) const char * get_opcode_name(int opc) { - /* FIXME i#3544: Not implemented */ - ASSERT_NOT_IMPLEMENTED(false); - return ""; + return get_instruction_info(opc)->name; } bool diff --git a/suite/tests/CMakeLists.txt b/suite/tests/CMakeLists.txt index 59c267d5d6d..c911c6eb835 100644 --- a/suite/tests/CMakeLists.txt +++ b/suite/tests/CMakeLists.txt @@ -3518,8 +3518,13 @@ if (BUILD_SAMPLES) foreach (sample ${sample_list}) # FIXME i#4392: Remove sanity checks and replace with functioning tests like # that done for the opcode_count and memtrace_simple samples. - torunonly_ci(sample.${sample} common.${control_flags} - ${sample} common/${control_flags}.c "" "" "") + if (RISCV64 AND sample STREQUAL "memtrace_simple") + torunonly_ci(sample.${sample} common.${control_flags} + ${sample} common/${control_flags}.c "" "-max_bb_instrs 8" "") + else () + torunonly_ci(sample.${sample} common.${control_flags} + ${sample} common/${control_flags}.c "" "" "") + endif () if (sample STREQUAL "inscount") # test out-of-line clean call torunonly_ci(sample.${sample}.cleancall common.${control_flags} ${sample} @@ -6195,6 +6200,7 @@ if (RISCV64) code_api|sample.inscount code_api|sample.inscount.cleancall code_api|sample.inscount.prof-pcs.cleancall + code_api|sample.memtrace_simple code_api|sample.opcode_count code_api|sample.signal code_api|sample.stl_test