ubuntu 上的编译错误及解决方法
l~/repo/tool/pcie_debug$ make
gcc -Wall -lreadline -lcurses pci_debug.c -o pci_debug
pci_debug.c:32:10: fatal error: readline/readline.h: 没有那个文件或目录
#include <readline/readline.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<内置>: recipe for target 'pci_debug' failed
make: *** [pci_debug] Error 1
原因是缺少依赖库:sudo apt-get install libreadline-dev
~/repo/tool/pcie_debug$ make
gcc -Wall -lreadline -lcurses pci_debug.c -o pci_debug
/usr/bin/ld: 找不到 -lcurses
collect2: error: ld returned 1 exit status
<内置>: recipe for target 'pci_debug' failed
make: *** [pci_debug] Error 1
sudo apt-get install libncurses5-dev
gcc -Wall -lreadline -lcurses pci_debug.c -o pci_debug
/tmp/ccwU9wyj.o:在函数‘parse_command’中:
pci_debug.c:(.text+0x65b):对‘readline’未定义的引用
pci_debug.c:(.text+0x6af):对‘add_history’未定义的引用
collect2: error: ld returned 1 exit status
<内置>: recipe for target 'pci_debug' failed
make: *** [pci_debug] Error 1
gcc pci_debug.c -o pci_debug -lreadline -lcurses
./pci_debug
Usage: pci_debug -s <device>
-h Help (this message)
-s <device> Slot/device (as per lspci)
-b <BAR> Base address region (BAR) to access, eg. 0 for BAR0
可以看出pci_debug工具是导出BAR空间的寄存器
sudo ./pci_debug -s 00:14.0 -b 0
PCI debug
---------
- accessing BAR0
- region size is 65536-bytes
- offset into region is 0-bytes
? Help
d[width] addr len Display memory starting from addr
[width]
8 - 8-bit access
16 - 16-bit access
32 - 32-bit access (default)
c[width] addr val Change memory at addr to val
e Print the endian access mode
e[mode] Change the endian access mode
[mode]
b - big-endian (default)
l - little-endian
f[width] addr val len inc Fill memory
addr - start address
val - start value
len - length (in bytes)
inc - increment (defaults to 1)
q Quit
Notes:
1. addr, len, and val are interpreted as hex values
addresses are always byte based
PCI> d 0x0 20
00000000: 01000080 12000840 14200054 0200000A
00000010: 200077C1 00003000 00002000 00000000
PCI> d 0x0 0x20
00000000: 01000080 12000840 14200054 0200000A
00000010: 200077C1 00003000 00002000 00000000
PCI> d 0x0 0x30
00000000: 01000080 12000840 14200054 0200000A
00000010: 200077C1 00003000 00002000 00000000
00000020: 00000000 00000000 00000000 00000000
PCI>