LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-03-2011, 10:33 AM   #1
perort
LQ Newbie
 
Registered: May 2011
Distribution: Fedora
Posts: 5

Rep: Reputation: 0
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!
 
Old 05-03-2011, 10:48 AM   #2
MS3FGX
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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
 
Old 05-03-2011, 11:38 AM   #3
perort
LQ Newbie
 
Registered: May 2011
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 05-03-2011, 11:45 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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").
 
Old 05-04-2011, 09:58 AM   #5
perort
LQ Newbie
 
Registered: May 2011
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
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!
 
Old 05-04-2011, 10:55 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 05-04-2011, 02:12 PM   #7
perort
LQ Newbie
 
Registered: May 2011
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 05-04-2011, 02:52 PM   #8
MS3FGX
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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?
 
Old 05-04-2011, 03:15 PM   #9
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,747

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
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.
 
Old 05-04-2011, 03:19 PM   #10
Vrajgh
Member
 
Registered: Aug 2005
Posts: 65

Rep: Reputation: 31
Quote:
Originally Posted by perort View Post
... 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!
 
Old 05-04-2011, 05:58 PM   #11
perort
LQ Newbie
 
Registered: May 2011
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
Reply

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GDB: Run program automatically kenneho Programming 5 12-05-2009 09:14 AM
Passing program arguments to gdb eddyq Linux - General 2 11-18-2009 11:17 AM
Question about running a program with gdb calypso9 Linux - Newbie 1 04-09-2009 05:30 PM
How to ru a program on GDB/ARMulator /uClinux 2.4 milky87 Linux - Embedded & Single-board computer 0 12-12-2008 03:34 PM
how can I debug the interactinve program with GDB bigapple Programming 1 08-03-2005 09:55 PM


All times are GMT -5. The time now is 09:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration