debuginfo: Improve commandline option handling for debuginfo

Fixes #12811 as described in the issue.