C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-30-2009, 08:16 AM   #1
Registered User
 
Join Date: Jan 2009
Posts: 156
Questions about Debug and Library

Hi,
I have two questions. Thanks in advance for helping me out!

1. This is a question of GDB. How to step over instead of stepping into in the following code:
Code:
  for(int i = 0; i < argc; i++)
    cout << (i > 0 ? "  " : "") << argv << (i < argc - 1 ? " \\" : "")
         << endl;
I try to use next to step over, but always step into some other source file as I get the information:
Code:
517      __ostream_insert(__out, __s,
(gdb)
444         { return __check_facet(_M_ctype).widen(__c); }
(gdb)
53         if (!__f)
(gdb)
873      if (_M_widen_ok)
(gdb)
1169        __tmp[__i] = __i;
(gdb)
1168      for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
(gdb)
1169        __tmp[__i] = __i;
(gdb)
1168      for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
(gdb)
1169        __tmp[__i] = __i;
If I try to step out, I get:
Code:
(gdb) finish
"finish" not meaningful in the outermost frame.
The Makefile is something like:
Code:
LDFLAGS=-static -lm -ljpeg -lpng -lz
OPTIMIZE_FLAG = -ggdb3 -DDEBUG
CXXFLAGS = -Wall $(OPTIMIZE_FLAG)
absurdity: xxx.o
    $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
Makefile.depend: *.h *.cc Makefile
    $(CC) -M *.cc > Makefile.depend
include Makefile.depend
2. On the contrary, sometimes I'd like to get inside the implementation of some library, say libpng, but when I try to debug into it I can't. I download its source code, which contains all the .c files, from http://prdownloads.sourceforge.net/l...ar.gz?download. After ./configure, make and make install, the .h files gets into /usr/local/include/libpng12/, the library files get into /usr/local/lib/, but no .c files get into /usr/local/src/ or /usr/src. Is that why there is no source file to debug? How could I fix it?

Thanks a lot!
lehe is offline   Reply With Quote
Old 01-30-2009, 08:21 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
I can't really answer question 1 - you should use next and it should go to the next line.

For question 2:
Most likely, if you want to step into a library, you need to build it with debug symbols, and most of the time, the default build doesn't do that.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 01-30-2009, 08:59 AM   #3
Registered User
 
Join Date: Jan 2009
Posts: 156
Thanks Mats!
I looked into the configure file. Although not completely understand it, I did ./configure debug=yes. Now I can debug into the implementation of libpng. However the source code .c files are still in the directory where I put my downloaded installation files, which means "make install" does not put .c files into some system directory like /usr/local/src or /usr/src. How to specify a directory for the source files when calling ./configure?
Thank you!
lehe is offline   Reply With Quote
Old 01-30-2009, 09:04 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
I have no idea how you tell ./configure where to install the source (if it at all has the capabilty of installing the source). I also don't really see the point of copying the source to /usr/src/... What benefit would that be?

I often work on more than one version of some particular source code [changes for different reasons] - so I _LIKE_ the idea of each library knowing where the source code was that it got compiled from. And most of the time, if you do NOT move the source code, it will find it from wherever you had it when you built the library.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 01-30-2009, 09:21 AM   #5
Registered User
 
Join Date: Jan 2009
Posts: 156
Thanks!
So it means don't delete the directory from where I built the library if debugging into the source code is desired?
I am honestly not clear about the benefit, just some intuition from previous experience that the system directory might be a relatively better place to put the source files in. If the place from where I complied the source files is Desktop or some place that I frequently clean up, then the source code will not be able to traced by debugger.

I used to program in Visual C++. If not wrong, I remember a library is usually by default installed under C:/program files/libraryname/, and header files are put under C:/program files/libraryname/include, library file under C:/program files/libraryname/lib and source files under C:/program files/libraryname/src.
lehe is offline   Reply With Quote
Old 01-30-2009, 09:38 AM   #6
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Well, if you store files that you need later on the desktop, then I suggest you find a better way to keep your files organized.

I tend to have a "project" folder which I have directories for each project inside. If a project has several versions, I may have /project/blah/v1.1 and /project/blah/v1.2 or some such.

Ultimately, you need to KEEP the source code in a place you can find back to. If that means that you copy the source to /usr/src, then that's your decision. But it's not where I would store anything other than the SYSTEM source code (e.g. the linux source).

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 01-30-2009, 11:13 AM   #7
Registered User
 
Join Date: Jan 2009
Posts: 156
Thank you!

Last edited by lehe; 01-30-2009 at 11:21 AM.
lehe is offline   Reply With Quote
Reply

Tags
debug, gdb, library

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug into Source lehe C++ Programming 4 02-18-2009 10:45 AM
Linker errors in VC++ 2005 C+/- C++ Programming 0 05-18-2007 07:42 AM
VC++ 6 question: browsing into a library maxhavoc Tech Board 4 09-15-2006 06:57 AM
direct 3d x debug library required? Rune Hunter Game Programming 12 10-30-2005 06:08 PM
very weird .h problem royuco77 C++ Programming 1 09-11-2005 07:55 AM


All times are GMT -6. The time now is 02:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22