Skip to content

Commit

Permalink
LLDB dashboard (#9)
Browse files Browse the repository at this point in the history
* initial commit

* output and show commands

* fix pyright warnings

* save progress

* fix shellcheck warning

* add dashboard commands

* register module general purpose register display

* avx register display

* import dashboard
  • Loading branch information
JensDll committed Apr 29, 2024
1 parent 4d80800 commit 2e49d5d
Show file tree
Hide file tree
Showing 55 changed files with 1,641 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ cython_debug/

# Other stuff
.gdb_history
dev.gdb
gdbdash.json
.dash
*.gdb
*.lldb
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.17
3.10.12
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"shellcheck.useWorkspaceRootAsCwd": true
}
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
# https://microsoft.github.io/pyright/#/configuration?id=main-configuration-options
include = ['unix', 'windows', 'misc', 'scripts']
exclude = ['**/__pycache__']
ignore = ['gdb']
pythonVersion = '3.8'

[tool.black]
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#t-target-version
target-version = ['py38']

[tool.isort]
# https://pycqa.github.io/isort/docs/configuration/options.html#python-version
py_version = 38
# https://pycqa.github.io/isort/docs/configuration/options.html#profile
profile = 'black'
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
black==23.7.0
pyright==1.1.324
isort==5.12.0
black==24.3.0
pyright==1.1.359
isort==5.13.2
24 changes: 24 additions & 0 deletions scripts/create_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

root="$(
cd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null 2>&1 || exit
pwd -P
)"
declare -r root
declare -r unix="$root/unix"

shopt -s expand_aliases

# shellcheck source=./unix/.bash_aliases
source "$unix/.bash_aliases"

pushd "$root" > /dev/null || exit

python -m venv .venv

