GDB缺少行号

时间:2016-10-03 16:05:44

标签: c linker gdb arm embedded

我正在使用stm32f746vg微控制器调试嵌入式系统,其中一些速度关键的代码段加载到数据RAM而不是闪存中。其余的非关键代码都加载到flash中,默认情况下链接器会将所有.text部分放入flash中。

我用这样令人讨厌的小函数原型做这个重定位:

int main(void) __attribute__((section(".data")));

这会强制main()加载到地址0x2000 0000,这就是我想要的。不幸的是,GDB希望main()加载到地址0x0080 0000,其余的程序代码都在地址main()。因此,GDB不知道main()的行号在哪里。有没有办法告诉GDB" arm-none-eabi-gdb实际上是在这个地址" ?

  • 我有最新版本的arm-none-eabi-gccarm-none-eabi-gcc
  • 我正在使用-g选项运行__attribute__
  • 当我注释掉包含/* Entry Point */ ENTRY(Reset_Handler) /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ /** * for the time being, we are going to buffer the image in sram1. sram1 is * entirely dedicated to buffering images. * DTCM_RAM will be used for user variables */ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K DTCM_SRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K /* RAM1 (xrw) : ORIGIN = 0x20010000, LENGTH = 240K*/ RAM1 (xrw) : ORIGIN = 0x20010000, LENGTH = 245760 RAM2 (xrw) : ORIGIN = 0x2004c000, LENGTH = 16K ITCM_SRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 16K } /* Define output sections */ SECTIONS { /* Vectors need to be loaded at the start of flash. */ .isr_vector : { . = ALIGN(4); KEEP(*(.vector)) /* Startup code */ . = ALIGN(4); } >FLASH /* The program code and other data goes into FLASH */ .text : { . = ALIGN(4); *(.text) /* .text sections (code) */ *(.text*) /* .text* sections (code) */ *(.rodata) /* .rodata sections (constants, strings, etc.) */ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ *(.glue_7) /* glue arm to thumb code */ *(.glue_7t) /* glue thumb to arm code */ *(.eh_frame) /*KEEP (*(.init))*/ /*KEEP (*(.fini))*/ . = ALIGN(4); _etext = .; /* define a global symbols at end of code */ _exit = .; } >FLASH .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH .ARM : { __exidx_start = .; *(.ARM.exidx*) __exidx_end = .; } >FLASH /* used by the startup to initialize data */ _sidata = .; /* Initialized data sections goes into RAM, load LMA copy after code */ .data ORIGIN(DTCM_SRAM) : { . = ALIGN(4); _sdata = .; /* create a global symbol at data start */ *(.data) /* .data sections */ *(.data*) /* .data* sections */ . = ALIGN(4); _edata = .; /* define a global symbol at data end */ } AT > FLASH __const_data_length__ = SIZEOF(.data); /* Uninitialized data section */ . = ALIGN(4); .bss . : { /* This is used by the startup in order to initialize the .bss secion */ _sbss = .; /* define a global symbol at bss start */ __bss_start__ = _sbss; *(.bss) *(.bss*) *(COMMON) . = ALIGN(4); _ebss = .; /* define a global symbol at bss end */ __bss_end__ = _ebss; } >DTCM_SRAM /* User_heap_stack section, used to check that there is enough RAM left */ ._user_heap_stack : { . = ALIGN(4); PROVIDE ( end = . ); PROVIDE ( _end = . ); . = . + _Min_Heap_Size; . = . + _Min_Stack_Size; . = ALIGN(4); } >DTCM_SRAM /* ram1 section, vars must be located here explicitly */ /* Example: extern int foo(void) __attribute__ ((section (".ram1"))); */ /* No initialization is offered for this section.*/ .ram1 ORIGIN(RAM1) : { *(.ram1) } >RAM1 /* Remove information from the standard libraries */ /DISCARD/ : { libc.a ( * ) libm.a ( * ) libgcc.a ( * ) } .ARM.attributes 0 : { *(.ARM.attributes) } } 指令的main原型时,GDB找到行号没有问题。

以下是我的链接描述文件:

CFLAGS  = -gstabs -Wall -std=gnu99 -ffunction-sections -Wno-unused-variable
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mlong-calls
CFLAGS += -I. -ggdb
CFLAGS += -DHSE_VALUE=$(HSE_VALUE)
CFLAGS += -DUSE_STDPERIPH_DRIVER

这些是我的gcc标志

import tensorflow

1 个答案:

答案 0 :(得分:1)

你可以通过将main()放在你选择的特殊代码部分来实现这一点,然后调用它.fast_exec

int main(void) __attribute__((section(".fast_exec")));

然后,在链接描述文件中,将此新部分放在RAM中执行。它将在启动时从FLASH复制:

.fast_exec : {
   *(.fast_exec)
} > DTCM_SRAM AT> FLASH

您可以通过检查地图文件来验证此效果。

请参阅:https://stackoverflow.com/a/15142268/1096140