JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3 IDE Quick Start Tutorial     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Creating Projects

Creating an Application Project

Switching Between the Logical View and the Physical View of the Project

Adding Files and Folders to Your Project

Adding New Files to Your Project

Adding More New Files to Your Project

Adding Existing Files to Your Project

Setting Project Properties

Managing Configurations

Setting Source File Properties

Setting the Main Project

Building Your Project

Compiling a Single File

Running a Project

Creating a Project From Existing Sources

Building and Rebuilding Your Project

Creating a Project From a Binary File

Creating an Oracle Database Project

Doing Remote Development

Packaging an Application

Editing Source Files

Setting the Formatting Style

Folding Blocks of Code in C and C++ Files

Using Semantic Highlighting

Using Code Completion

Using Static Code Error Checking

Adding Source Code Documentation

Using Code Templates

Using Pair Completion

Navigating Source Files

Using the Classes Window

Using the Navigator Window

Finding Class, Method, and Field Usages

Using the Call Graph

Using Hyperlinks

Using the Include Hierarchy

Using the Type Hierarchy

Running Memory Access Checking on Your Project

Creating Breakpoints

Creating and Removing a Line Breakpoint

Creating a Function Breakpoint

Debugging a Project

Starting a Debugging Session

Inspecting the State of the Application

Debugging at the Machine-Instruction Level

Debugging a Running Program by Attaching to It

Debugging a Core File

Oracle® Solaris Studio 12.3 IDE Quick Start Tutorial

December 2011

This tutorial takes you through some of the basic steps of developing a C, C++, or Fortran application using the Oracle Solaris Studio 12.3 IDE.

Creating Projects

The Oracle Solaris Studio IDE lets you create C, C++, and Fortran Application and Library projects with generated makefiles, as well as projects that have existing source code and makefiles, and projects from existing binary files.

You can build, run, and debug your project on the local host (the system from which you started the IDE), or on a remote host running the Solaris operating system or the Linux operating system.

With a C/C++/Fortran Application, Dynamic Library, Static Library, or Oracle Database project, the IDE controls all aspects of how your application is built, run, and debugged. You specify project settings when creating the project and in the Project Properties dialog box. The IDE generates a makefile in which all of your settings are stored.

A project from existing sources is built using your makefile.

Creating an Application Project

  1. Open the New Project wizard by choosing File > New Project (Ctrl+Shift+N).

  2. In the wizard, select the C/C++/Fortran category.

  3. The wizard gives you a choice of several types of new projects. Select C/C++/Fortran Application and click Next.

    image:New Project wizard
  4. Create a new C/C++/Fortran Application project from the wizard using the defaults. You can choose the name of the project and the location of the project.

  5. Click Finish to exit the wizard.

A project is created with several logical folders. A logical folder is not a directory. It is a way for you to organize your files and does not reflect where the files are physically stored on disk. Files added to logical folders are automatically part of the project and are compiled when you build the project.

Files added to the Important Files folder are not part of the project and are not compiled when you build the project. These files are just for reference and are convenient when you have a project with an existing makefile.

Switching Between the Logical View and the Physical View of the Project

A project has both a logical and a physical view. You can switch between the logical view and the physical view of your project.

  1. Select the Files tab. This window shows the physical view of your project. It displays files and folders as they are stored on disk.

    image:Files tab
  2. Select the Projects tab. This window shows the logical view of your project.

    image:Projects tab

Adding Files and Folders to Your Project

You can add logical folders to your project.

  1. Right-click the project node of your CppApplication_1 project and choose New Logical Folder. A new logical folder is added to the project.

  2. Right-click the new logical folder and select Rename. Type the name you would like to give the new folder.

You can add both files and folders to an existing folder. Logical folders can be nested.

Adding New Files to Your Project

You can add new files to your project.

  1. Right-click the Source Files folder and choose New > C Main File.

  2. On the Name and Location page, newmain is displayed in the File Name field.

  3. Click Finish.

The newmain.c file is created on disk in the project directory and added to the Source Files folder. You can add any kind of file to this folder, not only source files.


Note - You can also remove files from the folder. In this case, you do not need the main.cpp file that was added by default when you created the project. To remove this file from the project, right-click on the file name and choose Remove From Project.


Adding More New Files to Your Project

  1. Right-click the Header Files folder and choose New > C Header File.

  2. On the Name and Location page, newfile is displayed in the File Name field.

  3. Click Finish.

The newfile.h file is created on disk in the project directory and added to the Header Files folder.

Adding Existing Files to Your Project

You can add existing files to your project in two ways:

Do not use the New menu item to add existing items. The Name and Location panel will tell you the file already exists.

Setting Project Properties

When the project is created, it has two configurations, Debug and Release. A configuration is a collection of settings used for the project, which allows you to easily switch many property settings at once. The Debug configuration builds a version of your application that includes debug information. The Release configuration builds an optimized version.

The Project Properties dialog box contains build and configuration information for your project. To open the Project Properties dialog box:

You can modify the compiler settings and other configuration settings in the Project Properties dialog box by selecting a node in the left panel and modifying the properties in the right panel. Select some of the nodes and property values and notice the properties you can set. When you set General properties, you are setting them in all configurations of the project. When you set Build, Run, or Debug properties, you are setting properties in the currently selected configuration.

Managing Configurations

Properties changed in the Project Properties dialog box are stored in the makefile for the current configuration. You can edit the default configurations or create new ones. To create a new configuration:

  1. Click the Manage Configurations button in the Project Properties dialog box.

  2. In the Configurations dialog box, select the configuration which most closely matches your desired configuration. In this case, select the Release configuration and click the Copy button. Then click Rename.

  3. In the Rename dialog box, rename the configuration to PerformanceRelease. Click OK.

  4. Click OK in the Configurations dialog box.

  5. In the Project Properties dialog box, select the C Compiler node in the left panel. Note that the PerformanceRelease configuration is selected in the Configuration drop-down list.

  6. In the property sheet in the right panel, change the Development Mode from Release to PerformanceRelease. Click OK.

You have created a new configuration that will compile the application with a different set of options.

Setting Source File Properties

When you set the project properties for your project, the relevant properties apply to all files in the project. You can set some properties for a specific file.

  1. Right-click the newmain.c source file and choose Properties.

  2. Click the General node in the Categories panel and see that you can select a different compiler or other tool to build this file. You can also select a checkbox to exclude the file from the build of the currently selected project configuration.

  3. Click the C compiler node and see that you can override the project compiler settings and other properties for this file.

  4. Cancel the Project Properties dialog box.

Setting the Main Project

When you right-click a project node in the Projects window, the IDE displays a pop-up menu of actions you can perform on the selected project. If you have multiple projects open at the same time, the pop-up menu for a project node implies you are operating on that project.

Most of the project-related actions on the menu bar and toolbar operate on the main project. The main project node is displayed in bold text in the Projects window.

To change the main project in the IDE:

Building Your Project

To build your project:

  1. Right-click the project and choose Build. The project builds. The build output is shown in the Output window.

    image:Output window
  2. Switch the configuration from Debug to PerformanceRelease in the configuration drop-down list in the main toolbar. Now the project will be built using the PerformanceRelease configuration.

  3. Right-click the project and choose Build. The project builds. The build output is shown in the Output window.

To build multiple configurations of the project at the same time, choose Run > Batch Build Main Project and select the configurations you want to build in the Batch Build dialog box.

You can build, clean, or both clean and build the project by right-clicking the project and choosing actions from the menu. The project also keeps object files and executables from different configurations separate, so you do not have to worry about mixing files from multiple configurations.

Compiling a Single File

To compile a single source file:


Note - Single file compilation is not supported for the project type C/C++/Fortran Project From Existing Code.


Running a Project

The Arguments sample program prints command-line arguments. Before running the program, you'll set some arguments in the current configuration. Then you'll run the program.

