# lldb的使用

​ gdb12版本,目前还不支持M1芯片的mac,就算源码编译也是没办法的,所以,该情况下,只能使用lldb。

  • 但是好像可以cgdb安装,https://formulae.brew.sh/formula/cgdb
    • 但是请注意,这样还是用不了cgdb,因为他后边调用的gdb,你没gdb,还是调试不了
    • cgdb:是gdb的一个扩展,打开后自动显示源码TUI,方便阅读源码,gdb虽然也可以,但是会经常花屏,需要自己手动刷新界面 , 缺点:使用print命令的时,无法显示中文字符,可能是乱码或不显示
    • CGDB是GDB的前端(可以这么理解)
➜  ~ brew install cgdb
==> Fetching cgdb
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/cgdb-0.8.0.arm64_monterey.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cgdb-0.8.0.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/cgdb/0.8.0: 8 files, 614.4KB
==> Running `brew cleanup cgdb`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> `brew cleanup` has not been run in the last 30 days, running now...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /Users/whoway/Library/Caches/Homebrew/libx11--1.8.2.arm64_monterey.bottle.tar.gz... (2.1MB)
Removing: /Users/whoway/Library/Caches/Homebrew/libxcb--1.15.arm64_monterey.bottle.1.tar.gz... (958.6KB)
Removing: /Users/whoway/Library/Caches/Homebrew/libxrender--0.9.10.arm64_monterey.bottle.tar.gz... (46.2KB)
Pruned 0 symbolic links and 11 directories from /opt/homebrew
➜  ~ cgdb -v
CGDB 0.8.0
Copyright 2002-2022 Bob Rossi and Mike Mueller.
CGDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for CGDB.
➜  cxxstl brew uninstall cgdb
Uninstalling /opt/homebrew/Cellar/cgdb/0.8.0... (8 files, 614.4KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 目录

[toc]

# 1.背景

​ 随着Xcode 5的发布,LLDB调试器已经取代了GDB,成为了Xcode工程中默认的调试器。它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能。

# 2.demo演示

//➜  remote-ssh git:(master) ✗ cat demo.cpp
#include<iostream>
using namespace std;

int main()
{
	int i=0;
	int sum=0;
	for(; i<9; ++i)
	{
		sum+=i;
	}
	printf("sum===%d\n",sum);
	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜  remote-ssh git:(master)ls
codes                  flang                  huawei                 whoway
demo.cpp               fortran_align_examples ssh-whoway.sh
➜  remote-ssh git:(master) ✗ clang++ demo.cpp -g
➜  remote-ssh git:(master)ls
⭐️a.out                  codes                  flang                  huawei                 whoway
⭐️a.out.dSYM             demo.cpp               fortran_align_examples ssh-whoway.sh
1
2
3
4
5
6
7
➜  remote-ssh git:(master) ✗ lldb a.out
(lldb) target create "a.out"
Current executable set to '/Users/whoway/work/gitee/remote-ssh/a.out' (arm64).
(lldb) b 6
Breakpoint 1: where = a.out`main + 16 at demo.cpp:6:6, address = 0x0000000100003f34
(lldb) r
Process 23264 launched: '/Users/whoway/work/gitee/remote-ssh/a.out' (arm64)
Process 23264 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f34 a.out`main at demo.cpp:6:6
   3
   4   	int main()
   5   	{
-> 6   		int i=0;
   7   		int sum=0;
   8   		for(; i<9; ++i)
   9   		{
Target 0: (a.out) stopped.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 参考资料