[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- ABI.cpp -----------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/ABI.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
2011-12-17 09:35:57 +08:00
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Core/ValueObjectConstResult.h"
|
2019-06-01 04:17:21 +08:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2015-08-12 06:53:00 +08:00
|
|
|
#include "lldb/Symbol/CompilerType.h"
|
2015-10-01 03:57:57 +08:00
|
|
|
#include "lldb/Symbol/TypeSystem.h"
|
2011-12-23 03:12:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2011-12-17 09:35:57 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
Have ABI plugins vend llvm MCRegisterInfo data
Summary:
I was recently surprised to learn that there is a total of 2 (two) users
of the register info definitions contained in the ABI plugins. Yet, the
defitions themselves span nearly 10kLOC.
The two users are:
- dwarf expression pretty printer
- the mechanism for augmenting the register info definitions obtained
over gdb-remote protocol (AugmentRegisterInfoViaABI)
Both of these uses need the DWARF an EH register numbers, which is
information that is already available in LLVM. This patch makes it
possible to do so.
It adds a GetMCRegisterInfo method to the ABI class, which every class
is expected to implement. Normally, it should be sufficient to obtain
the definitions from the appropriate llvm::Target object (for which I
provide a utility function), but the subclasses are free to construct it
in any way they deem fit.
We should be able to always get the MCRegisterInfo object from llvm,
with one important exception: if the relevant llvm target was disabled
at compile time. To handle this, I add a mechanism to disable the
compilation of ABI plugins based on the value of LLVM_TARGETS_TO_BUILD
cmake setting. This ensures all our existing are able to create their
MCRegisterInfo objects.
The new MCRegisterInfo api is not used yet, but the intention is to make
use of it in follow-up patches.
Reviewers: jasonmolenda, aprantl, JDevlieghere, tatyana-krasnukha
Subscribers: wuzish, nemanjai, mgorny, kbarton, atanasyan, lldb-commits
Differential Revision: https://reviews.llvm.org/D67965
llvm-svn: 372862
2019-09-25 21:03:04 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2020-02-18 01:06:18 +08:00
|
|
|
#include <cctype>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-05-12 02:39:18 +08:00
|
|
|
ABISP
|
2017-06-29 10:57:03 +08:00
|
|
|
ABI::FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch) {
|
2011-05-12 02:39:18 +08:00
|
|
|
ABISP abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
ABICreateInstance create_callback;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
for (uint32_t idx = 0;
|
2016-02-18 08:10:17 +08:00
|
|
|
(create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) !=
|
|
|
|
nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
++idx) {
|
2017-06-29 10:57:03 +08:00
|
|
|
abi_sp = create_callback(process_sp, arch);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-12 02:39:18 +08:00
|
|
|
if (abi_sp)
|
|
|
|
return abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-05-12 02:39:18 +08:00
|
|
|
abi_sp.reset();
|
|
|
|
return abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-18 08:10:17 +08:00
|
|
|
ABI::~ABI() = default;
|
2011-08-22 10:49:39 +08:00
|
|
|
|
2020-02-02 17:27:40 +08:00
|
|
|
bool RegInfoBasedABI::GetRegisterInfoByName(ConstString name, RegisterInfo &info) {
|
2011-08-22 10:49:39 +08:00
|
|
|
uint32_t count = 0;
|
|
|
|
const RegisterInfo *register_info_array = GetRegisterInfoArray(count);
|
|
|
|
if (register_info_array) {
|
|
|
|
const char *unique_name_cstr = name.GetCString();
|
|
|
|
uint32_t i;
|
2016-02-18 08:10:17 +08:00
|
|
|
for (i = 0; i < count; ++i) {
|
2020-02-19 18:27:10 +08:00
|
|
|
const char *reg_name = register_info_array[i].name;
|
|
|
|
assert(ConstString(reg_name).GetCString() == reg_name &&
|
|
|
|
"register_info_array[i].name not from a ConstString?");
|
|
|
|
if (reg_name == unique_name_cstr) {
|
2011-08-22 10:49:39 +08:00
|
|
|
info = register_info_array[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-18 08:10:17 +08:00
|
|
|
for (i = 0; i < count; ++i) {
|
2020-02-19 18:27:10 +08:00
|
|
|
const char *reg_alt_name = register_info_array[i].alt_name;
|
|
|
|
assert((reg_alt_name == nullptr ||
|
|
|
|
ConstString(reg_alt_name).GetCString() == reg_alt_name) &&
|
|
|
|
"register_info_array[i].alt_name not from a ConstString?");
|
|
|
|
if (reg_alt_name == unique_name_cstr) {
|
2011-08-22 10:49:39 +08:00
|
|
|
info = register_info_array[i];
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-22 01:21:01 +08:00
|
|
|
ValueObjectSP ABI::GetReturnValueObject(Thread &thread, CompilerType &ast_type,
|
|
|
|
bool persistent) const {
|
2011-12-17 09:35:57 +08:00
|
|
|
if (!ast_type.IsValid())
|
|
|
|
return ValueObjectSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-22 01:21:01 +08:00
|
|
|
ValueObjectSP return_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-22 01:21:01 +08:00
|
|
|
return_valobj_sp = GetReturnValueObjectImpl(thread, ast_type);
|
2011-12-23 03:12:40 +08:00
|
|
|
if (!return_valobj_sp)
|
2014-07-22 01:21:01 +08:00
|
|
|
return return_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
// Now turn this into a persistent variable.
|
|
|
|
// FIXME: This code is duplicated from Target::EvaluateExpression, and it is
|
|
|
|
// used in similar form in a couple
|
|
|
|
// of other places. Figure out the correct Create function to do all this
|
2016-09-07 04:57:50 +08:00
|
|
|
// work.
|
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
if (persistent) {
|
2018-05-01 07:59:15 +08:00
|
|
|
Target &target = *thread.CalculateTarget();
|
2015-10-02 00:28:02 +08:00
|
|
|
PersistentExpressionState *persistent_expression_state =
|
2018-05-01 07:59:15 +08:00
|
|
|
target.GetPersistentExpressionStateForLanguage(
|
2015-10-02 00:28:02 +08:00
|
|
|
ast_type.GetMinimumLanguage());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-01 03:57:57 +08:00
|
|
|
if (!persistent_expression_state)
|
2020-01-09 06:18:47 +08:00
|
|
|
return {};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 07:59:17 +08:00
|
|
|
ConstString persistent_variable_name =
|
2020-03-21 05:59:54 +08:00
|
|
|
persistent_expression_state->GetNextPersistentVariableName();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
lldb::ValueObjectSP const_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
// Check in case our value is already a constant value
|
|
|
|
if (return_valobj_sp->GetIsConstant()) {
|
|
|
|
const_valobj_sp = return_valobj_sp;
|
|
|
|
const_valobj_sp->SetName(persistent_variable_name);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2011-12-23 03:12:40 +08:00
|
|
|
const_valobj_sp =
|
|
|
|
return_valobj_sp->CreateConstantValue(persistent_variable_name);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
lldb::ValueObjectSP live_valobj_sp = return_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
return_valobj_sp = const_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-17 15:03:17 +08:00
|
|
|
ExpressionVariableSP expr_variable_sp(
|
2015-10-02 07:07:06 +08:00
|
|
|
persistent_expression_state->CreatePersistentVariable(
|
|
|
|
return_valobj_sp));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-17 15:03:17 +08:00
|
|
|
assert(expr_variable_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
// Set flags and live data as appropriate
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
const Value &result_value = live_valobj_sp->GetValue();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
switch (result_value.GetValueType()) {
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
// we don't do anything with these for now
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2011-12-23 03:12:40 +08:00
|
|
|
case Value::eValueTypeScalar:
|
2012-10-31 07:56:14 +08:00
|
|
|
case Value::eValueTypeVector:
|
2019-07-17 15:03:17 +08:00
|
|
|
expr_variable_sp->m_flags |=
|
2019-06-01 04:17:21 +08:00
|
|
|
ExpressionVariable::EVIsFreezeDried;
|
2019-07-17 15:03:17 +08:00
|
|
|
expr_variable_sp->m_flags |=
|
2019-06-01 04:17:21 +08:00
|
|
|
ExpressionVariable::EVIsLLDBAllocated;
|
2019-07-17 15:03:17 +08:00
|
|
|
expr_variable_sp->m_flags |=
|
2019-06-01 04:17:21 +08:00
|
|
|
ExpressionVariable::EVNeedsAllocation;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2011-12-23 03:12:40 +08:00
|
|
|
case Value::eValueTypeLoadAddress:
|
2019-07-17 15:03:17 +08:00
|
|
|
expr_variable_sp->m_live_sp = live_valobj_sp;
|
|
|
|
expr_variable_sp->m_flags |=
|
2019-06-01 04:17:21 +08:00
|
|
|
ExpressionVariable::EVIsProgramReference;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-17 15:03:17 +08:00
|
|
|
return_valobj_sp = expr_variable_sp->GetValueObject();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-07-22 01:21:01 +08:00
|
|
|
return return_valobj_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 01:21:01 +08:00
|
|
|
ValueObjectSP ABI::GetReturnValueObject(Thread &thread, llvm::Type &ast_type,
|
2012-02-21 08:09:25 +08:00
|
|
|
bool persistent) const {
|
2014-07-22 01:21:01 +08:00
|
|
|
ValueObjectSP return_valobj_sp;
|
2011-12-23 03:12:40 +08:00
|
|
|
return_valobj_sp = GetReturnValueObjectImpl(thread, ast_type);
|
2014-07-22 01:21:01 +08:00
|
|
|
return return_valobj_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// specialized to work with llvm IR types
|
|
|
|
//
|
|
|
|
// for now we will specify a default implementation so that we don't need to
|
|
|
|
// modify other ABIs
|
|
|
|
lldb::ValueObjectSP ABI::GetReturnValueObjectImpl(Thread &thread,
|
|
|
|
llvm::Type &ir_type) const {
|
|
|
|
ValueObjectSP return_valobj_sp;
|
|
|
|
|
|
|
|
/* this is a dummy and will only be called if an ABI does not override this */
|
|
|
|
|
|
|
|
return return_valobj_sp;
|
|
|
|
}
|
2011-12-17 09:35:57 +08:00
|
|
|
|
2014-07-22 01:21:01 +08:00
|
|
|
bool ABI::PrepareTrivialCall(Thread &thread, lldb::addr_t sp,
|
|
|
|
lldb::addr_t functionAddress,
|
|
|
|
lldb::addr_t returnAddress, llvm::Type &returntype,
|
|
|
|
llvm::ArrayRef<ABI::CallArgument> args) const {
|
|
|
|
// dummy prepare trivial call
|
2017-01-06 08:38:06 +08:00
|
|
|
llvm_unreachable("Should never get here!");
|
2014-07-22 01:21:01 +08:00
|
|
|
}
|
2016-04-14 22:25:20 +08:00
|
|
|
|
|
|
|
bool ABI::GetFallbackRegisterLocation(
|
|
|
|
const RegisterInfo *reg_info,
|
|
|
|
UnwindPlan::Row::RegisterLocation &unwind_regloc) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Did the UnwindPlan fail to give us the caller's stack pointer? The stack
|
|
|
|
// pointer is defined to be the same as THIS frame's CFA, so return the CFA
|
|
|
|
// value as the caller's stack pointer. This is true on x86-32/x86-64 at
|
|
|
|
// least.
|
2016-04-14 22:25:20 +08:00
|
|
|
if (reg_info->kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_SP) {
|
|
|
|
unwind_regloc.SetIsCFAPlusOffset(0);
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-04-14 22:25:20 +08:00
|
|
|
// If a volatile register is being requested, we don't want to forward the
|
2018-05-01 00:49:04 +08:00
|
|
|
// next frame's register contents up the stack -- the register is not
|
|
|
|
// retrievable at this frame.
|
2016-04-14 22:25:20 +08:00
|
|
|
if (RegisterIsVolatile(reg_info)) {
|
|
|
|
unwind_regloc.SetUndefined();
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-04-14 22:25:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
Have ABI plugins vend llvm MCRegisterInfo data
Summary:
I was recently surprised to learn that there is a total of 2 (two) users
of the register info definitions contained in the ABI plugins. Yet, the
defitions themselves span nearly 10kLOC.
The two users are:
- dwarf expression pretty printer
- the mechanism for augmenting the register info definitions obtained
over gdb-remote protocol (AugmentRegisterInfoViaABI)
Both of these uses need the DWARF an EH register numbers, which is
information that is already available in LLVM. This patch makes it
possible to do so.
It adds a GetMCRegisterInfo method to the ABI class, which every class
is expected to implement. Normally, it should be sufficient to obtain
the definitions from the appropriate llvm::Target object (for which I
provide a utility function), but the subclasses are free to construct it
in any way they deem fit.
We should be able to always get the MCRegisterInfo object from llvm,
with one important exception: if the relevant llvm target was disabled
at compile time. To handle this, I add a mechanism to disable the
compilation of ABI plugins based on the value of LLVM_TARGETS_TO_BUILD
cmake setting. This ensures all our existing are able to create their
MCRegisterInfo objects.
The new MCRegisterInfo api is not used yet, but the intention is to make
use of it in follow-up patches.
Reviewers: jasonmolenda, aprantl, JDevlieghere, tatyana-krasnukha
Subscribers: wuzish, nemanjai, mgorny, kbarton, atanasyan, lldb-commits
Differential Revision: https://reviews.llvm.org/D67965
llvm-svn: 372862
2019-09-25 21:03:04 +08:00
|
|
|
|
|
|
|
std::unique_ptr<llvm::MCRegisterInfo> ABI::MakeMCRegisterInfo(const ArchSpec &arch) {
|
|
|
|
std::string triple = arch.GetTriple().getTriple();
|
|
|
|
std::string lookup_error;
|
|
|
|
const llvm::Target *target =
|
|
|
|
llvm::TargetRegistry::lookupTarget(triple, lookup_error);
|
|
|
|
if (!target) {
|
|
|
|
LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS),
|
|
|
|
"Failed to create an llvm target for {0}: {1}", triple,
|
|
|
|
lookup_error);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::unique_ptr<llvm::MCRegisterInfo> info_up(
|
|
|
|
target->createMCRegInfo(triple));
|
|
|
|
assert(info_up);
|
|
|
|
return info_up;
|
|
|
|
}
|
2019-12-03 18:39:20 +08:00
|
|
|
|
2020-02-02 17:27:40 +08:00
|
|
|
void RegInfoBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
|
2019-12-03 18:39:20 +08:00
|
|
|
if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM &&
|
|
|
|
info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RegisterInfo abi_info;
|
|
|
|
if (!GetRegisterInfoByName(ConstString(info.name), abi_info))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame];
|
|
|
|
if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF];
|
|
|
|
if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric];
|
|
|
|
}
|
[lldb] Delete register info definitions in the x86_64 ABI classes
Summary:
These definitions are used to "augment" information received from the remote
target with eh/debug frame and "generic" register numbers.
Besides being verbose, this information was also incomplete (new registers like
xmm16-31 were missing) and sometimes even downright wrong (ymm register
numbers).
Most of this information is available via llvm's MCRegisterInfo. This patch
creates a new class, MCBasedABI, which retrieves the eh and debug frame register
numbers this way. The tricky part here is that the llvm class uses all-caps
register names, whereas lldb register are lowercase, and sometimes called
slightly differently. Therefore this class introduces some hooks to allow a
subclass to customize the MC lookup. The subclass also needs to suply the
"generic" register numbers, as this is an lldb invention.
This patch ports the x86_64 ABI classes to use the new register info mechanism.
It also creates a new "ABIx86_64" class which can be used to house code common
to x86_64 both ABIs. Right now, this just consists of a single function, but
there are plenty of other things that could be moved here too.
Reviewers: JDevlieghere, jasonmolenda
Subscribers: mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74244
2020-02-04 00:58:37 +08:00
|
|
|
|
|
|
|
void MCBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
|
|
|
|
uint32_t eh, dwarf;
|
|
|
|
std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name);
|
|
|
|
|
|
|
|
if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindEHFrame] = eh;
|
|
|
|
if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindDWARF] = dwarf;
|
|
|
|
if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
|
|
|
|
info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<uint32_t, uint32_t>
|
|
|
|
MCBasedABI::GetEHAndDWARFNums(llvm::StringRef name) {
|
|
|
|
std::string mc_name = GetMCName(name.str());
|
2020-02-17 21:12:29 +08:00
|
|
|
for (char &c : mc_name)
|
|
|
|
c = std::toupper(c);
|
[lldb] Delete register info definitions in the x86_64 ABI classes
Summary:
These definitions are used to "augment" information received from the remote
target with eh/debug frame and "generic" register numbers.
Besides being verbose, this information was also incomplete (new registers like
xmm16-31 were missing) and sometimes even downright wrong (ymm register
numbers).
Most of this information is available via llvm's MCRegisterInfo. This patch
creates a new class, MCBasedABI, which retrieves the eh and debug frame register
numbers this way. The tricky part here is that the llvm class uses all-caps
register names, whereas lldb register are lowercase, and sometimes called
slightly differently. Therefore this class introduces some hooks to allow a
subclass to customize the MC lookup. The subclass also needs to suply the
"generic" register numbers, as this is an lldb invention.
This patch ports the x86_64 ABI classes to use the new register info mechanism.
It also creates a new "ABIx86_64" class which can be used to house code common
to x86_64 both ABIs. Right now, this just consists of a single function, but
there are plenty of other things that could be moved here too.
Reviewers: JDevlieghere, jasonmolenda
Subscribers: mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74244
2020-02-04 00:58:37 +08:00
|
|
|
int eh = -1;
|
|
|
|
int dwarf = -1;
|
|
|
|
for (unsigned reg = 0; reg < m_mc_register_info_up->getNumRegs(); ++reg) {
|
|
|
|
if (m_mc_register_info_up->getName(reg) == mc_name) {
|
|
|
|
eh = m_mc_register_info_up->getDwarfRegNum(reg, /*isEH=*/true);
|
|
|
|
dwarf = m_mc_register_info_up->getDwarfRegNum(reg, /*isEH=*/false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::pair<uint32_t, uint32_t>(eh == -1 ? LLDB_INVALID_REGNUM : eh,
|
|
|
|
dwarf == -1 ? LLDB_INVALID_REGNUM
|
|
|
|
: dwarf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCBasedABI::MapRegisterName(std::string &name, llvm::StringRef from_prefix,
|
|
|
|
llvm::StringRef to_prefix) {
|
|
|
|
llvm::StringRef name_ref = name;
|
|
|
|
if (!name_ref.consume_front(from_prefix))
|
|
|
|
return;
|
|
|
|
uint64_t _;
|
|
|
|
if (name_ref.empty() || to_integer(name_ref, _, 10))
|
|
|
|
name = (to_prefix + name_ref).str();
|
|
|
|
}
|