This is the mail archive of the gdb-prs@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]

[Bug breakpoints/14419] New: Prologue not set properly for Non-Gcccompilers


http://sourceware.org/bugzilla/show_bug.cgi?id=14419

             Bug #: 14419
           Summary: Prologue not set properly for Non-Gcc compilers
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: critical
          Priority: P2
         Component: breakpoints
        AssignedTo: unassigned@sourceware.org
        ReportedBy: kv.bhat@samsung.com
    Classification: Unclassified


Created attachment 6561
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6561
Sample Code and Logs

Dear All,
I'm are trying to use GDB with binary generated from non-Gcc compiler. I'm
using clang 3.1 generated compiling the code from LLVM site
(http://www.llvm.org/)
In this case when we try to set a breakpoint in a function with float/double
arguments GDB is unable to detect the prologue end properly.


Please find the example below-

int floater(float a1)
{
int a = a1;
return a;
}
int main()
{
  int a =  floater(1);
  return 0;
}

The assembly for this code is attached. When we call --
break floater in GDB the breakpoint is getting set at the start of function
instead of 1st executable instruction.

[OUR ANALYSIS]
Upon analysing we found that for non-gcc compilers GDB specifically checks for
prologue sequence with few pre recognized instruction set. 
File:  arm-tdep.c
Function: arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)

In the function arm_skip_prologue GDB calls arm_analyze_prologue which checks
for the prologue sequence with predefined register sets. It seems like not all
instructions possible in prologue is covered by GDB in this function as several
possible prologues can be written, resulting in slightly different stack
configuration.

In the example above we added few logs and extracted the object dump-
GDB Logs-

(gdb) b floater 
post_prologue_pc is 83c4 
analyzed_limit is 83bc 
post_prologue_pc is 83c4 
analyzed_limit is 83bc 

Object Dump -

000083b8 <floater>:
    83b8: e24dd008  sub sp, sp, #8
    83bc: ee000a10  vmov s0, r0
    83c0: e58d0004  str r0, [sp, #4]
    83c4: eebd0ac0  vcvt.s32.f32 s0, s0
    83c8: ed8d0a00  vstr s0, [sp]
    83cc: ee100a10  vmov r0, s0
    83d0: e28dd008  add sp, sp, #8
    83d4: e12fff1e  bx lr

As shown in the snippet above GDB is unable to recognize vmov as a valid
instruction in Prologue and hence the check 

 if (analyzed_limit != post_prologue_pc)   in function arm_skip_prologue
succeeds and func_addr is returned instead of post_prologue_pc resulting in
breakpoint set at the start of function instead of 1st executable instruction.

[FIX AND Query]
I had a query as to if the call to  arm_analyze_prologue is required for
non-GCC compilers. We already have the prologue end location in
post_prologue_pc. Is it not possible to return the same directly?

We modified the code to emit post_prologue_pc irrespective of the return value
of arm_analyze_prologue  as we have already determined the prologue end
properly in post_prologue_pc. After the fix GDB sets breakpoint properly for
non-GCC compilers as well.

Modiffied code -

      if (post_prologue_pc != 0)
 {
    return post_prologue_pc;  // Just return post_prologue_pc .
 }

I would like to get few inputs form you all if we can push this fix into GDB
trunk.

Files and analysis are attached.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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