To create the Arguments_1 project, set some arguments, and run the project:

  1. Choose File > New Project.

  2. In the project wizard, expand the Samples category.

  3. Select the C/C++ subcategory, then select the Arguments project. Click Next, then click Finish.

  4. Right-click the Arguments_1 project node and choose Build. The project builds.

  5. Right-click the Arguments_1 project node and choose Properties.

  6. In the Project Properties dialog box, select the Run node.

  7. In the Run Command text field, type 1111 2222 3333 after the output path. Click OK.

    image:Project Properties dialog box
  8. Choose Run > Run Main Project. The application builds and runs. Your arguments are displayed in an external window.


Tip - The Run Monitor tab opens when you run the project and displays profiling tools for observing your application's behavior. You can turn off the profiling tools in the Profile category in the Project Properties dialog box.


Creating a Project From Existing Sources

With a C/C++/Fortran Project From Existing Sources, the IDE relies on your existing makefile for instructions on how to compile and run your application.

  1. Choose File > New Project.

  2. Select the C/C++/Fortran category.

  3. Select C/C++/Fortran Project From Existing Sources and click Next.

  4. On the Select mode page of the New Project wizard, click the Browse button. In the Select Project Folder dialog box, navigate to the directory where your source code is located. Click Select.

    image:New Project wizard
  5. Use the default configuration mode, Automatic. Click Finish.

  6. The project is created and opened in the Projects window, and the IDE automatically runs the Clean and Build sections specified in the existing Makefile. The project is also automatically configured for code assistance.

The project is created and opened in the Projects window. You have created a project that is a thin wrapper around existing code.

Building and Rebuilding Your Project

To build the project:

To rebuild the project:

Creating a Project From a Binary File

With a C/C++/Fortran project from a binary file, you can create a project from an existing binary file.

  1. Choose File > New Project.

  2. Select the C/C++/Fortran category.

  3. Select C/C++/Fortran Project from Binary File and click Next.

  4. On the Select Binary File page of the New Project wizard, click the Browse button. In the Select Binary File dialog box, navigate to the binary file from which you want to create a project.

    The root directory for the source files from which the binary was built is filled in automatically. By default, only the source files from which the binary was built are included in the project. By default, dependencies are included in the project. The shared libraries required by the project are automatically listed.

    image:New Project wizard Select Binary File page for Project from a Binary File
  5. Click Next.

  6. On the Project Name and Location page, you can choose the name and location of the project. Click Finish.

Creating an Oracle Database Project

You can create a project for an Oracle Database application. In order to do so, the Oracle Solaris Studio installation you are using must include the optional Oracle Instant Client component.

  1. Choose File > New Project.

  2. In the New Project dialog box, select the C/C++/Fortran category and the C/C++ Database Application project. Click Next.

  3. On the Project Name and Location page, you can choose name and location of the project. Click Next.

  4. On the Master table page, select jdbc:derby://localhost:1527/sample from the Database Connection drop-down list. The IDE connects to the database. Select the master table for your project from the Database Table drop-down list. Use the arrow keys between the Available Columns and Columns to Include lists to select the table columns you want to include in your project.

    image:New Project wizard Master Table page for Oracle Database Project
  5. Click Finish.

Doing Remote Development

You can build, run, and debug projects on the local host (the system from which you started the IDE) or on a remote host running a UNIX® operating system. Remote development lets you run the IDE locally in your familiar desktop environment, while using the computing power and development tools on a remote server to build your projects.

You can configure remote development hosts in the Build Tools tab of the Options dialog box. To add a remote host:

  1. Choose Tools > Options, and click the C/C++ category.

  2. In the Build Tools tab of the Options dialog box, click Edit.

  3. In the Build Hosts Manager dialog box, click Add.

  4. On the Select Host page in the New Remote Build Host wizard, type the system name of the host in the Hostname field or double-click an available host in the Network neighborhood list to select it. Click Next.

    image:New Remote Build Host dialog box, Select Host page
  5. On the Setup Host page, type your login name in the Login field and click Next.

    image:New Build Development Host, Setup Host page
  6. The wizard prompts you for a password, connects to the host, and displays a Summary page. Click Finish.

  7. After the host is added to the Build Hosts list in the Build Hosts Manager dialog box, click OK.

  8. You can set properties that specify how the IDE uses the remote host in the Services window. Expand the C/C++ Build Hosts node, right-click the remote host, and choose Properties. Set the desired properties in the Host Properties dialog box.

  9. To set the remote host as the default build host, right-click the host in the C/C++ Build Hosts node in the Services window, and choose Set as Default.

