eric6/DebugClients/Python/DebugBase.py

changeset 7707
6abcf4275d0e
parent 7639
422fd05e9c91
child 7711
5e6792b85a8a
--- a/eric6/DebugClients/Python/DebugBase.py	Sun Sep 20 18:32:43 2020 +0200
+++ b/eric6/DebugClients/Python/DebugBase.py	Mon Sep 21 19:03:35 2020 +0200
@@ -15,6 +15,7 @@
 import ctypes
 import time
 from inspect import CO_GENERATOR
+import dis
 
 from BreakpointWatch import Breakpoint, Watch
 
@@ -865,10 +866,12 @@
         
         self.isBroken = True
         
+        disassembly = None
         stack = []
         if exctb:
             frlist = self.__extract_stack(exctb)
             frlist.reverse()
+            disassembly = self.__disassemble(frlist[0][0])
             
             self.currentFrame = frlist[0][0]
             stack = self.getStack(frlist[self.skipFrames:])
@@ -877,6 +880,7 @@
         self._dbgClient.currentThread = self
         self._dbgClient.currentThreadExec = self
         self._dbgClient.sendException(exctypetxt, excvaltxt, stack)
+        self._dbgClient.setDisassembly(disassembly)
         self._dbgClient.dumpThreadList()
         
         if exctb is not None:
@@ -918,6 +922,34 @@
         tb = None
         return stack
 
+    def __disassemble(self, frame):
+        """
+        Private method to generate a disassembly of the given code object.
+        
+        @param frame frame object to be disassembled
+        @type code
+        @return dictionary containing the disassembly information
+        @rtype dict
+        """
+        disDict = {
+            "lasti": frame.f_lasti,
+            "firstlineno": frame.f_code.co_firstlineno,
+            "instructions": [],
+        }
+        for instr in dis.get_instructions(frame.f_code):
+            instrDict = {
+                "lineno":
+                    0 if instr.starts_line is None else instr.starts_line,
+                "isJumpTarget": instr.is_jump_target,
+                "offset": instr.offset,
+                "opname": instr.opname,
+                "arg": instr.arg,
+                "argrepr": instr.argrepr,
+            }
+            disDict["instructions"].append(instrDict)
+        
+        return disDict
+    
     def __extractSystemExitMessage(self, excinfo):
         """
         Private method to get the SystemExit code and message.

eric ide

mercurial