1.官网 http://lldb.llvm.org/ 源码:svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb
2.官方资源网址 http://releases.llvm.org/7.0.1/
3.CentOS7 编译安装版 安装流程(至少保证有60G的硬盘空间)
#a. 先安装依赖:
yum -y install gcc gcc-c++ swig python-devel libedit-devel automake autoconf libtool make wget
#安装cmake
tar -zxvf cmake-3.12.4.tar.gz
cd cmake-3.12.4
./configure
make
make install
#b.下载llvm源码(注意:.net core2.0.0只能使用lldb 3.6;.net core2.1以上必须是3.9.0,下同):
wget http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz
tar -xf llvm-7.0.1.src.tar.xz
mv llvm-7.0.1.src llvm
#c.进入llvm/tools目录并下载clang源码:
cd llvm/tools
wget http://releases.llvm.org/7.0.1/cfe-7.0.1.src.tar.xz
tar -xf cfe-7.0.1.src.tar.xz
mv cfe-7.0.1.src clang
#d.下载lldb源码:
wget http://releases.llvm.org/7.0.1/lldb-7.0.1.src.tar.xz
tar -xf lldb-7.0.1.src.tar.xz
mv lldb-7.0.1.src lldb
#e.下载compiler-rt的源码:
cd ../projects
wget http://releases.llvm.org/7.0.1/compiler-rt-7.0.1.src.tar.xz
tar -xf compiler-rt-7.0.1.src.tar.xz
mv compiler-rt-7.0.1.src compiler-rt
#f.下载libcxxabi的源码:
wget http://releases.llvm.org/7.0.1/libcxxabi-7.0.1.src.tar.xz
tar -xf libcxxabi-7.0.1.src.tar.xz
mv libcxxabi-7.0.1.src libcxxabi
#g.下载libcxx的源码:
wget http://releases.llvm.org/7.0.1/libcxx-7.0.1.src.tar.xz
tar -xf libcxx-7.0.1.src.tar.xz
mv libcxx-7.0.1.src libcxx
#h.回到llvm目录,配置编译选项:
cd ..
mkdir build
cd build
export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-2/root/usr/bin/g++
cmake .. #会编译2个小时
cmake --build .
cmake --build . --target install #这步会将编译的内容,考到/usr/local/bin 下面,由于有20多G ,可以直接将本目录加入环境变量,跳过拷贝 export PATH="$PATH:/data/zhangyanzeng/llvm/build/bin"
#下载过慢,可直接用下载好的 \\10.35.49.145\public\Software\lldb安装
4.使用流程
a. 使用netcore 自带的 createdump 创建dump文件
/usr/share/dotnet/shared/Microsoft.NETCore.App/2.1.6/createdump $1 -h -u -f ./coredump.$1 #$1为进程号
b.命令解释
COMMAND: createdump.
createdump [options] [dumpFileName]
-n - create minidump.
-h - create minidump with heap (default).
-t - create triage minidump.
-f - create full core dump (everything).
-d - enable diagnostic messages.
5.lldb 查看dump文件
lldb dotnet -c $1 -o "plugin load /usr/share/dotnet/shared/Microsoft.NETCore.App/2.1.6/libsosplugin.so" #$1 为dump文件名
6.常用命令
mt(methodtable) 方法表地址
dumpheap -stat #队内存使用统计,会按内存大小排序列出各个引用的数量和大小
dumpheap -type #查看指定内容的堆栈,类似grep
dumpheap -mt 查看mt地址
dumpobj 查看对象地址
sos DumpArray -start 0 -length 10 00007fd5febff9d8(对象地址)
sos DumpVC(查看值类型命令) 00007fd611151460(数组元素类型的mt地址) 00007fd5febff9e9(数组元素对象的地址)
gcroot (对象地址)查看引用
sos DumpArray -details(可以把每个对象的基本结构都打印出来)
COMMAND: dumpheap
-stat Restrict the output to the statistical type summary
-strings Restrict the output to a statistical string value summary
-short Limits output to just the address of each object. This allows you
to easily pipe output from the command to another debugger
command for automation.
-min Ignore objects less than the size given in bytes
-max Ignore objects larger than the size given in bytes
-live Only print live objects
-dead Only print dead objects (objects which will be collected in the next full GC)
-thinlock Report on any ThinLocks
-startAtLowerBound
-mt List only those objects with the MethodTable given
-type List only those objects whose type name is a substring match of the string provided.
start Begin listing from this address
end Stop listing at this address
7.命令手册
\\xx.xx.xx.145\public\Software\lldb安装\sosdocsunix.txt
8.参考文档
https://cloud.tencent.com/developer/article/1365654