Peter,

thanks! That actually pointed me to a good solution.

The issue in that ticket looks like exactly the same problem, and you're 
right, enabling optimization does seem to solve it, though it does of 
course cause other problems.

By looking through the flags O1 turns on, and removing them in bunches, it 
appears actually that just -fomit-frame-pointer is needed to solve the 
problem - no other optimizations necessary!

Even without -fomit-frame-pointer, there doesn't seem to be a problem with 
functions other than main.

Thanks for your help - much appreciated.

Carl


On Thu, 6 Dec 2012, Peter Bigot wrote:

> msp430-gdb is not currently maintained.  There have historically been
> issues getting debug information from the compiler to the debugger
> correctly; currently
> https://sourceforge.net/tracker/?func=detail&aid=3564453&group_id=42303&atid=432701is
> open, but that may not be your problem.  Generally enabling
> optimization
> has eliminated the problem.
>
> Presumably this will not be an issue in the Red Hat replacement of GNU
> toolchain msp430 support.
>
> Peter
>
>
> On Thu, Dec 6, 2012 at 12:59 PM, Carl Michal <mic...@physics.ubc.ca> wrote:
>
>> Hi,
>>
>> I've been looking into this a little further, and it appears to me that
>> the problem is in gcc providing the wrong debug info.
>>
>> readelf -w shows:
>>
>> in .debug_info:
>>
>> <2><45>: Abbrev Number: 4 (DW_TAG_variable)
>>      <46>   DW_AT_name        : a
>>      <48>   DW_AT_decl_file   : 1
>>      <49>   DW_AT_decl_line   : 4
>>      <4a>   DW_AT_type        : <0x8e>
>>      <4e>   DW_AT_location    : 2 byte block: 91 78      (DW_OP_fbreg: -8)
>>
>> and then in .debug_loc:
>>      Offset   Begin    End      Expression
>>      00000000 f83e f840 (DW_OP_breg1 (r1): 0)
>>      00000000 f840 f842 (DW_OP_breg4 (r4): 0)
>>      00000000 f842 f8bc (DW_OP_breg4 (r4): -2)
>>      00000000 <End of list>
>>
>> The 2 byte offset I'm seeing appears to be coming from the last line in
>> .debug_loc. (If I change that -2 to 0 with a hex editor then the debugger
>> finds the variables in the right place).
>>
>> I'm a total newbie to dwarf and gdb internals, but also see that changing
>> the DW_OP_fbreg that describes the variable location to
>> DW_OP_breg4 allows gdb to see the correct value.
>>
>> I see this with all the currently distributed msp430-gcc installs I've
>> found: those currently distributed in Gentoo, Ubuntu 12.10, as well
>> as MacPorts.
>>
>> In an older Ubuntu with
>> gcc version 4.5.3 (GNU GCC patched mspgcc-20110716)
>> the details are different, but the symptoms are similar. With that
>> compilier,
>> readelf shows that variable location as DW_OP_fbreg: -10 (when it should
>> be -8), and .debug_loc shows:
>>
>>     Offset   Begin    End      Expression
>>      00000000 fc38 fc3a (DW_OP_breg1 (r1): 2)
>>      00000000 fc3a fc3c (DW_OP_breg4 (r4): 2)
>>      00000000 fc3c fcb4 (DW_OP_breg4 (r4): 0)
>>      00000000 <End of list>
>>
>> The net result here is the same that the debugger is looking two bytes off
>> of where it should be.
>>
>> Seems like if I could keep the .debug_loc from the old compiler and the
>> .debug_info from the new compiler it would all work...
>>
>> Any help in getting to the bottom of this would be appreciated.
>>
>> Carl
>>
>>
>> On Wed, 5 Dec 2012, Carl Michal wrote:
>>
>>> Hello,
>>>
>>> I've noticed that when debugging programs with gdb on an MSP430 Launchpad
>>> (MSP430G2231), the print command in gdb doesn't work properly for local
>>> variables.  The issue I'm seeing has very similar symptoms to:
>>>
>> http://sourceforge.net/tracker/?func=detail&aid=3417263&group_id=42303&atid=432701
>>> but the mspgcc I'm using appears to be much newer than that.
>>>
>>> If I ask gdb:
>>>>  info address a
>>> it tells me:
>>> Symbol "a" is a variable at frame base reg $r4 offset -2+-8.
>>>
>>> but looking at the assembly code produced with msp-gcc -S, a is always
>>> referenced at -8(r4). The value I get with
>>> (gdb) print a
>>> corresponds to the variable at -10(r4). Doing
>>> (gdb) x/1hd $r4-8
>>>
>>> shows the correct value for a.
>>>
>>> I'm using
>>> gcc version 4.6.3 20120301 (mspgcc LTS 20120406 unpatched) (Gentoo
>>> 4.6.3_p20120406 p1.0)
>>> and
>>> GNU gdb (Gentoo MSP430 7.2_p20111205) 7.2
>>> on Gentoo.
>>>
>>> Carl
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
>> Remotely access PCs and mobile devices and provide instant support
>> Improve your efficiency, and focus on delivering more value-add services
>> Discover what IT Professionals Know. Rescue delivers
>> http://p.sf.net/sfu/logmein_12329d2d
>> _______________________________________________
>> Mspgcc-users mailing list
>> Mspgcc-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>>
>

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to