LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-31-2008, 02:07 PM   #1
akm3
LQ Newbie
 
Registered: Dec 2008
Location: Atlanta GA
Distribution: Ubuntu 8.10
Posts: 11

Rep: Reputation: 0
Debugging Problem in Gdb


Dear All,

I have written a program with FFMPEG API(This a library for video/audio manipulation)
I have tried to debug the executable file using DDD(which uses 'gdb' itself)

To make it simple, I am trying to see where in the ffmpeg source code, a function (namely "avcodec_decode_video()")referes to.
I put a breakpoint on the function name, and use "step" to debug.
But, when it reaches the line containing the function, I get the following message:
http://i43.tinypic.com/6ej436.jpg

I wanted to know which of these is the source of this error;

1) I have done some mistakes installing ffmpeg (i.e. wrong ./configure options [I think this is not the case, since I've disabled all optimization options])

2) I have problem with "root" privileges (since the libraries are at "use/local/lib")(note I tried "sudo ddd executable_filename" instead of "ddd executable_filename", and i get an error in the beginnig of debugging which says :
http://i39.tinypic.com/311ozyq.png
)

3) I am using gcc(in compiling the file)wrongly
(I compile it like:
Code:
gcc -o executable_filename myCCode.c -g -lavutil -lavformat -lavcodec -lz
where I have used the names of the required libraries and -g for being debuggable
)(Note that the program compiles correctly, and works when I'm not debugging)

I appreciate your help on this, cuz it has made me stuck in working on a project.
Though, this is not an ffmpeg forum, I am attaching the source code, in case anybody with knowledge of ffmpeg wants to take a look.

My C Code
 
Old 12-31-2008, 04:02 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by akm3 View Post
I put a breakpoint on the function name, and use "step" to debug.
You cannot step into the source code for a library unless
  1. The library was built with debugging information included.
  2. You have the source code for the library.

Debugging library code is quite tricky. You need to know how to build the library from source with debugging information included. You will probably need to use the "-L" option to gcc to override the library include path with the path to your debugging libraries.

Last edited by David1357; 12-22-2009 at 09:47 AM. Reason: Changed "library was build" to "library was built".
 
Old 12-31-2008, 04:52 PM   #3
akm3
LQ Newbie
 
Registered: Dec 2008
Location: Atlanta GA
Distribution: Ubuntu 8.10
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David1357 View Post
You cannot step into the source code for a library unless
  1. The library was build with debugging information included.
  2. You have the source code for the library.

Debugging library code is quite tricky. You need to know how to build the library from source with debugging information included. You will probably need to use the "-L" option to gcc to override the library include path with the path to your debugging libraries.

Well, I have the source code for the library, since it is an oopen-source one.
To build it with debugging information, I followed the following instructions:

Quote:
....You need to tell libav's makefile to
add "-g" to all calls to gcc, and tell the makefile not to run "strip" on the library when you are done. Also, its handy not to get lost in
assembly code and you want your debugger to generally follow the source
line-by-line, so might as well disable optimizations while you're at it.

And, you do this with the configure command, which generates the makefiles
for you.

Use:
configure --enable-shared --disable-static --disable-optimizations
--disable-mmx --disable-stripping

You can look at ./configure --help for details.
I configured the library on linux with the above mentioned options, and then did a "make" , "make install".
But I still had the problem with debugging that it says "Cannot access memory at address ****"

So, first of all, are you sure the cause of this error is that I have errors in building the library, and it still doesn't have the debug information?

Second, since I am using "./configure"+"make"+"make install" to build the library, how should I override the library include path with the path to my debugging libraries?
 
Old 12-31-2008, 05:25 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by akm3 View Post
So, first of all, are you sure the cause of this error is that I have errors in building the library, and it still doesn't have the debug information?
Do you have two versions of the library installed? Is there a version in "/usr/lib" and your debug version in "/usr/local/lib"?

Quote:
Originally Posted by akm3 View Post
Second, since I am using "./configure"+"make"+"make install" to build the library, how should I override the library include path with the path to my debugging libraries?
Did you run "configure" with the specified options?

Did you tell "make" to use the "-g" option for compiling and linking?
Code:
$ make CFLAGS=-g LDFLAGS-g
Did you pass the path to your debug libraries to GCC?
Code:
$ gcc -o executable_filename myCCode.c -g -L/usr/local/lib -lavutil -lavformat -lavcodec -lz
 
Old 12-31-2008, 06:44 PM   #5
akm3
LQ Newbie
 
Registered: Dec 2008
Location: Atlanta GA
Distribution: Ubuntu 8.10
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David1357 View Post
Do you have two versions of the library installed? Is there a version in "/usr/lib" and your debug version in "/usr/local/lib"?



Did you run "configure" with the specified options?

Did you tell "make" to use the "-g" option for compiling and linking?
Code:
$ make CFLAGS=-g LDFLAGS-g
Did you pass the path to your debug libraries to GCC?
Code:
$ gcc -o executable_filename myCCode.c -g -L/usr/local/lib -lavutil -lavformat -lavcodec -lz
Thanks a lot for your help.
I appreciate it.
Seems that the problem was with having two versions in /usr/lib and /usr/local/lib, the latter had debug information, but I was using the former all the time.
I included -L/usr/local/lib, and it goes inside the code now.

Thnaks agiain.
 
Old 01-01-2009, 10:03 AM   #6
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by akm3 View Post
Thanks a lot for your help.
You are eminently welcome. If I know anything about Linux, it is because so many people took the time to answer my questions.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DISCUSSION: Debugging with GDB (Part 1) Matir LQ Articles Discussion 3 10-21-2011 09:46 AM
thread debugging gdbserver gdb 256Doofus Linux - Embedded & Single-board computer 6 04-13-2009 06:13 AM
gdb debugging assembly with no symbols Four Programming 5 10-01-2008 08:47 PM
debugging remote process in gdb arunachalam Linux - Software 2 02-18-2008 10:27 PM
gdb problem during debugging xine crash ... rs_javadi Linux - Software 0 08-24-2004 06:25 AM


All times are GMT -5. The time now is 01:42 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