From b7d4f96d195323cf9344a2af6720dfae3d9f299d Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Thu, 21 Feb 2019 20:21:50 -0500 Subject: [PATCH] rust-lldb: fix crash when printing empty string --- src/etc/lldb_rust_formatters.py | 2 ++ src/test/debuginfo/empty-string.rs | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/test/debuginfo/empty-string.rs diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py index 2c651c90f82eb..fdc1c4fa0cc38 100644 --- a/src/etc/lldb_rust_formatters.py +++ b/src/etc/lldb_rust_formatters.py @@ -290,6 +290,8 @@ def render_element(i): def read_utf8_string(ptr_val, byte_count): + if byte_count == 0: + return '""' error = lldb.SBError() process = ptr_val.get_wrapped_value().GetProcess() data = process.ReadMemory(ptr_val.as_integer(), byte_count, error) diff --git a/src/test/debuginfo/empty-string.rs b/src/test/debuginfo/empty-string.rs new file mode 100644 index 0000000000000..43ce21908a958 --- /dev/null +++ b/src/test/debuginfo/empty-string.rs @@ -0,0 +1,33 @@ +// compile-flags:-g +// min-gdb-version: 7.7 +// min-lldb-version: 310 + +// === GDB TESTS =================================================================================== + +// gdb-command: run + +// gdb-command: print empty_string +// gdb-check:$1 = "" + +// gdb-command: print empty_str +// gdb-check:$2 = "" + +// === LLDB TESTS ================================================================================== + +// lldb-command: run + +// lldb-command: fr v empty_string +// lldb-check:[...]empty_string = "" + +// lldb-command: fr v empty_str +// lldb-check:[...]empty_str = "" + +fn main() { + let empty_string = String::new(); + + let empty_str = ""; + + zzz(); // #break +} + +fn zzz() {}