crash提供了eval命令,实现了一些很好用的功能,下面学习一下。
格式:
eval [-b][-l] (表达式) | 值
支持的运算符:+ - & | ^ * % / << >>
下面是需要注意的:
- 括号并不是必须的,但是如果使用了
|
、<<
或者>>
,那么需要使用括号
crash> eval (1 << 32) hexadecimal: 100000000 (4GB) decimal: 4294967296 octal: 40000000000 binary: 0000000000000000000000000000000100000000000000000000000000000000
- 传给eval的值可以是数字(10进制或者16进制),也可以符号,比如如果传入函数名或者全局变量名,返回函数或者全局变量的地址。
crash> eval panic_on_oops hexadecimal: ffffffff844c3dc4 decimal: 18446744071634173380 (-2075378236) octal: 1777777777760423036704 binary: 1111111111111111111111111111111110000100010011000011110111000100 crash> crash> rd panic_on_oops ffffffff844c3dc4: 0000000000000001 ........
- 如果传给eval的值是16进制,
0x
并不是必须的,比如有a~f
crash> eval 10 hexadecimal: a decimal: 10 octal: 12 binary: 0000000000000000000000000000000000000000000000000000000000001010 crash> eval 0x10 hexadecimal: 10 decimal: 16 octal: 20 binary: 0000000000000000000000000000000000000000000000000000000000010000 crash> eval 1a hexadecimal: 1a decimal: 26 octal: 32 binary: 0000000000000000000000000000000000000000000000000000000000011010 crash> eval 0x1a hexadecimal: 1a decimal: 26 octal: 32 binary: 0000000000000000000000000000000000000000000000000000000000011010
- 数字后面可以跟
K/k M/m G/g
,这里1K表示1024,1M表示10241024,1G表示10241024*1024
crash> eval 1k hexadecimal: 400 (1KB) decimal: 1024 octal: 2000 binary: 0000000000000000000000000000000000000000000000000000010000000000 crash> eval 8*2k hexadecimal: 4000 (16KB) decimal: 16384 octal: 40000 binary: 0000000000000000000000000000000000000000000000000100000000000000 crash> eval 0x10m hexadecimal: 1000000 (16MB) decimal: 16777216 octal: 100000000 binary: 0000000000000000000000000000000000000001000000000000000000000000 crash> eval 1k*1k hexadecimal: 100000 (1MB) decimal: 1048576 octal: 4000000 binary: 0000000000000000000000000000000000000000000100000000000000000000 crash> eval 1k*1G hexadecimal: 10000000000 (1024GB) decimal: 1099511627776 octal: 20000000000000 binary: 0000000000000000000000010000000000000000000000000000000000000000
- 可以在数字前面使用
~
表示取反
crash> eval ~2 hexadecimal: fffffffffffffffd decimal: 18446744073709551613 (-3) octal: 1777777777777777777775 binary: 1111111111111111111111111111111111111111111111111111111111111101 crash> eval ~a hexadecimal: fffffffffffffff5 decimal: 18446744073709551605 (-11) octal: 1777777777777777777765 binary: 1111111111111111111111111111111111111111111111111111111111110101
- 查看负数的表示
crash> eval -1 hexadecimal: ffffffffffffffff decimal: 18446744073709551615 (-1) octal: 1777777777777777777777 binary: 1111111111111111111111111111111111111111111111111111111111111111 crash> eval -a hexadecimal: fffffffffffffff6 decimal: 18446744073709551606 (-10) octal: 1777777777777777777766 binary: 1111111111111111111111111111111111111111111111111111111111110110
- 如果需要按64位计算,那么可以在数字前面使用
-l
参数。但是如果本身传入数字就是64位的,那么就不用传-l
。如果是在64系统上,都是按64位计算,不需要传-l
- 有时我们想知道一个数字的那些位是1,那么需要在数字前面使用
-b
参数
crash> eval -b 0x5 hexadecimal: 5 decimal: 5 octal: 5 binary: 0000000000000000000000000000000000000000000000000000000000000101 bits set: 2 0 crash> eval -b 0xa5 hexadecimal: a5 decimal: 165 octal: 245 binary: 0000000000000000000000000000000000000000000000000000000010100101 bits set: 7 5 2 0 crash> eval -b -1 hexadecimal: ffffffffffffffff decimal: 18446744073709551615 (-1) octal: 1777777777777777777777 binary: 1111111111111111111111111111111111111111111111111111111111111111 bits set: 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0