Bug 1946184 - Fix computing the CSD margin right after calling HideWindowChrome(...
[gecko.git] / tools / profiler / tests / gtest / LulTestInfrastructure.h
blob305ecbeab899099c500547b4c0dc6bfe0692dc8d
1 // -*- mode: C++ -*-
3 // Copyright (c) 2010, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
34 // Derived from:
35 // cfi_assembler.h: Define CFISection, a class for creating properly
36 // (and improperly) formatted DWARF CFI data for unit tests.
38 // Derived from:
39 // test-assembler.h: interface to class for building complex binary streams.
41 // To test the Breakpad symbol dumper and processor thoroughly, for
42 // all combinations of host system and minidump processor
43 // architecture, we need to be able to easily generate complex test
44 // data like debugging information and minidump files.
46 // For example, if we want our unit tests to provide full code
47 // coverage for stack walking, it may be difficult to persuade the
48 // compiler to generate every possible sort of stack walking
49 // information that we want to support; there are probably DWARF CFI
50 // opcodes that GCC never emits. Similarly, if we want to test our
51 // error handling, we will need to generate damaged minidumps or
52 // debugging information that (we hope) the client or compiler will
53 // never produce on its own.
55 // google_breakpad::TestAssembler provides a predictable and
56 // (relatively) simple way to generate complex formatted data streams
57 // like minidumps and CFI. Furthermore, because TestAssembler is
58 // portable, developers without access to (say) Visual Studio or a
59 // SPARC assembler can still work on test data for those targets.
61 #ifndef LUL_TEST_INFRASTRUCTURE_H
62 #define LUL_TEST_INFRASTRUCTURE_H
64 #include "LulDwarfExt.h"
66 #include <string>
67 #include <vector>
69 using std::string;
70 using std::vector;
72 namespace lul_test {
73 namespace test_assembler {
75 // A Label represents a value not yet known that we need to store in a
76 // section. As long as all the labels a section refers to are defined
77 // by the time we retrieve its contents as bytes, we can use undefined
78 // labels freely in that section's construction.
80 // A label can be in one of three states:
81 // - undefined,
82 // - defined as the sum of some other label and a constant, or
83 // - a constant.
85 // A label's value never changes, but it can accumulate constraints.
86 // Adding labels and integers is permitted, and yields a label.
87 // Subtracting a constant from a label is permitted, and also yields a
88 // label. Subtracting two labels that have some relationship to each
89 // other is permitted, and yields a constant.
91 // For example:
93 // Label a; // a's value is undefined
94 // Label b; // b's value is undefined
95 // {
96 // Label c = a + 4; // okay, even though a's value is unknown
97 // b = c + 4; // also okay; b is now a+8
98 // }
99 // Label d = b - 2; // okay; d == a+6, even though c is gone
100 // d.Value(); // error: d's value is not yet known
101 // d - a; // is 6, even though their values are not known
102 // a = 12; // now b == 20, and d == 18
103 // d.Value(); // 18: no longer an error
104 // b.Value(); // 20
105 // d = 10; // error: d is already defined.
107 // Label objects' lifetimes are unconstrained: notice that, in the
108 // above example, even though a and b are only related through c, and
109 // c goes out of scope, the assignment to a sets b's value as well. In
110 // particular, it's not necessary to ensure that a Label lives beyond
111 // Sections that refer to it.
112 class Label {
113 public:
114 Label(); // An undefined label.
115 explicit Label(uint64_t value); // A label with a fixed value
116 Label(const Label& value); // A label equal to another.
117 ~Label();
119 Label& operator=(uint64_t value);
120 Label& operator=(const Label& value);
121 Label operator+(uint64_t addend) const;
122 Label operator-(uint64_t subtrahend) const;
123 uint64_t operator-(const Label& subtrahend) const;
125 // We could also provide == and != that work on undefined, but
126 // related, labels.
128 // Return true if this label's value is known. If VALUE_P is given,
129 // set *VALUE_P to the known value if returning true.
130 bool IsKnownConstant(uint64_t* value_p = NULL) const;
132 // Return true if the offset from LABEL to this label is known. If
133 // OFFSET_P is given, set *OFFSET_P to the offset when returning true.
135 // You can think of l.KnownOffsetFrom(m, &d) as being like 'd = l-m',
136 // except that it also returns a value indicating whether the
137 // subtraction is possible given what we currently know of l and m.
138 // It can be possible even if we don't know l and m's values. For
139 // example:
141 // Label l, m;
142 // m = l + 10;
143 // l.IsKnownConstant(); // false
144 // m.IsKnownConstant(); // false
145 // uint64_t d;
146 // l.IsKnownOffsetFrom(m, &d); // true, and sets d to -10.
147 // l-m // -10
148 // m-l // 10
149 // m.Value() // error: m's value is not known
150 bool IsKnownOffsetFrom(const Label& label, uint64_t* offset_p = NULL) const;
152 private:
153 // A label's value, or if that is not yet known, how the value is
154 // related to other labels' values. A binding may be:
155 // - a known constant,
156 // - constrained to be equal to some other binding plus a constant, or
157 // - unconstrained, and free to take on any value.
159 // Many labels may point to a single binding, and each binding may
160 // refer to another, so bindings and labels form trees whose leaves
161 // are labels, whose interior nodes (and roots) are bindings, and
162 // where links point from children to parents. Bindings are
163 // reference counted, allowing labels to be lightweight, copyable,
164 // assignable, placed in containers, and so on.
165 class Binding {
166 public:
167 Binding();
168 explicit Binding(uint64_t addend);
169 ~Binding();
171 // Increment our reference count.
172 void Acquire() { reference_count_++; };
173 // Decrement our reference count, and return true if it is zero.
174 bool Release() { return --reference_count_ == 0; }
176 // Set this binding to be equal to BINDING + ADDEND. If BINDING is
177 // NULL, then set this binding to the known constant ADDEND.
178 // Update every binding on this binding's chain to point directly
179 // to BINDING, or to be a constant, with addends adjusted
180 // appropriately.
181 void Set(Binding* binding, uint64_t value);
183 // Return what we know about the value of this binding.
184 // - If this binding's value is a known constant, set BASE to
185 // NULL, and set ADDEND to its value.
186 // - If this binding is not a known constant but related to other
187 // bindings, set BASE to the binding at the end of the relation
188 // chain (which will always be unconstrained), and set ADDEND to the
189 // value to add to that binding's value to get this binding's
190 // value.
191 // - If this binding is unconstrained, set BASE to this, and leave
192 // ADDEND unchanged.
193 void Get(Binding** base, uint64_t* addend);
195 private:
196 // There are three cases:
198 // - A binding representing a known constant value has base_ NULL,
199 // and addend_ equal to the value.
201 // - A binding representing a completely unconstrained value has
202 // base_ pointing to this; addend_ is unused.
204 // - A binding whose value is related to some other binding's
205 // value has base_ pointing to that other binding, and addend_
206 // set to the amount to add to that binding's value to get this
207 // binding's value. We only represent relationships of the form
208 // x = y+c.
210 // Thus, the bind_ links form a chain terminating in either a
211 // known constant value or a completely unconstrained value. Most
212 // operations on bindings do path compression: they change every
213 // binding on the chain to point directly to the final value,
214 // adjusting addends as appropriate.
215 Binding* base_;
216 uint64_t addend_;
218 // The number of Labels and Bindings pointing to this binding.
219 // (When a binding points to itself, indicating a completely
220 // unconstrained binding, that doesn't count as a reference.)
221 int reference_count_;
224 // This label's value.
225 Binding* value_;
228 // Conventions for representing larger numbers as sequences of bytes.
229 enum Endianness {
230 kBigEndian, // Big-endian: the most significant byte comes first.
231 kLittleEndian, // Little-endian: the least significant byte comes first.
232 kUnsetEndian, // used internally
235 // A section is a sequence of bytes, constructed by appending bytes
236 // to the end. Sections have a convenient and flexible set of member
237 // functions for appending data in various formats: big-endian and
238 // little-endian signed and unsigned values of different sizes;
239 // LEB128 and ULEB128 values (see below), and raw blocks of bytes.
241 // If you need to append a value to a section that is not convenient
242 // to compute immediately, you can create a label, append the
243 // label's value to the section, and then set the label's value
244 // later, when it's convenient to do so. Once a label's value is
245 // known, the section class takes care of updating all previously
246 // appended references to it.
248 // Once all the labels to which a section refers have had their
249 // values determined, you can get a copy of the section's contents
250 // as a string.
252 // Note that there is no specified "start of section" label. This is
253 // because there are typically several different meanings for "the
254 // start of a section": the offset of the section within an object
255 // file, the address in memory at which the section's content appear,
256 // and so on. It's up to the code that uses the Section class to
257 // keep track of these explicitly, as they depend on the application.
258 class Section {
259 public:
260 explicit Section(Endianness endianness = kUnsetEndian)
261 : endianness_(endianness) {};
263 // A base class destructor should be either public and virtual,
264 // or protected and nonvirtual.
265 virtual ~Section() = default;
267 // Return the default endianness of this section.
268 Endianness endianness() const { return endianness_; }
270 // Append the SIZE bytes at DATA to the end of this section. Return
271 // a reference to this section.
272 Section& Append(const string& data) {
273 contents_.append(data);
274 return *this;
277 // Append data from SLICE to the end of this section. Return
278 // a reference to this section.
279 Section& Append(const lul::ImageSlice& slice) {
280 for (size_t i = 0; i < slice.length_; i++) {
281 contents_.append(1, slice.start_[i]);
283 return *this;
286 // Append data from CSTRING to the end of this section. The terminating
287 // zero is not included. Return a reference to this section.
288 Section& Append(const char* cstring) {
289 for (size_t i = 0; cstring[i] != '\0'; i++) {
290 contents_.append(1, cstring[i]);
292 return *this;
295 // Append SIZE copies of BYTE to the end of this section. Return a
296 // reference to this section.
297 Section& Append(size_t size, uint8_t byte) {
298 contents_.append(size, (char)byte);
299 return *this;
302 // Append NUMBER to this section. ENDIANNESS is the endianness to
303 // use to write the number. SIZE is the length of the number in
304 // bytes. Return a reference to this section.
305 Section& Append(Endianness endianness, size_t size, uint64_t number);
306 Section& Append(Endianness endianness, size_t size, const Label& label);
308 // Append SECTION to the end of this section. The labels SECTION
309 // refers to need not be defined yet.
311 // Note that this has no effect on any Labels' values, or on
312 // SECTION. If placing SECTION within 'this' provides new
313 // constraints on existing labels' values, then it's up to the
314 // caller to fiddle with those labels as needed.
315 Section& Append(const Section& section);
317 // Append the contents of DATA as a series of bytes terminated by
318 // a NULL character.
319 Section& AppendCString(const string& data) {
320 Append(data);
321 contents_ += '\0';
322 return *this;
325 // Append VALUE or LABEL to this section, with the given bit width and
326 // endianness. Return a reference to this section.
328 // The names of these functions have the form <ENDIANNESS><BITWIDTH>:
329 // <ENDIANNESS> is either 'L' (little-endian, least significant byte first),
330 // 'B' (big-endian, most significant byte first), or
331 // 'D' (default, the section's default endianness)
332 // <BITWIDTH> is 8, 16, 32, or 64.
334 // Since endianness doesn't matter for a single byte, all the
335 // <BITWIDTH>=8 functions are equivalent.
337 // These can be used to write both signed and unsigned values, as
338 // the compiler will properly sign-extend a signed value before
339 // passing it to the function, at which point the function's
340 // behavior is the same either way.
341 Section& L8(uint8_t value) {
342 contents_ += value;
343 return *this;
345 Section& B8(uint8_t value) {
346 contents_ += value;
347 return *this;
349 Section& D8(uint8_t value) {
350 contents_ += value;
351 return *this;
353 Section &L16(uint16_t), &L32(uint32_t), &L64(uint64_t), &B16(uint16_t),
354 &B32(uint32_t), &B64(uint64_t), &D16(uint16_t), &D32(uint32_t),
355 &D64(uint64_t);
356 Section &L8(const Label& label), &L16(const Label& label),
357 &L32(const Label& label), &L64(const Label& label),
358 &B8(const Label& label), &B16(const Label& label),
359 &B32(const Label& label), &B64(const Label& label),
360 &D8(const Label& label), &D16(const Label& label),
361 &D32(const Label& label), &D64(const Label& label);
363 // Append VALUE in a signed LEB128 (Little-Endian Base 128) form.
365 // The signed LEB128 representation of an integer N is a variable
366 // number of bytes:
368 // - If N is between -0x40 and 0x3f, then its signed LEB128
369 // representation is a single byte whose value is N.
371 // - Otherwise, its signed LEB128 representation is (N & 0x7f) |
372 // 0x80, followed by the signed LEB128 representation of N / 128,
373 // rounded towards negative infinity.
375 // In other words, we break VALUE into groups of seven bits, put
376 // them in little-endian order, and then write them as eight-bit
377 // bytes with the high bit on all but the last.
379 // Note that VALUE cannot be a Label (we would have to implement
380 // relaxation).
381 Section& LEB128(long long value);
383 // Append VALUE in unsigned LEB128 (Little-Endian Base 128) form.
385 // The unsigned LEB128 representation of an integer N is a variable
386 // number of bytes:
388 // - If N is between 0 and 0x7f, then its unsigned LEB128
389 // representation is a single byte whose value is N.
391 // - Otherwise, its unsigned LEB128 representation is (N & 0x7f) |
392 // 0x80, followed by the unsigned LEB128 representation of N /
393 // 128, rounded towards negative infinity.
395 // Note that VALUE cannot be a Label (we would have to implement
396 // relaxation).
397 Section& ULEB128(uint64_t value);
399 // Jump to the next location aligned on an ALIGNMENT-byte boundary,
400 // relative to the start of the section. Fill the gap with PAD_BYTE.
401 // ALIGNMENT must be a power of two. Return a reference to this
402 // section.
403 Section& Align(size_t alignment, uint8_t pad_byte = 0);
405 // Return the current size of the section.
406 size_t Size() const { return contents_.size(); }
408 // Return a label representing the start of the section.
410 // It is up to the user whether this label represents the section's
411 // position in an object file, the section's address in memory, or
412 // what have you; some applications may need both, in which case
413 // this simple-minded interface won't be enough. This class only
414 // provides a single start label, for use with the Here and Mark
415 // member functions.
417 // Ideally, we'd provide this in a subclass that actually knows more
418 // about the application at hand and can provide an appropriate
419 // collection of start labels. But then the appending member
420 // functions like Append and D32 would return a reference to the
421 // base class, not the derived class, and the chaining won't work.
422 // Since the only value here is in pretty notation, that's a fatal
423 // flaw.
424 Label start() const { return start_; }
426 // Return a label representing the point at which the next Appended
427 // item will appear in the section, relative to start().
428 Label Here() const { return start_ + Size(); }
430 // Set *LABEL to Here, and return a reference to this section.
431 Section& Mark(Label* label) {
432 *label = Here();
433 return *this;
436 // If there are no undefined label references left in this
437 // section, set CONTENTS to the contents of this section, as a
438 // string, and clear this section. Return true on success, or false
439 // if there were still undefined labels.
440 bool GetContents(string* contents);
442 private:
443 // Used internally. A reference to a label's value.
444 struct Reference {
445 Reference(size_t set_offset, Endianness set_endianness, size_t set_size,
446 const Label& set_label)
447 : offset(set_offset),
448 endianness(set_endianness),
449 size(set_size),
450 label(set_label) {}
452 // The offset of the reference within the section.
453 size_t offset;
455 // The endianness of the reference.
456 Endianness endianness;
458 // The size of the reference.
459 size_t size;
461 // The label to which this is a reference.
462 Label label;
465 // The default endianness of this section.
466 Endianness endianness_;
468 // The contents of the section.
469 string contents_;
471 // References to labels within those contents.
472 vector<Reference> references_;
474 // A label referring to the beginning of the section.
475 Label start_;
478 } // namespace test_assembler
479 } // namespace lul_test
481 namespace lul_test {
483 using lul::DwarfPointerEncoding;
484 using lul_test::test_assembler::Endianness;
485 using lul_test::test_assembler::Label;
486 using lul_test::test_assembler::Section;
488 class CFISection : public Section {
489 public:
490 // CFI augmentation strings beginning with 'z', defined by the
491 // Linux/IA-64 C++ ABI, can specify interesting encodings for
492 // addresses appearing in FDE headers and call frame instructions (and
493 // for additional fields whose presence the augmentation string
494 // specifies). In particular, pointers can be specified to be relative
495 // to various base address: the start of the .text section, the
496 // location holding the address itself, and so on. These allow the
497 // frame data to be position-independent even when they live in
498 // write-protected pages. These variants are specified at the
499 // following two URLs:
501 // http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html
502 // http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
504 // CFISection leaves the production of well-formed 'z'-augmented CIEs and
505 // FDEs to the user, but does provide EncodedPointer, to emit
506 // properly-encoded addresses for a given pointer encoding.
507 // EncodedPointer uses an instance of this structure to find the base
508 // addresses it should use; you can establish a default for all encoded
509 // pointers appended to this section with SetEncodedPointerBases.
510 struct EncodedPointerBases {
511 EncodedPointerBases() : cfi(), text(), data() {}
513 // The starting address of this CFI section in memory, for
514 // DW_EH_PE_pcrel. DW_EH_PE_pcrel pointers may only be used in data
515 // that has is loaded into the program's address space.
516 uint64_t cfi;
518 // The starting address of this file's .text section, for DW_EH_PE_textrel.
519 uint64_t text;
521 // The starting address of this file's .got or .eh_frame_hdr section,
522 // for DW_EH_PE_datarel.
523 uint64_t data;
526 // Create a CFISection whose endianness is ENDIANNESS, and where
527 // machine addresses are ADDRESS_SIZE bytes long. If EH_FRAME is
528 // true, use the .eh_frame format, as described by the Linux
529 // Standards Base Core Specification, instead of the DWARF CFI
530 // format.
531 CFISection(Endianness endianness, size_t address_size, bool eh_frame = false)
532 : Section(endianness),
533 address_size_(address_size),
534 eh_frame_(eh_frame),
535 pointer_encoding_(lul::DW_EH_PE_absptr),
536 entry_length_(NULL),
537 in_fde_(false) {
538 // The 'start', 'Here', and 'Mark' members of a CFISection all refer
539 // to section offsets.
540 start() = 0;
543 // Return this CFISection's address size.
544 size_t AddressSize() const { return address_size_; }
546 // Return true if this CFISection uses the .eh_frame format, or
547 // false if it contains ordinary DWARF CFI data.
548 bool ContainsEHFrame() const { return eh_frame_; }
550 // Use ENCODING for pointers in calls to FDEHeader and EncodedPointer.
551 void SetPointerEncoding(DwarfPointerEncoding encoding) {
552 pointer_encoding_ = encoding;
555 // Use the addresses in BASES as the base addresses for encoded
556 // pointers in subsequent calls to FDEHeader or EncodedPointer.
557 // This function makes a copy of BASES.
558 void SetEncodedPointerBases(const EncodedPointerBases& bases) {
559 encoded_pointer_bases_ = bases;
562 // Append a Common Information Entry header to this section with the
563 // given values. If dwarf64 is true, use the 64-bit DWARF initial
564 // length format for the CIE's initial length. Return a reference to
565 // this section. You should call FinishEntry after writing the last
566 // instruction for the CIE.
568 // Before calling this function, you will typically want to use Mark
569 // or Here to make a label to pass to FDEHeader that refers to this
570 // CIE's position in the section.
571 CFISection& CIEHeader(uint64_t code_alignment_factor,
572 int data_alignment_factor,
573 unsigned return_address_register, uint8_t version = 3,
574 const string& augmentation = "", bool dwarf64 = false);
576 // Append a Frame Description Entry header to this section with the
577 // given values. If dwarf64 is true, use the 64-bit DWARF initial
578 // length format for the CIE's initial length. Return a reference to
579 // this section. You should call FinishEntry after writing the last
580 // instruction for the CIE.
582 // This function doesn't support entries that are longer than
583 // 0xffffff00 bytes. (The "initial length" is always a 32-bit
584 // value.) Nor does it support .debug_frame sections longer than
585 // 0xffffff00 bytes.
586 CFISection& FDEHeader(Label cie_pointer, uint64_t initial_location,
587 uint64_t address_range, bool dwarf64 = false);
589 // Note the current position as the end of the last CIE or FDE we
590 // started, after padding with DW_CFA_nops for alignment. This
591 // defines the label representing the entry's length, cited in the
592 // entry's header. Return a reference to this section.
593 CFISection& FinishEntry();
595 // Append the contents of BLOCK as a DW_FORM_block value: an
596 // unsigned LEB128 length, followed by that many bytes of data.
597 CFISection& Block(const lul::ImageSlice& block) {
598 ULEB128(block.length_);
599 Append(block);
600 return *this;
603 // Append data from CSTRING as a DW_FORM_block value: an unsigned LEB128
604 // length, followed by that many bytes of data. The terminating zero is not
605 // included.
606 CFISection& Block(const char* cstring) {
607 ULEB128(strlen(cstring));
608 Append(cstring);
609 return *this;
612 // Append ADDRESS to this section, in the appropriate size and
613 // endianness. Return a reference to this section.
614 CFISection& Address(uint64_t address) {
615 Section::Append(endianness(), address_size_, address);
616 return *this;
619 // Append ADDRESS to this section, using ENCODING and BASES. ENCODING
620 // defaults to this section's default encoding, established by
621 // SetPointerEncoding. BASES defaults to this section's bases, set by
622 // SetEncodedPointerBases. If the DW_EH_PE_indirect bit is set in the
623 // encoding, assume that ADDRESS is where the true address is stored.
624 // Return a reference to this section.
626 // (C++ doesn't let me use default arguments here, because I want to
627 // refer to members of *this in the default argument expression.)
628 CFISection& EncodedPointer(uint64_t address) {
629 return EncodedPointer(address, pointer_encoding_, encoded_pointer_bases_);
631 CFISection& EncodedPointer(uint64_t address, DwarfPointerEncoding encoding) {
632 return EncodedPointer(address, encoding, encoded_pointer_bases_);
634 CFISection& EncodedPointer(uint64_t address, DwarfPointerEncoding encoding,
635 const EncodedPointerBases& bases);
637 // Restate some member functions, to keep chaining working nicely.
638 CFISection& Mark(Label* label) {
639 Section::Mark(label);
640 return *this;
642 CFISection& D8(uint8_t v) {
643 Section::D8(v);
644 return *this;
646 CFISection& D16(uint16_t v) {
647 Section::D16(v);
648 return *this;
650 CFISection& D16(Label v) {
651 Section::D16(v);
652 return *this;
654 CFISection& D32(uint32_t v) {
655 Section::D32(v);
656 return *this;
658 CFISection& D32(const Label& v) {
659 Section::D32(v);
660 return *this;
662 CFISection& D64(uint64_t v) {
663 Section::D64(v);
664 return *this;
666 CFISection& D64(const Label& v) {
667 Section::D64(v);
668 return *this;
670 CFISection& LEB128(long long v) {
671 Section::LEB128(v);
672 return *this;
674 CFISection& ULEB128(uint64_t v) {
675 Section::ULEB128(v);
676 return *this;
679 private:
680 // A length value that we've appended to the section, but is not yet
681 // known. LENGTH is the appended value; START is a label referring
682 // to the start of the data whose length was cited.
683 struct PendingLength {
684 Label length;
685 Label start;
688 // Constants used in CFI/.eh_frame data:
690 // If the first four bytes of an "initial length" are this constant, then
691 // the data uses the 64-bit DWARF format, and the length itself is the
692 // subsequent eight bytes.
693 static const uint32_t kDwarf64InitialLengthMarker = 0xffffffffU;
695 // The CIE identifier for 32- and 64-bit DWARF CFI and .eh_frame data.
696 static const uint32_t kDwarf32CIEIdentifier = ~(uint32_t)0;
697 static const uint64_t kDwarf64CIEIdentifier = ~(uint64_t)0;
698 static const uint32_t kEHFrame32CIEIdentifier = 0;
699 static const uint64_t kEHFrame64CIEIdentifier = 0;
701 // The size of a machine address for the data in this section.
702 size_t address_size_;
704 // If true, we are generating a Linux .eh_frame section, instead of
705 // a standard DWARF .debug_frame section.
706 bool eh_frame_;
708 // The encoding to use for FDE pointers.
709 DwarfPointerEncoding pointer_encoding_;
711 // The base addresses to use when emitting encoded pointers.
712 EncodedPointerBases encoded_pointer_bases_;
714 // The length value for the current entry.
716 // Oddly, this must be dynamically allocated. Labels never get new
717 // values; they only acquire constraints on the value they already
718 // have, or assert if you assign them something incompatible. So
719 // each header needs truly fresh Label objects to cite in their
720 // headers and track their positions. The alternative is explicit
721 // destructor invocation and a placement new. Ick.
722 PendingLength* entry_length_;
724 // True if we are currently emitting an FDE --- that is, we have
725 // called FDEHeader but have not yet called FinishEntry.
726 bool in_fde_;
728 // If in_fde_ is true, this is its starting address. We use this for
729 // emitting DW_EH_PE_funcrel pointers.
730 uint64_t fde_start_address_;
733 } // namespace lul_test
735 #endif // LUL_TEST_INFRASTRUCTURE_H