Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Commits on Dec 1, 2023

  1. cli: Add a command system

    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>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    5b25c56 View commit details
    Browse the repository at this point in the history
  2. 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>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    16450b2 View commit details
    Browse the repository at this point in the history
  3. Add eval_typed_expression()

    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>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    a859b39 View commit details
    Browse the repository at this point in the history
  4. 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>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    b8b7f5e View commit details
    Browse the repository at this point in the history
  5. doc: Properly document the CLI command feature

    Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    1338a08 View commit details
    Browse the repository at this point in the history
  6. cli: load drgn commands using drgn.command.v1 entry point

    Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    8b31350 View commit details
    Browse the repository at this point in the history
  7. contrib: Add command support to ptdrgn.py

    Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
    brenns10 committed Dec 1, 2023
    Configuration menu
    Copy the full SHA
    3809cd2 View commit details
    Browse the repository at this point in the history