[gdb/tui] Fix len_without_escapes in tui-disasm.c
authorTom de Vries <tdevries@suse.de>
Tue, 6 Apr 2021 08:40:11 +0000 (10:40 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 6 Apr 2021 08:40:11 +0000 (10:40 +0200)
On openSUSE Tumbleweed I run into:
...
FAIL: gdb.tui/basic.exp: asm window shows main
ERROR: invalid command name "_csi_L"
...

Using a minimal example, we get:
...
$ gdb -q outputs/gdb.tui/basic/basic -ex "tui enable" -ex "layout asm"
<TUI output>
src/gdb/ui-style.c:243: internal-error: bool \
  ui_file_style::parse(const char*, size_t*): Assertion `match == 0' failed.
...

The problem is in len_without_escapes, where we detect the start of an escape
sequence, but then pass ptr to style.parse while ptr no longer points to the
escape due to the ptr++ in the while condition:
...
  while ((c = *ptr++) != '\0')
     {
      if (c == '\033')
        {
          ui_file_style style;
          size_t n_read;
          if (style.parse (ptr, &n_read))
...

Fix this by removing the ++ in the while condition, and adding ptr++ in the
loop body where appropriate.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-04-06  Tom de Vries  <tdevries@suse.de>

PR tui/27680
* tui/tui-disasm.c (len_without_escapes): Pass ptr pointing at escape
to style.parse.

gdb/ChangeLog
gdb/tui/tui-disasm.c

index 281c567a8d7f68c573e3d5292a050c45cc5fcfce..0abd3dd6df19ec466ad859c8f97a4234e1a1e373 100644 (file)
@@ -1,3 +1,9 @@
+2021-04-06  Tom de Vries  <tdevries@suse.de>
+
+       PR tui/27680
+       * tui/tui-disasm.c (len_without_escapes): Pass ptr pointing at escape
+       to style.parse.
+
 2021-04-04  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * avr-tdep.c (avr_frame_unwind_cache): Use
index 65b300cb0084cf77feac954397a1aaa08a5bd65c..163552aede4a5bb3cb012635f7a4c0294dbcbf19 100644 (file)
@@ -61,7 +61,7 @@ len_without_escapes (const std::string &str)
   const char *ptr = str.c_str ();
   char c;
 
-  while ((c = *ptr++) != '\0')
+  while ((c = *ptr) != '\0')
     {
       if (c == '\033')
        {
@@ -77,7 +77,10 @@ len_without_escapes (const std::string &str)
            }
        }
       else
-       ++len;
+       {
+         ++len;
+         ++ptr;
+       }
     }
   return len;
 }
This page took 0.027759 seconds and 4 git commands to generate.