DEBINIT Example

Shows a sample DEBINIT program.
/* Compile on Windows using:  mfplx -dll -deb -defext debinit.pli */
/* Compile on Linux using: mfplx -dll -deb -defext debinit.pli -o debinit.so */ 

DEBINIT: proc(str);

  dcl str char(*);

  /* Variables for PLICTF */  
  dcl  EVENT_ERROR     fixed bin(31) static init(1000);
  dcl  LEVEL_DEBUG               fixed bin(31) static init(0);
  dcl  LEVEL_INFO                fixed bin(31) static init(1);
  dcl  LEVEL_WARNING             fixed bin(31) static init(2);
  dcl  LEVEL_ERROR               fixed bin(31) static init(3);
  dcl  TRACE_FLAGS_ALL           fixed bin(31) static init(-1);
  dcl  error_msg                 char(300) varying;
  
  /* Variables for Memory Validation */
  DCL _MFP_MEMVALID    entry(fixed bin(31) value, *) 
         returns(fixed bin(31)) options(nodescriptor);
      
  dcl  01 mem_validate_param,       
          05  cblte_mv_version   fixed bin(31) init(0), 
          05  cblte_mv_flags     fixed bin(31) init(0), 
          05  cblte_mv_type      fixed bin(31) init(0), 
          05  cblte_mv_size      fixed bin(31) init(0), 
          05  cblte_mv_address   poinTer init(NULL);                                                                                                                                              
  dcl  ret           fixed bin(31);

  
  on error
     begin;
       on error system;
       error_msg = "DEBINIT Error: " || trim(str) || ' :' ||  oncode();
       call PLICTF(EVENT_ERROR, LEVEL_ERROR, TRACE_FLAGS_ALL, error_msg, length(error_msg));     
       /* Continue processing   */
       /* don't want to take down user code because of bad initcall code! */       
       goto end_debcall;  
     end;

      ret = _MFP_MEMVALID(3, mem_validate_param);
      if (ret = 1000) then
        do;
          error_msg = "Memory Corruption detected: " || trim(str) || ' :' ||  hex(cblte_mv_address);        
          call PLICTF(EVENT_ERROR, LEVEL_ERROR, TRACE_FLAGS_ALL, error_msg, length(error_msg));               
        end;
  
  end_debcall:
end;