annotate src/dumper.c @ 460:223736d75acb r21-2-45

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