Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

738 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