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