* * *

Author Topic: Remote debugging from Windows to Linux  (Read 3416 times)

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Remote debugging from Windows to Linux
« on: April 25, 2016, 05:01:05 pm »
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?
« Last Edit: April 25, 2016, 05:02:46 pm by aradeonas »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #1 on: April 28, 2016, 04:28:04 am »
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.html

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

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #2 on: April 28, 2016, 03:49:09 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #3 on: April 28, 2016, 04:06:24 pm »
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 https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/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

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #4 on: April 28, 2016, 04:52:34 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #5 on: April 28, 2016, 05:44:00 pm »
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

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #6 on: April 30, 2016, 11:40:33 am »
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]
  1. WinSCP.com /script=c:\Tools\script.txt
it 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

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #7 on: April 30, 2016, 03:54:24 pm »
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

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #8 on: April 30, 2016, 04:00:05 pm »
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.
 :D


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #9 on: April 30, 2016, 04:07:22 pm »
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
« Last Edit: April 30, 2016, 04:13:45 pm by Martin_fr »

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #10 on: April 30, 2016, 05:35:18 pm »
OK. I will see what can I do about it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #11 on: April 30, 2016, 05:43:38 pm »
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

  • Hero Member
  • *****
  • Posts: 824
Re: Remote debugging from Windows to Linux
« Reply #12 on: May 03, 2016, 08:11:11 am »
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
« Last Edit: May 03, 2016, 08:25:07 am by aradeonas »

mig-31

  • Full Member
  • ***
  • Posts: 208
Re: Remote debugging from Windows to Linux
« Reply #13 on: May 03, 2016, 10:07:09 am »
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.
Lazarus 1.6 - Linux 32/64 bit, win32

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4173
    • wiki
Re: Remote debugging from Windows to Linux
« Reply #14 on: May 03, 2016, 05:19:15 pm »
1- 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.

 

Recent

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