Bug 14419 - Prologue not set properly for Non-Gcc compilers
Summary: Prologue not set properly for Non-Gcc compilers
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: HEAD
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-30 10:34 UTC by karthik
Modified: 2012-09-26 14:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Sample Code and Logs (65.29 KB, application/x-zip-compressed)
2012-07-30 10:34 UTC, karthik
Details

Note You need to log in before you can comment on or make changes to this bug.
Description karthik 2012-07-30 10:34:49 UTC
Created attachment 6561 [details]
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.
Comment 1 karthik 2012-08-06 05:02:25 UTC
Hi All,
We had a discussion on this issue on Linaro GDB as well. https://bugs.launchpad.net/gdb-linaro/+bug/1030813

As discussed in the link we can extend the arm_skip_prologue function to support clang.

We wanted input from community if we can contribute this patch to GDB trunk?

Awaiting response.
Thanks.
Comment 2 Tom Tromey 2012-08-06 14:15:16 UTC
(In reply to comment #1)

> We wanted input from community if we can contribute this patch to GDB trunk?

Send it to gdb-patches following the contribution guidelines.
Comment 3 karthik 2012-09-26 14:05:26 UTC
A patch for this has been submitted at 
http://sourceware.org/ml/gdb-cvs/2012-09/msg00148.html