Procházet zdrojové kódy

executed instruction and phase now shown when (big, small) stepping

Simon Van Mierlo před 9 roky
rodič
revize
bde0ab258c

+ 9 - 9
kernel/modelverse_kernel/main.py

@@ -77,7 +77,7 @@ class ModelverseKernel(object):
             self.inst, phase =   yield [("RD", [user_frame, "IP"]),
                                    ("RD", [user_frame, "phase"]),
                                   ]
-            self.new_debug, self.phase_v, inst_v = \
+            self.new_debug, self.phase_v, self.inst_v = \
                             yield [("RD", [self.inst, "__debug"]),
                                    ("RV", [phase]),
                                    ("RV", [self.inst]),
@@ -94,18 +94,18 @@ class ModelverseKernel(object):
                 if self.phase_v == "init" and self.inst in self.compiled:
                     #print("%-30s(%s)" % ("COMPILED " + str(self.compiled[self.inst]), self.phase_v))
                     gen = self.execute_primitive(user_root, self.inst, username)
-                elif inst_v is None:
-                    raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], inst_v, self.phase_v))
+                elif self.inst_v is None:
+                    raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], self.inst_v, self.phase_v))
                 else:
-                    #print("%-30s(%s) -- %s" % (inst_v["value"], self.phase_v, username))
-                    gen = getattr(self, "%s_%s" % (inst_v["value"], self.phase_v))(user_root)
-            elif inst_v is None:
-                raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], inst_v, self.phase_v))
-            elif inst_v["value"] == "call":
+                    #print("%-30s(%s) -- %s" % (self.inst_v["value"], self.phase_v, username))
+                    gen = getattr(self, "%s_%s" % (self.inst_v["value"], self.phase_v))(user_root)
+            elif self.inst_v is None:
+                raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], self.inst_v, self.phase_v))
+            elif self.inst_v["value"] == "call":
                 #print("%-30s(%s)" % ("call", "param"))
                 gen = self.call_param(user_root)
             else:
-                raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], inst_v, self.phase_v))
+                raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[username], self.inst_v, self.phase_v))
 
             try:
                 inp = None

+ 52 - 46
kernel/mvk_server/classes/user_statechart.xml

@@ -22,6 +22,7 @@
             self.curr_line = None
             self.curr_begin_char = None
             self.curr_end_char = None
+            self.curr_phase_v = None
             
             self.big_step_info = None
             self.line_step_info = None
