gdb/2236: gdb ignores breakpoint at _start

Stephen Ma stephenma@telus.net
Sat Mar 3 18:28:00 GMT 2007


>Number:         2236
>Category:       gdb
>Synopsis:       gdb ignores breakpoint at _start
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 03 18:28:01 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Stephen Ma <stephenma@telus.net>
>Release:        6.6-debian
>Organization:
>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".
>Description:
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.
>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.
>Fix:
Workaround: put the first breakpoint somewhere else.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gdb-prs mailing list