Skip to content

Commit

Permalink
Adds debug launch configuration and task for Slint (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Nov 19, 2024
1 parent 6ec1ea8 commit 8675ec8
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 15 deletions.
21 changes: 19 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@
"kind": "bin"
}
},
"args": [
"--kernel",
"${workspaceFolder}/build/obkrnl"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Kernel",
"name": "Kernel | Qt",
"type": "lldb",
"request": "custom",
"preLaunchTask": "Launch VMM (Debug & Qt)",
"targetCreateCommands": [
"target create ${workspaceFolder}/build/obkrnl",
"target modules load --file ${workspaceFolder}/build/obkrnl -s 0xffffffff82200000"
],
"processCreateCommands": [
"gdb-remote 1234"
]
},
{
"name": "Kernel | Slint",
"type": "lldb",
"request": "custom",
"preLaunchTask": "Launch VMM (Debug)",
"preLaunchTask": "Launch VMM (Debug & Slint)",
"targetCreateCommands": [
"target create ${workspaceFolder}/build/obkrnl",
"target modules load --file ${workspaceFolder}/build/obkrnl -s 0xffffffff82200000"
Expand Down
29 changes: 28 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "Launch VMM (Debug)",
"label": "Launch VMM (Debug & Qt)",
"detail": "Launch the GUI then start the VMM in debug mode",
"type": "process",
"isBackground": true,
Expand All @@ -29,6 +29,33 @@
"--kernel",
"${workspaceFolder}/build/obkrnl"
]
},
{
"label": "Launch VMM (Debug & Slint)",
"detail": "Launch the Slint GUI then start the VMM in debug mode",
"type": "shell",
"isBackground": true,
"runOptions": {
"instanceLimit": 1
},
"command": "cargo",
"args": [
"run",
"-p",
"gui",
"--features",
"slint",
"--bin",
"obliteration",
"--",
"--debug",
"127.0.0.1:1234",
"--kernel",
"${workspaceFolder}/build/obkrnl"
],
"options": {
"cwd": "${workspaceFolder}"
}
}
]
}
68 changes: 64 additions & 4 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use self::ui::ErrorDialog;
use self::vmm::Vmm;
use args::CliArgs;
use clap::Parser;
use debug::DebugServer;
use graphics::{GraphicsApi, PhysicalDevice};
use slint::{ComponentHandle, Global, ModelExt, ModelRc, SharedString, VecModel};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::ExitCode;
use thiserror::Error;

Expand Down Expand Up @@ -43,12 +44,29 @@ fn run() -> Result<(), ApplicationError> {
run_wizard().map_err(ApplicationError::RunWizard)?;

if let Some(debug_addr) = args.debug_addr() {
let kernel_path = get_kernel_path(&args)?;

let debug_server = DebugServer::new(debug_addr)
.map_err(|e| ApplicationError::StartDebugServer(e, debug_addr))?;

let _debug_client = debug_server
let debug_client = debug_server
.accept()
.map_err(ApplicationError::CreateDebugClient)?;

let graphics_api =
graphics::DefaultApi::new().map_err(ApplicationError::InitGraphicsApi)?;

let screen = ui::Screen::new().map_err(ApplicationError::CreateScreen)?;

let vmm = Vmm::new(
kernel_path,
todo!(),
todo!(),
Some(debug_client),
todo!(),
todo!(),
)
.map_err(ApplicationError::RunVmm)?;
}

run_main_app()?;
Expand Down Expand Up @@ -90,6 +108,39 @@ fn run_main_app() -> Result<(), ApplicationError> {
Ok(())
}

fn get_kernel_path(args: &CliArgs) -> Result<PathBuf, ApplicationError> {
let kernel_path = if let Some(kernel_path) = args.kernel_path() {
kernel_path.to_path_buf()
} else {
let mut pathbuf = std::env::current_exe().map_err(ApplicationError::GetCurrentExePath)?;
pathbuf.pop();

#[cfg(target_os = "windows")]
{
pathbuf.push("share");
}

#[cfg(not(target_os = "windows"))]
{
pathbuf.pop();

#[cfg(target_os = "macos")]
{
pathbuf.push("Resources");
}
#[cfg(not(target_os = "macos"))]
{
pathbuf.push("share");
}
}
pathbuf.push("obkrnl");

pathbuf
};

Ok(kernel_path)
}

fn display_error(e: impl std::error::Error) {
use std::fmt::Write;

Expand Down Expand Up @@ -131,7 +182,7 @@ where
global_callbacks.on_open_url(|url| {
let url = url.as_str();

if let Err(e) = open::that(url) {
if let Err(_e) = open::that(url) {
// TODO: Show a modal dialog.
}
});
Expand Down Expand Up @@ -183,21 +234,30 @@ enum ApplicationError {
#[error("failed to run wizard")]
RunWizard(#[source] slint::PlatformError),

#[error("get current executable path")]
GetCurrentExePath(#[source] std::io::Error),

#[error("failed to start debug server on {1}")]
StartDebugServer(
#[source] debug::StartDebugServerError,
std::net::SocketAddrV4,
),

#[error("failed to accept debug client")]
#[error("failed to accept debug connection")]
CreateDebugClient(#[source] std::io::Error),

#[error("failed to create screen")]
CreateScreen(#[source] slint::PlatformError),

#[error("failed to create main window")]
CreateMainWindow(#[source] slint::PlatformError),

#[error("failed to initialize graphics API")]
InitGraphicsApi(#[source] <graphics::DefaultApi as GraphicsApi>::CreateError),

#[error("failed to run vmm")]
RunVmm(#[source] vmm::VmmError),

#[error("failed to run main window")]
RunMainWindow(#[source] slint::PlatformError),
}
10 changes: 9 additions & 1 deletion gui/src/vmm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ pub unsafe extern "C" fn vmm_start(
}
};

let screen = unsafe { &*screen };
let profile = unsafe { &*profile };
let screen = unsafe { &*screen };

let screen = match crate::screen::Default::from_screen(screen) {
Ok(v) => v,
Err(e) => {
*err = RustError::with_source("couldn't setup a screen", e).into_c();
return null_mut();
}
};

match Vmm::new(path, screen, profile, debugger, event, cx) {
Ok(vmm) => Box::into_raw(Box::new(vmm)),
Expand Down
8 changes: 1 addition & 7 deletions gui/src/vmm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Vmm {
impl Vmm {
pub fn new(
kernel_path: impl AsRef<Path>,
screen: &VmmScreen,
screen: crate::screen::Default,
profile: &Profile,
debugger: Option<DebugClient>,
event_handler: unsafe extern "C" fn(*const VmmEvent, *mut c_void),
Expand Down Expand Up @@ -309,9 +309,6 @@ impl Vmm {
.build(&feats, vm_page_size, &devices, dynamic)
.map_err(VmmError::BuildRam)?;

// Setup screen.
let screen = crate::screen::Default::from_screen(screen).map_err(VmmError::SetupScreen)?;

// Setup CPU manager.
let shutdown = Arc::new(AtomicBool::new(false));
let mut cpu_manager = CpuManager::new(
Expand Down Expand Up @@ -544,9 +541,6 @@ pub enum VmmError {
#[error("couldn't build RAM")]
BuildRam(#[source] ram::RamBuilderError),

#[error("couldn't setup a screen")]
SetupScreen(#[source] crate::screen::ScreenError),

#[error("couldn't setup a GDB stub")]
SetupGdbStub(
#[source] GdbStubError<GdbError, <DebugClient as gdbstub::conn::Connection>::Error>,
Expand Down

0 comments on commit 8675ec8

Please sign in to comment.