Introduction to the Omega Server CSE 1105. Overview Intro to Omega Basic Unix Command Files...

33
Introduction to the Omega Server CSE 1105

Transcript of Introduction to the Omega Server CSE 1105. Overview Intro to Omega Basic Unix Command Files...

Introduction to the Omega Server

CSE 1105

Overview

Intro to Omega Basic Unix Command

Files Directories Printing C and C++ compilers

GNU Debugger

Omega Server

Unix-based Server Provides C, C++, Lisp, Prolog,

Cobol, and Fortran Language Compilers

Pine Mail Server Users connect via telnet, ssh,

hummingbird or other remote log ins

How to connect to Omega

1. Using the telnet command > telnet omega.uta.edu2. Enter username at the prompt

Connect

2. SSH Secure Shell

installed on all school computers

Connect

3. Hummingbird

Writing programs

Edit a file using an existing Unix editor vi editor pico editor

Edit a text file and upload it to omega telnet ftp e-mail content or attachment

Basic Unix CommandsManaging Files

ls : displays the files in a specified directory <usage with prompt of %>%ls

rm : delete a file <usage>%rm file_name

cp : copy files <usage>%cp source_file destination_file

mv : renames files and/or moves files <usage>%mv old_filename new_filename <usage>%mv old_filename

directory/new_name

pwd : print the current (working) directory<usage>%pwd

cd : change directory <usage>%cd subdirectory_name <usage>%cd .. <to go up one level>

mkdir : make a new directory <usage>%mkdir subdirectory_name

rmdir : remove a directory <usage>%rmdir subdirectory_name

Basic Unix CommandsManaging Directories

Basic Unix CommandsPrinting Files

cat : concatenate the file to the screen (list the file)

<usage>%cat file_name: or pipe the file to a selected output

location<usage>%cat file_name | output_loc

lpr : send to the printer <usage>%lpr file_name

Basic Unix CommandsInvoking C and C++ compilers

gcc : compile a C program to output file a.out<usage>%gcc program_file.c: with the math library option to a file

my.out<usage>%gcc program_file.c -lm -o

my.out

g++ : compile a C++ program to file a.out <usage>% g++ program_file.cpp

GNU Debugger (GDB) Use GDB to debug programs in C, C++, Modular-2, and Pascal, Fortran GDB is part of the GNU Project that was

launched in 1984 to develop a complete UNIX style operating system.

Free software: the GNU system is free ( pronounced “guh-noo”) at www.gnu.org

GDB is protected by the GNU General Public License (GPL)

Capabilities with GDB Start your program, specifying anything

that might affect its behavior. Make your program stop on specified

conditions. Examine what has happened, when

your program has stopped. Change things in your program, so you

can experiment with correcting the effects of one bug and go on to learn about another.

Starting GDB

gcc filename with option –g <usage> gcc filename –g gdb in shell prompt with executable

file <usage> gdb a.out gdb prompt – executing by gdb

command (gdb) commands

GDB Commands

list(l) – show the source list each 10line

list [[file:]n|func] help – show the information of gdb

command help [name] break – setup the breakpoint break [[file:]n|function]

GDB Commands - cont.

clear – remove the breakpoint clear [[file:]n|function] run – begin program run [arglist] print expr – show the value of expr print expr

GDB Commands - cont.

c (or continue) – continue the program

c [n] next – execute n lines and display

the line if the next line is the function, it

executes the whole function. next [n]

GDB Commands - cont.

step - execute n lines and display the line

if the next line is the function, it executes n line inside the function.

step [n] bt (or backtrace) – display the

program stack’s order which functions are called in program

GDB Commands - cont. ret (or return) – exit the current

function as return retrunvalue ret retval finish – execute the current function

until the function returns the retval kill – quit the current debugging

process quit – quit the gdb

Example – bugsome.c The program is to calculate factorial

and power Not working for power function Setup the breakpoint as power function Program bugsome.c has been compiled

