Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* [Bug:cli] Loading user-defined function generates an internal error
@ 2009-12-30  5:35 Nick Roberts
  2009-12-30  5:46 ` Joel Brobecker
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2009-12-30  5:35 UTC (permalink / raw)
  To: gdb


If the user-defined function below is put in a file user.cmd, say, then in
internal error is generated upon loading it:

..
(gdb) source user.cmd
utils.c:1206: internal-error: virtual memory exhausted.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) [answered Y; input not from terminal]
utils.c:1206: internal-error: virtual memory exhausted.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) [answered Y; input not from terminal]
Aborted (core dumped)

This didn't used to happen, say 3 months ago.

-- 
Nick                                           http://users.snap.net.nz/~nickrob


define p_tree

  set $tree = ($arg0)
  set $i = 0
  set $node = $tree->_M_t->_M_impl->_M_header->_M_left
  set $tree_size = $tree->_M_t->_M_impl->_M_node_count

  while ($i < $tree_size)
    set $i++
    printf "NODE %d: ", $i
    set $value = (void *)($node + 1)
    p *($arg1 *)$value
    set $value = $value + 4
    p *($arg2 *)$value

    # Next (bigger) value must be to right...
    if ($node->_M_right != 0)
      set $node = $node->_M_right

      # Descend tree while there is a left node.
      while ($node->_M_left != 0)
        set $node = $node->_M_left
      end

      # ...or further up the tree.
    else
      set $tmp_node = $node->_M_parent

      # Ascend tree while at right node.
      while ($node == $tmp_node->_M_right)
        set $node = $tmp_node
        set $tmp_node = $tmp_node->_M_parent
      end

      # Set to parent of first left node (condition always true?)
      if ($node->_M_right != $tmp_node)
        set $node = $tmp_node
      end
    end
  end
end


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Bug:cli] Loading user-defined function generates an internal  error
  2009-12-30  5:35 [Bug:cli] Loading user-defined function generates an internal error Nick Roberts
@ 2009-12-30  5:46 ` Joel Brobecker
  2009-12-30  8:50   ` Nick Roberts
  2009-12-30 22:26   ` Nick Roberts
  0 siblings, 2 replies; 9+ messages in thread
From: Joel Brobecker @ 2009-12-30  5:46 UTC (permalink / raw)
  To: Nick Roberts; +Cc: gdb

> If the user-defined function below is put in a file user.cmd, say, then in
> internal error is generated upon loading it:

I can reproduce too. Have you tried debugging the problem?

-- 
Joel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Bug:cli] Loading user-defined function generates an internal  error
  2009-12-30  5:46 ` Joel Brobecker
@ 2009-12-30  8:50   ` Nick Roberts
  2009-12-31  6:27     ` Vladimir Prus
  2009-12-30 22:26   ` Nick Roberts
  1 sibling, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2009-12-30  8:50 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb

 > > If the user-defined function below is put in a file user.cmd, say, then in
 > > internal error is generated upon loading it:
 > 
 > I can reproduce too. Have you tried debugging the problem?

It's due to this change:

2009-11-18  Vladimir Prus  <vladimir@codesourcery.com>

	* cli/cli-script.c (process_next_line): Recognize 'end'
	even when the line has leading space and we're not parsing
	commands.

-- 
Nick                                           http://users.snap.net.nz/~nickrob


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Bug:cli] Loading user-defined function generates an internal  error
  2009-12-30  5:46 ` Joel Brobecker
  2009-12-30  8:50   ` Nick Roberts
@ 2009-12-30 22:26   ` Nick Roberts
  2010-01-01  8:41     ` [patch] Fix crash on CLI indented comments [Re: [Bug:cli] Loading user-defined function generates an internal error] Jan Kratochvil
  1 sibling, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2009-12-30 22:26 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb

 > I can reproduce too. Have you tried debugging the problem?

Heres a simpler user defined function that gives a segmentation fault.  It
appears that GDB can no longer handle indented comments.

define my_fun
 #indented comment
end

-- 
Nick                                           http://users.snap.net.nz/~nickrob


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Bug:cli] Loading user-defined function generates an internal  error
  2009-12-30  8:50   ` Nick Roberts
@ 2009-12-31  6:27     ` Vladimir Prus
  0 siblings, 0 replies; 9+ messages in thread
From: Vladimir Prus @ 2009-12-31  6:27 UTC (permalink / raw)
  To: gdb

Nick Roberts wrote:

>  > > If the user-defined function below is put in a file user.cmd, say, then in
>  > > internal error is generated upon loading it:
>  > 
>  > I can reproduce too. Have you tried debugging the problem?
> 
> It's due to this change:
> 
> 2009-11-18  Vladimir Prus  <vladimir@codesourcery.com>
> 
> * cli/cli-script.c (process_next_line): Recognize 'end'
> even when the line has leading space and we're not parsing
> commands.

Do you happen to know what is wrong, exactly? Unfortunately, I won't
be able to address this until Jan 11, so if you don't have the time
to investigate further, I suggest you open an issue in bugzilla.

Thanks,
Volodya



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [patch] Fix crash on CLI indented comments  [Re: [Bug:cli] Loading  user-defined function generates an internal  error]
  2009-12-30 22:26   ` Nick Roberts
@ 2010-01-01  8:41     ` Jan Kratochvil
  2010-01-01 10:36       ` Joel Brobecker
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2010-01-01  8:41 UTC (permalink / raw)
  To: Nick Roberts; +Cc: Joel Brobecker, gdb, gdb-patches

On Wed, 30 Dec 2009 23:26:27 +0100, Nick Roberts wrote:
> Heres a simpler user defined function that gives a segmentation fault.  It
> appears that GDB can no longer handle indented comments.
> 
> define my_fun
>  #indented comment
> end

      (*command)->line = savestring (p, p1 - p);
#1  0x0000000000487405 in savestring (ptr=0x1d5dd31 "", size=18446744073709551615) at utils.c:1377
(gdb) p/x size
$1 = 0xffffffffffffffff
(gdb) p p
$2 = 0x1d5dd31 ""
(gdb) p p1
$3 = 0x1d5dd30 " "


OK to check-in? Probably [obv].


Thanks,
Jan


2010-01-01  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cli/cli-script.c (process_next_line): Check P2 overrun.

--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -893,7 +893,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands)
 
   p2 = p;
   /* Strip leading whitespace.  */
-  while (*p2 == ' ' || *p2 == '\t')
+  while (p2 != p1 && (*p2 == ' ' || *p2 == '\t'))
     p2++;
 
   /* 'end' is always recognized, regardless of parse_commands value. 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] Fix crash on CLI indented comments  [Re: [Bug:cli]  Loading user-defined function generates an internal  error]
  2010-01-01  8:41     ` [patch] Fix crash on CLI indented comments [Re: [Bug:cli] Loading user-defined function generates an internal error] Jan Kratochvil
@ 2010-01-01 10:36       ` Joel Brobecker
  2010-01-01 11:01         ` Jan Kratochvil
  2010-01-01 11:12         ` Joel Brobecker
  0 siblings, 2 replies; 9+ messages in thread
From: Joel Brobecker @ 2010-01-01 10:36 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Nick Roberts, gdb, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 642 bytes --]

> 2010-01-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* cli/cli-script.c (process_next_line): Check P2 overrun.

Yes - I agree it's obvious when you know that the comment is stripped
upstream...

Approved. Thanks for fixing.

Given the number of regressions/failures we've seen in this area,
I really thought we should add a test for this, so I created
the attached patch.  I will commit after you have committed yours.

gdb/testsuite/

        Test indented comment in file being sourced.
        * commands.exp: Test indented comment in file being sourced.

Tested on x86_64-linux.  Fails miserably without Jan's patch.

-- 
Joel

[-- Attachment #2: test-indented-comment.diff --]
[-- Type: text/x-diff, Size: 1246 bytes --]

commit 0f79c42a551762d87088fd5916c4ed390dde9942
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Fri Jan 1 14:31:07 2010 +0400

    Test indented comment in file being sourced.
    
            * commands.exp: Test indented comment in file being sourced.

diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 2aba51f..228c464 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -577,6 +577,19 @@ proc stray_arg0_test { } {
 	"stray_arg0_test #4"
 }
 
+# Test that GDB is able to source a file with an indented comment.
+proc source_file_with_indented_comment {} {
+    set fd [open "file1" w]
+    puts $fd \
+{define my_fun
+    #indented comment
+end
+echo Done!\n}
+    close $fd
+
+    gdb_test "source file1" "Done!" "source file with indented comment"
+}
+
 # Test that GDB can handle arguments when sourcing files recursively.
 # If the arguments are overwritten with ####### then the test has failed.
 proc recursive_source_test {} {
@@ -761,6 +774,7 @@ deprecated_command_test
 bp_deleted_in_command_test
 temporary_breakpoint_commands
 stray_arg0_test
+source_file_with_indented_comment
 recursive_source_test
 if_commands_test
 redefine_hook_test

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] Fix crash on CLI indented comments  [Re: [Bug:cli]   Loading user-defined function generates an internal  error]
  2010-01-01 10:36       ` Joel Brobecker
