From: iam ahal <hal9000ed2k@gmail.com>
To: gdb-patches@sourceware.org
Cc: pmuldoon@redhat.com, tromey@redhat.com, brobecker@adacore.com,
eliz@gnu.org
Subject: Re: [patch] GDB 7.2: new feature for "backtrace" that cuts path to file (remain filename)
Date: Tue, 19 Jul 2011 13:28:00 -0000 [thread overview]
Message-ID: <CAA18ubLBZseSxqjWSk1jH7OeZi06K_o75HKc0CN-_iCAjQ5boA@mail.gmail.com> (raw)
In-Reply-To: <CAA18ubJAvwHt-sq8XN98PhC=LSFXPbcy4P1+AVic-G=MNE7R2A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 386 bytes --]
I've made tiny changes in my test script. You can find out everything
in the attachment (i.e. every my message with attachment is suitable
to possible commit, if it will be reviewed).
My test script is separate *.exp file but I don't sure that it's right.
To test I just run:
... gdb-7.2/gdb/testsuite$ runtest --all gdb.base/bt-nopath.exp
Is everything ok? Or what I should change?
[-- Attachment #2: gdb-7.2-backtrace-nofull-2.patch --]
[-- Type: text/x-patch, Size: 9504 bytes --]
diff -rupN gdb-7.2-orig/gdb/doc/gdb.texinfo gdb-7.2/gdb/doc/gdb.texinfo
--- gdb-7.2-orig/gdb/doc/gdb.texinfo 2010-09-01 23:15:59.000000000 +0400
+++ gdb-7.2/gdb/doc/gdb.texinfo 2011-07-18 22:36:21.714535001 +0400
@@ -5890,6 +5890,10 @@ Similar, but print only the outermost @v
@itemx bt full -@var{n}
Print the values of the local variables also. @var{n} specifies the
number of frames to print, as described above.
+
+@item backtrace nopath
+@itemx bt nopath
+Same as @code{backtrace}, but print only the basename of the file.
@end table
@kindex where
diff -rupN gdb-7.2-orig/gdb/frame.h gdb-7.2/gdb/frame.h
--- gdb-7.2-orig/gdb/frame.h 2010-01-01 10:31:32.000000000 +0300
+++ gdb-7.2/gdb/frame.h 2011-07-18 22:36:21.714535001 +0400
@@ -582,7 +582,10 @@ enum print_what
/* Print both of the above. */
SRC_AND_LOC,
/* Print location only, but always include the address. */
- LOC_AND_ADDRESS
+ LOC_AND_ADDRESS,
+ /* Print only the location but without the full path to file, *
+ * i.e. print only filename even if full path is defined in symtable. */
+ LOC_NO_FULLPATH
};
/* Allocate zero initialized memory from the frame cache obstack.
diff -rupN gdb-7.2-orig/gdb/stack.c gdb-7.2/gdb/stack.c
--- gdb-7.2-orig/gdb/stack.c 2010-07-01 19:36:17.000000000 +0400
+++ gdb-7.2/gdb/stack.c 2011-07-18 22:36:21.714535001 +0400
@@ -592,7 +592,8 @@ print_frame_info (struct frame_info *fra
location_print = (print_what == LOCATION
|| print_what == LOC_AND_ADDRESS
- || print_what == SRC_AND_LOC);
+ || print_what == SRC_AND_LOC
+ || print_what == LOC_NO_FULLPATH);
if (location_print || !sal.symtab)
print_frame (frame, print_level, print_what, print_args, sal);
@@ -652,7 +653,7 @@ print_frame_info (struct frame_info *fra
do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
}
- if (print_what != LOCATION)
+ if (print_what != LOCATION || print_what != LOC_NO_FULLPATH)
set_default_breakpoint (1, sal.pspace,
get_frame_pc (frame), sal.symtab, sal.line);
@@ -810,11 +811,21 @@ print_frame (struct frame_info *frame, i
ui_out_text (uiout, ")");
if (sal.symtab && sal.symtab->filename)
{
+ const char *filename;
+
annotate_frame_source_begin ();
ui_out_wrap_hint (uiout, " ");
ui_out_text (uiout, " at ");
annotate_frame_source_file ();
- ui_out_field_string (uiout, "file", sal.symtab->filename);
+
+ filename = NULL;
+ if (print_what == LOC_NO_FULLPATH)
+ filename = lbasename (sal.symtab->filename);
+
+ if (filename == NULL || *filename == '\0')
+ filename = sal.symtab->filename;
+
+ ui_out_field_string (uiout, "file", filename);
if (ui_out_is_mi_like_p (uiout))
{
const char *fullname = symtab_to_fullname (sal.symtab);
@@ -1269,7 +1280,7 @@ frame_info (char *addr_exp, int from_tty
frames. */
static void
-backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
+backtrace_command_1 (char *count_exp, int show_locals, int from_tty, int nofull_path)
{
struct frame_info *fi;
int count;
@@ -1345,7 +1356,11 @@ backtrace_command_1 (char *count_exp, in
means further attempts to backtrace would fail (on the other
hand, perhaps the code does or could be fixed to make sure
the frame->prev field gets set to NULL in that case). */
- print_frame_info (fi, 1, LOCATION, 1);
+ if (nofull_path)
+ print_frame_info (fi, 1, LOC_NO_FULLPATH, 1);
+ else
+ print_frame_info (fi, 1, LOCATION, 1);
+
if (show_locals)
print_frame_local_vars (fi, 1, gdb_stdout);
@@ -1375,6 +1390,7 @@ struct backtrace_command_args
char *count_exp;
int show_locals;
int from_tty;
+ int nofull_path;
};
/* Stub for catch_errors. */
@@ -1384,7 +1400,8 @@ backtrace_command_stub (void *data)
{
struct backtrace_command_args *args = data;
- backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty);
+ backtrace_command_1 (args->count_exp, args->show_locals,
+ args->from_tty, args->nofull_path);
return 0;
}
@@ -1392,7 +1409,7 @@ static void
backtrace_command (char *arg, int from_tty)
{
struct cleanup *old_chain = NULL;
- int fulltrace_arg = -1, arglen = 0, argc = 0;
+ int fulltrace_arg = -1, arglen = 0, argc = 0, nofull_path = -1;
struct backtrace_command_args btargs;
if (arg)
@@ -1412,6 +1429,8 @@ backtrace_command (char *arg, int from_t
if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
fulltrace_arg = argc;
+ else if (nofull_path < 0 && subset_compare (argv[i], "nopath"))
+ nofull_path = argc;
else
{
arglen += strlen (argv[i]);
@@ -1419,7 +1438,7 @@ backtrace_command (char *arg, int from_t
}
}
arglen += argc;
- if (fulltrace_arg >= 0)
+ if (fulltrace_arg >= 0 || nofull_path >= 0)
{
if (arglen > 0)
{
@@ -1427,7 +1446,7 @@ backtrace_command (char *arg, int from_t
memset (arg, 0, arglen + 1);
for (i = 0; i < (argc + 1); i++)
{
- if (i != fulltrace_arg)
+ if (i != fulltrace_arg && i != nofull_path)
{
strcat (arg, argv[i]);
strcat (arg, " ");
@@ -1442,9 +1461,10 @@ backtrace_command (char *arg, int from_t
btargs.count_exp = arg;
btargs.show_locals = (fulltrace_arg >= 0);
btargs.from_tty = from_tty;
+ btargs.nofull_path = (nofull_path >= 0);
catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR);
- if (fulltrace_arg >= 0 && arglen > 0)
+ if ((fulltrace_arg >= 0 || nofull_path >= 0) && arglen > 0)
xfree (arg);
if (old_chain)
@@ -1459,6 +1479,7 @@ backtrace_full_command (char *arg, int f
btargs.count_exp = arg;
btargs.show_locals = 1;
btargs.from_tty = from_tty;
+ btargs.nofull_path = 0;
catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR);
}
\f
diff -rupN gdb-7.2-orig/gdb/testsuite/gdb.base/bt-nopath.c gdb-7.2/gdb/testsuite/gdb.base/bt-nopath.c
--- gdb-7.2-orig/gdb/testsuite/gdb.base/bt-nopath.c 1970-01-01 03:00:00.000000000 +0300
+++ gdb-7.2/gdb/testsuite/gdb.base/bt-nopath.c 2011-07-18 22:36:21.714535001 +0400
@@ -0,0 +1,17 @@
+
+void func1()
+{
+
+}
+
+void func()
+{
+ func1();
+}
+
+int main()
+{
+ func();
+
+ return 0;
+}
diff -rupN gdb-7.2-orig/gdb/testsuite/gdb.base/bt-nopath.exp gdb-7.2/gdb/testsuite/gdb.base/bt-nopath.exp
--- gdb-7.2-orig/gdb/testsuite/gdb.base/bt-nopath.exp 1970-01-01 03:00:00.000000000 +0300
+++ gdb-7.2/gdb/testsuite/gdb.base/bt-nopath.exp 2011-07-19 14:55:58.845733001 +0400
@@ -0,0 +1,112 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile "bt-nopath"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+proc bt_compile { path } {
+ global binfile
+
+ if { [gdb_compile $path $binfile executable {debug nowarnings}] != "" } {
+ return -1
+ }
+
+ if [get_compiler_info $binfile] {
+ return -1
+ }
+}
+
+proc bt_line { num func {flag ""} } {
+ global srcfile
+
+ if { [string match $flag full] } {
+ return "\#${num}.*${func}.*().*at\\s*/.*${srcfile}.*"
+ } elseif { [string match $flag rel] } {
+ return "\#${num}.*${func}.*().*at\\s*\\..*${srcfile}.*"
+ } else {
+ return "\#${num}.*${func}.*().*at\\s*${srcfile}.*"
+ }
+}
+
+proc nopath_test { {flag ""} } {
+ global srcdir
+ global subdir
+ global binfile
+ global gdb_prompt
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir ${srcdir}/${subdir}
+ gdb_load ${binfile}
+
+ gdb_breakpoint main
+ gdb_breakpoint func
+ gdb_breakpoint func1
+
+ gdb_run_cmd
+ gdb_expect {
+ -re "Breakpoint 1,.*main.* at .*:.*${gdb_prompt} $" {
+ pass "run until function breakpoint"
+ }
+ -re "$gdb_prompt $" {
+ fail "run until function breakpoint"
+ }
+ timeout {
+ fail "run until function breakpoint (timeout)"
+ }
+ }
+
+ gdb_test "backtrace" [bt_line 0 main $flag]
+ gdb_test "backtrace nopath" [bt_line 0 main]
+
+ gdb_continue func
+
+ gdb_test "backtrace" [bt_line 0 func $flag][bt_line 1 main $flag]
+ gdb_test "backtrace nopath" [bt_line 0 func][bt_line 1 main]
+
+ gdb_continue func1
+
+ gdb_test "backtrace" [bt_line 0 func1 $flag][bt_line 1 func $flag][bt_line 2 main $flag]
+ gdb_test "backtrace nopath" [bt_line 0 func1][bt_line 1 func][bt_line 2 main]
+}
+
+set save_pwd [pwd]
+cd $subdir
+set full_src_path [pwd]/${srcfile}
+cd $save_pwd
+
+if { [bt_compile $full_src_path] == -1 } {
+ untested bt-nopath.exp
+ return -1
+}
+
+nopath_test full
+
+remote_exec build "rm -f ${binfile}"
+
+set rel_src_path [exec find . -path *${srcdir}/${subdir}/${srcfile}]
+
+if { [bt_compile $rel_src_path] == -1 } {
+ untested bt-nopath.exp
+ return -1
+}
+
+nopath_test rel
+
[-- Attachment #3: ChangeLog --]
[-- Type: application/octet-stream, Size: 1445 bytes --]
2011-06-26 Eldar Gaynetdinov <hal9000ed2k@gmail.com>
* frame.h (print_what): Added new element LOC_NO_FULLPATH with
comment.
* stack.c (print_frame_info): Added LOC_NO_FULLPATH in two places near
LOCATION.
(print_frame): Added new variable 'filename' in the condition
scope and the new conditions in this scope with 'filename' and
LOC_NO_FULLPATH before call ui_out_field_string with 'filename'.
'sal.symtab->filename' is used in body of these new conditions.
(backtrace_command_1): Added new argument of this function witn name
'nofull_path'. Added new condition with 'nofull_path'. Arguments that
are passed to print_frame_info depends on this new condition now.
(backtrace_command_args): Added new member 'nofull_path'.
(backtrace_command_stub): backtrace_command_1 is now called with new
argument 'args->nofull_path'.
(backtrace_command): Added new variable 'nofull_path' at this function
scope. Added new condition with 'nofull_path' and 'argv[i]'. 'argc' is
assigned to 'nofull_path' if this new condition is satisfied.
Modified condition with 'fulltrace_arg' by adding 'nofull_path'.
Modified condition with 'fulltrace_arg' in the for-loop by adding
'nofull_path'. Added assignment with 'btargs.nofull_path'. Modified
condition with 'fulltrace_arg' and 'arglen' by adding 'nofull_path'.
(backtrace_full_command): Assign zero to 'btargs.nofull_path' was
added.
* bt-nopath.exp: New file.
* bt-nopath.c: New file.
next prev parent reply other threads:[~2011-07-19 12:17 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-26 20:00 iam ahal
2011-06-26 20:49 ` Phil Muldoon
2011-06-27 16:00 ` Joel Brobecker
2011-06-27 16:18 ` Phil Muldoon
2011-06-28 20:08 ` Tom Tromey
2011-06-28 22:36 ` Phil Muldoon
2011-07-03 18:12 ` iam ahal
2011-07-03 21:13 ` Eli Zaretskii
2011-07-04 11:26 ` iam ahal
2011-07-04 12:05 ` Eli Zaretskii
2011-07-04 21:47 ` Joel Brobecker
2011-07-05 4:35 ` Eli Zaretskii
2011-07-19 14:43 ` Pedro Alves
2011-07-05 8:38 ` iam ahal
2011-07-19 14:19 ` Pedro Alves
2011-07-17 19:24 ` iam ahal
2011-07-19 13:28 ` iam ahal [this message]
2011-07-19 17:04 ` Eli Zaretskii
2011-07-24 21:12 ` iam ahal
2011-07-26 14:17 ` iam ahal
2011-07-28 15:34 ` Tom Tromey
2011-07-28 15:57 ` Tom Tromey
2011-07-28 16:36 ` Joel Brobecker
2011-07-28 17:39 ` Tom Tromey
2011-07-28 17:51 ` Tom Tromey
2011-07-29 12:01 ` Joel Brobecker
2011-07-29 12:36 ` Eli Zaretskii
2011-08-02 19:41 ` iam ahal
2011-08-03 17:45 ` Tom Tromey
2011-10-30 19:52 ` iam ahal
2011-11-02 19:06 ` Tom Tromey
2011-11-02 22:53 ` Doug Evans
2011-12-04 15:52 ` iam ahal
2011-12-04 16:55 ` Eli Zaretskii
2011-12-04 18:41 ` iam ahal
2011-12-04 19:01 ` Pedro Alves
2011-12-04 19:56 ` Eli Zaretskii
2011-12-04 21:00 ` Pedro Alves
2011-12-05 3:54 ` Eli Zaretskii
2011-12-05 5:17 ` Eli Zaretskii
2011-12-06 13:03 ` Pedro Alves
2011-12-06 14:04 ` Eli Zaretskii
2011-12-06 18:00 ` Doug Evans
2011-12-06 20:45 ` Tom Tromey
2011-12-07 8:00 ` Eli Zaretskii
2012-03-10 20:15 ` iam ahal
2012-03-11 1:22 ` asmwarrior
2012-03-12 13:10 ` iam ahal
2012-03-14 16:11 ` Tom Tromey
2012-03-14 16:27 ` Jan Kratochvil
2012-03-14 17:40 ` Eli Zaretskii
2012-03-15 22:46 ` Jan Kratochvil
2012-03-18 18:30 ` iam ahal
2012-03-18 18:35 ` Jan Kratochvil
2012-04-06 14:22 ` Jan Kratochvil
2012-03-18 20:46 ` Eli Zaretskii
2012-03-25 19:27 ` iam ahal
2012-03-25 19:31 ` Jan Kratochvil
2012-03-25 21:23 ` Eli Zaretskii
2011-12-06 12:50 ` Pedro Alves
2011-12-06 20:40 ` Tom Tromey
2011-12-06 23:02 ` Jan Kratochvil
2011-07-29 13:35 ` Jan Kratochvil
2011-08-01 18:04 ` Tom Tromey
2011-06-29 10:09 ` Andrew Burgess
2011-06-29 16:06 ` Joel Brobecker
2011-07-03 18:15 ` Daniel Jacobowitz
2011-06-28 20:08 ` Tom Tromey
2012-04-09 15:39 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA18ubLBZseSxqjWSk1jH7OeZi06K_o75HKc0CN-_iCAjQ5boA@mail.gmail.com \
--to=hal9000ed2k@gmail.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=pmuldoon@redhat.com \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox