Bug 18144 - [aarch64] the skip prologue functionality doesn't work well for same assembly functions
Summary: [aarch64] the skip prologue functionality doesn't work well for same assembly...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: HEAD
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-19 11:08 UTC by Mihail-Marian Nistor
Modified: 2018-04-18 19:05 UTC (History)
4 users (show)

See Also:
Host:
Target: aarch64
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments
an example, gdb and gcc information (1.98 KB, application/x-7z-compressed)
2015-03-19 11:08 UTC, Mihail-Marian Nistor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mihail-Marian Nistor 2015-03-19 11:08:05 UTC
Created attachment 8198 [details]
an example, gdb and gcc information

The gdb always sets the break-point to an assembly function (or a symbol) at
the next line when the ASM file is compiled with debug information (-g option)
even if the function does not have prologue instructions. 

Let's have an example:

  .global _start
_start: 
	nop
	nop
  ret

The gdb will put the break-point at the second nop instruction - that is wrong - when the user uses the break-point _start command.
In this scenario, the gdb should put the break-point at the first nop instruction.
Comment 1 Keith Seitz 2015-03-19 15:52:22 UTC
In the attachment is a reproducer:

---- from readme.txt in the attachment ----
1) The command line to compile the assembly file with debug information
aarch64-none-elf-gcc -O0 -g -nostartfiles -o main.elf main.S

2) You can see below the steps in order to reproduce the aarch64 gdb problem.
aarch64-none-elf-gdb main.elf
(gdb) b _start
Breakpoint 1 at 0x400028: file main.S, line 4.

Observed:
The breakpoint was set at the second nop instruction. 
Expected:
The breakpoint should be set at the first nop instruction.
---- end readme.txt ----

The problem here is that when you use the break command and give it a linespec location, it *will* attempt to skip prologue instructions. Always.

However, if you give it an address location instead, gdb will *not* attempt to skip the prologue. I guess some of us old-timers have the proper idiom hammered into our fingers already.

Using "break *_start" should better suit your needs when debugging assembler source files.

I am recategorizing this to "enhancement" because I think it might be desirable to change the behavior based on the source language, e.g., if the source language of a breakpoint location is assembler, do not do prologue-skipping. I can see arguments both ways for this, so I will wait for maintainers to weigh in on the issue.
Comment 2 weimin.pan 2017-10-05 01:39:25 UTC
It works fine now with current git master:

(gdb) disass _start
Dump of assembler code for function _start:
   0x0000000000400244 <+0>:     nop
   0x0000000000400248 <+4>:     nop
   0x000000000040024c <+8>:     ret
End of assembler dump.
(gdb) b _start
Breakpoint 1 at 0x400244
Comment 3 Pedro Alves 2017-10-05 14:24:22 UTC
GDB stopped skipping the prologue of asm sources with:

commit 6e22494e5076e4d3c0b2c2785883162f83db499e
Author:     Jan Kratochvil <jan.kratochvil@redhat.com>
AuthorDate: Fri Jun 26 15:11:14 2015 +0200

    Do not skip prologue for asm (.S) files
Comment 4 weimin.pan 2018-04-18 19:05:24 UTC
Fix verified.