Gdbserver: Difference between revisions

Content deleted Content added
m clean up, typos fixed: developper → developer, added orphan tag using AWB
Adding short description: "Remote debugging program"
 
(40 intermediate revisions by 28 users not shown)
Line 1:
{{Short description|Remote debugging program}}
{{orphan|date=February 2010}}
{{lowercase|title=gdbserver}}
'''gdbserver''' is a computer program that makes it possible to remotely [[Debugging|debug]] other programs.<ref>[http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_130.html GDB Manual]</ref> Running on the same system as the program to be debugged, it allows the [[GNU Debugger]] to connect from another system; that is, only the executable to be debugged needs to be resident on the target system ("target"), while the source code and a copy of the binary file to be debugged reside on the developer's local computer ("host"). The connection can be either TCP or a serial line.
 
== How Itit Worksworks ==
{{dated prod|concern = non-notable and written like a how to.|month = February|day = 11|year = 2010|time = 23:55|timestamp = 20100211235555}}
# <code>gdbserver</code> is launched on the target system, with the arguments:
<!-- Do not use the "dated prod" template directly; the above line is generated by "subst:prod|reason" -->
#* Either a device name (to use a serial line) or a TCP hostname and port number, and
{{Unreferenced|date=February 2010}}
#* The path and filename of the executable to be debugged
'''gdbserver''' is a program that allows to remotely debug with the [[GNU Debugger]]. It runs as a command-line tool on many [[Unix-like]] systems.{{clarify}}
#:It then waits passively for the host gdb to communicate with it.
# <code>gdb</code> is run on the host, with the arguments:
#* The path and filename of the executable (and any sources) on the host, and
#* A device name (for a serial line) or the IP address and port number needed for connection to the target system.
 
Example for debugging a program called <code>hello_world</code> on a remote target using TCP ("2159" is the [[List of TCP and UDP port numbers#Registered ports|registered TCP port number for remote GDB]]):
It only needs the presence of the executable on the target, while the source code stays in the computer used by the developer (with also a copy of the binary file).
<syntaxhighlight lang="console">
remote@~$ gdbserver :2159 hello_world
Process hello_world created; pid = 2509
Listening on port 2159
</syntaxhighlight>
 
<syntaxhighlight lang="console">
== How It Works ==
local@~$ gdb -q hello_world
# <tt>gdbserver</tt> is launched on the target with the path and name of the executable to debug, and a port number (TCP or UDP). It listens for connections on the port.
Reading symbols from /home/user/hello_world...done.
# <tt>gdb</tt> is run on the host with the path and name of the executable (and the sources) on the host, and the IP address and port number to connect to the target.
(gdb) target remote 192.168.0.11:23452159
Remote debugging using 192.168.0.11:2159
0x002f3850 in ?? () from /lib/ld-linux.so.2
(gdb) continue
Continuing.
 
Program received signal SIGSEGV, Segmentation fault.
This is a example of a command to run on the target (where "hello_world" is the name of the executable and "2345" the TCP port number):
0x08048414 in main () at hello_world.c:10
gdbserver hello_world :2345
10 printf("x[%d] = %g\n", i, x[i]);
(gdb)
</syntaxhighlight>
 
== Alternatives ==
From the host side, {{{gdb}}} is run in the standard way
Another technique for debugging programs remotely is to use a ''remote stub''.<ref>[https://sourceware.org/gdb/onlinedocs/gdb/Remote-Stub.html#SEC140 Debugging with GDB]</ref>{{Clarify|date=February 2010}} In this case, the program to be debugged is linked with a few special-purpose subroutines that implement the GDB remote serial protocol. The file containing these subroutines is called a "debugging stub".
gdb hello_world
and then needs to connect
target remote 192.168.0.11:2345
 
== See also ==
 
* [[GNU Debugger]]
* [[KGDB]]
 
=== ExternalNotes links ===
{{Reflist}}
* [http://www.gnu.org/software/gdb/ GDB homepage]
 
== References ==
* Andreas Zeller: <cite>Why Programs Fail: A Guide to Systematic Debugging</cite>, Morgan Kaufmann, 2005. {{ISBN|1-55860-866-4}}
 
== External links ==
* [httphttps://www.gnu.org/software/gdb/ GDB homepage]
* [http://davis.lbl.gov/Manuals/GDB/gdb_17.html Debugging with GDB]
 
{{GNU}}
 
[[Category:Debuggers]]
[[Category:GNU project software|DebuggerDebugging]]
[[Category:GNU Project software|Debugger]]
[[Category:Unix programming tools]]
 
 
[[fr:Gdbserver]]
{{compu-prog-stub}}