| 1 |
# |
| 2 |
# this file defines some utilities for printing various structures |
| 3 |
# found in the net-snmp source code. You can source it from within |
| 4 |
# gdb and then use it to print variable chains, oids, etc directly |
| 5 |
# from memory. |
| 6 |
# |
| 7 |
# as an example, consider the variables: |
| 8 |
# |
| 9 |
# oid *name; |
| 10 |
# size_t name_len; |
| 11 |
# |
| 12 |
# normally display oids is difficult under gdb, and the best you can |
| 13 |
# do is to use x/12dw name or so to print the first 12 numbers of the |
| 14 |
# oid array. however, with this file you can now use: |
| 15 |
# |
| 16 |
# gdb> printoid name_len name |
| 17 |
# .1.3.6.1.2.1.1.0 |
| 18 |
# |
| 19 |
# which will print oids in a more readable fashion. etc... |
| 20 |
# |
| 21 |
|
| 22 |
define initme |
| 23 |
set $varindent = "" |
| 24 |
end |
| 25 |
|
| 26 |
define hookpost-run |
| 27 |
initme |
| 28 |
end |
| 29 |
|
| 30 |
define printvarval |
| 31 |
printf "value: " |
| 32 |
if $arg0->type == 2 |
| 33 |
printf "int: %d\n", $arg0->val.integer |
| 34 |
end |
| 35 |
if $arg0->type == 4 |
| 36 |
printf "string: %s\n", $arg0->val.string |
| 37 |
end |
| 38 |
if $arg0->type == 5 |
| 39 |
printf "ASN NULL\n" |
| 40 |
end |
| 41 |
if $arg0->type == 6 |
| 42 |
printoid (($arg0->val_len)/sizeof(oid)) $arg0->val.objid |
| 43 |
end |
| 44 |
if $arg0->type == 128 |
| 45 |
printf "NO SUCH NAME\n" |
| 46 |
end |
| 47 |
if $arg0->type == 129 |
| 48 |
printf "NO SUCH INSTANCE\n" |
| 49 |
end |
| 50 |
if $arg0->type == 130 |
| 51 |
printf "END OF MIB VIEW\n" |
| 52 |
end |
| 53 |
if $arg0->type == 194 |
| 54 |
printf "AGENTX INCL RANGE: " |
| 55 |
printoid (($arg0->val_len)/sizeof(oid)) $arg0->val.objid |
| 56 |
end |
| 57 |
if $arg0->type == 195 |
| 58 |
printf "AGENTX EXCL RANGE: " |
| 59 |
printoid (($arg0->val_len)/sizeof(oid)) $arg0->val.objid |
| 60 |
end |
| 61 |
end |
| 62 |
document printvarval |
| 63 |
printvarval VARPTR |
| 64 |
prints the value part of a net-snmp "struct variable". |
| 65 |
This is called from inside printvar. |
| 66 |
end |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
define printvar |
| 71 |
printf "%stype: %d\n", $varindent, $arg0->type |
| 72 |
printf "%soid: ", $varindent |
| 73 |
printoid $arg0->name_length $arg0->name |
| 74 |
printf "%s", $varindent |
| 75 |
printvarval $arg0 |
| 76 |
end |
| 77 |
document printvar |
| 78 |
printvar VARPTR |
| 79 |
prints the variable information contained in a net-snmp struct |
| 80 |
variable. printvarval POINTER will print it's oid, value type and |
| 81 |
value contents |
| 82 |
end |
| 83 |
|
| 84 |
define printvars |
| 85 |
set $tmpcount = 1 |
| 86 |
set $tmpvar = $arg0 |
| 87 |
set $varindent = " " |
| 88 |
while $tmpvar != 0 |
| 89 |
printf "VARIABLE #%d\n", $tmpcount |
| 90 |
printvar $tmpvar |
| 91 |
set $tmpvar = $tmpvar->next_variable |
| 92 |
set $tmpcount = $tmpcount + 1 |
| 93 |
end |
| 94 |
set $varindent = "" |
| 95 |
end |
| 96 |
document printvars |
| 97 |
printvars VARPTR |
| 98 |
calls printvar repeatedly on a chain of variables, displaying all |
| 99 |
the variables in a net-snmp struct variable chain. |
| 100 |
end |
| 101 |
|
| 102 |
define printoid |
| 103 |
set $printoid_tmp = 0 |
| 104 |
while $printoid_tmp < $arg0 |
| 105 |
printf ".%d", $arg1[$printoid_tmp] |
| 106 |
set $printoid_tmp = $printoid_tmp + 1 |
| 107 |
end |
| 108 |
printf "\n" |
| 109 |
end |
| 110 |
document printoid |
| 111 |
printoid LENGTH OIDPTR |
| 112 |
prints an oid (.x.y.z...) given it's length and a pointer. |
| 113 |
end |
| 114 |
|
| 115 |
define poid |
| 116 |
printoid $arg0_len $arg0 |
| 117 |
end |
| 118 |
document poid |
| 119 |
poid NAME |
| 120 |
shorthand for 'printoid NAME_len NAME" |
| 121 |
end |
| 122 |
|
| 123 |
define poidl |
| 124 |
printoid $arg0_length $arg0 |
| 125 |
end |
| 126 |
document poidl |
| 127 |
poid NAME |
| 128 |
shorthand for 'printoid NAME_length NAME" |
| 129 |
end |
| 130 |
|
| 131 |
define printindex |
| 132 |
printoid $arg0->len $arg0->oids |
| 133 |
end |
| 134 |
document printindex |
| 135 |
printindex NETSNMP_INDEX_PTR |
| 136 |
prints the OID contained in a netsnmp_index struct variable. |
| 137 |
end |
| 138 |
|