Remote debugging from Windows to Linux lazarus / 12-Debugger ---------------------------------------------------------------------- aradeonas · 2016-04-25 15:01 Hi, As subject said I want to debug from my local Windows machine Lazarus a Linux server and for that I read wiki and all posts like: http://wiki.lazarus.freepascal.org/Remote_Debugging http://forum.lazarus.freepascal.org/index.php/topic,19014.0.html http://forum.lazarus.freepascal.org/index.php/topic,20101.0.html http://www.lazarusforum.de/viewtopic.php?f=4&t=6645 http://www.lazarusforum.de/viewtopic.php?f=9&t=6664 I cant make it work because I dont understand what should I do exactly and these posts seems old, so anyone here can explain in brief steps of doing this so I can update Wiki? ---------------------------------------------------------------------- Martin_fr · 2016-04-28 02:28 There hasnt been much work on remote debugging neither, so the post are probably still accurate. (Unless there are new bugs somewhere / this is scarcely used, and hence little tested.) I recommend to try gdbserver. you need a gdbserver on the linux machine. I dont know if there are any issues with different versions of gdbserver and gdb. this should describe how http://forum.lazarus.freepascal.org/index.php/topic,19014.msg107930.ht ml Before starting the debugger: - you need to copy the exe to the linux box - and start the exe in gdbserver. Then the Ide can debug in gdbserver mode. ---------------------------------------------------------------------- aradeonas · 2016-04-28 13:49 Thanks Martin, I had a hard time trying to make a cross compile gdb for Windows 64 to Linux 64. Can you help me in this way? ---------------------------------------------------------------------- Martin_fr · 2016-04-28 14:06 Sorry I dont know about building your own gdb. Also do you really need to? What linux comes without gdb? (Well gdbserver in this case) Even then, why cross compiling it? Build your gdb(server) on the linux machine (or on a local linux machine (virtual machine) and copy it over). A win64 gdb is included in Lazarus, and an updated win64 gdb is here h ttps://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%2 0bits/Alternative%20GDB/ ---------------- Or do you mean fpc cross compiler? Then better ask on a new subject, so someone who knows this can help. I dont personally do cross compilation, so I cant answer that neither. ---------------------------------------------------------------------- aradeonas · 2016-04-28 14:52 Ah, It was a huge misunderstanding! I was trying to make a cross compile gdb for win and linux! Now it works. I will update the wiki. Another question : When you trying to debug on a remote machine how do you move executable file to it every time? is there a way to automate this job that you know is good? Problem is when you change the file you should copy it to Linux machine, then change permissions to run and then run remote server again and then debug and do all of this everytime you changed a thing. ---------------------------------------------------------------------- Martin_fr · 2016-04-28 15:44 Menu: Project > Project Options for copying the file, that depends what tools you need to use. If the remote folder is mounted to the local file system, just set the compiler settings to create the file there. (Compiler Options > Path) Otherwise in Compiler Options > Compiler Commands you can specify to run any command on your system that will be run after the compile To set exe bit, and start gdbserver you need to run commands on the remote system. Should be possible to do that by running ssh with the correct commandline. ---------------------------------------------------------------------- aradeonas · 2016-04-30 09:40 OK Now I tried to do what you said and I need to do these: 1- Compile for linux. 2- Copy it to remote machine. 3- Run gdbserver. 4- Debug program in IDE with compile option set to gdbserver. So problems: 1- When I run for debugging and even set before run command for copy file to server like this : 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 WinSCP.com /script=c:\Tools\script.txtit even wont run, why? because it needs gdbserver running on remote machine and remote machine needs program to run! So how can I do this automatically? ---------------------------------------------------------------------- Martin_fr · 2016-04-30 13:54 First of all, I never done this. Also I dont know the details of winscp. openssh iirc can be given a command on the commandline and execute it on the remote Code: [Select]ssh 127.0.0.1 -C lswill run "ls" on the remote, and then close the connection. I dont know if and which (or how) the windows ssh clients do that. ---------------------------------------------------------------------- aradeonas · 2016-04-30 14:00 Thanks. winscp is not the point. point and problem is how can I copy the file to the remote machine automaticly and run it with gdbserver when even running program with ide needs gdbserver be run on remote machine! Host needs gdbserver to run so it can copy the file. Remote needs program file for gdbserevr so it can run. ---------------------------------------------------------------------- Martin_fr · 2016-04-30 14:07 The problem is support for remote debugging is very basic. And it always only concerned the IDE being able to talk to the remote gdb. Copying the files, and running remote setup was always left to the user. Things like the "run before/after" are separate features, that can be used for anything. Patches to improve remote debugging are always welcome. EDIT: the best way would be a remote-ide-client, that the IDE can talk to, and that takes care of all the steps ---------------------------------------------------------------------- aradeonas · 2016-04-30 15:35 OK. I will see what can I do about it. ---------------------------------------------------------------------- Martin_fr · 2016-04-30 15:43 just as I note. IIRC there is/was some work on fpdebug too. So it might not be gdbserver only. But it will have at least the same restrictions. ---------------------------------------------------------------------- aradeonas · 2016-05-03 06:11 For now this is the best approach I could find: 1- Manually include gdbmidebugger the public "uses" clause of debugmanager.pas file located in lazarus/ide and recompile ide. 2- Install gdb and gdbserver on Linux. 3- Make a cross compile Lazarus. 4- Set  IDE options/Debugger to gdbserver and in the debugger options on the bottom set Debugger_Remote_Hostname to remote Linux machine IP or name and set the port to 2159. 5- Add a Linux build mode to project option. 6- Build project. 7- Use whatever tool like WinSCP to move binary file to Linux machine. 8- Run gdbserver on remote machine like this : gdbserver host:2159 ./project1 9- Set breakponits where you want. 10- Run project in your IDE and test it. I edited wiki for now : http://wiki.lazarus.freepascal.org/Remote_Debugging#Using_gdbserver ---------------------------------------------------------------------- mig-31 · 2016-05-03 08:07 A lot of steps. For me it not make sense todo remote debug Linux machine under Windows machine, more simple todo it remote Linux under Linux. ---------------------------------------------------------------------- Martin_fr · 2016-05-03 15:19 Quote from: aradeonas on May 03, 2016, 08:11:11 am1- Manually include gdbmidebugger the public "uses" clause of debugmanager.pas file located in lazarus/ide and recompile ide. Why? The package should take care of that. ---------------------------------------------------------------------- aradeonas · 2016-05-04 09:35 It seems in newer version of Lazarus package is installed by default. Can you verify it? ---------------------------------------------------------------------- z0rr0 · 2017-02-28 11:27 This is very interesting indeed. I am planning to do it to debug my kernel in pascal by connecting to the qemu machine. Do you see any issue related with the steps proposed above? I don't understand what it means "Manually include gdbmidebugger the public "uses" clause of debugmanager.pas". Thanks