VMwareFusionのCentOS6.5にVMware Toolsを再インストール(追記)

http://d.hatena.ne.jp/kazuokohchi/20150704

に書いた件の追記。
今回VMwareFusion7からVMwareFution8にアップグレードしてから、同様にCentOSVMware Toolsをインストールしようとしたら、以下のように「VMware Toolsの再インストール」のメニューがなかった(「VMware Toolsのインストール」がグレイアウトという状態)。

試しに一度、CentOSをshutdownして再度起動したところ表示された。。。。

あとは以前書いたとおり、「VMware Toolsの再インストール」を選択後、マウントされたことを確認してインストールスクリプトを実行して完了。

$ df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      18134344 7080440  10132716  42% /
tmpfs                   953272      80    953192   1% /dev/shm
/dev/sda1               495844  126913    343331  27% /boot
/dev/sr0                 71704   71704         0 100% /media/VMware Tools
$ cd /media/VMware\ Tools/
$ ls
VMwareTools-10.0.1-3160059.tar.gz  vmware-tools-upgrader-32
manifest.txt                       vmware-tools-upgrader-64
run_upgrader.sh
$ pwd
/media/VMware Tools
$ ls -l
合計 71352
-r--r--r-- 1 kohchi kohchi 71613955 1019 04:34 2015 VMwareTools-10.0.1-3160059.tar.gz
-r-xr-xr-x 1 kohchi kohchi     1994 1019 04:33 2015 manifest.txt
-r-xr-xr-x 1 kohchi kohchi     1850 1019 04:15 2015 run_upgrader.sh
-r-xr-xr-x 1 kohchi kohchi   687524 1019 04:17 2015 vmware-tools-upgrader-32
-r-xr-xr-x 1 kohchi kohchi   757944 1019 04:20 2015 vmware-tools-upgrader-64
$ cp -ip VMwareTools-10.0.1-3160059.tar.gz /tmp
$ cd /tmp
$ zcat VMwareTools-10.0.1-3160059.tar.gz | tar xf -
$ cd vmware-tools-distrib/
$ su
パスワード:
# ./vmware-install.pl
A previous installation of VMware Tools has been detected.

The previous installation was made by the tar installer (version 4).

Keeping the tar4 installer database format.

You have a version of VMware Tools installed.  Continuing this install will 
first uninstall the currently installed version.  Do you wish to continue? 
(yes/no) [yes] 

Uninstalling the tar installation of VMware Tools.

Stopping services for VMware Tools

Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   Common Agent:                                           [  OK  ]
   VGAuthService:                                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done

This program previously created the directory 
/var/lib/vmware-caf/pme/data/input, and was about to remove it. Since there are
files in that directory that this program did not create, it will not be 
removed.

This program previously created the directory /var/lib/vmware-caf/pme/data, and
was about to remove it. Since there are files in that directory that this 
program did not create, it will not be removed.

This program previously created the directory /usr/lib/vmware-caf/pme/bin, and 
was about to remove it. Since there are files in that directory that this 
program did not create, it will not be removed.

This program previously created the directory /etc/vmware-caf/pme/config, and 
was about to remove it. Since there are files in that directory that this 
program did not create, it will not be removed.

This program previously created the directory /usr/lib/vmware-caf/pme, and was 
about to remove it. Since there are files in that directory that this program 
did not create, it will not be removed.

This program previously created the directory /var/lib/vmware-caf/pme, and was 
about to remove it. Since there are files in that directory that this program 
did not create, it will not be removed.

This program previously created the directory /var/lib/vmware-caf, and was 
about to remove it. Since there are files in that directory that this program 
did not create, it will not be removed.

This program previously created the directory /usr/lib/vmware-caf, and was 
about to remove it. Since there are files in that directory that this program 
did not create, it will not be removed.

This program previously created the directory /etc/vmware-caf/pme, and was 
about to remove it. Since there are files in that directory that this program 
did not create, it will not be removed.

