2016-05-19 21 views
6

Vui lòng xem dòng lệnh bên dưới. Tôi đặt hai điểm ngắt: một điểm trên strcpy và cái kia trên printf. Tại sao nó bỏ qua breakpoint 1?Tại sao gdb không phá vỡ trên strcpy?

[email protected]:~/Desktop/Programs# gcc -g -o exp exp.c 
[email protected]:~/Desktop/Programs# gdb -q exp 
Reading symbols from /root/Desktop/Programs/exp...done. 
(gdb) list 
1 #include <stdio.h> 
2 #include <string.h> 
3 
4 int main() { 
5  char str_a[20]; 
6  
7  strcpy(str_a, "Hello world!\n"); 
8  printf(str_a); 
9 } 
(gdb) break strcpy 
Function "strcpy" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) y 
Breakpoint 1 (strcpy) pending. 
(gdb) break printf 
Breakpoint 2 at 0x8048300 
(gdb) run 
Starting program: /root/Desktop/Programs/exp 

Breakpoint 2, 0xb7eabf54 in printf() from /lib/i386-linux-gnu/i686/cmov/libc.so.6 
(gdb) i r eip 
eip   0xb7eabf54 0xb7eabf54 <printf+4> 
(gdb) cont 
Continuing. 
Hello world! 
[Inferior 1 (process 3726) exited with code 015] 
+7

Nó có thể được tối ưu hóa và giảm xuống mã nội tuyến không phải là cuộc gọi hàm thực sự. Thử biên dịch không có tối ưu hóa. – Rohan

+0

@Rohan Tôi đã sử dụng 'gcc -g -O0 -o exp exp.c' nhưng nó không hoạt động. –

+4

@ W.Zhu Kiểm tra mã lắp ráp. Bạn sẽ thấy rằng ngay cả với '-O0' không có lệnh gọi' strcpy'. – kaylum

Trả lời

0

Điểm ngắt đầu tiên đang chờ xử lý.

(gdb) break strcpy 
Function "strcpy" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) y 
Breakpoint 1 (strcpy) pending.             <<here 

thử: (gdb) break 7

7 là số dòng.

Các vấn đề liên quan