Skip to content
b4tinPublic

About

A small, scriptable x86-64 Linux user-space debugger.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tinydbg

A small, scriptable x86-64 Linux user-space debugger.

The debugger core is C++20 (libtinydbg): it owns ptrace, breakpoints, registers, memory, /proc/<pid>/maps, ELF symbols, and Capstone disassembly. A Rust CLI (tinydbg) is a thin client over a versioned C ABI.

Status: v0.1 MVP. Linux x86-64 only. This is not GDB or LLDB and does not claim compatibility with either.

Features

  • run a non-PIE executable under the debugger, or attach to a same-user process
  • software breakpoints by runtime address or exact ELF symbol
  • continue, single-step, and automatic step-over of breakpoints
  • general-purpose and segment registers
  • bounded target memory access (reads in the CLI; read/write in the core API, using process_vm_* with a ptrace fallback)
  • /proc/<pid>/maps
  • x86-64 disassembly from live target memory (Intel syntax)
  • batch mode (--batch -ex ...) and an interactive REPL
  • explicit cleanup: spawned targets are killed, attached targets are detached, and children are reaped

Not in v0.1: PIE/ASLR load bias, multi-thread tracing, DWARF line info, backtraces, demangling, hardware watchpoints, interrupt/Ctrl-C support, GDB RSP, TUI, JSON output, macOS/Windows, telemetry, or network access.

Roadmap: v0.2 adds DWARF lines, backtraces, and hardware watchpoints; v0.3 adds PIE/ASLR, threads, and interrupt support.

Requirements

  • Linux x86-64 (kernel 5.15+ recommended)
  • CMake 3.25+, Ninja, C and C++20 compilers with a C++ standard library (GCC 13+ or Clang 17+ with libstdc++)
  • elfutils development files: libelf-dev (and libdw-dev for v0.2+)
  • Capstone development files: 4.0.2+ or 5.x (libcapstone-dev). Ubuntu 24.04 ships 4.0.2, which works; development also builds against 5.0.3.
  • pkg-config
  • Rust stable, MSRV 1.85
  • Optional: just, bindgen-cli 0.73.2, clang-format, clang-tidy

macOS and Windows are unsupported hosts. Use a Linux VM or container; the core refuses to configure on Darwin because ptrace semantics differ.

Build and test

With just:

just core                         # configure, build, install into build/install
just bindings && git diff --exit-code
just build
just test
just fmt --check
just lint

Without just:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_INSTALL_PREFIX="$PWD/build/install" \
  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_TESTING=ON
cmake --build build
cmake --install build
ctest --test-dir build --output-on-failure

export TINYDBG_CORE_DIR="$PWD/build/install"
export TINYDBG_FIXTURES_DIR="$PWD/build/fixtures"
export LD_LIBRARY_PATH="$PWD/build/install/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test -p tinydbg-cli

crates/tinydbg-cli/build.rs does not build or download C++; it locates the installed core through TINYDBG_CORE_DIR or pkg-config and emits link flags. If the core is missing, it tells you to run just core.

Quick start

just core builds small test fixtures into build/fixtures/. They can also be built standalone:

tests/fixtures/build.sh /tmp/tinydbg-fixtures

Batch mode is the reliable scripting path:

./target/debug/tinydbg --batch \
  -ex 'b main' \
  -ex 'c' \
  -ex 'regs' \
  -ex 'x/4xb g_buffer' \
  -ex 'disas' \
  -ex 'maps' \
  run -- build/fixtures/breakpoint_target

Interactive mode:

$ ./target/debug/tinydbg run -- build/fixtures/breakpoint_target
(tinydbg) b main
Breakpoint 1 at 0x401126
(tinydbg) c
Breakpoint 1, 0x401126
(tinydbg) si
0x401127
(tinydbg) regs
    rax=0x0000000000000000  ...
(tinydbg) q

The initial stop is at the target's exec entry point; set a breakpoint before continuing.

Commands

Command Aliases Meaning
break <address|symbol> b set a software breakpoint
continue c resume until a stop or exit
stepi [n] si execute n instructions (default 1)
regs info registers show registers
x/<count><unit> <address> examine memory; unit b, h, w, or g
disassemble [address] [count] disas disassemble (max 256)
maps info proc mappings list target mappings
detach restore breakpoints and detach
quit q, exit quit
help ? command help

Addresses accept 0x hex, decimal, or an exact main-executable ELF symbol name (main, g_buffer). See docs/commands.md for exact output formats, batch semantics, and the x grammar.

Exit codes

Code Meaning
0 success; target exited normally or debugger quit cleanly
1 command/runtime error
2 CLI usage error
3 ptrace/permission/target setup error
4 internal error (bug; please report)
5 target terminated by a signal

A target exiting with a nonzero status is still code 0; its status is printed. Batch mode stops at the first error.

Permissions

Spawned targets are permitted when the debugger can trace its own child. Attaching to an unrelated same-user process may be blocked by Yama (kernel.yama.ptrace_scope); tinydbg reports EPERM and the likely cause. It does not run as root, ask you to disable kernel security, or bypass ptrace policy.

The test fixtures are tiny C programs compiled with -g -O0 -fno-omit-frame-pointer -no-pie. The long-running fixture opts into being traced with PR_SET_PTRACER for the attach test only.

Safety and limitations

  • One target per session. A session belongs to its creating thread (!Send/!Sync in Rust).
  • Spawn and attach perform a best-effort ELF check and reject readable non-x86-64 executables.
  • Spawned targets use PTRACE_O_EXITKILL; if the debugger dies unexpectedly, the kernel kills the target.
  • Attached targets are detached on clean exit. Without EXITKILL, an uncatchable debugger death can leave a breakpoint byte patched in the target; this crash limitation is documented in docs/ptrace.md.
  • If a breakpoint cannot be restored or RIP cannot be rewound, cleanup kills an attached target rather than detaching corrupted code.
  • Ctrl-C while a target is running is a v0.3 feature. On SIGINT, the CLI dies; spawned targets are killed by EXITKILL. Detach or quit first for attached targets.
  • Multi-thread targets are not supported: PTRACE_O_TRACECLONE is not enabled, and only the thread-group leader is traced.
  • The target inherits stdin/stdout/stderr, so interactive targets compete with the REPL. Use --batch -ex for automation.
  • Symbol resolution requires a non-PIE ET_EXEC main executable and reads the ELF symbol table only; there is no DWARF, split-debug-info, or demangling support yet.
  • Target-derived strings are escaped before printing; control characters cannot inject terminal escapes.

Documentation

License

Project code is licensed under MIT OR Apache-2.0. Third-party components retain their own licenses; see THIRD_PARTY_NOTICES.md.

About

A small, scriptable x86-64 Linux user-space debugger.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages