我有一个指向结构的指针,我可以使用print /x (*s)
在gdb中打印它。
但是这给了我:
...,intensity = 2'\ 002'},{distance_2cm = 3045,intensity = 3'\ 003'},{distance_2cm = 14735,intensity = 7'\ a'},{dis tance_2cm = 3345,强度= 3'\ 003'},{distance_2cm = 14272,强度= 7'\ a'},{distance_2cm = 3735,强度= 2'\ 002'},{distance_2cm = 14617,强度= 6'\ 006'},{distance_2cm = 4239,强度= 2'\ 002'},{distance_2cm = 9741,强度= 5'\ 005'},{distance_2cm = 4892,强度= 2'\ 002'},{distance_2cm = 10686,强度= 4'\ 004' },{distance_2cm = 6012,intensity = 3'\ 003'},{distance_2cm = 9906,intensity = 3'\ 003'}}},{head = {laser_block_id = 61183,rotation_theta = 21191},lasers_arary = {{distance_2cm = 0,intensity = 2'\ 002'},{distance_2cm = 0,inte nsity = 1'\ 001'},{distance_2cm = 0,intensity = 3'\ 003'},{distance_2cm = 0,intensity = 1'\ 001'},{distance_2cm = 0,强度= 2'\ 002'},{distance_2cm = 0,强度= 2'\ 002'},{distance_2cm = 0,强度= 1'\ 001'},{distan ce_2cm = 6426,强度= 1'\ 001'},{distance_2cm = 2040,强度= 3'\ 003'},{distance_2cm = 6584,强度= 2 '\ 002'},{distance_2cm = 2154,intensity = 3'\ 003'},{distance_2cm = 0,intensity = 1'\ 001'},{distance_2cm = 2282, intensity = 3'\ 003'},{distance_2cm = 0,intensity = 1'\ 001'},{distance_2cm = 2428,intensity = 2'\ 002'},{distan ce_2cm = 26580,强度= 33'!'},{distance_2cm = 2592,强度= 5'\ 005'},{distance_2cm = 27180,强度= 2 7'\ 033'},{distance_2cm = 2795,强度= 3'\ 003'},{distance_2cm = 0,强度= 2'\ 002'},{distance_2cm = 3045 ,intensity = 3'\ 003'},{distance_2cm = 14712,intensity = 22'\ 026'},{distance_2cm = 3342,intensity = 3'\ 003'},{ distance_2cm = 14181,intensity = 7'\ a'},{distance_2cm = 3729,intensity = 2'\ 002'},{distance_2cm = 14474,intensi ty = 6'\ 006'},{distance_2cm = 4228,intensity = 2'\ 002'},{distance_2cm = 9744,intensity = 1'\ 001'},{distance_2c m = 4887,强度= 2'\ 002'},{distance_2cm = 13075,强度= 7'\ a'},{distance_2cm = 5994,强度= 3'\ 003 '},{distance_2cm = 9947,intensity = 4'\ 004'}}},{head = {laser_block_id = 61183,rotating_theta = 21207},lasers_ arary = {{distance_2cm = 0,intensity = 2'\ 002'},{distance_2cm = 0,intensity = 1'\ 001'},{distance_2cm = 0,intens ity = 3'\ 003'},{distance_2cm = 0,strength = 1'\ 001'},{distance_2cm = 0,intensity = 2'\ 002'},{distance_2cm = 0 ,intensity = 2'\ 002'},{distance_2cm = 0,intensity = 1'\ 001'},{distance_2cm = 0,intensity = 1'\ 001'},{distance _2cm = 2038,强度= 6'\ 006'},{distance_2cm = 6548,强度= 1'\ 001'},{distance_2cm = 2146,强度= 3' \ 003'},{distance_2cm = 0,strength = 1'\ 001'},{distance_2cm = 2285,intensity = 3'\ 003'},{distance_2cm = 0,inte nsity = 1'\ 001'},{distance_2cm = 2428,intensity = 2'\ 002'},{distance_2cm = 26498,intensity = 33'!'},{distance_ 2cm = 2590,强度= 5'\ 005'},{distance_2cm = 26177,强度= 29'\ 035'},{distance_2cm = 2792,强度= 3 '\ 003'},{distance_2cm = 0,strength = 2'\ 002'},{distance_2cm = 3044,intensity = 3'\ 003'},{distance_2cm = 14743, 强度= 7'\ a'},{distance_2cm = 3344,强度= 3'\ 003'},{distance_2cm = 14147,强度= 7'\ a'},{distan ce_2cm = 3728,强度= 2'\ 002'},{distance_2cm = 14520,强度= 13'\ r'},{distance_2cm = 4222,强度= 2 '\ 002'},{distance_2cm = 14567,强度= 5'\ 005'},{distance_2cm = 4885,强度= 3'\ 003'},{distance_2cm = 1 0842,强度= 6'\ 006'},{distance_2cm = 5978,强度= 3'\ 003'},{distance_2cm = 9964,强度= 6'\ 006'}} },} sd = {gps_time_stamp = 59467414,status_type = 55'7',status_value = 33'!'}}
我想用十六进制查看它,类似于下面的假设输出:
00000000: 2369 6e63 6c75 6465 203c 6368 6563 6b2e
00000010: 683e 0a0a 2369 6e63 6c75 6465 2022 635f
00000020: 7665 6c6f 6479 6e65 2f61 7267 7061 7273
00000030: 652e 6822 0a23 696e 636c 7564 6520 2263
有没有办法用gdb做到这一点?
答案 0 :(得分:4)
可以使用x
命令完成此操作。最简单的方法是首先找到结构的大小,然后将其作为参数传递给x
。类似的东西:
(gdb) print sizeof(whatever)
$1 = 1024
(gdb) x/512xh &whatever
解码x/512xh
:
x
表示以十六进制打印; h
表示" halfword",又名2个字节。gdb手册解释了可以在这里使用的所有标志。
您可以使用eval
以更高级的方式为您计算长度。如果您经常这样做,我建议可能在Python中编写一个新命令,进行一些处理,然后调用x
。