Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

[stable] Small follow-up to core.internal.execinfo refactoring #2903

Merged
merged 2 commits into from Jan 11, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 19 additions & 21 deletions src/core/internal/execinfo.d
Expand Up @@ -195,39 +195,37 @@ const(char)[] getMangledSymbolName(const(char)[] btBuf, out size_t symBeg,
}
else
{
import core.stdc.string : memchr;

char pChar = '+';
char mChar = '-';

static if (BacktraceFmt.GNU)
{
char bChar = '(';
char eChar = ')';
enum bChar = '(';
enum eChar = ')';
}
else static if (BacktraceFmt.BSD)
{
char bChar = '<';
char eChar = '>';
enum bChar = '<';
enum eChar = '>';
}
else static if (BacktraceFmt.Solaris)
{
char bChar = '\'';
char eChar = '+';
enum bChar = '\'';
enum eChar = '+';
}

if (auto bptr = cast(char*) memchr(btBuf.ptr, bChar, btBuf.length))
foreach (i; 0 .. btBuf.length)
{
++bptr; // skip bChar
if (auto eptr = cast(char*) memchr(bptr, eChar, (btBuf.ptr + btBuf.length) - bptr))
if (btBuf[i] == bChar)
{
if (auto pptr = cast(char*) memchr(bptr, pChar, eptr - bptr))
eptr = pptr;
if (auto mptr = cast(char*) memchr(bptr, mChar, eptr - bptr))
eptr = mptr;

symBeg = bptr - btBuf.ptr;
symEnd = eptr - btBuf.ptr;
foreach (j; i+1 .. btBuf.length)
{
const e = btBuf[j];
if (e == eChar || e == '+' || e == '-')
{
symBeg = i + 1;
symEnd = j;
break;
}
}
break;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/rt/backtrace/dwarf.d
Expand Up @@ -31,7 +31,7 @@ else
import rt.backtrace.elf;

import rt.util.container.array;
import core.stdc.string : strlen, memchr, memcpy;
import core.stdc.string : strlen, memcpy;

//debug = DwarfDebugMachine;
debug(DwarfDebugMachine) import core.stdc.stdio : printf;
Expand Down Expand Up @@ -348,10 +348,11 @@ bool runStateMachine(ref const(LineNumberProgram) lp, scope RunStateMachineCallb
return true;
}

const(char)[] getDemangledSymbol(const(char)[] btSymbol, ref char[1024] buffer)
const(char)[] getDemangledSymbol(const(char)[] btSymbol, return ref char[1024] buffer)
{
import core.demangle;
return demangle(getMangledSymbolName(btSymbol), buffer[]);
const mangledName = getMangledSymbolName(btSymbol);
return !mangledName.length ? buffer[0..0] : demangle(mangledName, buffer[]);
}

T read(T)(ref const(ubyte)[] buffer) @nogc nothrow
Expand Down