New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Documentation for developers: Debugging spk packages #2784
Comments
Hi, This looks like some fantastic information, although it would be better suited on the WIKI |
Thanks, @KaraokeStu. Yes, I'm planning to submit this to the Wiki (see Objective 2 above), but am looking for reviewers and possible improvements before I do this. I was hoping to reach more people here. |
Really interesting. My naive question is: why not running your application on a standard workstation Linux and debug it there ? By the way, there may exist situation where bug may only appear on DSM. I have only one NAS, it is my "productive" one, so I am really reluctant to install any compilation/debug related stuff on it. To test packages, I use virtual machines - xpenology for DSM 5.2 and a DSM 6.0 x86_64 VM, this add some comfort: no risk for my production, discard changes and redo from scratch (or revert to snapshot) I propose you to give a try to "remote debugging" with |
Thanks, @ymartin59. This is exactly the kind of feedback I was hoping for. What you are writing makes total sense. I just ran into all of this because I cross-compile an application that is developed by somebody else. I experienced dead-locks and the developer asked me for backtraces, but I have not been continuously developing and debugging myself. As to your questions: I don't have a Linux workstation, just the NAS and a Windows laptop with an Ubuntu VM, that I'm using to cross-compile Synology packages via the spksrc framework. The idea to run Xpenology VMs to test cross-compiled packages has never even occured to me, but is great and definitely easier and safer than the route I have been taking. To that extent, debugging on the NAS itself should probably just be a fall-back option for boarderline cases where bugs / crashes / dead-locks cannot be reproduced in an Xpenology environment. I will adapt the documentation accordingly.
Again, many thanks @ymartin59. Very, very helpful. |
Motivation
I'm maintaining a Tvheadend-testing version of the current master branch (4.3.x) on my spksrc fork in order to follow and support the development. Experiencing crashes and dead-locks I started looking into ways how to debug self-cross-compiled spk packages on my Synology NAS. I have not been able to find any reasonable documentation on how to do this and spend hours learning the hard way. I would like to share my findings with those who might run into similar issues in the future. Having said that, my way of approaching this problem might be far from ideal. If you are aware of better ways / approaches, please comment on this issue so that we can optimize the documentation.
Objective
[WIP]Documentation
Debugging
Cross-compiling with debug symbols (on your VM or docker spksrc environment)
First, you have to ensure that your cross-compiled package contains debug symbols. This is usually not the case, as the spksrc framework routinely strips (i.e. removes) those symbols from packaged libraries and binaries. There are two ways to achieve that:
spksrc/mk/spksrc.strip.mk
file and comment out thedo \ [...] done
block understrip_target
, which is easier if you have multiple dependencies and cross packages.Once you have done this, just build your package as usual via
make arch-[ARCH]-[toolchain version]
, e.g.make arch-evansport-6.1
. The package will be substantially bigger as usual as it contains all the debug symbols. Do not forget to revert the changes above once you are done with debugging.Debugging on XPEnology / your Synology NAS
It is recommended to test and debug your packages in a safe environment and not on a production system. You can run XPEnology in a VM to provide such an environment. Debugging on your NAS should be last resort if you cannot reproduce the problems otherwise.
Once your package is installed,
ssh
into your XPEnology / Synology NAS asadmin
user. Then...sudo su
and enter theadmin
/root
password again (the password is identical)synogear install
will install diagnosis tools on your system, including thegdb
debugger, which is what we are looking for.Note: You will have to repeat 1. and 2. for each
ssh
debugging session as the diagnosis environment is not maintained after exiting yourssh
session.If you just need to debug the main thread, you are done here and can start debugging. However, frequently, you want to be able to debug multiple threads. If so, continue from here...
evansport-6.1
toolchains from the official Synology sources and untar them into some accessible directory, e.g./volume1/public/toolchains
on your XPEnology / NAS.root
user, go into your home directory (cd ~
) and create a file.gdbinit
. Include the following lines (adapting directories as needed):set sysroot /volume1/public/toolchains/i686-pc-linux-gnu/i686-pc-linux-gnu/sys-root
add-auto-load-safe-path /volume1/public/toolchains/i686-pc-linux-gnu/i686-pc-linux-gnu/sys-root/lib/libthread_db-1.0.so
set solib-search-path /volume1/@appstore/tvheadend-testing/lib
The last line should contain the path to the libraries of the application you have packaged and are trying to debug.
With this, you are finally ready to go: Start your application manually within
gdb
or start it via the package center and hook the debugger on viagdb [application] [PID]
. You will be able to create back traces and core dumps as usual.The text was updated successfully, but these errors were encountered: