* * *

Author Topic: Debugging AVR over debugWIRE using dwire-debug  (Read 2813 times)

ccrause

  • Full Member
  • ***
  • Posts: 129
Debugging AVR over debugWIRE using dwire-debug
« on: March 21, 2018, 11:04:45 am »
I've tested dwire-debug, a simple debugWIRE implementation which uses  a serial connection that supports custom BAUD rates and a simple diode to communicate with AVR hardware.  A very simple and cheap way to perform on-chip debugging.

I've tested the debugging capability with an interrupt driven blink demo on a tiny45:
Code: Pascal  [Select]
  1. program blink;
  2.  
  3. uses intrinsics;
  4.  
  5. const
  6.   LEDpin = 1 shl 4;
  7.   countsPerSecond = ((F_CPU div 1024) + 128) div 256;  // Hz
  8.   CS00msk = 1 shl 0;
  9.   CS02msk = 1 shl 2;
  10.   TOIE0msk = 1 shl 1;
  11.  
  12. var
  13.   LEDport: byte absolute PORTB;
  14.   LEDdir: byte absolute DDRB;
  15.   i: byte = 1;
  16.  
  17. procedure Timer0Overflow; alias: 'TIMER0_OVF_ISR'; interrupt;
  18. begin
  19.   inc(i);
  20.   if i > countsPerSecond then
  21.   begin
  22.     LEDport := LEDport xor LEDpin;
  23.     i := 0;
  24.   end;
  25. end;
  26.  
  27. begin
  28.   LEDdir := LEDdir or LEDpin;  // Set pin to output
  29.   LEDport := LEDport or LEDpin; // Set LED high
  30.   TCCR0A := 0;
  31.   TCCR0B := CS02msk or CS00msk;  // clock prescaler = 1024
  32.   // enable timer1 overflow interrupt
  33.   TIMSK := TOIE0msk;
  34.   avr_sei;
  35.   while True do;
  36. end.
  37.  

Procedure:
  • Enable DWEN fuse using ISP.  Note this disables the ISP interface, but can be restored over debugWIRE.
  • Download and make dwire-debug.  Optionally implement this fix to remove an annoying popup in Lazarus when stopping at a breakpoint during debugging.
  • Start dwire-debug as follows:
Code: [Select]
./dwdebug device <serial port>, gdbserver, qrThis will start dwire-debug, connect to the serial port, start the gdb server and when the debug session is finished (Ctrl-F2) exit dwire-debug and continue running on the target.
  • Configure Lazarus for remote debugging with avr-gdb.  Set port to 4444.
  • Compile project in Lazarus.  Place breakpoint in interrupt routine (e.g. line 23).
  • Press run and wait for Lazarus to jump to breakpoint in code.
  • When finished with debugging code, kill session by pressing on stop button or press [Ctrl-F2].
It is quite satisfying to see Lazarus hitting the breakpoint inside the interrupt after about 1 second.

Note that in dwire-debug uses a single hardware breakpoint to avoid writing BREAK instructions in flash.  It is not clear what is done when writing more than one breakpoint, I assume dwire-debug will set the first breakpoint in hardware and the rest must then be written to flash. This will cause wear of the flash, so I suggest one tries to debug with a single breakpoint as far as possible.

avra

  • Hero Member
  • *****
  • Posts: 1366
    • Additional info
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #1 on: March 21, 2018, 05:54:12 pm »
Nice work, although I prefer full JTAG ICE over somewhat limited debugWIRE.  :D ;) :D
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #2 on: March 22, 2018, 02:28:44 pm »
Hi, in my spare time I'm trying to add UART support in the USBasp Firmware.

  And IF/WHEN I'm successful  then I had in mind to try this AVR/Arduino Hardware Debugger on the Cheap for a full blown solution with FPC/Lazarus.
