• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- DWARFDefines.cpp --------------------------------------------------===//
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 #include "DWARFDefines.h"
10 #include "lldb/Utility/ConstString.h"
11 #include <cstdio>
12 #include <cstring>
13 #include <string>
14 
15 namespace lldb_private {
16 
DW_TAG_value_to_name(uint32_t val)17 const char *DW_TAG_value_to_name(uint32_t val) {
18   static char invalid[100];
19 
20   if (val == 0)
21     return "NULL";
22 
23   llvm::StringRef llvmstr = llvm::dwarf::TagString(val);
24   if (llvmstr.empty()) {
25     snprintf(invalid, sizeof(invalid), "Unknown DW_TAG constant: 0x%x", val);
26     return invalid;
27   }
28   return llvmstr.data();
29 }
30 
DW_AT_value_to_name(uint32_t val)31 const char *DW_AT_value_to_name(uint32_t val) {
32   static char invalid[100];
33   llvm::StringRef llvmstr = llvm::dwarf::AttributeString(val);
34   if (llvmstr.empty()) {
35     snprintf(invalid, sizeof(invalid), "Unknown DW_AT constant: 0x%x", val);
36     return invalid;
37   }
38   return llvmstr.data();
39 }
40 
DW_FORM_value_to_name(uint32_t val)41 const char *DW_FORM_value_to_name(uint32_t val) {
42   static char invalid[100];
43   llvm::StringRef llvmstr = llvm::dwarf::FormEncodingString(val);
44   if (llvmstr.empty()) {
45     snprintf(invalid, sizeof(invalid), "Unknown DW_FORM constant: 0x%x", val);
46     return invalid;
47   }
48   return llvmstr.data();
49 }
50 
DW_OP_value_to_name(uint32_t val)51 const char *DW_OP_value_to_name(uint32_t val) {
52   static char invalid[100];
53   llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString(val);
54   if (llvmstr.empty()) {
55     snprintf(invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val);
56     return invalid;
57   }
58   return llvmstr.data();
59 }
60 
DW_ATE_value_to_name(uint32_t val)61 const char *DW_ATE_value_to_name(uint32_t val) {
62   static char invalid[100];
63   llvm::StringRef llvmstr = llvm::dwarf::AttributeEncodingString(val);
64   if (llvmstr.empty()) {
65     snprintf(invalid, sizeof(invalid), "Unknown DW_ATE constant: 0x%x", val);
66     return invalid;
67   }
68   return llvmstr.data();
69 }
70 
DW_LANG_value_to_name(uint32_t val)71 const char *DW_LANG_value_to_name(uint32_t val) {
72   static char invalid[100];
73   llvm::StringRef llvmstr = llvm::dwarf::LanguageString(val);
74   if (llvmstr.empty()) {
75     snprintf(invalid, sizeof(invalid), "Unknown DW_LANG constant: 0x%x", val);
76     return invalid;
77   }
78   return llvmstr.data();
79 }
80 
DW_LNS_value_to_name(uint32_t val)81 const char *DW_LNS_value_to_name(uint32_t val) {
82   static char invalid[100];
83   llvm::StringRef llvmstr = llvm::dwarf::LNStandardString(val);
84   if (llvmstr.empty()) {
85     snprintf(invalid, sizeof(invalid), "Unknown DW_LNS constant: 0x%x", val);
86     return invalid;
87   }
88   return llvmstr.data();
89 }
90 
91 } // namespace lldb_private
92