Skip to content

Commit 1c66201

Browse files
minor cleanup
python filename bug fix attempt debug console inject
1 parent a80400b commit 1c66201

File tree

4 files changed

+47
-50
lines changed

4 files changed

+47
-50
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"out": true // set this to false to include "out" folder in search results
88
},
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off"
10+
"typescript.tsc.autoDetect": "off",
11+
"cmake.configureOnOpen": false
1112
}

main.py

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import json
44

55

6-
76
class gdbHandler():
87

9-
108
def __init__(self, fName, cName):
119
print("### initialising gdbHandler ###")
1210
self.fileName = fName
@@ -16,7 +14,7 @@ def __init__(self, fName, cName):
1614
self.currentStep = 0
1715
gdb.execute("file " + self.fileName)
1816
gdb.execute("set pagination off")
19-
gdb.execute("set style enabled off") # remove colors
17+
gdb.execute("set style enabled off") # remove colors
2018

2119
def getFrameAmount(self):
2220
num_frames = 0
@@ -48,7 +46,8 @@ def getLocals(self):
4846

4947
def getArgs(self):
5048
args = gdb.execute("info args", to_string=True)
51-
if args == "No arguments.\n": return
49+
if args == "No arguments.\n":
50+
return
5251
args = args.strip().split("\n")
5352
dic = {}
5453
for arg in args:
@@ -74,7 +73,8 @@ def analyzeLine(self):
7473
currentLine = currentFrame.find_sal().line
7574
currentLocals = self.getVars()
7675
currentFile = currentFrame.find_sal().symtab.filename
77-
currentLineStr = gdb.execute("frame ", to_string=True ).split("\n")[1].split("\t",1)[1].strip()
76+
currentLineStr = gdb.execute("frame ", to_string=True).split("\n")[
77+
1].split("\t", 1)[1].strip()
7878
currentStep = self.currentStep
7979

8080
gdb.execute("step")
@@ -93,27 +93,30 @@ def analyzeLine(self):
9393

9494
# came back from recursion or just steped on new line
9595
# find diferences and save them
96-
self.saveAssiggnmentHistory(currentLine, currentLocals, currentLineStr, currentHeight, currentStep)
96+
self.saveAssiggnmentHistory(
97+
currentLine, currentLocals, currentLineStr, currentHeight, currentStep, currentFile)
9798

9899
# continue recurse
99100
self.analyzeLine()
100101

101-
def saveAssiggnmentHistory(self, line : int, oldlocals : dict, oldLineStr : str, stackHeight : int, currentStep : int):
102-
file = gdb.selected_frame().find_sal().symtab.filename
103-
oldLineStr = " "+oldLineStr # to exclude any " or '
102+
def saveAssiggnmentHistory(self, line: int, oldlocals: dict, oldLineStr: str, stackHeight: int, currentStep: int, file: str):
103+
oldLineStr = " "+oldLineStr # to exclude any " or '
104104
newLocals = self.getVars()
105-
if newLocals is None: return
105+
if newLocals is None:
106+
return
106107

107108
for key in newLocals:
108109
try:
109-
if oldlocals[key] != newLocals[key]: # found a difference, save it
110-
obj = {"line" : line, "value" : newLocals[key], "var": key, "file" : file, "stackHeight" : stackHeight, "step" : currentStep}
110+
if oldlocals[key] != newLocals[key]: # found a difference, save it
111+
obj = {"line": line, "value": newLocals[key], "var": key,
112+
"file": file, "stackHeight": stackHeight, "step": currentStep}
111113
self.history.append(obj)
112114
return
113115

114-
except: # means that a new var was added to the scope
116+
except: # means that a new var was added to the scope
115117
currentLine = gdb.selected_frame().find_sal().line
116-
obj = {"line" : currentLine, "value" : newLocals[key], "var": key, "file" : file, "stackHeight" : stackHeight, "step" : currentStep}
118+
obj = {"line": currentLine, "value": newLocals[key], "var": key,
119+
"file": file, "stackHeight": stackHeight, "step": currentStep}
117120

