Florin-Popescu / avarice-unofficial

AVaRICE with support for newer devices
GNU General Public License v2.0
13 stars 8 forks source link

UPDI data breakpoint(s)? #12

Closed urjaman closed 11 months ago

urjaman commented 11 months ago

Okay, so, i added support for attiny3217, and the first thing i tried to do was to watch a global 8-bit variable and run, like this:

[urjaman@veyron bikeoledsw]$ ~/avr-tools8/bin/avr-gdb bikeoled.out 
GNU gdb (GDB) 13.0.50.20221120-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=armv7l-unknown-linux-gnueabihf --target=avr".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from bikeoled.out...
(gdb) target remote :4242
Remote debugging using :4242
0x00000000 in __vectors ()
(gdb) watch pulses_per_rotation
Hardware watchpoint 1: pulses_per_rotation
(gdb) continue
Continuing.
Remote connection closed
(gdb) 

Meanwhile avarice reported this:

[urjaman@veyron bikeoledsw]$ ~/avr-tools8/bin/avarice -d -4 -u -P attiny3217 :4242 
AVaRICE version 2.14svn20200906, Jul 21 2023 23:07:55

Found HID PID:VID 0x03eb:0x2141, serno J41800058896
Probing for HID max. packet size
Setting max. packet size to 512 from DAP_Info
HID thread started
JTAG config starting.

command "sign-on" [0x01, 0x10]
0E 00 00 00 01 10 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x00
read:  0e 00 00 01 80 00

Got message seqno 0 (command_sequence == 0)
response: 01 80 00 

command "get info (serial number)" [0x00, 0x00]
0E 00 01 00 00 00 00 81 
Received 0x81 0x11 0x00 0x12 0x0e 0x01
read:  0e 01 00 00 81 00 4a 34 31 38 30 30 30 35 38 38 39 36

Got message seqno 1 (command_sequence == 1)
response: 00 81 00 4A 34 31 38 30 30 30 35 38 38 39 36 
Found a device, serial number: J41800058896

command "get parameter" [0x01, 0x02]
0E 00 02 00 01 02 00 00 00 05 
Received 0x81 0x11 0x00 0x0c 0x0e 0x02
read:  0e 02 00 01 84 01 00 01 29 89 00 00

Got message seqno 2 (command_sequence == 2)
response: 01 84 01 00 01 29 89 00 00 
ICE hardware version: 0
ICE firmware version: 1.41 (rel. 137)

command "set parameter" [0x12, 0x01]
0E 00 03 00 12 01 00 00 00 01 05 
Received 0x81 0x11 0x00 0x06 0x0e 0x03
read:  0e 03 00 12 80 00

Got message seqno 3 (command_sequence == 3)
response: 12 80 00 

command "set parameter" [0x12, 0x01]
0E 00 04 00 12 01 00 00 01 01 02 
Received 0x81 0x11 0x00 0x06 0x0e 0x04
read:  0e 04 00 12 80 00

Got message seqno 4 (command_sequence == 4)
response: 12 80 00 

command "set parameter" [0x12, 0x01]
0E 00 05 00 12 01 00 01 00 01 08 
Received 0x81 0x11 0x00 0x06 0x0e 0x05
read:  0e 05 00 12 80 00

Got message seqno 5 (command_sequence == 5)
response: 12 80 00 

command "set parameter" [0x12, 0x01]
0E 00 06 00 12 01 00 02 00 08 00 40 80 40 00 10 80 0F 
Received 0x81 0x11 0x00 0x06 0x0e 0x06
read:  0e 06 00 12 80 00

Got message seqno 6 (command_sequence == 6)
response: 12 80 00 

command "AVR sign-on" [0x12, 0x10]
0E 00 07 00 12 10 00 00 
Received 0x81 0x11 0x00 0x0b 0x0e 0x07
read:  0e 07 00 12 84 00 74 69 6e 79 00

