From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21281 invoked by alias); 7 Jun 2008 07:48:54 -0000 Received: (qmail 21272 invoked by uid 22791); 7 Jun 2008 07:48:53 -0000 X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.155) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 07 Jun 2008 07:48:24 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.2/jtpda-5.5pre1) with ESMTP id m577mDLA039126 ; Sat, 7 Jun 2008 09:48:13 +0200 (CEST) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [IPv6:2001:660:2402::142]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id m577mDqW025553 ; Sat, 7 Jun 2008 09:48:13 +0200 (CEST) Received: from d620muller ([130.79.244.152]) by mailserver.u-strasbg.fr (8.13.8/jtpda-5.5pre1) with ESMTP id m577m8nw005441 ; Sat, 7 Jun 2008 09:48:13 +0200 (CEST) From: "Pierre Muller" To: , , "'Mark Kettenis'" , References: <004f01c8ac58$06a1ddb0$13e59910$@u-strasbg.fr> <000c01c8c246$de300f50$9a902df0$@u-strasbg.fr> <200805301157.m4UBvOL5009408@brahms.sibelius.xs4all.nl> <001901c8c256$06f8be00$14ea3a00$@u-strasbg.fr> <001a01c8c263$f493b1d0$ddbb1570$@u-strasbg.fr> <200805301457.m4UEvnGD028393@brahms.sibelius.xs4all.nl> <000301c8c2ea$0c2d72a0$248857e0$@u-strasbg.fr> <20080605202640.GL25085@caradoc.them.org> <200806052041.m55Kfneh015684@brahms.sibelius.xs4all.nl> <002101c8c7a5$8066c850$813458f0$@u-strasbg.fr> In-Reply-To: <002101c8c7a5$8066c850$813458f0$@u-strasbg.fr> Subject: [RFA] New skip __main version Date: Sat, 07 Jun 2008 07:48:00 -0000 Message-ID: <000301c8c872$d9493660$8bdba320$@u-strasbg.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Content-Language: en-us X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (mailhost.u-strasbg.fr [IPv6:2001:660:2402::155]); Sat, 07 Jun 2008 09:48:13 +0200 (CEST) X-Virus-Status: Clean Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-06/txt/msg00126.txt.bz2 Here is a new version of this patch: it should fix the concern I raised about potential wrapping problems if CORE_ADDR is 64 bit wide. I am still unable to test the 64-bit as the --enable-target=all --enable-64bit-bfd is still broken. A patch has been submitted by Ulrich Weigand http://sourceware.org/ml/gdb-patches/2008-05/msg00537.html but has not yet been committed, prevent successful compilation of gdb configured with the two options above :( For cygwin native gdb, the testsuite results show no change to the previous version. === gdb Summary === ! # of expected passes 10791 ! # of unexpected failures 581 # of expected failures 59 # of unknown successes 2 ! # of known failures 22 # of unresolved testcases 40 # of untested testcases 14 # of unsupported tests 23 ! /usr/local/src/gdbcvs/build-bare/gdb/testsuite/../../gdb/gdb version 6.8.50.2 0080606-cvs -nx --- 12103,12115 ---- === gdb Summary === ! # of expected passes 10954 ! # of unexpected failures 386 # of expected failures 59 # of unknown successes 2 ! # of known failures 23 # of unresolved testcases 40 # of untested testcases 14 # of unsupported tests 23 ! /usr/local/src/gdbcvs/build-bare/gdb/testsuite/../../gdb/gdb version 6.8.50.2 0080604-cvs -nx ChangeLog entry: 2008-06-07 Pedro Alves Pierre Muller * gdbarch.sh (gdbarch_skip_main_prologue): New. * gdbarch.h, gdbarch.c: Regenerate. * i386-tdep.h (i386_skip_main_prologue): Declare. * i386-tdep.c (i386_skip_main_prologue): New. * i386-cygwin-tdep.c (i386_cygwin_init_abi): Register i386_skip_main_prologue as gdbarch_skip_main_prologue gdbarch callback. * symtab.c (find_function_start_sal): When pc points at the "main" function, call gdbarch_skip_main_prologue. Index: gdb/gdbarch.c =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.c,v retrieving revision 1.428 diff -u -p -r1.428 gdbarch.c --- gdb/gdbarch.c 24 May 2008 16:32:01 -0000 1.428 +++ gdb/gdbarch.c 6 Jun 2008 10:54:57 -0000 @@ -183,6 +183,7 @@ struct gdbarch gdbarch_integer_to_address_ftype *integer_to_address; gdbarch_return_value_ftype *return_value; gdbarch_skip_prologue_ftype *skip_prologue; + gdbarch_skip_main_prologue_ftype *skip_main_prologue; gdbarch_inner_than_ftype *inner_than; gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc; gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address; @@ -313,6 +314,7 @@ struct gdbarch startup_gdbarch = 0, /* integer_to_address */ 0, /* return_value */ 0, /* skip_prologue */ + 0, /* skip_main_prologue */ 0, /* inner_than */ 0, /* breakpoint_from_pc */ 0, /* adjust_breakpoint_address */ @@ -561,6 +563,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of return_value, has predicate */ if (gdbarch->skip_prologue == 0) fprintf_unfiltered (log, "\n\tskip_prologue"); + /* Skip verify of skip_main_prologue, has predicate */ if (gdbarch->inner_than == 0) fprintf_unfiltered (log, "\n\tinner_than"); if (gdbarch->breakpoint_from_pc == 0) @@ -999,6 +1002,12 @@ gdbarch_dump (struct gdbarch *gdbarch, s "gdbarch_dump: single_step_through_delay = <0x%lx>\n", (long) gdbarch->single_step_through_delay); fprintf_unfiltered (file, + "gdbarch_dump: gdbarch_skip_main_prologue_p() = %d\n", + gdbarch_skip_main_prologue_p (gdbarch)); + fprintf_unfiltered (file, + "gdbarch_dump: skip_main_prologue = <0x%lx>\n", + (long) gdbarch->skip_main_prologue); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_skip_permanent_breakpoint_p() = %d\n", gdbarch_skip_permanent_breakpoint_p (gdbarch)); fprintf_unfiltered (file, @@ -2123,6 +2132,30 @@ set_gdbarch_skip_prologue (struct gdbarc } int +gdbarch_skip_main_prologue_p (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + return gdbarch->skip_main_prologue != NULL; +} + +CORE_ADDR +gdbarch_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR ip) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->skip_main_prologue != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_skip_main_prologue called\n"); + return gdbarch->skip_main_prologue (gdbarch, ip); +} + +void +set_gdbarch_skip_main_prologue (struct gdbarch *gdbarch, + gdbarch_skip_main_prologue_ftype skip_main_prologue) +{ + gdbarch->skip_main_prologue = skip_main_prologue; +} + +int gdbarch_inner_than (struct gdbarch *gdbarch, CORE_ADDR lhs, CORE_ADDR rhs) { gdb_assert (gdbarch != NULL); Index: gdb/gdbarch.h =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.h,v retrieving revision 1.383 diff -u -p -r1.383 gdbarch.h --- gdb/gdbarch.h 24 May 2008 16:32:01 -0000 1.383 +++ gdb/gdbarch.h 6 Jun 2008 10:54:57 -0000 @@ -379,6 +379,12 @@ typedef CORE_ADDR (gdbarch_skip_prologue extern CORE_ADDR gdbarch_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR ip); extern void set_gdbarch_skip_prologue (struct gdbarch *gdbarch, gdbarch_skip_prologue_ftype *skip_prologue); +extern int gdbarch_skip_main_prologue_p (struct gdbarch *gdbarch); + +typedef CORE_ADDR (gdbarch_skip_main_prologue_ftype) (struct gdbarch *gdbarch, CORE_ADDR ip); +extern CORE_ADDR gdbarch_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR ip); +extern void set_gdbarch_skip_main_prologue (struct gdbarch *gdbarch, gdbarch_skip_main_prologue_ftype *skip_main_prologue); + typedef int (gdbarch_inner_than_ftype) (CORE_ADDR lhs, CORE_ADDR rhs); extern int gdbarch_inner_than (struct gdbarch *gdbarch, CORE_ADDR lhs, CORE_ADDR rhs); extern void set_gdbarch_inner_than (struct gdbarch *gdbarch, gdbarch_inner_than_ftype *inner_than); Index: gdb/gdbarch.sh =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.sh,v retrieving revision 1.469 diff -u -p -r1.469 gdbarch.sh --- gdb/gdbarch.sh 24 May 2008 16:32:01 -0000 1.469 +++ gdb/gdbarch.sh 6 Jun 2008 10:54:58 -0000 @@ -482,6 +482,7 @@ M:CORE_ADDR:integer_to_address:struct ty M:enum return_value_convention:return_value:struct type *functype, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf:functype, valtype, regcache, readbuf, writebuf m:CORE_ADDR:skip_prologue:CORE_ADDR ip:ip:0:0 +M:CORE_ADDR:skip_main_prologue:CORE_ADDR ip:ip f:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs:0:0 m:const gdb_byte *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr::0: M:CORE_ADDR:adjust_breakpoint_address:CORE_ADDR bpaddr:bpaddr Index: gdb/i386-cygwin-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-cygwin-tdep.c,v retrieving revision 1.16 diff -u -p -r1.16 i386-cygwin-tdep.c --- gdb/i386-cygwin-tdep.c 1 Jan 2008 22:53:10 -0000 1.16 +++ gdb/i386-cygwin-tdep.c 6 Jun 2008 10:54:58 -0000 @@ -227,6 +227,8 @@ i386_cygwin_init_abi (struct gdbarch_inf set_gdbarch_skip_trampoline_code (gdbarch, i386_cygwin_skip_trampoline_code); + set_gdbarch_skip_main_prologue (gdbarch, i386_skip_main_prologue); + tdep->struct_return = reg_struct_return; tdep->gregset_reg_offset = i386_win32_gregset_reg_offset; Index: gdb/i386-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-tdep.c,v retrieving revision 1.258 diff -u -p -r1.258 i386-tdep.c --- gdb/i386-tdep.c 16 May 2008 00:27:23 -0000 1.258 +++ gdb/i386-tdep.c 6 Jun 2008 10:54:59 -0000 @@ -1160,6 +1160,38 @@ i386_skip_prologue (struct gdbarch *gdba return pc; } +/* Check that the code pointed to by PC corresponds to a call to + __main, skip it if so. Return PC otherwise. */ + +CORE_ADDR +i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + gdb_byte op; + + target_read_memory (pc, &op, 1); + if (op == 0xe8) + { + gdb_byte buf[4]; + + if (target_read_memory (pc + 1, buf, sizeof buf) == 0) + { + /* Make sure address is computed correctly as a 32bit + integer even if CORE_ADDR is 64 bit wide. */ + struct minimal_symbol *s; + CORE_ADDR call_dest = pc + 5 + extract_signed_integer (buf, 4); + + call_dest = call_dest & 0xffffffffU; + s = lookup_minimal_symbol_by_pc (call_dest); + if (s != NULL + && SYMBOL_LINKAGE_NAME (s) != NULL + && strcmp (SYMBOL_LINKAGE_NAME (s), "__main") == 0) + pc += 5; + } + } + + return pc; +} + /* This function is 64-bit safe. */ static CORE_ADDR Index: gdb/i386-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/i386-tdep.h,v retrieving revision 1.54 diff -u -p -r1.54 i386-tdep.h --- gdb/i386-tdep.h 2 May 2008 16:49:54 -0000 1.54 +++ gdb/i386-tdep.h 6 Jun 2008 10:54:59 -0000 @@ -170,6 +170,7 @@ extern struct type *i386_sse_type (struc /* Functions exported from i386-tdep.c. */ extern CORE_ADDR i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name); +extern CORE_ADDR i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc); /* Return the name of register REGNUM. */ extern char const *i386_register_name (struct gdbarch * gdbarch, int regnum); Index: gdb/symtab.c =================================================================== RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.189 diff -u -p -r1.189 symtab.c --- gdb/symtab.c 27 May 2008 19:29:51 -0000 1.189 +++ gdb/symtab.c 6 Jun 2008 10:55:00 -0000 @@ -2617,6 +2617,21 @@ find_function_start_sal (struct symbol * /* Recalculate the line number (might not be N+1). */ sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0); } + + /* On targets with executable formats that don't have a concept of + constructors (ELF with .init has, PE doesn't), gcc emits a call + to `__main' in `main' between the prologue and before user + code. */ + if (funfirstline + && gdbarch_skip_main_prologue_p (current_gdbarch) + && SYMBOL_LINKAGE_NAME (sym) + && strcmp (SYMBOL_LINKAGE_NAME (sym), "main") == 0) + { + pc = gdbarch_skip_main_prologue (current_gdbarch, pc); + /* Recalculate the line number (might not be N+1). */ + sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0); + } + sal.pc = pc; return sal;