Skip to content

Commit 9b6e9c7

Browse files
committed
add c++ symbol name demangler
1 parent b290812 commit 9b6e9c7

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/EIDEProjectExplorer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ import {
110110
openocd_getConfigList,
111111
pyocd_getTargetList,
112112
generateDotnetProgramCmd,
113-
isGccFamilyToolchain
113+
isGccFamilyToolchain,
114+
cxxDemangle
114115
} from './utility';
115116
import { concatSystemEnvPath, DeleteDir, exeSuffix, kill, osType, DeleteAllChildren, userhome, getGlobalState } from './Platform';
116117
import { KeilARMOption, KeilC51Option, KeilParser, KeilRteDependence } from './KeilXmlParser';
@@ -1834,6 +1835,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
18341835
let elftool = '';
18351836
let elfcmds = [''];
18361837
let elfsort = false; // elftool has sorted ?
1838+
let cxxfilt: string | undefined; // c++filt tools
18371839

18381840
let staMatcher: RegExp | undefined;
18391841
let endMatcher: RegExp | undefined;
@@ -1887,6 +1889,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
18871889
case 'MTI_GCC':
18881890
elfpath = prj.getExecutablePath();
18891891
elftool = [toolchain.getToolchainDir().path, 'bin', `${toolchainPrefix}nm${exeSuffix()}`].join(File.sep);
1892+
cxxfilt = [toolchain.getToolchainDir().path, 'bin', `${toolchainPrefix}c++filt${exeSuffix()}`].join(File.sep);
18901893
elfcmds = sortType == 'size' ? ['-l', '-S', '--size-sort', elfpath] : ['-ln', '-S', elfpath];
18911894
elfsort = true;
18921895
symMatcher = /^(?<addr>[0-9a-f]+)\s+(?<size>[0-9a-f]+\s+)?(?<type>\w)\s+(?<name>[^\s]+)\s+(?<loca>.*)/i;
@@ -1914,6 +1917,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
19141917
// 20011c14 00000001 B __lock___libc_recursive_mutex
19151918
elfpath = prj.getExecutablePath();
19161919
elftool = [toolchain.getToolchainDir().path, 'bin', `llvm-nm${exeSuffix()}`].join(File.sep);
1920+
cxxfilt = [toolchain.getToolchainDir().path, 'bin', `llvm-cxxfilt${exeSuffix()}`].join(File.sep);
19171921
elfcmds = sortType == 'size' ? ['-l', '-S', '--size-sort', elfpath] : ['-ln', '-S', elfpath];
19181922
elfsort = true;
19191923
symMatcher = /^(?<addr>[0-9a-f]+)\s+(?<size>[0-9a-f]+\s+)?(?<type>\w)\s+(?<name>[^\s]+)\s+(?<loca>.*)/i;
@@ -2040,6 +2044,10 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
20402044
let name = m.groups['name']?.trim();
20412045
let loca = m.groups['loca']?.trim();
20422046

2047+
// C++ symbol name demangler
2048+
if (cxxfilt)
2049+
name = cxxDemangle(name, cxxfilt);
2050+
20432051
if (!addr || !name) {
20442052
continue;
20452053
}

src/utility.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ export const TIME_ONE_MINUTE = 60 * 1000;
4949
export const TIME_ONE_HOUR = 3600 * 1000;
5050
export const TIME_ONE_DAY = 24 * 3600 * 1000;
5151

52+
/**
53+
* It's a symbol demangler that can be used as a replacement for the GNU c++filt tool.
54+
* It takes a series of symbol names and prints their demangled form on the standard output stream.
55+
* If a name cannot be demangled, it is simply printed as is.
56+
*
57+
* example:
58+
* _ZN10__cxxabiv120__unexpected_handlerE -> __cxxabiv1::__unexpected_handler
59+
*/
60+
export function cxxDemangle(name: string, cxxfilt_path?: string): string {
61+
cxxfilt_path = cxxfilt_path || `arm-none-eabi-c++filt${platform.exeSuffix()}`;
62+
try {
63+
return child_process.execFileSync(cxxfilt_path, [name]).toString().trim();
64+
} catch (error) {
65+
return name;
66+
}
67+
}
68+
5269
export function parseCliArgs(cliStr: string): string[] {
5370

5471
let argsLi: string[] = [];

0 commit comments

Comments
 (0)