Got message seqno 7 (command_sequence == 7)
response: 12 84 00 74 69 6E 79 00 
AVR sign-on responded with tiny
Automatic device detection: jtagRead 
command "enter progmode" [0x12, 0x15]
0E 00 08 00 12 15 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x08
read:  0e 08 00 12 80 00

Got message seqno 8 (command_sequence == 8)
response: 12 80 00 

command "read memory" [0x12, 0x21]
0E 00 09 00 12 21 00 B4 00 11 00 00 03 00 00 00 
Received 0x81 0x11 0x00 0x0a 0x0e 0x09
read:  0e 09 00 12 84 00 1e 95 22 00

Got message seqno 9 (command_sequence == 9)
response: 12 84 00 1E 95 22 00 

command "leave progmode" [0x12, 0x16]
0E 00 0A 00 12 16 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x0a
read:  0e 0a 00 12 80 00

Got message seqno 10 (command_sequence == 10)
response: 12 80 00 
Reported device ID: 0x9522
Looking for device: attiny3217
Configured for device ID: 0x9522 attiny3217 -- Matched with attiny3217

command "set parameter" [0x12, 0x01]
0E 00 0B 00 12 01 00 02 00 08 00 80 80 40 00 10 80 0F 
Received 0x81 0x11 0x00 0x06 0x0e 0x0b
read:  0e 0b 00 12 80 00

Got message seqno 11 (command_sequence == 11)
response: 12 80 00 
JTAG config complete.
Preparing the target device for On Chip Debugging.

command "set parameter" [0x12, 0x01]
0E 00 0C 00 12 01 00 03 00 01 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x0c
read:  0e 0c 00 12 80 00

Got message seqno 12 (command_sequence == 12)
response: 12 80 00 

command "reset" [0x12, 0x30]
0E 00 0D 00 12 30 00 01 
Received 0x81 0x11 0x00 0x06 0x0e 0x0d
read:  0e 0d 00 12 80 00

Got message seqno 13 (command_sequence == 13)
response: 12 80 00 
read:  0e 00 02 00 12 40 00 00 00 00 01 84 00 30
Event serial 0x0002
caching PC: 0x0000
Waiting for connection on port 4242.
Connection opened by host 127.0.0.1, port 40962.
GDB: <qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+;memory-tagging+>
->GDB: PacketSize=40;qXfer:memory-map:read+
GDB: <vMustReplyEmpty>
->GDB: 
GDB: <Hg0>
->GDB: 
GDB: <qTStatus>
->GDB: 
GDB: <?>
->GDB: S05
GDB: <qfThreadInfo>
->GDB: 
GDB: <qL1020000000000000000>
->GDB: 
GDB: <Hc-1>
->GDB: 
GDB: <qC>
->GDB: 
GDB: <qAttached>
->GDB: 
GDB: <qOffsets>
->GDB: 
GDB: <g>

GDB: (Registers)Read 32 bytes from 0x800000
jtagRead 
command "read memory" [0x12, 0x21]
0E 00 0E 00 12 21 00 20 00 00 00 00 20 00 00 00 
Received 0x81 0x11 0x00 0x27 0x0e 0x0e
read:  0e 0e 00 12 84 00 00 00 7e 00 00 00 03 00 00 00 3f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Got message seqno 14 (command_sequence == 14)
response: 12 84 00 00 00 7E 00 00 00 03 00 00 00 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
jtagRead 
command "read memory" [0x12, 0x21]
0E 00 0F 00 12 21 00 20 5D 00 00 00 03 00 00 00 
Received 0x81 0x11 0x00 0x0a 0x0e 0x0f
read:  0e 0f 00 12 84 00 00 00 00 00

Got message seqno 15 (command_sequence == 15)
response: 12 84 00 00 00 00 00 

command "read PC" [0x12, 0x35]
0E 00 10 00 12 35 00 
Received 0x81 0x11 0x00 0x0a 0x0e 0x10
read:  0e 10 00 12 83 00 00 00 00 00

