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