forked from ccoutant/dwarf-locations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
005-locations-on-stack.txt
1607 lines (1307 loc) · 79.7 KB
/
005-locations-on-stack.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Part 5: Allow Location Descriptions on the Stack
This is part 5 in a series of proposals related to support for debugging
on heterogeneous architectures. This is the core proposal of the series:
it unifies DWARF values and location descriptions and allows the
expression stack to operate on both. Several subsequent proposals will
build on this foundation.
The immediate benefit of this proposal is that the DW_OP_call* operators
can now return a location description, permitting the DWARF producer
to use DWARF procedures for complex location descriptions that might
be shared among several variables, or shared among several entries in
a location list.
This proposal also lays the groundwork for later proposals in this series
that add the ability to operate on location descriptions to modify them
(e.g., to describe a sub-field of a vector register). These follow-on
proposals are presented separately in order to keep the size of each
one manageable and understandable.
BACKGROUND
----------
The changes proposed below change the DWARF expression evaluation stack
from a stack of (typed) values only to a stack of items that can be
either values or location descriptions. As such, the location
description operators are no longer "terminal" and can participate in
subsequent DWARF stack operations.
PROPOSED CHANGES
----------------
In Section 2.5 DWARF Expressions, remove the second sentence of the
first paragraph: "They are expressed in terms of DWARF operations that
operate on a stack of values."
Add the following paragraph after the paragraph beginning "If the
evaluation of a DWARF expression...":
--------------------------------------------------------------------
If a result kind is specified, and the result of the evaluation does
not match the specified result kind, then the implicit conversions
described in 2.5.4.4.3 Memory Location Description Operations are
performed if valid. Otherwise, the DWARF expression is ill-formed.
--------------------------------------------------------------------
Remove the paragraph "A DWARF expression is encoded as a stream of
operations..."
Add the following text at the end of the section:
--------------------------------------------------------------------
A DWARF expression can either be encoded as an operation expression
(see 2.5.x DWARF Operation Expressions), or as a location list
expression (see 2.5.x DWARF Location List Expressions).
--------------------------------------------------------------------
In Section 2.5.1, DWARF Expression Evaluation Context, in item 8, "an
initial stack," change "a list of values..." to "a list of values or
location descriptions..."
After Section 2.5.1, insert a new section "2.5.2 DWARF Expression Value"
(and renumber subsequent subsections):
Move paragraphs 2-5 of 2.5.x General Operations into this new section,
and change "A value on the stack has..." to "A value has...":
--------------------------------------------------------------------
2.5.2 DWARF Expression Value
A value has a type and a literal value. It can represent a literal
value of any supported base type of the target architecture. The
base type specifies the size, encoding, and endianity of the literal
value.
There is a distinguished base type termed the generic type, which is
an integral type that has the size of an address in the target
architecture default address space, a target architecture defined
endianity, and unspecified signedness.
[non-normative] The generic type is the same as the unspecified type
used for stack operations defined in DWARF Version 4 and before.
An integral type is a base type that has an encoding of
DW_ATE_signed, DW_ATE_signed_char, DW_ATE_unsigned,
DW_ATE_unsigned_char, DW_ATE_boolean, or any target architecture
defined integral encoding in the inclusive range DW_ATE_lo_user to
DW_ATE_hi_user.
--------------------------------------------------------------------
> [For further discussion...]
> It may be desirable to add an implicit pointer base type encoding.
> It would be used for the type of the value that is produced when
> the DW_OP_deref* operation retrieves the full contents of an
> implicit pointer location storage created by the
> DW_OP_implicit_pointer operation. The literal value would record
> the debugging information entry and byte displacement specified by
> the associated DW_OP_implicit_pointer operation.
>
> It is unclear if DW_ATE_address is an integral type. GDB does not
> seem to consider it as integral.
Rename the subsection 2.5.x General Operations:
--------------------------------------------------------------------
2.5.3 DWARF Operation Expressions
--------------------------------------------------------------------
Insert the following as the first paragraph of the section:
--------------------------------------------------------------------
An operation expression is comprised of a stream of operations, each
consisting of an opcode followed by zero or more operands. The
number of operands is implied by the opcode.
--------------------------------------------------------------------
Insert the following before the paragraph beginning “Operations can act
on entries on the stack...”:
--------------------------------------------------------------------
Each stack entry can hold either a value or a location description.
--------------------------------------------------------------------
Insert the following after the same paragraph:
--------------------------------------------------------------------
If the kind of a stack entry does not match the kind required by the
operation and is not implicitly convertible to the required kind
(see 2.x.x.x Memory Location Description Operations), then the DWARF
operation expression is ill-formed.
--------------------------------------------------------------------
Change the paragraph starting "Evaluation of an expression starts with an empty
stack..." to "Evaluation of an operation expression starts with an empty
stack...".
Near the end of the section, under the first-level bullet item that
begins "If the current result kind specifies a location description":
(1) Replace the second-level bullet item beginning "If the stack is
empty..." with the following:
--------------------------------------------------------------------
* If the stack is empty, the result is a location description
with one undefined location description.
[non-normative] This rule is for backwards compatibility
with DWARF Version 5 which uses an empty operation
expression for this purpose.
--------------------------------------------------------------------
(2) Replace the second-level bullet item beginning "If the stack is not
empty..." with the following:
--------------------------------------------------------------------
* If the top stack entry is a location description, or can be
converted to one (see 2.5.4.4.3 Memory Location Description
Operations), then the result is that, possibly converted,
location description. Any other entries on the stack are
discarded.
--------------------------------------------------------------------
Under the first-level bullet item beginning "If the current result kind
specifies a value," replace the second-level bullet
beginning "If the stack is not empty" with the following:
--------------------------------------------------------------------
* If the top stack entry is a value, or can be converted to
one (see 2.5.4.4.3 Memory Location Description Operations),
then the result is that, possibly converted, value. Any
other entries on the stack are discarded.
--------------------------------------------------------------------
Under the first-level bullet item beginning "If the current result kind
is not specified," replace the second-level bullet item beginning "If
the stack is empty" with the following:
--------------------------------------------------------------------
* If the stack is empty, the result is a location description
with one undefined location description.
[non-normative] This rule is for backwards compatibility
with DWARF Version 5 which uses an empty operation
expression for this purpose.
> [For further discussion...]
> This rule is consistent with the rule above for when a
> location description is requested. However, GDB appears to
> report this as an error and no GDB tests appear to cause
> an empty stack for this case.
--------------------------------------------------------------------
In Section 2.5.1.1 Literal Encodings, replace the description of
DW_OP_addr with the following:
--------------------------------------------------------------------
DW_OP_addr has a single byte constant value operand, which has the
size of the generic type, that represents an address A.
It pushes a location description L with one memory location
description SL on the stack. SL specifies the memory location
storage corresponding to the target architecture default address
space with a bit offset equal to A scaled by 8 (the byte size).
[non-normative] If the DWARF is part of a code object, then A may
need to be relocated. For example, in the ELF code object format, A
must be adjusted by the difference between the ELF segment virtual
address and the virtual address at which the segment is loaded.
--------------------------------------------------------------------
In the same section, replace the description of DW_OP_addrx with the
following:
--------------------------------------------------------------------
DW_OP_addrx has a single unsigned LEB128 integer operand that
represents a zero-based index into the .debug_addr section relative
to the value of the DW_AT_addr_base attribute of the associated
compilation unit. The address value A in the .debug_addr section has
the size of the generic type.
It pushes a location description L with one memory location
description SL on the stack. SL specifies the memory location
storage corresponding to the target architecture default address
space with a bit offset equal to A scaled by 8 (the byte size).
[non-normative] If the DWARF is part of a code object, then A may
need to be relocated. For example, in the ELF code object format, A
must be adjusted by the difference between the ELF segment virtual
address and the virtual address at which the segment is loaded.
--------------------------------------------------------------------
In Section 2.5.1.2 Register Values, replace the description of
DW_OP_fbreg with the following:
--------------------------------------------------------------------
DW_OP_fbreg has a single signed LEB128 integer operand that
represents a byte displacement B.
The location description L for the <i>frame base</i> of the current
subprogram is obtained from the DW_AT_frame_base attribute of the
debugger information entry corresponding to the current subprogram
as described in 3.3.5 Low-Level Information.
The location description L is updated by bit offset B scaled by 8
(the byte size) and pushed on the stack.
--------------------------------------------------------------------
In the same section, replace the description of
DW_OP_breg0...DW_OP_breg31 with the following:
--------------------------------------------------------------------
The DW_OP_breg<N> operations encode the numbers of up to 32
registers, numbered from 0 through 31, inclusive. The register
number R corresponds to the N in the operation name.
They have a single signed LEB128 integer operand that represents a
byte displacement B.
The address space identifier AS is defined as the one corresponding
to the target architecture specific default address space.
The address size S is defined as the address bit size of the target
architecture specific address space corresponding to AS.
The contents of the register specified by R are retrieved as if a
DW_OP_regval_type R, DR operation was performed where DR is the
offset of a hypothetical debug information entry in the current
compilation unit for an unsigned integral base type of size S bits.
B is added and the least significant S bits are treated as an
unsigned value to be used as an address A.
They push a location description L comprising one memory location
description LS on the stack. LS specifies the memory location
storage that corresponds to AS with a bit offset equal to A scaled
by 8 (the byte size).
--------------------------------------------------------------------
In the same section, in the description of DW_OP_regval_type, add the
following:
--------------------------------------------------------------------
The operation is equivalent to performing DW_OP_regx R;
DW_OP_deref_type DR.
--------------------------------------------------------------------
In Section 2.5.1.3 Stack Operations, insert the following at the end of
the first paragraph, following “Operations that index the stack assume
that the top of the stack (most recently added entry) has index 0”:
--------------------------------------------------------------------
They allow the stack entries to be either a value or location
description.
--------------------------------------------------------------------
Insert the following new paragraph after that paragraph:
--------------------------------------------------------------------
If any stack entry accessed by a stack operation is an incomplete
composite location description (see 2.x.x Composite Location
Description Operations), then the DWARF expression is ill-formed.
--------------------------------------------------------------------
> [For further discussion...]
> If it is desired to also make them work with incomplete composite
> location descriptions, then would need to define that the
> composite location storage specified by the incomplete composite
> location description is also replicated when a copy is pushed.
> This ensures that each copy of the incomplete composite location
> description can update the composite location storage they specify
> independently.
In the description of DW_OP_deref_type, replace the paragraph beginning
“It pops one stack entry and treats it as an address...” with the
following:
--------------------------------------------------------------------
It pops one stack entry that must be a location description L.
A value V of TS bits is retrieved from the location storage LS
specified by one of the single location descriptions SL of L.
[non-normative] If L, or the location description of any composite
location description part that is a subcomponent of L, has more than
one single location description, then any one of them can be
selected as they are required to all have the same value. For any
single location description SL, bits are retrieved from the
associated storage location starting at the bit offset specified by
SL. For a composite location description, the retrieved bits are the
concatenation of the N bits from each composite location part PL,
where N is limited to the size of PL.
V is pushed on the stack with the type T.
--------------------------------------------------------------------
> [For further discussion...]
> This definition makes it an evaluation error if L is a register location
> description that has less than TS bits remaining in the register storage.
> Particularly since these extensions extend location descriptions to have a
> bit offset, it would be odd to define this as performing sign extension
> based on the type, or be target architecture dependent, as the number of
> remaining bits could be any number. This matches the GDB implementation
> for DW_OP_deref_type.
>
> These extensions define DW_OP_*breg* in terms of DW_OP_regval_type.
> DW_OP_regval_type is defined in terms of DW_OP_regx, which uses a 0 bit
> offset, and DW_OP_deref_type. Therefore, it requires the register size to
> be greater or equal to the address size of the address space. This matches
> the GDB implementation for DW_OP_*breg*.
Add the following to the end of the description of DW_OP_deref_type:
--------------------------------------------------------------------
It is an evaluation error if any bit of the value is retrieved from
the undefined location storage or the offset of any bit exceeds the
size of the location storage LS specified by any single location
description SL of L.
See 2.5.x.x Implicit Location Description Operations for special
rules concerning implicit location descriptions created by the
DW_OP_implicit_pointer operation.
--------------------------------------------------------------------
In the description of DW_OP_xderef, replace the paragraph beginning “The
value V is retrieved from the location described by L...” with the
following:
--------------------------------------------------------------------
The operation is equivalent to popping A and AS, pushing L, and then
performing DW_OP_deref. The value V retrieved is left on the stack
with the generic type.
--------------------------------------------------------------------
In the description of DW_OP_xderef_size, replace the paragraph beginning
“The value V of size S is retrieved from the location described by L...”
with the following:
--------------------------------------------------------------------
The operation is equivalent to popping A and AS, pushing L, and then
performing DW_OP_deref_size S. The zero-extended value V retrieved
is left on the stack with the generic type.
--------------------------------------------------------------------
In the description of DW_OP_xderef_type, replace the paragraph beginning
“The value V is retrieved from the location described by L...” with the
following:
--------------------------------------------------------------------
The operation is equivalent to popping A and AS, pushing L, and then
performing DW_OP_deref_type DR. The value V retrieved is left on the
stack with the type T.
--------------------------------------------------------------------
Replace the description of DW_OP_push_object_address with the following:
--------------------------------------------------------------------
DW_OP_push_object_address pushes the location description L of the
current object.
[non-normative] This object may correspond to an independent
variable that is part of a user presented expression that is being
evaluated. The object location description may be determined from
the variable’s own debugging information entry or it may be a
component of an array, structure, or class whose address has been
dynamically determined by an earlier step during user expression
evaluation.
[non-normative] This operation provides explicit functionality
(especially for arrays involving descriptors) that is analogous to
the implicit push of the base location description of a structure
prior to evaluation of a DW_AT_data_member_location to access a data
member of a structure.
> [For further discussion...]
> This operation could be removed and the object location
> description specified as the initial stack as for
> DW_AT_data_member_location.
>
> Or this operation could be used instead of needing to specify an
> initial stack. The latter approach is more composable as access to
> the object may be needed at any point of the expression, and
> passing it as the initial stack requires the entire expression to
> be aware where on the stack it is. If this were done,
> DW_AT_use_location would require a DW_OP_push_object2_address
> operation for the second object.
>
> Or a more general way to pass an arbitrary number of arguments in
> and an operation to get the Nth one such as DW_OP_arg N. A vector
> of arguments would then be passed in the expression context rather
> than an initial stack. This could also resolve the issues with
> DW_OP_call* by allowing a specific number of arguments passed in
> and returned to be specified. The DW_OP_call* operation could then
> always execute on a separate stack: the number of arguments would
> be specified in a new call operation and taken from the callers
> stack, and similarly the number of return results specified and
> copied from the called stack back to the callee stack when the
> called expression was complete.
>
> The only attribute that specifies a current object is
> DW_AT_data_location so the non-normative text seems to overstate
> how this is being used. Or are there other attributes that need to
> state they pass an object?
--------------------------------------------------------------------
In the same section, replace the first paragraph of the description of
DW_OP_form_tls_address with the following:
--------------------------------------------------------------------
DW_OP_form_tls_address pops one stack entry that must be an integral
type value and treats it as a thread-local storage address TA.
It pushes a location description L with one memory location
description SL on the stack. SL is the target architecture specific
memory location description that corresponds to the thread-local
storage address TA.
The meaning of the thread-local storage address TA is defined by the
run-time environment. If the run-time environment supports multiple
thread-local storage blocks for a single thread, then the block
corresponding to the executable or shared library containing this
DWARF expression is used.
--------------------------------------------------------------------
In the same section, replace the description of DW_OP_call_frame_cfa
with the following:
--------------------------------------------------------------------
DW_OP_call_frame_cfa pushes the location description L of the
Canonical Frame Address (CFA) of the current subprogram, obtained
from the call frame information on the stack. See Section 6.4 Call
Frame Information.
[non-normative] Although the value of the DW_AT_frame_base attribute
of the debugger information entry corresponding to the current
subprogram can be computed using a location list expression, in some
cases this would require an extensive location list because the
values of the registers used in computing the CFA change during a
subprogram execution. If the call frame information is present, then
it already encodes such changes, and it is space efficient to
reference that using the DW_OP_call_frame_cfa operation.
--------------------------------------------------------------------
In Section 2.5.1.5 Control Flow Operations, in the description of
DW_OP_call2/4/ref, replace the first paragraph:
--------------------------------------------------------------------
DW_OP_call2, DW_OP_call4, and DW_OP_call_ref perform DWARF procedure calls
during evaluation of a DWARF expression.
--------------------------------------------------------------------
with:
--------------------------------------------------------------------
DW_OP_call2, DW_OP_call4, and DW_OP_call_ref perform DWARF procedure calls
during evaluation of a DWARF operation expression.
--------------------------------------------------------------------
In Section 2.5.1.5 Control Flow Operations, in the description of
DW_OP_call2/4/ref, add the following after the first bullet under "The
call operation is evaluated by":
--------------------------------------------------------------------
* If D has a DW_AT_location attribute that is encoded as a loclist
or loclistsptr, then the specified location list expression E is
evaluated. The evaluation of E uses the current context, except
the result kind is a location description, the compilation unit
is the one that contains D, and the initial stack is empty. The
location description result is pushed on the stack.
> [For further discussion...]
> This rule avoids having to define how to execute a matched location
> list entry operation expression on the same stack as the call when
> there are multiple matches. But it allows the call to obtain the
> location description for a variable or formal parameter which may use
> a location list expression.
>
> An alternative is to treat the case when D has a DW_AT_location
> attribute that is encoded as a loclist or loclistsptr, and the
> specified location list expression E' matches a single location list
> entry with operation expression E, the same as the exprloc case and
> evaluate on the same stack.
>
> But this is not attractive as if the attribute is for a variable that
> happens to end with a non-singleton stack, it will not simply put a
> location description on the stack. Presumably the intent of using
> DW_OP_call* on a variable or formal parameter debugger information
> entry is to push just one location description on the stack. That
> location description may have more than one single location
> description.
>
> The previous rule for exprloc also has the same problem, as normally a
> variable or formal parameter location expression may leave multiple
> entries on the stack and only return the top entry.
>
> GDB implements DW_OP_call* by always executing E on the same stack. If
> the location list has multiple matching entries, it simply picks the
> first one and ignores the rest. This seems fundamentally at odds with
> the desire to support multiple places for variables.
>
> So, it feels like DW_OP_call* should both support pushing a location
> description on the stack for a variable or formal parameter, and also
> support being able to execute an operation expression on the same
> stack. Being able to specify a different operation expression for
> different program locations seems a desirable feature to retain.
>
> A solution to that is to have a distinct DW_AT_proc attribute for the
> DW_TAG_dwarf_procedure debugging information entry. Then the
> DW_AT_location attribute expression is always executed separately and
> pushes a location description (that may have multiple single location
> descriptions), and the DW_AT_proc attribute expression is always
> executed on the same stack and can leave anything on the stack.
>
> The DW_AT_proc attribute could have the new classes exprproc,
> loclistproc, and loclistsptrproc to indicate that the expression is
> executed on the same stack. exprproc is the same encoding as exprloc.
> loclistproc and loclistsptrproc are the same encoding as their
> non-proc counterparts, except the DWARF is ill-formed if the location
> list does not match exactly one location list entry and a default
> entry is required. These forms indicate explicitly that the matched
> single operation expression must be executed on the same stack. This
> is better than ad hoc special rules for loclistproc and
> loclistsptrproc which are currently clearly defined to always return a
> location description. The producer then explicitly indicates the
> intent through the attribute classes.
>
> Such a change would be a breaking change for how GDB implements
> DW_OP_call*. However, are the breaking cases actually occurring in
> practice? GDB could implement the current approach for DWARF Version
> 5, and the new semantics for DWARF Version 6 which has been done for
> some other features.
>
> Another option is to limit the execution to be on the same stack only
> to the evaluation of an expression E that is the value of a
> DW_AT_location attribute of a DW_TAG_dwarf_procedure debugging
> information entry. The DWARF would be ill-formed if E is a location
> list expression that does not match exactly one location list entry.
> In all other cases the evaluation of an expression E that is the value
> of a DW_AT_location attribute would evaluate E with the current
> context, except the result kind is a location description, the
> compilation unit is the one that contains D, and the initial stack is
> empty. The location description result is pushed on the stack.
* If D has a DW_AT_const_value attribute with a value V, then it
is as if a DW_OP_implicit_value V operation was executed.
[non-normative] This allows a call operation to be used to
compute the location description for any variable or formal
parameter regardless of whether the producer has optimized it to
a constant. This is consistent with the DW_OP_implicit_pointer
operation.
> [For further discussion...]
> Alternatively, could deprecate using DW_AT_const_value for
> DW_TAG_variable and DW_TAG_formal_parameter debugger information
> entries that are constants and instead use DW_AT_location with an
> operation expression that results in a location description with one
> implicit location description. Then this rule would not be required.
--------------------------------------------------------------------
In Section 2.6.1.1.2 Memory Location Descriptions (now 2.6.2), delete the first
paragraph "A memory location description consists of a non-empty DWARF
expression", and add the following paragraphs to the end of the section:
--------------------------------------------------------------------
If a stack entry is required to be a location description, but it is
a value V with the generic type, then it is implicitly converted to
a location description L with one memory location description SL. SL
specifies the memory location storage that corresponds to the target
architecture default address space with a bit offset equal to V
scaled by 8 (the byte size).
> [For further discussion...]
> If it is wanted to allow any integral type value to be implicitly
> converted to a memory location description in the target
> architecture default address space:
>
> If a stack entry is required to be a location description, but
> is a value V with an integral type, then it is implicitly
> converted to a location description L with a one memory
> location description SL. If the type size of V is less than
> the generic type size, then the value V is zero extended to
> the size of the generic type. The least significant generic
> type size bits are treated as an unsigned value to be used as
> an address A. SL specifies memory location storage
> corresponding to the target architecture default address space
> with a bit offset equal to A scaled by 8 (the byte size).
>
> The implicit conversion could also be defined as target
> architecture specific. For example, GDB checks if V is an integral
> type. If it is not it gives an error. Otherwise, GDB zero-extends
> V to 64 bits. If the GDB target defines a hook function, then it
> is called. The target specific hook function can modify the 64-bit
> value, possibly sign extending based on the original value type.
> Finally, GDB treats the 64-bit value V as a memory location
> address.
If a stack entry is required to be a location description, but it is
an implicit pointer value IPV with the target architecture default
address space, then it is implicitly converted to a location
description with one single location description specified by IPV.
See 2.5.4.4.5 Implicit Location Description Operations.
If a stack entry is required to be a value, but it is a location
description L with one memory location description SL in the target
architecture default address space with a bit offset B that is a
multiple of 8, then it is implicitly converted to a value equal to B
divided by 8 (the byte size) with the generic type.
--------------------------------------------------------------------
In Section 2.6.1.1.3 (now 2.6.3) Register Location Descriptions, rename
the section "Register Location Description Operations."
Replace the first four paragraphs of the section with the following:
--------------------------------------------------------------------
There is a register location storage that corresponds to each of the
target architecture registers. The size of each register location
storage corresponds to the size of the corresponding target
architecture register.
A register location description specifies a register location
storage. The bit offset corresponds to a bit position within the
register. Bits accessed using a register location description access
the corresponding target architecture register starting at the
specified bit offset.
--------------------------------------------------------------------
Replace the description of DW_OP_regx with the following:
--------------------------------------------------------------------
DW_OP_regx has a single unsigned LEB128 integer operand that
represents a target architecture register number R.
If the current call frame is the top call frame, it pushes a
location description L that specifies one register location
description SL on the stack. SL specifies the register location
storage that corresponds to R with a bit offset of 0 for the current
thread.
If the current call frame is not the top call frame, call frame
information (see 6.4 Call Frame Information) is used to determine
the location description that holds the register for the current
call frame and current program location of the current thread. The
resulting location description L is pushed.
[non-normative] Note that if call frame information is used, the
resulting location description may be register, memory, or
undefined.
[non-normative] An implementation may evaluate the call frame
information immediately, or may defer evaluation until L is accessed
by an operation. If evaluation is deferred, R and the current
context can be recorded in L. When accessed, the recorded context is
used to evaluate the call frame information, not the current context
of the access operation.
--------------------------------------------------------------------
Replace the last paragraph with:
--------------------------------------------------------------------
[non-normative] These operations obtain a register location. To fetch the
contents of a register, it is necessary to use DW_OP_regval_type, use one of
the DW_OP_breg* register-based addressing operations, or use DW_OP_deref* on
a register location description.
--------------------------------------------------------------------
In Section 2.6.1.1.4 (now 2.6.4) Implicit Location Descriptions, rename the
section "Implicit Location Description Operations."
Replace the first paragraph with:
--------------------------------------------------------------------
Implicit location storage represents a piece or all of an object which has
no actual location in the program but whose contents are nonetheless known,
either as a constant or can be computed from other locations and values in
the program.
An implicit location description specifies an implicit location
storage. The bit offset corresponds to a bit position within the
implicit location storage. Bits accessed using an implicit location
description, access the corresponding implicit storage value
starting at the bit offset.
--------------------------------------------------------------------
Delete the following paragraph that begins with "The following DWARF operations
may be used...".
Replace the description of DW_OP_implicit_value with the following:
--------------------------------------------------------------------
DW_OP_implicit_value has two operands. The first is an unsigned
LEB128 integer that represents a byte size S. The second is a block
of bytes with a length equal to S treated as a literal value V.
An implicit location storage LS is created with the literal value V
and a size of S.
It pushes location description L with one implicit location
description SL on the stack. SL specifies LS with a bit offset of 0.
--------------------------------------------------------------------
Replace the description of DW_OP_stack_value with the following:
--------------------------------------------------------------------
DW_OP_stack_value pops one stack entry that must be a value V.
An implicit location storage LS is created with the literal value V
using the size, encoding, and endianity specified by V’s base type.
It pushes a location description L with one implicit location
description SL on the stack. SL specifies LS with a bit offset of 0.
[non-normative] The DW_OP_stack_value operation specifies that the
object does not exist in memory, but its value is nonetheless known.
In this form, the location description specifies the actual value of
the object, rather than specifying the memory or register storage
that holds the value.
See DW_OP_implicit_pointer (following) for special rules concerning
implicit pointer values produced by dereferencing implicit location
descriptions created by the DW_OP_implicit_pointer operation.
Note: Since location descriptions are allowed on the stack, the
DW_OP_stack_value operation no longer terminates the DWARF operation
expression execution as in DWARF Version 5.
--------------------------------------------------------------------
Replace the description of DW_OP_implicit_pointer with the following:
--------------------------------------------------------------------
[unchanged] [non-normative] An optimizing compiler may eliminate a
pointer, while still retaining the value that the pointer addressed.
DW_OP_implicit_pointer allows a producer to describe this value.
[non-normative] DW_OP_implicit_pointer specifies an object is a
pointer to the target architecture default address space that cannot
be represented as a real pointer, even though the value it would
point to can be described. In this form, the location description
specifies a debugging information entry that represents the actual
location description of the object to which the pointer would point.
Thus, a consumer of the debug information would be able to access
the dereferenced pointer, even when it cannot access the pointer
itself.
DW_OP_implicit_pointer has two operands. The first operand is a
4-byte unsigned value in the 32-bit DWARF format, or an 8-byte
unsigned value in the 64-bit DWARF format, that represents the byte
offset DR of a debugging information entry D relative to the
beginning of the .debug_info section that contains the current
compilation unit. The second operand is a signed LEB128 integer that
represents a byte displacement B.
[non-normative] Note that D might not be in the current compilation
unit.
[non-normative] The first operand interpretation is exactly like
that for DW_FORM_ref_addr.
The address space identifier AS is defined as the one corresponding
to the target architecture specific default address space.
The address size S is defined as the address bit size of the target
architecture specific address space corresponding to AS.
An implicit location storage LS is created with the debugging
information entry D, address space AS, and size of S.
It pushes a location description L that comprises one implicit
location description SL on the stack. SL specifies LS with a bit
offset of 0.
It is an evaluation error if a DW_OP_deref* operation pops a
location description L’, and retrieves S bits, such that any
retrieved bits come from an implicit location storage that is the
same as LS, unless both the following conditions are met:
1. All retrieved bits come from an implicit location description
that refers to an implicit location storage that is the same as
LS.
[non-normative] Note that all bits do not have to come from the
same implicit location description, as L’ may involve composite
location descriptions.
2. The bits come from consecutive ascending offsets within their
respective implicit location storage.
[non-normative] These rules are equivalent to retrieving the
complete contents of LS.
If both the above conditions are met, then the value V pushed by the
DW_OP_deref* operation is an implicit pointer value IPV with a
target architecture specific address space of AS, a debugging
information entry of D, and a base type of T. If AS is the target
architecture default address space, then T is the generic type.
Otherwise, T is a target architecture specific integral type with a
bit size equal to S.
If IPV is implicitly converted to a location description (only done if AS is
the target architecture default address space), then the resulting location
description RL is:
* If D has a DW_AT_location attribute, the DWARF expression E from
the DW_AT_location attribute is evaluated with the current
context, except that the result kind is a location description,
the compilation unit is the one that contains D, the object is
unspecified, and the initial stack is empty. RL is the
expression result.
[non-normative] Note that E is evaluated with the context of the
expression accessing IPV, and not the context of the expression
that contained the DW_OP_implicit_pointer operation that created
L.
* If D has a DW_AT_const_value attribute, then an implicit
location storage RLS is created from the DW_AT_const_value
attribute’s value with a size matching the size of the
DW_AT_const_value attribute’s value. RL comprises one implicit
location description SRL. SRL specifies RLS with a bit offset of
0.
> [For further discussion...]
> If using DW_AT_const_value for variables and formal parameters
> is deprecated and instead DW_AT_location is used with an
> implicit location description, then this rule would not be
> required.
* Otherwise, it is an evaluation error.
The location description RL is updated by bit offset B scaled by 8
(the byte size).
If a DW_OP_stack_value operation pops a value that is the same as
IPV, then it pushes a location description that is the same as L.
It is an evaluation error if LS or IPV is accessed in any other
manner.
[non-normative] The restrictions on how an implicit pointer location
description created by DW_OP_implicit_pointer can be used are to
simplify the DWARF consumer. Similarly, for an implicit pointer
value created by DW_OP_deref* and DW_OP_stack_value.
--------------------------------------------------------------------
Add the following paragraphs after the description of DW_OP_implicit_pointer:
--------------------------------------------------------------------
[non-normative] Typically a DW_OP_implicit_pointer operation is used
in a DWARF expression E1 of a DW_TAG_variable or
DW_TAG_formal_parameter debugging information entry D1’s
DW_AT_location attribute. The debugging information entry referenced
by the DW_OP_implicit_pointer operation is typically itself a
DW_TAG_variable or DW_TAG_formal_parameter debugging information
entry D2 whose DW_AT_location attribute gives a second DWARF
expression E2.
[non-normative] D1 and E1 are describing the location of a pointer
type object. D2 and E2 are describing the location of the object
pointed to by that pointer object.
[non-normative] However, D2 may be any debugging information entry
that contains a DW_AT_location or DW_AT_const_value attribute (for
example, DW_TAG_dwarf_procedure). By using E2, a consumer can
reconstruct the value of the object when asked to dereference the
pointer described by E1 which contains the DW_OP_implicit_pointer
operation.
--------------------------------------------------------------------
Delete the final paragraph:
--------------------------------------------------------------------
[non-normative] DWARF location descriptions are intended to yield the
location of a value rather than the value itself. An optimizing compiler may
perform a number of code transformations where it becomes impossible to give
a location for a value, but it remains possible to describe the value
itself. Section 2.6.1.1.3 on page 39 describes operators that can be used to
describe the location of a value when that value exists in a register but
not in memory. The operations in this section are used to describe values
that exist neither in memory nor in a single register.
--------------------------------------------------------------------
In Section 2.6.1.2 (now 2.6.5) Composite Location Descriptions, rename
the section and replace its contents with the following:
--------------------------------------------------------------------
2.6.5 Composite Location Description Operations
A composite location storage represents an object or value which may
be contained in part of another location storage or contained in
parts of more than one location storage.
Each part has a part location description L and a part bit size S. L
can have one or more single location descriptions SL. If there are
more than one SL then that indicates that part is located in more
than one place. The bits of each place of the part comprise S
contiguous bits from the location storage LS specified by SL
starting at the bit offset specified by SL. All the bits must be
within the size of LS or the DWARF expression is ill-formed.
A composite location storage can have zero or more parts. The parts
are contiguous such that the zero-based location storage bit index
will range over each part with no gaps between them. Therefore, the
size of a composite location storage is the sum of the size of its
parts. The DWARF expression is ill-formed if the size of the
contiguous location storage is larger than the size of the memory
location storage corresponding to the largest target architecture
specific address space.
A composite location description specifies a composite location
storage. The bit offset corresponds to a bit position within the
composite location storage.
There are operations that create a composite location storage.
There are other operations that allow a composite location storage
to be incrementally created. Each part is created by a separate
operation. There may be one or more operations to create the final
composite location storage. A series of such operations describes
the parts of the composite location storage that are in the order
that the associated part operations are executed.
To support incremental creation, a composite location storage can be
in an incomplete state. When an incremental operation operates on an
incomplete composite location storage, it adds a new part.
A composite location description that specifies a composite location
storage that is incomplete is termed an incomplete composite
location description. A composite location description that
specifies a composite location storage that is complete is termed a
complete composite location description.
If the top stack entry is a location description that has one
incomplete composite location description SL after the execution of
an operation expression has completed, SL is converted to a complete
composite location description.
[non-normative] Note that this conversion does not happen after the
completion of an operation expression that is evaluated on the same
stack by the DW_OP_call* operations. Such executions are not a
separate evaluation of an operation expression, but rather the
continued evaluation of the same operation expression that contains
the DW_OP_call* operation.
If a stack entry is required to be a location description L, but L
has an incomplete composite location description, then the DWARF
expression is ill-formed. The exception is for the operations
involved in incrementally creating a composite location description
as described below.
[non-normative] Note that a DWARF operation expression may
arbitrarily compose composite location descriptions from any other
location description, including those that have multiple single
location descriptions, and those that have composite location
descriptions.
[non-normative] The incremental composite location description
operations are defined to be compatible with the definitions in
DWARF Version 5.