Re-implement OSDK debugging fixes and other facilities upon the refactor

This commit bring back the features introduced from d28292c to a52e432:
 - Disable KVM when using GDB;
 - Update docs about the GDB server address;
 - Add `config` option for `CargoArgs` in OSDK;
 - Ensure debug info added when debugging in the release profile.
This commit is contained in:
Zhang Junyang
2024-04-22 22:42:14 +08:00
committed by Tate, Hongliang Tian
parent f9ac2ee498
commit 56175f63df
13 changed files with 121 additions and 71 deletions

View File

@ -12,7 +12,7 @@ use std::{
use bin::strip_elf_for_qemu;
use super::util::{cargo, COMMON_CARGO_ARGS, DEFAULT_TARGET_RELPATH};
use super::util::{cargo, profile_name_adapter, COMMON_CARGO_ARGS, DEFAULT_TARGET_RELPATH};
use crate::{
arch::Arch,
base_crate::new_base_crate,
@ -153,6 +153,7 @@ pub fn do_build(
&build.profile,
&build.features[..],
build.no_default_features,
&build.override_configs[..],
&cargo_target_directory,
rustflags,
);
@ -186,6 +187,7 @@ fn build_kernel_elf(
profile: &str,
features: &[String],
no_default_features: bool,
override_configs: &[String],
cargo_target_directory: impl AsRef<Path>,
rustflags: &[&str],
) -> AsterBin {
@ -219,6 +221,9 @@ fn build_kernel_elf(
.arg(cargo_target_directory.as_ref());
command.args(COMMON_CARGO_ARGS);
command.arg("--profile=".to_string() + profile);
for override_config in override_configs {
command.arg("--config").arg(override_config);
}
info!("Building kernel ELF using command: {:#?}", command);
@ -228,13 +233,11 @@ fn build_kernel_elf(
process::exit(Errno::ExecuteCommand as _);
}
let aster_bin_path = cargo_target_directory.as_ref().join(&target_os_string);
let aster_bin_path = if profile == "dev" {
aster_bin_path.join("debug")
} else {
aster_bin_path.join(profile)
}
.join(get_current_crate_info().name);
let aster_bin_path = cargo_target_directory
.as_ref()
.join(&target_os_string)
.join(profile_name_adapter(profile))
.join(get_current_crate_info().name);
AsterBin::new(
aster_bin_path,

View File

@ -1,16 +1,18 @@
// SPDX-License-Identifier: MPL-2.0
use crate::commands::util::bin_file_name;
use crate::{cli::DebugArgs, util::get_target_directory};
use crate::{
cli::DebugArgs,
commands::util::{bin_file_name, profile_name_adapter},
util::get_target_directory,
};
use std::process::Command;
pub fn execute_debug_command(profile: &String, args: &DebugArgs) {
pub fn execute_debug_command(profile: &str, args: &DebugArgs) {
let remote = &args.remote;
let file_path = get_target_directory()
.join("x86_64-unknown-none")
.join(profile)
.join(profile_name_adapter(profile))
.join(bin_file_name());
println!("Debugging {}", file_path.display());

View File

@ -3,7 +3,7 @@
use super::{build::create_base_and_cached_build, util::DEFAULT_TARGET_RELPATH};
use crate::{
cli::GdbServerArgs,
config::{scheme::ActionChoice, Config},
config::{scheme::ActionChoice, unix_args::split_to_kv_array, Config},
util::{get_current_crate_info, get_target_directory},
};
@ -40,10 +40,33 @@ pub fn execute_run_command(config: &Config, gdb_server_args: &GdbServerArgs) {
}
};
config.run.qemu.args += &qemu_gdb_args;
// FIXME: Disable KVM from QEMU args in debug mode.
// Currently, the QEMU GDB server does not work properly with KVM enabled.
let mut splitted = split_to_kv_array(&config.run.qemu.args);
let args_num = splitted.len();
splitted.retain(|x| !x.contains("kvm"));
if splitted.len() != args_num {
println!(
"[WARNING] KVM is forced to be disabled in GDB server currently. \
Options related with KVM are ignored."
);
}
config.run.qemu.args = splitted.join(" ");
// Ensure debug info added when debugging in the release profile.
if config.run.build.profile == "release" {
config
.run
.build
.override_configs
.push("profile.release.debug=true".to_owned());
}
}
let _vsc_launch_file = gdb_server_args.vsc_launch_file.then(|| {
vsc::check_gdb_config(gdb_server_args);
let profile = super::util::profile_adapter(&config.build.profile);
let profile = super::util::profile_name_adapter(&config.build.profile);
vsc::VscLaunchConfig::new(profile, &gdb_server_args.gdb_server_addr)
});

View File

@ -15,7 +15,7 @@ pub fn cargo() -> Command {
Command::new("cargo")
}
pub fn profile_adapter(profile: &str) -> &str {
pub fn profile_name_adapter(profile: &str) -> &str {
match profile {
"dev" => "debug",
_ => profile,