]> sourceware.org Git - lvm2.git/blob - scripts/gdbinit
dc7dd88e354cfda4154c55a8087acf4627d8e1cd
[lvm2.git] / scripts / gdbinit
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
11 #
12 # Author(s):
13 # Jonathan Brassow <jbrassow@redhat.com>
14 #
15 # Copy this file to ~/.gdbinit or <working_dir>/.gdbinit
16
17 printf "\n\n"
18 printf "Loading commands:\n"
19 printf " - dm_list_size <list ptr>\n"
20 printf " - pv_dev_name <PV ptr>\n"
21 printf " - first_seg <LV ptr>\n"
22 printf " - lv_status <LV ptr>\n"
23 printf " - lv_status_r <LV ptr>\n"
24 printf " - lv_is_mirrored <LV ptr>\n"
25 printf " - seg_item <seg ptr> <index>\n"
26 printf " - seg_status <seg ptr>\n"
27 printf " - segs_using_this_lv <seg ptr>\n"
28 printf " - seg_pvs <list ptr>\n"
29 printf " - \n"
30 printf "Use 'help <command>' for more info\n"
31 printf "\n\n"
32 printf "Popular breakpoints:\n"
33 printf "break _alloc_image_components\n"
34 printf "run --repair --use-policies vg/lv\n"
35 printf "\n\n"
36
37 set follow-fork-mode child
38
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
46
47
48 define 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
59 end
60
61 document dm_list_size
62 Returns the number of elements in the dm_list
63
64 Usage: dm_list_size <list ptr>
65 end
66
67 define 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
73 end
74
75 document pv_dev_name
76 Print the name of the PV for the given PV pointer
77
78 Usage: pv_dev_name <PV ptr>
79 end
80
81 define 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
94 end
95
96 document seg_pvs
97 Print the elements of a seg_pvs list
98
99 Usage: seg_pvs <list ptr>
100 end
101
102 #
103 # __first_seg <return> <LV>
104 define __first_seg
105 set $arg0 = 0x0
106 set $_FS_lv = (struct logical_volume *)$arg1
107
108 if ($_FS_lv->segments.n != &$_FS_lv->segments)
109 set $arg0 = (struct lv_segment *)$_FS_lv->segments.n
110 end
111 end
112
113 define first_seg
114 set $_seg = 0
115 set $_lv=(struct logical_volume *)$arg0
116
117 __first_seg $_seg $_lv
118
119 if ($_seg)
120 p $_seg
121 else
122 printf "No segments (list empty)\n"
123 end
124 end
125
126 document first_seg
127 Returns the pointer to the first segment of an LV
128
129 Usage: first_seg <LV ptr>
130
131 WARNING: If the list pointer in 'struct lv_segment' moves,
132 this function will be wrong.
133 end
134
135 #
136 # __seg_type <return> <seg> <index>
137 define __seg_type
138 set $arg0 = 0x0
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
143
144 set $arg0 = $_ST_type
145 end
146
147 #
148 # __seg_item <return> <seg> <index>
149 define __seg_item
150 set $arg0 = 0x0
151 set $_SI_seg = (struct lv_segment *)$arg1
152 set $_SI_index= $arg2
153
154 if ($_SI_index < $_SI_seg->area_count)
155 set $_SI_area = $_SI_seg->areas[$_SI_index]
156 set $_SI_type = $_SI_area.type
157
158 if ($_SI_type == AREA_PV)
159 set $arg0 = $_SI_area.u.pv.pvseg->pv
160 else
161 if ($_SI_type == AREA_LV)
162 set $arg0 = $_SI_area.u.lv.lv
163 end
164 end
165 end
166 end
167
168 #
169 # __seg_metaitem <return> <seg> <index>
170 define __seg_metaitem
171 set $arg0 = 0x0
172 set $_SMI_seg = (struct lv_segment *)$arg1
173 set $_SMI_index= $arg2
174
175 if (($_SMI_index < $_SMI_seg->area_count) && $_SMI_seg->meta_areas)
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
187 end
188
189 define 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
198 end
199
200 define 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
209 end
210
211 document seg_item
212 Returns the pointer to the LV or PV for the indexed area of a segment
213
214 Usage: seg_item <struct lv_segment *> <index>
215
216 Example - 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"
228 end
229
230 define __status
231 set $_s_status = $arg0->status
232
233 # Constants defined in metadata-exported.h
234
235 # if ($_s_status & RAID)
236 if ($_s_status & 0x0000000100000000LU)
237 set $_s_status = $_s_status & ~0x0000000100000000LU
238 printf " RAID"
239 end
240 # if ($_s_status & RAID_META)
241 if ($_s_status & 0x0000000200000000LU)
242 set $_s_status = $_s_status & ~0x0000000200000000LU
243 printf " RAID_META"
244 end
245 # if ($_s_status & RAID_IMAGE)
246 if ($_s_status & 0x0000000400000000LU)
247 set $_s_status = $_s_status & ~0x0000000400000000LU
248 printf " RAID_IMAGE"
249 end
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
265 # if ($_s_status & VISIBLE_LV)
266 if ($_s_status & 0x00000040U)
267 printf " VISIBLE_LV"
268 set $_s_status = $_s_status & ~0x00000040U
269 else
270 printf " *HIDDEN_LV*"
271 end
272 # if ($_s_status & FIXED_MINOR)
273 if ($_s_status & 0x00000080U)
274 set $_s_status = $_s_status & ~0x00000080U
275 printf " FIXED_MINOR"
276 end
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
287 # if ($_s_status & SNAPSHOT)
288 if ($_s_status & 0x00001000U)
289 set $_s_status = $_s_status & ~0x00001000U
290 printf " SNAPSHOT"
291 end
292 # if ($_s_status & PVMOVE)
293 if ($_s_status & 0x00002000U)
294 set $_s_status = $_s_status & ~0x00002000U
295 printf " PVMOVE"
296 end
297 # if ($_s_status & LOCKED)
298 if ($_s_status & 0x00004000U)
299 set $_s_status = $_s_status & ~0x00004000U
300 printf " LOCKED"
301 end
302 # if ($_s_status & LV_NOTSYNCED)
303 if ($_s_status & 0x00080000U)
304 set $_s_status = $_s_status & ~0x00080000U
305 printf " LV_NOTSYNCED"
306 end
307 # if ($_s_status & CONVERTING)
308 if ($_s_status & 0x00400000U)
309 set $_s_status = $_s_status & ~0x00400000U
310 printf " CONVERTING"
311 end
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
322 # if ($_s_status & MERGING)
323 if ($_s_status & 0x10000000U)
324 set $_s_status = $_s_status & ~0x10000000U
325 printf " MERGING"
326 end
327 # if ($_s_status & LV_WRITEMOSTLY)
328 if ($_s_status & 0x10000000000U)
329 set $_s_status = $_s_status & ~0x10000000000U
330 printf " LV_WRITEMOSTLY"
331 end
332
333 if ($_s_status)
334 printf " 0x%x", $_s_status
335 end
336 end
337
338 #
339 # __print_indent <num indents> [No marks]
340 define __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
361 end
362
363 define lv_status
364 # Use __lv because we don't want to overwrite higher functions
365 set $__lv = (struct logical_volume *)$arg0
366
367 if ($argc == 2)
368 __print_indent $arg1
369 end
370 printf "%s->status:", $__lv->name
371 __status $__lv
372 printf "\n"
373 end
374
375 document lv_status
376 Display the flags that are set on an LV.
377
378 Usage: lv_status <LV ptr>
379 end
380
381 define seg_status
382 set $_seg=(struct lv_segment *)$arg0
383
384 if ($argc == 2)
385 __print_indent $arg1 1
386 end
387 printf "[ (%s) seg->status:", $_seg->lv->name
388 __status $_seg
389 printf " ]\n"
390 end
391
392 document seg_status
393 Display the flags that are set on an lv_segment.
394
395 Usage: seg_status <(struct lv_segment *)>
396 end
397
398 #
399 # get_only_segment_using_this_lv <return> <LV>
400 define __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
405 set $_i = 0
406
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
410
411 set $_i++
412 set $_s = $_s->n
413 end
414
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
421 end
422
423 define 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
443 set $_i++
444 set $_s = $_s->n
445 end
446 end
447
448 document segs_using_this_lv
449 Display the segments (and their associated LV) using an LV
450
451 Usage: segs_using_this_lv <LV ptr>
452
453 Example:
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]
469 end
470
471 #
472 # __next_area_index <return> <seg> <seg_item>
473 define __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
492 end
493
494 #
495 # __lv_status_r <LV>
496 # Descend tree, printing LV and seg status as we go. This
497 # performs a depth first approach (but can't come up)
498 #
499 # or
500 #
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.
505 define __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
512 # printf "\n"
513 lv_status $_lv $indent
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)
531 __print_indent $indent 1
532 printf "[ No segments for %s ]\n", $_lv->name
533 end
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
540 else
541 set $_seg = (struct lv_segment *)$_s
542 set $_type = 0x0
543
544 if (!$_area_index)
545 seg_status $_seg $indent
546 end
547 __seg_type $_type $_seg $_area_index
548 if ($_type == AREA_LV)
549 set $indent++
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
566 __seg_item $_lv $_seg $_area_index
567 __lv_status_r $_lv
568 else
569 if ($_seg->log_lv)
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--
578 end
579 __get_only_segment_using_this_lv $_seg $_lv
580 if ($_seg)
581 set $indent--
582 __lv_status_r $_lv $_seg
583 end
584 end
585 end
586 end
587
588 define lv_status_r
589 set $indent = 0
590 __lv_status_r $arg0
591 end
592
593 document lv_status_r
594 Display the status flags of an LV and its sub_lvs.
595
596 Usage: lv_status_r <LV ptr>
597
598 This function is useful for checking that all the LVs that
599 compose a logical volume have the correct flags set (and also
600 their associated lv_segments)
601 end
602
603 define 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
623 end
624
625 document lv_is_mirrored
626 Report whether the given LV is mirrored (and its log type).
627
628 Usage: lv_is_mirrored <LV ptr>
629 end
This page took 0.063705 seconds and 6 git commands to generate.