[Bug tools/24509] eu-readelf does not know how to dissect DW_AT_discr_list

2019-05-02 Thread tromey at sourceware dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=24509

--- Comment #2 from Tom Tromey  ---
Here's one that uses both ranges and discrete elements:

package Rng is

   type Rec (I : Integer) is record
  case I is
 when Positive =>
C : Character;
case I is
   when 1..15 | 17 | 23 =>
  null;
   when others =>
  N : Natural;
end case;
 when others =>
S : String (1 .. 10);
  end case;
   end record;

   R : Rec (1);

end Rng;



And here's one that uses unsigned types:

package Urng is

   type Unsigned is mod 65536;
   type Rec (I : Unsigned) is record
  case I is
 when 17 | 23 | 32768..65535 =>
null;
 when others =>
S : String (1 .. 10);
  end case;
   end record;

   R : Rec (1);

end Urng;

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug tools/24509] eu-readelf does not know how to dissect DW_AT_discr_list

2019-05-02 Thread tromey at sourceware dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=24509

--- Comment #3 from Tom Tromey  ---
To check for negative values, I think you can add another
clause, here's what I did:

package Rng is

   type Rec (I : Integer) is record
  case I is
 when Positive =>
C : Character;
case I is
   when 1..15 | 17 | 23 =>
  null;
   when others =>
  N : Natural;
end case;
 when -52..-1 =>
Q: Natural;
 when others =>
S : String (1 .. 10);
  end case;
   end record;

   R : Rec (1);

end Rng;


The proposed patch does not handle this properly:

 [9f]variant  abbrev: 5
 discr_list   (block1) range: 76-127

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: Dwarf_Op

2019-05-02 Thread Sasha Da Rocha Pinheiro
So why not a DW_OP_constu or DW_OP_consts and then a DW_OP_plus?

About the Dwarf_Op array we get from dwarf_frame_register(), (which are a 
sequence of Dwarf expressions): are they suppose to be an abstraction to all 
types of dwarf location descriptions? Including Single (single and composite) 
and Location Lists?

Is there more documentation about dwfl? What does dwfl stand for? (dwarf frame 
library?!)
We already have access to the process memory space and registers, so would 
expr_eval be suffice?

In case of finding the registers values at some PC, would it always gives us a 
single expression (like an address or an offset from a register)?

In the comment of dwarf_frame_register() in the file libdw.h, there is:
"Note the last operation is DW_OP_stack_value if there is no mutable location 
but only a computable value."
What is a mutable location, I didn't find this concept in the Dwarf Debugging 
Information Format v4.

Also there there is:

1057    For common simple expressions *OPS is OPS_MEM.  For arbitrary DWARF
1058    expressions in the CFI, *OPS is an internal pointer that can be used as
1059    long as the Dwarf_CFI used to create FRAME remains alive.  */

Why simple expression can only have 3 operations? (since Dwarf_Op ops_mem[3])
And what's an arbitrary Dwarf expression? What's a non-arbitrary?


Regards,
Sasha



From: Mark Wielaard 
Sent: Wednesday, May 1, 2019 6:02 PM
To: Sasha Da Rocha Pinheiro
Cc: elfutils-devel@sourceware.org
Subject: Re: Dwarf_Op
 
On Wed, May 01, 2019 at 05:08:15PM +, Sasha Da Rocha Pinheiro wrote:
> yes, I did use dwarf_frame_register(), I believe I mentioned that :).

Sorry, I missed that.

> In the case I brought up you're saying it was an elfutils' libdw
> decision to provide negative number as DW_OP_plus_uconst (unsigned
> constant)? So there would be no harm to cast it to a signed int??

Yes, since I don't believe there is a better representation.
There is no DW_OP_plus_sconst for example.

> Do you know if the rules to find the registers will always have only
> another one register associated to it?  Because libdwarf function
> dwarf_get_fde_info_for_reg3() returns a register_num, which is
> described as: "Argument register_num should point to a location
> which will hold the register number associated with the register
> rule."

I am not familiar with libdwarf, so don't know how to answer this question

> elfutils only gives us a location description in an array of
> Dwarf_Op. Does it provide methods to "execute" it so we can get the
> result of the expressions? Or it delegates it to the consumer?

It doesn't have a generic location description "executor". It really
should have. But to make it generic it needs a lot of context.

libdwfl does contain a partial operator interpreter for unwinding. See
expr_eval in libdwfl/frame_unwind.c. To turn that into something more
generic we would need some way to provide it with things like memory
accessors and register values. libdwfl provides some of that through
dwfl_attach_state.

Cheers,

Mark


[Bug tools/24509] eu-readelf does not know how to dissect DW_AT_discr_list

2019-05-02 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=24509

Mark Wielaard  changed:

   What|Removed |Added

  Attachment #11760|0   |1
is obsolete||

--- Comment #4 from Mark Wielaard  ---
Created attachment 11762
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11762&action=edit
discr_list patch that handles signed/unsigned variant_part types

Updated patch that handles signed/unsigned discriminators.

So this is what I used as testcase to have a signed (Integer) and unsigned
(Character) discr.

package Rng is

   type Rec (I : Integer) is record
  case I is
 when Positive =>
C : Character;
case I is
   when 1..15 | 17 | 23..255 =>
  null;
   when others =>
  N : Natural;
end case;
 when -52..-1 =>
Q: Natural;
 when -53 =>
R: Character;
 when others =>
S : String (1 .. 10);
  end case;
   end record;

   Subtype Uppercase is Character Range 'A'..'Z';
   Subtype Lowercase is Character Range 'a'..'z';
   Subtype Numbers is Character Range '0'..'9';

   type RecC (C : Character) is record
  case C is
 when '@' =>
B : Boolean;
 when Lowercase | Uppercase | Numbers =>
D : Character;
 when others =>
null;
  end case;
   end record;

   R : Rec (1);
   RC : RecC ('$');

end Rng;

Does the output look like what you would expect?

BTW. The byte_size expressions are impressive!

-- 
You are receiving this mail because:
You are on the CC list for the bug.