-
Notifications
You must be signed in to change notification settings - Fork 159
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
Commands - dot-prefixed, stdlib only #367
base: main
Are you sure you want to change the base?
Commits on Dec 1, 2023
-
As a debugger library, drgn can be a little bit verbose when running interactively. There has been general concensus that it would be nice to have a way to define shorthands for common operations, or define user scripts that are easy to run within the shell. However we have yet to settle upon a solution. Implementing a full CLI seems out of the scope of drgn. Leveraging the power of a system like IPython's "magic" commands is promising, but adds heavy dependencies. One example CLI to draw inspiration from is SQLite, which uses the "." prefix to define meta-commands that aren't part of the SQL language. Python, like SQL, cannot begin a statement with a ".", so it could be used to unambiguously signal that a command is being entered, and thanks to the code.InteractiveConsole, we can easily extend the console to handle these commands. So, let's add a command system. Commands are simply callables which take a program, the full line of text (which may contain arguments), and the CLI locals. They may return a Python object which is stored to `builtins._`. They can be registered using a decorator, and an API is available to retrieve the default list. The run_interactive() function allows the user to customize the available command list. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for 5b25c56 - Browse repository at this point
Copy the full SHA 5b25c56View commit details -
execscript: Allow setting the globals
The execscript() helper is intended to run from the CLI and access the calling scope's global variables. However, for CLI commands to use it, execscript() must optionally accept a global variable dict directly. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for 16450b2 - Browse repository at this point
Copy the full SHA 16450b2View commit details -
This helper allows users to evaluate very basic C expressions of the form "(type)int_literal". This enables users to more easily copy and paste printed results back into the console to get the corresponding object. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for a859b39 - Browse repository at this point
Copy the full SHA a859b39View commit details -
Add some built-in commands: x, contrib, and let
The "x" command is short for "eXecute" or execscript(). The "contrib" command is similar to "x", but runs scripts from the "contrib/" directory if it is present. The "let" command sets variables based on the typed expression. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for b8b7f5e - Browse repository at this point
Copy the full SHA b8b7f5eView commit details -
doc: Properly document the CLI command feature
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for 1338a08 - Browse repository at this point
Copy the full SHA 1338a08View commit details -
cli: load drgn commands using drgn.command.v1 entry point
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for 8b31350 - Browse repository at this point
Copy the full SHA 8b31350View commit details -
contrib: Add command support to ptdrgn.py
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Configuration menu - View commit details
-
Copy full SHA for 3809cd2 - Browse repository at this point
Copy the full SHA 3809cd2View commit details