annotate src/dumper.c @ 973:ea6a06f7bf2c

[xemacs-hg @ 2002-08-22 14:56:23 by stephent] implement test skipping <87d6sblzat.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Thu, 22 Aug 2002 14:56:32 +0000
parents c925bacdda60
children e22b0213b713
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
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
4 Copyright (C) 2001, 2002 Ben Wing.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6 This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 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
10 Free Software Foundation; either version 2, or (at your option) any
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11 later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
12
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16 for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
25 /* !!#### Not yet Mule-ized */
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
26
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
27 #include <config.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
28 #include "lisp.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 #include "specifier.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
31 #include "file-coding.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32 #include "elhash.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33 #include "sysfile.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34 #include "console-stream.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 #include "dumper.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37 #ifdef WIN32_NATIVE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
38 #include "syswindows.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
39 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
40 #ifdef HAVE_MMAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41 #include <sys/mman.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 #endif
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;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
48 Bytecount 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
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
87 dump_add_opaque (const void *varaddress, Bytecount 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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
101 dump_add_root_struct_ptr (void *ptraddress,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
102 const struct struct_description *desc)
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
103 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
104 pdump_root_struct_ptr info;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
105 info.ptraddress = (void **) ptraddress;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
106 info.desc = desc;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
107 if (pdump_root_struct_ptrs == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
108 pdump_root_struct_ptrs = Dynarr_new (pdump_root_struct_ptr);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
109 Dynarr_add (pdump_root_struct_ptrs, info);
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
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
112 /* Mark the Lisp_Object at non-heap address VARADDRESS for dumping.
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
113 All the objects reachable from this var will also be dumped. */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
114 void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
115 dump_add_root_object (Lisp_Object *varaddress)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
116 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
117 if (pdump_root_objects == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
118 pdump_root_objects = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
119 Dynarr_add (pdump_root_objects, varaddress);
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
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
122 /* 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
123 void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
124 dump_add_weak_object_chain (Lisp_Object *varaddress)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
125 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
126 if (pdump_weak_object_chains == NULL)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
127 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
128 Dynarr_add (pdump_weak_object_chains, varaddress);
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
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
131
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
132 inline static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
133 pdump_align_stream (FILE *stream, Bytecount alignment)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
134 {
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
135 long offset = ftell (stream);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
136 long adjustment = ALIGN_SIZE (offset, alignment) - offset;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
137 if (adjustment)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
138 fseek (stream, adjustment, SEEK_CUR);
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
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
141 #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
142
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
143 #define PDUMP_WRITE(type, object) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
144 retry_fwrite (&object, sizeof (object), 1, pdump_out);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
145
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
146 #define PDUMP_WRITE_ALIGNED(type, object) do { \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
147 PDUMP_ALIGN_OUTPUT (type); \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
148 PDUMP_WRITE (type, object); \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
149 } while (0)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
150
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
151 #define PDUMP_READ(ptr, type) \
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
152 (((type *) (ptr = (char*) (((type *) ptr) + 1)))[-1])
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
153
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
154 #define PDUMP_READ_ALIGNED(ptr, type) \
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
155 ((ptr = (char *) ALIGN_PTR (ptr, type)), PDUMP_READ (ptr, type))
458
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
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
158
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
159 typedef struct
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
160 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163 } pdump_reloc_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165 static char *pdump_rt_list = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168 pdump_objects_unmark (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
169 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171 char *p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
172 if (p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
173 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175 pdump_reloc_table *rt = (pdump_reloc_table *)p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 p += sizeof (pdump_reloc_table);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 if (rt->desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
179 for (i=0; i<rt->count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
180 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181 struct lrecord_header *lh = * (struct lrecord_header **) p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 if (! C_READONLY_RECORD_HEADER_P (lh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183 UNMARK_RECORD_HEADER (lh);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
184 p += sizeof (EMACS_INT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
185 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
186 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
187 break;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
192 /* The structure of the file
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
193 0 - header
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
194 - dumped objects
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
195 stab_offset - nb_root_struct_ptrs*pair(void *, adr)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
196 for pointers to structures
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
197 - nb_opaques*pair(void *, size) for raw bits to restore
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
198 - relocation table
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
199 - root lisp object address/value couples with the count
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
200 preceding the list
442
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
203
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
204 #define PDUMP_SIGNATURE "XEmacsDP"
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
205 #define PDUMP_SIGNATURE_LEN (sizeof (PDUMP_SIGNATURE) - 1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
206
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
207 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
208 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
209 char signature[PDUMP_SIGNATURE_LEN];
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
210 unsigned int id;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
211 EMACS_UINT stab_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
212 EMACS_UINT reloc_address;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
213 int nb_root_struct_ptrs;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
214 int nb_opaques;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
215 } pdump_header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
216
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
217 char *pdump_start;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
218 char *pdump_end;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
219 static Bytecount pdump_length;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
220
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
221 #ifdef WIN32_NATIVE
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
222 /* Handle for the dump file */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
223 static HANDLE pdump_hFile = INVALID_HANDLE_VALUE;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
224 /* Handle for the file mapping object for the dump file */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
225 static HANDLE pdump_hMap = INVALID_HANDLE_VALUE;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
226 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
227
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
228 static void (*pdump_free) (void);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
229
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
230 static unsigned char pdump_align_table[] =
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
231 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
232 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
233 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
234 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
235 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
236 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
237
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
238 static inline int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
239 pdump_size_to_align (Bytecount size)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
240 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
241 return pdump_align_table[size % countof (pdump_align_table)];
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
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
244 typedef struct pdump_entry_list_elt
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
245 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
246 struct pdump_entry_list_elt *next;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
247 const void *obj;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
248 Bytecount size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
250 EMACS_INT save_offset;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
251 } pdump_entry_list_elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
252
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
253 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
254 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
255 pdump_entry_list_elt *first;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
256 int align;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
257 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
258 } pdump_entry_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
259
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
260 typedef struct pdump_struct_list_elt
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
261 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
262 pdump_entry_list list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
263 const struct struct_description *sdesc;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
264 } pdump_struct_list_elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
265
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
266 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
267 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
268 pdump_struct_list_elt *list;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
269 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
270 int size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
271 } pdump_struct_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
272
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
273 static pdump_entry_list *pdump_object_table;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
274 static pdump_entry_list pdump_opaque_data_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
275 static pdump_struct_list pdump_struct_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
276
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
277 static int *pdump_alert_undump_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
278
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
279 static unsigned long cur_offset;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
280 static Bytecount max_size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
281 static int pdump_fd;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
282 static void *pdump_buf;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
283 static FILE *pdump_out;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
284
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
285 #define PDUMP_HASHSIZE 200001
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
286
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
287 static pdump_entry_list_elt **pdump_hash;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
289 /* 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
290 static int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
291 pdump_make_hash (const void *obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
292 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 return ((unsigned long)(obj)>>3) % PDUMP_HASHSIZE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
294 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
295
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
296 static pdump_entry_list_elt *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
297 pdump_get_entry (const void *obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
298 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
299 int pos = pdump_make_hash (obj);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
300 pdump_entry_list_elt *e;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
301
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
302 assert (obj != 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
303
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
304 while ((e = pdump_hash[pos]) != 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
305 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
306 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
307 return e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
308
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
309 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
310 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
311 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
312 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
313 return 0;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
316 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
317 pdump_add_entry (pdump_entry_list *list, const void *obj, Bytecount size,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
318 int count)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
319 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
320 pdump_entry_list_elt *e;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
321 int pos = pdump_make_hash (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
322
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
323 while ((e = pdump_hash[pos]) != 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
324 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
325 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
326 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
327
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
328 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
329 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
330 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
331 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
332
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
333 e = xnew (pdump_entry_list_elt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
334
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
335 e->next = list->first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
336 e->obj = obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
337 e->size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
338 e->count = count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
339 list->first = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
340
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
341 list->count += count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
342 pdump_hash[pos] = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
343
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
344 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
345 int align = pdump_size_to_align (size);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
346
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
347 if (align < list->align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
348 list->align = align;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
349 }
442
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
352 static pdump_entry_list *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
353 pdump_get_entry_list (const struct struct_description *sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
354 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
355 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
356 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
357 if (pdump_struct_table.list[i].sdesc == sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
358 return &pdump_struct_table.list[i].list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
359
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
360 if (pdump_struct_table.size <= pdump_struct_table.count)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
361 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
362 if (pdump_struct_table.size == -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
363 pdump_struct_table.size = 10;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
364 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
365 pdump_struct_table.size = pdump_struct_table.size * 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
366 pdump_struct_table.list = (pdump_struct_list_elt *)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
367 xrealloc (pdump_struct_table.list,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
368 pdump_struct_table.size * sizeof (pdump_struct_list_elt));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
369 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
370 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
371 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
372 pdump_struct_table.list[pdump_struct_table.count].list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
373 pdump_struct_table.list[pdump_struct_table.count].sdesc = sdesc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
374
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
375 return &pdump_struct_table.list[pdump_struct_table.count++].list;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
378 static struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
379 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
380 struct lrecord_header *obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
381 int position;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
382 int offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
383 } backtrace[65536];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
384
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
385 static int depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
386
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
387 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
388 pdump_backtrace (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
389 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
390 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
391 stderr_out ("pdump backtrace :\n");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
392 for (i = 0; i < depth; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
393 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
394 if (!backtrace[i].obj)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
395 stderr_out (" - ind. (%d, %d)\n",
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
396 backtrace[i].position,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
397 backtrace[i].offset);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
398 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
399 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
400 stderr_out (" - %s (%d, %d)\n",
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
401 LHEADER_IMPLEMENTATION (backtrace[i].obj)->name,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
402 backtrace[i].position,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
403 backtrace[i].offset);
442
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
408 static void pdump_register_object (Lisp_Object obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
409 static void pdump_register_struct_contents (const void *data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
410 const struct struct_description *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
411 sdesc,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
412 int count);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
413 static void pdump_register_struct (const void *data,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
414 const struct struct_description *sdesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
415 int count);
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 static EMACS_INT
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
418 pdump_get_indirect_count (EMACS_INT code,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
419 const struct lrecord_description *idesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
420 const void *idata)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
421 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
422 EMACS_INT count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
423 const void *irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
424
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
425 int line = XD_INDIRECT_VAL (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
426 int delta = XD_INDIRECT_DELTA (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
427
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
428 irdata = ((char *)idata) + idesc[line].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
429 switch (idesc[line].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
430 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
431 case XD_BYTECOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
432 count = *(Bytecount *)irdata;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
433 break;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
434 case XD_ELEMCOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
435 count = *(Elemcount *)irdata;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
436 break;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
437 case XD_HASHCODE:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
438 count = *(Hashcode *)irdata;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
439 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
440 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
441 count = *(int *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
442 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
443 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
444 count = *(long *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
445 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
446 default:
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
447 stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n",
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
448 idesc[line].type, line, (long)code);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
449 pdump_backtrace ();
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
450 count = 0; /* warning suppression */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
451 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
452 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
453 count += delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
454 return count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
455 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
456
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
457 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 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
459 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
460 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
462 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
463 for (pos = 0; desc[pos].type != XD_END; pos++)
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 const void *rdata = (const char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
466
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
467 backtrace[me].position = pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
468 backtrace[me].offset = desc[pos].offset;
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 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
471 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
472 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
473 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
474 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
475 goto restart;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
476 case XD_CODING_SYSTEM_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
477 pos = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
478 desc =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
479 ((const Lisp_Coding_System *)data)->methods->extra_description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
480 goto restart;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
481 case XD_BYTECOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
482 case XD_ELEMCOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
483 case XD_HASHCODE:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
484 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
485 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
486 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
487 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
488 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
489 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
490 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
491 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
492 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
493 count = pdump_get_indirect_count (count, desc, data);
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 pdump_add_entry (&pdump_opaque_data_list,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
496 *(void **)rdata, count, 1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
497 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
498 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
499 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
500 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
501 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502 if (str)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
503 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
504 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
508 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
509 if ((EMACS_INT)str > 0)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
510 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
511 break;
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 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
514 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
515 const Lisp_Object *pobj = (const Lisp_Object *)rdata;
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 assert (desc[pos].data1 == 0);
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 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
520 pdump_register_object (*pobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
521 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
522 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
523 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
524 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
525 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
526 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
527 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
528 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
529
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
530 for (i = 0; i < count; i++)
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 const Lisp_Object *pobj = ((const Lisp_Object *)rdata) + i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
533 Lisp_Object dobj = *pobj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
534
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
535 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
536 pdump_register_object (dobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
537 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
538 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
539 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
540 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
543 const struct struct_description *sdesc = desc[pos].data2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
544 const char *dobj = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
545 if (dobj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
546 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
547 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 pdump_register_struct (dobj, sdesc, count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
552 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
553 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
554 case XD_STRUCT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
555 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
556 EMACS_INT count = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
557 const struct struct_description *sdesc = desc[pos].data2;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
558
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
559 if (XD_IS_INDIRECT (count))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
560 count = pdump_get_indirect_count (count, desc, data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
561
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
562 pdump_register_struct_contents (rdata, sdesc, count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
563 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
564 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
565 case XD_UNION:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
566 abort (); /* #### IMPLEMENT ME! NEEDED FOR UNICODE SUPPORT */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
567
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
568 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
569 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
570 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
571 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
572 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
573 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
574 }
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 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
577 pdump_register_object (Lisp_Object obj)
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 struct lrecord_header *objh;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
580 const struct lrecord_implementation *imp;
442
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 if (!POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
583 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
584
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
585 objh = XRECORD_LHEADER (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
586 if (!objh)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
587 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
588
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
589 if (pdump_get_entry (objh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
590 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
591
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
592 imp = LHEADER_IMPLEMENTATION (objh);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
593
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 826
diff changeset
594 #ifdef USE_KKCC
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 826
diff changeset
595 if (imp->description
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 826
diff changeset
596 && RECORD_DUMPABLE(objh))
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 826
diff changeset
597 #else /* not USE_KKCC */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
598 if (imp->description)
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 826
diff changeset
599 #endif /* not USE_KKCC */
442
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 int me = depth++;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
602 if (me > 65536)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
603 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
604 stderr_out ("Backtrace overflow, loop ?\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
605 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
606 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
607 backtrace[me].obj = objh;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
608 backtrace[me].position = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
609 backtrace[me].offset = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
610
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
611 pdump_add_entry (pdump_object_table + objh->type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
612 objh,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
613 imp->static_size ?
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
614 imp->static_size :
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
615 imp->size_in_bytes_method (objh),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
616 1);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
617 pdump_register_sub (objh, imp->description, me);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
618 --depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
619 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
620 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
621 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
622 pdump_alert_undump_object[objh->type]++;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
623 stderr_out ("Undumpable object type : %s\n", imp->name);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
624 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
625 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
626 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
627
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
628 /* Return the size of the memory block (NOT necessarily a structure!)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
629 described by SDESC and pointed to by OBJ. If SDESC records an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
630 explicit size (i.e. non-zero), it is simply returned; otherwise,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
631 the size is calculated by the maximum offset and the size of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
632 object at that offset, rounded up to the maximum alignment. In
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
633 this case, we may need the object, for example when retrieving an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
634 "indirect count" of an inlined array (the count is not constant,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
635 but is specified by one of the elements of the memory block). (It
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
636 is generally not a problem if we return an overly large size -- we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
637 will simply end up reserving more space than necessary; but if the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
638 size is too small we could be in serious trouble, in particular
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
639 with nested inlined structures, where there may be alignment
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
640 padding in the middle of a block. #### In fact there is an (at
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
641 least theoretical) problem with an overly large size -- we may
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
642 trigger a protection fault when reading from invalid memory. We
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
643 need to handle this -- perhaps in a stupid but dependable way,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
644 i.e. by trapping SIGSEGV and SIGBUS.) */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
645
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
646 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
647 pdump_structure_size (const void *obj, const struct struct_description *sdesc)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
648 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
649 int max_offset = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
650 int max_offset_pos = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
651 int size_at_max = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
652 int pos;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
653 const struct lrecord_description *desc;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
654 void *rdata;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
655
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
656 if (sdesc->size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
657 return sdesc->size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
658
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
659 desc = sdesc->description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
660
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
661 for (pos = 0; desc[pos].type != XD_END; pos++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
662 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
663 if (desc[pos].offset == max_offset)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
664 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
665 stderr_out ("Two relocatable elements at same offset?\n");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
666 abort ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
667 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
668 else if (desc[pos].offset > max_offset)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
669 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
670 max_offset = desc[pos].offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
671 max_offset_pos = pos;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
672 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
673 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
674
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
675 if (max_offset_pos < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
676 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
677
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
678 pos = max_offset_pos;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
679 rdata = (char *) obj + desc[pos].offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
680
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
681 switch (desc[pos].type)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
682 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
683 case XD_LISP_OBJECT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
684 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
685 EMACS_INT val = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
686 if (XD_IS_INDIRECT (val))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
687 val = pdump_get_indirect_count (val, desc, obj);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
688 size_at_max = val * sizeof (Lisp_Object);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
689 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
690 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
691 case XD_LISP_OBJECT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
692 case XD_LO_LINK:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
693 size_at_max = sizeof (Lisp_Object);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
694 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
695 case XD_OPAQUE_PTR:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
696 size_at_max = sizeof (void *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
697 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
698 case XD_STRUCT_PTR:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
699 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
700 EMACS_INT val = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
701 if (XD_IS_INDIRECT (val))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
702 val = pdump_get_indirect_count (val, desc, obj);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
703 size_at_max = val * sizeof (void *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
704 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
705 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
706 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
707 case XD_STRUCT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
708 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
709 EMACS_INT val = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
710
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
711 if (XD_IS_INDIRECT (val))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
712 val = pdump_get_indirect_count (val, desc, obj);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
713
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
714 size_at_max = val * pdump_structure_size (rdata, desc[pos].data2);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
715 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
716 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
717 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
718 case XD_OPAQUE_DATA_PTR:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
719 size_at_max = sizeof (void *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
720 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
721 case XD_UNION:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
722 abort (); /* #### IMPLEMENT ME! NEEDED FOR UNICODE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
723 SUPPORT */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
724 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
725 case XD_C_STRING:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
726 size_at_max = sizeof (void *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
727 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
728 case XD_DOC_STRING:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
729 size_at_max = sizeof (void *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
730 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
731 case XD_INT_RESET:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
732 size_at_max = sizeof (int);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
733 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
734 case XD_BYTECOUNT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
735 size_at_max = sizeof (Bytecount);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
736 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
737 case XD_ELEMCOUNT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
738 size_at_max = sizeof (Elemcount);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
739 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
740 case XD_HASHCODE:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
741 size_at_max = sizeof (Hashcode);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
742 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
743 case XD_INT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
744 size_at_max = sizeof (int);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
745 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
746 case XD_LONG:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
747 size_at_max = sizeof (long);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
748 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
749 case XD_SPECIFIER_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
750 case XD_CODING_SYSTEM_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
751 stderr_out
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
752 ("Should not be seeing XD_SPECIFIER_END or\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
753 "XD_CODING_SYSTEM_END outside of struct Lisp_Specifier\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
754 "and struct Lisp_Coding_System.\n");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
755 abort ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
756 default:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
757 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
758 abort ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
759 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
760
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
761 /* We have no way of knowing the required alignment for this structure,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
762 so just max it maximally aligned. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
763 return MAX_ALIGN_SIZE (max_offset + size_at_max);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
764 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
765
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
766 /* Register the referenced objects in the array of COUNT objects of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
767 located at DATA; each object is described by SDESC. "Object" here
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
768 simply means any block of memory; it need not actually be a C
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
769 "struct". It could be a single integer or Lisp_Object, for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
770 example, as long as the description is accurate.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
772 This does not register the block of memory itself; it may, for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
773 example, be an array of structures inlined in another memory block
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
774 and thus should not be registered. See pdump_register_struct(),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
775 which does register the memory block. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
776
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
777 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
778 pdump_register_struct_contents (const void *data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
779 const struct struct_description *sdesc,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
780 int count)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
781
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
782 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
783 int me = depth++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
784 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
785 Bytecount elsize;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
786
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
787 if (me>65536)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
788 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
789 stderr_out ("Backtrace overflow, loop ?\n");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
790 abort ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
791 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
792 backtrace[me].obj = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
793 backtrace[me].position = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
794 backtrace[me].offset = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
795
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
796 elsize = pdump_structure_size (data, sdesc);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
797
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
798 for (i = 0; i < count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
799 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
800 pdump_register_sub (((char *) data) + elsize * i,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
801 sdesc->description,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
802 me);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
803 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
804 --depth;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
805 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
806
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
807 /* Register the array of COUNT objects of located at DATA; each object is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
808 described by SDESC. "Object" here simply means any block of memory;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
809 it need not actually be a C "struct". It could be a single integer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
810 or Lisp_Object, for example, as long as the description is accurate.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
811
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
812 This is like pdump_register_struct_contents() but also registers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
813 the memory block itself. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
814
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
815 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
816 pdump_register_struct (const void *data,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
817 const struct struct_description *sdesc,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
818 int count)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
819 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
820 if (data && !pdump_get_entry (data))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
821 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
822 pdump_add_entry (pdump_get_entry_list (sdesc), data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
823 pdump_structure_size (data, sdesc), count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
824
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
825 pdump_register_struct_contents (data, sdesc, count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
826 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
827 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
828
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
829 /* Store the already-calculated new pointer offsets for all pointers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
830 in the COUNT contiguous blocks of memory, each described by DESC
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
831 and of size SIZE, whose original is located at ORIG_DATA and the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
832 modifiable copy at DATA.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
833
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
834 This is done just before writing the modified block of memory to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
835 the dump file. The new pointer offsets have been carefully
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
836 calculated so that the data being pointed gets written at that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
837 offset in the dump file. That way, the dump file is a correct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
838 memory image except perhaps for a constant that needs to be added
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
839 to all pointers. (#### In fact, we SHOULD be starting up a dumped
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
840 XEmacs, seeing where the dumped file gets loaded into memory, and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
841 then rewriting the dumped file after relocating all the pointers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
842 relative to this memory location. That way, if the file gets
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
843 loaded again at the same location, which will be common, we don't
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
844 have to do any relocating, which is both faster at startup and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
845 allows the read-only part of the dumped data to be shared read-only
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
846 between different invocations of XEmacs.)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
847
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
848 #### Do we distinguish between read-only and writable dumped data?
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
849 Should we? It's tricky because the dumped data, once loaded again,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
850 cannot really be free()d or garbage collected since it's all stored
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
851 in one contiguous block of data with no malloc() headers, and we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
852 don't keep track of the pointers used internally in malloc() and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
853 the Lisp allocator to track allocated blocks of memory. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
854
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
855 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
856 pdump_store_new_pointer_offsets (int count, void *data, const void *orig_data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
857 const struct lrecord_description *desc,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
858 int size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
859 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
860 int pos, i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
861 /* Process each block one by one */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
862 for (i = 0; i < count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
863 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
864 /* CUR points to the beginning of each block in the new data. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
865 char *cur = ((char *)data) + i*size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
866 restart:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
867 /* Scan each line of the description for relocatable pointers */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
868 for (pos = 0; desc[pos].type != XD_END; pos++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
869 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
870 /* RDATA points to the beginning of each element in the new data. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
871 void *rdata = cur + desc[pos].offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
872 switch (desc[pos].type)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
873 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
874 case XD_SPECIFIER_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
875 desc = ((const Lisp_Specifier *)(orig_data))->
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
876 methods->extra_description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
877 goto restart;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
878 case XD_CODING_SYSTEM_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
879 desc = ((const Lisp_Coding_System *)(orig_data))->
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
880 methods->extra_description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
881 goto restart;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
882 case XD_BYTECOUNT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
883 case XD_ELEMCOUNT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
884 case XD_HASHCODE:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
885 case XD_INT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
886 case XD_LONG:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
887 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
888 case XD_INT_RESET:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
889 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
890 EMACS_INT val = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
891 if (XD_IS_INDIRECT (val))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
892 val = pdump_get_indirect_count (val, desc, orig_data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
893 * (int *) rdata = val;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
894 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
895 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
896 case XD_OPAQUE_DATA_PTR:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
897 case XD_C_STRING:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
898 case XD_STRUCT_PTR:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
899 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
900 void *ptr = * (void **) rdata;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
901 if (ptr)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
902 * (EMACS_INT *) rdata = pdump_get_entry (ptr)->save_offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
903 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
904 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
905 case XD_LO_LINK:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
906 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
907 /* As described in lrecord.h, this is a weak link.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
908 Thus, we need to link this object not (necessarily)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
909 to the object directly pointed to, but to the next
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
910 referenced object in the chain. None of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
911 intermediate objects will be written out, so we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
912 traverse down the chain of objects until we find a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
913 referenced one. (The Qnil or Qunbound that ends the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
914 chain will always be a referenced object.) */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
915 Lisp_Object obj = * (Lisp_Object *) rdata;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
916 pdump_entry_list_elt *elt1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
917 for (;;)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
918 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
919 elt1 = pdump_get_entry (XRECORD_LHEADER (obj));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
920 if (elt1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
921 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
922 obj = * (Lisp_Object *) (desc[pos].offset +
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
923 (char *)(XRECORD_LHEADER (obj)));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
924 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
925 * (EMACS_INT *) rdata = elt1->save_offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
926 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
927 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
928 case XD_LISP_OBJECT:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
929 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
930 Lisp_Object *pobj = (Lisp_Object *) rdata;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
931
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
932 assert (desc[pos].data1 == 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
933
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
934 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
935 * (EMACS_INT *) pobj =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
936 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
937 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
938 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
939 case XD_LISP_OBJECT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
940 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
941 EMACS_INT num = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
942 int j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
943 if (XD_IS_INDIRECT (num))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
944 num = pdump_get_indirect_count (num, desc, orig_data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
945
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
946 for (j = 0; j < num; j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
947 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
948 Lisp_Object *pobj = ((Lisp_Object *) rdata) + j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
949 if (POINTER_TYPE_P (XTYPE (*pobj)) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
950 XRECORD_LHEADER (*pobj))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
951 * (EMACS_INT *) pobj =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
952 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
953 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
954 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
955 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
956 case XD_DOC_STRING:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
957 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
958 EMACS_INT str = *(EMACS_INT *)rdata;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
959 if (str > 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
960 * (EMACS_INT *) rdata =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
961 pdump_get_entry ((void *)str)->save_offset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
962 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
963 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
964 case XD_STRUCT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
965 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
966 EMACS_INT num = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
967 if (XD_IS_INDIRECT (num))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
968 num = pdump_get_indirect_count (num, desc, orig_data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
969
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
970 pdump_store_new_pointer_offsets
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
971 (num, rdata,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
972 ((char *) rdata - (char *) data) + (char *) orig_data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
973 desc[pos].data2->description,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
974 pdump_structure_size
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
975 (((char *) rdata - (char *) data) + (char *) orig_data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
976 desc[pos].data2));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
977 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
978 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
979 case XD_UNION:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
980 abort (); /* #### IMPLEMENT ME! NEEDED FOR UNICODE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
981 SUPPORT */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
982
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
983 default:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
984 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
985 abort ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
986 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
987 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
988 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
989 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
990
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
991 /* Write out to global file descriptor PDUMP_OUT the element (one or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
992 more contiguous blocks of identical size/description) recorded in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
993 ELT and described by DESC. The element is first copied to a buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
994 and then all pointers (this includes Lisp_Objects other than
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
995 integer/character) are relocated to the (pre-computed) offset in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
996 the dump file. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
997
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
998 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
999 pdump_dump_data (pdump_entry_list_elt *elt,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1000 const struct lrecord_description *desc)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1001 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1002 Bytecount size = elt->size;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1003 int count = elt->count;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1004 if (desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1005 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1006 /* Copy to temporary buffer */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1007 memcpy (pdump_buf, elt->obj, size*count);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1008
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1009 /* Store new offsets into all pointers in block */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1010 pdump_store_new_pointer_offsets (count, pdump_buf, elt->obj, desc, size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1011 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1012 retry_fwrite (desc ? pdump_buf : elt->obj, size, count, pdump_out);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1013 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1014
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1015 /* Relocate a single memory block at DATA, described by DESC, from its
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1016 assumed load location to its actual one by adding DELTA to all
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1017 pointers in the block. Does not recursively relocate any other
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1018 memory blocks pointed to. (We already have a list of all memory
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1019 blocks in the dump file.) */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1020
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1021 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1022 pdump_reloc_one (void *data, EMACS_INT delta,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1023 const struct lrecord_description *desc)
442
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 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1026
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1027 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1028 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1029 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1030 void *rdata = (char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1031 switch (desc[pos].type)
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 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1034 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1035 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1036 goto restart;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1037 case XD_CODING_SYSTEM_END:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1038 pos = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1039 desc =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1040 ((const Lisp_Coding_System *)data)->methods->extra_description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1041 goto restart;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1042 case XD_BYTECOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1043 case XD_ELEMCOUNT:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1044 case XD_HASHCODE:
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1045 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1046 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1047 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1048 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1049 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1050 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1051 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1052 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1053 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1054 EMACS_INT ptr = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1055 if (ptr)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1056 *(EMACS_INT *)rdata = ptr+delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1057 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1058 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1059 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1060 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1061 Lisp_Object *pobj = (Lisp_Object *) rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1062
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1063 assert (desc[pos].data1 == 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1064
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1065 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1066 && ! EQ (*pobj, Qnull_pointer))
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1067 *pobj = wrap_pointer_1 ((char *) XPNTR (*pobj) + delta);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1068
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1069 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1070 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1071 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1072 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1073 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1074 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1075 if (XD_IS_INDIRECT (num))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1076 num = pdump_get_indirect_count (num, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1077
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1078 for (j=0; j<num; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1079 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1080 Lisp_Object *pobj = (Lisp_Object *) rdata + j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1081
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1082 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1083 && ! EQ (*pobj, Qnull_pointer))
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1084 *pobj = wrap_pointer_1 ((char *) XPNTR (*pobj) + delta);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1085 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1086 break;
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 case XD_DOC_STRING:
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 EMACS_INT str = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1091 if (str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1092 *(EMACS_INT *)rdata = str + delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1093 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1094 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1095 case XD_STRUCT_ARRAY:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1096 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1097 EMACS_INT num = desc[pos].data1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1098 int j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1099 const struct struct_description *sdesc = desc[pos].data2;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1100 Bytecount size = pdump_structure_size (rdata, sdesc);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1101
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1102 if (XD_IS_INDIRECT (num))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1103 num = pdump_get_indirect_count (num, desc, data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1104 /* Note: We are recursing over data in the block itself */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1105 for (j = 0; j < num; j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1106 pdump_reloc_one ((char *) rdata + j * size, delta,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1107 sdesc->description);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1108
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1109 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1110 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1111
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1112 case XD_UNION:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1113 abort (); /* #### IMPLEMENT ME! NEEDED FOR UNICODE SUPPORT */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1114 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1115 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1116 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1117 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1118 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1119 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1120
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1121 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1122 pdump_allocate_offset (pdump_entry_list_elt *elt,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1123 const struct lrecord_description *desc)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1124 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1125 Bytecount size = elt->count * elt->size;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1126 elt->save_offset = cur_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1127 if (size>max_size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1128 max_size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1129 cur_offset += size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1130 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1131
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1132 static void
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1133 pdump_scan_by_alignment (void (*f)(pdump_entry_list_elt *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1134 const struct lrecord_description *))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1135 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1136 int align;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1137
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1138 for (align = ALIGNOF (max_align_t); align; align>>=1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1139 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1140 int i;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1141 pdump_entry_list_elt *elt;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1142
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1143 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1144 if (pdump_object_table[i].align == align)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1145 for (elt = pdump_object_table[i].first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1146 f (elt, lrecord_implementations_table[i]->description);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1147
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1148 for (i=0; i<pdump_struct_table.count; i++)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1149 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1150 pdump_struct_list_elt list = pdump_struct_table.list[i];
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1151 if (list.list.align == align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1152 for (elt = list.list.first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1153 f (elt, list.sdesc->description);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1154 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1155
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1156 for (elt = pdump_opaque_data_list.first; elt; elt = elt->next)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1157 if (pdump_size_to_align (elt->size) == align)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1158 f (elt, 0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1159 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1160 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1161
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1162 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1163 pdump_dump_root_struct_ptrs (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1164 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1165 int i;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1166 Elemcount count = Dynarr_length (pdump_root_struct_ptrs);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1167 pdump_static_pointer *data = alloca_array (pdump_static_pointer, count);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1168 for (i = 0; i < count; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1169 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1170 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
1171 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
1172 }
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1173 PDUMP_ALIGN_OUTPUT (pdump_static_pointer);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1174 retry_fwrite (data, sizeof (pdump_static_pointer), count, pdump_out);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1175 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1176
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1177 static void
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1178 pdump_dump_opaques (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1179 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1180 int i;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1181 for (i = 0; i < Dynarr_length (pdump_opaques); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1182 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1183 pdump_opaque *info = Dynarr_atp (pdump_opaques, i);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1184 PDUMP_WRITE_ALIGNED (pdump_opaque, *info);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1185 retry_fwrite (info->varaddress, info->size, 1, pdump_out);
442
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1189 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1190 pdump_dump_rtables (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1191 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1192 int i;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1193 pdump_entry_list_elt *elt;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1194 pdump_reloc_table rt;
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 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1197 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1198 elt = pdump_object_table[i].first;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1199 if (!elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1200 continue;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1201 rt.desc = lrecord_implementations_table[i]->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1202 rt.count = pdump_object_table[i].count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1203 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1204 while (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1205 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1206 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1207 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1208 elt = elt->next;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1209 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1210 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1211
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1212 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1213 rt.count = 0;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1214 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1215
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1216 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1217 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1218 elt = pdump_struct_table.list[i].list.first;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1219 rt.desc = pdump_struct_table.list[i].sdesc->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1220 rt.count = pdump_struct_table.list[i].list.count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1221 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1222 while (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1223 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1224 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1225 int j;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1226 for (j=0; j<elt->count; j++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1227 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1228 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1229 rdata += elt->size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1230 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1231 elt = elt->next;
442
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 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1235 rt.count = 0;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1236 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1237 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1238
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1239 static void
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1240 pdump_dump_root_objects (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1241 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1242 Elemcount count = (Dynarr_length (pdump_root_objects) +
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
1243 Dynarr_length (pdump_weak_object_chains));
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1244 Elemcount i;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1245
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1246 PDUMP_WRITE_ALIGNED (Elemcount, count);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1247 PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1248
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 619
diff changeset
1249 for (i = 0; i < Dynarr_length (pdump_root_objects); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1250 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1251 pdump_static_Lisp_Object obj;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1252 obj.address = Dynarr_at (pdump_root_objects, i);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1253 obj.value = * obj.address;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1254
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1255 if (POINTER_TYPE_P (XTYPE (obj.value)))
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
1256 obj.value =
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
1257 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
1258 (obj.value))->save_offset);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1259
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1260 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1261 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1262
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1263 for (i=0; i<Dynarr_length (pdump_weak_object_chains); i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1264 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1265 pdump_entry_list_elt *elt;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1266 pdump_static_Lisp_Object obj;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1267
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1268 obj.address = Dynarr_at (pdump_weak_object_chains, i);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1269 obj.value = * obj.address;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1270
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1271 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1272 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1273 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1274 int pos;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1275 elt = pdump_get_entry (XRECORD_LHEADER (obj.value));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1276 if (elt)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1277 break;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1278 desc = XRECORD_LHEADER_IMPLEMENTATION (obj.value)->description;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1279 for (pos = 0; desc[pos].type != XD_LO_LINK; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1280 assert (desc[pos].type != XD_END);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1281
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1282 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
1283 }
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
1284 obj.value = wrap_pointer_1 ((void *) elt->save_offset);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1285
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1286 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1287 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1288 }
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 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1291 pdump (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1292 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1293 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1294 Lisp_Object t_console, t_device, t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1295 int none;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1296 pdump_header header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1297
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1298 pdump_object_table = xnew_array (pdump_entry_list, lrecord_type_count);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1299 pdump_alert_undump_object = xnew_array (int, lrecord_type_count);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1300
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1301 assert (ALIGNOF (max_align_t) <= pdump_align_table[0]);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1302
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1303 for (i = 0; i < countof (pdump_align_table); i++)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1304 if (pdump_align_table[i] > ALIGNOF (max_align_t))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1305 pdump_align_table[i] = ALIGNOF (max_align_t);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1306
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1307 flush_all_buffer_local_cache ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1308
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1309 /* These appear in a DEFVAR_LISP, which does a staticpro() */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1310 t_console = Vterminal_console; Vterminal_console = Qnil;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1311 t_frame = Vterminal_frame; Vterminal_frame = Qnil;
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1312 t_device = Vterminal_device; Vterminal_device = Qnil;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1313
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1314 dump_add_opaque (&lrecord_implementations_table,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1315 lrecord_type_count * sizeof (lrecord_implementations_table[0]));
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1316 dump_add_opaque (&lrecord_markers,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1317 lrecord_type_count * sizeof (lrecord_markers[0]));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1318
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1319 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
1320
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1321 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1322 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1323 pdump_object_table[i].first = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1324 pdump_object_table[i].align = ALIGNOF (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1325 pdump_object_table[i].count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1326 pdump_alert_undump_object[i] = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1327 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1328 pdump_struct_table.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1329 pdump_struct_table.size = -1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1330
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1331 pdump_opaque_data_list.first = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1332 pdump_opaque_data_list.align = ALIGNOF (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1333 pdump_opaque_data_list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1334 depth = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1335
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1336 for (i=0; i<Dynarr_length (pdump_root_objects); i++)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1337 pdump_register_object (* Dynarr_at (pdump_root_objects, i));
442
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 none = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1340 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1341 if (pdump_alert_undump_object[i])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1342 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1343 if (none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1344 printf ("Undumpable types list :\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1345 none = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1346 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
1347 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1348 if (!none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1349 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1350
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1351 for (i=0; i<Dynarr_length (pdump_root_struct_ptrs); i++)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1352 {
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1353 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
1354 pdump_register_struct (*(info.ptraddress), info.desc, 1);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1355 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1356
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1357 memcpy (header.signature, PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1358 header.id = dump_id;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1359 header.reloc_address = 0;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1360 header.nb_root_struct_ptrs = Dynarr_length (pdump_root_struct_ptrs);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1361 header.nb_opaques = Dynarr_length (pdump_opaques);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1362
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1363 cur_offset = MAX_ALIGN_SIZE (sizeof (header));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1364 max_size = 0;
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 pdump_scan_by_alignment (pdump_allocate_offset);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1367 cur_offset = MAX_ALIGN_SIZE (cur_offset);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1368 header.stab_offset = cur_offset;
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 pdump_buf = xmalloc (max_size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1371 pdump_fd = open (EMACS_PROGNAME ".dmp",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1372 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, 0666);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1373 if (pdump_fd < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1374 report_file_error ("Unable to open dump file",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1375 build_string (EMACS_PROGNAME ".dmp"));
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1376 pdump_out = fdopen (pdump_fd, "w");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1377 if (pdump_out < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1378 report_file_error ("Unable to open dump file for writing",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1379 build_string (EMACS_PROGNAME ".dmp"));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1380
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1381 retry_fwrite (&header, sizeof (header), 1, pdump_out);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1382 PDUMP_ALIGN_OUTPUT (max_align_t);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1383
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1384 pdump_scan_by_alignment (pdump_dump_data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1385
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1386 fseek (pdump_out, header.stab_offset, SEEK_SET);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1387
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1388 pdump_dump_root_struct_ptrs ();
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1389 pdump_dump_opaques ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1390 pdump_dump_rtables ();
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1391 pdump_dump_root_objects ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1392
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1393 retry_fclose (pdump_out);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1394 retry_close (pdump_fd);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1395
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1396 free (pdump_buf);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1397
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1398 free (pdump_hash);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1399
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1400 Vterminal_console = t_console;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1401 Vterminal_frame = t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1402 Vterminal_device = t_device;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1403 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1404
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1405 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1406 pdump_load_check (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1407 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1408 return (!memcmp (((pdump_header *)pdump_start)->signature,
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1409 PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN)
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1410 && ((pdump_header *)pdump_start)->id == dump_id);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1411 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1412
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1413 /*----------------------------------------------------------------------*/
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1414 /* Reading the dump file */
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1415 /*----------------------------------------------------------------------*/
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1416 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1417 pdump_load_finish (void)
442
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 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1420 char *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1421 EMACS_INT delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1422 EMACS_INT count;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1423 pdump_header *header = (pdump_header *)pdump_start;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1424
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1425 pdump_end = pdump_start + pdump_length;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1426
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1427 delta = ((EMACS_INT)pdump_start) - header->reloc_address;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1428 p = pdump_start + header->stab_offset;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1429
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1430 /* Put back the pdump_root_struct_ptrs */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1431 p = (char *) ALIGN_PTR (p, pdump_static_pointer);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1432 for (i=0; i<header->nb_root_struct_ptrs; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1433 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1434 pdump_static_pointer ptr = PDUMP_READ (p, pdump_static_pointer);
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1435 (* ptr.address) = ptr.value + delta;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1436 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1437
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1438 /* Put back the pdump_opaques */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1439 for (i=0; i<header->nb_opaques; i++)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1440 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1441 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
1442 memcpy ((void*)info.varaddress, p, info.size);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1443 p += info.size;
442
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 /* Do the relocations */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1447 pdump_rt_list = p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1448 count = 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1449 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1450 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1451 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1452 p = (char *) ALIGN_PTR (p, char *);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1453 if (rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1454 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1455 char **reloc = (char **)p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1456 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1457 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1458 reloc[i] += delta;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1459 pdump_reloc_one (reloc[i], delta, rt.desc);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1460 }
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1461 p += rt.count * sizeof (char *);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1462 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1463 if (!(--count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1464 break;
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
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1467 /* Put the pdump_root_objects variables in place */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1468 i = PDUMP_READ_ALIGNED (p, Elemcount);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1469 p = (char *) ALIGN_PTR (p, pdump_static_Lisp_Object);
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1470 while (i--)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1471 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1472 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
1473
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1474 if (POINTER_TYPE_P (XTYPE (obj.value)))
619
8d7292eb4a18 [xemacs-hg @ 2001-06-19 01:35:35 by ben]
ben
parents: 617
diff changeset
1475 obj.value = wrap_pointer_1 ((char *) XPNTR (obj.value) + delta);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1476
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1477 (* obj.address) = obj.value;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1478 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1479
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1480 /* Final cleanups */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1481 /* reorganize hash tables */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1482 p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1483 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1484 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
1485 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
1486 p = (char *) ALIGN_PTR (p, Lisp_Object);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1487 if (!rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1488 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1489 if (rt.desc == hash_table_description)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1490 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1491 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1492 pdump_reorganize_hash_table (PDUMP_READ (p, Lisp_Object));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1493 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1494 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1495 p += sizeof (Lisp_Object) * rt.count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1496 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1497
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1498 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1499 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1500
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1501 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1502 /* 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
1503 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1504 pdump_file_unmap (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1505 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1506 UnmapViewOfFile (pdump_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1507 CloseHandle (pdump_hFile);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1508 CloseHandle (pdump_hMap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1509 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1510
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1511 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1512 pdump_file_get (const char *path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1513 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1514
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1515 pdump_hFile = CreateFileA (path,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1516 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1517 0, /* Not shared */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1518 NULL, /* Not inheritable */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1519 OPEN_EXISTING,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1520 FILE_ATTRIBUTE_NORMAL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1521 NULL); /* No template file */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1522 if (pdump_hFile == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1523 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1524
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1525 pdump_length = GetFileSize (pdump_hFile, NULL);
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1526 pdump_hMap = CreateFileMappingA (pdump_hFile,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1527 NULL, /* No security attributes */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1528 PAGE_WRITECOPY, /* Copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1529 0, /* Max size, high half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1530 0, /* Max size, low half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1531 NULL); /* Unnamed */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1532 if (pdump_hMap == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1533 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1534
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1535 pdump_start = MapViewOfFile (pdump_hMap,
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1536 FILE_MAP_COPY, /* Copy on write */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1537 0, /* Start at zero */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1538 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1539 0); /* Map all of it */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1540 pdump_free = pdump_file_unmap;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1541 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1542 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1543
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1544 /* pdump_resource_free is called (via the pdump_free pointer) to release
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1545 any resources allocated by pdump_resource_get. Since the Windows API
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1546 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
1547 resources allocated by FindResource, LoadResource, and LockResource this
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1548 routine does nothing. */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1549 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1550 pdump_resource_free (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1551 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1552 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1553
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1554 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1555 pdump_resource_get (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1556 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1557 HRSRC hRes; /* Handle to dump resource */
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1558 HRSRC hResLoad; /* Handle to loaded dump resource */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1559
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1560 /* See Q126630 which describes how Windows NT and 95 trap writes to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1561 resource sections and duplicate the page to allow the write to proceed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1562 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
1563 private to each process). Doing this avoids the exceptions and related
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1564 overhead, but causes the resource section to be private to each process
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1565 that is running XEmacs. Since the resource section contains little
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1566 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
1567 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
1568
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1569 hRes = FindResourceA (NULL, MAKEINTRESOURCE (101), "DUMP");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1570 if (hRes == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1571 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1572
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1573 /* Found it, use the data in the resource */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1574 hResLoad = LoadResource (NULL, hRes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1575 if (hResLoad == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1576 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1577
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1578 pdump_start = LockResource (hResLoad);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1579 if (pdump_start == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1580 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1581
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1582 pdump_free = pdump_resource_free;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1583 pdump_length = SizeofResource (NULL, hRes);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1584 if (pdump_length <= (Bytecount) sizeof (pdump_header))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1585 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1586 pdump_start = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1587 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1588 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1589
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1590 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1591 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1592
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1593 #else /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1594
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1595 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1596 pdump_file_free (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1597 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1598 xfree (pdump_start);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1599 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1600
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1601 #ifdef HAVE_MMAP
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1602 static void
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1603 pdump_file_unmap (void)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1604 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1605 munmap (pdump_start, pdump_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1606 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1607 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1608
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1609 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1610 pdump_file_get (const char *path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1611 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1612 int fd = open (path, O_RDONLY | OPEN_BINARY);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1613 if (fd<0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1614 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1615
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1616 pdump_length = lseek (fd, 0, SEEK_END);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1617 if (pdump_length < (Bytecount) sizeof (pdump_header))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1618 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1619 retry_close (fd);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1620 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1621 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1622
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1623 lseek (fd, 0, SEEK_SET);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1624
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1625 #ifdef HAVE_MMAP
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1626 /* Unix 98 requires that sys/mman.h define MAP_FAILED,
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1627 but many earlier implementations don't. */
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1628 # ifndef MAP_FAILED
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1629 # define MAP_FAILED ((void *) -1L)
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1630 # endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1631 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
1632 if (pdump_start != (char *) MAP_FAILED)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1633 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1634 pdump_free = pdump_file_unmap;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1635 retry_close (fd);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1636 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1637 }
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1638 #endif /* HAVE_MMAP */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1639
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1640 pdump_start = xnew_array (char, pdump_length);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1641 pdump_free = pdump_file_free;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1642 retry_read (fd, pdump_start, pdump_length);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1643
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1644 retry_close (fd);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1645 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1646 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1647 #endif /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1648
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1649
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1650 static int
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1651 pdump_file_try (char *exe_path)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1652 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
1653 char *w = exe_path + strlen (exe_path);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1654
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1655 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1656 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1657 sprintf (w, "-%s-%08x.dmp", EMACS_VERSION, dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1658 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1659 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1660 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1661 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1662 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1663 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1664
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1665 sprintf (w, "-%08x.dmp", dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1666 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1667 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1668 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1669 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1670 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1671 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1672
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1673 sprintf (w, ".dmp");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1674 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1675 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1676 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1677 return 1;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1678 pdump_free ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1679 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1680
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1681 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1682 w--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1683 while (w>exe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.'));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1684 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1685 while (w>exe_path && !IS_DIRECTORY_SEP (*w));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1686 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1687 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1688
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1689 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1690 pdump_load (const Extbyte *argv0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1691 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1692 Extbyte exe_path[PATH_MAX];
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1693 #ifdef WIN32_NATIVE
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1694 GetModuleFileNameA (NULL, exe_path, PATH_MAX);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1695 #else /* !WIN32_NATIVE */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1696 Extbyte *w;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1697 const Extbyte *dir, *p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1698
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1699 dir = argv0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1700 if (dir[0] == '-')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1701 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1702 /* XEmacs as a login shell, oh goody! */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1703 dir = getenv ("SHELL"); /* not egetenv -- not yet initialized */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1704 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1705
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1706 p = dir + strlen (dir);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1707 while (p != dir && !IS_ANY_SEP (p[-1])) p--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1708
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1709 if (p != dir)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1710 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1711 /* invocation-name includes a directory component -- presumably it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1712 is relative to cwd, not $PATH */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1713 strcpy (exe_path, dir);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1714 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1715 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1716 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1717 const Extbyte *path = getenv ("PATH"); /* not egetenv -- not yet init. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1718 const Extbyte *name = p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1719 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1720 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1721 p = path;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1722 while (*p && *p != SEPCHAR)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1723 p++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1724 if (p == path)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1725 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1726 exe_path[0] = '.';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1727 w = exe_path + 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1728 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1729 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1730 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1731 memcpy (exe_path, path, p - path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1732 w = exe_path + (p - path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1733 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1734 if (!IS_DIRECTORY_SEP (w[-1]))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1735 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1736 *w++ = '/';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1737 }
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
1738 strcpy (w, name);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1739
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1740 if (!access (exe_path, X_OK))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1741 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1742 if (!*p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1743 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1744 /* Oh well, let's have some kind of default */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1745 sprintf (exe_path, "./%s", name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1746 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1747 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1748 path = p+1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1749 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1750 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1751 #endif /* WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1752
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1753 if (pdump_file_try (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1754 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1755 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1756 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1757 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1758
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1759 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1760 if (pdump_resource_get ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1761 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1762 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1763 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1764 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1765 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1766 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1767 pdump_free ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1768 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1769 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1770
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1771 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1772 }