with gcc to file a.out/home/dsk22/ xxx1234 /1320> gcc bugsome.c

#include <stdio.h>#include <stdlib.h> /* returns n * (n-1) * ... * 1 */int factorial(int n){ if(n == 1) return 1; return n * factorial(n - 1);} /* returns b^e , e>=0 */int power(int b, int e){ return b * power(b, e-1);}

void f3() { printf("This is f3().\n");} void f2() { f3(); printf("11^7 = %d\n", power(11, 7));} void f1() { printf("11! = %d\n", factorial(11)); f2();} int main() { f1(); printf("0! = %d\n", factorial(0)); return 0;}

List – bugsome.c

Result – a.out/home/dsk22/ xxx1234 /1320> a.out11! = 39916800This is f3().Stack overflow: pid 315, proc a.out, addr

0x11fdfffe0, pc 0x1200012bc

/home: warning, disk quota exceeded for user id 18531

Segmentation fault (core dumped)/home/dsk22/xxx1234/1320>

Debugging example/home/dsk22/ xxx1234 /1320> gcc bugsome.c -g/home/dsk22/ xxx1234 /1320> gdb a.outGDB is free software and you are welcome to distribute

copies of it under certain conditions; type "show copying" to see the

conditions.There is absolutely no warranty for GDB; type "show

warranty" for details.GDB 4.16 (alpha-dec-osf4.0), Copyright 1996 Free

Software Foundation, Inc...(gdb) break powerBreakpoint 1 at 0x1200012d8: file bugsome.c, line 16.

Example continued(gdb) runStarting program: /home/dsk22/xxx1234/1320/a.out11! = 39916800This is f3().

Breakpoint 1, power (b=11, e=7) at bugsome.c:1616 return b * power(b, e-1);(gdb) cContinuing.

Breakpoint 1, power (b=11, e=6) at bugsome.c:1616 return b * power(b, e-1);

(gdb) c 3Will ignore next 2 crossings of breakpoint 1.

Continuing.

Breakpoint 1, power (b=11, e=3) at bugsome.c:1616 return b * power(b, e-1);(gdb) cContinuing.

Breakpoint 1, power (b=11, e=2) at bugsome.c:1616 return b * power(b, e-1);(gdb) cContinuing.

Breakpoint 1, power (b=11, e=1) at bugsome.c:1616 return b * power(b, e-1);(gdb) cContinuing.

Breakpoint 1, power (b=11, e=0) at bugsome.c:1616 return b * power(b, e-1);

(gdb) ret 1Make power return now? (y or n) y#0 0x1200012f8 in power (b=11, e=1) at

bugsome.c:16return b * power(b, e-1);

(gdb) l11 }1213 /* returns b^e , e>=0 */14 int power(int b, int e)15 { 16 return b * power(b, e-1);17 }1819 void f3()20 {

(gdb) l21 printf("This is f3().\n");22 }2324 void f2()25 {26 f3();27 printf("11^7 = %d\n", power(11, 7));28 }2930 void f1()(gdb) break 28Breakpoint 2 at 0x1200013c4: file bugsome.c,

line 28.(gdb) cContinuing.11^7 = 19487171

Breakpoint 2, f2 () at bugsome.c:2828 }

(gdb) nf1 () at bugsome.c:3434 }(gdb) nmain () at bugsome.c:4141 printf("0! = %d\n", factorial(0));(gdb) sfactorial (n=0) at bugsome.c:77 if(n == 1)(gdb) l2 #include <stdlib.h>34 /* returns n * (n-1) * ... * 1 */5 int factorial(int n)6 {7 if(n == 1)8 return 1;910 return n * factorial(n - 1);11 }

(gdb) ret 1Make factorial return now? (y or n) y#0 0x120001478 in main () at bugsome.c:4141 printf("0! = %d\n", factorial(0));(gdb) cContinuing.0! = 1

Program exited normally. (gdb) quit