Mercurial > emacs
annotate etc/emacs-buffer.gdb @ 112429:6e50030da731
Some copyright.el updates.
* lisp/emacs-lisp/copyright.el (copyright-find-copyright): New function,
split out from copyright-update-year.
(copyright-update): Don't mess with the GPL version if we don't own the
copyright. Update license regexp, and remove no longer needed
Esperanto stuff.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 22 Jan 2011 14:09:09 -0800 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
62894 | 1 # emacs-buffer.gdb --- gdb macros for recovering buffers from emacs coredumps |
2 | |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
62894 | 4 |
5 # Maintainer: Noah Friedman <friedman@splode.com> | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
6 # Status: Works with Emacs 22.0.51.1 (prerelease) as of 2006-01-12. |
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
7 # Older cvs snapshots, and released versions, will not work due to |
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
8 # changes in lisp data structures. But there are older versions of |
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
9 # this gdb script which work with those versions. |
62894 | 10 # Created: 2005-04-28 |
11 | |
12 # This file is part of GNU Emacs. | |
95004
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
13 |
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
14 # GNU Emacs is free software: you can redistribute it and/or modify |
62894 | 15 # it under the terms of the GNU General Public License as published by |
95004
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
16 # the Free Software Foundation, either version 3 of the License, or |
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
17 # (at your option) any later version. |
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
18 |
62894 | 19 # GNU Emacs is distributed in the hope that it will be useful, |
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 # GNU General Public License for more details. | |
95004
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
23 |
62894 | 24 # You should have received a copy of the GNU General Public License |
95004
cbf5528cf447
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79776
diff
changeset
|
25 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
62894 | 26 |
27 # Commentary: | |
28 | |
29 # This is a set of gdb macros for recovering the contents of buffers from | |
30 # an Emacs coredump; they may not always be file-backed or have a recent | |
31 # autosave. | |
32 # | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
33 # The Emacs executable must have debugging symbols for this to work. |
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
34 # But you never strip Emacs, right? |
62894 | 35 # |
36 # The main commands of interest are `ybuffer-list', `yfile-buffers', | |
37 # `ysave-buffer', and `ybuffer-contents'. The `y' prefix avoids any | |
38 # namespace collisions with emacs/src/.gdbinit. | |
39 | |
40 # Example usage: | |
41 # | |
42 # $ gdb /export/src/emacs/2005-05-02--03-17/src/emacs core.emacs.6.9845 | |
43 # Current directory is /u/noah/ | |
44 # GNU gdb (6.1post-1.20040607.43rh) | |
45 # ... | |
46 # #0 0x400007a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 | |
47 # (gdb) source emacs-buffer.gdb | |
48 # (gdb) ybuffer-list | |
49 # B# M Size Name Mode File | |
50 # -- - ---- ---- ---- ---- | |
51 # 0 * 556 mail to emacs-devel@gnu.org Mail | |
52 # 1 * 0 *Minibuf-1* Fundamental | |
53 # 2 145769 ChangeLog Change Log /u/noah/lib/elisp/noahf/ChangeLog | |
54 # 3 6619 ascii-table.el Elisp /u/noah/lib/elisp/noahf/ascii-table.el | |
55 # 4 * 48396 *Messages* Fundamental | |
56 # 5 3191 *Apropos* Apropos | |
57 # 6 17642 init-21.el Elisp /u/noah/etc/init/emacs/init-21.el | |
58 # 7 333 cpuid.c C /u/noah/cpuid.c | |
59 # 8 230 src Dired | |
60 # 9 218 noah Dired | |
61 # 10 * 21 *Echo Area 0* Fundamental | |
62 # 11 * 0 *Echo Area 1* Fundamental | |
63 # 12 319952 *bbdb data* Text /u/noah/.bbdb | |
64 # (gdb) ysave-buffer 0 mail.save | |
65 # [Wrote buffer "mail to emacs-devel@gnu.org" to file mail.save] | |
66 # (gdb) quit | |
67 # $ ls -l mail.save | |
68 # -rw-rw-rw- 1 noah user 556 May 2 04:05 mail.save | |
69 # $ | |
70 | |
71 # Code: | |
72 | |
73 # Force loading of symbols, enough to give us gdb_valbits etc. | |
74 set main | |
75 | |
76 # When nonzero, display some extra diagnostics in various commands | |
77 set $yverbose = 1 | |
78 set $yfile_buffers_only = 0 | |
79 | |
80 set $tagmask = (((long)1 << gdb_gctypebits) - 1) | |
81 set $valmask = gdb_use_lsb ? ~($tagmask) : ((long)1 << gdb_valbits) - 1 | |
82 | |
83 define ygetptr | |
84 set $ptr = $arg0 | |
85 set $ptr = (gdb_use_union ? $ptr.u.val : $ptr & $valmask) | gdb_data_seg_bits | |
86 end | |
87 | |
88 define ybuffer-list | |
89 set $files_only = $yfile_buffers_only | |
90 set $yfile_buffers_only = 0 | |
91 | |
92 if $yverbose | |
93 printf "B# M Size Name Mode File\n" | |
94 printf "-- - ---- ---- ---- ----\n" | |
95 end | |
96 | |
97 set $i = 0 | |
98 set $alist = Vbuffer_alist | |
99 while $alist != Qnil | |
100 ygetptr $alist | |
101 set $this = ((struct Lisp_Cons *) $ptr)->car | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
102 set $alist = ((struct Lisp_Cons *) $ptr)->u.cdr |
62894 | 103 |
104 # Vbuffer_alist elts are pairs of the form (name . buffer) | |
105 ygetptr $this | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
106 set $buf = ((struct Lisp_Cons *) $ptr)->u.cdr |
62894 | 107 ygetptr $buf |
108 set $buf = (struct buffer *) $ptr | |
109 | |
110 if ! ($files_only && $buf->filename == Qnil) | |
111 ygetptr $buf->name | |
112 set $name = ((struct Lisp_String *) $ptr)->data | |
113 set $modp = ($buf->text->modiff > $buf->text->save_modiff) ? '*' : ' ' | |
114 | |
115 ygetptr $buf->mode_name | |
116 set $mode = ((struct Lisp_String *) $ptr)->data | |
117 | |
118 if $buf->filename != Qnil | |
119 ygetptr $buf->filename | |
63292
5ca9652ec98b
(ybuffer-list): Don't use $filename; can't use char as placeholder when
Noah Friedman <friedman@splode.com>
parents:
62906
diff
changeset
|
120 printf "%2d %c %9d %-20s %-10s %s\n", \ |
5ca9652ec98b
(ybuffer-list): Don't use $filename; can't use char as placeholder when
Noah Friedman <friedman@splode.com>
parents:
62906
diff
changeset
|
121 $i, $modp, ($buf->text->z_byte - 1), $name, $mode, \ |
5ca9652ec98b
(ybuffer-list): Don't use $filename; can't use char as placeholder when
Noah Friedman <friedman@splode.com>
parents:
62906
diff
changeset
|
122 ((struct Lisp_String *) $ptr)->data |
62894 | 123 else |
63292
5ca9652ec98b
(ybuffer-list): Don't use $filename; can't use char as placeholder when
Noah Friedman <friedman@splode.com>
parents:
62906
diff
changeset
|
124 printf "%2d %c %9d %-20s %-10s\n", \ |
5ca9652ec98b
(ybuffer-list): Don't use $filename; can't use char as placeholder when
Noah Friedman <friedman@splode.com>
parents:
62906
diff
changeset
|
125 $i, $modp, ($buf->text->z_byte - 1), $name, $mode |
62894 | 126 end |
127 end | |
128 | |
129 set $i++ | |
130 end | |
131 end | |
132 document ybuffer-list | |
133 Display a list of buffer names, sizes, and other attributes. | |
134 The buffer number in the first column is used as an argument | |
135 to some other emacs-buffer recovery commands, e.g. `ysave-buffer'. | |
136 end | |
137 | |
138 define yfile-buffers | |
139 set $yfile_buffers_only = 1 | |
140 ybuffer-list | |
141 end | |
142 document yfile-buffers | |
143 Display a list of buffers which are associated with files. | |
144 This is like `ybuffer-list', but only buffers that were visiting files | |
145 are displayed. | |
146 end | |
147 | |
148 define yset-buffer | |
149 set $i = $arg0 | |
150 | |
151 set $alist = Vbuffer_alist | |
152 while ($alist != Qnil && $i > 0) | |
153 ygetptr $alist | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
154 set $alist = ((struct Lisp_Cons *) $ptr)->u.cdr |
62894 | 155 set $i-- |
156 end | |
157 | |
158 # Get car of alist; this is a pair (name . buffer) | |
159 ygetptr $alist | |
160 set $this = ((struct Lisp_Cons *) $ptr)->car | |
161 | |
162 # Get the buffer object | |
163 ygetptr $this | |
68376
b257be06d411
Replace all references to `cdr' field of conses with `u.cdr',
Noah Friedman <friedman@splode.com>
parents:
63292
diff
changeset
|
164 set $this = ((struct Lisp_Cons *) $ptr)->u.cdr |
62894 | 165 |
166 ygetptr $this | |
167 set $ycurrent_buffer = (struct buffer *) $ptr | |
168 end | |
169 document yset-buffer | |
170 Set current buffer (for other emacs-buffer recovery commands) to the ARG'th | |
171 buffer as displayed by `ybuffer-list'. | |
172 end | |
173 | |
174 define yget-buffer-pointers | |
175 yset-buffer $arg0 | |
176 set $buf = $ycurrent_buffer->text | |
177 | |
178 set $beg = $buf->beg | |
179 set $gap = $beg + $buf->gpt_byte | |
180 set $gap_end = $gap + $buf->gap_size - 1 | |
181 set $end = $gap_end + ($buf->z_byte - $buf->gpt_byte) | |
182 | |
183 set $modp = $buf->modiff > $buf->save_modiff | |
184 | |
185 #print *$beg@($gap - $beg) | |
186 #print *$gap_end@($end - $gap_end) | |
187 end | |
188 document yget-buffer-pointers | |
189 Update convenience variables with address pointers for the ARG'th buffer | |
190 as displayed by `ybuffer-list'. | |
191 | |
192 This also sets the current buffer using `yset-buffer' (which see). | |
193 end | |
194 | |
195 define yget-current-buffer-name | |
196 set $this = $ycurrent_buffer->name | |
197 ygetptr $this | |
198 set $ycurrent_buffer_name = ((struct Lisp_String *) $ptr)->data | |
199 end | |
200 document yget-current-buffer-name | |
201 Set $ycurrent_buffer_name to the name of the currently selected buffer. | |
202 end | |
203 | |
204 define ycurrent-buffer | |
205 yget-current-buffer-name | |
206 printf "%s\n", $ycurrent_buffer_name | |
207 end | |
208 document ycurrent-buffer | |
209 Display the currently selected buffer. | |
210 end | |
211 | |
212 define ydump-buffer | |
213 yget-buffer-pointers $arg0 | |
214 if $buf->z_byte > 1 | |
215 if $buf->z_byte <= $buf->gpt_byte | |
216 set $endptr = $beg + $buf->gpt_byte - 1 | |
217 dump binary memory $arg1 $beg $endptr | |
218 else | |
219 dump binary memory $arg1 $beg $gap-1 | |
220 append binary memory $arg1 $gap_end $end | |
221 set $endptr = $end | |
222 end | |
223 end | |
224 end | |
225 document ydump-buffer | |
226 Write contents of buffer N (as numbered according to `ybuffer-list') to | |
227 file FILE. | |
228 | |
229 This is mainly used as an internal subroutine for `ysave-buffer' and | |
230 `ybuffer-contents', which see. | |
231 end | |
232 | |
233 define ysave-buffer | |
234 ydump-buffer $arg0 $arg1 | |
235 if $yverbose | |
236 yget-current-buffer-name | |
237 if $buf->z_byte <= 1 | |
238 printf "[Buffer \"%s\" is empty.]\n", $ycurrent_buffer_name | |
239 else | |
240 # Output string broken into separate calls as necessary to avoid | |
241 # requiring a running process for evaluation. | |
242 printf "[Wrote buffer \"%s\" to file ", $ycurrent_buffer_name | |
243 echo $arg1]\n | |
244 end | |
245 end | |
246 end | |
247 document ysave-buffer | |
248 Save contents of buffer N (as numbered according to `ybuffer-list') to | |
249 file FILE. | |
250 end | |
251 | |
252 define ybuffer-contents | |
253 ydump-buffer $arg0 /dev/stdout | |
254 if $yverbose && $buf->z_byte <= 1 | |
255 yget-current-buffer-name | |
256 printf "[Buffer \"%s\" is empty.]\n", $ycurrent_buffer_name | |
257 else | |
258 if *($endptr-1) != '\n' | |
259 echo \n | |
260 end | |
261 end | |
262 end | |
263 document ybuffer-contents | |
264 Write contents of buffer N (numbered according to `ybuffer-list') to stdout. | |
265 end | |
266 | |
267 # local variables: | |
268 # mode: gdb-script | |
269 # end: | |
62905 | 270 |