Skip to content

Commit d27efd3

Browse files
authored
Add debugging instructions (#985)
Add debugging instructions: pycharm + pdb
1 parent 7c170cf commit d27efd3

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

docs/debugging.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Debugging
2+
3+
Debugging GEF has a trick, let's see some examples
4+
5+
## Debugging a command execution with pdb
6+
7+
Open gef.py
8+
9+
Search for **class NopCommand(GenericCommand)**, go to do_invoke method and insert:
10+
11+
```python
12+
import pdb; pdb.set_trace()
13+
```
14+
15+
Open a gdb session -> start -> nop
16+
17+
Done!
18+
19+
```bash
20+
gef➤ nop
21+
> /home/dreg/.gef-7c170cf6be3d84b2672a22e43b9128a23fe53c3b.py(6075)do_invoke()
22+
-> args : argparse.Namespace = kwargs["arguments"]
23+
(Pdb) ll
24+
6070 @only_if_gdb_running
25+
6071 @parse_arguments({"address": "$pc"}, {"--i": 1, "--b": True, "--f": True, "--n": True})
26+
6072 def do_invoke(self, _: List[str], **kwargs: Any) -> None:
27+
6073 import pdb; pdb.set_trace()
28+
6074
29+
6075 -> args : argparse.Namespace = kwargs["arguments"]
30+
6076 address = parse_address(args.address)
31+
```
32+
33+
Learn more about [pdb](https://docs.python.org/3/library/pdb.html)
34+
35+
## Debugging a command execution with pycharm
36+
37+
Install [pycharm](https://www.jetbrains.com/help/pycharm/installation-guide.html)
38+
39+
Create a new project:
40+
41+
![pycharm1](https://github.com/hugsy/gef/assets/9882181/600a9522-208a-4f2e-89b2-707136ba020a)
42+
43+
![pycharm2](https://github.com/hugsy/gef/assets/9882181/4cf51b17-6aa0-463f-b538-200dd9e9b5e6)
44+
45+
Go to menu -> Run -> Edit configurations...:
46+
47+
![pycharm3](https://github.com/hugsy/gef/assets/9882181/6fdacda8-c4cc-44e0-8fc1-3b18cf118fbe)
48+
49+
Create a Python Debug Server:
50+
51+
![pycharm4](https://github.com/hugsy/gef/assets/9882181/09f99b28-5716-48be-8a0c-8ed69920c4a0)
52+
53+
![pycharm5](https://github.com/hugsy/gef/assets/9882181/814fe019-c390-4ca3-8605-e3842be04df1)
54+
55+
Debug your new Unnamed:
56+
57+
![pycharm6](https://github.com/hugsy/gef/assets/9882181/f0f1eee9-fcaa-4919-8985-8d7d09907ebd)
58+
59+
![pycharm7](https://github.com/hugsy/gef/assets/9882181/039e8749-b949-49e8-917f-b592f9cf6dac)
60+
61+
Copy the info from output Window to gef.py:
62+
63+
![pycharm8](https://github.com/hugsy/gef/assets/9882181/be24ee23-3101-4b71-b62f-70883c9135ad)
64+
65+
First, add to gef.py:
66+
67+
```python
68+
import pydevd_pycharm
69+
```
70+
71+
Second, search for **class NopCommand(GenericCommand)**, go to do_invoke method and insert:
72+
73+
```python
74+
pydevd_pycharm.settrace('localhost', port=35747, stdoutToServer=True, stderrToServer=True)
75+
```
76+
77+
Open a gdb session -> start -> nop
78+
79+
Done!
80+
81+
![pycharm9](https://github.com/hugsy/gef/assets/9882181/b22ec431-57e7-442a-835e-5817bdac7687)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ nav:
2121
- Testing: testing.md
2222
- Write extensions: api.md
2323
- API: api/gef.md
24+
- Debugging: debugging.md
2425
- Coverage: https://hugsy.github.io/gef/coverage/
2526
- Commands:
2627
- aliases: commands/aliases.md

0 commit comments

Comments
 (0)