@@ -33,8 +34,8 @@
     <method name="extract_line_info">
         <body>
             <![CDATA[
-            if self.debug_info[-1] != 'None':
-                splitted = self.debug_info[-1].split(':')                 
+            if self.mvk.debug_info[self.username][-1] != 'None':
+                splitted = self.mvk.debug_info[self.username][-1].split(':')                 
                 self.curr_file = ":".join(splitted[0:-2])[1:]
                 self.curr_line = splitted[-2]
                 splitted_chars = splitted[-1].split("-")
@@ -194,7 +195,35 @@
         
         <state id="running_debug">
             <parallel id="running">
-                <state id="execution_flow" initial="reading_debug_info">
+                <state id="execution_flow" initial="check_termination">
+                    <state id="check_termination">
+                        <transition cond="INSTATE('../../execution_state/running')" target="../stepping" />
+                    </state>
+                    <state id="stepping">
+                        <onentry>
+                            <raise event="execute_debug" scope="narrow" target="'parent/executor'">
+                                <parameter expr="self.returnpath"/>
+                                <parameter expr="self.username"/>
+                                <parameter expr="'execute_rule'"/>
+                                <parameter expr="[]"/>
+                                <parameter expr="self.request_id"/>
+                            </raise>
+                            <script>
+                                self.outstanding_execution = self.request_id
+                                self.request_id += 1
+                            </script>
+                        </onentry>
+                        <transition event="executed" cond="success and self.outstanding_execution == request_id" target="../reading_debug_info">
+                            <parameter name="returnvalue"/>
+                            <parameter name="success"/>
+                            <parameter name="request_id"/>
+                        </transition>
+                        <transition event="executed" cond="not success and self.outstanding_execution == request_id" target="../timeout">
+                            <parameter name="returnvalue"/>
+                            <parameter name="success"/>
+                            <parameter name="request_id"/>
+                        </transition>
+                    </state>
                     <state id="reading_debug_info" initial="reading">
                         <state id="reading">
                             <onentry>
@@ -216,10 +245,11 @@
                                 <parameter name="request_id"/>
                                 <script>
                                     if returnvalue:
-                                        self.debug_info_returnvalue = returnvalue
-                                        if returnvalue['debug_info']:
-                                            self.debug_info = returnvalue['debug_info']
+                                        if 'debug_info' in returnvalue:
+                                            self.mvk.debug_info[self.username] = returnvalue['debug_info']
                                             self.extract_line_info()
+                                        if 'phase_v' in returnvalue:
+                                            self.curr_phase_v = returnvalue['phase_v']
                                 </script>
                             </transition>
                             <transition event="executed" cond="not success and self.outstanding_execution == request_id" target="../timeout">
@@ -229,10 +259,10 @@
                             </transition>
                         </state>
                         <state id="checking_line_step">
-                            <transition target="../checking_step_into" cond="self.line_step_info and len(self.debug_info) == self.line_step_info['stack_len'] and (self.curr_file != self.line_step_info['file'] or self.curr_line != self.line_step_info['line'])">
+                            <transition target="../checking_step_into" cond="self.line_step_info and (len(self.mvk.debug_info[self.username]) &lt; self.line_step_info['stack_len'] or (len(self.mvk.debug_info[self.username]) == self.line_step_info['stack_len'] and (self.curr_file != self.line_step_info['file'] or self.curr_line != self.line_step_info['line'])))">
                                 <raise event="line_step_done" />
                             </transition>
-                            <transition target="../checking_step_into" cond="not self.line_step_info or len(self.debug_info) > self.line_step_info['stack_len'] or (self.curr_file == self.line_step_info['file'] and self.curr_line == self.line_step_info['line'])" />
+                            <transition target="../checking_step_into" cond="not self.line_step_info or len(self.mvk.debug_info[self.username]) > self.line_step_info['stack_len'] or (self.curr_file == self.line_step_info['file'] and self.curr_line == self.line_step_info['line'])" />
                         </state>
                         <state id="checking_step_into">
                             <transition target="../checking_big_step" cond="self.step_into_info and (self.curr_file != self.step_into_info['file'] or self.curr_line != self.step_into_info['line'])">
@@ -241,46 +271,22 @@
                             <transition target="../checking_big_step" cond="not self.step_into_info or (self.curr_file == self.step_into_info['file'] and self.curr_line == self.step_into_info['line'])" />
                         </state>
                         <state id="checking_big_step">
-                            <transition target="../checking_small_step" />
+                            <transition target="../checking_small_step" cond="self.curr_phase_v == 'finish'">
+                                <raise event="big_step_done" />
+                            </transition>
+                            <transition target="../checking_small_step" cond="self.curr_phase_v != 'finish'" />
                         </state>
                         <state id="checking_small_step">
-                            <transition target="../../check_termination" after="self.sccd_yield()">
+                            <onentry>
                                 <raise event="small_step_done" />
-                            </transition>
+                            </onentry>
+                            <transition target="../../check_termination" after="self.sccd_yield()" />
                         </state>
                         <state id="timeout">
                             <transition after="1.0" target=".."/>
                             <transition event="set_input_done" target=".."/>
                         </state>
                     </state>
-                    <state id="check_termination">
-                        <transition cond="INSTATE('../../execution_state/running')" target="../stepping" />
-                    </state>
-                    <state id="stepping">
-                        <onentry>
-                            <raise event="execute_debug" scope="narrow" target="'parent/executor'">
-                                <parameter expr="self.returnpath"/>
-                                <parameter expr="self.username"/>
-                                <parameter expr="'execute_rule'"/>
-                                <parameter expr="[]"/>
-                                <parameter expr="self.request_id"/>
-                            </raise>
-                            <script>
-                                self.outstanding_execution = self.request_id
-                                self.request_id += 1
-                            </script>
-                        </onentry>
-                        <transition event="executed" cond="success and self.outstanding_execution == request_id" target="../reading_debug_info">
-                            <parameter name="returnvalue"/>
-                            <parameter name="success"/>
-                            <parameter name="request_id"/>
-                        </transition>
-                        <transition event="executed" cond="not success and self.outstanding_execution == request_id" target="../timeout">
-                            <parameter name="returnvalue"/>
-                            <parameter name="success"/>
-                            <parameter name="request_id"/>
-                        </transition>
-                    </state>
                     <state id="timeout">
                         <transition after="1.0" target="../check_termination"/>
                         <transition event="set_input_done" target="../check_termination"/>
@@ -331,28 +337,28 @@
                                 <parameter name="source"/>
                                 <parameter name="args"/>
                                 <raise event="HTTP_input" scope="narrow" target="'parent/to_mvi/' + source">
-                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'info': self.debug_info})"/>
+                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'stack': self.mvk.debug_info[self.username]})"/>
                                 </raise>
                             </transition>
                         </state>
                         <state id="big_step">
                             <transition event="big_step_done" target="../../paused">
                                 <raise event="HTTP_input" scope="narrow" target="'parent/to_mvi/' + self.big_step_source">
