Skip to content

Commit a694172

Browse files
authored
[tools] Show helpful message when demangling '_' (#61369)
From most shells, the symbol(s) given to `swift demangle` should be quoted or escaped, otherwise the shell will perform variable expansion on the `$...` suffix of the symbol. For example: ``` % swift demangle _$sScMMa _ ---> _ ``` Instead the command should be edited to one of the following: ``` % swift demangle sScMMa _$sScMMa ---> type metadata accessor for Swift.MainActor % swift demangle '_$sScMMa' _$sScMMa ---> type metadata accessor for Swift.MainActor % swift demangle _\$sScMMa _$sScMMa ---> type metadata accessor for Swift.MainActor ``` When variable expansion has happened, `swift demangle` will see the symbol only as "`_`". This change adds a warning that identifies the likely issue, and contains suggestions on how the user can fix and rerun the invocation.
1 parent 8677190 commit a694172

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/swift-demangle/swift-demangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ int main(int argc, char **argv) {
391391
} else {
392392
swift::Demangle::Context DCtx;
393393
for (llvm::StringRef name : InputNames) {
394+
if (name == "_") {
395+
llvm::errs() << "warning: input symbol '_' is likely the result of "
396+
"variable expansion by the shell. Ensure the argument "
397+
"is quoted or escaped.\n";
398+
continue;
399+
}
394400
if (name.startswith("S") || name.startswith("s") ) {
395401
std::string correctedName = std::string("$") + name.str();
396402
demangle(llvm::outs(), correctedName, DCtx, options);

0 commit comments

Comments
 (0)