annotate src/dumper.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents
children 1ccc32a20af4
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
3
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
4 This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7 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
8 Free Software Foundation; either version 2, or (at your option) any
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
10
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11 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
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
14 for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23 #include <config.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24 #include "lisp.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
25
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
26 #include "dump-id.h"
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 "alloc.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29 #include "elhash.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 #include "sysfile.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
31 #include "console-stream.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32 #include "dumper.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 #include "nt.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37 #ifdef HAVE_MMAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
38 #include <sys/mman.h>
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 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 #ifndef SEPCHAR
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
43 #define SEPCHAR ':'
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
44 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
45
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
46 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
47 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
48 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
49 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
50 } pdump_reloc_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
51
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
52 static char *pdump_rt_list = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
53
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
54 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
55 pdump_objects_unmark (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
56 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
57 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
58 char *p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
59 if (p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
60 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
61 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
62 pdump_reloc_table *rt = (pdump_reloc_table *)p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
63 p += sizeof (pdump_reloc_table);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
64 if (rt->desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
65 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
66 for (i=0; i<rt->count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
67 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
68 struct lrecord_header *lh = * (struct lrecord_header **) p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
69 if (! C_READONLY_RECORD_HEADER_P (lh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
70 UNMARK_RECORD_HEADER (lh);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
71 p += sizeof (EMACS_INT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
72 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
73 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
74 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
75 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
76 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
77
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
78
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
79 /* The structure of the file
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
80 *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
81 * 0 - header
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
82 * 256 - dumped objects
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
83 * stab_offset - nb_staticpro*(Lisp_Object *) from staticvec
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
84 * - nb_staticpro*(relocated Lisp_Object) pointed to by staticpro
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
85 * - nb_structdmp*pair(void *, adr) for pointers to structures
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
86 * - lrecord_implementations_table[]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
87 * - relocation table
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
88 * - wired variable address/value couples with the count preceding the list
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
89 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
90
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
91
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
92 #define DUMP_SIGNATURE "XEmacsDP"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
93 #define DUMP_SIGNATURE_LEN (sizeof (DUMP_SIGNATURE) - 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
94
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
95 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
96 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
97 char signature[DUMP_SIGNATURE_LEN];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
98 unsigned int id;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
99 EMACS_UINT stab_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
100 EMACS_UINT reloc_address;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
101 int nb_staticpro;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
102 int nb_structdmp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
103 int nb_opaquedmp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
104 } dump_header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
105
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
106 char *pdump_start, *pdump_end;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
107 static size_t pdump_length;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
108
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
109 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
110 // Handle for the dump file
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
111 HANDLE pdump_hFile = INVALID_HANDLE_VALUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
112 // Handle for the file mapping object for the dump file
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
113 HANDLE pdump_hMap = INVALID_HANDLE_VALUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
114 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
115
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
116 void (*pdump_free) (void);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
117
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
118 static const unsigned char align_table[256] =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
119 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
120 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
121 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
122 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
123 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
124 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
125 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
126 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
127 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
128 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
129 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
130 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
131 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
132 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
133 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
134 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
135 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
136 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
137
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
138 typedef struct pdump_entry_list_elmt
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
139 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
140 struct pdump_entry_list_elmt *next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
141 const void *obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
142 size_t size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
143 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
144 int is_lrecord;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
145 EMACS_INT save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
146 } pdump_entry_list_elmt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
147
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
148 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
149 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
150 pdump_entry_list_elmt *first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
151 int align;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
152 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
153 } pdump_entry_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
154
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
155 typedef struct pdump_struct_list_elmt
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
156 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
157 pdump_entry_list list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
158 const struct struct_description *sdesc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
159 } pdump_struct_list_elmt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
160
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 typedef struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163 pdump_struct_list_elmt *list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164 int count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165 int size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166 } pdump_struct_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168 static pdump_entry_list pdump_object_table[256];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
169 static pdump_entry_list pdump_opaque_data_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 static pdump_struct_list pdump_struct_table;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171 static pdump_entry_list_elmt *pdump_qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
172
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
173 static int pdump_alert_undump_object[256];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175 static unsigned long cur_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 static size_t max_size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 static int pdump_fd;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 static void *pdump_buf;
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 #define PDUMP_HASHSIZE 200001
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 static pdump_entry_list_elmt **pdump_hash;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
184 /* 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
185 static int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
186 pdump_make_hash (const void *obj)
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 return ((unsigned long)(obj)>>3) % PDUMP_HASHSIZE;
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 static pdump_entry_list_elmt *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
192 pdump_get_entry (const void *obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
193 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
194 int pos = pdump_make_hash (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
195 pdump_entry_list_elmt *e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
196
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
197 assert (obj != 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
198
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
199 while ((e = pdump_hash[pos]) != 0)
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 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
202 return e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
203
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
204 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
205 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
206 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
207 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
208 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
209 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
210
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
211 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
212 pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, int count, int is_lrecord)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
213 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
214 pdump_entry_list_elmt *e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
215 int align;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
216 int pos = pdump_make_hash (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
217
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
218 while ((e = pdump_hash[pos]) != 0)
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 if (e->obj == obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
221 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
222
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
223 pos++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
224 if (pos == PDUMP_HASHSIZE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
225 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
226 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
227
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
228 e = xnew (pdump_entry_list_elmt);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
229
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
230 e->next = list->first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
231 e->obj = obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
232 e->size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
233 e->count = count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
234 e->is_lrecord = is_lrecord;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
235 list->first = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
236
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
237 list->count += count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
238 pdump_hash[pos] = e;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
239
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
240 align = align_table[size & 255];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
241 if (align < 2 && is_lrecord)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
242 align = 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
243
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
244 if (align < list->align)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
245 list->align = align;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
246 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
247
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
248 static pdump_entry_list *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 pdump_get_entry_list (const struct struct_description *sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
250 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
251 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
252 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
253 if (pdump_struct_table.list[i].sdesc == sdesc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
254 return &pdump_struct_table.list[i].list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
255
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
256 if (pdump_struct_table.size <= pdump_struct_table.count)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
257 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
258 if (pdump_struct_table.size == -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
259 pdump_struct_table.size = 10;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
260 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
261 pdump_struct_table.size = pdump_struct_table.size * 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
262 pdump_struct_table.list = (pdump_struct_list_elmt *)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
263 xrealloc (pdump_struct_table.list,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
264 pdump_struct_table.size * sizeof (pdump_struct_list_elmt));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
265 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
266 pdump_struct_table.list[pdump_struct_table.count].list.first = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
267 pdump_struct_table.list[pdump_struct_table.count].list.align = 8;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
268 pdump_struct_table.list[pdump_struct_table.count].list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
269 pdump_struct_table.list[pdump_struct_table.count].sdesc = sdesc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
270
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
271 return &pdump_struct_table.list[pdump_struct_table.count++].list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
272 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
273
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
274 static struct
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
275 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
276 struct lrecord_header *obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
277 int position;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
278 int offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
279 } backtrace[65536];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
280
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
281 static int depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
282
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
283 static void pdump_backtrace (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
284 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
285 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
286 stderr_out ("pdump backtrace :\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
287 for (i=0;i<depth;i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
289 if (!backtrace[i].obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
290 stderr_out (" - ind. (%d, %d)\n", backtrace[i].position, backtrace[i].offset);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
291 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
292 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 stderr_out (" - %s (%d, %d)\n",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
294 LHEADER_IMPLEMENTATION (backtrace[i].obj)->name,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
295 backtrace[i].position,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
296 backtrace[i].offset);
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
299 }
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 static void pdump_register_object (Lisp_Object obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
302 static void pdump_register_struct (const void *data, const struct struct_description *sdesc, int count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
303
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
304 static EMACS_INT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
305 pdump_get_indirect_count (EMACS_INT code, const struct lrecord_description *idesc, const void *idata)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
306 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
307 EMACS_INT count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
308 const void *irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
309
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
310 int line = XD_INDIRECT_VAL (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
311 int delta = XD_INDIRECT_DELTA (code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
312
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
313 irdata = ((char *)idata) + idesc[line].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
314 switch (idesc[line].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
315 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
316 case XD_SIZE_T:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
317 count = *(size_t *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
318 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
319 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
320 count = *(int *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
321 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
322 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
323 count = *(long *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
324 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
325 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
326 count = *(Bytecount *)irdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
327 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
328 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
329 stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n", idesc[line].type, line, (long)code);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
330 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
331 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
332 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
333 count += delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
334 return count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
335 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
336
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
337 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
338 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
339 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
340 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
341
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
342 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
343 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
344 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
345 const void *rdata = (const char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
346
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
347 backtrace[me].position = pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
348 backtrace[me].offset = desc[pos].offset;
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 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
351 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
352 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
353 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
354 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
355 goto restart;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
356 case XD_SIZE_T:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
357 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
358 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
359 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
360 case XD_LO_RESET_NIL:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
361 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
362 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
363 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
364 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
365 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
366 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
367 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
368 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
369
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
370 pdump_add_entry (&pdump_opaque_data_list,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
371 *(void **)rdata,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
372 count,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
373 1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
374 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
375 break;
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 case XD_C_STRING:
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 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
380 if (str)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
381 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
382 break;
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 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
385 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
386 const char *str = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
387 if ((EMACS_INT)str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
388 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
389 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
390 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
391 case XD_LISP_OBJECT:
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 const Lisp_Object *pobj = (const Lisp_Object *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
394
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
395 assert (desc[pos].data1 == 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
396
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
397 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
398 pdump_register_object (*pobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
399 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
400 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
401 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
402 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
403 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
404 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
405 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
406 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
407
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
408 for (i = 0; i < count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
409 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
410 const Lisp_Object *pobj = ((const Lisp_Object *)rdata) + i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
411 Lisp_Object dobj = *pobj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
412
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
413 backtrace[me].offset = (const char *)pobj - (const char *)data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
414 pdump_register_object (dobj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
415 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
416 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
417 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
418 case XD_STRUCT_PTR:
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 EMACS_INT count = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
421 const struct struct_description *sdesc = desc[pos].data2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
422 const char *dobj = *(const char **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
423 if (dobj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
424 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
425 if (XD_IS_INDIRECT (count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
426 count = pdump_get_indirect_count (count, desc, data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
427
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
428 pdump_register_struct (dobj, sdesc, count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
429 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
430 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
431 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
432 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
433 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
434 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
435 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
436 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
437 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
438 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
439
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
440 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
441 pdump_register_object (Lisp_Object obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
442 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
443 struct lrecord_header *objh;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
444
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
445 if (!POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
446 return;
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 objh = XRECORD_LHEADER (obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
449 if (!objh)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
450 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
451
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
452 if (pdump_get_entry (objh))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
453 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
454
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
455 if (LHEADER_IMPLEMENTATION (objh)->description)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
456 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
457 int me = depth++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 if (me>65536)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
459 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
460 stderr_out ("Backtrace overflow, loop ?\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461 abort ();
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 backtrace[me].obj = objh;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
464 backtrace[me].position = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
465 backtrace[me].offset = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
466
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
467 pdump_add_entry (pdump_object_table + objh->type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
468 objh,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
469 LHEADER_IMPLEMENTATION (objh)->static_size ?
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
470 LHEADER_IMPLEMENTATION (objh)->static_size :
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
471 LHEADER_IMPLEMENTATION (objh)->size_in_bytes_method (objh),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
472 1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
473 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
474 pdump_register_sub (objh,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
475 LHEADER_IMPLEMENTATION (objh)->description,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
476 me);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
477 --depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
478 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
479 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
480 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
481 pdump_alert_undump_object[objh->type]++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
482 stderr_out ("Undumpable object type : %s\n", LHEADER_IMPLEMENTATION (objh)->name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
483 pdump_backtrace ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
484 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
485 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
486
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
487 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
488 pdump_register_struct (const void *data, const struct struct_description *sdesc, int count)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
489 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
490 if (data && !pdump_get_entry (data))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
491 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
492 int me = depth++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
493 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
494 if (me>65536)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
495 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
496 stderr_out ("Backtrace overflow, loop ?\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
497 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
498 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
499 backtrace[me].obj = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
500 backtrace[me].position = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
501 backtrace[me].offset = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
503 pdump_add_entry (pdump_get_entry_list (sdesc),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
504 data,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 sdesc->size,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506 count,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
508 for (i=0; i<count; i++)
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 pdump_register_sub (((char *)data) + sdesc->size*i,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
511 sdesc->description,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
512 me);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
513 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
514 --depth;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
515 }
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
518 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
519 pdump_dump_data (pdump_entry_list_elmt *elmt, const struct lrecord_description *desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
520 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
521 size_t size = elmt->size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
522 int count = elmt->count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
523 if (desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
524 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
525 int pos, i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
526 memcpy (pdump_buf, elmt->obj, size*count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
527
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
528 for (i=0; i<count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
529 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
530 char *cur = ((char *)pdump_buf) + i*size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
531 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
532 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
533 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
534 void *rdata = cur + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
535 switch (desc[pos].type)
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 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
538 desc = ((const Lisp_Specifier *)(elmt->obj))->methods->extra_description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
539 goto restart;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
540 case XD_SIZE_T:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541 case XD_INT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 case XD_LONG:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
543 case XD_BYTECOUNT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
544 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
545 case XD_LO_RESET_NIL:
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 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549 if (XD_IS_INDIRECT (num))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 num = pdump_get_indirect_count (num, desc, elmt->obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 for (j=0; j<num; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
552 ((EMACS_INT *)rdata)[j] = pdump_qnil->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
553 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
554 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
555 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
556 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
557 EMACS_INT val = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
558 if (XD_IS_INDIRECT (val))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
559 val = pdump_get_indirect_count (val, desc, elmt->obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
560 *(int *)rdata = val;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
561 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
562 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
563 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
564 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
565 case XD_STRUCT_PTR:
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 void *ptr = *(void **)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
568 if (ptr)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
569 *(EMACS_INT *)rdata = pdump_get_entry (ptr)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
570 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
571 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
572 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
573 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
574 Lisp_Object obj = *(Lisp_Object *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
575 pdump_entry_list_elmt *elmt1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
576 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
577 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
578 elmt1 = pdump_get_entry (XRECORD_LHEADER (obj));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
579 if (elmt1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
580 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
581 obj = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
582 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
583 *(EMACS_INT *)rdata = elmt1->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
584 break;
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 case XD_LISP_OBJECT:
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 Lisp_Object *pobj = (Lisp_Object *) rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
589
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
590 assert (desc[pos].data1 == 0);
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 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
593 *(EMACS_INT *)pobj =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
594 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
595 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
596 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
597 case XD_LISP_OBJECT_ARRAY:
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 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
600 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
601 if (XD_IS_INDIRECT (num))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
602 num = pdump_get_indirect_count (num, desc, elmt->obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
603
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
604 for (j=0; j<num; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
605 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
606 Lisp_Object *pobj = ((Lisp_Object *)rdata) + j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
607 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
608 *(EMACS_INT *)pobj =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
609 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
610 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
611 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
612 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
613 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
614 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
615 EMACS_INT str = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
616 if (str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
617 *(EMACS_INT *)rdata = pdump_get_entry ((void *)str)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
618 break;
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 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
621 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
622 abort ();
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
625 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
626 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
627 write (pdump_fd, desc ? pdump_buf : elmt->obj, size*count);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
628 if (elmt->is_lrecord && ((size*count) & 3))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
629 write (pdump_fd, "\0\0\0", 4-((size*count) & 3));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
630 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
631
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
632 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
633 pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description *desc)
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 int pos;
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 restart:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
638 for (pos = 0; desc[pos].type != XD_END; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
639 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
640 void *rdata = (char *)data + desc[pos].offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
641 switch (desc[pos].type)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
642 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
643 case XD_SPECIFIER_END:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
644 pos = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
645 desc = ((const Lisp_Specifier *)data)->methods->extra_description;
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 case XD_INT_RESET:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
652 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
653 case XD_OPAQUE_DATA_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
654 case XD_C_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
655 case XD_STRUCT_PTR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
656 case XD_LO_LINK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
657 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
658 EMACS_INT ptr = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
659 if (ptr)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
660 *(EMACS_INT *)rdata = ptr+delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
661 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
662 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
663 case XD_LISP_OBJECT:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
664 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
665 Lisp_Object *pobj = (Lisp_Object *) rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
666
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
667 assert (desc[pos].data1 == 0);
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 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
670 && ! EQ (*pobj, Qnull_pointer))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
671 XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
672
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
673 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
674 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
675 case XD_LISP_OBJECT_ARRAY:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
676 case XD_LO_RESET_NIL:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
677 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
678 EMACS_INT num = desc[pos].data1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
679 int j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
680 if (XD_IS_INDIRECT (num))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
681 num = pdump_get_indirect_count (num, desc, data);
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 for (j=0; j<num; j++)
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 + j;
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 if (POINTER_TYPE_P (XTYPE (*pobj))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
688 && ! EQ (*pobj, Qnull_pointer))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
689 XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
690 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
691 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
692 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
693 case XD_DOC_STRING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
694 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
695 EMACS_INT str = *(EMACS_INT *)rdata;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
696 if (str > 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
697 *(EMACS_INT *)rdata = str + delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
698 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
699 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
700 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
701 stderr_out ("Unsupported dump type : %d\n", desc[pos].type);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
702 abort ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
703 };
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
704 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
705 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
706
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
707 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
708 pdump_allocate_offset (pdump_entry_list_elmt *elmt, const struct lrecord_description *desc)
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 size_t size = (elmt->is_lrecord ? (elmt->size + 3) & ~3 : elmt->size)*elmt->count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
711 elmt->save_offset = cur_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
712 if (size>max_size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
713 max_size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
714 cur_offset += size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
715 }
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 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
718 pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord_description *))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
719 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
720 int align, i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
721 const struct lrecord_description *idesc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
722 pdump_entry_list_elmt *elmt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
723 for (align=8; align>=0; align--)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
724 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
725 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
726 if (pdump_object_table[i].align == align)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
727 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
728 elmt = pdump_object_table[i].first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
729 if (!elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
730 continue;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
731 idesc = lrecord_implementations_table[i]->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
732 while (elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
733 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
734 f (elmt, idesc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
735 elmt = elmt->next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
736 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
737 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
738
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
739 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
740 if (pdump_struct_table.list[i].list.align == align)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
741 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
742 elmt = pdump_struct_table.list[i].list.first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
743 idesc = pdump_struct_table.list[i].sdesc->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
744 while (elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
745 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
746 f (elmt, idesc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
747 elmt = elmt->next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
748 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
749 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
750
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
751 elmt = pdump_opaque_data_list.first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
752 while (elmt)
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 if (align_table[elmt->size & 255] == align)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
755 f (elmt, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
756 elmt = elmt->next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
757 }
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 }
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 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
762 pdump_dump_staticvec (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
763 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
764 EMACS_INT *reloc = xnew_array (EMACS_INT, staticidx);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
765 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
766 write (pdump_fd, staticvec, staticidx*sizeof (Lisp_Object *));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
767
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
768 for (i=0; i<staticidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
769 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
770 Lisp_Object obj = *staticvec[i];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
771 if (POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
772 reloc[i] = pdump_get_entry (XRECORD_LHEADER (obj))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
773 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
774 reloc[i] = *(EMACS_INT *)(staticvec[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
775 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
776 write (pdump_fd, reloc, staticidx*sizeof (Lisp_Object));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
777 free (reloc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
778 }
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 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
781 pdump_dump_structvec (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
782 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
783 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
784 for (i=0; i<dumpstructidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
785 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
786 EMACS_INT adr;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
787 write (pdump_fd, &(dumpstructvec[i].data), sizeof (void *));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
788 adr = pdump_get_entry (*(void **)(dumpstructvec[i].data))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
789 write (pdump_fd, &adr, sizeof (adr));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
790 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
791 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
792
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
793 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
794 pdump_dump_opaquevec (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
795 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
796 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
797 for (i=0; i<dumpopaqueidx; i++)
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 write (pdump_fd, &(dumpopaquevec[i]), sizeof (dumpopaquevec[i]));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
800 write (pdump_fd, dumpopaquevec[i].data, dumpopaquevec[i].size);
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
803
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
804 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
805 pdump_dump_itable (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
806 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
807 write (pdump_fd, lrecord_implementations_table, lrecord_type_count*sizeof (lrecord_implementations_table[0]));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
808 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
809
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
810 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
811 pdump_dump_rtables (void)
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 int i, j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
814 pdump_entry_list_elmt *elmt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
815 pdump_reloc_table rt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
816
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
817 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
818 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
819 elmt = pdump_object_table[i].first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
820 if (!elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
821 continue;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
822 rt.desc = lrecord_implementations_table[i]->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
823 rt.count = pdump_object_table[i].count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
824 write (pdump_fd, &rt, sizeof (rt));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
825 while (elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
826 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
827 EMACS_INT rdata = pdump_get_entry (elmt->obj)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
828 write (pdump_fd, &rdata, sizeof (rdata));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
829 elmt = elmt->next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
830 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
831 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
832
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
833 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
834 rt.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
835 write (pdump_fd, &rt, sizeof (rt));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
836
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
837 for (i=0; i<pdump_struct_table.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
838 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
839 elmt = pdump_struct_table.list[i].list.first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
840 rt.desc = pdump_struct_table.list[i].sdesc->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
841 rt.count = pdump_struct_table.list[i].list.count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
842 write (pdump_fd, &rt, sizeof (rt));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
843 while (elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
844 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
845 EMACS_INT rdata = pdump_get_entry (elmt->obj)->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
846 for (j=0; j<elmt->count; j++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
847 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
848 write (pdump_fd, &rdata, sizeof (rdata));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
849 rdata += elmt->size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
850 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
851 elmt = elmt->next;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
852 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
853 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
854 rt.desc = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
855 rt.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
856 write (pdump_fd, &rt, sizeof (rt));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
859 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
860 pdump_dump_wired (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
861 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
862 EMACS_INT count = pdump_wireidx + pdump_wireidx_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
863 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
864
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
865 write (pdump_fd, &count, sizeof (count));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
866
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
867 for (i=0; i<pdump_wireidx; i++)
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 EMACS_INT obj = pdump_get_entry (XRECORD_LHEADER (*(pdump_wirevec[i])))->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
870 write (pdump_fd, &pdump_wirevec[i], sizeof (pdump_wirevec[i]));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
871 write (pdump_fd, &obj, sizeof (obj));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
872 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
873
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
874 for (i=0; i<pdump_wireidx_list; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
875 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
876 Lisp_Object obj = *(pdump_wirevec_list[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
877 pdump_entry_list_elmt *elmt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
878 EMACS_INT res;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
879
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
880 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
881 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
882 const struct lrecord_description *desc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
883 int pos;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
884 elmt = pdump_get_entry (XRECORD_LHEADER (obj));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
885 if (elmt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
886 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
887 desc = XRECORD_LHEADER_IMPLEMENTATION (obj)->description;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
888 for (pos = 0; desc[pos].type != XD_LO_LINK; pos++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
889 assert (desc[pos].type != XD_END);
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 obj = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj)));
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 res = elmt->save_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
894
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
895 write (pdump_fd, &pdump_wirevec_list[i], sizeof (pdump_wirevec_list[i]));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
896 write (pdump_fd, &res, sizeof (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
897 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
898 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
899
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
900 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
901 pdump (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
902 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
903 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
904 Lisp_Object t_console, t_device, t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
905 int none;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
906 dump_header hd;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
907
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
908 /* These appear in a DEFVAR_LISP, which does a staticpro() */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
909 t_console = Vterminal_console;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
910 t_frame = Vterminal_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
911 t_device = Vterminal_device;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
912
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
913 Vterminal_console = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
914 Vterminal_frame = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
915 Vterminal_device = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
916
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
917 pdump_hash = xnew_array_and_zero (pdump_entry_list_elmt *, PDUMP_HASHSIZE);
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 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
920 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
921 pdump_object_table[i].first = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
922 pdump_object_table[i].align = 8;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
923 pdump_object_table[i].count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
924 pdump_alert_undump_object[i] = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
925 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
926 pdump_struct_table.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
927 pdump_struct_table.size = -1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
928
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
929 pdump_opaque_data_list.first = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
930 pdump_opaque_data_list.align = 8;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
931 pdump_opaque_data_list.count = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
932 depth = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
933
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
934 for (i=0; i<staticidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
935 pdump_register_object (*staticvec[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
936 for (i=0; i<pdump_wireidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
937 pdump_register_object (*pdump_wirevec[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
938
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
939 none = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
940 for (i=0; i<lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
941 if (pdump_alert_undump_object[i])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
942 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
943 if (none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
944 printf ("Undumpable types list :\n");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
945 none = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
946 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
947 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
948 if (!none)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
949 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
950
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
951 for (i=0; i<dumpstructidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
952 pdump_register_struct (*(void **)(dumpstructvec[i].data), dumpstructvec[i].desc, 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
953
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
954 memcpy (hd.signature, DUMP_SIGNATURE, DUMP_SIGNATURE_LEN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
955 hd.id = dump_id;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
956 hd.reloc_address = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
957 hd.nb_staticpro = staticidx;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
958 hd.nb_structdmp = dumpstructidx;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
959 hd.nb_opaquedmp = dumpopaqueidx;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
960
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
961 cur_offset = 256;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
962 max_size = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
963
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
964 pdump_scan_by_alignment (pdump_allocate_offset);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
965 pdump_qnil = pdump_get_entry (XRECORD_LHEADER (Qnil));
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 pdump_buf = xmalloc (max_size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
968 /* Avoid use of the `open' macro. We want the real function. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
969 #undef open
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
970 pdump_fd = open (EMACS_PROGNAME ".dmp",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
971 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, 0666);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
972 hd.stab_offset = (cur_offset + 3) & ~3;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
973
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
974 write (pdump_fd, &hd, sizeof (hd));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
975 lseek (pdump_fd, 256, SEEK_SET);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
976
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
977 pdump_scan_by_alignment (pdump_dump_data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
978
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
979 lseek (pdump_fd, hd.stab_offset, SEEK_SET);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
980
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
981 pdump_dump_staticvec ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
982 pdump_dump_structvec ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
983 pdump_dump_opaquevec ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
984 pdump_dump_itable ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
985 pdump_dump_rtables ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
986 pdump_dump_wired ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
987
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
988 close (pdump_fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
989 free (pdump_buf);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
990
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
991 free (pdump_hash);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
992
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
993 Vterminal_console = t_console;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
994 Vterminal_frame = t_frame;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
995 Vterminal_device = t_device;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
996 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
997
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
998 static int pdump_load_check (void)
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 return (!memcmp (((dump_header *)pdump_start)->signature, DUMP_SIGNATURE, DUMP_SIGNATURE_LEN)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1001 && ((dump_header *)pdump_start)->id == dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1002 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1003
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1004 static int pdump_load_finish (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1005 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1006 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1007 char *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1008 EMACS_INT delta;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1009 EMACS_INT count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1010
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1011 pdump_end = pdump_start + pdump_length;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1012
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1013 #define PDUMP_READ(p, type) (p = (char*) (((type *) p) + 1), *((type *) p - 1))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1014
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1015 staticidx = ((dump_header *)(pdump_start))->nb_staticpro;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1016 delta = ((EMACS_INT)pdump_start) - ((dump_header *)pdump_start)->reloc_address;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1017 p = pdump_start + ((dump_header *)pdump_start)->stab_offset;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1018
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1019 /* Put back the staticvec in place */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1020 memcpy (staticvec, p, staticidx*sizeof (Lisp_Object *));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1021 p += staticidx*sizeof (Lisp_Object *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1022 for (i=0; i<staticidx; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1023 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1024 Lisp_Object obj = PDUMP_READ (p, Lisp_Object);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1025 if (POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1026 XSETOBJ (obj, (char *) XPNTR (obj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1027 *staticvec[i] = obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1028 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1029
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1030 /* Put back the dumpstructs */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1031 for (i=0; i<((dump_header *)pdump_start)->nb_structdmp; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1032 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1033 void **adr = PDUMP_READ (p, void **);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1034 *adr = (void *) (PDUMP_READ (p, char *) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1035 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1036
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1037 /* Put back the opaques */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1038 for (i=0; i<((dump_header *)pdump_start)->nb_opaquedmp; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1039 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1040 struct pdump_dumpopaqueinfo di = PDUMP_READ (p, struct pdump_dumpopaqueinfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1041 memcpy (di.data, p, di.size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1042 p += di.size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1043 }
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 /* Put back the lrecord_implementations_table */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1046 /* The (void *) cast is there to make Ben happy. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1047 memcpy ((void *) lrecord_implementations_table, p, lrecord_type_count*sizeof (lrecord_implementations_table[0]));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1048 p += lrecord_type_count*sizeof (lrecord_implementations_table[0]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1049
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1050 /* Reinitialize lrecord_markers from lrecord_implementations_table */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1051 for (i=0; i < lrecord_type_count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1052 if (lrecord_implementations_table[i])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1053 lrecord_markers[i] = lrecord_implementations_table[i]->marker;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1054
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1055 /* Do the relocations */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1056 pdump_rt_list = p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1057 count = 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1058 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1059 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1060 pdump_reloc_table rt = PDUMP_READ (p, pdump_reloc_table);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1061 if (rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1062 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1063 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1064 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1065 char *adr = delta + *(char **)p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1066 *(char **)p = adr;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1067 pdump_reloc_one (adr, delta, rt.desc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1068 p += sizeof (char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1069 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1070 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1071 if (!(--count))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1072 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1073 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1074
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1075 /* Put the pdump_wire variables in place */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1076 count = PDUMP_READ (p, EMACS_INT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1077
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1078 for (i=0; i<count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1079 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1080 Lisp_Object *var = PDUMP_READ (p, Lisp_Object *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1081 Lisp_Object obj = PDUMP_READ (p, Lisp_Object);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1082
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1083 if (POINTER_TYPE_P (XTYPE (obj)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1084 XSETOBJ (obj, (char *) XPNTR (obj) + delta);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1085
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1086 *var = obj;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1087 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1088
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1089 /* Final cleanups */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1090 /* reorganize hash tables */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1091 p = pdump_rt_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1092 for (;;)
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 pdump_reloc_table rt = PDUMP_READ (p, pdump_reloc_table);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1095 if (!rt.desc)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1096 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1097 if (rt.desc == hash_table_description)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1098 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1099 for (i=0; i < rt.count; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1100 pdump_reorganize_hash_table (PDUMP_READ (p, Lisp_Object));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1101 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1102 } else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1103 p += sizeof (Lisp_Object) * rt.count;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1104 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1105
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1106 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1107 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1108
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1109 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1110 /* Free the mapped file if we decide we don't want it after all */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1111 static void pdump_file_unmap(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1112 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1113 UnmapViewOfFile (pdump_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1114 CloseHandle (pdump_hFile);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1115 CloseHandle (pdump_hMap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1116 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1117
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1118 static int pdump_file_get(const char *path)
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 pdump_hFile = CreateFile (path,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1122 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1123 0, /* Not shared */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1124 NULL, /* Not inheritable */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1125 OPEN_EXISTING,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1126 FILE_ATTRIBUTE_NORMAL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1127 NULL); /* No template file */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1128 if (pdump_hFile == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1129 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1130
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1131 pdump_length = GetFileSize (pdump_hFile, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1132 pdump_hMap = CreateFileMapping (pdump_hFile,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1133 NULL, /* No security attributes */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1134 PAGE_WRITECOPY, /* Copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1135 0, /* Max size, high half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1136 0, /* Max size, low half */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1137 NULL); /* Unnamed */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1138 if (pdump_hMap == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1139 return 0;
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 pdump_start = MapViewOfFile (pdump_hMap,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1142 FILE_MAP_COPY, /* Copy on write */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1143 0, /* Start at zero */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1144 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1145 0); /* Map all of it */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1146 pdump_free = pdump_file_unmap;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1147 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1148 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1149
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1150 /* pdump_resource_free is called (via the pdump_free pointer) to release
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1151 any resources allocated by pdump_resource_get. Since the Windows API
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1152 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
1153 resources allocated by FindResource, LoadResource, and LockResource this
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1154 routine does nothing. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1155 static void pdump_resource_free (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1156 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1157 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1158
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1159 static int pdump_resource_get (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1160 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1161 HRSRC hRes; /* Handle to dump resource */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1162 HRSRC hResLoad; /* Handle to loaded dump resource */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1163
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1164 /* See Q126630 which describes how Windows NT and 95 trap writes to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1165 resource sections and duplicate the page to allow the write to proceed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1166 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
1167 private to each process). Doing this avoids the exceptions and related
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1168 overhead, but causes the resource section to be private to each process
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1169 that is running XEmacs. Since the resource section contains little
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1170 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
1171 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
1172
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1173 hRes = FindResource (NULL, MAKEINTRESOURCE(101), "DUMP");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1174 if (hRes == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1175 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1176
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1177 /* Found it, use the data in the resource */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1178 hResLoad = LoadResource (NULL, hRes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1179 if (hResLoad == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1180 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1181
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1182 pdump_start = LockResource (hResLoad);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1183 if (pdump_start == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1184 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1185
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1186 pdump_free = pdump_resource_free;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1187 pdump_length = SizeofResource (NULL, hRes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1188 if (pdump_length <= sizeof(dump_header))
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_start = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1191 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1192 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1193
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1194 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1195 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1196
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1197 #else /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1198
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1199 static void *pdump_mallocadr;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1200
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1201 static void pdump_file_free(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1202 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1203 xfree (pdump_mallocadr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1204 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1205
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1206 #ifdef HAVE_MMAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1207 static void pdump_file_unmap(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1208 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1209 munmap (pdump_start, pdump_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1210 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1211 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1212
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1213 static int pdump_file_get(const char *path)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1214 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1215 int fd = open (path, O_RDONLY | OPEN_BINARY);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1216 if (fd<0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1217 return 0;
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_length = lseek (fd, 0, SEEK_END);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1220 if (pdump_length < sizeof (dump_header))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1221 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1222 close (fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1223 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1224 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1225
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1226 lseek (fd, 0, SEEK_SET);
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 #ifdef HAVE_MMAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1229 pdump_start = (char *) mmap (0, pdump_length, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1230 if (pdump_start != MAP_FAILED)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1231 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1232 pdump_free = pdump_file_unmap;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1233 close (fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1234 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1235 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1236 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1237
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1238 pdump_mallocadr = xmalloc(pdump_length+255);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1239 pdump_free = pdump_file_free;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1240 pdump_start = (char *)((255 + (unsigned long)pdump_mallocadr) & ~255);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1241 read (pdump_fd, pdump_start, pdump_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1242
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1243 close (pdump_fd);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1244 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1245 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1246 #endif /* !WIN32_NATIVE */
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1249 static int pdump_file_try(char *exe_path)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1250 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1251 char *w;
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 w = exe_path + strlen(exe_path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1254 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1255 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1256 sprintf (w, "-%s-%08x.dmp", EMACS_VERSION, dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1257 if (pdump_file_get (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1258 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1259 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1260 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1261 pdump_free();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1262 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1263
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1264 sprintf (w, "-%08x.dmp", dump_id);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1265 if (pdump_file_get (exe_path))
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 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1268 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1269 pdump_free();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1270 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1271
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1272 sprintf (w, ".dmp");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1273 if (pdump_file_get (exe_path))
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 if (pdump_load_check ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1276 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1277 pdump_free();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1278 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1279
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1280 do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1281 w--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1282 while (w>exe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.'));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1283 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1284 while (w>exe_path && !IS_DIRECTORY_SEP (*w));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1285 return 0;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1288 int pdump_load(const char *argv0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1289 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1290 char exe_path[PATH_MAX];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1291 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1292 GetModuleFileName (NULL, exe_path, PATH_MAX);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1293 #else /* !WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1294 char *w;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1295 const char *dir, *p;
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 dir = argv0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1298 if (dir[0] == '-')
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 /* XEmacs as a login shell, oh goody! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1301 dir = getenv("SHELL");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1302 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1303
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1304 p = dir + strlen(dir);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1305 while (p != dir && !IS_ANY_SEP (p[-1])) p--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1306
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1307 if (p != dir)
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 /* invocation-name includes a directory component -- presumably it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1310 is relative to cwd, not $PATH */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1311 strcpy (exe_path, dir);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1312 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1313 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1314 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1315 const char *path = getenv ("PATH");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1316 const char *name = p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1317 for (;;)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1318 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1319 p = path;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1320 while (*p && *p != SEPCHAR)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1321 p++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1322 if (p == path)
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 exe_path[0] = '.';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1325 w = exe_path + 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1326 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1327 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1328 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1329 memcpy (exe_path, path, p - path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1330 w = exe_path + (p - path);
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 if (!IS_DIRECTORY_SEP (w[-1]))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1333 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1334 *w++ = '/';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1335 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1336 strcpy(w, name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1337
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 #ifdef access
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1340 #undef access
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1341 #endif
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 (!access (exe_path, X_OK))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1344 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1345 if (!*p)
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 /* Oh well, let's have some kind of default */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1348 sprintf (exe_path, "./%s", name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1349 break;
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 path = p+1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1352 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1353 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1354 #endif /* WIN32_NATIVE */
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 if (pdump_file_try (exe_path))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1357 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1358 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1359 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1360 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1361
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1362 #ifdef WIN32_NATIVE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1363 if (pdump_resource_get ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1364 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1365 if (pdump_load_check ())
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 pdump_load_finish ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1368 return 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1369 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1370 pdump_free ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1371 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1372 #endif
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 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1375 }