To develop a project on a remote host, the project must be on a shared filesystem that is visible on both the local host and the remote host. Typically such a filesystem is shared using NFS or Samba. You can define the mapping between local and remote paths to project source files when you define the remote host.

When you create a project, the default build host is selected as the build host for the project. You can change the build host for the project on the Build panel of the Project Properties dialog box. You can also specify the build host when you are debugging an executable or a core file.

To work on a project that resides on a remote host on your local host, choose File > Open Remote C/C++ Project.

Packaging an Application

You can package a completed application as a tar file, zip file, Solaris SVR4 package, RPM, or Debian package.

  1. Right-click the Arguments_1 project and choose Properties.

  2. In the Project Properties dialog box, select the Packaging node.

  3. Select the Solaris SVR4 package type from the drop-down list.

  4. Change the output path if you want to use a different destination directory or filename for the package.

  5. Click the Packaging Files browse button. In the Packaging Files dialog box (for an SVR4 package), modify the package parameters on the Info tab as needed.

    image:Packaging Files dialog box, Info tab
  6. For all package types, add files to the package using the buttons on the Files tab. For each file, you can specify the path you want it to have in the package in the File or Directory Path in Package column of the Files list. Click OK when your Files list is complete.

    image:Packaging Files dialog box, Files tab
  7. Turn off verbose mode if you wish by clicking the checkbox.

  8. Click OK.

  9. To build your package, right-click the project and choose More Build Commands > Build Package.

Editing Source Files

The Oracle Solaris Studio IDE provides advanced editing and code assistance features to help you in viewing and modifying your source code. To explore these features, use the Quote project:

  1. Choose File > New Project.

  2. In the project wizard, expand the Samples category and the C/C++ subcategory, then select the Quote project. Click Next, then click Finish.

Setting the Formatting Style

You can use the Options dialog box to configure default formatting style for your projects.

  1. Choose Tools > Options.

  2. Click Editor in the top pane of the dialog box.

  3. Click the Formatting tab.

  4. Select the language for which you want to set formatting style from the Language drop-down list.

  5. Select the style you want to set from the Style drop-down list.

    image:Formatting tab in Options dialog box
  6. Modify the style properties as desired.

Folding Blocks of Code in C and C++ Files

For some types of files, you can use the code folding feature to collapse blocks of code so that only the first line of the block appears in the Source Editor.

  1. In the Quote_1 application project, open the Source Files folder, then double-click the cpu.cc file to open it in the Source Editor.

  2. Click the collapse icon (small box with minus sign) in the left margin to fold the code of one of the methods.

  3. Mouse over the {...} symbol to the right of the folded block to display the code in the block.

Using Semantic Highlighting

You can set an option so that when you click on a class, function, variable, or macro, all occurrences of that class, function, variable, or macro in the current file are highlighted.

  1. Choose Tools > Options.

  2. Click C/C++ in the top pane of the dialog box.

  3. Click the Highlighting tab.

  4. Make sure that all of the check boxes contain checkmarks.

  5. Click OK.

  6. In the customer.cc file of the Quote_1 project, notice that the function names are highlighted in bold.

  7. Click on an occurrence of the Customer class.

  8. All of the occurrences of the Customer class in the file are highlighted with a yellow background.

    image:Editor window with instances of Customer class highlighted in yellow
  9. In the customer.h file, notice that class fields are highlighted in bold.

    image:Editor window with function names highlighted in bold

Using Code Completion

