-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Location
is missing the function name
#95529
Comments
You shouldn't need to. You can use something like I wouldn't store the "function name" but rather the mangled symbol (frankly, ideally a For demangling, I don't think it would be a stretch to include |
Well, I'm no expert in compiler building, my focus is databases, so I'd prefer to leave the implementation to the compiler experts who know what they are doing :-). But sure, if there is a more efficient way, that's even better.
Yes, I'd personally also prefer the mangled symbol.
Mhm. A crazy idea: What about putting the names into a special ELF string section (not regular initialized data or debuginfo), so it could be trimmed, if needed (resulting in |
Sorry, what I should've said was that Ideas for Sadly custom debuginfo is pretty tricky in LLVM, otherwise that could be interesting to experiment with. |
We pretty much abandoned the idea of moving Backtrace into core, but maybe we could move just the functionality we need here into core? |
There is some previous discussion about getting the function name in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/macro.20for.20getting.20the.20function.20name/near/269583366 |
Piping in to say that I desire the exact same thing for the exact same use case (return-tracing powered by I also brought this up in an old zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/function.20names.20in.20.60.23.5Btrack_caller.5D.60 I am willing to work on the implementation of this if I get buy-in and a little bit of mentoring from somebody. We really desire this at my place of work and I'm on a team where I can dedicate work hours to doing this. |
@BGR360 Were you already able to work on the topic? We would like to use it as well (that's why I opened the issue), but I don't have anyone with the right skillset to implement it and/or help you with mentoring. The only help I can offer is what I found in rustc code (where the |
I do have a question if anyone can help me. I started out implementing this for the rustc_const_eval interpreter context, and leaving the function as But when I tried to test that, all the function names from Is there any way I can write a UI test that is guaranteed to go through the If so, I'll update the existing UI tests accordingly, cuz I assume we're missing out on code coverage for the |
That sounds right, IIRC You would need to add another argument to it, Either way, you'd have to pass that in to be able to add it to the Also, when used from a const context, miri definitely also has the same amount of information anyway, so the In terms of dealing with miri internals and other CTFE details, cc @oli-obk |
Oh, why's that? I was thinking of just using
Yeah I originally wanted to use
Yep, that's my plan. Do you think |
@BGR360 Were you able to make further progress on your implementation? I stumbled across this issue yesterday after working on my own error wrapper that collects the location of every construction/propagation. Could I help contribute to prototype an implementation? |
It would be good to profile the size cost of any implementation of this -- adding filename / line number already has a significant cost for embedded |
@hudson-ayers I agree with you that this may have significant costs. That's why I suggested some crazy ideas above. And yes, a flag to turn it off for users who don't need it also makes sense. Maybe one could use |
For our project, I implemented a version of
Result
which usesTry
trait in such a way as to track the error handling locations, so we get a "call stack" of the error at the end. This works in conjunction with#[track_caller]
very well and we see the locations the error handling took.However, there is one major deficiency in
Location
- it only gives us the source name and line. Yes, with that, it's possible to manually look up the function where it happened, but it would be significantly simpler to evaluate bug reports by looking at the call trace with function names (we have practiced this in a large C++ project, where basically the dev support standardized on initially evaluating everything by function names in the call trace, ignoring line numbers). So it would be extremely useful if theLocation
would be extended with another&str
containing the function name (ideally with generics). It can be also a mangled name, I don't care much, but the function name is important.Before you shout "backtrace!" - yes, but... We are using heavy asynchronous processing, handling errors across
await
s, where the backtrace has about zero value. Similar for tracing, we can't just keep the trace active permanently due to performance reasons. So the error handling "call stack" is a perfect compromise - cheap and sufficiently valuable (except that it's missing the function name).According to my code study of the Rust compiler code, it should basically boil down to getting the function name from the current
Span
and adding it in addition to the file name to the generated constLocation
here:rust/compiler/rustc_codegen_cranelift/src/common.rs
Line 351 in 012720f
I raised this initially in a comment in #47809. Here some observations from the discussion there:
To alleviate this, storing function name could be made optional at compilation time, e.g., using a compiler flag.
Of course, one could argue that this could be also done in post-processing of traced errors. Of course, that's a possibility. But that's another step, which makes it quite cumbersome to use and needs a lot of resources and exact source code. The compiler already knows it at compile time and aside from costing more space in the generated executable (string section), there should be no adverse effects of having the function name in the
Location
.Further, having the function name in
Location
, it would in general allow building various tools which use the location for debugging purposes, which in turn would help the community in general. So I think it's worth extending it.@anp, @eddyb & @aturon you seem to have worked on this topic recently, so CC to you.
The text was updated successfully, but these errors were encountered: