Przejdลบ do treล›ci

๐Ÿก NetBSD Debugging Tools

NetBSD provides a comprehensive set of debugging and diagnostic tools designed for portability and reliability across diverse hardware platforms. Drawing from its strong BSD heritage, these utilities enable precise system analysis and troubleshooting.


๐Ÿ” Core Debugging Utilities

strace โ€“ System Call Tracingยน

Traces system calls made by a process, useful for diagnosing hangs or unexpected behavior.

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

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

# Follow child processes
strace -f daemon_program

ยน Note: May require installation via pkgsrc (pkgin install strace)


ktrace / kdump โ€“ Kernel-Level Tracing

Native NetBSD kernel tracing facility for detailed process and kernel activity monitoring.

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

# View trace results
kdump

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

gdb โ€“ GNU Debugger

Standard debugger for analyzing compiled programs with symbolic debugging information.

 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

Real-time display of system resource usage including CPU, memory, and process activity.

1
2
3
4
5
# Interactive top view
top

# Batch mode for scripting
top -b -n 1

ps โ€“ Process Status

Detailed view of running processes with customizable output formats.

1
2
3
4
5
6
7
8
# All processes with full details
ps auxww

# Tree view of processes
ps axf

# Custom format output
ps -eo pid,ppid,cmd,%cpu,time

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

๐Ÿ—ƒ๏ธ 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

disklabel โ€“ Disk Label Management

View and manage disk partition layouts and labels.

1
2
3
4
5
# Show disk label information
disklabel wd0

# Edit disk label (advanced)
disklabel -E wd0

๐ŸŒ Network Troubleshooting

sockstat โ€“ Socket Statistics

Lists active sockets and associated processes (if available).

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

# All IPv4 connections
sockstat -4

# Specific protocol
sockstat -P tcp

โš ๏ธ Note: Not all NetBSD versions include sockstat; alternative approaches below.


Alternative Network Tools

1
2
3
4
5
6
7
8
# Show active connections with netstat
netstat -an

# List 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 pkgsrc: pkgin install 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 NetBSD.

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

Commands:

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

# Continue execution
continue

# Show registers
show registers

ยฒ Requires kernel recompilation with DDB support.


kgdb โ€“ Kernel Debuggerยณ

Used for debugging the running kernel or crash dumps.

1
2
# Analyze core dump
kgdb /netbsd /var/crash/netbsd.core

ยณ Requires kernel debugging enabled and proper setup.


๐Ÿงพ Summary Table

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

๐Ÿง  Best Practices

โœ… Use ktrace/kdump for native kernel-level tracing โœ… 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