#调试 #昂贵 #Windows #应用 #功能 #等待 #版本

dbgtools-win

昂贵且侵入式调试工具(适用于Windows)

3 个不稳定版本

0.2.1 2021年5月3日
0.2.0 2021年5月3日
0.1.0 2021年3月7日

#2323开发工具


用于 3 crate

0BSD 许可证

23KB
350 代码行

dbgtools-win

一组特定平台的功能,当调试用户空间Windows应用程序和库时可能很有用。

使用方法

此crate仅适用于开发环境。其功能紧密依赖于其他开发工具,并且可能会给您的代码添加显著的额外开销。

推荐使用 dbgtools 的方式是将其添加为可选功能,以便仅在需要调试时将其编译到项目中

In Cargo.toml

[dependencies]
dbgtools-win = { version = "0.2", optional = true }

In code

// Wait for a debugger to connect and break as soon as it has
#[cfg(feature="dbgtools-win")]
dbgtools_win::debugger::wait_for_then_break();

使用以下方式构建

cargo build --features dbgtools-win

另请参阅

  • verboten - 一个简单的Windows服务包装器,用于msvsmon,Visual Studio的远程调试服务器。

lib.rs:

Windows的昂贵调试实用函数。

此crate旨在用于应用程序的开发版本中,以帮助调试,通常不应包含在生产版本中使用的发布构建中。

膨胀示例

以下是一个关于dbgtools-win的示例用法,该示例更改了许多默认设置,仅为了展示可用的选项。

use std::path::PathBuf;
use dbgtools_win::*;

fn init() {
  let mut wp = WinPicnic::default();

  // If a panic occurs, append its output to a log file.  Can be useful if
  // process does not have a console, like a service.  If a debugger is
  // attached the output can be sent to PanicOutput::Debugger instead.
  let plog = PathBuf::from("C:\\Temp\\panic.log");
  wp.output = PanicOutput::FileAppend(plog);

  // If a panic occurs, and there's a debugger attached to the process,
  // then trigger a debug interrupt.
  wp.brk = true;

  // If a panic occurs, play three short notes.  This can be useful to
  // indicate a problem when running in an environment which doesn't have a
  // console, like a service.
  wp.beep = true;

  // Instruct panic hook to generate minidumps if a panic occurs.
  wp.mdump = Some({
    let mut md = minidump::DumpInfo::default();

    // Generate a full memory dump
    md.mdtype = minidump::DumpType::FullMem;

    // Write dumps to a specific, absolute, directory.  This is useful if
    // you don't know what directory your process will be in, or if the
    // process has write access in it, when the panic handler is run.
    let dumpdir = PathBuf::from("C:\\Temp");
    md.dumpsdir = Some(dumpdir);

    // Set a hardcoded base file name for dumps.
    let basename = PathBuf::from("myapp");
    md.name = Some(basename);

    // Don't overwrite existing dump file; instead attach a sequence
    // number to the base name and skip existing sequence numbers.
    md.seq = true;

    md
  });

  // Set custom panic handler
  set_panic_handler(wp);

  // Wait for a debugger to attach.  Once a debugger attaches, trigger a
  // hard-coded debug breakpoint.  This can be useful when remote
  // debugging services which start early during boot.
  debugger::wait_for_then_break();
}

实时调试示例

debugger::set_panic_handler() 中有一个特殊的简短版本 set_panic_handler(),它具有较少的选项,但特别适合程序始终与调试器一起运行的情况。

use std::path::PathBuf;
use dbgtools_win::*;
use dbgtools_win::debugger::OnPanic;

fn init() {
  // Set up a custom panic hook which will output the panic information and
  // backtrace to the debugger output terminal, and trigger an explicit
  // debug breakpoint
  debugger::set_panic_handler(OnPanic::Break);

  // Wait for a debugger to attach and trigger an explicit code breakpoint
  // when that happens.
  debugger::wait_for_then_break();
}

依赖关系

~128MB
~2M SLoC