LLDB mainline
ArchSpec.h
Go to the documentation of this file.
1//===-- ArchSpec.h ----------------------------------------------*- C++ -*-===//
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#ifndef LLDB_UTILITY_ARCHSPEC_H
10#define LLDB_UTILITY_ARCHSPEC_H
11
14#include "lldb/lldb-forward.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/TargetParser/Triple.h"
18#include <cstddef>
19#include <cstdint>
20#include <string>
21
22namespace lldb_private {
23
24/// \class ArchSpec ArchSpec.h "lldb/Utility/ArchSpec.h" An architecture
25/// 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 conversions
29/// of strings to architecture enumeration values confined to this class
30/// allows new architecture support to be added easily.
31class ArchSpec {
32public:
48
49 // Masks for the ases word of an ABI flags structure.
50 enum MIPSASE {
51 eMIPSAse_dsp = 0x00000001, // DSP ASE
52 eMIPSAse_dspr2 = 0x00000002, // DSP R2 ASE
53 eMIPSAse_eva = 0x00000004, // Enhanced VA Scheme
54 eMIPSAse_mcu = 0x00000008, // MCU (MicroController) ASE
55 eMIPSAse_mdmx = 0x00000010, // MDMX ASE
56 eMIPSAse_mips3d = 0x00000020, // MIPS-3D ASE
57 eMIPSAse_mt = 0x00000040, // MT ASE
58 eMIPSAse_smartmips = 0x00000080, // SmartMIPS ASE
59 eMIPSAse_virt = 0x00000100, // VZ ASE
60 eMIPSAse_msa = 0x00000200, // MSA ASE
61 eMIPSAse_mips16 = 0x00000400, // MIPS16 ASE
62 eMIPSAse_micromips = 0x00000800, // MICROMIPS ASE
63 eMIPSAse_xpa = 0x00001000, // XPA ASE
64 eMIPSAse_mask = 0x00001fff,
65 eMIPSABI_O32 = 0x00002000,
66 eMIPSABI_N32 = 0x00004000,
67 eMIPSABI_N64 = 0x00008000,
68 eMIPSABI_O64 = 0x00020000,
69 eMIPSABI_EABI32 = 0x00040000,
70 eMIPSABI_EABI64 = 0x00080000,
71 eMIPSABI_mask = 0x000ff000
72 };
73
74 // MIPS Floating point ABI Values
76 eMIPS_ABI_FP_ANY = 0x00000000,
77 eMIPS_ABI_FP_DOUBLE = 0x00100000, // hard float / -mdouble-float
78 eMIPS_ABI_FP_SINGLE = 0x00200000, // hard float / -msingle-float
79 eMIPS_ABI_FP_SOFT = 0x00300000, // soft float
80 eMIPS_ABI_FP_OLD_64 = 0x00400000, // -mips32r2 -mfp64
81 eMIPS_ABI_FP_XX = 0x00500000, // -mfpxx
82 eMIPS_ABI_FP_64 = 0x00600000, // -mips32r2 -mfp64
83 eMIPS_ABI_FP_64A = 0x00700000, // -mips32r2 -mfp64 -mno-odd-spreg
84 eMIPS_ABI_FP_mask = 0x00700000
85 };
86
87 // ARM specific e_flags
88 enum ARMeflags {
89 eARM_abi_soft_float = 0x00000200,
91 };
92
94 eRISCV_rvc = 0x00000001, /// RVC, +c
95 eRISCV_float_abi_soft = 0x00000000, /// soft float
96 eRISCV_float_abi_single = 0x00000002, /// single precision floating point, +f
97 eRISCV_float_abi_double = 0x00000004, /// double precision floating point, +d
98 eRISCV_float_abi_quad = 0x00000006, /// quad precision floating point, +q
100 eRISCV_rve = 0x00000008, /// RVE, +e
101 eRISCV_tso = 0x00000010, /// RVTSO (total store ordering)
102 };
103
109
111 eLoongArch_abi_soft_float = 0x00000000, /// soft float
113 0x00000001, /// single precision floating point, +f
115 0x00000002, /// double precision floating point, +d
117 };
118
124
125 enum Core {
143
163
184
186
200
204
206
208
210
215
217 eCore_x86_64_x86_64h, // Haswell enabled x86_64
219
223
226
229
232
233 eCore_arc, // little endian ARC
234
236
238
240
242 // The following constants are used for wildcard matching only
250
253
256
259
262
265
268
271
274
277
280
283
286
287 };
288
289 /// Default constructor.
290 ///
291 /// Default constructor that initializes the object with invalid cpu type
292 /// and subtype values.
294
295 /// Constructor over triple.
296 ///
297 /// Constructs an ArchSpec with properties consistent with the given Triple.
298 explicit ArchSpec(const llvm::Triple &triple);
299 explicit ArchSpec(const char *triple_cstr);
300 explicit ArchSpec(llvm::StringRef triple_str);
301 /// Constructor over architecture name.
302 ///
303 /// Constructs an ArchSpec with properties consistent with the given object
304 /// type and architecture name.
305 explicit ArchSpec(ArchitectureType arch_type, uint32_t cpu_type,
306 uint32_t cpu_subtype);
307
308 /// Destructor.
310
311 /// Returns true if the OS, vendor and environment fields of the triple are
312 /// unset. The triple is expected to be normalized
313 /// (llvm::Triple::normalize).
314 static bool ContainsOnlyArch(const llvm::Triple &normalized_triple);
315
316 static void ListSupportedArchNames(StringList &list);
317 static void AutoComplete(CompletionRequest &request);
318
319 /// Returns a static string representing the current architecture.
320 ///
321 /// \return A static string corresponding to the current
322 /// architecture.
323 const char *GetArchitectureName() const;
324
325 /// if MIPS architecture return true.
326 ///
327 /// \return a boolean value.
328 bool IsMIPS() const;
329
330 /// If NVPTX architecture return true.
331 ///
332 /// \return a boolean value.
333 bool IsNVPTX() const;
334
335 /// Returns a string representing current architecture as a target CPU for
336 /// tools like compiler, disassembler etc.
337 ///
338 /// \return A string representing target CPU for the current
339 /// architecture.
340 std::string GetClangTargetCPU() const;
341
342 /// Return a string representing target application ABI.
343 ///
344 /// \return A string representing target application ABI.
345 std::string GetTargetABI() const;
346
347 /// Clears the object state.
348 ///
349 /// Clears the object state back to a default invalid state.
350 void Clear();
351
352 /// Returns the size in bytes of an address of the current architecture.
353 ///
354 /// \return The byte size of an address of the current architecture.
355 uint32_t GetAddressByteSize() const;
356
357 /// Returns a machine family for the current architecture.
358 ///
359 /// \return An LLVM arch type.
360 llvm::Triple::ArchType GetMachine() const;
361
362 /// Tests if this ArchSpec is valid.
363 ///
364 /// \return True if the current architecture is valid, false
365 /// otherwise.
366 bool IsValid() const {
368 }
369 explicit operator bool() const { return IsValid(); }
370
372 return !m_triple.getVendorName().empty();
373 }
374
375 bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); }
376
378 return m_triple.hasEnvironment();
379 }
380
381 /// Merges fields from another ArchSpec into this ArchSpec.
382 ///
383 /// This will use the supplied ArchSpec to fill in any fields of the triple
384 /// in this ArchSpec which were unspecified. This can be used to refine a
385 /// generic ArchSpec with a more specific one. For example, if this
386 /// ArchSpec's triple is something like i386-unknown-unknown-unknown, and we
387 /// have a triple which is x64-pc-windows-msvc, then merging that triple
388 /// into this one will result in the triple i386-pc-windows-msvc.
389 ///
390 void MergeFrom(const ArchSpec &other);
391
392 /// Change the architecture object type, CPU type and OS type.
393 ///
394 /// \param[in] arch_type The object type of this ArchSpec.
395 ///
396 /// \param[in] cpu The required CPU type.
397 ///
398 /// \param[in] os The optional OS type
399 /// The default value of 0 was chosen to from the ELF spec value
400 /// ELFOSABI_NONE. ELF is the only one using this parameter. If another
401 /// format uses this parameter and 0 does not work, use a value over
402 /// 255 because in the ELF header this is value is only a byte.
403 ///
404 /// \return True if the object, and CPU were successfully set.
405 ///
406 /// As a side effect, the vendor value is usually set to unknown. The
407 /// exceptions are
408 /// aarch64-apple-ios
409 /// arm-apple-ios
410 /// thumb-apple-ios
411 /// x86-apple-
412 /// x86_64-apple-
413 ///
414 /// As a side effect, the os value is usually set to unknown The exceptions
415 /// are
416 /// *-*-aix
417 /// aarch64-apple-ios
418 /// arm-apple-ios
419 /// thumb-apple-ios
420 /// powerpc-apple-darwin
421 /// *-*-freebsd
422 /// *-*-linux
423 /// *-*-netbsd
424 /// *-*-openbsd
425 /// *-*-solaris
426 bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub,
427 uint32_t os = 0);
428
429 /// Returns the byte order for the architecture specification.
430 ///
431 /// \return The endian enumeration for the current endianness of
432 /// the architecture specification
434
435 /// Sets this ArchSpec's byte order.
436 ///
437 /// In the common case there is no need to call this method as the byte
438 /// order can almost always be determined by the architecture. However, many
439 /// CPU's are bi-endian (ARM, Alpha, PowerPC, etc) and the default/assumed
440 /// byte order may be incorrect.
441 void SetByteOrder(lldb::ByteOrder byte_order) { m_byte_order = byte_order; }
442
443 uint32_t GetMinimumOpcodeByteSize() const;
444
445 uint32_t GetMaximumOpcodeByteSize() const;
446
447 Core GetCore() const { return m_core; }
448
449 uint32_t GetMachOCPUType() const;
450
451 uint32_t GetMachOCPUSubType() const;
452
453 /// Architecture data byte width accessor
454 ///
455 /// \return the size in 8-bit (host) bytes of a minimum addressable unit
456 /// from the Architecture's data bus
457 uint32_t GetDataByteSize() const;
458
459 /// Architecture code byte width accessor
460 ///
461 /// \return the size in 8-bit (host) bytes of a minimum addressable unit
462 /// from the Architecture's code bus
463 uint32_t GetCodeByteSize() const;
464
465 /// Architecture triple accessor.
466 ///
467 /// \return A triple describing this ArchSpec.
468 llvm::Triple &GetTriple() { return m_triple; }
469
470 /// Architecture triple accessor.
471 ///
472 /// \return A triple describing this ArchSpec.
473 const llvm::Triple &GetTriple() const { return m_triple; }
474
475 void DumpTriple(llvm::raw_ostream &s) const;
476
477 /// Architecture triple setter.
478 ///
479 /// Configures this ArchSpec according to the given triple. If the triple
480 /// has unknown components in all of the vendor, OS, and the optional
481 /// environment field (i.e. "i386-unknown-unknown") then default values are
482 /// taken from the host. Architecture and environment components are used
483 /// to further resolve the CPU type and subtype, endian characteristics,
484 /// etc.
485 ///
486 /// \return A triple describing this ArchSpec.
487 bool SetTriple(const llvm::Triple &triple);
488
489 bool SetTriple(llvm::StringRef triple_str);
490
491 /// Returns the default endianness of the architecture.
492 ///
493 /// \return The endian enumeration for the default endianness of
494 /// the architecture.
496
497 /// Returns true if 'char' is a signed type by default in the architecture
498 /// false otherwise
499 ///
500 /// \return True if 'char' is a signed type by default on the
501 /// architecture and false otherwise.
502 bool CharIsSignedByDefault() const;
503
505
506 /// Compare this ArchSpec to another ArchSpec. \a match specifies the kind of
507 /// matching that is to be done. CompatibleMatch requires only a compatible
508 /// cpu type (e.g., armv7s is compatible with armv7). ExactMatch requires an
509 /// exact match (armv7s is not an exact match with armv7).
510 ///
511 /// \return true if the two ArchSpecs match.
512 bool IsMatch(const ArchSpec &rhs, MatchType match) const;
513
514 /// Shorthand for IsMatch(rhs, ExactMatch).
515 bool IsExactMatch(const ArchSpec &rhs) const {
516 return IsMatch(rhs, ExactMatch);
517 }
518
519 /// Shorthand for IsMatch(rhs, CompatibleMatch).
520 bool IsCompatibleMatch(const ArchSpec &rhs) const {
521 return IsMatch(rhs, CompatibleMatch);
522 }
523
524 bool IsFullySpecifiedTriple() const;
525
526 /// Detect whether this architecture uses thumb code exclusively
527 ///
528 /// Some embedded ARM chips (e.g. the ARM Cortex M0-7 line) can only execute
529 /// the Thumb instructions, never Arm. We should normally pick up
530 /// arm/thumbness from their the processor status bits (cpsr/xpsr) or hints
531 /// on each function - but when doing bare-boards low level debugging
532 /// (especially common with these embedded processors), we may not have
533 /// those things easily accessible.
534 ///
535 /// \return true if this is an arm ArchSpec which can only execute Thumb
536 /// instructions
537 bool IsAlwaysThumbInstructions() const;
538
539 uint32_t GetFlags() const { return m_flags; }
540
541 void SetFlags(uint32_t flags) { m_flags = flags; }
542
543 void SetFlags(const std::string &elf_abi);
544
545protected:
546 void UpdateCore();
547
548 llvm::Triple m_triple;
551
552 // Additional arch flags which we cannot get from triple and core For MIPS
553 // these are application specific extensions like micromips, mips16 etc.
554 uint32_t m_flags = 0;
555
556 // Called when m_def or m_entry are changed. Fills in all remaining members
557 // with default values.
558 void CoreUpdated(bool update_triple);
559};
560
561/// \fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs) Less than
562/// operator.
563///
564/// Tests two ArchSpec objects to see if \a lhs is less than \a rhs.
565///
566/// \param[in] lhs The Left Hand Side ArchSpec object to compare. \param[in]
567/// rhs The Left Hand Side ArchSpec object to compare.
568///
569/// \return true if \a lhs is less than \a rhs
570bool operator<(const ArchSpec &lhs, const ArchSpec &rhs);
571bool operator==(const ArchSpec &lhs, const ArchSpec &rhs);
572bool operator!=(const ArchSpec &lhs, const ArchSpec &rhs);
573
574bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch);
575
576} // namespace lldb_private
577
578#endif // LLDB_UTILITY_ARCHSPEC_H
An architecture specification class.
Definition ArchSpec.h:31
static void ListSupportedArchNames(StringList &list)
Definition ArchSpec.cpp:275
bool IsFullySpecifiedTriple() const
void SetByteOrder(lldb::ByteOrder byte_order)
Sets this ArchSpec's byte order.
Definition ArchSpec.h:441
bool IsNVPTX() const
If NVPTX architecture return true.
Definition ArchSpec.cpp:548
static void AutoComplete(CompletionRequest &request)
Definition ArchSpec.cpp:280
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:676
uint32_t GetCodeByteSize() const
Architecture code byte width accessor.
Definition ArchSpec.cpp:666
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:366
void Clear()
Clears the object state.
Definition ArchSpec.cpp:529
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:468
void SetFlags(uint32_t flags)
Definition ArchSpec.h:541
bool IsAlwaysThumbInstructions() const
Detect whether this architecture uses thumb code exclusively.
bool TripleEnvironmentWasSpecified() const
Definition ArchSpec.h:377
bool IsMatch(const ArchSpec &rhs, MatchType match) const
Compare this ArchSpec to another ArchSpec.
Definition ArchSpec.cpp:960
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp:732
llvm::Triple m_triple
Definition ArchSpec.h:548
lldb::ByteOrder GetDefaultEndian() const
Returns the default endianness of the architecture.
Definition ArchSpec.cpp:690
lldb::ByteOrder m_byte_order
Definition ArchSpec.h:550
~ArchSpec()
Destructor.
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
Definition ArchSpec.cpp:836
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition ArchSpec.cpp:794
void DumpTriple(llvm::raw_ostream &s) const
uint32_t GetMachOCPUSubType() const
Definition ArchSpec.cpp:652
void CoreUpdated(bool update_triple)
@ eLoongArch_abi_single_float
soft float
Definition ArchSpec.h:112
@ eLoongArch_abi_mask
double precision floating point, +d
Definition ArchSpec.h:116
@ eLoongArch_abi_double_float
single precision floating point, +f
Definition ArchSpec.h:114
bool IsMIPS() const
if MIPS architecture return true.
Definition ArchSpec.cpp:546
uint32_t GetDataByteSize() const
Architecture data byte width accessor.
Definition ArchSpec.cpp:664
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition ArchSpec.h:520
bool CharIsSignedByDefault() const
Returns true if 'char' is a signed type by default in the architecture false otherwise.
Definition ArchSpec.cpp:697
bool IsExactMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, ExactMatch).
Definition ArchSpec.h:515
ArchSpec()
Default constructor.
uint32_t GetMachOCPUType() const
Definition ArchSpec.cpp:640
std::string GetTargetABI() const
Return a string representing target application ABI.
Definition ArchSpec.cpp:550
uint32_t GetMinimumOpcodeByteSize() const
Definition ArchSpec.cpp:915
uint32_t GetFlags() const
Definition ArchSpec.h:539
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition ArchSpec.cpp:723
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:668
@ eRISCV_float_abi_double
single precision floating point, +f
Definition ArchSpec.h:97
@ eRISCV_float_abi_soft
RVC, +c.
Definition ArchSpec.h:95
@ eRISCV_float_abi_quad
double precision floating point, +d
Definition ArchSpec.h:98
@ eRISCV_float_abi_mask
quad precision floating point, +q
Definition ArchSpec.h:99
@ eRISCV_float_abi_single
soft float
Definition ArchSpec.h:96
std::string GetClangTargetCPU() const
Returns a string representing current architecture as a target CPU for tools like compiler,...
Definition ArchSpec.cpp:586
uint32_t GetMaximumOpcodeByteSize() const
Definition ArchSpec.cpp:922
bool TripleVendorWasSpecified() const
Definition ArchSpec.h:371
Core GetCore() const
Definition ArchSpec.h:447
bool TripleOSWasSpecified() const
Definition ArchSpec.h:375
static bool ContainsOnlyArch(const llvm::Triple &normalized_triple)
Returns true if the OS, vendor and environment fields of the triple are unset.
Definition ArchSpec.cpp:787
const llvm::Triple & GetTriple() const
Architecture triple accessor.
Definition ArchSpec.h:473
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:539
"lldb/Utility/ArgCompletionRequest.h"
A class that represents a running process on the host machine.
bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch)
Definition ArchSpec.cpp:738
bool operator!=(const Address &lhs, const Address &rhs)
Definition Address.cpp:1017
bool operator==(const Address &lhs, const Address &rhs)
Definition Address.cpp:1011
bool operator<(const Address &lhs, const Address &rhs)
Definition Address.cpp:980
ByteOrder
Byte ordering definitions.