This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[breakpoint.c] Does ``break overloaded if x'' leak memory?


Hello,

Now that I understand how breapoint.c:break_command_1() can end up with
several breakpoints :-) I'm wondering if the code that parses the ``if''
condition leaks memory:


  /* Resolve all line numbers to PC's, and verify that conditions
     can be parsed, before setting any breakpoints.  */
  for (i = 0; i < sals.nelts; i++)
    {
      char *tok, *end_tok;
      int toklen;

      resolve_sal_pc (&sals.sals[i]);

     [...]

      tok = arg;

      while (tok && *tok)
	{
	  while (*tok == ' ' || *tok == '\t')
	    tok++;

	  end_tok = tok;

	  while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
	    end_tok++;

	  toklen = end_tok - tok;

	  if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
	    {
	      tok = cond_start = end_tok + 1;
	      cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
	      cond_end = tok;
	    }
	[...]

As far as I can tell the if statement is re-parsed each time round this
loop but, unfortunatly, each time, the old result is thrown away :-(. 
At the end the code ends up with just one expression and that is stored
in all the created breakpoints.

	Andrew

PS: Why? I'm looking to split break_command_1() into the part that
creates the breakpoint and the part that does the parsing.

PPS: I strongly suspect this is correct :-)

(gdb) break foo::overload1arg if 1
[0] cancel
[1] all
[2] foo::overload1arg(double) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:121
[3] foo::overload1arg(float) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:120
[4] foo::overload1arg(unsigned long) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:119
[5] foo::overload1arg(long) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:118
[6] foo::overload1arg(unsigned int) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:117
[7] foo::overload1arg(int) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:116
[8] foo::overload1arg(unsigned short) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:115
[9] foo::overload1arg(short) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:114
[10] foo::overload1arg(unsigned char) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:113
[11] foo::overload1arg(signed char) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:112
[12] foo::overload1arg(char) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:111
[13] foo::overload1arg(void) at
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc:110
> 1
Note: breakpoint 14 also set at pc 0x4d6.
Breakpoint 26 at 0x4d6: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 121.
Note: breakpoint 15 also set at pc 0x4c1.
Breakpoint 27 at 0x4c1: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 120.
Note: breakpoint 16 also set at pc 0x4ac.
Breakpoint 28 at 0x4ac: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 119.
Note: breakpoint 17 also set at pc 0x497.
Breakpoint 29 at 0x497: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 118.
Note: breakpoint 18 also set at pc 0x482.
Breakpoint 30 at 0x482: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 117.
Note: breakpoint 19 also set at pc 0x46d.
Breakpoint 31 at 0x46d: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 116.
Note: breakpoint 20 also set at pc 0x458.
Breakpoint 32 at 0x458: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 115.
Note: breakpoint 21 also set at pc 0x43f.
Breakpoint 33 at 0x43f: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 114.
Note: breakpoint 22 also set at pc 0x426.
Breakpoint 34 at 0x426: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 113.
Note: breakpoint 23 also set at pc 0x40d.
Breakpoint 35 at 0x40d: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 112.
Note: breakpoint 24 also set at pc 0x3f4.
Breakpoint 36 at 0x3f4: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 111.
Note: breakpoint 25 also set at pc 0x3df.
Breakpoint 37 at 0x3df: file
/home/scratch/wip-gdb-breakpoint-B-devo/devo/gdb/testsuite/gdb.c++/ovldbreak.cc,
line 110.
warning: Multiple breakpoints were set.
warning: Use the "delete" command to delete unwanted breakpoints.
(gdb) delete
Delete all breakpoints? (y or n) y
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
gdb in free(): warning: chunk is already free.
(gdb)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]