-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.tgdbinit
201 lines (159 loc) · 6.14 KB
/
.tgdbinit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#ARCHIVO MODIFICADO DEL ORIGINAL OBTENIDO EN
#https://github.com/ficoos/tgdbdb/tree/master
#A este archivo renómbrenlo como .tgdbinit y lo pueden usar en lugar del original.
python
import subprocess as sp
class Pane():
class SplitDir():
HORIZONTAL_RIGHT = '-h'
HORIZONTAL_LEFT = '-hb'
VERTICAL_ABOVE = '-vb'
VERTICAL_BELOW = '-v'
class ResizeDir():
RIGHT = '-R'
LEFT = '-L'
UP = '-U'
DOWN = '-D'
def __init__(self, id: str, tty: str, module_name: str):
self.id = id
self.tty = tty
self.module_name = module_name
if module_name == 'dashboard':
self.add_extra_module('')
elif module_name != 'gdb':
self.add_extra_module(module_name)
def set_title(self):
with open(self.tty, 'ab') as t:
t.write(b'\x1b]2;' + self.module_name.encode('utf8') + b'\x1b\\')
def split(self, dir = SplitDir.VERTICAL_ABOVE, percentage = 50, module_name = ''):
NULLPROG = "sh -c 'while [ 1 = 1 ]; do sleep 100; done'"
id, tty = Pane.tmux('split-window', '-l', f"{percentage}", '-t', self.id, '-d', dir,
'-P', '-F', '#{pane_id},#{pane_tty}', NULLPROG)
# self.check()
return Pane(id, tty, module_name)
def splitResizeCurrent(self, dir = SplitDir.VERTICAL_ABOVE, percentage = 50, module_name = ''):
NULLPROG = "sh -c 'while [ 1 = 1 ]; do sleep 100; done'"
id, tty = Pane.tmux('split-window', '-l', '9999', '-t', self.id, '-d', dir,
'-P', '-F', '#{pane_id},#{pane_tty}', NULLPROG)
Pane.tmux('select-pane', '-t', self.id)
Pane.tmux('resize-pane', '-D', f"{percentage}")
# self.check()
return Pane(id, tty, module_name)
# def set_dashboard(self):
# gdb.execute(f'dashboard -output {self.tty}')
def add_extra_module(self, module_name: str):
gdb.execute(f'dashboard {module_name} -output {self.tty}')
def check(self):
sp.check_call(['stty', '--file', self.tty, '-echo'])
@staticmethod
def tmux(*args):
return sp.check_output(['tmux'] + list(args)).decode('utf8').strip().split(',')
def __str__(self) -> str:
return f"{self.module_name}: {{ id: {self.id}, tty: {self.tty} }}"
class Window(Pane):
def __init__(self, module_name: str):
id, tty = Window.create_window()
Pane.__init__(self, id, tty, module_name)
self.set_title()
@staticmethod
def create_window():
Pane.tmux('setw', 'remain-on-exit', 'on')
return Pane.tmux('display-message', '-p' , '-F', '#{pane_index},#{pane_tty}')
################### Layout ####################
# ---------------------------------------------
# | | | |
# | | | Memory |
# | GDB | Registers | |
# | | |----------|
# | | | |
# |--------------------------------| |
# | | | |
# | | | Stack |
# | Source | Assembly | |
# | | | |
# | | | |
# | | | |
# ---------------------------------------------
gdb_window = Window('gdb')
# Tamano ideal 64bits = 60 columnas
stack_pane = gdb_window.split(
dir=Pane.SplitDir.HORIZONTAL_RIGHT,
percentage='60',
module_name='stackmemory'
)
stack_pane.add_extra_module('breakpoints')
# Tamano preferido lineas para zona memoria = 15 lineas
memory_pane = stack_pane.split(
dir=Pane.SplitDir.VERTICAL_ABOVE,
percentage=15,
module_name='memory'
)
memory_pane.add_extra_module('threads')
source_pane = gdb_window.splitResizeCurrent(
dir=Pane.SplitDir.VERTICAL_BELOW,
percentage=19,
module_name='source'
)
# dashboard_pane.set_dashboard()
source_pane.add_extra_module('variables')
# Tamano ideal 64bits = 82 columnas
registers_pane = gdb_window.split(
dir=Pane.SplitDir.HORIZONTAL_RIGHT,
percentage=82,
module_name='registers'
)
registers_pane.add_extra_module('history')
registers_pane.add_extra_module('expressions')
# Tamano ideal 64bits = 55 columnas (al menos)
assembly_pane = source_pane.split(
dir=Pane.SplitDir.HORIZONTAL_RIGHT,
percentage=55,
module_name='assembly'
)
#configuraciones que quiero tener siempre
gdb.execute(f'dashboard memory -style full True')
gdb.execute(f'dashboard registers -style column-major True')
gdb.execute(f'dashboard source -style height 0')
gdb.execute(f'dashboard assembly -style height 0')
gdb.execute(f'dashboard source -style highlight-line True')
gdb.execute(f'dashboard assembly -style highlight-line True')
#gdb.execute(f'set debuginfod enabled on')
gdb.execute(f'set disassembly-flavor intel')
# Disable unwanted sections
gdb.execute(f'dashboard breakpoints')
gdb.execute(f'dashboard threads')
# gdb.execute(f'dashboard variables')
gdb.execute(f'dashboard history')
gdb.execute(f'dashboard stack')
# para debug docker
# set debuginfod enabled off
gdb.execute(f'target remote 10.2.69.203')
gdb.execute(f"dashboard registers -style list 'rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15 rip eflags cs ss ds es fs gs fs_base gs_base k_gs_base cr0 cr2 cr3 cr4 cr8 efer'")
# Antes que los add-symbol-file, en caso de que falle alguno de los dos, alcance a setear el dir.
gdb.execute(f'set dir Kernel:Userland:Userland/SampleCodeModule')
gdb.execute(f'add-symbol-file Kernel/kernel.elf 0x100000')
gdb.execute(f'add-symbol-file Userland/0000-sampleCodeModule.elf 0x400000')
end
#dashboard -layout memory source assembly registers stack
dashboard -enabled on
dashboard -style syntax_highlighting 'monokai'
# make sure dashboard output is updated when gdb state changes
define hookpost-up
dashboard
end
define hookpost-down
dashboard
end
define hookpost-thread
dashboard
end
define hookpost-delete
dashboard
end
define hookpost-clear
dashboard
end
define hookpost-break
dashboard
end
# vim: set ft=python: