From 013a2b68fb86549d517bb846b6487cb812a5b38a Mon Sep 17 00:00:00 2001 From: Yuri Ershov Date: Mon, 9 Oct 2023 11:17:20 +0300 Subject: [PATCH] Updated according to review comments. --- clients/drcachesim/docs/drcachesim.dox.in | 16 ++++++++-------- .../tools/external/example/CMakeLists.txt | 11 ++++++++--- .../drcachesim/tools/external/example/empty.cpp | 5 ++--- .../drcachesim/tools/external/example/empty.h | 2 +- .../tools/external/example/empty.templatex | 2 -- .../tools/external/example/nonexistent.templatex | 2 -- .../tools/loader/external_tool_creator.h | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 clients/drcachesim/tools/external/example/empty.templatex delete mode 100644 clients/drcachesim/tools/external/example/nonexistent.templatex diff --git a/clients/drcachesim/docs/drcachesim.dox.in b/clients/drcachesim/docs/drcachesim.dox.in index b06c46f5fcb..74d6aa87c3e 100644 --- a/clients/drcachesim/docs/drcachesim.dox.in +++ b/clients/drcachesim/docs/drcachesim.dox.in @@ -1603,7 +1603,7 @@ reuse_time_tool_create(), view_tool_create(), cache_simulator_create(), tlb_simulator_create(), func_view_create(), and syscall_mix_tool_create() functions. -\section external_tools Separately-built tools +\section external_tools Separately-Built Tools \p drcachesim \p drmemtrace analysis tool framework allows to load non-predefined separately-built external tools. This tool can be loaded by drcachesim @@ -1613,9 +1613,9 @@ using the \p -simulator_type option. The tool package should consist of - Registration file called \p toolname.drcachesim. -- Static library containing subclass -#dynamorio::drmemtrace::analysis_tool_t with tool internal logic. This library described -in prevoius section. +- Static library containing a subclass of +#dynamorio::drmemtrace::analysis_tool_t with tool internal logic. This library was +described in previous section. - Tool creator dynamic library containing tool factory function. Registration file should be placed to the \p tools subdirectory of the root of the @@ -1628,7 +1628,7 @@ CREATOR_BIN32=/absolute/path/to/32-bit-creator-library CREATOR_BIN64=/absolute/path/to/64-bit-creator-library \endcode -This enables \p drcachsim to locate the tool's creator library. The 32 and +This enables \p drcachesim to locate the tool's creator library. The 32 and 64 specifiers allow pointing at alternate-bitwidth paths for use if the target application creates a child process of a different bitwidth. @@ -1636,13 +1636,13 @@ For more extensive actions on launching the tool, a custom front-end executable can be created that replaces \p drcachesim modeled after histogram_launcher.cpp or opcode_mix_launcher.cpp. -Creator dynamic library should contain 2 export functions: +The creator dynamic library should contain 2 export functions: \code extern "C" EXPORT const char * get_tool_name() { - return "name-of-concrete-tool"; + return "name-of-tool"; } extern "C" EXPORT analysis_tool_t * @@ -1652,7 +1652,7 @@ analysis_tool_create() } \endcode -which allows \p drcachsim to create appropriate analyis tool. As an +which allows \p drcachesim to create an analyis tool. As an example, see minimal external analysis tool. diff --git a/clients/drcachesim/tools/external/example/CMakeLists.txt b/clients/drcachesim/tools/external/example/CMakeLists.txt index a539a73c64d..06db2a91c70 100644 --- a/clients/drcachesim/tools/external/example/CMakeLists.txt +++ b/clients/drcachesim/tools/external/example/CMakeLists.txt @@ -55,6 +55,8 @@ target_link_libraries(empty_launcher use_DynamoRIO_extension(empty_launcher droption) add_dependencies(empty_launcher api_headers) +# These add_win32_flags() calls are necessary only for building the project inside +# the DR top level project. add_win32_flags(drmemtrace_empty) add_win32_flags(empty_creator) add_win32_flags(empty_launcher) @@ -98,20 +100,23 @@ if (X86 AND X64 AND ZIP_FOUND) set_tests_properties(tool.empty_launcher PROPERTIES TIMEOUT ${test_seconds}) # Simple test to ensure empty tool can be loaded by drcachesim. - file(READ "${CMAKE_CURRENT_SOURCE_DIR}/empty.templatex" empty_regex) set(trace_dir "${PROJECT_SOURCE_DIR}/clients/drcachesim/tests/drmemtrace.threadsig.x64.tracedir") add_test(NAME drcachesim.empty_load COMMAND ${PROJECT_BINARY_DIR}/bin64/drrun -t drcachesim -offline -simulator_type empty -indir ${trace_dir}) + set(empty_regex "Empty tool created\nEmpty tool results:") set_tests_properties(drcachesim.empty_load PROPERTIES PASS_REGULAR_EXPRESSION "${empty_regex}") # Simple test to ensure non-existent tool load by drcachesim should fail. - file(READ "${CMAKE_CURRENT_SOURCE_DIR}/nonexistent.templatex" nonexistent_regex) add_test(NAME drcachesim.non-existent_load COMMAND ${PROJECT_BINARY_DIR}/bin64/drrun -t drcachesim -offline -simulator_type non-existent -indir ${trace_dir}) + set(nonexistent_regex "Usage error: unsupported analyzer type "non-existent". + Please choose cache, miss_analyzer, TLB, histogram, reuse_distance, basic_counts, + opcode_mix, syscall_mix, view, func_view, or some external analyzer.\nERROR: failed + to initialize analyzer: Failed to create analysis tool:") set_tests_properties(drcachesim.non-existent_load PROPERTIES PASS_REGULAR_EXPRESSION "${nonexistent_regex}") -endif () \ No newline at end of file +endif () diff --git a/clients/drcachesim/tools/external/example/empty.cpp b/clients/drcachesim/tools/external/example/empty.cpp index e8d3f5c84a6..0723f3f7d57 100644 --- a/clients/drcachesim/tools/external/example/empty.cpp +++ b/clients/drcachesim/tools/external/example/empty.cpp @@ -34,7 +34,6 @@ #include "dr_api.h" #include "empty.h" -#include const std::string empty_t::TOOL_NAME = "Empty tool"; @@ -46,7 +45,7 @@ empty_tool_create(unsigned int verbose) empty_t::empty_t(unsigned int verbose) { - std::cout << "Empty tool created" << std::endl; + fprintf(stderr, "Empty tool created\n"); } std::string @@ -110,6 +109,6 @@ empty_t::process_memref(const memref_t &memref) bool empty_t::print_results() { - std::cout << "Empty tool results:" << std::endl; + fprintf(stderr, "Empty tool results:\n"); return true; } diff --git a/clients/drcachesim/tools/external/example/empty.h b/clients/drcachesim/tools/external/example/empty.h index 8214b2b2f34..1aec3744f08 100644 --- a/clients/drcachesim/tools/external/example/empty.h +++ b/clients/drcachesim/tools/external/example/empty.h @@ -42,7 +42,7 @@ using dynamorio::drmemtrace::memref_t; class empty_t : public analysis_tool_t { public: - empty_t(unsigned int verbose); + explicit empty_t(unsigned int verbose); virtual ~empty_t(); std::string initialize() override; diff --git a/clients/drcachesim/tools/external/example/empty.templatex b/clients/drcachesim/tools/external/example/empty.templatex deleted file mode 100644 index 013568952a6..00000000000 --- a/clients/drcachesim/tools/external/example/empty.templatex +++ /dev/null @@ -1,2 +0,0 @@ -Empty tool created -Empty tool results: diff --git a/clients/drcachesim/tools/external/example/nonexistent.templatex b/clients/drcachesim/tools/external/example/nonexistent.templatex deleted file mode 100644 index 6e46d4a6d23..00000000000 --- a/clients/drcachesim/tools/external/example/nonexistent.templatex +++ /dev/null @@ -1,2 +0,0 @@ -Usage error: unsupported analyzer type "non-existent". Please choose cache, miss_analyzer, TLB, histogram, reuse_distance, basic_counts, opcode_mix, syscall_mix, view, func_view, or some external analyzer. -ERROR: failed to initialize analyzer: Failed to create analysis tool: \ No newline at end of file diff --git a/clients/drcachesim/tools/loader/external_tool_creator.h b/clients/drcachesim/tools/loader/external_tool_creator.h index b2e069d1640..cfdc19d3b28 100644 --- a/clients/drcachesim/tools/loader/external_tool_creator.h +++ b/clients/drcachesim/tools/loader/external_tool_creator.h @@ -51,7 +51,7 @@ class external_tool_creator_t : public dynamic_lib_t { analysis_tool_t * create_tool(); -public: +private: using get_tool_name_t = const char *(*)(); using create_tool_t = analysis_tool_t *(*)();