Debugging AVR over debugWIRE using dwire-debug lazarus / 12-Debugger ---------------------------------------------------------------------- ccrause · 2018-03-21 10:04 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program blink; uses intrinsics; const  LEDpin = 1 shl 4;  countsPerSecond = ((F_CPU div 1024) + 128) div 256;  // Hz  CS00msk = 1 shl 0;  CS02msk = 1 shl 2;  TOIE0msk = 1 shl 1; var  LEDport: byte absolute PORTB;  LEDdir: byte absolute DDRB;  i: byte = 1; procedure Timer0Overflow; alias: 'TIMER0_OVF_ISR'; interrupt;begin  inc(i);  if i > countsPerSecond then  begin    LEDport := LEDport xor LEDpin;    i := 0;  end;end; begin  LEDdir := LEDdir or LEDpin;  // Set pin to output  LEDport := LEDport or LEDpin; // Set LED high  TCCR0A := 0;  TCCR0B := CS02msk or CS00msk;  // clock prescaler = 1024  // enable timer1 overflow interrupt  TIMSK := TOIE0msk;  avr_sei;  while True do;end.  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 , 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 · 2018-03-21 16:54 Nice work, although I prefer full JTAG ICE over somewhat limited debugWIRE. ---------------------------------------------------------------------- d.ioannidis · 2018-03-22 13:28 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. ---------------------------------------------------------------------- ccrause · 2018-03-22 14:40 Quote from: Dimitrios Chr. Ioannidis on March 22, 2018, 02:28:44 pmI 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... ---------------------------------------------------------------------- d.ioannidis · 2018-03-24 11:04 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        if RequirePID then    <------------ Added this line ...      if not DoChangeFilename then begin        SetDebuggerErrorState(synfFailedToLoadApplicationExecutable, FErrorMsg);        exit;      end;    if not DoSetPascal then begin    SetDebuggerErrorState(synfFailedToInitializeTheDebuggerSetPascalFail ed,        FLastExecResult.Values);      exit;    end; regards. ---------------------------------------------------------------------- d.ioannidis · 2018-03-24 11:12 Hi, Quote from: avra on March 21, 2018, 05:54:12 pmNice work, although I prefer full JTAG ICE over somewhat limited debugWIRE.  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, ---------------------------------------------------------------------- ccrause · 2018-03-24 13:00 Quote from: Dimitrios Chr. Ioannidis on March 24, 2018, 12:04:54 pmBut 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. QuotePS: 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. QuotePS1: 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. QuotePS2: Plus, I had to add in gdbmidebugger.pp in line 5036 the following : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        if RequirePID then    <------------ Added this line ...      if not DoChangeFilename then begin        SetDebuggerErrorState(synfFailedToLoadApplicationExecutable, FErrorMsg);        exit;      end;    if not DoSetPascal then begin    SetDebuggerErrorState(synfFailedToInitializeTheDebuggerSetPascalFail ed,        FLastExecResult.Values);      exit;    end;What debugging error lead you to suspect the DoChangeFilename statement? ---------------------------------------------------------------------- d.ioannidis · 2018-03-24 16:18 Hi, Quote from: ccrause on March 24, 2018, 02:00:19 pmQuote from: Dimitrios Chr. Ioannidis on March 24, 2018, 12:04:54 pmBut 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [TCmdLineDebugger] Debug PID: 1956<< TCmdLineDebugger.ReadLn "=thread- group-added,id="i1""<< TCmdLineDebugger.ReadLn "(gdb) "Executing (Recurse-Count=0) queued= 0 CmdPrior=0 CmdMinRunLvl=-1 : "TGDBMIServerDebuggerCommandInitDebugger" State=dsNone PauseWaitState=0  >> TCmdLineDebugger.SendCmdLn "-gdb-set confirm off"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-gdb-set new-console off"  << TCmdLineDebugger.ReadLn "^error,msg="No symbol table is loaded.  Use the \"file\" command.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "set width 50000"  << TCmdLineDebugger.ReadLn "&"set width 50000\n""  << TCmdLineDebugger.ReadLn "=cmd-param- changed,param="width",value="50000""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "set target-async on"  << TCmdLineDebugger.ReadLn "&"set target-async on\n""  << TCmdLineDebugger.ReadLn "=cmd-param-changed,param="mi- async",value="on""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "show target-async"  << TCmdLineDebugger.ReadLn "&"show target-async\n""  << TCmdLineDebugger.ReadLn "~"Whether MI is in asynchronous mode is on.\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-gdb- version"  << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 7.8\n""  << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""  << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later \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""  << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"-- host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""  << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""  << TCmdLineDebugger.ReadLn "~".\n""  << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n.\n""  << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""  << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "target remote localhost:4242"  << TCmdLineDebugger.ReadLn "&"target remote localhost:4242\n""  << TCmdLineDebugger.ReadLn "~"Remote debugging using localhost:4242\n""  << TCmdLineDebugger.ReadLn "=thread-group-started,id="i1",pid="42000""  << TCmdLineDebugger.ReadLn "=thread-created,id="1",group-id="i1""  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor  DebugDataMonitor: <> Run OnIdle  OnIdle: UnLock<< Run OnIdleOnIdle: Finished < sniping a lot of env var's > Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i >> TCmdLineDebugger.SendCmdLn "info file"  << TCmdLineDebugger.ReadLn "&"info file\n""  << TCmdLineDebugger.ReadLn "~"Symbols from \"G:\\Pro gramming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink\".\n""  << TCmdLineDebugger.ReadLn "~"Remote serial target in gdb-specific protocol:\n""  << TCmdLineDebugger.ReadLn "~"Debugging a target over a serial line.\n""  << TCmdLineDebugger.ReadLn "~"\tWhile running this, GDB does not access memory from...\n""  << TCmdLineDebugger.ReadLn "~"Local exec file:\n""  << TCmdLineDebugger.ReadLn "~"\t`G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink', file type elf32-avr.\n""  << TCmdLineDebugger.ReadLn "~"\tEntry point: 0x0\n""  << TCmdLineDebugger.ReadLn "~"\t0x00000000 - 0x00000124 is .text\n""  << TCmdLineDebugger.ReadLn "~"\t0x00800100 - 0x00800102 is .data\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression sizeof(^byte)"  << TCmdLineDebugger.ReadLn "^done,value="2""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert -f foo"  << TCmdLineDebugger.ReadLn "&"Function \"foo\" not defined.\n""  << TCmdLineDebugger.ReadLn "^done,bkpt={number="1",type="breakpoint",disp ="keep",enabled="y",addr="",pending="foo",times="0",original- location="foo"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-delete 1"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert main"  << TCmdLineDebugger.ReadLn "^done,bkpt={number="2",type="breakpoint",disp ="keep",enabled="n",addr="0x00000108",func="$main",file="prjAVRBlink.l pr",fullname="G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVR Blink.lpr",line="24",thread-groups=["i1"],times="0",original- location="main"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert +0"  << TCmdLineDebugger.ReadLn "^done,bkpt={number="3",type="breakpoint",disp ="keep",enabled="n",addr="0x00000000",file="avr/avrcommon.inc",fullnam e="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\a vrcommon.inc",l" ..(92).. "ginal-location="G:\\Programming\\dimitris\\ tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc:+0"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "info address main"  << TCmdLineDebugger.ReadLn "&"info address main\n""  << TCmdLineDebugger.ReadLn "~"Symbol \"main\" is at 0x104 in a file compiled without debugging.\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert *260"  << TCmdLineDebugger.ReadLn "^done,bkpt={number=" 4",type="breakpoint",disp="keep",enabled="y",addr="0x00800104",thread- groups=["i1"],times="0",original-location="*260"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-exec-continue &"  << TCmdLineDebugger.ReadLn "^running"  << TCmdLineDebugger.ReadLn "*running,thread-id="all""  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor  DebugDataMonitor: <> TCmdLineDebugger.SendCmdLn "-break-delete 2"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-delete 4"  << 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.""  << TCmdLineDebugger.ReadLn "(gdb) "  Quote from: ccrause on March 24, 2018, 02:00:19 pmNote 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. Quote from: ccrause on March 24, 2018, 02:00:19 pmWhat 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program prjAVRBlink; {$mode objfpc}{$H+} const  BP1 = 1;      // Pin 1   procedure HW_Delay; alias: 'TIMER2_OVF_ISR'; interrupt; public;  const    counter: integer = 0;    delay = 16000000 div 1024 div 256 div 2;   // 16.000.000Hz / Clock / TCNT / 2 = 0,5 Second  begin    inc(counter);    if counter = delay div 2 then begin      PORTB := PORTB or (1 shl BP1);      // Port  High    end;    if counter >= delay   then begin      PORTB := PORTB and not (1 shl BP1); // Port Low      counter := 0;    end;  end; begin  DDRB := DDRB or (1 shl BP1);            // Pin 1 Port Output   TCCR2A := $0;                         // Normal Timer  TCCR2B := $7;                           // Clock / 1024  TIMSK2 := (1 shl TOIE2);                // Enable Timer2 overflow interrupt  asm    sei                                   // Enable interrupts  end;   repeat  until False;end.  with compiler options Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  -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. ---------------------------------------------------------------------- ccrause · 2018-03-24 18:18 Quote from: Dimitrios Chr. Ioannidis on March 24, 2018, 05:18:50 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i >> TCmdLineDebugger.SendCmdLn "info file"  << TCmdLineDebugger.ReadLn "^d one,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0 x00800104",thread-groups=["i1"],times="0",original-location="*260"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-exec-continue &"  << TCmdLineDebugger.ReadLn "^running"  << TCmdLineDebugger.ReadLn "*running,thread-id="all""  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor  DebugDataMonitor: <> TCmdLineDebugger.SendCmdLn "-break-insert *146" << TCmdLineDebugger.ReadLn "^done,bkpt={number="4",type="breakpoint",d isp="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",f ile="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? ---------------------------------------------------------------------- d.ioannidis · 2018-03-24 18:55 Quote from: ccrause on March 24, 2018, 07:18:10 pm < snip > What version of avr-gdb are you using? It was in the first code post : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   >> TCmdLineDebugger.SendCmdLn "-gdb-version"  << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 7.8\n""  << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""  << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later \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""  << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"-- host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""  << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""  << TCmdLineDebugger.ReadLn "~".\n""  << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n.\n""  << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""  << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""  << TCmdLineDebugger.ReadLn "^done"  << 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i The GDB command:"-break-delete 4"returned the error:",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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   >> TCmdLineDebugger.SendCmdLn "-gdb-version"  << TCmdLineDebugger.ReadLn "~"GNU gdb (AVR_8_bit_GNU_Toolchain_3.6.1_1750) 7.8\n""  << TCmdLineDebugger.ReadLn "~"Copyright (C) 2014 Free Software Foundation, Inc.\n""  << TCmdLineDebugger.ReadLn "~"License GPLv3+: GNU GPL version 3 or later \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""  << TCmdLineDebugger.ReadLn "~"This GDB was configured as \"-- host=i686-w64-mingw32 --target=avr\".\nType \"show configuration\" for configuration details.""  << TCmdLineDebugger.ReadLn "~"\nFor bug reporting instructions, please see:\n""  << TCmdLineDebugger.ReadLn "~".\n""  << TCmdLineDebugger.ReadLn "~"Find the GDB manual and other documentation resources online at:\n.\n""  << TCmdLineDebugger.ReadLn "~"For help, type \"help\".\n""  << TCmdLineDebugger.ReadLn "~"Type \"apropos word\" to search for commands related to \"word\".\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "target remote localhost:4242"  << TCmdLineDebugger.ReadLn "&"target remote localhost:4242\n""  << TCmdLineDebugger.ReadLn "~"Remote debugging using localhost:4242\n""  << TCmdLineDebugger.ReadLn "=thread-group-started,id="i1",pid="42000""  << TCmdLineDebugger.ReadLn "=thread-created,id="1",group-id="i1""  << TCmdLineDebugger.ReadLn "~"0xfffffffe in ?? ()\n""  << TCmdLineDebugger.ReadLn "*stopped,frame={addr="0xfffffffe",func="??",args=[]},thread- id="1",stopped-threads="all""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "Exec doneLeaving Queue with count: 0 Recurse-Count=0 State=dsNone < A lot of se-env calls snipped > Hint: (lazarus) [TMainIDE.DoRunProject] Debugger=TGDBMIServerDebuggerHint: (lazarus) [TMainIDE.DoRunProject] END----------------Executing (Recurse-Count=0) queued= 0 CmdPrior=0 CmdMinRunLvl=-1 : "TGDBMIServerDebuggerCommandStartDebugging: ContinueCommand= TGDBMIDebuggerCommandExecute: -exec-continue" State=dsStop PauseWaitState=0  >> TCmdLineDebugger.SendCmdLn "-file-exec-and- symbols "G:/Programming/dimitris/Projects/avrFPCBlink/prjAVRBlink""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-gdb-set language pascal"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  TGDBMIDebugger.StartDebugging WorkingDir="G:\Programming\dimitris\Projects\avrFPCBlink\"  >> TCmdLineDebugger.SendCmdLn "-environment-cd ."  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-environment-cd "G:/Programming/dimitris/Projects/avrFPCBlink/""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression FPC_THREADVAR_RELOCATE_PROC"  << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"FPC_THREADVAR_RELOCATE_PROC\" in current context.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "info functions FPC_CPUINIT"  << TCmdLineDebugger.ReadLn "&"info functions FPC_CPUINIT\n""  << TCmdLineDebugger.ReadLn "~"All functions matching regular expression \"FPC_CPUINIT\":\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "info functions $$_RUNERROR$"  << TCmdLineDebugger.ReadLn "&"info functions $$_RUNERROR$\n""  << TCmdLineDebugger.ReadLn "~"All functions matching regular expression \"$$_RUNERROR$\":\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-exec-arguments "  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-gdb-set language pascal"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "ptype TObject"  << TCmdLineDebugger.ReadLn "&"ptype TObject\n""  << TCmdLineDebugger.ReadLn "&"No symbol \"TObject\" in current context.\n""  << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"TObject\" in current context.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "ptype Exception"  << TCmdLineDebugger.ReadLn "&"ptype Exception\n""  << TCmdLineDebugger.ReadLn "&"No symbol \"Exception\" in current context.\n""  << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"Exception\" in current context.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "ptype Shortstring"  << TCmdLineDebugger.ReadLn "&"ptype Shortstring\n""  << TCmdLineDebugger.ReadLn "&"No symbol \"Shortstring\" in current context.\n""  << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"Shortstring\" in current context.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "ptype pointer"  << TCmdLineDebugger.ReadLn "&"ptype pointer\n""  << TCmdLineDebugger.ReadLn "&"No symbol \"pointer\" in current context.\n""  << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"pointer\" in current context.""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "ptype byte"  << TCmdLineDebugger.ReadLn "&"ptype byte\n""  << TCmdLineDebugger.ReadLn "~"type = Byte\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "set print elements 2500"  << TCmdLineDebugger.ReadLn "&"set print elements 2500\n""  << TCmdLineDebugger.ReadLn "=cmd-param-changed,param="print elements",value="2500""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "info file"  << TCmdLineDebugger.ReadLn "&"info file\n""  << TCmdLineDebugger.ReadLn "~"Symbols from \"G:\\Programming\\dimitris\\P rojects\\avrFPCBlink\\prjAVRBlink\".\n""  << TCmdLineDebugger.ReadLn "~"Remote serial target in gdb-specific protocol:\n""  << TCmdLineDebugger.ReadLn "~"Debugging a target over a serial line.\n""  << TCmdLineDebugger.ReadLn "~"\tWhile running this, GDB does not access memory from...\n""  << TCmdLineDebugger.ReadLn "~"Local exec file:\n""  << TCmdLineDebugger.ReadLn "~"\t`G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVRBlink', file type elf32-avr.\n""  << TCmdLineDebugger.ReadLn "~"\tEntry point: 0x0\n""  << TCmdLineDebugger.ReadLn "~"\t0x00000000 - 0x00000124 is .text\n""  << TCmdLineDebugger.ReadLn "~"\t0x00800100 - 0x00800102 is .data\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression sizeof(^byte)"  << TCmdLineDebugger.ReadLn "^done,value="2""  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert -f foo"  << TCmdLineDebugger.ReadLn "&"Function \"foo\" not defined.\n""  << TCmdLineDebugger.ReadLn "^done,bkpt={number="1",type="breakpoint",disp ="keep",enabled="y",addr="",pending="foo",times="0",original- location="foo"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-delete 1"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert main"  << TCmdLineDebugger.ReadLn "^done,bkpt={number="2",type="breakpoint",disp ="keep",enabled="n",addr="0x00000108",func="$main",file="prjAVRBlink.l pr",fullname="G:\\Programming\\dimitris\\Projects\\avrFPCBlink\\prjAVR Blink.lpr",line="24",thread-groups=["i1"],times="0",original- location="main"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert +0"  << TCmdLineDebugger.ReadLn "^done,bkpt={number="3",type="breakpoint",disp ="keep",enabled="n",addr="0x00000000",file="avr/avrcommon.inc",fullnam e="G:\\Programming\\dimitris\\tools\\svn\\trunk\\rtl\\embedded\\avr\\a vrcommon.inc",l" ..(92).. "ginal-location="G:\\Programming\\dimitris\\ tools\\svn\\trunk\\rtl\\embedded\\avr\\avrcommon.inc:+0"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "info address main"  << TCmdLineDebugger.ReadLn "&"info address main\n""  << TCmdLineDebugger.ReadLn "~"Symbol \"main\" is at 0x104 in a file compiled without debugging.\n""  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-insert *260"  << TCmdLineDebugger.ReadLn "^done,bkpt={number=" 4",type="breakpoint",disp="keep",enabled="y",addr="0x00800104",thread- groups=["i1"],times="0",original-location="*260"}"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-exec-continue &"  << TCmdLineDebugger.ReadLn "^running"  << TCmdLineDebugger.ReadLn "*running,thread-id="all""  DebugDataMonitor: >>ENTER: TThreadsDlg.ThreadsChanged from TIdeThreadsMonitor  DebugDataMonitor: <> TCmdLineDebugger.SendCmdLn "-break-delete 2"  << TCmdLineDebugger.ReadLn "^done"  << TCmdLineDebugger.ReadLn "(gdb) "  >> TCmdLineDebugger.SendCmdLn "-break-delete 4"  << 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.""  << TCmdLineDebugger.ReadLn "(gdb) "  DebuggerState: Setting to dsError, from dsStop regards, ---------------------------------------------------------------------- ccrause · 2018-03-25 05:35 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 · 2018-03-25 08:24 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",f ile="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="kee p",bkptno="4",frame={addr="0x00000104",func="$main",args=[],file="prjA VRBlink.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. ---------------------------------------------------------------------- d.ioannidis · 2018-03-26 10:14 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,