summaryrefslogtreecommitdiff
path: root/gdb/i386-tdep.c
diff options
context:
space:
mode:
authorPierre Muller <muller@sourceware.org>2008-06-11 22:03:49 +0000
committerPierre Muller <muller@sourceware.org>2008-06-11 22:03:49 +0000
commit4309257cda01fce18971fd5a5ea28ed6aaf552cc (patch)
tree3207f06e4a8f03ae972c6da4a37a795ec78cfeda /gdb/i386-tdep.c
parenta4e2ee12f0631722c380973c0336dd165fd0137d (diff)
downloadbinutils-gdb-4309257cda01fce18971fd5a5ea28ed6aaf552cc.tar.gz
* 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.
Diffstat (limited to 'gdb/i386-tdep.c')
-rw-r--r--gdb/i386-tdep.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index be4f4f38dfe..91bd7d040b2 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -1160,6 +1160,38 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
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