[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
|
|
|
//===-- SBMemoryRegionInfo.cpp --------------------------------------------===//
|
2016-06-23 16:35:37 +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
|
2016-06-23 16:35:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBMemoryRegionInfo.h"
|
2019-03-06 08:05:55 +08:00
|
|
|
#include "Utils.h"
|
2016-06-23 16:35:37 +08:00
|
|
|
#include "lldb/API/SBDefines.h"
|
|
|
|
#include "lldb/API/SBError.h"
|
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
#include "lldb/Target/MemoryRegionInfo.h"
|
2022-01-20 03:38:26 +08:00
|
|
|
#include "lldb/Utility/Instrumentation.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2016-06-23 16:35:37 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBMemoryRegionInfo::SBMemoryRegionInfo() : m_opaque_up(new MemoryRegionInfo()) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
[lldb/Plugins] Add memory region support in ScriptedProcess
This patch adds support for memory regions in Scripted Processes.
This is necessary to read the stack memory region in order to
reconstruct each stackframe of the program.
In order to do so, this patch makes some changes to the SBAPI, namely:
- Add a new constructor for `SBMemoryRegionInfo` that takes arguments
such as the memory region name, address range, permissions ...
This is used when reading memory at some address to compute the offset
in the binary blob provided by the user.
- Add a `GetMemoryRegionContainingAddress` method to `SBMemoryRegionInfoList`
to simplify the access to a specific memory region.
With these changes, lldb is now able to unwind the stack and reconstruct
each frame. On top of that, reloading the target module at offset 0 allows
lldb to symbolicate the `ScriptedProcess` using debug info, similarly to an
ordinary Process.
To test this, I wrote a simple program with multiple function calls, ran it in
lldb, stopped at a leaf function and read the registers values and copied
the stack memory into a binary file. These are then used in the python script.
Differential Revision: https://reviews.llvm.org/D108953
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-10-08 20:25:04 +08:00
|
|
|
SBMemoryRegionInfo::SBMemoryRegionInfo(const char *name, lldb::addr_t begin,
|
|
|
|
lldb::addr_t end, uint32_t permissions,
|
|
|
|
bool mapped, bool stack_memory)
|
|
|
|
: SBMemoryRegionInfo() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, name, begin, end, permissions, mapped, stack_memory);
|
[lldb/Plugins] Add memory region support in ScriptedProcess
This patch adds support for memory regions in Scripted Processes.
This is necessary to read the stack memory region in order to
reconstruct each stackframe of the program.
In order to do so, this patch makes some changes to the SBAPI, namely:
- Add a new constructor for `SBMemoryRegionInfo` that takes arguments
such as the memory region name, address range, permissions ...
This is used when reading memory at some address to compute the offset
in the binary blob provided by the user.
- Add a `GetMemoryRegionContainingAddress` method to `SBMemoryRegionInfoList`
to simplify the access to a specific memory region.
With these changes, lldb is now able to unwind the stack and reconstruct
each frame. On top of that, reloading the target module at offset 0 allows
lldb to symbolicate the `ScriptedProcess` using debug info, similarly to an
ordinary Process.
To test this, I wrote a simple program with multiple function calls, ran it in
lldb, stopped at a leaf function and read the registers values and copied
the stack memory into a binary file. These are then used in the python script.
Differential Revision: https://reviews.llvm.org/D108953
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-10-08 20:25:04 +08:00
|
|
|
m_opaque_up->SetName(name);
|
|
|
|
m_opaque_up->GetRange().SetRangeBase(begin);
|
|
|
|
m_opaque_up->GetRange().SetRangeEnd(end);
|
|
|
|
m_opaque_up->SetLLDBPermissions(permissions);
|
|
|
|
m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
|
|
|
|
: MemoryRegionInfo::eNo);
|
|
|
|
m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
|
|
|
|
: MemoryRegionInfo::eNo);
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(new MemoryRegionInfo()) {
|
2016-06-23 16:35:37 +08:00
|
|
|
if (lldb_object_ptr)
|
|
|
|
ref() = *lldb_object_ptr;
|
|
|
|
}
|
|
|
|
|
2022-01-03 14:44:15 +08:00
|
|
|
SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const SBMemoryRegionInfo &SBMemoryRegionInfo::
|
|
|
|
operator=(const SBMemoryRegionInfo &rhs) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2022-01-10 14:54:08 +08:00
|
|
|
return *this;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 14:57:06 +08:00
|
|
|
SBMemoryRegionInfo::~SBMemoryRegionInfo() = default;
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBMemoryRegionInfo::Clear() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
m_opaque_up->Clear();
|
|
|
|
}
|
2016-06-23 16:35:37 +08:00
|
|
|
|
|
|
|
bool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
return ref() == rhs.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
return ref() != rhs.ref();
|
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
MemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_up; }
|
2016-06-23 16:35:37 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
|
2016-06-23 16:35:37 +08:00
|
|
|
|
|
|
|
lldb::addr_t SBMemoryRegionInfo::GetRegionBase() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetRange().GetRangeBase();
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetRange().GetRangeEnd();
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBMemoryRegionInfo::IsReadable() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBMemoryRegionInfo::IsWritable() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBMemoryRegionInfo::IsExecutable() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
|
2016-06-23 16:35:37 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 16:21:28 +08:00
|
|
|
bool SBMemoryRegionInfo::IsMapped() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
|
2016-07-07 16:21:28 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 20:55:35 +08:00
|
|
|
const char *SBMemoryRegionInfo::GetName() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up->GetName().AsCString();
|
2016-07-22 20:55:35 +08:00
|
|
|
}
|
|
|
|
|
2021-08-17 04:46:12 +08:00
|
|
|
bool SBMemoryRegionInfo::HasDirtyMemoryPageList() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2021-06-21 03:19:50 +08:00
|
|
|
|
2022-06-21 11:05:16 +08:00
|
|
|
return m_opaque_up->GetDirtyPageList().has_value();
|
2021-06-21 03:19:50 +08:00
|
|
|
}
|
|
|
|
|
2021-08-17 04:46:12 +08:00
|
|
|
uint32_t SBMemoryRegionInfo::GetNumDirtyPages() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2021-06-21 03:19:50 +08:00
|
|
|
|
|
|
|
uint32_t num_dirty_pages = 0;
|
2022-05-17 21:43:08 +08:00
|
|
|
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
|
2021-06-21 03:19:50 +08:00
|
|
|
m_opaque_up->GetDirtyPageList();
|
|
|
|
if (dirty_page_list.hasValue())
|
|
|
|
num_dirty_pages = dirty_page_list.getValue().size();
|
|
|
|
|
|
|
|
return num_dirty_pages;
|
|
|
|
}
|
|
|
|
|
2021-08-17 04:46:12 +08:00
|
|
|
addr_t SBMemoryRegionInfo::GetDirtyPageAddressAtIndex(uint32_t idx) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, idx);
|
2021-06-21 03:19:50 +08:00
|
|
|
|
|
|
|
addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
|
|
|
|
m_opaque_up->GetDirtyPageList();
|
|
|
|
if (dirty_page_list.hasValue() && idx < dirty_page_list.getValue().size())
|
|
|
|
dirty_page_addr = dirty_page_list.getValue()[idx];
|
|
|
|
|
|
|
|
return dirty_page_addr;
|
|
|
|
}
|
|
|
|
|
2021-08-17 04:46:12 +08:00
|
|
|
int SBMemoryRegionInfo::GetPageSize() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2021-08-17 04:40:07 +08:00
|
|
|
|
2021-06-21 03:19:50 +08:00
|
|
|
return m_opaque_up->GetPageSize();
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
bool SBMemoryRegionInfo::GetDescription(SBStream &description) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, description);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2016-06-23 16:35:37 +08:00
|
|
|
Stream &strm = description.ref();
|
2019-02-13 14:25:41 +08:00
|
|
|
const addr_t load_addr = m_opaque_up->GetRange().base;
|
2016-06-23 16:35:37 +08:00
|
|
|
|
|
|
|
strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
|
2019-02-13 14:25:41 +08:00
|
|
|
load_addr + m_opaque_up->GetRange().size);
|
|
|
|
strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
|
|
|
|
strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
|
|
|
|
strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
|
2016-06-23 16:35:37 +08:00
|
|
|
strm.Printf("]");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|