Improve flow of command-line debugging
This commit is contained in:
		
							parent
							
								
									d6eb8ec7ef
								
							
						
					
					
						commit
						6fd8d8f5cf
					
				
							
								
								
									
										18
									
								
								src/app.rs
								
								
								
								
							
							
						
						
									
										18
									
								
								src/app.rs
								
								
								
								
							| 
						 | 
				
			
			@ -86,6 +86,12 @@ impl Application {
 | 
			
		|||
 | 
			
		||||
impl ApplicationHandler<UserEvent> for Application {
 | 
			
		||||
    fn resumed(&mut self, event_loop: &ActiveEventLoop) {
 | 
			
		||||
        if let Some(port) = self.init_debug_port {
 | 
			
		||||
            let mut server =
 | 
			
		||||
                GdbServerWindow::new(SimId::Player1, self.client.clone(), self.proxy.clone());
 | 
			
		||||
            server.launch(port);
 | 
			
		||||
            self.open(event_loop, Box::new(server));
 | 
			
		||||
        }
 | 
			
		||||
        let app = GameWindow::new(
 | 
			
		||||
            self.client.clone(),
 | 
			
		||||
            self.proxy.clone(),
 | 
			
		||||
| 
						 | 
				
			
			@ -93,11 +99,6 @@ impl ApplicationHandler<UserEvent> for Application {
 | 
			
		|||
            SimId::Player1,
 | 
			
		||||
        );
 | 
			
		||||
        self.open(event_loop, Box::new(app));
 | 
			
		||||
        if let Some(port) = self.init_debug_port {
 | 
			
		||||
            let mut server = GdbServerWindow::new(SimId::Player1, self.client.clone());
 | 
			
		||||
            server.start(port);
 | 
			
		||||
            self.open(event_loop, Box::new(server));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn window_event(
 | 
			
		||||
| 
						 | 
				
			
			@ -193,7 +194,8 @@ impl ApplicationHandler<UserEvent> for Application {
 | 
			
		|||
                self.open(event_loop, Box::new(about));
 | 
			
		||||
            }
 | 
			
		||||
            UserEvent::OpenDebugger(sim_id) => {
 | 
			
		||||
                let debugger = GdbServerWindow::new(sim_id, self.client.clone());
 | 
			
		||||
                let debugger =
 | 
			
		||||
                    GdbServerWindow::new(sim_id, self.client.clone(), self.proxy.clone());
 | 
			
		||||
                self.open(event_loop, Box::new(debugger));
 | 
			
		||||
            }
 | 
			
		||||
            UserEvent::OpenInput => {
 | 
			
		||||
| 
						 | 
				
			
			@ -209,6 +211,9 @@ impl ApplicationHandler<UserEvent> for Application {
 | 
			
		|||
                );
 | 
			
		||||
                self.open(event_loop, Box::new(p2));
 | 
			
		||||
            }
 | 
			
		||||
            UserEvent::Quit => {
 | 
			
		||||
                event_loop.exit();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -390,6 +395,7 @@ pub enum UserEvent {
 | 
			
		|||
    OpenDebugger(SimId),
 | 
			
		||||
    OpenInput,
 | 
			
		||||
    OpenPlayer2,
 | 
			
		||||
    Quit,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub enum Action {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -92,6 +92,7 @@ pub struct EmulatorBuilder {
 | 
			
		|||
    state: Arc<Atomic<EmulatorState>>,
 | 
			
		||||
    audio_on: Arc<[AtomicBool; 2]>,
 | 
			
		||||
    linked: Arc<AtomicBool>,
 | 
			
		||||
    start_paused: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl EmulatorBuilder {
 | 
			
		||||
| 
						 | 
				
			
			@ -107,6 +108,7 @@ impl EmulatorBuilder {
 | 
			
		|||
            state: Arc::new(Atomic::new(EmulatorState::Paused)),
 | 
			
		||||
            audio_on: Arc::new([AtomicBool::new(true), AtomicBool::new(true)]),
 | 
			
		||||
            linked: Arc::new(AtomicBool::new(false)),
 | 
			
		||||
            start_paused: false,
 | 
			
		||||
        };
 | 
			
		||||
        let client = EmulatorClient {
 | 
			
		||||
            queue,
 | 
			
		||||
| 
						 | 
				
			
			@ -125,6 +127,13 @@ impl EmulatorBuilder {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn start_paused(self, paused: bool) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            start_paused: paused,
 | 
			
		||||
            ..self
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn build(self) -> Result<Emulator> {
 | 
			
		||||
        let mut emulator = Emulator::new(
 | 
			
		||||
            self.commands,
 | 
			
		||||
| 
						 | 
				
			
			@ -136,6 +145,9 @@ impl EmulatorBuilder {
 | 
			
		|||
        if let Some(path) = self.rom {
 | 
			
		||||
            emulator.load_cart(SimId::Player1, &path)?;
 | 
			
		||||
        }
 | 
			
		||||
        if self.start_paused {
 | 
			
		||||
            emulator.pause_sims()?;
 | 
			
		||||
        }
 | 
			
		||||
        Ok(emulator)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,7 @@ impl GdbServer {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn start(&mut self, port: u16) {
 | 
			
		||||
        *self.status.lock().unwrap() = GdbServerStatus::Connecting;
 | 
			
		||||
        let sim_id = self.sim_id;
 | 
			
		||||
        let client = self.client.clone();
 | 
			
		||||
        let status = self.status.clone();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,6 +87,9 @@ fn main() -> Result<()> {
 | 
			
		|||
    if let Some(path) = args.rom {
 | 
			
		||||
        builder = builder.with_rom(&path);
 | 
			
		||||
    }
 | 
			
		||||
    if args.debug_port.is_some() {
 | 
			
		||||
        builder = builder.start_paused(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ThreadBuilder::default()
 | 
			
		||||
        .name("Emulator".to_owned())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,8 @@
 | 
			
		|||
use egui::{Button, CentralPanel, TextEdit, ViewportBuilder, ViewportId};
 | 
			
		||||
use winit::event_loop::EventLoopProxy;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    app::UserEvent,
 | 
			
		||||
    emulator::{EmulatorClient, SimId},
 | 
			
		||||
    gdbserver::{GdbServer, GdbServerStatus},
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -10,21 +12,26 @@ use super::AppWindow;
 | 
			
		|||
pub struct GdbServerWindow {
 | 
			
		||||
    sim_id: SimId,
 | 
			
		||||
    port_str: String,
 | 
			
		||||
    launched: bool,
 | 
			
		||||
    server: GdbServer,
 | 
			
		||||
    proxy: EventLoopProxy<UserEvent>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl GdbServerWindow {
 | 
			
		||||
    pub fn new(sim_id: SimId, client: EmulatorClient) -> Self {
 | 
			
		||||
    pub fn new(sim_id: SimId, client: EmulatorClient, proxy: EventLoopProxy<UserEvent>) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            sim_id,
 | 
			
		||||
            port_str: (8080 + sim_id.to_index()).to_string(),
 | 
			
		||||
            launched: false,
 | 
			
		||||
            server: GdbServer::new(sim_id, client),
 | 
			
		||||
            proxy,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn start(&mut self, port: u16) {
 | 
			
		||||
    pub fn launch(&mut self, port: u16) {
 | 
			
		||||
        self.server.stop();
 | 
			
		||||
        self.port_str = port.to_string();
 | 
			
		||||
        self.launched = true;
 | 
			
		||||
        self.server.start(port);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +64,9 @@ impl AppWindow for GdbServerWindow {
 | 
			
		|||
            });
 | 
			
		||||
 | 
			
		||||
            if !status.running() {
 | 
			
		||||
                if self.launched {
 | 
			
		||||
                    self.proxy.send_event(UserEvent::Quit).unwrap();
 | 
			
		||||
                }
 | 
			
		||||
                let start_button = Button::new("Start");
 | 
			
		||||
                if ui.add_enabled(port_num.is_some(), start_button).clicked() {
 | 
			
		||||
                    let port = port_num.unwrap();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue