Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB remote debugging with valgrind

If I remote debug using gdb I connect to the gdbserver using

target remote host:2345

If I debug memory errors with valgrind and gdb (to break on invalid memory access) I use

target remote | vgdb

(after starting

valgrind --track-origins=yes --vgdb=yes --vgdb-error=0 [binary]

on the local machine)

Can I combine the two to debug memory errors on a remote machine?

Note that I want to avoid using a login shell on the remote machine to work there.

like image 474
highsciguy Avatar asked Mar 05 '13 14:03

highsciguy


People also ask

Can you run GDB with Valgrind?

Using Valgrind and GDB togetherStart up two terminal windows so that you can interact with Valgrind and GDB simultaneously. In one terminal, run Valgrind with the --vgdb-error=0 option. When running with --vgdb-error= n, Valgrind waits for n errors to occur before pausing and waiting for a connection from GDB.

How does Valgrind help in debugging?

The GNU Debugger (GDB) allows you to pause a running program and inspect its state. Valgrind's memcheck monitors a program's memory accesses and prints warnings if the program accesses invalid locations or attempts to read values that the program never set (initialized).

Is Valgrind a debugging tool?

Valgrind (/ˈvælɡrɪnd/) is a programming tool for memory debugging, memory leak detection, and profiling. Valgrind was originally designed to be a free memory debugging tool for Linux on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers.

Does Valgrind require debug build?

To be most effective valgrind requires that debugging information be present in the binaries that are being instrumented, although a full debug build is not required.


1 Answers

Can I combine the two to debug memory errors on a remote machine?

Yes: current vgdb accepts --port= argument since this commit:

r12204 | sewardj | 2011-10-22 13:38:08 -0700 (Sat, 22 Oct 2011) | 5 lines

So run vgdb --port=2345, and then (gdb) target remote host:2345 as usual.

like image 166
Employed Russian Avatar answered Oct 22 '22 10:10

Employed Russian