]> sourceware.org Git - lvm2.git/blob - scripts/gdbinit
update reworded string
[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 " - first_seg <LV ptr>\n"
21 printf " - lv_status <LV ptr>\n"
22 printf " - lv_status_r <LV ptr>\n"
23 printf " - lv_is_mirrored <LV ptr>\n"
24 printf " - seg_item <seg ptr> <index>\n"
25 printf " - seg_status <seg ptr>\n"
26 printf " - segs_using_this_lv <seg ptr>\n"
27 printf " - \n"
28 printf "Use 'help <command>' for more info\n"
29 printf "\n\n"
30 printf "Popular breakpoints:\n"
31 printf "break _get_udev_flags\n"
32 printf "run --splitmirrors 1 -n split vg/lv\n"
33 printf "\n\n"
34
35 set follow-fork-mode child
36
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
44 define 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
55 end
56
57 document dm_list_size
58 Returns the number of elements in the dm_list
59
60 Usage: dm_list_size <list ptr>
61 end
62
63 #
64 # __first_seg <return> <LV>
65 define __first_seg
66 set $arg0 = 0x0
67 set $_FS_lv = (struct logical_volume *)$arg1
68
69 if ($_FS_lv->segments.n != &$_FS_lv->segments)
70 set $arg0 = (struct lv_segment *)$_FS_lv->segments.n
71 end
72 end
73
74 define first_seg
75 set $_seg = 0
76 set $_lv=(struct logical_volume *)$arg0
77
78 __first_seg $_seg $_lv
79
80 if ($_seg)
81 p $_seg
82 else
83 printf "No segments (list empty)\n"
84 end
85 end
86
87 document first_seg
88 Returns the pointer to the first segment of an LV
89
90 Usage: first_seg <LV ptr>
91
92 WARNING: If the list pointer in 'struct lv_segment' moves,
93 this function will be wrong.
94 end
95
96 #
97 # __seg_type <return> <seg> <index>
98 define __seg_type
99 set $arg0 = 0x0
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
104
105 set $arg0 = $_ST_type
106 end
107
108 #
109 # __seg_item <return> <seg> <index>
110 define __seg_item
111 set $arg0 = 0x0
112 set $_SI_seg = (struct lv_segment *)$arg1
113 set $_SI_index= $arg2
114
115 if ($_SI_index < $_SI_seg->area_count)
116 set $_SI_area = $_SI_seg->areas[$_SI_index]
117 set $_SI_type = $_SI_area.type
118
119 if ($_SI_type == AREA_PV)
120 set $arg0 = $_SI_area.u.pv.pvseg->pv
121 else
122 if ($_SI_type == AREA_LV)
123 set $arg0 = $_SI_area.u.lv.lv
124 end
125 end
126 end
127 end
128
129 #
130 # __seg_metaitem <return> <seg> <index>
131 define __seg_metaitem
132 set $arg0 = 0x0
133 set $_SMI_seg = (struct lv_segment *)$arg1
134 set $_SMI_index= $arg2
135
136 if (($_SMI_index < $_SMI_seg->area_count) && $_SMI_seg->meta_areas)
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
148 end
149
150 define 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
159 end
160
161 define 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
170 end
171
172 document seg_item
173 Returns the pointer to the LV or PV for the indexed area of a segment
174
175 Usage: seg_item <struct lv_segment *> <index>
176
177 Example - 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"
189 end
190
191 define __status
192 set $_s_status = $arg0->status
193
194 # Constants defined in metadata-exported.h
195
196 # if ($_s_status & RAID)
197 if ($_s_status & 0x0000000100000000LU)
198 set $_s_status = $_s_status & ~0x0000000100000000LU
199 printf " RAID"
200 end
201 # if ($_s_status & RAID_META)
202 if ($_s_status & 0x0000000200000000LU)
203 set $_s_status = $_s_status & ~0x0000000200000000LU
204 printf " RAID_META"
205 end
206 # if ($_s_status & RAID_IMAGE)
207 if ($_s_status & 0x0000000400000000LU)
208 set $_s_status = $_s_status & ~0x0000000400000000LU
209 printf " RAID_IMAGE"
210 end
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
226 # if ($_s_status & VISIBLE_LV)
227 if ($_s_status & 0x00000040U)
228 printf " VISIBLE_LV"
229 set $_s_status = $_s_status & ~0x00000040U
230 else
231 printf " *HIDDEN_LV*"
232 end
233 # if ($_s_status & FIXED_MINOR)
234 if ($_s_status & 0x00000080U)
235 set $_s_status = $_s_status & ~0x00000080U
236 printf " FIXED_MINOR"
237 end
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
248 # if ($_s_status & SNAPSHOT)
249 if ($_s_status & 0x00001000U)
250 set $_s_status = $_s_status & ~0x00001000U
251 printf " SNAPSHOT"
252 end
253 # if ($_s_status & PVMOVE)
254 if ($_s_status & 0x00002000U)
255 set $_s_status = $_s_status & ~0x00002000U
256 printf " PVMOVE"
257 end
258 # if ($_s_status & LOCKED)
259 if ($_s_status & 0x00004000U)
260 set $_s_status = $_s_status & ~0x00004000U
261 printf " LOCKED"
262 end
263 # if ($_s_status & LV_NOTSYNCED)
264 if ($_s_status & 0x00080000U)
265 set $_s_status = $_s_status & ~0x00080000U
266 printf " LV_NOTSYNCED"
267 end
268 # if ($_s_status & CONVERTING)
269 if ($_s_status & 0x00400000U)
270 set $_s_status = $_s_status & ~0x00400000U
271 printf " CONVERTING"
272 end
273 # if ($_s_status & MERGING)
274 if ($_s_status & 0x10000000U)
275 set $_s_status = $_s_status & ~0x10000000U
276 printf " MERGING"
277 end
278
279 if ($_s_status)
280 printf " 0x%x", $_s_status
281 end
282 end
283
284 #
285 # __print_indent <num indents> [No marks]
286 define __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
307 end
308
309 define lv_status
310 # Use __lv because we don't want to overwrite higher functions
311 set $__lv = (struct logical_volume *)$arg0
312
313 if ($argc == 2)
314 __print_indent $arg1
315 end
316 printf "%s->status:", $__lv->name
317 __status $__lv
318 printf "\n"
319 end
320
321 document lv_status
322 Display the flags that are set on an LV.
323
324 Usage: lv_status <LV ptr>
325 end
326
327 define seg_status
328 set $_seg=(struct lv_segment *)$arg0
329
330 if ($argc == 2)
331 __print_indent $arg1 1
332 end
333 printf "[ (%s) seg->status:", $_seg->lv->name
334 __status $_seg
335 printf " ]\n"
336 end
337
338 document seg_status
339 Display the flags that are set on an lv_segment.
340
341 Usage: seg_status <(struct lv_segment *)>
342 end
343
344 #
345 # get_only_segment_using_this_lv <return> <LV>
346 define __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
351 set $_i = 0
352
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
356
357 set $_i++
358 set $_s = $_s->n
359 end
360
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
367 end
368
369 define 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
389 set $_i++
390 set $_s = $_s->n
391 end
392 end
393
394 document segs_using_this_lv
395 Display the segments (and their associated LV) using an LV
396
397 Usage: segs_using_this_lv <LV ptr>
398
399 Example:
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]
415 end
416
417 #
418 # __next_area_index <return> <seg> <seg_item>
419 define __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
438 end
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)
444 #
445 # or
446 #
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.
451 define __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
458 # printf "\n"
459 lv_status $_lv $indent
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)
477 __print_indent $indent 1
478 printf "[ No segments for %s ]\n", $_lv->name
479 end
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
486 else
487 set $_seg = (struct lv_segment *)$_s
488 set $_type = 0x0
489
490 if (!$_area_index)
491 seg_status $_seg $indent
492 end
493 __seg_type $_type $_seg $_area_index
494 if ($_type == AREA_LV)
495 set $indent++
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
512 __seg_item $_lv $_seg $_area_index
513 __lv_status_r $_lv
514 else
515 if ($_seg->log_lv)
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--
524 end
525 __get_only_segment_using_this_lv $_seg $_lv
526 if ($_seg)
527 set $indent--
528 __lv_status_r $_lv $_seg
529 end
530 end
531 end
532 end
533
534 define lv_status_r
535 set $indent = 0
536 __lv_status_r $arg0
537 end
538
539 document lv_status_r
540 Display the status flags of an LV and its sub_lvs.
541
542 Usage: lv_status_r <LV ptr>
543
544 This function is useful for checking that all the LVs that
545 compose a logical volume have the correct flags set (and also
546 their associated lv_segments)
547 end
548
549 define 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
569 end
570
571 document lv_is_mirrored
572 Report whether the given LV is mirrored (and its log type).
573
574 Usage: lv_is_mirrored <LV ptr>
575 end
This page took 0.059046 seconds and 5 git commands to generate.