Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Cary Coutant via Dwarf-Discuss
> DW_OP_implicit_value and DW_OP_stack_value produce values (that is
> R-values), not locations.  I might be able to read
> DW_OP_implicit_pointer as providing a location; I'm not sure.

No, they don't produce a value. The expression that precedes them
produces a value, and these operators produce a location description
for that value.

> As I said, values and locations are muddled.  If you think that a
> variable which has been eliminated has a location which is described by
> a DW_OP_implicit_value, then we aren't working with the same definition
> of "location".

Evidently not. For values that don't have a location, we have these
operators that provide a location description anyway. Even though
they're not real locations in the sense of existing in memory or a
register, they are locations in the sense that they are described by a
location description.

Perhaps it would help to think of "locations" as what you think of as
locations, and "location descriptions" as something a bit more
general. A location description can describe a real location, or it
can describe something more ethereal.

> This doesn't work with any of the Implicit Location Descriptions,
> because there isn't any "there" there.  They don't result in locations;
> they give the values which would be found if the variable did exist.  So
> they implicitly perform the dereference operation.

Quite the opposite; they perform the inverse of a dereference
operation. They provide something at the level of a location
description that can be dereferenced but has no other purpose.

-cary
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Michael Eager via Dwarf-Discuss

On 3/23/20 3:58 PM, Cary Coutant via Dwarf-Discuss wrote:

I think that the description has become a bit less clear with the
addition of the Implicit Location Descriptions in Section 2.6.1.1.4,
which do compute values, rather than locations.  Perhaps these should
have been described in Section 2.5 as parts of a DWARF expression, not
as parts of a Location Description.


Strongly disagree. The whole point of an implicit location description
is to give a (pseudo/virtual) location to a value that has no
location. A DWARF *expression* has no use for these operators.


DW_OP_implicit_value and DW_OP_stack_value produce values (that is 
R-values), not locations.  I might be able to read 
DW_OP_implicit_pointer as providing a location; I'm not sure.


As I said, values and locations are muddled.  If you think that a 
variable which has been eliminated has a location which is described by 
a DW_OP_implicit_value, then we aren't working with the same definition 
of "location".


The problem is that the basic DWARF concept is that a variable has a 
location and that you can fetch its values from this location.  Thus, we 
expect to be able to evaluate a location description and dereference it 
to get a value.  Similarly, you can change a variable's value by 
modifying its location.  This dereference or modification may be a bit 
complicated if DW_OP_piece is involved, but the operation is symmetric. 
This I might call a "real" location description.


This doesn't work with any of the Implicit Location Descriptions, 
because there isn't any "there" there.  They don't result in locations; 
they give the values which would be found if the variable did exist.  So 
they implicitly perform the dereference operation.  But, in contrast to 
"real" location descriptions, the operation is not symmetric, you can't 
change the variable's value.

___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Cary Coutant via Dwarf-Discuss
> I think that the description has become a bit less clear with the
> addition of the Implicit Location Descriptions in Section 2.6.1.1.4,
> which do compute values, rather than locations.  Perhaps these should
> have been described in Section 2.5 as parts of a DWARF expression, not
> as parts of a Location Description.

Strongly disagree. The whole point of an implicit location description
is to give a (pseudo/virtual) location to a value that has no
location. A DWARF *expression* has no use for these operators.

> The description (and implementation) of DWARF expressions and locations
> are somewhat muddled together.  This can be seen in the first sentence
> of Section 2.5:
> DWARF expressions describe how to compute a value or specify a
> location.
> A clearer definition would specify that the DWARF expression only
> computes a value, and leaving what that value means (e.g.,
> register/memory contents, arbitrary computation, memory address) to the
> context in which the expression is used.  A more precise definition of a
> location, especially a composite location, would help.
>
> Part of this is historical, with the expression evaluation initially
> used to compute a memory address and then extended to accommodate
> composite locations and further extended to compute arbitrary values.
> These extensions were in divergent directions, affecting both location
> composition and value computation.  It would have been better if the two
> concepts were clearly distinguished.

Other than that first sentence of 2.5, I think they are pretty clearly
distinguished. Location descriptions, covered by Section 2.6, are
built on top of DWARF expressions, and provide additional operators
for specifying locations other than simple memory locations.

