![]() |
|
|||||||||||||||
|
||||||||||||||||
|
| Debugging using the DBDK-generated tracing features | ||||
This article shows how to debug an Informix C UDR using DBDK-generated tracing. Includes sample C source code. Introduction What are the DBDK Tracing Features?
Tracing Features in the C
Code If you look at the generated code for one of your functions, you'll see three kinds of tracing calls:
Each of these macros calls Gen_Trace(). Tracing Features in the
Header File
The DBDK_TRACE_ENTER and DBDK_TRACE_EXIT macros are special cases of DBDK_TRACE_MSG. All of the macros are designed to simplify calls to Gen_Trace() by reducing the number of arguments required. In addition to the tracing macros, the generated header file contains #define statements for a set of pre-defined error messages. These statements map the ERRORMESG numbers used by the tracing macros to the NAME column in the SYSTRACEMSGS catalog. Tracing Features in the
System Catalogs If you create a new database and look at this table, you'll find that it's empty. When you register a DataBlade, the BladeSmith utility seeds the table with a collection of standard messages. These messages are shared by all DataBlade modules, and should not be changed. You can, however, add your own messages. See Adding Your Own Trace Messages below for details. How is the DBDK Tracing Activated? Creating the
TraceSet_<bladename> procedure.
Although your DataBlade's .bld file will contain the executable code for your TraceSet_<bladename> routine, the generated scripts that register your DataBlade in a database don't include the directive to create the corresponding SQL procedure. This is because tracing is considered a development/debugging tool; it is assumed that end users won't normally use it. To create the SQL procedure to turn on tracing for your DataBlade, follow the instructions in the comments block in the source for your TraceSet_<bladename> routine. The SQL statement will look like this:
Where "myblade" is the name of your DataBlade module, and "/path" is the path to your DataBlade's installation directory, normally "$INFORMIXDIR/extend/<bladename.revision". The comments block in your TraceSet_<bladename> source code will show the exact syntax for your DataBlade. Once you have run BladeManager to register your DataBlade in a database, and used the above SQL statement to create your TraceSet procedure, you can turn on tracing for an SQL session with the following SQL statement:
Where "/path/file" is the full path to your trace log. Creating a trace
class The built-in tracing provided by the DBDK assumes you'll have a single trace class, and that its name is the same as the name of your DataBlade module. Trace classes are maintained in the systraceclasses system catalog. If your DataBlade name is "Foo", use the following SQL statement to create a trace class "Foo":
Setting a trace
level The basic tracing provided by the DBDK uses trace level 20. So, to see the DBDK_TRACE_ENTER and DBDK_TRACE_EXIT messages, turn on tracing for the appropriate trace class, and set the level to at least 20. Setting
the trace output file
The filename argument specifies the file into which your trace messages will be written. So, to turn on tracing for a session, directing the output to "/tmp/myblade.trc", and setting the trace level to "20", use the following SQL call:
You have the option of letting the system assign an output file, instead of choosing one yourself. To do so, leave the filename argument blank when you call TraceSet_myblade:
The server will create a file in /tmp with a numeric base and the extension ".trc", e.g., "/tmp/123.trc". The base part of the name is your session number. Setting your
locale If your trace file looks like this:
then chances are you have your LOCALE variables set incorrectly. Take a look at your systracemsgs catalog, i.e.:
Chances are the "locale" column is set to "en_us.8859-1"; this is the default for US English on the Unix platform. The system will only display messages to your session that match the locale specified in your session's CLIENT_LOCALE environment variable. To see the messages whose locale is en_us.8859-1, set your environment as follows:
(Note that this syntax is for the UNIX C shell. If you are using the Bourne shell, Bash, or ksh, modify your syntax accordingly. If you are using SQL Editor on NT, you can set this environment variable via SetNet32.) Now try again. Your trace file should look something like this:
Adding Your Own Trace Messages
Adding
an entry to systracemsgs:
When you register your DataBlade in a database, your new trace message will be added to the systracemsgs system catalog. Note: In addition to h2traceh2 messages, you can also set h2errorh2 messages using BladeSmith. Follow the steps above, but set the "Register message as" to "Error" (step 4). Errors are used by the mi_db_error_raise() DataBlade API call. See the DataBlade API Programmer's Manual for detailed information about mi_db_error_raise(). Adding
tracing statements to your C code:
In this example, we used the same trace class as is used by the DBDK_TRACE_ENTER and DBDK_TRACE_EXIT macros ("TraceDemo"), we used the new systracemsgs name ("TD002"), and we set the threshold to the same value as the _ENTER and _EXIT macros use (20). Now when we run the demo as above, our trace file looks like this:
We could (and the demo does) create several new trace messages and set each one to fire at a different trace level setting. For example, we could create these trace messages:
We could put the following code in our C routine:
Now when we call our function, the messages we see in our trace file will depend on the trace level we use in the SQL session. Any trace level 10 or higher will cause TD001 to be printed, a trace level of 20 or higher will cause TD001 and TD002 to print, and a trace level of 30 or higher will cause all three messages to print to the trace log. Adding messages
with variable text The DBDK doesn't provide macros that handle variable arguments, but you can call GL_DPRINTF directly to accomplish this. To include variable text in your trace messages, enclose a keyword in percent signs in the "SQL error text", and then specify the keyword, a printf-style format specifier, and the substitution text when you invoke the message. For example, your "SQL error text" might look like this:
When you call GL_DPRINTF in your program, you include the keyword followed by a format specifier, and the value to substitute:
In this example, TraceDemo is the trace class name, 60 is the trace level, TD005 is the trace message name, COUNTER is the keyword, %d is the format specifier, i is an integer value, and MI_LIST_END is a flag that signals the end of your list of substitution variables. If you call your routine in an SQL session where the trace level is set to 60 or higher, you'll see lines like the following in your trace log:
The downloadable demo includes trace messages with variable text. IBM, DB2, Informix, and WebSphere are trademarks or registered trademarks of IBM Corporation in the United States, other countries, or both. Windows and Windows NT are registered trademarks of Microsoft Corporation in the United States, other countries, or both. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Other company, product, and service names may be trademarks or service marks of others. IBM copyright and trademark information Additional information can be found in the following sources:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|