-                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'info': self.debug_info})"/>
+                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'stack': self.mvk.debug_info[self.username], 'instruction': self.mvk.inst_v['value']})"/>
                                 </raise>
                             </transition>
                         </state>
                         <state id="small_step">
                             <transition event="small_step_done" target="../../paused">
                                 <raise event="HTTP_input" scope="narrow" target="'parent/to_mvi/' + self.small_step_source">
-                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'info': self.debug_info})"/>
+                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'stack': self.mvk.debug_info[self.username], 'instruction': self.mvk.inst_v['value'], 'phase': self.mvk.phase_v})"/>
                                 </raise>
                             </transition>
                         </state>
                         <state id="step_into">
                             <transition event="step_into_done" target="../../paused">
                                 <raise event="HTTP_input" scope="narrow" target="'parent/to_mvi/' + self.step_into_info['source']">
-                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'info': self.debug_info})"/>
+                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'stack': self.mvk.debug_info[self.username]})"/>
                                 </raise>
                                 <script>
                                     self.step_into_info = None
@@ -362,7 +368,7 @@
                         <state id="line_step">
                             <transition event="line_step_done" target="../../paused">
                                 <raise event="HTTP_input" scope="narrow" target="'parent/to_mvi/' + self.line_step_info['source']">
-                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'info': self.debug_info})"/>
+                                    <parameter expr="json.dumps({'user': self.username, 'result': 'success', 'state': 'paused', 'stack': self.mvk.debug_info[self.username]})"/>
                                 </raise>
                                 <script>
                                     self.line_step_info = None
@@ -397,7 +403,7 @@
                             <parameter name="args"/>
                             <script>
                                 self.step_into_info = {'source': source,
-                                                       'stack_len': len(self.debug_info),
+                                                       'stack_len': len(self.mvk.debug_info[self.username]),
                                                        'file': self.curr_file,
                                                        'line': self.curr_line}
                             </script>
@@ -407,7 +413,7 @@
                             <parameter name="args"/>
                             <script>
                                 self.line_step_info = {'source': source,
-                                                       'stack_len': len(self.debug_info),
+                                                       'stack_len': len(self.mvk.debug_info[self.username]),
                                                        'file': self.curr_file,
                                                        'line': self.curr_line}
                             </script>

+ 6 - 2
scripts/debug_prompt.py

@@ -48,5 +48,9 @@ while 1:
     reply = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read())
     print "RES: %s" % reply['result']
     print "STATE: %s" % reply['state']
-    if 'info' in reply:
-        print "STACK:\n\t%s" % '\n\t'.join(["%s. %s" % item for item in reversed(list(enumerate(reply['info'])))])
+    if 'stack' in reply:
+        print "STACK:\n\t%s" % '\n\t'.join(["%s. %s" % item for item in reversed(list(enumerate(reply['stack'])))])
+    if 'instruction' in reply:
+        print "INST: %s" % reply['instruction']
+    if 'phase' in reply:
+        print "PHASE: %s" % reply['phase']