#How to use GDB debugger to debug an array with user input

1 messages · Page 1 of 1 (latest)

worldly pendant
#

As the title says.

I am having a segmentation fault in my program.
The code is a fairly simple one - to do a set union on two arrays. I am making use of pointers and that's probably where the bug's occurring. I have been trying for the past two hours but as of now, I am unable to spot any bugs in it. So, in the end, now I am thinking to debug it as the last option.
The arrays take user input and I am stumped since I am unable to use the debugger on them. I know very basic stuff about how to use GDB to debug fairly simple programs and my past experience was always with arrays that already had data in them.
I tried searching on Youtube but was unable to find any source about it.

Does anyone know how to do it? Or maybe some resource that explains how to do it? It would be greatly helpful to me!

solemn bladeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

split igloo
#

if you've compiled with debug info, and it's an actual array type, you can simply do print array where array is the name of the array variable. if it's memory returned by malloc, you can use the x (examine) command, like x/6gd array to view six 64 bit array entries in decimal. use h x or help x for more info

#

also now that i think about it, you can still use print on a malloced array, you just have to cast it to an array type, like print (int[6])*array

#

these commands also work with memory addresses if you know their locations but gdb doesn't know their name

#

another thing you could do is to set a watch point on the array, which will trigger a break whenever the data is changed, like watch (int[6])*array

solemn bladeBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.