Solved

GDB

Posted on 2003-10-21
7
311 Views
Last Modified: 2010-04-15
with GDB, i think I should be able to directly call a function in my program then trace the flow step by step.

However, when the parameters of the function are very complicated, such as structures(within the structure, its
members can be structures too) instead of simple data type such as int or ulong, what can I do in this case in order
to debug this function?

Seems there is just no way out?

Thx!
0
Comment
Question by:codenamecharlie
  • 4
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9596844
Hi codenamecharlie,

set a break point at the first line of function ... b filename:line_number
run the program ... r
to examine the structs passed, use print
p struct_name->element


Cheers!
Sunny:o)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9596866
>when the parameters of the function are very complicated, such as structures(within the structure, its
>members can be structures too) instead of simple data type such as int or ulong,

you might also like to set a watch if you doubt that one particular element is bein manipulated incorrectly

otherwise, setting break points and using print is the best option

If you feel more comfortable with GUIs then look into ddd .. it is the graphical front to gdb
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 50 total points
ID: 9596891
I think sunnycoder misinterpreted your question (or perhaps I did)

I believe you want to call a function directly from the gdb  prompt as such:

gdb> p somefunction(anInt)

which is easy if somefunction() takes an int parameter.  However if it takes
a very complex data type, that data is hard to mock up using gdb commands.

What I have done in that case is to set a breakpoint in my program logic after
the complex data structure has been created.  Then manually call somefunction,
passing the data structure constructed.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

Expert Comment

by:sunnycoder
ID: 9596898
oops .. looks like I misinterpreted it
0
 

Author Comment

by:codenamecharlie
ID: 9596909
hi brettmjohnson,

yes, sunnycoder misinterpreted my Q and your understanding is correct.
Your way might be a way out.. i will look into it. Thx
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9886759
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed with A grade to brettmjohnson

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer
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

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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

747 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

14 Experts available now in Live!

Get 1:1 Help Now