עבודה ב- T2

  • View
    71

  • Download
    2

Embed Size (px)

DESCRIPTION

- T2. . ?. . - Eclipse . - Debugging. . - PowerPoint PPT Presentation

Transcript

- Debugging

-T2 1 ? .

-Eclipse.

-Debugging.

2 3myuser@t2 > bank database.txt database2.txtadd Moshe Cohen Premium 50000.00deposit Moshe Cohen Premium 4000.00withdraw Dani Din Regular 300.00exitmyuser@t2 >database.txt[Business Yaron Levi 6000.00][Regular Dani Din 600.00]

database2.txt[Business Yaron Levi 6000.00][Regular Dani Din 300.00][Premium Moshe Cohen 54000.00]

4 : account.c, account.h

main.c 5 1: -T2 -SSH -T2.SSH Windows :ftp://ftp.cs.technion.ac.il/pub/ssh-client/sshclient.exe

( OSX) ssh.

... 6 1: -T2 :

mtmaux_tut 7 2: -T2:nano ...Emacs " ... 8 2: ~mtm/public/1314b/aux_tut/bank

bank aux_tut 99 3: , . , .

-Unix C GCC. GNU Compiler Collection.

(IDE). ( -C) , . , .

10 ++C. GCC g++ .

GNU Compiler Collection - -GCC ( ++C ).10 3: .

a.out. EXE Windows. 11 " GCC.11 GCC :

-o exefile a.out.

-std=c99 . C99.-C99 , for:

-pedantic-errors .

myuser@t2 > gcc -o -std=c99 -pedantic-errors -Wall -Werror for (int i = 0; i < n; ++i) {printf("%d\n", i);} 1212 GCC :

-Wall . . (errors) , (warnings) ." . .

-Werror . ." ( ) .

myuser@t2 > gcc -o -std=c99 -pedantic-errors -Wall -Werror 13 . -Wall --std=c99 .13 3: . ... 14 4: : . . .

, .

15 ? . . . ., ** .

: . .

- , .

15 4: : . . .

.

16 ?! : diff diff . . .

myuser@t2 > cat file1.txt[Business Yaron Levi 6000.00][Regular Dani Din 600.00]myuser@t2 > cat file2.txt[Premium Moshe Cohen 54000.00][Business Yaron Levi 6000.00][Regular Dani Din 300.00]myuser@t2 > diff file1.txt file2.txt0a1> [Premium Moshe Cohen 54000.00]2c3< [Regular Dani Din 600.00]---> [Regular Dani Din 300.00]:0a1: 0 ( ) 1 ( )

:2c3 2 3 .

, .

17 diff . .17 : diff ! !

18 diff . .18 : sdiffsdiff .shiroko2@t2 > diff file1.txt file2.txt>[Premium Moshe Cohen 54000.00][Business Yaron Levi 6000.00][Business Yaron Levi 6000.00][Regular Dani Din 600.00]|[Regular Dani Din 300.00] 19 , ( ). diff (" diff )

. - kompare -T2. - WinMerge -Windows. - -Eclipse Compare With .19 4: : . . diff . 20 4: , test.

:

. . .

myuser@t2 > ./bank test/test1.data out.txt < test/test1.inmyuser@t2 > diff out.txt test/test1.out 2121 -Shell-Shell . -T2 -Shell Bash.

Shell " .

:TAB: . / . 2222Scripts " source. (scripts). , .

, Script .

23 C-Shell -Unix (scripts) 6-7 ' 3. script Unix ( Windows ).23 5: . . . "" .

run_tests.cshgcc -o bank -std=c99 -pedantic-errors -Wall -Werror main.c account.c

echo Test no.1 (Adding accounts)./bank test/test1.data out.txt < test/test1.indiff out.txt test/test1.out

echo Test no.2 (Depositing)./bank test/test2.data out.txt < test/test2.indiff out.txt test/test2.out

echo Test no.3 (Withdraw)./bank test/test3.data out.txt < test/test3.indiff out.txt test/test3.outmyuser@t2 > source run_tests.cshTest no.1 (Adding accounts)Test no.2 (Depositing)Test no.3 (Withdraw)myuser@t2 >

2424 6: GDB.GDB " GCC.

"" .

"" -g. -GDB .

myuser@t2 > gcc -o bank -g -std=c99 -pedantic-errors -Wall -Werror main.c account.c 25GDB vs. Segmentation Fault #include int twice(int* ptr) {int result = *ptr + *ptr;return result;}int main() {int a = 5;printf("%d\n",twice(&a));int* ptr = NULL;printf("%d\n",twice(ptr));return 0;} 26 ~mtm/public/1314b/aux_tut/crash

26GDB vs. Segmentation Fault NULL

-f NULL.

.#include int twice(int* ptr) {int result = *ptr + *ptr;return result;}int main() {int a = 5;printf("%d\n",twice(&a));int* ptr = NULL;printf("%d\n",twice(ptr));return 0;}myuser@t2 > gcc crash.cmyuser@t2 > ./a.out10Segmentation faultmyuser@t2 >

2727 GDB

GDB . GDB, :run - continue - step ( )print - " Ctrl+z. " Ctrl+C.

GDB vs. Segmentation Faultmyuser@t2 > gdb 2828GDB vs. Segmentation Fault" backtrace . twice -main.myuser@t2 > gcc -g crash.cmyuser@t2 > gdb -q a.out(gdb) runUsing host libthread_db library "/lib64/tls/libthread_db.so.1".Starting program: /u1/115/myuser/a.out 10

Program received signal SIGSEGV, Segmentation fault.0x00000000004004b4 in twice (ptr=0x0) at crash.c:44 int result = *ptr + *ptr;(gdb) backtrace#0 0x00000000004004b4 in twice (ptr=0x0) at crash.c:4#1 0x00000000004004fa in main () at crash.c:12(gdb) -q . run 2929Breakpoints . , .

(breakpoint) " break

print.

-continue ( )

step. 30GDB: GDB . . . " help . 3131