Skip to content

gdb crashes when printing a vector before it is defined #32954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dlrobertson opened this issue Apr 14, 2016 · 4 comments
Closed

gdb crashes when printing a vector before it is defined #32954

dlrobertson opened this issue Apr 14, 2016 · 4 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.)

Comments

@dlrobertson
Copy link
Contributor

When debugging something like the following with rust-gdb

fn main() {
    let x: Vec<i32> = Vec::new();
}

And doing something silly like the following

$ rust-gdb ./test
(gdb) br main
(gdb) frame
#0   test::main () at test.rs:2
2            let mut x: Vec<i32> = Vec::new();
(gdb) print x # printing x before it is defined

gdb freezes and will eventually be killed (on another of my machines a Python Exception is raised). This didn't occur with primitives (integer, slice, &str), but Python Exceptions were raised with Option, String, etc., but Vec was the only one that caused gdb to crash. Probably not too important since checking the values of items before they are defined is not useful.

@sfackler sfackler added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Apr 14, 2016
@tromey
Copy link
Contributor

tromey commented Apr 15, 2016

The Rust vector printer collects all the children at once:

        for index in range(0, length):
            cs.append((str(index), (gdb_ptr + index).dereference()))
        return cs

However this is not recommended practice for gdb pretty-printers. Instead they should return a lazy iterator. gdb will limit the displayed length according to either user settings (like set print elements); or, in MI mode, according to what the UI asked for.

@tromey
Copy link
Contributor

tromey commented Apr 24, 2016

Also, this is issue #29467, which apparently has a patch.

@nateozem
Copy link

I think this is no longer an issue. When I tried, I'd get No symbol 'x' in current context

$ rust-gdb builds/main
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin15.6.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Printing of array indexes is on.
Reading symbols from builds/main...Reading symbols from ../rust@gdb@crash@print@vector@issue@32954/builds/main.dSYM/Contents/Resources/DWARF/main...done.
done.
(gdb) break main::main
Breakpoint 1 at 0x1000014bc: file ../rust@gdb@crash@print@vector@issue@32954/main.rs, line 2.
(gdb) c
The program is not being run.
(gdb) r
Starting program: ../rust@gdb@crash@print@vector@issue@32954/builds/main

Breakpoint 1, main::main () at ../rust@gdb@crash@print@vector@issue@32954/main.rs:2
2           let x: Vec<i32> = Vec::new();
(gdb) print x
No symbol 'x' in current context
(gdb)

@Mark-Simulacrum
Copy link
Member

Closing as fixed. Verified that the vector is printed locally when going to the next line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.)
Projects
None yet
Development

No branches or pull requests

5 participants