diff options
Diffstat (limited to 'application-devel/app-debugging/handout_app-debugging_de.tex')
| -rw-r--r-- | application-devel/app-debugging/handout_app-debugging_de.tex | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/application-devel/app-debugging/handout_app-debugging_de.tex b/application-devel/app-debugging/handout_app-debugging_de.tex index b082790..dca0e76 100644 --- a/application-devel/app-debugging/handout_app-debugging_de.tex +++ b/application-devel/app-debugging/handout_app-debugging_de.tex @@ -10,11 +10,11 @@ des zu tracenden Programms wird einfach strace vorangestellt: $ strace /bin/ls execve("/bin/ls", ["/bin/ls"], [/* 50 vars */]) = 0 brk(0) = 0x2246000 -access("/etc/ld.so.nohwcap", F_OK) = +access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f32457fe000 -access("/etc/ld.so.preload", R_OK) = +access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=110532, ...}) = 0 @@ -45,14 +45,14 @@ der für alle gängigen Prozessorarchitekturen verfügbar ist. GDB bietet ein sehr mächtiges Commandlineinterface. Es existieren diverse grafische Frontends für GDB (z.B. DDD). Eine einfache Debuggingsession stellt sich wie folgt dar: \begin{lstlisting}[language=c] - /* hello.c */ - #include <stdio.h> - - int main (void) - { - printf("Hello world\n"); - return 0; - } + /* hello.c */ + #include <stdio.h> + + int main (void) + { + printf("Hello world\n"); + return 0; + } \end{lstlisting} Übersetzen des Programms mit Debuginformationen: \begin{lstlisting} @@ -62,7 +62,7 @@ Starten der Debugsession: \begin{lstlisting} $ gdb ./hello (gdb) run -Starting program: /home/jan/work/examples/hello +Starting program: /home/jan/work/examples/hello Hello world Program exited normally. @@ -71,13 +71,13 @@ Mit dem Kommando ''list'' kann der zugehörige Quellcode angezeigt werden. Breakpoints werden mit ''break'' gesetzt: \begin{lstlisting} (gdb) list -1 #include <stdio.h> -2 -3 int main (void) -4 { -5 printf("Hello world\n"); -6 return 0; -7 } +1 #include <stdio.h> +2 +3 int main (void) +4 { +5 printf("Hello world\n"); +6 return 0; +7 } (gdb) break 5 Breakpoint 1 at 0x400528: file hello.c, line 5. \end{lstlisting} @@ -85,14 +85,14 @@ Mit ''next'' und ''step'' werden einzelne Codezeilen ausgeführt, während ''next'' einem step-OVER und ''step'' einem step-IN entspricht: \begin{lstlisting} (gdb) run -Starting program: /home/jan/work/examples/hello +Starting program: /home/jan/work/examples/hello Breakpoint 1, main () at hello.c:5 -5 printf("Hello world\n"); +5 printf("Hello world\n"); (gdb) next Hello world -6 return 0; -(gdb) continue +6 return 0; +(gdb) continue Continuing. \end{lstlisting} Folgende Tabelle zeigt eine Übersicht der wichtigsten GDB Kommandos:\\ @@ -162,14 +162,14 @@ können hier verwendet werden: \end{center} Folgendes Beispiel verdeutlicht die Analyse eines core-Files: \begin{lstlisting}[language=c] - /* segfault.c */ - #include <stdio.h> - - int main (void) - { - char *arthur_dent = NULL; - printf("%c\n", *arthur_dent); - return 0; + /* segfault.c */ + #include <stdio.h> + + int main (void) + { + char *arthur_dent = NULL; + printf("%c\n", *arthur_dent); + return 0; } \end{lstlisting} Programm übersetzen: @@ -197,7 +197,7 @@ Loaded symbols for /lib64/ld-linux-x86-64.so.2 Core was generated by `./segfault'. Program terminated with signal 11, Segmentation fault. #0 0x0000000000400538 in main () at segfault.c:6 -6 printf("%c\n", *arthur_dent); +6 printf("%c\n", *arthur_dent); (gdb) bt #0 0x0000000000400538 in main () at segfault.c:6 \end{lstlisting} @@ -351,12 +351,12 @@ int main(void) { int *my_array = (int*) malloc(10 * sizeof(int)); int i = 0; - memset(my_array, 0, 10); + memset(my_array, 0, 10); for(i = 0; i < 11; i++) printf("%d ", my_array[i]); - printf("\n"); + printf("\n"); return 0; } \end{lstlisting} @@ -444,7 +444,7 @@ $ valgrind --leak-check=full ./mem_leak =5764= Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info =5764= Command: ./mem_leak -=5764= +=5764= =5764= HEAP SUMMARY: =5764= in use at exit: 49 bytes in 49 blocks =5764= total heap usage: 50 allocs, 1 frees, @@ -453,7 +453,7 @@ $ valgrind --leak-check=full ./mem_leak =5764= loss record 1 of 1 =5764= at 0x4C274A8: malloc (vg_replace_malloc.c:236) =5764= by 0x40058D: main (mem_leak.c:10) -=5764= +=5764= =5764= LEAK SUMMARY: =5764= definitely lost: 49 bytes in 49 blocks [...] |
