]> sourceware.org Git - lvm2.git/blob - scripts/gdbinit
spacing
[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., 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
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
328 if ($_s_status)
329 printf " 0x%x", $_s_status
330 end
331 end
332
333 #
334 # __print_indent <num indents> [No marks]
335 define __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
356 end
357
358 define lv_status
359 # Use __lv because we don't want to overwrite higher functions
360 set $__lv = (struct logical_volume *)$arg0
361
362 if ($argc == 2)
363 __print_indent $arg1
364 end
365 printf "%s->status:", $__lv->name
366 __status $__lv
367 printf "\n"
368 end
369
370 document lv_status
371 Display the flags that are set on an LV.
372
373 Usage: lv_status <LV ptr>
374 end
375
376 define seg_status
377 set $_seg=(struct lv_segment *)$arg0
378
379 if ($argc == 2)
380 __print_indent $arg1 1
381 end
382 printf "[ (%s) seg->status:", $_seg->lv->name
383 __status $_seg
384 printf " ]\n"
385 end
386
387 document seg_status
388 Display the flags that are set on an lv_segment.
389
390 Usage: seg_status <(struct lv_segment *)>
391 end
392
393 #
394 # get_only_segment_using_this_lv <return> <LV>
395 define __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
400 set $_i = 0
401
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
405
406 set $_i++
407 set $_s = $_s->n
408 end
409
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
416 end
417
418 define 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
438 set $_i++
439 set $_s = $_s->n
440 end
441 end
442
443 document segs_using_this_lv
444 Display the segments (and their associated LV) using an LV
445
446 Usage: segs_using_this_lv <LV ptr>
447
448 Example:
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]
464 end
465
466 #
467 # __next_area_index <return> <seg> <seg_item>
468 define __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
487 end
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)
493 #
494 # or
495 #
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.
500 define __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
507 # printf "\n"
508 lv_status $_lv $indent
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)
526 __print_indent $indent 1
527 printf "[ No segments for %s ]\n", $_lv->name
528 end
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
535 else
536 set $_seg = (struct lv_segment *)$_s
537 set $_type = 0x0
538
539 if (!$_area_index)
540 seg_status $_seg $indent
541 end
542 __seg_type $_type $_seg $_area_index
543 if ($_type == AREA_LV)
544 set $indent++
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
561 __seg_item $_lv $_seg $_area_index
562 __lv_status_r $_lv
563 else
564 if ($_seg->log_lv)
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--
573 end
574 __get_only_segment_using_this_lv $_seg $_lv
575 if ($_seg)
576 set $indent--
577 __lv_status_r $_lv $_seg
578 end
579 end
580 end
581 end
582
583 define lv_status_r
584 set $indent = 0
585 __lv_status_r $arg0
586 end
587
588 document lv_status_r
589 Display the status flags of an LV and its sub_lvs.
590
591 Usage: lv_status_r <LV ptr>
592
593 This function is useful for checking that all the LVs that
594 compose a logical volume have the correct flags set (and also
595 their associated lv_segments)
596 end
597
598 define 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
618 end
619
620 document lv_is_mirrored
621 Report whether the given LV is mirrored (and its log type).
622
623 Usage: lv_is_mirrored <LV ptr>
624 end
This page took 0.061334 seconds and 5 git commands to generate.