forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.c
4016 lines (3291 loc) · 113 KB
/
value.c
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
/* Low level packing and unpacking of values for GDB, the GNU Debugger.
Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "arch-utils.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "value.h"
#include "gdbcore.h"
#include "command.h"
#include "gdbcmd.h"
#include "target.h"
#include "language.h"
#include "demangle.h"
#include "doublest.h"
#include "regcache.h"
#include "block.h"
#include "dfp.h"
#include "objfiles.h"
#include "valprint.h"
#include "cli/cli-decode.h"
#include "extension.h"
#include <ctype.h>
#include "tracepoint.h"
#include "cp-abi.h"
#include "user-regs.h"
/* Prototypes for exported functions. */
void _initialize_values (void);
/* Definition of a user function. */
struct internal_function
{
/* The name of the function. It is a bit odd to have this in the
function itself -- the user might use a differently-named
convenience variable to hold the function. */
char *name;
/* The handler. */
internal_function_fn handler;
/* User data for the handler. */
void *cookie;
};
/* Defines an [OFFSET, OFFSET + LENGTH) range. */
struct range
{
/* Lowest offset in the range. */
int offset;
/* Length of the range. */
int length;
};
typedef struct range range_s;
DEF_VEC_O(range_s);
/* Returns true if the ranges defined by [offset1, offset1+len1) and
[offset2, offset2+len2) overlap. */
static int
ranges_overlap (int offset1, int len1,
int offset2, int len2)
{
ULONGEST h, l;
l = max (offset1, offset2);
h = min (offset1 + len1, offset2 + len2);
return (l < h);
}
/* Returns true if the first argument is strictly less than the
second, useful for VEC_lower_bound. We keep ranges sorted by
offset and coalesce overlapping and contiguous ranges, so this just
compares the starting offset. */
static int
range_lessthan (const range_s *r1, const range_s *r2)
{
return r1->offset < r2->offset;
}
/* Returns true if RANGES contains any range that overlaps [OFFSET,
OFFSET+LENGTH). */
static int
ranges_contain (VEC(range_s) *ranges, int offset, int length)
{
range_s what;
int i;
what.offset = offset;
what.length = length;
/* We keep ranges sorted by offset and coalesce overlapping and
contiguous ranges, so to check if a range list contains a given
range, we can do a binary search for the position the given range
would be inserted if we only considered the starting OFFSET of
ranges. We call that position I. Since we also have LENGTH to
care for (this is a range afterall), we need to check if the
_previous_ range overlaps the I range. E.g.,
R
|---|
|---| |---| |------| ... |--|
0 1 2 N
I=1
In the case above, the binary search would return `I=1', meaning,
this OFFSET should be inserted at position 1, and the current
position 1 should be pushed further (and before 2). But, `0'
overlaps with R.
Then we need to check if the I range overlaps the I range itself.
E.g.,
R
|---|
|---| |---| |-------| ... |--|
0 1 2 N
I=1
*/
i = VEC_lower_bound (range_s, ranges, &what, range_lessthan);
if (i > 0)
{
struct range *bef = VEC_index (range_s, ranges, i - 1);
if (ranges_overlap (bef->offset, bef->length, offset, length))
return 1;
}
if (i < VEC_length (range_s, ranges))
{
struct range *r = VEC_index (range_s, ranges, i);
if (ranges_overlap (r->offset, r->length, offset, length))
return 1;
}
return 0;
}
static struct cmd_list_element *functionlist;
/* Note that the fields in this structure are arranged to save a bit
of memory. */
struct value
{
/* Type of value; either not an lval, or one of the various
different possible kinds of lval. */
enum lval_type lval;
/* Is it modifiable? Only relevant if lval != not_lval. */
unsigned int modifiable : 1;
/* If zero, contents of this value are in the contents field. If
nonzero, contents are in inferior. If the lval field is lval_memory,
the contents are in inferior memory at location.address plus offset.
The lval field may also be lval_register.
WARNING: This field is used by the code which handles watchpoints
(see breakpoint.c) to decide whether a particular value can be
watched by hardware watchpoints. If the lazy flag is set for
some member of a value chain, it is assumed that this member of
the chain doesn't need to be watched as part of watching the
value itself. This is how GDB avoids watching the entire struct
or array when the user wants to watch a single struct member or
array element. If you ever change the way lazy flag is set and
reset, be sure to consider this use as well! */
unsigned int lazy : 1;
/* If value is a variable, is it initialized or not. */
unsigned int initialized : 1;
/* If value is from the stack. If this is set, read_stack will be
used instead of read_memory to enable extra caching. */
unsigned int stack : 1;
/* If the value has been released. */
unsigned int released : 1;
/* Register number if the value is from a register. */
short regnum;
/* Location of value (if lval). */
union
{
/* If lval == lval_memory, this is the address in the inferior.
If lval == lval_register, this is the byte offset into the
registers structure. */
CORE_ADDR address;
/* Pointer to internal variable. */
struct internalvar *internalvar;
/* Pointer to xmethod worker. */
struct xmethod_worker *xm_worker;
/* If lval == lval_computed, this is a set of function pointers
to use to access and describe the value, and a closure pointer
for them to use. */
struct
{
/* Functions to call. */
const struct lval_funcs *funcs;
/* Closure for those functions to use. */
void *closure;
} computed;
} location;
/* Describes offset of a value within lval of a structure in target
addressable memory units. If lval == lval_memory, this is an offset to
the address. If lval == lval_register, this is a further offset from
location.address within the registers structure. Note also the member
embedded_offset below. */
int offset;
/* Only used for bitfields; number of bits contained in them. */
int bitsize;
/* Only used for bitfields; position of start of field. For
gdbarch_bits_big_endian=0 targets, it is the position of the LSB. For
gdbarch_bits_big_endian=1 targets, it is the position of the MSB. */
int bitpos;
/* The number of references to this value. When a value is created,
the value chain holds a reference, so REFERENCE_COUNT is 1. If
release_value is called, this value is removed from the chain but
the caller of release_value now has a reference to this value.
The caller must arrange for a call to value_free later. */
int reference_count;
/* Only used for bitfields; the containing value. This allows a
single read from the target when displaying multiple
bitfields. */
struct value *parent;
/* Frame register value is relative to. This will be described in
the lval enum above as "lval_register". */
struct frame_id frame_id;
/* Type of the value. */
struct type *type;
/* If a value represents a C++ object, then the `type' field gives
the object's compile-time type. If the object actually belongs
to some class derived from `type', perhaps with other base
classes and additional members, then `type' is just a subobject
of the real thing, and the full object is probably larger than
`type' would suggest.
If `type' is a dynamic class (i.e. one with a vtable), then GDB
can actually determine the object's run-time type by looking at
the run-time type information in the vtable. When this
information is available, we may elect to read in the entire
object, for several reasons:
- When printing the value, the user would probably rather see the
full object, not just the limited portion apparent from the
compile-time type.
- If `type' has virtual base classes, then even printing `type'
alone may require reaching outside the `type' portion of the
object to wherever the virtual base class has been stored.
When we store the entire object, `enclosing_type' is the run-time
type -- the complete object -- and `embedded_offset' is the
offset of `type' within that larger type, in target addressable memory
units. The value_contents() macro takes `embedded_offset' into account,
so most GDB code continues to see the `type' portion of the value, just
as the inferior would.
If `type' is a pointer to an object, then `enclosing_type' is a
pointer to the object's run-time type, and `pointed_to_offset' is
the offset in target addressable memory units from the full object
to the pointed-to object -- that is, the value `embedded_offset' would
have if we followed the pointer and fetched the complete object.
(I don't really see the point. Why not just determine the
run-time type when you indirect, and avoid the special case? The
contents don't matter until you indirect anyway.)
If we're not doing anything fancy, `enclosing_type' is equal to
`type', and `embedded_offset' is zero, so everything works
normally. */
struct type *enclosing_type;
int embedded_offset;
int pointed_to_offset;
/* Values are stored in a chain, so that they can be deleted easily
over calls to the inferior. Values assigned to internal
variables, put into the value history or exposed to Python are
taken off this list. */
struct value *next;
/* Actual contents of the value. Target byte-order. NULL or not
valid if lazy is nonzero. */
gdb_byte *contents;
/* Unavailable ranges in CONTENTS. We mark unavailable ranges,
rather than available, since the common and default case is for a
value to be available. This is filled in at value read time.
The unavailable ranges are tracked in bits. Note that a contents
bit that has been optimized out doesn't really exist in the
program, so it can't be marked unavailable either. */
VEC(range_s) *unavailable;
/* Likewise, but for optimized out contents (a chunk of the value of
a variable that does not actually exist in the program). If LVAL
is lval_register, this is a register ($pc, $sp, etc., never a
program variable) that has not been saved in the frame. Not
saved registers and optimized-out program variables values are
treated pretty much the same, except not-saved registers have a
different string representation and related error strings. */
VEC(range_s) *optimized_out;
};
/* See value.h. */
struct gdbarch *
get_value_arch (const struct value *value)
{
return get_type_arch (value_type (value));
}
int
value_bits_available (const struct value *value, int offset, int length)
{
gdb_assert (!value->lazy);
return !ranges_contain (value->unavailable, offset, length);
}
int
value_bytes_available (const struct value *value, int offset, int length)
{
return value_bits_available (value,
offset * TARGET_CHAR_BIT,
length * TARGET_CHAR_BIT);
}
int
value_bits_any_optimized_out (const struct value *value, int bit_offset, int bit_length)
{
gdb_assert (!value->lazy);
return ranges_contain (value->optimized_out, bit_offset, bit_length);
}
int
value_entirely_available (struct value *value)
{
/* We can only tell whether the whole value is available when we try
to read it. */
if (value->lazy)
value_fetch_lazy (value);
if (VEC_empty (range_s, value->unavailable))
return 1;
return 0;
}
/* Returns true if VALUE is entirely covered by RANGES. If the value
is lazy, it'll be read now. Note that RANGE is a pointer to
pointer because reading the value might change *RANGE. */
static int
value_entirely_covered_by_range_vector (struct value *value,
VEC(range_s) **ranges)
{
/* We can only tell whether the whole value is optimized out /
unavailable when we try to read it. */
if (value->lazy)
value_fetch_lazy (value);
if (VEC_length (range_s, *ranges) == 1)
{
struct range *t = VEC_index (range_s, *ranges, 0);
if (t->offset == 0
&& t->length == (TARGET_CHAR_BIT
* TYPE_LENGTH (value_enclosing_type (value))))
return 1;
}
return 0;
}
int
value_entirely_unavailable (struct value *value)
{
return value_entirely_covered_by_range_vector (value, &value->unavailable);
}
int
value_entirely_optimized_out (struct value *value)
{
return value_entirely_covered_by_range_vector (value, &value->optimized_out);
}
/* Insert into the vector pointed to by VECTORP the bit range starting of
OFFSET bits, and extending for the next LENGTH bits. */
static void
insert_into_bit_range_vector (VEC(range_s) **vectorp, int offset, int length)
{
range_s newr;
int i;
/* Insert the range sorted. If there's overlap or the new range
would be contiguous with an existing range, merge. */
newr.offset = offset;
newr.length = length;
/* Do a binary search for the position the given range would be
inserted if we only considered the starting OFFSET of ranges.
Call that position I. Since we also have LENGTH to care for
(this is a range afterall), we need to check if the _previous_
range overlaps the I range. E.g., calling R the new range:
#1 - overlaps with previous
R
|-...-|
|---| |---| |------| ... |--|
0 1 2 N
I=1
In the case #1 above, the binary search would return `I=1',
meaning, this OFFSET should be inserted at position 1, and the
current position 1 should be pushed further (and become 2). But,
note that `0' overlaps with R, so we want to merge them.
A similar consideration needs to be taken if the new range would
be contiguous with the previous range:
#2 - contiguous with previous
R
|-...-|
|--| |---| |------| ... |--|
0 1 2 N
I=1
If there's no overlap with the previous range, as in:
#3 - not overlapping and not contiguous
R
|-...-|
|--| |---| |------| ... |--|
0 1 2 N
I=1
or if I is 0:
#4 - R is the range with lowest offset
R
|-...-|
|--| |---| |------| ... |--|
0 1 2 N
I=0
... we just push the new range to I.
All the 4 cases above need to consider that the new range may
also overlap several of the ranges that follow, or that R may be
contiguous with the following range, and merge. E.g.,
#5 - overlapping following ranges
R
|------------------------|
|--| |---| |------| ... |--|
0 1 2 N
I=0
or:
R
|-------|
|--| |---| |------| ... |--|
0 1 2 N
I=1
*/
i = VEC_lower_bound (range_s, *vectorp, &newr, range_lessthan);
if (i > 0)
{
struct range *bef = VEC_index (range_s, *vectorp, i - 1);
if (ranges_overlap (bef->offset, bef->length, offset, length))
{
/* #1 */
ULONGEST l = min (bef->offset, offset);
ULONGEST h = max (bef->offset + bef->length, offset + length);
bef->offset = l;
bef->length = h - l;
i--;
}
else if (offset == bef->offset + bef->length)
{
/* #2 */
bef->length += length;
i--;
}
else
{
/* #3 */
VEC_safe_insert (range_s, *vectorp, i, &newr);
}
}
else
{
/* #4 */
VEC_safe_insert (range_s, *vectorp, i, &newr);
}
/* Check whether the ranges following the one we've just added or
touched can be folded in (#5 above). */
if (i + 1 < VEC_length (range_s, *vectorp))
{
struct range *t;
struct range *r;
int removed = 0;
int next = i + 1;
/* Get the range we just touched. */
t = VEC_index (range_s, *vectorp, i);
removed = 0;
i = next;
for (; VEC_iterate (range_s, *vectorp, i, r); i++)
if (r->offset <= t->offset + t->length)
{
ULONGEST l, h;
l = min (t->offset, r->offset);
h = max (t->offset + t->length, r->offset + r->length);
t->offset = l;
t->length = h - l;
removed++;
}
else
{
/* If we couldn't merge this one, we won't be able to
merge following ones either, since the ranges are
always sorted by OFFSET. */
break;
}
if (removed != 0)
VEC_block_remove (range_s, *vectorp, next, removed);
}
}
void
mark_value_bits_unavailable (struct value *value, int offset, int length)
{
insert_into_bit_range_vector (&value->unavailable, offset, length);
}
void
mark_value_bytes_unavailable (struct value *value, int offset, int length)
{
mark_value_bits_unavailable (value,
offset * TARGET_CHAR_BIT,
length * TARGET_CHAR_BIT);
}
/* Find the first range in RANGES that overlaps the range defined by
OFFSET and LENGTH, starting at element POS in the RANGES vector,
Returns the index into RANGES where such overlapping range was
found, or -1 if none was found. */
static int
find_first_range_overlap (VEC(range_s) *ranges, int pos,
int offset, int length)
{
range_s *r;
int i;
for (i = pos; VEC_iterate (range_s, ranges, i, r); i++)
if (ranges_overlap (r->offset, r->length, offset, length))
return i;
return -1;
}
/* Compare LENGTH_BITS of memory at PTR1 + OFFSET1_BITS with the memory at
PTR2 + OFFSET2_BITS. Return 0 if the memory is the same, otherwise
return non-zero.
It must always be the case that:
OFFSET1_BITS % TARGET_CHAR_BIT == OFFSET2_BITS % TARGET_CHAR_BIT
It is assumed that memory can be accessed from:
PTR + (OFFSET_BITS / TARGET_CHAR_BIT)
to:
PTR + ((OFFSET_BITS + LENGTH_BITS + TARGET_CHAR_BIT - 1)
/ TARGET_CHAR_BIT) */
static int
memcmp_with_bit_offsets (const gdb_byte *ptr1, size_t offset1_bits,
const gdb_byte *ptr2, size_t offset2_bits,
size_t length_bits)
{
gdb_assert (offset1_bits % TARGET_CHAR_BIT
== offset2_bits % TARGET_CHAR_BIT);
if (offset1_bits % TARGET_CHAR_BIT != 0)
{
size_t bits;
gdb_byte mask, b1, b2;
/* The offset from the base pointers PTR1 and PTR2 is not a complete
number of bytes. A number of bits up to either the next exact
byte boundary, or LENGTH_BITS (which ever is sooner) will be
compared. */
bits = TARGET_CHAR_BIT - offset1_bits % TARGET_CHAR_BIT;
gdb_assert (bits < sizeof (mask) * TARGET_CHAR_BIT);
mask = (1 << bits) - 1;
if (length_bits < bits)
{
mask &= ~(gdb_byte) ((1 << (bits - length_bits)) - 1);
bits = length_bits;
}
/* Now load the two bytes and mask off the bits we care about. */
b1 = *(ptr1 + offset1_bits / TARGET_CHAR_BIT) & mask;
b2 = *(ptr2 + offset2_bits / TARGET_CHAR_BIT) & mask;
if (b1 != b2)
return 1;
/* Now update the length and offsets to take account of the bits
we've just compared. */
length_bits -= bits;
offset1_bits += bits;
offset2_bits += bits;
}
if (length_bits % TARGET_CHAR_BIT != 0)
{
size_t bits;
size_t o1, o2;
gdb_byte mask, b1, b2;
/* The length is not an exact number of bytes. After the previous
IF.. block then the offsets are byte aligned, or the
length is zero (in which case this code is not reached). Compare
a number of bits at the end of the region, starting from an exact
byte boundary. */
bits = length_bits % TARGET_CHAR_BIT;
o1 = offset1_bits + length_bits - bits;
o2 = offset2_bits + length_bits - bits;
gdb_assert (bits < sizeof (mask) * TARGET_CHAR_BIT);
mask = ((1 << bits) - 1) << (TARGET_CHAR_BIT - bits);
gdb_assert (o1 % TARGET_CHAR_BIT == 0);
gdb_assert (o2 % TARGET_CHAR_BIT == 0);
b1 = *(ptr1 + o1 / TARGET_CHAR_BIT) & mask;
b2 = *(ptr2 + o2 / TARGET_CHAR_BIT) & mask;
if (b1 != b2)
return 1;
length_bits -= bits;
}
if (length_bits > 0)
{
/* We've now taken care of any stray "bits" at the start, or end of
the region to compare, the remainder can be covered with a simple
memcmp. */
gdb_assert (offset1_bits % TARGET_CHAR_BIT == 0);
gdb_assert (offset2_bits % TARGET_CHAR_BIT == 0);
gdb_assert (length_bits % TARGET_CHAR_BIT == 0);
return memcmp (ptr1 + offset1_bits / TARGET_CHAR_BIT,
ptr2 + offset2_bits / TARGET_CHAR_BIT,
length_bits / TARGET_CHAR_BIT);
}
/* Length is zero, regions match. */
return 0;
}
/* Helper struct for find_first_range_overlap_and_match and
value_contents_bits_eq. Keep track of which slot of a given ranges
vector have we last looked at. */
struct ranges_and_idx
{
/* The ranges. */
VEC(range_s) *ranges;
/* The range we've last found in RANGES. Given ranges are sorted,
we can start the next lookup here. */
int idx;
};
/* Helper function for value_contents_bits_eq. Compare LENGTH bits of
RP1's ranges starting at OFFSET1 bits with LENGTH bits of RP2's
ranges starting at OFFSET2 bits. Return true if the ranges match
and fill in *L and *H with the overlapping window relative to
(both) OFFSET1 or OFFSET2. */
static int
find_first_range_overlap_and_match (struct ranges_and_idx *rp1,
struct ranges_and_idx *rp2,
int offset1, int offset2,
int length, ULONGEST *l, ULONGEST *h)
{
rp1->idx = find_first_range_overlap (rp1->ranges, rp1->idx,
offset1, length);
rp2->idx = find_first_range_overlap (rp2->ranges, rp2->idx,
offset2, length);
if (rp1->idx == -1 && rp2->idx == -1)
{
*l = length;
*h = length;
return 1;
}
else if (rp1->idx == -1 || rp2->idx == -1)
return 0;
else
{
range_s *r1, *r2;
ULONGEST l1, h1;
ULONGEST l2, h2;
r1 = VEC_index (range_s, rp1->ranges, rp1->idx);
r2 = VEC_index (range_s, rp2->ranges, rp2->idx);
/* Get the unavailable windows intersected by the incoming
ranges. The first and last ranges that overlap the argument
range may be wider than said incoming arguments ranges. */
l1 = max (offset1, r1->offset);
h1 = min (offset1 + length, r1->offset + r1->length);
l2 = max (offset2, r2->offset);
h2 = min (offset2 + length, offset2 + r2->length);
/* Make them relative to the respective start offsets, so we can
compare them for equality. */
l1 -= offset1;
h1 -= offset1;
l2 -= offset2;
h2 -= offset2;
/* Different ranges, no match. */
if (l1 != l2 || h1 != h2)
return 0;
*h = h1;
*l = l1;
return 1;
}
}
/* Helper function for value_contents_eq. The only difference is that
this function is bit rather than byte based.
Compare LENGTH bits of VAL1's contents starting at OFFSET1 bits
with LENGTH bits of VAL2's contents starting at OFFSET2 bits.
Return true if the available bits match. */
static int
value_contents_bits_eq (const struct value *val1, int offset1,
const struct value *val2, int offset2,
int length)
{
/* Each array element corresponds to a ranges source (unavailable,
optimized out). '1' is for VAL1, '2' for VAL2. */
struct ranges_and_idx rp1[2], rp2[2];
/* See function description in value.h. */
gdb_assert (!val1->lazy && !val2->lazy);
/* We shouldn't be trying to compare past the end of the values. */
gdb_assert (offset1 + length
<= TYPE_LENGTH (val1->enclosing_type) * TARGET_CHAR_BIT);
gdb_assert (offset2 + length
<= TYPE_LENGTH (val2->enclosing_type) * TARGET_CHAR_BIT);
memset (&rp1, 0, sizeof (rp1));
memset (&rp2, 0, sizeof (rp2));
rp1[0].ranges = val1->unavailable;
rp2[0].ranges = val2->unavailable;
rp1[1].ranges = val1->optimized_out;
rp2[1].ranges = val2->optimized_out;
while (length > 0)
{
ULONGEST l = 0, h = 0; /* init for gcc -Wall */
int i;
for (i = 0; i < 2; i++)
{
ULONGEST l_tmp, h_tmp;
/* The contents only match equal if the invalid/unavailable
contents ranges match as well. */
if (!find_first_range_overlap_and_match (&rp1[i], &rp2[i],
offset1, offset2, length,
&l_tmp, &h_tmp))
return 0;
/* We're interested in the lowest/first range found. */
if (i == 0 || l_tmp < l)
{
l = l_tmp;
h = h_tmp;
}
}
/* Compare the available/valid contents. */
if (memcmp_with_bit_offsets (val1->contents, offset1,
val2->contents, offset2, l) != 0)
return 0;
length -= h;
offset1 += h;
offset2 += h;
}
return 1;
}
int
value_contents_eq (const struct value *val1, int offset1,
const struct value *val2, int offset2,
int length)
{
return value_contents_bits_eq (val1, offset1 * TARGET_CHAR_BIT,
val2, offset2 * TARGET_CHAR_BIT,
length * TARGET_CHAR_BIT);
}
/* Prototypes for local functions. */
static void show_values (char *, int);
static void show_convenience (char *, int);
/* The value-history records all the values printed
by print commands during this session. Each chunk
records 60 consecutive values. The first chunk on
the chain records the most recent values.
The total number of values is in value_history_count. */
#define VALUE_HISTORY_CHUNK 60
struct value_history_chunk
{
struct value_history_chunk *next;
struct value *values[VALUE_HISTORY_CHUNK];
};
/* Chain of chunks now in use. */
static struct value_history_chunk *value_history_chain;
static int value_history_count; /* Abs number of last entry stored. */
/* List of all value objects currently allocated
(except for those released by calls to release_value)
This is so they can be freed after each command. */
static struct value *all_values;
/* Allocate a lazy value for type TYPE. Its actual content is
"lazily" allocated too: the content field of the return value is
NULL; it will be allocated when it is fetched from the target. */
struct value *
allocate_value_lazy (struct type *type)
{
struct value *val;
/* Call check_typedef on our type to make sure that, if TYPE
is a TYPE_CODE_TYPEDEF, its length is set to the length
of the target type instead of zero. However, we do not
replace the typedef type by the target type, because we want
to keep the typedef in order to be able to set the VAL's type
description correctly. */
check_typedef (type);
val = XCNEW (struct value);
val->contents = NULL;
val->next = all_values;
all_values = val;
val->type = type;
val->enclosing_type = type;
VALUE_LVAL (val) = not_lval;
val->location.address = 0;
VALUE_FRAME_ID (val) = null_frame_id;
val->offset = 0;
val->bitpos = 0;
val->bitsize = 0;
VALUE_REGNUM (val) = -1;
val->lazy = 1;
val->embedded_offset = 0;
val->pointed_to_offset = 0;
val->modifiable = 1;
val->initialized = 1; /* Default to initialized. */
/* Values start out on the all_values chain. */
val->reference_count = 1;
return val;
}
/* Allocate the contents of VAL if it has not been allocated yet. */
static void
allocate_value_contents (struct value *val)
{
if (!val->contents)
val->contents = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
}
/* Allocate a value and its contents for type TYPE. */
struct value *
allocate_value (struct type *type)
{
struct value *val = allocate_value_lazy (type);
allocate_value_contents (val);
val->lazy = 0;
return val;
}
/* Allocate a value that has the correct length
for COUNT repetitions of type TYPE. */
struct value *
allocate_repeat_value (struct type *type, int count)
{
int low_bound = current_language->string_lower_bound; /* ??? */
/* FIXME-type-allocation: need a way to free this type when we are
done with it. */
struct type *array_type
= lookup_array_range_type (type, low_bound, count + low_bound - 1);
return allocate_value (array_type);
}
struct value *
allocate_computed_value (struct type *type,
const struct lval_funcs *funcs,
void *closure)
{
struct value *v = allocate_value_lazy (type);