CS3214: Project 1 - Virginia Techcs3214/spring2017/documents/CS3214__Project_1.pdfCS3214: Project 1....

Preview:

Citation preview

CS3214: Project 1

Today’s presentation• Git• gdb• Project 1

Project 1• Due Monday, February 20 at 11:59 PM• Office hours are on course website

Check Piazza for updates

Git

Version Control System• Keep snapshots of your code• Sync your code with other developers

Getting the code!• Generate SSH keys, add to profile• Step by step instructions:

https://docs.gitlab.com/ee/ssh/README.html• Fork the repository here:

https://git.cs.vt.edu/cs3214-staff/cs3214-esh

• MAKE IT PRIVATE • Give developer access to your partner

Git basics• Git keeps your

projects history like a timeline

• Each point in the timeline is called a commit

Committing code• Edit some amount of code• You can view the status of files as you work

• “git status” to see file status (edited, staged, etc)• Add changes to staging area:

• “git add <file>” Adds file to staging area• “git add .” Adds all files to staging area

• When ready, commit them• “git commit -m “message”” Commit with message

• Push your changes to Gitlab“git push”

• Pull teammate’s changes from Gitlab“git pull”

Must pull before push!

Merge Conflict Resolution

<<<<<<< HEAD// Author: Richard Feynman=======// Author: Elon Musk>>>>>>> 52ea9255764f9b67b1ce91250e1d70ddca7ab2cc...

src/esh.c

Red: My changesBlue: Remote changes

● Perform necessary changes (don’t forget to remove extra markup) and save file● Stage changes ($ git add src/esh.c )● Commit changes ($ git commit )● Do another pull ($ git pull ), just in case● Push final changes ($ git push )

Git Commands - TL;DR VersionShows a list of files that have been modified; shows changes that have been staged and those that haven’t$ git statusCopies the specified repo to the current directory$ git clone <repo url>Add the specified files to the staging area$ git add <files>Commit all staged changes$ git commit -m “commit message here”Get changes from the remote repo (gitlab) and apply them to local copy$ git pullPush local changes to the remote repo (gitlab)$ git push

Always do PULL before PUSH!

ResourcesOfficial tutorial page:http://git-scm.com/docs/gittutorialFree Codeschool guided tutorial:https://www.codeschool.com/courses/try-gitWalk-through tutorial:http://gitimmersion.com/index.htmlAlso, google.comSeriously… git is very popular you will probably find everything you need just by searching for it.

Questions?

GDBDebugging is key to success!

$ gcc -g • Code MUST compile with -g for gdb to work

properly!• Also highly recommended to turn off

optimizations (-O0) as compilers may shift around or optimize out code

$ gdb --args • $ gdb --args program arg1 arg2• Is saved as part of BASH history• Great alternative to “run arg1 arg2”

(gdb) layout src• Show source code lines while debugging• Far superior alternative to list• Turn off with Ctrl-X+A

Backtrace and Frames• (gdb) bt (show function call trace)• (gdb) frame <num>• After selecting a frame, you can print all

variables declared in that function call

(gdb) call function()• Make any function call while debugging• Can also call print function() instead, will

also show the return value• Don’t forget the ()!

Zoning in on the bug• Scenario: your program breaks after a while• Be clever with breakpoints (bp)• (gdb) ignore 1 100 (ignore bp 1 100 times)• (gdb) info b (show how many times bp was

hit)

Zoning in on the bug

Watchpoints• Very good at finding memory bugs• watch *0xADDRESS• Don’t forget the *

GDB Commands - Summary

$ gcc -g -O0 $ gdb --args

(gdb) layout src(gdb) bt(gdb) frame <num>(gdb) info b(gdb) ignore <bp> <num>(gdb) watch *0x<address>(gdb) call function()

Graphical GDB• For those of you who prefer graphical

debuggers like Eclipse, try DDD

Questions?

Project 1

Base code-Already includes a parser!-Parser spits out hierarchical data structures-Most of the project will be playing with these data structures

esh_* data structures

List data structure• “Node contains (a pointer to) data” vs “Data

contains node”• Retrieve data from a struct list_elem

by using the list_entry macro • struct esh_command *cmd = list_entry(e, struct esh_command, elem);

List data structureRegular linked list

class listnode<T> { T data; listnode<T> next;}

List data structure“struct list”

struct list_elem { struct list_elem *prev; struct list_elem *next; };

List data structure• Don’t:

• Use the same list_elem for multiple lists • Forget to list_init• Pass your struct list to a function (pass a pointer

instead)

Questions?

Demo

Recommended