i#725: Re-expose the Windows detach in drconfig (#6205)

The old way to trigger detach on the Windows platform is the
no-longer-supported "drcontrol" front-end.
Re-exposing the detach feature in drconfig front-end on the Windows
platform.

The following briefly describes my manual testing process, and I'll
continue to submit an automated testing tool in a new PR soon.


I wrote my own continuously running example as a manual test case for
DynamoRIO, which counts the time of summing the first 1 billion numbers
in real time. I'd like to use the real-time output of the test case to
present the running state of the program.
```
#include <iostream>
#include <chrono>
#define LOOPCOUNT 100000;
// Function to perform a computationally intensive task
void performTask()
{
    //calculate the sum of the first 1 billion numbers
    long long unsigned sum = 0;
    for (int i = 1; i <= 1000000000; ++i)
    {
            sum += i;
    }
    std::cout << "The sum of the first 1 billion numbers: " << sum << std::endl;
}
void single_loop() {
    // Start the timer
    auto start = std::chrono::high_resolution_clock::now();
    // Perform the computationally intensive task
    performTask();
    // Stop the timer
    auto end = std::chrono::high_resolution_clock::now();
    // Calculate the elapsed time
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
    // Print the elapsed time
    std::cout << "Elapsed time: " << duration.count() << " milliseconds" << std::endl;
}
int main()
{
    int counts = LOOPCOUNT;
    for (int i = 0; i < counts;i++)
    {
        single_loop();
    }
    return 0;
}
```
Here are the steps to perform a manual test:

1. Execute our test case: ./SumOneBillion.exe
2. Use the "ps" command to get the target process ID: ps | grep
SumOneBillion
3. Use "-attach" option to instrument the target process ID: .\drrun.exe
-attach pid -c64 D:\dynamorio\build_debug\api\bin\inscount.dll
4. Use "-detach" option to stop the instrumentation:.\drconfig.exe
-detach pid

The output of the test case and the DynamoRIO in debug version is like
following.


> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 192 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 191 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 191 milliseconds
**> <Starting application
D:\vs_demos_repos\SumOneBillion\x64\Release\SumOneBillion.exe (16300)>
> <cannot remove dll from rbtree: at root/min + can't find real tree>
> <Running on newer-than-this-build "Microsoft Windows 10-2009 x64">
> <Early threads found>
> <Initial options = -no_dynamic_options -client_lib
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -client_lib64
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -code_api -probe_api
-stack_size 56K -max_elide_jmp 0 -max_elide_call 0
-no_inline_ignored_syscalls -native_exec_default_list ''
-no_native_exec_managed_code -skip_terminating_threads
-no_indcall2direct >
> Client inscount is running**
> <CURIOSITY : instr_get_opcode(instr_new) !=
instr_get_opcode(instr_old) in file
D:\DynamoRIODetach\dynamorio-master\core\win32\callback.c line 2079
> version 9.93.19549, custom build
> -no_dynamic_options -client_lib
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -client_lib64
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -code_api -probe_api
-stack_size 56K -max_elide_jmp 0 -max_elide_call 0
-no_inline_ignored_syscalls -native_exec_default_list ''
> D:\dynamorio\build_debug\lib64\debug\dynamorio.dll=0x0000000015000000
> D:\dynamorio\build_debug\api\bin\inscount.dll=0x00007ff721f90000
> C:\WINDOWS/system32/KERNEL32.dll=0x0000026257e00000
> C:\WINDOWS/system32/KERNELBASE.dll=0x0000026257f40000
> D:\dynamorio\build_debug\ext\lib64\debug/drmgr.dll=0x00007ff721ff0000>
> <CURIOSITY : instr_new == instrlist_first(ilist) || instr_new ==
instr_get_next(instrlist_first(ilist)) in file
D:\dynamorio\core\win32\callback.c line 2082
> version 9.93.19549, custom build
> -no_dynamic_options -client_lib
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -client_lib64
'D:\dynamorio\build_debug\api\bin\inscount.dll;0;' -code_api -probe_api
-stack_size 56K -max_elide_jmp 0 -max_elide_call 0
-no_inline_ignored_syscalls -native_exec_default_list ''
> D:\dynamorio\build_debug\lib64\debug\dynamorio.dll=0x0000000015000000
> D:\dynamorio\build_debug\api\bin\inscount.dll=0x00007ff721f90000
> C:\WINDOWS/system32/KERNEL32.dll=0x0000026257e00000
> C:\WINDOWS/system32/KERNELBASE.dll=0x0000026257f40000
> D:\dynamorio\build_debug\ext\lib64\debug/drmgr.dll=0x00007ff721ff0000>
> <Cleaning hooked Nt wrapper @0x00007ffeba790800 sysnum=0x1c2>
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 417 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 552 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 545 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 537 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 543 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 539 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 538 milliseconds
**> <curiosity: rex.w on OPSZ_6_irex10_short4!>
> <received nudge mask=0x4 id=0x00000000 arg=0x0000000000000000>
> <Detaching from application
D:\vs_demos_repos\SumOneBillion\x64\Release\SumOneBillion.exe (16300)>
> <Detaching from process, entering final cleanup>
> Instrumentation results: 20766267822 instructions executed**
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 194 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 194 milliseconds
> The sum of the first 1 billion numbers: 500000000500000000
> Elapsed time: 194 milliseconds
> 

