这部分代码,主要参考自用GDB追踪glibc代码执行过程。感谢作者的分享,让我可以继续我的NPTL 线程栈和TLS的分析。希望近期能完成这个NPTL的学习。
值得一提的是,分析Ubuntu提供的patch,可以看到,glibc查看版本号一节中的输出中含有Ubuntu EGLIC的原因:
-rw-r--r-- 1 root root 10368576 1月 28 19:03 eglibc_2.15-0ubuntu10.4.diff
centos中默认情况下库函数是不带调试信息的,所以用gdb无法进入到printf()函数里。
解决办法是:
1.为libc安装调试信息
a. 先要安装一个命令:sudo yum install /usr/bin/debuginfo-install
b. 设置一下repos: vi /etc/yum.repos.d/CentOS-Debuginfo.repo, 把enabled设置为1
c. 为标准库安装调试信息: sudo debuginfo-install glibc
2.再来一次gdb并进入printf()函数即可. 我这里看到的第一行代码是
_IO_size_t len = strlen (str);
oot@localhost yum.repos.d]# ls
adobe-linux-i386.repo CentOS-Debuginfo.repo mirrors-rpmforge-extras
CentOS-Base-163.repo CentOS-Media.repo mirrors-rpmforge-testing
CentOS-Base.repo CentOS-Vault.repo rpmforge.repo
CentOS-Base.repo.bak mirrors-rpmforge
[root@localhost yum.repos.d]# vi CentOS-Debuginfo.repo
[root@localhost yum.repos.d]# cat CentOS-Debuginfo.repo
# CentOS-Debuginfo.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# All debug packages from all the various CentOS-5 releases
# are merged into a single repo, split by BaseArch
#
# Note: packages in the debuginfo repo are currently not signed
#
[debug]
name=CentOS-5 - Debuginfo
baseurl=
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
enabled=1
[root@localhost yum.repos.d]# cd
[root@localhost ~]# debuginfo-install glibc-2.5-107
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* addons: mirror.bit.edu.cn
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* rpmforge: mirror-fpt-telecom.fpt.net
* updates: mirror.bit.edu.cn
debug | 1.9 kB 00:00
debug/primary_db | 2.8 MB 00:14
Checking for new repos for mirrors
--> Running transaction check
---> Package glibc-debuginfo.i686 0:2.5-107 set to be updated
--> Processing Dependency: glibc-debuginfo-common = 2.5-107 for package: glibc-debuginfo
--> Running transaction check
---> Package glibc-debuginfo-common.i386 0:2.5-107 set to be updated
--> Finished Dependency Resolution
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
glibc-debuginfo i686 2.5-107 debug 6.2 M
Installing for dependencies:
glibc-debuginfo-common i386 2.5-107 debug 12 M
Transaction Summary
================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 18 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): glibc-debuginfo-2.5-107.i686.rpm | 6.2 MB 00:26
(2/2): glibc-debuginfo-common-2.5-107.i386.rpm | 12 MB 00:33
--------------------------------------------------------------------------------
Total 301 kB/s | 18 MB 01:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : glibc-debuginfo-common 1/2
Installing : glibc-debuginfo 2/2
Installed:
glibc-debuginfo.i686 0:2.5-107
Dependency Installed:
glibc-debuginfo-common.i386 0:2.5-107