0%

Reduce the disk usage of VSCode

以下文件可以删除:

  • .vscode-server/data/User/workspaceStorage/*:几十GB.

  • .vscode-server:参考

  • .config: 可以针对每个目录找到相应的程序,比如 Chrome,然后有针对性地删除一些文件。参考这里

  • .cache: 和 .config 类似处理,参考这里

    .cache/vscode-cpptools: This cache folder stores cached precompiled headers or “ipch” files that the IntelliSense engine uses to improve performance. You can limit the size of the cache by changing the setting value of C_Cpp.intelliSenseCacheSize. 参考这里
    C_Cpp.intelliSenseCacheSize

Hot keys

  1. 跳转到对应大括号:Ctrl Shift \

Debug code in VSCode

Useful plugins

  • Remote - SSH: Windows 连接 Linux。前置条件:Windows 本身需要安装 ssh 命令行工具。
  • Perforce for VS Code: perforce 工具。
  • intent-rainbow: 用彩色显示缩进。
  • C/C++
  • Makefile Tools
  • Verilog Format
  • All in one
  • c/c++ definition generator
  • KoroFileHeader: 参考这里

Useful configurations

自动填充头文件,比如ifndef宏

配置文件:

  • launch.json
  • tasks.json: ref, ref

函数

glic Functions

backtrace
backtrace_symbols
backtrace_symbols_fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>

void print_trace() {
static const int SIZE = 10;

void* buffer[SIZE];
char** strings;
int size, i;

size = backtrace(buffer, SIZE);
strings = backtrace_symbols(buffer, size);
if (strings != NULL) {
printf("Obtained %d stack frames.\n", size);
for (i = 0; i < size; ++i)
printf("%s\n", strings[i]);
free(strings);
}
}

第三方库

breakpad: https://blog.csdn.net/weixin_45609638/article/details/125090204

https://juejin.cn/post/6899070041074073614

https://juejin.cn/post/7130820896213712927

内核编译

obj-m: 链接

make modules: 链接

编译内核模块

文档

Makefile:

obj-m += hello-1.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

make -C changes to a new directory where the new makefiles will be run.

M=$(PWD) defines a variable M which the child makefiles can use.

命令

  • insmod: 插入一个模块(.ko)到kernel中。
  • rmmod: 从内核中删除一个模块。
  • modprobe: 从内核中增删模块。modprobe/lib/modules/`uname -r`中搜索所有的模块和其他文件,除了/etc/modprobe.d目录中的可选配置文件(参见modprobe.d(5))。
  • lsmod: 显示当前加载的内核模块的状态(即对/proc/modules内容的格式化)。
  • modinfo: 从命令行指定的内核模块中提取信息,如果没有给出模块名称,那么会搜索/lib/modules/version目录,就像modprobe加载模块时一样。
  • depmod: 生成modules.dep和映射文件。
  • dmesg: 打印或控制内核ring buffer(存储kernel message)。

词汇表(Glossary)

  • BAR: base address register.
  • PCI configuration space.
  • sba: system bus address.

PCI

PCI configurtation space

PCI设备有一组被称为configuratin space的寄存器,并且PCI Express引入了Extended configuration space。configuration space寄存器被映射到memory locations。
驱动设备和诊断软件必须要有权限访问configuration space,操作系统通常使用APIs来授权访问设备configuration space。

PCI configuration space有两种类型的Header(64 bytes):

Header Type 0x0

Register Offset Bits 31-24 Bits 23-16 Bits 15-8 Bits 7-0
0x0 0x0 Device ID Vendor ID
0x1 0x4 Status Command
0x2 0x8 Class code Subclass Prog IF Revision ID
0x3 0xC BIST Header type Latency Timer Cache Line Size
0x4 0x10 Base address #0 (BAR0)
0x5 0x14 Base address #1 (BAR1)
0x6 0x18 Secondary Latency Timer Subordinate Bus Number Secondary Bus Number Primary Bus Number
0x7 0x1C Secondary Status I/O Limit I/O Base
0x8 0x20 Memory Limit Memory Base
0x9 0x24 Prefetchable Memory Limit Prefetchable Memory Base
0xA 0x28 Prefetchable Base Upper 32 Bits
0xB 0x2C Prefetchable Limit Upper 32 Bits
0xC 0x30 I/O Limit Upper 16 Bits I/O Base Upper 16 Bits
0xD 0x34 Reserved Capability Pointer
0xE 0x38 Expansion ROM base address
0xF 0x3C Bridge Control Interrupt PIN Interrupt Line

Header Type 0x1

Register Offset Bits 31-24 Bits 23-16 Bits 15-8 Bits 7-0
0x0 0x0 Device ID Vendor ID
0x1 0x4 Status Command
0x2 0x8 Class code Subclass Prog IF Revision ID
0x3 0xC BIST Header type Latency Timer Cache Line Size
0x4 0x10 Base address #0 (BAR0)
0x5 0x14 Base address #1 (BAR1)
0x6 0x18 Secondary Latency Timer Subordinate Bus Number Secondary Bus Number Primary Bus Number
0x7 0x1C Secondary Status I/O Limit I/O Base
0x8 0x20 Memory Limit Memory Base
0x9 0x24 Prefetchable Memory Limit Prefetchable Memory Base
0xA 0x28 Prefetchable Base Upper 32 Bits
0xB 0x2C Prefetchable Limit Upper 32 Bits
0xC 0x30 I/O Limit Upper 16 Bits I/O Base Upper 16 Bits
0xD 0x34 Reserved Capability Pointer
0xE 0x38 Expansion ROM base address
0xF 0x3C Bridge Control Interrupt PIN Interrupt Line
BAR0
Memory-mapped I/O (MMIO) registers
BAR1
Device memory windows.
BAR2/3
Complementary space of BAR1.
BAR5
I/O port.
BAR6
PCI ROM.

Commands

lspci

Interpreting the output of lspci

参考

简介

LDAP, Lightweight Directory Access Protocol.

参考

Bull Support

驱动

本文介绍驱动。

命令

  • lsmod - Show status of modules in the Linux kernel.

    lsmod is a trivial program which nicely formats the contents of the /proc/odules,
    showing what kernel modules are currently loaded.

  • dmesg - examine or control the kernel ring buffer.

    The kernel buffer is a data structure used for keeping the log messages of the kernel and the kernel modules.
    It’s a ring buffer with a fixed size. Once it’s full, new messages overwrite the oldest messages.
    During boot, the kernel saves the messages into the kernel buffer.

  • lsscsi - Uses information in sysfs (Linux kernel series 2.6 and later) to list SCSI devices (or hosts) currently attached to the system.

gitignore不生效

参考:链接

file mode 10064的含义

参考博客

环境变量

  • environ - 用户环境,一个全局变量。头文件 <unistd.h>。可以通过 man environ 查看手册。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #include <unistd.h>
    #include <iostream>
    using namespace std;

    int main() {
    cout << "program environment: " << endl;
    for (char** entry = environ; *entry; ++entry) {
    cout << *entry << endl;
    }
    }
  • getenv - 获取环境变量。头文件 <stdlib.h>

  • setenv - 设置环境变量。头文件 stdlib.h