Issue: [#725](https://github.com/DynamoRIO/dynamorio/issues/725)
1 file changed
tree: f31193728b7888c9f3b4134916f2e932f5cef98b
  1. .github/
  2. api/
  3. clients/
  4. core/
  5. ext/
  6. libutil/
  7. make/
  8. suite/
  9. third_party/
  10. tools/
  11. .clang-format
  12. .gitignore
  13. .gitmodules
  14. ACKNOWLEDGEMENTS
  15. CMakeLists.txt
  16. CONTRIBUTING.md
  17. CTestConfig.cmake
  18. License.txt
  19. README
  20. README.md
README.md

DynamoRIO

DynamoRIO logo

About DynamoRIO

DynamoRIO is a runtime code manipulation system that supports code transformations on any part of a program, while it executes. DynamoRIO exports an interface for building dynamic tools for a wide variety of uses: program analysis and understanding, profiling, instrumentation, optimization, translation, etc. Unlike many dynamic tool systems, DynamoRIO is not limited to insertion of callouts/trampolines and allows arbitrary modifications to application instructions via a powerful IA-32/AMD64/ARM/AArch64 instruction manipulation library. DynamoRIO provides efficient, transparent, and comprehensive manipulation of unmodified applications running on stock operating systems (Windows, Linux, or Android) and commodity IA-32, AMD64, ARM, and AArch64 hardware. Mac OSX support is in progress.

Existing DynamoRIO-based tools

DynamoRIO is the basis for some well-known external tools:

Tools built on DynamoRIO and available in the release package include:

  • The memory debugging tool Dr. Memory
  • The tracing and analysis framework drmemtrace with multiple tools that operate on both online (with multi-process support) and offline instruction and memory address traces:
  • The legacy processor emulator drcpusim
  • The “strace for Windows” tool drstrace
  • The code coverage tool drcov
  • The library tracing tool drltrace
  • The memory address tracing tool memtrace (drmemtrace's offline traces are faster with more surrounding infrastructure, but this is a simpler starting point for customized memory address tracing)
  • The memory value tracing tool memval
  • The instruction tracing tool instrace (drmemtrace's offline traces are faster with more surrounding infrastructure, but this is a simpler starting point for customized instruction tracing)
  • The basic block tracing tool bbbuf
  • The instruction counting tool inscount
  • The dynamic fuzz testing tool Dr. Fuzz
  • The disassembly tool drdisas
  • And more, including opcode counts, branch instrumentation, etc.: see API samples

Building your own custom tools

DynamoRIO‘s powerful API abstracts away the details of the underlying infrastructure and allows the tool builder to concentrate on analyzing or modifying the application’s runtime code stream. API documentation is included in the release package and can also be browsed online. Slides from our past tutorials are also available.

Downloading DynamoRIO

DynamoRIO is available free of charge as a binary package for both Windows and Linux. DynamoRIO's source code is available primarily under a BSD license.

Obtaining Help

Use the discussion list to ask questions.

To report a bug, use the issue tracker.

See also the DynamoRIO home page: http://dynamorio.org/