Bug 9341 - gdb ignores breakpoint at _start
Summary: gdb ignores breakpoint at _start
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 6.6
: P3 enhancement
Target Milestone: ---
Assignee: Jan Kratochvil
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-03 18:28 UTC by stephenma
Modified: 2010-04-04 22:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description stephenma 2007-03-03 18:28:01 UTC
[Converted from Gnats 2236]

On GNU/Linux (Intel 386), the symbol "_start" labels the first machine instruction to be executed.  If the program is pure assembler (no C or C library startup code), and I put a breakpoint at _start, the break does not happen.

Oddly enough, if _start is in the C library's startup code (start.S), the break *does* happen.

Release:
6.6-debian

Environment:
Linux jp 2.6.18-1-686 #1 SMP Fri Sep 29 16:25:40 UTC 2006 i686 GNU/Linux
GNU assembler 2.17 Debian GNU/Linux
This GDB was configured as "i486-linux-gnu".

How-To-Repeat:
Here is the full assembler program in file "hello.s":

		.global _start
	
	_start:
	
	# Output "hello world" message.
		mov	$4, %eax	# 4 = write
		mov	$1, %ebx	# stdout
		mov	$msg, %ecx
		mov	$len, %edx
		int	$0x80
	
	# Exit from program.
		xor	%ebx, %ebx
		mov	$1, %eax
		int	$0x80
	
		ret
	
		.data
	
	msg:	.ascii	"Hello world"
		.byte	0x0a
		.equiv  len, .-msg

Assemble and link it with:

	as --gdwarf-2 -o hello.o hello.s  &&  ld -o hello hello.o

Here is a transcript of the GDB session:

	$ gdb add
	GNU gdb 6.6-debian
	Copyright (C) 2006 Free Software Foundation, Inc.
	GDB is free software, covered by the GNU General Public License, and you are
	welcome to change it and/or distribute copies of it under certain conditions.
	Type "show copying" to see the conditions.
	There is absolutely no warranty for GDB.  Type "show warranty" for details.
	This GDB was configured as "i486-linux-gnu"...
	Using host libthread_db library "/lib/tls/libthread_db.so.1".
	(gdb) b _start
	Breakpoint 1 at 0x8048074: file add.s, line 6.
	(gdb) r
	Starting program: /home/steve/src/smf/add 
	Failed to read a valid object file image from memory.
	Hello world
	
	Program exited normally.
	(gdb) q

Notice the program proceeds to output "Hello world" despite the breakpoint on its first instruction.
Comment 1 stephenma 2007-03-03 18:28:01 UTC
Fix:
Workaround: put the first breakpoint somewhere else.
Comment 2 Jan Kratochvil 2010-04-04 21:52:36 UTC

*** This bug has been marked as a duplicate of 9436 ***
Comment 3 Jan Kratochvil 2010-04-04 22:13:22 UTC
http://sourceware.org/ml/gdb-cvs/2010-04/msg00029.html
gdb/
	* infcmd.c (run_command_1): Call proceed with regcache_read_pc address.
	* config/djgpp/fnchange.lst: Add translation for break-entry.exp.

gdb/testsuite/
	* gdb.base/break-entry.exp: New.
Comment 4 Jan Kratochvil 2010-04-04 22:14:17 UTC
Checked-in.