Menu

#942 Monitor watch

v3.1
open
nobody
None
Monitor
2024-08-17
2017-10-03
robozz
No

This command does some strange things:

.C:1000  78          SEI
.C:1001  EE 20 D0    INC $D020
.C:1004  AD 20 D0    LDA $D020
.C:1007  4C 01 10    JMP $1001

(C:$1011) watch d020
WATCH: 1  C:$d020  (Stop on load store)
(C:$1011) sw reset
Stopwatch reset to 0.
(C:$1011) g 1000
#1 (Stop on  load d020)  000 011
.C:1001  EE 20 D0    INC $D020      - A:00 X:00 Y:0A SP:f
3 N.-..I..         10
.C:1004  AD 20 D0    LDA $D020      - A:00 X:00 Y:0A SP:f
3 N.-..I..         10
(C:$1004) x
#1 (Stop on store d020)  000 011
.C:1001  EE 20 D0    INC $D020      - A:00 X:00 Y:0A SP:f
3 N.-..I..         10
.C:1004  AD 20 D0    LDA $D020      - A:00 X:00 Y:0A SP:f
3 N.-..I..         10

notice how it breaks on INC $D020 (load and store) correctly, but doesn't break on LDA $D020 (load) ?
It almost seems like this bug https://sourceforge.net/p/vice-emu/bugs/221/ hasn't been fixed properly,
and also notice how two lines are displayed when there should only be one line?

Discussion

  • gpz

    gpz - 2017-10-04

    strange indeed that it doesn't break on the LDA - thats a bug

    however, it is correct that the INC throws two (actually three) lines - what the INC does is a load, then a dummy store (original value), then a store (new value), and the monitor reflects that.

     
  • robozz

    robozz - 2017-10-05

    single stepping shows some interesting things:

    .C:1000  78          SEI
    .C:1001  EE 20 D0    INC $D020
    .C:1004  AD 20 D0    LDA $D020
    .C:1007  60          RTS
    
    (C:$1011) break 1000
    BREAK: 1  C:$1000  (Stop on exec)
    (C:$1011) watch d020
    WATCH: 2  C:$d020  (Stop on load store)
    
    (C:$1004) x
    #1 (Stop on  exec 1000)  052 018
    .C:1000  78          SEI            - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632270
    (C:$1000) z
    .C:1001  EE 20 D0    INC $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632272
    (C:$1001) z
    .C:1004  AD 20 D0    LDA $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632278
    (C:$1004) z
    #2 (Stop on  load d020)  052 026
    .C:1001  EE 20 D0    INC $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632278
    .C:1004  AD 20 D0    LDA $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632278
    (C:$1004) z
    #2 (Stop on store d020)  052 026
    .C:1001  EE 20 D0    INC $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632278
    .C:1004  AD 20 D0    LDA $D020      - A:F1 X:00 Y:00 SP:f7 N.-B.I..   16632278
    (C:$1004) z
    .C:1007  60          RTS            - A:F2 X:00 Y:00 SP:f7 N.-B.I..   16632282
    

    from what I can tell it misses the LDA $D020 because break on load/store breaks on the line after (the PC is at $1004 when the load/store break happens), so the question is then why it does that.

     
  • robozz

    robozz - 2018-07-21

    Found two more variations of this bug:

    .C:1000 78 SEI
    .C:1001 A9 00 LDA #$00
    .C:1003 8D 20 D0 STA $D020
    .C:1006 EE 02 10 INC $1002
    .C:1009 60 RTS

     (C:$1011) break 1000 1fff
     BREAK: 1  C:$1000-$1fff  (Stop on exec)
     (C:$1011) watch 1000 1fff
     WATCH: 2  C:$1000-$1fff  (Stop on load store)
    

    this should now break on $1000, $1001, $1003, $1006, $1009 (exec) and twice on $1002 (load and store) but...

    sys4096 ->
    
    #1 (Stop on  exec 1000)  170 047
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    (C:$1000) x
    #2 (Stop on  load 1004)  170 047
    .C:e144  6C 14 00    JMP ($0014)    - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    #2 (Stop on  load 1003)  170 047
    .C:e144  6C 14 00    JMP ($0014)    - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    #2 (Stop on  load 1002)  170 047
    .C:e144  6C 14 00    JMP ($0014)    - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    #2 (Stop on  load 1001)  170 047
    .C:e144  6C 14 00    JMP ($0014)    - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    #2 (Stop on  load 1000)  170 047
    .C:e144  6C 14 00    JMP ($0014)    - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-.....   24679037
    (C:$1000) x
    #1 (Stop on  exec 1001)  170 049
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    (C:$1001) x
    #2 (Stop on  load 1005)  170 049
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    #2 (Stop on  load 1004)  170 049
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    #2 (Stop on  load 1003)  170 049
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    #2 (Stop on  load 1002)  170 049
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    #2 (Stop on  load 1001)  170 049
    .C:1000  78          SEI            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..I..   24679039
    (C:$1001) x
    #1 (Stop on  exec 1003)  170 051
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    (C:$1003) x
    #2 (Stop on  load 1007)  170 051
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    #2 (Stop on  load 1006)  170 051
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    #2 (Stop on  load 1005)  170 051
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    #2 (Stop on  load 1004)  170 051
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    #2 (Stop on  load 1003)  170 051
    .C:1001  A9 00       LDA #$00       - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679041
    (C:$1003) x
    #1 (Stop on  exec 1006)  170 055
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    (C:$1006) x
    #2 (Stop on  load 100a)  170 055
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    #2 (Stop on  load 1009)  170 055
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    #2 (Stop on  load 1008)  170 055
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    #2 (Stop on  load 1007)  170 055
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    #2 (Stop on  load 1006)  170 055
    .C:1003  8D 20 D0    STA $D020      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..IZ.   24679045
    (C:$1006) x
    #1 (Stop on  exec 1009)  170 061
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    (C:$1009) x
    #2 (Stop on  load 100d)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    #2 (Stop on  load 100c)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    #2 (Stop on  load 100b)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    #2 (Stop on  load 100a)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    #2 (Stop on  load 1009)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    #2 (Stop on  load 1002)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    (C:$1009) x
    #2 (Stop on store 1002)  170 061
    .C:1006  EE 02 10    INC $1002      - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-..I..   24679051
    (C:$1009) x
    #2 (Stop on  load 100c)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 100b)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 100a)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 1009)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 100a)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 1009)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 1008)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 1007)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    #2 (Stop on  load 1006)  171 004
    .C:1009  60          RTS            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    .C:e147  08          PHP            - A:00 X:00 Y:00 SP:f9 ..-..I..   24679057
    

    the other monitor watch bug happens when branching across a page boundary:

    .C:0fff 60 RTS
    .C:1000 78 SEI
    .C:1001 A9 00 LDA #$00
    .C:1003 F0 FA BEQ $0FFF

     #2 (Stop on  load 10ff)  213 045
    .C:1003  F0 FA       BEQ $0FFF      - A:00 X:00 Y:00 SP:f7 ..-B.IZ.  468946556
    .C:0fff  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-B.IZ.  468946556
    
     
    • Ingo Korb

      Ingo Korb - 2018-07-21

      On 21.07.2018 23:15, robozz wrote:

      the other monitor watch bug happens when branching across a page boundary:

      .C:0fff 60 RTS
      .C:1000 78 SEI
      .C:1001 A9 00 LDA #$00
      .C:1003 F0 FA BEQ $0FFF

       #2 (Stop on  load 10ff)  213 045
      .C:1003  F0 FA       BEQ $0FFF      - A:00 X:00 Y:00 SP:f7 ..-B.IZ.  468946556
      .C:0fff  60          RTS            - A:00 X:00 Y:00 SP:f7 ..-B.IZ.  468946556
      

      This is not a bug, the monitor correctly triggers on the read access at
      $10FF generated by the CPU during the branch instruction.

      A real 6502 only has an 8 bit ALU to calculate the target address, so it
      needs an additional cycle due to the underflow and during that cycle the
      partial result is visible on the address bus.

      -ik

       
  • gpz

    gpz - 2021-10-26

    Checked a bit, it looks like part of the issue is solved - and the confusion about the dummy accesses is removed by having it optional (using the "dummy" command)

    however, there still is some strange behaviour - when singlestepping it looks like watchpoints trigger too late (as seen in the original post).

    my guess is that the reason is that the watchpoint breaks into the monitor "before the next instruction" instead of "after the current instruction"

     
  • dqh

    dqh - 2021-10-30
    (C:$e5cd) a 1000
    .1000  SEI
    .1001  INC D020
    .1004  LDA D020
    .1007  JMP 1001
    .100a  
    (C:$100a) watch D020
    WATCH: 1  C:$d020  (Stop on load store)
    (C:$100a) sw reset
    Stopwatch reset to 0.
    (C:$100a) g 1000
    #1 (Stop on  load d020)  121/$079,  12/$0c
    .C:1001  EE 20 D0    INC $D020      - A:00 X:00 Y:0A SP:f3 N.-..I..         10
    (C:$1004) x
    #1 (Stop on store d020)  121/$079,  12/$0c
    .C:1001  EE 20 D0    INC $D020      - A:00 X:00 Y:0A SP:f3 N.-..I..         10
    (C:$1004) x
    #1 (Stop on  load d020)  121/$079,  16/$10
    .C:1004  AD 20 D0    LDA $D020      - A:FF X:00 Y:0A SP:f3 N.-..I..         14
    (C:$1007) x
    #1 (Stop on  load d020)  121/$079,  25/$19
    .C:1001  EE 20 D0    INC $D020      - A:FF X:00 Y:0A SP:f3 ..-..IZ.         23
    (C:$1004) x
    #1 (Stop on store d020)  121/$079,  25/$19
    .C:1001  EE 20 D0    INC $D020      - A:FF X:00 Y:0A SP:f3 ..-..IZ.         23
    (C:$1004) x
    #1 (Stop on  load d020)  121/$079,  29/$1d
    .C:1004  AD 20 D0    LDA $D020      - A:F0 X:00 Y:0A SP:f3 N.-..I..         27
    (C:$1007) disable 1
    (C:$1007) break 1007
    BREAK: 2  C:$1007  (Stop on exec)
    (C:$1007) x
    #2 (Stop on  exec 1007)  121/$079,  42/$2a
    .C:1007  4C 01 10    JMP $1001      - A:F1 X:00 Y:0A SP:f3 N.-..I..         40
    (C:$1007) 
    

    I'm coming at this fresh. So, with the attached patch_1.diff against r41011, I've fixed the weird double output. I haven't committed it yet because i'm not sure what things to test to make sure it's not breaking something else. I'm also not sure I understand what else is wrong here.

    But - there is something a bit weird. When it breaks on a load/store within the instruction, the command prompt lists the address of the next instruction, not the currently executing instruction. However, when it breaks on execution of a particular address, then the prompt shows the address of the instruction about to execute. Is that what we want?

     
  • gpz

    gpz - 2021-10-30

    When it breaks on a load/store within the instruction, the command prompt lists the address of the next instruction, not the currently executing instruction. However, when it breaks on execution of a particular address, then the prompt shows the address of the instruction about to execute. Is that what we want?

    can you give an example? I think what we want is

    • the logged instruction is always the one that caused the breakpoint to trigger
    • the prompt shows the address following that instruction (ie the address of the next instruction)

    also, dont forget to test with both "x" and "z" given the original examples - there might be subtle differences

     
    • dqh

      dqh - 2021-10-30

      My post includes examples - prompt is 1004 rather than 1001 when it breaks on watching d020:

      #1 (Stop on  load d020)  121/$079,  12/$0c
      .C:1001  EE 20 D0    INC $D020      - A:00 X:00 Y:0A SP:f3 N.-..I..         10
      (C:$1004)
      

      but if i used a regular break on 1007, the prompt shows 1007:

      (C:$1007) break 1007
      BREAK: 2  C:$1007  (Stop on exec)
      (C:$1007) x
      #2 (Stop on  exec 1007)  121/$079,  42/$2a
      .C:1007  4C 01 10    JMP $1001      - A:F1 X:00 Y:0A SP:f3 N.-..I..         40
      (C:$1007) 
      
       
  • Greg King

    Greg King - 2021-10-31

    It's the disassembly, not the prompt, that's different. The prompt always shows the PC register, which anticipates the next instruction. Your first example disassembles the current instruction, while your second example disassembles the next instruction,

     
    • dqh

      dqh - 2021-10-31

      Actually, I recently learned that the prompt doesn't show PC, it shows the address that will be used for the next monitor command if an address is not supplied. This should illustrate:

      (C:$e5d1) d e5d1 e5e0
      .C:e5d1  8D 92 02    STA $0292
      .C:e5d4  F0 F7       BEQ $E5CD
      .C:e5d6  78          SEI
      .C:e5d7  A5 CF       LDA $CF
      .C:e5d9  F0 0C       BEQ $E5E7
      .C:e5db  A5 CE       LDA $CE
      .C:e5dd  AE 87 02    LDX $0287
      .C:e5e0  A0 00       LDY #$00
      (C:$e5e2) z
      .C:e5d4  F0 F7       BEQ $E5CD      - A:00 X:00 Y:0A SP:f3 ..-...Z.    3802119
      (C:$e5d4) 
      

      Note the prompt (C:$e5e2), showing the address of the next instruction after the output of the d command - not PC. Then the z command executes e5d1, and shows e5d4 as the next address of interest. So in light of that, the output I posted makes sense. It's also not the case in my example above that PC == 1004 - it's not finished executing the instruction at 1001.

       
      • dqh

        dqh - 2021-10-31

        here's a better illustration:

        (C:$e5d1) d
        .C:e5d1  8D 92 02    STA $0292
        .C:e5d4  F0 F7       BEQ $E5CD
        <snip>
        .C:e5fe  C9 0D       CMP #$0D
        .C:e600  D0 C8       BNE $E5CA
        (C:$e602) d
        .C:e602  A4 D5       LDY $D5
        .C:e604  84 D0       STY $D0
        <snip>
        .C:e62c  C5 C8       CMP $C8
        .C:e62e  90 0A       BCC $E63A
        (C:$e630) z
        .C:e5d4  F0 F7       BEQ $E5CD      - A:00 X:00 Y:0A SP:f3 ..-...Z.    2869152
        (C:$e5d4) 
        
         
  • gpz

    gpz - 2024-08-17

    So, as a first step to get these things under control i knocked up the beginning of a test bench for the monitor: https://sourceforge.net/p/vice-emu/code/HEAD/tree/testprogs/Monitor/testbench/
    Refer to the included readme for details, how to add tests etc. Obviously more tests would be good, so feel free to provide some :)

    As for this ticket:

    • i believe the original issue was fixed already in 3.8
    • i am not sure what issue(s) the follow up posts actually bring up, those need to be reviewed (perhaps not by me) and missing tests should be created.
    • for new issues, new tickets should be opened - and then this ticket can be closed eventually
     

Log in to post a comment.

MongoDB Logo MongoDB