LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can and how do I run a program with GDB? (http://www.linuxquestions.org/questions/linux-newbie-8/can-and-how-do-i-run-a-program-with-gdb-878576/)

perort 05-03-2011 11:33 AM

Can and how do I run a program with GDB?
 
I want to run a file off the Internet with GNU Debugger. So I download the tar.gz file off the Internet, and I extract it and compile it. Then in the directory of the compiled source, I type: gdb -q ./whatever.c
where "whatever.c" is the name of the file I want to run

However, when I do this gdb doesn't have access to the source code, so I cant do much with it. So is there any way I can make it have access to the source code? Please be specific, I'm not very good with this kind of thing.

Thanks!

MS3FGX 05-03-2011 11:48 AM

You need to compile the program with GDB debug info enabled using the -g option, you can't run it on normal binary programs.

Doing this depends on the program's makefile, but usually could be done with something like:

Code:

make CFLAGS=-g

perort 05-03-2011 12:38 PM

Reply
 
Okay. So what changes do I need to make in the makefile so that it compiles that way? Do I just need add the line "make CFLAGS=-g" somewhere in the makefile?

Nylex 05-03-2011 12:45 PM

If there is a line containing the variable CFLAGS, then simply add the -g flag to it. If the line doesn't exist, then add the whole thing (i.e. add the line"CFLAGS=-g").

perort 05-04-2011 10:58 AM

Response
 
I tried this and it failed. Can you please be more specific? Or give me a link which will show me in more detail how to do this? Thanks!

Nylex 05-04-2011 11:55 AM

What do you mean by "it failed"? Please post error messages verbatim. I'd google for makefile tutorials. Otherwise, post the makefile here and what exactly you're having problems with.

perort 05-04-2011 03:12 PM

Reply
 
There were no variables named CFLAGS, so I added the line "CFLAGS=-g" to the makefile. It compiled without any errors. But when I ran it with GDB it still didn't let me look at the source code. So basically adding "CFLAGS=-g" didn't change anything. I even tried it on many different files off the Internet, and this didn't work with any of them.

MS3FGX 05-04-2011 03:52 PM

The line "CFLAGS=-g" itself doesn't do anything, the makefile has to be setup for it. Since your makefile didn't include that variable, adding the line will do nothing. Without the CFLAGS variable, you might as well just find the line where the makefile is calling gcc and add in "-g" yourself.

Can you post the makefile (use CODE tags), or at least tell us what program you are trying to compile?

bigrigdriver 05-04-2011 04:15 PM

A question for perort: the tar.gz file that you compiled; does the compile begin with the ./configure step? If yes, then you can edit the makefile in the prefered method, by setting the appropriate options to ./configure.

Try "./configure --with-gdb" (sans quotes), then make and install.

Vrajgh 05-04-2011 04:19 PM

Quote:

Originally Posted by perort (Post 4345160)
... Then in the directory of the compiled source, I type: gdb -q ./whatever.c
where "whatever.c" is the name of the file I want to run

Your compiled executable will not have a .c extension so make sure you are pointing the debugger at the correct file.

If this was a typo in your original post then this advice won't help!

perort 05-04-2011 06:58 PM

Reply
 
Okay, thanks. Bigrigdriver's ./configure method worked.


All times are GMT -5. The time now is 02:23 AM.