• C


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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

>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
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

oops .. looks like I misinterpreted it
codenamecharlieAuthor Commented:
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
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to

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.


EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.