From dc44c74411158e7cda7608890c3fdb3da12e93055af28b95633e453ed9f379ee Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 3 May 2021 07:47:57 +0000 Subject: [PATCH] - Backport fix for tui assert [swo#27680]: * gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch OBS-URL: https://build.opensuse.org/package/show/devel:gcc/gdb?expand=0&rev=274 --- ...-len_without_escapes-in-tui-disasm.c.patch | 71 +++++++++++++++++++ gdb.changes | 6 ++ gdb.spec | 2 + 3 files changed, 79 insertions(+) create mode 100644 gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch diff --git a/gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch b/gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch new file mode 100644 index 0000000..64f6bdf --- /dev/null +++ b/gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch @@ -0,0 +1,71 @@ +[gdb/tui] Fix len_without_escapes in tui-disasm.c + +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" + +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 + + PR tui/27680 + * tui/tui-disasm.c (len_without_escapes): Pass ptr pointing at escape + to style.parse. + +--- + gdb/tui/tui-disasm.c | 7 +++++-- + 2 files changed, 11 insertions(+), 2 deletions(-) + +diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c +index 65b300cb008..163552aede4 100644 +--- a/gdb/tui/tui-disasm.c ++++ b/gdb/tui/tui-disasm.c +@@ -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; + } diff --git a/gdb.changes b/gdb.changes index 05b9585..247ad0e 100644 --- a/gdb.changes +++ b/gdb.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Sun May 2 18:24:36 UTC 2021 - Tom de Vries + +- Backport fix for tui assert [swo#27680]: + * gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch + ------------------------------------------------------------------- Wed Apr 7 03:51:41 UTC 2021 - Tom de Vries diff --git a/gdb.spec b/gdb.spec index d659067..2025730 100644 --- a/gdb.spec +++ b/gdb.spec @@ -316,6 +316,7 @@ Patch2014: gdb-testsuite-fix-xfail-handling-in-gdb.threads-gcore-thread.exp Patch2015: gdb-threads-fix-lin_thread_get_thread_signals-for-glibc-2.28.patch Patch2016: gdb-testsuite-ignore-debuginfod_urls.patch Patch2017: gdb-testsuite-fix-unset-of-debuginfod_urls-in-default_gdb_init.patch +Patch2018: gdb-tui-fix-len_without_escapes-in-tui-disasm.c.patch # Testsuite patches @@ -732,6 +733,7 @@ find -name "*.info*"|xargs rm -f %patch2015 -p1 %patch2016 -p1 %patch2017 -p1 +%patch2018 -p1 %patch2500 -p1 %if 0%{?suse_version} > 1500