[{"data":1,"prerenderedAt":367},["ShallowReactive",2],{"content:\u002Fen\u002Ffiddling\u002Fcsapplab0":3,"surround:\u002Fen\u002Ffiddling\u002Fcsapplab0":356},{"id":4,"title":5,"authorship":6,"body":7,"categories":325,"date":327,"description":328,"draft":329,"extension":330,"image":331,"meta":332,"navigation":334,"path":335,"permalink":336,"published":336,"readingTime":337,"recommend":336,"references":336,"seo":342,"seoDescription":343,"seoTitle":336,"sitemap":344,"stem":347,"tags":348,"type":354,"__hash__":355},"content_en\u002Fposts\u002Ffiddling\u002Fcsapplab0.md","Setting Up the CSAPP Lab Environment","human-only",{"type":8,"value":9,"toc":309},"minimark",[10,15,22,25,47,50,53,61,64,68,71,82,85,91,94,101,105,110,113,123,126,130,133,136,142,145,151,154,158,161,164,167,173,176,182,185,189,192,201,204,207,210,216,219,225,228,234,238,242,245,251,254,260,263,270,272,275,282,285,288,297,301],[11,12,14],"h3",{"id":13},"introduction","Introduction",[16,17,18],"blockquote",{},[19,20,21],"p",{},"Studying CSAPP without doing the labs is like reading China's Four Great Classical Novels but skipping Dream of the Red Chamber. It exposes a lack of literary accomplishment and self-cultivation: you cannot appreciate its refined inner artistry, seeing only ornate words while failing to grasp its profound spiritual core. Your entire existence hits its ceiling there, leaving you a relatively unsuccessful life.",[19,23,24],{},"The biggest deterrent to doing CSAPP labs is the Linux environment. I did them as an undergraduate using Ubuntu Desktop in VMware Workstation. I personally had no trouble, but people around me ran into:",[26,27,28,32,35,38,41,44],"ul",{},[29,30,31],"li",{},"Virtual machine installation errors",[29,33,34],{},"VMware incompatibility with Hyper-V",[29,36,37],{},"No network in the VM",[29,39,40],{},"Shared folders between guest and host not working",[29,42,43],{},"Chinese input methods in Ubuntu",[29,45,46],{},"Other inexplicable problems",[19,48,49],{},"VM performance is also hard to praise. You have to carve out memory from the host, and you never know which will run out first: the guest or the host.",[19,51,52],{},"For these reasons, I chose WSL (Windows Subsystem for Linux). I recommend Windows 10 version 2004 or later, or Windows 11, for WSL 2. Older Windows versions, even those with WSL, only support WSL 1, which translates Linux system calls into Windows system calls. WSL 2 uses a lightweight, maintenance-free VM running a complete Linux kernel. A full Linux kernel is crucial for the CSAPP labs.",[19,54,55,56,60],{},"What about macOS? On an Intel MacBook, install VirtualBox, VMware Fusion, or Parallels Desktop and run a Linux distribution, or use Docker. For an M1 MacBook, ",[57,58,59],"strong",{},"get another computer",". I am not joking: you really cannot do the labs on M1.",[19,62,63],{},"Wow, I really do talk too much.",[11,65,67],{"id":66},"installing-wsl-and-ubuntu","Installing WSL and Ubuntu",[19,69,70],{},"Installing WSL on Windows is easy. Run this in an administrator PowerShell:",[72,73,79],"pre",{"className":74,"code":76,"language":77,"meta":78},[75],"language-shell","wsl --install -d Ubuntu\n","shell","",[80,81,76],"code",{"__ignoreMap":78},[19,83,84],{},"Windows automatically enables the required features and downloads the latest Ubuntu LTS, version 20.04 at the time of writing. Once installation finishes, a terminal asks you for a username and password:",[72,86,89],{"className":87,"code":88,"language":77,"meta":78},[75],"Installing, this may take a few minutes...\nPlease create a default UNIX user account. The username does not need to match your Windows username.\nFor more information visit: https:\u002F\u002Faka.ms\u002Fwslusers\nEnter new UNIX username: shinya\nNew password:\nRetype new password:\npasswd: password updated successfully\nInstallation successful!\n",[80,90,88],{"__ignoreMap":78},[19,92,93],{},"Note that nothing appears on screen while you type your password.",[19,95,96,97,100],{},"After setup, you will see a prompt such as ",[80,98,99],{"code":99},"shinya@DESKTOP-4TMFLAE:~$",", waiting for a command. You are now in Ubuntu.",[11,102,104],{"id":103},"a-few-useful-tips","A few useful tips",[106,107,109],"h4",{"id":108},"windows-terminal","Windows Terminal",[19,111,112],{},"Windows Terminal is arguably the king of terminals on Windows.",[19,114,115,116,122],{},"Search for “Windows Terminal” in Microsoft Store to install it, or download the msixbundle from its GitHub Releases page, ",[117,118,119],"a",{"href":119,"rel":120},"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fterminal\u002Freleases",[121],"nofollow",", and double-click it.",[19,124,125],{},"If WSL and Ubuntu are already installed, an Ubuntu entry appears in the dropdown next to the plus sign in Windows Terminal's top bar. Click it to open Ubuntu's default shell.",[106,127,129],{"id":128},"file-sharing","File sharing",[19,131,132],{},"Ubuntu in WSL and Windows are isolated systems with separate filesystems. Isolated, but not entirely.",[19,134,135],{},"Windows's C drive is mounted at \u002Fmnt\u002Fc in Ubuntu. For example, to access the Windows desktop from Linux:",[72,137,140],{"className":138,"code":139,"language":77,"meta":78},[75],"$ cd \u002Fmnt\u002Fc\u002FUsers\u002FShinya\u002FDesktop\n$ ls\n course.py     desktop.ini     szxx.bat     szxx.txt\n",[80,141,139],{"__ignoreMap":78},[19,143,144],{},"Likewise, to view files in WSL's own filesystem from Windows, such as your home directory ~, run:",[72,146,149],{"className":147,"code":148,"language":77,"meta":78},[75],"$ cd ~\n$ explorer.exe .\n",[80,150,148],{"__ignoreMap":78},[19,152,153],{},"Windows File Explorer opens the folder you requested. You can work with it just like a Windows folder.",[106,155,157],{"id":156},"visual-studio-code","Visual Studio Code",[19,159,160],{},"VS Code, the world's best text editor, can open WSL folders directly, offering the same experience as a local project. After all, not everyone enjoys doing their labs in vim.",[19,162,163],{},"Open VS Code on Windows, search for WSL in the extensions marketplace, and install “Remote - WSL”. It is usually the first result.",[19,165,166],{},"Then, from your project directory in Ubuntu, run:",[72,168,171],{"className":169,"code":170,"language":77,"meta":78},[75],"$ code .\n",[80,172,170],{"__ignoreMap":78},[19,174,175],{},"The first time you run it, the necessary support components are installed:",[72,177,180],{"className":178,"code":179,"language":77,"meta":78},[75],"$ code .\nInstalling VS Code Server for x64 (899d46d82c4c95423fb7e10e68eba52050e30ba3)\nDownloading: 100%\nUnpacking: 100%\n",[80,181,179],{"__ignoreMap":78},[19,183,184],{},"VS Code on Windows then opens automatically with the Ubuntu project folder as its working directory. Develop however you like from there.",[106,186,188],{"id":187},"switching-to-chinese-package-mirrors","Switching to Chinese package mirrors",[19,190,191],{},"First, what is a “source”?",[16,193,194],{},[19,195,196,197,200],{},"Ancient texts tell of a time when heaven and earth mingled to create all things, amid dense chaos and spiritual mist. Many spiritual beings absorbed the primordial essence of the world, forming amber-like crystals that sealed vast stores of life essence within.",[198,199],"br",{},"\nThose surviving today are called “Sources”.",[19,202,203],{},"Sorry, wrong universe.",[19,205,206],{},"Put simply, apt, the package manager used by Ubuntu and other Debian-based systems, maintains a list of URLs. When you run apt install, it searches, downloads, and installs packages from those addresses. This URL list is the package sources. The defaults point overseas, and for well-known reasons they can be slow or entirely unreachable from China. So we replace them with mirrors within China.",[19,208,209],{},"Here is how:",[72,211,214],{"className":212,"code":213,"language":77,"meta":78},[75],"$ sudo mv \u002Fetc\u002Fapt\u002Fsources.list \u002Fetc\u002Fapt\u002Fsources.list.bak\n$ sudo nano \u002Fetc\u002Fapt\u002Fsources.list\n",[80,215,213],{"__ignoreMap":78},[19,217,218],{},"Paste the following. I use Alibaba's mirror here. Different distributions and versions need different sources, so choose carefully. These are for Ubuntu 20.04.",[72,220,223],{"className":221,"code":222,"language":77,"meta":78},[75],"deb http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal main restricted universe multiverse\ndeb-src http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal main restricted universe multiverse\ndeb http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-security main restricted universe multiverse\ndeb-src http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-security main restricted universe multiverse\ndeb http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-updates main restricted universe multiverse\ndeb-src http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-updates main restricted universe multiverse\ndeb http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-proposed main restricted universe multiverse\ndeb-src http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-proposed main restricted universe multiverse\ndeb http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-backports main restricted universe multiverse\ndeb-src http:\u002F\u002Fmirrors.aliyun.com\u002Fubuntu\u002F focal-backports main restricted universe multiverse\n",[80,224,222],{"__ignoreMap":78},[19,226,227],{},"Then refresh the package lists and upgrade packages:",[72,229,232],{"className":230,"code":231,"language":77,"meta":78},[75],"$ sudo apt update\n$ sudo apt upgrade\n",[80,233,231],{"__ignoreMap":78},[11,235,237],{"id":236},"installing-software-for-the-labs","Installing software for the labs",[106,239,241],{"id":240},"packages","Packages",[19,243,244],{},"The essentials take just one command:",[72,246,249],{"className":247,"code":248,"language":77,"meta":78},[75],"$ sudo apt install build-essential gcc-multilib gdb\n",[80,250,248],{"__ignoreMap":78},[19,252,253],{},"Optional: cgdb, a lightweight frontend for GDB. It provides a split view of the gdb command interface, identical to regular gdb, and your source code. The repository's cgdb is not the latest version, so I build it from source:",[72,255,258],{"className":256,"code":257,"language":77,"meta":78},[75],"$ sudo apt install automake libncurses5-dev flex texinfo libreadline-dev\n$ git clone git:\u002F\u002Fgithub.com\u002Fcgdb\u002Fcgdb.git\n$ cd cgdb\n$ .\u002Fautogen.sh\n$ .\u002Fconfigure --prefix=\u002Fusr\u002Flocal\n$ make\n$ sudo make install\n",[80,259,257],{"__ignoreMap":78},[19,261,262],{},"Once installed, you can open it anywhere with the cgdb command. It looks like this:",[19,264,265],{},[266,267],"img",{"alt":268,"src":269},"CGDB","https:\u002F\u002Fblog-img.774352199.xyz\u002F2025\u002Fa36f15210399888f0e0cf56efe45a202.jpg",[19,271,268],{},[19,273,274],{},"The left pane is the source window; the right is the gdb window.",[19,276,277,278,281],{},"By default, cgdb stacks the two panes one above the other. Press ",[80,279,280],{"code":280},"ctrl+w"," to switch to side-by-side panes.",[19,283,284],{},"Press esc to move focus from gdb to the source window. There you can scroll through the source and press space to set a breakpoint on the focused line.",[19,286,287],{},"Press i to return focus to the gdb window, which works exactly like regular gdb.",[19,289,290,291,296],{},"For more details, see this ",[117,292,295],{"href":293,"rel":294},"https:\u002F\u002Fleeyiw.gitbooks.io\u002Fcgdb-manual-in-chinese",[121],"CGDB manual in Chinese",".",[106,298,300],{"id":299},"where-are-the-labs","Where are the labs?",[19,302,303,304,308],{},"If you are studying CSAPP independently, visit ",[117,305,306],{"href":306,"rel":307},"http:\u002F\u002Fcsapp.cs.cmu.edu\u002F3e\u002Flabs.html",[121],". Each lab's Self-Study Handout link downloads the lab materials. Copy them into WSL and enjoy the labs!",{"title":78,"searchDepth":310,"depth":310,"links":311},4,[312,314,315,321],{"id":13,"depth":313,"text":14},3,{"id":66,"depth":313,"text":67},{"id":103,"depth":313,"text":104,"children":316},[317,318,319,320],{"id":108,"depth":310,"text":109},{"id":128,"depth":310,"text":129},{"id":156,"depth":310,"text":157},{"id":187,"depth":310,"text":188},{"id":236,"depth":313,"text":237,"children":322},[323,324],{"id":240,"depth":310,"text":241},{"id":299,"depth":310,"text":300},[326],"fiddling","2021-12-27 00:09:00","The labs are an essential part of learning CSAPP, but setting up Linux can be discouraging. Virtual machines bring installation errors, compatibility problems, and broken networking. WSL (Windows Subsystem for Linux), especially on Windows 10 version 2004 and later, provides a simpler, more direct Linux environment without the complexity and performance bottlenecks of a traditional VM.",false,"md","https:\u002F\u002Fblog-img.774352199.xyz\u002FvqOC7N.webp",{"slots":333},{},true,"\u002Ffiddling\u002Fcsapplab0",null,{"text":338,"minutes":339,"time":340,"words":341},"6 min read",5.295,317700,1059,{"title":5,"description":328},"Set up a CSAPP lab environment on Windows with WSL2 and Ubuntu, including VS Code integration, file sharing, package mirrors, and GDB and CGDB tools.",{"loc":335,"images":345},[346],{"loc":269},"posts\u002Ffiddling\u002Fcsapplab0",[349,350,351,352,353],"CSAPP","WSL2","Linux","GDB","Lab environment","tech","nfHBPpLgPIftIvYhbhrVj2sR0My0zxgn4bO40S3TUpk",[357,362],{"title":358,"path":359,"stem":360,"date":361,"type":354,"children":-1},"MYDB 10. Implementing the Server, Client, and Wire Protocol","\u002Fprojects\u002Fmydb\u002Fmydb10","posts\u002Fprojects\u002Fmydb\u002Fmydb10","2021-12-25 18:26:00",{"title":363,"path":364,"stem":365,"date":366,"type":354,"children":-1},"How Java’s this Keyword Can Prevent Compile-Time Constant Propagation","\u002Ffiddling\u002Fthis-in-javac-string-concat","posts\u002Ffiddling\u002Fthis-in-javac-string-concat","2022-04-16 00:01:28",1789914049830]