demangled characters like { make debugging annoying

96a6171
Opened by m4b at 2023-04-05 17:45:48

(in gdb at least)

I think I complained to @tromey about this already and he proposed a solution, but I'm finding this more and more annoying when debugging that the '{' was chosen demangle to, for closures and impls, e.g.:

_ZN4clap4args3arg3Arg5short28_$u7b$$u7b$closure$u7d$$u7d$17h7c4595ce99cae01bE

demangles to:

clap::args::arg::Arg::short::{{closure}}::h7c4595ce99cae01b

as it breaks gdb's symbol auto-complete, it's hard to set a breakpoint, print the type, etc.

As I mentioned, I think @tromey suggested how to fix this with certain gdb expressions, or some work around, but I've already forgotten and maybe we should just make it demangle to something different ? :angel:

  1. See also issue #32925. In some cases the linkage name in the debuginfo disagrees with the actual linkage name.

    For impls I think a more comprehensive DWARF emission approach is needed. A few of us have a google doc on this topic but most of it hasn't been turned into bugs or an RFC or whatever yet.

    I haven't given the naming of closures any thought. It's important, though, to separate what is put into the mangled name and what sort of information is emitted in the debuginfo.

    For breakpoints, break file:line is the usual workaround. For printing types and whatnot, I'm not sure, I think it's just a pain.

    Tom Tromey at 2016-11-08 14:43:36

  2. I think we could switch from {{closure}} to something like ___closure without breaking anything.

    Is there a character that cannot be part of a valid Rust identifier but works with GDB's about-completion? $ or # maybe?

    Michael Woerister at 2016-11-08 16:43:13

  3. @tromey would know better than me.

    Just to be clear, I like the brackets around closures, it's just they don't play nice. __ seems ugly to me, but will do if all else fails. I like idea of different char for bracket that plays nice. I wonder if | will work (also it evokes closures, but I digress)?

    m4b at 2016-11-08 22:50:44

  4. Can square brackets or angle brackets be used?

    mark at 2016-12-17 01:15:11

  5. FWIW I now tend to think this is just a bug in gdb (and lldb) and should be filed there instead. (The bugs about things like { appearing in the linkage name, though, are rustc bugs.)

    In gdb there are two ways to refer to items.

    One is "linespecs", which is the syntax you use for break and some other commands like that. If linespecs don't support the {{closure}} syntax, then we can fix that. There's already a gdb bug open to remind me to look into this someday. Putting quotes around the name should already work.

    The other way to refer to items is via expressions. It's normal in gdb to add a language extension to let one refer to unusual names this way -- for C this is done using single quotes. Perhaps that would work ok for rust as well.

    For lldb I'm less sure about the linespec equivalent, but we do completely control the expression parser at least, and can make it work however we like.

    Tom Tromey at 2018-12-12 18:05:02

  6. This is still an issue and I’m still not able to print things or break on them with {{ with quotes, single quotes, without, etc.

    Alternatively quoting demangled cpp names works as expected.

    Since I filed this 2 years ago and no action has been taken to fix it in gdb can we just not emit these symbols in rustc ?

    m4b at 2018-12-13 01:51:29

  7. Discussed in wg-debugging triage

    We propose that a community member should file a compiler MCP here, suggesting that we change the choice of symbol name to better accommodate this scenario.

    @wesleywiser says that *-windows-msvc targets already adopt $ for similar reasons. (But they also say that users complain about symbols being ugly on windows, so those people might see $ as a step in the wrong direction here.)

    Felix S Klock II at 2022-09-19 14:53:56