~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpcom/reflect/xptcall/src/md/unix/vtable_layout_x86.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* this code contributed by Bert Driehuis <bert_driehuis@nl.compuware.com> */
 
2
 
 
3
#include <stdio.h>
 
4
 
 
5
// Try to determine the vtable layout generated by G++
 
6
// Produces the offset at which the first vtable entry can be
 
7
// found, and the factor to apply for subsequent entries on stdout.
 
8
// Example output:
 
9
//    #define GCC_VTABLE_START        0xc
 
10
//    #define GCC_VTABLE_FACTOR       0x8
 
11
 
 
12
class test {
 
13
public:
 
14
      virtual int     t1(void);
 
15
      virtual int     t2(void);
 
16
      int             x;
 
17
};
 
18
 
 
19
test::test() { this->x = 0x12121212; };
 
20
 
 
21
int test::t1(void) { return 1; }
 
22
int test::t2(void) { return 2; }
 
23
 
 
24
void die(char *x) {
 
25
      fprintf(stderr, "%s\n", x);
 
26
      exit(1);
 
27
}
 
28
 
 
29
int 
 
30
main()
 
31
{
 
32
      int             i;
 
33
      test           *t = new test();
 
34
      int            *tp = (int *) t;
 
35
      int             off1 = -1;
 
36
      int             off2 = -1;
 
37
      int             factor;
 
38
      int             factorshift;
 
39
 
 
40
      if (*tp++ != 0x12121212)
 
41
              die("Integer element test::x not found!");
 
42
      tp = (int *) *tp;
 
43
      for (i = 0; i < 10; i++) {
 
44
              if (tp[i] == (int) t->t1)
 
45
                      off1 = i;
 
46
              if (tp[i] == (int) t->t2)
 
47
                      off2 = i;
 
48
      }
 
49
      if (off1 == -1 || off2 == -1)
 
50
              die("Could not determine offset into vtable!");
 
51
      factor = (off2 - off1) * 4;
 
52
      factorshift = -1;
 
53
      while (factor) {
 
54
              factorshift++;
 
55
              factor >>= 1;
 
56
      }
 
57
      printf("/* Automatically generated by vtable_layout_x86.cpp */\n");
 
58
      printf("#define GCC_VTABLE_START\t0x%x\n", off1 * 4);
 
59
      printf("#define GCC_VTABLE_FACTOR\t0x%x\n", (off2 - off1) * 4);
 
60
      printf("#define GCC_VTABLE_SHIFT\t0x%x\n", factorshift);
 
61
      exit(0);
 
62
}