INFORMIX DataBlade Developers Kit Tutorial

List of Exercises

Tutorial Exercise 2

Debugging a DataBlade Module

This exercise demonstrates debugging a DataBlade module. You will debug the AddInts DataBlade module that you created in Exercise 1. The AddInts DataBlade module contains one user-defined routine, AddIntegers(), which adds two integers and returns the result.

This exercise provides instructions for debugging a DataBlade module on Windows NT using Microsoft Visual C++ Developer Studio. You are assumed to be running your Informix server on the Windows NT workstation on which you built the AddInts DataBlade module.

WARNING: Use a test database server for debugging because when you bring down the debugger in Step 5, the database server crashes.

For information about debugging on UNIX, see the DataBlade Developers Kit User's Guide. Additional information about debugging is available from the Informix Developers Network.

Tutorial Steps

This exercise consists of seven steps. It takes approximately 30 minutes to complete.


1

Load the DataBlade module by calling one of its routines.

Before you attach the debugger process to the database server, load your DataBlade module dynamic link library file into the database server address space. With the dynamic link library file loaded, you can set breakpoints on module entry points and examine local storage provided by module functions.

To load the DataBlade module into the database server address space, execute a DataBlade module routine using SQL Editor or DB-Access.

Because you have not debugged your routines, you should execute a noncritical routine to load your DataBlade module. There are two methods for loading a DataBlade module dynamic link library without executing an untested critical routine:

  • Call the routine with an impossible condition, such as in the following query (you can run this query against any table from which you have permission to select data):
         select AddIntegers(2,5) from sysbldregistered where 2=0; 
    
    
  • Add a simple user-defined routine to your DataBlade module: for example, one that returns a hard-coded version number through SQL. You can then call this simple version number routine instead of a critical routine that you want to test.

2

Start the database server, if necessary.

See " Starting Informix Dynamic Server on Windows NT" for detailed instructions on starting Informix Dynamic Server on Windows NT.

For instructions on starting Informix Dynamic Server on UNIX, see the Administrator's Guide for your database server.


3

Attach the debugger to the server process.

Start Microsoft Visual C++ Developer Studio.

Choose Build Start Debug Attach to Process. The Attach to Process dialog box appears.

Select the Informix server process oninit.

Click OK.


4

Set breakpoints in your source code.

Choose File Open and select udr.c from the AddInts\src\C directory.

To set breakpoints in your code, place your cursor on the line in which you want to set a breakpoint and right-click anywhere on the line. Select Insert/Remove Breakpoint from the popup menu.

Set a breakpoint at the line in which the AddInts() function adds the two integers:

    Gen_RetVal = Int1 + Int2; 
    
    

Save udr.c.


5

Issue SQL statements to call your DataBlade module routines.

Using SQL Editor or DB-Access, issue the following SQL statements to call the AddInts() function:

    execute function AddIntegers(2,5); 
    
    

The debugger stops the function from executing before it adds the two input values. You can check the values of the variables before and after their values are added. At the breakpoint, the variables have the following values.

Variable Name Value

Gen_Con

0x0000000

Gen_RetVal

a stack number

Int1

2

Int2

5

Use the Step Into or Step Over commands in the Debug toolbar to pass the breakpoint. The variables now have the following values.

Variable name Value

Gen_RetVal

7

Int1

2

Int2

5


6

Stop the debugger and the database server.

Run your code until the function is finished executing.

In Visual C++, choose Debug Stop Debugging and exit Visual C++. The database server crashes.

Disconnect SQL Editor or DB-Access from the database. The tool may take a few minutes to exit.


7

If necessary, recompile and repeat the debugging process.

If you have detected problems, you can re-open the Visual C++ workspace for your project (in this example, the file AddInts.dsw in the src\C directory) and modify the source code to correct the problems. Then save your changes and rebuild your DataBlade module to repeat the debugging process.

Important: You must shut down the database server before you replace the DataBlade module dynamic link library (shared object file). See the "DataBlade Developers Kit User's Guide" for more information.


Please Send Us Your Feedback

How useful was this exercise?

Very useful Somewhat useful Useful Not useful

How would you describe your experience with Informix software?

Very experienced Some experience Novice Complete beginner

How would you like to see this exercise improved? Any other comments?


Copyright © 1998, Informix Software, Inc. All rights reserved.