118121
# only accept the new var if it came from a for loop
119122
if self.findForLoop(key):
@@ -125,11 +128,13 @@ def saveAssiggnmentHistory(self, line : int, oldlocals : dict, oldLineStr : str,
125128
match = re.search(assignmentRegX, oldLineStr)
126129
if match:
127130
res = match.group(3).strip()
128-
obj = {"line" : line, "value" : oldlocals[res], "var": res, "file" : file, "stackHeight" : stackHeight, "step" : currentStep}
131+
obj = {"line": line, "value": oldlocals[res], "var": res,
132+
"file": file, "stackHeight": stackHeight, "step": currentStep}
129133
self.history.append(obj)
130134

131135
def findForLoop(self, var):
132-
currentLineStr = gdb.execute("frame ", to_string=True ).split("\n")[1].split("\t",1)[1].strip()
136+
currentLineStr = gdb.execute("frame ", to_string=True).split("\n")[
137+
1].split("\t", 1)[1].strip()
133138
for_regex = r"^(\s*)(for)(\s*)(\()([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\+\=|\-\=|\*\=|\/\=|\%\=|\=)(\s*)"
134139
match = re.search(for_regex, currentLineStr)
135140
if not match or match.group(5) != var:
@@ -141,9 +146,11 @@ def saveFunctionParams(self):
141146
file = gdb.selected_frame().find_sal().symtab.filename
142147
functionName = gdb.selected_frame().name()
143148
dic = self.getArgs()
144-
if dic is None: return
149+
if dic is None:
150+
return
145151

146-
obj = {"line" : line, "value" : dic, "file": file, "stackHeight" : self.getFrameAmount(), "stackName" : functionName, "step" : self.currentStep}
152+
obj = {"line": line, "value": dic, "file": file, "stackHeight": self.getFrameAmount(
153+
), "stackName": functionName, "step": self.currentStep}
147154
self.history.append(obj)
148155

149156

@@ -154,11 +161,12 @@ def __init__(self, stackName):
154161
self.values = []
155162

156163
def append(self, varObj, step, stackHeight):
157-
self.values.append({"dict": varObj, "stackHeight": stackHeight, "step": step})
164+
self.values.append(
165+
{"dict": varObj, "stackHeight": stackHeight, "step": step})
158166
# step is the first step in this function so it is incorrect, used for finding nearest step with <= step
159167

160168
def asSerial(self):
161-
return { "functionName": self.stackName, "values": self.values}
169+
return {"functionName": self.stackName, "values": self.values}
162170

163171

164172
class lineHistory():
@@ -170,7 +178,8 @@ def __init__(self, var):
170178
self.minValue = float("inf")
171179

172180
def append(self, value, step, stackHeight):
173-
self.values.append({"value": value, "step": step, "stackHeight": stackHeight})
181+
self.values.append({"value": value, "step": step,
182+
"stackHeight": stackHeight})
174183
value = value
175184
try:
176185
value = float(value)
@@ -180,15 +189,15 @@ def append(self, value, step, stackHeight):
180189
self.minValue = min(self.minValue, value)
181190

182191
def asSerial(self):
183-
self.maxValue = self.maxValue if self.maxValue > float("-inf") else None
192+
self.maxValue = self.maxValue if self.maxValue > float(
193+
"-inf") else None
184194
self.minValue = self.minValue if self.minValue < float("inf") else None
185-
return { "var": self.var, "values": self.values, "maxValue": self.maxValue, "minValue": self.minValue}
195+
return {"var": self.var, "values": self.values, "maxValue": self.maxValue, "minValue": self.minValue}
186196

187197

188198
class exeHistory():
189199
history = {}
190200

191-
192201
def append(self, obj):
193202
fileName = obj["file"]
194203
line = obj["line"]
@@ -198,47 +207,37 @@ def append(self, obj):
198207
stackHeight = obj["stackHeight"]
199208
stackName = obj["stackName"] if "stackName" in obj else None
200209

201-
if fileName not in self.history: # first time
210+
if fileName not in self.history: # first time
202211
self.history[fileName] = {}
203212

204-
if var is None: # args
205-
self.handleArgs(fileName, line, value, step, stackHeight, stackName)
206-
else: # line
213+
if var is None: # args
214+
self.handleArgs(fileName, line, value, step,
215+
stackHeight, stackName)
216+
else: # line
207217
self.handleLines(fileName, line, var, value, step, stackHeight)
208218

209219
def handleArgs(self, fileName, line, value, step, stackHeight, stackName):
210-
if line not in self.history[fileName]: # first time
220+
if line not in self.history[fileName]: # first time
211221
self.history[fileName][line] = argsHistory(stackName)
212222

213223
self.history[fileName][line].append(value, step, stackHeight)
214224

215225
def handleLines(self, fileName, line, var, value, step, stackHeight):
216-
if line not in self.history[fileName]: # first time
226+
if line not in self.history[fileName]: # first time
217227
self.history[fileName][line] = lineHistory(var)
218228

219229
self.history[fileName][line].append(value, step, stackHeight)
220230

221-
222231
def asSerial(self):
223232
return self.history
224233

225234

226-
227-
228-
229235
def serializer(obj):
230236
if hasattr(obj, "asSerial"):
231237
return obj.asSerial()
232238
return obj.__dict__
233239

234240

235-
236-
237-
238-
239-
240-
241-
242241
if __name__ == "__main__":
243242
gdbHandler = gdbHandler("a.out", "hello.c")
244243
gdb.execute("b main")
@@ -250,15 +249,8 @@ def serializer(obj):
250249
print(e)
251250
print("### end of program ###")
252251

253-
254252
print("### printing history ###")
255253
with open("history.json", "w") as f:
256254
json.dump(gdbHandler.history, f, indent=4, default=serializer)
257255

258-
259256
gdb.execute("quit")
260-
261-
262-
263-
264-

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ function getCSS(lineHeight: number): string {
7373
}
7474

7575

76+
7677
function webviewMessageHandler(message: any) {
7778
switch (message.command) {
7879
case "highlight-line":
7980
utils.changeHighlightedLine(message.id);
81+
const debugC = vscode.debug.activeDebugConsole;
82+
83+
if (!debugC) { break; }
84+
debugC.appendLine("-exec s");
8085
break;
8186
default:
8287
console.log("Unknown command: " + message.command);

src/webview/webview_script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ function removeAllBars() {
104104
});
105105
}
106106

107-
108107
function changeDivToBar(div, overlap) {
109108

110109

0 commit comments

Comments
 (0)