Solved

How to set break point in a method in a class and other questions?

Posted on 2008-06-16
3
319 Views
Last Modified: 2010-04-16
New to gdb  !!! I have trouble  in few issues.
1) Is it possible to browse source code from inside gdb?
2) How to set a break point in a function in a class?
3) How to set a break point in constructor?
4) How to switch between threads?


Thanks
Emad
0
Comment
Question by:EmadGirgis
  • 2
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21795027
>1) Is it possible to browse source code from inside gdb?
Browse as in code navigation - No ... But you can trace through the code ... n takes you to next statement and s steps into it
A basic primer
http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html

>2) How to set a break point in a function in a class?
b function_name
OR
b filename:lineno

b stands for brakpoint

>3) How to set a break point in constructor?
gdb ./a.out
b filename:lineno
run

>4) How to switch between threads?
info threads
this will display all current threads ... note down the thread number that you wish to switch to
thread <thread no>
0
 

Author Comment

by:EmadGirgis
ID: 21795247
Thanks!!

So,

If I need a file name of myclass.cpp
I use :myclass.cpp:101
or myclass.h:101

Do I need to provide a path for the file source?
=================================================================
can you say
b myclass::myfunction

====================================
can you give me a little definition on trace and how to do it in couple of steps?

============================
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 21795359
You can use either of myclass.cpp:101 myclass.h:101 ... former sets a breakpoint in the .cpp file and latter sets it in a .h file ... however generally we dont have much interesting executable code in .h file, so probably you would like to place it in the .cpp file.

>Do I need to provide a path for the file source?
You need to load the binary in the same directory as source ... gdb would automatically detect the source so you need only to specify the filename.

>can you say
>b myclass::myfunction
Yes

>can you give me a little definition on trace and how to do it in couple of steps?
Its a way of instrumenting your code ... You would define various messages within your source embedded in specific directives  ... you turn on those directives to get various levels of details of code execution.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question