How can I make gdb print unprintable characters of a string in hex instead of octal while preserving the ascii characters in ascii form?

前端 未结 3 1379
忘了有多久
忘了有多久 2021-02-12 10:11

Suppose I have a buffer buf whose c string representation is

 char* buf = \"Hello World \\x1c\"

When I print this buf in gdb using

3条回答
  •  悲哀的现实
    2021-02-12 10:47

    For anyone else who shares the irritation with octal escape-sequences in GDB, it's easy to fix (if you're prepared to build GDB yourself): in gdb/valprint.c, find the comment:

    /* If the value fits in 3 octal digits, print it that
                         way.  Otherwise, print it as a hex escape.  */
    

    and comment out the following 4 lines - all escape-sequences will then be printed as hex.

提交回复
热议问题