LLVM 24.0.0git
Dwarf.cpp
Go to the documentation of this file.
1//===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for generic dwarf information.
10//
11//===----------------------------------------------------------------------===//
12
17
18using namespace llvm;
19using namespace dwarf;
20
22 switch (Tag) {
23 default:
24 return StringRef();
25#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
26 case DW_TAG_##NAME: \
27 return "DW_TAG_" #NAME;
28#include "llvm/BinaryFormat/Dwarf.def"
29 }
30}
31
34#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
35 .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
36#include "llvm/BinaryFormat/Dwarf.def"
38}
39
41 switch (Tag) {
42 default:
43 return 0;
44#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
45 case DW_TAG_##NAME: \
46 return VERSION;
47#include "llvm/BinaryFormat/Dwarf.def"
48 }
49}
50
52 switch (Tag) {
53 default:
54 return 0;
55#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
56 case DW_TAG_##NAME: \
57 return DWARF_VENDOR_##VENDOR;
58#include "llvm/BinaryFormat/Dwarf.def"
59 }
60}
61
63 switch (Children) {
64 case DW_CHILDREN_no:
65 return "DW_CHILDREN_no";
66 case DW_CHILDREN_yes:
67 return "DW_CHILDREN_yes";
68 }
69 return StringRef();
70}
71
73 switch (Attribute) {
74 default:
75 return StringRef();
76#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
77 case DW_AT_##NAME: \
78 return "DW_AT_" #NAME;
79#include "llvm/BinaryFormat/Dwarf.def"
80 }
81}
82
84 switch (Attribute) {
85 default:
86 return 0;
87#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
88 case DW_AT_##NAME: \
89 return VERSION;
90#include "llvm/BinaryFormat/Dwarf.def"
91 }
92}
93
95 switch (Attribute) {
96 default:
97 return 0;
98#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
99 case DW_AT_##NAME: \
100 return DWARF_VENDOR_##VENDOR;
101#include "llvm/BinaryFormat/Dwarf.def"
102 }
103}
104
106 switch (Encoding) {
107 default:
108 return StringRef();
109#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
110 case DW_FORM_##NAME: \
111 return "DW_FORM_" #NAME;
112#include "llvm/BinaryFormat/Dwarf.def"
113 }
114}
115
117 switch (Form) {
118 default:
119 return 0;
120#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
121 case DW_FORM_##NAME: \
122 return VERSION;
123#include "llvm/BinaryFormat/Dwarf.def"
124 }
125}
126
128 switch (Form) {
129 default:
130 return 0;
131#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
132 case DW_FORM_##NAME: \
133 return DWARF_VENDOR_##VENDOR;
134#include "llvm/BinaryFormat/Dwarf.def"
135 }
136}
137
139 switch (Encoding) {
140 default:
141 return StringRef();
142#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
143 case DW_OP_##NAME: \
144 return "DW_OP_" #NAME;
145#include "llvm/BinaryFormat/Dwarf.def"
147 return "DW_OP_LLVM_convert";
149 return "DW_OP_LLVM_fragment";
151 return "DW_OP_LLVM_tag_offset";
153 return "DW_OP_LLVM_entry_value";
155 return "DW_OP_LLVM_implicit_pointer";
156 case DW_OP_LLVM_arg:
157 return "DW_OP_LLVM_arg";
159 return "DW_OP_LLVM_extract_bits_sext";
161 return "DW_OP_LLVM_extract_bits_zext";
162 }
163}
164
167#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
168 .Case("DW_OP_" #NAME, DW_OP_##NAME)
169#include "llvm/BinaryFormat/Dwarf.def"
170 .Case("DW_OP_LLVM_convert", DW_OP_LLVM_convert)
171 .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment)
172 .Case("DW_OP_LLVM_tag_offset", DW_OP_LLVM_tag_offset)
173 .Case("DW_OP_LLVM_entry_value", DW_OP_LLVM_entry_value)
174 .Case("DW_OP_LLVM_implicit_pointer", DW_OP_LLVM_implicit_pointer)
175 .Case("DW_OP_LLVM_arg", DW_OP_LLVM_arg)
176 .Case("DW_OP_LLVM_extract_bits_sext", DW_OP_LLVM_extract_bits_sext)
177 .Case("DW_OP_LLVM_extract_bits_zext", DW_OP_LLVM_extract_bits_zext)
178 .Default(0);
179}
180
182 switch (Encoding) {
183 default:
184 llvm_unreachable("unhandled DWARF operation with LLVM user op");
185#define HANDLE_DW_OP_LLVM_USEROP(ID, NAME) \
186 case DW_OP_LLVM_##NAME: \
187 return "DW_OP_LLVM_" #NAME;
188#include "llvm/BinaryFormat/Dwarf.def"
189 }
190}
191
192static unsigned
195#define HANDLE_DW_OP_LLVM_USEROP(ID, NAME) \
196 .Case("DW_OP_LLVM_" #NAME, DW_OP_LLVM_##NAME)
197#include "llvm/BinaryFormat/Dwarf.def"
198 .Default(0);
199 assert(E && "unhandled DWARF operation string with LLVM user op");
200 return E;
201}
202
204 unsigned SubOpEncoding) {
205 assert(OpEncoding == DW_OP_LLVM_user);
206 return LlvmUserOperationEncodingString(SubOpEncoding);
207}
208
209unsigned
215
217 switch (Op) {
218 default:
219 return 0;
220#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
221 case DW_OP_##NAME: \
222 return VERSION;
223#include "llvm/BinaryFormat/Dwarf.def"
224 }
225}
226
228 switch (Op) {
229 default:
230 return std::nullopt;
231#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
232 case DW_OP_##NAME: \
233 if (OPERANDS == -1) \
234 return std::nullopt; \
235 return OPERANDS;
236#include "llvm/BinaryFormat/Dwarf.def"
237 }
238}
239
241 switch (Op) {
242 default:
243 return std::nullopt;
244#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
245 case DW_OP_##NAME: \
246 if (ARITY == -1) \
247 return std::nullopt; \
248 return ARITY;
249#include "llvm/BinaryFormat/Dwarf.def"
250 }
251}
252
254 switch (Op) {
255 default:
256 return 0;
257#define HANDLE_DW_OP(ID, NAME, OPERANDS, ARITY, VERSION, VENDOR) \
258 case DW_OP_##NAME: \
259 return DWARF_VENDOR_##VENDOR;
260#include "llvm/BinaryFormat/Dwarf.def"
261 }
262}
263
265 switch (Encoding) {
266 default:
267 return StringRef();
268#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
269 case DW_ATE_##NAME: \
270 return "DW_ATE_" #NAME;
271#include "llvm/BinaryFormat/Dwarf.def"
272 }
273}
274
276 return StringSwitch<unsigned>(EncodingString)
277#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
278 .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
279#include "llvm/BinaryFormat/Dwarf.def"
280 .Default(0);
281}
282
284 switch (ATE) {
285 default:
286 return 0;
287#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
288 case DW_ATE_##NAME: \
289 return VERSION;
290#include "llvm/BinaryFormat/Dwarf.def"
291 }
292}
293
295 switch (ATE) {
296 default:
297 return 0;
298#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
299 case DW_ATE_##NAME: \
300 return DWARF_VENDOR_##VENDOR;
301#include "llvm/BinaryFormat/Dwarf.def"
302 }
303}
304
306 switch (Sign) {
307 case DW_DS_unsigned:
308 return "DW_DS_unsigned";
310 return "DW_DS_leading_overpunch";
312 return "DW_DS_trailing_overpunch";
314 return "DW_DS_leading_separate";
316 return "DW_DS_trailing_separate";
317 }
318 return StringRef();
319}
320
322 switch (Endian) {
323 case DW_END_default:
324 return "DW_END_default";
325 case DW_END_big:
326 return "DW_END_big";
327 case DW_END_little:
328 return "DW_END_little";
329 case DW_END_lo_user:
330 return "DW_END_lo_user";
331 case DW_END_hi_user:
332 return "DW_END_hi_user";
333 }
334 return StringRef();
335}
336
338 switch (Access) {
339 // Accessibility codes
340 case DW_ACCESS_public:
341 return "DW_ACCESS_public";
343 return "DW_ACCESS_protected";
345 return "DW_ACCESS_private";
346 }
347 return StringRef();
348}
349
350StringRef llvm::dwarf::DefaultedMemberString(unsigned DefaultedEncodings) {
351 switch (DefaultedEncodings) {
352 // Defaulted Member Encodings codes
353 case DW_DEFAULTED_no:
354 return "DW_DEFAULTED_no";
355 case DW_DEFAULTED_in_class:
356 return "DW_DEFAULTED_in_class";
357 case DW_DEFAULTED_out_of_class:
358 return "DW_DEFAULTED_out_of_class";
359 }
360 return StringRef();
361}
362
364 switch (Visibility) {
365 case DW_VIS_local:
366 return "DW_VIS_local";
367 case DW_VIS_exported:
368 return "DW_VIS_exported";
369 case DW_VIS_qualified:
370 return "DW_VIS_qualified";
371 }
372 return StringRef();
373}
374
376 switch (Virtuality) {
377 default:
378 return StringRef();
379#define HANDLE_DW_VIRTUALITY(ID, NAME) \
380 case DW_VIRTUALITY_##NAME: \
381 return "DW_VIRTUALITY_" #NAME;
382#include "llvm/BinaryFormat/Dwarf.def"
383 }
384}
385
388#define HANDLE_DW_VIRTUALITY(ID, NAME) \
389 .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
390#include "llvm/BinaryFormat/Dwarf.def"
392}
393
395 switch (EnumKind) {
396 default:
397 return StringRef();
398#define HANDLE_DW_APPLE_ENUM_KIND(ID, NAME) \
399 case DW_APPLE_ENUM_KIND_##NAME: \
400 return "DW_APPLE_ENUM_KIND_" #NAME;
401#include "llvm/BinaryFormat/Dwarf.def"
402 }
403}
404
407#define HANDLE_DW_APPLE_ENUM_KIND(ID, NAME) \
408 .Case("DW_APPLE_ENUM_KIND_" #NAME, DW_APPLE_ENUM_KIND_##NAME)
409#include "llvm/BinaryFormat/Dwarf.def"
411}
412
414 switch (Language) {
415 default:
416 return StringRef();
417#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
418 case DW_LANG_##NAME: \
419 return "DW_LANG_" #NAME;
420#include "llvm/BinaryFormat/Dwarf.def"
421 }
422}
423
426#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
427 .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
428#include "llvm/BinaryFormat/Dwarf.def"
429 .Default(0);
430}
431
433 switch (Lang) {
434 default:
435 return 0;
436#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
437 case DW_LANG_##NAME: \
438 return VERSION;
439#include "llvm/BinaryFormat/Dwarf.def"
440 }
441}
442
444 switch (Lang) {
445 default:
446 return 0;
447#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
448 case DW_LANG_##NAME: \
449 return DWARF_VENDOR_##VENDOR;
450#include "llvm/BinaryFormat/Dwarf.def"
451 }
452}
453
454std::optional<unsigned>
456 switch (Lang) {
457 default:
458 return std::nullopt;
459#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
460 case DW_LANG_##NAME: \
461 return LOWER_BOUND;
462#include "llvm/BinaryFormat/Dwarf.def"
463 }
464}
465
467 switch (lname) {
468#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) \
469 case DW_LNAME_##NAME: \
470 return DESC;
471#include "llvm/BinaryFormat/Dwarf.def"
472 }
473 return "Unknown";
474}
475
478 switch (Name) {
479 // YYYY
480 case DW_LNAME_Ada: {
481 if (Version <= 1983)
482 return "Ada 83";
483 if (Version <= 1995)
484 return "Ada 95";
485 if (Version <= 2005)
486 return "Ada 2005";
487 if (Version <= 2012)
488 return "Ada 2012";
489 } break;
490
491 case DW_LNAME_Cobol: {
492 if (Version <= 1974)
493 return "COBOL-74";
494 if (Version <= 1985)
495 return "COBOL-85";
496 } break;
497
498 case DW_LNAME_Fortran: {
499 if (Version <= 1977)
500 return "FORTRAN 77";
501 if (Version <= 1990)
502 return "FORTRAN 90";
503 if (Version <= 1995)
504 return "Fortran 95";
505 if (Version <= 2003)
506 return "Fortran 2003";
507 if (Version <= 2008)
508 return "Fortran 2008";
509 if (Version <= 2018)
510 return "Fortran 2018";
511 if (Version <= 2023)
512 return "Fortran 2023";
513 } break;
514
515 // YYYYMM
516 case DW_LNAME_C: {
517 if (Version == 0)
518 break;
519 if (Version <= 198912)
520 return "C89";
521 if (Version <= 199901)
522 return "C99";
523 if (Version <= 201112)
524 return "C11";
525 if (Version <= 201710)
526 return "C17";
527 if (Version <= 202311)
528 return "C23";
529 } break;
530
531 case DW_LNAME_C_plus_plus: {
532 if (Version == 0)
533 break;
534 if (Version <= 199711)
535 return "C++98";
536 if (Version <= 200310)
537 return "C++03";
538 if (Version <= 201103)
539 return "C++11";
540 if (Version <= 201402)
541 return "C++14";
542 if (Version <= 201703)
543 return "C++17";
544 if (Version <= 202002)
545 return "C++20";
546 if (Version <= 202302)
547 return "C++23";
548 } break;
549
550 case DW_LNAME_ObjC_plus_plus:
551 case DW_LNAME_ObjC:
552 case DW_LNAME_Move:
553 case DW_LNAME_SYCL:
554 case DW_LNAME_BLISS:
555 case DW_LNAME_Crystal:
556 case DW_LNAME_D:
557 case DW_LNAME_Dylan:
558 case DW_LNAME_Go:
559 case DW_LNAME_Haskell:
560 case DW_LNAME_HIP:
561 case DW_LNAME_HLSL:
562 case DW_LNAME_Java:
563 case DW_LNAME_Julia:
564 case DW_LNAME_Kotlin:
565 case DW_LNAME_Modula2:
566 case DW_LNAME_Modula3:
567 case DW_LNAME_OCaml:
568 case DW_LNAME_OpenCL_C:
569 case DW_LNAME_Pascal:
570 case DW_LNAME_PLI:
571 case DW_LNAME_Python:
572 case DW_LNAME_RenderScript:
573 case DW_LNAME_Rust:
574 case DW_LNAME_Swift:
575 case DW_LNAME_UPC:
576 case DW_LNAME_Zig:
577 case DW_LNAME_Assembly:
578 case DW_LNAME_C_sharp:
579 case DW_LNAME_Mojo:
580 case DW_LNAME_GLSL:
581 case DW_LNAME_GLSL_ES:
582 case DW_LNAME_OpenCL_CPP:
583 case DW_LNAME_CPP_for_OpenCL:
584 case DW_LNAME_Ruby:
585 case DW_LNAME_Hylo:
586 case DW_LNAME_Metal:
587 case DW_LNAME_Odin:
588 case DW_LNAME_P4:
589 case DW_LNAME_V:
590 case DW_LNAME_Algol68:
591 case DW_LNAME_Nim:
592 case DW_LNAME_Erlang:
593 case DW_LNAME_Elixir:
594 case DW_LNAME_Gleam:
595 break;
596 }
597
598 // Fallback to un-versioned name.
599 return LanguageDescription(Name);
600}
601
603 switch (Lang) {
604#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) \
605 case DW_LNAME_##NAME: \
606 return "DW_LNAME_" #NAME;
607#include "llvm/BinaryFormat/Dwarf.def"
608 }
609
610 return {};
611}
612
613unsigned
616#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) \
617 .Case("DW_LNAME_" #NAME, DW_LNAME_##NAME)
618#include "llvm/BinaryFormat/Dwarf.def"
619 .Default(0);
620}
621
623 switch (LanguageDialect) {
624 default:
625 return StringRef();
626#define HANDLE_DW_LLVM_LANG_DIALECT(ID, NAME) \
627 case DW_LLVM_LANG_DIALECT_##NAME: \
628 return "DW_LLVM_LANG_DIALECT_" #NAME;
629#include "llvm/BinaryFormat/Dwarf.def"
630 }
631}
632
634 // Return ~0U for unrecognized spellings. The "no dialect" state is
635 // represented by numeric 0 (i.e. omitting the field); there is no
636 // corresponding symbolic enumerator for it.
638#define HANDLE_DW_LLVM_LANG_DIALECT(ID, NAME) \
639 .Case("DW_LLVM_LANG_DIALECT_" #NAME, DW_LLVM_LANG_DIALECT_##NAME)
640#include "llvm/BinaryFormat/Dwarf.def"
641 .Default(~0U);
642}
643
645 switch (Case) {
647 return "DW_ID_case_sensitive";
648 case DW_ID_up_case:
649 return "DW_ID_up_case";
650 case DW_ID_down_case:
651 return "DW_ID_down_case";
653 return "DW_ID_case_insensitive";
654 }
655 return StringRef();
656}
657
659 switch (CC) {
660 default:
661 return StringRef();
662#define HANDLE_DW_CC(ID, NAME) \
663 case DW_CC_##NAME: \
664 return "DW_CC_" #NAME;
665#include "llvm/BinaryFormat/Dwarf.def"
666 }
667}
668
670 return StringSwitch<unsigned>(CCString)
671#define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
672#include "llvm/BinaryFormat/Dwarf.def"
673 .Default(0);
674}
675
677 switch (Code) {
679 return "DW_INL_not_inlined";
680 case DW_INL_inlined:
681 return "DW_INL_inlined";
683 return "DW_INL_declared_not_inlined";
685 return "DW_INL_declared_inlined";
686 }
687 return StringRef();
688}
689
691 switch (Order) {
692 case DW_ORD_row_major:
693 return "DW_ORD_row_major";
694 case DW_ORD_col_major:
695 return "DW_ORD_col_major";
696 }
697 return StringRef();
698}
699
701 switch (Standard) {
702 default:
703 return StringRef();
704#define HANDLE_DW_LNS(ID, NAME) \
705 case DW_LNS_##NAME: \
706 return "DW_LNS_" #NAME;
707#include "llvm/BinaryFormat/Dwarf.def"
708 }
709}
710
712 switch (Encoding) {
713 default:
714 return StringRef();
715#define HANDLE_DW_LNE(ID, NAME) \
716 case DW_LNE_##NAME: \
717 return "DW_LNE_" #NAME;
718#include "llvm/BinaryFormat/Dwarf.def"
719 }
720}
721
723 switch (Encoding) {
724 // Macinfo Type Encodings
726 return "DW_MACINFO_define";
727 case DW_MACINFO_undef:
728 return "DW_MACINFO_undef";
730 return "DW_MACINFO_start_file";
732 return "DW_MACINFO_end_file";
734 return "DW_MACINFO_vendor_ext";
736 return "DW_MACINFO_invalid";
737 }
738 return StringRef();
739}
740
743 .Case("DW_MACINFO_define", DW_MACINFO_define)
744 .Case("DW_MACINFO_undef", DW_MACINFO_undef)
745 .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
746 .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
747 .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
749}
750
752 switch (Encoding) {
753 default:
754 return StringRef();
755#define HANDLE_DW_MACRO(ID, NAME) \
756 case DW_MACRO_##NAME: \
757 return "DW_MACRO_" #NAME;
758#include "llvm/BinaryFormat/Dwarf.def"
759 }
760}
761
763 switch (Encoding) {
764 default:
765 return StringRef();
766#define HANDLE_DW_MACRO_GNU(ID, NAME) \
767 case DW_MACRO_GNU_##NAME: \
768 return "DW_MACRO_GNU_" #NAME;
769#include "llvm/BinaryFormat/Dwarf.def"
770 }
771}
772
775#define HANDLE_DW_MACRO(ID, NAME) .Case("DW_MACRO_" #NAME, ID)
776#include "llvm/BinaryFormat/Dwarf.def"
778}
780 switch (Encoding) {
781 default:
782 return StringRef();
783#define HANDLE_DW_RLE(ID, NAME) \
784 case DW_RLE_##NAME: \
785 return "DW_RLE_" #NAME;
786#include "llvm/BinaryFormat/Dwarf.def"
787 }
788}
789
791 switch (Encoding) {
792 default:
793 return StringRef();
794#define HANDLE_DW_LLE(ID, NAME) \
795 case DW_LLE_##NAME: \
796 return "DW_LLE_" #NAME;
797#include "llvm/BinaryFormat/Dwarf.def"
798 }
799}
800
802 Triple::ArchType Arch) {
804#define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64)
805#define SELECT_MIPS64 Arch == llvm::Triple::mips64
806#define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9)
807#define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
808#define HANDLE_DW_CFA(ID, NAME)
809#define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \
810 if (ID == Encoding && PRED) \
811 return "DW_CFA_" #NAME;
812#include "llvm/BinaryFormat/Dwarf.def"
813
814 switch (Encoding) {
815 default:
816 return StringRef();
817#define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
818#define HANDLE_DW_CFA(ID, NAME) \
819 case DW_CFA_##NAME: \
820 return "DW_CFA_" #NAME;
821#include "llvm/BinaryFormat/Dwarf.def"
822
823#undef SELECT_X86
824#undef SELECT_SPARC
825#undef SELECT_MIPS64
826#undef SELECT_AARCH64
827 }
828}
829
831 switch (Prop) {
832 default:
833 return StringRef();
834#define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
835 case DW_APPLE_PROPERTY_##NAME: \
836 return "DW_APPLE_PROPERTY_" #NAME;
837#include "llvm/BinaryFormat/Dwarf.def"
838 }
839}
840
842 switch (UT) {
843 default:
844 return StringRef();
845#define HANDLE_DW_UT(ID, NAME) \
846 case DW_UT_##NAME: \
847 return "DW_UT_" #NAME;
848#include "llvm/BinaryFormat/Dwarf.def"
849 }
850}
851
853 switch (AT) {
855 return "DW_ATOM_null";
857 return "DW_ATOM_die_offset";
859 return "DW_ATOM_cu_offset";
860 case DW_ATOM_die_tag:
861 return "DW_ATOM_die_tag";
864 return "DW_ATOM_type_flags";
866 return "DW_ATOM_qual_name_hash";
867 }
868 return StringRef();
869}
870
872 switch (Kind) {
873 case GIEK_NONE:
874 return "NONE";
875 case GIEK_TYPE:
876 return "TYPE";
877 case GIEK_VARIABLE:
878 return "VARIABLE";
879 case GIEK_FUNCTION:
880 return "FUNCTION";
881 case GIEK_OTHER:
882 return "OTHER";
883 case GIEK_UNUSED5:
884 return "UNUSED5";
885 case GIEK_UNUSED6:
886 return "UNUSED6";
887 case GIEK_UNUSED7:
888 return "UNUSED7";
889 }
890 llvm_unreachable("Unknown GDBIndexEntryKind value");
891}
892
895 switch (Linkage) {
896 case GIEL_EXTERNAL:
897 return "EXTERNAL";
898 case GIEL_STATIC:
899 return "STATIC";
900 }
901 llvm_unreachable("Unknown GDBIndexEntryLinkage value");
902}
903
905 switch (Attr) {
906 case DW_AT_accessibility:
907 return AccessibilityString(Val);
908 case DW_AT_virtuality:
909 return VirtualityString(Val);
910 case DW_AT_language:
911 return LanguageString(Val);
912 case DW_AT_LLVM_language_dialect:
913 return LanguageDialectString(Val);
914 case DW_AT_encoding:
915 return AttributeEncodingString(Val);
916 case DW_AT_decimal_sign:
917 return DecimalSignString(Val);
918 case DW_AT_endianity:
919 return EndianityString(Val);
920 case DW_AT_visibility:
921 return VisibilityString(Val);
922 case DW_AT_identifier_case:
923 return CaseString(Val);
924 case DW_AT_calling_convention:
925 return ConventionString(Val);
926 case DW_AT_inline:
927 return InlineCodeString(Val);
928 case DW_AT_ordering:
929 return ArrayOrderString(Val);
930 case DW_AT_APPLE_runtime_class:
931 return LanguageString(Val);
932 case DW_AT_defaulted:
933 return DefaultedMemberString(Val);
934 case DW_AT_APPLE_enum_kind:
935 return EnumKindString(Val);
936 case DW_AT_language_name:
937 return SourceLanguageNameString(static_cast<SourceLanguageName>(Val));
938 }
939
940 return StringRef();
941}
942
944 switch (Atom) {
945 case DW_ATOM_null:
946 return "NULL";
947 case DW_ATOM_die_tag:
948 return TagString(Val);
949 }
950
951 return StringRef();
952}
953
955 switch (Idx) {
956 default:
957 return StringRef();
958#define HANDLE_DW_IDX(ID, NAME) \
959 case DW_IDX_##NAME: \
960 return "DW_IDX_" #NAME;
961#include "llvm/BinaryFormat/Dwarf.def"
962 }
963}
964
966 FormParams Params) {
967 switch (Form) {
968 case DW_FORM_addr:
969 if (Params)
970 return Params.AddrSize;
971 return std::nullopt;
972
973 case DW_FORM_block: // ULEB128 length L followed by L bytes.
974 case DW_FORM_block1: // 1 byte length L followed by L bytes.
975 case DW_FORM_block2: // 2 byte length L followed by L bytes.
976 case DW_FORM_block4: // 4 byte length L followed by L bytes.
977 case DW_FORM_string: // C-string with null terminator.
978 case DW_FORM_sdata: // SLEB128.
979 case DW_FORM_udata: // ULEB128.
980 case DW_FORM_ref_udata: // ULEB128.
981 case DW_FORM_indirect: // ULEB128.
982 case DW_FORM_exprloc: // ULEB128 length L followed by L bytes.
983 case DW_FORM_strx: // ULEB128.
984 case DW_FORM_addrx: // ULEB128.
985 case DW_FORM_loclistx: // ULEB128.
986 case DW_FORM_rnglistx: // ULEB128.
987 case DW_FORM_GNU_addr_index: // ULEB128.
988 case DW_FORM_GNU_str_index: // ULEB128.
989 return std::nullopt;
990
991 case DW_FORM_ref_addr:
992 if (Params)
993 return Params.getRefAddrByteSize();
994 return std::nullopt;
995
996 case DW_FORM_flag:
997 case DW_FORM_data1:
998 case DW_FORM_ref1:
999 case DW_FORM_strx1:
1000 case DW_FORM_addrx1:
1001 return 1;
1002
1003 case DW_FORM_data2:
1004 case DW_FORM_ref2:
1005 case DW_FORM_strx2:
1006 case DW_FORM_addrx2:
1007 return 2;
1008
1009 case DW_FORM_strx3:
1010 case DW_FORM_addrx3:
1011 return 3;
1012
1013 case DW_FORM_data4:
1014 case DW_FORM_ref4:
1015 case DW_FORM_ref_sup4:
1016 case DW_FORM_strx4:
1017 case DW_FORM_addrx4:
1018 return 4;
1019
1020 case DW_FORM_strp:
1021 case DW_FORM_GNU_ref_alt:
1022 case DW_FORM_GNU_strp_alt:
1023 case DW_FORM_line_strp:
1024 case DW_FORM_sec_offset:
1025 case DW_FORM_strp_sup:
1026 if (Params)
1027 return Params.getDwarfOffsetByteSize();
1028 return std::nullopt;
1029
1030 case DW_FORM_data8:
1031 case DW_FORM_ref8:
1032 case DW_FORM_ref_sig8:
1033 case DW_FORM_ref_sup8:
1034 return 8;
1035
1036 case DW_FORM_flag_present:
1037 return 0;
1038
1039 case DW_FORM_data16:
1040 return 16;
1041
1042 case DW_FORM_implicit_const:
1043 // The implicit value is stored in the abbreviation as a SLEB128, and
1044 // there no data in debug info.
1045 return 0;
1046
1047 default:
1048 break;
1049 }
1050 return std::nullopt;
1051}
1052
1054 bool ExtensionsOk) {
1056 unsigned FV = FormVersion(F);
1057 return FV > 0 && FV <= Version;
1058 }
1059 return ExtensionsOk;
1060}
1061
1063 switch (Format) {
1064 case DWARF32:
1065 return "DWARF32";
1066 case DWARF64:
1067 return "DWARF64";
1068 }
1069 return StringRef();
1070}
1071
1073 return FormatString(IsDWARF64 ? DWARF64 : DWARF32);
1074}
1075
1077 switch (RLE) {
1078 default:
1079 return StringRef();
1080#define HANDLE_DW_RLE(ID, NAME) \
1081 case DW_RLE_##NAME: \
1082 return "DW_RLE_" #NAME;
1083#include "llvm/BinaryFormat/Dwarf.def"
1084 }
1085}
1086
1088 switch (AS) {
1089#define HANDLE_DW_ASPACE(ID, NAME) \
1090 case DW_ASPACE_LLVM_##NAME: \
1091 return "DW_ASPACE_LLVM_" #NAME;
1092#define HANDLE_DW_ASPACE_PRED(ID, NAME, PRED)
1093#include "llvm/BinaryFormat/Dwarf.def"
1094 default:
1095 break;
1096 }
1097
1098 bool SELECT_AMDGPU = TT.isAMDGPU();
1099#define HANDLE_DW_ASPACE(ID, NAME)
1100#define HANDLE_DW_ASPACE_PRED(ID, NAME, PRED) \
1101 if (DW_ASPACE_LLVM_##NAME == AS && PRED) \
1102 return "DW_ASPACE_LLVM_" #NAME;
1103#include "llvm/BinaryFormat/Dwarf.def"
1104
1105 return "";
1106}
1107
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DXIL Resource Access
static unsigned getLlvmUserOperationEncoding(StringRef LlvmUserOperationEncodingString)
Definition Dwarf.cpp:193
static StringRef LlvmUserOperationEncodingString(unsigned Encoding)
Definition Dwarf.cpp:181
This file contains constants used for implementing Dwarf debug support.
#define F(x, y, z)
Definition MD5.cpp:54
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
@ UnknownArch
Definition Triple.h:51
LLVM_ABI StringRef LNExtendedString(unsigned Encoding)
Definition Dwarf.cpp:711
LLVM_ABI StringRef RangeListEncodingString(unsigned Encoding)
Definition Dwarf.cpp:779
LLVM_ABI StringRef LanguageDialectString(unsigned LanguageDialect)
Definition Dwarf.cpp:622
LLVM_ABI StringRef CaseString(unsigned Case)
Definition Dwarf.cpp:644
LLVM_ABI StringRef SourceLanguageNameString(SourceLanguageName Lang)
Definition Dwarf.cpp:602
LLVM_ABI StringRef VisibilityString(unsigned Visibility)
Definition Dwarf.cpp:363
LLVM_ABI StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition Dwarf.cpp:894
LLVM_ABI StringRef AttributeString(unsigned Attribute)
Definition Dwarf.cpp:72
LLVM_ABI StringRef CallFrameString(unsigned Encoding, Triple::ArchType Arch)
Definition Dwarf.cpp:801
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
Definition Dwarf.cpp:105
LLVM_ABI StringRef ArrayOrderString(unsigned Order)
Definition Dwarf.cpp:690
LLVM_ABI StringRef MacroString(unsigned Encoding)
Definition Dwarf.cpp:751
LLVM_ABI StringRef EnumKindString(unsigned EnumKind)
Definition Dwarf.cpp:394
LLVM_ABI StringRef LocListEncodingString(unsigned Encoding)
Definition Dwarf.cpp:790
LLVM_ABI StringRef IndexString(unsigned Idx)
Definition Dwarf.cpp:954
LLVM_ABI StringRef RLEString(unsigned RLE)
Definition Dwarf.cpp:1076
LLVM_ABI StringRef SubOperationEncodingString(unsigned OpEncoding, unsigned SubOpEncoding)
Definition Dwarf.cpp:203
LLVM_ABI StringRef LanguageString(unsigned Language)
Definition Dwarf.cpp:413
LLVM_ABI StringRef DecimalSignString(unsigned Sign)
Definition Dwarf.cpp:305
LLVM_ABI StringRef VirtualityString(unsigned Virtuality)
Definition Dwarf.cpp:375
LLVM_ABI StringRef AttributeEncodingString(unsigned Encoding)
Definition Dwarf.cpp:264
LLVM_ABI StringRef AddressSpaceString(unsigned AS, const llvm::Triple &TT)
Definition Dwarf.cpp:1087
LLVM_ABI StringRef ChildrenString(unsigned Children)
Definition Dwarf.cpp:62
LLVM_ABI StringRef ApplePropertyString(unsigned)
Definition Dwarf.cpp:830
LLVM_ABI StringRef AtomTypeString(unsigned Atom)
Definition Dwarf.cpp:852
LLVM_ABI StringRef FormatString(DwarfFormat Format)
Definition Dwarf.cpp:1062
LLVM_ABI StringRef GnuMacroString(unsigned Encoding)
Definition Dwarf.cpp:762
LLVM_ABI StringRef EndianityString(unsigned Endian)
Definition Dwarf.cpp:321
LLVM_ABI StringRef ConventionString(unsigned Convention)
Definition Dwarf.cpp:658
LLVM_ABI StringRef MacinfoString(unsigned Encoding)
Definition Dwarf.cpp:722
LLVM_ABI StringRef OperationEncodingString(unsigned Encoding)
Definition Dwarf.cpp:138
LLVM_ABI StringRef UnitTypeString(unsigned)
Definition Dwarf.cpp:841
LLVM_ABI StringRef InlineCodeString(unsigned Code)
Definition Dwarf.cpp:676
LLVM_ABI StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition Dwarf.cpp:871
LLVM_ABI StringRef TagString(unsigned Tag)
Definition Dwarf.cpp:21
LLVM_ABI StringRef LNStandardString(unsigned Standard)
Definition Dwarf.cpp:700
LLVM_ABI StringRef AccessibilityString(unsigned Access)
Definition Dwarf.cpp:337
LLVM_ABI StringRef DefaultedMemberString(unsigned DefaultedEncodings)
Definition Dwarf.cpp:350
LLVM_ABI unsigned getSourceLanguageName(StringRef SourceLanguageNameString)
Definition Dwarf.cpp:614
LLVM_ABI unsigned getSubOperationEncoding(unsigned OpEncoding, StringRef SubOperationEncodingString)
Definition Dwarf.cpp:210
LLVM_ABI unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition Dwarf.cpp:165
LLVM_ABI unsigned getAttributeEncoding(StringRef EncodingString)
Definition Dwarf.cpp:275
LLVM_ABI unsigned getLanguageDialect(StringRef LanguageDialectString)
Definition Dwarf.cpp:633
LLVM_ABI unsigned getTag(StringRef TagString)
Definition Dwarf.cpp:32
LLVM_ABI unsigned getCallingConvention(StringRef LanguageString)
Definition Dwarf.cpp:669
LLVM_ABI unsigned getLanguage(StringRef LanguageString)
Definition Dwarf.cpp:424
LLVM_ABI unsigned getVirtuality(StringRef VirtualityString)
Definition Dwarf.cpp:386
LLVM_ABI unsigned getEnumKind(StringRef EnumKindString)
Definition Dwarf.cpp:405
LLVM_ABI unsigned getMacro(StringRef MacroString)
Definition Dwarf.cpp:773
LLVM_ABI unsigned getMacinfo(StringRef MacinfoString)
Definition Dwarf.cpp:741
LLVM_ABI unsigned AttributeEncodingVendor(TypeKind E)
Definition Dwarf.cpp:294
LLVM_ABI unsigned FormVendor(Form F)
Definition Dwarf.cpp:127
LLVM_ABI unsigned AttributeVendor(Attribute A)
Definition Dwarf.cpp:94
LLVM_ABI unsigned OperationVendor(LocationAtom O)
Definition Dwarf.cpp:253
LLVM_ABI unsigned TagVendor(Tag T)
Definition Dwarf.cpp:51
LLVM_ABI unsigned LanguageVendor(SourceLanguage L)
Definition Dwarf.cpp:443
LLVM_ABI unsigned OperationVersion(LocationAtom O)
Definition Dwarf.cpp:216
LLVM_ABI unsigned AttributeVersion(Attribute A)
Definition Dwarf.cpp:83
LLVM_ABI unsigned LanguageVersion(SourceLanguage L)
Definition Dwarf.cpp:432
LLVM_ABI unsigned AttributeEncodingVersion(TypeKind E)
Definition Dwarf.cpp:283
LLVM_ABI unsigned TagVersion(Tag T)
Definition Dwarf.cpp:40
LLVM_ABI unsigned FormVersion(Form F)
Definition Dwarf.cpp:116
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
@ DW_INL_not_inlined
Definition Dwarf.h:859
@ DW_INL_declared_not_inlined
Definition Dwarf.h:861
@ DW_INL_inlined
Definition Dwarf.h:860
@ DW_INL_declared_inlined
Definition Dwarf.h:862
@ DW_ACCESS_private
Definition Dwarf.h:187
@ DW_ACCESS_protected
Definition Dwarf.h:186
@ DW_ACCESS_public
Definition Dwarf.h:185
Attribute
Attributes.
Definition Dwarf.h:125
LLVM_ABI std::optional< unsigned > LanguageLowerBound(SourceLanguage L)
Definition Dwarf.cpp:455
LLVM_ABI StringRef AtomValueString(uint16_t Atom, unsigned Val)
Returns the symbolic string representing Val when used as a value for atom Atom.
Definition Dwarf.cpp:943
SourceLanguageName
Definition Dwarf.h:229
LLVM_ABI std::optional< unsigned > OperationArity(LocationAtom O)
The arity of the given LocationAtom.
Definition Dwarf.cpp:240
@ DW_VIS_local
Definition Dwarf.h:192
@ DW_VIS_exported
Definition Dwarf.h:193
@ DW_VIS_qualified
Definition Dwarf.h:194
@ DW_ORD_row_major
Definition Dwarf.h:867
@ DW_ORD_col_major
Definition Dwarf.h:868
@ DW_END_lo_user
Definition Dwarf.h:179
@ DW_END_hi_user
Definition Dwarf.h:180
@ DW_OP_LLVM_entry_value
Only used in LLVM metadata.
Definition Dwarf.h:147
@ DW_OP_LLVM_implicit_pointer
Only used in LLVM metadata.
Definition Dwarf.h:148
@ DW_OP_LLVM_extract_bits_zext
Only used in LLVM metadata.
Definition Dwarf.h:151
@ DW_OP_LLVM_tag_offset
Only used in LLVM metadata.
Definition Dwarf.h:146
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Definition Dwarf.h:144
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition Dwarf.h:149
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
Definition Dwarf.h:145
@ DW_OP_LLVM_extract_bits_sext
Only used in LLVM metadata.
Definition Dwarf.h:150
@ DW_ID_down_case
Definition Dwarf.h:839
@ DW_ID_case_insensitive
Definition Dwarf.h:840
@ DW_ID_case_sensitive
Definition Dwarf.h:837
@ DW_ID_up_case
Definition Dwarf.h:838
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition Dwarf.h:93
@ DWARF64
Definition Dwarf.h:93
@ DWARF32
Definition Dwarf.h:93
LLVM_ABI bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition Dwarf.cpp:1053
@ DW_MACINFO_undef
Definition Dwarf.h:901
@ DW_MACINFO_start_file
Definition Dwarf.h:902
@ DW_MACINFO_end_file
Definition Dwarf.h:903
@ DW_MACINFO_define
Definition Dwarf.h:900
@ DW_MACINFO_vendor_ext
Definition Dwarf.h:904
LLVM_ABI std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition Dwarf.cpp:965
GDBIndexEntryKind
Definition Dwarf.h:1054
@ GIEK_UNUSED7
Definition Dwarf.h:1062
@ GIEK_UNUSED6
Definition Dwarf.h:1061
@ GIEK_FUNCTION
Definition Dwarf.h:1058
@ GIEK_UNUSED5
Definition Dwarf.h:1060
@ GIEK_VARIABLE
Definition Dwarf.h:1057
@ DW_CHILDREN_no
Definition Dwarf.h:948
@ DW_CHILDREN_yes
Definition Dwarf.h:949
LLVM_ABI StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition Dwarf.cpp:904
LLVM_ABI std::optional< unsigned > OperationOperands(LocationAtom O)
The number of operands for the given LocationAtom.
Definition Dwarf.cpp:227
@ DW_DS_leading_separate
Definition Dwarf.h:171
@ DW_DS_trailing_separate
Definition Dwarf.h:172
@ DW_DS_trailing_overpunch
Definition Dwarf.h:170
@ DW_DS_leading_overpunch
Definition Dwarf.h:169
@ DW_DS_unsigned
Definition Dwarf.h:168
LLVM_ABI llvm::StringRef LanguageDescription(SourceLanguageName name)
Returns a version-independent language name.
Definition Dwarf.cpp:466
@ DW_ATOM_type_flags
Definition Dwarf.h:1027
@ DW_ATOM_null
Definition Dwarf.h:1022
@ DW_ATOM_die_tag
Definition Dwarf.h:1026
@ DW_ATOM_qual_name_hash
Definition Dwarf.h:1030
@ DW_ATOM_die_offset
Marker as the end of a list of atoms.
Definition Dwarf.h:1023
@ DW_ATOM_type_type_flags
Definition Dwarf.h:1029
@ DW_ATOM_cu_offset
Definition Dwarf.h:1024
@ DW_TAG_invalid
LLVM mock tags (see also llvm/BinaryFormat/Dwarf.def).
Definition Dwarf.h:48
@ DW_MACINFO_invalid
Macinfo type for invalid results.
Definition Dwarf.h:50
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
Definition Dwarf.h:51
@ DW_VIRTUALITY_invalid
Virtuality for invalid results.
Definition Dwarf.h:49
@ DWARF_VENDOR_DWARF
Identifiers we use to distinguish vendor extensions.
Definition Dwarf.h:71
GDBIndexEntryLinkage
Definition Dwarf.h:1065
@ GIEL_EXTERNAL
Definition Dwarf.h:1065
@ GIEL_STATIC
Definition Dwarf.h:1065
This is an optimization pass for GlobalISel generic memory operations.
DWARFExpression::Operation Op
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition Dwarf.h:1199
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition Dwarf.h:1217
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition Dwarf.h:1210