28 cmd =
"&((({0} *)0)->{1})".
format(container, field)
29 tmp = gdb.parse_and_eval(cmd)
30 return tmp.type.target()
33 macro_call =
"offsetof({0}, {1})".
format(container, field)
34 offset = long(gdb.parse_and_eval(macro_call))
58 if count != 0
or (count == 0
and result ==
""):
59 result +=
"{0}B".
format(count)
61 return str(saved_count) +
"<" + result.strip() +
">" 63 def sum(start_addr, count):
64 a = gdb.parse_and_eval(
"(unsigned char *){0:#x}".
format(start_addr))
66 for i
in range(count):
75 """Prints m0_list/m0_tl elements. 77 Usage: m0-list-print [&]list [[struct|union] tag link [visit|"in-detail"]] 79 First argument is only mandatory argument. It can be of type 80 - struct m0_list or struct m0_list *, 81 - struct m0_tl or struct m0_tl * 82 If this is the only argument supplied, then m0-list-print prints 83 address of each of links forming the list. 85 (gdb) m0-list-print session->s_slot_table[0]->sl_item_list 90 Later three arguments can be either all present or all absent. 91 The three arguments together specify name of link field 92 within ambient object. This form of m0-list-print prints pointers to 95 (gdb) m0-list-print session->s_slot_table[0]->sl_item_list struct m0_rpc_item ri_slot_refs[0].sr_link 100 The last parameter is optional, if present controls how the elements 102 - If the last parameter == "in-detail", then it prints all the contents of 103 ambient objects(not addreses) of the list 104 - Otherwise the last argument 'visit' if present is name of a user-defined command 105 that takes one argument(think m0-list-print as a list traversing function 106 with pointer to 'visit' function as arguemnt). 107 The visit command will be executed for each object in list. 108 The implementation of visit command can decide which objects to print and how. 110 (gdb) m0-list-print fop_types_list struct m0_fop_type ft_linkage in-detail 111 <Prints all m0_fop_type objects from fop_types_list> 113 (gdb) define session_visit 114 >set $s = (struct m0_rpc_session *)$arg0 115 >printf "session %p id %lu state %d\\n", $s, $s->s_session_id, $s->s_state 117 (gdb) m0-list-print session->s_conn->c_sessions struct m0_rpc_session s_link session_visit 118 session 0x604c60 id 191837184000000002 state 4 119 session 0x624e50 id 0 state 4 121 (gdb) m0-list-print session->s_conn->c_sessions struct m0_rpc_session s_link 128 gdb.Command.__init__(self,
"m0-list-print",
129 gdb.COMMAND_SUPPORT, gdb.COMPLETE_SYMBOL)
132 argv = gdb.string_to_argv(arg)
134 if argc
not in (1, 4, 5):
135 print 'Error: Usage: m0-list-print [&]list' \
136 ' [[struct|union] tag link [visit|"in-detail"]]' 139 vhead, head, ok = self.
get_head(argv)
146 visit = argv[4]
if argc == 5
else None 147 vnd = vhead[
'l_head']
152 obj_addr = nd - offset
154 print "0x%x" % obj_addr
155 elif visit ==
"in-detail":
156 cmd =
"p *({0} *){1}".
format(str(elm_type), obj_addr)
159 cmd =
"{0} {1}".
format(visit, obj_addr)
166 print "Total: %d" % total
171 vhead = gdb.parse_and_eval(argv[0])
172 type = str(vhead.type)
173 if type.startswith(
'const '):
174 type = type[len(
'const '):]
176 if type ==
"struct m0_list":
177 head = long(vhead.address)
178 elif type ==
"struct m0_list *":
180 elif type
in (
"struct m0_tl",
"struct m0_tl *"):
181 vhead = vhead[
't_head']
182 head = long(vhead.address)
184 print "Error: Invalid argument type: '%s'" % type
186 return vhead, head, ok
194 if argv[1]
not in (
"struct",
"union"):
195 print 'Error: Argument 2 must be ' + \
196 'either "struct" or "union"' 197 return 0,
None,
False 199 str_elm_type =
"{0} {1}".
format(argv[1], argv[2])
202 elm_type = gdb.lookup_type(str_elm_type)
204 print "Error: type '{0}' does not exist".
format(str_elm_type)
205 return 0,
None,
False 208 if type
not in (
"struct m0_list_link",
"struct m0_tlink"):
209 print "Error: Argument 4 must be of type m0_list_link or m0_tlink" 210 return 0,
None,
False 212 if type ==
"struct m0_tlink":
213 anchor = anchor.strip() +
".t_link" 217 return offset, elm_type,
True 224 """Prints segments in m0_bufvec 226 Usage: m0-bufvec-print [&]m0_bufvec 227 For each segment, the command prints, 229 - [start address, end_address), 230 - offset of first byte of segment, inside entire m0_bufvec, along with its 231 human readable representation, 232 - number of bytes in segment in human readable form, 233 - sumation of all the bytes in the segment. sum = 0, implies all the bytes in 234 the segment are zero. 237 gdb.Command.__init__(self,
"m0-bufvec-print", \
238 gdb.COMMAND_SUPPORT, gdb.COMPLETE_SYMBOL)
241 argv = gdb.string_to_argv(arg)
245 print "Error: Usage: m0-bufvec-print [&]m0_bufvec" 248 vbufvec = gdb.parse_and_eval(argv[0])
249 t = str(vbufvec.type)
250 if t !=
"struct m0_bufvec" and t !=
"struct m0_bufvec *":
251 print "Error: Argument 1 must be either 'struct m0_bufvec' or" + \
252 " 'struct m0_bufvec *' type" 255 nr_seg = long(vbufvec[
'ov_vec'][
'v_nr'])
258 sum_of_bytes_in_buf = 0
259 print "seg:index start_addr end_addr offset bcount sum" 260 for i
in range(nr_seg):
261 start_addr = long(vbufvec[
'ov_buf'][i])
262 count = long(vbufvec[
'ov_vec'][
'v_count'][i])
263 end_addr = start_addr + count
264 sum_of_bytes_in_seg =
sum(start_addr, count)
265 print "seg:{0} {1:#x} {2:#x} {3} {4} {5}".
format(i, \
270 sum_of_bytes_in_buf += sum_of_bytes_in_seg
272 print "nr_seg:", nr_seg
274 print "sum:", sum_of_bytes_in_buf
281 """Prints segments in m0_indexvec 283 Usage: m0-indexvec-print [&]m0_indexvec 286 gdb.Command.__init__(self,
"m0-indexvec-print", \
287 gdb.COMMAND_SUPPORT, gdb.COMPLETE_SYMBOL)
290 argv = gdb.string_to_argv(arg)
294 print "Error: Usage: m0-indexvec-print [&]m0_indexvec" 297 v_ivec = gdb.parse_and_eval(argv[0])
299 if t !=
"struct m0_indexvec" and t !=
"struct m0_indexvec *":
300 print "Error: Argument 1 must be of either 'struct m0_indexvec' or" + \
301 " 'struct m0_indexvec *' type." 304 nr_seg = long(v_ivec[
'iv_vec'][
'v_nr'])
307 print " :seg_num index count" 308 for i
in range(nr_seg):
309 index = long(v_ivec[
'iv_index'][i])
310 count = long(v_ivec[
'iv_vec'][
'v_count'][i])
311 print "seg:", i, index, count
314 print "nr_seg:", nr_seg
315 print "total:", total_count
319 "offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))", \
320 "container_of(ptr, type, member) " + \
321 "((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))" \
326 gdb.execute(
"macro define %s" % m)
332 print "Loading python gdb extensions for Motr..."
def invoke(self, arg, from_tty)
def invoke(self, arg, from_tty)
def field_type(container, field)
def get_offset(self, argv)
def invoke(self, arg, from_tty)
def sum(start_addr, count)
def offset_of(container, field)
def human_readable(count)