title: How can I make gdb print unprintable characters of a string in hex instead of octal while preserving the ascii characters in ascii form?
body: <p>Suppose I have a buffer <code>buf</code> whose c string representation is</p>
  
  <pre><code> char* buf = "Hello World \x1c"
  </code></pre>
  
  <p>When I print this buf in gdb using the command <code>p buf</code>, I get the following</p>
  
  <pre><code> $1 = "Hello World \034"
  </code></pre>
  
  <p><strong>Is there a print command or a gdb setting that will print the following instead?</strong></p>
  
  <pre><code>$1 = "Hello World \x1c"
  </code></pre>
  
  <p>I have tried various format parameters such as <code>/c</code> and  <code>/x</code>, but none of them get the effect that I am looking for. I have also played with printf but was unable to achieve the desired effect.</p>
  
  <p>Update: I am using "GNU gdb (GDB) 7.0.1-debian".</p>
  
  <p>Update: 
  I have played with x as well. </p>
  
  <p>If I do <code>x/c</code> it prints octal and decimal for nonprintable characters, and then prints printable characters with the ascii and decimal. </p>
  
  <p>If I do <code>x/s</code> it outputs exactly the same as the p command. </p>
  
  <p>If I do <code>x/x</code> it just outputs hex but then we lose the ascii characters for the printable part.</p>
  
  <p>Update: This <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Print-Settings.html#Print-Settings">reference</a>, unless incomplete, suggests that what I desire is not available, but can anyone confirm?</p>