/
lldbdplugin.d
72 lines (58 loc) · 1.58 KB
/
lldbdplugin.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/+
Usage
build lldb with https://reviews.llvm.org/D44321 (formerly https://github.com/llvm-mirror/lldb/pull/3)
```
## build lldb
git clone https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone https://github.com/llvm-mirror/lldb
## also, patch in https://github.com/llvm-mirror/lldb/pull/3
git clone https://github.com/llvm-mirror/clang
cd ..
mkdir build
cd build
cmake .. -G Ninja
ninja all
## build lldbdplugin
#dtools_D=path to dtools repo
#NOTE: -link-defaultlib-shared=false was added in ldc 1.8.0
ldmd2 -of=liblldbdplugin.dylib -shared -link-defaultlib-shared=false -g -I$dtools_D $dtools_D/dtools/modified/demangle.d $dtools_D/dtools/lldbdplugin.d
```
## run
```
## add this to .lldbinit:
settings set plugin.language.D.pluginfile "path_to/liblldbdplugin.dylib"
$path_to/lldb -- $some_program
b full.qualified.name
#understands D fully qualified names (note: no templates yet it seems)
r
bt
# shows backtrace with demangled D symbols
addresses: https://issues.dlang.org/show_bug.cgi?id=8172
```
+/
module dtools.lldbdplugin;
import core.stdc.stdio;
import core.runtime;
import core.thread;
import core.memory;
import std.concurrency;
extern(C) {
bool d_initialize(){
return Runtime.initialize;
}
bool d_terminate(){
return Runtime.terminate;
}
char* lldbd_demangle(size_t length, const(char)* mangled){
import dtools.alloc;
auto mangled2=mangled[0..length];
// can configure
enum L_max=size_t.max;
if(length>=L_max)
return mangled2.malloc_cpy(true).ptr;
import dtools.modified.demangle:demangle;
auto ret = demangle(mangled2);
return ret.malloc_cpy(true).ptr;
}
}