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