11import json
22import sys
33import threading
4-
4+ from nopdb import nopdb
55from vertx import EventBus
66
7- from nopdb import nopdb
87from sourceplusplus .models .command .CommandType import CommandType
98from sourceplusplus .models .command .LiveInstrumentCommand import LiveInstrumentCommand
109from sourceplusplus .models .command .LiveInstrumentContext import LiveInstrumentContext
1110from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
1211from sourceplusplus .models .instrument .LiveLog import LiveLog
12+ from sourceplusplus .models .instrument .LiveMeter import LiveMeter
1313from sourceplusplus .models .instrument .common .LiveInstrumentType import LiveInstrumentType
1414from sourceplusplus .models .instrument .common .LiveSourceLocation import LiveSourceLocation
1515
@@ -25,55 +25,50 @@ def __init__(self, eb: EventBus):
2525 LiveInstrumentRemote .dbg .start ()
2626 threading .settrace (sys .gettrace ())
2727
28- def add_live_log (self , context : LiveInstrumentContext ):
29- for i in context .instruments :
30- live_log = LiveLog .from_json (i )
31- bp = LiveInstrumentRemote .dbg .breakpoint (file = live_log .location .source , line = live_log .location .line )
32- LiveInstrumentRemote .instruments [live_log .id ] = [bp , live_log ]
33- bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
34- "ContextReceiver.do_log('" + live_log .id + "',globals(),locals())" )
35- self .eb .publish (address = "spp.platform.status.live-log-applied" , body = json .loads (i ))
36-
37- def remove_live_log (self , context : LiveInstrumentContext ):
38- print ("Removing live log(s)" )
39- for i in context .instruments :
40- live_log = LiveLog .from_json (i )
41- try :
42- LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (live_log .id )[0 ]._handle )
43- except KeyError :
44- pass
45- for i in context .locations :
46- loc = LiveSourceLocation .from_json (i )
47- delete = []
48- for key , val in LiveInstrumentRemote .instruments .items ():
49- if isinstance (val [1 ], LiveLog ) and val [1 ].location == loc :
50- delete .append (key )
51- for i in delete :
52- del LiveInstrumentRemote .instruments [i ]
53-
54- def add_live_breakpoint (self , context : LiveInstrumentContext ):
55- print ("Adding live breakpoint(s)" )
28+ def add_live_instrument (self , context : LiveInstrumentContext , instrument_type : LiveInstrumentType ):
5629 for i in context .instruments :
57- live_bp = LiveBreakpoint .from_json (i )
58- bp = LiveInstrumentRemote .dbg .breakpoint (file = live_bp .location .source , line = live_bp .location .line )
59- LiveInstrumentRemote .instruments [live_bp .id ] = [bp , live_bp ]
60- bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
61- "ContextReceiver.do_breakpoint('" + live_bp .id + "',globals(),locals())" )
62- self .eb .publish (address = "spp.platform.status.live-breakpoint-applied" , body = json .loads (i ))
30+ if instrument_type == LiveInstrumentType .BREAKPOINT :
31+ live_instrument = LiveBreakpoint .from_json (i )
32+ elif instrument_type == LiveInstrumentType .LOG :
33+ live_instrument = LiveLog .from_json (i )
34+ else :
35+ live_instrument = LiveMeter .from_json (i )
36+ bp = LiveInstrumentRemote .dbg .breakpoint (
37+ file = live_instrument .location .source ,
38+ line = live_instrument .location .line
39+ )
40+ LiveInstrumentRemote .instruments [live_instrument .id ] = [bp , live_instrument ]
41+ if instrument_type == LiveInstrumentType .BREAKPOINT :
42+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
43+ "ContextReceiver.apply_breakpoint('" + live_instrument .id + "',globals(),locals())" )
44+ self .eb .publish (address = "spp.platform.status.live-breakpoint-applied" , body = json .loads (i ))
45+ elif instrument_type == LiveInstrumentType .LOG :
46+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
47+ "ContextReceiver.apply_log('" + live_instrument .id + "',globals(),locals())" )
48+ self .eb .publish (address = "spp.platform.status.live-log-applied" , body = json .loads (i ))
49+ else :
50+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
51+ "ContextReceiver.apply_meter('" + live_instrument .id + "',globals(),locals())" )
52+ self .eb .publish (address = "spp.platform.status.live-meter-applied" , body = json .loads (i ))
6353
64- def remove_live_breakpoint (self , context : LiveInstrumentContext ):
65- print ("Removing live breakpoint (s)" )
54+ def remove_live_instrument (self , context : LiveInstrumentContext , type : LiveInstrumentType ):
55+ print ("Removing live instrument (s)" )
6656 for i in context .instruments :
67- live_bp = LiveBreakpoint .from_json (i )
57+ if type == LiveInstrumentType .BREAKPOINT :
58+ instrument = LiveBreakpoint .from_json (i )
59+ elif type == LiveInstrumentType .LOG :
60+ instrument = LiveLog .from_json (i )
61+ else :
62+ instrument = LiveMeter .from_json (i )
6863 try :
69- LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (live_bp .id )[0 ]._handle )
64+ LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (instrument .id )[0 ]._handle )
7065 except KeyError :
7166 pass
7267 for i in context .locations :
7368 loc = LiveSourceLocation .from_json (i )
7469 delete = []
7570 for key , val in LiveInstrumentRemote .instruments .items ():
76- if isinstance ( val [1 ], LiveBreakpoint ) and val [1 ].location == loc :
71+ if val [1 ]. type == type and val [1 ].location == loc :
7772 delete .append (key )
7873 for i in delete :
7974 del LiveInstrumentRemote .instruments [i ]
@@ -82,11 +77,10 @@ def handle_instrument_command(self, command: LiveInstrumentCommand, instrument_t
8277 print ("Received command: " + command .command_type )
8378 if command .command_type == CommandType .ADD_LIVE_INSTRUMENT :
8479 if instrument_type == LiveInstrumentType .BREAKPOINT :
85- self .add_live_breakpoint (command .context )
80+ self .add_live_instrument (command .context , LiveInstrumentType .BREAKPOINT )
81+ elif instrument_type == LiveInstrumentType .LOG :
82+ self .add_live_instrument (command .context , LiveInstrumentType .LOG )
8683 else :
87- self .add_live_log (command .context )
84+ self .add_live_instrument (command .context , LiveInstrumentType . METER )
8885 elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
89- if instrument_type == LiveInstrumentType .BREAKPOINT :
90- self .remove_live_breakpoint (command .context )
91- else :
92- self .remove_live_log (command .context )
86+ self .remove_live_instrument (command .context , instrument_type )
0 commit comments