在 IAR Workbench 中调试时如何 "live watch" 联合中的变量

How can I "live watch" a variable in a union when debugging in IAR Workbench

我是编程新手,但在 IAR 调试方面需要一些帮助。

我创建了一个带浮点数的并集,一个包含 4 个 uint8 和 4 个 uint8 变量的数组并且工作正常,我可以设置浮点数并且在打印到 IO 终端时其他值是正确的。

我想在调试时监控live watch window中的变量,但它显示"Error, cannot take address of Test"(测试是联合的名称)。

除了查看内存位置之外,还有其他办法吗? 如果所有变量都是 32 位,它会工作吗,我会在几个小时后到达办公室时测试它?

union Eeprom
{
struct
{
uint8_t Byte1;
uint8_t Byte2;
uint8_t Byte3;
uint8_t Byte4;
};
float floatvalue;
uint8_t Array[4];
};

int main(void)
{
  union Eeprom Test;

  Test.floatvalue = 23.1;

printf("floatvalue %3.2f \n Byte1 %x\n Byte2 %x\n Byte3 %x\n Byte4 %x\n 
   Array[0] %x\n Array[1] %x\n Array[2] %x\n Array[3] %x\n",      Test.floatvalue, 
   Test.Byte1, Test.Byte2, Test.Byte3, Test.Byte4, 
   Test.Array[0], Test.Array[1], Test.Array[2], Test.Array[3]);

实时观看 window 如下所示:

输出如下所示:

任何帮助将不胜感激

我的 IAR 手册是这样说的:

LIVE WATCH WINDOW

The Live Watch window—available from the View menu—repeatedly samples and displays the value of expressions while your application is executing. Variables in the expressions must be statically located, such as global variables.

变量union Eeprom Test;是在main函数内部声明的,所以它有自动存储期限。它们被放置在堆栈上并且没有预定义的地址,这使得调试器更难保留。因此它们不能与 Live Watch 一起使用。

Test 移到 main 之外,或者用 static 声明它。

所以,现在的代码是:

union Eeprom
{
struct
{
uint8_t Byte1;
uint8_t Byte2;
uint8_t Byte3;
uint8_t Byte4;
};
float floatvalue;
uint8_t Array[4];
};

union Eeprom Test;

int main(void)
{

  Test.floatvalue = 23.1;

printf("floatvalue %3.2f \n Byte1 %x\n Byte2 %x\n Byte3 %x\n Byte4 %x\n 
   Array[0] %x\n Array[1] %x\n Array[2] %x\n Array[3] %x\n",      Test.floatvalue, 
   Test.Byte1, Test.Byte2, Test.Byte3, Test.Byte4, 
   Test.Array[0], Test.Array[1], Test.Array[2], Test.Array[3]);

实时观看 windows 看起来像这样: