Regarding QCoreApplication::applicationDirPath() and stripping the path from argv[0] in KCmdLineArgs
George Kiagiadakis
kiagiadakis.george at gmail.com
Thu Oct 15 12:36:13 BST 2009
Hi,
I'm doing some work on drkonqi and kcrash lately and I'm currently
trying to fix a bug that appears in freebsd, but I have run into a
little trouble.
Background information:
On freebsd (and possibly on many other non-linux unix systems), by
default, there is no /proc filesystem and thus there is no way to know
an application's file name when you only have the pid available (which
on linux can be retrieved from /proc/<pid>/exe). For this reason, when
you invoke gdb with just "gdb --pid 1234", it cannot generate a
backtrace because it can't read the symbols from the executable. To
solve this, one must pass the application's file name as an argument
to gdb. In order to do that from drkonqi, drkonqi has to know the
application's file path. Fortunately, KCrash can pass the file path
with the --apppath command line argument to drkonqi, if it has been
specified with KCrash::setApplicationPath(). But the problem here is
that KApplication never sets the apppath. So, I thought of just
putting this line of code in KApplication at the place where it sets
the crash handler as well:
KCrash::setApplicationPath(QCoreApplication::applicationDirPath());
The problem:
The real problem here is that QCoreApplication::applicationDirPath()
relies on argv[0] for finding the path and falls back to looking in
$PATH if argv[0] does not contain a path. However, KCmdLineArgs for
some strange reason strips the path from argv[0], discarding this
valuable information. This happens in kcmdlineargs.cpp line 466:
------------
// Strip path from argv[0]
if (s->argc) {
char *p = strrchr( s->argv[0], '/');
if (p)
s->argv[0] = p+1;
}
-----------
And my question is, why is the path stripped there? Is there a good
reason? Could I just get rid of this code? Maybe we could have a
separate variable with the stripped argv[0] if it is needed for some
purpose and pass the original one to QApplication?
Regards,
George
More information about the kde-core-devel
mailing list