-cary
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Todd Allen via Dwarf-Discuss
I recall this being intentional as well.  This is how I think of these items.
And this is just the gist of things.  I didn't put on my ABI Lawyer hat for
this:

A DWARF expression is a stack machine that evaluates to a value.

A location description describes the "location" of an object.  A "location" is
pure concept here, and doesn't necessarily require any physical location.  It
can be:
 * In memory at an address: It has a DWARF expression which computes the
   start address.
 * In a register: DW_OP_regN, DW_OP_regx.  No locdesc needed.
 * Nowhere, but with a known value: DW_OP_implicit_value, DW_OP_stack_value.
   I think of this as being an ephemeral "location", which in concrete terms
   would be in a buffer in the debugger or some other consumer.  There's a
   DWARF expression which computes the value.
 * Nowhere, but where it's an optimized-away pointer, and its designated
   (pointed-to) value is a known value, much like above.
 * Spread out across multiple distinct locations: DW_OP_piece's, where each
   piece can be any one of the above.
Oh, and one more:
 * Nowhere at all.  Go fish.

So locdescs can use a DWARF expression for a couple different purposes, or even
multiple DWARF expressions.  But they have additional operators for additional
cases (e.g. registers), and for "glue" (DW_OP_piece).

Conversely, DWARF expressions cannot use any of the locdesc special operators or
"glue".

But, of course, there could be use cases where some of these would make sense in
a DWARF expression, and we just didn't think of it.  Nothing springs to my mind
right now...  But if you have a compelling case, we certainly could move some of
those special/glue operators from the locdesc category to the DWARF expression
category.

It think it feels a little blurry only because locdescs came first, and then we
co-opted them for DWARF expressions, and restricted the use of certain operators
in that case.  And then it eventually changed into what we have now.  But a lot
of us remember the history, which creates that blur.

-- 
Todd Allen
Concurrent Real-Time

On Mon, Mar 23, 2020 at 12:04:58PM -0700, Dwarf Discussion wrote:
> On 3/23/20 6:28 AM, Robinson, Paul via Dwarf-Discuss wrote:
> > > From: Dwarf-Discuss  On Behalf
> > > Of Adrian Prantl via Dwarf-Discuss
> > > > On Mar 19, 2020, at 5:49 PM, Michael Eager via Dwarf-Discuss  > > disc...@lists.dwarfstd.org> wrote:
> > > > 
> > > > My reading of sections 2.5 & 2.6 is that you cannot have a DW_OP_piece
> > > in an DWARF expression.
> > > > 
> > > 
> > > I wonder if this is an intentional part of the design because of
> > > ambiguity/correctness issues or is this just something that happens to
> > > fall out of the way the text is worded? I can see how such a restriction
> > > might simplify DWARF consumers, but it also seems like an arbitrary
> > > restriction for which there may not be a technical reason.
> > 
> > My intuition (clearly I wasn't there at the time) is that this is like
> > a C expression being an rvalue (DWARF expression) or lvalue (location
> > description).  Values and locations aren't the same thing.
> 
> It is somewhat an L-value vs R-value issue.
> 
> You can craft a DWARF expression to extract a value (an R-value) from
> arbitrary memory locations or registers (for example, using DW_OP_and,
> DW_OP_sh?, etc.) and place it on the top of the stack.  A DW_OP_piece
> operator doesn't do this.  (There might be value in an operator which
> extracts a value from a composite location.)
> 
> A location (an L-value) which includes potentially multiple register or
> memory locations and multiple DW_OP_piece or DW_OP_bit_piece operations
> can't be evaluated by a simple stack-based expression interpreter.
> 
> The design is intentional, AFAIK, not accidental.
> 
> I think that the description has become a bit less clear with the addition
> of the Implicit Location Descriptions in Section 2.6.1.1.4, which do compute
> values, rather than locations.  Perhaps these should have been described in
> Section 2.5 as parts of a DWARF expression, not as parts of a Location
> Description.
> 
> The description (and implementation) of DWARF expressions and locations are
> somewhat muddled together.  This can be seen in the first sentence of
> Section 2.5:
>DWARF expressions describe how to compute a value or specify a
>location.
> A clearer definition would specify that the DWARF expression only computes a
> value, and leaving what that value means (e.g., register/memory contents,
> arbitrary computation, memory address) to the context in which the
> expression is used.  A more precise definition of a location, especially a
> composite location, would help.
> 
> Part of this is historical, with the expression evaluation initially used to
> compute a memory address and then extended to accommodate composite
> locations and further extended to compute arbitrary values. These extensions
> were in divergent directions, affecting both location composition and value
> co

Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Michael Eager via Dwarf-Discuss

