LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Debugging Problem in Gdb (https://www.linuxquestions.org/questions/programming-9/debugging-problem-in-gdb-694113/)

akm3 12-31-2008 02:07 PM

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

David1357 12-31-2008 04:02 PM

Quote:

Originally Posted by akm3 (Post 3392849)
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.

akm3 12-31-2008 04:52 PM

Quote:

Originally Posted by David1357 (Post 3392907)
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?

David1357 12-31-2008 05:25 PM

Quote:

Originally Posted by akm3 (Post 3392937)
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 (Post 3392937)
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

akm3 12-31-2008 06:44 PM

Quote:

Originally Posted by David1357 (Post 3392964)
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.

David1357 01-01-2009 10:03 AM

Quote:

Originally Posted by akm3 (Post 3393018)
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.


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