两句话帮你彻底记住gdb之eXamining memory

对于刚学习Unix/Linux环境C编程的小朋友们或者写了很多所谓的C代码的老手们(其实很可能是机械程序员或者是伪程序员)来说,要记住gdb的eXaming memory的语法其实是相当不容易的,如果学习了gdb的这一语法后不再反复操练,很快就会忘记得干干净净。

先看看gnu/docs/gdb上怎么说,

8.5 Examining memory

You can use the command x (for "examine") to examine memory in any of several formats, independently of your program's data types.

x/nfu addr
x addr
x
    Use the x command to examine memory.

n, f, and u are all optional parameters that specify how much memory to display and how to format it; addr is an expression giving the address where you want to start displaying memory. If you use defaults for nfu, you need not type the slash `/'. Several commands set convenient defaults for addr.

n, the repeat count
    The repeat count is a decimal integer; the default is 1. It specifies how much memory (counting by units u) to display.

f, the display format
    The display format is one of the formats used by print, `s' (null-terminated string), or `i' (machine instruction). The default is `x' (hexadecimal) initially. The default changes each time you use either x or print.

u, the unit size
    The unit size is any of

b
        Bytes.
    h
        Halfwords (two bytes).
    w
        Words (four bytes). This is the initial default.
    g
        Giant words (eight bytes).

Each time you specify a unit size with x, that size becomes the default unit the next time you use x. (For the `s' and `i' formats, the unit size is ignored and is normally not written.)

addr, starting display address
    ...<snip>...

好吧,eXamine memory语法格式可简单地总结为:

X /NFU <addr> #(为方便后面巧记,下面对关键字符一律采用大写)
X: eXamine (可大约理解为从内存地址<addr>里读数据)
N: the repeat couNt (重复读取的次数)
F: the display Format (格式化显示)
U: the Unit size (读取的内存单元尺寸) 对于U: the Unit Size,
B: Byte 1个字节
H: Halfword (two bytes)(半字)2个字节
W: Word (four bytes)(字) 4个字节
G: Giant (eight bytes)(双字) 8个字节

第一句话: 我X,No Follow Up!

如果你是一个工作多年的人,那么这句话一定能说到你心里去。想想看,好几个月前,就某个问题开了一下午会,扯了好几个小时的淡,但是没有人记AI,也没有人后续跟进落实,不就是典型的"我X(嚓),No Follow Up"不是?

第二句话: 彪悍啦,我滴哥! (Biao Han la, Wo di Ge!) 我滴哥,我滴天堂~

能想到这句话,我要特别感谢一下我亲爱的弟儿。大约6年前,我亲爱的弟儿来北京集团总部开会,跟我还有我媳妇一起去巴沟的华联吃海底捞火锅,远远看见华联的标识BHG,他脱口而出,“BHG, 彪悍哥!”。当时我很自豪地回应了他一句,“我为你感到骄傲,二娃!”。 他问“为啥子?”,我说:“因为你有一个特别好的‘锅锅’(重庆话:哥哥),还有一个特别好的嫂子!” 弟娃儿的一句“BHG, 彪悍哥!”启发了我,于是我彻底记住了BHWG,从此再也不可能忘记,因为已经灰常灰常形象地刻进了脑子里!

上一篇:[转载]QString 乱谈(3)-Qt5与中文


下一篇:《RabbitMQ Tutorial》译文 第 6 章 远程过程调用(RPC)