@ 2010-01-01 11:01         ` Jan Kratochvil
  2010-01-01 11:12         ` Joel Brobecker
  1 sibling, 0 replies; 9+ messages in thread
From: Jan Kratochvil @ 2010-01-01 11:01 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Nick Roberts, gdb, gdb-patches

On Fri, 01 Jan 2010 11:35:20 +0100, Joel Brobecker wrote:
> Approved. Thanks for fixing.

Checked-in.


>         Test indented comment in file being sourced.
>         * commands.exp: Test indented comment in file being sourced.

OK, thanks for this work.


Regards,
Jan


http://sourceware.org/ml/gdb-cvs/2010-01/msg00014.html

--- src/gdb/ChangeLog	2010/01/01 09:44:05	1.11190
+++ src/gdb/ChangeLog	2010/01/01 10:57:42	1.11191
@@ -1,3 +1,7 @@
+2010-01-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* cli/cli-script.c (process_next_line): Check P2 overrun.
+
 2009-01-01  Joel Brobecker  <brobecker@adacore.com>
 
 	Update the copyright hearder to add year 2010 for most GDB files.
--- src/gdb/cli/cli-script.c	2010/01/01 07:31:47	1.55
+++ src/gdb/cli/cli-script.c	2010/01/01 10:57:43	1.56
@@ -893,7 +893,7 @@
 
   p2 = p;
   /* Strip leading whitespace.  */
-  while (*p2 == ' ' || *p2 == '\t')
+  while (p2 != p1 && (*p2 == ' ' || *p2 == '\t'))
     p2++;
 
   /* 'end' is always recognized, regardless of parse_commands value. 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] Fix crash on CLI indented comments  [Re: [Bug:cli]   Loading user-defined function generates an internal  error]
  2010-01-01 10:36       ` Joel Brobecker
  2010-01-01 11:01         ` Jan Kratochvil
@ 2010-01-01 11:12         ` Joel Brobecker
  1 sibling, 0 replies; 9+ messages in thread
From: Joel Brobecker @ 2010-01-01 11:12 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Nick Roberts, gdb, gdb-patches

> gdb/testsuite/
> 
>         Test indented comment in file being sourced.
>         * gdb.base/commands.exp: Test indented comment in file being sourced.

This patch is now in as well. (notice that I added the missing gdb.base
in the name of the file - oops)

-- 
Joel


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-01-01 11:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-30  5:35 [Bug:cli] Loading user-defined function generates an internal error Nick Roberts
2009-12-30  5:46 ` Joel Brobecker
2009-12-30  8:50   ` Nick Roberts
2009-12-31  6:27     ` Vladimir Prus
2009-12-30 22:26   ` Nick Roberts
2010-01-01  8:41     ` [patch] Fix crash on CLI indented comments [Re: [Bug:cli] Loading user-defined function generates an internal error] Jan Kratochvil
2010-01-01 10:36       ` Joel Brobecker
2010-01-01 11:01         ` Jan Kratochvil
2010-01-01 11:12         ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox