OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [coremaker.c] - Diff between revs 107 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 107 Rev 1765
/* Simple little program that just generates a core dump from inside some
/* Simple little program that just generates a core dump from inside some
   nested function calls. */
   nested function calls. */
 
 
#include <stdio.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/types.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <signal.h>
#include <signal.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
 
 
#ifndef __STDC__
#ifndef __STDC__
#define const   /**/
#define const   /**/
#endif
#endif
 
 
#define MAPSIZE (8 * 1024)
#define MAPSIZE (8 * 1024)
 
 
/* Don't make these automatic vars or we will have to walk back up the
/* Don't make these automatic vars or we will have to walk back up the
   stack to access them. */
   stack to access them. */
 
 
char *buf1;
char *buf1;
char *buf2;
char *buf2;
 
 
int coremaker_data = 1; /* In Data section */
int coremaker_data = 1; /* In Data section */
int coremaker_bss;      /* In BSS section */
int coremaker_bss;      /* In BSS section */
 
 
const int coremaker_ro = 201;   /* In Read-Only Data section */
const int coremaker_ro = 201;   /* In Read-Only Data section */
 
 
/* Note that if the mapping fails for any reason, we set buf2
/* Note that if the mapping fails for any reason, we set buf2
   to -1 and the testsuite notices this and reports it as
   to -1 and the testsuite notices this and reports it as
   a failure due to a mapping error.  This way we don't have
   a failure due to a mapping error.  This way we don't have
   to test for specific errors when running the core maker. */
   to test for specific errors when running the core maker. */
 
 
void
void
mmapdata ()
mmapdata ()
{
{
  int j, fd;
  int j, fd;
 
 
  /* Allocate and initialize a buffer that will be used to write
  /* Allocate and initialize a buffer that will be used to write
     the file that is later mapped in. */
     the file that is later mapped in. */
 
 
  buf1 = (char *) malloc (MAPSIZE);
  buf1 = (char *) malloc (MAPSIZE);
  for (j = 0; j < MAPSIZE; ++j)
  for (j = 0; j < MAPSIZE; ++j)
    {
    {
      buf1[j] = j;
      buf1[j] = j;
    }
    }
 
 
  /* Write the file to map in */
  /* Write the file to map in */
 
 
  fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
  fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
  if (fd == -1)
  if (fd == -1)
    {
    {
      perror ("coremmap.data open failed");
      perror ("coremmap.data open failed");
      buf2 = (char *) -1;
      buf2 = (char *) -1;
      return;
      return;
    }
    }
  write (fd, buf1, MAPSIZE);
  write (fd, buf1, MAPSIZE);
 
 
  /* Now map the file into our address space as buf2 */
  /* Now map the file into our address space as buf2 */
 
 
  buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  if (buf2 == (char *) -1)
  if (buf2 == (char *) -1)
    {
    {
      perror ("mmap failed");
      perror ("mmap failed");
      return;
      return;
    }
    }
 
 
  /* Verify that the original data and the mapped data are identical.
  /* Verify that the original data and the mapped data are identical.
     If not, we'd rather fail now than when trying to access the mapped
     If not, we'd rather fail now than when trying to access the mapped
     data from the core file. */
     data from the core file. */
 
 
  for (j = 0; j < MAPSIZE; ++j)
  for (j = 0; j < MAPSIZE; ++j)
    {
    {
      if (buf1[j] != buf2[j])
      if (buf1[j] != buf2[j])
        {
        {
          fprintf (stderr, "mapped data is incorrect");
          fprintf (stderr, "mapped data is incorrect");
          buf2 = (char *) -1;
          buf2 = (char *) -1;
          return;
          return;
        }
        }
    }
    }
}
}
 
 
void
void
func2 ()
func2 ()
{
{
  int coremaker_local[5];
  int coremaker_local[5];
  int i;
  int i;
 
 
#ifdef SA_FULLDUMP
#ifdef SA_FULLDUMP
  /* Force a corefile that includes the data section for AIX.  */
  /* Force a corefile that includes the data section for AIX.  */
  {
  {
    struct sigaction sa;
    struct sigaction sa;
 
 
    sigaction (SIGABRT, (struct sigaction *)0, &sa);
    sigaction (SIGABRT, (struct sigaction *)0, &sa);
    sa.sa_flags |= SA_FULLDUMP;
    sa.sa_flags |= SA_FULLDUMP;
    sigaction (SIGABRT, &sa, (struct sigaction *)0);
    sigaction (SIGABRT, &sa, (struct sigaction *)0);
  }
  }
#endif
#endif
 
 
  /* Make sure that coremaker_local doesn't get optimized away. */
  /* Make sure that coremaker_local doesn't get optimized away. */
  for (i = 0; i < 5; i++)
  for (i = 0; i < 5; i++)
    coremaker_local[i] = i;
    coremaker_local[i] = i;
  coremaker_bss = 0;
  coremaker_bss = 0;
  for (i = 0; i < 5; i++)
  for (i = 0; i < 5; i++)
    coremaker_bss += coremaker_local[i];
    coremaker_bss += coremaker_local[i];
  coremaker_data = coremaker_ro + 1;
  coremaker_data = coremaker_ro + 1;
  abort ();
  abort ();
}
}
 
 
void
void
func1 ()
func1 ()
{
{
  func2 ();
  func2 ();
}
}
 
 
int main ()
int main ()
{
{
  mmapdata ();
  mmapdata ();
  func1 ();
  func1 ();
  return 0;
  return 0;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.