« Last Edit: March 22, 2018, 02:55:44 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Full Member
  • ***
  • Posts: 129
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #3 on: March 22, 2018, 03:40:51 pm »
I had in mind to try this AVR/Arduino Hardware Debugger on the Cheap
Yes, one of the other interesting projects I want to evaluate someday...

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #4 on: March 24, 2018, 12:04:54 pm »
Hi,

  last night I had some free time and tried to use an old avr dragon lying around, avarice 2.12 ( with cygwin and libusb filter ), avr8-gnu-toolchain 3.5.4 (avr-gdb 7.8 ) and FPC/Lazarus ( both trunk ).

  After some hiccups ( and web searching ) I was successful to the point that Lazarus builds the project, starts a custom command bat file for the avarice with args to bridge with the dragon, the hex is uploaded and voila the avr-gdb connects. The avr dragon was connected to a atmega328p on a breadboard using ICSP ( debugwire ) connection.

  But as I saw in the debug window, the commands and most important the command sequence is not suitable for the avr-gdb, ( or I'm simply wrong ).  AFAIU, there is a need for a new class like gdbmiserverdebugger but for the embedded platform.

PS: I can write a detailed tutorial how to set it up, if there is interest.

PS1: I used the patches from the Remote debugging on embedded system fails in Lazarus because no PID is available on remote target.

PS2: Plus, I had to add in gdbmidebugger.pp in line 5036 the following :

Code: Pascal  [Select]
  1.    
  2.     if RequirePID then    <------------ Added this line ...
  3.       if not DoChangeFilename then begin
  4.         SetDebuggerErrorState(synfFailedToLoadApplicationExecutable, FErrorMsg);
  5.         exit;
  6.       end;
  7.     if not DoSetPascal then begin
  8.       SetDebuggerErrorState(synfFailedToInitializeTheDebuggerSetPascalFailed,
  9.         FLastExecResult.Values);
  10.       exit;
  11.     end;

regards.
« Last Edit: March 24, 2018, 12:25:10 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #5 on: March 24, 2018, 12:12:43 pm »
Hi,

Nice work, although I prefer full JTAG ICE over somewhat limited debugWIRE.  :D ;) :D

