LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   syntax for gdb to print elements of 2D array? (https://www.linuxquestions.org/questions/programming-9/syntax-for-gdb-to-print-elements-of-2d-array-539911/)

johnpaulodonnell 03-23-2007 08:28 AM

syntax for gdb to print elements of 2D array?
 
Hi.

The syntax for gdb to print all the elements of a 1-D array is:
Code:


(gdb) p myArray

and to print the next 5 elements of array myarray starting at element 3, say, is:

Code:

(gdb) p myIntArray[3]@5
Can anyone tell me the syntax to print elements when you go beyond a 1-D array?

Thanks

zWaR 03-24-2007 08:37 AM

I don't know the gdb's syntax, but perhaps you could help yourself with ddd (if you're running X), it's actually a really sophisticated GUI for gdb, which can also graphically display the arrays and it displays the gdb commands it uses.

http://www.gnu.org/software/ddd/

johnpaulodonnell 03-26-2007 06:27 AM

Thanks for that...but Suse(this and previous version anyway, I think!) is missing a certain Motif file Xm needed to build the GUI. I've come across this problem before trying to install another GUI program. I could install the Lesstif package in it's place but don't think it's worth the trouble for all I need to do...

So if anyone does know the command line gdb syntax for checkin gthe elements of a multi-dimensional array?

thanks

johnpaulodonnell 03-26-2007 07:20 AM

ok. I think the syntax is:

Code:

print array(2,3)
- for example to entry (2,3) of array array...

but I can't check this because my array is messed up!

entering

Code:

ptype myarray
into gdb returns the type of the array and the dimension of the array...is this right?

doing this for the array that I am trying to get at gives:

Code:

(gdb) ptype bderi
type = real*8 (0:-1,0:-1)

I assume the (0:-1,0:-1) refers to the extents of the array - here a bit wacky!

Can anyone confirm this?

bigearsbilly 03-26-2007 07:24 AM

if you do a lot of C programming
ddd is definitely worth it.


All times are GMT -5. The time now is 08:28 PM.