1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# Easily save breakpoints to and restore from a file
proc get_breakpoints_dir {} {
set path [file normalize $::env(OPENMSX_USER_DATA)/../breakpoints]
file mkdir $path
return $path
}
namespace eval breakpoints {
proc fix_extension {filename} {
expr {[string match *.breakpoints $filename] ? $filename : "$filename.breakpoints"}
}
proc fix_filename {filename} {
file join [get_breakpoints_dir] [fix_extension $filename]
}
proc get_breakpoints_dir_help {args} {
return \
{get_breakpoints_dir
Return breakpoint directory for this user.
}}
set_help_proc get_breakpoints_dir breakpoints::get_breakpoints_dir_help
proc save_breakpoints_help {args} {
return \
{save_breakpoints <filename>
Save all breakpoint subtypes (breakpoints, watchpoint, conditions) to a given file.
}}
set_help_proc save_breakpoints breakpoints::save_breakpoints_help
proc load_breakpoints_help {args} {
return \
{load_breakpoints <filename>
Load all breakpoint subtypes (breakpoints, watchpoints and conditions) from a given file.
}}
set_help_proc load_breakpoints breakpoints::load_breakpoints_help
}
proc save_breakpoints {filename} {
set fh [open [breakpoints::fix_filename $filename] "w"]
foreach type {breakpoint watchpoint condition} {
puts $fh "\[$type\]\n[join [dict values [debug $type list]] \n]\n"
}
close $fh
}
proc load_breakpoints {filename} {
foreach type {breakpoint watchpoint condition} {
set existing_bps($type) [dict values [debug $type list]]
}
set section {}
set fh [open [breakpoints::fix_filename $filename] "r"]
foreach line [split [read -nonewline $fh] \n] {
set line [string trim $line]
# load valid file section only
if {[regexp {^\[([^\]]+)\]$} $line -> section]} continue
if {!($section in {breakpoint watchpoint condition})} continue
# compare and create breakpoints if not found
if {$line eq {} || $line in $existing_bps($section)} continue
debug $section create {*}$line
}
close $fh
}
|