-gc-sections breaking debugger

OP #1174617
Hi,

I been working on a set of tools for a lpc2387 board I developed,

I built openocd(trunk), gcc(4.3.2) and insight(6.8) under Cygwin, those
work very well, I have scrips to download code and to debug the target.
Those work great as well, but I have a problem.

If a build the code with:

LINKER_FLAGS=-nostartfiles -Xlinker -o$(BUILDDIR)/lpc2387.elf -Xlinker
-M -Wl,-Map=$(BUILDDIR)/lpc2387.map,--cref,--gc-sections

and

CFLAGS= $(DEBUG) \
    $(OPTIM) \
    -T$(LDSCRIPT) \
    -mcpu=arm7tdmi \
    -I$(INCLUDEPATH)\
    -D PACK_STRUCT_END=__attribute\(\(packed\)\) \
    -D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) \
    -fomit-frame-pointer \
    -mthumb-interwork  \
          -ffreestanding    \
          -ffunction-sections     \
         -fdata-sections    \

The debugger won't allow me to step over to the next line of code, if I
remove the -gc-sections parameter (thus removing dead code elimination)
the debugger will work as expected.

Although the debugger is working, is very annoying to have to step line
per line of code, I can set temporal breakpoints but may be someone had
this problem before?
#1174619
Alfredo Cabral wrote:
> Alfredo Cabral wrote:
>
> Further examination reveals, it was only with the first function.
>
> The rest of the debugging session works as expected.

generally if using -gc-sections breaks your code then you need to check
the linker script.

Do you have the KEEP sections correctly defined (usually on the reset
vector)?

Cheers
Spen
OP #1174620
Spencer Oliver wrote:
> Alfredo Cabral wrote:
>> Alfredo Cabral wrote:
>>
>> Further examination reveals, it was only with the first function.
>>
>> The rest of the debugging session works as expected.
>
> generally if using -gc-sections breaks your code then you need to check
> the linker script.
>
> Do you have the KEEP sections correctly defined (usually on the reset
> vector)?
>
> Cheers
> Spen

Spen,

The code compiled and linked fine, the thing is, while debugging it was
impossible to step over a function, Insight jumped into everytime,
however this only happened on a very specific binary, most compiles work
ok, and those that exhibit anomalies, only do so on the very first
function. It drove me nuts at some point because I thought this wasn't
an isolated case, but as I explained above, turns out it was.

Cheers
Alfredo

Reply

A question of your own? This thread is over 17 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.