]> sourceware.org Git - lvm2.git/blame - scripts/gdbinit
.
[lvm2.git] / scripts / gdbinit
CommitLineData
0a1d29b1
JEB
1# Copyright (C) 2011 Red Hat, Inc. All rights reserved.
2# This file is part of LVM2.
3
4# This copyrighted material is made available to anyone wishing to use,
5# modify, copy, or redistribute it subject to the terms and conditions
6# of the GNU Lesser General Public License v.2.1.
7
8# You should have received a copy of the GNU Lesser General Public License
9# along with this program; if not, write to the Free Software Foundation,
10# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11#
12# Author(s):
13# Jonathan Brassow <jbrassow@redhat.com>
14#
15# Copy this file to ~/.gdbinit or <working_dir>/.gdbinit
16
17printf "\n\n"
18printf "Loading commands:\n"
9aedb143 19printf " - dm_list_size <list ptr>\n"
0a1d29b1
JEB
20printf " - first_seg <LV ptr>\n"
21printf " - lv_status <LV ptr>\n"
22printf " - lv_status_r <LV ptr>\n"
23printf " - lv_is_mirrored <LV ptr>\n"
24printf " - seg_item <seg ptr> <index>\n"
25printf " - seg_status <seg ptr>\n"
26printf " - segs_using_this_lv <seg ptr>\n"
27printf " - \n"
28printf "Use 'help <command>' for more info\n"
29printf "\n\n"
30printf "Popular breakpoints:\n"
9aedb143
JEB
31printf "break _get_udev_flags\n"
32printf "run --splitmirrors 1 -n split vg/lv\n"
0a1d29b1
JEB
33printf "\n\n"
34
35set follow-fork-mode child
36
ab999c86
JEB
37# Conventions:
38# foo : function named 'foo' available to user
39# __foo : an internal function
40#
41# External functions should have a corresponding 'document'
42# section. Internal functions should have leading comments
43
9aedb143
JEB
44define dm_list_size
45 set $_DLS_list_head = (struct dm_list *)$arg0
46 set $_DLS_list = $_DLS_list_head->n
47 set $_DLS_size = 0
48
49 while (($_DLS_list != $_DLS_list_head) && ($_DLS_size < 100))
50 set $_DLS_list = $_DLS_list->n
51 set $_DLS_size++
52 end
53
54 printf "%d list items\n", $_DLS_size
55end
56
57document dm_list_size
58Returns the number of elements in the dm_list
59
60 Usage: dm_list_size <list ptr>
61end
ab999c86
JEB
62
63#
64# __first_seg <return> <LV>
65define __first_seg
66 set $arg0 = 0x0
547d3f13 67 set $_FS_lv = (struct logical_volume *)$arg1
ab999c86 68
547d3f13
JEB
69 if ($_FS_lv->segments.n != &$_FS_lv->segments)
70 set $arg0 = (struct lv_segment *)$_FS_lv->segments.n
ab999c86
JEB
71 end
72end
73
0a1d29b1 74define first_seg
ab999c86
JEB
75 set $_seg = 0
76 set $_lv=(struct logical_volume *)$arg0
0a1d29b1 77
ab999c86
JEB
78 __first_seg $_seg $_lv
79
80 if ($_seg)
81 p $_seg
0a1d29b1 82 else
ab999c86 83 printf "No segments (list empty)\n"
0a1d29b1
JEB
84 end
85end
86
87document first_seg
88Returns the pointer to the first segment of an LV
89
90 Usage: first_seg <LV ptr>
91
92WARNING: If the list pointer in 'struct lv_segment' moves,
93 this function will be wrong.
94end
95
ab999c86 96#
075658c0 97# __seg_type <return> <seg> <index>
ab999c86
JEB
98define __seg_type
99 set $arg0 = 0x0
547d3f13
JEB
100 set $_ST_seg = (struct lv_segment *)$arg1
101 set $_ST_index= $arg2
102 set $_ST_area = $_ST_seg->areas[$_ST_index]
103 set $_ST_type = $_ST_area.type
ab999c86 104
547d3f13 105 set $arg0 = $_ST_type
ab999c86 106end
0a1d29b1 107
ab999c86
JEB
108#
109# __seg_item <return> <seg> <index>
110define __seg_item
111 set $arg0 = 0x0
547d3f13
JEB
112 set $_SI_seg = (struct lv_segment *)$arg1
113 set $_SI_index= $arg2
ab999c86 114
547d3f13
JEB
115 if ($_SI_index < $_SI_seg->area_count)
116 set $_SI_area = $_SI_seg->areas[$_SI_index]
117 set $_SI_type = $_SI_area.type
ab999c86 118
547d3f13
JEB
119 if ($_SI_type == AREA_PV)
120 set $arg0 = $_SI_area.u.pv.pvseg->pv
0a1d29b1 121 else
547d3f13
JEB
122 if ($_SI_type == AREA_LV)
123 set $arg0 = $_SI_area.u.lv.lv
ab999c86 124 end
0a1d29b1
JEB
125 end
126 end
127end
128
075658c0
JEB
129#
130# __seg_metaitem <return> <seg> <index>
131define __seg_metaitem
132 set $arg0 = 0x0
133 set $_SMI_seg = (struct lv_segment *)$arg1
134 set $_SMI_index= $arg2
135
673c8d01 136 if (($_SMI_index < $_SMI_seg->area_count) && $_SMI_seg->meta_areas)
075658c0
JEB
137 set $_SMI_area = $_SMI_seg->meta_areas[$_SMI_index]
138 set $_SMI_type = $_SMI_area.type
139
140 if ($_SMI_type == AREA_PV)
141 set $arg0 = $_SMI_area.u.pv.pvseg->pv
142 else
143 if ($_SMI_type == AREA_LV)
144 set $arg0 = $_SMI_area.u.lv.lv
145 end
146 end
147 end
148end
149
ab999c86
JEB
150define seg_item
151 set $_item = 0x0
152
153 __seg_item $_item $arg0 $arg1
154 if ($_item)
155 p $_item
156 else
157 printf "AREA_UNASSIGNED or invalid\n"
158 end
159end
160
075658c0
JEB
161define seg_metaitem
162 set $_metaitem = 0x0
163
164 __seg_metaitem $_metaitem $arg0 $arg1
165 if ($_metaitem)
166 p $_metaitem
167 else
168 printf "AREA_UNASSIGNED or invalid\n"
169 end
170end
171
0a1d29b1
JEB
172document seg_item
173Returns the pointer to the LV or PV for the indexed area of a segment
174
175 Usage: seg_item <struct lv_segment *> <index>
176
177Example - Getting to the sub-lv of a mirror:
178 (gdb) p lv->name
179 $1 = 0x712548 "lv"
180
181 (gdb) first_seg lv
182 $2 = (struct lv_segment *) 0x7128b8
183
184 (gdb) seg_item $2 0
185 $3 = (struct logical_volume *) 0x712688
186
187 (gdb) p $3->name
188 $4 = 0x712770 "lv_mimage_0"
189end
190
191define __status
075658c0
JEB
192 set $_s_status = $arg0->status
193
0a1d29b1
JEB
194# Constants defined in metadata-exported.h
195
673c8d01 196# if ($_s_status & RAID)
4c259ae9
JEB
197 if ($_s_status & 0x0000000100000000LU)
198 set $_s_status = $_s_status & ~0x0000000100000000LU
673c8d01
JEB
199 printf " RAID"
200 end
201# if ($_s_status & RAID_META)
4c259ae9
JEB
202 if ($_s_status & 0x0000000200000000LU)
203 set $_s_status = $_s_status & ~0x0000000200000000LU
673c8d01
JEB
204 printf " RAID_META"
205 end
206# if ($_s_status & RAID_IMAGE)
4c259ae9
JEB
207 if ($_s_status & 0x0000000400000000LU)
208 set $_s_status = $_s_status & ~0x0000000400000000LU
673c8d01
JEB
209 printf " RAID_IMAGE"
210 end
08c50a29
JEB
211# if ($_s_status & MIRRORED)
212 if ($_s_status & 0x00008000U)
213 set $_s_status = $_s_status & ~0x00008000U
214 printf " MIRRORED"
215 end
216# if ($_s_status & MIRROR_LOG)
217 if ($_s_status & 0x00020000U)
218 set $_s_status = $_s_status & ~0x00020000U
219 printf " MIRROR_LOG"
220 end
221# if ($_s_status & MIRROR_IMAGE)
222 if ($_s_status & 0x00040000U)
223 set $_s_status = $_s_status & ~0x00040000U
224 printf " MIRROR_IMAGE"
225 end
075658c0
JEB
226# if ($_s_status & VISIBLE_LV)
227 if ($_s_status & 0x00000040U)
0a1d29b1 228 printf " VISIBLE_LV"
075658c0 229 set $_s_status = $_s_status & ~0x00000040U
0a1d29b1
JEB
230 else
231 printf " *HIDDEN_LV*"
232 end
075658c0
JEB
233# if ($_s_status & FIXED_MINOR)
234 if ($_s_status & 0x00000080U)
235 set $_s_status = $_s_status & ~0x00000080U
0a1d29b1
JEB
236 printf " FIXED_MINOR"
237 end
673c8d01
JEB
238# if ($_s_status & LVM_READ)
239 if ($_s_status & 0x00000100U)
240 set $_s_status = $_s_status & ~0x00000100U
241 printf " LVM_READ"
242 end
243# if ($_s_status & LVM_WRITE)
244 if ($_s_status & 0x00000200U)
245 set $_s_status = $_s_status & ~0x00000200U
246 printf " LVM_WRITE"
247 end
075658c0
JEB
248# if ($_s_status & SNAPSHOT)
249 if ($_s_status & 0x00001000U)
250 set $_s_status = $_s_status & ~0x00001000U
0a1d29b1
JEB
251 printf " SNAPSHOT"
252 end
075658c0
JEB
253# if ($_s_status & PVMOVE)
254 if ($_s_status & 0x00002000U)
255 set $_s_status = $_s_status & ~0x00002000U
0a1d29b1
JEB
256 printf " PVMOVE"
257 end
075658c0
JEB
258# if ($_s_status & LOCKED)
259 if ($_s_status & 0x00004000U)
260 set $_s_status = $_s_status & ~0x00004000U
0a1d29b1
JEB
261 printf " LOCKED"
262 end
075658c0
JEB
263# if ($_s_status & LV_NOTSYNCED)
264 if ($_s_status & 0x00080000U)
265 set $_s_status = $_s_status & ~0x00080000U
1e094d34 266 printf " LV_NOTSYNCED"
0a1d29b1 267 end
075658c0
JEB
268# if ($_s_status & CONVERTING)
269 if ($_s_status & 0x00400000U)
270 set $_s_status = $_s_status & ~0x00400000U
0a1d29b1
JEB
271 printf " CONVERTING"
272 end
673c8d01
JEB
273# if ($_s_status & MERGING)
274 if ($_s_status & 0x10000000U)
275 set $_s_status = $_s_status & ~0x10000000U
276 printf " MERGING"
075658c0
JEB
277 end
278
279 if ($_s_status)
280 printf " 0x%x", $_s_status
281 end
0a1d29b1
JEB
282end
283
547d3f13
JEB
284#
285# __print_indent <num indents> [No marks]
286define __print_indent
287 set $_PI_indent = $arg0
288 set $_PI_lead_mark = 0
289
290 while ($_PI_indent)
291 if ($_PI_indent == 1)
292 if ($argc > 1)
293 if ($_PI_lead_mark)
294 printf " "
295 else
296 printf "| "
297 end
298 else
299 printf "|-----> "
300 end
301 else
302 printf "| "
303 set $_PI_lead_mark = 1
304 end
305 set $_PI_indent--
306 end
307end
308
0a1d29b1 309define lv_status
0b1a79bf
JEB
310 # Use __lv because we don't want to overwrite higher functions
311 set $__lv = (struct logical_volume *)$arg0
0a1d29b1 312
547d3f13
JEB
313 if ($argc == 2)
314 __print_indent $arg1
315 end
0b1a79bf
JEB
316 printf "%s->status:", $__lv->name
317 __status $__lv
0a1d29b1
JEB
318 printf "\n"
319end
320
321document lv_status
322Display the flags that are set on an LV.
323
324 Usage: lv_status <LV ptr>
325end
326
327define seg_status
328 set $_seg=(struct lv_segment *)$arg0
329
547d3f13
JEB
330 if ($argc == 2)
331 __print_indent $arg1 1
332 end
ab999c86 333 printf "[ (%s) seg->status:", $_seg->lv->name
0a1d29b1 334 __status $_seg
ab999c86 335 printf " ]\n"
0a1d29b1
JEB
336end
337
338document seg_status
339Display the flags that are set on an lv_segment.
340
547d3f13 341 Usage: seg_status <(struct lv_segment *)>
0a1d29b1
JEB
342end
343
ab999c86
JEB
344#
345# get_only_segment_using_this_lv <return> <LV>
346define __get_only_segment_using_this_lv
347 set $arg0 = 0x0
348 set $_lv=(struct logical_volume *)$arg1
349 set $_seg_list_head = &$_lv->segs_using_this_lv
350 set $_s = $_lv->segs_using_this_lv.n
0a1d29b1
JEB
351 set $_i = 0
352
ab999c86
JEB
353 while (($_s != $_seg_list_head) && ($_i < 100))
354 set $_seg_list = (struct seg_list *)$_s
355 set $_seg = (struct lv_segment *)$_seg_list->seg
0a1d29b1 356
ab999c86
JEB
357 set $_i++
358 set $_s = $_s->n
0a1d29b1 359 end
0a1d29b1 360
ab999c86
JEB
361 if ($_i > 1)
362 printf "More than %s using %s\n", ($_i > 99) ? "100 segments" : "one segment", $_lv->name
363 end
364 if ($_i == 1)
365 set $arg0 = $_seg
366 end
0a1d29b1
JEB
367end
368
369define segs_using_this_lv
370 set $_lv=(struct logical_volume *)$arg0
371 set $_seg_list_head = &$_lv->segs_using_this_lv
372 set $_s = $_lv->segs_using_this_lv.n
373 set $_i = 0
374
375 if ($_s != $_seg_list_head)
376 printf "Segments using %s\n", $_lv->name
377 else
378 printf "No segments using %s\n", $_lv->name
379 end
380 while ($_s != $_seg_list_head)
381 set $_seg_list = (struct seg_list *)$_s
382 set $_seg = (struct lv_segment *)$_seg_list->seg
383 printf " %d) seg: %p", $_i, $_seg
384 if ($_seg->lv < 0x200)
385 printf " [BAD LV POINTER FROM THIS SEG]\n"
386 else
387 printf " [seg found in %s]\n", $_seg->lv->name
388 end
ab999c86 389 set $_i++
0a1d29b1 390 set $_s = $_s->n
0a1d29b1
JEB
391 end
392end
393
394document segs_using_this_lv
395Display the segments (and their associated LV) using an LV
396
397 Usage: segs_using_this_lv <LV ptr>
398
399Example:
400 (gdb) lv_is_mirrored lv
401 lv is mirrored ('core' log)
402
403 (gdb) segs_using_this_lv lv
404 No segments using lv
405
406 (gdb) first_seg lv
407 $1 = (struct lv_segment *) 0x92d360
408
409 (gdb) seg_item $1 0
410 $2 = (struct logical_volume *) 0x928f58
411
412 (gdb) segs_using_this_lv $2
413 Segments using lv_mimage_0
414 0) seg: 0x92d360 [seg found in lv]
415end
416
ab999c86
JEB
417#
418# __next_area_index <return> <seg> <seg_item>
419define __next_area_index
420 set $arg0 = 0x0
421 set $_seg = (struct lv_segment *)$arg1
422 set $_item = 0x0
423 set $_i = 0
424
425 __seg_item $_item $_seg $_i
426 while ($_item && ($_item != $arg2))
427 set $_i++
428 __seg_item $_item $_seg $_i
429 end
430
431 # $_i points to current, now get next (if there)
432 set $_i++
433 __seg_item $_item $_seg $_i
434
435 if ($_item)
436 set $arg0 = $_i
437 end
438end
439
440#
441# __lv_status_r <LV>
442# Decend tree, printing LV and seg status as we go. This
443# performs a depth first approach (but can't come up)
673c8d01 444#
ab999c86 445# or
673c8d01 446#
ab999c86
JEB
447# __lv_status_r <sub_lv> <seg using sub_lv>
448# Try continuing decent of tree by first shifting to the
449# next 'area' in the seg ($arg1). If no more areas, then
450# try going to the next segment.
451define __lv_status_r
452 if ($argc == 1)
453 set $_lv=(struct logical_volume *)$arg0
454 set $_seg_list_head = &$_lv->segments
455 set $_s = $_lv->segments.n
456 set $_area_index = 0
457
547d3f13
JEB
458# printf "\n"
459 lv_status $_lv $indent
ab999c86
JEB
460 else
461 set $_seg = (struct lv_segment *)$arg1
462
463 __next_area_index $_area_index $_seg $arg0
464
465 # Don't fuck this up. We need the next two lines here.
466 set $_lv=(struct logical_volume *)$_seg->lv
467 set $_seg_list_head = &$_lv->segments
468 set $_s = (struct dm_list *)$_seg
469
470 if (!$_area_index)
471 set $_s = $_s->n
472 end
473 end
474
475 if ($_s == $_seg_list_head)
476 if ($argc == 1)
2d1175a8 477 __print_indent $indent 1
ab999c86
JEB
478 printf "[ No segments for %s ]\n", $_lv->name
479 end
2d1175a8
JEB
480 __get_only_segment_using_this_lv $_seg $_lv
481
482 if ($_seg && $indent)
483 set $indent--
484 __lv_status_r $_lv $_seg
485 end
ab999c86
JEB
486 else
487 set $_seg = (struct lv_segment *)$_s
488 set $_type = 0x0
489
490 if (!$_area_index)
547d3f13 491 seg_status $_seg $indent
ab999c86 492 end
ab999c86
JEB
493 __seg_type $_type $_seg $_area_index
494 if ($_type == AREA_LV)
547d3f13 495 set $indent++
075658c0
JEB
496
497 __seg_metaitem $_lv $_seg $_area_index
498 if ($_lv)
499 set $rindent = $indent
500 set $rseg = $_seg
501 set $rarea_index = $_area_index
502 set $rlv = $_lv
503
504 __lv_status_r $_lv
505
506 set $indent = $rindent
507 set $_seg = $rseg
508 set $_area_index = $rarea_index
509 set $_lv = $rlv
510 end
511
ab999c86
JEB
512 __seg_item $_lv $_seg $_area_index
513 __lv_status_r $_lv
514 else
0b1a79bf 515 if ($_seg->log_lv)
547d3f13
JEB
516 set $indent++
517 set $_log_seg = 0x0
518
519 __first_seg $_log_seg $_seg->log_lv
520 lv_status $_seg->log_lv $indent
521 seg_status $_log_seg $indent
522
523 set $indent--
0b1a79bf 524 end
ab999c86
JEB
525 __get_only_segment_using_this_lv $_seg $_lv
526 if ($_seg)
547d3f13 527 set $indent--
ab999c86
JEB
528 __lv_status_r $_lv $_seg
529 end
530 end
531 end
532end
533
534define lv_status_r
547d3f13 535 set $indent = 0
ab999c86
JEB
536 __lv_status_r $arg0
537end
538
539document lv_status_r
540Display the status flags of an LV and its sub_lvs.
541
542 Usage: lv_status_r <LV ptr>
543
544This function is useful for checking that all the LVs that
545compose a logical volume have the correct flags set (and also
546their associated lv_segments)
547end
548
0a1d29b1
JEB
549define lv_is_mirrored
550 set $_lv=(struct logical_volume *)$arg0
551 set $_fs=(struct lv_segment *)$_lv->segments.n
552 set $_log_lv=(struct logical_volume *)$_fs->log_lv
553
554# if ($_lv->status & MIRRORED)
555 if ($_lv->status & 0x00008000U)
556 printf "%s is mirrored (", $_lv->name
557 if ($_log_lv)
558 if ($_log_lv->status & 0x00008000U)
559 printf "'mirrored' log)\n"
560 else
561 printf "'disk' log)\n"
562 end
563 else
564 printf "'core' log)\n"
565 end
566 else
567 printf "%s is not mirrored\n", $_lv->name
568 end
569end
570
571document lv_is_mirrored
572Report whether the given LV is mirrored (and its log type).
573
574 Usage: lv_is_mirrored <LV ptr>
575end
This page took 0.09381 seconds and 5 git commands to generate.