Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse debugger expression window using matrixes(Eclipse debugger does not show input matrix as expected in "Expression" window)
Eclipse debugger expression window using matrixes [message #1772164] Wed, 06 September 2017 08:51 Go to next message
Magnus Jönsson is currently offline Magnus JönssonFriend
Messages: 1
Registered: September 2017
Junior Member
Hi,

I am trying to run the below code in the Eclipse debugger and view the matrixes in the "Expression" window. I have set a breakpoint in "myFunction()" at the first for-loop and executed the program until this point. Then I added the "myGlobalMatrix" and "myInputMatrix" to the "Expression" window. In the "Expression" window I can see "myGlobalMatrix" with the [3][4] dimensions and the values inside properly. The "myInputMatrix" shows (*)[4] instead of [3][4] even if the size of the matrix is the same. When looking into the "myInputMatrix" it shows "0,10,20,0" which is the first value in each inner dimension. However, the last 0 is outside the matrix. In order to show "myInputMatrix" correctly in the "Expression" window, "Display As Array" needs to be used by rightclick on the type of "myInputMatrix" and choose the right length of the outer dimension (3).

Why is this extra step needed when looking at input matrixes to a function and not to global matrixes ?

If this is not done, the "myInputMatrix" in "Expression" window does not make any sense.

Ex:
Name : matrix.c
#include <stdio.h>
#include <stdlib.h>
int myGlobalMatrix[3][4] =
{{0, 1, 2, 3},
{10, 11, 12, 13},
{20, 21, 22, 23}};
int myFunction(int myInputMatrix[3][4]);
int myFunction(int myInputMatrix[3][4])
{
int sum,i,j;
for (i=0; i < 3; i++)
{
for (j=0; j < 4; j++)
{
sum += myInputMatrix[i][j];
}
}
return sum;
}

int main(void)
{
int mySum = 0;
mySum = myFunction(myGlobalMatrix);
return EXIT_SUCCESS;
}

Re: Eclipse debugger expression window using matrixes [message #1772424 is a reply to message #1772164] Sat, 09 September 2017 04:42 Go to previous message
David Vavra is currently offline David VavraFriend
Messages: 627
Registered: October 2012
Senior Member
This is likely a bug in the GDB/CDT interface.
Here's something that sort of works: (*myInputMatrix@4)
Looks like:
index.php/fa/30678/0/

I came across this some time ago and don't know where this is documented
Note that it assumes a square matrix (i.e., int [4][4]).
I'm not sure how to make it [3][4]
Every attempt causes an error.

What also works is to cast to type int [][4]
then display with myInputMatrix[x] where x is {0:2}
index.php/fa/30679/0/

UPDATE:
The expressions appear to be the same as those used by GDB.
For GDB 5:
https://ftp.gnu.org/pub/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_9.html#SEC54
https://sourceware.org/gdb/onlinedocs/gdb/Arrays.html

A newer one (for GDB 8): https://www.sourceware.org/gdb/onlinedocs/gdb.html

You may also find this helpful: https://stackoverflow.com/questions/19497339/how-to-print-2d-arry-values-in-gdb

[Updated on: Sat, 09 September 2017 23:55]

Report message to a moderator

Previous Topic:GLFW Arguements Read as Invalid
Next Topic:Keeping language.settings.xml under source control?
Goto Forum:
  


Current Time: Wed Dec 13 11:27:50 GMT 2017

Powered by FUDForum. Page generated in 0.02106 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software