annotate src/dumper.c @ 647:b39c14581166

[xemacs-hg @ 2001-08-13 04:45:47 by ben] removal of unsigned, size_t, etc.
author ben
date Mon, 13 Aug 2001 04:46:48 +0000
parents 8d7292eb4a18
children fdefd0186b75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1 /* Portable data dumper for XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
2 Copyright (C) 1999-2000 Olivier Galibert
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
3 Copyright (C) 2001 Martin Buchholz
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
4
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5 This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
10 later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15 for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24 #include <config.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
25 #include "lisp.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
26
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
27 #include "specifier.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
28 #include "elhash.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29 #include "sysfile.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 #include "console-stream.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
31 #include "dumper.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34 #include "nt.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36 #ifdef HAVE_MMAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37 #include <sys/mman.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
38 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
39 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
40
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41 #ifndef SEPCHAR
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 #define SEPCHAR ':'
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
43 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
44
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
45 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
46 {
545
9a775fb11bb7 [xemacs-hg @ 2001-05-18 04:39:39 by kkm]
kkm
parents: 462
diff changeset
47 const void *varaddress;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
48 Memory_Count size;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
49 } pdump_opaque;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
50
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
51 typedef struct
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
52 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
53 Dynarr_declare (pdump_opaque);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
54 } pdump_opaque_dynarr;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
55
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
56 typedef struct
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
57 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
58 void **ptraddress;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
59 const struct struct_description *desc;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
60 } pdump_root_struct_ptr;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
61
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
62 typedef struct
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
63 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
64 Dynarr_declare (pdump_root_struct_ptr);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
65 } pdump_root_struct_ptr_dynarr;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
66
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
67 typedef struct
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
68 {
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
69 Lisp_Object *address;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
70 Lisp_Object value;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
71 } pdump_static_Lisp_Object;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
72
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
73 typedef struct
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
74 {
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
75 char **address; /* char * for ease of doing relocation */
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
76 char * value;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
77 } pdump_static_pointer;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
78
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
79 static pdump_opaque_dynarr *pdump_opaques;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
80 static pdump_root_struct_ptr_dynarr *pdump_root_struct_ptrs;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
81 static Lisp_Object_ptr_dynarr *pdump_root_objects;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
82 static Lisp_Object_ptr_dynarr *pdump_weak_object_chains;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
83
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
84 /* Mark SIZE bytes at non-heap address VARADDRESS for dumping as is,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
85 without any bit-twiddling. */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
86 void
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
87 dump_add_opaque (const void *varaddress, Memory_Count size)
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
88 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
89 pdump_opaque info;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
90 info.varaddress = varaddress;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
91 info.size = size;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
92 if (pdump_opaques == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
93 pdump_opaques = Dynarr_new (pdump_opaque);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
94 Dynarr_add (pdump_opaques, info);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
95 }
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
96
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
97 /* Mark the struct described by DESC and pointed to by the pointer at
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
98 non-heap address VARADDRESS for dumping.
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
99 All the objects reachable from this pointer will also be dumped. */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
100 void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
101 dump_add_root_struct_ptr (void *ptraddress, const struct struct_description *desc)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
102 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
103 pdump_root_struct_ptr info;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
104 info.ptraddress = (void **) ptraddress;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
105 info.desc = desc;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
106 if (pdump_root_struct_ptrs == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
107 pdump_root_struct_ptrs = Dynarr_new (pdump_root_struct_ptr);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
108 Dynarr_add (pdump_root_struct_ptrs, info);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
109 }
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
110
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
111 /* Mark the Lisp_Object at non-heap address VARADDRESS for dumping.
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
112 All the objects reachable from this var will also be dumped. */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
113 void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
114 dump_add_root_object (Lisp_Object *varaddress)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
115 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
116 if (pdump_root_objects == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
117 pdump_root_objects = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
118 Dynarr_add (pdump_root_objects, varaddress);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
119 }
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
120
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
121 /* Mark the list pointed to by the Lisp_Object at VARADDRESS for dumping. */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
122 void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
123 dump_add_weak_object_chain (Lisp_Object *varaddress)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
124 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
125 if (pdump_weak_object_chains == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
126 pdump_weak_object_chains = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
127 Dynarr_add (pdump_weak_object_chains, varaddress);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
128 }
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
129
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
130
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
131 inline static void
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
132 pdump_align_stream (FILE *stream, Memory_Count alignment)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
133 {
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
134 long offset = ftell (stream);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
135 long adjustment = ALIGN_SIZE (offset, alignment) - offset;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
136 if (adjustment)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
137 fseek (stream, adjustment, SEEK_CUR);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
138 }
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
139
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
140 #define PDUMP_ALIGN_OUTPUT(type) pdump_align_stream (pdump_out, ALIGNOF (type))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
141
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
142 #define PDUMP_WRITE(type, object) \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
143 fwrite (&object, sizeof (object), 1, pdump_out);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
144
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
145 #define PDUMP_WRITE_ALIGNED(type, object) do { \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
146 PDUMP_ALIGN_OUTPUT (type); \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
147 PDUMP_WRITE (type, object); \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
148 } while (0)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
149
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
150 #define PDUMP_READ(ptr, type) \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
151 (((type *) (ptr = (char*) (((type *) ptr) + 1)))[-1])
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
152
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
153 #define PDUMP_READ_ALIGNED(ptr, type) \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
154 ((ptr = (char *) ALIGN_PTR (ptr, ALIGNOF (type))), PDUMP_READ (ptr, type))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
155
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
156
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
157
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
158 typedef struct
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
159 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
160 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162 } pdump_reloc_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164 static char *pdump_rt_list = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167 pdump_objects_unmark (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
169 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 char *p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171 if (p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
172 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
173 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174 pdump_reloc_table *rt = (pdump_reloc_table *)p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175 p += sizeof (pdump_reloc_table);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 if (rt->desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 for (i=0; i<rt->count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
179 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
180 struct lrecord_header *lh = * (struct lrecord_header **) p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181 if (! C_READONLY_RECORD_HEADER_P (lh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 UNMARK_RECORD_HEADER (lh);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183 p += sizeof (EMACS_INT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
184 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
185 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
186 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
187 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
188 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
189
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
190
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
191 /* The structure of the file
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
192 0 - header
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
193 - dumped objects
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
194 stab_offset - nb_root_struct_ptrs*pair(void *, adr)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
195 for pointers to structures
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
196 - nb_opaques*pair(void *, size) for raw bits to restore
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
197 - relocation table
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
198 - root lisp object address/value couples with the count
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
199 preceding the list
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
200 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
201
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
202
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
203 #define PDUMP_SIGNATURE "XEmacsDP"
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
204 #define PDUMP_SIGNATURE_LEN (sizeof (PDUMP_SIGNATURE) - 1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
205
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
206 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
207 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
208 char signature[PDUMP_SIGNATURE_LEN];
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
209 unsigned int id;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
210 EMACS_UINT stab_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
211 EMACS_UINT reloc_address;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
212 int nb_root_struct_ptrs;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
213 int nb_opaques;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
214 } pdump_header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
215
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
216 char *pdump_start;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
217 char *pdump_end;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
218 static Memory_Count pdump_length;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
219
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
220 #ifdef WIN32_NATIVE
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
221 /* Handle for the dump file */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
222 static HANDLE pdump_hFile = INVALID_HANDLE_VALUE;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
223 /* Handle for the file mapping object for the dump file */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
224 static HANDLE pdump_hMap = INVALID_HANDLE_VALUE;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
225 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
226
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
227 static void (*pdump_free) (void);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
228
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
229 static unsigned char pdump_align_table[] =
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
230 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
231 64, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
232 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
233 32, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
234 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
235 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
236
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
237 static inline int
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
238 pdump_size_to_align (Memory_Count size)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
239 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
240 return pdump_align_table[size % countof (pdump_align_table)];
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
241 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
242
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
243 typedef struct pdump_entry_list_elt
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
244 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
245 struct pdump_entry_list_elt *next;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
246 const void *obj;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
247 Memory_Count size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
248 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 EMACS_INT save_offset;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
250 } pdump_entry_list_elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
251
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
252 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
253 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
254 pdump_entry_list_elt *first;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
255 int align;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
256 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
257 } pdump_entry_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
258
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
259 typedef struct pdump_struct_list_elt
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
260 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
261 pdump_entry_list list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
262 const struct struct_description *sdesc;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
263 } pdump_struct_list_elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
264
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
265 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
266 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
267 pdump_struct_list_elt *list;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
268 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
269 int size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
270 } pdump_struct_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
271
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
272 static pdump_entry_list *pdump_object_table;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
273 static pdump_entry_list pdump_opaque_data_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
274 static pdump_struct_list pdump_struct_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
275
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
276 static int *pdump_alert_undump_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
277
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
278 static unsigned long cur_offset;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
279 static Memory_Count max_size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
280 static int pdump_fd;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
281 static void *pdump_buf;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
282 static FILE *pdump_out;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
283
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
284 #define PDUMP_HASHSIZE 200001
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
285
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
286 static pdump_entry_list_elt **pdump_hash;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
287
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288 /* Since most pointers are eight bytes aligned, the >>3 allows for a better hash */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
289 static int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
290 pdump_make_hash (const void *obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
291 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
292 return ((unsigned long)(obj)>>3) % PDUMP_HASHSIZE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
294
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
295 static pdump_entry_list_elt *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
296 pdump_get_entry (const void *obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
297 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
298 int pos = pdump_make_hash (obj);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
299 pdump_entry_list_elt *e;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
300
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
301 assert (obj != 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
302
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
303 while ((e = pdump_hash[pos]) != 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
304 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
305 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
306 return e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
307
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
308 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
309 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
310 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
311 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
312 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
313 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
314
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
315 static void
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
316 pdump_add_entry (pdump_entry_list *list, const void *obj, Memory_Count size,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
317 int count)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
318 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
319 pdump_entry_list_elt *e;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
320 int pos = pdump_make_hash (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
321
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
322 while ((e = pdump_hash[pos]) != 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
323 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
324 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
325 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
326
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
327 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
328 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
329 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
330 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
331
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
332 e = xnew (pdump_entry_list_elt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
333
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
334 e->next = list->first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
335 e->obj = obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
336 e->size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
337 e->count = count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
338 list->first = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
339
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
340 list->count += count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
341 pdump_hash[pos] = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
342
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
343 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
344 int align = pdump_size_to_align (size);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
345
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
346 if (align < list->align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
347 list->align = align;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
348 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
349 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
350
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
351 static pdump_entry_list *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
352 pdump_get_entry_list (const struct struct_description *sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
353 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
354 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
355 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
356 if (pdump_struct_table.list[i].sdesc == sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
357 return &pdump_struct_table.list[i].list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
358
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
359 if (pdump_struct_table.size <= pdump_struct_table.count)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
360 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
361 if (pdump_struct_table.size == -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
362 pdump_struct_table.size = 10;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
363 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
364 pdump_struct_table.size = pdump_struct_table.size * 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
365 pdump_struct_table.list = (pdump_struct_list_elt *)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
366 xrealloc (pdump_struct_table.list,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
367 pdump_struct_table.size * sizeof (pdump_struct_list_elt));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
368 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
369 pdump_struct_table.list[pdump_struct_table.count].list.first = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
370 pdump_struct_table.list[pdump_struct_table.count].list.align = ALIGNOF (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
371 pdump_struct_table.list[pdump_struct_table.count].list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
372 pdump_struct_table.list[pdump_struct_table.count].sdesc = sdesc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
373
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
374 return &pdump_struct_table.list[pdump_struct_table.count++].list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
375 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
376
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
377 static struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
378 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
379 struct lrecord_header *obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
380 int position;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
381 int offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
382 } backtrace[65536];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
383
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
384 static int depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
385
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
386 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
387 pdump_backtrace (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
388 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
389 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
390 stderr_out ("pdump backtrace :\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
391 for (i=0;i<depth;i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
392 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
393 if (!backtrace[i].obj)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
394 stderr_out (" - ind. (%d, %d)\n",
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
395 backtrace[i].position,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
396 backtrace[i].offset);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
397 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
398 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
399 stderr_out (" - %s (%d, %d)\n",
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
400 LHEADER_IMPLEMENTATION (backtrace[i].obj)->name,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
401 backtrace[i].position,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
402 backtrace[i].offset);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
403 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
404 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
405 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
406
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
407 static void pdump_register_object (Lisp_Object obj);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
408 static void pdump_register_struct (const void *data,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
409 const struct struct_description *sdesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
410 int count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
411
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
412 static EMACS_INT
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
413 pdump_get_indirect_count (EMACS_INT code,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
414 const struct lrecord_description *idesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
415 const void *idata)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
416 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
417 EMACS_INT count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
418 const void *irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
419
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
420 int line = XD_INDIRECT_VAL (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
421 int delta = XD_INDIRECT_DELTA (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
422
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
423 irdata = ((char *)idata) + idesc[line].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
424 switch (idesc[line].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
425 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
426 case XD_MEMORY_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
427 count = *(Memory_Count *)irdata;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
428 break;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
429 case XD_ELEMENT_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
430 count = *(Element_Count *)irdata;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
431 break;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
432 case XD_HASH_CODE:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
433 count = *(Hash_Code *)irdata;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
434 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
435 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
436 count = *(int *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
437 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
438 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
439 count = *(long *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
440 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
441 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
442 count = *(Bytecount *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
443 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
444 default:
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
445 stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n",
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
446 idesc[line].type, line, (long)code);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
447 pdump_backtrace ();
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
448 count = 0; /* warning suppression */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
449 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
450 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
451 count += delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
452 return count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
453 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
454
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
455 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
456 pdump_register_sub (const void *data, const struct lrecord_description *desc, int me)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
457 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
459
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
460 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
462 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
463 const void *rdata = (const char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
464
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
465 backtrace[me].position = pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
466 backtrace[me].offset = desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
467
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
468 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
469 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
470 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
471 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
472 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
473 goto restart;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
474 case XD_MEMORY_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
475 case XD_ELEMENT_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
476 case XD_HASH_CODE:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
477 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
478 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
479 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
480 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
481 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
482 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
483 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
484 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
485 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
486 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
487 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
488
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
489 pdump_add_entry (&pdump_opaque_data_list,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
490 *(void **)rdata, count, 1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
491 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
492 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
493 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
494 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
495 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
496 if (str)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
497 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
498 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
499 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
500 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
501 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
503 if ((EMACS_INT)str > 0)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
504 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
508 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
509 const Lisp_Object *pobj = (const Lisp_Object *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
510
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
511 assert (desc[pos].data1 == 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
512
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
513 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
514 pdump_register_object (*pobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
515 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
516 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
517 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
518 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
519 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
520 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
521 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
522 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
523
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
524 for (i = 0; i < count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
525 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
526 const Lisp_Object *pobj = ((const Lisp_Object *)rdata) + i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
527 Lisp_Object dobj = *pobj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
528
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
529 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
530 pdump_register_object (dobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
531 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
532 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
533 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
534 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
535 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
536 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
537 const struct struct_description *sdesc = desc[pos].data2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
538 const char *dobj = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
539 if (dobj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
540 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
543
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
544 pdump_register_struct (dobj, sdesc, count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
545 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
546 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
547 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
552 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
553 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
554 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
555
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
556 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
557 pdump_register_object (Lisp_Object obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
558 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
559 struct lrecord_header *objh;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
560 const struct lrecord_implementation *imp;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
561
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
562 if (!POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
563 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
564
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
565 objh = XRECORD_LHEADER (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
566 if (!objh)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
567 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
568
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
569 if (pdump_get_entry (objh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
570 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
571
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
572 imp = LHEADER_IMPLEMENTATION (objh);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
573
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
574 if (imp->description)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
575 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
576 int me = depth++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
577 if (me>65536)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
578 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
579 stderr_out ("Backtrace overflow, loop ?\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
580 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
581 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
582 backtrace[me].obj = objh;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
583 backtrace[me].position = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
584 backtrace[me].offset = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
585
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
586 pdump_add_entry (pdump_object_table + objh->type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
587 objh,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
588 imp->static_size ?
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
589 imp->static_size :
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
590 imp->size_in_bytes_method (objh),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
591 1);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
592 pdump_register_sub (objh, imp->description, me);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
593 --depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
594 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
595 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
596 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
597 pdump_alert_undump_object[objh->type]++;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
598 stderr_out ("Undumpable object type : %s\n", imp->name);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
599 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
600 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
601 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
602
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
603 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
604 pdump_register_struct (const void *data,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
605 const struct struct_description *sdesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
606 int count)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
607 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
608 if (data && !pdump_get_entry (data))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
609 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
610 int me = depth++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
611 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
612 if (me>65536)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
613 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
614 stderr_out ("Backtrace overflow, loop ?\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
615 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
616 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
617 backtrace[me].obj = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
618 backtrace[me].position = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
619 backtrace[me].offset = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
620
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
621 pdump_add_entry (pdump_get_entry_list (sdesc),
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
622 data, sdesc->size, count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
623 for (i=0; i<count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
624 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
625 pdump_register_sub (((char *)data) + sdesc->size*i,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
626 sdesc->description,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
627 me);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
628 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
629 --depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
630 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
631 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
632
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
633 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
634 pdump_dump_data (pdump_entry_list_elt *elt,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
635 const struct lrecord_description *desc)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
636 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
637 Memory_Count size = elt->size;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
638 int count = elt->count;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
639 if (desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
640 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
641 int pos, i;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
642 memcpy (pdump_buf, elt->obj, size*count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
643
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
644 for (i=0; i<count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
645 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
646 char *cur = ((char *)pdump_buf) + i*size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
647 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
648 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
649 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
650 void *rdata = cur + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
651 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
652 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
653 case XD_SPECIFIER_END:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
654 desc = ((const Lisp_Specifier *)(elt->obj))->methods->extra_description;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
655 goto restart;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
656 case XD_MEMORY_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
657 case XD_ELEMENT_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
658 case XD_HASH_CODE:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
659 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
660 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
661 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
662 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
663 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
664 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
665 EMACS_INT val = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
666 if (XD_IS_INDIRECT (val))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
667 val = pdump_get_indirect_count (val, desc, elt->obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
668 *(int *)rdata = val;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
669 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
670 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
671 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
672 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
673 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
674 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
675 void *ptr = *(void **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
676 if (ptr)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
677 *(EMACS_INT *)rdata = pdump_get_entry (ptr)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
678 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
679 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
680 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
681 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
682 Lisp_Object obj = *(Lisp_Object *)rdata;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
683 pdump_entry_list_elt *elt1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
684 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
685 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
686 elt1 = pdump_get_entry (XRECORD_LHEADER (obj));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
687 if (elt1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
688 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
689 obj = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
690 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
691 *(EMACS_INT *)rdata = elt1->save_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
692 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
693 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
694 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
695 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
696 Lisp_Object *pobj = (Lisp_Object *) rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
697
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
698 assert (desc[pos].data1 == 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
699
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
700 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
701 *(EMACS_INT *)pobj =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
702 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
703 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
704 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
705 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
706 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
707 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
708 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
709 if (XD_IS_INDIRECT (num))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
710 num = pdump_get_indirect_count (num, desc, elt->obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
711
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
712 for (j=0; j<num; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
713 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
714 Lisp_Object *pobj = ((Lisp_Object *)rdata) + j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
715 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
716 *(EMACS_INT *)pobj =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
717 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
718 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
719 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
720 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
721 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
722 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
723 EMACS_INT str = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
724 if (str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
725 *(EMACS_INT *)rdata = pdump_get_entry ((void *)str)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
726 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
727 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
728 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
729 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
730 abort ();
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
731 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
732 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
733 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
734 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
735 fwrite (desc ? pdump_buf : elt->obj, size, count, pdump_out);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
736 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
737
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
738 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
739 pdump_reloc_one (void *data, EMACS_INT delta,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
740 const struct lrecord_description *desc)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
741 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
742 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
743
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
744 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
745 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
746 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
747 void *rdata = (char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
748 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
749 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
750 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
751 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
752 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
753 goto restart;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
754 case XD_MEMORY_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
755 case XD_ELEMENT_COUNT:
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
756 case XD_HASH_CODE:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
757 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
758 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
759 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
760 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
761 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
762 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
763 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
764 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
765 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
766 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
767 EMACS_INT ptr = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
768 if (ptr)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
769 *(EMACS_INT *)rdata = ptr+delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
770 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
771 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
772 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
773 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
774 Lisp_Object *pobj = (Lisp_Object *) rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
775
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
776 assert (desc[pos].data1 == 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
777
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
778 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
779 && ! EQ (*pobj, Qnull_pointer))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
780 XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
781
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
782 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
783 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
784 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
785 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
786 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
787 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
788 if (XD_IS_INDIRECT (num))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
789 num = pdump_get_indirect_count (num, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
790
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
791 for (j=0; j<num; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
792 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
793 Lisp_Object *pobj = (Lisp_Object *) rdata + j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
794
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
795 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
796 && ! EQ (*pobj, Qnull_pointer))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
797 XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
798 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
799 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
800 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
801 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
802 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
803 EMACS_INT str = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
804 if (str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
805 *(EMACS_INT *)rdata = str + delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
806 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
807 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
808 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
809 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
810 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
811 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
812 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
813 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
814
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
815 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
816 pdump_allocate_offset (pdump_entry_list_elt *elt,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
817 const struct lrecord_description *desc)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
818 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
819 Memory_Count size = elt->count * elt->size;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
820 elt->save_offset = cur_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
821 if (size>max_size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
822 max_size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
823 cur_offset += size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
824 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
825
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
826 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
827 pdump_scan_by_alignment (void (*f)(pdump_entry_list_elt *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
828 const struct lrecord_description *))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
829 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
830 int align;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
831
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
832 for (align = ALIGNOF (max_align_t); align; align>>=1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
833 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
834 int i;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
835 pdump_entry_list_elt *elt;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
836
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
837 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
838 if (pdump_object_table[i].align == align)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
839 for (elt = pdump_object_table[i].first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
840 f (elt, lrecord_implementations_table[i]->description);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
841
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
842 for (i=0; i<pdump_struct_table.count; i++)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
843 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
844 pdump_struct_list_elt list = pdump_struct_table.list[i];
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
845 if (list.list.align == align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
846 for (elt = list.list.first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
847 f (elt, list.sdesc->description);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
848 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
849
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
850 for (elt = pdump_opaque_data_list.first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
851 if (pdump_size_to_align (elt->size) == align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
852 f (elt, 0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
853 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
854 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
855
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
856 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
857 pdump_dump_root_struct_ptrs (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
858 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
859 int i;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
860 Element_Count count = Dynarr_length (pdump_root_struct_ptrs);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
861 pdump_static_pointer *data = alloca_array (pdump_static_pointer, count);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
862 for (i = 0; i < count; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
863 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
864 data[i].address = (char **) Dynarr_atp (pdump_root_struct_ptrs, i)->ptraddress;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
865 data[i].value = (char *) pdump_get_entry (* data[i].address)->save_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
866 }
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
867 PDUMP_ALIGN_OUTPUT (pdump_static_pointer);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
868 fwrite (data, sizeof (pdump_static_pointer), count, pdump_out);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
869 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
870
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
871 static void
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
872 pdump_dump_opaques (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
873 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
874 int i;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
875 for (i = 0; i < Dynarr_length (pdump_opaques); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
876 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
877 pdump_opaque *info = Dynarr_atp (pdump_opaques, i);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
878 PDUMP_WRITE_ALIGNED (pdump_opaque, *info);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
879 fwrite (info->varaddress, info->size, 1, pdump_out);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
880 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
881 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
882
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
883 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
884 pdump_dump_rtables (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
885 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
886 int i;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
887 pdump_entry_list_elt *elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
888 pdump_reloc_table rt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
889
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
890 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
891 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
892 elt = pdump_object_table[i].first;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
893 if (!elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
894 continue;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
895 rt.desc = lrecord_implementations_table[i]->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
896 rt.count = pdump_object_table[i].count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
897 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
898 while (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
899 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
900 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
901 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
902 elt = elt->next;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
903 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
904 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
905
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
906 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
907 rt.count = 0;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
908 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
909
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
910 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
911 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
912 elt = pdump_struct_table.list[i].list.first;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
913 rt.desc = pdump_struct_table.list[i].sdesc->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
914 rt.count = pdump_struct_table.list[i].list.count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
915 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
916 while (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
917 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
918 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
919 int j;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
920 for (j=0; j<elt->count; j++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
921 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
922 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
923 rdata += elt->size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
924 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
925 elt = elt->next;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
926 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
927 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
928 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
929 rt.count = 0;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
930 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
931 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
932
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
933 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
934 pdump_dump_root_objects (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
935 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
936 Element_Count count = (Dynarr_length (pdump_root_objects) +
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
937 Dynarr_length (pdump_weak_object_chains));
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
938 Element_Count i;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
939
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
940 PDUMP_WRITE_ALIGNED (Element_Count, count);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
941 PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
942
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
943 for (i = 0; i < Dynarr_length (pdump_root_objects); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
944 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
945 pdump_static_Lisp_Object obj;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
946 obj.address = Dynarr_at (pdump_root_objects, i);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
947 obj.value = * obj.address;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
948
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
949 if (POINTER_TYPE_P (XTYPE (obj.value)))
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
950 obj.value =
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
951 wrap_pointer_1 ((void *) pdump_get_entry (XRECORD_LHEADER
617
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 545
diff changeset
952 (obj.value))->save_offset);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
953
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
954 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
955 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
956
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
957 for (i=0; i<Dynarr_length (pdump_weak_object_chains); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
958 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
959 pdump_entry_list_elt *elt;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
960 pdump_static_Lisp_Object obj;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
961
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
962 obj.address = Dynarr_at (pdump_weak_object_chains, i);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
963 obj.value = * obj.address;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
964
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
965 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
966 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
967 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
968 int pos;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
969 elt = pdump_get_entry (XRECORD_LHEADER (obj.value));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
970 if (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
971 break;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
972 desc = XRECORD_LHEADER_IMPLEMENTATION (obj.value)->description;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
973 for (pos = 0; desc[pos].type != XD_LO_LINK; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
974 assert (desc[pos].type != XD_END);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
975
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
976 obj.value = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj.value)));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
977 }
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
978 obj.value = wrap_pointer_1 ((void *) elt->save_offset);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
979
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
980 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
981 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
982 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
983
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
984 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
985 pdump (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
986 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
987 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
988 Lisp_Object t_console, t_device, t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
989 int none;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
990 pdump_header header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
991
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
992 pdump_object_table = xnew_array (pdump_entry_list, lrecord_type_count);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
993 pdump_alert_undump_object = xnew_array (int, lrecord_type_count);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
994
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
995 assert (ALIGNOF (max_align_t) <= pdump_align_table[0]);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
996
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
997 for (i = 0; i < countof (pdump_align_table); i++)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
998 if (pdump_align_table[i] > ALIGNOF (max_align_t))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
999 pdump_align_table[i] = ALIGNOF (max_align_t);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1000
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1001 flush_all_buffer_local_cache ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1002
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1003 /* These appear in a DEFVAR_LISP, which does a staticpro() */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1004 t_console = Vterminal_console; Vterminal_console = Qnil;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1005 t_frame = Vterminal_frame; Vterminal_frame = Qnil;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1006 t_device = Vterminal_device; Vterminal_device = Qnil;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1007
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1008 dump_add_opaque (&lrecord_implementations_table,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1009 lrecord_type_count * sizeof (lrecord_implementations_table[0]));
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1010 dump_add_opaque (&lrecord_markers,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1011 lrecord_type_count * sizeof (lrecord_markers[0]));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1012
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1013 pdump_hash = xnew_array_and_zero (pdump_entry_list_elt *, PDUMP_HASHSIZE);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1014
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1015 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1016 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1017 pdump_object_table[i].first = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1018 pdump_object_table[i].align = ALIGNOF (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1019 pdump_object_table[i].count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1020 pdump_alert_undump_object[i] = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1021 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1022 pdump_struct_table.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1023 pdump_struct_table.size = -1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1024
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1025 pdump_opaque_data_list.first = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1026 pdump_opaque_data_list.align = ALIGNOF (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1027 pdump_opaque_data_list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1028 depth = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1029
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1030 for (i=0; i<Dynarr_length (pdump_root_objects); i++)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1031 pdump_register_object (* Dynarr_at (pdump_root_objects, i));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1032
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1033 none = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1034 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1035 if (pdump_alert_undump_object[i])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1036 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1037 if (none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1038 printf ("Undumpable types list :\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1039 none = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1040 printf (" - %s (%d)\n", lrecord_implementations_table[i]->name, pdump_alert_undump_object[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1041 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1042 if (!none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1043 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1044
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1045 for (i=0; i<Dynarr_length (pdump_root_struct_ptrs); i++)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1046 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1047 pdump_root_struct_ptr info = Dynarr_at (pdump_root_struct_ptrs, i);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1048 pdump_register_struct (*(info.ptraddress), info.desc, 1);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1049 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1050
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1051 memcpy (header.signature, PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1052 header.id = dump_id;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1053 header.reloc_address = 0;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1054 header.nb_root_struct_ptrs = Dynarr_length (pdump_root_struct_ptrs);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1055 header.nb_opaques = Dynarr_length (pdump_opaques);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1056
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1057 cur_offset = ALIGN_SIZE (sizeof (header), ALIGNOF (max_align_t));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1058 max_size = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1059
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1060 pdump_scan_by_alignment (pdump_allocate_offset);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1061 cur_offset = ALIGN_SIZE (cur_offset, ALIGNOF (max_align_t));
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1062 header.stab_offset = cur_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1063
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1064 pdump_buf = xmalloc (max_size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1065 /* Avoid use of the `open' macro. We want the real function. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1066 #undef open
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1067 pdump_fd = open (EMACS_PROGNAME ".dmp",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1068 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, 0666);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1069 pdump_out = fdopen (pdump_fd, "w");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1070
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1071 fwrite (&header, sizeof (header), 1, pdump_out);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1072 PDUMP_ALIGN_OUTPUT (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1073
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1074 pdump_scan_by_alignment (pdump_dump_data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1075
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1076 fseek (pdump_out, header.stab_offset, SEEK_SET);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1077
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1078 pdump_dump_root_struct_ptrs ();
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1079 pdump_dump_opaques ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1080 pdump_dump_rtables ();
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1081 pdump_dump_root_objects ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1082
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1083 fclose (pdump_out);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1084 close (pdump_fd);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1085
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1086 free (pdump_buf);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1087
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1088 free (pdump_hash);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1089
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1090 Vterminal_console = t_console;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1091 Vterminal_frame = t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1092 Vterminal_device = t_device;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1093 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1094
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1095 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1096 pdump_load_check (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1097 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1098 return (!memcmp (((pdump_header *)pdump_start)->signature,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1099 PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1100 && ((pdump_header *)pdump_start)->id == dump_id);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1101 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1102
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1103 /*----------------------------------------------------------------------*/
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1104 /* Reading the dump file */
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1105 /*----------------------------------------------------------------------*/
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1106 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1107 pdump_load_finish (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1108 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1109 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1110 char *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1111 EMACS_INT delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1112 EMACS_INT count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1113 pdump_header *header = (pdump_header *)pdump_start;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1115 pdump_end = pdump_start + pdump_length;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1116
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1117 delta = ((EMACS_INT)pdump_start) - header->reloc_address;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1118 p = pdump_start + header->stab_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1119
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1120 /* Put back the pdump_root_struct_ptrs */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1121 p = (char *) ALIGN_PTR (p, ALIGNOF (pdump_static_pointer));
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1122 for (i=0; i<header->nb_root_struct_ptrs; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1123 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1124 pdump_static_pointer ptr = PDUMP_READ (p, pdump_static_pointer);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1125 (* ptr.address) = ptr.value + delta;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1126 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1127
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1128 /* Put back the pdump_opaques */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1129 for (i=0; i<header->nb_opaques; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1130 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1131 pdump_opaque info = PDUMP_READ_ALIGNED (p, pdump_opaque);
545
9a775fb11bb7 [xemacs-hg @ 2001-05-18 04:39:39 by kkm]
kkm
parents: 462
diff changeset
1132 memcpy ((void*)info.varaddress, p, info.size);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1133 p += info.size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1134 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1135
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1136 /* Do the relocations */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1137 pdump_rt_list = p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1138 count = 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1139 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1140 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1141 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1142 p = (char *) ALIGN_PTR (p, ALIGNOF (char *));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1143 if (rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1144 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1145 char **reloc = (char **)p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1146 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1147 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1148 reloc[i] += delta;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1149 pdump_reloc_one (reloc[i], delta, rt.desc);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1150 }
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1151 p += rt.count * sizeof (char *);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1152 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1153 if (!(--count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1154 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1155 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1156
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1157 /* Put the pdump_root_objects variables in place */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
1158 i = PDUMP_READ_ALIGNED (p, Element_Count);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1159 p = (char *) ALIGN_PTR (p, ALIGNOF (pdump_static_Lisp_Object));
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1160 while (i--)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1161 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1162 pdump_static_Lisp_Object obj = PDUMP_READ (p, pdump_static_Lisp_Object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1163
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1164 if (POINTER_TYPE_P (XTYPE (obj.value)))
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
1165 obj.value = wrap_pointer_1 ((char *) XPNTR (obj.value) + delta);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1166
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1167 (* obj.address) = obj.value;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1168 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1169
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1170 /* Final cleanups */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1171 /* reorganize hash tables */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1172 p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1173 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1174 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1175 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1176 p = (char *) ALIGN_PTR (p, ALIGNOF (Lisp_Object));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1177 if (!rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1178 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1179 if (rt.desc == hash_table_description)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1180 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1181 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1182 pdump_reorganize_hash_table (PDUMP_READ (p, Lisp_Object));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1183 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1184 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1185 p += sizeof (Lisp_Object) * rt.count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1186 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1187
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1188 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1189 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1190
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1191 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1192 /* Free the mapped file if we decide we don't want it after all */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1193 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1194 pdump_file_unmap (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1195 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1196 UnmapViewOfFile (pdump_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1197 CloseHandle (pdump_hFile);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1198 CloseHandle (pdump_hMap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1199 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1200
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1201 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1202 pdump_file_get (const char *path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1203 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1204
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1205 pdump_hFile = CreateFile (path,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1206 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1207 0, /* Not shared */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1208 NULL, /* Not inheritable */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1209 OPEN_EXISTING,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1210 FILE_ATTRIBUTE_NORMAL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1211 NULL); /* No template file */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1212 if (pdump_hFile == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1213 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1214
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1215 pdump_length = GetFileSize (pdump_hFile, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1216 pdump_hMap = CreateFileMapping (pdump_hFile,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1217 NULL, /* No security attributes */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1218 PAGE_WRITECOPY, /* Copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1219 0, /* Max size, high half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1220 0, /* Max size, low half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1221 NULL); /* Unnamed */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1222 if (pdump_hMap == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1223 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1224
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1225 pdump_start = MapViewOfFile (pdump_hMap,
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1226 FILE_MAP_COPY, /* Copy on write */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1227 0, /* Start at zero */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1228 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1229 0); /* Map all of it */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1230 pdump_free = pdump_file_unmap;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1231 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1232 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1233
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1234 /* pdump_resource_free is called (via the pdump_free pointer) to release
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1235 any resources allocated by pdump_resource_get. Since the Windows API
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1236 specs specifically state that you don't need to (and shouldn't) free the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1237 resources allocated by FindResource, LoadResource, and LockResource this
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1238 routine does nothing. */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1239 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1240 pdump_resource_free (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1241 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1242 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1243
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1244 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1245 pdump_resource_get (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1246 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1247 HRSRC hRes; /* Handle to dump resource */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1248 HRSRC hResLoad; /* Handle to loaded dump resource */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1249
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1250 /* See Q126630 which describes how Windows NT and 95 trap writes to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1251 resource sections and duplicate the page to allow the write to proceed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1252 It also describes how to make the resource section read/write (and hence
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1253 private to each process). Doing this avoids the exceptions and related
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1254 overhead, but causes the resource section to be private to each process
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1255 that is running XEmacs. Since the resource section contains little
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1256 other than the dumped data, which should be private to each process, we
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1257 make the whole resource section read/write so we don't have to copy it. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1258
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1259 hRes = FindResource (NULL, MAKEINTRESOURCE(101), "DUMP");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1260 if (hRes == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1261 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1262
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1263 /* Found it, use the data in the resource */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1264 hResLoad = LoadResource (NULL, hRes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1265 if (hResLoad == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1266 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1267
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1268 pdump_start = LockResource (hResLoad);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1269 if (pdump_start == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1270 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1271
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1272 pdump_free = pdump_resource_free;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1273 pdump_length = SizeofResource (NULL, hRes);
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
1274 if (pdump_length <= (Memory_Count) sizeof (pdump_header))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1275 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1276 pdump_start = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1277 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1278 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1279
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1280 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1281 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1282
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1283 #else /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1284
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1285 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1286 pdump_file_free (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1287 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1288 xfree (pdump_start);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1289 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1290
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1291 #ifdef HAVE_MMAP
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1292 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1293 pdump_file_unmap (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1294 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1295 munmap (pdump_start, pdump_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1296 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1297 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1298
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1299 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1300 pdump_file_get (const char *path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1301 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1302 int fd = open (path, O_RDONLY | OPEN_BINARY);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1303 if (fd<0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1304 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1305
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1306 pdump_length = lseek (fd, 0, SEEK_END);
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
1307 if (pdump_length < (Memory_Count) sizeof (pdump_header))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1308 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1309 close (fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1310 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1311 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1312
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1313 lseek (fd, 0, SEEK_SET);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1314
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1315 #ifdef HAVE_MMAP
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1316 /* Unix 98 requires that sys/mman.h define MAP_FAILED,
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1317 but many earlier implementations don't. */
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1318 # ifndef MAP_FAILED
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1319 # define MAP_FAILED ((void *) -1L)
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1320 # endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1321 pdump_start = (char *) mmap (0, pdump_length, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1322 if (pdump_start != (char *) MAP_FAILED)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1323 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1324 pdump_free = pdump_file_unmap;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1325 close (fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1326 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1327 }
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1328 #endif /* HAVE_MMAP */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1329
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1330 pdump_start = xnew_array (char, pdump_length);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1331 pdump_free = pdump_file_free;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1332 read (fd, pdump_start, pdump_length);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1333
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1334 close (fd);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1335 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1336 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1337 #endif /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1338
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1339
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1340 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1341 pdump_file_try (char *exe_path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1342 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1343 char *w = exe_path + strlen (exe_path);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1344
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1345 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1346 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1347 sprintf (w, "-%s-%08x.dmp", EMACS_VERSION, dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1348 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1349 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1350 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1351 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1352 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1353 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1354
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1355 sprintf (w, "-%08x.dmp", dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1356 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1357 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1358 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1359 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1360 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1361 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1362
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1363 sprintf (w, ".dmp");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1364 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1365 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1366 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1367 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1368 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1369 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1370
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1371 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1372 w--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1373 while (w>exe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.'));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1374 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1375 while (w>exe_path && !IS_DIRECTORY_SEP (*w));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1376 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1377 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1378
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1379 int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1380 pdump_load (const char *argv0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1381 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1382 char exe_path[PATH_MAX];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1383 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1384 GetModuleFileName (NULL, exe_path, PATH_MAX);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1385 #else /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1386 char *w;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1387 const char *dir, *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1388
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1389 dir = argv0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1390 if (dir[0] == '-')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1391 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1392 /* XEmacs as a login shell, oh goody! */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1393 dir = getenv ("SHELL");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1394 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1395
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1396 p = dir + strlen (dir);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1397 while (p != dir && !IS_ANY_SEP (p[-1])) p--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1398
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1399 if (p != dir)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1400 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1401 /* invocation-name includes a directory component -- presumably it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1402 is relative to cwd, not $PATH */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1403 strcpy (exe_path, dir);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1404 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1405 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1406 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1407 const char *path = getenv ("PATH");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1408 const char *name = p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1409 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1410 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1411 p = path;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1412 while (*p && *p != SEPCHAR)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1413 p++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1414 if (p == path)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1415 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1416 exe_path[0] = '.';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1417 w = exe_path + 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1418 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1419 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1420 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1421 memcpy (exe_path, path, p - path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1422 w = exe_path + (p - path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1423 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1424 if (!IS_DIRECTORY_SEP (w[-1]))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1425 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1426 *w++ = '/';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1427 }
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1428 strcpy (w, name);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1429
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1430 /* ### #$%$#^$^@%$^#%@$ ! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1431 #ifdef access
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1432 #undef access
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1433 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1434
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1435 if (!access (exe_path, X_OK))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1436 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1437 if (!*p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1438 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1439 /* Oh well, let's have some kind of default */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1440 sprintf (exe_path, "./%s", name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1441 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1442 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1443 path = p+1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1444 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1445 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1446 #endif /* WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1447
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1448 if (pdump_file_try (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1449 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1450 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1451 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1452 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1453
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1454 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1455 if (pdump_resource_get ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1456 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1457 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1458 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1459 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1460 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1461 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1462 pdump_free ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1463 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1464 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1465
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1466 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1467 }