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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [coremaker.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* Simple little program that just generates a core dump from inside some
2
   nested function calls. */
3
 
4
#include <stdio.h>
5
#include <sys/types.h>
6
#include <fcntl.h>
7
#include <sys/mman.h>
8
#include <signal.h>
9
#include <stdlib.h>
10
#include <unistd.h>
11
 
12
#ifndef __STDC__
13
#define const   /**/
14
#endif
15
 
16
#define MAPSIZE (8 * 1024)
17
 
18
/* Don't make these automatic vars or we will have to walk back up the
19
   stack to access them. */
20
 
21
char *buf1;
22
char *buf2;
23
 
24
int coremaker_data = 1; /* In Data section */
25
int coremaker_bss;      /* In BSS section */
26
 
27
const int coremaker_ro = 201;   /* In Read-Only Data section */
28
 
29
/* Note that if the mapping fails for any reason, we set buf2
30
   to -1 and the testsuite notices this and reports it as
31
   a failure due to a mapping error.  This way we don't have
32
   to test for specific errors when running the core maker. */
33
 
34
void
35
mmapdata ()
36
{
37
  int j, fd;
38
 
39
  /* Allocate and initialize a buffer that will be used to write
40
     the file that is later mapped in. */
41
 
42
  buf1 = (char *) malloc (MAPSIZE);
43
  for (j = 0; j < MAPSIZE; ++j)
44
    {
45
      buf1[j] = j;
46
    }
47
 
48
  /* Write the file to map in */
49
 
50
  fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
51
  if (fd == -1)
52
    {
53
      perror ("coremmap.data open failed");
54
      buf2 = (char *) -1;
55
      return;
56
    }
57
  write (fd, buf1, MAPSIZE);
58
 
59
  /* Now map the file into our address space as buf2 */
60
 
61
  buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
62
  if (buf2 == (char *) -1)
63
    {
64
      perror ("mmap failed");
65
      return;
66
    }
67
 
68
  /* Verify that the original data and the mapped data are identical.
69
     If not, we'd rather fail now than when trying to access the mapped
70
     data from the core file. */
71
 
72
  for (j = 0; j < MAPSIZE; ++j)
73
    {
74
      if (buf1[j] != buf2[j])
75
        {
76
          fprintf (stderr, "mapped data is incorrect");
77
          buf2 = (char *) -1;
78
          return;
79
        }
80
    }
81
}
82
 
83
void
84
func2 ()
85
{
86
  int coremaker_local[5];
87
  int i;
88
 
89
#ifdef SA_FULLDUMP
90
  /* Force a corefile that includes the data section for AIX.  */
91
  {
92
    struct sigaction sa;
93
 
94
    sigaction (SIGABRT, (struct sigaction *)0, &sa);
95
    sa.sa_flags |= SA_FULLDUMP;
96
    sigaction (SIGABRT, &sa, (struct sigaction *)0);
97
  }
98
#endif
99
 
100
  /* Make sure that coremaker_local doesn't get optimized away. */
101
  for (i = 0; i < 5; i++)
102
    coremaker_local[i] = i;
103
  coremaker_bss = 0;
104
  for (i = 0; i < 5; i++)
105
    coremaker_bss += coremaker_local[i];
106
  coremaker_data = coremaker_ro + 1;
107
  abort ();
108
}
109
 
110
void
111
func1 ()
112
{
113
  func2 ();
114
}
115
 
116
int main ()
117
{
118
  mmapdata ();
119
  func1 ();
120
  return 0;
121
}
122
 

powered by: WebSVN 2.1.0

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