This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: [PATCH] Fix for incorect breakpoint set in case of clang compiled binary


Thanks Pedro/Mark. Appologies for the build break. I'm a bit new to GDB community will take care of it from next time.
I have fixed the warning resulting in error and modified the indentation -
Let me also try to explain the fix a bit more. 

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.14849
diff -u -p -r1.14849 ChangeLog
--- ChangeLog	21 Nov 2012 14:09:03 -0000	1.14849
+++ ChangeLog	21 Nov 2012 15:11:47 -0000
@@ -1,3 +1,9 @@
+2012-11-20  Karthik Bhat  <kv.bhat@samsung.com>
+
+	* i386-tdep.c (i386_skip_prologue): See if we
+	can determine the end of the prologue via the symbol table.
+	If so use the same instead of going through prologue instructions.
+
 2012-11-21  Yao Qi  <yao@codesourcery.com>
 
 	PR tdep/7438
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.364
diff -u -p -r1.364 i386-tdep.c
--- i386-tdep.c	21 Nov 2012 14:09:10 -0000	1.364
+++ i386-tdep.c	21 Nov 2012 15:11:48 -0000
@@ -1582,6 +1582,27 @@ i386_skip_prologue (struct gdbarch *gdba
   CORE_ADDR pc;
   gdb_byte op;
   int i;
+  CORE_ADDR func_addr;
+
+  if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
+    {
+      CORE_ADDR post_prologue_pc
+	= skip_prologue_using_sal (gdbarch, func_addr);
+      struct symtab *s = find_pc_symtab (func_addr);
+
+      /* GCC and clang always emits a line note before the prologue and another
+	 one after, even if the two are at the same address or on the
+	 same line.  Take advantage of this so that we do not need to
+	 know every instruction that might appear in the prologue.  We
+	 will have producer information for most binaries; if it is
+	 missing (e.g. for -gstabs), assuming the GNU tools.  */
+      if (post_prologue_pc
+	  && (s == NULL
+	      || s->producer == NULL
+	      || strncmp (s->producer, "GNU ", sizeof ("GNU ") - 1) == 0 
+	      || strncmp (s->producer, "clang ", sizeof ("clang ") - 1) == 0))
+	return max (start_pc, post_prologue_pc);
+    }
 
   cache.locals = -1;
   pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);


I wanted to add this patch in GDB to fix a problem which we are currently facing when we use gdb with binary compiled with clang.
The problem faced is clang generates function prologue which is a bit different from that of GCC as a result when we try to skip prologue instruction by instruction it results in incorrect prologue_end.

There is one more method to skip prologue which is used in other architectures such as ARM(arm-tdep.c), MIPS(mips-tdep.c) etc. In this method we try to determine prologue end via symbol table.
If we are unable to do this we then we examine instruction to determine prologue end.

Added the same for i386. Here we are trying to see if we can resolve prologue end from symbol table. 
This will avoid instruction by instruction examining to determine prologue end if we are able to determine it through symbol table.

Thanks

------- Original Message -------
Sender : Pedro Alves<palves@redhat.com>
Date : Nov 21, 2012 23:10 (GMT+09:00)
Title : Re: [PATCH] Fix for incorect breakpoint set in case of clang compiled binary

On 11/21/2012 01:20 PM, Mark Kettenis wrote:

> Please back it out.

Since this breaking the build I went ahead and reverted it.

-- 
Pedro Alves

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]