Using Diagnostic Blocks in ODB

Process models contain a component known as the diagnostic block, and the Process Editor provides an operation for editing the contents of this block. The diagnostic block consists of a sequence of C statements that are executed only under the control of ODB commands. Typical uses of diagnostic block statements are similar to the uses of user-defined trace statements: they can display information that conveniently summarizes relevant process information for quick evaluation, or perform more involved operations that interact with the process resources. Diagnostic block statements differ from user-defined trace statements in how they are invoked:

  • user-defined trace statements are enabled by an ODB command, but invoked when the process state containing them is executed due to the delivery of an interrupt
  • diagnostic block statements are directly invoked by an ODB command; diagnostic blocks of any existing process can be invoked at any ODB breakpoint

The ability to execute any diagnostic block at any breakpoint enhances the flexibility of ODB. For example, a breakpoint set for a particular process can be used to stop the simulation at an appropriate interrupt, and then a diagnostic block in another process can be invoked to check the values of state variables that are of interest only at the time of the breakpoint.

There are two methods for invoking a diagnostic block, described below:

Table 16: Diagnostic Block Commands

"prodiag" Invokes the diagnostic block of a specified process.
"proldiag" Invokes the diagnostic block of a specified process, and sets a trace for a specified label restricted to the execution of the block. Invocations of op_prg_odb_ltrace_active() with a matching label within the block return 1.

The basic command is prodiag, which executes the whole diagnostic block without alteration. This command is typically used with diagnostic blocks that print comprehensive information about the current state of a process model. A labeled version of diagnostic block invocation is available via the proldiag command. This command invokes the whole diagnostic block, but sets a trace for a single label during the invocation that can be queried using the KP op_prg_odb_ltrace_active(). By bracketing several groups of statements within if statements that check different labels, a complex diagnostic block can be written to support several different operations. This feature can be used to extend ODB’s functionality with user-defined “commands” based on proldiag. A example of this appears in Figure 22.

Diagnostic blocks typically contain some statements concerned with printing out process information. To display messages or variable values in the style of ODB, the KPs op_prg_odb_print_major() and op_prg_odb_print_minor() can be used. For more format flexibility, the C function printf() is useful.

Diagnostic blocks can go beyond printing information; they can also perform complex operations within the process context which serve diagnostic functions. Diagnostic statements can include KP invocations and references to process temporary and state variables, and can modify process state. KPs invoked from diagnostic statements can schedule events which will be performed later. One restriction on diagnostic statements is that they should not invoke processes or cause forced interrupts of processes.

Figure 22: Diagnostic Block with Labeled Sections

/* State variable summary;  label is "sv_summary". */
if (op_prg_odb_ltrace_active ("sv_summary"))
   {
   op_prg_odb_print_major ("----- State Variable Summary -----", OPC_NIL);
   sprintf (mstring, "Sequence Number (%d)", seq_num);
   op_prg_odb_print_minor (mstring, OPC_NIL);
   sprintf (mstring, "Mode (%s)", (mode == MODE_OPEN) ? "open" : "closed");
   op_prg_odb_print_minor (mstring, OPC_NIL);
   }
/* Queue contents summary; label is "q_summary". */
if (op_prg_odb_ltrace_active ("q_summary"))
   {
   op_prg_odb_print_major ("----- Queue Summary -----", OPC_NIL);

   /* Determine how many packets are in the queue. */
   qsize = op_subq_stat (0, OPC_QSTAT_PKSIZE);

   /* Loop through each packet in the queue, printing its address. */
   for (i = 0; i < qsize; i++)
      {
      /* Obtain a pointer to the ith packet & extract address field. */
      pkptr = op_subq_pk_access (0, i);
      op_pk_fd_get (pkptr, PKFD_ADDR, &addr);

      sprintf (mstring, "index (%d): pk address (%d)", i, addr);
      op_prg_odb_print_minor (mstring, OPC_NIL);
      }
   }