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

Commit c66ae59

Browse files
authored
Merge pull request #2903 from kinke/execinfo
[stable] Small follow-up to core.internal.execinfo refactoring merged-on-behalf-of: Petar Kirov <[email protected]>
2 parents d62a454 + 52b869a commit c66ae59

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/core/internal/execinfo.d

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,39 +195,37 @@ const(char)[] getMangledSymbolName(const(char)[] btBuf, out size_t symBeg,
195195
}
196196
else
197197
{
198-
import core.stdc.string : memchr;
199-
200-
char pChar = '+';
201-
char mChar = '-';
202-
203198
static if (BacktraceFmt.GNU)
204199
{
205-
char bChar = '(';
206-
char eChar = ')';
200+
enum bChar = '(';
201+
enum eChar = ')';
207202
}
208203
else static if (BacktraceFmt.BSD)
209204
{
210-
char bChar = '<';
211-
char eChar = '>';
205+
enum bChar = '<';
206+
enum eChar = '>';
212207
}
213208
else static if (BacktraceFmt.Solaris)
214209
{
215-
char bChar = '\'';
216-
char eChar = '+';
210+
enum bChar = '\'';
211+
enum eChar = '+';
217212
}
218213

219-
if (auto bptr = cast(char*) memchr(btBuf.ptr, bChar, btBuf.length))
214+
foreach (i; 0 .. btBuf.length)
220215
{
221-
++bptr; // skip bChar
222-
if (auto eptr = cast(char*) memchr(bptr, eChar, (btBuf.ptr + btBuf.length) - bptr))
216+
if (btBuf[i] == bChar)
223217
{
224-
if (auto pptr = cast(char*) memchr(bptr, pChar, eptr - bptr))
225-
eptr = pptr;
226-
if (auto mptr = cast(char*) memchr(bptr, mChar, eptr - bptr))
227-
eptr = mptr;
228-
229-
symBeg = bptr - btBuf.ptr;
230-
symEnd = eptr - btBuf.ptr;
218+
foreach (j; i+1 .. btBuf.length)
219+
{
220+
const e = btBuf[j];
221+
if (e == eChar || e == '+' || e == '-')
222+
{
223+
symBeg = i + 1;
224+
symEnd = j;
225+
break;
226+
}
227+
}
228+
break;
231229
}
232230
}
233231
}

src/rt/backtrace/dwarf.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else
3131
import rt.backtrace.elf;
3232

3333
import rt.util.container.array;
34-
import core.stdc.string : strlen, memchr, memcpy;
34+
import core.stdc.string : strlen, memcpy;
3535

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

351-
const(char)[] getDemangledSymbol(const(char)[] btSymbol, ref char[1024] buffer)
351+
const(char)[] getDemangledSymbol(const(char)[] btSymbol, return ref char[1024] buffer)
352352
{
353353
import core.demangle;
354-
return demangle(getMangledSymbolName(btSymbol), buffer[]);
354+
const mangledName = getMangledSymbolName(btSymbol);
355+
return !mangledName.length ? buffer[0..0] : demangle(mangledName, buffer[]);
355356
}
356357

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

0 commit comments

Comments
 (0)