Root @ Ubuntu:/home/libz/share/project/gdb_test # GDB./gdb_test.elf-Q
Reading symbols from/home/libz/share/project/gdb_test/gdb_test.elf... done.
(GDB) Break func
Breakpoint 1 at 0x8048946: file./gdb_test.c, Line 36.
(GDB) r
Starting program:/home/libz/share/project/gdb_test/gdb_test.elf
[Thread Debugging Using libthread_db enabled]
[New thread 0xb7fecb70 (lwp 29620)]
[Switching to thread 0xb7fecb70 (lwp 29620)]
Breakpoint 1, func () at./gdb_test.c: 36
36 pthread_mutex_lock (& g_mutex_thread );
(GDB) info breakpoints
Num type disp ENB address what
1 breakpoint keep Y 0x08048946 in func at./gdb_test.c: 36
Breakpoint already hit 1 time
(GDB) delete 1
(GDB) L
31 {
32 static int32_t i32num = 0;
33 static char P [10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G ', 'H', 'I', 'J '};
34
35 while (1 ){
36 pthread_mutex_lock (& g_mutex_thread );
37
38 printf ("g_stpid = [% d] i32num = [% d] \ n", (uint32_t) g_stpid, i32num ++ );
39
40 pthread_mutex_unlock (& g_mutex_thread );
(GDB)
41 sleep (1 );
42}
43}
44
45 void create_thread (void)
46 {
47 pthread_attr_t stattr;
48 struct sched_param sched_proi;
49
50 memset (& sched_proi, 0x0, sizeof (sched_proi ));
(GDB) S
_ Pthread_mutex_lock (mutex = 0x804a0d4) at pthread_mutex_lock.c: 47
47 pthread_mutex_lock.c: no such file or directory.
In pthread_mutex_lock.c
(GDB) Finish
Run till exit from #0 _ pthread_mutex_lock (mutex = 0x804a0d4) at pthread_mutex_lock.c: 47
Func () at./gdb_test.c: 38
38 printf ("g_stpid = [% d] i32num = [% d] \ n", (uint32_t) g_stpid, i32num ++ );
Value returned is $1 = 0
(GDB) S
_ Printf (format = 0x8048d90 "g_stpid = [% d] i32num = [% d] \ n") at printf. C: 30
30 printf. C: no such file or directory.
In printf. c
(GDB) Finish
Run till exit from #0 _ printf (format = 0x8048d90 "g_stpid = [% d] i32num = [% d] \ n") at printf. C: 30
G_stpid = [-1208038544] i32num = [0]
Func () at./gdb_test.c: 40
40 pthread_mutex_unlock (& g_mutex_thread );
Value returned is $2 = 37
(GDB) Watch 5 = i32num
Hardware watchpoint 2: 5 = i32num
(GDB) c
Continuing.
G_stpid = [-1208038544] i32num = [1]
G_stpid = [-1208038544] i32num = [2]
G_stpid = [-1208038544] i32num = [3]
Hardware watchpoint 2: 5 = i32num
Old value = 0
New value = 1
0x08048961 in func () at./gdb_test.c: 38
38 printf ("g_stpid = [% d] i32num = [% d] \ n", (uint32_t) g_stpid, i32num ++ );
(GDB) print i32num
$3 = 5
(GDB)