ln --symbolic --force "$(lldb -P)"/lldb ./.venv/lib/python*/site-packages
if [[ $(gdb --eval-command 'show data-directory' --batch) =~ \"(.*)\" ]]; then
ln --symbolic --force "${BASH_REMATCH[1]}"/python/gdb ./.venv/lib/python*/site-packages
fi

popd > /dev/null || exit
11 changes: 0 additions & 11 deletions scripts/dev.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ root="$(
declare -r root
declare -r unix="$root/unix"

shellcheck --external-sources "$root"/**/*.sh "$unix"/.local/bin/* "$unix"/.local/share/bash-completion/completions/* \
shellcheck "$root"/**/*.sh "$unix"/.local/bin/* "$unix"/.local/share/bash-completion/completions/* \
"$unix/.bash_aliases" "$unix/.bash_logout" "$unix/.bashrc" "$unix/.profile"
16 changes: 16 additions & 0 deletions unix/.bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo
# https://manpages.debian.org/date
alias today='date +%d.%m.%y'

for i in {15..25}; do
if [[ $(type -t lldb-"$i") = file ]]; then
# shellcheck disable=SC2139
# https://lldb.llvm.org/index.html
alias lldb="lldb-$i"
break
fi
done

# https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#index-type

if [[ $(type -t kubectl) = file ]]; then
Expand All @@ -53,3 +62,10 @@ fi
if [[ $(type -t pip) = file ]]; then
source <(pip completion --bash)
fi

if [[ $(type -t pnpm) = file ]]; then
source <(pnpm completion bash)
if [[ $(type -t _pnpm_completion) = function ]]; then
complete -F _pnpm_completion pnpm
fi
fi
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gdb # pyright: ignore [reportMissingModuleSource]
import gdb

from .dashboard import Dashboard

Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gdb # pyright: ignore [reportMissingModuleSource]
import gdb


class Command:
Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/command.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Command:
): ...
def dont_repeat(self) -> None: ...
def invoke(self, arg: str, from_tty: bool) -> None: ...
def complete(self, text: str, word: str) -> None: ...
def complete(self, text: str, word: str) -> object: ...
def write(self, message: str, fileno: int) -> None: ...
def stdout(self, message: str) -> None: ...
def stderr(self, message: str) -> None: ...
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Sequence

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.utils import GdbBool, GdbInt, complete

from .command import Command
Expand Down
9 changes: 5 additions & 4 deletions unix/.config/gdbdash/gdbdash/commands/configure.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass
from typing import Mapping, Protocol, Sequence
from functools import cached_property
from typing import Any, Mapping, Protocol, Sequence

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.utils import GdbBool, GdbInt

from .command import CommandProtocol
Expand All @@ -26,13 +27,13 @@ class StrOption:
choices: int = gdb.COMPLETE_NONE

Option = BoolOption | IntOption | StrOption
Options = Mapping[str, Option]
Options = Mapping[str, Any]

class ConfigurableProtocol(CommandProtocol, Protocol):
options: Options

class Configurable(metaclass=ABCMeta):
def __init__(self, /, **kwargs) -> None: ...
@property
@cached_property
@abstractmethod
def options(self) -> Options: ...
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/dump.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb

from .command import Command
from .configure import Configurable
Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/enable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.utils import GdbBool, complete

from .command import Command
Expand Down
3 changes: 1 addition & 2 deletions unix/.config/gdbdash/gdbdash/commands/order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb

from .command import Command

Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/commands/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb

from .command import Command

Expand Down
9 changes: 4 additions & 5 deletions unix/.config/gdbdash/gdbdash/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os import get_terminal_size
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
import gdbdash.modules
import gdbdash.utils
from gdbdash.commands import (
Expand All @@ -22,7 +22,6 @@
if TYPE_CHECKING:
from typing import Iterator

from gdb.events import StopEvent # pyright: ignore [reportMissingModuleSource]
from gdbdash.utils import FileDescriptorOrPath

from .dashboard import DashboardModulesDict, DashboardOptions
Expand Down Expand Up @@ -117,7 +116,7 @@ def render_file(
module.divider(width, height, write)
module.render(width, height, write)

def on_stop_handler(self, event): # type: (StopEvent) -> None
def on_stop_handler(self, event):
self.render()

def on_output_changed(self, old_output):
Expand Down Expand Up @@ -160,8 +159,8 @@ def dump(self, path):
with open(path, "w") as f:
json.dump(values, f, indent=2)

def load(self, path):
with open(path) as f:
def load(self, config_path):
with open(config_path) as f:
config = json.load(f)

json_dashboard = config["dashboard"]
Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/modules/alignment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import cached_property
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.commands import IntOption
from gdbdash.utils import RESET_COLOR, fetch_instructions, fetch_pc

Expand Down
4 changes: 2 additions & 2 deletions unix/.config/gdbdash/gdbdash/modules/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import cached_property
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.commands import BoolOption, IntOption
from gdbdash.utils import FONT_BOLD, RESET_COLOR, fetch_instructions, fetch_pc

Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self.fetch_new_instructions(self.frame)

def render(self, width, hight, write):
def render(self, width, height, write):
inferior = gdb.selected_inferior()
frame = gdb.selected_frame()
pc = fetch_pc(frame)
Expand Down
2 changes: 1 addition & 1 deletion unix/.config/gdbdash/gdbdash/modules/module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import abstractmethod
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.commands import Command, Configurable, Orderable, Outputable, Togglable
from gdbdash.utils import RESET_COLOR

Expand Down
4 changes: 2 additions & 2 deletions unix/.config/gdbdash/gdbdash/modules/registers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from functools import cached_property
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.commands import BoolOption

from .module import Module
from .register import (
from .registers_display import (
EflagsRegister,
GeneralPurposeRegister,
MxcsrRegister,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from typing import TYPE_CHECKING

import gdb # pyright: ignore [reportMissingModuleSource]
import gdb
from gdbdash.utils import FONT_UNDERLINE, RESET_COLOR

if TYPE_CHECKING:
from gdb import ( # pyright: ignore [reportMissingModuleSource]
RegisterDescriptor,
Type,
)
from gdb import RegisterDescriptor, Type
from gdbdash.dashboard import DashboardOptions


Expand Down
Loading

0 comments on commit 2e49d5d

Please sign in to comment.