[ADD] 新增 段错误崩溃 测试程序

This commit is contained in:
gaoyang3513
2024-10-10 15:09:50 +08:00
parent 7455f611b8
commit 9bc4c3f029
3 changed files with 84 additions and 1 deletions

3
.gitignore vendored
View File

@ -2,3 +2,6 @@
*.o
a.out
# Directories
output/

73
02-segfault/Makefile Normal file
View File

@ -0,0 +1,73 @@
#*******************************************************************************
# xxx Co., Ltd. All Right Reserved.
# Author : yegaoyang@hikvision.com.cn
# Version : V1.0.0 202x.xx.xx
# Description :
# Note :
#*******************************************************************************
#*******************************************************************************
# Target name
#*******************************************************************************
TARGET_NAME = test_segfault
#*******************************************************************************
# Source and oject files
#*******************************************************************************
OBJS := segfault.o
#*******************************************************************************
# Path information
#*******************************************************************************
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
# Subdirectory
# Output
OUTPUT_DIR := $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/__install
#$(info Output directoty : $(OUTPUT_DIR))
#$(info Install directoty: $(INSTALL_DIR))
#*******************************************************************************
# Compile configure
#*******************************************************************************
# Toolchain
CROSS_COMPILE ?= /home/gaoyang3513/Source/06-SG20x/02-Projects/SDK_SG200x_DuoS/host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
# Falgs
CFLAGS := -Wall -O2 -DUSER_API -g
LDFLAGS := -static
ARFLAGS :=
#*******************************************************************************
# Variables
#*******************************************************************************
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
#*******************************************************************************
# Targets
#*******************************************************************************
# Specify suffix names and pseudo-targets
.SUFFIXES: .c,.o
.PHONY: all clean checkenv $(TARGET_NAME)
all: checkenv $(TARGET_NAME)
clean:
@rm -rf $(OBJS) $(TARGET_NAME)
checkenv:
@mkdir -p $(OUTPUT_DIR)
$(TARGET_NAME):$(OBJS)
@$(CC) -o $(OUTPUT_DIR)/$@ $^ $(LDFLAGS)
@chmod +x $(OUTPUT_DIR)/$@
%.o:%.c
@$(CC) -o $@ -c $< $(CFLAGS)

7
02-segfault/segfault.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main() {
int *ptr = NULL; // 初始化一个指向NULL的指针
*ptr = 1; // 尝试写入NULL指针引用的地址这将导致段错误
return 0;
}