TechLang includes a powerful debugger that lets you pause execution, inspect state, and step through code to understand what your program is doing.
The debugger provides several commands to help you track down bugs and understand program flow:
- Breakpoints: Pause execution at specific points
- Stepping: Execute one command at a time
- Inspection: View detailed state information
- Watching: Monitor specific variables
Use breakpoint to mark a point where execution should pause:
set x 10
breakpoint # Execution will pause here
set x 20
Enable step mode to pause after each command:
step # Enable step mode
set x 5
set y 10 # Will pause after each command
add x y
Use inspect to see detailed information about your program's current state:
set counter 0
set max 100
array_create data 5
dict_create config
inspect # Shows all state information
The inspect command displays:
- Current command number
- Stack contents
- Current value
- Variables (all or watched only)
- Arrays (names)
- Strings (names)
- Dictionaries (names)
- Active breakpoints
- Debug mode status
Monitor specific variables to see their values in inspect output:
set x 0
watch x # Add x to watch list
loop 10
add x 1
end
inspect # Shows watched variables
unwatch x # Remove from watch list
Resume from a paused state:
continue # Resume execution
Remove all breakpoints:
clear_breakpoints # Removes all breakpoints
Here's a complete debugging session:
# Enable watching
watch total
watch count
# Set initial values
set total 0
set count 0
# Set breakpoint before loop
breakpoint
# Process items
loop 5
add count 1
add total count
inspect # Check state each iteration
end
# Final inspection
print "Final values:"
inspect
# Cleanup
unwatch total
unwatch count
clear_breakpoints
def calculate_average
set sum 0
set count 0
watch sum
watch count
loop 5
add sum count
add count 1
inspect # Check accumulation
end
div sum count
end
call calculate_average
set x 10
watch x
# Multiple operations
mul x 2 # x = 20
add x 5 # x = 25
sub x 3 # x = 22
inspect # See final value
set i 0
watch i
breakpoint # Stop before loop
loop 10
add i 1
inspect # Check each iteration
end
def process_data
set result 0
watch result
# Complex calculation
set result 100
mul result 2
inspect # Check intermediate state
end
call process_data
def worker
set value 0
watch value
loop 5
add value 10
end
inspect
end
thread_create worker
thread_join 1
watch line_count
set line_count 0
file_read "data.txt" content
breakpoint # Pause before processing
str_length content
inspect
watch record_count
set record_count 0
db_select "users" "name"
inspect # Check query results
The debugger tracks each command executed with a counter. This helps you:
- Identify where breakpoints are set
- Track execution progress
- Correlate debug output with code position
set x 1 # Command #1
set y 2 # Command #2
breakpoint # Sets at #3
add x y # Command #4
inspect # Shows command count
- Use watches for key variables: Don't watch everything, focus on what matters
- Strategic breakpoints: Set breakpoints before complex sections
- Inspect frequently: Check state at decision points
- Clean up: Remove watches and breakpoints when done
- Step carefully: Use step mode for tricky bugs
- Document findings: Add comments explaining what you discovered
- Breakpoints are per-command, not per-line in source file
- Step mode pauses after each command (can be verbose)
- Watched variables shown in inspect, not on each change
- No time-travel debugging (yet!)
boot
print "=== Debugging Session ==="
# Setup
watch x
watch y
watch result
# Initialize
set x 10
set y 20
set result 0
# Checkpoint 1
breakpoint
inspect
# Calculate
add result x
add result y
# Checkpoint 2
breakpoint
inspect
# Process
mul result 2
# Final check
inspect
# Cleanup
unwatch x
unwatch y
unwatch result
clear_breakpoints
crash
See also:
- Control Flow - For understanding execution order
- Data Types - For working with inspected data
- Examples - For complete debugging examples