-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add a new func_trace builtin #125
base: add-function-trace
Are you sure you want to change the base?
Add a new func_trace builtin #125
Conversation
In which I cannibalize func_error and func_strip into a new func_trace builtin used as `$(trace ...)`. This is used similar to tracing function in functional programming languages: they both print (like `$(info ...)`) and return their argument. A test run during development looked like: ``` $ nix-shell -I nixpkgs=channel:nixos-unstable -p gdb '((enableDebugging remake).overrideAttrs (o: { patches = [ ./trace.patch ]; NIX_CFLAGS_COMPILE="-O0"; }))' git \ --run 'env -i SHELL=bash TERM=screen $(which gdb) $(which remake) -q -ex "b func_call" -ex "directory /remake/src" -ex "dis" -ex "r -X < <(echo -e \"expand \\\$(trace somestring)\\nq\")" -ex "q"' /nix/store/wvr3sj436yjla36i0fgrwpi6cpbx5rax-gdb-10.2/bin/gdb: warning: Couldn't determine a path for the index cache directory. Reading symbols from /nix/store/a68rnl52gqg2kfsk0bi9jxz1pbjfqr1s-remake-4.3+dbg-1.5/bin/remake... Breakpoint 1 at 0x418c24: file src/function.c, line 2428. Source directories searched: /remake/src:$cdir:$cwd Starting program: /nix/store/a68rnl52gqg2kfsk0bi9jxz1pbjfqr1s-remake-4.3+dbg-1.5/bin/remake -X < <(echo -e "expand \$(trace somestring)\nq") Reading makefiles... hello Updating makefiles... Updating goal targets... File 'all' does not exist. Must remake target 'all'. Successfully remade target file 'all'. <- (/tmp/tmp.h4PduA6Uid/Makefile:12) all remake<0> expand $(trace somestring) somestring somestring remake<1> q remake: That's all, folks... [Inferior 1 (process 30082) exited with code 0115] ```
Usage example:
|
In theory, I think this is great idea and would like to see it pursued. The implementation here I don't see as being complete or that helpful: I have to rewrite my entire source to be able to use this. And if a function calls another function, I have to wrap those as well. Probably better is a way to have each function (or a set of listed functions) traced showing arguments. |
If I understood you correctly, yes this is how these kinds of functions are supposed to work, you just wrap them around individual points of interest. I've now x-linked this to the originating issue #124 . Another part of the rationale is that it's composable and can be used in "any" situation. This does not necessarily preclude implementing something like what you said, I think they are somewhat orthogonal implementation-wise. With that said, I'm nowhere near an experienced make user and I'm not able to judge if this generally has the desired semantics, nor am I able to give users advice about using this new primitive in weird make syntax cases. Also I think some of your message got cut off? Also, this isn't in any way remake specific, so it could in theory be upstreamed, but I don't really want to figure out how to deal with that right now. It seems easier here. |
I suspect this might be doable in GNU Make using the existing set of functions.
The fragmentary stuff is removed now.
Sure, that makes sense. But still, what you are doing has to make sense and have some value, and I am not convinced right now. So maybe this should hang out until a more convincing use case is at hand. If you use this to debug something you are doing, describe how this helped. |
Well, I don't see any other way to look at expansions other than doing something like this, and it's nicer than If this isn't enough, I don't really know how to convince you.
|
|
Third attempt. I'm learning; How do you figure why this doesn't do anything?
I was looking at this code because it didn't do anything. I don't actually expect you to accept the code here, there aren't even tests (I don't know if there even are tests) or documentation included in this patch, but I do believe the idea has merit. [1] specifically, the problem is that I accidentally used |
TODO:
results in:
I'm not sure if that comment issue is normal macro behavior. Trace should have a prefix and line information or something; it's hard or impossible to tell if you're tracing an empty value |
In which I cannibalize func_error and func_strip into a new func_trace builtin used as
$(trace ...)
.This is used similar to tracing function in functional programming languages: they both print (like
$(info ...)
)and return their argument.
A test run during development looked like: