-
Notifications
You must be signed in to change notification settings - Fork 341
[Syntax Highlighting] Add name and parameters syntax highlighting in Swift backtraces #10710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: swift/release/6.2
Are you sure you want to change the base?
Changes from all commits
ffff0b7
1664713
ab98bc5
1a1468e
554852f
77eafcd
3967962
1491a30
8ded08d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,75 @@ class Mangled { | |
|
||
Stream &operator<<(Stream &s, const Mangled &obj); | ||
|
||
using namespace swift::Demangle; | ||
class TrackingNodePrinter : public NodePrinter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a doxygen comment explaining the purpose of this? |
||
public: | ||
TrackingNodePrinter(DemangleOptions options) : NodePrinter(options) {} | ||
|
||
DemangledNameInfo takeInfo() { return std::move(info); } | ||
|
||
private: | ||
DemangledNameInfo info; | ||
std::optional<unsigned> parametersDepth; | ||
|
||
void startName() { | ||
if (!info.hasBasename()) | ||
info.BasenameRange.first = getStreamLength(); | ||
} | ||
|
||
void endName() { | ||
if (!info.hasBasename()) | ||
info.BasenameRange.second = getStreamLength(); | ||
} | ||
|
||
void startParameters(unsigned depth) { | ||
if (parametersDepth || !info.hasBasename() || info.hasArguments()) { | ||
return; | ||
} | ||
info.ArgumentsRange.first = getStreamLength(); | ||
parametersDepth = depth; | ||
} | ||
|
||
void endParameters(unsigned depth) { | ||
if (!parametersDepth || *parametersDepth != depth || info.hasArguments()) { | ||
return; | ||
} | ||
info.ArgumentsRange.second = getStreamLength(); | ||
} | ||
|
||
bool shouldTrackNameRange(NodePointer Node) const { | ||
switch (Node->getKind()) { | ||
case Node::Kind::Function: | ||
case Node::Kind::Constructor: | ||
case Node::Kind::Allocator: | ||
case Node::Kind::ExplicitClosure: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
void printFunctionName(bool hasName, llvm::StringRef &OverwriteName, | ||
llvm::StringRef &ExtraName, bool MultiWordName, | ||
int &ExtraIndex, NodePointer Entity, | ||
unsigned int depth) override { | ||
if (shouldTrackNameRange(Entity)) | ||
startName(); | ||
NodePrinter::printFunctionName(hasName, OverwriteName, ExtraName, | ||
MultiWordName, ExtraIndex, Entity, depth); | ||
if (shouldTrackNameRange(Entity)) | ||
endName(); | ||
} | ||
|
||
void printFunctionParameters(NodePointer LabelList, NodePointer ParameterType, | ||
unsigned depth, bool showTypes) override { | ||
startParameters(depth); | ||
NodePrinter::printFunctionParameters(LabelList, ParameterType, depth, | ||
showTypes); | ||
endParameters(depth); | ||
} | ||
}; | ||
|
||
} // namespace lldb_private | ||
|
||
#endif // LLDB_CORE_MANGLED_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -610,6 +610,14 @@ class PluginManager { | |
static bool CreateSettingForCPlusPlusLanguagePlugin( | ||
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, | ||
llvm::StringRef description, bool is_global_property); | ||
|
||
static lldb::OptionValuePropertiesSP | ||
GetSettingForSwiftLanguagePlugin(Debugger &debugger, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, it would be nice if this could live in Plugin/ (but maybe it's harder to pull off here?) |
||
llvm::StringRef setting_name); | ||
|
||
static bool CreateSettingForSwiftLanguagePlugin( | ||
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, | ||
llvm::StringRef description, bool is_global_property); | ||
}; | ||
|
||
} // namespace lldb_private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,8 +353,15 @@ ConstString Mangled::GetDemangledNameImpl(bool force, // BEGIN SWIFT | |
const char *mangled_name = m_mangled.GetCString(); | ||
Log *log = GetLog(LLDBLog::Demangle); | ||
LLDB_LOGF(log, "demangle swift: %s", mangled_name); | ||
std::string demangled(SwiftLanguageRuntime::DemangleSymbolAsString( | ||
mangled_name, SwiftLanguageRuntime::eTypeName, sc)); | ||
auto [demangled, info] = SwiftLanguageRuntime::TrackedDemangleSymbolAsString( | ||
mangled_name, SwiftLanguageRuntime::eSimplified, sc); | ||
info.PrefixRange.second = | ||
std::min(info.BasenameRange.first, info.ArgumentsRange.first); | ||
info.SuffixRange.first = | ||
std::max(info.BasenameRange.second, info.ArgumentsRange.second); | ||
info.SuffixRange.second = demangled.length(); | ||
m_demangled_info.emplace(info); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a function that does all of this, like in the C++ case? |
||
|
||
// Don't cache the demangled name the function isn't available yet. | ||
if (!sc || !sc->function) { | ||
LLDB_LOGF(log, "demangle swift: %s -> \"%s\" (not cached)", mangled_name, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include "../../../../include/lldb/Core/PropertiesBase.td" | ||
Michael137 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let Definition = "language_swift" in { | ||
def FunctionNameFormat: Property<"function-name-format", "FormatEntity">, | ||
Global, | ||
DefaultStringValue<"${function.prefix}${ansi.fg.yellow}${function.basename}${ansi.normal}${function.formatted-arguments}${function.suffix}">, | ||
Desc<"Swift specific frame format string to use when displaying stack frame information for threads.">; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.