Script started on Fri 02 Oct 2009 01:45:33 AM EDT
[loki.cs.kent.edu]{1}-> cat helloworld.cpp //changed
from class code to
add an array
#include "helloworld.h" //note the code is somewhat silly
#include <iostream> //addition
code in blue
using namespace std;
void mytry(int x[]);
void hello_world(){
int a[10], i;
for (i=0;i<10;i++)
a[i] = i;
cout << "Hello World!\n";
mytry(a);
}
void mytry(int a[]) {
for (int i=0; i < 10 ; i++)
cout << a[i] <<endl;
}
[loki.cs.kent.edu]{2}-> cat helloworld.h //code
not changed
#ifndef _HELLOWORLD_H
#define _HELLOWORLD_H
#include <iostream>
void hello_world();
#endif
[loki.cs.kent.edu]{3}-> cat main.cpp //code
not changed
#include "helloworld.h"
int main(){
hello_world();
return 0;
}
Makefile not changed.
Script done on Fri 02 Oct 2009 01:46:13 AM EDT
=======================================================================================================
Script started on Fri 02 Oct 2009 01:47:10 AM EDT
[loki.cs.kent.edu]{1}-> make hello: `hello' is up to date.
[loki.cs.kent.edu]{2}-> gdb hello GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) l
1 #include "helloworld.h"
2
3 int main(){
4 hello_world();
5 return 0;
6 }
(gdb) b 4
Breakpoint 1 at 0x8048707: file main.cpp, line 4.
(gdb) r
Starting program: /users/cs/faculty/jbaker/cs1-alt/hello
Breakpoint 1, main () at main.cpp:4
4 hello_world();
(gdb) s //step into
function - contrast with n (next)
hello_world () at helloworld.cpp:9
9 for (i=0;i<10;i++)
(gdb) l
4
5 void mytry(int x[]);
6
7 void hello_world(){
8 int a[10], i;
9 for (i=0;i<10;i++)
10 a[i] = i;
11 cout << "Hello World!\n";
12 mytry(a);
13 }
(gdb) b 11
Breakpoint 2 at 0x80487f7: file helloworld.cpp, line 11.
(gdb) c
Continuing.
Breakpoint 2, hello_world () at helloworld.cpp:11
11 cout << "Hello World!\n";
(gdb) display a //show a as an array
1: a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
(gdb) set variable a[3]=100 //you can change
values while in gdb
(gdb) display a
2: a = {0, 1, 2, 100, 4, 5, 6, 7, 8, 9}
(gdb) c
Continuing.
Hello World!
0
1
2
100
4
5
6
7
8
9
Program exited normally.
(gdb) quit
[loki.cs.kent.edu]{3}-> exit exit
Script done on Fri 02 Oct 2009 01:48:51 AM EDT