[PATCH v4] scripts/gdb: fix lx-version string output

From: Kieran Bingham
Date: Sun Nov 11 2018 - 11:20:43 EST


From: Du Changbin <changbin.du@xxxxxxxxx>

A bug is present in GDB which causes early string termination when
parsing variables. This has been reported [0], but we should ensure that
we can support at least basic printing of the core kernel strings.

For current gdb version (has been tested with 7.3 and 8.1), 'lx-version'
only prints one character.
(gdb) lx-version
L(gdb)

This can be fixed by casting 'linux_banner' as (char *).
(gdb) lx-version
Linux version 4.19.0-rc1+ (changbin@acer) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #21 SMP Sat Sep 1 21:43:30 CST 2018

[0] https://sourceware.org/bugzilla/show_bug.cgi?id=20077

Fixes: 2d061d999424 ("scripts/gdb: add version command")
Signed-off-by: Du Changbin <changbin.du@xxxxxxxxx>
Acked-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
[Kieran: Added detail to commit message]
Signed-off-by: Kieran Bingham <kbingham@xxxxxxxxxx>
---

Andrew - could you consider this patch for inclusion in your tree
please?

Regards

Kieran

scripts/gdb/linux/proc.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py
index 086d27223c0c..0aebd7565b03 100644
--- a/scripts/gdb/linux/proc.py
+++ b/scripts/gdb/linux/proc.py
@@ -41,7 +41,7 @@ class LxVersion(gdb.Command):

def invoke(self, arg, from_tty):
# linux_banner should contain a newline
- gdb.write(gdb.parse_and_eval("linux_banner").string())
+ gdb.write(gdb.parse_and_eval("(char *)linux_banner").string())

LxVersion()

--
2.17.1