11

I believe (correct me if I'm wrong) that when remote debugging with gdb and gdbserver, the binary running on the target under gdbserver doesn't need the debug information in the binary, but the host, running gdb, does.

Our application binary with debugging symbols is about 112 megs (!). If I run strip, the binary is only 6.7 megs, which would be much faster to deploy to our target.

Is it possible to have Qt Creator strip the binary before deploying it? Will we still be able to debug?

Steve
  • 6,334
  • 4
  • 39
  • 67

2 Answers2

2

To strip symbols, you can have Qt Creator run a final build step after qmake and make, which calls the 'strip' command on the binary in your app bundle. For example: -

strip -u -r ./MyApplication/Contents/MacOS/MyApplication

In order to debug, you'd need a separate .dsym file to be generated during the build, which contains the symbols. If this resides on the host, the debugger should automatically pick this up; it does with lldb, though with gdb, you may need to manually load the symbol file.

how to enable that extra build step

Select projects from the right-side tool bar

Menu bar

Ensure you're on the Build and Run tab (GraphicsScene is just the name of the project)

tabs

Under Build Steps, you'll see two steps, qMake and Make. Select add build step for a custom process step

Build Steps

Fill in the relevant fields you may need to correct for the paths, rather than just copy these:

Enter details

When the build has finished, the strip command will run. If you've any errors, it's likely a problem with the path to either the strip command or the path to your app bundle's executable.

Note that if you need the full path to strip, it resides in /usr/bin/strip.

As for the symbol file, I believe you can use the addsymbolfilecommand with the argument to the path to the dsym file. However, gdb has since been deprecated and you should really be using lldb now, which automatically finds the dsym file, once it has been indexed by Spotlight.

Community
  • 1
  • 1
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • I'm using QtCreator with my toolchain's gdb, nothing fancy. The project builds from Creator using qmake. Can you expand a bit on how to enable that extra build step, and how I would manually load those symbols as you mention? – Steve Feb 22 '16 at 17:32
  • I've updated the answer in response to your question. – TheDarkKnight Feb 23 '16 at 09:18
  • Is that custom process step something local to the developer machine, or is it saved somewhere in a .pro file? I'd love to be able to implement this and have it "just work" for the other developers on my team. I'll give this a shot before the end of the week. – Steve Feb 23 '16 at 12:54
  • It's local to the developer machine, but what you can do is just put the commands in a bash script and point the custom step to the script. That way you can add commands to the script and share it via source control. – TheDarkKnight Feb 23 '16 at 13:21
  • Could you explain the arguments `-r` and `-u`? I can’t find them in the `strip` manpage. – Philipp Ludwig Apr 27 '20 at 10:35
  • Taken directly from the strip man page in 10.15.4 `-u Save all undefined symbols. This is intended for use with relocatable objects to save symbols referred to by external relocation entries. Note that common symbols are also referred to by external relocation entries and this flag does not save those symbols. -r Save all symbols referenced dynamically.` – TheDarkKnight Apr 28 '20 at 10:59
0

You can strip the debug symbols like this:

Add a line to your make file, this will remove all debug symbols from it:

cd $(MY_BINARY_INSTALL_PATH); strip --strip-debug $(MY_BINARY_INSTALL_PATH)/bin/mybinary -o $(MY_BINARY_INSTALL_PATH)/bin/mybinary

If you want to remove all symbols from it you could use something like:

cd $(MY_BINARY_INSTALL_PATH); strip --strip-all $(MY_BINARY_INSTALL_PATH)/bin/mybinary -o $(MY_BINARY_INSTALL_PATH)/bin/mybinary

Stripping all symbols will help reduce the size of the binary significantly

Samer Tufail
  • 1,835
  • 15
  • 25