Solved

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

Posted on 2008-06-16
3
299 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
Comment Utility
>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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now