[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
|
|
|
//===-- CommandObjectMemory.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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
#include "CommandObjectMemory.h"
|
2021-02-20 00:31:46 +08:00
|
|
|
#include "CommandObjectMemoryTag.h"
|
2017-03-04 04:57:05 +08:00
|
|
|
#include "lldb/Core/DumpDataExtractor.h"
|
2016-06-10 00:34:06 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
#include "lldb/Core/ValueObjectMemory.h"
|
2019-06-13 01:47:06 +08:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2016-06-10 00:34:06 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
2022-04-14 18:56:44 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupMemoryTag.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupOutputFile.h"
|
2011-04-29 04:55:26 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
2019-06-13 01:47:06 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueLanguage.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueString.h"
|
2016-06-10 00:34:06 +08:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2016-02-11 05:28:13 +08:00
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
2016-06-10 00:34:06 +08:00
|
|
|
#include "lldb/Symbol/TypeList.h"
|
2021-11-03 20:10:40 +08:00
|
|
|
#include "lldb/Target/ABI.h"
|
2019-06-13 01:47:06 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2014-09-04 09:03:18 +08:00
|
|
|
#include "lldb/Target/MemoryHistory.h"
|
2016-06-10 00:34:06 +08:00
|
|
|
#include "lldb/Target/MemoryRegionInfo.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2013-11-04 17:33:30 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2019-06-13 01:47:06 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2014-09-04 09:03:18 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2020-11-04 23:25:38 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <cinttypes>
|
|
|
|
#include <memory>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-07-25 19:22:46 +08:00
|
|
|
#define LLDB_OPTIONS_memory_read
|
|
|
|
#include "CommandOptions.inc"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
class OptionGroupReadMemory : public OptionGroup {
|
|
|
|
public:
|
|
|
|
OptionGroupReadMemory()
|
2022-01-24 03:07:14 +08:00
|
|
|
: m_num_per_line(1, 1), m_offset(0, 0),
|
2019-06-13 01:47:06 +08:00
|
|
|
m_language_for_type(eLanguageTypeUnknown) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~OptionGroupReadMemory() override = default;
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-07-28 14:24:07 +08:00
|
|
|
return llvm::makeArrayRef(g_memory_read_options);
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2019-07-28 14:24:07 +08:00
|
|
|
const int short_option = g_memory_read_options[option_idx].short_option;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
switch (short_option) {
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'l':
|
2016-09-24 01:48:13 +08:00
|
|
|
error = m_num_per_line.SetValueFromString(option_value);
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_num_per_line.GetCurrentValue() == 0)
|
2011-10-26 08:56:27 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2016-09-24 01:48:13 +08:00
|
|
|
"invalid value for --num-per-line option '%s'",
|
|
|
|
option_value.str().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-11 04:52:20 +08:00
|
|
|
case 'b':
|
|
|
|
m_output_as_binary = true;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case 't':
|
2016-09-24 01:48:13 +08:00
|
|
|
error = m_view_as_type.SetValueFromString(option_value);
|
2010-10-11 04:52:20 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-04-28 09:27:38 +08:00
|
|
|
case 'r':
|
|
|
|
m_force = true;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
case 'x':
|
|
|
|
error = m_language_for_type.SetValueFromString(option_value);
|
|
|
|
break;
|
|
|
|
|
2015-11-05 03:32:01 +08:00
|
|
|
case 'E':
|
2016-09-24 01:48:13 +08:00
|
|
|
error = m_offset.SetValueFromString(option_value);
|
2015-10-30 07:40:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
2011-04-29 04:55:26 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
m_num_per_line.Clear();
|
|
|
|
m_output_as_binary = false;
|
2011-04-28 06:04:39 +08:00
|
|
|
m_view_as_type.Clear();
|
2011-10-25 14:44:01 +08:00
|
|
|
m_force = false;
|
|
|
|
m_offset.Clear();
|
2019-06-13 01:47:06 +08:00
|
|
|
m_language_for_type.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status FinalizeSettings(Target *target, OptionGroupFormat &format_options) {
|
|
|
|
Status error;
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionValueUInt64 &byte_size_value = format_options.GetByteSizeValue();
|
|
|
|
OptionValueUInt64 &count_value = format_options.GetCountValue();
|
2011-10-26 08:56:27 +08:00
|
|
|
const bool byte_size_option_set = byte_size_value.OptionWasSet();
|
2011-10-25 14:44:01 +08:00
|
|
|
const bool num_per_line_option_set = m_num_per_line.OptionWasSet();
|
|
|
|
const bool count_option_set = format_options.GetCountValue().OptionWasSet();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
switch (format_options.GetFormat()) {
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
case eFormatBoolean:
|
|
|
|
if (!byte_size_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = 1;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 1;
|
|
|
|
if (!count_option_set)
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
format_options.GetCountValue() = 8;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatCString:
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
case eFormatInstruction:
|
|
|
|
if (count_option_set)
|
|
|
|
byte_size_value = target->GetArchitecture().GetMaximumOpcodeByteSize();
|
|
|
|
m_num_per_line = 1;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatAddressInfo:
|
|
|
|
if (!byte_size_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = target->GetArchitecture().GetAddressByteSize();
|
2011-04-29 04:55:26 +08:00
|
|
|
m_num_per_line = 1;
|
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
format_options.GetCountValue() = 8;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatPointer:
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = target->GetArchitecture().GetAddressByteSize();
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 4;
|
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
format_options.GetCountValue() = 8;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatBinary:
|
|
|
|
case eFormatFloat:
|
|
|
|
case eFormatOctal:
|
|
|
|
case eFormatDecimal:
|
|
|
|
case eFormatEnum:
|
2019-08-22 05:30:55 +08:00
|
|
|
case eFormatUnicode8:
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatUnicode16:
|
|
|
|
case eFormatUnicode32:
|
|
|
|
case eFormatUnsigned:
|
|
|
|
case eFormatHexFloat:
|
2011-10-26 08:56:27 +08:00
|
|
|
if (!byte_size_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = 4;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 1;
|
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
format_options.GetCountValue() = 8;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-06-18 07:50:44 +08:00
|
|
|
case eFormatBytes:
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatBytesWithASCII:
|
2011-04-29 04:55:26 +08:00
|
|
|
if (byte_size_option_set) {
|
2011-10-25 14:44:01 +08:00
|
|
|
if (byte_size_value > 1)
|
2016-07-15 06:03:10 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"display format (bytes/bytes with ASCII) conflicts with the "
|
|
|
|
"specified byte size %" PRIu64 "\n"
|
|
|
|
"\tconsider using a different display format or don't specify "
|
|
|
|
"the byte size.",
|
|
|
|
byte_size_value.GetCurrentValue());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = 1;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 16;
|
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
format_options.GetCountValue() = 32;
|
2013-03-23 13:16:54 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-06-18 07:50:44 +08:00
|
|
|
case eFormatCharArray:
|
2013-03-23 13:16:54 +08:00
|
|
|
case eFormatChar:
|
|
|
|
case eFormatCharPrintable:
|
|
|
|
if (!byte_size_option_set)
|
|
|
|
byte_size_value = 1;
|
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 32;
|
|
|
|
if (!count_option_set)
|
|
|
|
format_options.GetCountValue() = 64;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatComplex:
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!byte_size_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = 8;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 1;
|
|
|
|
if (!count_option_set)
|
|
|
|
format_options.GetCountValue() = 8;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-29 04:55:26 +08:00
|
|
|
case eFormatComplexInteger:
|
|
|
|
if (!byte_size_option_set)
|
|
|
|
byte_size_value = 8;
|
|
|
|
if (!num_per_line_option_set)
|
|
|
|
m_num_per_line = 1;
|
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
format_options.GetCountValue() = 8;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatHex:
|
|
|
|
if (!byte_size_option_set)
|
|
|
|
byte_size_value = 4;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set) {
|
2011-10-25 14:44:01 +08:00
|
|
|
switch (byte_size_value) {
|
|
|
|
case 1:
|
2016-09-07 04:57:50 +08:00
|
|
|
case 2:
|
2011-10-25 14:44:01 +08:00
|
|
|
m_num_per_line = 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2011-04-29 04:55:26 +08:00
|
|
|
m_num_per_line = 4;
|
2011-10-25 14:44:01 +08:00
|
|
|
break;
|
2011-04-29 04:55:26 +08:00
|
|
|
case 8:
|
|
|
|
m_num_per_line = 2;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-04-29 04:55:26 +08:00
|
|
|
m_num_per_line = 1;
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
count_value = 8;
|
2011-04-29 04:55:26 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-29 04:55:26 +08:00
|
|
|
case eFormatVectorOfChar:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatVectorOfSInt8:
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatVectorOfUInt8:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatVectorOfSInt16:
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatVectorOfUInt16:
|
|
|
|
case eFormatVectorOfSInt32:
|
|
|
|
case eFormatVectorOfUInt32:
|
|
|
|
case eFormatVectorOfSInt64:
|
|
|
|
case eFormatVectorOfUInt64:
|
2015-10-16 16:28:47 +08:00
|
|
|
case eFormatVectorOfFloat16:
|
2011-04-28 06:04:39 +08:00
|
|
|
case eFormatVectorOfFloat32:
|
|
|
|
case eFormatVectorOfFloat64:
|
|
|
|
case eFormatVectorOfUInt128:
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!byte_size_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
byte_size_value = 128;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!num_per_line_option_set)
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
m_num_per_line = 1;
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!count_option_set)
|
2011-10-25 14:44:01 +08:00
|
|
|
count_value = 4;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-10-26 12:32:38 +08:00
|
|
|
bool AnyOptionWasSet() const {
|
|
|
|
return m_num_per_line.OptionWasSet() || m_output_as_binary ||
|
2019-06-13 01:47:06 +08:00
|
|
|
m_view_as_type.OptionWasSet() || m_offset.OptionWasSet() ||
|
|
|
|
m_language_for_type.OptionWasSet();
|
2011-10-26 12:32:38 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
OptionValueUInt64 m_num_per_line;
|
|
|
|
bool m_output_as_binary = false;
|
|
|
|
OptionValueString m_view_as_type;
|
2012-04-28 09:27:38 +08:00
|
|
|
bool m_force;
|
2015-10-30 07:40:24 +08:00
|
|
|
OptionValueUInt64 m_offset;
|
2019-06-13 01:47:06 +08:00
|
|
|
OptionValueLanguage m_language_for_type;
|
2011-04-28 06:04:39 +08:00
|
|
|
};
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
// Read memory from the inferior process
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectMemoryRead : public CommandObjectParsed {
|
2011-04-28 06:04:39 +08:00
|
|
|
public:
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectMemoryRead(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(
|
|
|
|
interpreter, "memory read",
|
|
|
|
"Read from the memory of the current target process.", nullptr,
|
|
|
|
eCommandRequiresTarget | eCommandProcessMustBePaused),
|
2022-01-24 03:07:14 +08:00
|
|
|
m_format_options(eFormatBytesWithASCII, 1, 8),
|
2022-04-13 21:32:18 +08:00
|
|
|
m_memory_tag_options(/*note_binary=*/true),
|
2022-01-24 03:07:14 +08:00
|
|
|
m_prev_format_options(eFormatBytesWithASCII, 1, 8) {
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentEntry arg2;
|
2011-10-25 14:44:01 +08:00
|
|
|
CommandArgumentData start_addr_arg;
|
2011-04-29 04:55:26 +08:00
|
|
|
CommandArgumentData end_addr_arg;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
start_addr_arg.arg_type = eArgTypeAddressOrExpression;
|
2010-10-05 06:28:36 +08:00
|
|
|
start_addr_arg.arg_repetition = eArgRepeatPlain;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
2010-10-05 06:28:36 +08:00
|
|
|
// argument entry.
|
2011-04-28 06:04:39 +08:00
|
|
|
arg1.push_back(start_addr_arg);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
2013-01-29 09:48:30 +08:00
|
|
|
end_addr_arg.arg_type = eArgTypeAddressOrExpression;
|
2010-10-05 06:28:36 +08:00
|
|
|
end_addr_arg.arg_repetition = eArgRepeatOptional;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
2010-10-05 06:28:36 +08:00
|
|
|
// argument entry.
|
|
|
|
arg2.push_back(end_addr_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
2010-10-05 06:28:36 +08:00
|
|
|
m_arguments.push_back(arg1);
|
2013-11-13 10:18:44 +08:00
|
|
|
m_arguments.push_back(arg2);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
// Add the "--format" and "--count" options to group 1 and 3
|
2011-10-25 14:44:01 +08:00
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
OptionGroupFormat::OPTION_GROUP_FORMAT |
|
|
|
|
OptionGroupFormat::OPTION_GROUP_COUNT,
|
2011-11-23 02:07:35 +08:00
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3);
|
2011-10-25 14:44:01 +08:00
|
|
|
m_option_group.Append(&m_format_options,
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
OptionGroupFormat::OPTION_GROUP_GDB_FMT,
|
2011-11-23 02:07:35 +08:00
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_3);
|
2011-10-25 14:44:01 +08:00
|
|
|
// Add the "--size" option to group 1 and 2
|
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
OptionGroupFormat::OPTION_GROUP_SIZE,
|
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
|
2011-04-28 06:04:39 +08:00
|
|
|
m_option_group.Append(&m_memory_options);
|
|
|
|
m_option_group.Append(&m_outfile_options, LLDB_OPT_SET_ALL,
|
2011-11-23 02:07:35 +08:00
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3);
|
2011-04-29 04:55:26 +08:00
|
|
|
m_option_group.Append(&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3);
|
2022-04-14 18:56:44 +08:00
|
|
|
m_option_group.Append(&m_memory_tag_options, LLDB_OPT_SET_ALL,
|
|
|
|
LLDB_OPT_SET_ALL);
|
2015-10-08 00:56:17 +08:00
|
|
|
m_option_group.Finalize();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
~CommandObjectMemoryRead() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-02-05 07:16:31 +08:00
|
|
|
llvm::Optional<std::string> GetRepeatCommand(Args ¤t_command_args,
|
|
|
|
uint32_t index) override {
|
|
|
|
return m_cmd_name;
|
2011-10-26 12:32:38 +08:00
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2015-05-27 13:04:35 +08:00
|
|
|
// No need to check "target" for validity as eCommandRequiresTarget ensures
|
|
|
|
// it is valid
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t argc = command.GetArgumentCount();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-26 12:32:38 +08:00
|
|
|
if ((argc == 0 && m_next_addr == LLDB_INVALID_ADDRESS) || argc > 2) {
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendErrorWithFormat("%s takes a start address expression with "
|
|
|
|
"an optional end address expression.\n",
|
|
|
|
m_cmd_name.c_str());
|
2021-02-24 21:08:49 +08:00
|
|
|
result.AppendWarning("Expressions should be quoted if they contain "
|
|
|
|
"spaces or other special characters.");
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
CompilerType compiler_type;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
const char *view_as_type_cstr =
|
|
|
|
m_memory_options.m_view_as_type.GetCurrentValue();
|
|
|
|
if (view_as_type_cstr && view_as_type_cstr[0]) {
|
|
|
|
// We are viewing memory as a type
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-27 07:03:23 +08:00
|
|
|
const bool exact_match = false;
|
2011-04-28 06:04:39 +08:00
|
|
|
TypeList type_list;
|
|
|
|
uint32_t reference_count = 0;
|
|
|
|
uint32_t pointer_count = 0;
|
|
|
|
size_t idx;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-07-11 05:24:26 +08:00
|
|
|
#define ALL_KEYWORDS \
|
|
|
|
KEYWORD("const") \
|
|
|
|
KEYWORD("volatile") \
|
|
|
|
KEYWORD("restrict") \
|
|
|
|
KEYWORD("struct") \
|
|
|
|
KEYWORD("class") \
|
|
|
|
KEYWORD("union")
|
2011-04-29 04:55:26 +08:00
|
|
|
|
2012-07-11 05:24:26 +08:00
|
|
|
#define KEYWORD(s) s,
|
|
|
|
static const char *g_keywords[] = {ALL_KEYWORDS};
|
|
|
|
#undef KEYWORD
|
|
|
|
|
|
|
|
#define KEYWORD(s) (sizeof(s) - 1),
|
|
|
|
static const int g_keyword_lengths[] = {ALL_KEYWORDS};
|
|
|
|
#undef KEYWORD
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-07-11 05:24:26 +08:00
|
|
|
#undef ALL_KEYWORDS
|
2015-10-19 03:34:38 +08:00
|
|
|
|
2013-06-12 02:47:55 +08:00
|
|
|
static size_t g_num_keywords = sizeof(g_keywords) / sizeof(const char *);
|
|
|
|
std::string type_str(view_as_type_cstr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-06-12 02:47:55 +08:00
|
|
|
// Remove all instances of g_keywords that are followed by spaces
|
|
|
|
for (size_t i = 0; i < g_num_keywords; ++i) {
|
2011-04-28 06:04:39 +08:00
|
|
|
const char *keyword = g_keywords[i];
|
2013-06-12 02:47:55 +08:00
|
|
|
int keyword_len = g_keyword_lengths[i];
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
idx = 0;
|
2013-06-12 02:47:55 +08:00
|
|
|
while ((idx = type_str.find(keyword, idx)) != std::string::npos) {
|
|
|
|
if (type_str[idx + keyword_len] == ' ' ||
|
|
|
|
type_str[idx + keyword_len] == '\t') {
|
2011-04-28 06:04:39 +08:00
|
|
|
type_str.erase(idx, keyword_len + 1);
|
2016-09-07 04:57:50 +08:00
|
|
|
idx = 0;
|
|
|
|
} else {
|
2012-07-11 05:24:26 +08:00
|
|
|
idx += keyword_len;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-12 02:47:55 +08:00
|
|
|
bool done = type_str.empty();
|
2016-09-07 04:57:50 +08:00
|
|
|
//
|
2011-04-28 06:04:39 +08:00
|
|
|
idx = type_str.find_first_not_of(" \t");
|
2013-06-12 02:47:55 +08:00
|
|
|
if (idx > 0 && idx != std::string::npos)
|
2011-04-28 06:04:39 +08:00
|
|
|
type_str.erase(0, idx);
|
|
|
|
while (!done) {
|
2013-06-12 02:47:55 +08:00
|
|
|
// Strip trailing spaces
|
|
|
|
if (type_str.empty())
|
2011-04-28 06:04:39 +08:00
|
|
|
done = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
else {
|
2013-06-12 02:47:55 +08:00
|
|
|
switch (type_str[type_str.size() - 1]) {
|
2015-10-02 00:28:02 +08:00
|
|
|
case '*':
|
|
|
|
++pointer_count;
|
|
|
|
LLVM_FALLTHROUGH;
|
2011-04-28 06:04:39 +08:00
|
|
|
case ' ':
|
|
|
|
case '\t':
|
2015-10-02 00:28:02 +08:00
|
|
|
type_str.erase(type_str.size() - 1);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
case '&':
|
2015-10-02 00:28:02 +08:00
|
|
|
if (reference_count == 0) {
|
|
|
|
reference_count = 1;
|
|
|
|
type_str.erase(type_str.size() - 1);
|
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat("invalid type string: '%s'\n",
|
2016-03-19 08:51:43 +08:00
|
|
|
view_as_type_cstr);
|
2011-04-28 06:04:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2015-10-19 03:34:38 +08:00
|
|
|
|
2013-06-12 02:47:55 +08:00
|
|
|
default:
|
2015-08-25 07:46:31 +08:00
|
|
|
done = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2013-06-12 02:47:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:07:51 +08:00
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
|
|
|
|
ConstString lookup_type_name(type_str.c_str());
|
2011-10-25 14:44:01 +08:00
|
|
|
StackFrame *frame = m_exe_ctx.GetFramePtr();
|
2019-01-15 06:41:21 +08:00
|
|
|
ModuleSP search_first;
|
2011-10-25 14:44:01 +08:00
|
|
|
if (frame) {
|
2019-01-15 06:41:21 +08:00
|
|
|
search_first = frame->GetSymbolContext(eSymbolContextModule).module_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-01-15 06:41:21 +08:00
|
|
|
target->GetImages().FindTypes(search_first.get(), lookup_type_name,
|
|
|
|
exact_match, 1, searched_symbol_files,
|
|
|
|
type_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
if (type_list.GetSize() == 0 && lookup_type_name.GetCString()) {
|
|
|
|
LanguageType language_for_type =
|
|
|
|
m_memory_options.m_language_for_type.GetCurrentValue();
|
|
|
|
std::set<LanguageType> languages_to_check;
|
|
|
|
if (language_for_type != eLanguageTypeUnknown) {
|
|
|
|
languages_to_check.insert(language_for_type);
|
|
|
|
} else {
|
|
|
|
languages_to_check = Language::GetSupportedLanguages();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<CompilerType> user_defined_types;
|
|
|
|
for (auto lang : languages_to_check) {
|
|
|
|
if (auto *persistent_vars =
|
|
|
|
target->GetPersistentExpressionStateForLanguage(lang)) {
|
|
|
|
if (llvm::Optional<CompilerType> type =
|
|
|
|
persistent_vars->GetCompilerTypeFromPersistentDecl(
|
|
|
|
lookup_type_name)) {
|
|
|
|
user_defined_types.emplace(*type);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2019-06-13 01:47:06 +08:00
|
|
|
|
|
|
|
if (user_defined_types.size() > 1) {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"Mutiple types found matching raw type '%s', please disambiguate "
|
|
|
|
"by specifying the language with -x",
|
|
|
|
lookup_type_name.GetCString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_defined_types.size() == 1) {
|
|
|
|
compiler_type = *user_defined_types.begin();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
if (!compiler_type.IsValid()) {
|
2011-04-29 04:55:26 +08:00
|
|
|
if (type_list.GetSize() == 0) {
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendErrorWithFormat("unable to find any types that match "
|
2013-06-12 02:47:55 +08:00
|
|
|
"the raw type '%s' for full type '%s'\n",
|
2012-12-07 06:49:16 +08:00
|
|
|
lookup_type_name.GetCString(),
|
|
|
|
view_as_type_cstr);
|
2011-04-29 04:55:26 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-06-12 02:47:55 +08:00
|
|
|
TypeSP type_sp(type_list.GetTypeAtIndex(0));
|
2019-06-13 01:47:06 +08:00
|
|
|
compiler_type = type_sp->GetFullCompilerType();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-10-26 12:32:38 +08:00
|
|
|
while (pointer_count > 0) {
|
2019-06-13 01:47:06 +08:00
|
|
|
CompilerType pointer_type = compiler_type.GetPointerType();
|
2013-07-12 06:46:58 +08:00
|
|
|
if (pointer_type.IsValid())
|
2019-06-13 01:47:06 +08:00
|
|
|
compiler_type = pointer_type;
|
2011-10-26 12:32:38 +08:00
|
|
|
else {
|
|
|
|
result.AppendError("unable make a pointer type\n");
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
--pointer_count;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-10-26 12:32:38 +08:00
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
llvm::Optional<uint64_t> size = compiler_type.GetByteSize(nullptr);
|
2019-01-16 02:07:52 +08:00
|
|
|
if (!size) {
|
2014-09-29 16:02:24 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"unable to get the byte size of the type '%s'\n",
|
2013-06-12 02:47:55 +08:00
|
|
|
view_as_type_cstr);
|
2014-09-29 16:02:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-01-16 02:07:52 +08:00
|
|
|
m_format_options.GetByteSizeValue() = *size;
|
2014-09-29 16:02:24 +08:00
|
|
|
|
2011-04-29 04:55:26 +08:00
|
|
|
if (!m_format_options.GetCountValue().OptionWasSet())
|
|
|
|
m_format_options.GetCountValue() = 1;
|
|
|
|
} else {
|
|
|
|
error = m_memory_options.FinalizeSettings(target, m_format_options);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-29 04:55:26 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Look for invalid combinations of settings
|
|
|
|
if (error.Fail()) {
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendError(error.AsCString());
|
2011-10-26 12:32:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
|
|
|
lldb::addr_t addr;
|
|
|
|
size_t total_byte_size = 0;
|
|
|
|
if (argc == 0) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Use the last address and byte size and all options as they were if no
|
|
|
|
// options have been set
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
|
|
|
addr = m_next_addr;
|
|
|
|
total_byte_size = m_prev_byte_size;
|
2019-06-13 01:47:06 +08:00
|
|
|
compiler_type = m_prev_compiler_type;
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
|
|
|
if (!m_format_options.AnyOptionWasSet() &&
|
|
|
|
!m_memory_options.AnyOptionWasSet() &&
|
2011-10-26 12:32:38 +08:00
|
|
|
!m_outfile_options.AnyOptionWasSet() &&
|
2022-04-14 18:56:44 +08:00
|
|
|
!m_varobj_options.AnyOptionWasSet() &&
|
|
|
|
!m_memory_tag_options.AnyOptionWasSet()) {
|
2012-12-15 10:08:17 +08:00
|
|
|
m_format_options = m_prev_format_options;
|
2011-10-26 12:32:38 +08:00
|
|
|
m_memory_options = m_prev_memory_options;
|
2012-12-15 10:08:17 +08:00
|
|
|
m_outfile_options = m_prev_outfile_options;
|
|
|
|
m_varobj_options = m_prev_varobj_options;
|
2022-04-14 18:56:44 +08:00
|
|
|
m_memory_tag_options = m_prev_memory_tag_options;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-12-07 06:49:16 +08:00
|
|
|
size_t item_count = m_format_options.GetCountValue().GetCurrentValue();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
// TODO For non-8-bit byte addressable architectures this needs to be
|
|
|
|
// revisited to fully support all lldb's range of formatting options.
|
2018-05-01 00:49:04 +08:00
|
|
|
// Furthermore code memory reads (for those architectures) will not be
|
|
|
|
// correctly formatted even w/o formatting options.
|
2012-11-30 05:49:15 +08:00
|
|
|
size_t item_byte_size =
|
2010-06-09 00:52:24 +08:00
|
|
|
target->GetArchitecture().GetDataByteSize() > 1
|
|
|
|
? target->GetArchitecture().GetDataByteSize()
|
2011-10-25 14:44:01 +08:00
|
|
|
: m_format_options.GetByteSizeValue().GetCurrentValue();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
const size_t num_per_line =
|
|
|
|
m_memory_options.m_num_per_line.GetCurrentValue();
|
2014-09-29 16:02:24 +08:00
|
|
|
|
2013-06-05 06:54:16 +08:00
|
|
|
if (total_byte_size == 0) {
|
2015-01-28 08:07:51 +08:00
|
|
|
total_byte_size = item_count * item_byte_size;
|
2011-04-28 06:04:39 +08:00
|
|
|
if (total_byte_size == 0)
|
2014-03-09 01:15:35 +08:00
|
|
|
total_byte_size = 32;
|
2013-07-25 02:17:35 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
if (argc > 0)
|
2019-09-13 19:26:48 +08:00
|
|
|
addr = OptionArgParser::ToAddress(&m_exe_ctx, command[0].ref(),
|
2018-04-10 17:03:59 +08:00
|
|
|
LLDB_INVALID_ADDRESS, &error);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-12-15 10:08:17 +08:00
|
|
|
if (addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
result.AppendError("invalid start address expression.");
|
|
|
|
result.AppendError(error.AsCString());
|
2011-04-28 06:04:39 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2021-11-03 20:10:40 +08:00
|
|
|
ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
|
|
|
|
if (abi)
|
|
|
|
addr = abi->FixDataAddress(addr);
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
if (argc == 2) {
|
2018-04-10 17:03:59 +08:00
|
|
|
lldb::addr_t end_addr = OptionArgParser::ToAddress(
|
2019-09-13 19:26:48 +08:00
|
|
|
&m_exe_ctx, command[1].ref(), LLDB_INVALID_ADDRESS, nullptr);
|
2021-11-03 20:10:40 +08:00
|
|
|
if (end_addr != LLDB_INVALID_ADDRESS && abi)
|
|
|
|
end_addr = abi->FixDataAddress(end_addr);
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
if (end_addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
result.AppendError("invalid end address expression.");
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendError(error.AsCString());
|
2011-04-28 06:04:39 +08:00
|
|
|
return false;
|
|
|
|
} else if (end_addr <= addr) {
|
|
|
|
result.AppendErrorWithFormat(
|
2014-03-04 03:15:20 +08:00
|
|
|
"end address (0x%" PRIx64
|
2021-03-17 17:43:06 +08:00
|
|
|
") must be greater than the start address (0x%" PRIx64 ").\n",
|
2012-11-30 05:49:15 +08:00
|
|
|
end_addr, addr);
|
2011-04-28 06:04:39 +08:00
|
|
|
return false;
|
|
|
|
} else if (m_format_options.GetCountValue().OptionWasSet()) {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"specify either the end address (0x%" PRIx64
|
2013-01-26 02:06:21 +08:00
|
|
|
") or the count (--count %" PRIu64 "), not both.\n",
|
|
|
|
end_addr, (uint64_t)item_count);
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
total_byte_size = end_addr - addr;
|
|
|
|
item_count = total_byte_size / item_byte_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
uint32_t max_unforced_size = target->GetMaximumMemReadSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-11 04:52:20 +08:00
|
|
|
if (total_byte_size > max_unforced_size && !m_memory_options.m_force) {
|
2013-01-26 02:06:21 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"Normally, \'memory read\' will not read over %" PRIu32
|
2012-11-30 05:49:15 +08:00
|
|
|
" bytes of data.\n",
|
|
|
|
max_unforced_size);
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"Please use --force to override this restriction just once.\n");
|
|
|
|
result.AppendErrorWithFormat("or set target.max-memory-read-size if you "
|
|
|
|
"will often need a larger limit.\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-02 06:59:18 +08:00
|
|
|
WritableDataBufferSP data_sp;
|
2011-04-28 06:04:39 +08:00
|
|
|
size_t bytes_read = 0;
|
2019-06-13 01:47:06 +08:00
|
|
|
if (compiler_type.GetOpaqueQualType()) {
|
2012-11-30 05:49:15 +08:00
|
|
|
// Make sure we don't display our type as ASCII bytes like the default
|
2012-12-15 10:08:17 +08:00
|
|
|
// memory read
|
2016-02-20 08:58:29 +08:00
|
|
|
if (!m_format_options.GetFormatValue().OptionWasSet())
|
2012-12-15 10:08:17 +08:00
|
|
|
m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-06-13 01:47:06 +08:00
|
|
|
llvm::Optional<uint64_t> size = compiler_type.GetByteSize(nullptr);
|
2019-01-16 02:07:52 +08:00
|
|
|
if (!size) {
|
|
|
|
result.AppendError("can't get size of type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bytes_read = *size * m_format_options.GetCountValue().GetCurrentValue();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-26 12:32:38 +08:00
|
|
|
if (argc > 0)
|
2019-01-16 02:07:52 +08:00
|
|
|
addr = addr + (*size * m_memory_options.m_offset.GetCurrentValue());
|
2013-01-22 03:20:50 +08:00
|
|
|
} else if (m_format_options.GetFormatValue().GetCurrentValue() !=
|
|
|
|
eFormatCString) {
|
2019-02-12 07:13:08 +08:00
|
|
|
data_sp = std::make_shared<DataBufferHeap>(total_byte_size, '\0');
|
2016-02-20 08:58:29 +08:00
|
|
|
if (data_sp->GetBytes() == nullptr) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2012-11-30 05:49:15 +08:00
|
|
|
"can't allocate 0x%" PRIx32
|
|
|
|
" bytes for the memory read buffer, specify a smaller size to read",
|
|
|
|
(uint32_t)total_byte_size);
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-11 04:52:20 +08:00
|
|
|
Address address(addr, nullptr);
|
2021-04-17 07:10:16 +08:00
|
|
|
bytes_read = target->ReadMemory(address, data_sp->GetBytes(),
|
|
|
|
data_sp->GetByteSize(), error, true);
|
2011-04-28 06:04:39 +08:00
|
|
|
if (bytes_read == 0) {
|
|
|
|
const char *error_cstr = error.AsCString();
|
2012-05-26 01:05:55 +08:00
|
|
|
if (error_cstr && error_cstr[0]) {
|
2011-04-28 06:04:39 +08:00
|
|
|
result.AppendError(error_cstr);
|
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"failed to read memory from 0x%" PRIx64 ".\n", addr);
|
2010-10-11 04:52:20 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
if (bytes_read < total_byte_size)
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendWarningWithFormat(
|
|
|
|
"Not all bytes (%" PRIu64 "/%" PRIu64
|
|
|
|
") were able to be read from 0x%" PRIx64 ".\n",
|
|
|
|
(uint64_t)bytes_read, (uint64_t)total_byte_size, addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-01-22 03:20:50 +08:00
|
|
|
// we treat c-strings as a special case because they do not have a fixed
|
2016-09-07 04:57:50 +08:00
|
|
|
// size
|
2013-01-22 03:20:50 +08:00
|
|
|
if (m_format_options.GetByteSizeValue().OptionWasSet() &&
|
|
|
|
!m_format_options.HasGDBFormat())
|
|
|
|
item_byte_size = m_format_options.GetByteSizeValue().GetCurrentValue();
|
2010-10-11 04:52:20 +08:00
|
|
|
else
|
|
|
|
item_byte_size = target->GetMaximumSizeOfStringSummary();
|
|
|
|
if (!m_format_options.GetCountValue().OptionWasSet())
|
2013-01-22 03:20:50 +08:00
|
|
|
item_count = 1;
|
2019-02-12 07:13:08 +08:00
|
|
|
data_sp = std::make_shared<DataBufferHeap>(
|
|
|
|
(item_byte_size + 1) * item_count,
|
|
|
|
'\0'); // account for NULLs as necessary
|
2016-02-20 08:58:29 +08:00
|
|
|
if (data_sp->GetBytes() == nullptr) {
|
2013-06-05 06:54:16 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2013-07-25 02:17:35 +08:00
|
|
|
"can't allocate 0x%" PRIx64
|
|
|
|
" bytes for the memory read buffer, specify a smaller size to read",
|
|
|
|
(uint64_t)((item_byte_size + 1) * item_count));
|
2012-04-28 09:27:38 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-01-22 03:20:50 +08:00
|
|
|
uint8_t *data_ptr = data_sp->GetBytes();
|
2010-10-11 04:52:20 +08:00
|
|
|
auto data_addr = addr;
|
|
|
|
auto count = item_count;
|
2013-01-22 03:20:50 +08:00
|
|
|
item_count = 0;
|
2015-04-07 02:41:17 +08:00
|
|
|
bool break_on_no_NULL = false;
|
2013-01-22 03:20:50 +08:00
|
|
|
while (item_count < count) {
|
|
|
|
std::string buffer;
|
|
|
|
buffer.resize(item_byte_size + 1, 0);
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2010-10-11 04:52:20 +08:00
|
|
|
size_t read = target->ReadCStringFromMemory(data_addr, &buffer[0],
|
2013-01-22 03:20:50 +08:00
|
|
|
item_byte_size + 1, error);
|
|
|
|
if (error.Fail()) {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2010-10-11 04:52:20 +08:00
|
|
|
"failed to read memory from 0x%" PRIx64 ".\n", addr);
|
2013-07-25 02:17:35 +08:00
|
|
|
return false;
|
2010-10-11 04:52:20 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
if (item_byte_size == read) {
|
|
|
|
result.AppendWarningWithFormat(
|
2012-11-30 05:49:15 +08:00
|
|
|
"unable to find a NULL terminated string at 0x%" PRIx64
|
2021-12-01 22:56:18 +08:00
|
|
|
". Consider increasing the maximum read length.\n",
|
2012-11-30 05:49:15 +08:00
|
|
|
data_addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
--read;
|
2015-04-07 02:41:17 +08:00
|
|
|
break_on_no_NULL = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2015-04-07 02:41:17 +08:00
|
|
|
++read; // account for final NULL byte
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-11-30 05:49:15 +08:00
|
|
|
memcpy(data_ptr, &buffer[0], read);
|
2013-01-22 03:20:50 +08:00
|
|
|
data_ptr += read;
|
|
|
|
data_addr += read;
|
|
|
|
bytes_read += read;
|
2012-11-30 05:49:15 +08:00
|
|
|
item_count++; // if we break early we know we only read item_count
|
2013-01-22 03:20:50 +08:00
|
|
|
// strings
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
if (break_on_no_NULL)
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-02-12 07:13:08 +08:00
|
|
|
data_sp =
|
|
|
|
std::make_shared<DataBufferHeap>(data_sp->GetBytes(), bytes_read + 1);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
m_next_addr = addr + bytes_read;
|
|
|
|
m_prev_byte_size = bytes_read;
|
2012-12-15 10:08:17 +08:00
|
|
|
m_prev_format_options = m_format_options;
|
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
|
|
|
m_prev_memory_options = m_memory_options;
|
|
|
|
m_prev_outfile_options = m_outfile_options;
|
|
|
|
m_prev_varobj_options = m_varobj_options;
|
2022-04-14 18:56:44 +08:00
|
|
|
m_prev_memory_tag_options = m_memory_tag_options;
|
2019-06-13 01:47:06 +08:00
|
|
|
m_prev_compiler_type = compiler_type;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
std::unique_ptr<Stream> output_stream_storage;
|
|
|
|
Stream *output_stream_p = nullptr;
|
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
|
|
|
const FileSpec &outfile_spec =
|
|
|
|
m_outfile_options.GetFile().GetCurrentValue();
|
2018-11-03 06:34:51 +08:00
|
|
|
|
|
|
|
std::string path = outfile_spec.GetPath();
|
2011-04-28 06:04:39 +08:00
|
|
|
if (outfile_spec) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-04-06 23:39:03 +08:00
|
|
|
File::OpenOptions open_options =
|
2021-07-29 02:07:03 +08:00
|
|
|
File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate;
|
2011-04-28 06:04:39 +08:00
|
|
|
const bool append = m_outfile_options.GetAppend().GetCurrentValue();
|
2021-04-06 23:39:03 +08:00
|
|
|
open_options |=
|
|
|
|
append ? File::eOpenOptionAppend : File::eOpenOptionTruncate;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
auto outfile = FileSystem::Instance().Open(outfile_spec, open_options);
|
|
|
|
|
|
|
|
if (outfile) {
|
|
|
|
auto outfile_stream_up =
|
|
|
|
std::make_unique<StreamFile>(std::move(outfile.get()));
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_memory_options.m_output_as_binary) {
|
2010-10-11 04:52:20 +08:00
|
|
|
const size_t bytes_written =
|
2019-09-27 01:54:59 +08:00
|
|
|
outfile_stream_up->Write(data_sp->GetBytes(), bytes_read);
|
2010-10-11 04:52:20 +08:00
|
|
|
if (bytes_written > 0) {
|
2011-04-28 06:04:39 +08:00
|
|
|
result.GetOutputStream().Printf(
|
|
|
|
"%zi bytes %s to '%s'\n", bytes_written,
|
2018-11-03 06:34:51 +08:00
|
|
|
append ? "appended" : "written", path.c_str());
|
2011-04-28 06:04:39 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat("Failed to write %" PRIu64
|
2014-03-04 03:15:20 +08:00
|
|
|
" bytes to '%s'.\n",
|
2018-11-03 06:34:51 +08:00
|
|
|
(uint64_t)bytes_read, path.c_str());
|
2013-01-22 03:20:50 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2010-10-11 04:52:20 +08:00
|
|
|
// We are going to write ASCII to the file just point the
|
|
|
|
// output_stream to our outfile_stream...
|
2019-09-27 01:54:59 +08:00
|
|
|
output_stream_storage = std::move(outfile_stream_up);
|
|
|
|
output_stream_p = output_stream_storage.get();
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2019-09-27 01:54:59 +08:00
|
|
|
result.AppendErrorWithFormat("Failed to open file '%s' for %s:\n",
|
2018-11-03 06:34:51 +08:00
|
|
|
path.c_str(), append ? "append" : "write");
|
2019-09-27 01:54:59 +08:00
|
|
|
|
|
|
|
result.AppendError(llvm::toString(outfile.takeError()));
|
2013-01-22 03:20:50 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-27 01:54:59 +08:00
|
|
|
output_stream_p = &result.GetOutputStream();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
|
2019-06-13 01:47:06 +08:00
|
|
|
if (compiler_type.GetOpaqueQualType()) {
|
2011-04-28 06:04:39 +08:00
|
|
|
for (uint32_t i = 0; i < item_count; ++i) {
|
2013-07-25 02:17:35 +08:00
|
|
|
addr_t item_addr = addr + (i * item_byte_size);
|
2011-04-28 06:04:39 +08:00
|
|
|
Address address(item_addr);
|
|
|
|
StreamString name_strm;
|
2011-09-22 12:58:26 +08:00
|
|
|
name_strm.Printf("0x%" PRIx64, item_addr);
|
|
|
|
ValueObjectSP valobj_sp(ValueObjectMemory::Create(
|
2019-06-13 01:47:06 +08:00
|
|
|
exe_scope, name_strm.GetString(), address, compiler_type));
|
2011-04-28 06:04:39 +08:00
|
|
|
if (valobj_sp) {
|
2013-05-22 01:39:04 +08:00
|
|
|
Format format = m_format_options.GetFormat();
|
|
|
|
if (format != eFormatDefault)
|
|
|
|
valobj_sp->SetFormat(format);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
|
2014-03-04 03:15:20 +08:00
|
|
|
eLanguageRuntimeDescriptionDisplayVerbosityFull, format));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
valobj_sp->Dump(*output_stream_p, options);
|
2014-03-04 03:15:20 +08:00
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"failed to create a value object for: (%s) %s\n",
|
2016-11-17 05:15:24 +08:00
|
|
|
view_as_type_cstr, name_strm.GetData());
|
2013-10-30 07:04:29 +08:00
|
|
|
return false;
|
2013-05-22 01:39:04 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 04:52:20 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2010-10-11 04:52:20 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2013-01-26 02:06:21 +08:00
|
|
|
DataExtractor data(data_sp, target->GetArchitecture().GetByteOrder(),
|
|
|
|
target->GetArchitecture().GetAddressByteSize(),
|
2014-09-29 16:02:24 +08:00
|
|
|
target->GetArchitecture().GetDataByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-29 16:02:24 +08:00
|
|
|
Format format = m_format_options.GetFormat();
|
|
|
|
if (((format == eFormatChar) || (format == eFormatCharPrintable)) &&
|
2013-10-30 07:04:29 +08:00
|
|
|
(item_byte_size != 1)) {
|
2014-09-29 16:02:24 +08:00
|
|
|
// if a count was not passed, or it is 1
|
2013-01-22 03:20:50 +08:00
|
|
|
if (!m_format_options.GetCountValue().OptionWasSet() || item_count == 1) {
|
2013-10-30 07:04:29 +08:00
|
|
|
// this turns requests such as
|
|
|
|
// memory read -fc -s10 -c1 *charPtrPtr
|
2018-05-01 00:49:04 +08:00
|
|
|
// which make no sense (what is a char of size 10?) into a request for
|
|
|
|
// fetching 10 chars of size 1 from the same memory location
|
2013-01-26 02:06:21 +08:00
|
|
|
format = eFormatCharArray;
|
|
|
|
item_count = item_byte_size;
|
2011-10-29 07:44:55 +08:00
|
|
|
item_byte_size = 1;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// here we passed a count, and it was not 1 so we have a byte_size and
|
|
|
|
// a count we could well multiply those, but instead let's just fail
|
2011-10-29 07:44:55 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"reading memory as characters of size %" PRIu64 " is not supported",
|
2010-10-11 04:52:20 +08:00
|
|
|
(uint64_t)item_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
assert(output_stream_p);
|
2017-03-04 04:57:05 +08:00
|
|
|
size_t bytes_dumped = DumpDataExtractor(
|
2019-09-27 01:54:59 +08:00
|
|
|
data, output_stream_p, 0, format, item_byte_size, item_count,
|
2017-03-04 04:57:05 +08:00
|
|
|
num_per_line / target->GetArchitecture().GetDataByteSize(), addr, 0, 0,
|
2022-04-14 18:56:44 +08:00
|
|
|
exe_scope, m_memory_tag_options.GetShowTags().GetCurrentValue());
|
2015-10-30 07:40:24 +08:00
|
|
|
m_next_addr = addr + bytes_dumped;
|
2019-09-27 01:54:59 +08:00
|
|
|
output_stream_p->EOL();
|
2011-04-28 06:04:39 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupFormat m_format_options;
|
|
|
|
OptionGroupReadMemory m_memory_options;
|
|
|
|
OptionGroupOutputFile m_outfile_options;
|
2011-04-29 04:55:26 +08:00
|
|
|
OptionGroupValueObjectDisplay m_varobj_options;
|
2022-04-14 18:56:44 +08:00
|
|
|
OptionGroupMemoryTag m_memory_tag_options;
|
2022-03-15 04:32:03 +08:00
|
|
|
lldb::addr_t m_next_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
lldb::addr_t m_prev_byte_size = 0;
|
2011-10-26 12:32:38 +08:00
|
|
|
OptionGroupFormat m_prev_format_options;
|
|
|
|
OptionGroupReadMemory m_prev_memory_options;
|
|
|
|
OptionGroupOutputFile m_prev_outfile_options;
|
|
|
|
OptionGroupValueObjectDisplay m_prev_varobj_options;
|
2022-04-14 18:56:44 +08:00
|
|
|
OptionGroupMemoryTag m_prev_memory_tag_options;
|
2019-06-13 01:47:06 +08:00
|
|
|
CompilerType m_prev_compiler_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2019-07-25 19:22:46 +08:00
|
|
|
#define LLDB_OPTIONS_memory_find
|
|
|
|
#include "CommandOptions.inc"
|
2013-11-13 10:18:44 +08:00
|
|
|
|
|
|
|
// Find the specified data in memory
|
|
|
|
class CommandObjectMemoryFind : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
class OptionGroupFindMemory : public OptionGroup {
|
|
|
|
public:
|
2022-01-24 03:07:14 +08:00
|
|
|
OptionGroupFindMemory() : m_count(1), m_offset(0) {}
|
2016-02-20 08:58:29 +08:00
|
|
|
|
|
|
|
~OptionGroupFindMemory() override = default;
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-07-28 14:24:07 +08:00
|
|
|
return llvm::makeArrayRef(g_memory_find_options);
|
2013-11-13 10:18:44 +08:00
|
|
|
}
|
2013-11-14 04:08:30 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2019-07-28 14:24:07 +08:00
|
|
|
const int short_option = g_memory_find_options[option_idx].short_option;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'e':
|
2016-09-24 01:48:13 +08:00
|
|
|
m_expr.SetValueFromString(option_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
case 's':
|
2016-09-24 01:48:13 +08:00
|
|
|
m_string.SetValueFromString(option_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
case 'c':
|
2016-09-24 01:48:13 +08:00
|
|
|
if (m_count.SetValueFromString(option_value).Fail())
|
2013-11-13 10:18:44 +08:00
|
|
|
error.SetErrorString("unrecognized value for count");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-11-14 04:08:30 +08:00
|
|
|
case 'o':
|
2016-09-24 01:48:13 +08:00
|
|
|
if (m_offset.SetValueFromString(option_value).Fail())
|
2013-11-14 04:08:30 +08:00
|
|
|
error.SetErrorString("unrecognized value for dump-offset");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2013-11-13 10:18:44 +08:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2013-11-13 10:18:44 +08:00
|
|
|
m_expr.Clear();
|
|
|
|
m_string.Clear();
|
|
|
|
m_count.Clear();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
OptionValueString m_expr;
|
|
|
|
OptionValueString m_string;
|
|
|
|
OptionValueUInt64 m_count;
|
2013-11-14 04:08:30 +08:00
|
|
|
OptionValueUInt64 m_offset;
|
2013-11-13 10:18:44 +08:00
|
|
|
};
|
2016-07-15 06:03:10 +08:00
|
|
|
|
|
|
|
CommandObjectMemoryFind(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(
|
|
|
|
interpreter, "memory find",
|
|
|
|
"Find a value in the memory of the current target process.",
|
2022-01-24 03:07:14 +08:00
|
|
|
nullptr, eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
|
2013-11-13 10:18:44 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentEntry arg2;
|
|
|
|
CommandArgumentData addr_arg;
|
|
|
|
CommandArgumentData value_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
2015-08-04 04:47:19 +08:00
|
|
|
addr_arg.arg_type = eArgTypeAddressOrExpression;
|
2013-11-13 10:18:44 +08:00
|
|
|
addr_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg1.push_back(addr_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
2015-08-04 04:47:19 +08:00
|
|
|
value_arg.arg_type = eArgTypeAddressOrExpression;
|
|
|
|
value_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg2.push_back(value_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
m_arguments.push_back(arg2);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-04-13 05:26:48 +08:00
|
|
|
m_option_group.Append(&m_memory_options);
|
2022-04-13 21:32:18 +08:00
|
|
|
m_option_group.Append(&m_memory_tag_options, LLDB_OPT_SET_ALL,
|
|
|
|
LLDB_OPT_SET_ALL);
|
2013-11-13 10:18:44 +08:00
|
|
|
m_option_group.Finalize();
|
|
|
|
}
|
2016-02-20 08:58:29 +08:00
|
|
|
|
|
|
|
~CommandObjectMemoryFind() override = default;
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
protected:
|
2016-09-01 08:09:59 +08:00
|
|
|
class ProcessMemoryIterator {
|
|
|
|
public:
|
|
|
|
ProcessMemoryIterator(ProcessSP process_sp, lldb::addr_t base)
|
2022-03-15 04:32:03 +08:00
|
|
|
: m_process_sp(process_sp), m_base_addr(base) {
|
2016-09-01 08:09:59 +08:00
|
|
|
lldbassert(process_sp.get() != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid() { return m_is_valid; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
uint8_t operator[](lldb::addr_t offset) {
|
|
|
|
if (!IsValid())
|
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
uint8_t retval = 0;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (0 ==
|
2016-09-01 08:09:59 +08:00
|
|
|
m_process_sp->ReadMemory(m_base_addr + offset, &retval, 1, error)) {
|
|
|
|
m_is_valid = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
return retval;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
private:
|
|
|
|
ProcessSP m_process_sp;
|
|
|
|
lldb::addr_t m_base_addr;
|
2022-03-15 04:32:03 +08:00
|
|
|
bool m_is_valid = true;
|
2016-09-01 08:09:59 +08:00
|
|
|
};
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2015-05-27 13:04:35 +08:00
|
|
|
// No need to check "process" for validity as eCommandRequiresProcess
|
|
|
|
// ensures it is valid
|
2013-11-13 10:18:44 +08:00
|
|
|
Process *process = m_exe_ctx.GetProcessPtr();
|
|
|
|
|
|
|
|
const size_t argc = command.GetArgumentCount();
|
|
|
|
|
|
|
|
if (argc != 2) {
|
2013-11-13 10:22:24 +08:00
|
|
|
result.AppendError("two addresses needed for memory find");
|
2013-11-13 10:18:44 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2018-04-10 17:03:59 +08:00
|
|
|
lldb::addr_t low_addr = OptionArgParser::ToAddress(
|
2019-09-13 19:26:48 +08:00
|
|
|
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);
|
2013-11-13 10:18:44 +08:00
|
|
|
if (low_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
|
|
|
|
result.AppendError("invalid low address");
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-04-10 17:03:59 +08:00
|
|
|
lldb::addr_t high_addr = OptionArgParser::ToAddress(
|
2019-09-13 19:26:48 +08:00
|
|
|
&m_exe_ctx, command[1].ref(), LLDB_INVALID_ADDRESS, &error);
|
2013-11-13 10:18:44 +08:00
|
|
|
if (high_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
|
2014-09-06 19:29:08 +08:00
|
|
|
result.AppendError("invalid high address");
|
2013-11-13 10:18:44 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-01-14 00:54:04 +08:00
|
|
|
ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
|
|
|
|
if (abi) {
|
|
|
|
low_addr = abi->FixDataAddress(low_addr);
|
|
|
|
high_addr = abi->FixDataAddress(high_addr);
|
|
|
|
}
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
if (high_addr <= low_addr) {
|
2014-09-06 19:29:08 +08:00
|
|
|
result.AppendError(
|
2013-11-13 10:18:44 +08:00
|
|
|
"starting address must be smaller than ending address");
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
lldb::addr_t found_location = LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
DataBufferHeap buffer;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-04-14 22:06:27 +08:00
|
|
|
if (m_memory_options.m_string.OptionWasSet()) {
|
|
|
|
llvm::StringRef str = m_memory_options.m_string.GetStringValue();
|
|
|
|
if (str.empty()) {
|
|
|
|
result.AppendError("search string must have non-zero length.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
buffer.CopyData(str);
|
|
|
|
} else if (m_memory_options.m_expr.OptionWasSet()) {
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *frame = m_exe_ctx.GetFramePtr();
|
2013-11-13 10:18:44 +08:00
|
|
|
ValueObjectSP result_sp;
|
2015-08-04 02:51:39 +08:00
|
|
|
if ((eExpressionCompleted ==
|
|
|
|
process->GetTarget().EvaluateExpression(
|
|
|
|
m_memory_options.m_expr.GetStringValue(), frame, result_sp)) &&
|
|
|
|
result_sp) {
|
2013-11-13 10:18:44 +08:00
|
|
|
uint64_t value = result_sp->GetValueAsUnsigned(0);
|
2019-01-16 04:33:58 +08:00
|
|
|
llvm::Optional<uint64_t> size =
|
|
|
|
result_sp->GetCompilerType().GetByteSize(nullptr);
|
2019-01-16 02:07:52 +08:00
|
|
|
if (!size)
|
|
|
|
return false;
|
|
|
|
switch (*size) {
|
2013-11-13 10:18:44 +08:00
|
|
|
case 1: {
|
|
|
|
uint8_t byte = (uint8_t)value;
|
|
|
|
buffer.CopyData(&byte, 1);
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
2013-11-13 10:18:44 +08:00
|
|
|
case 2: {
|
|
|
|
uint16_t word = (uint16_t)value;
|
|
|
|
buffer.CopyData(&word, 2);
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
2013-11-13 10:18:44 +08:00
|
|
|
case 4: {
|
|
|
|
uint32_t lword = (uint32_t)value;
|
|
|
|
buffer.CopyData(&lword, 4);
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
2013-11-13 10:18:44 +08:00
|
|
|
case 8: {
|
|
|
|
buffer.CopyData(&value, 8);
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
2013-11-13 10:18:44 +08:00
|
|
|
result.AppendError("unknown type. pass a string instead");
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
default:
|
2013-11-13 10:18:44 +08:00
|
|
|
result.AppendError(
|
|
|
|
"result size larger than 8 bytes. pass a string instead");
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-09-06 19:29:08 +08:00
|
|
|
result.AppendError(
|
2015-08-04 02:51:39 +08:00
|
|
|
"expression evaluation failed. pass a string instead");
|
2013-11-13 10:18:44 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-09-06 19:29:08 +08:00
|
|
|
result.AppendError(
|
2013-11-13 10:18:44 +08:00
|
|
|
"please pass either a block of text, or an expression to evaluate.");
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-11-13 10:18:44 +08:00
|
|
|
|
|
|
|
size_t count = m_memory_options.m_count.GetCurrentValue();
|
|
|
|
found_location = low_addr;
|
|
|
|
bool ever_found = false;
|
|
|
|
while (count) {
|
|
|
|
found_location = FastSearch(found_location, high_addr, buffer.GetBytes(),
|
2016-09-01 08:09:59 +08:00
|
|
|
buffer.GetByteSize());
|
2013-11-13 10:18:44 +08:00
|
|
|
if (found_location == LLDB_INVALID_ADDRESS) {
|
|
|
|
if (!ever_found) {
|
|
|
|
result.AppendMessage("data not found within the range.\n");
|
|
|
|
result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
|
|
|
|
} else
|
|
|
|
result.AppendMessage("no more matches within the range.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result.AppendMessageWithFormat("data found at location: 0x%" PRIx64 "\n",
|
|
|
|
found_location);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
DataBufferHeap dumpbuffer(32, 0);
|
2015-08-04 02:51:39 +08:00
|
|
|
process->ReadMemory(
|
|
|
|
found_location + m_memory_options.m_offset.GetCurrentValue(),
|
2015-08-25 07:46:31 +08:00
|
|
|
dumpbuffer.GetBytes(), dumpbuffer.GetByteSize(), error);
|
|
|
|
if (!error.Fail()) {
|
2013-11-13 10:18:44 +08:00
|
|
|
DataExtractor data(dumpbuffer.GetBytes(), dumpbuffer.GetByteSize(),
|
|
|
|
process->GetByteOrder(),
|
2015-08-04 02:51:39 +08:00
|
|
|
process->GetAddressByteSize());
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpDataExtractor(
|
|
|
|
data, &result.GetOutputStream(), 0, lldb::eFormatBytesWithASCII, 1,
|
|
|
|
dumpbuffer.GetByteSize(), 16,
|
2022-04-13 21:32:18 +08:00
|
|
|
found_location + m_memory_options.m_offset.GetCurrentValue(), 0, 0,
|
|
|
|
m_exe_ctx.GetBestExecutionContextScope(),
|
|
|
|
m_memory_tag_options.GetShowTags().GetCurrentValue());
|
2015-08-04 02:51:39 +08:00
|
|
|
result.GetOutputStream().EOL();
|
2013-11-13 10:18:44 +08:00
|
|
|
}
|
2013-11-14 04:08:30 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
--count;
|
|
|
|
found_location++;
|
|
|
|
ever_found = true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
lldb::addr_t FastSearch(lldb::addr_t low, lldb::addr_t high, uint8_t *buffer,
|
|
|
|
size_t buffer_size) {
|
|
|
|
const size_t region_size = high - low;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
if (region_size < buffer_size)
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
std::vector<size_t> bad_char_heuristic(256, buffer_size);
|
|
|
|
ProcessSP process_sp = m_exe_ctx.GetProcessSP();
|
|
|
|
ProcessMemoryIterator iterator(process_sp, low);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-01 08:09:59 +08:00
|
|
|
for (size_t idx = 0; idx < buffer_size - 1; idx++) {
|
|
|
|
decltype(bad_char_heuristic)::size_type bcu_idx = buffer[idx];
|
|
|
|
bad_char_heuristic[bcu_idx] = buffer_size - idx - 1;
|
2013-11-13 10:18:44 +08:00
|
|
|
}
|
2016-09-01 08:09:59 +08:00
|
|
|
for (size_t s = 0; s <= (region_size - buffer_size);) {
|
2010-06-09 00:52:24 +08:00
|
|
|
int64_t j = buffer_size - 1;
|
2016-09-01 08:09:59 +08:00
|
|
|
while (j >= 0 && buffer[j] == iterator[s + j])
|
2016-09-07 04:57:50 +08:00
|
|
|
j--;
|
2016-09-01 08:09:59 +08:00
|
|
|
if (j < 0)
|
|
|
|
return low + s;
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2016-09-01 08:09:59 +08:00
|
|
|
s += bad_char_heuristic[iterator[s + buffer_size - 1]];
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-13 10:18:44 +08:00
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupFindMemory m_memory_options;
|
2022-04-13 21:32:18 +08:00
|
|
|
OptionGroupMemoryTag m_memory_tag_options;
|
2013-11-13 10:18:44 +08:00
|
|
|
};
|
|
|
|
|
2019-07-25 19:22:46 +08:00
|
|
|
#define LLDB_OPTIONS_memory_write
|
|
|
|
#include "CommandOptions.inc"
|
2011-10-25 14:44:01 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Write memory to the inferior process
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectMemoryWrite : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
2011-10-25 14:44:01 +08:00
|
|
|
class OptionGroupWriteMemory : public OptionGroup {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
2022-04-01 04:20:46 +08:00
|
|
|
OptionGroupWriteMemory() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~OptionGroupWriteMemory() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-07-28 14:24:07 +08:00
|
|
|
return llvm::makeArrayRef(g_memory_write_options);
|
2011-10-25 14:44:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2019-07-28 14:24:07 +08:00
|
|
|
const int short_option = g_memory_write_options[option_idx].short_option;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-26 08:56:27 +08:00
|
|
|
switch (short_option) {
|
2011-10-25 14:44:01 +08:00
|
|
|
case 'i':
|
2018-11-02 05:05:36 +08:00
|
|
|
m_infile.SetFile(option_value, FileSpec::Style::native);
|
|
|
|
FileSystem::Instance().Resolve(m_infile);
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(m_infile)) {
|
2011-10-26 08:56:27 +08:00
|
|
|
m_infile.Clear();
|
|
|
|
error.SetErrorStringWithFormat("input file does not exist: '%s'",
|
2016-09-24 01:48:13 +08:00
|
|
|
option_value.str().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-11 04:52:20 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-14 04:08:30 +08:00
|
|
|
case 'o': {
|
2016-09-24 01:48:13 +08:00
|
|
|
if (option_value.getAsInteger(0, m_infile_offset)) {
|
|
|
|
m_infile_offset = 0;
|
2011-10-26 08:56:27 +08:00
|
|
|
error.SetErrorStringWithFormat("invalid offset string '%s'",
|
2016-09-24 01:48:13 +08:00
|
|
|
option_value.str().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-07-15 06:03:10 +08:00
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-05 06:28:36 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
m_infile.Clear();
|
2011-10-25 14:44:01 +08:00
|
|
|
m_infile_offset = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec m_infile;
|
|
|
|
off_t m_infile_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandObjectMemoryWrite(CommandInterpreter &interpreter)
|
2016-07-15 06:03:10 +08:00
|
|
|
: CommandObjectParsed(
|
2010-06-09 00:52:24 +08:00
|
|
|
interpreter, "memory write",
|
|
|
|
"Write to the memory of the current target process.", nullptr,
|
2016-07-15 06:03:10 +08:00
|
|
|
eCommandRequiresProcess | eCommandProcessMustBeLaunched),
|
2021-11-26 18:28:14 +08:00
|
|
|
m_format_options(
|
|
|
|
eFormatBytes, 1, UINT64_MAX,
|
|
|
|
{std::make_tuple(
|
|
|
|
eArgTypeFormat,
|
|
|
|
"The format to use for each of the value to be written."),
|
2022-01-24 03:07:14 +08:00
|
|
|
std::make_tuple(eArgTypeByteSize,
|
|
|
|
"The size in bytes to write from input file or "
|
|
|
|
"each value.")}) {
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandArgumentEntry arg1;
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg2;
|
|
|
|
CommandArgumentData addr_arg;
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandArgumentData value_arg;
|
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
addr_arg.arg_type = eArgTypeAddress;
|
|
|
|
addr_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg1.push_back(addr_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
value_arg.arg_type = eArgTypeValue;
|
2015-08-04 04:47:19 +08:00
|
|
|
value_arg.arg_repetition = eArgRepeatPlus;
|
2021-11-26 18:04:57 +08:00
|
|
|
value_arg.arg_opt_set_association = LLDB_OPT_SET_1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg2.push_back(value_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg1);
|
|
|
|
m_arguments.push_back(arg2);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
OptionGroupFormat::OPTION_GROUP_FORMAT,
|
|
|
|
LLDB_OPT_SET_1);
|
|
|
|
m_option_group.Append(&m_format_options,
|
|
|
|
OptionGroupFormat::OPTION_GROUP_SIZE,
|
|
|
|
LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
|
|
|
|
m_option_group.Append(&m_memory_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_2);
|
|
|
|
m_option_group.Finalize();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~CommandObjectMemoryWrite() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2016-06-10 00:34:06 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2015-05-27 13:04:35 +08:00
|
|
|
// No need to check "process" for validity as eCommandRequiresProcess
|
|
|
|
// ensures it is valid
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
|
|
|
Process *process = m_exe_ctx.GetProcessPtr();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t argc = command.GetArgumentCount();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
if (m_memory_options.m_infile) {
|
2010-10-11 04:52:20 +08:00
|
|
|
if (argc < 1) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2010-10-11 04:52:20 +08:00
|
|
|
"%s takes a destination address when writing file contents.\n",
|
|
|
|
m_cmd_name.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2021-11-26 18:04:57 +08:00
|
|
|
if (argc > 1) {
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"%s takes only a destination address when writing file contents.\n",
|
|
|
|
m_cmd_name.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-11 04:52:20 +08:00
|
|
|
} else if (argc < 2) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2010-10-11 04:52:20 +08:00
|
|
|
"%s takes a destination address and at least one value.\n",
|
|
|
|
m_cmd_name.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamString buffer(
|
|
|
|
Stream::eBinary,
|
|
|
|
process->GetTarget().GetArchitecture().GetAddressByteSize(),
|
|
|
|
process->GetTarget().GetArchitecture().GetByteOrder());
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionValueUInt64 &byte_size_value = m_format_options.GetByteSizeValue();
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t item_byte_size = byte_size_value.GetCurrentValue();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2018-04-10 17:03:59 +08:00
|
|
|
lldb::addr_t addr = OptionArgParser::ToAddress(
|
2019-09-13 19:26:48 +08:00
|
|
|
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
result.AppendError("invalid address expression\n");
|
|
|
|
result.AppendError(error.AsCString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
if (m_memory_options.m_infile) {
|
2010-10-11 04:52:20 +08:00
|
|
|
size_t length = SIZE_MAX;
|
|
|
|
if (item_byte_size > 1)
|
2011-10-25 14:44:01 +08:00
|
|
|
length = item_byte_size;
|
2018-11-13 05:24:50 +08:00
|
|
|
auto data_sp = FileSystem::Instance().CreateDataBuffer(
|
2017-03-07 07:42:14 +08:00
|
|
|
m_memory_options.m_infile.GetPath(), length,
|
|
|
|
m_memory_options.m_infile_offset);
|
2010-10-11 04:52:20 +08:00
|
|
|
if (data_sp) {
|
|
|
|
length = data_sp->GetByteSize();
|
|
|
|
if (length > 0) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2010-10-11 04:52:20 +08:00
|
|
|
size_t bytes_written =
|
|
|
|
process->WriteMemory(addr, data_sp->GetBytes(), length, error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-11 04:52:20 +08:00
|
|
|
if (bytes_written == length) {
|
|
|
|
// All bytes written
|
|
|
|
result.GetOutputStream().Printf(
|
|
|
|
"%" PRIu64 " bytes were written to 0x%" PRIx64 "\n",
|
|
|
|
(uint64_t)bytes_written, addr);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
} else if (bytes_written > 0) {
|
|
|
|
// Some byte written
|
|
|
|
result.GetOutputStream().Printf(
|
|
|
|
"%" PRIu64 " bytes of %" PRIu64
|
|
|
|
" requested were written to 0x%" PRIx64 "\n",
|
|
|
|
(uint64_t)bytes_written, (uint64_t)length, addr);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-10-11 04:52:20 +08:00
|
|
|
result.AppendErrorWithFormat("Memory write to 0x%" PRIx64
|
|
|
|
" failed: %s.\n",
|
|
|
|
addr, error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-10-11 04:52:20 +08:00
|
|
|
result.AppendErrorWithFormat("Unable to read contents of file.\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 04:52:20 +08:00
|
|
|
return result.Succeeded();
|
2011-10-25 14:44:01 +08:00
|
|
|
} else if (item_byte_size == 0) {
|
|
|
|
if (m_format_options.GetFormat() == eFormatPointer)
|
2010-10-11 04:52:20 +08:00
|
|
|
item_byte_size = buffer.GetAddressByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2010-10-11 04:52:20 +08:00
|
|
|
item_byte_size = 1;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-16 05:59:32 +08:00
|
|
|
command.Shift(); // shift off the address argument
|
2011-10-25 14:44:01 +08:00
|
|
|
uint64_t uval64;
|
|
|
|
int64_t sval64;
|
|
|
|
bool success = false;
|
2016-12-09 09:08:29 +08:00
|
|
|
for (auto &entry : command) {
|
2011-10-25 14:44:01 +08:00
|
|
|
switch (m_format_options.GetFormat()) {
|
2011-06-24 05:22:24 +08:00
|
|
|
case kNumFormats:
|
2012-12-07 06:49:16 +08:00
|
|
|
case eFormatFloat: // TODO: add support for floats soon
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatCharPrintable:
|
2012-12-07 06:49:16 +08:00
|
|
|
case eFormatBytesWithASCII:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatComplex:
|
|
|
|
case eFormatEnum:
|
2019-08-22 05:30:55 +08:00
|
|
|
case eFormatUnicode8:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatUnicode16:
|
|
|
|
case eFormatUnicode32:
|
|
|
|
case eFormatVectorOfChar:
|
|
|
|
case eFormatVectorOfSInt8:
|
|
|
|
case eFormatVectorOfUInt8:
|
|
|
|
case eFormatVectorOfSInt16:
|
|
|
|
case eFormatVectorOfUInt16:
|
|
|
|
case eFormatVectorOfSInt32:
|
|
|
|
case eFormatVectorOfUInt32:
|
|
|
|
case eFormatVectorOfSInt64:
|
2012-12-07 06:49:16 +08:00
|
|
|
case eFormatVectorOfUInt64:
|
|
|
|
case eFormatVectorOfFloat16:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatVectorOfFloat32:
|
|
|
|
case eFormatVectorOfFloat64:
|
|
|
|
case eFormatVectorOfUInt128:
|
2011-03-20 12:57:14 +08:00
|
|
|
case eFormatOSType:
|
2012-12-07 06:49:16 +08:00
|
|
|
case eFormatComplexInteger:
|
|
|
|
case eFormatAddressInfo:
|
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
|
|
|
case eFormatHexFloat:
|
2012-12-07 06:49:16 +08:00
|
|
|
case eFormatInstruction:
|
|
|
|
case eFormatVoid:
|
|
|
|
result.AppendError("unsupported format for writing memory");
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatDefault:
|
|
|
|
case eFormatBytes:
|
|
|
|
case eFormatHex:
|
2012-08-10 03:33:34 +08:00
|
|
|
case eFormatHexUppercase:
|
2019-10-31 06:26:19 +08:00
|
|
|
case eFormatPointer: {
|
2010-06-09 00:52:24 +08:00
|
|
|
// Decode hex bytes
|
2017-04-06 09:33:38 +08:00
|
|
|
// Be careful, getAsInteger with a radix of 16 rejects "0xab" so we
|
|
|
|
// have to special case that:
|
|
|
|
bool success = false;
|
2019-09-13 19:26:48 +08:00
|
|
|
if (entry.ref().startswith("0x"))
|
|
|
|
success = !entry.ref().getAsInteger(0, uval64);
|
2017-04-06 09:33:38 +08:00
|
|
|
if (!success)
|
2019-09-13 19:26:48 +08:00
|
|
|
success = !entry.ref().getAsInteger(16, uval64);
|
2017-04-06 09:33:38 +08:00
|
|
|
if (!success) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 09:08:29 +08:00
|
|
|
"'%s' is not a valid hex string value.\n", entry.c_str());
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
2020-11-04 23:25:38 +08:00
|
|
|
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendErrorWithFormat("Value 0x%" PRIx64
|
2014-03-04 03:15:20 +08:00
|
|
|
" is too large to fit in a %" PRIu64
|
|
|
|
" byte unsigned integer value.\n",
|
|
|
|
uval64, (uint64_t)item_byte_size);
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
buffer.PutMaxHex64(uval64, item_byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2017-04-06 09:33:38 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatBoolean:
|
2019-09-13 19:26:48 +08:00
|
|
|
uval64 = OptionArgParser::ToBoolean(entry.ref(), false, &success);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (!success) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 09:08:29 +08:00
|
|
|
"'%s' is not a valid boolean string value.\n", entry.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
buffer.PutMaxHex64(uval64, item_byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatBinary:
|
2019-09-13 19:26:48 +08:00
|
|
|
if (entry.ref().getAsInteger(2, uval64)) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 09:08:29 +08:00
|
|
|
"'%s' is not a valid binary string value.\n", entry.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2020-11-04 23:25:38 +08:00
|
|
|
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
|
2012-12-07 06:49:16 +08:00
|
|
|
result.AppendErrorWithFormat("Value 0x%" PRIx64
|
2014-03-04 03:15:20 +08:00
|
|
|
" is too large to fit in a %" PRIu64
|
|
|
|
" byte unsigned integer value.\n",
|
|
|
|
uval64, (uint64_t)item_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-12-07 06:49:16 +08:00
|
|
|
buffer.PutMaxHex64(uval64, item_byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-06-18 07:50:44 +08:00
|
|
|
case eFormatCharArray:
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatChar:
|
2016-12-09 09:08:29 +08:00
|
|
|
case eFormatCString: {
|
2019-09-13 19:26:48 +08:00
|
|
|
if (entry.ref().empty())
|
2016-12-09 09:08:29 +08:00
|
|
|
break;
|
|
|
|
|
2019-09-13 19:26:48 +08:00
|
|
|
size_t len = entry.ref().size();
|
2016-12-09 09:08:29 +08:00
|
|
|
// Include the NULL for C strings...
|
|
|
|
if (m_format_options.GetFormat() == eFormatCString)
|
|
|
|
++len;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-12-09 09:08:29 +08:00
|
|
|
if (process->WriteMemory(addr, entry.c_str(), len, error) == len) {
|
|
|
|
addr += len;
|
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat("Memory write to 0x%" PRIx64
|
|
|
|
" failed: %s.\n",
|
|
|
|
addr, error.AsCString());
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-10-25 14:44:01 +08:00
|
|
|
break;
|
2016-12-09 09:08:29 +08:00
|
|
|
}
|
2011-10-25 14:44:01 +08:00
|
|
|
case eFormatDecimal:
|
2019-09-13 19:26:48 +08:00
|
|
|
if (entry.ref().getAsInteger(0, sval64)) {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 09:08:29 +08:00
|
|
|
"'%s' is not a valid signed decimal value.\n", entry.c_str());
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
2020-11-04 23:25:38 +08:00
|
|
|
} else if (!llvm::isIntN(item_byte_size * 8, sval64)) {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"Value %" PRIi64 " is too large or small to fit in a %" PRIu64
|
|
|
|
" byte signed integer value.\n",
|
|
|
|
sval64, (uint64_t)item_byte_size);
|
2010-10-11 04:52:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
buffer.PutMaxHex64(sval64, item_byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatUnsigned:
|
2016-12-09 09:08:29 +08:00
|
|
|
|
2021-03-17 23:45:37 +08:00
|
|
|
if (entry.ref().getAsInteger(0, uval64)) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2010-06-09 00:52:24 +08:00
|
|
|
"'%s' is not a valid unsigned decimal string value.\n",
|
2016-12-09 09:08:29 +08:00
|
|
|
entry.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2020-11-04 23:25:38 +08:00
|
|
|
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
|
2010-10-11 04:52:20 +08:00
|
|
|
result.AppendErrorWithFormat("Value %" PRIu64
|
|
|
|
" is too large to fit in a %" PRIu64
|
2014-03-04 03:15:20 +08:00
|
|
|
" byte unsigned integer value.\n",
|
2010-10-11 04:52:20 +08:00
|
|
|
uval64, (uint64_t)item_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2010-10-11 04:52:20 +08:00
|
|
|
}
|
2013-01-26 02:06:21 +08:00
|
|
|
buffer.PutMaxHex64(uval64, item_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eFormatOctal:
|
2019-09-13 19:26:48 +08:00
|
|
|
if (entry.ref().getAsInteger(8, uval64)) {
|
2014-03-04 03:15:20 +08:00
|
|
|
result.AppendErrorWithFormat(
|
2016-12-09 09:08:29 +08:00
|
|
|
"'%s' is not a valid octal string value.\n", entry.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2020-11-04 23:25:38 +08:00
|
|
|
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat("Value %" PRIo64
|
2014-03-04 03:15:20 +08:00
|
|
|
" is too large to fit in a %" PRIu64
|
|
|
|
" byte unsigned integer value.\n",
|
|
|
|
uval64, (uint64_t)item_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
buffer.PutMaxHex64(uval64, item_byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (!buffer.GetString().empty()) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-11-17 05:15:24 +08:00
|
|
|
if (process->WriteMemory(addr, buffer.GetString().data(),
|
2010-07-21 06:52:08 +08:00
|
|
|
buffer.GetString().size(),
|
|
|
|
error) == buffer.GetString().size())
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
else {
|
2012-11-30 05:49:15 +08:00
|
|
|
result.AppendErrorWithFormat("Memory write to 0x%" PRIx64
|
|
|
|
" failed: %s.\n",
|
|
|
|
addr, error.AsCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupFormat m_format_options;
|
|
|
|
OptionGroupWriteMemory m_memory_options;
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
// Get malloc/free history of a memory address.
|
|
|
|
class CommandObjectMemoryHistory : public CommandObjectParsed {
|
|
|
|
public:
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectMemoryHistory(CommandInterpreter &interpreter)
|
2019-10-31 06:26:19 +08:00
|
|
|
: CommandObjectParsed(interpreter, "memory history",
|
|
|
|
"Print recorded stack traces for "
|
|
|
|
"allocation/deallocation events "
|
|
|
|
"associated with an address.",
|
|
|
|
nullptr,
|
|
|
|
eCommandRequiresTarget | eCommandRequiresProcess |
|
|
|
|
eCommandProcessMustBePaused |
|
|
|
|
eCommandProcessMustBeLaunched) {
|
2014-09-04 09:03:18 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentData addr_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
addr_arg.arg_type = eArgTypeAddress;
|
|
|
|
addr_arg.arg_repetition = eArgRepeatPlain;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg1.push_back(addr_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg1);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
~CommandObjectMemoryHistory() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-02-05 07:16:31 +08:00
|
|
|
llvm::Optional<std::string> GetRepeatCommand(Args ¤t_command_args,
|
|
|
|
uint32_t index) override {
|
|
|
|
return m_cmd_name;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
protected:
|
2016-06-10 00:34:06 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2014-09-04 09:03:18 +08:00
|
|
|
const size_t argc = command.GetArgumentCount();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
if (argc == 0 || argc > 1) {
|
|
|
|
result.AppendErrorWithFormat("%s takes an address expression",
|
|
|
|
m_cmd_name.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2014-09-04 09:03:18 +08:00
|
|
|
}
|
2016-02-20 08:58:29 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2018-04-10 17:03:59 +08:00
|
|
|
lldb::addr_t addr = OptionArgParser::ToAddress(
|
2019-09-13 19:26:48 +08:00
|
|
|
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);
|
2016-02-20 08:58:29 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
if (addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
result.AppendError("invalid address expression");
|
|
|
|
result.AppendError(error.AsCString());
|
2014-09-04 09:03:18 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
Stream *output_stream = &result.GetOutputStream();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
const ProcessSP &process_sp = m_exe_ctx.GetProcessSP();
|
|
|
|
const MemoryHistorySP &memory_history =
|
|
|
|
MemoryHistory::FindPlugin(process_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
if (!memory_history) {
|
2014-09-04 09:03:18 +08:00
|
|
|
result.AppendError("no available memory history provider");
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
HistoryThreads thread_list = memory_history->GetHistoryThreads(addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-09 04:36:40 +08:00
|
|
|
const bool stop_format = false;
|
2014-09-04 09:03:18 +08:00
|
|
|
for (auto thread : thread_list) {
|
2016-11-09 04:36:40 +08:00
|
|
|
thread->GetStatus(*output_stream, 0, UINT32_MAX, 0, stop_format);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 09:03:18 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-09-04 09:03:18 +08:00
|
|
|
};
|
|
|
|
|
2016-06-10 00:34:06 +08:00
|
|
|
// CommandObjectMemoryRegion
|
|
|
|
#pragma mark CommandObjectMemoryRegion
|
|
|
|
|
2022-05-19 19:57:44 +08:00
|
|
|
#define LLDB_OPTIONS_memory_region
|
|
|
|
#include "CommandOptions.inc"
|
|
|
|
|
2016-06-10 00:34:06 +08:00
|
|
|
class CommandObjectMemoryRegion : public CommandObjectParsed {
|
|
|
|
public:
|
2022-05-19 19:57:44 +08:00
|
|
|
class OptionGroupMemoryRegion : public OptionGroup {
|
|
|
|
public:
|
|
|
|
OptionGroupMemoryRegion() : OptionGroup(), m_all(false, false) {}
|
|
|
|
|
|
|
|
~OptionGroupMemoryRegion() override = default;
|
|
|
|
|
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
|
|
|
return llvm::makeArrayRef(g_memory_region_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status status;
|
|
|
|
const int short_option = g_memory_region_options[option_idx].short_option;
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 'a':
|
|
|
|
m_all.SetCurrentValue(true);
|
|
|
|
m_all.SetOptionWasSet();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unimplemented option");
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
m_all.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValueBoolean m_all;
|
|
|
|
};
|
|
|
|
|
2016-06-10 00:34:06 +08:00
|
|
|
CommandObjectMemoryRegion(CommandInterpreter &interpreter)
|
2016-07-15 06:03:10 +08:00
|
|
|
: CommandObjectParsed(interpreter, "memory region",
|
|
|
|
"Get information on the memory region containing "
|
|
|
|
"an address in the current target process.",
|
2022-05-19 19:57:44 +08:00
|
|
|
"memory region <address-expression> (or --all)",
|
2016-07-15 06:03:10 +08:00
|
|
|
eCommandRequiresProcess | eCommandTryTargetAPILock |
|
2022-05-19 19:57:44 +08:00
|
|
|
eCommandProcessMustBeLaunched) {
|
|
|
|
// Address in option set 1.
|
|
|
|
m_arguments.push_back(CommandArgumentEntry{CommandArgumentData(
|
|
|
|
eArgTypeAddressOrExpression, eArgRepeatPlain, LLDB_OPT_SET_1)});
|
|
|
|
// "--all" will go in option set 2.
|
|
|
|
m_option_group.Append(&m_memory_region_options);
|
|
|
|
m_option_group.Finalize();
|
|
|
|
}
|
2016-06-10 00:34:06 +08:00
|
|
|
|
|
|
|
~CommandObjectMemoryRegion() override = default;
|
|
|
|
|
2022-05-19 19:57:44 +08:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
|
|
|
|
2016-06-10 00:34:06 +08:00
|
|
|
protected:
|
2022-05-19 19:57:44 +08:00
|
|
|
void DumpRegion(CommandReturnObject &result, Target &target,
|
|
|
|
const MemoryRegionInfo &range_info, lldb::addr_t load_addr) {
|
|
|
|
lldb_private::Address addr;
|
|
|
|
ConstString section_name;
|
|
|
|
if (target.ResolveLoadAddress(load_addr, addr)) {
|
|
|
|
SectionSP section_sp(addr.GetSection());
|
|
|
|
if (section_sp) {
|
|
|
|
// Got the top most section, not the deepest section
|
|
|
|
while (section_sp->GetParent())
|
|
|
|
section_sp = section_sp->GetParent();
|
|
|
|
section_name = section_sp->GetName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString name = range_info.GetName();
|
|
|
|
result.AppendMessageWithFormatv(
|
|
|
|
"[{0:x16}-{1:x16}) {2:r}{3:w}{4:x}{5}{6}{7}{8}",
|
|
|
|
range_info.GetRange().GetRangeBase(),
|
|
|
|
range_info.GetRange().GetRangeEnd(), range_info.GetReadable(),
|
|
|
|
range_info.GetWritable(), range_info.GetExecutable(), name ? " " : "",
|
|
|
|
name, section_name ? " " : "", section_name);
|
|
|
|
MemoryRegionInfo::OptionalBool memory_tagged = range_info.GetMemoryTagged();
|
|
|
|
if (memory_tagged == MemoryRegionInfo::OptionalBool::eYes)
|
|
|
|
result.AppendMessage("memory tagging: enabled");
|
|
|
|
|
|
|
|
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
|
|
|
|
range_info.GetDirtyPageList();
|
|
|
|
if (dirty_page_list.hasValue()) {
|
|
|
|
const size_t page_count = dirty_page_list.getValue().size();
|
|
|
|
result.AppendMessageWithFormat(
|
|
|
|
"Modified memory (dirty) page list provided, %zu entries.\n",
|
|
|
|
page_count);
|
|
|
|
if (page_count > 0) {
|
|
|
|
bool print_comma = false;
|
|
|
|
result.AppendMessageWithFormat("Dirty pages: ");
|
|
|
|
for (size_t i = 0; i < page_count; i++) {
|
|
|
|
if (print_comma)
|
|
|
|
result.AppendMessageWithFormat(", ");
|
|
|
|
else
|
|
|
|
print_comma = true;
|
|
|
|
result.AppendMessageWithFormat("0x%" PRIx64,
|
|
|
|
dirty_page_list.getValue()[i]);
|
|
|
|
}
|
|
|
|
result.AppendMessageWithFormat(".\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 00:34:06 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
ProcessSP process_sp = m_exe_ctx.GetProcessSP();
|
2020-09-24 21:50:41 +08:00
|
|
|
if (!process_sp) {
|
2016-06-10 00:34:06 +08:00
|
|
|
m_prev_end_addr = LLDB_INVALID_ADDRESS;
|
2020-09-24 21:50:41 +08:00
|
|
|
result.AppendError("invalid process");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status error;
|
|
|
|
lldb::addr_t load_addr = m_prev_end_addr;
|
|
|
|
m_prev_end_addr = LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-09-24 21:50:41 +08:00
|
|
|
const size_t argc = command.GetArgumentCount();
|
2021-12-02 00:14:54 +08:00
|
|
|
const lldb::ABISP &abi = process_sp->GetABI();
|
2020-09-24 21:50:41 +08:00
|
|
|
|
|
|
|
if (argc == 1) {
|
2022-05-19 19:57:44 +08:00
|
|
|
if (m_memory_region_options.m_all) {
|
|
|
|
result.AppendError(
|
|
|
|
"The \"--all\" option cannot be used when an address "
|
|
|
|
"argument is given");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:50:41 +08:00
|
|
|
auto load_addr_str = command[0].ref();
|
2021-12-02 00:14:54 +08:00
|
|
|
// Non-address bits in this will be handled later by GetMemoryRegion
|
2020-09-24 21:50:41 +08:00
|
|
|
load_addr = OptionArgParser::ToAddress(&m_exe_ctx, load_addr_str,
|
|
|
|
LLDB_INVALID_ADDRESS, &error);
|
|
|
|
if (error.Fail() || load_addr == LLDB_INVALID_ADDRESS) {
|
|
|
|
result.AppendErrorWithFormat("invalid address argument \"%s\": %s\n",
|
|
|
|
command[0].c_str(), error.AsCString());
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-02 00:14:54 +08:00
|
|
|
} else if (argc > 1 ||
|
|
|
|
// When we're repeating the command, the previous end address is
|
|
|
|
// used for load_addr. If that was 0xF...F then we must have
|
|
|
|
// reached the end of memory.
|
2022-05-19 19:57:44 +08:00
|
|
|
(argc == 0 && !m_memory_region_options.m_all &&
|
|
|
|
load_addr == LLDB_INVALID_ADDRESS) ||
|
2021-12-02 00:14:54 +08:00
|
|
|
// If the target has non-address bits (tags, limited virtual
|
|
|
|
// address size, etc.), the end of mappable memory will be lower
|
|
|
|
// than that. So if we find any non-address bit set, we must be
|
|
|
|
// at the end of the mappable range.
|
2022-04-13 20:27:46 +08:00
|
|
|
(abi && (abi->FixAnyAddress(load_addr) != load_addr))) {
|
2022-05-19 19:57:44 +08:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
"'%s' takes one argument or \"--all\" option:\nUsage: %s\n",
|
|
|
|
m_cmd_name.c_str(), m_cmd_syntax.c_str());
|
2021-12-02 00:14:54 +08:00
|
|
|
return false;
|
2020-09-24 21:50:41 +08:00
|
|
|
}
|
2016-06-10 00:34:06 +08:00
|
|
|
|
2022-05-19 19:57:44 +08:00
|
|
|
// Is is important that we track the address used to request the region as
|
|
|
|
// this will give the correct section name in the case that regions overlap.
|
|
|
|
// On Windows we get mutliple regions that start at the same place but are
|
|
|
|
// different sizes and refer to different sections.
|
|
|
|
std::vector<std::pair<lldb_private::MemoryRegionInfo, lldb::addr_t>>
|
|
|
|
region_list;
|
|
|
|
if (m_memory_region_options.m_all) {
|
|
|
|
// We don't use GetMemoryRegions here because it doesn't include unmapped
|
|
|
|
// areas like repeating the command would. So instead, emulate doing that.
|
|
|
|
lldb::addr_t addr = 0;
|
|
|
|
while (error.Success() && addr != LLDB_INVALID_ADDRESS &&
|
|
|
|
// When there are non-address bits the last range will not extend
|
|
|
|
// to LLDB_INVALID_ADDRESS but to the max virtual address.
|
|
|
|
// This prevents us looping forever if that is the case.
|
|
|
|
(abi && (abi->FixAnyAddress(addr) == addr))) {
|
|
|
|
lldb_private::MemoryRegionInfo region_info;
|
|
|
|
error = process_sp->GetMemoryRegionInfo(addr, region_info);
|
|
|
|
|
|
|
|
if (error.Success()) {
|
|
|
|
region_list.push_back({region_info, addr});
|
|
|
|
addr = region_info.GetRange().GetRangeEnd();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-17 22:02:04 +08:00
|
|
|
|
2022-05-19 19:57:44 +08:00
|
|
|
// Even if we read nothing, don't error for --all
|
|
|
|
error.Clear();
|
|
|
|
} else {
|
|
|
|
lldb_private::MemoryRegionInfo region_info;
|
|
|
|
error = process_sp->GetMemoryRegionInfo(load_addr, region_info);
|
|
|
|
if (error.Success())
|
|
|
|
region_list.push_back({region_info, load_addr});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error.Success()) {
|
|
|
|
for (std::pair<MemoryRegionInfo, addr_t> &range : region_list) {
|
|
|
|
DumpRegion(result, process_sp->GetTarget(), range.first, range.second);
|
|
|
|
m_prev_end_addr = range.first.GetRange().GetRangeEnd();
|
2021-06-21 03:19:50 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:50:41 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
2016-06-10 00:34:06 +08:00
|
|
|
}
|
2020-09-24 21:50:41 +08:00
|
|
|
|
|
|
|
result.AppendErrorWithFormat("%s\n", error.AsCString());
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-02-05 07:16:31 +08:00
|
|
|
llvm::Optional<std::string> GetRepeatCommand(Args ¤t_command_args,
|
|
|
|
uint32_t index) override {
|
2013-07-25 02:17:35 +08:00
|
|
|
// If we repeat this command, repeat it without any arguments so we can
|
2016-06-10 00:34:06 +08:00
|
|
|
// show the next memory range
|
2022-02-05 07:16:31 +08:00
|
|
|
return m_cmd_name;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-06-10 00:34:06 +08:00
|
|
|
|
2022-03-15 04:32:03 +08:00
|
|
|
lldb::addr_t m_prev_end_addr = LLDB_INVALID_ADDRESS;
|
2022-05-19 19:57:44 +08:00
|
|
|
|
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupMemoryRegion m_memory_region_options;
|
2016-06-10 00:34:06 +08:00
|
|
|
};
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// CommandObjectMemory
|
|
|
|
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectMemory::CommandObjectMemory(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(
|
|
|
|
interpreter, "memory",
|
|
|
|
"Commands for operating on memory in the current target process.",
|
|
|
|
"memory <subcommand> [<subcommand-options>]") {
|
2016-06-10 00:34:06 +08:00
|
|
|
LoadSubCommand("find",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryFind(interpreter)));
|
|
|
|
LoadSubCommand("read",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryRead(interpreter)));
|
|
|
|
LoadSubCommand("write",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryWrite(interpreter)));
|
|
|
|
LoadSubCommand("history",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryHistory(interpreter)));
|
|
|
|
LoadSubCommand("region",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryRegion(interpreter)));
|
2021-02-20 00:31:46 +08:00
|
|
|
LoadSubCommand("tag",
|
|
|
|
CommandObjectSP(new CommandObjectMemoryTag(interpreter)));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
CommandObjectMemory::~CommandObjectMemory() = default;
|