DevelopmentByDavid / OS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CS153

Copy-Paste Bank

kill $(pgrep qemu)
find . -type f -name \*.c -exec sed -i.bak 's|TOREPLACE|REPLACEWITH|g' {} +
grep -rnw '/path/to/somewhere/' -e 'pattern'
echo "add-auto-load-safe-path $HOME/xv6/.gdbinit" > ~/.gdbinit
make qemu-nox-gdb
make qemu-gdb

Adding System Calls

The prototypes for the user's system calls should appear in defs.h and user.h

Adding a basic system call

Adding a system call with user passed parameters

Writing Test Files

When writing user programs only use lib functions found in user.h and end the main function with an exit(status) instead of return as pictured

#include "types.h"
#include "user.h"


int main(){
  printf(1, "Hello World \n");
  exit(0);
}

Adding a program to run in qemu shell

Sed & Find basic usage

Sed detailed tutorial here
Sed basic stack overflow answer here
decent find tutorial here; make sure to view -xargs vs -exec

Basic global read/write command for ease of copy-paste. CAPS = PLACEHOLDER

find . -type f -name \*.c -exec sed -i.bak 's|TOREPLACE|REPLACEWITH|g' {} +
-type f : type of thing to find = file(s)
-name \*.c:name of the file will be anything (because * matches anything b/c regex) ending with a .c extension
-i.bak: creates a backup file with the same name as the original
's|TOREPLACE|REPLACEWITH|g': s = substitute g = global

Alternatively, to just find all occurences of something Source
grep -rnw '/path/to/somewhere/' -e 'pattern'

  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.

Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

  • This will only search through those files which have .c or .h extensions:

    grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
    
  • This will exclude searching all the files ending with .o extension:

    grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
    
  • For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

    grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

This works very well for me, to achieve almost the same purpose like yours.

For more options check man grep.

vim settings

in ~/.vimrc add...

 1 filetype plugin indent on
  2 " show existing tab with 4 spaces width
  3 set tabstop=4
  4 " " when indenting with '>', use 4 spaces width
  5 set shiftwidth=4
  6 " " On pressing tab, insert 4 spaces
  7 set expandtab
  8 set number

About


Languages

Language:C 79.7%Language:C++ 5.1%Language:Assembly 3.9%Language:Makefile 3.5%Language:Shell 2.4%Language:Perl 2.1%Language:Objective-C 1.4%Language:Ruby 1.1%Language:OpenEdge ABL 0.8%Language:Emacs Lisp 0.0%