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

debuginfo: Generate debugging information for function level static variables #13144

Closed
cmacknz opened this issue Mar 25, 2014 · 3 comments
Closed
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.)

Comments

@cmacknz
Copy link
Contributor

cmacknz commented Mar 25, 2014

Support for crate level static variable debug info will be added once the patch for #9227 lands, but it does not include support for handling statics declared at the function level.

Fundamentally the new debuginfo::create_global_var_metadata() function needs to be updated to do the following:

  1. Identify when the variable it was called with was declared within a function.
  2. Emit scope metadata indicating that the variable belongs to the function, rather than the containing crate.

The "correct" way to approach this would be to update debuginfo::populate_scope_map::walk_decl() to handle the DeclItem case for ItemStatic items as is done for function local variables.

However, as a consequence of a bug in clang/llvm (see: http://llvm.org/bugs/show_bug.cgi?id=19238), passing the lexical scope metadata from a debuginfo::FunctionDebugContextData::scope_map member to llvm::LLVMDIBuilderCreateStaticVariable() results in a segfault when generating debug information.

The suggested work around is to use the function debug info as scope for the variable instead, with the consequence that the generated debug info will be not be entirely correct (similar to the clang case in the bug above).

@brson
Copy link
Contributor

brson commented Mar 26, 2014

Neat!

cc @michaelwoerister

bors added a commit that referenced this issue Mar 29, 2014
Only supports crate level statics. No debug info is generated for function level statics. Closes #9227.

As discussed at the end of the comments for #9227, I took an initial stab at adding support for function level statics and decided it would be enough work to warrant being split into a separate issue.

See #13144 for the new issue describing the need to add support for function level static variables.
@steveklabnik steveklabnik added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jan 23, 2015
@huonw
Copy link
Member

huonw commented Nov 18, 2015

Hm, it seems this may've regressed, because I cannot see even module-level statics in GDB.

static OUTSIDE: i32 = 123;
fn main() {
    static INSIDE: i32 = 456;
}
(gdb) break debug_fn_static.rs:4
Breakpoint 1 at 0x5164: file debug_fn_static.rs, line 4.
(gdb) run
...

Breakpoint 1, debug_fn_static::main () at debug_fn_static.rs:4
4   }
(gdb) info variables .*SIDE.*
All variables matching regular expression ".*SIDE.*":
(gdb) 

@Mark-Simulacrum
Copy link
Member

I believe that the static variables huonw notes above aren't being picked up because they're const folded away, but this appears to be working now. Both module-level and function-local statics are picked up.

pub static mut OUTSIDE: i32 = 123;

fn main() {
    static mut INSIDE: i32 = 456;

    unsafe { (OUTSIDE, INSIDE) };
}

generates

(gdb) info variables .*SIDE.*
All variables matching regular expression ".*SIDE.*":

File ./t.rs:
static i32 t::OUTSIDE;
static i32 t::main::INSIDE;

Non-debugging symbols:
0x000000000024e2a8  t::OUTSIDE::h631ab381ceee3286
0x000000000024e2ac  t::main::INSIDE::hcfa46a7f78bcb925

dingxiangfei2009 pushed a commit to dingxiangfei2009/rust that referenced this issue Jul 28, 2024
…hat, r=y21

Make restriction lint's use `span_lint_and_then` (i -> p)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by rust-lang/rust-clippy#7797.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

cc: rust-lang/rust-clippy#7797

brother PR of: rust-lang/rust-clippy#13136

changelog: none
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