Customizing the tracer

38 views
Skip to first unread message

Reza Ghanbari

unread,
Apr 29, 2025, 12:42:06 PMApr 29
to DynamoRIO Users
Hi, I am trying to implement a tracer that in addition to the memory tracer logs the memory ranges allocated by malloc/new. I was wondering if I can use drmemtrace for that purpose and add malloc/new tracing functionality on top of that.

I have tried implementing the new tracer as described here but I get compile errors saying the client cannot find the definition of  drmemtrace_client_main() symbol. Here is the minial source code and CMakeLists.txt content that I am using:

client.cpp:
#include "dr_api.h"
#include "drmemtrace/drmemtrace.h"

 
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dynamorio::drmemtrace::drmemtrace_client_main(id, argc, argv);
}



and CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(MemoryTracerClient)

set(DynamoRIO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dynamorio/install/cmake")
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -g")

find_package(DynamoRIO)
if (NOT DynamoRIO_FOUND)
  message(FATAL_ERROR "DynamoRIO package required to build")
endif(NOT DynamoRIO_FOUND)

configure_DynamoRIO_global(ON ON)

set(name "memtrace_client")

function (add_client name source_file_list extension_list)
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/dynamorio/install/tools/lib64/release")
  use_DynamoRIO_drmemtrace_tracer(${name})
  add_library(${name} SHARED ${source_file_list})
  configure_DynamoRIO_client(${name})
  foreach (ext ${extension_list})
    use_DynamoRIO_extension(${name} ${ext})
  endforeach (ext)
endfunction (add_client)

dd_client(memtrace_client "client.cpp" "")

Enrico Deiana

unread,
Apr 29, 2025, 3:10:24 PMApr 29
to DynamoRIO Users
It looks like what you're trying to achieve can be done by the (already present) function tracing feature in DynamoRIO's tracer, which allows you to record arguments and return values of functions (you can deduce the memory ranges from that).
Also, there is already a utility flag: `-record_heap` that conveniently records functions related to heap allocations (not just malloc/new), which can be further controlled via `-record_heap_value` (more info on those options at: https://dynamorio.org/sec_drcachesim_ops.html).
Then you'd only need a custom trace analyzer tool to extract and compose whatever information you need.

If you think you still need to build your custom tracer, please post the full error you're getting.

- Enrico

Reza Ghanbari

unread,
Apr 30, 2025, 11:10:35 AMApr 30
to DynamoRIO Users
Hi Enrico, Thank you for your help and your suggestions about the func_view and function tracing, I have looked into it but unfortunately it does not provide all the information I need;
Here is the error that I get (by the way it is actually a run-time error not a compile-time one):

Error: Something went wrong!
<ERROR: using undefined symbol!>

running with gdb it says that the  drmemtrace_client_main() symbol is undefined.
Also, here is the script I use to run the tool:

LIB_BUILD=/PATH-TO-CMAKE-FILE/build
cmake -B $LIB_BUILD
cd $LIB_BUILD
make
cd ..
./dynamorio/build/bin64/drrun -c $LIB_BUILD/libmemtrace_client.so -- ./test/test_prog
the 'test_prog' could be anything, in my case it is a simple HelloWorld C code.

Derek Bruening

unread,
Apr 30, 2025, 3:45:10 PMApr 30
to Reza Ghanbari, DynamoRIO Users
Please see the documentation which provides command lines for running the drmemtrace tracer.
Generally offline mode is recommended to allow repeated analyses, so from https://dynamorio.org/sec_drcachesim_offline.html you would run:

$ bin64/drrun -t drmemtrace -offline -record_heap -- ./test/test_prog


--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/dynamorio-users/dae5f01c-186d-48a7-86c6-813c922eaef4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages