Beginner's question: Cannot debug with rust-gdb under openSUSE

Hi Guys, I am fighting to build up the programming environment with VS code under openSUSE. Now the topmost issue is that I can't debug with rust-gdb or lldb or other debuggers.

I paste the debug info below to show you this issue:

rust-gdb main
(gdb) l
1 /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/obj/../src/libcore/iter/traits.rs: No such file or directory.
(gdb) l main
1 mod ac;
2
3 fn main() {
4 let mut ia;
5 for i in 0..10 {
6 ia = i;
7 println!("Hello{}!", ia);
8 }
9 }
(gdb) l
Line number 10 out of range; /home/Rust/hello/src/main.rs has 9 lines.
(gdb) b 8
No line 8 in the current file.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb)

It looks like the current location in the program is not in main.rs, but in libcore/iter/traits.rs, and GDB is having a hard time finding that file. That's what GDB is saying in response to your first attempt to list the current context.

Does the file /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/obj/../src/libcore/iter/traits.rs exist? Can it be made to exist?

You can set a breakpoint on line 8 of the current file using b 8, or in line 8 of main.rs (which I think is your goal) using b main.rs:8.

Thank you, cbiffle.

I checked the file "/buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/obj/../src/libcore/iter/traits.rs" but it doesn't exist.

I am not familiar with gdb either, should I tell gdb where the source file(main.rs) is? But I tried C lang, and there is no need to do that.

And I tried the way you tell me, but it still not works, I copied the printed info below:

(gdb) l main.rs
Function "main.rs" not defined.
(gdb) b main.rs 8
Function "main.rs 8" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b main:8
Breakpoint 1 at 0x5e70
(gdb) run
_Starting program: /home/Gene/ST/Studio/VSCode/Rust/hello/src/main _
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.19-22.1.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, 0x0000555555559e70 in main ()
Missing separate debuginfos, use: zypper install libgcc_s1-debuginfo-5.3.1+r233831-6.1.x86_64
(gdb) c
Continuing.
Hello0!
Hello1!
Hello2!
Hello3!
Hello4!
Hello5!
Hello6!
Hello7!
Hello8!
Hello9!
[Inferior 1 (process 11699) exited normally]

Good, then gdb is not crazy. That file existed when the compiler ran, and its path was recorded in the binary you're debugging. Something later made it disappear. If you want to debug code that comes from that file, you'll need to make it reappear.

I assume something is managing this /buildslave directory and moving files around on you. I don't know what it is though. (Whatever it is, it's also embedding absolute source paths in the debug symbols, which may be making your life harder than it ought to be.)

The thing is, the code you're interacting with isn't from main.rs. It came from a file included with the standard library (libcore/iter/traits.rs), probably because it was called from your main. If you're going to debug that code, you need to have the source files available to GDB. They were available to the compiler, but then something moved or removed them.

You missed the colon: b main.rs:8

It keeps saying this. I assume your distro doesn't install debug symbols for common libraries by default. You should run the command it prints to install them, which should make your GDB experience smoother.

Thank you again, cbiffle, very grateful for you help, I am sorry for the late response.

The the missing packages mentioned by gdb, I cannot install them, here is the report:

~> sudo zypper install glibc-debuginfo-2.19-22.1.x86_64
Loading repository data...
Reading installed packages...
'glibc-debuginfo-2.19-22.1.x86_64' not found in package names. Trying capabilities.
No provider of 'glibc-debuginfo-2.19-22.1.x86_64' found. ['--plus-content debug'?]
Resolving package dependencies...
Nothing to do.
~> sudo zypper install libgcc_s1-debuginfo-5.3.1+r233831-6.1.x86_64
Loading repository data...
Reading installed packages...
'libgcc_s1-debuginfo-5.3.1+r233831-6.1.x86_64' not found in package names. Trying capabilities.
No provider of 'libgcc_s1-debuginfo-5.3.1+r233831-6.1.x86_64' found. ['--plus-content debug'?]
Resolving package dependencies...
Nothing to do.

2.1
All content in main.rs is the main function.
I compiled the main.rs, and debug:
~> rustc -g main.rs
...
Reading symbols from main...done.
// Actually there is no /buildslave directory exists.
(gdb) l1
_ /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/obj/../src/libcore/iter/traits.rs: No such file or directory._
// Here cannot list the file content.
(gdb) l main.rs
Function "main.rs" not defined.
// Is able to list the function inside the main.rs.
(gdb) l main
1 fn main() {
2 let mut ia;
3 for i in 0..10 {
4 ia = i;
5 println!("Hello{}!", ia);
6 }
7 }
(gdb) b main.rs:8
// Cannot hit the breakpoint
(gdb) b main.rs:5
No line 5 in file "main.rs".
Make breakpoint pending on future shared library load? (y or [n])
2.2
Then I compiled in the default way:
~> rust-gdb main
...
Reading symbols from main...done.
(gdb) l
1 ../sysdeps/x86_64/start.S: No such file or directory.
(gdb) l main.rs
Function "main.rs" not defined.
(gdb) l main
(gdb) b main.rs:5
No source file named main.rs.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b 5
Breakpoint 1 at 0x58d0: file ../sysdeps/x86_64/start.S, line 5.
(gdb)