Skip to content

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

@cmacknz

Description

@cmacknz
Contributor

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).

Activity

brson

brson commented on Mar 26, 2014

@brson
Contributor
added
A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
on Jan 23, 2015
huonw

huonw commented on Nov 18, 2015

@huonw
Contributor

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

Mark-Simulacrum commented on Apr 15, 2017

@Mark-Simulacrum
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
added a commit that references this issue on Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@brson@huonw@cmacknz@Mark-Simulacrum

        Issue actions

          debuginfo: Generate debugging information for function level static variables · Issue #13144 · rust-lang/rust