about summary refs log tree commit diff stats
path: root/dev/c/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'dev/c/index.html')
-rw-r--r--dev/c/index.html199
1 files changed, 133 insertions, 66 deletions
diff --git a/dev/c/index.html b/dev/c/index.html
index 1c3b478..aeff035 100644
--- a/dev/c/index.html
+++ b/dev/c/index.html
@@ -1,102 +1,169 @@
 <!DOCTYPE html>
 <html dir="ltr" lang="en">
     <head>
-        <meta charset='utf-8'>
-        <title>C &amp; GDB</title>
+	<meta charset='utf-8'>
+	<title>C &amp; GDB</title>
     </head>
     <body>
-        <a href="../index.html">Development Index</a>
+	<a href="../index.html">Development Index</a>
 
-        <h1>C &amp; GDB</h1>
+	<h1>C &amp; GDB</h1>
 
-        <p><a href="http://blog.fourthbit.com/2013/06/18/creating-an-open-source-program-in-c-with-autotools-part-1-of-2/">C program with autotools</a>
-        </p>
+	<h2 id="hello">Hello World</h2>
 
-        <pre>
-        $ touch NEWS README AUTHORS ChangeLog
-        $ mkdir -p src/bin src/lib
-        </pre>
+	<p>Create file hello.c with;</p>
 
-        <p>
-        <a href="http://web.eecs.umich.edu/~sugih/pointers/gdbQS.html">GDB Quick Start</a>,
-        <a href="https://www.hackerschool.com/blog/5-learning-c-with-gdb">Learning C with GDB</a>
-        and <a href="http://www.dirac.org/linux/gdb/02a-Memory_Layout_And_The_Stack.php">Memory Layout and the Stack</a>
-        are great sources of introductory information.</a>
-        </p>
+	<pre>
+	#include &lt;stdio.h&gt;
 
-        <p>To use gdb you need to compile program with -g flag. To
-        debug a program;</p>
+	int main() {
+	    printf("Hello World!");
+	    return 0;
+	}
+	</pre>
 
-        <pre>
-        gdb program
-        </pre>
+	<p>Compile;</p>
 
-        <p>If the program needs arguments you can set it;</p>
+	<pre>
+	$ gcc -Wall hello.c -o hello
+	</pre>
 
-        <pre>
-        (gdb)set args -parameter1 -parameter2
-        </pre>
+	<p>Run;</p>
 
-        <p>To start the program you can type run, this way gdb
-        will try to run the program until the end. If program
-        crash, gdb will stop it for debuging.</p>
+	<pre>
+	$./hello
+	Hello World!
+	</pre>
 
-        <pre>
-        (gdb) run
-        </pre>
+	<h2 ="sources">Multiple Sources</h2>
 
-        <pre>
-        n - execute next line
-        s - step in next line
-        b - backtrace
-        info locals
-        print
-        x
-        </pre>
+	<p>To organize code in multiple files split above
+	example in main.c, hello.c and hello.h. Content of
+	main.c;<p>
 
-        <h2>SysCalls</h2>
+	<pre>
+	#include "hello.h"
 
-        <pre>catch syscall open</pre>
+	int main() {
+	    hello("world");
+	    return 0;
+	}
+	</pre>
 
-        <h2>Threads</h2>
+	<p>Header file contains declaration of the function hello,
+	content of hello.h;</p>
 
-        <p>When new thread is created you receive
-        a notification. To get information about
-        threads;</p>
+	<pre>
+	void hello(const char* name);
+	</pre>
 
-        <pre>
-        info threads
-        </pre>
+	<p>Implementation of hello function in hello.c;</p>
 
-        <p>To select thread;</p>
+	<pre>
+	#include &lt;stdio.h&gt;
+	#include "hello.h"
 
-        <pre>
-        thread 1
-        </pre>
+	void hello(const char* name) {
+	    printf("Hello, %s!\n", name);
+	}
+	</pre>
+
+	<p>Compile;</p>
+
+	<pre>
+	$ gcc -Wall main.c hello.c -o hello
+	</pre>
+
+	<h2 id="makefile">Makefile</h2>
+
+	<p>Make reads a Makefile by default on current directory,
+	Makefile defines targets, for example executables and their
+	dependencies, for example object files and source files.<p>
+
+	<p>Create Makefile;</p>
 
-        <p><a href="http://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_39.html#SEC40">Stopping and Starting</a>
-        multi-thread programs</p>
+	<pre>
+	CC=gcc
+	CFLAGS=-Wall
+
+	hello: main.o hello.o
+
+	clean:
+		rm -f hello main.o hello.o
+	</pre>
+
+	<pre>
+	$ touch NEWS README AUTHORS ChangeLog
+	</pre>
+
+	<h2 id="debug">Debug</h2>
+
+	<p>To use gdb you need to compile program with -g flag. Change
+	Makefile</p>
+
+	<pre>
+	CC=gcc
+	CFLAGS=-Wall -g
+
+	hello: main.o hello.o
+
+	clean:
+		rm -f hello main.o hello.o
+	</pre>
+
+	<pre>
+	$ gdb hello
+	</pre>
+
+	<p>Set break point;</p>
+
+	<pre>
+	(gdb) break main
+	</pre>
+
+	<p>To start the program you can type run, this way gdb
+	will try to run the program until the end. If program
+	crash, gdb will stop it for debuging. Start program;</p>
+
+	<pre>
+	(gdb) run
+	</pre>
+
+	<p>Step in next line;</p>
+
+	<pre>
+	(gdb) s
+	</pre>
+
+        <p>Print variable "name" value;</p>
 
         <pre>
-        break linespec thread threadno
+        (gdb) print name
+        $1 = 0x4005b0 "world"
+        (gdb)
         </pre>
 
-        <h2>Strace</h2>
+        <p>Print variable "name" type;</p>
 
         <pre>
-        strace -c ./program
+        (gdb) ptype name
+        type = const char *
+        (gdb)
         </pre>
 
-        <a href="../index.html">Development Index</a>
-        <p>
-        This is part of the c9-doc Manual.
-        Copyright (C) 2016
-        c9 team.
-        See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
-        for copying conditions.</p>
+        <p>Variable is a <a href="elements.html#const">string constant</a>.
+        Execute next line to end;</p>
 
+	<pre>
+	(gdb) n
+	</pre>
 
+	<a href="../index.html">Development Index</a>
+	<p>
+	This is part of the c9-doc Manual.
+	Copyright (C) 2016
+	c9 team.
+	See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
+	for copying conditions.</p>
     </body>
-
 </html>
-