関数の呼び出し関係の追跡
まず,
% grep 'copy_remote_file ' *.c
fr-archive.c:copy_remote_file (FrArchive *archive,
fr-archive.c: copy_remote_file (archive, password);
この結果を見ると copy_
リスト6 fr-archive.
1255 gboolean
1256 fr_archive_load (FrArchive *archive,
1257 const char *uri,
1258 const char *password)
1259 {
1260 g_return_val_if_fail (archive != NULL, FALSE);
1261
1262 g_signal_emit (G_OBJECT (archive),
1263 fr_archive_signals[START],
1264 0,
1265 FR_ACTION_LOADING_ARCHIVE);
1266
1267 fr_archive_set_uri (archive, uri);
1268 copy_remote_file (archive, password);
1269
1270 return TRUE;
1271 }
この部分にもprintf()文を入れて調べると,
リストは省きますが,
リスト7 main.
907 int i = 0;
908 while ((filename = remaining_args[i++]) != NULL) {
909 GtkWidget *window;
910 GFile *file;
911 char *uri;
912
913 window = fr_window_new ();
914 gtk_widget_show (window);
915
916 file = g_file_new_for_commandline_arg (filename);
917 uri = g_file_get_uri (file);
918 fr_window_archive_open (FR_WINDOW (window), uri, GTK_WINDOW (window));
919 g_free (uri);
このコードを見ると,
リスト8 main.
917 uri = g_file_get_uri (file);
918 printf("my_debug/main.c: filename:%s, file:%s, uri:%s\n", filename, file, uri);
919 fr_window_archive_open (FR_WINDOW (window), uri, GTK_WINDOW (window));
再度コンパイルし直して動かしてみると,
Google等で調べると,
出力結果にfileは正しく表示されていませんが,
ここで気になるのはfilenameがUTF-8形式で表示されていることです。g_
Creates a GFile with the given argument from the command line. The value of arg can be either a URI,
an absolute path or a relative path resolved relative to the current working directory. This operation
never fails, but the returned object might not support any I/O operation if arg points to a malformed path.
この関数が引数に取るのはURIか絶対パス,
どうやらファイル名のエンコーディングの扱いに齟齬が生じている気配なので,
リスト9 filenameを強制的にEUC-JPに変換する処理を追加
916 gchar *tmpname = g_filename_from_utf8(filename, -1, NULL, NULL, NULL);
917 file = g_file_new_for_commandline_arg (tmpname);
918 uri = g_file_get_uri (file);
919 printf("my_debug/main.c: filename:%s, file:%s, tmpname:%s, uri:%s\n", filename, file, tmpname, uri);
920 fr_window_archive_open (FR_WINDOW (window), uri, GTK_WINDOW (window));
UTF-8化されているfilenameをg_
g_
このように修正すると,
どうやら今回のバグは,
後日談
これらの内容を簡単に整理してPlamo Linuxのメンテナ日記に書いてみたら,
改めてmain.
リスト9 main.
173 static const GOptionEntry options[] = {
174 { "add-to", 'a', 0, G_OPTION_ARG_STRING, &add_to,
175 N_("Add files to the specified archive and quit the program"),
176 N_("ARCHIVE") },
177
178 { "add", 'd', 0, G_OPTION_ARG_NONE, &add,
179 N_("Add files asking the name of the archive and quit the program"),
180 NULL },
181
182 { "extract-to", 'e', 0, G_OPTION_ARG_STRING, &extract_to,
....
198 { "force", '\0', 0, G_OPTION_ARG_NONE, &ForceDirectoryCreation,
199 N_("Create destination folder without asking confirmation"),
200 NULL },
201
202 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args,
203 NULL,
204 NULL },
205
206 { NULL }
207 };
ここで"add-to"や"extract-to"はfile-roller コマンドに与えることができるオプションパラメータです。それらあらかじめ指定されたオプション以外の部分は,
一方,
そこで,
結論として,
今回の記事だけを見れば,
先にデバッグ作業には探偵のような推理力が必要と述べましたが,
デバッグ作業は,
与えられたソフトウェアを,