-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
commands.py
134 lines (104 loc) · 3.88 KB
/
commands.py
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
# -*- coding: utf-8 -*-
#
# gdb-frontend is a easy, flexible and extensionable gui debugger
#
# https://github.com/rohanrhu/gdb-frontend
# https://oguzhaneroglu.com/projects/gdb-frontend/
#
# Licensed under GNU/GPLv3
# Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) <[email protected]>
import sys
import importlib
import json
gdb = importlib.import_module("gdb")
import config
import plugin
import api.globalvars
class GDBFrontendLoadPluginPrefixCommand(gdb.Command):
"Loads GDBFrontend plugin."
def __init__(self):
super(GDBFrontendLoadPluginPrefixCommand, self).__init__ (
"gf-load-plugin",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE,
True
)
def invoke(self, plugin_name, from_tty):
if not plugin.load(plugin_name):
print("Plugin not found:", plugin_name)
GDBFrontendLoadPluginPrefixCommand()
class GDBFrontendUnloadPluginPrefixCommand(gdb.Command):
"Unloads GDBFrontend plugin."
def __init__(self):
super(GDBFrontendUnloadPluginPrefixCommand, self).__init__ (
"gf-unload-plugin",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE,
True
)
def invoke(self, plugin_name, from_tty):
if not plugin.unload(plugin_name):
print("Plugin is already not loaded:", plugin_name)
GDBFrontendUnloadPluginPrefixCommand()
class GDBFrontendListPluginsPrefixCommand(gdb.Command):
"Lists all GDBFrontend plugins in the plugin directory."
def __init__(self):
super(GDBFrontendListPluginsPrefixCommand, self).__init__ (
"gf-list-plugins",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE,
True
)
def invoke(self, args, from_tty):
for _plugin_name in plugin.getAll():
_plugin = plugin.getPlugin(_plugin_name)
sys.stdout.write(_plugin_name)
sys.stdout.write(" - ")
if _plugin:
sys.stdout.write("Enabled")
else:
sys.stdout.write("Disabled")
sys.stdout.write("\n")
GDBFrontendListPluginsPrefixCommand()
class GDBFrontendRefreshPrefixCommand(gdb.Command):
"Refreshes all browser clients."
def __init__(self):
super(GDBFrontendRefreshPrefixCommand, self).__init__ (
"gf-refresh",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE,
True
)
def invoke(self, arg, from_tty):
if api.globalvars.httpServer:
for client in api.globalvars.httpServer.ws_clients:
client.wsSend(json.dumps({
"event": "refresh"
}))
GDBFrontendRefreshPrefixCommand()
class GDBFrontendThemePrefixCommand(gdb.Command):
"Switch to desired theme."
def __init__(self):
super(GDBFrontendThemePrefixCommand, self).__init__ (
"gf-theme",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE,
True
)
def invoke(self, theme_name, from_tty):
if not theme_name:
theme_name = "default"
if not theme_name.startswith("theme_"):
theme_name = "theme_" + theme_name
for _plugin_name in list(plugin.plugins.keys()).copy():
if _plugin_name.startswith("theme_"):
plugin.unload(_plugin_name)
if theme_name and theme_name != "theme_default":
if not plugin.load(theme_name):
print("Plugin not found:", theme_name)
if api.globalvars.httpServer:
for client in api.globalvars.httpServer.ws_clients:
client.wsSend(json.dumps({
"event": "refresh"
}))
GDBFrontendThemePrefixCommand()