-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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 zdebuglog for basic debug logging and profiling #1544
Open
belak
wants to merge
3
commits into
master
Choose a base branch
from
belak/zdebuglog
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I <3
zstyle
we need more of those (python humor)Nonetheless there is an
zsh
idiomatic way of achieving this. (perhaps the way it works makes other debugging features harder to implement? depends on your implementation details).My suggestion is to use a
TRAPNAL
function or define atrap
-list with thetrap
builtin. ether theTRAPNAL
function or the builtin trap are set to be triggered uponSIGDEBUG
emission, which happens before command execution by default. if youunsetopt DEBUG_BEFORE_COMMAND
thenSIGDEBUG
is emitted after command execution. It's like a hook function, but awesome-erthe difference between a
TRAPNAL
function and atrap
builtin-defned list is that functions are executed with their own context independent context whiletrap
lists are "injected" to the calling command's context, soalso,
TRAPDEBUG
functions have an internal parameterZSH_DEBUG_CMD
automagically available inside them, and it is set to the string representation of the next command to be executed vis a vis the one being debugged after all. This allows for interesting stuff happening in logs, for example via plainsyslog
and a more interestingzstyle
set to an array of commands we are interested in profiling instead of just a boolean (overkill perhaps) it could look something like this:You can go crazy there and do even counterintuitive stuff, such as skipping the execution o the next command when certain conditions are met, besides membership to the
zstyle
array. It' perhaps an elegant solution to instrumentate THE WHOLE SHELL in just a few lines of code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my initial experiments with TRAPDEBUG (and TRAP 'do_stuff' DEBUG, you don't get the function calls in ZSH_DEBUG_CMD, you get the function body, so while this would be much more flexible, it also doesn't quite do what I want.