Thread: Questions about Debug and Library

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    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!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    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!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    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.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Thank you!
    Last edited by lehe; 01-30-2009 at 11:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

Tags for this Thread