Upload
others
View
17
Download
0
Embed Size (px)
Citation preview
MiniTutorial: RTX
Debugging Applications Using Visual Studio
Copyright © 1996-2010 by IntervalZero Inc. All rights reserved.
No part of this document may be reproduced or transmitted in any form or by any means, graphic, electronic, or mechanical,including photocopying, and recording or by any information storage or retrieval system without the prior written permission ofIntervalZero Inc., unless such copying is expressly permitted by federal copyright law.
While every effort has been made to ensure the accuracy and completeness of all information in this document, IntervalZero Inc.assumes no liability to any party for any loss or damage caused by errors or omissions or by statements of any kind in this doc-ument, its updates, supplements, or special editions, whether such errors, omissions, or statements result from negligence, acci-dent, or any other cause. IntervalZero Inc. further assumes no liability arising out of the application or use of any product orsystem described herein; nor any liability for incidental or consequential damages arising from the use of this document. Inter-valZero Inc. disclaims all warranties regarding the information contained herein, whether expressed, implied or statutory, includ-ing implied warranties of merchantability or fitness for a particular purpose.
IntervalZero Inc. reserves the right to make changes to this document or to the products described herein without further notice.
IntervalZero RTX is a trademark of IntervalZero, Inc.
Microsoft, MS, and Win32 are registered trademarks and Windows 7, Windows Vista, Windows XP, Windows 2000 and Windows
Server 2003 are trademarks of Microsoft Corporation.
All other companies and product names may be trademarks or registered trademarks of their respective holders.
MiniTutorial: RTX - Debugging Applications Using Visual Studio
Document Number: DOC-RTX-011
March 2010
Overview
Overview
IntervalZero RTX applications can be debugged using the familiar Microsoft Visual Studiodevelopment environment. ThisMiniTutorial will show how to debug:
l A simple application
l An application using an RTDLL function library
To ensure you are running in a supported environment, please read the sectionPreparingyour RTX Environment in the document IntervalZero RTX®Quick Start Guide.
Running an RTSS Application in the Debugger
WhenReal-time Subsystem (RTSS) applications are debugged in the Visual Studio devel-opment environment, the RTX debugger plug-in ensures that the RTSS project will be underRTX control. RTSS applications are started by the RTX loader instead of theWindowsloader. For this reason, when debugging RTSS applications in Visual Studio, conditionalbreakpoints and the following options in theDebug pull-downmenu (which would assumeWindows control) are not supported:
l Start without debugging
l Attach to Process
l Detach All
Sample Programs
Program source code that will be used in debug exampleswill come from existing appli-cations found in the <RTXDIR>\samples directory, where the default location for<RTXDIR> is C:\Program Files\IntervalZero\RTX.
The Visual Studio 2008 Development Environment was used for the debug examples.
- 3 -
Simple Visual Studio Debug Session
Simple Visual Studio Debug Session
The following stepswill demonstrate a simple Visual Studio debug session, using one of theprovided RTX sample programs. Follow along to:
l Start Visual Studio and create a new project
l Build the project
l Perform simple debugging
Start Visual Studio and Create a New Project
To begin your debug session, start Microsoft Visual Studio.
To check if the add-in has successfully been installed, selectAdd-in Manager from theTools pull-downmenu and look forRTX Debugger Support (with a check in the box to theleft) in the list of available add-ins. Or, look for the RTX toolbar:
Start a new project by clicking
File → New→ Project
When the New Project wizard begins, selectRtx Application from the Visual C++ templates, name the projectRtxRespTime and select a location to store project files.
Note: The difference between the Rtx ApplicationWizard and Driver Wiz-ard is the source template that will be provided.
- 4 -
Start Visual Studio and Create a New Project
The RTX ApplicationWizard overview shows the initial default settings. Tomodify thesedefaults, clickNext.
- 5 -
Simple Visual Studio Debug Session
SelectMultithreaded C Run-time support to allow your application tomake supported CRuntime calls and then clickFinish.
Note:ClickingNextwill allow you to create a basic application framework,which is not necessary since existing sample programswill be used.
This session will use the existing SystemResponse TimeMeasurement (SRTM) programfound in <RTXDIR>/samples/srtm. Copy the Srtm.c source code file to the directorythat was just created for the project RtxRespTime. The files now in the project directoryshould look something like this:
- 6 -
Start Visual Studio and Create a New Project
Add the Srtm.c program to your project by right-clickingSource Files and selectingAdd→ Existing Item... from the pull-downmenu.
Browse to your new project directory and select the sample program that you recently copiedthere.
- 7 -
Simple Visual Studio Debug Session
Build the Project
When the RTX ApplicationWizard runs, it creates solution configurations to buildWin32executable files with and without debug symbols (Debug / Release) and RTSS executablefiles with and without debug symbols (RTSSDebug / RTSSRelease).
To build all executable files at once, select Batch Build... from theBuild pull-downmenu.
- 8 -
Build the Project
Check the boxes to the right of each solution configuration and then clickBuild orRebuild.
Build output will display in the Output window at the bottom of the screen. If the output win-dow is not visible, selectOutput from theView pull-downmenu.
- 9 -
Simple Visual Studio Debug Session
Perform Simple Debug
Open the source file that you will be debugging by double-clicking the file name.
Set the first breakpoint by double-clicking in the column to the left of the RtCreateTimerfunction call, or by right-clicking on the line and clickingBreakpoint → Insert Breakpoint inthe pop-upmenu.
Set a second breakpoint by double-clicking in the column to the left of the RtGet-ClockTime function call.
- 10 -
PerformSimple Debug
Select one of the available Solution Configurations from the short-cut menu, or by selectingConfiguration Manager from theBuild pull-downmenu. To debug theWin32 version ofthe program, set the solution configuration toDebug. To debug the RTSS version of the pro-gram, set the solution configuration toRTSSDebug.
To start debugging, select Start Debugging from theDebug pull-downmenu, or press theF5 key.
- 11 -
Simple Visual Studio Debug Session
The RTX Server console window will open and display text from the program and then thedebugger will stop the program at the first breakpoint.
To continue from the breakpoint, selectContinue from theDebug pull-downmenu or pressthe F5 key.
- 12 -
PerformSimple Debug
When the debugger stops at the second breakpoint, view variable values in the Autoswin-dow. If the debug windows are not visible, use theWindows option in theDebug pull-downmenu to display them. Press the F5 key to continue debugging.
While debugging, you can select toContinue or toStop Debugging from theDebug pull-downmenu. If you selectContinue, program execution will continue until it completes orreaches another breakpoint. If you select Stop, program execution will halt.
- 13 -
Simple Visual Studio Debug Session
After you have finished the debug session, you can close the RTX Server console window.
- 14 -
Visual Studio Debug of RTDLL
Visual Studio Debug of RTDLL
The following stepswill demonstrate a simple Visual Studio debug session, when the appli-cation uses an RTDLL. An RTDLL is not an RTSS process, so it can be debugged within theVisual Studio instance that is debugging your application.
This solution will use existing projects from the <RTXDIR>\samples directory, wherethe default location for <RTXDIR> is C:\Program Files\IntervalZero\RTX.
To debug an RTX application and an RTDLL, do the following:
l Start Visual Studio and Create an Empty Solution
l Add Projects to the Solution
l Build Projects in the Solution
l Register the RTDLL
l Debug the Program and RTDLL
- 15 -
Start Visual Studio and Create a New Solution
Start Visual Studio and Create a New Solution
To begin your debug session, start Microsoft Visual Studio and create a new project using:
File → New→ Project
- 16 -
Visual Studio Debug of RTDLL
When the New Project window appears, expandOther Project Types, clickVisual StudioSolutions and then selectBlank Solution. Name the projectRtxApp_wRTDLL and spec-ify the location that you will store project files.
Copy the .c program source and .vcproj project files from the <RTXDIR>/sa-mples/RTDLL directory to the directory location that you specified in the New Project Wiz-ard. After copying from the samples directory, files in the solution directory should includethose shown below:
- 17 -
Start Visual Studio and Create a New Solution
Add the RTDLL.vcproj and UsingRTDLL.vcproj project files to your solution by right-clicking the solution and selectingAdd → Existing Project... from the pull-downmenu.
Browse to your new project directory.
- 18 -
Visual Studio Debug of RTDLL
Select the RTDLL.vcproj project file that you recently copied from the RTX\samplesdirectory to your working directory location.
Repeat these steps (right-click solution, clickAdd → Existing Project and browse to yourworking directory) to select the UsingRTDLL.vcproj project file.
- 19 -
Build the Solution
You should now have a solution with the two projects you copied from the samples directory.
Build the Solution
When the projects were included in the solution, they included configurations to buildWin32executable files with, and without debug symbols (Debug / Release) and RTSS executablefiles with, and without debug symbols (RTSSDebug / RTSSRelease).
- 20 -
Visual Studio Debug of RTDLL
When the DLL is built as aWin32 library, it will have a .dll file extension.When it is built to runin the real-time subsystem, it will have a .RTDLL file extension. The programUsingRTDLL.c source file currently lists sampleRTDLL.dll (with the .dll extension) in itscall to LoadLibrary. This is correct for all configurations, as the Loadlibrary function call willload the correct dynamic library (DLL or RTDLL) based on the calling applicationWindows(exe) or Real-time ( RTSS).
- 21 -
Build the Solution
Right-click the projectUsingRTDLL and select for this to beSet as Startup Project.
- 22 -
Visual Studio Debug of RTDLL
SelectBatch Build from theBuild pull-downmenu.
Check theRTSSDebug solution configurations for both theSampleRTDLL andUsingRTDLL projects and then clickBuild orRebuild.
Output from the build will be shown in debugger Output window.
------ Build started: Project: SampleRTDLL, Configuration: RTSSDebug Win32 ------
Compiling...
sampleRTDLL.c
Linking...
Creating library C:\Samples\RTX\RtxApp_wRTDLL\RTSSDebug/SampleRTDLL.lib and object C:\Samples\RTX\RtxApp_wRTDLL\RTSSDebug/SampleRTDLL.exp
- 23 -
Build the Solution
Creating manifest...
Build log was saved at "file://c:\Samples\RTX\RtxApp_wRTDLL\RTSSDebug\BuildLog.htm"
SampleRTDLL - 0 error(s), 0 warning(s)
------ Build started: Project: UsingRTDLL, Configuration: RTSSDebug Win32 ------
Compiling...
usingRTDLL.c
Linking...
Creating manifest...
Build log was saved at "file://c:\Samples\RTX\RtxApp_wRTDLL\RTSSDebug\BuildLog.htm"
UsingRTDLL - 0 error(s), 0 warning(s)
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
The project RTSSDebug directory should now include the files shown below.
- 24 -
Visual Studio Debug of RTDLL
Register the RTDLL
Each time a new RTDLL is built (or changed) it must be registered. Register the RTDLLusing the RtssRun command or by starting the program:
IntervalZero → RTX 2009 → Tools → RtssRun
Browse to the location of the RTDLL that was just created, click theRegister RTDLL radiobutton and then clickOK.
- 25 -
PerformDebug of Program and RTDLL
To verify that the RTDLLwas registered, look for SampleRTDLL.RTDLL in the Rtss TaskManager by starting the program:
IntervalZero → RTX 2009 → Tools → Rtss Task Manager
Perform Debug of Program and RTDLL
To debug the program and RTDLL, ensure that the configuration is set to RTSSDebug.
Set the first breakpoint in program UsingRTDLL.c by double-clicking in the column to theleft of the RtCreateTimer function call or by right-clicking on the line and clickingBreak-point → Insert Breakpoint in the pop-upmenu.
- 26 -
Visual Studio Debug of RTDLL
Set a second breakpoint in program UsingRTDLL.c by double-clicking in the column to theleft of the call to function toggle (pointed to by FunctionPtr). This function is located in theRTDLL.
To start debugging, select Start Debugging from theDebug pull-downmenu, or press theF5 key.
- 27 -
PerformDebug of Program and RTDLL
If you get amessage asking if you would like to rebuild the SampleRTDLL clickNo. A rebuildis not necessary since there were no changes since the previous build.
The debugger will stop at the first breakpoint, pointed to by a yellow arrow in a red circle.
At the first breakpoint, clickModules at the bottom of the window. If symbols are not loadedfor either of themodules, right-click and select Load Symbols from the pull-downmenu.
Note: If Modules is not available from the status bar at the bottom of thewindow, selectModules from theWindows option in theDebug pull-downmenu to open themodules window.
Important: Visual Studio 2008 SP1 does not always load RTDLL symbolscorrectly. This is a known issue for RTX.
- 28 -
Visual Studio Debug of RTDLL
Locate the symbol file in the RTSSDebug subdirectory.
TheOutput window should now indicate that symbols are loaded.
- 29 -
PerformDebug of Program and RTDLL
To continue from the first breakpoint, selectContinue from theDebug pull-downmenu orpress the F5 key.
- 30 -
Visual Studio Debug of RTDLL
When the debugger stops at the second breakpoint, if this is the call to the toggle function,select Step Into or press the F11 key to step into the DLL function.
- 31 -
PerformDebug of Program and RTDLL
Focuswill now turn to the SampleRTDLL.c source code.
To continue, select Step Out from theDebug pull-downmenu or pressShift+F11.
- 32 -
Visual Studio Debug of RTDLL
When focus returns to the SampleRTDLL.c program, you can select toContinue or toStop Debugging from theDebug pull-downmenu. If you selectContinue, programexecution will continue until it completes or reaches another breakpoint. If you select Stop,program execution will halt.
Note: TheDetach All andAttach to Process options are not supportedfor programs running under RTSS control.
- 33 -
Resources
For more information, see theRT-TCP/IP section in theRTX SubsystemGuide and theNet-work section ofUnderstanding RTX Behavior in theRTX Application Guide. Also, visit theIntervalZero website at http://www.intervalzero.com/.
- 34 -