]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ArchSpec.h
Merge ^/head r285793 through r285923.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / ArchSpec.h
1 //===-- ArchSpec.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
12
13 #if defined(__cplusplus)
14
15 #include "lldb/lldb-forward.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/Triple.h"
18
19 namespace lldb_private {
20
21 struct CoreDefinition;    
22
23 //----------------------------------------------------------------------
24 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
25 /// @brief An architecture specification class.
26 ///
27 /// A class designed to be created from a cpu type and subtype, a
28 /// string representation, or an llvm::Triple.  Keeping all of the
29 /// conversions of strings to architecture enumeration values confined
30 /// to this class allows new architecture support to be added easily.
31 //----------------------------------------------------------------------
32 class ArchSpec
33 {
34 public:
35     enum MIPSSubType
36     {
37         eMIPSSubType_unknown,
38         eMIPSSubType_mips32,
39         eMIPSSubType_mips32r2,
40         eMIPSSubType_mips32r6,
41         eMIPSSubType_mips32el,
42         eMIPSSubType_mips32r2el,
43         eMIPSSubType_mips32r6el,
44         eMIPSSubType_mips64,
45         eMIPSSubType_mips64r2,
46         eMIPSSubType_mips64r6,
47         eMIPSSubType_mips64el,
48         eMIPSSubType_mips64r2el,
49         eMIPSSubType_mips64r6el,
50     };
51     
52     enum Core
53     {
54         eCore_arm_generic,
55         eCore_arm_armv4,
56         eCore_arm_armv4t,
57         eCore_arm_armv5,
58         eCore_arm_armv5e,
59         eCore_arm_armv5t,
60         eCore_arm_armv6,
61         eCore_arm_armv6m,
62         eCore_arm_armv7,
63         eCore_arm_armv7f,
64         eCore_arm_armv7s,
65         eCore_arm_armv7k,
66         eCore_arm_armv7m,
67         eCore_arm_armv7em,
68         eCore_arm_xscale,  
69
70         eCore_thumb,
71         eCore_thumbv4t,
72         eCore_thumbv5,
73         eCore_thumbv5e,
74         eCore_thumbv6,
75         eCore_thumbv6m,
76         eCore_thumbv7,
77         eCore_thumbv7s,
78         eCore_thumbv7k,
79         eCore_thumbv7f,
80         eCore_thumbv7m,
81         eCore_thumbv7em,
82         eCore_arm_arm64,
83         eCore_arm_armv8,
84         eCore_arm_aarch64,
85
86         eCore_mips32,
87         eCore_mips32r2,
88         eCore_mips32r3,
89         eCore_mips32r5,
90         eCore_mips32r6,
91         eCore_mips32el,
92         eCore_mips32r2el,
93         eCore_mips32r3el,
94         eCore_mips32r5el,
95         eCore_mips32r6el,
96         eCore_mips64,
97         eCore_mips64r2,
98         eCore_mips64r3,
99         eCore_mips64r5,
100         eCore_mips64r6,
101         eCore_mips64el,
102         eCore_mips64r2el,
103         eCore_mips64r3el,
104         eCore_mips64r5el,
105         eCore_mips64r6el,
106
107         eCore_ppc_generic,
108         eCore_ppc_ppc601,
109         eCore_ppc_ppc602,
110         eCore_ppc_ppc603,
111         eCore_ppc_ppc603e,
112         eCore_ppc_ppc603ev,
113         eCore_ppc_ppc604,
114         eCore_ppc_ppc604e,
115         eCore_ppc_ppc620,
116         eCore_ppc_ppc750,
117         eCore_ppc_ppc7400,
118         eCore_ppc_ppc7450,
119         eCore_ppc_ppc970,
120         
121         eCore_ppc64_generic,
122         eCore_ppc64_ppc970_64,
123         
124         eCore_sparc_generic,
125         
126         eCore_sparc9_generic,
127         
128         eCore_x86_32_i386,
129         eCore_x86_32_i486,
130         eCore_x86_32_i486sx,
131         eCore_x86_32_i686,
132         
133         eCore_x86_64_x86_64,
134         eCore_x86_64_x86_64h, // Haswell enabled x86_64
135         eCore_hexagon_generic,
136         eCore_hexagon_hexagonv4,
137         eCore_hexagon_hexagonv5,
138
139         eCore_uknownMach32,
140         eCore_uknownMach64,
141
142         eCore_kalimba3,
143         eCore_kalimba4,
144         eCore_kalimba5,
145
146         kNumCores,
147
148         kCore_invalid,
149         // The following constants are used for wildcard matching only
150         kCore_any,
151         kCore_arm_any,
152         kCore_ppc_any,
153         kCore_ppc64_any,
154         kCore_x86_32_any,
155         kCore_x86_64_any,
156         kCore_hexagon_any,
157
158         kCore_arm_first     = eCore_arm_generic,
159         kCore_arm_last      = eCore_arm_xscale,
160
161         kCore_thumb_first   = eCore_thumb,
162         kCore_thumb_last    = eCore_thumbv7em,
163
164         kCore_ppc_first     = eCore_ppc_generic,
165         kCore_ppc_last      = eCore_ppc_ppc970,
166
167         kCore_ppc64_first   = eCore_ppc64_generic,
168         kCore_ppc64_last    = eCore_ppc64_ppc970_64,
169
170         kCore_x86_32_first  = eCore_x86_32_i386,
171         kCore_x86_32_last   = eCore_x86_32_i686,
172
173         kCore_x86_64_first  = eCore_x86_64_x86_64,
174         kCore_x86_64_last   = eCore_x86_64_x86_64h,
175
176         kCore_hexagon_first  = eCore_hexagon_generic,
177         kCore_hexagon_last   = eCore_hexagon_hexagonv5,
178
179         kCore_kalimba_first = eCore_kalimba3,
180         kCore_kalimba_last = eCore_kalimba5,
181
182         kCore_mips32_first  = eCore_mips32,
183         kCore_mips32_last   = eCore_mips32r6,
184
185         kCore_mips32el_first  = eCore_mips32el,
186         kCore_mips32el_last   = eCore_mips32r6el,
187
188         kCore_mips64_first  = eCore_mips64,
189         kCore_mips64_last   = eCore_mips64r6,
190
191         kCore_mips64el_first  = eCore_mips64el,
192         kCore_mips64el_last   = eCore_mips64r6el
193     };
194
195     typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
196
197     //------------------------------------------------------------------
198     /// Default constructor.
199     ///
200     /// Default constructor that initializes the object with invalid
201     /// cpu type and subtype values.
202     //------------------------------------------------------------------
203     ArchSpec ();
204
205     //------------------------------------------------------------------
206     /// Constructor over triple.
207     ///
208     /// Constructs an ArchSpec with properties consistent with the given
209     /// Triple.
210     //------------------------------------------------------------------
211     explicit 
212     ArchSpec (const llvm::Triple &triple);
213     explicit 
214     ArchSpec (const char *triple_cstr);
215     explicit 
216     ArchSpec (const char *triple_cstr, Platform *platform);
217     //------------------------------------------------------------------
218     /// Constructor over architecture name.
219     ///
220     /// Constructs an ArchSpec with properties consistent with the given
221     /// object type and architecture name.
222     //------------------------------------------------------------------
223     explicit 
224     ArchSpec (ArchitectureType arch_type,
225               uint32_t cpu_type,
226               uint32_t cpu_subtype);
227
228     //------------------------------------------------------------------
229     /// Destructor.
230     //------------------------------------------------------------------
231     ~ArchSpec ();
232
233     //------------------------------------------------------------------
234     /// Assignment operator.
235     ///
236     /// @param[in] rhs another ArchSpec object to copy.
237     ///
238     /// @return A const reference to this object.
239     //------------------------------------------------------------------
240     const ArchSpec&
241     operator= (const ArchSpec& rhs);
242
243     static size_t
244     AutoComplete (const char *name, 
245                   StringList &matches);
246
247     //------------------------------------------------------------------
248     /// Returns a static string representing the current architecture.
249     ///
250     /// @return A static string correcponding to the current
251     ///         architecture.
252     //------------------------------------------------------------------
253     const char *
254     GetArchitectureName () const;
255
256     //------------------------------------------------------------------
257     /// Clears the object state.
258     ///
259     /// Clears the object state back to a default invalid state.
260     //------------------------------------------------------------------
261     void
262     Clear ();
263
264     //------------------------------------------------------------------
265     /// Returns the size in bytes of an address of the current
266     /// architecture.
267     ///
268     /// @return The byte size of an address of the current architecture.
269     //------------------------------------------------------------------
270     uint32_t
271     GetAddressByteSize () const;
272
273     //------------------------------------------------------------------
274     /// Returns a machine family for the current architecture.
275     ///
276     /// @return An LLVM arch type.
277     //------------------------------------------------------------------
278     llvm::Triple::ArchType
279     GetMachine () const;
280
281     //------------------------------------------------------------------
282     /// Returns the distribution id of the architecture.
283     ///
284     /// This will be something like "ubuntu", "fedora", etc. on Linux.
285     ///
286     /// @return A ConstString ref containing the distribution id,
287     ///         potentially empty.
288     //------------------------------------------------------------------
289     const ConstString&
290     GetDistributionId () const;
291
292     //------------------------------------------------------------------
293     /// Set the distribution id of the architecture.
294     ///
295     /// This will be something like "ubuntu", "fedora", etc. on Linux.
296     /// This should be the same value returned by
297     /// HostInfo::GetDistributionId ().
298     ///------------------------------------------------------------------
299     void
300     SetDistributionId (const char* distribution_id);
301
302     //------------------------------------------------------------------
303     /// Tests if this ArchSpec is valid.
304     ///
305     /// @return True if the current architecture is valid, false
306     ///         otherwise.
307     //------------------------------------------------------------------
308     bool
309     IsValid () const
310     {
311         return m_core >= eCore_arm_generic && m_core < kNumCores;
312     }
313
314     bool
315     TripleVendorWasSpecified() const
316     {
317         return !m_triple.getVendorName().empty();
318     }
319
320     bool
321     TripleOSWasSpecified() const
322     {
323         return !m_triple.getOSName().empty();
324     }
325
326     //------------------------------------------------------------------
327     /// Merges fields from another ArchSpec into this ArchSpec.
328     ///
329     /// This will use the supplied ArchSpec to fill in any fields of
330     /// the triple in this ArchSpec which were unspecified.  This can
331     /// be used to refine a generic ArchSpec with a more specific one.
332     /// For example, if this ArchSpec's triple is something like
333     /// i386-unknown-unknown-unknown, and we have a triple which is
334     /// x64-pc-windows-msvc, then merging that triple into this one
335     /// will result in the triple i386-pc-windows-msvc.
336     ///
337     //------------------------------------------------------------------
338     void
339     MergeFrom(const ArchSpec &other);
340     
341     //------------------------------------------------------------------
342     /// Change the architecture object type, CPU type and OS type.
343     ///
344     /// @param[in] arch_type The object type of this ArchSpec.
345     ///
346     /// @param[in] cpu The required CPU type.
347     ///
348     /// @param[in] os The optional OS type
349     /// The default value of 0 was choosen to from the ELF spec value
350     /// ELFOSABI_NONE.  ELF is the only one using this parameter.  If another
351     /// format uses this parameter and 0 does not work, use a value over
352     /// 255 because in the ELF header this is value is only a byte.
353     ///
354     /// @return True if the object, and CPU were successfully set.
355     ///
356     /// As a side effect, the vendor value is usually set to unknown.
357     /// The exections are
358     ///   aarch64-apple-ios
359     ///   arm-apple-ios
360     ///   thumb-apple-ios
361     ///   x86-apple-
362     ///   x86_64-apple-
363     ///
364     /// As a side effect, the os value is usually set to unknown
365     /// The exceptions are
366     ///   *-*-aix
367     ///   aarch64-apple-ios
368     ///   arm-apple-ios
369     ///   thumb-apple-ios
370     ///   powerpc-apple-darwin
371     ///   *-*-freebsd
372     ///   *-*-linux
373     ///   *-*-netbsd
374     ///   *-*-openbsd
375     ///   *-*-solaris
376     //------------------------------------------------------------------
377     bool
378     SetArchitecture (ArchitectureType arch_type, 
379                      uint32_t cpu,
380                      uint32_t sub,
381                      uint32_t os = 0);
382
383     //------------------------------------------------------------------
384     /// Returns the byte order for the architecture specification.
385     ///
386     /// @return The endian enumeration for the current endianness of
387     ///     the architecture specification
388     //------------------------------------------------------------------
389     lldb::ByteOrder
390     GetByteOrder () const;
391
392     //------------------------------------------------------------------
393     /// Sets this ArchSpec's byte order.
394     ///
395     /// In the common case there is no need to call this method as the
396     /// byte order can almost always be determined by the architecture.
397     /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
398     /// and the default/assumed byte order may be incorrect.
399     //------------------------------------------------------------------
400     void
401     SetByteOrder (lldb::ByteOrder byte_order)
402     {
403         m_byte_order = byte_order;
404     }
405
406     uint32_t
407     GetMinimumOpcodeByteSize() const;
408
409     uint32_t
410     GetMaximumOpcodeByteSize() const;
411
412     Core
413     GetCore () const
414     {
415         return m_core;
416     }
417
418     uint32_t
419     GetMachOCPUType () const;
420
421     uint32_t
422     GetMachOCPUSubType () const;
423
424     //------------------------------------------------------------------
425     /// Architecture data byte width accessor
426     ///
427     /// @return the size in 8-bit (host) bytes of a minimum addressable
428     /// unit from the Architecture's data bus
429     //------------------------------------------------------------------
430     uint32_t
431     GetDataByteSize() const;
432
433     //------------------------------------------------------------------
434     /// Architecture code byte width accessor
435     ///
436     /// @return the size in 8-bit (host) bytes of a minimum addressable
437     /// unit from the Architecture's code bus
438     //------------------------------------------------------------------
439     uint32_t
440     GetCodeByteSize() const;
441  
442     //------------------------------------------------------------------
443     /// Architecture tripple accessor.
444     ///
445     /// @return A triple describing this ArchSpec.
446     //------------------------------------------------------------------
447     llvm::Triple &
448     GetTriple ()
449     {
450         return m_triple;
451     }
452
453     //------------------------------------------------------------------
454     /// Architecture tripple accessor.
455     ///
456     /// @return A triple describing this ArchSpec.
457     //------------------------------------------------------------------
458     const llvm::Triple &
459     GetTriple () const
460     {
461         return m_triple;
462     }
463
464     //------------------------------------------------------------------
465     /// Architecture tripple setter.
466     ///
467     /// Configures this ArchSpec according to the given triple.  If the 
468     /// triple has unknown components in all of the vendor, OS, and 
469     /// the optional environment field (i.e. "i386-unknown-unknown")
470     /// then default values are taken from the host.  Architecture and
471     /// environment components are used to further resolve the CPU type
472     /// and subtype, endian characteristics, etc.
473     ///
474     /// @return A triple describing this ArchSpec.
475     //------------------------------------------------------------------
476     bool
477     SetTriple (const llvm::Triple &triple);
478
479     bool
480     SetTriple (const char *triple_cstr);
481
482     bool
483     SetTriple (const char *triple_cstr,
484                Platform *platform);
485     
486     //------------------------------------------------------------------
487     /// Returns the default endianness of the architecture.
488     ///
489     /// @return The endian enumeration for the default endianness of
490     ///         the architecture.
491     //------------------------------------------------------------------
492     lldb::ByteOrder
493     GetDefaultEndian () const;
494
495     //------------------------------------------------------------------
496     /// Returns true if 'char' is a signed type by defualt in the 
497     /// architecture false otherwise
498     ///
499     /// @return True if 'char' is a signed type by default on the
500     ///         architecture and false otherwise.
501     //------------------------------------------------------------------
502     bool
503     CharIsSignedByDefault () const;
504
505     //------------------------------------------------------------------
506     /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
507     /// type match between them.
508     /// e.g. armv7s is not an exact match with armv7 - this would return false
509     ///
510     /// @return true if the two ArchSpecs match.
511     //------------------------------------------------------------------
512     bool
513     IsExactMatch (const ArchSpec& rhs) const;
514
515     //------------------------------------------------------------------
516     /// Compare an ArchSpec to another ArchSpec, requiring a compatible
517     /// cpu type match between them.  
518     /// e.g. armv7s is compatible with armv7 - this method would return true
519     ///
520     /// @return true if the two ArchSpecs are compatible
521     //------------------------------------------------------------------
522     bool
523     IsCompatibleMatch (const ArchSpec& rhs) const;
524
525     //------------------------------------------------------------------
526     /// Get a stop info override callback for the current architecture.
527     ///
528     /// Most platform specific code should go in lldb_private::Platform,
529     /// but there are cases where no matter which platform you are on
530     /// certain things hold true.
531     ///
532     /// This callback is currently intended to handle cases where a
533     /// program stops at an instruction that won't get executed and it
534     /// allows the stop reasonm, like "breakpoint hit", to be replaced
535     /// with a different stop reason like "no stop reason".
536     ///
537     /// This is specifically used for ARM in Thumb code when we stop in
538     /// an IT instruction (if/then/else) where the instruction won't get
539     /// executed and therefore it wouldn't be correct to show the program
540     /// stopped at the current PC. The code is generic and applies to all
541     /// ARM CPUs.
542     ///
543     /// @return NULL or a valid stop info override callback for the
544     ///     current architecture.
545     //------------------------------------------------------------------
546     StopInfoOverrideCallbackType
547     GetStopInfoOverrideCallback () const;
548
549 protected:
550     bool
551     IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
552
553     llvm::Triple m_triple;
554     Core m_core;
555     lldb::ByteOrder m_byte_order;
556
557     ConstString m_distribution_id;
558
559     // Called when m_def or m_entry are changed.  Fills in all remaining
560     // members with default values.
561     void
562     CoreUpdated (bool update_triple);
563 };
564
565 //------------------------------------------------------------------
566 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
567 /// @brief Less than operator.
568 ///
569 /// Tests two ArchSpec objects to see if \a lhs is less than \a
570 /// rhs.
571 ///
572 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
573 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
574 ///
575 /// @return true if \a lhs is less than \a rhs
576 //------------------------------------------------------------------
577 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
578
579 } // namespace lldb_private
580
581 #endif  // #if defined(__cplusplus)
582 #endif  // #ifndef liblldb_ArchSpec_h_