Pintos的编译、跟踪及动态调试方法
来源:网络收集 点击: 时间:2025-02-17pintos/src/threads/build,下输入make 命令,然后再输入 make check 命令来测试,输入 make clean 来清空之前编译的结果的,那么这个目录下的Makefile应该是一个总的Makefile了,看看这个Makefile里面的内容,一点一点来解析吧!

# -*- makefile -*-
SRCDIR = ../..
#所有存放源文件的目录,也就是 pintos/src/
all: kernel.bin loader.bin
#这个all是标签,Makefile中的第一个目标会被作为其默认目标,由于伪目标的特性是,总是被执行的,
#所以其依赖的 kernel.bin loader.bin 就总是不如“all”这个目标新。所以,这2个二进制文件总会更新
include ../../Make.config
include ../Make.vars
include ../../tests/Make.tests

这个是Makefile的前面几行,all是个标签,输入命令 make all 的话就会运行 kernel.bin loader.bin 这2个程序
然后看到 include 了一个文件,去看看 pintos/src/Make.config
那么对3个这Makefile的文件的解析我都写在这里了:
首先是../../Make.config:
# -*- makefile -*-
SHELL = /bin/sh
#指定使用的shell
VPATH = $(SRCDIR)
#特殊变量 VPATH 指定文件的查找路径
# Binary utilities.
# If the host appears to be x86, use the normal tools.
# If its x86-64, use the compiler and linker in 32-bit mode.
# Otherwise assume cross-tools are installed as i386-elf-*.
X86 = i.86\|pentium.*\|\|nexgen\|viac3\|6x86\|athlon.*\|i86pc
# .*是模糊匹配,\|是管道的转义
X86_64 = x86_64

# Pintos doesnt compile/run properly using gcc 4.3+. Force 4.1 for now.
# 这句话的意思大概是 必须是4.1版本的gcc 才可以正常编译
CCPROG = /usr/class/cs140/x86_64/bin/i586-elf-gcc
ifeq ($(strip $(shell command -v $(CCPROG) 2 /dev/null)),)
#strip函数:功能:去掉string字串中开头和结尾的空字符。返回被去掉空格的字符串值。
#如果strip这个函数返回为空的话
#strip是函数名, 函数参数是 $(shell command -v $(CCPROG) 2 /dev/null) ,单独的一个变量
#参考博客: http://www.cnblogs.com/bethal/p/5430229.html
# 这个函数会新生成一个Shell程序来执行命令
CCPROG = gcc
endif

ifneq (0, $(shell expr `uname -m` : $(X86)))
CC = $(CCPROG)
LD = ld
OBJCOPY = objcopy
else
ifneq (0, $(shell expr `uname -m` : $(X86_64)))
CC = $(CCPROG) -m32
LD = ld -melf_i386
OBJCOPY = objcopy
else
CC = i386-elf-gcc
LD = i386-elf-ld
OBJCOPY = i386-elf-objcopy
endif
endif
ifeq ($(strip $(shell command -v $(CC) 2 /dev/null)),)
$(warning *** Compiler ($(CC)) not found. Did you set $$PATH properly? Please refer to the Getting Started section in the documentation for details. ***)
endif

# Compiler and assembler invocation.
DEFINES =
WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers
CFLAGS = -g -msoft-float -O
CPPFLAGS = -nostdinc -I$(SRCDIR) -I$(SRCDIR)/lib
ASFLAGS = -Wa,--gstabs
LDFLAGS =
DEPS = -MMD -MF $(@:.o=.d)
# Turn off -fstack-protector, which we dont support.
ifeq ($(strip $(shell echo | $(CC) -fno-stack-protector -E - /dev/null 21; echo $$?)),0)
CFLAGS += -fno-stack-protector
endif
# Turn off --build-id in the linker, which confuses the Pintos loader.
ifeq ($(strip $(shell $(LD) --help | grep -q build-id; echo $$?)),0)
LDFLAGS += -Wl,--build-id=none
endif

如有不明者,还请咨询专业人士。
版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_1240473.html