Tuesday, October 21, 2008

GCC Options and GDB notes

gcc example.c [options]

-S - Compiles and stops. Output is assembler code (suffix .S).
-o [name] - Gives executable as 'name'.
-E - Preprocess source file only.
    Comments will be discared unless -C is also specified.
    Creates #line directives unless -P is also specified.
-M - The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files,including those coming from -include or -imacros command line options.
-W - Print extra warning messages.
    -Wall print all warnings


Example:
cat > example.c << EOF
#include <stdio.h>
#include <string.h>

int main()
{
printf("Hello world");
}
EOF
#


GDB notes:

Compile C code with -g option and run 'gdb a.out'
In gdb prompt set the break point as 'break main' or any function.
To run 'run '
To watch the particular variable set 'watch ' and if the variable get modified then it will get notified
To see the local variables 'info local'
To proceed next line 'n or next'
list to display the source code

No comments: