Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-16
3
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

670 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