If the MCU support it ( JTAG that is ) then the setup I described in my previous post works also. The AVR Dragon using the JTAG connection and not the ICSP connection.

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Full Member
  • ***
  • Posts: 129
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #6 on: March 24, 2018, 02:00:19 pm »
But as I saw in the debug window, the commands and most important the command sequence is not suitable for the avr-gdb, ( or I'm simply wrong ).  AFAIU, there is a need for a new class like gdbmiserverdebugger but for the embedded platform.
Perhaps show the debug output (or read this to see how you can enable IDE logging with lots of detail).  There is a chance that something simple is messing up.  I've managed to debug with avr-gdb connected to simavr and now dwire-debug.  Note that avr-gdb also needs a patch to correctly translate addresses.
Quote
PS: I can write a detailed tutorial how to set it up, if there is interest.
Please do.  You can either add a section to the existing remote debugging page or create your own page and just add a link to this page.

Quote
PS1: I used the patches from the Remote debugging on embedded system fails in Lazarus because no PID is available on remote target.
That is the only Lazarus patch I need to debug with avr-gdb.

Quote
PS2: Plus, I had to add in gdbmidebugger.pp in line 5036 the following :

Code: Pascal  [Select]
  1.    
  2.     if RequirePID then    <------------ Added this line ...
  3.       if not DoChangeFilename then begin
  4.         SetDebuggerErrorState(synfFailedToLoadApplicationExecutable, FErrorMsg);
  5.         exit;
  6.       end;
  7.     if not DoSetPascal then begin
  8.       SetDebuggerErrorState(synfFailedToInitializeTheDebuggerSetPascalFailed,
  9.         FLastExecResult.Values);
  10.       exit;
  11.     end;
What debugging error lead you to suspect the DoChangeFilename statement?

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #7 on: March 24, 2018, 05:18:50 pm »
Hi,

But as I saw in the debug window, the commands and most important the command sequence is not suitable for the avr-gdb, ( or I'm simply wrong ).  AFAIU, there is a need for a new class like gdbmiserverdebugger but for the embedded platform.
Perhaps show the debug output (or read this to see how you can enable IDE logging with lots of detail).  There is a chance that something simple is messing up.  I've managed to debug with avr-gdb connected to simavr and now dwire-debug.

Assuming initialization

Code: Pascal  [Select]
  1. [TCmdLineDebugger] Debug PID: 1956
  2. << TCmdLineDebugger.ReadLn "=thread-group-added,id="i1""
  3. << TCmdLineDebugger.ReadLn "(gdb) "
  4. Executing (Recurse-Count=0) queued= 0 CmdPrior=0 CmdMinRunLvl=-1 : "TGDBMIServerDebuggerCommandInitDebugger" State=dsNone PauseWaitState=0
  5.   >> TCmdLineDebugger.SendCmdLn "-gdb-set confirm off"
  6.   << TCmdLineDebugger.ReadLn "^done"
  7.   << TCmdLineDebugger.ReadLn "(gdb) "
  8.   >> TCmdLineDebugger.SendCmdLn "-gdb-set new-console off"
  9.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol table is loaded.  Use the \"file\" command.""
  10.   << TCmdLineDebugger.ReadLn "(gdb) "
  11.   >> TCmdLineDebugger.SendCmdLn "set width 50000"
  12.   << TCmdLineDebugger.ReadLn "&"set width 50000\n""
  13.   << TCmdLineDebugger.ReadLn "=cmd-param-changed,param="width",value="50000""
  14.   << TCmdLineDebugger.ReadLn "^done"
  15.   << TCmdLineDebugger.ReadLn "(gdb) "
  16.   >> TCmdLineDebugger.SendCmdLn "set target-async on"
  17.   << TCmdLineDebugger.ReadLn "&"set target-async on\n""
  18.   << TCmdLineDebugger.ReadLn "=cmd-param-changed,param="mi-async",value="on""
  19.   << TCmdLineDebugger.ReadLn "^done"
  20.   << TCmdLineDebugger.ReadLn "(gdb) "
  21.   >> TCmdLineDebugger.SendCmdLn "show target-async"
  22.   << TCmdLineDebugger.ReadLn "&"show target-async\n""
  23.   << TCmdLineDebugger.ReadLn "~"Whether MI is in asynchronous mode is on.\n""
  24.   << TCmdLineDebugger.ReadLn "^done"
  25.   << TCmdLineDebugger.ReadLn "(gdb) "
  26.   >> TCmdLineDebugger.SendCmdLn "-gdb-version"
  27.   << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 7.8\n""
  28.   << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""
  29.   << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n""
  30.   << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"--host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""
  31.   << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""
  32.   << TCmdLineDebugger.ReadLn "~"<http://www.atmel.com>.\n""
  33.   << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n""
  34.   << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""
  35.   << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""
  36.   << TCmdLineDebugger.ReadLn "^done"
  37.   << TCmdLineDebugger.ReadLn "(gdb) "
  38.   >> TCmdLineDebugger.SendCmdLn "target remote localhost:4242"
  39.   << TCmdLineDebugger.ReadLn "&"target remote localhost:4242\n""
  40.   << TCmdLineDebugger.ReadLn "~"Remote debugging using localhost:4242\n""
  41.   << TCmdLineDebugger.ReadLn "=thread-group-started,id="i1",pid="42000""
  42.   << TCmdLineDebugger.ReadLn "=thread-created,id="1",group-id="i1""
  43.   DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor
  44.   DebugDataMonitor: <<EXIT: TThreadsDlg.ThreadsChanged
  45.   << TCmdLineDebugger.ReadLn "~"0xfffffffe in ?? ()\n""
  46.   << TCmdLineDebugger.ReadLn "*stopped,frame={addr="0xfffffffe",func="??",args=[]},thread-id="1",stopped-threads="all""
  47.   << TCmdLineDebugger.ReadLn "^done"
  48.   << TCmdLineDebugger.ReadLn "(gdb) "
  49. Exec done
  50. Leaving Queue with count: 0 Recurse-Count=0 State=dsNone
  51. >> Run OnIdle
  52.   OnIdle: UnLock
  53. << Run OnIdle
  54. OnIdle: Finished

< sniping a lot of env var's >

Code: Pascal  [Select]
  1. >> TCmdLineDebugger.SendCmdLn "info file"
  2.   << TCmdLineDebugger.ReadLn "&"info file\n""
  3.   << TCmdLineDebugger.ReadLn "~"Symbols from \"G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink\".\n""
  4.   << TCmdLineDebugger.ReadLn "~"Remote serial target in gdb-specific protocol:\n""
  5.   << TCmdLineDebugger.ReadLn "~"Debugging a target over a serial line.\n""
  6.   << TCmdLineDebugger.ReadLn "~"\tWhile running this, GDB does not access memory from...\n""
  7.   << TCmdLineDebugger.ReadLn "~"Local exec file:\n""
  8.   << TCmdLineDebugger.ReadLn "~"\t`G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink', file type elf32-avr.\n""
  9.  << TCmdLineDebugger.ReadLn "~"\tEntry point: 0x0\n""
  10.  << TCmdLineDebugger.ReadLn "~"\t0x00000000 - 0x00000124 is .text\n""
  11.  << TCmdLineDebugger.ReadLn "~"\t0x00800100 - 0x00800102 is .data\n""
  12.  << TCmdLineDebugger.ReadLn "^done"
  13.  << TCmdLineDebugger.ReadLn "(gdb) "
  14.  >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression sizeof(^byte)"
  15.  << TCmdLineDebugger.ReadLn "^done,value="2""
  16.  << TCmdLineDebugger.ReadLn "(gdb) "
  17.  >> TCmdLineDebugger.SendCmdLn "-break-insert -f foo"
  18.  << TCmdLineDebugger.ReadLn "&"Function \"foo\" not defined.\n""
  19.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="foo",times="0",original-location="foo"}"
  20.  << TCmdLineDebugger.ReadLn "(gdb) "
  21.  >> TCmdLineDebugger.SendCmdLn "-break-delete 1"
  22.  << TCmdLineDebugger.ReadLn "^done"
  23.  << TCmdLineDebugger.ReadLn "(gdb) "
  24.  >> TCmdLineDebugger.SendCmdLn "-break-insert main"
  25.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="n",addr="0x00000108",func="$main",file="prjAVRBlink.lpr",fullname="G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink.lpr",line="24",thread-groups=["i1"],times="0",original-location="main"}"
  26.  << TCmdLineDebugger.ReadLn "(gdb) "
  27.  >> TCmdLineDebugger.SendCmdLn "-break-insert +0"
  28.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="3",type="breakpoint",disp="keep",enabled="n",addr="0x00000000",file="avr/avrcommon.inc",fullname="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc",l" ..(92).. "ginal-location="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc:+0"}"
  29.  << TCmdLineDebugger.ReadLn "(gdb) "
  30.  >> TCmdLineDebugger.SendCmdLn "info address main"
  31.  << TCmdLineDebugger.ReadLn "&"info address main\n""
  32.  << TCmdLineDebugger.ReadLn "~"Symbol \"main\" is at 0x104 in a file compiled without debugging.\n""
  33.  << TCmdLineDebugger.ReadLn "^done"
  34.  << TCmdLineDebugger.ReadLn "(gdb) "
  35.  >> TCmdLineDebugger.SendCmdLn "-break-insert *260"
  36.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00800104",thread-groups=["i1"],times="0",original-location="*260"}"
  37.  << TCmdLineDebugger.ReadLn "(gdb) "
  38.  >> TCmdLineDebugger.SendCmdLn "-exec-continue &"
  39.  << TCmdLineDebugger.ReadLn "^running"
  40.  << TCmdLineDebugger.ReadLn "*running,thread-id="all""
  41.  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor
  42.  DebugDataMonitor: <<EXIT: TThreadsDlg.ThreadsChanged
  43.  << TCmdLineDebugger.ReadLn "(gdb) "
  44.  << TCmdLineDebugger.ReadLn "(gdb) "
  45.  >> TCmdLineDebugger.SendCmdLn "-break-delete 2"
  46.  << TCmdLineDebugger.ReadLn "^done"
  47.  << TCmdLineDebugger.ReadLn "(gdb) "
  48.  >> TCmdLineDebugger.SendCmdLn "-break-delete 4"
  49.  << TCmdLineDebugger.ReadLn "^error,msg="Cannot execute this command while the target is running.\nUse the \"interrupt\" command to stop the target\nand then try again.""
  50.  << TCmdLineDebugger.ReadLn "(gdb) "
  51.  

Note that avr-gdb also needs a patch to correctly translate addresses.

I'm on Windows box and I'm trying to use the executable released from the source.

What debugging error lead you to suspect the DoChangeFilename statement?

The same hiccup with the name extension elf you had also. I just didn't want to change the name manual every time ...

PS: This is the program code ( an mcu hello world ;) ) :

Code: Pascal  [Select]
  1. program prjAVRBlink;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. const
  6.   BP1 = 1;      // Pin 1
  7.  
  8.   procedure HW_Delay; alias: 'TIMER2_OVF_ISR'; interrupt; public;
  9.   const
  10.     counter: integer = 0;
  11.     delay = 16000000 div 1024 div 256 div 2;   // 16.000.000Hz / Clock / TCNT / 2 = 0,5 Second
  12.   begin
  13.     inc(counter);
  14.     if counter = delay div 2 then begin
  15.       PORTB := PORTB or (1 shl BP1);      // Port  High
  16.     end;
  17.     if counter >= delay   then begin
  18.       PORTB := PORTB and not (1 shl BP1); // Port Low
  19.       counter := 0;
  20.     end;
  21.   end;
  22.  
  23. begin
  24.   DDRB := DDRB or (1 shl BP1);            // Pin 1 Port Output
  25.  
  26.   TCCR2A := $0;                           // Normal Timer
  27.   TCCR2B := $7;                           // Clock / 1024
  28.   TIMSK2 := (1 shl TOIE2);                // Enable Timer2 overflow interrupt
  29.   asm
  30.     sei                                   // Enable interrupts
  31.   end;
  32.  
  33.   repeat
  34.   until False;
  35. end.
  36.  

with compiler options
Code: Pascal  [Select]
  1.  -Tembedded -Pavr -CpAVR5 -MObjFPC -Scghi -CX -O3 -g -XX -l -vewnhibq -Filib\avr-embedded -Fu. -FUlib\avr-embedded -WpATMEGA328P -dF_CPU:=16000000 -Sm -al

Unfortunately now I'm home sitting in a different box with FPC trunk ( updated 15/3/2018 ) / Lazarus 1.8.1 rev:57130.

regards.
« Last Edit: March 24, 2018, 05:24:37 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Full Member
  • ***
  • Posts: 129
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #8 on: March 24, 2018, 07:18:10 pm »
Code: Pascal  [Select]
  1. >> TCmdLineDebugger.SendCmdLn "info file"
  2.   << TCmdLineDebugger.ReadLn "^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00800104",thread-groups=["i1"],times="0",original-location="*260"}"
  3.   << TCmdLineDebugger.ReadLn "(gdb) "
  4.   >> TCmdLineDebugger.SendCmdLn "-exec-continue &"
  5.   << TCmdLineDebugger.ReadLn "^running"
  6.   << TCmdLineDebugger.ReadLn "*running,thread-id="all""
  7.   DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor
  8.   DebugDataMonitor: <<EXIT: TThreadsDlg.ThreadsChanged
  9.   << TCmdLineDebugger.ReadLn "(gdb) "
  10.   << TCmdLineDebugger.ReadLn "(gdb) "
  11.  
The double (gdb) response above after the -exec-continue & is unexpected, as far as I know gdb should indicate that it is finished with a command by a single (gdb) response.

Below similar output from a debug sessions running in simavr.  Very similar to your log, but there is only a single (gdb) response after -exec-continue &:
Code: [Select]
>> TCmdLineDebugger.SendCmdLn "-break-insert *146"
<< TCmdLineDebugger.ReadLn "^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00000092",func="$main",file="blink.pp",fullname="/home/christo/fpc/fpc-avr/src/examples/blink2/blink.pp",line="35",thread-groups=["i1"],times="0",original-location="*146"}"
<< TCmdLineDebugger.ReadLn "(gdb) "
>> TCmdLineDebugger.SendCmdLn "-exec-continue &"
<< TCmdLineDebugger.ReadLn "^running"
<< TCmdLineDebugger.ReadLn "*running,thread-id="all""
<< TCmdLineDebugger.ReadLn "~"Note: automatically using hardware breakpoints for read-only addresses.\n""
<< TCmdLineDebugger.ReadLn "(gdb) "
<< TCmdLineDebugger.ReadLn "=breakpoint-modified,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00000092",func="$main",file="blink.pp",fullname="/home/christo/fpc/fpc-avr/src/examples/blink2/blink.pp",line="35",thread-groups=["i1"],times="1",original-location="*146"}"
<< TCmdLineDebugger.ReadLn "~"\n""

What version of avr-gdb are you using?

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #9 on: March 24, 2018, 07:55:19 pm »

< snip >

What version of avr-gdb are you using?

It was in the first code post :

Code: Pascal  [Select]
  1.   >> TCmdLineDebugger.SendCmdLn "-gdb-version"
  2.   << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 7.8\n""
  3.   << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""
  4.   << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n""
  5.   << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"--host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""
  6.   << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""
  7.   << TCmdLineDebugger.ReadLn "~"<http://www.atmel.com>.\n""
  8.   << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n""
  9.   << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""
  10.   << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""
  11.   << TCmdLineDebugger.ReadLn "^done"
  12.   << TCmdLineDebugger.ReadLn "(gdb) "

The last toolchain I could find in Microchip's site ....

I didn't try the ATMEL Studio's 7 toolchain though .... I'll give it a try and report back ...

Update: Nope  ... I got
Code: Pascal  [Select]
  1. The GDB command:
  2. "-break-delete 4"
  3. returned the error:
  4. ",msg="Cannot execute this command while the target is running.\nUse the \"interrupt\" command to stop the target\nand then try again.""

with

Code: Pascal  [Select]
  1.   >> TCmdLineDebugger.SendCmdLn "-gdb-version"
  2.   << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.6.1_1750) 7.8\n""
  3.   << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""
  4.   << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n""
  5.   << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"--host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""
  6.   << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""
  7.   << TCmdLineDebugger.ReadLn "~"<http://www.atmel.com>.\n""
  8.   << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n""
  9.   << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""
  10.   << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""
  11.   << TCmdLineDebugger.ReadLn "^done"
  12.   << TCmdLineDebugger.ReadLn "(gdb) "
  13.   >> TCmdLineDebugger.SendCmdLn "target remote localhost:4242"
  14.   << TCmdLineDebugger.ReadLn "&"target remote localhost:4242\n""
  15.   << TCmdLineDebugger.ReadLn "~"Remote debugging using localhost:4242\n""
  16.   << TCmdLineDebugger.ReadLn "=thread-group-started,id="i1",pid="42000""
  17.   << TCmdLineDebugger.ReadLn "=thread-created,id="1",group-id="i1""
  18.   << TCmdLineDebugger.ReadLn "~"0xfffffffe in ?? ()\n""
  19.   << TCmdLineDebugger.ReadLn "*stopped,frame={addr="0xfffffffe",func="??",args=[]},thread-id="1",stopped-threads="all""
  20.   << TCmdLineDebugger.ReadLn "^done"
  21.   << TCmdLineDebugger.ReadLn "(gdb) "
  22. Exec done
  23. Leaving Queue with count: 0 Recurse-Count=0 State=dsNone
  24.  
  25. < A lot of se-env calls snipped >
  26.  
  27. Hint: (lazarus) [TMainIDE.DoRunProject] Debugger=TGDBMIServerDebugger
  28. Hint: (lazarus) [TMainIDE.DoRunProject] END
  29. ----------------
  30. Executing (Recurse-Count=0) queued= 0 CmdPrior=0 CmdMinRunLvl=-1 : "TGDBMIServerDebuggerCommandStartDebugging: ContinueCommand= TGDBMIDebuggerCommandExecute: -exec-continue" State=dsStop PauseWaitState=0
  31.   >> TCmdLineDebugger.SendCmdLn "-file-exec-and-symbols "G:/Programming/dimitris/Projects/avrFPCBlink/prjAVRBlink""
  32.   << TCmdLineDebugger.ReadLn "^done"
  33.   << TCmdLineDebugger.ReadLn "(gdb) "
  34.   >> TCmdLineDebugger.SendCmdLn "-gdb-set language pascal"
  35.   << TCmdLineDebugger.ReadLn "^done"
  36.   << TCmdLineDebugger.ReadLn "(gdb) "
  37.   TGDBMIDebugger.StartDebugging WorkingDir="G:\Programming\dimitris\Projects\avrFPCBlink\"
  38.   >> TCmdLineDebugger.SendCmdLn "-environment-cd ."
  39.   << TCmdLineDebugger.ReadLn "^done"
  40.   << TCmdLineDebugger.ReadLn "(gdb) "
  41.   >> TCmdLineDebugger.SendCmdLn "-environment-cd "G:/Programming/dimitris/Projects/avrFPCBlink/""
  42.   << TCmdLineDebugger.ReadLn "^done"
  43.   << TCmdLineDebugger.ReadLn "(gdb) "
  44.   >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression FPC_THREADVAR_RELOCATE_PROC"
  45.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"FPC_THREADVAR_RELOCATE_PROC\" in current context.""
  46.   << TCmdLineDebugger.ReadLn "(gdb) "
  47.   >> TCmdLineDebugger.SendCmdLn "info functions FPC_CPUINIT"
  48.   << TCmdLineDebugger.ReadLn "&"info functions FPC_CPUINIT\n""
  49.   << TCmdLineDebugger.ReadLn "~"All functions matching regular expression \"FPC_CPUINIT\":\n""
  50.   << TCmdLineDebugger.ReadLn "^done"
  51.   << TCmdLineDebugger.ReadLn "(gdb) "
  52.   >> TCmdLineDebugger.SendCmdLn "info functions $$_RUNERROR$"
  53.   << TCmdLineDebugger.ReadLn "&"info functions $$_RUNERROR$\n""
  54.   << TCmdLineDebugger.ReadLn "~"All functions matching regular expression \"$$_RUNERROR$\":\n""
  55.   << TCmdLineDebugger.ReadLn "^done"
  56.   << TCmdLineDebugger.ReadLn "(gdb) "
  57.   >> TCmdLineDebugger.SendCmdLn "-exec-arguments "
  58.   << TCmdLineDebugger.ReadLn "^done"
  59.   << TCmdLineDebugger.ReadLn "(gdb) "
  60.   >> TCmdLineDebugger.SendCmdLn "-gdb-set language pascal"
  61.   << TCmdLineDebugger.ReadLn "^done"
  62.   << TCmdLineDebugger.ReadLn "(gdb) "
  63.   >> TCmdLineDebugger.SendCmdLn "ptype TObject"
  64.   << TCmdLineDebugger.ReadLn "&"ptype TObject\n""
  65.   << TCmdLineDebugger.ReadLn "&"No symbol \"TObject\" in current context.\n""
  66.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"TObject\" in current context.""
  67.   << TCmdLineDebugger.ReadLn "(gdb) "
  68.   >> TCmdLineDebugger.SendCmdLn "ptype Exception"
  69.   << TCmdLineDebugger.ReadLn "&"ptype Exception\n""
  70.   << TCmdLineDebugger.ReadLn "&"No symbol \"Exception\" in current context.\n""
  71.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"Exception\" in current context.""
  72.   << TCmdLineDebugger.ReadLn "(gdb) "
  73.   >> TCmdLineDebugger.SendCmdLn "ptype Shortstring"
  74.   << TCmdLineDebugger.ReadLn "&"ptype Shortstring\n""
  75.   << TCmdLineDebugger.ReadLn "&"No symbol \"Shortstring\" in current context.\n""
  76.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"Shortstring\" in current context.""
  77.   << TCmdLineDebugger.ReadLn "(gdb) "
  78.   >> TCmdLineDebugger.SendCmdLn "ptype pointer"
  79.   << TCmdLineDebugger.ReadLn "&"ptype pointer\n""
  80.   << TCmdLineDebugger.ReadLn "&"No symbol \"pointer\" in current context.\n""
  81.   << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"pointer\" in current context.""
  82.   << TCmdLineDebugger.ReadLn "(gdb) "
  83.   >> TCmdLineDebugger.SendCmdLn "ptype byte"
  84.   << TCmdLineDebugger.ReadLn "&"ptype byte\n""
  85.   << TCmdLineDebugger.ReadLn "~"type = Byte\n""
  86.   << TCmdLineDebugger.ReadLn "^done"
  87.   << TCmdLineDebugger.ReadLn "(gdb) "
  88.   >> TCmdLineDebugger.SendCmdLn "set print elements 2500"
  89.   << TCmdLineDebugger.ReadLn "&"set print elements 2500\n""
  90.   << TCmdLineDebugger.ReadLn "=cmd-param-changed,param="print elements",value="2500""
  91.   << TCmdLineDebugger.ReadLn "^done"
  92.   << TCmdLineDebugger.ReadLn "(gdb) "
  93.   >> TCmdLineDebugger.SendCmdLn "info file"
  94.   << TCmdLineDebugger.ReadLn "&"info file\n""
  95.   << TCmdLineDebugger.ReadLn "~"Symbols from \"G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink\".\n""
  96.   << TCmdLineDebugger.ReadLn "~"Remote serial target in gdb-specific protocol:\n""
  97.   << TCmdLineDebugger.ReadLn "~"Debugging a target over a serial line.\n""
  98.   << TCmdLineDebugger.ReadLn "~"\tWhile running this, GDB does not access memory from...\n""
  99.   << TCmdLineDebugger.ReadLn "~"Local exec file:\n""
  100.   << TCmdLineDebugger.ReadLn "~"\t`G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink', file type elf32-avr.\n""
  101.  << TCmdLineDebugger.ReadLn "~"\tEntry point: 0x0\n""
  102.  << TCmdLineDebugger.ReadLn "~"\t0x00000000 - 0x00000124 is .text\n""
  103.  << TCmdLineDebugger.ReadLn "~"\t0x00800100 - 0x00800102 is .data\n""
  104.  << TCmdLineDebugger.ReadLn "^done"
  105.  << TCmdLineDebugger.ReadLn "(gdb) "
  106.  >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression sizeof(^byte)"
  107.  << TCmdLineDebugger.ReadLn "^done,value="2""
  108.  << TCmdLineDebugger.ReadLn "(gdb) "
  109.  >> TCmdLineDebugger.SendCmdLn "-break-insert -f foo"
  110.  << TCmdLineDebugger.ReadLn "&"Function \"foo\" not defined.\n""
  111.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="foo",times="0",original-location="foo"}"
  112.  << TCmdLineDebugger.ReadLn "(gdb) "
  113.  >> TCmdLineDebugger.SendCmdLn "-break-delete 1"
  114.  << TCmdLineDebugger.ReadLn "^done"
  115.  << TCmdLineDebugger.ReadLn "(gdb) "
  116.  >> TCmdLineDebugger.SendCmdLn "-break-insert main"
  117.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="n",addr="0x00000108",func="$main",file="prjAVRBlink.lpr",fullname="G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink.lpr",line="24",thread-groups=["i1"],times="0",original-location="main"}"
  118.  << TCmdLineDebugger.ReadLn "(gdb) "
  119.  >> TCmdLineDebugger.SendCmdLn "-break-insert +0"
  120.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="3",type="breakpoint",disp="keep",enabled="n",addr="0x00000000",file="avr/avrcommon.inc",fullname="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc",l" ..(92).. "ginal-location="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc:+0"}"
  121.  << TCmdLineDebugger.ReadLn "(gdb) "
  122.  >> TCmdLineDebugger.SendCmdLn "info address main"
  123.  << TCmdLineDebugger.ReadLn "&"info address main\n""
  124.  << TCmdLineDebugger.ReadLn "~"Symbol \"main\" is at 0x104 in a file compiled without debugging.\n""
  125.  << TCmdLineDebugger.ReadLn "^done"
  126.  << TCmdLineDebugger.ReadLn "(gdb) "
  127.  >> TCmdLineDebugger.SendCmdLn "-break-insert *260"
  128.  << TCmdLineDebugger.ReadLn "^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00800104",thread-groups=["i1"],times="0",original-location="*260"}"
  129.  << TCmdLineDebugger.ReadLn "(gdb) "
  130.  >> TCmdLineDebugger.SendCmdLn "-exec-continue &"
  131.  << TCmdLineDebugger.ReadLn "^running"
  132.  << TCmdLineDebugger.ReadLn "*running,thread-id="all""
  133.  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor
  134.  DebugDataMonitor: <<EXIT: TThreadsDlg.ThreadsChanged
  135.  << TCmdLineDebugger.ReadLn "(gdb) "
  136.  << TCmdLineDebugger.ReadLn "(gdb) "
  137.  >> TCmdLineDebugger.SendCmdLn "-break-delete 2"
  138.  << TCmdLineDebugger.ReadLn "^done"
  139.  << TCmdLineDebugger.ReadLn "(gdb) "
  140.  >> TCmdLineDebugger.SendCmdLn "-break-delete 4"
  141.  << TCmdLineDebugger.ReadLn "^error,msg="Cannot execute this command while the target is running.\nUse the \"interrupt\" command to stop the target\nand then try again.""
  142.  << TCmdLineDebugger.ReadLn "(gdb) "
  143.  DebuggerState: Setting to dsError, from dsStop

