GDB no source available ARM-M23

0

I know there are a lot of posts about GDB and "no source available", but none of them have solved my issue.

I have a main.c file, which contains my main-function. This function calls another function named Lib_XOM_ADD, which is in a file named xom_add.c. My main also includes some other files from the CMSIS and other M23 libraries. When I run gdb with the -tui option and I want to enter the Lib_XOM_ADD function, the above window shows "no source available". On the other hand, all the functions in the other included files are shown there. So my question is: How can I tell gdb where to find the source for this function? And why does it not work for this file but for all others?

So here is some of my main.c file

#include <stdio.h>
#include <stdint.h>
#include "NuMicro.h"
#include <gpio_reg.h>

int32_t result;

#define LED_INIT()  {PA->MODE = (PA->MODE &(~(0xf << 10*2))) | (0x5 << 10 * 2);}
#define LED_GREEN  PA10
#define LED_YELLOW   PA11

int32_t main(void)
{
    LED_INIT();
    LED_YELLOW = 1; 
    LED_GREEN = 0;

    SYS_UnlockReg();
    SYS_Init();

    uint32_t v1 = 100;
    uint32_t v2 = 200;
    uint32_t cnt = 0;

    while(1){
       result = Lib_XOM_ADD(v1, v2);
       result = Lib_XOM_ADD(100, cnt);
       cnt = cnt + 1;
    }
}

And this is part of my makefile

BUILDDIR = build

CROSS_COMPILE = /mypath/gcc-arm-none-eabi-*/bin
CC = $(CROSS_COMPILE)/arm-none-eabi-gcc
LD = $(CROSS_COMPILE)/arm-none-eabi-gcc
AR = $(CROSS_COMPILE)/arm-none-eabi-ar
OBJCOPY = $(CROSS_COMPILE)/arm-none-eabi-objcopy
OD = $(CROSS_COMPILE)/arm-none-eabi-objdump
GDB = $(CROSS_COMPILE)/arm-none-eabi-gdb

LIB = /mypath/M2351BSP/Library
DEV = /Device/Nuvoton/M2351/Source
DRIV = /StdDriver/src
SRC = .

SOURCES += $(SRC)/main.c
SOURCES += $(SRC)/xom_add.c
SOURCES += $(LIB)$(DEV)/GCC/startup_M2351.s \
    $(LIB)$(DEV)/system_M2351.c
SOURCES += $(LIB)$(DRIV)/clk.c \
    $(LIB)$(DRIV)/retarget.c
SOURCES += $(LIB)$(DRIV)/fmc.c \
    $(LIB)$(DRIV)/sys.c \
    $(LIB)$(DRIV)/gpio.c \

OBJECTS = $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(basename $(SOURCES))))

INCLUDES += -I$(LIB)/CMSIS/Include \
    -I$(LIB)/Device/Nuvoton/M2351/Include \
    -I$(LIB)/StdDriver/inc \

ELF = $(BUILDDIR)/main.elf
HEX = $(BUILDDIR)/main.hex
BIN = $(BUILDDIR)/main.bin

ELF_ABS = $(CURDIR)/$(ELF)
MCU_FLAGS = -mcpu=cortex-m23 -mthumb
CFLAGS = -g -W $(MCU_FLAGS) $(INCLUDES)

LDSCRIPT = linkerfile.ld
LDFLAGS = $(MCU_FLAGS) -T$(LDSCRIPT) -Wl,-Map=output.map

$(BIN): $(ELF)
    $(OBJCOPY) -O binary $< $@

$(HEX): $(ELF)
    $(OBJCOPY) -O ihex $< $@

$(ELF): $(OBJECTS)
    $(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)

$(BUILDDIR)/%.o: %.c
    mkdir -p $(dir $@)
    $(CC) -c $(CFLAGS) $< -o $@

$(BUILDDIR)/%.o: %.s
    mkdir -p $(dir $@)
    $(CC) -c $(CFLAGS) $< -o $@

As I said, for example in sys.h, there is the function "SYS_UnlockReg()", and when I set a breakpoint to that function, gdb halts there and displays the code lines in the above window. But for the breakpoint at Lib_XOM_ADD, there is "no source available".

The program compiles and runs successfully. The only problem is this "no source available".

Also, when I type (gdb) info sources, the xom_add.c file is not listed there.

I really don't know where to look and would be very grateful for some hints.

EDIT

While inside the Lib_XOM_ADD function, I get the following output:

(gdb) info source
Current source file is main.c
Compilation directory is /mypath/nuvotonM2351/FMC_XOM
Located in /mypath/nuvotonM2351/FMC_XOM/main.c
Contains 117 lines.
Source language is c.
Producer is GNU C17 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] -mcpu=cortex-m23 -mthumb -mfloat-abi=soft -march=armv8-m.base -ggdb.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info

So the problem seems to be that gdb thinks it is still in main.c but instead it is in xom_add.c How can I fix this?

Also when typing (gdb) next, the following text shows: "Single stepping until exit from function Lib_XOM_ADD, which has no line number information."

When typing (gdb) info functions, the Lib_XOM_ADD function appears under "Non-debugging symbols".

EDIT 2

Found out something: I wanted to place the xom_add.c file into a special memory region. If I don't do that, the source is shown in the gdb-tui. But when I want to place the function inside my special memory region (with the linkerscript), I get the above problem.

So what I have done there already is adjust the linkerscript as follows (only shown the above part of the linkerscript):

/* Linker script to configure memory regions. */

/* Entry Point */
ENTRY(Reset_Handler)

/* Specify the memory areas */
MEMORY
{
  FLASH (rx)      : ORIGIN = 0x00000000, LENGTH = 0x70000   /* 458k */
  FLASH_myregion (x) : ORIGIN = 0x00070000, LENGTH = 0x05000   /*  20k */
  RAM (rwx)       : ORIGIN = 0x20000000, LENGTH = 0x18000   /* 160k */
}


/* Define output sections */
SECTIONS
{
    .text :
    {
        KEEP(*(.vectors))
        __Vectors_End = .;
        __Vectors_Size = __Vectors_End - __Vectors;
        __end__ = .;

        *(EXCLUDE_FILE(*xom_add.o) *.text*)

        KEEP(*(.init))
        KEEP(*(.fini))

        /* .ctors */
        *crtbegin.o(.ctors)
        *crtbegin?.o(.ctors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
        *(SORT(.ctors.*))
        *(.ctors)

        /* .dtors */
        *crtbegin.o(.dtors)
        *crtbegin?.o(.dtors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
        *(SORT(.dtors.*))
        *(.dtors)

        *(.rodata*)

        KEEP(*(.eh_frame*))
    } > FLASH

    .mysection :
    {
        KEEP(*(.mysection))
        . = ALIGN(4);
        *xom_add.o

        . = ALIGN(4);
        _etext = .;       

     } > FLASH_myregion
gdb
cortex-m
asked on Stack Overflow Jul 21, 2020 by straumle • edited Sep 2, 2020 by straumle

1 Answer

0

SOLUTION

As mentioned in a comment above, I suddenly realized that the problem is that I wanted to place the function inside a specific memory region. And apparently, I did that wrong.

Now it is working fine.

For those interested: I had to place the __attribute__((__section__(".mysection"))) before the definition of the function in the xom_add.c file and then could erase the *EXCLUDE part in the linkerscript and the *xom_add.c part in mysection. So very simple solution!

answered on Stack Overflow Sep 2, 2020 by straumle

User contributions licensed under CC BY-SA 3.0