搭建环境

使用 docker 准备 xv6 环境

wtakuo/xv6-env

使用 docker 方式,参见:https://github.com/wtakuo/xv6-env

  1. cd {path-to-xv6-riscv}
  2. docker run -it --rm -v $(pwd):/home/xv6/xv6-riscv wtakuo/xv6-env

jjolly/xv6 (推荐)

  1. cd {path-to-xv6-riscv}
  2. docker run --name=xv6 -h xv6 -ti -v $(pwd):/xv6-riscv jjolly/xv6

再次运行 docker:

  1. docker run -it 900266e4df99 /bin/bash
  2. # or
  3. docker run -it --rm -v $(pwd):/xv6-riscv jjolly/xv6

运行 xv6

  1. cd /xv6-riscv
  2. make qemu

详见:https://www.youtube.com/watch?v=juA01R9PzTI

Debug

基本使用

  1. make CPUS=1 qemu-gdb

image.png
再打开一个 terminal

  1. gdb-multiarch -q kernel/kernel

image.png
输入:layout n
image.png

问题

  1. docker 环境下,gdb no Source Available

gdb 输入 c运行后,能看到 source。

使用 vscode Remote Containers 来连接 docker 环境

前提条件

  1. 安装 Remote-Containers 插件。

image.png
在原镜像基础上又安装了一些软件,比如:vim, bear, clangd(Extension) 等。
保存成新的镜像:

  1. docker commit {container_id} bermaker/xv6:latest

基本使用

  1. 生成 compile_commands.json

    1. bear make qemu
    1. [
    2. {
    3. "arguments": [
    4. "riscv64-linux-gnu-gcc",
    5. "-c",
    6. "-Wall",
    7. "-Werror",
    8. "-O",
    9. "-fno-omit-frame-pointer",
    10. "-ggdb",
    11. "-mcmodel=medany",
    12. "-ffreestanding",
    13. "-fno-common",
    14. "-nostdlib",
    15. "-mno-relax",
    16. "-I.",
    17. "-fno-stack-protector",
    18. "-fno-pie",
    19. "-no-pie",
    20. "-o",
    21. "kernel/kalloc.o",
    22. "kernel/kalloc.c"
    23. ],
    24. "directory": "/xv6-riscv",
    25. "file": "kernel/kalloc.c"
    26. },
    27. {
    28. "arguments": [
    29. "riscv64-linux-gnu-gcc",
    30. "-c",
    31. "-Wall",
    32. "-Werror",
    33. "-O",
    34. "-fno-omit-frame-pointer",
    35. "-ggdb",
    36. "-mcmodel=medany",
    37. "-ffreestanding",
    38. "-fno-common",
    39. "-nostdlib",
    40. "-mno-relax",
    41. "-I.",
    42. "-fno-stack-protector",
    43. "-fno-pie",
    44. "-no-pie",
    45. "-o",
    46. "kernel/fs.o",
    47. "kernel/fs.c"
    48. ],
    49. "directory": "/xv6-riscv",
    50. "file": "kernel/fs.c"
    51. },
    52. {
    53. "arguments": [
    54. "riscv64-linux-gnu-gcc",
    55. "-c",
    56. "-Wall",
    57. "-Werror",
    58. "-O",
    59. "-fno-omit-frame-pointer",
    60. "-ggdb",
    61. "-mcmodel=medany",
    62. "-ffreestanding",
    63. "-fno-common",
    64. "-nostdlib",
    65. "-mno-relax",
    66. "-I.",
    67. "-fno-stack-protector",
    68. "-fno-pie",
    69. "-no-pie",
    70. "-o",
    71. "user/umalloc.o",
    72. "user/umalloc.c"
    73. ],
    74. "directory": "/xv6-riscv",
    75. "file": "user/umalloc.c"
    76. },
    77. {
    78. "arguments": [
    79. "riscv64-linux-gnu-gcc",
    80. "-c",
    81. "-Wall",
    82. "-Werror",
    83. "-O",
    84. "-fno-omit-frame-pointer",
    85. "-ggdb",
    86. "-mcmodel=medany",
    87. "-ffreestanding",
    88. "-fno-common",
    89. "-nostdlib",
    90. "-mno-relax",
    91. "-I.",
    92. "-fno-stack-protector",
    93. "-fno-pie",
    94. "-no-pie",
    95. "-o",
    96. "user/rm.o",
    97. "user/rm.c"
    98. ],
    99. "directory": "/xv6-riscv",
    100. "file": "user/rm.c"
    101. },
    102. {
    103. "arguments": [
    104. "riscv64-linux-gnu-gcc",
    105. "-c",
    106. "-Wall",
    107. "-Werror",
    108. "-O",
    109. "-fno-omit-frame-pointer",
    110. "-ggdb",
    111. "-mcmodel=medany",
    112. "-ffreestanding",
    113. "-fno-common",
    114. "-nostdlib",
    115. "-mno-relax",
    116. "-I.",
    117. "-fno-stack-protector",
    118. "-fno-pie",
    119. "-no-pie",
    120. "-o",
    121. "kernel/main.o",
    122. "kernel/main.c"
    123. ],
    124. "directory": "/xv6-riscv",
    125. "file": "kernel/main.c"
    126. },
    127. {
    128. "arguments": [
    129. "riscv64-linux-gnu-gcc",
    130. "-c",
    131. "-Wall",
    132. "-Werror",
    133. "-O",
    134. "-fno-omit-frame-pointer",
    135. "-ggdb",
    136. "-mcmodel=medany",
    137. "-ffreestanding",
    138. "-fno-common",
    139. "-nostdlib",
    140. "-mno-relax",
    141. "-I.",
    142. "-fno-stack-protector",
    143. "-fno-pie",
    144. "-no-pie",
    145. "-o",
    146. "kernel/proc.o",
    147. "kernel/proc.c"
    148. ],
    149. "directory": "/xv6-riscv",
    150. "file": "kernel/proc.c"
    151. },
    152. {
    153. "arguments": [
    154. "riscv64-linux-gnu-gcc",
    155. "-c",
    156. "-Wall",
    157. "-Werror",
    158. "-O",
    159. "-fno-omit-frame-pointer",
    160. "-ggdb",
    161. "-mcmodel=medany",
    162. "-ffreestanding",
    163. "-fno-common",
    164. "-nostdlib",
    165. "-mno-relax",
    166. "-I.",
    167. "-fno-stack-protector",
    168. "-fno-pie",
    169. "-no-pie",
    170. "-march=rv64g",
    171. "-nostdinc",
    172. "-I.",
    173. "-Ikernel",
    174. "-o",
    175. "user/initcode.o",
    176. "user/initcode.S"
    177. ],
    178. "directory": "/xv6-riscv",
    179. "file": "user/initcode.S"
    180. },
    181. {
    182. "arguments": [
    183. "riscv64-linux-gnu-gcc",
    184. "-c",
    185. "-Wall",
    186. "-Werror",
    187. "-O",
    188. "-fno-omit-frame-pointer",
    189. "-ggdb",
    190. "-mcmodel=medany",
    191. "-ffreestanding",
    192. "-fno-common",
    193. "-nostdlib",
    194. "-mno-relax",
    195. "-I.",
    196. "-fno-stack-protector",
    197. "-fno-pie",
    198. "-no-pie",
    199. "-o",
    200. "user/mkdir.o",
    201. "user/mkdir.c"
    202. ],
    203. "directory": "/xv6-riscv",
    204. "file": "user/mkdir.c"
    205. },
    206. {
    207. "arguments": [
    208. "riscv64-linux-gnu-gcc",
    209. "-c",
    210. "-Wall",
    211. "-Werror",
    212. "-O",
    213. "-fno-omit-frame-pointer",
    214. "-ggdb",
    215. "-mcmodel=medany",
    216. "-ffreestanding",
    217. "-fno-common",
    218. "-nostdlib",
    219. "-mno-relax",
    220. "-I.",
    221. "-fno-stack-protector",
    222. "-fno-pie",
    223. "-no-pie",
    224. "-o",
    225. "kernel/sysproc.o",
    226. "kernel/sysproc.c"
    227. ],
    228. "directory": "/xv6-riscv",
    229. "file": "kernel/sysproc.c"
    230. },
    231. {
    232. "arguments": [
    233. "riscv64-linux-gnu-gcc",
    234. "-c",
    235. "-Wall",
    236. "-Werror",
    237. "-O",
    238. "-fno-omit-frame-pointer",
    239. "-ggdb",
    240. "-mcmodel=medany",
    241. "-ffreestanding",
    242. "-fno-common",
    243. "-nostdlib",
    244. "-mno-relax",
    245. "-I.",
    246. "-fno-stack-protector",
    247. "-fno-pie",
    248. "-no-pie",
    249. "-o",
    250. "user/grind.o",
    251. "user/grind.c"
    252. ],
    253. "directory": "/xv6-riscv",
    254. "file": "user/grind.c"
    255. },
    256. {
    257. "arguments": [
    258. "riscv64-linux-gnu-gcc",
    259. "-c",
    260. "-o",
    261. "kernel/entry.o",
    262. "kernel/entry.S"
    263. ],
    264. "directory": "/xv6-riscv",
    265. "file": "kernel/entry.S"
    266. },
    267. {
    268. "arguments": [
    269. "riscv64-linux-gnu-gcc",
    270. "-c",
    271. "-Wall",
    272. "-Werror",
    273. "-O",
    274. "-fno-omit-frame-pointer",
    275. "-ggdb",
    276. "-mcmodel=medany",
    277. "-ffreestanding",
    278. "-fno-common",
    279. "-nostdlib",
    280. "-mno-relax",
    281. "-I.",
    282. "-fno-stack-protector",
    283. "-fno-pie",
    284. "-no-pie",
    285. "-o",
    286. "kernel/console.o",
    287. "kernel/console.c"
    288. ],
    289. "directory": "/xv6-riscv",
    290. "file": "kernel/console.c"
    291. },
    292. {
    293. "arguments": [
    294. "riscv64-linux-gnu-gcc",
    295. "-c",
    296. "-o",
    297. "kernel/kernelvec.o",
    298. "kernel/kernelvec.S"
    299. ],
    300. "directory": "/xv6-riscv",
    301. "file": "kernel/kernelvec.S"
    302. },
    303. {
    304. "arguments": [
    305. "riscv64-linux-gnu-gcc",
    306. "-c",
    307. "-Wall",
    308. "-Werror",
    309. "-O",
    310. "-fno-omit-frame-pointer",
    311. "-ggdb",
    312. "-mcmodel=medany",
    313. "-ffreestanding",
    314. "-fno-common",
    315. "-nostdlib",
    316. "-mno-relax",
    317. "-I.",
    318. "-fno-stack-protector",
    319. "-fno-pie",
    320. "-no-pie",
    321. "-o",
    322. "kernel/vm.o",
    323. "kernel/vm.c"
    324. ],
    325. "directory": "/xv6-riscv",
    326. "file": "kernel/vm.c"
    327. },
    328. {
    329. "arguments": [
    330. "riscv64-linux-gnu-gcc",
    331. "-c",
    332. "-Wall",
    333. "-Werror",
    334. "-O",
    335. "-fno-omit-frame-pointer",
    336. "-ggdb",
    337. "-mcmodel=medany",
    338. "-ffreestanding",
    339. "-fno-common",
    340. "-nostdlib",
    341. "-mno-relax",
    342. "-I.",
    343. "-fno-stack-protector",
    344. "-fno-pie",
    345. "-no-pie",
    346. "-o",
    347. "kernel/trap.o",
    348. "kernel/trap.c"
    349. ],
    350. "directory": "/xv6-riscv",
    351. "file": "kernel/trap.c"
    352. },
    353. {
    354. "arguments": [
    355. "riscv64-linux-gnu-gcc",
    356. "-c",
    357. "-Wall",
    358. "-Werror",
    359. "-O",
    360. "-fno-omit-frame-pointer",
    361. "-ggdb",
    362. "-mcmodel=medany",
    363. "-ffreestanding",
    364. "-fno-common",
    365. "-nostdlib",
    366. "-mno-relax",
    367. "-I.",
    368. "-fno-stack-protector",
    369. "-fno-pie",
    370. "-no-pie",
    371. "-o",
    372. "kernel/exec.o",
    373. "kernel/exec.c"
    374. ],
    375. "directory": "/xv6-riscv",
    376. "file": "kernel/exec.c"
    377. },
    378. {
    379. "arguments": [
    380. "riscv64-linux-gnu-gcc",
    381. "-c",
    382. "-Wall",
    383. "-Werror",
    384. "-O",
    385. "-fno-omit-frame-pointer",
    386. "-ggdb",
    387. "-mcmodel=medany",
    388. "-ffreestanding",
    389. "-fno-common",
    390. "-nostdlib",
    391. "-mno-relax",
    392. "-I.",
    393. "-fno-stack-protector",
    394. "-fno-pie",
    395. "-no-pie",
    396. "-o",
    397. "kernel/log.o",
    398. "kernel/log.c"
    399. ],
    400. "directory": "/xv6-riscv",
    401. "file": "kernel/log.c"
    402. },
    403. {
    404. "arguments": [
    405. "riscv64-linux-gnu-gcc",
    406. "-c",
    407. "-Wall",
    408. "-Werror",
    409. "-O",
    410. "-fno-omit-frame-pointer",
    411. "-ggdb",
    412. "-mcmodel=medany",
    413. "-ffreestanding",
    414. "-fno-common",
    415. "-nostdlib",
    416. "-mno-relax",
    417. "-I.",
    418. "-fno-stack-protector",
    419. "-fno-pie",
    420. "-no-pie",
    421. "-o",
    422. "user/kill.o",
    423. "user/kill.c"
    424. ],
    425. "directory": "/xv6-riscv",
    426. "file": "user/kill.c"
    427. },
    428. {
    429. "arguments": [
    430. "riscv64-linux-gnu-gcc",
    431. "-c",
    432. "-Wall",
    433. "-Werror",
    434. "-O",
    435. "-fno-omit-frame-pointer",
    436. "-ggdb",
    437. "-mcmodel=medany",
    438. "-ffreestanding",
    439. "-fno-common",
    440. "-nostdlib",
    441. "-mno-relax",
    442. "-I.",
    443. "-fno-stack-protector",
    444. "-fno-pie",
    445. "-no-pie",
    446. "-o",
    447. "kernel/uart.o",
    448. "kernel/uart.c"
    449. ],
    450. "directory": "/xv6-riscv",
    451. "file": "kernel/uart.c"
    452. },
    453. {
    454. "arguments": [
    455. "riscv64-linux-gnu-gcc",
    456. "-c",
    457. "-o",
    458. "kernel/trampoline.o",
    459. "kernel/trampoline.S"
    460. ],
    461. "directory": "/xv6-riscv",
    462. "file": "kernel/trampoline.S"
    463. },
    464. {
    465. "arguments": [
    466. "riscv64-linux-gnu-gcc",
    467. "-c",
    468. "-Wall",
    469. "-Werror",
    470. "-O",
    471. "-fno-omit-frame-pointer",
    472. "-ggdb",
    473. "-mcmodel=medany",
    474. "-ffreestanding",
    475. "-fno-common",
    476. "-nostdlib",
    477. "-mno-relax",
    478. "-I.",
    479. "-fno-stack-protector",
    480. "-fno-pie",
    481. "-no-pie",
    482. "-o",
    483. "kernel/spinlock.o",
    484. "kernel/spinlock.c"
    485. ],
    486. "directory": "/xv6-riscv",
    487. "file": "kernel/spinlock.c"
    488. },
    489. {
    490. "arguments": [
    491. "riscv64-linux-gnu-gcc",
    492. "-c",
    493. "-Wall",
    494. "-Werror",
    495. "-O",
    496. "-fno-omit-frame-pointer",
    497. "-ggdb",
    498. "-mcmodel=medany",
    499. "-ffreestanding",
    500. "-fno-common",
    501. "-nostdlib",
    502. "-mno-relax",
    503. "-I.",
    504. "-fno-stack-protector",
    505. "-fno-pie",
    506. "-no-pie",
    507. "-o",
    508. "user/echo.o",
    509. "user/echo.c"
    510. ],
    511. "directory": "/xv6-riscv",
    512. "file": "user/echo.c"
    513. },
    514. {
    515. "arguments": [
    516. "riscv64-linux-gnu-gcc",
    517. "-c",
    518. "-Wall",
    519. "-Werror",
    520. "-O",
    521. "-fno-omit-frame-pointer",
    522. "-ggdb",
    523. "-mcmodel=medany",
    524. "-ffreestanding",
    525. "-fno-common",
    526. "-nostdlib",
    527. "-mno-relax",
    528. "-I.",
    529. "-fno-stack-protector",
    530. "-fno-pie",
    531. "-no-pie",
    532. "-o",
    533. "kernel/string.o",
    534. "kernel/string.c"
    535. ],
    536. "directory": "/xv6-riscv",
    537. "file": "kernel/string.c"
    538. },
    539. {
    540. "arguments": [
    541. "riscv64-linux-gnu-gcc",
    542. "-c",
    543. "-Wall",
    544. "-Werror",
    545. "-O",
    546. "-fno-omit-frame-pointer",
    547. "-ggdb",
    548. "-mcmodel=medany",
    549. "-ffreestanding",
    550. "-fno-common",
    551. "-nostdlib",
    552. "-mno-relax",
    553. "-I.",
    554. "-fno-stack-protector",
    555. "-fno-pie",
    556. "-no-pie",
    557. "-o",
    558. "user/usertests.o",
    559. "user/usertests.c"
    560. ],
    561. "directory": "/xv6-riscv",
    562. "file": "user/usertests.c"
    563. },
    564. {
    565. "arguments": [
    566. "riscv64-linux-gnu-gcc",
    567. "-c",
    568. "-Wall",
    569. "-Werror",
    570. "-O",
    571. "-fno-omit-frame-pointer",
    572. "-ggdb",
    573. "-mcmodel=medany",
    574. "-ffreestanding",
    575. "-fno-common",
    576. "-nostdlib",
    577. "-mno-relax",
    578. "-I.",
    579. "-fno-stack-protector",
    580. "-fno-pie",
    581. "-no-pie",
    582. "-o",
    583. "user/stressfs.o",
    584. "user/stressfs.c"
    585. ],
    586. "directory": "/xv6-riscv",
    587. "file": "user/stressfs.c"
    588. },
    589. {
    590. "arguments": [
    591. "riscv64-linux-gnu-gcc",
    592. "-c",
    593. "-Wall",
    594. "-Werror",
    595. "-O",
    596. "-fno-omit-frame-pointer",
    597. "-ggdb",
    598. "-mcmodel=medany",
    599. "-ffreestanding",
    600. "-fno-common",
    601. "-nostdlib",
    602. "-mno-relax",
    603. "-I.",
    604. "-fno-stack-protector",
    605. "-fno-pie",
    606. "-no-pie",
    607. "-o",
    608. "user/sh.o",
    609. "user/sh.c"
    610. ],
    611. "directory": "/xv6-riscv",
    612. "file": "user/sh.c"
    613. },
    614. {
    615. "arguments": [
    616. "riscv64-linux-gnu-gcc",
    617. "-c",
    618. "-Wall",
    619. "-Werror",
    620. "-O",
    621. "-fno-omit-frame-pointer",
    622. "-ggdb",
    623. "-mcmodel=medany",
    624. "-ffreestanding",
    625. "-fno-common",
    626. "-nostdlib",
    627. "-mno-relax",
    628. "-I.",
    629. "-fno-stack-protector",
    630. "-fno-pie",
    631. "-no-pie",
    632. "-o",
    633. "user/cat.o",
    634. "user/cat.c"
    635. ],
    636. "directory": "/xv6-riscv",
    637. "file": "user/cat.c"
    638. },
    639. {
    640. "arguments": [
    641. "riscv64-linux-gnu-gcc",
    642. "-c",
    643. "-Wall",
    644. "-Werror",
    645. "-O",
    646. "-fno-omit-frame-pointer",
    647. "-ggdb",
    648. "-mcmodel=medany",
    649. "-ffreestanding",
    650. "-fno-common",
    651. "-nostdlib",
    652. "-mno-relax",
    653. "-I.",
    654. "-fno-stack-protector",
    655. "-fno-pie",
    656. "-no-pie",
    657. "-o",
    658. "user/zombie.o",
    659. "user/zombie.c"
    660. ],
    661. "directory": "/xv6-riscv",
    662. "file": "user/zombie.c"
    663. },
    664. {
    665. "arguments": [
    666. "riscv64-linux-gnu-gcc",
    667. "-c",
    668. "-Wall",
    669. "-Werror",
    670. "-O",
    671. "-fno-omit-frame-pointer",
    672. "-ggdb",
    673. "-mcmodel=medany",
    674. "-ffreestanding",
    675. "-fno-common",
    676. "-nostdlib",
    677. "-mno-relax",
    678. "-I.",
    679. "-fno-stack-protector",
    680. "-fno-pie",
    681. "-no-pie",
    682. "-o",
    683. "kernel/pipe.o",
    684. "kernel/pipe.c"
    685. ],
    686. "directory": "/xv6-riscv",
    687. "file": "kernel/pipe.c"
    688. },
    689. {
    690. "arguments": [
    691. "riscv64-linux-gnu-gcc",
    692. "-c",
    693. "-Wall",
    694. "-Werror",
    695. "-O",
    696. "-fno-omit-frame-pointer",
    697. "-ggdb",
    698. "-mcmodel=medany",
    699. "-ffreestanding",
    700. "-fno-common",
    701. "-nostdlib",
    702. "-mno-relax",
    703. "-I.",
    704. "-fno-stack-protector",
    705. "-fno-pie",
    706. "-no-pie",
    707. "-o",
    708. "user/grep.o",
    709. "user/grep.c"
    710. ],
    711. "directory": "/xv6-riscv",
    712. "file": "user/grep.c"
    713. },
    714. {
    715. "arguments": [
    716. "riscv64-linux-gnu-gcc",
    717. "-c",
    718. "-Wall",
    719. "-Werror",
    720. "-O",
    721. "-fno-omit-frame-pointer",
    722. "-ggdb",
    723. "-mcmodel=medany",
    724. "-ffreestanding",
    725. "-fno-common",
    726. "-nostdlib",
    727. "-mno-relax",
    728. "-I.",
    729. "-fno-stack-protector",
    730. "-fno-pie",
    731. "-no-pie",
    732. "-o",
    733. "kernel/sysfile.o",
    734. "kernel/sysfile.c"
    735. ],
    736. "directory": "/xv6-riscv",
    737. "file": "kernel/sysfile.c"
    738. },
    739. {
    740. "arguments": [
    741. "riscv64-linux-gnu-gcc",
    742. "-c",
    743. "-Wall",
    744. "-Werror",
    745. "-O",
    746. "-fno-omit-frame-pointer",
    747. "-ggdb",
    748. "-mcmodel=medany",
    749. "-ffreestanding",
    750. "-fno-common",
    751. "-nostdlib",
    752. "-mno-relax",
    753. "-I.",
    754. "-fno-stack-protector",
    755. "-fno-pie",
    756. "-no-pie",
    757. "-o",
    758. "kernel/syscall.o",
    759. "kernel/syscall.c"
    760. ],
    761. "directory": "/xv6-riscv",
    762. "file": "kernel/syscall.c"
    763. },
    764. {
    765. "arguments": [
    766. "riscv64-linux-gnu-gcc",
    767. "-c",
    768. "-Wall",
    769. "-Werror",
    770. "-O",
    771. "-fno-omit-frame-pointer",
    772. "-ggdb",
    773. "-mcmodel=medany",
    774. "-ffreestanding",
    775. "-fno-common",
    776. "-nostdlib",
    777. "-mno-relax",
    778. "-I.",
    779. "-fno-stack-protector",
    780. "-fno-pie",
    781. "-no-pie",
    782. "-o",
    783. "kernel/plic.o",
    784. "kernel/plic.c"
    785. ],
    786. "directory": "/xv6-riscv",
    787. "file": "kernel/plic.c"
    788. },
    789. {
    790. "arguments": [
    791. "riscv64-linux-gnu-gcc",
    792. "-c",
    793. "-o",
    794. "kernel/swtch.o",
    795. "kernel/swtch.S"
    796. ],
    797. "directory": "/xv6-riscv",
    798. "file": "kernel/swtch.S"
    799. },
    800. {
    801. "arguments": [
    802. "riscv64-linux-gnu-gcc",
    803. "-c",
    804. "-Wall",
    805. "-Werror",
    806. "-O",
    807. "-fno-omit-frame-pointer",
    808. "-ggdb",
    809. "-mcmodel=medany",
    810. "-ffreestanding",
    811. "-fno-common",
    812. "-nostdlib",
    813. "-mno-relax",
    814. "-I.",
    815. "-fno-stack-protector",
    816. "-fno-pie",
    817. "-no-pie",
    818. "-o",
    819. "user/usys.o",
    820. "user/usys.S"
    821. ],
    822. "directory": "/xv6-riscv",
    823. "file": "user/usys.S"
    824. },
    825. {
    826. "arguments": [
    827. "riscv64-linux-gnu-gcc",
    828. "-c",
    829. "-Wall",
    830. "-Werror",
    831. "-O",
    832. "-fno-omit-frame-pointer",
    833. "-ggdb",
    834. "-mcmodel=medany",
    835. "-ffreestanding",
    836. "-fno-common",
    837. "-nostdlib",
    838. "-mno-relax",
    839. "-I.",
    840. "-fno-stack-protector",
    841. "-fno-pie",
    842. "-no-pie",
    843. "-o",
    844. "kernel/start.o",
    845. "kernel/start.c"
    846. ],
    847. "directory": "/xv6-riscv",
    848. "file": "kernel/start.c"
    849. },
    850. {
    851. "arguments": [
    852. "riscv64-linux-gnu-gcc",
    853. "-c",
    854. "-Wall",
    855. "-Werror",
    856. "-O",
    857. "-fno-omit-frame-pointer",
    858. "-ggdb",
    859. "-mcmodel=medany",
    860. "-ffreestanding",
    861. "-fno-common",
    862. "-nostdlib",
    863. "-mno-relax",
    864. "-I.",
    865. "-fno-stack-protector",
    866. "-fno-pie",
    867. "-no-pie",
    868. "-o",
    869. "kernel/printf.o",
    870. "kernel/printf.c"
    871. ],
    872. "directory": "/xv6-riscv",
    873. "file": "kernel/printf.c"
    874. },
    875. {
    876. "arguments": [
    877. "riscv64-linux-gnu-gcc",
    878. "-c",
    879. "-Wall",
    880. "-Werror",
    881. "-O",
    882. "-fno-omit-frame-pointer",
    883. "-ggdb",
    884. "-mcmodel=medany",
    885. "-ffreestanding",
    886. "-fno-common",
    887. "-nostdlib",
    888. "-mno-relax",
    889. "-I.",
    890. "-fno-stack-protector",
    891. "-fno-pie",
    892. "-no-pie",
    893. "-o",
    894. "user/forktest.o",
    895. "user/forktest.c"
    896. ],
    897. "directory": "/xv6-riscv",
    898. "file": "user/forktest.c"
    899. },
    900. {
    901. "arguments": [
    902. "riscv64-linux-gnu-gcc",
    903. "-c",
    904. "-Wall",
    905. "-Werror",
    906. "-O",
    907. "-fno-omit-frame-pointer",
    908. "-ggdb",
    909. "-mcmodel=medany",
    910. "-ffreestanding",
    911. "-fno-common",
    912. "-nostdlib",
    913. "-mno-relax",
    914. "-I.",
    915. "-fno-stack-protector",
    916. "-fno-pie",
    917. "-no-pie",
    918. "-o",
    919. "kernel/virtio_disk.o",
    920. "kernel/virtio_disk.c"
    921. ],
    922. "directory": "/xv6-riscv",
    923. "file": "kernel/virtio_disk.c"
    924. },
    925. {
    926. "arguments": [
    927. "riscv64-linux-gnu-gcc",
    928. "-c",
    929. "-Wall",
    930. "-Werror",
    931. "-O",
    932. "-fno-omit-frame-pointer",
    933. "-ggdb",
    934. "-mcmodel=medany",
    935. "-ffreestanding",
    936. "-fno-common",
    937. "-nostdlib",
    938. "-mno-relax",
    939. "-I.",
    940. "-fno-stack-protector",
    941. "-fno-pie",
    942. "-no-pie",
    943. "-o",
    944. "kernel/bio.o",
    945. "kernel/bio.c"
    946. ],
    947. "directory": "/xv6-riscv",
    948. "file": "kernel/bio.c"
    949. },
    950. {
    951. "arguments": [
    952. "riscv64-linux-gnu-gcc",
    953. "-c",
    954. "-Wall",
    955. "-Werror",
    956. "-O",
    957. "-fno-omit-frame-pointer",
    958. "-ggdb",
    959. "-mcmodel=medany",
    960. "-ffreestanding",
    961. "-fno-common",
    962. "-nostdlib",
    963. "-mno-relax",
    964. "-I.",
    965. "-fno-stack-protector",
    966. "-fno-pie",
    967. "-no-pie",
    968. "-o",
    969. "user/ln.o",
    970. "user/ln.c"
    971. ],
    972. "directory": "/xv6-riscv",
    973. "file": "user/ln.c"
    974. },
    975. {
    976. "arguments": [
    977. "riscv64-linux-gnu-gcc",
    978. "-c",
    979. "-Wall",
    980. "-Werror",
    981. "-O",
    982. "-fno-omit-frame-pointer",
    983. "-ggdb",
    984. "-mcmodel=medany",
    985. "-ffreestanding",
    986. "-fno-common",
    987. "-nostdlib",
    988. "-mno-relax",
    989. "-I.",
    990. "-fno-stack-protector",
    991. "-fno-pie",
    992. "-no-pie",
    993. "-o",
    994. "user/ls.o",
    995. "user/ls.c"
    996. ],
    997. "directory": "/xv6-riscv",
    998. "file": "user/ls.c"
    999. },
    1000. {
    1001. "arguments": [
    1002. "riscv64-linux-gnu-gcc",
    1003. "-c",
    1004. "-Wall",
    1005. "-Werror",
    1006. "-O",
    1007. "-fno-omit-frame-pointer",
    1008. "-ggdb",
    1009. "-mcmodel=medany",
    1010. "-ffreestanding",
    1011. "-fno-common",
    1012. "-nostdlib",
    1013. "-mno-relax",
    1014. "-I.",
    1015. "-fno-stack-protector",
    1016. "-fno-pie",
    1017. "-no-pie",
    1018. "-o",
    1019. "kernel/file.o",
    1020. "kernel/file.c"
    1021. ],
    1022. "directory": "/xv6-riscv",
    1023. "file": "kernel/file.c"
    1024. },
    1025. {
    1026. "arguments": [
    1027. "riscv64-linux-gnu-gcc",
    1028. "-c",
    1029. "-Wall",
    1030. "-Werror",
    1031. "-O",
    1032. "-fno-omit-frame-pointer",
    1033. "-ggdb",
    1034. "-mcmodel=medany",
    1035. "-ffreestanding",
    1036. "-fno-common",
    1037. "-nostdlib",
    1038. "-mno-relax",
    1039. "-I.",
    1040. "-fno-stack-protector",
    1041. "-fno-pie",
    1042. "-no-pie",
    1043. "-o",
    1044. "user/ulib.o",
    1045. "user/ulib.c"
    1046. ],
    1047. "directory": "/xv6-riscv",
    1048. "file": "user/ulib.c"
    1049. },
    1050. {
    1051. "arguments": [
    1052. "riscv64-linux-gnu-gcc",
    1053. "-c",
    1054. "-Wall",
    1055. "-Werror",
    1056. "-O",
    1057. "-fno-omit-frame-pointer",
    1058. "-ggdb",
    1059. "-mcmodel=medany",
    1060. "-ffreestanding",
    1061. "-fno-common",
    1062. "-nostdlib",
    1063. "-mno-relax",
    1064. "-I.",
    1065. "-fno-stack-protector",
    1066. "-fno-pie",
    1067. "-no-pie",
    1068. "-o",
    1069. "user/printf.o",
    1070. "user/printf.c"
    1071. ],
    1072. "directory": "/xv6-riscv",
    1073. "file": "user/printf.c"
    1074. },
    1075. {
    1076. "arguments": [
    1077. "gcc",
    1078. "-c",
    1079. "-Werror",
    1080. "-Wall",
    1081. "-I.",
    1082. "-o",
    1083. "mkfs/mkfs",
    1084. "mkfs/mkfs.c"
    1085. ],
    1086. "directory": "/xv6-riscv",
    1087. "file": "mkfs/mkfs.c"
    1088. },
    1089. {
    1090. "arguments": [
    1091. "riscv64-linux-gnu-gcc",
    1092. "-c",
    1093. "-Wall",
    1094. "-Werror",
    1095. "-O",
    1096. "-fno-omit-frame-pointer",
    1097. "-ggdb",
    1098. "-mcmodel=medany",
    1099. "-ffreestanding",
    1100. "-fno-common",
    1101. "-nostdlib",
    1102. "-mno-relax",
    1103. "-I.",
    1104. "-fno-stack-protector",
    1105. "-fno-pie",
    1106. "-no-pie",
    1107. "-o",
    1108. "user/wc.o",
    1109. "user/wc.c"
    1110. ],
    1111. "directory": "/xv6-riscv",
    1112. "file": "user/wc.c"
    1113. },
    1114. {
    1115. "arguments": [
    1116. "riscv64-linux-gnu-gcc",
    1117. "-c",
    1118. "-Wall",
    1119. "-Werror",
    1120. "-O",
    1121. "-fno-omit-frame-pointer",
    1122. "-ggdb",
    1123. "-mcmodel=medany",
    1124. "-ffreestanding",
    1125. "-fno-common",
    1126. "-nostdlib",
    1127. "-mno-relax",
    1128. "-I.",
    1129. "-fno-stack-protector",
    1130. "-fno-pie",
    1131. "-no-pie",
    1132. "-o",
    1133. "user/init.o",
    1134. "user/init.c"
    1135. ],
    1136. "directory": "/xv6-riscv",
    1137. "file": "user/init.c"
    1138. },
    1139. {
    1140. "arguments": [
    1141. "riscv64-linux-gnu-gcc",
    1142. "-c",
    1143. "-Wall",
    1144. "-Werror",
    1145. "-O",
    1146. "-fno-omit-frame-pointer",
    1147. "-ggdb",
    1148. "-mcmodel=medany",
    1149. "-ffreestanding",
    1150. "-fno-common",
    1151. "-nostdlib",
    1152. "-mno-relax",
    1153. "-I.",
    1154. "-fno-stack-protector",
    1155. "-fno-pie",
    1156. "-no-pie",
    1157. "-o",
    1158. "kernel/sleeplock.o",
    1159. "kernel/sleeplock.c"
    1160. ],
    1161. "directory": "/xv6-riscv",
    1162. "file": "kernel/sleeplock.c"
    1163. }
    1164. ]
  2. .vscode/tasks.json

    1. {
    2. "version": "2.0.0",
    3. "tasks": [
    4. {
    5. "label": "xv6 build",
    6. "type": "shell",
    7. "isBackground": true,
    8. "command": "make qemu-gdb",
    9. "problemMatcher": [
    10. {
    11. "pattern": [
    12. {
    13. "regexp": ".",
    14. "file": 1,
    15. "location": 2,
    16. "message": 3
    17. }
    18. ],
    19. "background": {
    20. "beginsPattern": ".*Now run 'gdb' in another window.",
    21. "endsPattern": "."
    22. }
    23. }
    24. ],
    25. "group": {
    26. "kind": "build",
    27. "isDefault": true
    28. }
    29. }
    30. ]
    31. }
  3. .vscode/launch.json

    1. {
    2. "version": "0.2.0",
    3. "configurations": [
    4. {
    5. "name": "xv6 debug",
    6. "type": "cppdbg",
    7. "request": "launch",
    8. "program": "${workspaceFolder}/kernel/kernel",
    9. "stopAtEntry": true,
    10. "cwd": "${workspaceFolder}",
    11. "miDebuggerServerAddress": "127.0.0.1:25000", //见.gdbinit 中 target remote xxxx:xx
    12. "miDebuggerPath": "/usr/bin/gdb-multiarch", // which gdb-multiarch
    13. "MIMode": "gdb",
    14. "preLaunchTask": "xv6 build"
    15. }
    16. ]
    17. }
  4. .vscode/c_cpp_properties.json

    1. {
    2. "configurations": [
    3. {
    4. "name": "Linux",
    5. "includePath": [
    6. "${workspaceFolder}/**"
    7. ],
    8. "defines": [],
    9. "compilerPath": "/usr/bin/gcc",
    10. "cStandard": "gnu17",
    11. "cppStandard": "gnu++14",
    12. "intelliSenseMode": "linux-gcc-x64",
    13. "compileCommands": "${workspaceFolder}/compile_commands.json"
    14. }
    15. ],
    16. "version": 4
    17. }

参见:

  1. 从零开始使用Vscode调试XV6
  2. 使用VS code 连接远程linux服务器 —— VSCODE clangd插件

    Reference

  3. https://github.com/mit-pdos/xv6-riscv

  4. xv6-riscv book
  5. https://pdos.csail.mit.edu/6.828/2021/