Skip to content

Commit

Permalink
rust-lldb: fix crash when printing empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Feb 22, 2019
1 parent 633d75a commit 7c74bac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/etc/lldb_rust_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 30 additions & 20 deletions src/test/debuginfo/pretty-std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ignore-windows failing on win32 bot
// ignore-freebsd: gdb package too new
// ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
// ignore-android: FIXME(#10381)
// compile-flags:-g
// min-gdb-version 7.7
Expand All @@ -23,45 +22,54 @@
// gdb-check:$4 = "IAMA string!"

// gdb-command: print some
// gdb-check:$5 = Some = {8}
// gdbg-check:$5 = Some = {8}
// gdbr-check:$5 = core::option::Option<i16>::Some(8)

// gdb-command: print none
// gdbg-check:$6 = None
// gdbr-check:$6 = core::option::Option::None
// gdbr-check:$6 = core::option::Option<i64>::None

// gdb-command: print os_string
// gdb-check:$7 = "IAMA OS string 😃"
// gdb-check:$7 = "IAMA OS string"

// gdb-command: print some_string
// gdb-check:$8 = Some = {"IAMA optional string!"}
// gdbg-check:$8 = {RUST$ENCODED$ENUM$0$None = Some = {"IAMA optional string!"}}
// gdbr-check:$8 = core::option::Option<alloc::string::String>::Some("IAMA optional string!")

// gdb-command: set print length 5
// gdb-command: set print elements 5
// gdb-command: print some_string
// gdb-check:$8 = Some = {"IAMA "...}
// gdbg-check:$9 = {RUST$ENCODED$ENUM$0$None = Some = {"IAMA "...}}
// gdbr-check:$9 = core::option::Option<alloc::string::String>::Some("IAMA "...)

// gdb-command: print empty_str
// gdb-check:$10 = ""

// === LLDB TESTS ==================================================================================

// lldb-command: run

// lldb-command: print slice
// lldb-check:[...]$0 = &[0, 1, 2, 3]
// lldb-command: fr v slice
// lldb-check:[...]slice = &[0, 1, 2, 3]

// lldb-command: print vec
// lldb-check:[...]$1 = vec![4, 5, 6, 7]
// lldb-command: fr v vec
// lldb-check:[...]vec = vec![4, 5, 6, 7]

// lldb-command: print str_slice
// lldb-check:[...]$2 = "IAMA string slice!"
// lldb-command: fr v str_slice
// lldb-check:[...]str_slice = "IAMA string slice!"

// lldb-command: print string
// lldb-check:[...]$3 = "IAMA string!"
// lldb-command: fr v string
// lldb-check:[...]string = "IAMA string!"

// lldb-command: print some
// lldb-check:[...]$4 = Some(8)
// FIXME #58492
// lldb-command: fr v some
// lldb-check:[...]some = Option<i16> { }

// lldb-command: print none
// lldb-check:[...]$5 = None
// FIXME #58492
// lldb-command: fr v none
// lldb-check:[...]none = Option<i64> { }

// lldb-command: fr v empty_str
// lldb-check:[...]empty_str = ""

#![allow(unused_variables)]
use std::ffi::OsString;
Expand All @@ -82,14 +90,16 @@ fn main() {
let string = "IAMA string!".to_string();

// OsString
let os_string = OsString::from("IAMA OS string \u{1F603}");
let os_string = OsString::from("IAMA OS string");

// Option
let some = Some(8i16);
let none: Option<i64> = None;

let some_string = Some("IAMA optional string!".to_owned());

let empty_str = "";

zzz(); // #break
}

Expand Down

0 comments on commit 7c74bac

Please sign in to comment.