Author Topic: How can I debug into the C++ source code?  (Read 5388 times)

Offline leeguevara

  • Single posting newcomer
  • *
  • Posts: 4
How can I debug into the C++ source code?
« on: February 06, 2010, 07:12:39 am »
Hi, all. I am a begineer of C++. I use the code::blocks, and I want to debug into the c++ source code.
For example,I write a simple code.

int main()
{
     int i=10;
     cout<<i<<endl;
}

I toggle a break point before the "cout", and I want to step into the "cout".
In the "call stack" window, I can see such message "#0 0042E583   std::ostream::operator<<(std::ostream& (*)(std::ostream&) (C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iostream:77)"   

How can I see source code of "std::ostream::operator<<(std::ostream& (*)(std::ostream&)"?
Thanks a lot.

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: How can I debug into the C++ source code?
« Reply #1 on: February 06, 2010, 07:35:07 am »
Hi, all. I am a begineer of C++. I use the code::blocks, and I want to debug into the c++ source code.
For example,I write a simple code.

int main()
{
     int i=10;
     cout<<i<<endl;
}

I toggle a break point before the "cout", and I want to step into the "cout".
In the "call stack" window, I can see such message "#0 0042E583   std::ostream::operator<<(std::ostream& (*)(std::ostream&) (C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iostream:77)"   

How can I see source code of "std::ostream::operator<<(std::ostream& (*)(std::ostream&)"?
Thanks a lot.

You need to actually have a copy of the source code somewhere on your hard-disk; all the debugger will ever do is read that source code file and show you which line you are currently on.  If the debugger can not find the source code, it will not be able to show it to you.

Also, you really need to be asking these sorts of questions on a forum dedicated to C++ programming.  This forum is for discussing Code::Blocks (which in an IDE, not a compiler).

Ringo

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5930
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How can I debug into the C++ source code?
« Reply #2 on: February 06, 2010, 07:37:46 am »
Hi, all. I am a begineer of C++. I use the code::blocks, and I want to debug into the c++ source code.
For example,I write a simple code.

int main()
{
     int i=10;
     cout<<i<<endl;
}

I toggle a break point before the "cout", and I want to step into the "cout".
In the "call stack" window, I can see such message "#0 0042E583   std::ostream::operator<<(std::ostream& (*)(std::ostream&) (C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iostream:77)"   

How can I see source code of "std::ostream::operator<<(std::ostream& (*)(std::ostream&)"?
Thanks a lot.
No, you can't debug into the source of "cout". only if you're using a debug version of c++ library.
So, did you build the c++ library yourself?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline leeguevara

  • Single posting newcomer
  • *
  • Posts: 4
Re: How can I debug into the C++ source code?
« Reply #3 on: March 02, 2010, 10:10:51 am »
I didn't build the C++ library myself. I just down load the MinGW from the internet.