[SOLVED] Show variable of crate in rust-gdb

Hello!

I've been debugging my application which uses some crates. I can't get if it's possible to print a variable from a third party crate. I try to do this with command print extern libc::SIGUSR2 according that document. Unfortunately I get No symbol '::libc::SIGUSR2' in current context. Well does somebody know how to fix it?

I don't know about the problem, but maybe you could work around it by adding pub use libc; to your crate.

Do you mean pub extern crate libc? If so then it still raises the same error.

No, I mean pub use libc; only, as extern crate is not needed.

Of course, you have to have libc added as a dependency first. If you've created your project before 2019, then you also need to add edition = "2018" to Cargo.toml.

I missed that change in Cargo.toml. Now I see it. Thank you so much! Very well, I decided to make an example which is easy to use for reproducing the issue.

In order do to that you need:

git clone https://github.com/ANtlord/rust-gdb-test/tree/master
cargo build
rust-gdb rust-gdb target/debug/rust-gdb-test

inside GDB

break rust_gdb_test::main
print extern libc::SIGUSR2

Also, it's my fault that I forgot to designate versions of software
rustc 1.42.0 (b8cedc004 2020-03-09)
gdb 8.3
ubuntu 19.10 (kernel 5.3.0-46-generic)

Any thoughts?

Ok, looks like GDB doesn't show a constant (const statement). It shows variables and static variables but not constants. It's reasonable because they are not DIE (DWARF Information Entries). Does somebody know how to show a constant?

I don’t think constants show up in the binary at all as they are substituted directly where used during compilation. You should be able to assign the constant to a static variable in your code and print that.

Ok, I think it could marked as solved as the problem is located

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.