How to proceed when you want to debug RTC-Tools C++-code from within NGHS1.1 C#-code. This description is specific to that version of the code, since the exact details have changed over time (and probably will change again in the future). Please keep this document up to date when things change.

 

Prerequisites:

Install CMake, https://cmake.org

Install Visual Studio 2010, with the C++ compiler

Install depends (for troubleshooting), http://www.dependencywalker.com/ Install both versions (32bits and 64 bits), in separate directories. Use the one that matches the architecture of the dll or exe that you are troubleshooting.

Checkout code

Subversion:

https://repos.deltares.nl/repos/delft-tools/branches/nghs-1.1

https://svn.oss.deltares.nl/repos/rtc-tools/branches/RTC-Tools_1_4

Be sure to check that the version of the dll that is used by the NGHS-code (snv revision of file 'RTCTools_OpenMI' in location (1) ) matches the revision of the RTC-Tools checkout (by doing an 'update item to revision' on the RTC-Tools checkout, if needed).

(1)   The kernel exist at the following location in the repository:

<nghs1.1>\src\DeltaShell.Plugins.DelftModels.RealTimeControl\rtc_kernel\

(2)   The wrapper code exists at the following location in the repository:

<nghs1.1>\src\DeltaShell.Plugins.DelftModels.RealTimeControl\lib\

At the time of writing this document, the RTCTools_OpenMI.dll had no version number. If this gets fixed in the future, this version can be found in the file properties (right mouse button click on file, 'Properties', tab 'Details').

The steps I took now:

  1. right mouse button click on fRTCTools_OpenMI.dll, 'TortoiseSVN', 'SVN log'. This shows the following information 
  2. If you follow the links you will learn that the file is built the following teamcity configuration 
  3. If you check the settings of that configuration it shows that the subversion root is 
  4. Do the same for the other file (Deltares.RtcTools.Net.dll), and you'll learn that its root is the same

Build RTC-Tools on your machine:

Execute <rtctools>\oss\RTCTools\cmake\win32\builddebug.bat

You might need to edit the script to include the absolute path to cmake (if you have not added it to your path).

As a result of the previous step the file RTCTools.sln was created. Open this in VS2010.

Build the code there, in debug mode. This should not cause any issues.

Copy debug dll’s to nghs1.1 codebase:

The debug version of the RTCTools Dll's can be found in the following directory:

<rtctools>\oss\RTCTools\bin

Copy them to the correct location in the Delta Shell sources, which are (1) and (2).

Note that some files have the same name, but are bigger. This is because they are debug versions, but this is not reflected in their name.

 

The full path in the last screenshot is:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\

Add the files to the NGHS1.1 solution to make sure they get picked up during a build:

Open (1)\NGHS.sln, navigate to src, DeltaShell.Plugins.DelftModels.RealTimeControl, kernel and choose the option to show all files

right-click all the files that were copied in the previous step, include them in the project, and set the option 'Copy if newer'. This ensures the files are always copied to the debug location when the application is built.

Take care not to commit these changes by accident when you're done!

Set project properties to make sure the external code can be debugged:

The project from which you want to debug the C++-code needs to be setup to allow for this type of debugging.

If you want to debug from a unit test, right click the unit test's project, select properties, and enable the option 'Enable native code debugging' from the debug tab.

If you want to debug from within the gui, right click the startup project of the application (by default this is DeltaShell.NGHS.IO),  select properties, and enable the option 'Enable native code debugging' from the debug tab.

Open a RTCTools source file in the NGHS VIsual Studio environment:

In order to debug the RTCTools code, open the file where you want to set the breakpoint and add it. If you're not sure where to start, a logical choice is to open <rtctools>\oss\RTCTools\src\rtcToolsRuntime.cpp and add the breakpoint in its constructor.

Make sure you start in the right configuration (32 bits):

If you want to debug from within the gui, right click the startup project of the application (by default this is DeltaShell.NGHS.IO),  select properties, debug tab, and check the option 'Start external program', which should be

<nghs1.1>\bin\Debug\DeltaShell\DeltaShell.Gui.x86.exe

If you have a unit test you want to debug, right click its  unit test icon, right mouse click, and create a new unit test session for it . In the unit test session window, set the platform to x86 . Now if you debug the test you should hit the breakpoint in the RTCTools code.

Troubleshooting

If things do not go as planned, the following suggestions might help:

  • check if the engine is not running in a remote process (RealTimeControl.RunEngineRemote) in the NGHS1.1-code
  • check if the correct files are present in (1), but also in <nghs1.1>\bin\Debug\plugins\DeltaShell.Plugins.DelftModels.RealTimeControl\rtc_kernel\. The contents of these directories should be identical.
  • check if the correct files are present in (2), but also in <nghs1.1>\bin\Debug\plugins\DeltaShell.Plugins.DelftModels.RealTimeControl\. Files that exist in both directories should be identical.
  • check if all the dependencies of RTCTools_OpenMI.dll are present by opening the file in the 32bit version of DependencyWalker. If dll's are missng, copy them next to the RTCTools_OpenMI.dll
  • In resharper's unit test settings, make sure the option 'Shadow-copy assemblies being tested' is turned off.

 

 

 

  • No labels