-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
compile time function to generate line number information for debugging #577
Comments
File/line information should be also part of test metadata available for the test runner, as suggested in #567. |
For the C allocator I designed every alloc/free function automatically and invisibly passes down In similar way, when I create some important object (say an associative array), it has field with file/line where it was constructed. It turned out not to be especially useful (VC++ debugger is enough for my needs) and serves mostly as assurance that if things go really bad there will be at least something to get a clue. [I also experimented to store full stack trace instead of single file/line. It is relatively easy (with the help of Win32), but eventually I decided it has too low value for its performance impact.] If Zig acquires such feature it should be:
As an idea for (1): if inside a function there's assignement |
Support for other debugging metadata may be also considered. Apart of file/line and stack trace there could be:
Support could mean keeping syntactic noise low when the feature is used. In C it gets ugly very fast:
|
There is a better way to do this, which is with @returnAddress. Put it in a function like this: noinline fn lineInfo() usize {
return @returnAddress();
} This depends on #640. This gives you a This is the Zig way to do this. Although |
@andrewrk if that's the case, then there should be a way to look up debug information for the running binary (which may obviously be unavailable). |
@daurnimator there is- that's how stack traces work in Zig. If one chooses to make debug info unavailable (or available but on a different server, etc), they have decided that they want a leaner binary without the debug info. And so not having |
What is the function(s) in the std library for it?
Yeah it makes sense to me. |
look around here: Line 174 in c58b802
|
So really, this issue can be solved with: fn getLineNumber() !usize {
const address = @returnAddress();
const di = try getSelfDebugInfo();
const cu = try findCompileUnit(di, address);
// TODO: dispatch to correct getLinuxNumberInfo
return try getLineNumberInfoDwarf(di, cu.*, address);
}
fn main() !void {
const currentline = (try getLineNumber()).line;
} I think this issue could be reopened as a feature request to add a similar function to the standard library. |
This has been re-opened for consideration in #2029 |
Update? |
this was added as https://ziglang.org/documentation/master/#src |
To help with debugging, it would be very useful to have a function that reports line information.
For example, have a function
@lineinfo()
which could return something like a struct{ filename: []const u8, line: u64 }
or something like that.The text was updated successfully, but these errors were encountered: