How to debug the Common Printing Dialog
-
Upload
naruhiko-ogasawara -
Category
Technology
-
view
1.825 -
download
6
description
Transcript of How to debug the Common Printing Dialog
![Page 1: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/1.jpg)
Debugging of CPD
Naruhiko OgasawaraOpenPrinting Japan
Koedo LUG Offline MeetingJune 13th, 2009
![Page 2: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/2.jpg)
What is OpenPrinting?
*nix の印刷関連の標準化を行う団体
The Linux Foundation の下部組織
Manager: Till Kamppeter 元 Mandriva Linux の印刷オタク
Foomatic という印刷ミドルウェアの開発者
主な業績 Open Printing Vector Printing (OPVP) PDF Print Path Automatic Driver Downloading Common Printing Dialog (CPD)
![Page 3: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/3.jpg)
What's Common Printing Dialog?
Desktop OS ではプリンタの印刷設定についてOS 側が用意するのが普通 アプリケーションはどのプリンタについても同じように実
装することができる
プリンタベンダは統一された方法でベンダ独自の機能をユーザに見せることができる
*nix にはこれまでそういう仕組みがなかった GTK+ / KDE それぞれ持っているが、互換性がない
それを解消するのが Common Printing Dialog
![Page 4: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/4.jpg)
Demonstration
![Page 5: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/5.jpg)
Problem of CPD
No Human Resource 思想は高邁だが、実装する人間がコミュニティに存在し
ない
Google Summer of Code だより
Enough Usability Testing? 既存の UI とかなり異なる User Experience
それ自体はいいとして、ちゃんと検証しているのか?
BUG ! BUG ! BUG ! 結局人がいないので、サンプル実装はバグだらけ
![Page 6: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/6.jpg)
Debug Hacks!
私は長らく Windows プログラマであった
*nix についてはよくしらない 技術者と言うより政治屋
社内で *nix についてどう対応していくかを考えて関連部署を説得するのが仕事
それじゃつまらん! ということで本を
買いました。
![Page 7: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/7.jpg)
Debugging CPD (KDE ver.)
CPD の KDE バージョンはプリントキューが一個 もないと Qt がクラッシュするというナイス不具合
がある
半年ぐらい前にバグレポしたのにちっとも治らない
せっかくなのでこれをデバッグしてみよう! とかいってるうちに開発が進んでしまった (6/11 にごっ
そりコミットされた) ので、このネタはもう古いです。しくしく。
コンパイルなどなどについてはブログ見てくださいhttp://d.hatena.ne.jp/naruoga/20090527/1243382202
![Page 8: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/8.jpg)
Debugging CPD (KDE ver.) (2)
とりあえずデーモンもどきを起動して、ダイアログア プリを gdb で起動してえいっと実行
$ kde4dialog/kde4cpd &$ gdb kde4dialog/viewdialogGNU gdb 6.8debianCopyright (C) 2008 Free Software Foundation, Inc.<snip>This GDB was configured as "i486linuxgnu"...(gdb) runStarting program: /home/naruhiko/commonprintingdialog/build/kde4dialog/viewdialog [Thread debugging using libthread_db enabled][New Thread 0xb5f19940 (LWP 19299)]ASSERT failure in QVector<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qvector.h, line 335
Program received signal SIGABRT, Aborted.[Switching to Thread 0xb5f19940 (LWP 19299)]0xb800b422 in __kernel_vsyscall ()
![Page 9: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/9.jpg)
Debugging CPD (KDE ver.) (3)
Qt の QVector クラスの []オペレータで死んでる
でもまさかこんな基本クラスがバグってるとは考えにくい
呼出側があやしい!> Backtrace !
(gdb) bt#0 0xb800b422 in __kernel_vsyscall ()#1 0xb66286d0 in raise () from /lib/tls/i686/cmov/libc.so.6#2 0xb662a098 in abort () from /lib/tls/i686/cmov/libc.so.6#3 0xb7658595 in qt_message_output () from /usr/lib/libQtCore.so.4#4 0xb7658681 in qFatal () from /usr/lib/libQtCore.so.4#5 0xb765872c in qt_assert_x () from /usr/lib/libQtCore.so.4#6 0x08064941 in QVector<CommonPrinting::CUPSDestination>::operator[] ( this=0xa0aef84, i=0) at /usr/include/qt4/QtCore/qvector.h:335#7 0x0805dc40 in CPDialogWidget::initWidgets (this=0xa0aef50) at /home/naruhiko/commonprintingdialog/kde4dialog/cpd_dialog_widget.cpp:861...
![Page 10: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/10.jpg)
Debugging CPD (KDE ver.) (4)
人の書いたプログラムなのでロジックを追いたい
そこでメソッドの先頭に breakpoint して再実行(gdb) b CPDialogWidget::initWidgets()
Breakpoint 1 at 0x805db19: file /home/naruhiko/commonprintingdialog/kde4dialog/cpd_dialog_widget.cpp, line 855.(gdb) runStarting program: /home/naruhiko/commonprintingdialog/build/kde4dialog/viewdialog [Thread debugging using libthread_db enabled][New Thread 0xb5eac940 (LWP 19668)][Switching to Thread 0xb5eac940 (LWP 19668)]
Breakpoint 1, CPDialogWidget::initWidgets (this=0x892b120) at /home/naruhiko/commonprintingdialog/kde4dialog/cpd_dialog_widget.cpp:855<snip>861 currentPrinter = &(printers[0]);(gdb) nASSERT failure in QVector<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qvector.h, line 335
Program received signal SIGABRT, Aborted.0xb7f9e422 in __kernel_vsyscall ()
![Page 11: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/11.jpg)
Debugging CPD (KDE ver.) (5)
printers[0] の呼び出しで死んでるらしい
この人 (printers) は何者?
ちょっと上を見れば分かる857 printers = CUPSSupport::getDests();(gdb) n858 for(int i = 0; i < printers.size(); i++) {(gdb) print printers$1 = {{p = 0x8070670, d = 0x8070670}}(gdb) print printers.size()$2 = 0
CUPSSupport クラスは見てないけど、多分Destination ( 印刷先 ) を列挙してベクタに返す
だから size == 0 になるのも当然
![Page 12: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/12.jpg)
Debugging CPD (KDE ver.) (6)
Qt のドキュメントをチェック http://doc.trolltech.com/4.5/qvector.html#operator-5b-5d
T & QVector::operator[] ( int i )
Returns the item at index position i as a modifiable reference.
i must be a valid index position in the vector (i.e., 0 <= i < size()).
size() == 0 のときに operator [] 呼んじゃダメ
だからこのコードの場合 size() == 0 ならアラート出して終了するのが一番簡単
![Page 13: How to debug the Common Printing Dialog](https://reader035.fdocuments.net/reader035/viewer/2022081805/556155e5d8b42adb6b8b556a/html5/thumbnails/13.jpg)
Conclusion
エンジニアを引退した私でも gdb でデバッグできた! しかも楽しい! やってみようと思わせた Debug Hacks 素晴らしい
今度はもっと複雑なバグを追っかけてみたい
CPD 自体ははやいとこ品質あげてほしいので、こうやってちょこちょこ手伝えたら楽しいかも
Printing の標準化は人手が足りないので、こういうことに興味がある人ぜひ参加してくださいなっ。