首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

arm + linux 难解有关问题 高人

2012-04-28 
arm + linux 难解问题 求助高人硬件环境 arm s3c2410a-20交叉编译环境CT_BINUTILS_VERSION2.19.1CT_KERNE

arm + linux 难解问题 求助高人
硬件环境 arm s3c2410a-20 
交叉编译环境
CT_BINUTILS_VERSION=2.19.1  
CT_KERNEL_VERSION=2.6.29.4
CT_LIBC_VERSION=2.9
[DEBUG] CT_ARCH_TARGET_CFLAGS=' -mlittle-endian -march=armv4t -mcpu=arm9tdmi -mtune=arm920t -msoft-float'
[DEBUG] CT_ARCH_TARGET_LDFLAGS=' -EL'
[DEBUG] CT_ARCH_TUNE=arm920t
gcc-4.3.2

出问题的代码如下

C/C++ code
int main(int argc, char *argv[]){    U8 testBuf[100]= {0};    //memset( testBuf,0,100 );    U16 *len = (U16*)testBuf;    U8 *ver = testBuf+2;    U8 *msgType = testBuf+3;    U8 *flag = testBuf+4;    U32 *data = (U32*)(testBuf+5);    *len = 4;    *ver = 1;    *msgType = 2;    *flag = 3;        int dataLen(0);    bool reVal = true;    //for (int i = 0; i < 100; ++i)    //{        *data = 0xFFFFFFFF;    //}    return 0;}


gdb调试日志如下
Assembly code
Breakpoint 1, main (argc=1, argv=0xbec05db4) at test.cpp:55        U8 testBuf[100]= {0};1: /x *testBuf @ 30 = {0xd8, 0xd0, 0x2, 0x40, 0xb0, 0xda, 0xf9, 0xe, 0xd8,   0xee, 0x2, 0x40, 0xe8, 0xdd, 0x1, 0x40, 0x50, 0xe5, 0x1, 0x40, 0x6c, 0xbd,   0x1c, 0x40, 0xc0, 0xd7, 0x1, 0x40, 0x0, 0x50}7        U16 *len = (U16*)testBuf;1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}8        U8 *ver = testBuf+2;1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}9        U8 *msgType = testBuf+3;1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}10        U8 *flag = testBuf+4;1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}11        U32 *data = (U32*)(testBuf+5);1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}13        *len = 4;1: /x *testBuf @ 30 = {0x0 <repeats 30 times>}14        *ver = 1;1: /x *testBuf @ 30 = {0x4, 0x0 <repeats 29 times>}15        *msgType = 2;1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x0 <repeats 27 times>}16        *flag = 3;1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2, 0x0 <repeats 26 times>}18        int dataLen(0);1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2, 0x3, 0x0 <repeats 25 times>}19        bool reVal = true;1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2, 0x3, 0x0 <repeats 25 times>}22            *data = 0xFFFFFFFF;1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2, 0x3, 0x0 <repeats 25 times>}25        return 0;1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2,[color=#FF0000] 0xff, 0xff, 0xff, 0xff, [/color]  0x0 <repeats 22 times>}26    }1: /x *testBuf @ 30 = {0x4, 0x0, 0x1, 0x2, 0xff, 0xff, 0xff, 0xff,   0x0 <repeats 22 times>}0x401d5004 in __libc_start_main () from /lib/libc.so.6Single stepping until exit from function __libc_start_main, which has no line number information.Program exited normally.

问题是 为什么U32 *data = (U32*)(testBuf+5);的数值会把U8 *flag = testBuf+4;的数值3覆盖掉 此代码在x86下运行正常



[解决办法]
好像是因为地址4字节对齐的原因吧

(U32*)(testBuf+5); 相当于 (U32*)(testBuf+4);,就是说,对于U32来说,地址的低两位是无效的

好长时间没弄底层了,记不太清楚了

热点排行