所以我正在做一个实验室任务,我们基本上是在调试一个旧版本的coreutils ls。我跑了info functions
。输出行中有static int compare_mtime(V, V);
。然后我运行list compare_mtime
来查看源代码,并输出以下内容:
(gdb) list compare_mtime
43 /* Return negative, zero, positive if A < B, A == B, A > B, respectively.
44 Assume the nanosecond components are in range, or close to it. */
45 static inline int
46 timespec_cmp (struct timespec a, struct timespec b)
47 {
48 int diff = a.tv_sec - b.tv_sec;
49 return diff ? diff : a.tv_nsec - b.tv_nsec;
50 }
51
52 # if ! HAVE_DECL_NANOSLEEP
显然,timespec_cmp
不是compare_mtime
。为什么要打印timespec_cmp
而不是compare_mtime
?
EXTRA INFO
我通过在compare_mtime设置断点并运行程序进一步调查:
Breakpoint 1, compare_mtime (a=0x617160, b=0x617210) at ls.c:2884
2884 static int compare_mtime (V a, V b) { return cmp_mtime (a, b, xstrcoll); }
所以很明显compare_mtime只调用cmp_mtime。继续,我在cmp_mtime设置了另一个断点:
(gdb) break cmp_mtime
Note: breakpoint 1 also set at pc 0x4070d3.
Note: breakpoint 1 also set at pc 0x4070a0.
Breakpoint 2 at 0x405223: cmp_mtime. (4 locations)
重新运行程序永远不会在Breakpoint 2停止。list cmp_mtime
输出与list compare_mtime
相同的内容。