On 3/23/20 6:28 AM, Robinson, Paul via Dwarf-Discuss wrote:

From: Dwarf-Discuss  On Behalf
Of Adrian Prantl via Dwarf-Discuss

On Mar 19, 2020, at 5:49 PM, Michael Eager via Dwarf-Discuss 
disc...@lists.dwarfstd.org> wrote:


My reading of sections 2.5 & 2.6 is that you cannot have a DW_OP_piece

in an DWARF expression.




I wonder if this is an intentional part of the design because of
ambiguity/correctness issues or is this just something that happens to
fall out of the way the text is worded? I can see how such a restriction
might simplify DWARF consumers, but it also seems like an arbitrary
restriction for which there may not be a technical reason.


My intuition (clearly I wasn't there at the time) is that this is like
a C expression being an rvalue (DWARF expression) or lvalue (location
description).  Values and locations aren't the same thing.


It is somewhat an L-value vs R-value issue.

You can craft a DWARF expression to extract a value (an R-value) from 
arbitrary memory locations or registers (for example, using DW_OP_and, 
DW_OP_sh?, etc.) and place it on the top of the stack.  A DW_OP_piece 
operator doesn't do this.  (There might be value in an operator which 
extracts a value from a composite location.)


A location (an L-value) which includes potentially multiple register or 
memory locations and multiple DW_OP_piece or DW_OP_bit_piece operations 
can't be evaluated by a simple stack-based expression interpreter.


The design is intentional, AFAIK, not accidental.

I think that the description has become a bit less clear with the 
addition of the Implicit Location Descriptions in Section 2.6.1.1.4, 
which do compute values, rather than locations.  Perhaps these should 
have been described in Section 2.5 as parts of a DWARF expression, not 
as parts of a Location Description.


The description (and implementation) of DWARF expressions and locations 
are somewhat muddled together.  This can be seen in the first sentence 
of Section 2.5:

   DWARF expressions describe how to compute a value or specify a
   location.
A clearer definition would specify that the DWARF expression only 
computes a value, and leaving what that value means (e.g., 
register/memory contents, arbitrary computation, memory address) to the 
context in which the expression is used.  A more precise definition of a 
location, especially a composite location, would help.


Part of this is historical, with the expression evaluation initially 
used to compute a memory address and then extended to accommodate 
composite locations and further extended to compute arbitrary values. 
These extensions were in divergent directions, affecting both location 
composition and value computation.  It would have been better if the two 
concepts were clearly distinguished.


--
Michael Eager

___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-23 Thread Robinson, Paul via Dwarf-Discuss



> -Original Message-
> From: Dwarf-Discuss  On Behalf
> Of Adrian Prantl via Dwarf-Discuss
> Sent: Friday, March 20, 2020 1:29 PM
> To: Michael Eager 
> Cc: dwarf-discuss@lists.dwarfstd.org
> Subject: Re: [Dwarf-Discuss] Use of Location Description operations in
> DWARF Expressions?
> 
> 
> 
> > On Mar 19, 2020, at 5:49 PM, Michael Eager via Dwarf-Discuss  disc...@lists.dwarfstd.org> wrote:
> >
> > My reading of sections 2.5 & 2.6 is that you cannot have a DW_OP_piece
> in an DWARF expression.
> >
> 
> I wonder if this is an intentional part of the design because of
> ambiguity/correctness issues or is this just something that happens to
> fall out of the way the text is worded? I can see how such a restriction
> might simplify DWARF consumers, but it also seems like an arbitrary
> restriction for which there may not be a technical reason.

