Linux GDB Commands
Linux GDB Commands
# gcc -c program1.c
program2.c library.c
# ld program1.o library.o -o
4 gcc -c program1
# ld program2.o library.o -o
program2
5 Gcc Gcc -g
12 (gdb) run
13 (gdb) n
14 (gdb) s
15 (gdb) bt
16 (gdb) p
17 (gdb) l (list)
18 (gdb) c
19 (gdb) quit
20 (gdb) program
25 (gdb) -h
29 (gdb) kill
38 info program
39 watchpoints
40 watch expr
41 rwatch expr
42 awatch expr
43 Stack Examining the stack
44 frame args
45 select-frame
46 bt
47 bt n
48 bt -n
49 frame n
50 f addr
51 up n
52 down n
53 info f
54 f
55 info f addr
56 info args
57 info locals
58 info catch
63 info registers
64 info float
65 info vector
66 Trace tracepoints
67 trace
68 tr foo.c:121
69 tr +2
70 tr my_function
71 tr *my_function
72 tr *0x2117c4
73 delete trace 1 2 3
74 delete
75 actions
76 tstart
77 tstop
78 tstatus
81 target
82 run
83 attach
84 help target name
85 target exec program
86 target core filename
87 target remote dev
89 load filename
92 Gdbserver Gdbserver
On the target Target> gdbserver comm
93
machine program [args ...]
Target> gdbserver
94
/dev/com1 emacs foo.txt
Target> gdbserver
95
host:2345 emacs foo.txt
On the GDB host
96 (gdb) --baud
machine
(gdb) Target remote
97
/dev/ttyb
(gdb) target remote the-
98
target:2345
99
100
Description 2
The option -o specifies the name of the executable to be
produced, which traditionally has no extension.
gcc offers three levels of optimization: -O1 (or -O), -O2, and
-O3.
Use the gnu profiler gprof, which measures the time spent
in each routine during execution.
The gcc option -pg compiles in the hooks necessary for the
gnu profiler to perform its measurements. When run, the
executable produces the file gmon.out containing the
profile informaton; gprof reads this file to produce a report
containing the profile information. Very useful!
You can use the -c option to have gcc compile files into an
objects rather than executables. Object files need not
contain a main routine, so you can collect libraries of
routines which may be useful to multiple programs into
object files. You can then use ld to link the required object
files together into an executable, without having to
recompile the libraries.