diff --git a/contrib/gdb_cmds.gdb b/contrib/gdb_cmds.gdb new file mode 100644 index 0000000..8f0ba8c --- /dev/null +++ b/contrib/gdb_cmds.gdb @@ -0,0 +1,42 @@ +# misc helpers for gdb debugging + +# first run lc3, then +# +# echo 0 | doas tee /proc/sys/kernel/yama/ptrace_scope +# +# to disable security measures that prevent debugging, +# then +# +# rust-gdb -p $(pgrep lc3) +# +# then in the gdb shell +# +# source contrib/gdb_cmds.gdb +# +# you can then use the commands defined here + + +define vmb + # set a breakpoint at VM addr $0 + break lc3::vm::instruction::execute_instruction if vm.registers.pc == $arg0 + 1 + set $vmb_break = $bpnum +end + +define vmj + # jump execution to VM addr $0 + vmb $arg0 + c + d $vmb_break + p vm.registers.pc-1 +end + +define vms + # step in vm with breakpoint $0 + # before this break at the second line in lc3::vm::instruction::execute_instruction + # pass the number of this breakpoint in as $0 + enable $arg0 + c + p opcode + p vm.registers.pc-1 + disable $arg0 +end diff --git a/src/vm/instruction.rs b/src/vm/instruction.rs index 3594e8c..65f67e6 100644 --- a/src/vm/instruction.rs +++ b/src/vm/instruction.rs @@ -276,7 +276,7 @@ fn op_not(vm: &mut VM, instr: u16) { // NOTE // rustc is very friendly and tells you off if you use ~ as bitwise not let res = !vm.registers.get_reg(sr); - vm.registers.set_reg_with_cond(sr, res); + vm.registers.set_reg_with_cond(dr, res); } ////////////////