The IDE has a dynamic C and C++ code completion feature that enables you to type one or more characters and then see a list of possible classes, methods, variables, and so on that can be used to complete the expression.

  1. Open the quote.cc file in the Quote_1 project.

  2. On the first blank line of the quote.cc file, type a capital C and press Ctrl-Space. The code completion box displays a short list that includes the Cpu and Customer classes. A documentation window also opens and displays the message No documentation found because the project source code does not include documentation.

  3. Expand the code completion list by pressing Ctrl-Space again.

    image:Code completion list
  4. Select a standard library function such as calloc() from the list and the documentation window displays the man page for the function if the man page is accessible to the IDE.

  5. Select the Customer class and press Enter.

  6. Complete the new instance of the Customer class by typing andrew;. On the next line, type the letter a and press Ctrl-Space. The code completion box displays a list of choices starting with the letter a, such as method arguments, class fields, and global names, that are accessible from the current context.

    image:Code completion list
  7. Double-click the andrew option to accept it and type a period after it. You are automatically provided with a list of the public methods and fields of the Customer class.

    image:Code completion list
  8. Delete the code you have added.

Using Static Code Error Checking

When you type code in a source or header file in the Source Editor, the editor performs static code error checking as you type and displays an error icon image:error iconin the left margin when it detects an error.

  1. In the quote.cc file of the Quote_1 project, type #include "m on line 40 and notice the error icon that appears in the margin.

    image:code in Editor window showing error icon on line 40
  2. Backspace over the second quotation mark and complete the statement by typing odule.h”, and notice that error icon disappears as soon as the statement references an existing header file.

  3. Delete the statement you have added.

Adding Source Code Documentation

