* [RFC/RFA] PING: skip __main
@ 2008-05-02 13:26 Pierre Muller
2008-05-04 19:57 ` Pedro Alves
2008-05-30 15:56 ` [PING2] : " Pierre Muller
0 siblings, 2 replies; 16+ messages in thread
From: Pierre Muller @ 2008-05-02 13:26 UTC (permalink / raw)
To: 'Pedro Alves', 'Daniel Jacobowitz', gdb-patches
Cc: 'Mark Kettenis'
Pedro submitted this patch end of January,
but the 6.8 release pushed it to a later date.
http://sourceware.org/ml/gdb-patches/2008-01/msg00665.html
Now that GDB 6.8 is out,
I would really like to get this patch in.
Pedro, this is your work, but you seem to be
much more involved in other things lately,
thus, if you don't mind, I can try to push this through.
I updated the patch from the first message
referenced and just followed Daniel's advice in
http://sourceware.org/ml/gdb-patches/2008-01/msg00883.html
to change skip___main into skip_main_constructor.
This __main call seems to be
a common feature for coff format, thus
I suppose that it applies to other targets,
go32v2 djgpp is probably one of them.
For cygwin target, I get this:
=== gdb Summary ===
-# of expected passes 10733
-# of unexpected failures 560
+# of expected passes 10928
+# of unexpected failures 363
# of expected failures 59
# of unknown successes 2
-# of known failures 21
+# of known failures 23
# of unresolved testcases 40
# of untested testcases 14
# of unsupported tests 23
Almost 200 failures less...
Daniel wanted to get a comment from Mark
in his last email in that thread, that is the reason
why I added Mark Kettenis to the list of recipients.
Does this patch look OK now?
One point that should still be discussed is
if we should call main_name function
rather than hardcoded "main" in find_function_start_sal in symtab.c.
Pierre Muller
Pascal language support maintainer for GDB
2008-05-02 Pedro Alves <pedro_alves@portugalmail.pt>
Pierre Muller <muller@ics.u-strasbg.fr>
* gdbarch.sh (gdbarch_skip_main_constructor_call): New.
* gdbarch.h, gdbarch.c: Regenerate.
* i386-tdep.h (i386_skip_main_constructor_call): Declare.
* i386-tdep.c (i386_skip_main_constructor_call): New.
* i386-cygwin-tdep.c (i386_cygwin_init_abi): Register
i386_skip_main_constructor_call as
gdbarch_skip_main_constructor_call
gdbarch callback.
* symtab.c (find_function_start_sal): When pc points at the "main"
function, call gdbarch_skip_main_constructor_call.
Index: gdb/gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.422
diff -u -p -r1.422 gdbarch.c
--- gdb/gdbarch.c 22 Apr 2008 11:03:41 -0000 1.422
+++ gdb/gdbarch.c 30 Apr 2008 13:01:33 -0000
@@ -184,6 +184,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_constructor_call_ftype *skip_main_constructor_call;
gdbarch_inner_than_ftype *inner_than;
gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
@@ -306,6 +307,7 @@ struct gdbarch startup_gdbarch =
0, /* integer_to_address */
0, /* return_value */
0, /* skip_prologue */
+ 0, /* skip_main_constructor_call */
0, /* inner_than */
0, /* breakpoint_from_pc */
0, /* adjust_breakpoint_address */
@@ -542,6 +544,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_constructor_call, has predicate */
if (gdbarch->inner_than == 0)
fprintf_unfiltered (log, "\n\tinner_than");
if (gdbarch->breakpoint_from_pc == 0)
@@ -934,6 +937,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_constructor_call_p()
= %d\n",
+ gdbarch_skip_main_constructor_call_p (gdbarch));
+ fprintf_unfiltered (file,
+ "gdbarch_dump: skip_main_constructor_call =
<0x%lx>\n",
+ (long) gdbarch->skip_main_constructor_call);
+ fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_skip_permanent_breakpoint_p()
= %d\n",
gdbarch_skip_permanent_breakpoint_p (gdbarch));
fprintf_unfiltered (file,
@@ -2075,6 +2084,30 @@ set_gdbarch_skip_prologue (struct gdbarc
}
int
+gdbarch_skip_main_constructor_call_p (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ return gdbarch->skip_main_constructor_call != NULL;
+}
+
+CORE_ADDR
+gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch, CORE_ADDR ip)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->skip_main_constructor_call != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_skip_main_constructor_call
called\n");
+ return gdbarch->skip_main_constructor_call (gdbarch, ip);
+}
+
+void
+set_gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch,
+ gdbarch_skip_main_constructor_call_ftype
skip_main_constructor_call)
+{
+ gdbarch->skip_main_constructor_call = skip_main_constructor_call;
+}
+
+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.377
diff -u -p -r1.377 gdbarch.h
--- gdb/gdbarch.h 29 Apr 2008 16:06:07 -0000 1.377
+++ gdb/gdbarch.h 30 Apr 2008 13:01:33 -0000
@@ -381,6 +381,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_constructor_call_p (struct gdbarch *gdbarch);
+
+typedef CORE_ADDR (gdbarch_skip_main_constructor_call_ftype) (struct
gdbarch *gdbarch, CORE_ADDR ip);
+extern CORE_ADDR gdbarch_skip_main_constructor_call (struct gdbarch
*gdbarch, CORE_ADDR ip);
+extern void set_gdbarch_skip_main_constructor_call (struct gdbarch
*gdbarch, gdbarch_skip_main_constructor_call_ftype
*skip_main_constructor_call);
+
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.463
diff -u -p -r1.463 gdbarch.sh
--- gdb/gdbarch.sh 29 Apr 2008 16:06:06 -0000 1.463
+++ gdb/gdbarch.sh 30 Apr 2008 13:01:34 -0000
@@ -483,6 +483,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_constructor_call: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 30 Apr 2008 13:01:34 -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_constructor_call (gdbarch,
i386_skip_main_constructor_call);
+
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.255
diff -u -p -r1.255 i386-tdep.c
--- gdb/i386-tdep.c 25 Apr 2008 14:57:30 -0000 1.255
+++ gdb/i386-tdep.c 30 Apr 2008 13:01:35 -0000
@@ -941,6 +941,33 @@ 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_constructor_call (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)
+ {
+ CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
+
+ struct minimal_symbol *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.53
diff -u -p -r1.53 i386-tdep.h
--- gdb/i386-tdep.h 11 Mar 2008 05:21:38 -0000 1.53
+++ gdb/i386-tdep.h 30 Apr 2008 13:01:35 -0000
@@ -166,6 +166,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_constructor_call (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.177
diff -u -p -r1.177 symtab.c
--- gdb/symtab.c 19 Apr 2008 11:39:50 -0000 1.177
+++ gdb/symtab.c 30 Apr 2008 13:01:36 -0000
@@ -2572,6 +2572,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_constructor_call_p (current_gdbarch)
+ && SYMBOL_LINKAGE_NAME (sym)
+ && strcmp (SYMBOL_LINKAGE_NAME (sym), "main") == 0)
+ {
+ pc = gdbarch_skip_main_constructor_call (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;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC/RFA] PING: skip __main
2008-05-02 13:26 [RFC/RFA] PING: skip __main Pierre Muller
@ 2008-05-04 19:57 ` Pedro Alves
2008-05-30 15:56 ` [PING2] : " Pierre Muller
1 sibling, 0 replies; 16+ messages in thread
From: Pedro Alves @ 2008-05-04 19:57 UTC (permalink / raw)
To: Pierre Muller
Cc: 'Daniel Jacobowitz', gdb-patches, 'Mark Kettenis'
A Friday 02 May 2008 14:25:44, Pierre Muller wrote:
> Pedro submitted this patch end of January,
> but the 6.8 release pushed it to a later date.
> http://sourceware.org/ml/gdb-patches/2008-01/msg00665.html
>
> Now that GDB 6.8 is out,
> I would really like to get this patch in.
> Pedro, this is your work, but you seem to be
> much more involved in other things lately,
> thus, if you don't mind, I can try to push this through.
>
I don't mind at all. I even thank you. :-)
> I updated the patch from the first message
> referenced and just followed Daniel's advice in
> http://sourceware.org/ml/gdb-patches/2008-01/msg00883.html
> to change skip___main into skip_main_constructor.
>
> This __main call seems to be
> a common feature for coff format, thus
> I suppose that it applies to other targets,
> go32v2 djgpp is probably one of them.
>
> For cygwin target, I get this:
>
> === gdb Summary ===
>
> -# of expected passes 10733
> -# of unexpected failures 560
> +# of expected passes 10928
> +# of unexpected failures 363
> # of expected failures 59
> # of unknown successes 2
> -# of known failures 21
> +# of known failures 23
> # of unresolved testcases 40
> # of untested testcases 14
> # of unsupported tests 23
>
> Almost 200 failures less...
>
> Daniel wanted to get a comment from Mark
> in his last email in that thread, that is the reason
> why I added Mark Kettenis to the list of recipients.
>
> Does this patch look OK now?
>
> One point that should still be discussed is
> if we should call main_name function
> rather than hardcoded "main" in find_function_start_sal in symtab.c.
>
I believe "__main" is only emitted by gcc in the "main"
entry point. I'd expect other gcc languages' runtimes
to have something like this somewhere in the startup routines:
int
main ()
{
initialize_my_lang_runtime ();
mylang_entry_point ();
}
In gcc the call is emitted in:
void
expand_main_function (void)
{
#if (defined(INVOKE__main) \
|| (!defined(HAS_INIT_SECTION) \
&& !defined(INIT_SECTION_ASM_OP) \
&& !defined(INIT_ARRAY_SECTION_ASM_OP)))
emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
#endif
}
And that is called like so:
/* If this function is `main', emit a call to `__main'
to run global initializers, etc. */
if (DECL_NAME (current_function_decl)
&& MAIN_NAME_P (DECL_NAME (current_function_decl))
&& DECL_FILE_SCOPE_P (current_function_decl))
expand_main_function ();
#define MAIN_NAME_P(NODE) \
(IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node)
#define main_identifier_node global_trees[TI_MAIN_IDENTIFIER]
I can only find C variants and ADA setting main_identifier_node,
and it's always on "main". So, the ADA case alone invalidates usage
of main_name in this case.
ada/utils.c:763: main_identifier_node = get_identifier ("main");
c-common.c:3912: main_identifier_node = get_identifier ("main");
gdb/ada-lang.c:
/* The name of the symbol to use to get the name of the main subprogram. */
static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[]
= "__gnat_ada_main_program_name";
> Pierre Muller
> Pascal language support maintainer for GDB
>
>
> 2008-05-02 Pedro Alves <pedro_alves@portugalmail.pt>
> Pierre Muller <muller@ics.u-strasbg.fr>
>
> * gdbarch.sh (gdbarch_skip_main_constructor_call): New.
> * gdbarch.h, gdbarch.c: Regenerate.
>
> * i386-tdep.h (i386_skip_main_constructor_call): Declare.
> * i386-tdep.c (i386_skip_main_constructor_call): New.
> * i386-cygwin-tdep.c (i386_cygwin_init_abi): Register
> i386_skip_main_constructor_call as
> gdbarch_skip_main_constructor_call
> gdbarch callback.
> * symtab.c (find_function_start_sal): When pc points at the "main"
> function, call gdbarch_skip_main_constructor_call.
>
> Index: gdb/gdbarch.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbarch.c,v
> retrieving revision 1.422
> diff -u -p -r1.422 gdbarch.c
> --- gdb/gdbarch.c 22 Apr 2008 11:03:41 -0000 1.422
> +++ gdb/gdbarch.c 30 Apr 2008 13:01:33 -0000
> @@ -184,6 +184,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_constructor_call_ftype *skip_main_constructor_call;
> gdbarch_inner_than_ftype *inner_than;
> gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
> gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
> @@ -306,6 +307,7 @@ struct gdbarch startup_gdbarch =
> 0, /* integer_to_address */
> 0, /* return_value */
> 0, /* skip_prologue */
> + 0, /* skip_main_constructor_call */
> 0, /* inner_than */
> 0, /* breakpoint_from_pc */
> 0, /* adjust_breakpoint_address */
> @@ -542,6 +544,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_constructor_call, has predicate */
> if (gdbarch->inner_than == 0)
> fprintf_unfiltered (log, "\n\tinner_than");
> if (gdbarch->breakpoint_from_pc == 0)
> @@ -934,6 +937,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_constructor_call_p() = %d\n",
> + gdbarch_skip_main_constructor_call_p (gdbarch));
> + fprintf_unfiltered (file,
> + "gdbarch_dump: skip_main_constructor_call =
> <0x%lx>\n",
> + (long) gdbarch->skip_main_constructor_call);
> + fprintf_unfiltered (file,
> "gdbarch_dump: gdbarch_skip_permanent_breakpoint_p()
> = %d\n",
> gdbarch_skip_permanent_breakpoint_p (gdbarch));
> fprintf_unfiltered (file,
> @@ -2075,6 +2084,30 @@ set_gdbarch_skip_prologue (struct gdbarc
> }
>
> int
> +gdbarch_skip_main_constructor_call_p (struct gdbarch *gdbarch)
> +{
> + gdb_assert (gdbarch != NULL);
> + return gdbarch->skip_main_constructor_call != NULL;
> +}
> +
> +CORE_ADDR
> +gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch, CORE_ADDR ip)
> +{
> + gdb_assert (gdbarch != NULL);
> + gdb_assert (gdbarch->skip_main_constructor_call != NULL);
> + if (gdbarch_debug >= 2)
> + fprintf_unfiltered (gdb_stdlog, "gdbarch_skip_main_constructor_call
> called\n");
> + return gdbarch->skip_main_constructor_call (gdbarch, ip);
> +}
> +
> +void
> +set_gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch,
> + gdbarch_skip_main_constructor_call_ftype
> skip_main_constructor_call)
> +{
> + gdbarch->skip_main_constructor_call = skip_main_constructor_call;
> +}
> +
> +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.377
> diff -u -p -r1.377 gdbarch.h
> --- gdb/gdbarch.h 29 Apr 2008 16:06:07 -0000 1.377
> +++ gdb/gdbarch.h 30 Apr 2008 13:01:33 -0000
> @@ -381,6 +381,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_constructor_call_p (struct gdbarch *gdbarch);
> +
> +typedef CORE_ADDR (gdbarch_skip_main_constructor_call_ftype) (struct
> gdbarch *gdbarch, CORE_ADDR ip);
> +extern CORE_ADDR gdbarch_skip_main_constructor_call (struct gdbarch
> *gdbarch, CORE_ADDR ip);
> +extern void set_gdbarch_skip_main_constructor_call (struct gdbarch
> *gdbarch, gdbarch_skip_main_constructor_call_ftype
> *skip_main_constructor_call);
> +
> 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.463
> diff -u -p -r1.463 gdbarch.sh
> --- gdb/gdbarch.sh 29 Apr 2008 16:06:06 -0000 1.463
> +++ gdb/gdbarch.sh 30 Apr 2008 13:01:34 -0000
> @@ -483,6 +483,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_constructor_call: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 30 Apr 2008 13:01:34 -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_constructor_call (gdbarch,
> i386_skip_main_constructor_call);
> +
> 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.255
> diff -u -p -r1.255 i386-tdep.c
> --- gdb/i386-tdep.c 25 Apr 2008 14:57:30 -0000 1.255
> +++ gdb/i386-tdep.c 30 Apr 2008 13:01:35 -0000
> @@ -941,6 +941,33 @@ 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_constructor_call (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)
> + {
> + CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
> +
> + struct minimal_symbol *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.53
> diff -u -p -r1.53 i386-tdep.h
> --- gdb/i386-tdep.h 11 Mar 2008 05:21:38 -0000 1.53
> +++ gdb/i386-tdep.h 30 Apr 2008 13:01:35 -0000
> @@ -166,6 +166,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_constructor_call (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.177
> diff -u -p -r1.177 symtab.c
> --- gdb/symtab.c 19 Apr 2008 11:39:50 -0000 1.177
> +++ gdb/symtab.c 30 Apr 2008 13:01:36 -0000
> @@ -2572,6 +2572,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_constructor_call_p (current_gdbarch)
> + && SYMBOL_LINKAGE_NAME (sym)
> + && strcmp (SYMBOL_LINKAGE_NAME (sym), "main") == 0)
> + {
> + pc = gdbarch_skip_main_constructor_call (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;
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING2] : [RFC/RFA] PING: skip __main
2008-05-02 13:26 [RFC/RFA] PING: skip __main Pierre Muller
2008-05-04 19:57 ` Pedro Alves
@ 2008-05-30 15:56 ` Pierre Muller
2008-05-30 17:04 ` Mark Kettenis
1 sibling, 1 reply; 16+ messages in thread
From: Pierre Muller @ 2008-05-30 15:56 UTC (permalink / raw)
To: 'Pierre Muller', 'Pedro Alves',
'Daniel Jacobowitz',
gdb-patches
Cc: 'Mark Kettenis'
Hi, is there any chance that someone will have
the time to review this patch?
Pierre Muller
Pascal language support maintainer for GDB
-----Message d'origine-----
De : gdb-patches-owner@sourceware.org
[mailto:gdb-patches-owner@sourceware.org] De la part de Pierre Muller
Envoyé : Friday, May 02, 2008 3:26 PM
À : 'Pedro Alves'; 'Daniel Jacobowitz'; gdb-patches@sourceware.org
Cc : 'Mark Kettenis'
Objet : [RFC/RFA] PING: skip __main
Pedro submitted this patch end of January,
but the 6.8 release pushed it to a later date.
http://sourceware.org/ml/gdb-patches/2008-01/msg00665.html
Now that GDB 6.8 is out,
I would really like to get this patch in.
Pedro, this is your work, but you seem to be
much more involved in other things lately,
thus, if you don't mind, I can try to push this through.
I updated the patch from the first message
referenced and just followed Daniel's advice in
http://sourceware.org/ml/gdb-patches/2008-01/msg00883.html
to change skip___main into skip_main_constructor.
This __main call seems to be
a common feature for coff format, thus
I suppose that it applies to other targets,
go32v2 djgpp is probably one of them.
For cygwin target, I get this:
=== gdb Summary ===
-# of expected passes 10733
-# of unexpected failures 560
+# of expected passes 10928
+# of unexpected failures 363
# of expected failures 59
# of unknown successes 2
-# of known failures 21
+# of known failures 23
# of unresolved testcases 40
# of untested testcases 14
# of unsupported tests 23
Almost 200 failures less...
Daniel wanted to get a comment from Mark
in his last email in that thread, that is the reason
why I added Mark Kettenis to the list of recipients.
Does this patch look OK now?
One point that should still be discussed is
if we should call main_name function
rather than hardcoded "main" in find_function_start_sal in symtab.c.
Pierre Muller
Pascal language support maintainer for GDB
2008-05-02 Pedro Alves <pedro_alves@portugalmail.pt>
Pierre Muller <muller@ics.u-strasbg.fr>
* gdbarch.sh (gdbarch_skip_main_constructor_call): New.
* gdbarch.h, gdbarch.c: Regenerate.
* i386-tdep.h (i386_skip_main_constructor_call): Declare.
* i386-tdep.c (i386_skip_main_constructor_call): New.
* i386-cygwin-tdep.c (i386_cygwin_init_abi): Register
i386_skip_main_constructor_call as
gdbarch_skip_main_constructor_call
gdbarch callback.
* symtab.c (find_function_start_sal): When pc points at the "main"
function, call gdbarch_skip_main_constructor_call.
Index: gdb/gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.422
diff -u -p -r1.422 gdbarch.c
--- gdb/gdbarch.c 22 Apr 2008 11:03:41 -0000 1.422
+++ gdb/gdbarch.c 30 Apr 2008 13:01:33 -0000
@@ -184,6 +184,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_constructor_call_ftype *skip_main_constructor_call;
gdbarch_inner_than_ftype *inner_than;
gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
@@ -306,6 +307,7 @@ struct gdbarch startup_gdbarch =
0, /* integer_to_address */
0, /* return_value */
0, /* skip_prologue */
+ 0, /* skip_main_constructor_call */
0, /* inner_than */
0, /* breakpoint_from_pc */
0, /* adjust_breakpoint_address */
@@ -542,6 +544,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_constructor_call, has predicate */
if (gdbarch->inner_than == 0)
fprintf_unfiltered (log, "\n\tinner_than");
if (gdbarch->breakpoint_from_pc == 0)
@@ -934,6 +937,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_constructor_call_p()
= %d\n",
+ gdbarch_skip_main_constructor_call_p (gdbarch));
+ fprintf_unfiltered (file,
+ "gdbarch_dump: skip_main_constructor_call =
<0x%lx>\n",
+ (long) gdbarch->skip_main_constructor_call);
+ fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_skip_permanent_breakpoint_p()
= %d\n",
gdbarch_skip_permanent_breakpoint_p (gdbarch));
fprintf_unfiltered (file,
@@ -2075,6 +2084,30 @@ set_gdbarch_skip_prologue (struct gdbarc
}
int
+gdbarch_skip_main_constructor_call_p (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ return gdbarch->skip_main_constructor_call != NULL;
+}
+
+CORE_ADDR
+gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch, CORE_ADDR ip)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->skip_main_constructor_call != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_skip_main_constructor_call
called\n");
+ return gdbarch->skip_main_constructor_call (gdbarch, ip);
+}
+
+void
+set_gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch,
+ gdbarch_skip_main_constructor_call_ftype
skip_main_constructor_call)
+{
+ gdbarch->skip_main_constructor_call = skip_main_constructor_call;
+}
+
+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.377
diff -u -p -r1.377 gdbarch.h
--- gdb/gdbarch.h 29 Apr 2008 16:06:07 -0000 1.377
+++ gdb/gdbarch.h 30 Apr 2008 13:01:33 -0000
@@ -381,6 +381,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_constructor_call_p (struct gdbarch *gdbarch);
+
+typedef CORE_ADDR (gdbarch_skip_main_constructor_call_ftype) (struct
gdbarch *gdbarch, CORE_ADDR ip);
+extern CORE_ADDR gdbarch_skip_main_constructor_call (struct gdbarch
*gdbarch, CORE_ADDR ip);
+extern void set_gdbarch_skip_main_constructor_call (struct gdbarch
*gdbarch, gdbarch_skip_main_constructor_call_ftype
*skip_main_constructor_call);
+
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.463
diff -u -p -r1.463 gdbarch.sh
--- gdb/gdbarch.sh 29 Apr 2008 16:06:06 -0000 1.463
+++ gdb/gdbarch.sh 30 Apr 2008 13:01:34 -0000
@@ -483,6 +483,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_constructor_call: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 30 Apr 2008 13:01:34 -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_constructor_call (gdbarch,
i386_skip_main_constructor_call);
+
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.255
diff -u -p -r1.255 i386-tdep.c
--- gdb/i386-tdep.c 25 Apr 2008 14:57:30 -0000 1.255
+++ gdb/i386-tdep.c 30 Apr 2008 13:01:35 -0000
@@ -941,6 +941,33 @@ 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_constructor_call (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)
+ {
+ CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
+
+ struct minimal_symbol *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.53
diff -u -p -r1.53 i386-tdep.h
--- gdb/i386-tdep.h 11 Mar 2008 05:21:38 -0000 1.53
+++ gdb/i386-tdep.h 30 Apr 2008 13:01:35 -0000
@@ -166,6 +166,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_constructor_call (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.177
diff -u -p -r1.177 symtab.c
--- gdb/symtab.c 19 Apr 2008 11:39:50 -0000 1.177
+++ gdb/symtab.c 30 Apr 2008 13:01:36 -0000
@@ -2572,6 +2572,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_constructor_call_p (current_gdbarch)
+ && SYMBOL_LINKAGE_NAME (sym)
+ && strcmp (SYMBOL_LINKAGE_NAME (sym), "main") == 0)
+ {
+ pc = gdbarch_skip_main_constructor_call (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;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 15:56 ` [PING2] : " Pierre Muller
@ 2008-05-30 17:04 ` Mark Kettenis
2008-05-30 18:18 ` Pierre Muller
0 siblings, 1 reply; 16+ messages in thread
From: Mark Kettenis @ 2008-05-30 17:04 UTC (permalink / raw)
To: muller; +Cc: muller, pedro, drow, gdb-patches, mark.kettenis
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Fri, 30 May 2008 13:18:20 +0200
>
> Hi, is there any chance that someone will have
> the time to review this patch?
I'm afraid I think that skip_main_constructor_call is too long as a name.
I'd also appreciate it if you could seperate local variable
declarations from the stations that follow by a blank line. Otherwise
this looks ok to me.
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org
> [mailto:gdb-patches-owner@sourceware.org] De la part de Pierre Muller
> Envoyé : Friday, May 02, 2008 3:26 PM
> ÃÂ : 'Pedro Alves'; 'Daniel Jacobowitz'; gdb-patches@sourceware.org
> Cc : 'Mark Kettenis'
> Objet : [RFC/RFA] PING: skip __main
>
> Pedro submitted this patch end of January,
> but the 6.8 release pushed it to a later date.
> http://sourceware.org/ml/gdb-patches/2008-01/msg00665.html
>
> Now that GDB 6.8 is out,
> I would really like to get this patch in.
> Pedro, this is your work, but you seem to be
> much more involved in other things lately,
> thus, if you don't mind, I can try to push this through.
>
> I updated the patch from the first message
> referenced and just followed Daniel's advice in
> http://sourceware.org/ml/gdb-patches/2008-01/msg00883.html
> to change skip___main into skip_main_constructor.
>
> This __main call seems to be
> a common feature for coff format, thus
> I suppose that it applies to other targets,
> go32v2 djgpp is probably one of them.
>
> For cygwin target, I get this:
>
> === gdb Summary ===
>
> -# of expected passes 10733
> -# of unexpected failures 560
> +# of expected passes 10928
> +# of unexpected failures 363
> # of expected failures 59
> # of unknown successes 2
> -# of known failures 21
> +# of known failures 23
> # of unresolved testcases 40
> # of untested testcases 14
> # of unsupported tests 23
>
> Almost 200 failures less...
>
> Daniel wanted to get a comment from Mark
> in his last email in that thread, that is the reason
> why I added Mark Kettenis to the list of recipients.
>
> Does this patch look OK now?
>
> One point that should still be discussed is
> if we should call main_name function
> rather than hardcoded "main" in find_function_start_sal in symtab.c.
>
> Pierre Muller
> Pascal language support maintainer for GDB
>
>
> 2008-05-02 Pedro Alves <pedro_alves@portugalmail.pt>
> Pierre Muller <muller@ics.u-strasbg.fr>
>
> * gdbarch.sh (gdbarch_skip_main_constructor_call): New.
> * gdbarch.h, gdbarch.c: Regenerate.
>
> * i386-tdep.h (i386_skip_main_constructor_call): Declare.
> * i386-tdep.c (i386_skip_main_constructor_call): New.
> * i386-cygwin-tdep.c (i386_cygwin_init_abi): Register
> i386_skip_main_constructor_call as
> gdbarch_skip_main_constructor_call
> gdbarch callback.
> * symtab.c (find_function_start_sal): When pc points at the "main"
> function, call gdbarch_skip_main_constructor_call.
>
> Index: gdb/gdbarch.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbarch.c,v
> retrieving revision 1.422
> diff -u -p -r1.422 gdbarch.c
> --- gdb/gdbarch.c 22 Apr 2008 11:03:41 -0000 1.422
> +++ gdb/gdbarch.c 30 Apr 2008 13:01:33 -0000
> @@ -184,6 +184,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_constructor_call_ftype *skip_main_constructor_call;
> gdbarch_inner_than_ftype *inner_than;
> gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
> gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
> @@ -306,6 +307,7 @@ struct gdbarch startup_gdbarch =
> 0, /* integer_to_address */
> 0, /* return_value */
> 0, /* skip_prologue */
> + 0, /* skip_main_constructor_call */
> 0, /* inner_than */
> 0, /* breakpoint_from_pc */
> 0, /* adjust_breakpoint_address */
> @@ -542,6 +544,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_constructor_call, has predicate */
> if (gdbarch->inner_than == 0)
> fprintf_unfiltered (log, "\n\tinner_than");
> if (gdbarch->breakpoint_from_pc == 0)
> @@ -934,6 +937,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_constructor_call_p()
> = %d\n",
> + gdbarch_skip_main_constructor_call_p (gdbarch));
> + fprintf_unfiltered (file,
> + "gdbarch_dump: skip_main_constructor_call =
> <0x%lx>\n",
> + (long) gdbarch->skip_main_constructor_call);
> + fprintf_unfiltered (file,
> "gdbarch_dump: gdbarch_skip_permanent_breakpoint_p()
> = %d\n",
> gdbarch_skip_permanent_breakpoint_p (gdbarch));
> fprintf_unfiltered (file,
> @@ -2075,6 +2084,30 @@ set_gdbarch_skip_prologue (struct gdbarc
> }
>
> int
> +gdbarch_skip_main_constructor_call_p (struct gdbarch *gdbarch)
> +{
> + gdb_assert (gdbarch != NULL);
> + return gdbarch->skip_main_constructor_call != NULL;
> +}
> +
> +CORE_ADDR
> +gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch, CORE_ADDR ip)
> +{
> + gdb_assert (gdbarch != NULL);
> + gdb_assert (gdbarch->skip_main_constructor_call != NULL);
> + if (gdbarch_debug >= 2)
> + fprintf_unfiltered (gdb_stdlog, "gdbarch_skip_main_constructor_call
> called\n");
> + return gdbarch->skip_main_constructor_call (gdbarch, ip);
> +}
> +
> +void
> +set_gdbarch_skip_main_constructor_call (struct gdbarch *gdbarch,
> + gdbarch_skip_main_constructor_call_ftype
> skip_main_constructor_call)
> +{
> + gdbarch->skip_main_constructor_call = skip_main_constructor_call;
> +}
> +
> +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.377
> diff -u -p -r1.377 gdbarch.h
> --- gdb/gdbarch.h 29 Apr 2008 16:06:07 -0000 1.377
> +++ gdb/gdbarch.h 30 Apr 2008 13:01:33 -0000
> @@ -381,6 +381,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_constructor_call_p (struct gdbarch *gdbarch);
> +
> +typedef CORE_ADDR (gdbarch_skip_main_constructor_call_ftype) (struct
> gdbarch *gdbarch, CORE_ADDR ip);
> +extern CORE_ADDR gdbarch_skip_main_constructor_call (struct gdbarch
> *gdbarch, CORE_ADDR ip);
> +extern void set_gdbarch_skip_main_constructor_call (struct gdbarch
> *gdbarch, gdbarch_skip_main_constructor_call_ftype
> *skip_main_constructor_call);
> +
> 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.463
> diff -u -p -r1.463 gdbarch.sh
> --- gdb/gdbarch.sh 29 Apr 2008 16:06:06 -0000 1.463
> +++ gdb/gdbarch.sh 30 Apr 2008 13:01:34 -0000
> @@ -483,6 +483,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_constructor_call: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 30 Apr 2008 13:01:34 -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_constructor_call (gdbarch,
> i386_skip_main_constructor_call);
> +
> 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.255
> diff -u -p -r1.255 i386-tdep.c
> --- gdb/i386-tdep.c 25 Apr 2008 14:57:30 -0000 1.255
> +++ gdb/i386-tdep.c 30 Apr 2008 13:01:35 -0000
> @@ -941,6 +941,33 @@ 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_constructor_call (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)
> + {
> + CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
> +
> + struct minimal_symbol *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.53
> diff -u -p -r1.53 i386-tdep.h
> --- gdb/i386-tdep.h 11 Mar 2008 05:21:38 -0000 1.53
> +++ gdb/i386-tdep.h 30 Apr 2008 13:01:35 -0000
> @@ -166,6 +166,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_constructor_call (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.177
> diff -u -p -r1.177 symtab.c
> --- gdb/symtab.c 19 Apr 2008 11:39:50 -0000 1.177
> +++ gdb/symtab.c 30 Apr 2008 13:01:36 -0000
> @@ -2572,6 +2572,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_constructor_call_p (current_gdbarch)
> + && SYMBOL_LINKAGE_NAME (sym)
> + && strcmp (SYMBOL_LINKAGE_NAME (sym), "main") == 0)
> + {
> + pc = gdbarch_skip_main_constructor_call (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;
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 17:04 ` Mark Kettenis
@ 2008-05-30 18:18 ` Pierre Muller
2008-05-30 18:45 ` Pierre Muller
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Pierre Muller @ 2008-05-30 18:18 UTC (permalink / raw)
To: 'Mark Kettenis'; +Cc: pedro, drow, gdb-patches
Thanks for the fast reply.
> I'm afraid I think that skip_main_constructor_call is too long as a name.
I am perfectly willing to use something shorter,
the only problem is to find something that would still be
of clear meaning.
maybe
skip_main_prologue
would be better?
> I'd also appreciate it if you could seperate local variable
> declarations from the stations that follow by a blank line. Otherwise
> this looks ok to me.
Does this apply to both uninitialized and initialized variables?
Would the code hereafter be correct, or did I add too many empty lines?
+/* 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_constructor_call (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)
+ {
+ CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
+
+ struct minimal_symbol *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;
+}
+
Thanks again for the reply.
Pierre Muller
Pascal language support maintainer for GDB
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 18:18 ` Pierre Muller
@ 2008-05-30 18:45 ` Pierre Muller
2008-05-30 20:23 ` Mark Kettenis
2008-05-31 16:06 ` [PING2] : [RFC/RFA] PING: skip __main Daniel Jacobowitz
2008-05-31 23:40 ` Mark Kettenis
2 siblings, 1 reply; 16+ messages in thread
From: Pierre Muller @ 2008-05-30 18:45 UTC (permalink / raw)
To: 'Mark Kettenis'; +Cc: pedro, drow, gdb-patches
+ target_read_memory (pc, &op, 1);
+ if (op == 0xe8)
+ {
+ gdb_byte buf[4];
+
+ if (target_read_memory (pc + 1, buf, sizeof buf) == 0)
+ {
+ CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
Just one small question about this line:
I fear that this line is incorrect,
shouldn't we use extract_signed_integer here?
The address is relative to pc+5 meaning that
if main is at a higher address than __main,
buf will contain a negative 4byte integer.
This will usually not matter (if overflows are allowed),
unless CORE_ADDR is 8-byte long,
which would then give a value above 0xffffffff.
This can happen for cross configured gdb, but also if gdb is configured
with --enable-64bit-bfd.
I don't even know if these result would be always correct
(assuming for instance that main is below __main, but that
__main resides above 0x80000000 boundary for example).
Maybe the only correct way is to force the operation to be performed
with 4-byte integers and take the result, even if overflow
occurred.
Pierre Muller
Pascal language support maintainer for GDB
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 18:45 ` Pierre Muller
@ 2008-05-30 20:23 ` Mark Kettenis
2008-05-31 2:30 ` Pierre Muller
[not found] ` <000301c8c2ea$0c2d72a0$248857e0$@u-strasbg.fr>
0 siblings, 2 replies; 16+ messages in thread
From: Mark Kettenis @ 2008-05-30 20:23 UTC (permalink / raw)
To: muller; +Cc: pedro, drow, gdb-patches
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Fri, 30 May 2008 16:46:28 +0200
>
> + target_read_memory (pc, &op, 1);
> + if (op == 0xe8)
> + {
> + gdb_byte buf[4];
> +
> + if (target_read_memory (pc + 1, buf, sizeof buf) == 0)
> + {
> + CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
> Just one small question about this line:
> I fear that this line is incorrect,
> shouldn't we use extract_signed_integer here?
>
> The address is relative to pc+5 meaning that
> if main is at a higher address than __main,
> buf will contain a negative 4byte integer.
You're absolutely right. Can you make that change and retest?
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 20:23 ` Mark Kettenis
@ 2008-05-31 2:30 ` Pierre Muller
[not found] ` <000301c8c2ea$0c2d72a0$248857e0$@u-strasbg.fr>
1 sibling, 0 replies; 16+ messages in thread
From: Pierre Muller @ 2008-05-31 2:30 UTC (permalink / raw)
To: 'Mark Kettenis'; +Cc: gdb-patches, pedro, drow
I restarted a testsuite, but I
won't expect any change because
main seems to be at a lower address than __main
in the few executables I tested, meaning that
the value in buf will be positive anyhow.
Pierre Muller
Pascal language support maintainer for GDB
-----Message d'origine-----
De : gdb-patches-owner@sourceware.org
[mailto:gdb-patches-owner@sourceware.org] De la part de Mark Kettenis
Envoyé : Friday, May 30, 2008 4:58 PM
À : muller@ics.u-strasbg.fr
Cc : pedro@codesourcery.com; drow@false.org; gdb-patches@sourceware.org
Objet : Re: [PING2] : [RFC/RFA] PING: skip __main
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Fri, 30 May 2008 16:46:28 +0200
>
> + target_read_memory (pc, &op, 1);
> + if (op == 0xe8)
> + {
> + gdb_byte buf[4];
> +
> + if (target_read_memory (pc + 1, buf, sizeof buf) == 0)
> + {
> + CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf,
4);
> Just one small question about this line:
> I fear that this line is incorrect,
> shouldn't we use extract_signed_integer here?
>
> The address is relative to pc+5 meaning that
> if main is at a higher address than __main,
> buf will contain a negative 4byte integer.
You're absolutely right. Can you make that change and retest?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 18:18 ` Pierre Muller
2008-05-30 18:45 ` Pierre Muller
@ 2008-05-31 16:06 ` Daniel Jacobowitz
2008-05-31 23:40 ` Mark Kettenis
2 siblings, 0 replies; 16+ messages in thread
From: Daniel Jacobowitz @ 2008-05-31 16:06 UTC (permalink / raw)
To: Pierre Muller; +Cc: 'Mark Kettenis', pedro, gdb-patches
On Fri, May 30, 2008 at 03:06:51PM +0200, Pierre Muller wrote:
> Thanks for the fast reply.
>
> > I'm afraid I think that skip_main_constructor_call is too long as a name.
>
> I am perfectly willing to use something shorter,
> the only problem is to find something that would still be
> of clear meaning.
>
> maybe
> skip_main_prologue
> would be better?
Just skip_main_constructor?
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
2008-05-30 18:18 ` Pierre Muller
2008-05-30 18:45 ` Pierre Muller
2008-05-31 16:06 ` [PING2] : [RFC/RFA] PING: skip __main Daniel Jacobowitz
@ 2008-05-31 23:40 ` Mark Kettenis
2 siblings, 0 replies; 16+ messages in thread
From: Mark Kettenis @ 2008-05-31 23:40 UTC (permalink / raw)
To: muller; +Cc: pedro, drow, gdb-patches
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Fri, 30 May 2008 15:06:51 +0200
>
> > I'm afraid I think that skip_main_constructor_call is too long as a name.
>
> I am perfectly willing to use something shorter,
> the only problem is to find something that would still be
> of clear meaning.
>
> maybe
> skip_main_prologue
> would be better?
Actually, I think it is. The functionality can be used for other
prologue skipping that's not really related to constructors as well.
> > I'd also appreciate it if you could seperate local variable
> > declarations from the stations that follow by a blank line. Otherwise
> > this looks ok to me.
>
> Does this apply to both uninitialized and initialized variables?
>
> Would the code hereafter be correct, or did I add too many empty lines?
Please remove the blank line before the "struct minimal_symbol *s"
declaration.
> +/* 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_constructor_call (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)
> + {
> + CORE_ADDR call_dest = pc + 5 + extract_unsigned_integer (buf, 4);
> +
> + struct minimal_symbol *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;
> +}
> +
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
[not found] ` <000301c8c2ea$0c2d72a0$248857e0$@u-strasbg.fr>
@ 2008-06-05 20:27 ` Daniel Jacobowitz
2008-06-05 20:44 ` Mark Kettenis
0 siblings, 1 reply; 16+ messages in thread
From: Daniel Jacobowitz @ 2008-06-05 20:27 UTC (permalink / raw)
To: Pierre Muller; +Cc: 'Mark Kettenis', pedro, gdb-patches
On Sat, May 31, 2008 at 08:46:25AM +0200, Pierre Muller wrote:
> Should I use the 32bit typecast strategy:
>
> unsigned int32 pc_after = pc + 5;
> unsigned int32 depl = extract_unsigned_integer (buf, 4);
>
> unsigned int32 dest = pc_after - depl;
> pc = dest;
>
> I don't know the checks done in C,
> are there any overflow checks in code like this,
> or is it safe to assume that it will work,
> even on machine that perform their operations
> on more than 32 bits?
If you use uint32_t, then you are guaranteed wrapping at 32 bits.
So that is probably the best thing to do. See the patch I just posted
to make stdint.h available everywhere.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING2] : [RFC/RFA] PING: skip __main
2008-06-05 20:27 ` Daniel Jacobowitz
@ 2008-06-05 20:44 ` Mark Kettenis
2008-06-06 7:18 ` Pierre Muller
0 siblings, 1 reply; 16+ messages in thread
From: Mark Kettenis @ 2008-06-05 20:44 UTC (permalink / raw)
To: drow; +Cc: muller, pedro, gdb-patches
> Date: Thu, 5 Jun 2008 16:26:40 -0400
> From: Daniel Jacobowitz <drow@false.org>
>
> On Sat, May 31, 2008 at 08:46:25AM +0200, Pierre Muller wrote:
> > Should I use the 32bit typecast strategy:
> >
> > unsigned int32 pc_after = pc + 5;
> > unsigned int32 depl = extract_unsigned_integer (buf, 4);
> >
> > unsigned int32 dest = pc_after - depl;
> > pc = dest;
> >
> > I don't know the checks done in C,
> > are there any overflow checks in code like this,
> > or is it safe to assume that it will work,
> > even on machine that perform their operations
> > on more than 32 bits?
>
> If you use uint32_t, then you are guaranteed wrapping at 32 bits.
> So that is probably the best thing to do. See the patch I just posted
> to make stdint.h available everywhere.
The diff should use extract_signed_integer().
I'm not sure if the wrapping is actually necessary. Does the
assembler/linker actually depend on it? Or does it error out on such
large jumps? If so, alternatively you could explicity truncate the
generated address to 32 bits using & 0xffffffffU.
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PING2] : [RFC/RFA] PING: skip __main
2008-06-05 20:44 ` Mark Kettenis
@ 2008-06-06 7:18 ` Pierre Muller
2008-06-07 7:48 ` [RFA] New skip __main version Pierre Muller
0 siblings, 1 reply; 16+ messages in thread
From: Pierre Muller @ 2008-06-06 7:18 UTC (permalink / raw)
To: 'Mark Kettenis', drow; +Cc: pedro, gdb-patches
I am not sure I understand your question about
assembler or linker, but
for sure if we call lookup_minimal_symbol_by_pc with
a CORE_ADDR outside the 0 to 0xffffffff range,
it might fail to find the right location
(although I must admit that I didn't try to look inside that
code to see if there is a bit truncation there)
Anyhow, using extract_signed_integer followed by
a "& 0xffffffffU", we should be on the safe side.
I will rerun a test a resubmit a modified patch after.
Pierre Muller
Pascal language support maintainer for GDB
-----Message d'origine-----
De : Mark Kettenis [mailto:mark.kettenis@xs4all.nl]
Envoyé : Thursday, June 05, 2008 10:42 PM
À : drow@false.org
Cc : muller@ics.u-strasbg.fr; pedro@codesourcery.com;
gdb-patches@sourceware.org
Objet : Re: [PING2] : [RFC/RFA] PING: skip __main
> Date: Thu, 5 Jun 2008 16:26:40 -0400
> From: Daniel Jacobowitz <drow@false.org>
>
> On Sat, May 31, 2008 at 08:46:25AM +0200, Pierre Muller wrote:
> > Should I use the 32bit typecast strategy:
> >
> > unsigned int32 pc_after = pc + 5;
> > unsigned int32 depl = extract_unsigned_integer (buf, 4);
> >
> > unsigned int32 dest = pc_after - depl;
> > pc = dest;
> >
> > I don't know the checks done in C,
> > are there any overflow checks in code like this,
> > or is it safe to assume that it will work,
> > even on machine that perform their operations
> > on more than 32 bits?
>
> If you use uint32_t, then you are guaranteed wrapping at 32 bits.
> So that is probably the best thing to do. See the patch I just posted
> to make stdint.h available everywhere.
The diff should use extract_signed_integer().
I'm not sure if the wrapping is actually necessary. Does the
assembler/linker actually depend on it? Or does it error out on such
large jumps? If so, alternatively you could explicity truncate the
generated address to 32 bits using & 0xffffffffU.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [RFA] New skip __main version
2008-06-06 7:18 ` Pierre Muller
@ 2008-06-07 7:48 ` Pierre Muller
2008-06-10 17:56 ` Mark Kettenis
0 siblings, 1 reply; 16+ messages in thread
From: Pierre Muller @ 2008-06-07 7:48 UTC (permalink / raw)
To: pedro, gdb-patches, 'Mark Kettenis', drow
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 <pedro_alves@portugalmail.pt>
Pierre Muller <muller@ics.u-strasbg.fr>
* 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;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFA] New skip __main version
2008-06-07 7:48 ` [RFA] New skip __main version Pierre Muller
@ 2008-06-10 17:56 ` Mark Kettenis
2008-06-11 23:18 ` Pierre Muller
0 siblings, 1 reply; 16+ messages in thread
From: Mark Kettenis @ 2008-06-10 17:56 UTC (permalink / raw)
To: muller; +Cc: pedro, gdb-patches, drow
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Sat, 7 Jun 2008 09:48:15 +0200
>
> Here is a new version of this patch:
Looks ok to me.
> ChangeLog entry:
>
> 2008-06-07 Pedro Alves <pedro_alves@portugalmail.pt>
> Pierre Muller <muller@ics.u-strasbg.fr>
>
> * 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.
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [RFA] New skip __main version
2008-06-10 17:56 ` Mark Kettenis
@ 2008-06-11 23:18 ` Pierre Muller
0 siblings, 0 replies; 16+ messages in thread
From: Pierre Muller @ 2008-06-11 23:18 UTC (permalink / raw)
To: 'Mark Kettenis'; +Cc: pedro, gdb-patches, drow
I took the liberty to interpret this answer from Mark
as an approval and committed this patch.
Thanks to all,
Pierre Muller
Pascal language support maintainer for GDB
-----Message d'origine-----
De : gdb-patches-owner@sourceware.org
[mailto:gdb-patches-owner@sourceware.org] De la part de Mark Kettenis
Envoyé : Tuesday, June 10, 2008 3:49 PM
À : muller@ics.u-strasbg.fr
Cc : pedro@codesourcery.com; gdb-patches@sourceware.org; drow@false.org
Objet : Re: [RFA] New skip __main version
> From: "Pierre Muller" <muller@ics.u-strasbg.fr>
> Date: Sat, 7 Jun 2008 09:48:15 +0200
>
> Here is a new version of this patch:
Looks ok to me.
> ChangeLog entry:
>
> 2008-06-07 Pedro Alves <pedro_alves@portugalmail.pt>
> Pierre Muller <muller@ics.u-strasbg.fr>
>
> * 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.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2008-06-11 22:36 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-02 13:26 [RFC/RFA] PING: skip __main Pierre Muller
2008-05-04 19:57 ` Pedro Alves
2008-05-30 15:56 ` [PING2] : " Pierre Muller
2008-05-30 17:04 ` Mark Kettenis
2008-05-30 18:18 ` Pierre Muller
2008-05-30 18:45 ` Pierre Muller
2008-05-30 20:23 ` Mark Kettenis
2008-05-31 2:30 ` Pierre Muller
[not found] ` <000301c8c2ea$0c2d72a0$248857e0$@u-strasbg.fr>
2008-06-05 20:27 ` Daniel Jacobowitz
2008-06-05 20:44 ` Mark Kettenis
2008-06-06 7:18 ` Pierre Muller
2008-06-07 7:48 ` [RFA] New skip __main version Pierre Muller
2008-06-10 17:56 ` Mark Kettenis
2008-06-11 23:18 ` Pierre Muller
2008-05-31 16:06 ` [PING2] : [RFC/RFA] PING: skip __main Daniel Jacobowitz
2008-05-31 23:40 ` Mark Kettenis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox