Exception Raising

From OC Systems Wiki!
Revision as of 17:57, 12 October 2021 by Swn (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You can raise exception in target program from your probes. Some examples are below. See $APROBE/include/aprobe.h for more information.


PowerAda

To raise an exception in PowerAda use one of the following in your probe:

  ap_RaisePowerAdaException(N)
  ap_RaisePowerAdaExceptionInModule(N.M)

The first form can be used when the exception is declared in the same module as the probed function. If the exception is declared in another module, use the second form.

   probe thread
   {
      probe "my function"
      {
         on_entry
         {
            ap_RaisePowerAdaException("MyException"):
         }
      }
   }

NOTE: You cannot use the name of a renamed exception, you must use the original exception name.

NOTE: If you use the -q min_heap option Aprobe throws away symbol info after program initialization. In this case the exception symbol must be found by name at program initialization, not at the point of the raise. You must resolve the exception symbol at program start-up and use ap_RasiePowerAdaExceptionBySymbol() found in $APROBE/include/aprobe.h. Here is an example:

probe program 
{
  ap_ModuleIdT mid = ap_ModuleNameToId (the_module_name);
  ap_SymbolIdT sid = ap_SymbolNameToId(
                       mid,
                       the_exception_name,
                       ap_ExternSymbol,
                       ap_FunctionSymbol);
}

probe thread
{
   probe "MyFunction"
   {
      on_entry
      {
         ap_RaisePowerAdaExceptionBySymbol(
             (ap_ThreadContextPtr,  
              ap_ExecutionContextPtr,             
              ap_ProbeActionReason,                  
              ap_FunctionId,                     
              ap_Offset,
              sid,
              (ap_nameT)"reason");
      }
   }
}

GNAT

To raise an exception in GNAT use the following in your probe:

  ap_RaiseGnatException(N)

This form can be used when the exception is declared in the same module as the probed function. If the exception is declared in another module, see ap_RaiseGnatExceptionBySymbol() below.

   probe thread
   {
      probe "my function"
      {
         on_entry
         {
            ap_RaiseGnatException("MyException"):
         }
      }
   }

NOTE: You cannot use the name of a renamed exception, you must use the original exception name.

NOTE: If you use the -q min_heap option Aprobe throws away symbol info after program initialization. In this case the exception symbol must be found by name at program initialization, not at the point of the raise. You must resolve the exception symbol at program start-up and use ap_RasieGnatExceptionBySymbol() found in $APROBE/include/aprobe.h. Here is an example:

probe program 
{
  ap_ModuleIdT mid = ap_ModuleNameToId (the_module_name);
  ap_SymbolIdT sid = ap_SymbolNameToId(
                       mid,
                       the_exception_name,
                       ap_ExternSymbol,
                       ap_FunctionSymbol);
}

probe thread
{
   probe "MyFunction"
   {
      on_entry
      {
         ap_RaiseGnatExceptionBySymbol(
             (ap_ThreadContextPtr,  
              ap_ExecutionContextPtr,             
              ap_ProbeActionReason,                  
              ap_FunctionId,                     
              ap_Offset,
              sid,
              (ap_nameT)"reason");
      }
   }
}


GCC C++

To raise an exception in GCC C++ use one of the following in your probe:

  ap_ThrowGccString(S)
  ap_ThrowGccExceptionObject(N,O,M)

The first for allows you to throw string constant (char cnst*).

   probe thread
   {
      probe "my function"
      {
         on_entry
         {
            ap_ThrowGccString("MyErrorString"):
         }
      }
   }

The second form allows you to throw a general static C++ object.

NOTE: If you use the -q min_heap option Aprobe throws away symbol info after program initialization. In this case the exception symbol must be found by name at program initialization, not at the point of the raise. You must resolve the exception symbol at program start-up and use ap_ThrowGccException() found in $APROBE/include/aprobe.h.