Sample C routine that calls cdump()

Figure 1 shows a sample C routine that uses the cdump function to generate a dump. Figure 1 shows the dump output.

Figure 1. Example C routine using cdump() to generate a dump (AMODE 64) (Part 1 of 2)
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>

void hsigfpe(int);
void hsigterm(int);
void atf1(void);

typedef int (*FuncPtr_T)(void);

int st1    =  99;
int st2    = 255;
int xcount =   0;

int main(void) {
  /*
   * 1) Open multiple files
   * 2) Register 2 signals
   * 3) Register 1 atexit function
   * 4) Fetch and execute a module
   */

  FuncPtr_T fetchPtr;
  FILE*     fp1;
  FILE*     fp2;
  int       rc;
  fp1 = fopen("myfile.data", "w");
  if (!fp1) {
    perror("Could not open myfile.data for write");
    exit(101);
  }

  fprintf(fp1, "record 1\n");
  fprintf(fp1, "record 2\n");
  fprintf(fp1, "record 3\n");

  fp2 = fopen("memory.data", "wb,type=memory");
  if (!fp2) {
    perror("Could not open memory.data for write");
    exit(102);
  }
  fprintf(fp2, "some data");
  fprintf(fp2, "some more data");
  fprintf(fp2, "even more data");

  signal(SIGFPE , hsigfpe);
  signal(SIGTERM, hsigterm);

  rc = atexit(atf1);
  if (rc) {
    fprintf(stderr, "Failed on registration of atexit function atf1\n");
    exit(103);
  }
  fetchPtr = (FuncPtr_T) fetch("MODULE1");
  if (!fetchPtr) {
    fprintf(stderr, "Failed to fetch MODULE1\n");
    exit(104);
  }
  fetchPtr();
  return(0);
}
Figure 2. Example C routine using cdump() to generate a dump (AMODE 64) (Part 2 of 2)
void hsigfpe(int sig) {
  ++st1;
  return;
}

void hsigterm(int sig) {
  ++st2;
  return;
}

void atf1() {
  ++xcount;
}

Figure 3 shows a fetched C module.

Figure 3. Fetched module for C routine (AMODE 64)
#include <ctest.h>

#pragma linkage(func1, fetchable)
int func1(void) {
  __cdump("This is a sample dump");
  return(0);
}