Got message seqno 16 (command_sequence == 16)
response: 12 83 00 00 00 00 00 
PC = 0
->GDB: 00007e000000030000003f00000000000000000000000000000000000000000000000000000000
GDB: <qL1020000000000000000>
->GDB: 
GDB: <qSymbol::>
->GDB: 
GDB: <qXfer:memory-map:read::0,3b>
->GDB: l<memory-map>
  <memory type="ram" start="0x800000" length="0x20000" />
  <memory type="flash" start="0" length="0x8000">
     <property name="blocksize">0x80</property>
  </memory>
</memory-map>

GDB: <m803801,1>

GDB: Read 1 bytes from 0x803801
jtagRead 
command "read memory" [0x12, 0x21]
0E 00 11 00 12 21 00 20 01 38 00 00 01 00 00 00 
Received 0x81 0x11 0x00 0x08 0x0e 0x11
read:  0e 11 00 12 84 00 07 00

Got message seqno 17 (command_sequence == 17)
response: 12 84 00 07 00 
->GDB: 07
GDB: <m803801,1>

GDB: Read 1 bytes from 0x803801
jtagRead 
command "read memory" [0x12, 0x21]
0E 00 12 00 12 21 00 20 01 38 00 00 01 00 00 00 
Received 0x81 0x11 0x00 0x08 0x0e 0x12
read:  0e 12 00 12 84 00 07 00

Got message seqno 18 (command_sequence == 18)
response: 12 84 00 07 00 
->GDB: 07
GDB: <Z2,803801,1>
BP ADD type: 2  addr: 0x803801 ->GDB: OK
GDB: <vCont?>
->GDB: 
GDB: <Hc0>
->GDB: 
GDB: <c>
Breakpoint added in ICE. slot: 2  type: 2  addr: 0x803801

command "set BP" [0x12, 0x40]
0E 00 13 00 12 40 00 02 02 01 38 00 00 01 
Received 0x81 0x11 0x00 0x07 0x0e 0x13
read:  0e 13 00 12 a0 00 80

Got message seqno 19 (command_sequence == 19)
response: 12 A0 00 80 
Failed to set breakpoint: Unknown response code 0x80

command "stop debugging" [0x12, 0x14]
0E 00 14 00 12 14 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x14
read:  0e 14 00 12 80 00

Got message seqno 20 (command_sequence == 20)
response: 12 80 00 

command "AVR sign-off" [0x12, 0x11]
0E 00 15 00 12 11 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x15
read:  0e 15 00 12 80 00

Got message seqno 21 (command_sequence == 21)
response: 12 80 00 

command "sign-off" [0x01, 0x11]
0E 00 16 00 01 11 00 
Received 0x81 0x11 0x00 0x06 0x0e 0x16
read:  0e 16 00 01 80 00

Got message seqno 22 (command_sequence == 22)
response: 01 80 00 

That EDBG documentation lists that response as AVR8_FAILURE_ILLEGAL_BREAKPOINT

so I'm assuming UPDI just can't do this (or we're doing it wrong)?

The EDBG doc says UPDI supports one breakpoint, but i'm not sure if it can be a data watchpoint, and then, slot=2 sounds wrong... I dont' have the time to investigate further right now, but wanted to just put this out ASAP.

(Meanwhile i'll put the attiny3217 support patch up...)

urjaman commented 11 months ago

The patch is up (and i'm on a train) -- the device datasheet actually says two hardware breakpoints, but makes no mention of data vs code.

urjaman commented 11 months ago

I loaded up that project for debugging in Microchip (ugh) Studio (yeah you can do that, you just need to configure avr-gcc for -gdwarf-2 ...), and tried to set the same data breakpoint:

kuva

I think that answer that, there are no data breakpoints for ATtiny3217. Now i need to investigate how to make avarice expose that properly to gdb..

urjaman commented 11 months ago

So i've figured this stuff out; i'll be reporting the details in a (WIP) PR, no point to leave this dangling, so closing.