Bug 5540 - location expression DW_OP_breg is sign extended
Summary: location expression DW_OP_breg is sign extended
Status: SUSPENDED
Alias: None
Product: frysk
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-03 22:31 UTC by Stan Cox
Modified: 2009-06-11 14:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stan Cox 2008-01-03 22:31:24 UTC
There is an intermittent failure caused by the sign extending of DW_OP_breg
values in LocationExpression.java at: long regval = frame.getRegister(register);
The scenario is:
 frysk.stack.Frame.getRegister
 return getRegisterValue(register).asLong()
  frysk.stack.Frame.getRegisterValue
  return new Value(register.getType()
   frysk.value.Value.Value
   where Location might have values such as: -128, 62, -105, -1 
where asLong is:
 frysk.value.Value.asLong
 return 
 ((ArithmeticType)type.getUltimateType()).getBigInteger(location).longValue()
  frysk.value.SignedType.getBigInteger
  return new BigInteger(location.get(order()))

I'm trying to come up with a simple test but here is a small java example
showing what is happening above:

import java.math.BigInteger;
// bigInteger.longValue is -15654349 for bytes = {-1,0x11,0x22,0x33}
// bigInteger.longValue is 4279312947 for bytes = {0,-1,0x11,0x22,0x33}
public class tstbi {
  public static void main(String[] args) {
    BigInteger bigInteger;
    byte [] bytes = {0,-1,0x11,0x22,0x33};
    bigInteger = new BigInteger(bytes);
    System.out.println("bigInteger=" + bigInteger.longValue());
  }
}
Comment 1 Stan Cox 2008-01-03 23:02:07 UTC
(fhpd) print argc          
[0.0]
Error: ptrace: Input/output error (op 0x2 (PTRACE_PEEKDATA), pid 1022, addr
0xffffffffff9f5ea0, data 0x0)
(fhpd) print argc -location
[0.0]
Address 0xffffffffff9f5ea0 - 4 byte(s)
(fhpd) peek 0xff9f5ea0     
[0.0]
The value at ff9f5ea0 = 1
(fhpd) 
Comment 2 Andrew Cagney 2008-01-11 17:44:06 UTC
Which register is OP_breg being applied to?

long Frame.getRegister(Register) returns the register, converted to a long,
based on the register's type.  So for pointer registers such as $esp, that
results in an unsigned extension, while for general registers (such as $eax)
that will be sign-extended due to SignedType.

Several questions:
-> should that breg be a pointer?
-> should there be a Frame method that returns registers as unsigned "Word"
values (which is more like what the location expression code expects)
-> should the location-expression code be doing word-sized, instead of Long
sized, arrithmetic?
Comment 3 Teresa Thomas 2008-01-14 21:07:45 UTC
    Fix sign extension bug with breg operation.
    
    frysk-core/frysk/debuginfo/ChangeLog
    2008-01-14  Teresa Thomas  <tthomas@redhat.com>
    
    	* TestLocationExpression.java (testOverFlow): New.
    	* LocationExpression.java (decode): Mask out
    	sign extension for BREG locations.