DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.63k stars 557 forks source link

Support attach with a tool that uses its own launcher #5480

Open derekbruening opened 2 years ago

derekbruening commented 2 years ago

Attach with a tool config file that simply points at a client lib works:

$ bin64/drrun -v -attach $(pgrep bc) -t drcov

However, a tool config file that provides its own launcher does not work and is misleading as it will do nothing:

$ bin64/drrun -v -attach $(pgrep bc) -t drcachesim -offline -verbose 1
INFO: reading tool config file /home/bruening/dr/git/build_x64_dbg_tests/bin64/../tools/drcachesim.drrun64
INFO: client 0 path: /home/bruening/dr/git/build_x64_dbg_tests/bin64/../clients/lib64/debug/libdrmemtrace.so
INFO: client 1 path: /home/bruening/dr/git/build_x64_dbg_tests/bin64/../clients/lib32/debug/libdrmemtrace.so
INFO: app cmdline: /home/bruening/dr/git/build_x64_dbg_tests/bin64/..
INFO: native tool cmdline:  "/home/bruening/dr/git/build_x64_dbg_tests/bin64/../clients/bin64/drcachesim" "-dr" "/home/bruening/dr/git/build_x64_dbg_tests/bin64/.." "-dr_ops" "" "-tracer" "/home/bruening/dr/git/build_x64_dbg_tests/bin64/../clients/lib64/debug/libdrmemtrace.so" "-tracer_alt" "/home/bruening/dr/git/build_x64_dbg_tests/bin64/../clients/lib32/debug/libdrmemtrace.so" "-dr_debug" "-offline" "-verbose" "1" "--"
INFO: debug build directory detected: switching to debug build
INFO: configuration directory is "/home/bruening/.dynamorio"
INFO: using ptrace to inject
INFO: waiting forever for app to exit...

For offline the drcachesim launcher is not needed so this is a workaround for offline drmemtrace:

$ bin64/drrun -v -attach $(pgrep bc) -c clients/lib64/debug/libdrmemtrace.so -offline -verbose 1

But for online drcachesim, or for Dr. Memory, or other cases where the launcher is required: how to support attach? Each launcher has to include code to use dr_inject_prepare_to_ptrace, dr_inject_prepare_to_attach, dr_inject_process_attach, or whatnot, duplicating whatever drrun is doing?

derekbruening commented 2 years ago

A first step would be to at least give an error message in drrun today if attach is requested with a native launcher (though I guess a 3rd party launcher could actually support attach...but right now drrun is not propagated the attach option nor pid arg).