Solved

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

Posted on 2008-06-16
3
324 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

790 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