Full Descending Stack

26 篇文章 1 订阅
20 篇文章 0 订阅

Demo:

#define LOG_TAG "QIANG_DEMO_TEST"
#define ATRACE_TAG ATRACE_TAG_ALWAYS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#ifdef __ANDROID__
#include <utils/Log.h>
#include <cutils/trace.h>
#endif

#ifdef __ANDROID__
#define LOGE(fmt, args...) ALOGE(fmt, ##args)
#else
#define LOGE(fmt, args...) printf(fmt, ##args)
#endif

/*===========================================================================
 * FUNCTION   : testBigLittleEndian
 *
 * DESCRIPTION: Function to test Big-Little Endian,
 *                      Litter endian: Low data address stores lower byte, high data address stores higher byte.
 *                      Big endian: Low data address stores higher byte, high data address stores lower byte.
 *                      https://blog.csdn.net/fervor_heart/article/details/8330177
 *
 * PARAMETERS :
 *   @       :
 *
 * RETURN     : Status
 *==========================================================================*/
int testBigLittleEndian() {
  int rc = 0;
  int x = 1;
  LOGE("%s %d \n", __func__, __LINE__);

  if (*(char*) &x ==1) {
    LOGE("Little-Endian. \n");
  } else {
    LOGE("Big-Endian. \n");
  }
  LOGE("%s %d \n", __func__, __LINE__);
  return rc;
}

/*===========================================================================
 * FUNCTION   : testPointerTrans
 *
 * DESCRIPTION: Function to test pointer type translate,
 *                      char* point to 1 byte memory, while int* point to 4 byte memory
 *                      https://blog.csdn.net/fervor_heart/article/details/8330177
 *
 * PARAMETERS :
 *   @       :
 *
 * RETURN     : Status
 *==========================================================================*/
int testPointerTrans() {
  int rc = 0;
  int x = 0x12345678;
  char* p;

  LOGE("%s %d \n", __func__, __LINE__);
  for (int i = 0; i < 4; i++) {
    p = (char*)&x + i;
    LOGE("MEM addr %p [%d] = 0x%x \n", p, i, *p);
  }
  LOGE("%s %d \n", __func__, __LINE__);
  return rc;
}

/*===========================================================================
 * FUNCTION   : testIntRange
 *
 * DESCRIPTION: Function to test int range, int 4 bytes, 32bits
 *                      By default, int was signed and range was -2147483648 ~ 2147483647
 *                      32th bit indicate +/-, 0 for + and 1 for -. See more about complement.
 *                      https://blog.csdn.net/fervor_heart/article/details/13628803
 *
 * PARAMETERS :
 *   @       :
 *
 * RETURN     : Status
 *==========================================================================*/
int testIntRange() {
  int rc = 0;
  int i = 0x7FFFFFFF; //2147483647
  int j = i + 1; //-2147483648
  int k = 0xFFFFFFFF; // -1

  LOGE("%s %d \n", __func__, __LINE__);

  LOGE("i = %d, j = %d, k = %d\n", i, j, k);

  LOGE("%s %d \n", __func__, __LINE__);
  return rc;
}

/*===========================================================================
 * FUNCTION   : testSignedPlusUnsignedInt
 *
 * DESCRIPTION: Function
 *
 * PARAMETERS :
 *   @       :
 *
 * RETURN     : Status
 *==========================================================================*/
int testSignedPlusUnsignedInt() {
  int rc = 0;
  signed int i = -2;
  unsigned int j = 1;

  LOGE("%s %d \n", __func__, __LINE__);

  LOGE("i = %d, j = %d, i + j = %u\n", i, j, i + j);

  LOGE("%s %d \n", __func__, __LINE__);
  return rc;
}

/*===========================================================================
* FUNCTION   : testFullDescendingStack
*
* DESCRIPTION: Function
*
* PARAMETERS :
*   @       :
*
* RETURN     : Status
*==========================================================================*/
int testFullDescendingStack() {
  int rc = 0;
  int i = 0;
  unsigned int k = 0xCCCCEEEE;
  unsigned int szTest_A[10] = {0};
  unsigned int x = 0xBBBBDDDD;
  unsigned int szTest_B[10] = {0};
  unsigned int m = 0xDDDDFFFF;

  //init the array A and array B
  for (i = 0; i < 10; i++) {
    szTest_A[i] = 0xAAAAAAA0 + i;
  }

  for (i = 0; i < 10; i++) {
    szTest_B[i] = 0xBBBBBBB0 + i;
  }

  //display the array A and array B
  for (i = 0; i < 10; i++) {
    LOGE("szTest_A[%d] MEM( %p ) = 0x%x \n", i, &szTest_A[i], szTest_A[i]);
  }

  LOGE("====================================== \n");
  LOGE("k MEM( %p ) = 0x%x, x MEM( %p ) = 0x%x, m MEM( %p ) = 0x%x \n",
    &k, k, &x, x, &m, m);
  LOGE("====================================== \n");

  for (i = 0; i < 10; i++) {
    LOGE("szTest_B[%d] MEM( %p ) = 0x%x \n", i, &szTest_B[i], szTest_B[i]);
  }

  LOGE("====================================== \n");
  for (i = -50; i < 50; i++) {
    LOGE("szTest_B[%d] MEM( %p ) = 0x%x \n", i, &szTest_B[i], szTest_B[i]);
  }
#ifdef __ANDROID__
  sleep(30);
  raise(SIGTRAP);
#endif
  return rc;
}

int main() {
  LOGE("%s %d \n", __func__, __LINE__);
  testBigLittleEndian();
  testPointerTrans();
  testIntRange();
  testSignedPlusUnsignedInt();
  testFullDescendingStack();
  LOGE("%s %d \n", __func__, __LINE__);
  return 0;
}

 

1. Android P ARM 手机上运行结果:

