| 1 |
|
| 2 |
# |
| 3 |
# gdb_macros is a gdb script file which can assist |
| 4 |
# developer in debugging. This script provides |
| 5 |
# following functions for debugging gluster processes |
| 6 |
# effectively: |
| 7 |
# |
| 8 |
# pdict : This function will iterate through all the |
| 9 |
# dictionary (dict_t) members and print the |
| 10 |
# key-value pair. |
| 11 |
# |
| 12 |
# plist : This function will print address of each member |
| 13 |
# of gluster list (list_head). |
| 14 |
# |
| 15 |
# gdb script should be loaded in gdb before using these |
| 16 |
# functions. gdb script can be loaded on-demand or on gdb |
| 17 |
# start-up. Use the following command on gdb prompt for |
| 18 |
# loading it on-demand. |
| 19 |
# source <script filename> |
| 20 |
# e.g. |
| 21 |
# (gdb) source /mnt/gdb_macros |
| 22 |
# |
| 23 |
# To automatically load gdb script on startup use .gdbinit |
| 24 |
# file. This file is automatically loaded by gdb on start. |
| 25 |
# Edit (or create) ~/.gdbinit file and add the following |
| 26 |
# entry: |
| 27 |
# source /mnt/gdb_macros |
| 28 |
# |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
# This is an internal helper function |
| 33 |
define _print_dict_data |
| 34 |
set $data = ($arg0) |
| 35 |
set $len = $data->len - 1 |
| 36 |
set $i = 0 |
| 37 |
set $ishex = 0 |
| 38 |
while ($i < $len) |
| 39 |
set $ch = $data->data [$i] |
| 40 |
|
| 41 |
# Print only alpha-numeric values as char |
| 42 |
# and remaining as hex value. This is done |
| 43 |
# in this way because using %s screws up |
| 44 |
# the display if the string has non-displayable |
| 45 |
# characters |
| 46 |
if ($ishex == 0) && ($ch > 31) && ($ch < 127) |
| 47 |
printf "%c", $ch |
| 48 |
else |
| 49 |
printf "%x", ($ch & 0xFF) |
| 50 |
set $ishex = 1 |
| 51 |
end |
| 52 |
set $i = $i + 1 |
| 53 |
end |
| 54 |
end |
| 55 |
|
| 56 |
|
| 57 |
define pdict |
| 58 |
set $cnt = 1 |
| 59 |
set $temp = *($arg0->members) |
| 60 |
while ($temp) |
| 61 |
printf "[%d](%s::",$cnt, $temp->key |
| 62 |
_print_dict_data ($temp)->value |
| 63 |
printf ")\n" |
| 64 |
set $temp = $temp->next |
| 65 |
set $cnt = $cnt + 1 |
| 66 |
end |
| 67 |
printf "Done\n" |
| 68 |
end |
| 69 |
|
| 70 |
|
| 71 |
define plist |
| 72 |
set $node = &($arg0) |
| 73 |
set $head = $node |
| 74 |
|
| 75 |
printf "[0x%lx]", $node |
| 76 |
set $node = $node->next |
| 77 |
|
| 78 |
while ($node != $head) |
| 79 |
printf "--> [0x%lx]", $node |
| 80 |
set $node = $node->next |
| 81 |
end |
| 82 |
printf "\n" |
| 83 |
end |
| 84 |
|