From eb3ca7f65bc88fe83f9901895b2109286508b8bb Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 27 Jun 2018 15:07:28 +0100 Subject: [PATCH] tests: Add print_info program Eases debugging by printing out dynarmic IR for a given A64 instruction, along with information about what instruction dynarmic thinks it is. Also prints an LLVM disassembly of the instruction. --- tests/CMakeLists.txt | 9 ++++++++ tests/print_info.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/print_info.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 575d64a5..7a915fab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,11 +44,20 @@ if (DYNARMIC_TESTS_USE_UNICORN) target_link_libraries(dynarmic_tests PRIVATE Unicorn::Unicorn) endif() +add_executable(dynarmic_print_info + print_info.cpp +) + include(CreateDirectoryGroups) create_target_directory_groups(dynarmic_tests) +create_target_directory_groups(dynarmic_print_info) target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch fmt) target_include_directories(dynarmic_tests PRIVATE . ../src) target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS}) +target_link_libraries(dynarmic_print_info PRIVATE dynarmic boost catch fmt) +target_include_directories(dynarmic_print_info PRIVATE . ../src) +target_compile_options(dynarmic_print_info PRIVATE ${DYNARMIC_CXX_FLAGS}) + add_test(dynarmic_tests dynarmic_tests) diff --git a/tests/print_info.cpp b/tests/print_info.cpp new file mode 100644 index 00000000..9486e06a --- /dev/null +++ b/tests/print_info.cpp @@ -0,0 +1,52 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2018 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#include +#include + +#include + +#include "common/common_types.h" +#include "common/llvm_disassemble.h" +#include "frontend/A64/decoder/a64.h" +#include "frontend/A64/location_descriptor.h" +#include "frontend/A64/translate/impl/impl.h" +#include "frontend/A64/translate/translate.h" +#include "frontend/ir/basic_block.h" + +using namespace Dynarmic; + +const char* GetNameOfInstruction(u32 instruction) { + if (auto decoder = A64::Decode(instruction)) { + return decoder->GetName(); + } + return ""; +} + +int main(int argc, char** argv) { + if (argc != 2) { + fmt::print("usage: {} \n", argv[0]); + return 1; + } + + if (strlen(argv[1]) > 8) { + fmt::print("hex string too long\n"); + return 1; + } + + const u32 instruction = strtol(argv[1], nullptr, 16); + fmt::print("{:08x} {}\n", instruction, Common::DisassembleAArch64(instruction)); + fmt::print("Name: {}\n", GetNameOfInstruction(instruction)); + + const A64::LocationDescriptor location{0, {}}; + IR::Block block{location}; + const bool should_continue = A64::TranslateSingleInstruction(block, location, instruction); + fmt::print("should_continue: {}\n", should_continue); + fmt::print("IR:\n"); + fmt::print("{}\n", IR::DumpBlock(block)); + + return 0; +}