06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: main 177 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testBigLittleEndian 36 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: Little-Endian. 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testBigLittleEndian 43 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testPointerTrans 64 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: MEM addr 0xffd861b4 [0] = 0x78 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: MEM addr 0xffd861b5 [1] = 0x56 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: MEM addr 0xffd861b6 [2] = 0x34 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: MEM addr 0xffd861b7 [3] = 0x12 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testPointerTrans 69 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testIntRange 92 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: i = 2147483647, j = -2147483648, k = -1
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testIntRange 96 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testSignedPlusUnsignedInt 115 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: i = -2, j = 1, i + j = 4294967295
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: testSignedPlusUnsignedInt 119 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[0] MEM( 0xffd86158 ) = 0xaaaaaaa0 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[1] MEM( 0xffd8615c ) = 0xaaaaaaa1 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[2] MEM( 0xffd86160 ) = 0xaaaaaaa2 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[3] MEM( 0xffd86164 ) = 0xaaaaaaa3 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[4] MEM( 0xffd86168 ) = 0xaaaaaaa4 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[5] MEM( 0xffd8616c ) = 0xaaaaaaa5 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[6] MEM( 0xffd86170 ) = 0xaaaaaaa6 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[7] MEM( 0xffd86174 ) = 0xaaaaaaa7 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[8] MEM( 0xffd86178 ) = 0xaaaaaaa8 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_A[9] MEM( 0xffd8617c ) = 0xaaaaaaa9 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: ====================================== 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: k MEM( 0xffd8612c ) = 0xcccceeee, x MEM( 0xffd86128 ) = 0xbbbbdddd, m MEM( 0xffd86124 ) = 0xddddffff 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: ====================================== 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[0] MEM( 0xffd86130 ) = 0xbbbbbbb0 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[1] MEM( 0xffd86134 ) = 0xbbbbbbb1 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[2] MEM( 0xffd86138 ) = 0xbbbbbbb2 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[3] MEM( 0xffd8613c ) = 0xbbbbbbb3 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[4] MEM( 0xffd86140 ) = 0xbbbbbbb4 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[5] MEM( 0xffd86144 ) = 0xbbbbbbb5 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[6] MEM( 0xffd86148 ) = 0xbbbbbbb6 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[7] MEM( 0xffd8614c ) = 0xbbbbbbb7 
06-18 19:29:48.085 25785 25785 E QIANG_DEMO_TEST: szTest_B[8] MEM( 0xffd86150 ) = 0xbbbbbbb8 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[9] MEM( 0xffd86154 ) = 0xbbbbbbb9 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: ====================================== 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-50] MEM( 0xffd86068 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-49] MEM( 0xffd8606c ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-48] MEM( 0xffd86070 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-47] MEM( 0xffd86074 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-46] MEM( 0xffd86078 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-45] MEM( 0xffd8607c ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-44] MEM( 0xffd86080 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-43] MEM( 0xffd86084 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-42] MEM( 0xffd86088 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-41] MEM( 0xffd8608c ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-40] MEM( 0xffd86090 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-39] MEM( 0xffd86094 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-38] MEM( 0xffd86098 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-37] MEM( 0xffd8609c ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-36] MEM( 0xffd860a0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-35] MEM( 0xffd860a4 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-34] MEM( 0xffd860a8 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-33] MEM( 0xffd860ac ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-32] MEM( 0xffd860b0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-31] MEM( 0xffd860b4 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-30] MEM( 0xffd860b8 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-29] MEM( 0xffd860bc ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-28] MEM( 0xffd860c0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-27] MEM( 0xffd860c4 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-26] MEM( 0xffd860c8 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-25] MEM( 0xffd860cc ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-24] MEM( 0xffd860d0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-23] MEM( 0xffd860d4 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-22] MEM( 0xffd860d8 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-21] MEM( 0xffd860dc ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-20] MEM( 0xffd860e0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-19] MEM( 0xffd860e4 ) = 0xd3a48a4e 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-18] MEM( 0xffd860e8 ) = 0xffd860cc 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-17] MEM( 0xffd860ec ) = 0xb09ec1e5 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-16] MEM( 0xffd860f0 ) = 0xffffffce 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-15] MEM( 0xffd860f4 ) = 0xffd86130 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-14] MEM( 0xffd860f8 ) = 0xb09ebc05 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-13] MEM( 0xffd860fc ) = 0xfffffff2 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-12] MEM( 0xffd86100 ) = 0xffd860fc 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-11] MEM( 0xffd86104 ) = 0xffd860fc 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-10] MEM( 0xffd86108 ) = 0xbbbbdddd 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-9] MEM( 0xffd8610c ) = 0xffd86124 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-8] MEM( 0xffd86110 ) = 0xddddffff 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-7] MEM( 0xffd86114 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-6] MEM( 0xffd86118 ) = 0xddddffff 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-5] MEM( 0xffd8611c ) = 0xcccceeee 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-4] MEM( 0xffd86120 ) = 0xffd86140 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-3] MEM( 0xffd86124 ) = 0xddddffff 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-2] MEM( 0xffd86128 ) = 0xbbbbdddd 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[-1] MEM( 0xffd8612c ) = 0xcccceeee 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[0] MEM( 0xffd86130 ) = 0xbbbbbbb0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[1] MEM( 0xffd86134 ) = 0xbbbbbbb1 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[2] MEM( 0xffd86138 ) = 0xbbbbbbb2 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[3] MEM( 0xffd8613c ) = 0xbbbbbbb3 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[4] MEM( 0xffd86140 ) = 0xbbbbbbb4 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[5] MEM( 0xffd86144 ) = 0xbbbbbbb5 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[6] MEM( 0xffd86148 ) = 0xbbbbbbb6 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[7] MEM( 0xffd8614c ) = 0xbbbbbbb7 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[8] MEM( 0xffd86150 ) = 0xbbbbbbb8 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[9] MEM( 0xffd86154 ) = 0xbbbbbbb9 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[10] MEM( 0xffd86158 ) = 0xaaaaaaa0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[11] MEM( 0xffd8615c ) = 0xaaaaaaa1 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[12] MEM( 0xffd86160 ) = 0xaaaaaaa2 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[13] MEM( 0xffd86164 ) = 0xaaaaaaa3 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[14] MEM( 0xffd86168 ) = 0xaaaaaaa4 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[15] MEM( 0xffd8616c ) = 0xaaaaaaa5 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[16] MEM( 0xffd86170 ) = 0xaaaaaaa6 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[17] MEM( 0xffd86174 ) = 0xaaaaaaa7 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[18] MEM( 0xffd86178 ) = 0xaaaaaaa8 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[19] MEM( 0xffd8617c ) = 0xaaaaaaa9 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[20] MEM( 0xffd86180 ) = 0xd3a48a4e 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[21] MEM( 0xffd86184 ) = 0xb09ec09c 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[22] MEM( 0xffd86188 ) = 0xffffffff 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[23] MEM( 0xffd8618c ) = 0xb09ec129 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[24] MEM( 0xffd86190 ) = 0xffd861b7 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[25] MEM( 0xffd86194 ) = 0xb09ec205 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[26] MEM( 0xffd86198 ) = 0xb09ec0d9 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[27] MEM( 0xffd8619c ) = 0xb09edfd8 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[28] MEM( 0xffd861a0 ) = 0xb09ec0ac 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[29] MEM( 0xffd861a4 ) = 0xb09ebf29 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[30] MEM( 0xffd861a8 ) = 0x77 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[31] MEM( 0xffd861ac ) = 0xffffffff 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[32] MEM( 0xffd861b0 ) = 0x0 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[33] MEM( 0xffd861b4 ) = 0x12345678 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[34] MEM( 0xffd861b8 ) = 0xd3a48a4e 
06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[35] MEM( 0xffd861bc ) = 0xb09ebded 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[36] MEM( 0xffd861c0 ) = 0xffd86214 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[37] MEM( 0xffd861c4 ) = 0x1 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[38] MEM( 0xffd861c8 ) = 0xffd8621c 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[39] MEM( 0xffd861cc ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[40] MEM( 0xffd861d0 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[41] MEM( 0xffd861d4 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[42] MEM( 0xffd861d8 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[43] MEM( 0xffd861dc ) = 0xea0cf837 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[44] MEM( 0xffd861e0 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[45] MEM( 0xffd861e4 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[46] MEM( 0xffd861e8 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[47] MEM( 0xffd861ec ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[48] MEM( 0xffd861f0 ) = 0x0 
06-18 19:29:48.087 25785 25785 E QIANG_DEMO_TEST: szTest_B[49] MEM( 0xffd861f4 ) = 0xb09eb5d3 

--------- beginning of crash
06-18 19:30:18.090 25785 25785 F libc    : Fatal signal 5 (SIGTRAP), code -6 (SI_TKILL) in tid 25785 (demo_test), pid 25785 (demo_test)
06-18 19:30:18.142 25798 25798 F DEBUG   : Revision: '0'
06-18 19:30:18.142 25798 25798 F DEBUG   : ABI: 'arm'
06-18 19:30:18.142 25798 25798 F DEBUG   : pid: 25785, tid: 25785, name: demo_test  >>> /vendor/bin/hw/demo_test <<<
06-18 19:30:18.142 25798 25798 F DEBUG   : signal 5 (SIGTRAP), code -6 (SI_TKILL), fault addr --------
06-18 19:30:18.142 25798 25798 F DEBUG   :     r0  00000000  r1  000064b9  r2  00000005  r3  ffd8625c
06-18 19:30:18.143 25798 25798 F DEBUG   :     r4  ffd8625c  r5  b09ec1e5  r6  00000032  r7  0000010c
06-18 19:30:18.143 25798 25798 F DEBUG   :     r8  b09ec17f  r9  b09ec09c  r10 ffd86158  r11 ffd8617c
06-18 19:30:18.143 25798 25798 F DEBUG   :     ip  00000030  sp  ffd86100  lr  b09ebd6b  pc  ea08ff04
06-18 19:30:18.144 25798 25798 F DEBUG   : 
06-18 19:30:18.144 25798 25798 F DEBUG   : backtrace:
06-18 19:30:18.144 25798 25798 F DEBUG   :     #00 pc 00061f04  /system/lib/libc.so (tgkill+12)
06-18 19:30:18.144 25798 25798 F DEBUG   :     #01 pc 00000d67  /vendor/bin/hw/demo_test (testFullDescendingStack()+1910)
06-18 19:30:18.144 25798 25798 F DEBUG   :     #02 pc 00000f25  /vendor/bin/hw/demo_test (main+312)
06-18 19:30:18.144 25798 25798 F DEBUG   :     #03 pc 000a1835  /system/lib/libc.so (__libc_init+48)
06-18 19:30:18.145 25798 25798 F DEBUG   :     #04 pc 000005cf  /vendor/bin/hw/demo_test (_start_main+38)
06-18 19:30:18.145 25798 25798 F DEBUG   :     #05 pc 00000016  <unknown>
06-18 19:30:18.158  1371  2070 W NativeCrashListener: Couldn't find ProcessRecord for pid 25785

程序执行到 sleep(30); 的时候,查看 proc 信息:

可以看到 demo_test 可执行文件代码段位于 内存 b09eb000-b09ed000 和 b09ed000-b09ee000, 其中 demo_test 代码段的起始地址是 b09eb000。 这个地址很重要,通过 LR 的地址 减去这个起始地址可以得到在这个文件中的相对地址,也就是 addr2line 中用的地址。

b09eb000-b09ed000 r-xp 00000000 103:25 1292                              /vendor/bin/hw/demo_test
b09ed000-b09ee000 r--p 00001000 103:25 1292                              /vendor/bin/hw/demo_test

lr  b09ebd6b , 对应的 demo_test 中的相对地址是 b09ebd6b - b09eb000 = d6b

$ arm-linux-androideabi-addr2line -f -e ./symbols/vendor/bin/hw/demo_test -a d6b
0x00000d6b
_Z23testFullDescendingStackv
hardware/qcom/camera/demo/main.cpp:171
也就是   raise(SIGTRAP); 这一行。

再看下 main 调用 testFullDescendingStack 的时候,将 LR push 到 栈中的地址

06-18 19:29:48.086 25785 25785 E QIANG_DEMO_TEST: szTest_B[29] MEM( 0xffd861a4 ) = 0xb09ebf29

b09ebf29 - b09eb000 = f29

$ arm-linux-androideabi-addr2line -f -e ./symbols/vendor/bin/hw/demo_test -a f29
0x00000f29
main
hardware/qcom/camera/demo/main.cpp:183
也就是 main 函数调用完 testFullDescendingStack,返回后执行的下一条指令地址。

 

同时可以看到 栈空间的内存地址范围:

ffd66000-ffd87000 rw-p 00000000 00:00 0 [stack]

可以看到函数 中定义的局部变量都是在栈上:

szTest_A[0] MEM( 0xffd86158 ) = 0xaaaaaaa0 
szTest_A[1] MEM( 0xffd8615c ) = 0xaaaaaaa1 
szTest_A[2] MEM( 0xffd86160 ) = 0xaaaaaaa2 
szTest_A[3] MEM( 0xffd86164 ) = 0xaaaaaaa3 
szTest_A[4] MEM( 0xffd86168 ) = 0xaaaaaaa4 
szTest_A[5] MEM( 0xffd8616c ) = 0xaaaaaaa5 
szTest_A[6] MEM( 0xffd86170 ) = 0xaaaaaaa6 
szTest_A[7] MEM( 0xffd86174 ) = 0xaaaaaaa7 
szTest_A[8] MEM( 0xffd86178 ) = 0xaaaaaaa8 
szTest_A[9] MEM( 0xffd8617c ) = 0xaaaaaaa9 
====================================== 
k MEM( 0xffd8612c ) = 0xcccceeee, x MEM( 0xffd86128 ) = 0xbbbbdddd, m MEM( 0xffd86124 ) = 0xddddffff 
====================================== 
szTest_B[0] MEM( 0xffd86130 ) = 0xbbbbbbb0 
szTest_B[1] MEM( 0xffd86134 ) = 0xbbbbbbb1 
szTest_B[2] MEM( 0xffd86138 ) = 0xbbbbbbb2 
szTest_B[3] MEM( 0xffd8613c ) = 0xbbbbbbb3 
szTest_B[4] MEM( 0xffd86140 ) = 0xbbbbbbb4 
szTest_B[5] MEM( 0xffd86144 ) = 0xbbbbbbb5 
szTest_B[6] MEM( 0xffd86148 ) = 0xbbbbbbb6 
szTest_B[7] MEM( 0xffd8614c ) = 0xbbbbbbb7 
szTest_B[8] MEM( 0xffd86150 ) = 0xbbbbbbb8 
szTest_B[9] MEM( 0xffd86154 ) = 0xbbbbbbb9 

int k, x, m; 在栈上的顺序符合 满递减栈的特点,先定义的 k 在 栈的高地址内存,m 在最低地址内存。(满递减栈,向下生长)

a[0] 总是位于 低地址。(貌似是 数组 和 int 变量在栈上的按照类别排序了 ???但是总体符合向下生长的规律),LR 在函数一开始压栈,因此是 szTest_B[29]

VariableMEM Address 
szTest_A[9]0xffd8617c高地址
szTest_A[8]0xffd86178 
szTest_A[7]0xffd86174
szTest_A[6]0xffd86170
szTest_A[5]0xffd8616c
szTest_A[4]0xffd86168
szTest_A[3]0xffd86164
szTest_A[2]0xffd86160
szTest_A[1]0xffd8615c
szTest_A[0]0xffd86158
  
szTest_B[9]0xffd86154
szTest_B[8]0xffd86150
szTest_B[7]0xffd8614c
szTest_B[6]0xffd86148
szTest_B[5]0xffd86144
szTest_B[4]0xffd86140
szTest_B[3]0xffd8613c
szTest_B[2]0xffd86138
szTest_B[1]0xffd86134
szTest_B[0]0xffd86130
  
k0xffd8612c
x0xffd86128
m0xffd86124低地址
$ adb shell ps -A |grep -i demo
root         25785  7874    7664   2552 hrtimer_nanosleep ea08f6a4 S demo_test
$ adb shell cat /proc/25785/maps
b09eb000-b09ed000 r-xp 00000000 103:25 1292                              /vendor/bin/hw/demo_test
b09ed000-b09ee000 r--p 00001000 103:25 1292                              /vendor/bin/hw/demo_test
b09ee000-b09ef000 rw-p 00000000 00:00 0 
e9bc9000-e9bce000 r-xp 00000000 fc:00 5474                               /system/lib/libnetd_client.so
e9bce000-e9bcf000 r--p 00004000 fc:00 5474                               /system/lib/libnetd_client.so
e9bcf000-e9bd0000 rw-p 00005000 fc:00 5474                               /system/lib/libnetd_client.so
e9c00000-e9d00000 rw-p 00000000 00:00 0                                  [anon:libc_malloc]
e9d02000-e9d05000 r-xp 00000000 fc:00 5610                               /system/lib/libvndksupport.so
e9d05000-e9d06000 r--p 00002000 fc:00 5610                               /system/lib/libvndksupport.so
e9d06000-e9d07000 rw-p 00003000 fc:00 5610                               /system/lib/libvndksupport.so
e9d5a000-e9d71000 r-xp 00000000 fc:00 5433                               /system/lib/liblog.so
e9d71000-e9d72000 r--p 00016000 fc:00 5433                               /system/lib/liblog.so
e9d72000-e9d73000 rw-p 00017000 fc:00 5433                               /system/lib/liblog.so
e9d80000-e9db8000 r-xp 00000000 fc:00 5931                               /system/lib/vndk-sp-28/libunwindstack.so
e9db8000-e9db9000 ---p 00000000 00:00 0 
e9db9000-e9dbd000 r--p 00038000 fc:00 5931                               /system/lib/vndk-sp-28/libunwindstack.so
e9dbd000-e9dbe000 rw-p 0003c000 fc:00 5931                               /system/lib/vndk-sp-28/libunwindstack.so
e9dce000-e9e6b000 r-xp 00000000 fc:00 5344                               /system/lib/libc++.so
e9e6b000-e9e6c000 ---p 00000000 00:00 0 
e9e6c000-e9e71000 r--p 0009d000 fc:00 5344                               /system/lib/libc++.so
e9e71000-e9e72000 rw-p 000a2000 fc:00 5344                               /system/lib/libc++.so
e9e72000-e9e73000 rw-p 00000000 00:00 0                                  [anon:.bss]
e9e98000-e9ead000 r-xp 00000000 fc:00 5915                               /system/lib/vndk-sp-28/libbacktrace.so
e9ead000-e9eae000 r--p 00014000 fc:00 5915                               /system/lib/vndk-sp-28/libbacktrace.so
e9eae000-e9eaf000 rw-p 00015000 fc:00 5915                               /system/lib/vndk-sp-28/libbacktrace.so
e9ee7000-e9f27000 r-xp 00000000 fc:00 5925                               /system/lib/vndk-sp-28/libhidltransport.so
e9f27000-e9f28000 ---p 00000000 00:00 0 
e9f28000-e9f2c000 r--p 00040000 fc:00 5925                               /system/lib/vndk-sp-28/libhidltransport.so
e9f2c000-e9f2d000 rw-p 00044000 fc:00 5925                               /system/lib/vndk-sp-28/libhidltransport.so
e9f50000-e9f76000 r-xp 00000000 fc:00 5929                               /system/lib/vndk-sp-28/liblzma.so
e9f76000-e9f77000 ---p 00000000 00:00 0 
e9f77000-e9f78000 r--p 00026000 fc:00 5929                               /system/lib/vndk-sp-28/liblzma.so
e9f78000-e9f79000 rw-p 00027000 fc:00 5929                               /system/lib/vndk-sp-28/liblzma.so
e9f79000-e9f7f000 rw-p 00000000 00:00 0                                  [anon:.bss]
e9f85000-e9f99000 r-xp 00000000 fc:00 5932                               /system/lib/vndk-sp-28/libutils.so
e9f99000-e9f9a000 ---p 00000000 00:00 0 
e9f9a000-e9f9b000 r--p 00014000 fc:00 5932                               /system/lib/vndk-sp-28/libutils.so
e9f9b000-e9f9c000 rw-p 00015000 fc:00 5932                               /system/lib/vndk-sp-28/libutils.so
e9fd2000-e9ff4000 r-xp 00000000 fc:00 5437                               /system/lib/libm.so
e9ff4000-e9ff5000 r--p 00021000 fc:00 5437                               /system/lib/libm.so
e9ff5000-e9ff6000 rw-p 00022000 fc:00 5437                               /system/lib/libm.so
ea02e000-ea0e5000 r-xp 00000000 fc:00 5345                               /system/lib/libc.so
ea0e5000-ea0e6000 ---p 00000000 00:00 0 
ea0e6000-ea0ea000 r--p 000b7000 fc:00 5345                               /system/lib/libc.so
ea0ea000-ea0ec000 rw-p 000bb000 fc:00 5345                               /system/lib/libc.so
ea0ec000-ea0ed000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea0ed000-ea0ee000 r--p 00000000 00:00 0                                  [anon:.bss]
ea0ee000-ea0f5000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea120000-ea12d000 r-xp 00000000 fc:00 5916                               /system/lib/vndk-sp-28/libbase.so
ea12d000-ea12e000 r--p 0000c000 fc:00 5916                               /system/lib/vndk-sp-28/libbase.so
ea12e000-ea12f000 rw-p 0000d000 fc:00 5916                               /system/lib/vndk-sp-28/libbase.so
ea15c000-ea15d000 r-xp 00000000 fc:00 5369                               /system/lib/libdl.so
ea15d000-ea15e000 r--p 00001000 fc:00 5369                               /system/lib/libdl.so
ea15e000-ea15f000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea1a1000-ea1ac000 r-xp 00000000 fc:00 5923                               /system/lib/vndk-sp-28/libhidlbase.so
ea1ac000-ea1ad000 r--p 0000a000 fc:00 5923                               /system/lib/vndk-sp-28/libhidlbase.so
ea1ad000-ea1ae000 rw-p 0000b000 fc:00 5923                               /system/lib/vndk-sp-28/libhidlbase.so
ea1ca000-ea1d7000 r-xp 00000000 fc:00 5921                               /system/lib/vndk-sp-28/libcutils.so
ea1d7000-ea1d8000 ---p 00000000 00:00 0 
ea1d8000-ea1d9000 r--p 0000d000 fc:00 5921                               /system/lib/vndk-sp-28/libcutils.so
ea1d9000-ea1da000 rw-p 0000e000 fc:00 5921                               /system/lib/vndk-sp-28/libcutils.so
ea227000-ea22c000 r-xp 00000000 fc:00 5933                               /system/lib/vndk-sp-28/libutilscallstack.so
ea22c000-ea22d000 r--p 00004000 fc:00 5933                               /system/lib/vndk-sp-28/libutilscallstack.so
ea22d000-ea22e000 rw-p 00005000 fc:00 5933                               /system/lib/vndk-sp-28/libutilscallstack.so
ea253000-ea2f0000 r-xp 00000000 fc:00 5919                               /system/lib/vndk-sp-28/libc++.so
ea2f0000-ea2f1000 ---p 00000000 00:00 0 
ea2f1000-ea2f6000 r--p 0009d000 fc:00 5919                               /system/lib/vndk-sp-28/libc++.so
ea2f6000-ea2f7000 rw-p 000a2000 fc:00 5919                               /system/lib/vndk-sp-28/libc++.so
ea2f7000-ea2f8000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea309000-ea357000 r-xp 00000000 fc:00 5812                               /system/lib/vndk-28/libbinder.so
ea357000-ea35c000 r--p 0004d000 fc:00 5812                               /system/lib/vndk-28/libbinder.so
ea35c000-ea35d000 rw-p 00052000 fc:00 5812                               /system/lib/vndk-28/libbinder.so
ea385000-ea3a2000 r-xp 00000000 fc:00 5926                               /system/lib/vndk-sp-28/libhwbinder.so
ea3a2000-ea3a3000 r--p 0001d000 fc:00 5926                               /system/lib/vndk-sp-28/libhwbinder.so
ea3a3000-ea3a4000 rw-p 0001e000 fc:00 5926                               /system/lib/vndk-sp-28/libhwbinder.so
ea3a4000-ea3a5000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea3db000-ea3f2000 r-xp 00000000 fc:00 5930                               /system/lib/vndk-sp-28/libunwind.so
ea3f2000-ea3f3000 r--p 00016000 fc:00 5930                               /system/lib/vndk-sp-28/libunwind.so
ea3f3000-ea3f4000 rw-p 00017000 fc:00 5930                               /system/lib/vndk-sp-28/libunwind.so
ea3f4000-ea43a000 rw-p 00000000 00:00 0                                  [anon:.bss]
ea477000-ea478000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea478000-ea479000 rw-p 00000000 00:00 0                                  [anon:linker_alloc]
ea49e000-ea49f000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea4a0000-ea4a1000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea4bf000-ea4c0000 rw-p 00000000 00:00 0                                  [anon:linker_alloc]
ea4db000-ea4fb000 r--s 00000000 00:10 11798                              /dev/__properties__/u:object_r:log_tag_prop:s0
ea4fb000-ea4fc000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea4fc000-ea51c000 r--s 00000000 00:10 11799                              /dev/__properties__/u:object_r:logd_prop:s0
ea51c000-ea53c000 r--s 00000000 00:10 11757                              /dev/__properties__/u:object_r:exported2_default_prop:s0
ea53c000-ea55c000 r--s 00000000 00:10 11917                              /dev/__properties__/properties_serial
ea55c000-ea569000 r--s 00000000 00:10 11694                              /dev/__properties__/property_info
ea569000-ea56a000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea56a000-ea56b000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea56b000-ea56c000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea56c000-ea56d000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea56d000-ea56e000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_lob]
ea56e000-ea570000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea571000-ea572000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea572000-ea573000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea574000-ea575000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea576000-ea577000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea578000-ea579000 r--p 00000000 00:00 0                                  [anon:atexit handlers]
ea579000-ea57b000 rw-p 00000000 00:00 0                                  [anon:System property context nodes]
ea57b000-ea57d000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_lob]
ea57d000-ea57e000 rw-p 00000000 00:00 0                                  [anon:arc4random data]
ea57e000-ea580000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea580000-ea581000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea581000-ea582000 rw-p 00000000 00:00 0                                  [anon:linker_alloc]
ea582000-ea584000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea584000-ea585000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea585000-ea5a5000 r--s 00000000 00:10 11767                              /dev/__properties__/u:object_r:exported_default_prop:s0
ea5a5000-ea5a6000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea5a6000-ea5c6000 r--s 00000000 00:10 11744                              /dev/__properties__/u:object_r:debug_prop:s0
ea5c6000-ea5c7000 ---p 00000000 00:00 0 
ea5c7000-ea5c8000 rw-p 00000000 00:00 0 
ea5c8000-ea5c9000 ---p 00000000 00:00 0 
ea5c9000-ea5e9000 r--s 00000000 00:10 11917                              /dev/__properties__/properties_serial
ea5e9000-ea5eb000 rw-p 00000000 00:00 0                                  [anon:System property context nodes]
ea5eb000-ea5f8000 r--s 00000000 00:10 11694                              /dev/__properties__/property_info
ea5f8000-ea5f9000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea5f9000-ea5fa000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_vector]
ea5fa000-ea5fb000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea5fb000-ea5fc000 r--p 00000000 00:00 0                                  [anon:linker_alloc]
ea5fc000-ea5fd000 rw-p 00000000 00:00 0                                  [anon:linker_alloc_small_objects]
ea5fd000-ea5fe000 r--p 00000000 00:00 0                                  [anon:atexit handlers]
ea5fe000-ea5ff000 ---p 00000000 00:00 0                                  [anon:thread signal stack guard]
ea5ff000-ea603000 rw-p 00000000 00:00 0                                  [anon:thread signal stack]
ea603000-ea604000 ---p 00000000 00:00 0                                  [anon:bionic TLS guard]
ea604000-ea607000 rw-p 00000000 00:00 0                                  [anon:bionic TLS]
ea607000-ea608000 ---p 00000000 00:00 0                                  [anon:bionic TLS guard]
ea608000-ea6db000 r-xp 00000000 fc:00 458                                /system/bin/linker
ea6db000-ea6dc000 rw-p 00000000 00:00 0                                  [anon:arc4random data]
ea6dc000-ea6e2000 r--p 000d3000 fc:00 458                                /system/bin/linker
ea6e2000-ea6e3000 rw-p 000d9000 fc:00 458                                /system/bin/linker
ea6e3000-ea6e5000 rw-p 00000000 00:00 0 
ea6e5000-ea6e6000 r--p 00000000 00:00 0 
ea6e6000-ea6ec000 rw-p 00000000 00:00 0 
ffd66000-ffd87000 rw-p 00000000 00:00 0                                  [stack]
ffff0000-ffff1000 r-xp 00000000 00:00 0                                  [vectors]

如果对上面的程序简单修改一下,让数组 A使用的时候越界,将会导致 LR 在栈中的内容被覆盖,发生 crash

diff --git a/demo/main.cpp b/demo/main.cpp
index f4d91d9ce..2a43f2b15 100755
--- a/demo/main.cpp
+++ b/demo/main.cpp
@@ -140,7 +140,7 @@ int testFullDescendingStack() {
   unsigned int m = 0xDDDDFFFF;
 
   //init the array A and array B
-  for (i = 0; i < 10; i++) {
+  for (i = 0; i < 20; i++) {
     szTest_A[i] = 0xAAAAAAA0 + i;
   }
 
@@ -168,7 +168,7 @@ int testFullDescendingStack() {
   }
 #ifdef __ANDROID__
   sleep(30);
-  raise(SIGTRAP);
+  //raise(SIGTRAP);
 #endif
   return rc;
 }

06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[0] MEM( 0xffeef328 ) = 0xaaaaaaa0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[1] MEM( 0xffeef32c ) = 0xaaaaaaa1 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[2] MEM( 0xffeef330 ) = 0xaaaaaaa2 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[3] MEM( 0xffeef334 ) = 0xaaaaaaa3 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[4] MEM( 0xffeef338 ) = 0xaaaaaaa4 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[5] MEM( 0xffeef33c ) = 0xaaaaaaa5 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[6] MEM( 0xffeef340 ) = 0xaaaaaaa6 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[7] MEM( 0xffeef344 ) = 0xaaaaaaa7 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[8] MEM( 0xffeef348 ) = 0xaaaaaaa8 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_A[9] MEM( 0xffeef34c ) = 0xaaaaaaa9 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: ====================================== 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: k MEM( 0xffeef2fc ) = 0xcccceeee, x MEM( 0xffeef2f8 ) = 0xbbbbdddd, m MEM( 0xffeef2f4 ) = 0xddddffff 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: ====================================== 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[0] MEM( 0xffeef300 ) = 0xbbbbbbb0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[1] MEM( 0xffeef304 ) = 0xbbbbbbb1 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[2] MEM( 0xffeef308 ) = 0xbbbbbbb2 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[3] MEM( 0xffeef30c ) = 0xbbbbbbb3 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[4] MEM( 0xffeef310 ) = 0xbbbbbbb4 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[5] MEM( 0xffeef314 ) = 0xbbbbbbb5 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[6] MEM( 0xffeef318 ) = 0xbbbbbbb6 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[7] MEM( 0xffeef31c ) = 0xbbbbbbb7 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[8] MEM( 0xffeef320 ) = 0xbbbbbbb8 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[9] MEM( 0xffeef324 ) = 0xbbbbbbb9 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: ====================================== 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-50] MEM( 0xffeef238 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-49] MEM( 0xffeef23c ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-48] MEM( 0xffeef240 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-47] MEM( 0xffeef244 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-46] MEM( 0xffeef248 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-45] MEM( 0xffeef24c ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-44] MEM( 0xffeef250 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-43] MEM( 0xffeef254 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-42] MEM( 0xffeef258 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-41] MEM( 0xffeef25c ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-40] MEM( 0xffeef260 ) = 0x0 
06-18 21:28:06.475 26820 26820 E QIANG_DEMO_TEST: szTest_B[-39] MEM( 0xffeef264 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-38] MEM( 0xffeef268 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-37] MEM( 0xffeef26c ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-36] MEM( 0xffeef270 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-35] MEM( 0xffeef274 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-34] MEM( 0xffeef278 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-33] MEM( 0xffeef27c ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-32] MEM( 0xffeef280 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-31] MEM( 0xffeef284 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-30] MEM( 0xffeef288 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-29] MEM( 0xffeef28c ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-28] MEM( 0xffeef290 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-27] MEM( 0xffeef294 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-26] MEM( 0xffeef298 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-25] MEM( 0xffeef29c ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-24] MEM( 0xffeef2a0 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-23] MEM( 0xffeef2a4 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-22] MEM( 0xffeef2a8 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-21] MEM( 0xffeef2ac ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-20] MEM( 0xffeef2b0 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-19] MEM( 0xffeef2b4 ) = 0xe80c074f 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-18] MEM( 0xffeef2b8 ) = 0xffeef29c 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-17] MEM( 0xffeef2bc ) = 0xb08cd1e5 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-16] MEM( 0xffeef2c0 ) = 0xffffffce 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-15] MEM( 0xffeef2c4 ) = 0xffeef300 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-14] MEM( 0xffeef2c8 ) = 0xb08ccbf5 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-13] MEM( 0xffeef2cc ) = 0xfffffff2 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-12] MEM( 0xffeef2d0 ) = 0xffeef2cc 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-11] MEM( 0xffeef2d4 ) = 0xffeef2cc 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-10] MEM( 0xffeef2d8 ) = 0xbbbbdddd 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-9] MEM( 0xffeef2dc ) = 0xffeef2f4 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-8] MEM( 0xffeef2e0 ) = 0xddddffff 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-7] MEM( 0xffeef2e4 ) = 0xddddffff 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-6] MEM( 0xffeef2e8 ) = 0xcccceeee 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-5] MEM( 0xffeef2ec ) = 0xffeef310 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-4] MEM( 0xffeef2f0 ) = 0xffeef324 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-3] MEM( 0xffeef2f4 ) = 0xddddffff 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-2] MEM( 0xffeef2f8 ) = 0xbbbbdddd 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[-1] MEM( 0xffeef2fc ) = 0xcccceeee 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[0] MEM( 0xffeef300 ) = 0xbbbbbbb0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[1] MEM( 0xffeef304 ) = 0xbbbbbbb1 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[2] MEM( 0xffeef308 ) = 0xbbbbbbb2 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[3] MEM( 0xffeef30c ) = 0xbbbbbbb3 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[4] MEM( 0xffeef310 ) = 0xbbbbbbb4 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[5] MEM( 0xffeef314 ) = 0xbbbbbbb5 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[6] MEM( 0xffeef318 ) = 0xbbbbbbb6 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[7] MEM( 0xffeef31c ) = 0xbbbbbbb7 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[8] MEM( 0xffeef320 ) = 0xbbbbbbb8 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[9] MEM( 0xffeef324 ) = 0xbbbbbbb9 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[10] MEM( 0xffeef328 ) = 0xaaaaaaa0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[11] MEM( 0xffeef32c ) = 0xaaaaaaa1 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[12] MEM( 0xffeef330 ) = 0xaaaaaaa2 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[13] MEM( 0xffeef334 ) = 0xaaaaaaa3 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[14] MEM( 0xffeef338 ) = 0xaaaaaaa4 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[15] MEM( 0xffeef33c ) = 0xaaaaaaa5 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[16] MEM( 0xffeef340 ) = 0xaaaaaaa6 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[17] MEM( 0xffeef344 ) = 0xaaaaaaa7 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[18] MEM( 0xffeef348 ) = 0xaaaaaaa8 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[19] MEM( 0xffeef34c ) = 0xaaaaaaa9 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[20] MEM( 0xffeef350 ) = 0xaaaaaaaa 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[21] MEM( 0xffeef354 ) = 0xaaaaaaab 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[22] MEM( 0xffeef358 ) = 0xaaaaaaac 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[23] MEM( 0xffeef35c ) = 0xaaaaaaad 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[24] MEM( 0xffeef360 ) = 0xaaaaaaae 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[25] MEM( 0xffeef364 ) = 0xaaaaaaaf 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[26] MEM( 0xffeef368 ) = 0xaaaaaab0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[27] MEM( 0xffeef36c ) = 0xaaaaaab1 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[28] MEM( 0xffeef370 ) = 0xaaaaaab2 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[29] MEM( 0xffeef374 ) = 0xaaaaaab3 

