2022年4月30日 星期六

Linux 清除系統日誌

cd /var/log

sudo su

> lastlog

> wtmp

> dpkg.log 

> kern.log

> syslog

exit

sudo systemctl restart syslog


註:指令中必須包含  >  符號


參考資料

https://askubuntu.com/questions/515146/very-large-log-files-what-should-i-do

2022年4月26日 星期二

GDB 基本操作

編譯 (要加入debug資訊)

gcc xxxxx.c -g --static


啟動

gdb -tui ./a.out


切換窗格

Ctrl + X , O 


執行一次

r
run


加入中斷點

b <行號>
b <標籤名>
break <行號>
break <標籤名>


移除中斷點

(gdb) b 25 
Breakpoint 5 at 0x7a4: file main.c, line 27.
(gdb) info break
Num     Type           Disp Enb Address            What
5       breakpoint     keep y   0x00000000000007a4 in main at main.c:27
(gdb) del 5
(gdb) info break
No breakpoints or watchpoints.


單步執行

s
step


執行下一行指令

n
next


顯示暫存器

info all-registers
info reg X0


顯示字元陣列

print str
print str[13]
x/13cb str


開啟內建說明

help







Ubuntu 20.04 安裝 GitHub CLI

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0

sudo apt-add-repository https://cli.github.com/packages

sudo apt update

sudo apt install gh

使用vscode來閱讀Linux內核原始程式碼

新增 .vscode/c_cpp_properties.json 檔案
內容如下:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/include",
                "${workspaceFolder}/include/linux",
                "${workspaceFolder}/arch/arm64/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4

或是

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/include/**",
                "${workspaceFolder}/include/linux/**",
                "${workspaceFolder}/arch/arm64/include/**",
                "${workspaceFolder}/arch/x86/include/**"
            ],
            "defines": [
                "__KERNEL__",
                "_GNU_SOURCE"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-clang-arm64"
        }
    ],
    "version": 4
}