development using foss tools - indian statistical institutemandar/misc/development-tools.pdf ·...
TRANSCRIPT
![Page 1: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/1.jpg)
Development using FOSS tools
Mandar Mitra
Indian Statistical Institute
M. Mitra (ISI) Development using FOSS tools 1 / 34
![Page 2: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/2.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 2 / 34
![Page 3: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/3.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 3 / 34
![Page 4: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/4.jpg)
Languages
+ perl, bash/shell scripts, awk, sed, grep, . . .
M. Mitra (ISI) Development using FOSS tools 4 / 34
![Page 5: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/5.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 5 / 34
![Page 6: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/6.jpg)
GCC: commonly used flags
What to generate?-o: specify output file
.
...... gcc -o program program.c ⇒ program
-c: compile / assemble but do not link....... gcc -c program.c ⇒ program.o
useful when combining multiple source files into executable / library
-S: generate assembly....... gcc -S program.c ⇒ program.s
-fverbose-asm: put extra commentary information in the generatedassembly code to make it more readable (useful if you actuallyneed to read the generated assembly code)
M. Mitra (ISI) Development using FOSS tools 6 / 34
![Page 7: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/7.jpg)
GCC: commonly used flags
-g: produces debugging information in the operating system’snative format
.
...... gcc -g -o program program.c
-Wall, -Wextra: enables all the warnings about constructions thatsome users consider questionable, and that are [usually] easy toavoid (or modify to prevent the warning)
.
...... gcc -Wall -g -o program program.c
-O, -O2: optimise the compiled code
M. Mitra (ISI) Development using FOSS tools 7 / 34
![Page 8: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/8.jpg)
GCC: warnings
Check calls to printf and scanf, etc., to make sure that thearguments supplied have types appropriate to the format stringspecifiedWarn if parentheses are omitted in certain contextsWarn when a declaration does not specify a type (assumed int)Warn whenever a function is defined without a return-type, or onreturn type mismatchesWarn if an automatic variable is used without first being initialized. . .
M. Mitra (ISI) Development using FOSS tools 8 / 34
![Page 9: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/9.jpg)
GCC: warnings
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[ ])
{ int i, j;
printf("%c\n", "not a character");
if (i = 10)
if (j != 10)
printf("another oops\n");
else
no_decl();
return(EXIT_SUCCESS);
}
void no_decl(void) { printf("no_decl\n"); }
M. Mitra (ISI) Development using FOSS tools 9 / 34
![Page 10: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/10.jpg)
GCC: warnings
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[ ]) // return type defaults to int
{ int i, j;
printf("%c\n", "not a character"); // wrong argument type
if (i = 10) // parentheses!
if (j != 10) // uninitialised j
printf("another oops\n");
else // ambiguous else
no_decl(); // implicit declaration
return(EXIT_SUCCESS);
}
void no_decl(void) { printf("no_decl\n"); }
M. Mitra (ISI) Development using FOSS tools 10 / 34
![Page 11: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/11.jpg)
GCC: other flags
Libraries, etc.-I: add a directory to the head of the list of directories to besearched for header files-L: add a directory to the list of directories to be searched forlinked libraries-l: search the named library when linking
order is important
.
...... gcc -I/a/b/include -L/a/b/lib -o program program.c -lm
M. Mitra (ISI) Development using FOSS tools 11 / 34
![Page 12: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/12.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 12 / 34
![Page 13: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/13.jpg)
GDB: getting started
To debug a program a.out:
$ gdb a.out
To start running the program:
(gdb) run
To find out where a fault occurred:
(gdb) where
(gdb) backtrace
To view code around this point:
(gdb) list
Can use unambiguous abbreviations
M. Mitra (ISI) Development using FOSS tools 13 / 34
![Page 14: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/14.jpg)
GDB: example
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char **argv)
5 {
6 char *buf;
7
8 buf = malloc(1<<31);
9
10 fgets(buf, 1024, stdin);
11 printf("%s\n", buf);
12
13 return 1;
14 }
M. Mitra (ISI) Development using FOSS tools 14 / 34
![Page 15: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/15.jpg)
GDB: example
$ gdb segfault
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
...
Reading symbols from /home/mandar/Dropbox/present/linux/examples/segfault...done.
(gdb) r
Starting program: /home/mandar/Dropbox/present/linux/examples/segfault
hallo
Program received signal SIGSEGV, Segmentation fault.
_IO_getline_info (fp=0x7ffff7dd4340, buf=0x0, n=1023, delim=10,
extract_delim=1, eof=0x0) at iogetline.c:91
91 iogetline.c: No such file or directory.
(gdb) bt
#0 _IO_getline_info (fp=0x7ffff7dd4340, buf=0x0, n=1023, delim=10,
extract_delim=1, eof=0x0) at iogetline.c:91
#1 0x00007ffff7a8bafb in _IO_fgets (buf=0x0, n=<optimized out>,
fp=0x7ffff7dd4340) at iofgets.c:58
#2 0x00000000004005fe in main (argc=1, argv=0x7fffffffd6c8) at
segfault.c:10
(gdb)
M. Mitra (ISI) Development using FOSS tools 15 / 34
![Page 16: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/16.jpg)
GDB: breakpoints
To stop a program at a particular position:
(gdb) break main
(gdb) break 8
(gdb) break segfault.c:8
To continue running the program:
(gdb) continue
To continue execution one step at a time:
(gdb) next
(gdb) step
To continue execution until end of a called function:
(gdb) finish
M. Mitra (ISI) Development using FOSS tools 16 / 34
![Page 17: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/17.jpg)
GDB: more commands
To navigate between functions (stack frames)
(gdb) up
(gdb) down
(gdb) frame 2
To see values of variables
(gdb) print buf
M. Mitra (ISI) Development using FOSS tools 17 / 34
![Page 18: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/18.jpg)
GDB: example
(gdb) b main
Breakpoint 1 at 0x4005d3: file segfault.c, line 8.
(gdb) r
Starting program: /home/mandar/Dropbox/present/linux/examples/segfault
Breakpoint 1, main (argc=1, argv=0x7fffffffd6c8) at segfault.c:8
8 buf = malloc(1<<31);
(gdb) n
10 fgets(buf, 1024, stdin);
(gdb)
M. Mitra (ISI) Development using FOSS tools 18 / 34
![Page 19: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/19.jpg)
GDB: example
(gdb) cont
Continuing.
abc
Program received signal SIGSEGV, Segmentation fault.
_IO_getline_info (fp=0x7ffff7dd4340, buf=0x0, n=1023, delim=10,
extract_delim=1, eof=0x0) at iogetline.c:91
91 iogetline.c: No such file or directory.
(gdb) frame 2
#2 0x00000000004005fe in main (argc=1, argv=0x7fffffffd6c8) at segfault.c:10
10 fgets(buf, 1024, stdin);
(gdb) p buf
$1 = 0x0
M. Mitra (ISI) Development using FOSS tools 19 / 34
![Page 20: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/20.jpg)
GDB: example
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char **argv)
5 {
6 char *buf;
7
8 buf = malloc(1<<31);
9
10 fgets(buf, 1024, stdin);
11 printf("%s\n", buf);
12
13 return 1;
14 }
M. Mitra (ISI) Development using FOSS tools 20 / 34
![Page 21: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/21.jpg)
GDB: more about breakpoints
(gdb) break file1.c:6 if i >= ARRAYSIZE
(gdb) condition 1 (i >= ARRAYSIZE)
(gdb) delete 1 (use (optional) breakpoint number)
(gdb) clear main (use breakpoint location)(gdb) disable 1
(gdb) enable 1
(gdb) tbreak
(gdb) info breakpoints
M. Mitra (ISI) Development using FOSS tools 21 / 34
![Page 22: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/22.jpg)
GDB: more about printing
print accepts expressions (including type casts, &, *, etc.)
(gdb) print (char) x
To print an array:
(gdb) print buffer[2]@16
To find out type of a variable:
(gdb) whatis buf
(gdb) ptype argc
M. Mitra (ISI) Development using FOSS tools 22 / 34
![Page 23: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/23.jpg)
GDB: watchpoints
To stop execution whenever the value of an expression changes:
(gdb) watch x
(gdb) watch *(int *)0x12345678
(gdb) watch a*b + c/d
To stop execution when an expression is read by the program:
(gdb) rwatch x
To stop execution when an expression is read / written:
(gdb) awatch x
M. Mitra (ISI) Development using FOSS tools 23 / 34
![Page 24: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/24.jpg)
GDB: odds and ends
Type control-C to interrupt an infinite loopUse quit or control-D to exitType return to repeat previous command(gdb) help <command name>
M. Mitra (ISI) Development using FOSS tools 24 / 34
![Page 25: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/25.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 25 / 34
![Page 26: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/26.jpg)
dmalloc
http://dmalloc.com/
In source: #include "dmalloc.h"
Link the dmalloc library into your program.Output:not freed: ’0x45048’ (10 bytes) from ’argv.c:1077’
WARNING: tried to free(0) from foo.c:708
ERROR: heap check: free space was overwritten
M. Mitra (ISI) Development using FOSS tools 26 / 34
![Page 27: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/27.jpg)
Valgrind
http://valgrind.org/
Usage: valgrind leak-check=yes myprog arg1 arg2
Output:==19182== Invalid write of size 4
==19182== at 0x804838F: f (example.c:6)
==19182== by 0x80483AB: main (example.c:11)
==19182== Address 0x1BA45050 is 0 bytes after a block of size 40 alloc’d
==19182== at 0x1B8FF5CD: malloc (vg_replace_malloc.c:130)
==19182== by 0x8048385: f (example.c:5)
==19182== by 0x80483AB: main (example.c:11)
M. Mitra (ISI) Development using FOSS tools 27 / 34
![Page 28: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/28.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 28 / 34
![Page 29: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/29.jpg)
Editors
bluefish http://bluefish.openoffice.nl/index.html
gedit http://projects.gnome.org/gedit/jEdit http://www.jedit.org/kate http://kate-editor.org/
nano http://www.nano-editor.org/
SciTE http://www.scintilla.org/SciTE.html
vim http://www.vim.org/
http://en.wikipedia.org/wiki/Comparison_of_text_editors
M. Mitra (ISI) Development using FOSS tools 29 / 34
![Page 30: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/30.jpg)
Outline
1 Languages
2 Compiling
3 Debugging
4 Memory related tools
5 Editors
6 IDEs
M. Mitra (ISI) Development using FOSS tools 30 / 34
![Page 31: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/31.jpg)
IDEs
Eclipse http://www.eclipse.org/
Geany http://www.geany.org/
KDevelop http://kdevelop.org/
NetBeans http://netbeans.org/
M. Mitra (ISI) Development using FOSS tools 31 / 34
![Page 32: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/32.jpg)
Emacs
Content-sensitive editing modes, including syntax coloringHighly customizable, using Emacs LispMany extensionsComplete built-in documentation, including a tutorial for new usersFull Unicode support for nearly all human languages and theirscripts
M. Mitra (ISI) Development using FOSS tools 32 / 34
![Page 33: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/33.jpg)
Others
Automatic compiling / building tools: make, antVersion control systems: bazaar, cvs, git, mercurial, subversionBug tracking: bugzilla, trac
M. Mitra (ISI) Development using FOSS tools 33 / 34
![Page 34: Development using FOSS tools - Indian Statistical Institutemandar/misc/development-tools.pdf · Geany ... including a tutorial for new users ... M. Mitra (ISI) Development using FOSS](https://reader031.vdocument.in/reader031/viewer/2022021910/5c00c87509d3f2fa038ba7aa/html5/thumbnails/34.jpg)
References
Overview:http://www.slideshare.net/sagara10/foss-tools
GCChttp://www.pearsonhighered.com/samplechapter/0672320215.pdf
GDBhttp://www.dirac.org/linux/gdb/
Search for “gdb tutorial”Editorshttp://en.wikipedia.org/wiki/List_of_text_editors
http://www.linuxlinks.com/article/20080824052425167/Editors.html
http://tuxarena.blogspot.in/2009/04/
14-most-popular-text-editors-for-linux.html
IDEshttp://en.wikipedia.org/wiki/Comparison_of_integrated_development_
environments
http://www.linuxlinks.com/article/20090620114618990/IDE.html
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
http://www.mojavelinux.com/wiki/doku.php?id=javaidecomparison
M. Mitra (ISI) Development using FOSS tools 34 / 34