Skip to content
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

Fresh MSYS2 gdb cannot set a breakpoint in Rust executables #79112

Closed
petrochenkov opened this issue Nov 16, 2020 · 7 comments
Closed

Fresh MSYS2 gdb cannot set a breakpoint in Rust executables #79112

petrochenkov opened this issue Nov 16, 2020 · 7 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows

Comments

@petrochenkov
Copy link
Contributor

Reproduction:

// main.c

#include <stdio.h>

int main() {
    printf("Hello world!\n");
}
// main.rs

fn main() {
    println!("Hello world!");
}
# script.gdb

break main
run
quit
# reproduce.sh

set -x

gcc --version
rustc --version
/mingw64/bin/gdb --version
/usr/bin/gdb --version

gcc -g main.c -o mainc
rustc -g main.rs -o mainrs

/mingw64/bin/gdb -q -x script.gdb ./mainc
/mingw64/bin/gdb -q -x script.gdb ./mainrs
/usr/bin/gdb -q -x script.gdb ./mainc
/usr/bin/gdb -q -x script.gdb ./mainrs

Output on my machine:

++ gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

++ rustc --version
rustc 1.50.0-nightly (74f7e32f4 2020-11-13)
++ /mingw64/bin/gdb --version
GNU gdb (GDB) 9.2
Copyright (C) 2020 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.
++ /usr/bin/gdb --version
GNU gdb (GDB) 9.2
Copyright (C) 2020 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.
++ gcc -g main.c -o mainc
++ rustc -g main.rs -o mainrs
++ /mingw64/bin/gdb -q -x script.gdb ./mainc
Reading symbols from ./mainc...
Breakpoint 1 at 0x4015a1: file main.c, line 6.

Breakpoint 1, main () at main.c:6
6           printf("Hello world!\n");
++ /mingw64/bin/gdb -q -x script.gdb ./mainrs
Reading symbols from ./mainrs...
Breakpoint 1 at 0x4015a7: main. (2 locations)

Breakpoint 1, 0x00000000013515fa in main ()
++ /usr/bin/gdb -q -x script.gdb ./mainc
Traceback (most recent call last):
  File "<string>", line 3, in <module>
ModuleNotFoundError: No module named 'libstdcxx'
/etc/gdbinit:6: Error in sourced command file:
Error while executing Python code.
Reading symbols from ./mainc...
Breakpoint 1 at 0x4015a1: file main.c, line 6.

Breakpoint 1, main () at main.c:6
6           printf("Hello world!\n");
++ /usr/bin/gdb -q -x script.gdb ./mainrs
Traceback (most recent call last):
  File "<string>", line 3, in <module>
ModuleNotFoundError: No module named 'libstdcxx'
/etc/gdbinit:6: Error in sourced command file:
Error while executing Python code.
Reading symbols from ./mainrs...
Breakpoint 1 at 0x4015a7: main. (2 locations)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x4015a7
Cannot insert breakpoint 1.
Cannot access memory at address 0x4015f0

script.gdb:4: Error in sourced command file:
Command aborted.
@petrochenkov petrochenkov added C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) labels Nov 16, 2020
@petrochenkov
Copy link
Contributor Author

As you can see with both /mingw64/bin/gdb and C executables breakpoints are set correctly, only the combination "/usr/bin/gdb + Rust" doesn't work.
This is a recent regression (a month or so).

(ModuleNotFoundError: No module named 'libstdcxx' is a red herring, this is an independent issue - a modern incarnation of msys2/MSYS2-packages#598.)

cc @mati865

@petrochenkov
Copy link
Contributor Author

The whole debuginfo test suite fails due to this issue.
The solution is to switch to /mingw64/bin/gdb (which has its own set of issues, but at least they don't affect the test suite).

@mati865
Copy link
Contributor

mati865 commented Nov 16, 2020

I don't think I've tried using /usr/bin/gdb with Rust but if you say it worked before bisecting could be useful.

@petrochenkov
Copy link
Contributor Author

@mati865
This is a consequence of enabling ASLR (#75406).
Apparently /usr/bin/gdb cannot handle it.
Perhaps it can be fixed on MSYS2 side?

The workaround is to build Rust code without ASLR using -Clink-args=-Wl,--disable-dynamicbase.

@mati865
Copy link
Contributor

mati865 commented Nov 18, 2020

@petrochenkov right, MinGW GDB was updated with ASLR fix but msys/gdb was not since msys/* packages do not use ASLR. Definitely could be fixed by MSYS2.

@mati865
Copy link
Contributor

mati865 commented May 4, 2021

This is now fixed upstream since version 10 was uploaded: https://packages.msys2.org/package/gdb?repo=msys&variant=x86_64

@petrochenkov
Copy link
Contributor Author

Great news.
I've just confirmed that it works.

The issue with libstdcxx pretty-printers (#79112 (comment)) still remains though, but it's not critical.

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.) C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows
Projects
None yet
Development

No branches or pull requests

2 participants