< Guidelines and HOWTOs | Debugging Revision as of 21:32, 11 May 2017 (view source)Elvis Angelaccio (talk | contribs) (Add ptrace note)← Older edit Revision as of 11:52, 28 April 2019 (view source) Jucato (talk | contribs) (Fixed link to kio fish and kio sftp debugging guides)Newer edit → Line 126: Line 126: == specific kioslaves == == specific kioslaves == −* [[Development/Tutorials/Debugging/Debugging IOSlaves/Debugging kio_fish|kio_fish]]+* [[Guidelines_and_HOWTOs/Debugging/Debugging IOSlaves/Debugging kio_fish|kio_fish]] −* [[Development/Tutorials/Debugging/Debugging IOSlaves/Debugging kio_sftp|kio_sftp]]+* [[Guidelines_and_HOWTOs/Debugging/Debugging IOSlaves/Debugging kio_sftp|kio_sftp]] Revision as of 11:52, 28 April 2019 This page describes how you can debug a KIO ioslave. Contents 1 How to get debug output 1.1 GUI (Qt5/KF5 instructions) 1.2 GUI (Qt4/kdelibs4 instructions) 1.3 Manual (Qt4/kdelibs4 instructions) 2 How does an io-slave get started? 3 Attaching gdb to an io-slave 4 Debugging io-slaves with valgrind 5 specific kioslaves How to get debug output GUI (Qt5/KF5 instructions) Press ALT+F2. Enter 'kdebugsettings' without the quotes and press enter. Type the name of the kioslave (e.g. ftp, http, ...). If it's not listed, it doesn't use categorized debug output, so either its output is always on, or commented out in the code (in which case it needs to be ported to qCDebug). Ensure the combobox for the kioslave says "Debug". "All" is misleading since it means "no rule", and the default could be off, not on. Press OK to close the dialog. Press ALT+F2, type kdeinit5 and press enter or alternatively log out of KDE and log back in. This will print additional debug info to the stderr of your kioslave, which typically ends up in ~/.X.err or ~/.xsession-errors GUI (Qt4/kdelibs4 instructions) Press ALT+F2. Enter 'kdebugdialog --fullmode' without the quotes and press enter. Select the desired number in the "Debug area", e.g. 7103 for http. In the [Information] box, select "File" as the output. Enter the desired file name, e.g. /tmp/kio_http.log. Press OK to close the dialog. Press ALT+F2, type kdeinit4 and press enter or alternatively log out of KDE and log back in. This will print additional debug info to the stderr of your kdeinit process, which typically ends up in ~/.X.err or ~/.xsession-errors Manual (Qt4/kdelibs4 instructions) It is useful to redirect the debug output of your particular slave to a file instead of stderr. E.g. I myself use the following lines in $KDEDIR/share/config/kdebugrc.  InfoOutput=0 InfoFilename=/tmp/http  InfoOutput=0 InfoFilename=/tmp/http This redirects all debug info for areas 7103 and 7113 (as used by kio_http) to the file /tmp/http. To get debug information from the SMB slave you can add the following to kioslaverc: [SMB] DebugLevel=100 This will print additional debug info to the stderr of your kdeinit process, which typically ends up in ~/.X.err or ~/.xsession-errors How does an io-slave get started? Your application requests 'klauncher' via DBus for a slave. If 'klauncher' does not have an idle slave ready, it will ask kdeinit to start a new one. kdeinit forks and dlopens the library that contains the io-slave. Then it calls a function called kdemain() in the library. Attaching gdb to an io-slave Due to the above sequence it is rather hard to get an io-slave in your debugger. But wait there is hope. You can start klauncher in such a way that slaves for a certain protocol (the first parameter of KIO::SlaveBase() constructor of the slave class) are started in debug mode. E.g. to start all 'http' slaves in debug mode, you type: KDE_SLAVE_DEBUG_WAIT=http kdeinit5 This will restart 'kdeinit' and 'klauncher'. Note: The string after the equal signal designates the name of a service, not the name of the slave! E.g. if you want to debug the kio_imap4, you must use: KDE_SLAVE_DEBUG_WAIT=imap kdeinit5 For example, these commands don't work: KDE_SLAVE_DEBUG_WAIT=imap4 kdeinit5 KDE_SLAVE_DEBUG_WAIT=143 kdeinit5 When your application now requests a http slave, the slave will be started by kdeinit, but before it calls kdemain() (cq. main()) it will suspend the slave by sending it a SIGSTOP signal. In the terminal from which you started kdeinit you will get the following message: kdeinit: Suspending process kdeinit: 'gdb kdeinit 16779' to debug kdeinit: 'kill -SIGCONT 16779' to continue You can now debug your slave by typing (or pasting) 'gdb kdeinit 16779' in a terminal. Note that modern linux kernels disable ptrace. If gdb says "ptrace: Operation not permitted." then you need this: echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope If you don't want to debug a slave you can let it continue by sending it a SIGCONT by typing 'kill -SIGCONT 16779'. Be aware that slaves will not be killed while they are suspended. Once you have started gdb, you can set e.g. breakpoints and then resume the slave by typing 'continue'. The debugger will return immediate with a message that a SIGSTOP has been received so you will have to type 'continue' a second time. See also Windows-specific notes on debugging io-slaves. Debugging io-slaves with valgrind KLauncher can be told to run certain io-slaves through valgrind. The following command can be used to let klauncher run all https io-slaves via valgrind: KDE_SLAVE_VALGRIND=https kdeinit5 The valgrind output will appear as the stderr output of the kdeinit process. The $VALGRIND_OPTS environment variable can be used to pass options to valgrind. If you want to use a different skin: KDE_SLAVE_VALGRIND_SKIN=callgrind ( for example ) specific kioslaves kio_fish kio_sftp Retrieved from "https://community.kde.org/index.php?title=Guidelines_and_HOWTOs/Debugging/Debugging_IOSlaves&oldid=83835" Content is available under Creative Commons License SA 4.0 unless otherwise noted.