目录
终端快键键
control + E : 定位到尾部
control + W : 向前清除一个单词
man命令
man命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。
比如查看 git 指令,在终端输入
man git
搜索git相关指令说明
#比如查找 push 的说明
/-push
/ : 开始查找
n : 查找下一个
N : 查找上一个
q : 退出
objdump命令
通过man命令查看objdump的说明
LLVM’s object file dumper
一. 查看 objdump 的命令帮助
#通过man命令的方式查看命令说明
/--macho
-m, --macho
Use Mach-O specific object file parser. Commands and other options may behave differently when used with --macho.
#通过help命令的方式查看说明
objdump --help | grep -- "--macho"
-m - Alias for --macho
--macho - Use MachO specific object file parser
二. 查看Mach header
objdump --macho --private-header MachOAndSymbol
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 X86_64 ALL 0x00 EXECUTE 20 1960 NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK PIE
三. 查看代码段
objdump --macho -d MachOAndSymbol
MachOAndSymbol:
(__TEXT,__text) section
_main:
100003ec0: 55 pushq %rbp
100003ec1: 48 89 e5 movq %rsp, %rbp
...
_weak_import_function:
100003f00: 55 pushq %rbp
100003f01: 48 89 e5 movq %rsp, %rbp
...
_weak_function:
100003f20: 55 pushq %rbp
100003f21: 48 89 e5 movq %rsp, %rbp
...
_weak_hidden_function:
100003f40: 55 pushq %rbp
100003f41: 48 89 e5 movq %rsp, %rbp
四. 查看符号表
objdump --macho -syms MachOAndSymbol2
MachOAndSymbol2:
SYMBOL TABLE:
0000000100008008 l O __DATA,__data __dyld_private
0000000100008010 l O __DATA,__data _global_init_value
0000000100008014 l O __DATA,__data _static_init_value
0000000100008018 l O __DATA,__bss _static_uninit_value
0000000100008028 l O __DATA,__common _default_x
0000000100000000 g F __TEXT,__text __mh_execute_header
0000000100008020 g O __DATA,__common _global_uninit_value
0000000100003f50 g F __TEXT,__text _main
0000000000000000 *UND* _NSLog
0000000000000000 *UND* ___CFConstantStringClassReference
0000000000000000 *UND* dyld_stub_binder
五. 查看导出符号
objdump --macho --exports-trie MachOAndSymbol3
MachOAndSymbol3:
Exports trie:
0x100000000 __mh_execute_header
0x100003F50 _main
0x100008014 _lxy_global_value
0x100008020 _global_uninit_value
六. 查看间接符号表
objdump --macho --indirect-symbols MachOAndSymbol3
MachOAndSymbol3:
Indirect symbols for (__TEXT,__stubs) 1 entries
address index name
0x0000000100003f90 9 _NSLog
Indirect symbols for (__DATA_CONST,__got) 1 entries
address index name
0x0000000100004000 11 dyld_stub_binder
Indirect symbols for (__DATA,__la_symbol_ptr) 1 entries
address index name
0x0000000100008000 9 _NSLog
七. 查看重定位符号表
#通过查看重定位符号表,就可以知道当前.o文件调用了哪些api.
objdump --macho -reloc xx.o文件
clang命令
一 编译test.m to test.o
echo "-------------编译test.m to test.o------------------"
clang -x objective-c \
-target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
-I ./StaticLibrary \
-c test.m -o test.o
二 编译TestExample.m to TestExample.o
echo "-------------进入到StaticLibrary目录------------------"
pushd ./StaticLibrary
echo "-------------编译TestExample.m to TestExample.o------------------"
clang -x objective-c \
-target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
-c TestExample.m -o TestExample.o
ar -q libTestExample.a TestExample.o
echo "-------------退出StaticLibrary目录------------------"
popd
三 test.o链接libTestExample.a to test EXEC
echo "-------------test.o链接libTestExample.a to test EXEC------------------"
clang -target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
-L./StaticLibrary \
-lTestExample \
test.o -o test
四 test.o链接TestExample.framework生成test可执行文件
clang -target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-F./Frameworks \
-framework TestExample \
test.o -o test
五 参数说明
设置选择的语言
-x <language>
Treat subsequent input files as having type language.
设置架构
--target=<value> Generate code for the given target
使用arc管理
-fobjc-arc Synthesize retain and release calls for Objective-C pointers
设置系统库的路径,比如我们用到了Foundation库
-isysroot <dir> Set the system root directory (usually /)
搜索头文件的路径
-I<directory>
Add the specified directory to the search path for include files.
生成目标文件
-c Run all of the above, plus the assembler, generating a target ".o" object file.
.a或.dylib的搜索路径
-L <dir> Add directory to library search path
指定链接的库文件的名称
-l<library_name> 指定链接的库文件名称(.a/.dylib库文件)
指定framework路径
-F<directory> 在指定目录寻找framework framework search path
指定framework名称
-framework <framework_name> 指定链接的framework名称 other link flags -framework AFNetworking
nm命令
一. 命令介绍
nm --help
OVERVIEW: llvm symbol table dumper
USAGE: nm [options] <input files>
OPTIONS:
Generic Options:
--help - Display available options (--help-hidden for more)
--help-list - Display list of available options (--help-list-hidden for more)
--version - Display the version of this program
llvm-nm Options:
-B - Alias for --format=bsd
-P - Alias for --format=posix
--add-dyldinfo - Add symbols from the dyldinfo not already in the symbol table, Mach-O only
...
二. 查看版本
nm --version
Apple LLVM version 12.0.5 (clang-1205.0.22.11)
Optimized build.
Default target: x86_64-apple-darwin20.5.0
Host CPU: broadwell
三. 查看符号表
# -p : 不排序
# -a : 显示所有符号,包括调试符号
nm -pa machoinfo
0000000100001020 t _read_magic
0000000100001080 t _is_magic_64
00000001000010b0 t _should_swap_bytes
0000000100001100 t _is_fat
0000000100001130 t _dump_fat_header
...
四. 查看符号表(详细)
nm -m machoinfo
swiftc命令
一. 命令介绍
swiftc --help
OVERVIEW: Swift compiler
USAGE: swiftc
MODES:
-dump-ast Parse and type-check input file(s) and dump AST(s)
-dump-parse Parse input file(s) and dump AST(s)
-dump-pcm Dump debugging information about a precompiled Clang module
...
二. 命令查看
swift --help | grep -- "-D"
-D <value> Marks a conditional compilation flag as true
ar命令
创建和维护静态库
create and maintain library archives
-r : 添加or替换文件
-c : 不输出任何信息
-t : 列出包含的目标文件
-q : (快速)将指定的文件追加到归档文件。如果存档不存在,则创建一个新的存档文件。比-r选项更快,当创建一个一个的大存档,因为没有检查文件是否已经存在于存档中。
行者常至,为者常成!