Created
April 20, 2023 12:52
-
-
Save fernandoc1/3b1383c34d7682f18504de64158378e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
#def stop_handler(event): | |
# print("Stopped at:", gdb.selected_frame().pc()) | |
#gdb.events.stop.connect(stop_handler) | |
# Set a breakpoint at main | |
#gdb.Breakpoint("main") | |
def getSourceLine(filepath, appPath, line): | |
actualPath = filepath | |
if not os.path.exists(filepath): | |
actualPath = os.path.dirname(appPath) + "/" + filepath | |
try: | |
lines = open(actualPath, "r").readlines() | |
content = lines[line] | |
return content | |
except: | |
print("Unable to open", actualPath) | |
return "" | |
# Run the target program | |
outFile = open("/tmp/gdb_output.txt", "w") | |
#for i in range(9999999): | |
for i in range(10): | |
gdb.execute("step") | |
frame = gdb.selected_frame() | |
space = gdb.current_progspace() | |
appPath = space.filename | |
sal = frame.find_sal() | |
if(sal.symtab is None): | |
print("<unknown>") | |
else: | |
try: | |
line = sal.line | |
filename = sal.symtab.filename | |
outFile.write(str(filename) + ":" + str(line) + " ") | |
outFile.write(getSourceLine(filename, appPath, line)) | |
outFile.flush() | |
except: | |
print("Python error") | |
raise | |
outFile.close() | |
#print("Stopped at:", gdb.selected_frame()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment