-
Notifications
You must be signed in to change notification settings - Fork 142
Debugging TinyTracer
In order to debug TinyTracer with VisualStudio, we need to first compile it in a Debug mode.
Then we need to copy the compiled modules into the install32_64 directory, as in the following script:
rem First, compile the 32 and 64 bit version of TinyTracer (in a Debug mode). Then, you can use this script to copy them into the directory with the run_me.bat (default: install32_64).
set INSTALL_DIR=install32_64
move Debug\TinyTracer.dll %INSTALL_DIR%\TinyTracer32.dll
move x64\Debug\TinyTracer.dll %INSTALL_DIR%\TinyTracer64.dll
pause
After that, we need to modify the script to run the TinyTracer (run_me.bat) to add there additional time before the execution is started.
We do it by adding to the Pin the parameter -pause_tool [seconds_to_wait]
. Example:
set DLL_CMD=%PIN_DIR%\pin.exe -pause_tool 30 -t %PINTOOL% -m "%TRACED_MODULE%" -o %TAG_FILE% -s %SETTINGS_FILE% -b "%WATCH_BEFORE%" -x "%EXCLUDED_FUNC%" -p "%STOP_OFFSETS%" -l "%SYSCALLS_TABLE%" -- "%DLL_LOAD%" "%TARGET_APP%" %DLL_EXPORTS%
set EXE_CMD=%PIN_DIR%\pin.exe -pause_tool 30 -t %PINTOOL% -m "%TRACED_MODULE%" -o %TAG_FILE% -s %SETTINGS_FILE% -b "%WATCH_BEFORE%" -x "%EXCLUDED_FUNC%" -p "%STOP_OFFSETS%" -l "%SYSCALLS_TABLE%" -- "%TARGET_APP%" %EXE_ARGS%
Now we are ready to run our traced application, and attach the Visual Studio Debugger to it.
Let's open the source to TinyTracer project in Visual Studio, and get ready.
Now we can run an executable that we want to trace. Let's do it in the usual way, using the context menu. Since we modified the run script, the tracing won't start immediately, but wait the specified time.
This is the time to connect the Visual Studio Debugger. We should do it from the same Visual Studio instance where we opened the source. From the "Debug" menu we select "Attach to Process", and choose our traced application. The debugger attached, and we should see a new window, "Output". We will see there various logs. It should contain the line:
[name of our target exe] : Loaded 'C:\pin\source\tools\tiny_tracer\install32_64\TinyTracer32.dll'. Symbols loaded.
It is now possible to set breakpoints in Pin tool.
Use "Go" command (F5) to proceed.
As the line states at this point we can already set the breakpoints that will be further hit. We do it on the Tiny Tracer source that we have previously opened.
After setting the breakpoints, we press F5 (or, click "Continue") and the application will resume. The breakpoints that we set on Tiny Tracer source will be triggered, and we can watch their execution context.