Skip to content

Commit 7ce084f

Browse files
committed
v1.2.0
2 parents 15de7ee + f87646d commit 7ce084f

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

CMakeLists.txt

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
22
project(demumble C CXX)
33

4-
# TODO: Also do this for gcc once gcc 4.9 is common.
5-
if (${UNIX} AND ${CMAKE_GENERATOR} STREQUAL "Ninja" AND
6-
${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
7-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color -Wall")
8-
endif()
4+
if (UNIX)
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti")
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
7+
if (${CMAKE_GENERATOR} STREQUAL "Ninja")
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
9+
endif()
910

10-
# 10.9 chosen somewhat arbitrary; it's the first target where clang defaults
11-
# to libc++ and ld64 defaults to stripping __TEXT,__eh_frame.
12-
if (APPLE)
13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9")
11+
# 10.9 chosen somewhat arbitrary; it's the first target where clang defaults
12+
# to libc++ and ld64 defaults to stripping __TEXT,__eh_frame.
13+
if (APPLE)
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9")
15+
else()
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-PIC")
17+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
18+
endif()
1419
endif()
1520

16-
# This is apparently the simplest way to statically link the CRT in CMake:
1721
if (WIN32)
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:inline /EHs-c- /GR-")
23+
24+
# This is apparently the simplest way to statically link the CRT in CMake:
1825
string(TOUPPER "${CMAKE_BUILD_TYPE}" build)
1926
set(flag_var "CMAKE_CXX_FLAGS_${build}")
2027
if(${flag_var} MATCHES "/MD")

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# demumble
22

3-
`demumble` demangles both POSIX and Visual Studio symbols. It runs on both
3+
`demumble` demangles both Itanium and Visual Studio symbols. It runs on both
44
POSIX and Windows.
55

66
$ demumble _Z4funcPci
@@ -37,9 +37,11 @@ thing:
3737

3838
Smart about filtering: Both c++filt and demumble can work as a stdin filter.
3939
demumble only demangles function symbols (which never look like other words),
40-
while c++filt defaults to demangling type names too, which are likely to look
41-
like regular words. demumble does demangle types when they're passed as args:
40+
while c++filt on macOS defaults to demangling type names too, which are likely
41+
to look like regular words. demumble does demangle types when they're passed
42+
as args without requiring the `--types` switch that c++filt needs on Linux:
4243

44+
# on macOS:
4345
$ echo 'I like Pi and _Znw' | c++filt
4446
I like int* and _Znw
4547
$ echo 'I like Pi and _Znw' | demumble
@@ -48,6 +50,9 @@ like regular words. demumble does demangle types when they're passed as args:
4850
int*
4951
$ demumble Pi
5052
int*
53+
# on Linux:
54+
$ c++filt Pi
55+
Pi
5156

5257
Cross-platform: demumble runs on Windows. demumble can demangle Windows-style
5358
symbols (also when running on non-Windows).

demumble.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "llvm/Demangle/Demangle.h"
88

9-
const char kDemumbleVersion[] = "1.1.0";
9+
const char kDemumbleVersion[] = "1.2.0";
1010

1111
static void print_help(FILE* out) {
1212
fprintf(out,
@@ -15,6 +15,7 @@ static void print_help(FILE* out) {
1515
"if symbols are unspecified, reads from stdin.\n"
1616
"\n"
1717
"options:\n"
18+
" -b print both demangled and mangled name\n"
1819
" -m only print mangled names that were demangled, omit other output\n"
1920
" -u use unbuffered output\n"
2021
" --version print demumble version (\"%s\")\n", kDemumbleVersion);
@@ -24,15 +25,15 @@ static bool starts_with(const char* s, const char* prefix) {
2425
return strncmp(s, prefix, strlen(prefix)) == 0;
2526
}
2627

27-
static void print_demangled(const char* s) {
28+
static void print_demangled(const char* format, const char* s) {
2829
const char* cxa_in = s;
2930
if (starts_with(s, "__Z") || starts_with(s, "____Z"))
3031
cxa_in += 1;
3132
if (char* itanium = llvm::itaniumDemangle(cxa_in, NULL, NULL, NULL)) {
32-
printf("%s", itanium);
33+
printf(format, itanium, s);
3334
free(itanium);
3435
} else if (char* ms = llvm::microsoftDemangle(s, NULL, NULL, NULL)) {
35-
printf("%s", ms);
36+
printf(format, ms, s);
3637
free(ms);
3738
} else {
3839
printf("%s", s);
@@ -61,10 +62,13 @@ static bool is_plausible_itanium_prefix(char* s) {
6162
static char buf[8192];
6263
int main(int argc, char* argv[]) {
6364
enum { kPrintAll, kPrintMatching } print_mode = kPrintAll;
65+
const char* print_format = "%s";
6466
while (argc > 1 && argv[1][0] == '-') {
6567
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
6668
print_help(stdout);
6769
return 0;
70+
} else if (strcmp(argv[1], "-b") == 0) {
71+
print_format = "\"%s\" (%s)";
6872
} else if (strcmp(argv[1], "-m") == 0) {
6973
print_mode = kPrintMatching;
7074
} else if (strcmp(argv[1], "-u") == 0) {
@@ -85,7 +89,7 @@ int main(int argc, char* argv[]) {
8589
++argv;
8690
}
8791
for (int i = 1; i < argc; ++i) {
88-
print_demangled(argv[i]);
92+
print_demangled(print_format, argv[i]);
8993
printf("\n");
9094
}
9195
if (argc == 1) { // Read stdin instead.
@@ -125,7 +129,7 @@ int main(int argc, char* argv[]) {
125129

126130
char tmp = cur[n_sym];
127131
cur[n_sym] = '\0';
128-
print_demangled(cur);
132+
print_demangled(print_format, cur);
129133
need_separator = true;
130134
cur[n_sym] = tmp;
131135

demumble_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
'.invocation function for block in blocksNRVO()\n'),
2424
('demumble -m < .____Z10blocksNRVOv_block_invoke',
2525
'invocation function for block in blocksNRVO()\n'),
26+
('demumble -- -b', '-b\n'),
2627
('demumble -- -m', '-m\n'),
2728
('demumble -- -h', '-h\n'),
2829
('demumble -h', re.compile('.*usage: demumble.*')),
2930
('demumble --help', re.compile('.*usage: demumble.*')),
3031
('demumble --version', re.compile('.*\..*')),
32+
('demumble -b hello', 'hello\n'),
33+
('demumble -b _Z1fv', '"f()" (_Z1fv)\n'),
34+
('demumble -b < _Z1fv', '"f()" (_Z1fv)\n'),
3135
]
3236

3337
status = 0

0 commit comments

Comments
 (0)