[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 08:23:27 +01:00
|
|
|
//===-- StackFrameRecognizer.cpp ------------------------------------------===//
|
2018-10-31 04:00:22 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2018-10-31 04:00:22 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
#include "lldb/Target/StackFrameRecognizer.h"
|
2018-10-31 04:00:22 +00:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
class ScriptedRecognizedStackFrame : public RecognizedStackFrame {
|
2024-08-23 09:55:47 -07:00
|
|
|
bool m_hidden;
|
|
|
|
|
|
2018-10-31 04:00:22 +00:00
|
|
|
public:
|
2024-08-23 09:55:47 -07:00
|
|
|
ScriptedRecognizedStackFrame(ValueObjectListSP args, bool hidden)
|
|
|
|
|
: m_hidden(hidden) {
|
|
|
|
|
m_arguments = std::move(args);
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
2024-08-23 09:55:47 -07:00
|
|
|
bool ShouldHide() override { return m_hidden; }
|
2018-10-31 04:00:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ScriptedStackFrameRecognizer::ScriptedStackFrameRecognizer(
|
|
|
|
|
ScriptInterpreter *interpreter, const char *pclass)
|
|
|
|
|
: m_interpreter(interpreter), m_python_class(pclass) {
|
|
|
|
|
m_python_object_sp =
|
|
|
|
|
m_interpreter->CreateFrameRecognizer(m_python_class.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RecognizedStackFrameSP
|
|
|
|
|
ScriptedStackFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame) {
|
|
|
|
|
if (!m_python_object_sp || !m_interpreter)
|
|
|
|
|
return RecognizedStackFrameSP();
|
|
|
|
|
|
|
|
|
|
ValueObjectListSP args =
|
|
|
|
|
m_interpreter->GetRecognizedArguments(m_python_object_sp, frame);
|
2019-02-07 01:49:10 +00:00
|
|
|
auto args_synthesized = ValueObjectListSP(new ValueObjectList());
|
2024-08-23 09:55:47 -07:00
|
|
|
if (args) {
|
|
|
|
|
for (const auto &o : args->GetObjects())
|
|
|
|
|
args_synthesized->Append(ValueObjectRecognizerSynthesizedValue::Create(
|
|
|
|
|
*o, eValueTypeVariableArgument));
|
2019-02-07 01:49:10 +00:00
|
|
|
}
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2024-08-23 09:55:47 -07:00
|
|
|
bool hidden = m_interpreter->ShouldHide(m_python_object_sp, frame);
|
|
|
|
|
|
2019-02-07 01:49:10 +00:00
|
|
|
return RecognizedStackFrameSP(
|
2024-08-23 09:55:47 -07:00
|
|
|
new ScriptedRecognizedStackFrame(args_synthesized, hidden));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StackFrameRecognizerManager::BumpGeneration() {
|
|
|
|
|
uint32_t n = m_generation;
|
|
|
|
|
n = (n + 1) & ((1 << 16) - 1);
|
|
|
|
|
m_generation = n;
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
void StackFrameRecognizerManager::AddRecognizer(
|
|
|
|
|
StackFrameRecognizerSP recognizer, ConstString module,
|
|
|
|
|
llvm::ArrayRef<ConstString> symbols, bool first_instruction_only) {
|
2020-07-23 17:25:17 +02:00
|
|
|
m_recognizers.push_front({(uint32_t)m_recognizers.size(), recognizer, false,
|
|
|
|
|
module, RegularExpressionSP(), symbols,
|
2020-07-17 08:36:38 +02:00
|
|
|
RegularExpressionSP(), first_instruction_only});
|
2024-08-23 09:55:47 -07:00
|
|
|
BumpGeneration();
|
2020-07-17 08:36:38 +02:00
|
|
|
}
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
void StackFrameRecognizerManager::AddRecognizer(
|
|
|
|
|
StackFrameRecognizerSP recognizer, RegularExpressionSP module,
|
|
|
|
|
RegularExpressionSP symbol, bool first_instruction_only) {
|
2020-07-23 17:25:17 +02:00
|
|
|
m_recognizers.push_front({(uint32_t)m_recognizers.size(), recognizer, true,
|
|
|
|
|
ConstString(), module, std::vector<ConstString>(),
|
|
|
|
|
symbol, first_instruction_only});
|
2024-08-23 09:55:47 -07:00
|
|
|
BumpGeneration();
|
2020-07-17 08:36:38 +02:00
|
|
|
}
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
void StackFrameRecognizerManager::ForEach(
|
|
|
|
|
const std::function<void(uint32_t, std::string, std::string,
|
|
|
|
|
llvm::ArrayRef<ConstString>, bool)> &callback) {
|
|
|
|
|
for (auto entry : m_recognizers) {
|
|
|
|
|
if (entry.is_regexp) {
|
|
|
|
|
std::string module_name;
|
|
|
|
|
std::string symbol_name;
|
2018-10-31 04:00:22 +00:00
|
|
|
|
|
|
|
|
if (entry.module_regexp)
|
2020-07-17 08:36:38 +02:00
|
|
|
module_name = entry.module_regexp->GetText().str();
|
2018-10-31 04:00:22 +00:00
|
|
|
if (entry.symbol_regexp)
|
2020-07-17 08:36:38 +02:00
|
|
|
symbol_name = entry.symbol_regexp->GetText().str();
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
callback(entry.recognizer_id, entry.recognizer->GetName(), module_name,
|
2023-01-09 18:11:07 +01:00
|
|
|
llvm::ArrayRef(ConstString(symbol_name)), true);
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
} else {
|
|
|
|
|
callback(entry.recognizer_id, entry.recognizer->GetName(),
|
|
|
|
|
entry.module.GetCString(), entry.symbols, false);
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
bool StackFrameRecognizerManager::RemoveRecognizerWithID(
|
|
|
|
|
uint32_t recognizer_id) {
|
|
|
|
|
if (recognizer_id >= m_recognizers.size())
|
|
|
|
|
return false;
|
2020-07-23 17:25:17 +02:00
|
|
|
auto found =
|
|
|
|
|
llvm::find_if(m_recognizers, [recognizer_id](const RegisteredEntry &e) {
|
|
|
|
|
return e.recognizer_id == recognizer_id;
|
|
|
|
|
});
|
|
|
|
|
if (found == m_recognizers.end())
|
2020-07-17 08:36:38 +02:00
|
|
|
return false;
|
2020-07-23 17:25:17 +02:00
|
|
|
m_recognizers.erase(found);
|
2024-08-23 09:55:47 -07:00
|
|
|
BumpGeneration();
|
2020-07-17 08:36:38 +02:00
|
|
|
return true;
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
void StackFrameRecognizerManager::RemoveAllRecognizers() {
|
2024-08-23 09:55:47 -07:00
|
|
|
BumpGeneration();
|
2020-07-17 08:36:38 +02:00
|
|
|
m_recognizers.clear();
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
StackFrameRecognizerSP
|
|
|
|
|
StackFrameRecognizerManager::GetRecognizerForFrame(StackFrameSP frame) {
|
|
|
|
|
const SymbolContext &symctx = frame->GetSymbolContext(
|
|
|
|
|
eSymbolContextModule | eSymbolContextFunction | eSymbolContextSymbol);
|
|
|
|
|
ConstString function_name = symctx.GetFunctionName();
|
|
|
|
|
ModuleSP module_sp = symctx.module_sp;
|
|
|
|
|
if (!module_sp)
|
|
|
|
|
return StackFrameRecognizerSP();
|
|
|
|
|
ConstString module_name = module_sp->GetFileSpec().GetFilename();
|
|
|
|
|
Symbol *symbol = symctx.symbol;
|
|
|
|
|
if (!symbol)
|
|
|
|
|
return StackFrameRecognizerSP();
|
|
|
|
|
Address start_addr = symbol->GetAddress();
|
|
|
|
|
Address current_addr = frame->GetFrameCodeAddress();
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
for (auto entry : m_recognizers) {
|
|
|
|
|
if (entry.module)
|
|
|
|
|
if (entry.module != module_name)
|
|
|
|
|
continue;
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
if (entry.module_regexp)
|
|
|
|
|
if (!entry.module_regexp->Execute(module_name.GetStringRef()))
|
|
|
|
|
continue;
|
2018-10-31 04:00:22 +00:00
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
if (!entry.symbols.empty())
|
|
|
|
|
if (!llvm::is_contained(entry.symbols, function_name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (entry.symbol_regexp)
|
|
|
|
|
if (!entry.symbol_regexp->Execute(function_name.GetStringRef()))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (entry.first_instruction_only)
|
|
|
|
|
if (start_addr != current_addr)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return entry.recognizer;
|
|
|
|
|
}
|
|
|
|
|
return StackFrameRecognizerSP();
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 08:36:38 +02:00
|
|
|
RecognizedStackFrameSP
|
|
|
|
|
StackFrameRecognizerManager::RecognizeFrame(StackFrameSP frame) {
|
|
|
|
|
auto recognizer = GetRecognizerForFrame(frame);
|
|
|
|
|
if (!recognizer)
|
|
|
|
|
return RecognizedStackFrameSP();
|
|
|
|
|
return recognizer->RecognizeFrame(frame);
|
2018-10-31 04:00:22 +00:00
|
|
|
}
|