This tutorial assumes that you are familiar with basic use of IAR Embedded Workbench; see the tutorial Getting Started using IAR Embedded Workbench.It defines a class Fibonacci that can be used for extracting a series of Fibonacci numbers. The result is printed on stdout.Creates fib objects from the class Fibonacci and manipulates them before it extracts three sequences of Fibonacci numbers using the Fibonacci class.
1 In the IDE, if Information Center is not open, choose Help>Information Center.
2 Click the Product explorer symbol.
3 Under the Language support heading, click Open the tutorial workspace. Choose a destination for your project in the browse dialog box that appears. We recommend that you create a specific directory (with a subdirectory) where you store all your tutorial files, if you have not done that already. In this tutorial we call the directory MyTutorials and the subdirectory LanguageSupport.After you have chosen a destination directory, the LanguageSupport workspace is opened in the IDE.
4 In the Workspace window, select the UsingAndDebuggingCpp project, right-click and choose Set as Active.The UsingAndDebuggingCpp project is preconfigured with appropriate option settings for this tutorial. However, this procedure guides you through the options required for this tutorial.
1 In the Workspace window, select UsingAndDebuggingCpp - Debug, right-click, and choose Options from the context menu.
C++ dialect (Only for some products) Extended Embedded C++ (only for some products) C++ might require some extra heap; for information about any settings required for heap usage, see the header of the UsingClasses.cpp file.
3 Click OK.
4 Choose Project>Make to compile and link your application.Static objects are created before main. In C++ there are constructors which are executed when the object is created. Thus, constructors for static objects are executed before main.
1
2 To be able to monitor the construction, set a breakpoint on cout << "A Fibonacci object that starts at Fibonacci number " which you find in the file FibonacciByClass.h.
3 Stopping execution before main means that the option setting Run to main is disabled. Therefore, you should also set a breakpoint close to main, for example on Fibonacci fib1; in the file UsingClasses.cpp.
4 Choose Project>Download and Debug to start C-SPY.
6 Click the Go button () to resume the execution.
8
1 Step until you reach fib1 = 1;.
The Fibonacci destructor.
2 Choose View>Call Stack. This window shows the chain of function calls. At the top line you can see that Fibonacci:Fibonacci(unsigned int) is the first of the three functions to be called.
3 There are various step commands to choose between to continue executing your application, for example Step Into and Step Over. However, because you in this case want to track the program flow on function call level, the best command to use is Step Over because this will take you directly to the next function call (in contrast to Step Into which will step into the function).
4 Click Step Over again and notice that the next call now is the final of the three calls, in other words Fibonacci::~Fibonacci().It can be interesting to backtrace the function calls a few levels down and examine the value of the parameter for each function call. In this example procedure you will locate the function nth and monitor parts of its call chain.
1 A couple of rows further down (still in UsingClasses.cpp), select fib1.next(), right-click, and choose Toggle Breakpoint (Code) from the context menu.
2 Click Go (); the execution stops at the breakpoint.
3
4 To locate the function nth, click Go to function () in the upper right corner of the editor window and choose nth.
5
6 Click Go () repeatedly to execute the application until the breakpoint is triggered.
7 In the Call Stack window, right-click and choose Show Arguments from the context menu. You can now see an instance of the function nth displayed on the call stack.Click Go () a few times. Because the Call Stack window displays the values of the function parameters, you can see the different values of n in the different function instances.In C-SPY, you can view the contents of STL containers (like for example msFib, which is a vector) in the same way as arrays.
1 Choose View>Watch>Watch 1.
2
1