This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: new feature for "backtrace" that cuts path to file (remain filename)
- From: asmwarrior <asmwarrior at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 02 Mar 2012 13:59:53 +0800
- Subject: Re: new feature for "backtrace" that cuts path to file (remain filename)
- Authentication-results: mr.google.com; spf=pass (google.com: domain of asmwarrior@gmail.com designates 10.68.217.136 as permitted sender) smtp.mail=asmwarrior@gmail.com; dkim=pass header.i=asmwarrior@gmail.com
This topic has discussed some months ago, see:
http://sourceware.org/ml/gdb-patches/2011-12/msg00207.html
and
http://sourceware.org/ml/gdb-patches/2011-08/msg00036.html
Consider Jan's suggestion, I think a modified version get_filename_display_from_sal() which use symtab_to_fullname looks like below:
/* See commentary in frame.h. */
const char *
get_filename_display_from_sal (struct symtab_and_line *sal)
{
const char *filename = sal->symtab->filename;
const char *dirname = sal->symtab->dirname;
size_t dlen = dirname ? strlen (dirname) : 0;
if (filename == NULL)
{
return NULL;
}
else if (filename_display_string == filename_display_basename)
{
return lbasename (filename);
}
else if (filename_display_string == filename_display_without_comp_directory
&& dirname && dlen && dlen <= strlen (filename)
&& !filename_ncmp (filename, dirname, dlen))
{
const char *start = filename + dlen;
const char *result = start;
while (IS_DIR_SEPARATOR (*result))
result++;
if (IS_DIR_SEPARATOR (dirname[dlen - 1]))
return result;
else
return result == start ? filename : result;
}
else if (filename_display_string == filename_display_full)
{
const char *fullname = symtab_to_fullname (sal->symtab);
if (fullname!=NULL)
return fullname;
else
return filename;
}
return filename;
}
BTW: It works fine under Windows mingw gdb, and I think showing a fullname in the backtrace has some good reasons, because the front end of gdb like (Codeblocks IDE) can quickly locate/navigate the source, but it may failed when bt command show some relative paths.
Zhang Yuanhui
ollydbg from codeblocks' forum