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-private.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
20 namespace lldb_private {
22 struct CoreDefinition;
24 //----------------------------------------------------------------------
25 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
26 /// @brief An architecture specification class.
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 //----------------------------------------------------------------------
87 eCore_ppc64_ppc970_64,
99 eCore_x86_64_x86_64h, // Haswell enabled x86_64
100 eCore_hexagon_generic,
101 eCore_hexagon_hexagonv4,
102 eCore_hexagon_hexagonv5,
114 // The following constants are used for wildcard matching only
123 kCore_arm_first = eCore_arm_generic,
124 kCore_arm_last = eCore_arm_xscale,
126 kCore_thumb_first = eCore_thumb,
127 kCore_thumb_last = eCore_thumbv7em,
129 kCore_ppc_first = eCore_ppc_generic,
130 kCore_ppc_last = eCore_ppc_ppc970,
132 kCore_ppc64_first = eCore_ppc64_generic,
133 kCore_ppc64_last = eCore_ppc64_ppc970_64,
135 kCore_x86_32_first = eCore_x86_32_i386,
136 kCore_x86_32_last = eCore_x86_32_i686,
138 kCore_x86_64_first = eCore_x86_64_x86_64,
139 kCore_x86_64_last = eCore_x86_64_x86_64h,
141 kCore_hexagon_first = eCore_hexagon_generic,
142 kCore_hexagon_last = eCore_hexagon_hexagonv5,
144 kCore_kalimba_first = eCore_kalimba3,
145 kCore_kalimba_last = eCore_kalimba5
148 typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
150 //------------------------------------------------------------------
151 /// Default constructor.
153 /// Default constructor that initializes the object with invalid
154 /// cpu type and subtype values.
155 //------------------------------------------------------------------
158 //------------------------------------------------------------------
159 /// Constructor over triple.
161 /// Constructs an ArchSpec with properties consistent with the given
163 //------------------------------------------------------------------
165 ArchSpec (const llvm::Triple &triple);
167 ArchSpec (const char *triple_cstr);
169 ArchSpec (const char *triple_cstr, Platform *platform);
170 //------------------------------------------------------------------
171 /// Constructor over architecture name.
173 /// Constructs an ArchSpec with properties consistent with the given
174 /// object type and architecture name.
175 //------------------------------------------------------------------
177 ArchSpec (ArchitectureType arch_type,
179 uint32_t cpu_subtype);
181 //------------------------------------------------------------------
183 //------------------------------------------------------------------
186 //------------------------------------------------------------------
187 /// Assignment operator.
189 /// @param[in] rhs another ArchSpec object to copy.
191 /// @return A const reference to this object.
192 //------------------------------------------------------------------
194 operator= (const ArchSpec& rhs);
197 AutoComplete (const char *name,
198 StringList &matches);
200 //------------------------------------------------------------------
201 /// Returns a static string representing the current architecture.
203 /// @return A static string correcponding to the current
205 //------------------------------------------------------------------
207 GetArchitectureName () const;
209 //------------------------------------------------------------------
210 /// Clears the object state.
212 /// Clears the object state back to a default invalid state.
213 //------------------------------------------------------------------
217 //------------------------------------------------------------------
218 /// Returns the size in bytes of an address of the current
221 /// @return The byte size of an address of the current architecture.
222 //------------------------------------------------------------------
224 GetAddressByteSize () const;
226 //------------------------------------------------------------------
227 /// Returns a machine family for the current architecture.
229 /// @return An LLVM arch type.
230 //------------------------------------------------------------------
231 llvm::Triple::ArchType
234 //------------------------------------------------------------------
235 /// Returns the distribution id of the architecture.
237 /// This will be something like "ubuntu", "fedora", etc. on Linux.
239 /// @return A ConstString ref containing the distribution id,
240 /// potentially empty.
241 //------------------------------------------------------------------
243 GetDistributionId () const;
245 //------------------------------------------------------------------
246 /// Set the distribution id of the architecture.
248 /// This will be something like "ubuntu", "fedora", etc. on Linux.
249 /// This should be the same value returned by
250 /// HostInfo::GetDistributionId ().
251 ///------------------------------------------------------------------
253 SetDistributionId (const char* distribution_id);
255 //------------------------------------------------------------------
256 /// Tests if this ArchSpec is valid.
258 /// @return True if the current architecture is valid, false
260 //------------------------------------------------------------------
264 return m_core >= eCore_arm_generic && m_core < kNumCores;
268 TripleVendorWasSpecified() const
270 return !m_triple.getVendorName().empty();
274 TripleOSWasSpecified() const
276 return !m_triple.getOSName().empty();
279 //------------------------------------------------------------------
280 /// Sets this ArchSpec according to the given architecture name.
282 /// The architecture name can be one of the generic system default
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).
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).
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:
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.
306 /// @param[in] arch_name The name of an architecture.
308 /// @return True if @p arch_name was successfully translated, false
310 //------------------------------------------------------------------
312 // SetArchitecture (const llvm::StringRef& arch_name);
315 // SetArchitecture (const char *arch_name);
317 //------------------------------------------------------------------
318 /// Change the architecture object type and CPU type.
320 /// @param[in] arch_type The object type of this ArchSpec.
322 /// @param[in] cpu The required CPU type.
324 /// @return True if the object and CPU type were successfully set.
325 //------------------------------------------------------------------
327 SetArchitecture (ArchitectureType arch_type,
331 //------------------------------------------------------------------
332 /// Returns the byte order for the architecture specification.
334 /// @return The endian enumeration for the current endianness of
335 /// the architecture specification
336 //------------------------------------------------------------------
338 GetByteOrder () const;
340 //------------------------------------------------------------------
341 /// Sets this ArchSpec's byte order.
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 //------------------------------------------------------------------
349 SetByteOrder (lldb::ByteOrder byte_order)
351 m_byte_order = byte_order;
355 GetMinimumOpcodeByteSize() const;
358 GetMaximumOpcodeByteSize() const;
367 GetMachOCPUType () const;
370 GetMachOCPUSubType () const;
372 //------------------------------------------------------------------
373 /// Architecture data byte width accessor
375 /// @return the size in 8-bit (host) bytes of a minimum addressable
376 /// unit from the Architecture's data bus
377 //------------------------------------------------------------------
379 GetDataByteSize() const;
381 //------------------------------------------------------------------
382 /// Architecture code byte width accessor
384 /// @return the size in 8-bit (host) bytes of a minimum addressable
385 /// unit from the Architecture's code bus
386 //------------------------------------------------------------------
388 GetCodeByteSize() const;
390 //------------------------------------------------------------------
391 /// Architecture tripple accessor.
393 /// @return A triple describing this ArchSpec.
394 //------------------------------------------------------------------
401 //------------------------------------------------------------------
402 /// Architecture tripple accessor.
404 /// @return A triple describing this ArchSpec.
405 //------------------------------------------------------------------
412 //------------------------------------------------------------------
413 /// Architecture tripple setter.
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.
422 /// @return A triple describing this ArchSpec.
423 //------------------------------------------------------------------
425 SetTriple (const llvm::Triple &triple);
428 SetTriple (const char *triple_cstr);
431 SetTriple (const char *triple_cstr,
434 //------------------------------------------------------------------
435 /// Returns the default endianness of the architecture.
437 /// @return The endian enumeration for the default endianness of
438 /// the architecture.
439 //------------------------------------------------------------------
441 GetDefaultEndian () const;
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
448 /// @return true if the two ArchSpecs match.
449 //------------------------------------------------------------------
451 IsExactMatch (const ArchSpec& rhs) const;
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
458 /// @return true if the two ArchSpecs are compatible
459 //------------------------------------------------------------------
461 IsCompatibleMatch (const ArchSpec& rhs) const;
463 //------------------------------------------------------------------
464 /// Get a stop info override callback for the current architecture.
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.
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".
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
481 /// @return NULL or a valid stop info override callback for the
482 /// current architecture.
483 //------------------------------------------------------------------
484 StopInfoOverrideCallbackType
485 GetStopInfoOverrideCallback () const;
489 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
491 llvm::Triple m_triple;
493 lldb::ByteOrder m_byte_order;
495 ConstString m_distribution_id;
497 // Called when m_def or m_entry are changed. Fills in all remaining
498 // members with default values.
500 CoreUpdated (bool update_triple);
503 //------------------------------------------------------------------
504 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
505 /// @brief Less than operator.
507 /// Tests two ArchSpec objects to see if \a lhs is less than \a
510 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
511 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
513 /// @return true if \a lhs is less than \a rhs
514 //------------------------------------------------------------------
515 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
517 } // namespace lldb_private
519 #endif // #if defined(__cplusplus)
520 #endif // #ifndef liblldb_ArchSpec_h_