This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Valgrind - used gdb


Hi Srivatsan,

> it again says that the error occured in the function.
> parseString() (but no line number is shown :-( )

Isn't this...

> #0  ABCParser::parseString (this=0x344b86f0) at
> stl_vector.h:501
> #1  0x341bb8f3 in ABCParser::execute (this=0x344b86f0)
> at ABCParser.cpp:97

...in parseString?

Remember, std::vector is a template, which means that it is instantiated,
and many of its routines are inlined.  Maybe use the -fno-inline flag.

What happens when you step through the routine?

Divide and conquer the bugs.  Set breadcrumb breakpoints inching forward,
such as "good to line 80"... "now good to line 86"... hmmm "broken between
line 86 and line 105" (the bug gets triggered somewhere in there)... restart
the app, get to line 86, single-step... blows up in line 92, set a break
point at line 91... oops, there is no line 91 since that's a comment...
breakpoint at line 90.  Restart.  Line 90, okay single-step and dive into
subroutines.  Subroutine A is called, line 1000 of A is good, 1001, 1002,
1003, 1007 broken.  Hmm, bug triggers between 1003 and 1007.  Restart.
Breakpoint at 1003.  Continue.  Hits breakpoint 90.  Continue.  Hits
breakpoint 1003.  Dive into sub-subroutine B.  Single-step.  Et cetera.

> it doesn't seem to say anything more....i know that
> the invalid read is cause when a vector variable is
> read beyond its boundary....but which one?? there are
> so many vectors in my prog...and it is a one huge
> function.

Sounds like your function is TOO huge.  Strive to make routines do "one unit
of work".  If the cyclometric complexity of the routine is greater than, oh,
7 or so, it's likely doing too much.

And "too much" translates into "hard to understand, hard to maintain, hard
to debug".

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]