Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Léa Massiot on October 28, 2012, 01:49:42 pm

Title: Debugging - Watching the contents of fixed size arrays
Post by: Léa Massiot on October 28, 2012, 01:49:42 pm
Hello,

My problem is about debugging within "C::B", "watches" and viewing the contents of fixed size arrays passed to functions.
Below is a simplified example code.

Code
#define N_ARRAY_S_LENGTH 100
int main()
{
fun_1();
return 0;
}

void fun_1()
{
unsigned char array[N_ARRAY_S_LENGTH];
[...]
fun_2(array);
[...]
}

void fun_2(unsigned char array[N_ARRAY_S_LENGTH])
{
[...]
fun_3(array);
[...]
}

void fun_3(unsigned char array[N_ARRAY_S_LENGTH])
{
array[0] = 'a';
array[1] = 0x0;
array[2] = 'b';
}

If I watch "array" in the "Watches" view when the debugging cursor points:
- inside "fun_3()" - I get: a
- inside "fun_2()" - I get: a
- inside "fun_1()" - I get: a\000b (this is what I would expect in the two previous cases).

The problem is that I can't check the contents of "array" when I'm inside "fun_3()" or "fun_2()", I have to wait till I'm back into "fun_1()".

So I am wondering why is it behaving that way.
Can you help?

Thank you.

--
OS: Debian GNU/Linux 6.0.3 (squeeze)
C::B SVN 7790
Compiler: GNU GCC Compiler
Debugger: GNU GDB
Title: Re: Debugging - Watching the contents of fixed size arrays
Post by: jarod42 on October 29, 2012, 12:05:47 pm
Code
void bar(int a[N])
is equivalent to
Code
void bar(int a[])

What you may want is
Code
void bar(int (&a)[N])
Title: Re: Debugging - Watching the contents of fixed size arrays
Post by: oBFusCATed on October 29, 2012, 07:31:52 pm
The problem is that I can't check the contents of "array" when I'm inside "fun_3()" or "fun_2()", I have to wait till I'm back into "fun_1()".
In watches windows do the following:
1. right click on a
2. select properties
3. the check watch as array
4. set the size
5. press ok
Title: Re: Debugging - Watching the contents of fixed size arrays
Post by: Léa Massiot on October 31, 2012, 10:21:42 pm
Hello jarod42 and oBFusCATed,

Both your solutions work for me.
So, thank you very much for your help  :).

Best regards.