You can add comments to your code to generate documentation for your functions, classes, and methods. The IDE recognizes comments that use Doxygen syntax and automatically generates documentation. It can also automatically generate a comment block to document the function below the comment.

  1. In the quote.cc file, place your cursor on the line above the line int readNumberOf(const char* item, int min, int max) {.

  2. Type a slash and two asterisks and press Enter The editor inserts a Doxygen-formatted comment for the readNumberOf class.

    image:Editor window with comment
  3. Add some descriptive text to each of the @param lines and save the file.

  4. Click the readNumberOf class to highlight it in yellow, and click one of the occurrences marks on the right to jump to a location where the class is used.

    image:Editor window with readNumberOf class highlighted
  5. Click the readNumberOf class in the line you jumped to, and press Ctrl-Shift-Space to show the documentation you just added for the parameters.

    image:Editor window showing documentation window with documentation
  6. Click anywhere else in the file to close the documentation window, and click on the readNumberOf class again.

  7. Choose Source > Show documentation to open the documentation window for the class again.

Using Code Templates

The Source Editor has a set of customizable code templates for common snippets of C, C++, and Fortran code. You can generate the full code snippet by typing its abbreviation and pressing the Tab key. For example, in the quote.cc file of the Quote_1 project:

To see all of the available code templates, modify them, create your own code templates, or select a different key to expanded the templates:

  1. Choose Tools > Options.

  2. In the Options dialog box, select C/C++, and click the Code Templates tab.

  3. Select a language from the Language drop-down list.

    image:Code Templates tab in Options dialog box

Using Pair Completion

When you edit your C and C++ source file, the Source Editor does “smart” matching of pair characters such as brackets, parentheses, and quotation marks. When you type one of these characters, the Source Editor automatically inserts the closing character.

  1. In the Quote_1 project, placed the cursor after the { on line 116 of the module.cc file and press Return to open a new line.

  2. Type enum state { and press Return. The closing curly bracket and the semi-colon are added automatically and the cursor is placed between the brackets.

  3. Type invalid=0, success=1 to complete the enumeration.

  4. On the line after the closing }; of the enumeration, type if (. The closing parenthesis is added automatically and the cursor is placed between the parentheses.

  5. Type v==null. Then type i and newline after the right parenthesis. The closing bracket is added automatically.

  6. Delete the code you have added.

Navigating Source Files

The IDE provides advanced navigation features for viewing your source code. To explore these features, continue using the Quote_1 project.

Using the Classes Window

The Classes window lets you see all of the classes in your project, and the members and fields for each class.

  1. Click the Classes tab to display the Classes window.

  2. Expand the Quote_1 node. All classes in the project are listed.

  3. Expand the Customer class.

    image:Classes window
  4. Double-click on the name variable to open the customer.h header file.

Using the Navigator Window

The Navigator window provides a compact view of the file that is currently selected, and simplifies navigation between different parts of the file. If the Navigator window is not open, choose Window > Navigating > Navigator to open it.

  1. Click anywhere in the quote.cc file in the Editor. window.

  2. A compact view of the file is displayed in the Navigator window. Click the node a the top of the window to expand the view.

    image:Navigator window
  3. To navigate to an element of the file, double-click the element in the Navigator window and the cursor in the Editor window moves to that element.

  4. Right-click in the Navigator window to see options for sorting the elements in the window, grouping the items, or filtering.

  5. To see what the icons in the Navigator window represent, open the IDE online help by choosing Help > Help Contents. In the Help browser, click the Search tab and type navigator icons in the Find field.

Finding Class, Method, and Field Usages

You can use the Usages window to show you everywhere a class (structure), function, variable, macro, or file is used in your project's source code.

  1. In the customer.cc file, right-click the Customer class on line 42, and choose Find Usages.

  2. In the Find Usages dialog box, click Find.

  3. The Usages window opens and displays all of the usages of the Customer class in the source files of the project.

    image:Usages window

Using the Call Graph

The Call Graph window displays two views of the calling relationships between functions in the classes. A tree view shows the functions called from a selected function, or the functions that call that function. A graphical view shows the calling relationships using arrows between the called and calling functions.

  1. In the quote.cc file, right-click on the main function and choose Show Call Graph.

  2. The Call Graph window opens and displays a tree view and a graphical view of all of the functions called from the main function.

    image:Call Graph window

    If you do not see all of the functions shown in the screen shot, click the third button on the left side of the Call Graph window to show who is called from this function.

  3. Expand the end1 node to display the functions called by that function. Notice that the graph is updated to add the functions called by end1.

  4. Select the end1 node and click the second button on the left side of the window to focus on the endl function, then click the fourth button to view all of the functions that call the end1 function.

    image:Call Graph window
  5. Expand some of the nodes in the tree to see more functions.

    image:Call Graph window

Using Hyperlinks

Hyperlink navigation lets you jump from the invocation of a class, method, variable, or constant to its declaration, and from its declaration to its definition. Hyperlinks also let you jump from a method that is overridden to the method that overrides it, and the reverse.

  1. In the cpu.cc file of the Quote_1 project, mouse over line 37 while pressing Ctrl. The ComputeSupportMetric function is highlighted and an annotation displays information about the function.

    image:Editor window with annotation for function
  2. Click the hyperlink and the editor jumps to the definition of the function.

    image:Editor window
  3. Mouse over the definition while pressing Ctrl, and click the hyperlink. The editor jumps to the declaration of the function in the cpu.h header file.

  4. Click the left arrow in the editor tool bar and the editor jumps back to the definition in cpu.cc.

  5. Hover the mouse cursor over the green circle image:green circle icon in the left margin and see the annotation that indicates that this method overrides another method.

    image:Editor window with override annotation
  6. Click the green circle to go to the overridden method and the editor jumps to the module.h header file, which shows a gray circle in the margin to indicate the method is overridden.

  7. Click the gray circle and the editor displays a list of methods that override this method.

    image:Editor window with methods list
  8. Click the Cpu::ComputerSupportMetric item and the editor jumps back to the declaration of the method in the cpu.h header file.

Using the Include Hierarchy

The Include Hierarchy window lets you inspect all header and source files that are directly or indirectly included in a source file, or all source and header files that directly or indirectly include a header file.

  1. In the Quote_1 project, open the module.cc file in the Source Editor.

  2. Right-click on the #include "module.h" line in the file and choose Navigate > View Includes Hierarchy.

  3. By default, the Hierarchy window displays a plain list of files that directly include the header file. Click the right-most button at the bottom of the window to change the display to a tree view. Click the second button from the right to change the display to all files that include or are included. Expand the nodes in the tree view to see all of the source files that include the header file.

    image:Include Hierarchy window

Using the Type Hierarchy

The Type Hierarchy window lets you inspect all subtypes or supertypes of a class.

  1. In the Quote_1 project, open the module.h file.

  2. Right-click on the declaration of the Module class and choose Navigate > View Type Hierarchy.

  3. The Hierarchy window displays all of the subtypes of the Module class.

    image:Type Hierarchy window

Running Memory Access Checking on Your Project

You can use the Memory Analysis Tool to find memory access errors in your project. The tool allows you to find these errors easily by pointing out exactly where the each error occurs in your source code.

The Memory Analysis tool catches and reports memory access errors dynamically during program execution, so if a portion of your code is not executed at run time, errors in that portion are not reported.

  1. If you have not already done so, download the sample applications zip file from the Oracle Solaris Studio 12.3 Sample Applications web page at http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/solaris-studio-samples-1408618.html, and unzip the file in a location of your choice. The memorychecks application is located in the CodeAnalyzer subdirectory of the SolarisStudioSampleApplications directory.

  2. Create a project from existing sources using the memorychecks application.

  3. Right-click the project and choose Properties. In the Project Properties dialog box, select the Run node, and type Customer.db after the output path in the Run Command. Click OK.

  4. Run the project.

  5. Now build the project with instrumentation for memory analysis.

    1. Make sure that your memorychecks project is set as the main project.

    2. Click the down arrow next to the Profile Project button image:Profile Project button and select Profile Project to find Memory Access Errors from the drop-down list.

    3. In the Select Analysis Type dialog box, select All Memory Access Errors from the drop-down list.

      image:Select Analysis Type dialog box

      The Overhead field displays High or Moderate to indicate the load that will be placed on the system. The performance of other programs running on your system might be affected when the overhead is high, which is the case when you are detecting both data races and deadlocks.

    4. Click Start.

  6. The Run Memory Profile dialog box opens to let you know that your binary will be instrumented. Click OK.

  7. The project is built and instrumented. The application starts running and the Memory Analysis window opens. When your project run is complete, the Memory Analysis window lists the memory access error types found in your project. The number of errors of each type is shown in parentheses after the error type.

    image:Memory Analysis window
  8. When you click on an error type, the errors of that type are displayed in the Memory Analysis Tool window.

    image:Memory analysis tool window

    By default, the errors are grouped by the source file in which they were found. When you click on an error, the call stack for that error is displayed. Double-click a function call in the stack to display the associated lines in the source file.

Creating Breakpoints

You can create and manipulate breakpoints in your code at any time.

Creating and Removing a Line Breakpoint

  1. In the Quote_1 project, open the quote.cc file.

  2. Set a line breakpoint by clicking in the left margin of the Editor window next to line 171 (response = readChar("Enter disk module type: (S for single disks, R for RAID; Q - exit)", 'S');). The line is highlighted in red to indicate that the breakpoint is set.

    image:Editor window showing line breakpoint
  3. You could remove the breakpoint by clicking on the icon in the left margin.

  4. Choose Window > Debugging > Breakpoints to open the Breakpoints window. Your line breakpoint is listed in the window.

    image:Breakpoints window

Creating a Function Breakpoint

  1. Choose Debug > New Breakpoint (Ctrl+Shift+f8) to open the New Breakpoint dialog box.

  2. In the Breakpoint Type drop-down list, set the type to Function.

  3. Type the function name Customer::GetDiscount in the Function text field. Click OK.

    image:New Breakpoint dialog box
  4. Your function breakpoint is set and is added to the list in the Breakpoints window.

    image:Breakpoints window

Debugging a Project

When you start a debugging session, the IDE starts the debugger in the project's associated tool collection (by default, the dbx debugger), then runs the application inside the debugger. The IDE automatically opens debugger windows and prints debugger output to the Debugger Console window.

Starting a Debugging Session

  1. Start a debugging session for the Quote_1 project by right-clicking the project node and choosing Debug. The debugger starts and the application runs, and the Variables and Debugger Console windows open.

    image:Debugger Console window
  2. Open the Sessions window by choosing Window > Debugging > Sessions. The debugging session is shown in this window.

    image:Sessions window

Inspecting the State of the Application

  1. The Quote_1 application prompts you for input in the Output window.

  2. Enter a customer name after the Enter customer name: prompt.

  3. The application stops at the function breakpoint you set earlier. The Breakpoints window lists the two breakpoints you set earlier. The green program counter arrow appears on top of the breakpoint icon of the function breakpoint.

    image:Breakpoints window
  4. In the customer.cc file, the green program counter arrow appears on top of the breakpoint icon on the first line of the GetDiscount function.

    image:Editor window showing program counter on breakpoint
  5. Open the Call Stack window. The call stack shows three frames.

    image:Call Stack window
  6. Click the Variables window and note that one variable is displayed. Click the nodes to expand the structure.

    image:Variables window
  7. Click the Continue button. The GetDiscount function is executed, printing the customer discount to the Output window. Then you are prompted for input.

  8. Enter the input in response to the prompts. The program stops at the next breakpoint, the line breakpoint you set earlier. Click the Variables window and note the long list of local variables.

    image:Variables window
  9. Look at the Call Stack window and note that there is only one frame in the stack.

  10. Click Continue image:Continue button and continue entering input in response to the prompts in the Output window until the program is completed. When you enter the last input to the program, your debug session ends. To end the debug session before the execution of the program was complete, you could right-click the session in the Sessions window, and choose Finish.

Debugging at the Machine-Instruction Level

The debugger provides windows that let you debug your project at the machine-instruction level.

  1. Right-click the Quote_1 project and choose Debug.

  2. In the Output window, type a customer name in response to the prompt.

  3. When the program pauses at the breakpoint on the GetDiscount function, choose Window > Debugging > Disassembly to open the Disassembly window as in the Editor window. The green program counter arrow appears on top of the breakpoint icon at the instruction on which the program is paused.

    image:Disassembly window
  4. Choose Window > Debugging > Registers to open the Registers window, which displays the contents of the registers.

    image:Registers window
  5. Choose Window > Debugging > Memory to open the Memory window, which displays the contents of memory currently used by your project At the bottom of the window, you can specify a memory address to browse, change the length of the memory browse, or change the format for memory information.

    image:Memory window

Debugging a Running Program by Attaching to It

If you want to debug a program that is already running, you can attach the debugger to the appropriate process.

  1. Choose File > New Project.

  2. In the New Project wizard, expand the Samples node and select the C/C++ category.

  3. Select the Freeway Simulator project. Click Next and then click Finish.

  4. Right-click the Freeway_1 project you created and choose Run. The project builds and the Freeway application starts. In the Freeway GUI window, choose Actions > Start.

  5. In the IDE, choose Debug > Attach Debugger.

    image:Attach dialog box
  6. In the Attach dialog box, type Freeway in the Filter field to filter the list of processes.

  7. Select the Freeway process from the filtered list.

  8. Click OK.

  9. A debugging session is started and execution of the Freeway process pauses at the point where the debugger attached to it.

  10. Click Continue image:Continue buttonto continue execution of Freeway, which is now running under control of the debugger. If you click Pause image:Pause button, execution of Freeway pauses, and you can examine variables, the call stack, and such.

  11. Click Continue again and then click Finish Debugger Session image:Finish Debugger Session button. The debugger session ends, but the Freeway process continues executing. Choose File > Exit in the Freeway GUI to exit the application.

Debugging a Core File

If your program is crashing, you might want to debug the core file (the memory image of your program when it crashed). To load a core file into the debugger:

  1. Choose Debug > Debug core file.

  2. Type the full path to a core file in the Core File field or click Browse and navigate to your core file in the Select Core File dialog box.

    image:Debug Core file dialog box
  3. If the debugger cannot associate the core file you specified with an executable, it displays an error message. If this situation occurs, type the path name of the executable in the Executable text box, or click the Browse button and use the Executable dialog box to select the executable.

  4. By default, the Project text field displays either <no project> or the name of an existing project that exactly matches the name of the executable. If you want a new project created for the executable, select <create new project>.

  5. Click Debug.

For a more in-depth tutorial on debugging, see the Oracle Solaris Studio 12.3: dbxtool Tutorial.