My intuition (clearly I wasn't there at the time) is that this is like
a C expression being an rvalue (DWARF expression) or lvalue (location
description).  Values and locations aren't the same thing.
--paulr

> That distinction is important, because if there is a *technical* reason
> for not supporting them we should refrain from implementing this in LLVM.
> But if there isn't, there is no harm done in implementing it as an
> extension, and DWARF consumers that don't support it can just ignore these
> expressions and return N/A.
> 
> -- adrian
> ___
> Dwarf-Discuss mailing list
> Dwarf-Discuss@lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-20 Thread Adrian Prantl via Dwarf-Discuss



> On Mar 19, 2020, at 5:49 PM, Michael Eager via Dwarf-Discuss 
>  wrote:
> 
> My reading of sections 2.5 & 2.6 is that you cannot have a DW_OP_piece in an 
> DWARF expression.
> 

I wonder if this is an intentional part of the design because of 
ambiguity/correctness issues or is this just something that happens to fall out 
of the way the text is worded? I can see how such a restriction might simplify 
DWARF consumers, but it also seems like an arbitrary restriction for which 
there may not be a technical reason.

That distinction is important, because if there is a *technical* reason for not 
supporting them we should refrain from implementing this in LLVM. But if there 
isn't, there is no harm done in implementing it as an extension, and DWARF 
consumers that don't support it can just ignore these expressions and return 
N/A.

-- adrian
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


Re: [Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-19 Thread Michael Eager via Dwarf-Discuss

On 3/19/20 9:30 AM, David Stenberg via Dwarf-Discuss wrote:

Hi!

This is something that has popped up in a number of LLVM patch reviews,
and is something that we would like to get some help with clarifying.

For DWARF[345], may a DWARF Expression (described in section 2.5)
contain any of the operations listed under the Location Descriptions
section (2.6)? For example, may a DW_AT_call_value in DWARF5, which
"is a DWARF expression", contain any of those operations
(e.g. a DW_OP_piece)?

DWARF5 section 2.5 specifies the following for the operations under
section 2.6:

"In addition to the general operations that are defined here, operations
  that are specific to location descriptions are defined in Section 2.6
  on page 38."

Reading section 2.5 and 2.6, I have interpreted the standard as if DWARF
Expressions and Location Descriptions are disparate things; Location
Descriptions may describe locations _using_ DWARF Expressions, but in
places where a DWARF Expression is expected, you may not have a Location
Description in its place. Is that correct?

Given the above quote, and if my interpretation of how DWARF Expressions
and Location Descriptions correlate is correct, I would assume that the
answer to this mail's initial question is no. Or am I overlooking
somethere here?


My reading of sections 2.5 & 2.6 is that you cannot have a DW_OP_piece 
in an DWARF expression.


A DWARF expression, when evaluated (as the result of evaluating a 
DW_AT_call_value), yields a value which is at the top of the stack.


A Composite Location Description, containing DW_OP_piece, as mentioned 
on page 42, "does not compute a value or store any result on the DWARF 
stack."


The DW_OP_reg* operations in a Location Description name a register, but 
do not modify the stack.  (See comment page 40.)


Implicit Location Descriptions may only appear in Location Descriptions. 
 The wording of the text says that the three operations specify a 
value, but do not say that this value is pushed on the stack.


--
Michael Eagerea...@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


[Dwarf-Discuss] Use of Location Description operations in DWARF Expressions?

2020-03-19 Thread David Stenberg via Dwarf-Discuss
Hi!

This is something that has popped up in a number of LLVM patch reviews,
and is something that we would like to get some help with clarifying.

For DWARF[345], may a DWARF Expression (described in section 2.5)
contain any of the operations listed under the Location Descriptions
section (2.6)? For example, may a DW_AT_call_value in DWARF5, which
"is a DWARF expression", contain any of those operations
(e.g. a DW_OP_piece)?

DWARF5 section 2.5 specifies the following for the operations under
section 2.6:

"In addition to the general operations that are defined here, operations
 that are specific to location descriptions are defined in Section 2.6
 on page 38."

Reading section 2.5 and 2.6, I have interpreted the standard as if DWARF
Expressions and Location Descriptions are disparate things; Location
Descriptions may describe locations _using_ DWARF Expressions, but in
places where a DWARF Expression is expected, you may not have a Location
Description in its place. Is that correct?

Given the above quote, and if my interpretation of how DWARF Expressions
and Location Descriptions correlate is correct, I would assume that the
answer to this mail's initial question is no. Or am I overlooking
somethere here?

Best regards,
David
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org