regards,
« Last Edit: March 24, 2018, 08:04:19 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Full Member
  • ***
  • Posts: 129
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #10 on: March 25, 2018, 07:35:29 am »
Not clear to me why you see an error when deleting specifically breakpoint 4. Perhaps simulate the Lazarus debug session in avr-gdb using the mi interpreter (. /avr-gdb - i=mi) to see if you get the same error. I suggest you start with a very basic session (connect, load file, set breakpoint, continue, disassemble) and if that works include more commands from your lazarus log.

ccrause

  • Full Member
  • ***
  • Posts: 129
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #11 on: March 25, 2018, 10:24:52 am »
Hi Dimitrios,

I've debugged your example using your settings via simavr, just to get a reference log.  Obviously most of the initial commands are the same, below I show the bit of the log around to the first -exec-continue command:
Code: [Select]
>> TCmdLineDebugger.SendCmdLn "-exec-continue &"
<< TCmdLineDebugger.ReadLn "^running"
<< TCmdLineDebugger.ReadLn "*running,thread-id="all""
<< TCmdLineDebugger.ReadLn "~"Note: automatically using hardware breakpoints for read-only addresses.\n""
<< TCmdLineDebugger.ReadLn "(gdb) "
<< TCmdLineDebugger.ReadLn "=breakpoint-modified,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00000104",func="$main",file="prjAVRBlink.pp",fullname="/home/christo/fpc/fpc-avr/src/tests/blinktemp/prjAVRBlink.pp",line="23",thread-groups=["i1"],times="1",original-location="*260"}"
<< TCmdLineDebugger.ReadLn "~"\n""
<< TCmdLineDebugger.ReadLn "~"Breakpoint 4, $main () at prjAVRBlink.pp:23\n""
<< TCmdLineDebugger.ReadLn "~"23\tbegin\n""
<< TCmdLineDebugger.ReadLn "*stopped,reason="breakpoint-hit",disp="keep",bkptno="4",frame={addr="0x00000104",func="$main",args=[],file="prjAVRBlink.pp",fullname="/home/christo/fpc/fpc-avr/src/tests/blinktemp/prjAVRBlink.pp",line="23"},thread-id="1",stopped-threads="all""
>> TCmdLineDebugger.SendCmdLn "-break-delete 2"
<< TCmdLineDebugger.ReadLn "^done"
<< TCmdLineDebugger.ReadLn "(gdb) "
>> TCmdLineDebugger.SendCmdLn "-break-delete 4"
<< TCmdLineDebugger.ReadLn "^done"
<< TCmdLineDebugger.ReadLn "(gdb) "
>> TCmdLineDebugger.SendCmdLn "-break-delete 3"
<< TCmdLineDebugger.ReadLn "^done"
<< TCmdLineDebugger.ReadLn "(gdb) "
DebuggerState: Setting to dsRun, from dsStop
So in this session the [-exec-continue[/tt] command responds with running and end off with a single (gdb).  After this it hits the Lazarus inserted breakpoint at start of main.  This is the standard initialization sequence Lazarus seems to follow.

I use avr-gdb 8.0 which I patched and compiled from source.  I believe all gdb versions for AVR from 7.1 up to 8 requires a patch to properly access memory, but this is not the problem you seem to get stuck at.

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 56
    • Nephelae
Re: Debugging AVR over debugWIRE using dwire-debug
« Reply #12 on: March 26, 2018, 12:14:06 pm »
Hi,

  as I use a setup like this MCU -> AVR Dragon -> Dragon Driver -> libusb filter -> avarice -> avr-gdb I assume that the communication between avr-gdb and avarice is the problem.

  I'll try some ideas the following days and I'll get back with my findings.

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus