Skip to content

debuginfo: Support for namespaces #9097

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

Closed

Conversation

michaelwoerister
Copy link
Member

Who would have thought that namespaces are such a can of worms :P This is mostly because of some GDB idiosyncrasies (does not use namespace information but linkage-name attributes for displaying items contained in namespaces, also cannot handle functions lexically nested within functions), monomorphization, and information about external items only available from metadata.

This pull request tries to tackle the problem anyway:

  • The DW_AT_linkage_name for functions is generated just to make GDB display a proper namespace-enabled function name. To this end, a pseudo-mangled name is generated, not corresponding to the real linkage name. This approach shows some success and could be extended to make GDB also show proper parameter types.
  • As GDB won't accept subprogram DIEs nested within other subprogram DIEs, the debuginfo module now generates a companion namespace for each functions (iff needed). A function fn abc() will get a companion namespace with name abc(), which contains all items (modules, types, functions) declared within the functions scope. The real, proper solution, in my opinion, would be to faithfully reflect the program's lexical structure within DWARF (which allows arbitrary nesting of DIEs, afaik), but I am not sure LLVM's source level debugging implementation would like that and I am pretty sure GDB won't support this in the foreseeable future.
  • Monomorphization leads to functions and companion namespaces like somelib::some_func<int, float>()::some_other_function<bool, bool, bool>(), which I think is the desired behaviour. There is some design space here, however. Maybe you people prefer somelib::some_func()::some_other_function<bool, bool, bool>() or somelib::some_func()::some_other_function::<int, float, bool, bool, bool>().

The solution will work for now but there are a few things on my 'far future wish list':

  • A real specification somewhere, what language constructs are mapped to what DWARF structures.
  • Proper tests that directly compare the generated DWARF information to the expected results (possibly using something like pyelftools or llvm-dwarfdump)
  • A unified implementation for crate-local and crate-external items (which would possibly involve beefing up ast_map::path and metadata a bit)

Any comments are welcome!

Closes #1541
Closes #1542 (there might be other issues with function name prettiness, but this specific issue should be fixed)
Closes #7715 (source locations for structs and enums are now read correctly from the AST)

@jdm
Copy link
Contributor

jdm commented Sep 10, 2013

Woo! I'll review this today :)

@michaelwoerister
Copy link
Member Author

Great! By the way, I plan to liberally comment the whole of debuginfo.rs during the GSoC pencils down period, explaining in more detail the workings of the whole module and debug info in general. At the moment comments are a bit sparse in places.

@jdm
Copy link
Contributor

jdm commented Sep 11, 2013

Nice work. I'm ready to r+ this once we resolve my naming nit.

@michaelwoerister
Copy link
Member Author

Yeah, I had the same feeling about the name. NamespaceTreeNode is a bit verbose but easier to understand.

bors added a commit that referenced this pull request Sep 11, 2013
Who would have thought that namespaces are such a can of worms `:P` This is mostly because of some GDB idiosyncrasies (does not use namespace information but linkage-name attributes for displaying items contained in namespaces, also cannot handle functions lexically nested within functions), monomorphization, and information about external items only available from metadata.

This pull request tries to tackle the problem anyway:
* The `DW_AT_linkage_name` for functions is generated just to make GDB display a proper namespace-enabled function name. To this end, a pseudo-mangled name is generated, not corresponding to the real linkage name. This approach shows some success and could be extended to make GDB also show proper parameter types.
* As GDB won't accept subprogram DIEs nested within other subprogram DIEs, the `debuginfo` module now generates a *companion namespace* for each functions (iff needed). A function `fn abc()` will get a companion namespace with name `abc()`, which contains all items (modules, types, functions) declared within the functions scope. The real, proper solution, in my opinion, would be to faithfully reflect the program's lexical structure within DWARF (which allows arbitrary nesting of DIEs, afaik), but I am not sure LLVM's source level debugging implementation would like that and I am pretty sure GDB won't support this in the foreseeable future.
* Monomorphization leads to functions and companion namespaces like `somelib::some_func<int, float>()::some_other_function<bool, bool, bool>()`, which I think is the desired behaviour. There is some design space here, however. Maybe you people prefer `somelib::some_func()::some_other_function<bool, bool, bool>()` or `somelib::some_func()::some_other_function::<int, float, bool, bool, bool>()`.

The solution will work for now but there are a few things on my 'far future wish list':
* A real specification somewhere, what language constructs are mapped to what DWARF structures.
* Proper tests that directly compare the generated DWARF information to the expected results (possibly using something like [pyelftools](https://github.com/eliben/pyelftools) or llvm-dwarfdump)
* A unified implementation for crate-local and crate-external items (which would possibly involve beefing up `ast_map::path` and metadata a bit)

Any comments are welcome!

Closes #1541
Closes #1542 (there might be other issues with function name prettiness, but this specific issue should be fixed)
Closes #7715 (source locations for structs and enums are now read correctly from the AST)
@bors bors closed this Sep 11, 2013
@michaelwoerister michaelwoerister deleted the namespaces branch February 7, 2022 09:28
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 18, 2022
…n-some, r=flip1995

Extend unnecessary_lazy_eval to cover `bool::then` -> `bool::then_some`

fixes rust-lang#9097

changelog: Extend `unnecessary_lazy_eval` to convert `bool::then` to `bool::then_some`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants