Commit 3892c15a authored by Simon Sobisch's avatar Simon Sobisch

internal handling for STOP RUN and runtime errors

parent 1dfb2849
......@@ -4576,6 +4576,61 @@ class CBreakWorker():
print('Breakpoint parameters not recognized')
return
@staticmethod
def handle_libcob_event(event_name, ext_parm=None):
# Handles specific 'events' the COBOL user is interested in
if event_name == "cob_stop_run":
# switch to COBOL frame and inform the user
try:
ext_msg = " with status " + str(gdb.parse_and_eval("status"))
except:
# in case of missing debugging info the user has to manually check the exit status -> no issue
ext_msg = ""
gdb.execute("cup 0")
print ("\nCOBOL Runtime is going to exit" + ext_msg)
elif event_name == "cob_runtime_error":
# that idea is nice but too wacky, libcob will make that easier with GC 3.2
# # [1a] check if we need to hack the "hdlrs" entries...
# try:
# hdlrs_setting = str(gdb.parse_and_eval("hdlrs")) == "0x0"
# except:
# # in case of missing debugging info -> just inform the user that something happened
# CBreakWorker.handle_libcob_event("cob_runtime_error_simple_handling")
# return
# # [1b] ... and do if necessary
# if hdlrs_setting:
# gdb.parse_and_eval("hdlrs = 1")
# # [2] set a temporary breakpoint after the place where "p" contains the runtime error
# # which is only reached because of hdlrs set (if necessary by our hack above)
# # The real whacky part is the line number...
# # TODO: solve by replacing it with an internal hardware watchpoint for "h" (setting both h and hdlrs in the hack back to zero)
# line_number = 7282 # correct for GC 3.1.2: 7282, 3.1 would have been 7236
# baddy = CBreakWorker.set_breakpoint(str(line_number), True, True)
# if not baddy:
# CBreakWorker.handle_libcob_event("cob_runtime_error_simple_handling")
# return
# # [3] telling GDB to do something else if that breakpoint is reached
# baddy.commands = "python CBreakWorker.handle_libcob_event(\"cob_runtime_error_hack\", ext_parm=" + str(hdlrs_setting) + ")"
# # [4} continue to (hopefully) reach the that breakpoint and do [3]
# # note: with most environments
# gdb.execute("continue")
# elif event_name == "cob_runtime_error_hack":
# # [5] hack the hdlrs back if we did it on the way here to ensure no bad calls happen if the user continues
# if ext_parm:
# gdb.parse_and_eval("hdlrs=NULL")
# # [6] get the error string
# err_str = gdb.parse_and_eval("p").string()
# # [7] switch to the COBOL and inform the user
# gdb.execute("cup 0")
# print ("\nCOBOL Runtime Error: " + err_str)
# elif event_name == "cob_runtime_error_simple_handling":
# simple variant for the case "no debug info for libcob" or internal errors in our hack:
# switch to COBOL frame and inform the user
gdb.execute("cup 0")
print ("\nCOBOL Runtime Error happened")
else:
raise Exception("unknown libcob event '" + str(event_name) + "'")
CBLDBG_CBREAK_WORKER = CBreakWorker()
......@@ -4792,6 +4847,15 @@ A breakpoint stops execution of your program whenever the expression matches
CTBreak()
CCondition()
if GV_GlobalVariables.gdb_version >= 70700:
print('Registering maintanance breakpoints for STOP RUN and runtime exceptions')
bp = CBreakWorker.set_breakpoint("cob_stop_run", False, True)
if bp:
bp.commands = "python CBreakWorker.handle_libcob_event(\"cob_stop_run\")"
bp = CBreakWorker.set_breakpoint("cob_runtime_error", False, True)
if bp:
bp.commands = "python CBreakWorker.handle_libcob_event(\"cob_runtime_error\")"
def invoke(self, arguments, from_tty):
self.dont_repeat()
self.worker.process_break_arguments(arguments, False, False)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment