Here's a transcript:
This silent video covers 3 tips on source-code level debugging a model-driven Rhapsody application with the Visual Studio IDE.
Many thanks to Hartmut W @ BTC (maker of Rhp TestConductor add-on) for a couple of advanced tips.
This model has a configuration with animation enabled. We can generate and build the code from Rhapsody (model-driven). I've modified Rhapsody 8.4's MSVC environment to use the Visual Studio 2019 compiler here but these tips apply equally to earlier versions. This results in an exe. With animation enabled, it talks back to Rhapsody via a port so that you can interact with it, e.g., in a panel or animated statechart. This is model-level debugging and can help correct "the bigger picture". Often, however, we also want to step through and debug at code-level. Well, this is surprising easy to do with Visual Studio ;-)
Suppose, for example, we want to set a code-level break point in this transition? Firstly, we open up the Visual Studio IDE. Choose to open a project or solution, and browse to select the executable (.exe) that Rhapsody generated. Now, open up the source file, e.g., .cpp, that you want to step through in Visual Studio. This is the folder where the source code is generated by Rhapsody for this configuration. We can now locate where we want to set the breakpoint and set a breakpoint in the code (e.g. F9).
Now, when we run the .exe from Visual Studio, it will break when it gets to this line. Voilà !! We can now debug at code level.
Oh dear, we've stepped into a Framework (OxF) class here. Time for the second tip!
The application object files are linked with a library that contains base classes for many elements such as statecharts, events and threads. This is known as the OxF (Object eXecution Framwork). The OxF model/code/libraries are in the installation OMROOT/Share folder. To step through OxF code we need to recompile it with a change to one of the switches. Locate the config's CPP_CG::MSVC::buildFrameworkCommand property and change USE_PDB=FALSE to USE_PDB=TRUE. Choose Code > Build Framework to rebuild the OxF libraries using the active configuration's settings. This may take a couple of minutes.
Let's rebuild and link the application now. We can now debug again using the new PDB info available for the OxF. We're now able to step into the source code that is part of the OxF framework. e.g. OMReactive is the base class for classifiers that have statecharts and OMThread is the base class that iterates over the event queue. We can also set breakpoints in the Framework code (if we want).
Time for the final tip! With Visual Studio Professional we can also set breakpoints programmatically in Rhapsody. To programmatically add a breakpoint, we first add crtdbg.h to the config's include or additional sources path. We can now add a _CrtDbgBreak(); directly into code in the model.
Optionally, if we run from Rhapsody then we could Attach to Process... in Visual Studio. However, I first want to remove all non-programmatic breakpoints. Visual Studio will break itself when it gets to the _CrtDbgBreak(); in the code. Ta-dah! ;-)
That's it then, 3 tips for source-level debugging Rhapsody applications using Visual Studio:
1. Open .exe/source files and run from VS
2. Recompile OXF with USE_PDB=TRUE to code-level debug framework (optional)
3. Using programmatic breakpoints by including crtdbg.h and using _CrtDbgBreak(); (requires VS Pro)
Post a Comment
Note: only a member of this blog may post a comment.