Difference between revisions of "Remote Debugging"

From Free Pascal wiki
(Introduction)
(Using SSH (Secure Shell): Language; rlogin etc are ancient. Anyway, mentioning this here is irrelevant)
Line 17: Line 17:
 
== Using SSH (Secure Shell) ==
 
== Using SSH (Secure Shell) ==
  
SSH (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP/IP ports can also be forwarded over the secure channel.
+
SSH (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP/IP ports can also be forwarded over the secure channel.
  
See the SSH man page for details. This text only handles ssh protocol 2. For differences for protocol 1 see the SSH man page.
+
See the SSH man page for details. This text only covers SSH protocol 2. For differences for protocol 1 see the SSH man page.
  
 
=== Requirements for Lazarus ===
 
=== Requirements for Lazarus ===
You must be able to log in via ssh to the remote machine (the computer where the program will run). This means the remote machine has an installed and running ssh server and you have an account allowed to login from your local machine (the computer where the lazarus IDE is running).
+
You must be able to log in via ssh to the remote machine (the computer where the program will run). This means the remote machine has an installed and running SSH server and you have an account allowed to login from your local machine (the computer where the Lazarus IDE is running).
  
 
You can test this by doing:
 
You can test this by doing:
 +
<syntaxhighlight lang="bash"> 
 +
ssh username@remotecomp ls -la
 +
</syntaxhighlight>
 
    
 
    
[]$ ssh username@remotecomp ls -la
+
This will create an SSH connection to 'remotecomp' with the username 'username'. After authentication it will print out a directory listing and return.
 
 
This will create a ssh connection to 'remotecomp' with the username 'username' and after authentification it will print out a directory listing and return.
 
 
    
 
    
 
==== Configuring SSH ====
 
==== Configuring SSH ====
  
The IDE needs a ssh connection without prompting for a password. There are a
+
The IDE needs an SSH connection that does not prompt for a password. There are a lot of possibilities to achieve this. This text only describes a few. For security reasons it is strongly recommended that you read the SSH manpage.
lot of possibilities to achieve this. This text only describes a few. For
 
security reasons it is strongly recommended that you read the SSH manpage.
 
  
Solution 1: User based authentification.
+
Solution 1: User based authentication.
  
This will allow one specific user on the local computer to establish a ssh connection to the remote computer as a specific user without prompting for password.  
+
This will allow one specific user on the local computer to establish an SSH connection to the remote computer as a specific user without prompting for passwords.  
  
 
: ToDo: describe the server settings. On redhat this works without any change.
 
: ToDo: describe the server settings. On redhat this works without any change.
 
      
 
      
;Step 1: create the rsa key on the local machine
+
;Step 1: create the public and private keys on the local machine
 
This will create two files on the local machine:
 
This will create two files on the local machine:
 
   ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub
 
   ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub
Line 49: Line 48:
 
Keep the default and leave the passphrase empty.
 
Keep the default and leave the passphrase empty.
 
              
 
              
;Step 2: copy the public rsa key of the local machine to the remote machine
+
;Step 2: copy the public key of the local machine to the remote machine
  []$ scp ~/.ssh/id_rsa.pub user@remotecomp:remote.pub     
+
<syntaxhighlight lang="bash">  
;Step 3: create on the remote machine the file ~/.ssh/authorized_keys2
+
scp ~/.ssh/id_rsa.pub user@remotecomp:remote.pub     
  []$ ssh user@remotecomp
+
</syntaxhighlight>
[]$ touch ~/.ssh/authorized_keys2
+
 
[]$ chmod 600 ~/.ssh/authorized_keys2<br>  
+
;Step 3: create the file ~/.ssh/authorized_keys2 on the remote machine
The chmod will set the permissions to only allow yourself to read the file. ssh wants this.    
+
<syntaxhighlight lang="bash">  
  []$ cat remote.pub >> ~/.ssh/authorized_keys2
+
ssh user@remotecomp
  []$ rm remote.pub
+
touch ~/.ssh/authorized_keys2
  []$ exit
+
chmod 600 ~/.ssh/authorized_keys2
 +
</syntaxhighlight>
 +
 
 +
The chmod will set the permissions to only allow yourself to read the file. SSH requires this.
 +
<syntaxhighlight lang="bash"> 
 +
cat remote.pub >> ~/.ssh/authorized_keys2
 +
rm remote.pub
 +
exit
 +
</syntaxhighlight>
 +
 
 
;Step 4: test
 
;Step 4: test
 
You should now be able to login without password.
 
You should now be able to login without password.
  []$ ssh user@remotecomp
+
<syntaxhighlight lang="bash"> 
 +
ssh user@remotecomp
 +
</syntaxhighlight>
 +
 
 
;Step 5: Setup the ssh debugger in the IDE
 
;Step 5: Setup the ssh debugger in the IDE
 
''ToDo''
 
''ToDo''
 
----
 
----
;Step 5a: Setup "Run parameters"  
+
 
For remote debug we need setup corect value for "Host aplication", "Command line parameters" and "Working directory".
+
;Step 6: Set "Run parameters"  
 +
For remote debug we need to set the correct value for "Host application", "Command line parameters" and "Working directory".
 
Remember: '''It is remote!'''  
 
Remember: '''It is remote!'''  
 
    
 
    
 
[[File:remote_debug_run_parameters.png]]
 
[[File:remote_debug_run_parameters.png]]
;Step 5b: Setup "Debugger parameters"  
+
 
 +
;Step 7: Set "Debugger parameters"  
 
Select "Debugger type and path" to "GNU Debugger trough SSH(ssh)"  
 
Select "Debugger type and path" to "GNU Debugger trough SSH(ssh)"  
  
 
[[File:remote_debug_debuger_parameters.png]]
 
[[File:remote_debug_debuger_parameters.png]]
 
''ToDo''
 
''ToDo''
 
  
 
== Using gdbserver ==
 
== Using gdbserver ==

Revision as of 13:40, 18 November 2014


Introduction

Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. In the following examples the name of the local computer is 'localcomp' and the name of the remote computer is 'remotecomp'.

Note-icon.png

Note: Remote debugging will only work if the gdb supports async mode (see gdb doc for "set target async"). GDBServer usually does. GDB does for some targets only. In some cases gdb/gdbserver does support it, but not if "mi" mode is used (used by the IDE. A workaround for this must yet be implemented in the IDE.
IF async mode is not supported, or not for "mi" then:

  • It is currently not possible to use the "Pause" function to interrupt the running application.
  • It is not possible to modify break-/watch-points, while the application in the debugger is running.
  • One should no switch editor tabs, or open/close units, while the application in the debugger is running.
The 2nd and 3rd can be done, if the app in the debugger is paused. The only way for the app to become paused is by reaching a breakpoint that was set before the app was run.

Using SSH (Secure Shell)

SSH (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP/IP ports can also be forwarded over the secure channel.

See the SSH man page for details. This text only covers SSH protocol 2. For differences for protocol 1 see the SSH man page.

Requirements for Lazarus

You must be able to log in via ssh to the remote machine (the computer where the program will run). This means the remote machine has an installed and running SSH server and you have an account allowed to login from your local machine (the computer where the Lazarus IDE is running).

You can test this by doing:

  
ssh username@remotecomp ls -la

This will create an SSH connection to 'remotecomp' with the username 'username'. After authentication it will print out a directory listing and return.

Configuring SSH

The IDE needs an SSH connection that does not prompt for a password. There are a lot of possibilities to achieve this. This text only describes a few. For security reasons it is strongly recommended that you read the SSH manpage.

Solution 1: User based authentication.

This will allow one specific user on the local computer to establish an SSH connection to the remote computer as a specific user without prompting for passwords.

ToDo: describe the server settings. On redhat this works without any change.
Step 1
create the public and private keys on the local machine

This will create two files on the local machine:

 ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub

If you already have these files, skip this step.

 []$ ssh-keygen -t rsa

Keep the default and leave the passphrase empty.

Step 2
copy the public key of the local machine to the remote machine
  
scp ~/.ssh/id_rsa.pub user@remotecomp:remote.pub
Step 3
create the file ~/.ssh/authorized_keys2 on the remote machine
  
ssh user@remotecomp
touch ~/.ssh/authorized_keys2
chmod 600 ~/.ssh/authorized_keys2

The chmod will set the permissions to only allow yourself to read the file. SSH requires this.

  
cat remote.pub >> ~/.ssh/authorized_keys2
rm remote.pub
exit
Step 4
test

You should now be able to login without password.

  
ssh user@remotecomp
Step 5
Setup the ssh debugger in the IDE

ToDo


Step 6
Set "Run parameters"

For remote debug we need to set the correct value for "Host application", "Command line parameters" and "Working directory". Remember: It is remote!

remote debug run parameters.png

Step 7
Set "Debugger parameters"

Select "Debugger type and path" to "GNU Debugger trough SSH(ssh)"

remote debug debuger parameters.png ToDo

Using gdbserver

See