Skip to content

Commit e82c452

Browse files
committed
v1.3.0
2 parents c874601 + 0bdefcd commit e82c452

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+34869
-146
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build and test
22

3-
on: [push, pull_request]
3+
on: {push: { branches: [main] }, pull_request: {}}
44

55
jobs:
66
build:

CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ if (WIN32)
3939
endif()
4040

4141
include_directories(third_party/llvm/include)
42+
include_directories(third_party/swift/include)
43+
add_definitions(
44+
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
45+
-DSWIFT_SUPPORT_OLD_MANGLING=1
46+
-DSWIFT_STDLIB_HAS_TYPE_PRINTING=1
47+
)
4248
add_executable(demumble
4349
demumble.cc
4450
third_party/llvm/lib/Demangle/Demangle.cpp
@@ -47,6 +53,17 @@ add_executable(demumble
4753
third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
4854
third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
4955
third_party/llvm/lib/Demangle/RustDemangle.cpp
56+
third_party/swift/lib/Demangling/Context.cpp
57+
third_party/swift/lib/Demangling/CrashReporter.cpp
58+
third_party/swift/lib/Demangling/Demangler.cpp
59+
third_party/swift/lib/Demangling/Errors.cpp
60+
third_party/swift/lib/Demangling/ManglingUtils.cpp
61+
third_party/swift/lib/Demangling/NodeDumper.cpp
62+
third_party/swift/lib/Demangling/NodePrinter.cpp
63+
third_party/swift/lib/Demangling/OldDemangler.cpp
64+
third_party/swift/lib/Demangling/OldRemangler.cpp
65+
third_party/swift/lib/Demangling/Punycode.cpp
66+
third_party/swift/lib/Demangling/Remangler.cpp
5067
)
5168
set_target_properties(demumble PROPERTIES CXX_STANDARD 17
5269
CXX_STANDARD_REQUIRED ON)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Use cmake to build: `cmake -G Ninja . && ninja`
8282
Run tests after building: `python demumble_test.py`
8383

8484
`cxa_demangle.cpp` needs more C++11 than Visual Studio 2013 supports, so
85-
to build on Windows you need to use Visual Studion 2015 or use clang-cl
85+
to build on Windows you need to use Visual Studio 2015 or use clang-cl
8686
as C++ compiler like so:
8787

8888
cmake -G Ninja -DCMAKE_CXX_COMPILER=path/to/llvm-build/bin/clang-cl.exe

RELEASING

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Push new release branch:
2-
1. make sure branches 'main' and 'release' are synced up locally
2+
1. make sure branches 'main' and 'release' are synced up locally, check out main
33
2. update kDemumbleVersion in demumble.cc with new version (with ".git"), then
44
git commit -am 'mark this 1.0.0.git'
55
3. git checkout release; git merge main
66
4. fix version number in src/version.cc (it will conflict in the above)
77
5. commit, tag, push (don't forget to push --tags), build binaries
8+
# on the 'release' branch
89
git commit -am v1.0.0; git push origin release
910
git tag v1.0.0; git push --tags
10-
./dist.py # on the 'release' branch
11+
./dist.py
1112
# Push the 1.0.0.git change on main too:
1213
git checkout main; git push origin main
1314
6. add demumble-{linux,mac,win}.zip to https://github.com/nico/demumble/releases

demumble.cc

+35-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include <algorithm>
66

77
#include "llvm/Demangle/Demangle.h"
8+
#include "swift/Demangling/Demangle.h"
89

9-
const char kDemumbleVersion[] = "1.2.3";
10+
const char kDemumbleVersion[] = "1.3.0";
1011

1112
static int print_help(FILE* out) {
1213
fprintf(out,
@@ -33,6 +34,14 @@ static void print_demangled(const char* format, std::string_view s,
3334
} else if (char* ms = llvm::microsoftDemangle(s, n_used, NULL)) {
3435
printf(format, ms, (int)s.size(), s.data());
3536
free(ms);
37+
} else if (swift::Demangle::isSwiftSymbol(s)) {
38+
swift::Demangle::DemangleOptions options;
39+
options.SynthesizeSugarOnTypes = true;
40+
std::string swift = swift::Demangle::demangleSymbolAsString(s, options);
41+
if (swift == s)
42+
printf("%.*s", (int)s.size(), s.data()); // Not a mangled name
43+
else
44+
printf(format, swift.c_str(), (int)s.size(), s.data());
3645
} else {
3746
printf("%.*s", (int)s.size(), s.data());
3847
}
@@ -44,11 +53,17 @@ static bool is_mangle_char_itanium(char c) {
4453
}
4554

4655
static bool is_mangle_char_rust(char c) {
47-
// See https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html.
56+
// https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html.
4857
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
4958
(c >= '0' && c <= '9') || c == '_';
5059
}
5160

61+
static bool is_mangle_char_swift(char c) {
62+
// https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst
63+
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
64+
(c >= '0' && c <= '9') || c == '_' || c == '$';
65+
}
66+
5267
static bool is_mangle_char_win(char c) {
5368
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
5469
(c >= '0' && c <= '9') || strchr("?_@$", c);
@@ -68,6 +83,18 @@ static bool is_plausible_rust_prefix(char* s) {
6883
return s[0] == '_' && s[1] == 'R';
6984
}
7085

86+
static bool is_plausible_swift_prefix(char* s) {
87+
// https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst
88+
// But also swift/test/Demangle/Inputs/manglings.txt, which has
89+
// _Tt, _TF etc as prefix.
90+
91+
// FIXME: This is missing prefix `@__swiftmacro_`.
92+
return
93+
(s[0] == '$' && s[1] == 's') ||
94+
(s[0] == '_' && s[1] == 'T') ||
95+
(s[0] == '$' && s[1] == 'S');
96+
}
97+
7198
static char buf[8192];
7299
int main(int argc, char* argv[]) {
73100
enum { kPrintAll, kPrintMatching } print_mode = kPrintAll;
@@ -119,13 +146,13 @@ int main(int argc, char* argv[]) {
119146
char* end = cur + strlen(cur);
120147

121148
while (cur != end) {
122-
size_t special = strcspn(cur, "_?");
149+
size_t offset_to_possible_symbol = strcspn(cur, "_?$");
123150
if (print_mode == kPrintAll)
124-
printf("%.*s", static_cast<int>(special), cur);
151+
printf("%.*s", static_cast<int>(offset_to_possible_symbol), cur);
125152
else if (need_separator)
126153
printf("\n");
127154
need_separator = false;
128-
cur += special;
155+
cur += offset_to_possible_symbol;
129156
if (cur == end)
130157
break;
131158

@@ -139,6 +166,9 @@ int main(int argc, char* argv[]) {
139166
else if (is_plausible_rust_prefix(cur))
140167
while (cur + n_sym != end && is_mangle_char_rust(cur[n_sym]))
141168
++n_sym;
169+
else if (is_plausible_swift_prefix(cur))
170+
while (cur + n_sym != end && is_mangle_char_swift(cur[n_sym]))
171+
++n_sym;
142172
else {
143173
if (print_mode == kPrintAll)
144174
printf("_");

demumble_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
'std::mem::align_of::<f64>\nmylib::foo::bar\n'),
1010
('demumble < _RINvNtC3std3mem8align_ofdE _RNvNvC5mylib3foo3bar',
1111
'std::mem::align_of::<f64>\nmylib::foo::bar\n'),
12+
('demumble _TtP3foo3bar_', 'foo.bar\n'),
13+
('demumble < _TtP3foo3bar_', 'foo.bar\n'),
14+
('demumble $sSS5countSivg', 'Swift.String.count.getter : Swift.Int\n'),
15+
('demumble < $sSS5countSivg', 'Swift.String.count.getter : Swift.Int\n'),
1216
('demumble ?Fxi@@YAHP6AHH@Z@Z', 'int __cdecl Fxi(int (__cdecl *)(int))\n'),
1317
('demumble ??0S@@QEAA@$$QEAU0@@Z', 'public: __cdecl S::S(struct S &&)\n'),
1418
('demumble ??_C@_02PCEFGMJL@hi?$AA@', '"hi"\n'),

scripts/copy-swift-demangle.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
# Swift's demangler is much less hermetic than LLVM's. This copies all the
4+
# code needed by Swift's demangler into this repository.
5+
6+
set -eu
7+
8+
# Adopt these three to match your local swift checkout and your local
9+
# llvm checkout and build dir:
10+
11+
LLVM_SRC=$HOME/src/llvm-project/llvm
12+
SWIFT_SRC=$HOME/src/swift
13+
LLVM_HEADER_GEN_SRC=$HOME/src/llvm-project/out/gn/gen/llvm/include/llvm
14+
15+
# The rest only needs updating if the set of needed files changes:
16+
17+
cd "$(dirname "$0")"/..
18+
19+
LLVM_INC_SRC=$LLVM_SRC/include/llvm
20+
LLVM_DST=third_party/llvm
21+
LLVM_INC_DST=$LLVM_DST/include/llvm
22+
23+
SWIFT_INC_SRC=$SWIFT_SRC/include/swift
24+
SWIFT_DST=third_party/swift
25+
SWIFT_INC_DST=$SWIFT_DST/include/swift
26+
27+
rm -rf $LLVM_INC_DST/ADT
28+
rm -rf $LLVM_INC_DST/Config
29+
rm -rf $LLVM_INC_DST/Support
30+
rm -rf $LLVM_DST/include/llvm-c
31+
rm -rf $SWIFT_DST
32+
33+
mkdir -p $LLVM_INC_DST/ADT
34+
cp "$LLVM_INC_SRC"/ADT/ADL.h $LLVM_INC_DST/ADT
35+
cp "$LLVM_INC_SRC"/ADT/DenseMapInfo.h $LLVM_INC_DST/ADT
36+
cp "$LLVM_INC_SRC"/ADT/Hashing.h $LLVM_INC_DST/ADT
37+
cp "$LLVM_INC_SRC"/ADT/STLExtras.h $LLVM_INC_DST/ADT
38+
cp "$LLVM_INC_SRC"/ADT/STLForwardCompat.h $LLVM_INC_DST/ADT
39+
cp "$LLVM_INC_SRC"/ADT/STLFunctionalExtras.h $LLVM_INC_DST/ADT
40+
cp "$LLVM_INC_SRC"/ADT/StringRef.h $LLVM_INC_DST/ADT
41+
cp "$LLVM_INC_SRC"/ADT/StringSwitch.h $LLVM_INC_DST/ADT
42+
cp "$LLVM_INC_SRC"/ADT/bit.h $LLVM_INC_DST/ADT
43+
cp "$LLVM_INC_SRC"/ADT/iterator.h $LLVM_INC_DST/ADT
44+
cp "$LLVM_INC_SRC"/ADT/iterator_range.h $LLVM_INC_DST/ADT
45+
46+
mkdir -p $LLVM_INC_DST/Config
47+
cp "$LLVM_HEADER_GEN_SRC"/Config/abi-breaking.h $LLVM_INC_DST/Config
48+
cp "$LLVM_HEADER_GEN_SRC"/Config/llvm-config.h $LLVM_INC_DST/Config
49+
50+
mkdir -p $LLVM_INC_DST/Support
51+
cp "$LLVM_INC_SRC"/Support/Casting.h $LLVM_INC_DST/Support
52+
cp "$LLVM_INC_SRC"/Support/Compiler.h $LLVM_INC_DST/Support
53+
cp "$LLVM_INC_SRC"/Support/DataTypes.h $LLVM_INC_DST/Support
54+
cp "$LLVM_INC_SRC"/Support/ErrorHandling.h $LLVM_INC_DST/Support
55+
cp "$LLVM_INC_SRC"/Support/SwapByteOrder.h $LLVM_INC_DST/Support
56+
cp "$LLVM_INC_SRC"/Support/type_traits.h $LLVM_INC_DST/Support
57+
58+
mkdir -p $LLVM_DST/include/llvm-c
59+
cp "$LLVM_SRC"/include/llvm-c/DataTypes.h $LLVM_DST/include/llvm-c
60+
61+
mkdir -p $SWIFT_DST
62+
cp "$SWIFT_SRC"/LICENSE.txt $SWIFT_DST
63+
64+
mkdir -p $SWIFT_INC_DST
65+
cp -R "$SWIFT_INC_SRC"/Demangling $SWIFT_INC_DST
66+
cp "$SWIFT_INC_SRC"/Strings.h $SWIFT_INC_DST
67+
68+
mkdir -p $SWIFT_INC_DST/ABI
69+
cp "$SWIFT_INC_SRC"/ABI/InvertibleProtocols.def $SWIFT_INC_DST/ABI
70+
71+
mkdir -p $SWIFT_INC_DST/AST
72+
cp "$SWIFT_INC_SRC"/AST/Ownership.h $SWIFT_INC_DST/AST
73+
cp "$SWIFT_INC_SRC"/AST/ReferenceStorage.def $SWIFT_INC_DST/AST
74+
75+
mkdir -p $SWIFT_INC_DST/Basic
76+
cp "$SWIFT_INC_SRC"/Basic/Assertions.h $SWIFT_INC_DST/Basic
77+
cp "$SWIFT_INC_SRC"/Basic/InlineBitfield.h $SWIFT_INC_DST/Basic
78+
cp "$SWIFT_INC_SRC"/Basic/LLVM.h $SWIFT_INC_DST/Basic
79+
cp "$SWIFT_INC_SRC"/Basic/MacroRoles.def $SWIFT_INC_DST/Basic
80+
cp "$SWIFT_INC_SRC"/Basic/STLExtras.h $SWIFT_INC_DST/Basic
81+
82+
mkdir -p $SWIFT_DST/lib
83+
cp -R "$SWIFT_SRC"/lib/Demangling $SWIFT_DST/lib
84+
rm $SWIFT_DST/lib/Demangling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*===-- include/llvm-c/DataTypes.h - Define fixed size types ------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file contains definitions to figure out the size of _HOST_ data types.*|
11+
|* This file is important because different host OS's define different macros,*|
12+
|* which makes portability tough. This file exports the following *|
13+
|* definitions: *|
14+
|* *|
15+
|* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
16+
|* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *|
17+
|* *|
18+
|* No library is required when using these functions. *|
19+
|* *|
20+
|*===----------------------------------------------------------------------===*/
21+
22+
/* Please leave this file C-compatible. */
23+
24+
#ifndef LLVM_C_DATATYPES_H
25+
#define LLVM_C_DATATYPES_H
26+
27+
#include <inttypes.h>
28+
#include <stdint.h>
29+
30+
#ifndef _MSC_VER
31+
32+
#if !defined(UINT32_MAX)
33+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
34+
"__STDC_LIMIT_MACROS before #including llvm-c/DataTypes.h"
35+
#endif
36+
37+
#if !defined(UINT32_C)
38+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
39+
"__STDC_CONSTANT_MACROS before #including llvm-c/DataTypes.h"
40+
#endif
41+
42+
/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
43+
#include <sys/types.h>
44+
45+
#ifdef _AIX
46+
// GCC is strict about defining large constants: they must have LL modifier.
47+
#undef INT64_MAX
48+
#undef INT64_MIN
49+
#endif
50+
51+
#else /* _MSC_VER */
52+
#ifdef __cplusplus
53+
#include <cstddef>
54+
#include <cstdlib>
55+
#else
56+
#include <stddef.h>
57+
#include <stdlib.h>
58+
#endif
59+
#include <sys/types.h>
60+
61+
#if defined(_WIN64)
62+
typedef signed __int64 ssize_t;
63+
#else
64+
typedef signed int ssize_t;
65+
#endif /* _WIN64 */
66+
67+
#endif /* _MSC_VER */
68+
69+
/* Set defaults for constants which we cannot find. */
70+
#if !defined(INT64_MAX)
71+
# define INT64_MAX 9223372036854775807LL
72+
#endif
73+
#if !defined(INT64_MIN)
74+
# define INT64_MIN ((-INT64_MAX)-1)
75+
#endif
76+
#if !defined(UINT64_MAX)
77+
# define UINT64_MAX 0xffffffffffffffffULL
78+
#endif
79+
80+
#endif /* LLVM_C_DATATYPES_H */

0 commit comments

Comments
 (0)