This program previously created the directory /etc/vmware-caf, and was about to
remove it. Since there are files in that directory that this program did not 
create, it will not be removed.

File /etc/pulse/default.pa is backed up to /etc/pulse/default.pa.old.7.

The removal of VMware Tools 10.0.1 build-3160059 for Linux completed 
successfully.

Installing VMware Tools.

In which directory do you want to install the binary files? 
[/usr/bin] 

What is the directory that contains the init directories (rc0.d/ to rc6.d/)? 
[/etc/rc.d] 

What is the directory that contains the init scripts? 
[/etc/rc.d/init.d] 

In which directory do you want to install the daemon files? 
[/usr/sbin] 

In which directory do you want to install the library files? 
[/usr/lib/vmware-tools] 

In which directory do you want to install the common agent library files? 
[/usr/lib] 

In which directory do you want to install the common agent transient files? 
[/var/lib] 

In which directory do you want to install the documentation files? 
[/usr/share/doc/vmware-tools] 

The path "/usr/share/doc/vmware-tools" does not exist currently. This program 
is going to create it, including needed parent directories. Is this what you 
want? [yes] 

The installation of VMware Tools 10.0.1 build-3160059 for Linux completed 
successfully. You can decide to remove this software from your system at any 
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by 
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want 
this program to invoke the command for you now? [yes] 

Initializing...


Making sure services for VMware Tools are stopped.

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done
Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   Common Agent:                                           [  OK  ]
   VGAuthService:                                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]


Found a compatible pre-built module for vmci.  Installing it...


Found a compatible pre-built module for vsock.  Installing it...


The module vmxnet3 has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module pvscsi has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module vmmemctl has already been installed on this system by another 
installer or package and will not be modified by this installer.

The VMware Host-Guest Filesystem allows for shared folders between the host OS 
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish 
to enable this feature? [yes] 

Found a compatible pre-built module for vmhgfs.  Installing it...


Found a compatible pre-built module for vmxnet.  Installing it...


The vmblock enables dragging or copying files between host and guest in a 
Fusion or Workstation virtual environment.  Do you wish to enable this feature?
[yes] 

VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present. This feature can
be enabled/disabled by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no] 

Thinprint provides driver-free printing. Do you wish to enable this feature? 
[yes] 


Disabling timer-based audio scheduling in pulseaudio.

Do you want to enable Guest Authentication (vgauth)? Enabling vgauth is needed 
if you want to enable Common Agent (caf). [yes] 

Do you want to enable Common Agent (caf)? [yes] 



Detected X server version 1.13.0



Distribution provided drivers for Xorg X server are used.

Skipping X configuration because X drivers are not included.

Creating a new initrd boot image for the kernel.

