MiniTutorial:Debugging ApplicationsUsingVisual Studio · 2017. 7. 6. · IZ-DOC-X86-0013...
Transcript of MiniTutorial:Debugging ApplicationsUsingVisual Studio · 2017. 7. 6. · IZ-DOC-X86-0013...
_______________________________________________________________________________________
MiniTutorial: DebuggingApplications Using Visual
Studio
Copyright © 1996-2011 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 and Windows Server 2003 aretrademarks of Microsoft Corporation.
All other companies and product names may be trademarks or registered trademarks of their respective holders.
MiniTutorial: Debugging Applications Using Visual Studio
Document Number: IZ-DOC-X86-0013
January 2011
IZ-DOC-X86-0013 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 DebuggerWhenReal-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 ProgramsProgram source code that will be used in debug exampleswill come from existing appli-cations found in the RTX samples directory. The default location for the RTX samples is:
C:\ProgramData\RTX\samples
The Visual Studio 2010 Development Environment was used for the debug examples.
Real-Time SubsystemBefore running or debugging any of the programs, ensure that the real-time subsystem is upby checking theControl tab in the RTX properties control panel.
3
Simple Visual Studio Debug Session IZ-DOC-X86-0013
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 ProjectTo 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 VisualC++ 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
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
TheRTX ApplicationWizard overview shows the initial default settings. Tomodify thesedefaults, clickNext.
SelectMultithreaded C Run-time support to allow your application tomake supported CRuntime calls and then clickFinish.
Note: Clicking Next will allow you to create a basic application framework,which is not necessary since existing sample programswill be used.
5
Simple Visual Studio Debug Session IZ-DOC-X86-0013
This session will use the existing SystemResponse TimeMeasurement (SRTM) programfound in the RTX samples directory.
6
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
Copy the Srtm.c source code file to the directory that was just created for the projectRtxRespTime. The files now in the project directory should look something like this:
Add the Srtm.c program to your project by right-clickingSource Files and selectingAdd→ Existing Item... from the pull-downmenu.
7
Simple Visual Studio Debug Session IZ-DOC-X86-0013
Browse to your new project directory, select the sample program that you recently copiedthere and clickAdd.
Build the ProjectWhen 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). These solution con-figurations can be see in the pull-downmenu.
8
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
To build all executable files at once, selectBatch Build... from theBuild pull-downmenu.
Select 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.
------ Rebuild All started: Project: RtxRespTime, Configuration: RTSSRelease Win32 ------Build started 12/20/2010 2:54:27 PM.InitializeBuildStatus:Creating "RTSSRelease\RtxRespTime.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:Srtm.c
Link:RtxRespTime.vcxproj -> C:\Samples\RTX\RtxRespTime\RTSSRelease\RtxRespTime.rtss
FinalizeBuildStatus:Deleting file "RTSSRelease\RtxRespTime.unsuccessfulbuild".Touching "RTSSRelease\RtxRespTime.lastbuildstate".
Build succeeded.
9
Simple Visual Studio Debug Session IZ-DOC-X86-0013
Time Elapsed 00:00:04.41------ Rebuild All started: Project: RtxRespTime, Configuration: RTSSDebug Win32 ------Build started 12/20/2010 2:54:32 PM.InitializeBuildStatus:Creating "RTSSDebug\RtxRespTime.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:Srtm.c
Link:RtxRespTime.vcxproj -> C:\Samples\RTX\RtxRespTime\RTSSDebug\RtxRespTime.rtss
FinalizeBuildStatus:Deleting file "RTSSDebug\RtxRespTime.unsuccessfulbuild".Touching "RTSSDebug\RtxRespTime.lastbuildstate".
Build succeeded.
Time Elapsed 00:00:01.85------ Rebuild All started: Project: RtxRespTime, Configuration: Release Win32 ------Build started 12/20/2010 2:54:34 PM.InitializeBuildStatus:Creating "Release\RtxRespTime.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:Srtm.c
Link:RtxRespTime.vcxproj -> C:\Samples\RTX\RtxRespTime\Release\RtxRespTime.exe
FinalizeBuildStatus:Deleting file "Release\RtxRespTime.unsuccessfulbuild".Touching "Release\RtxRespTime.lastbuildstate".
Build succeeded.
Time Elapsed 00:00:04.76------ Rebuild All started: Project: RtxRespTime, Configuration: Debug Win32 ------Build started 12/20/2010 2:54:39 PM.InitializeBuildStatus:Creating "Debug\RtxRespTime.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:Srtm.c
Link:RtxRespTime.vcxproj -> C:\Samples\RTX\RtxRespTime\Debug\RtxRespTime.exe
FinalizeBuildStatus:Deleting file "Debug\RtxRespTime.unsuccessfulbuild".Touching "Debug\RtxRespTime.lastbuildstate".
Build succeeded.
Time Elapsed 00:00:02.30========== Rebuild All: 4 succeeded, 0 failed, 0 skipped ==========
10
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
Perform Simple DebugOpen the source file that you will be debugging by right-clicking the file name and selectingOpen from the pull-downmenu, or 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.
11
Simple Visual Studio Debug Session IZ-DOC-X86-0013
Set a second breakpoint by double-clicking in the column to the left of the RtGet-ClockTime function call.
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, selectStart Debugging from theDebug pull-downmenu, or press theF5 key.
12
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
TheRTX 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.
13
Simple Visual Studio Debug Session IZ-DOC-X86-0013
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 selectStop, program execution will halt.
14
IZ-DOC-X86-0013 Simple Visual Studio Debug Session
After you have finished the debug session, you can close the RTX Server console window.
15
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
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 samples directory (listed in theOverview at thestart of this document).
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 andRTDLL
Start Visual Studio and Create a New SolutionTo begin your debug session, start Microsoft Visual Studio and create a new project using:
File > New > Project
16
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
When the New Project window appears, expandOther Project Types, clickVisual StudioSolutions and then selectBlank Solution. Name the projectRtxApp_wRTDLL, specifythe location that you will store project files and then clickOK.
You should now have a blank solution called RtxApp_wRtDll. Begin creating a newproject that will contain the RTDLL by right-clicking the solution name and selecting
Add > New Project
17
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
In the Add New Project window, select theVisual C++ > Rtx Application template. Givethe project a name, ensure it uses the same directory as the solution and then clickOK.
ClickNext in theWelcomewindow.
18
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
To build an RTDLL, select RTX DLL, add C Runtime support and then click Finish.
Locate the sample program sampleRtdll.c.
19
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
Copy the sampleRtdll.c program to the new RTDLL project directory.
Return to Visual Studio and add the sample program by right-clicking the SampleRtDllprojectSource Files and selectingAdd > Existing Item from the pull-downmenu.
20
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
Browse to the SampleRtDll project directory, select the sampleRtdll.c program and clickAdd.
Create a project for the application that will use the DLL by right-clicking theRtxApp_wRtDll solution name and selectingAdd > New Project from the pull-downmenu.
Select theVisual C++ > Rtx Application template, name the new project UsingRtDll,ensure it is using the same directory as your solution and then clickOK.
21
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
In the RTX ApplicationWizardWelcomewindow, clickNext.
In the RTX ApplicationWizard Application Settingswindow, selectRTX application andCRuntime support and then clickFinish.
22
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
Locate the usingRtdll.c program in the RTX samples directory.
Copy the usingRtdll.c program to your new project directory.
23
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
Return to Visual Studio and add the sample program by right-clicking the UsingRtDll projectSource Files and selectingAdd > Existing Item from the pull-downmenu.
24
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
Browse to the UsingRtDll project directory, select the usingRtdll.c program and clickAdd.
25
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
You should now have a solution with the two projects you created. The SampleRtDll projectwill create an RTDLL and the UsingRtDll project will use the RTDLL.
Program and DLL InteractionThe sample DLL can be built to run under Windows or RTX.When the DLL is built as aWin32 library, it will have a .DLL file extension.When it is built to run in the real-time sub-system, it will have a .RTDLL file extension. The program UsingRTDLL.c source file cur-rently lists sampleRTDLL.dll (with the .dll extension) in its call to LoadLibrary. This iscorrect for all configurations, as the RTX Loadlibrary function call will load the correctdynamic library (DLL or RTDLL) based on the calling applicationWindows (exe) or Real-time ( RTSS).
26
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
When the solution is built, the program that will use the DLL should startup when debuggingbegins. Ensure this is the case by right-clicking theUsingRtDll project and selectingSet asStartUp Project from the pull-downmenu.
27
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
Build the SolutionWhen the projects were created using the RTX wizards, four solution configurationsweredefined for each project. They allow the creation ofWin32 executable files with, and withoutdebug symbols (Debug / Release) and RTSS executable files with, and without debug sym-bols (RTSSDebug / RTSSRelease).
To select which configuration will be built, selectBatch Build from theBuild pull-downmenu.
This tutorial will only use the RTSSDebug configurations. You can check only SampleRtDllRTSSDebug configuration and UsingRtDll RTSSDebug configuration, or select all con-figurations. After configuration options have been selected, click Build orRebuild.
28
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
Output from the build will be displayed in the debugger Output window.
The solution directory will now have executable files for each of the projects.
29
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
Register the RTDLLEach 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 2011 > Tools > RtssRun
Browse to the location of the RTDLL that was just created, click theRegister RTDLL radiobutton and then clickOK.
30
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
To verify that the RTDLLwas registered, look for SampleRTDLL.RTDLL in the RTSS TaskManager by starting the program:
IntervalZero > RTX 2011 > Tools > RTSS Task Manager
Perform Debug of Program and RTDLLTo debug the program andRTDLL, 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.
31
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
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, selectStart Debugging from theDebug pull-downmenu, or press theF5 key.
32
IZ-DOC-X86-0013 Visual Studio Debug of 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, select Modules from theWindows option in the Debug pull-downmenu to open themoduleswindow.
Important: Visual Studio 2008 SP1 does not always load RTDLL symbolscorrectly. This is a known issue for RTX.
33
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
If necessary, locate the symbol file in the RTSSDebug subdirectory.
TheOutput window should now indicate that symbols are loaded.
To continue from the first breakpoint, selectContinue from theDebug pull-downmenu orpress the F5 key.
34
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
When the debugger stops at the second breakpoint, if this is the call to the toggle function,selectStep Into or press the F11 key to step into the DLL function.
35
Visual Studio Debug of RTDLL IZ-DOC-X86-0013
Focuswill now turn to the SampleRTDLL.c source code.
To continue, selectStep Out from theDebug pull-downmenu or pressShift+F11.
When focus returns to the SampleRTDLL.c program, you can select toContinue or toStop Debugging from theDebug pull-downmenu. If you selectContinue, program
36
IZ-DOC-X86-0013 Visual Studio Debug of RTDLL
execution will continue until it completes or reaches another breakpoint. If you selectStop,program execution will halt.
Note: The Detach All and Attach to Process options are not supportedfor programs running under RTSS control.
37
Resources IZ-DOC-X86-0013
Resources
For more information, visit the IntervalZero website at http://www.intervalzero.com/.
38