@@ -52,6 +52,7 @@ def __init__(self):
5252 self .icon_files = {
5353 "pause" : "qubes-vm-pause" ,
5454 "terminal" : "qubes-terminal" ,
55+ "debug" : "qubes-info" ,
5556 "preferences" : "qubes-vm-settings" ,
5657 "kill" : "qubes-vm-kill" ,
5758 "shutdown" : "qubes-vm-shutdown" ,
@@ -316,6 +317,35 @@ async def perform_action(self):
316317 )
317318
318319
320+ class RunDebugConsoleItem (VMActionMenuItem ):
321+ """Run Debug Console menu Item. When activated runs a qvm-console-dispvm."""
322+
323+ def __init__ (self , vm , icon_cache ):
324+ super ().__init__ (
325+ vm ,
326+ label = _ ("Debug Console" ),
327+ icon_cache = icon_cache ,
328+ icon_name = "debug" ,
329+ )
330+
331+ async def perform_action (self , * _args , ** _kwargs ):
332+ try :
333+ proc = await asyncio .create_subprocess_exec (
334+ "qvm-console-dispvm" , self .vm .name , stderr = subprocess .PIPE
335+ )
336+ _stdout , stderr = await proc .communicate ()
337+ if proc .returncode != 0 :
338+ raise exc .QubesException (stderr )
339+ except exc .QubesException as ex :
340+ show_error (
341+ _ ("Error starting debug console" ),
342+ _ (
343+ "The following error occurred while attempting to start"
344+ "debug console for qube {0}:\n {1}"
345+ ).format (self .vm .name , str (ex )),
346+ )
347+
348+
319349class OpenFileManagerItem (VMActionMenuItem ):
320350 """Attempts to open a file manager in the VM. If fails, displays an
321351 error message."""
@@ -368,6 +398,10 @@ def __init__(self, vm, app, icon_cache):
368398
369399 self .add (OpenFileManagerItem (self .vm , icon_cache ))
370400 self .add (RunTerminalItem (self .vm , icon_cache ))
401+ if self .app .wizard_mode or \
402+ not getattr (self .vm , "guivm" ) or \
403+ getattr (self .vm , "debug" ):
404+ self .add (RunDebugConsoleItem (self .vm , icon_cache ))
371405 self .add (PreferencesItem (self .vm , icon_cache ))
372406 self .add (PauseItem (self .vm , icon_cache ))
373407 self .add (ShutdownItem (self .vm , icon_cache ))
@@ -668,6 +702,11 @@ def __init__(self, app_name, qapp, dispatcher, stats_dispatcher):
668702 self .set_application_id (app_name )
669703 self .register () # register Gtk Application
670704
705+ # to display debug console for all qubes
706+ self .wizard_mode = self .qapp .domains ["dom0" ].features .get (
707+ "wizard-mode" , False
708+ )
709+
671710 def register_events (self ):
672711 self .dispatcher .add_handler ("connection-established" , self .refresh_all )
673712 self .dispatcher .add_handler ("domain-pre-start" , self .update_domain_item )
0 commit comments