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