Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/libmoex/base/demangle/Demangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Created by everettjf
// Copyright © 2017 everettjf. All rights reserved.
//
// C++ (Itanium) symbol demangling via the C++ runtime. No extra dependency:
// abi::__cxa_demangle ships with both libstdc++ and libc++.
#ifndef MOEX_DEMANGLE_H
#define MOEX_DEMANGLE_H

#include <string>
#include <cstdlib>
#include <cxxabi.h>

namespace moex { namespace demangle {

// Returns the demangled C++ name, or an empty string if the input is not an
// Itanium-mangled C++ symbol. Mach-O symbols carry an extra leading underscore
// (e.g. `__Z3fooi`), which is stripped before demangling.
inline std::string DemangleCxx(const std::string &name) {
const char *m = name.c_str();
if (name.size() > 1 && name[0] == '_') {
m = name.c_str() + 1;
}
if (!(m[0] == '_' && m[1] == 'Z')) {
return std::string();
}
int status = 0;
char *demangled = abi::__cxa_demangle(m, nullptr, nullptr, &status);
std::string out;
if (status == 0 && demangled != nullptr) {
out = demangled;
}
std::free(demangled);
return out;
}

}} // namespace moex::demangle

#endif // MOEX_DEMANGLE_H
9 changes: 8 additions & 1 deletion src/libmoex/viewnode/views/SymbolTableViewNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "SymbolTableViewNode.h"
#include "libmoex/base/demangle/Demangle.h"

MOEX_NAMESPACE_BEGIN

Expand All @@ -16,7 +17,13 @@ void SymbolTableViewNode::InitViewDatas() {
return;

for(auto & item : seg->nlists_ref()){
t->AddRow(item->n_strx(),"String Table Index",seg->GetStringByStrX(item->n_strx()));
const std::string name = seg->GetStringByStrX(item->n_strx());
t->AddRow(item->n_strx(),"String Table Index",name);

const std::string demangled = moex::demangle::DemangleCxx(name);
if(!demangled.empty()){
t->AddRow(item->n_strx(),"Demangled",demangled);
}

t->AddRow(item->n_type(),"Type",AsShortHexString((uint32_t )item->n_type()));
// foreach
Expand Down
Loading