push_back()使程序在进入main()之前停止, [英] push_back() causes program to stop before entering main()
问题描述
我在c ++中为我的STM32F3发现板开发,并使用std :: deque作为队列。在尝试调试我的代码(直接在设备与ST链接或在模拟器)后,代码最终停止在断点,甚至在main()中输入我的代码。但是,SystemInit()配置板很好..
I'm developing in c++ for my STM32F3 Discovery board and using std::deque as queue. After trying to debug my code (directly on device with ST-link or in simulator), the code eventually stops at breakpoint before even entering my code in main(). However, SystemInit() configures board just fine..
我已经跟踪这个行为,使用push_back()(和push_front)注释从代码解决问题。通过disassmebly我发现,使用它后,执行停止在断点指令BKPT,并将不会继续移动,继续执行后。此指令是_sysopen()调用的一部分,具有调用路径:
I've traced this behavior down to using push_back() (and push_front) as commenting it out from code solves the issue. Through disassmebly I found that after using it, the execution stops at breakpoint instruction BKPT and won't move further after resuming execution. This instruction is part of _sysopen() call, with call path:
__main -> __scatterload -> __scatterload_null -> __rt_entry -> __rt_lib_init -> __rt_lib_init_atexit_1 -> _initio -> freopen -> _sysopen
有什么让我感动的是 _initio
,如果不使用push_back,则缺失,因为没有 __ rt_lib_init_atexit_1
。介绍push_back还使代码大小从10 kB到34 kB。
What intrigues me is call to _initio
, which is missing if push_back isn't used, because there is no __rt_lib_init_atexit_1
. Introducing push_back also makes the code size go from 10 kB to 34 kB.
这可能是一些配置错误的结果,还是我应该尝试另一个IDE?我没有想法。
Might this be a result of some bad configuration or should I try another IDE? I'm out of ideas.
推荐答案
我有同样的问题。我知道它与所谓的半主机和
有关,我应该用我的项目文件'retarget.c',其中包含的
函数的定义像'_sys_xxxx()'是目标特定驱动程序级别函数
(许多版本的'retarget.c'是Keil-MDK的一部分,也在web上找到)。
所以我没有链接器抛出的错误类似于这样:
I had the same problem. I learnt it has something to do with so called 'semihosting' and that I should build with my project file 'retarget.c' that contains definitions of the functions like '_sys_xxxx()' that are target specific driver level functions (many versions of 'retarget.c' are part of the Keil-MDK and also found on web). So I did but than linker thrown errors similar to this:
Error: L6200E: Symbol _sys_open multiply defined (by arm_xxx_lib.o and retarget.o)
Error: L6200E: Symbol _sys_close multiply defined (by arm_xxx_lib.o and retarget.o)
...
我通过编辑原始的retarget.c来解决这个问题,因此定义的函数
会覆盖Keil-MDK库中的函数。所以我的新retarged.c在这里:
I solved this by editing original 'retarget.c' so that functions defined in it will override the ones in Keil-MDK libraries. So my new 'retarged.c' is here:
#include <stdio.h>
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
#include <rt_sys.h>
extern void $Super$$_sys_open(void);
FILEHANDLE $Sub$$_sys_open(const char *name, int openmode)
{
return 1; /* everything goes to the same output */
}
extern void $Super$$_sys_close(void);
int $Sub$$_sys_close(FILEHANDLE fh)
{
return 0;
}
extern void $Super$$_sys_write(void);
int $Sub$$_sys_write(FILEHANDLE fh, const unsigned char *buf,
unsigned len, int mode)
{
//your_device_write(buf, len);
return 0;
}
extern void $Super$$_sys_read(void);
int $Sub$$_sys_read(FILEHANDLE fh, unsigned char *buf,
unsigned len, int mode)
{
return -1; /* not supported */
}
extern void $Super$$_ttywrch(void);
void $Sub$$_ttywrch(int ch)
{
char c = ch;
//your_device_write(&c, 1);
}
extern void $Super$$_sys_istty(void);
int $Sub$$_sys_istty(FILEHANDLE fh)
{
return 0; /* buffered output */
}
extern void $Super$$_sys_seek(void);
int $Sub$$_sys_seek(FILEHANDLE fh, long pos)
{
return -1; /* not supported */
}
extern void $Super$$_sys_flen(void);
long $Sub$$_sys_flen(FILEHANDLE fh)
{
return -1; /* not supported */
}
extern void $Super$$_sys_exit(void);
long $Sub$$_sys_exit(FILEHANDLE fh)
{
return -1; /* not supported */
}
使用此版本的'retarget.c'满意,我的程序运行w / o问题。
也许这也会帮助你。
With this version of 'retarget.c' linker was satisfied and my program run w/o problem. Maybe this will help you as well.
这篇关于push_back()使程序在进入main()之前停止,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!