在当前目录, 运行多个含有main函数的源文件
cmake_minimum_required(VERSION 3.21)# 获取目录名get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)# 目录名中的空格替换成下划线string(REPLACE " " "_" ProjectId ${ProjectId})# project(${ProjectId} CXX)project(${ProjectId} C)set(CMAKE_CXX_STANDARD 23)# 将目录下的.c存入files# file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c")foreach(file ${files})get_filename_component(name ${file} NAME)add_executable(${name} ${file})endforeach()
下断点观察变量的变化

- GDB

- LLDB

- Watchs

- 执行下一次断点

- Evaluate Expression
反汇编/disassemble
#include <stdio.h>int main() {for(int i = 0; i < 5; ++i){printf("i=%d\n", i);}return 0;}

(lldb) disassemble02_DEBUG.c.exe`main(...):0x1f14b0 <+0>: pushl %ebp0x1f14b1 <+1>: movl %esp, %ebp0x1f14b3 <+3>: pushl %ecx0x1f14b4 <+4>: movl $0xcccccccc, -0x4(%ebp) ; imm = 0xCCCCCCCC0x1f14bb <+11>: movl $0x0, -0x4(%ebp)0x1f14c2 <+18>: jmp 0x1f14cd ; <+29> at 02_DEBUG.c:40x1f14c4 <+20>: movl -0x4(%ebp), %eax0x1f14c7 <+23>: addl $0x1, %eax0x1f14ca <+26>: movl %eax, -0x4(%ebp)0x1f14cd <+29>: cmpl $0x5, -0x4(%ebp)0x1f14d1 <+33>: jge 0x1f14e6 ; <+54> at 02_DEBUG.c:9-> 0x1f14d3 <+35>: movl -0x4(%ebp), %ecx0x1f14d6 <+38>: pushl %ecx0x1f14d7 <+39>: pushl $0x1fa000 ; imm = 0x1FA0000x1f14dc <+44>: calll 0x1f107d ; _printf0x1f14e1 <+49>: addl $0x8, %esp0x1f14e4 <+52>: jmp 0x1f14c4 ; <+20> at 02_DEBUG.c:40x1f14e6 <+54>: xorl %eax, %eax0x1f14e8 <+56>: addl $0x4, %esp0x1f14eb <+59>: cmpl %esp, %ebp0x1f14ed <+61>: calll 0x1f1159 ; __RTC_CheckEsp0x1f14f2 <+66>: movl %ebp, %esp0x1f14f4 <+68>: popl %ebp0x1f14f5 <+69>: retl
- 设置汇编指令格式:
settings set target.x86-disassembly-flavor- 常见Intel, AT&T


(lldb) settings set target.x86-disassembly-flavor intel(lldb) disassemble02_DEBUG.c.exe`main(...):0x1f14b0 <+0>: push ebp0x1f14b1 <+1>: mov ebp, esp0x1f14b3 <+3>: push ecx0x1f14b4 <+4>: mov dword ptr [ebp - 0x4], 0xcccccccc0x1f14bb <+11>: mov dword ptr [ebp - 0x4], 0x00x1f14c2 <+18>: jmp 0x1f14cd ; <+29> at 02_DEBUG.c:40x1f14c4 <+20>: mov eax, dword ptr [ebp - 0x4]0x1f14c7 <+23>: add eax, 0x10x1f14ca <+26>: mov dword ptr [ebp - 0x4], eax0x1f14cd <+29>: cmp dword ptr [ebp - 0x4], 0x50x1f14d1 <+33>: jge 0x1f14e6 ; <+54> at 02_DEBUG.c:9-> 0x1f14d3 <+35>: mov ecx, dword ptr [ebp - 0x4]0x1f14d6 <+38>: push ecx0x1f14d7 <+39>: push 0x1fa0000x1f14dc <+44>: call 0x1f107d ; _printf0x1f14e1 <+49>: add esp, 0x80x1f14e4 <+52>: jmp 0x1f14c4 ; <+20> at 02_DEBUG.c:40x1f14e6 <+54>: xor eax, eax0x1f14e8 <+56>: add esp, 0x40x1f14eb <+59>: cmp ebp, esp0x1f14ed <+61>: call 0x1f1159 ; __RTC_CheckEsp0x1f14f2 <+66>: mov esp, ebp0x1f14f4 <+68>: pop ebp0x1f14f5 <+69>: ret
(lldb) settings set target.x86-disassembly-flavor att(lldb) disassemble02_DEBUG.c.exe`main(...):0x1f14b0 <+0>: pushl %ebp0x1f14b1 <+1>: movl %esp, %ebp0x1f14b3 <+3>: pushl %ecx0x1f14b4 <+4>: movl $0xcccccccc, -0x4(%ebp) ; imm = 0xCCCCCCCC0x1f14bb <+11>: movl $0x0, -0x4(%ebp)0x1f14c2 <+18>: jmp 0x1f14cd ; <+29> at 02_DEBUG.c:40x1f14c4 <+20>: movl -0x4(%ebp), %eax0x1f14c7 <+23>: addl $0x1, %eax0x1f14ca <+26>: movl %eax, -0x4(%ebp)0x1f14cd <+29>: cmpl $0x5, -0x4(%ebp)0x1f14d1 <+33>: jge 0x1f14e6 ; <+54> at 02_DEBUG.c:9-> 0x1f14d3 <+35>: movl -0x4(%ebp), %ecx0x1f14d6 <+38>: pushl %ecx0x1f14d7 <+39>: pushl $0x1fa000 ; imm = 0x1FA0000x1f14dc <+44>: calll 0x1f107d ; _printf0x1f14e1 <+49>: addl $0x8, %esp0x1f14e4 <+52>: jmp 0x1f14c4 ; <+20> at 02_DEBUG.c:40x1f14e6 <+54>: xorl %eax, %eax0x1f14e8 <+56>: addl $0x4, %esp0x1f14eb <+59>: cmpl %esp, %ebp0x1f14ed <+61>: calll 0x1f1159 ; __RTC_CheckEsp0x1f14f2 <+66>: movl %ebp, %esp0x1f14f4 <+68>: popl %ebp0x1f14f5 <+69>: retl
- 将语句复制到
.lldbint,设置汇编显示的默认格式
Memory View

&main

&i


小端序: 低地址位在最左侧


