Skip to content

Commit d546f9b

Browse files
committed
✨ Support gdb
1 parent 33d1159 commit d546f9b

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
with:
7878
path: |
7979
dist/*
80-
- uses: softprops/action-gh-release@v1
80+
- uses: softprops/action-gh-release@v2
8181
if: runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/')
8282
with:
8383
# body_path: build/CHANGELOG.md

.pre-commit-config.yaml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exclude: ^templates/
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.5.0
6+
rev: v5.0.0
77
hooks:
88
- id: check-added-large-files
99
- id: fix-byte-order-marker
@@ -27,7 +27,7 @@ repos:
2727
hooks:
2828
- id: remove-crlf
2929
- repo: https://github.com/codespell-project/codespell
30-
rev: v2.2.6
30+
rev: v2.4.1
3131
hooks:
3232
- id: codespell
3333
additional_dependencies:
@@ -39,23 +39,23 @@ repos:
3939
args:
4040
- --msg-filename
4141
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
42-
rev: 2.7.3
42+
rev: 3.2.1
4343
hooks:
4444
- id: editorconfig-checker
4545
- repo: https://github.com/jumanjihouse/pre-commit-hooks
4646
rev: 3.0.0
4747
hooks:
4848
- id: check-mailmap
4949
- repo: https://github.com/rhysd/actionlint
50-
rev: v1.6.27
50+
rev: v1.7.7
5151
hooks:
5252
- id: actionlint
5353
- repo: https://github.com/adrienverge/yamllint
54-
rev: v1.35.1
54+
rev: v1.37.1
5555
hooks:
5656
- id: yamllint
5757
- repo: https://github.com/executablebooks/mdformat
58-
rev: 0.7.17
58+
rev: 0.7.22
5959
hooks:
6060
- id: mdformat
6161
additional_dependencies:
@@ -64,12 +64,12 @@ repos:
6464
- mdformat-myst
6565
- mdformat-toc
6666
- mdformat-deflist
67-
- mdformat-beautysh
67+
# - mdformat-beautysh
6868
- mdformat-ruff
6969
- mdformat-config
7070
- mdformat-web
7171
- repo: https://github.com/DavidAnson/markdownlint-cli2
72-
rev: v0.12.1
72+
rev: v0.18.1
7373
hooks:
7474
- id: markdownlint-cli2
7575
additional_dependencies:
@@ -80,18 +80,14 @@ repos:
8080
- id: update-CITATION.cff
8181
- id: update-pyproject.toml
8282
- repo: https://github.com/astral-sh/ruff-pre-commit
83-
rev: v0.2.1
83+
rev: v0.11.13
8484
hooks:
8585
- id: ruff
8686
- id: ruff-format
8787
- repo: https://github.com/kumaraditya303/mirrors-pyright
88-
rev: v1.1.350
88+
rev: v1.1.401
8989
hooks:
9090
- id: pyright
91-
- repo: https://github.com/nix-community/nixpkgs-fmt
92-
rev: v1.3.0
93-
hooks:
94-
- id: nixpkgs-fmt
9591

9692
ci:
9793
skip:

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
Python REPL plugin for automatic time tracking and metrics generated from your
4040
programming activity.
4141

42-
![screenshot](https://github.com/wakatime/repl-python-wakatime/assets/32936898/d0ac2fab-f9c2-4213-99e3-4249279b1213)
42+
![screenshot](https://github.com/user-attachments/assets/b745d591-60ac-462e-9485-1828914706a1)
4343

4444
Supported REPLs:
4545

@@ -81,6 +81,23 @@ from repl_python_wakatime.iptpython import install_hook
8181
install_hook(c)
8282
```
8383

84+
- [x] [gdb](https://sourceware.org/gdb/):
85+
86+
Your `gdb` must be compiled with
87+
[python port](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Python.html).
88+
89+
`~/.config/gdb/gdbinit`:
90+
91+
```gdb
92+
source /the/path/of/repl_python_wakatime/gdb.py
93+
```
94+
95+
See [GDB Hooks](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Hooks.html)
96+
to know more.
97+
98+
Use environment variables `HOOK_NAMES=hook1:hook2` to defines which
99+
[hook](#configure) will be used.
100+
84101
- [x] [ptipython](https://github.com/prompt-toolkit/ptpython): Same as
85102
[ipython](https://github.com/ipython/ipython).
86103
- [ ] [bpython](https://github.com/bpython/bpython)
@@ -109,14 +126,6 @@ REPLs are similar. Currently, `hook_function` can be:
109126
- [rescuetime](https://www.rescuetime.com/)
110127
- ...
111128

112-
## Related programs
113-
114-
Some programs is written in python or providing a python port.
115-
We can use this project to statistic their time:
116-
117-
- [gdb](https://sourceware.org/gdb): See
118-
[here](https://github.com/Freed-Wu/gdb-prompt)
119-
120129
## Similar projects
121130

122131
- [wakatime plugins for python and many shells](https://wakatime.com/terminal)

src/repl_python_wakatime/gdb.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
r"""GDB hook
2+
============
3+
4+
Record your debug time to use gdb in wakatime.
5+
"""
6+
7+
import os
8+
9+
import gdb # type: ignore
10+
11+
hook_names = os.getenv("HOOK_NAMES", "wakatime")
12+
13+
for hook_name in hook_names.split(":"):
14+
if hook_name == "wakatime":
15+
from repl_python_wakatime.hooks.wakatime import wakatime_hook as hook
16+
elif hook_name == "codestats":
17+
from repl_python_wakatime.hooks.codestats import codestats_hook as hook
18+
else:
19+
raise NotImplementedError
20+
21+
22+
class StopHook:
23+
def __init__(self):
24+
gdb.events.stop.connect(self.handler)
25+
26+
def handler(self, event):
27+
hook(plugin="repl-gdb-wakatime", language="gdb", category="debugging")
28+
29+
30+
StopHook()

tests/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import pytest
6+
67
from repl_python_wakatime.hooks.codestats import CodeStats
78
from repl_python_wakatime.utils.api import get_api_key
89

0 commit comments

Comments
 (0)