1

I have the following code that initializes an array of unsigned chars:

     unsigned char ultralightAtr[] = {0x3b,0x8f,0x80,0x01,0x80,0x4f,0x0c,0xa0,0x00,0x00,0x03,0x06,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x68}; 

When i inspect ultralightAtr in gdb I don't get the same values:

 (gdb) x/20x ultralightAtr
 0x7fffffffdd40:    0x70    0xdd    0xff    0xff    0xff    0x7f    0x00    0x00
 0x7fffffffdd48:    0x70    0x19    0xbd    0xf7    0xff    0x7f    0x00    0x00
 0x7fffffffdd50:    0x00    0xc7    0xfd    0xf7
 (gdb) 

Am I doing something wrong initializing the array or is it something wrong with the way I am printing the memory content in gdb?

4
  • 4
    Could you post the relevant code and sequence of gdb commands you used? Commented Aug 18, 2016 at 10:23
  • 5
    When do you examine the array? Where is the array? Is it a local variable inside a function? Can you please show us a Minimal, Complete, and Verifiable Example of your program? You don't overwrite the array anywhere? Commented Aug 18, 2016 at 10:24
  • You need to run the code to at least the start of main() so that the c init code has run and has initialised ultralightAtr. Have you done that, or are you running that immediately after loading the program? Commented Aug 18, 2016 at 10:24
  • debugging the array just after having run gdb works fine, apart for some format stuff (I use x /20xb) Commented Aug 18, 2016 at 10:29

1 Answer 1

3

Both the address and the contents of ultralightAtr indicate it is a local variable with automatic storage (aka on the stack). You probably examine its value with gdb before its initialization code is run in the function where it is defined. Did you just set a breakpoint at the function address and issued the x command there?

If this array is not modified in the function, you can make it static so it is initialized at load time instead of every time the function is entered.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it is a local varable, sorry for not making that clear. Setting it static solved the problem. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.