]> sourceware.org Git - lvm2.git/blame - scripts/gdbinit
dev-type: detect mixed dos partition with gpt's PMBR
[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,
fcbef05a 10# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0a1d29b1
JEB
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 326 end
2e0740f7
JB
327# if ($_s_status & LV_WRITEMOSTLY)
328 if ($_s_status & 0x10000000000U)
329 set $_s_status = $_s_status & ~0x10000000000U
330 printf " LV_WRITEMOSTLY"
331 end
075658c0
JEB
332
333 if ($_s_status)
334 printf " 0x%x", $_s_status
335 end
0a1d29b1
JEB
336end
337
547d3f13
JEB
338#
339# __print_indent <num indents> [No marks]
340define __print_indent
341 set $_PI_indent = $arg0
342 set $_PI_lead_mark = 0
343
344 while ($_PI_indent)
345 if ($_PI_indent == 1)
346 if ($argc > 1)
347 if ($_PI_lead_mark)
348 printf " "
349 else
350 printf "| "
351 end
352 else
353 printf "|-----> "
354 end
355 else
356 printf "| "
357 set $_PI_lead_mark = 1
358 end
359 set $_PI_indent--
360 end
361end
362
0a1d29b1 363define lv_status
0b1a79bf
JEB
364 # Use __lv because we don't want to overwrite higher functions
365 set $__lv = (struct logical_volume *)$arg0
0a1d29b1 366
547d3f13
JEB
367 if ($argc == 2)
368 __print_indent $arg1
369 end
0b1a79bf
JEB
370 printf "%s->status:", $__lv->name
371 __status $__lv
0a1d29b1
JEB
372 printf "\n"
373end
374
375document lv_status
376Display the flags that are set on an LV.
377
378 Usage: lv_status <LV ptr>
379end
380
381define seg_status
382 set $_seg=(struct lv_segment *)$arg0
383
547d3f13
JEB
384 if ($argc == 2)
385 __print_indent $arg1 1
386 end
ab999c86 387 printf "[ (%s) seg->status:", $_seg->lv->name
0a1d29b1 388 __status $_seg
ab999c86 389 printf " ]\n"
0a1d29b1
JEB
390end
391
392document seg_status
393Display the flags that are set on an lv_segment.
394
547d3f13 395 Usage: seg_status <(struct lv_segment *)>
0a1d29b1
JEB
396end
397
ab999c86
JEB
398#
399# get_only_segment_using_this_lv <return> <LV>
400define __get_only_segment_using_this_lv
401 set $arg0 = 0x0
402 set $_lv=(struct logical_volume *)$arg1
403 set $_seg_list_head = &$_lv->segs_using_this_lv
404 set $_s = $_lv->segs_using_this_lv.n
0a1d29b1
JEB
405 set $_i = 0
406
ab999c86
JEB
407 while (($_s != $_seg_list_head) && ($_i < 100))
408 set $_seg_list = (struct seg_list *)$_s
409 set $_seg = (struct lv_segment *)$_seg_list->seg
0a1d29b1 410
ab999c86
JEB
411 set $_i++
412 set $_s = $_s->n
0a1d29b1 413 end
0a1d29b1 414
ab999c86
JEB
415 if ($_i > 1)
416 printf "More than %s using %s\n", ($_i > 99) ? "100 segments" : "one segment", $_lv->name
417 end
418 if ($_i == 1)
419 set $arg0 = $_seg
420 end
0a1d29b1
JEB
421end
422
423define segs_using_this_lv
424 set $_lv=(struct logical_volume *)$arg0
425 set $_seg_list_head = &$_lv->segs_using_this_lv
426 set $_s = $_lv->segs_using_this_lv.n
427 set $_i = 0
428
429 if ($_s != $_seg_list_head)
430 printf "Segments using %s\n", $_lv->name
431 else
432 printf "No segments using %s\n", $_lv->name
433 end
434 while ($_s != $_seg_list_head)
435 set $_seg_list = (struct seg_list *)$_s
436 set $_seg = (struct lv_segment *)$_seg_list->seg
437 printf " %d) seg: %p", $_i, $_seg
438 if ($_seg->lv < 0x200)
439 printf " [BAD LV POINTER FROM THIS SEG]\n"
440 else
441 printf " [seg found in %s]\n", $_seg->lv->name
442 end
ab999c86 443 set $_i++
0a1d29b1 444 set $_s = $_s->n
0a1d29b1
JEB
445 end
446end
447
448document segs_using_this_lv
449Display the segments (and their associated LV) using an LV
450
451 Usage: segs_using_this_lv <LV ptr>
452
453Example:
454 (gdb) lv_is_mirrored lv
455 lv is mirrored ('core' log)
456
457 (gdb) segs_using_this_lv lv
458 No segments using lv
459
460 (gdb) first_seg lv
461 $1 = (struct lv_segment *) 0x92d360
462
463 (gdb) seg_item $1 0
464 $2 = (struct logical_volume *) 0x928f58
465
466 (gdb) segs_using_this_lv $2
467 Segments using lv_mimage_0
468 0) seg: 0x92d360 [seg found in lv]
469end
470
ab999c86
JEB
471#
472# __next_area_index <return> <seg> <seg_item>
473define __next_area_index
474 set $arg0 = 0x0
475 set $_seg = (struct lv_segment *)$arg1
476 set $_item = 0x0
477 set $_i = 0
478
479 __seg_item $_item $_seg $_i
480 while ($_item && ($_item != $arg2))
481 set $_i++
482 __seg_item $_item $_seg $_i
483 end
484
485 # $_i points to current, now get next (if there)
486 set $_i++
487 __seg_item $_item $_seg $_i
488
489 if ($_item)
490 set $arg0 = $_i
491 end
492end
493
494#
495# __lv_status_r <LV>
39b7d1ba 496# Descend tree, printing LV and seg status as we go. This
ab999c86 497# performs a depth first approach (but can't come up)
673c8d01 498#
ab999c86 499# or
673c8d01 500#
ab999c86
JEB
501# __lv_status_r <sub_lv> <seg using sub_lv>
502# Try continuing decent of tree by first shifting to the
503# next 'area' in the seg ($arg1). If no more areas, then
504# try going to the next segment.
505define __lv_status_r
506 if ($argc == 1)
507 set $_lv=(struct logical_volume *)$arg0
508 set $_seg_list_head = &$_lv->segments
509 set $_s = $_lv->segments.n
510 set $_area_index = 0
511
547d3f13
JEB
512# printf "\n"
513 lv_status $_lv $indent
ab999c86
JEB
514 else
515 set $_seg = (struct lv_segment *)$arg1
516
517 __next_area_index $_area_index $_seg $arg0
518
519 # Don't fuck this up. We need the next two lines here.
520 set $_lv=(struct logical_volume *)$_seg->lv
521 set $_seg_list_head = &$_lv->segments
522 set $_s = (struct dm_list *)$_seg
523
524 if (!$_area_index)
525 set $_s = $_s->n
526 end
527 end
528
529 if ($_s == $_seg_list_head)
530 if ($argc == 1)
2d1175a8 531 __print_indent $indent 1
ab999c86
JEB
532 printf "[ No segments for %s ]\n", $_lv->name
533 end
2d1175a8
JEB
534 __get_only_segment_using_this_lv $_seg $_lv
535
536 if ($_seg && $indent)
537 set $indent--
538 __lv_status_r $_lv $_seg
539 end
ab999c86
JEB
540 else
541 set $_seg = (struct lv_segment *)$_s
542 set $_type = 0x0
543
544 if (!$_area_index)
547d3f13 545 seg_status $_seg $indent
ab999c86 546 end
ab999c86
JEB
547 __seg_type $_type $_seg $_area_index
548 if ($_type == AREA_LV)
547d3f13 549 set $indent++
075658c0
JEB
550
551 __seg_metaitem $_lv $_seg $_area_index
552 if ($_lv)
553 set $rindent = $indent
554 set $rseg = $_seg
555 set $rarea_index = $_area_index
556 set $rlv = $_lv
557
558 __lv_status_r $_lv
559
560 set $indent = $rindent
561 set $_seg = $rseg
562 set $_area_index = $rarea_index
563 set $_lv = $rlv
564 end
565
ab999c86
JEB
566 __seg_item $_lv $_seg $_area_index
567 __lv_status_r $_lv
568 else
0b1a79bf 569 if ($_seg->log_lv)
547d3f13
JEB
570 set $indent++
571 set $_log_seg = 0x0
572
573 __first_seg $_log_seg $_seg->log_lv
574 lv_status $_seg->log_lv $indent
575 seg_status $_log_seg $indent
576
577 set $indent--
0b1a79bf 578 end
ab999c86
JEB
579 __get_only_segment_using_this_lv $_seg $_lv
580 if ($_seg)
547d3f13 581 set $indent--
ab999c86
JEB
582 __lv_status_r $_lv $_seg
583 end
584 end
585 end
586end
587
588define lv_status_r
547d3f13 589 set $indent = 0
ab999c86
JEB
590 __lv_status_r $arg0
591end
592
593document lv_status_r
594Display the status flags of an LV and its sub_lvs.
595
596 Usage: lv_status_r <LV ptr>
597
598This function is useful for checking that all the LVs that
599compose a logical volume have the correct flags set (and also
600their associated lv_segments)
601end
602
0a1d29b1
JEB
603define lv_is_mirrored
604 set $_lv=(struct logical_volume *)$arg0
605 set $_fs=(struct lv_segment *)$_lv->segments.n
606 set $_log_lv=(struct logical_volume *)$_fs->log_lv
607
608# if ($_lv->status & MIRRORED)
609 if ($_lv->status & 0x00008000U)
610 printf "%s is mirrored (", $_lv->name
611 if ($_log_lv)
612 if ($_log_lv->status & 0x00008000U)
613 printf "'mirrored' log)\n"
614 else
615 printf "'disk' log)\n"
616 end
617 else
618 printf "'core' log)\n"
619 end
620 else
621 printf "%s is not mirrored\n", $_lv->name
622 end
623end
624
625document lv_is_mirrored
626Report whether the given LV is mirrored (and its log type).
627
628 Usage: lv_is_mirrored <LV ptr>
629end
This page took 0.214076 seconds and 6 git commands to generate.