NOTE: both /etc/vmware-tools/GuestProxyData/server/key.pem and 
      /etc/vmware-tools/GuestProxyData/server/cert.pem already exist.
      They are not generated again. To regenerate them by force,
      use the "vmware-guestproxycerttool -g -f" command.

   Starting Virtual Printing daemon:                                   done
   Checking acpi hot plug                                  [  OK  ]
Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                       [  OK  ]
   VM communication interface:                             [  OK  ]
   VM communication interface socket family:               [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   Mounting HGFS shares:                                   [失敗]
   Blocking file system:                                   [  OK  ]
   VMware User Agent:                                      [  OK  ]
   Guest operating system daemon:                          [  OK  ]
   VGAuthService:                                          [  OK  ]
   Common Agent:                                           [  OK  ]
The configuration of VMware Tools 10.0.1 build-3160059 for Linux for this 
running kernel completed successfully.

You must restart your X session before any mouse or graphics changes take 
effect.

You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
command line.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and 
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session; and,
3. Restart your X session.

Enjoy,

--the VMware team

Found VMware Tools CDROM mounted at /media/VMware Tools. Ejecting device 
/dev/sr0 ...
# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      18134344 6840244  10372912  40% /
tmpfs                   953272     232    953040   1% /dev/shm
/dev/sda1               495844  126912    343332  27% /boot
# 

wgetでhttpsを使ってファイルを取得

以下を参考にして証明書無視してwgethttps経由でダウンロードできた。

http://pentan.info/server/linux/wget_error_ssl.html

というのはwordpressのモノは以前はhttpでダウンロードできていたのに、4.3になってからhttpでダウンロードしようとするとhttpsにフォワードしてくれてエラーとなるようだ。

$ wget http://ja.wordpress.org/wordpress-4.3-ja.zip
--2015-08-30 09:38:36--  http://ja.wordpress.org/wordpress-4.3-ja.zip
Resolving ja.wordpress.org... 66.155.40.250, 66.155.40.249
Connecting to ja.wordpress.org|66.155.40.250|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://ja.wordpress.org/wordpress-4.3-ja.zip [following]
--2015-08-30 09:38:37--  https://ja.wordpress.org/wordpress-4.3-ja.zip
Connecting to ja.wordpress.org|66.155.40.250|:443... connected.
ERROR: The certificate of ‘ja.wordpress.org’ is not trusted.
ERROR: The certificate of ‘ja.wordpress.org’ hasn't got a known issuer.
$ wget --no-check-certificate https://ja.wordpress.org/wordpress-4.3-ja.zip
--2015-08-30 09:39:44--  https://ja.wordpress.org/wordpress-4.3-ja.zip
Resolving ja.wordpress.org... 66.155.40.250, 66.155.40.249
Connecting to ja.wordpress.org|66.155.40.250|:443... connected.
WARNING: The certificate of ‘ja.wordpress.org’ is not trusted.
WARNING: The certificate of ‘ja.wordpress.org’ hasn't got a known issuer.
HTTP request sent, awaiting response... 200 OK
Length: 7579949 (7.2M) [application/zip]
Saving to: ‘wordpress-4.3-ja.zip’

wordpress-4.3-ja.zi 100%[=====================>]   7.23M   368KB/s   in 24s    

2015-08-30 09:40:09 (313 KB/s) - ‘wordpress-4.3-ja.zip’ saved [7579949/7579949]

$ md5sum wordpress-4.3-ja.zip 
83c8eb427c21f30aaab1cba73f0d98d9  wordpress-4.3-ja.zip
$

証明書確認なしなので、一応md5を確認して完了とした。

VMware FusionのWindows上で任意のファイル・フォルダを複数選択するには

Windows上での任意複数選択(CTRL+クリック)がMacOS XVMware Fusion上ではできない件。Shift+クリックでまとめて選択はできるけど、任意のファイルを複数選択ってことはできないので意外に不便。これは以下のようにして変更できる。

1. プロファイルを確認

[仮想マシン]->[設定]から[キーボードとマウス]を選択。

使用しているプロファイルを確認する。

2. 環境設定を変更

[VMware Fusion]->[環境設定]を選択し、[キーボードとマウス]を選択する。[キーボードとマウスのプロファイル]で確認したプロファイルに設定し、[副ボタン]のチェックをはずす。

使っているマシンは右クリックが付いているのでいいんだけれどApple純正のマウスやトラックパッドのときは却って右クリックがないので不便かもしれない。

参照サイトは以下

http://www.softantenna.com/wp/mac/ctrl-select-windows-on-vmware-fusion/

HTMLでの外部リソース指定にプロトコルがいらない件

以下の記事を見て省略できるってことを知り驚いた。

http://detarame.moo.jp/2012/08/07/google%E3%81%8C%E6%8E%A8%E8%96%A6%E3%81%99%E3%82%8Bhtml%E3%81%A8css%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0%E6%96%B9%E6%B3%95/
http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml

Google HTML/CSS Style Guideの[Protocol]の[Omit the protocol from embedded resources.]の箇所。

<!-- Not recommended -->
<script src="http://www.google.com/js/gweb/analytics/autotrack.js"></script>
<!-- Recommended -->
<script src="//www.google.com/js/gweb/analytics/autotrack.js"></script>
/* Not recommended */
.example {
  background: url(http://www.google.com/images/example);
}
/* Recommended */
.example {
  background: url(//www.google.com/images/example);
}

マジか。httpからhttpsへの変更、またはその逆で以前修正していたことを思い出しちょっと悲しくなった。
上記リンクではその他にも有能なtipsが載っている。

VMware Fustion7上のCentOS6.5にVMware Toolsを再インストール

VMware FusionをアップグレードしてからCentOSを起動していなかったのでVMware Toolsを再インストールしていなかった。そのため、ホストOSとゲストOS間でのコピペがうまくいかない(これが一番痛い)ので再インストールを実施。

1. メニューの[仮想マシン]の[VMware Toolsの再インストール]を選択。

2. ダイアログがでてくるので[インストール]をクリック。

3. メニューの[仮想マシン]では[VMware Toolsのインストールをキャンセル]となっている。

4. /media/VMware Toolsにマウントされるので、あとは解凍して実行する。質問はすべてデフォルト。

$ df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      18134344 6798704  10414452  40% /
tmpfs                   953272     232    953040   1% /dev/shm
/dev/sda1               495844  126912    343332  27% /boot
/dev/sr0                 62490   62490         0 100% /media/VMware Tools
$ pwd
/media/VMware Tools
$ ls -l
合計 62139
-r--r--r-- 1 kohchi kohchi 62183192  523 06:44 2015 VMwareTools-9.9.3-2759765.tar.gz
-r-xr-xr-x 1 kohchi kohchi     1959  523 06:43 2015 manifest.txt
-r--r--r-- 1 kohchi kohchi     1850  523 06:41 2015 run_upgrader.sh
-r-xr-xr-x 1 kohchi kohchi   683620  523 06:42 2015 vmware-tools-upgrader-32
-r-xr-xr-x 1 kohchi kohchi   758168  523 06:42 2015 vmware-tools-upgrader-64
$ cp -ip VMwareTools-9.9.3-2759765.tar.gz /tmp
$ cd /tmp
$ zcat VMwareTools-9.9.3-2759765.tar.gz | tar xvf -
解凍したファイルが表示
....
$ cd vmware-tools-distrib/
$ su
# ./vmware-install.pl
A previous installation of VMware Tools has been detected.

The previous installation was made by the tar installer (version 4).

Keeping the tar4 installer database format.

You have a version of VMware Tools installed.  Continuing this install will 
first uninstall the currently installed version.  Do you wish to continue? 
(yes/no) [yes] 

Uninstalling the tar installation of VMware Tools.

Stopping services for VMware Tools

Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done

File /etc/pulse/default.pa is backed up to /etc/pulse/default.pa.old.5.

The removal of VMware Tools 9.9.3 build-2759765 for Linux completed 
successfully.

Installing VMware Tools.

In which directory do you want to install the binary files? 
[/usr/bin] 

What is the directory that contains the init directories (rc0.d/ to rc6.d/)? 
[/etc/rc.d] 

What is the directory that contains the init scripts? 
[/etc/rc.d/init.d] 

In which directory do you want to install the daemon files? 
[/usr/sbin] 

In which directory do you want to install the library files? 
[/usr/lib/vmware-tools] 

In which directory do you want to install the documentation files? 
[/usr/share/doc/vmware-tools]

The path "/usr/share/doc/vmware-tools" does not exist currently. This program 
is going to create it, including needed parent directories. Is this what you 
want? [yes] 

The installation of VMware Tools 9.9.3 build-2759765 for Linux completed 
successfully. You can decide to remove this software from your system at any 
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by 
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want 
this program to invoke the command for you now? [yes]

Initializing...


Making sure services for VMware Tools are stopped.

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done
Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]


Found a compatible pre-built module for vmci.  Installing it...


Found a compatible pre-built module for vsock.  Installing it...


The module vmxnet3 has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module pvscsi has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module vmmemctl has already been installed on this system by another 
installer or package and will not be modified by this installer.

The VMware Host-Guest Filesystem allows for shared folders between the host OS 
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish 
to enable this feature? [yes] 

Found a compatible pre-built module for vmhgfs.  Installing it...


Found a compatible pre-built module for vmxnet.  Installing it...


The vmblock enables dragging or copying files between host and guest in a 
Fusion or Workstation virtual environment.  Do you wish to enable this feature?
[yes] 

VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present. This feature can be

enabled/disabled by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no] 

Thinprint provides driver-free printing. Do you wish to enable this feature? 
[yes] 


Disabling timer-based audio scheduling in pulseaudio.

Do you want to enable Guest Authentication (vgauth)? [yes] 



Detected X server version 1.13.0



Distribution provided drivers for Xorg X server are used.

Skipping X configuration because X drivers are not included.

Creating a new initrd boot image for the kernel.
   Starting Virtual Printing daemon:                                   done
   Checking acpi hot plug                                  [  OK  ]
Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                       [  OK  ]
   VM communication interface:                             [  OK  ]
   VM communication interface socket family:               [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   Mounting HGFS shares:                                   [失敗]
   Blocking file system:                                   [  OK  ]
   VMware User Agent:                                      [  OK  ]
   Guest operating system daemon:                          [  OK  ]
The configuration of VMware Tools 9.9.3 build-2759765 for Linux for this 
running kernel completed successfully.

You must restart your X session before any mouse or graphics changes take 
effect.

You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
command line.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and 
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session; and,
3. Restart your X session.

Enjoy,

--the VMware team

# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      18134344 7047724  10165432  41% /
tmpfs                   953272     232    953040   1% /dev/shm
/dev/sda1               495844  126913    343331  27% /boot
#

HGFSが失敗しているけど元々エラーだったのでとりあえず終了。

元記事は以下。

http://mawatari.jp/archives/centos-6-2-vmware-tools-install-log

gdbでgetopt()のoptind/optoptを参照したときに値が違うように見える

結構ハマったのでメモ。

#include <stdio.h>
#include <getopt.h>

char *short_opts = "ab:";
struct option long_opts[] = {
	{"test", no_argument, 0, 0},
	{"add", required_argument, 0, 0},
	{0, 0, 0, 0}
}; 
int main(int argc, char *argv[]) {
	int c = 0;
	int longindex;

	while (1) {
		longindex = 0;
		c = getopt_long(argc, argv, short_opts, long_opts, &longindex);
		if (c == -1) {
			break;
		}

		fprintf(stdout, "%d(%x) %d(%x) %c(%x)\n",
				c, &c, optind, &optind, optopt, &optopt);
	}
	return 0;
}

というソースがあり、getoptのextern変数optind, optoptの実際の値とgdbで参照した値が違うのに気がついた。

$ cc -g getopt.c
$ ./a.out -a -b a --test --add A
97(4cc7b7ac) 2(600ae4) (600ae0)
98(4cc7b7ac) 4(600ae4) (600ae0)
0(4cc7b7ac) 5(600ae4) (600ae0)
0(4cc7b7ac) 7(600ae4) (600ae0)
$ gdb a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/kohchi/C/a.out...done.
(gdb) b main
Breakpoint 1 at 0x4005e4: file getopt.c, line 14.
(gdb) run -a -b a --test --add A
Starting program: /home/kohchi/C/a.out -a -b a --test --add A

Breakpoint 1, main (argc=7, argv=0x7fffffffe1c8) at getopt.c:14
14		int c = 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2.x86_64
(gdb) n
18			longindex = 0;
(gdb) 
19			c = getopt_long(argc, argv, short_opts, long_opts, &longindex);
(gdb) 
20			if (c == -1) {
(gdb) 
24			fprintf(stdout, "%d(%x) %d(%x) %c(%x)\n",
(gdb) p c
$1 = 97
(gdb) p optind
$2 = 1
(gdb) p optopt
$3 = 63
(gdb) n
97(ffffe0cc) 2(600ae4) (600ae0)    ※あれ?optind=2 optopt=0になっている。
26		}
(gdb) 

で以下のページを参照したところ、シェアードライブラリの値と実行バイナリで使っているものが2つあるらしい。
コマンドを実行すると当然シェアードライブラリ中の値となるのだが、gdbで何も指定しないと実行バイナリのものを表示するらしい。

http://www.linuxquestions.org/questions/programming-9/gdb-does-not-print-right-value-908538/

なのでgdbでは以下のように"@@GLIBC_X.X.X"を指定するとシェアードライブラリの値を参照できるようだ。

$ gdb a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/kohchi/C/a.out...done.
(gdb) b main
Breakpoint 1 at 0x4005e4: file getopt.c, line 14.
(gdb) run -a -b a --test --add A
Starting program: /home/kohchi/C/a.out -a -b a --test --add A

Breakpoint 1, main (argc=7, argv=0x7fffffffe1c8) at getopt.c:14
14		int c = 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2.x86_64
(gdb) n
18			longindex = 0;
(gdb) 
19			c = getopt_long(argc, argv, short_opts, long_opts, &longindex);
(gdb) 
20			if (c == -1) {
(gdb) p c
$1 = 97
(gdb) p /c c
$2 = 97 'a'
(gdb) n
24			fprintf(stdout, "%d(%x) %d(%x) %c(%x)\n",
(gdb) l
19			c = getopt_long(argc, argv, short_opts, long_opts, &longindex);
20			if (c == -1) {
21				break;
22			}
23	
24			fprintf(stdout, "%d(%x) %d(%x) %c(%x)\n",
25					c, &c, optind, &optind, optopt, &optopt);
26		}
27		return 0;
28	}
(gdb) n
97(ffffe0cc) 2(600ae4) (600ae0)
26		}
(gdb) p optind
$3 = 12になっていないぞ
(gdb) p &optind
$4 = (int *) 0x38bfd8e114   ※参照先も違う
(gdb) p optopt
$5 = 630になっていないぞ
(gdb) p &optopt
$6 = (int *) 0x38bfd8e11c   ※参照先も違う
(gdb) p optind[tabを2回押す]
optind               optind@@GLIBC_2.2.5  
(gdb) p 'optind@@GLIBC_2.2.5' 
$7 = 2                                            ※OK!
(gdb) p &'optind@@GLIBC_2.2.5' 
$8 = (<data variable, no debug info> *) 0x600ae4  ※OK!
(gdb) p optopt[tabを2回押す]
optopt               optopt@@GLIBC_2.2.5  
(gdb) p 'optopt@@GLIBC_2.2.5' 
$9 = 0                                            ※OK!
(gdb) p &'optopt@@GLIBC_2.2.5' 
$10 = (<data variable, no debug info> *) 0x600ae0 ※OK!
(gdb) info var optind
All variables matching regular expression "optind":

Non-debugging symbols:
0x0000000000600ae4  optind@@GLIBC_2.2.5
(gdb) info var optopt
All variables matching regular expression "optopt":

Non-debugging symbols:
0x0000000000600ae0  optopt@@GLIBC_2.2.5
(gdb) n
18			longindex = 0;
(gdb) quit
A debugging session is active.

	Inferior 1 [process 8020] will be killed.

Quit anyway? (y or n) y
$

optindやoptoptの値で分岐していたりして、gdbデバッグしたら確実にハマるよね。