Przejdลบ do treล›ci

๐Ÿฆ‰ OpenBSD Debugging Tools

OpenBSD emphasizes security and simplicity, providing a focused set of debugging tools that align with its "secure by default" philosophy. These utilities offer essential diagnostics while maintaining the system's minimalist approach.


๐Ÿ” Core Debugging Utilities

ktrace / kdump โ€“ Kernel-Level Tracing

OpenBSD's primary tracing mechanism for monitoring system calls and signals.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Start tracing a process
ktrace ./my_app

# View trace results
kdump

# Trace specific system calls only
ktrace -t c ./network_program

# Follow child processes
ktrace -f ./daemon_program

strace โ€“ System Call Tracingยน

Third-party utility similar to Linux's strace (available via packages).

1
2
3
4
5
# Trace system calls of a command
strace ls

# Save trace output to file
strace -o trace.log ./my_program

ยน Install via: pkg_add strace


gdb โ€“ GNU Debugger

Standard debugger for analyzing compiled programs with debug symbols.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Load program into GDB
gdb ./program

# Run with arguments
(gdb) run arg1 arg2

# Set breakpoint at main
(gdb) break main

# Show backtrace
(gdb) bt

๐Ÿ“Š Performance Analysis Tools

top โ€“ Process Activity Monitor

Built-in tool showing real-time system resource usage.

1
2
3
4
5
# Interactive top view
top

# Batch mode for scripting
top -b -n 1

vmstat โ€“ Virtual Memory Statistics

Reports virtual memory, process scheduling, disk I/O, and interrupt statistics.

1
2
3
4
5
# Display every 2 seconds
vmstat 2

# Show disk-specific stats
vmstat -i

systat โ€“ Dynamic System Statistics

Interactive system monitoring with multiple display modes.

1
2
3
4
5
6
7
# Start systat
systat

# Switch views (e.g., network, disk, memory)
:network
:disk
:malloc

๐Ÿ—ƒ๏ธ Filesystem & Storage Diagnostics

fstat โ€“ File Status Information

Shows which files are currently open by processes.

1
2
3
4
5
6
7
8
# Show all open files
fstat

# Filter by process ID
fstat -p 1234

# Show network connections
fstat -n

iostat โ€“ I/O Statistics

Monitors disk I/O performance and device utilization.

1
2
3
4
5
# Extended device statistics
iostat -x

# Update every 5 seconds
iostat 5

df / du โ€“ Disk Space Usage

Monitor filesystem space and directory sizes.

1
2
3
4
5
# Human-readable disk usage summary
df -h

# Size of directories recursively
du -sh /var/log/*

๐ŸŒ Network Troubleshooting

sockstat โ€“ Socket Statistics

Lists active sockets and associated processes.

1
2
3
4
5
6
7
8
# Show listening sockets
sockstat -l

# All IPv4 connections
sockstat -4

# Specific protocol
sockstat -P tcp

netstat โ€“ Network Statistics

Displays network connections, routing tables, and interface statistics.

1
2
3
4
5
6
7
8
# Active connections
netstat -an

# Listening ports
netstat -an | grep LISTEN

# Interface statistics
netstat -i

tcpdump โ€“ Packet Sniffer

Captures and analyzes network traffic packets.

1
2
3
4
5
6
7
8
# Capture on default interface
tcpdump

# Filter HTTP traffic
tcpdump port 80

# Write capture to file
tcpdump -w capture.pcap

๐Ÿง  Memory Debugging

valgrind โ€“ Memory Error Detectorยน

Detects memory leaks and invalid memory accesses.

1
2
3
4
5
# Check for memory errors
valgrind --tool=memcheck ./my_program

# Generate suppressions
valgrind --gen-suppressions=all ./my_program

ยน Available via packages: pkg_add valgrind


/proc/*/status โ€“ Process Memory Info

Access process memory information directly from procfs (if mounted).

1
2
# Check process memory usage
cat /proc/1234/status | grep VmRSS

๐Ÿ•ต๏ธโ€โ™‚๏ธ Logs and System Messages

dmesg โ€“ Kernel Ring Buffer

Views boot-time messages and runtime kernel diagnostics.

1
2
3
4
5
# Recent kernel messages
dmesg | tail

# Highlight errors/warnings
dmesg -T | grep -E "(error|warning)"

syslogd + logger โ€“ System Logging

Standard Unix logging facilities supported in OpenBSD.

1
2
3
4
5
# Send custom log message
logger "Test log entry"

# View recent logs
tail /var/log/messages

๐Ÿงฐ Advanced Diagnostic Tools

DDB โ€“ In-Kernel Debugger

Built-in kernel debugger for live system analysis or crash dump examination.

Enable with kernel option:

1
options DDB

Common commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Show current backtrace
bt

# Continue execution
continue

# Show registers
show registers

# Examine memory
x/10x 0xffffffff80000000


crash โ€“ Crash Dump Analyzerยฒ

Analyzes kernel crash dumps for post-mortem debugging.

1
2
# Analyze crash dump
crash /var/crash/kern.core

ยฒ Requires crash dump configuration in /etc/rc.conf.local


๐Ÿงพ Summary Table

Tool Purpose
ktrace Kernel-level process tracing
strace System call tracing (external)
gdb Source-level debugging
fstat Open file descriptor tracking
sockstat Socket and connection monitoring
tcpdump Network packet capture
valgrind Memory error detection
dmesg Kernel diagnostic messages
DDB In-kernel debugger

๐Ÿง  Best Practices

โœ… Use ktrace/kdump as primary tracing mechanism โœ… Leverage fstat for identifying file handle leaks โœ… Monitor system resources with vmstat and iostat โœ… Regularly review dmesg for hardware compatibility issues โœ… Combine tools for cross-layer diagnostics โœ… Keep logs organized for audit purposes


๐Ÿงพ See Also