This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug mi/15806] Some fields in async MI events get escaped twice


https://sourceware.org/bugzilla/show_bug.cgi?id=15806

--- Comment #9 from asmwarrior <asmwarrior at gmail dot com> ---
Hi, when look at this function:
/* Print the character C on STREAM as part of the contents of a literal
   string whose delimiter is QUOTER.  Note that this routine should only
   be call for printing things which are independent of the language
   of the program being debugged.  */

static void
printchar (int c, void (*do_fputs) (const char *, struct ui_file *),
       void (*do_fprintf) (struct ui_file *, const char *, ...)
       ATTRIBUTE_FPTR_PRINTF_2, struct ui_file *stream, int quoter)
{
  c &= 0xFF;            /* Avoid sign bit follies */

  if (c < 0x20 ||        /* Low control chars */
      (c >= 0x7F && c < 0xA0) ||    /* DEL, High controls */
      (sevenbit_strings && c >= 0x80))
    {                /* high order bit set */
      switch (c)
    {
    case '\n':
      do_fputs ("\\n", stream);
      break;
    case '\b':
      do_fputs ("\\b", stream);
      break;
    case '\t':
      do_fputs ("\\t", stream);
      break;
    case '\f':
      do_fputs ("\\f", stream);
      break;
    case '\r':
      do_fputs ("\\r", stream);
      break;
    case '\033':
      do_fputs ("\\e", stream);
      break;
    case '\007':
      do_fputs ("\\a", stream);
      break;
    default:
      do_fprintf (stream, "\\%.3o", (unsigned int) c);
      break;
    }
    }
  else
    {
      if (c == '\\' || c == quoter)
    do_fputs ("\\", stream);
      do_fprintf (stream, "%c", c);
    }
}

I think we can fix our issue by look at this condition:
1, when   mi->event_channel = mi_console_file_new (raw_stdout, "=", 0); is
created, look at the third argument, it is 0, which means the quoter is 0

2, look at my comment 1, I have a call stack shown, where when gdb_flush
(mi->event_channel); is called, the deeper printchar will have the last
argument quoter = 0.

3, when read the document, I see that "Print the character C on STREAM as part
of the contents of a literal string whose delimiter is QUOTER", this means
usually the QUOTER is " (for c string) or ' (for c char), but what about quoter
== 0?

4, I think if quoter==0, we should not double the backslash.

5, So, we can change the if condition here is like:
      if (c == '\\' ||  (c == quoter && quoter != 0))
    do_fputs ("\\", stream);

6, I initial guess is that if the quoter == 0, we even don't need to escape the
\f \r \n (which is the first part of the printchar() function), but I may be
wrong.


Yuanhui Zhang(asmwarrior)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]