【问题标题】:GDB missing line numbersGDB 缺少行号
【发布时间】:2016-10-03 16:05:43
【问题描述】:

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

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

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

这会强制将main() 加载到地址0x2000 0000,这正是我想要的。不幸的是,GDB 期望main() 被加载到地址0x0080 0000,其余的程序代码就在这个地址。结果,GDB 不知道main() 的行号在哪里。有什么方法可以告诉 GDB“main() 实际上在这个地址”?

  • 我有最新版本的arm-none-eabi-gdb 和arm-none-eabi-gcc。
  • 我正在使用 -g 选项运行 arm-none-eabi-gcc。
  • 当我注释掉包含 __attribute__ 指令的 main 原型时​​,GDB 可以毫无问题地找到行号。

以下是我的链接器脚本:

/* 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) }
}

这些是我的 gcc 标志

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

【问题讨论】:

  • main 变成 .data?除了遇到麻烦,它应该实现什么?
  • @EugeneSh.,显然,它应该实现将main加载到RAM而不是闪存中。我倾向于怀疑有更好的方法来实现这一点,但不确定是否有任何这样的方法可以解决 OP 的问题。
  • @JohnBollinger 这确实是一种尴尬的方式。我想这是一个 XY 问题..
  • 如果问题只出在main,那么让您的main 只调用另一个充当真正main 的函数。
  • @jxh 仍然在data 中放置一个函数是个坏主意。只需将函数放在单独的 sub-text 部分中,然后将其定向到 RAM,如果这是有意的话。

标签: c linker gdb arm embedded


【解决方案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

【讨论】:

  • 这就是我现在正在做的事情。 “.fast_exec”是 GDB 识别的特殊名称吗?
  • 不,没什么特别的。
  • 您能否提供 gdb 在您输入 info symbol main 和 info address main 时所说的内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-25
  • 2015-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-05
相关资源
最近更新 更多