06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[30] MEM( 0xffeef378 ) = 0x77 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[31] MEM( 0xffeef37c ) = 0xffffffff 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[32] MEM( 0xffeef380 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[33] MEM( 0xffeef384 ) = 0x12345678 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[34] MEM( 0xffeef388 ) = 0xe80c074f 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[35] MEM( 0xffeef38c ) = 0xb08ccdfd 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[36] MEM( 0xffeef390 ) = 0xffeef3e4 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[37] MEM( 0xffeef394 ) = 0x1 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[38] MEM( 0xffeef398 ) = 0xffeef3ec 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[39] MEM( 0xffeef39c ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[40] MEM( 0xffeef3a0 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[41] MEM( 0xffeef3a4 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[42] MEM( 0xffeef3a8 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[43] MEM( 0xffeef3ac ) = 0xe92e1837 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[44] MEM( 0xffeef3b0 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[45] MEM( 0xffeef3b4 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[46] MEM( 0xffeef3b8 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[47] MEM( 0xffeef3bc ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[48] MEM( 0xffeef3c0 ) = 0x0 
06-18 21:28:06.476 26820 26820 E QIANG_DEMO_TEST: szTest_B[49] MEM( 0xffeef3c4 ) = 0xb08cc5a3 
 

--------- beginning of crash
06-18 21:28:36.480 26820 26820 F libc    : stack corruption detected (-fstack-protector)
06-18 21:28:36.481 26820 26820 F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 26820 (demo_test), pid 26820 (demo_test)
06-18 21:28:36.479 26820 26820 I demo_test: type=1400 audit(0.0:343): avc: denied { sys_resource } for capability=24 scontext=u:r:shell:s0 tcontext=u:r:shell:s0 tclass=capability permissive=1 ppid=7874 pcomm="adbd" pgid=26820 pgcomm="demo_test"
06-18 21:28:36.527 26827 26827 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
06-18 21:28:36.528  1036  1036 I /system/bin/tombstoned: received crash request for pid 26820
06-18 21:28:36.529 26827 26827 I crash_dump32: performing dump of process 26820 (target tid = 26820)
06-18 21:28:36.532 26827 26827 F DEBUG   : Revision: '0'
06-18 21:28:36.532 26827 26827 F DEBUG   : ABI: 'arm'
06-18 21:28:36.532 26827 26827 F DEBUG   : pid: 26820, tid: 26820, name: demo_test  >>> /vendor/bin/hw/demo_test <<<
06-18 21:28:36.532 26827 26827 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
06-18 21:28:36.532 26827 26827 F DEBUG   : Abort message: 'stack corruption detected (-fstack-protector)'
06-18 21:28:36.532 26827 26827 F DEBUG   :     r0  00000000  r1  000068c4  r2  00000006  r3  00000008
06-18 21:28:36.532 26827 26827 F DEBUG   :     r4  000068c4  r5  000068c4  r6  ffeef2ac  r7  0000010c
06-18 21:28:36.532 26827 26827 F DEBUG   :     r8  ffeef328  r9  b08cd09c  r10 ffeef348  r11 ffeef34c
06-18 21:28:36.532 26827 26827 F DEBUG   :     ip  e92fb3cc  sp  ffeef298  lr  e926605d  pc  e925cfde
06-18 21:28:36.534 26827 26827 F DEBUG   : 
06-18 21:28:36.534 26827 26827 F DEBUG   : backtrace:
06-18 21:28:36.534 26827 26827 F DEBUG   :     #00 pc 0001cfde  /system/lib/libc.so (abort+58)
06-18 21:28:36.534 26827 26827 F DEBUG   :     #01 pc 000605e7  /system/lib/libc.so (__stack_chk_fail+10)
06-18 21:28:36.534 26827 26827 F DEBUG   :     #02 pc 00000d6b  /vendor/bin/hw/demo_test (testFullDescendingStack()+1962)
06-18 21:28:36.534 26827 26827 F DEBUG   :     #03 pc aaaaaab3  <unknown>

 

2. ARM DS-5 Cortex A9 FVP 运行结果:

严格遵守 Full Descending Stack 规律,k 在最高地址,m 在最低地址。

 

3. x86 编译,运行,使用 gdb 调试该程序:

$ gdb ./main

// 设断点
(gdb) break main.cpp:158
Breakpoint 1 at 0x80487c9: file main.cpp, line 158.
(gdb) run ./main
Starting program: ./main
main 162 
testBigLittleEndian 36 
Little-Endian. 
testBigLittleEndian 43 
testPointerTrans 64 
MEM addr 0xffffc6a8 [0] = 0x78 
MEM addr 0xffffc6a9 [1] = 0x56 
MEM addr 0xffffc6aa [2] = 0x34 
MEM addr 0xffffc6ab [3] = 0x12 
testPointerTrans 69 
testIntRange 92 
i = 2147483647, j = -2147483648, k = -1
testIntRange 96 
testSignedPlusUnsignedInt 115 
i = -2, j = 1, i + j = 4294967295
testSignedPlusUnsignedInt 119 
szTest_A[0] is 0xaaaaaaa0, its memory address is 0xffffc65c 
szTest_A[1] is 0xaaaaaaa1, its memory address is 0xffffc660 
szTest_A[2] is 0xaaaaaaa2, its memory address is 0xffffc664 
szTest_A[3] is 0xaaaaaaa3, its memory address is 0xffffc668 
szTest_A[4] is 0xaaaaaaa4, its memory address is 0xffffc66c 
szTest_A[5] is 0xaaaaaaa5, its memory address is 0xffffc670 
szTest_A[6] is 0xaaaaaaa6, its memory address is 0xffffc674 
szTest_A[7] is 0xaaaaaaa7, its memory address is 0xffffc678 
szTest_A[8] is 0xaaaaaaa8, its memory address is 0xffffc67c 
szTest_A[9] is 0xaaaaaaa9, its memory address is 0xffffc680 
====================================== 
k = 0xcccceeee, x = 0xbbbbdddd, m = 0xddddffff 
szTest_B[0] is 0xbbbbbbb0, its memory address is 0xffffc684  
szTest_B[1] is 0xbbbbbbb1, its memory address is 0xffffc688  
szTest_B[2] is 0xbbbbbbb2, its memory address is 0xffffc68c  
szTest_B[3] is 0xbbbbbbb3, its memory address is 0xffffc690  
szTest_B[4] is 0xbbbbbbb4, its memory address is 0xffffc694  
szTest_B[5] is 0xbbbbbbb5, its memory address is 0xffffc698  
szTest_B[6] is 0xbbbbbbb6, its memory address is 0xffffc69c  
szTest_B[7] is 0xbbbbbbb7, its memory address is 0xffffc6a0  
szTest_B[8] is 0xbbbbbbb8, its memory address is 0xffffc6a4  
szTest_B[9] is 0xbbbbbbb9, its memory address is 0xffffc6a8  

Breakpoint 1, testFullDescendingStack () at main.cpp:159
159	}

// Callstack
(gdb) bt full
#0  testFullDescendingStack () at main.cpp:159
        i = 10
        szTest_A = {2863311520, 2863311521, 2863311522, 2863311523, 2863311524, 2863311525, 2863311526, 2863311527, 2863311528, 2863311529}
        szTest_B = {3149642672, 3149642673, 3149642674, 3149642675, 3149642676, 3149642677, 3149642678, 3149642679, 3149642680, 3149642681}
#1  0x08048403 in main () at main.cpp:167
        __func__ = "main"

// 查看内存		
(gdb) x /x 0xffffc65c
0xffffc65c:	0xaaaaaaa0

(gdb) x /x 0xffffc684
0xffffc684:	0xbbbbbbb0



(gdb) i proc mappings 
process 135308
Mapped address spaces:

	Start Addr   End Addr       Size     Offset objfile
	 0x8048000  0x8049000     0x1000        0x0 main
	 0x8049000  0x804a000     0x1000        0x0 main
	 0x804a000  0x804b000     0x1000     0x1000 main
	 0x804b000  0x806c000    0x21000        0x0 [heap]
	0xf7df7000 0xf7df8000     0x1000        0x0 
	0xf7df8000 0xf7fa8000   0x1b0000        0x0 /lib/i386-linux-gnu/libc-2.23.so
	0xf7fa8000 0xf7faa000     0x2000   0x1af000 /lib/i386-linux-gnu/libc-2.23.so
	0xf7faa000 0xf7fab000     0x1000   0x1b1000 /lib/i386-linux-gnu/libc-2.23.so
	0xf7fab000 0xf7fae000     0x3000        0x0 
	0xf7fd4000 0xf7fd5000     0x1000        0x0 
	0xf7fd5000 0xf7fd8000     0x3000        0x0 [vvar]
	0xf7fd8000 0xf7fd9000     0x1000        0x0 [vdso]
	0xf7fd9000 0xf7ffc000    0x23000        0x0 /lib/i386-linux-gnu/ld-2.23.so
	0xf7ffc000 0xf7ffd000     0x1000    0x22000 /lib/i386-linux-gnu/ld-2.23.so
	0xf7ffd000 0xf7ffe000     0x1000    0x23000 /lib/i386-linux-gnu/ld-2.23.so
	0xfffdc000 0xffffe000    0x22000        0x0 [stack]

(gdb) display /i $pc
1: x/i $pc
=> 0x8048403 <main()+67>:	push   $0xa8
(gdb) disassemble /r main
Dump of assembler code for function main():
   0x080483c0 <+0>:	8d 4c 24 04	lea    0x4(%esp),%ecx
   0x080483c4 <+4>:	83 e4 f0	and    $0xfffffff0,%esp
   0x080483c7 <+7>:	ff 71 fc	pushl  -0x4(%ecx)
   0x080483ca <+10>:	55	push   %ebp
   0x080483cb <+11>:	89 e5	mov    %esp,%ebp
   0x080483cd <+13>:	51	push   %ecx
   0x080483ce <+14>:	83 ec 04	sub    $0x4,%esp
   0x080483d1 <+17>:	68 a2 00 00 00	push   $0xa2
   0x080483d6 <+22>:	68 88 89 04 08	push   $0x8048988
   0x080483db <+27>:	68 70 88 04 08	push   $0x8048870
   0x080483e0 <+32>:	6a 01	push   $0x1
   0x080483e2 <+34>:	e8 b9 ff ff ff	call   0x80483a0 <__printf_chk@plt>
   0x080483e7 <+39>:	83 c4 10	add    $0x10,%esp
   0x080483ea <+42>:	e8 31 01 00 00	call   0x8048520 <testBigLittleEndian()>
   0x080483ef <+47>:	e8 6c 01 00 00	call   0x8048560 <testPointerTrans()>
   0x080483f4 <+52>:	e8 f7 01 00 00	call   0x80485f0 <testIntRange()>
   0x080483f9 <+57>:	e8 42 02 00 00	call   0x8048640 <testSignedPlusUnsignedInt()>
   0x080483fe <+62>:	e8 8d 02 00 00	call   0x8048690 <testFullDescendingStack()>
=> 0x08048403 <+67>:	68 a8 00 00 00	push   $0xa8
   0x08048408 <+72>:	68 88 89 04 08	push   $0x8048988
   0x0804840d <+77>:	68 70 88 04 08	push   $0x8048870
   0x08048412 <+82>:	6a 01	push   $0x1
   0x08048414 <+84>:	e8 87 ff ff ff	call   0x80483a0 <__printf_chk@plt>
   0x08048419 <+89>:	8b 4d fc	mov    -0x4(%ebp),%ecx
   0x0804841c <+92>:	83 c4 10	add    $0x10,%esp
   0x0804841f <+95>:	31 c0	xor    %eax,%eax
   0x08048421 <+97>:	c9	leave  
   0x08048422 <+98>:	8d 61 fc	lea    -0x4(%ecx),%esp
   0x08048425 <+101>:	c3	ret    
End of assembler dump.

https://wizardforcel.gitbooks.io/100-gdb-tips/tui-mode.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值