Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Using Valgrind with gdb in Eclipse
Using Valgrind with gdb in Eclipse [message #1281792] Tue, 01 April 2014 11:08 Go to next message
John Jefferies is currently offline John JefferiesFriend
Messages: 1
Registered: April 2014
Junior Member
Hello,
[I'm aware of the same question posted 2 years ago at http://www.eclipse.org/forums/index.php/t/354700/, but it doesn't give enough useful clues.]

I have a need to debug an application running within valgrind because for some reason it is manifesting an error that isn't there when the application is run standalone.

I have read the valgrind docs at http: //valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver (*), that tells us how to run the application in one command window, and use gdb in another, and that works. But how can I debug using Eclipse?

I seem to have got close by starting my application in a command window using:
valgrind --vgdb=yes --vgdb-error=0 <my application + args>

which stops and tells me to start gdb and use this gdb command:
target remote | /usr/lib/valgrind/../../bin/vgdb --pid=46181

If I put that line in a gdb command file that is referenced from the Debugger tab of the debug configuration I'm using, the application starts running, but breakpoints don't trigger.

What am I missing to trigger breakpoints?

Many thanks

John

(*) I wasn't allowed to include this as a link.
Re: Using Valgrind with gdb in Eclipse [message #1295602 is a reply to message #1281792] Mon, 14 April 2014 12:05 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
[I'm aware of the same question posted 2 years ago at http://www.eclipse.org/forums/index.php/t/354700/, but it doesn't give enough useful clues.]

I was also not able to get it working this way (my last question in the thread was not answered).
However, I found a different way to use gdb and Valgrind in Eclipse. I posted the instructions in Bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=269687
This works quite well for me for some years.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Using Valgrind with gdb in Eclipse [message #1422276 is a reply to message #1281792] Fri, 12 September 2014 15:42 Go to previous message
Rafael Gago is currently offline Rafael GagoFriend
Messages: 1
Registered: September 2014
Junior Member
I spent a part of my day trying to figure out a better and simpler way to do this (the solution in the previous answer didn't work for me) . I found one. I don't want anyone to lose its time so I'm bumping an old post.

Instructions:

1 - Create a "gdb_init" file (with the name that you want) containing the next lines and store it somewhere in your machine:

target remote | /usr/bin/vgdb
set sysroot /
define run

In my case there is no --pid option after "target remote | /usr/bin/vgdb", as I'm just running one valgring process simultaneously.

2 - Create a new regular "C/C++ Application" debug configuration. Then in the "Debugger" tab set the "GDB command file" field to the path of the file that you created in the previous step.

3 - Make the valgrind gdbserver be ready to run your app (in a separate terminal) "valgrind --vgdb=full --vgdb-error=0 APP ARG1 ARG2 ..."

4 - Start the debugger (gdb client) using the previously created debug configuration.

Now each time that valgrind finds an error the debugger breaks. You have the full stack trace and variable values.

The trick/hack here is that the custom "gdbinit" file runs before gdb executes the "run" command, so redefining the "run" command to do nothing (using the "define" gdb command) workarounds the problem of the eclipse debugger detecting that the first "run" command session has ended.

I don't know the internals, but integrating this with the current "Remote Application" debugger looks like an easy job for some Java developer that already knows the internals.

This was tested in eclipse luna.

[Updated on: Mon, 15 September 2014 07:22]

Report message to a moderator

Previous Topic:include paths for C
Next Topic:Auto generate dependencies
Goto Forum:
  


Current Time: Tue Apr 16 20:31:56 GMT 2024

Powered by FUDForum. Page generated in 0.04580 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top