1 //===-- ArchSpec.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
13 #if defined(__cplusplus)
15 #include "lldb/lldb-forward.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/Triple.h"
19 namespace lldb_private {
21 struct CoreDefinition;
23 //----------------------------------------------------------------------
24 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
25 /// @brief An architecture specification class.
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 //----------------------------------------------------------------------
39 eMIPSSubType_mips32r2,
40 eMIPSSubType_mips32r6,
41 eMIPSSubType_mips32el,
42 eMIPSSubType_mips32r2el,
43 eMIPSSubType_mips32r6el,
45 eMIPSSubType_mips64r2,
46 eMIPSSubType_mips64r6,
47 eMIPSSubType_mips64el,
48 eMIPSSubType_mips64r2el,
49 eMIPSSubType_mips64r6el,
122 eCore_ppc64_ppc970_64,
126 eCore_sparc9_generic,
134 eCore_x86_64_x86_64h, // Haswell enabled x86_64
135 eCore_hexagon_generic,
136 eCore_hexagon_hexagonv4,
137 eCore_hexagon_hexagonv5,
149 // The following constants are used for wildcard matching only
158 kCore_arm_first = eCore_arm_generic,
159 kCore_arm_last = eCore_arm_xscale,
161 kCore_thumb_first = eCore_thumb,
162 kCore_thumb_last = eCore_thumbv7em,
164 kCore_ppc_first = eCore_ppc_generic,
165 kCore_ppc_last = eCore_ppc_ppc970,
167 kCore_ppc64_first = eCore_ppc64_generic,
168 kCore_ppc64_last = eCore_ppc64_ppc970_64,
170 kCore_x86_32_first = eCore_x86_32_i386,
171 kCore_x86_32_last = eCore_x86_32_i686,
173 kCore_x86_64_first = eCore_x86_64_x86_64,
174 kCore_x86_64_last = eCore_x86_64_x86_64h,
176 kCore_hexagon_first = eCore_hexagon_generic,
177 kCore_hexagon_last = eCore_hexagon_hexagonv5,
179 kCore_kalimba_first = eCore_kalimba3,
180 kCore_kalimba_last = eCore_kalimba5,
182 kCore_mips32_first = eCore_mips32,
183 kCore_mips32_last = eCore_mips32r6,
185 kCore_mips32el_first = eCore_mips32el,
186 kCore_mips32el_last = eCore_mips32r6el,
188 kCore_mips64_first = eCore_mips64,
189 kCore_mips64_last = eCore_mips64r6,
191 kCore_mips64el_first = eCore_mips64el,
192 kCore_mips64el_last = eCore_mips64r6el
195 typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
197 //------------------------------------------------------------------
198 /// Default constructor.
200 /// Default constructor that initializes the object with invalid
201 /// cpu type and subtype values.
202 //------------------------------------------------------------------
205 //------------------------------------------------------------------
206 /// Constructor over triple.
208 /// Constructs an ArchSpec with properties consistent with the given
210 //------------------------------------------------------------------
212 ArchSpec (const llvm::Triple &triple);
214 ArchSpec (const char *triple_cstr);
216 ArchSpec (const char *triple_cstr, Platform *platform);
217 //------------------------------------------------------------------
218 /// Constructor over architecture name.
220 /// Constructs an ArchSpec with properties consistent with the given
221 /// object type and architecture name.
222 //------------------------------------------------------------------
224 ArchSpec (ArchitectureType arch_type,
226 uint32_t cpu_subtype);
228 //------------------------------------------------------------------
230 //------------------------------------------------------------------
233 //------------------------------------------------------------------
234 /// Assignment operator.
236 /// @param[in] rhs another ArchSpec object to copy.
238 /// @return A const reference to this object.
239 //------------------------------------------------------------------
241 operator= (const ArchSpec& rhs);
244 AutoComplete (const char *name,
245 StringList &matches);
247 //------------------------------------------------------------------
248 /// Returns a static string representing the current architecture.
250 /// @return A static string correcponding to the current
252 //------------------------------------------------------------------
254 GetArchitectureName () const;
256 //------------------------------------------------------------------
257 /// Clears the object state.
259 /// Clears the object state back to a default invalid state.
260 //------------------------------------------------------------------
264 //------------------------------------------------------------------
265 /// Returns the size in bytes of an address of the current
268 /// @return The byte size of an address of the current architecture.
269 //------------------------------------------------------------------
271 GetAddressByteSize () const;
273 //------------------------------------------------------------------
274 /// Returns a machine family for the current architecture.
276 /// @return An LLVM arch type.
277 //------------------------------------------------------------------
278 llvm::Triple::ArchType
281 //------------------------------------------------------------------
282 /// Returns the distribution id of the architecture.
284 /// This will be something like "ubuntu", "fedora", etc. on Linux.
286 /// @return A ConstString ref containing the distribution id,
287 /// potentially empty.
288 //------------------------------------------------------------------
290 GetDistributionId () const;
292 //------------------------------------------------------------------
293 /// Set the distribution id of the architecture.
295 /// This will be something like "ubuntu", "fedora", etc. on Linux.
296 /// This should be the same value returned by
297 /// HostInfo::GetDistributionId ().
298 ///------------------------------------------------------------------
300 SetDistributionId (const char* distribution_id);
302 //------------------------------------------------------------------
303 /// Tests if this ArchSpec is valid.
305 /// @return True if the current architecture is valid, false
307 //------------------------------------------------------------------
311 return m_core >= eCore_arm_generic && m_core < kNumCores;
315 TripleVendorWasSpecified() const
317 return !m_triple.getVendorName().empty();
321 TripleOSWasSpecified() const
323 return !m_triple.getOSName().empty();
326 //------------------------------------------------------------------
327 /// Merges fields from another ArchSpec into this ArchSpec.
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.
337 //------------------------------------------------------------------
339 MergeFrom(const ArchSpec &other);
341 //------------------------------------------------------------------
342 /// Change the architecture object type, CPU type and OS type.
344 /// @param[in] arch_type The object type of this ArchSpec.
346 /// @param[in] cpu The required CPU type.
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.
354 /// @return True if the object, and CPU were successfully set.
356 /// As a side effect, the vendor value is usually set to unknown.
357 /// The exections are
358 /// aarch64-apple-ios
364 /// As a side effect, the os value is usually set to unknown
365 /// The exceptions are
367 /// aarch64-apple-ios
370 /// powerpc-apple-darwin
376 //------------------------------------------------------------------
378 SetArchitecture (ArchitectureType arch_type,
383 //------------------------------------------------------------------
384 /// Returns the byte order for the architecture specification.
386 /// @return The endian enumeration for the current endianness of
387 /// the architecture specification
388 //------------------------------------------------------------------
390 GetByteOrder () const;
392 //------------------------------------------------------------------
393 /// Sets this ArchSpec's byte order.
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 //------------------------------------------------------------------
401 SetByteOrder (lldb::ByteOrder byte_order)
403 m_byte_order = byte_order;
407 GetMinimumOpcodeByteSize() const;
410 GetMaximumOpcodeByteSize() const;
419 GetMachOCPUType () const;
422 GetMachOCPUSubType () const;
424 //------------------------------------------------------------------
425 /// Architecture data byte width accessor
427 /// @return the size in 8-bit (host) bytes of a minimum addressable
428 /// unit from the Architecture's data bus
429 //------------------------------------------------------------------
431 GetDataByteSize() const;
433 //------------------------------------------------------------------
434 /// Architecture code byte width accessor
436 /// @return the size in 8-bit (host) bytes of a minimum addressable
437 /// unit from the Architecture's code bus
438 //------------------------------------------------------------------
440 GetCodeByteSize() const;
442 //------------------------------------------------------------------
443 /// Architecture tripple accessor.
445 /// @return A triple describing this ArchSpec.
446 //------------------------------------------------------------------
453 //------------------------------------------------------------------
454 /// Architecture tripple accessor.
456 /// @return A triple describing this ArchSpec.
457 //------------------------------------------------------------------
464 //------------------------------------------------------------------
465 /// Architecture tripple setter.
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.
474 /// @return A triple describing this ArchSpec.
475 //------------------------------------------------------------------
477 SetTriple (const llvm::Triple &triple);
480 SetTriple (const char *triple_cstr);
483 SetTriple (const char *triple_cstr,
486 //------------------------------------------------------------------
487 /// Returns the default endianness of the architecture.
489 /// @return The endian enumeration for the default endianness of
490 /// the architecture.
491 //------------------------------------------------------------------
493 GetDefaultEndian () const;
495 //------------------------------------------------------------------
496 /// Returns true if 'char' is a signed type by defualt in the
497 /// architecture false otherwise
499 /// @return True if 'char' is a signed type by default on the
500 /// architecture and false otherwise.
501 //------------------------------------------------------------------
503 CharIsSignedByDefault () const;
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
510 /// @return true if the two ArchSpecs match.
511 //------------------------------------------------------------------
513 IsExactMatch (const ArchSpec& rhs) const;
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
520 /// @return true if the two ArchSpecs are compatible
521 //------------------------------------------------------------------
523 IsCompatibleMatch (const ArchSpec& rhs) const;
525 //------------------------------------------------------------------
526 /// Get a stop info override callback for the current architecture.
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.
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".
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
543 /// @return NULL or a valid stop info override callback for the
544 /// current architecture.
545 //------------------------------------------------------------------
546 StopInfoOverrideCallbackType
547 GetStopInfoOverrideCallback () const;
551 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
553 llvm::Triple m_triple;
555 lldb::ByteOrder m_byte_order;
557 ConstString m_distribution_id;
559 // Called when m_def or m_entry are changed. Fills in all remaining
560 // members with default values.
562 CoreUpdated (bool update_triple);
565 //------------------------------------------------------------------
566 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
567 /// @brief Less than operator.
569 /// Tests two ArchSpec objects to see if \a lhs is less than \a
572 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
573 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
575 /// @return true if \a lhs is less than \a rhs
576 //------------------------------------------------------------------
577 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
579 } // namespace lldb_private
581 #endif // #if defined(__cplusplus)
582 #endif // #ifndef liblldb_ArchSpec_h_