Bug 3496 - CDTParser backtraces when using some source
Summary: CDTParser backtraces when using some source
Status: RESOLVED FIXED
Alias: None
Product: frysk
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Rick Moseley
URL:
Keywords:
Depends on:
Blocks: 1633
  Show dependency treegraph
 
Reported: 2006-11-09 16:42 UTC by Rick Moseley
Modified: 2006-11-09 20:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rick Moseley 2006-11-09 16:42:51 UTC
When trying to activate the source window to bring up the code below, the
CDTParser backtraces as follows:
java.lang.StringIndexOutOfBoundsException
   at java.lang.String.substring(libgcj.so.7)
   at frysk.dom.cparser.CDTParser$ParserCallBack.enterInclusion(CDTParser.java:882)
   at
org.eclipse.cdt.internal.core.parser.scanner2.ScannerCallbackManager.popCallbacks(ScannerCallbackManager.java:53)
   at
org.eclipse.cdt.internal.core.parser.scanner2.Scanner2.beforeSecondFetchToken(Scanner2.java:142)
   at
org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner.nextToken(BaseScanner.java:1532)
   at org.eclipse.cdt.internal.core.parser.Parser.fetchToken(Parser.java:2742)
   at org.eclipse.cdt.internal.core.parser.Parser.LA(Parser.java:197)
   at org.eclipse.cdt.internal.core.parser.Parser.LT(Parser.java:215)
   at org.eclipse.cdt.internal.core.parser.Parser.errorHandling(Parser.java:2873)
   at
org.eclipse.cdt.internal.core.parser.Parser.failParseWithErrorHandling(Parser.java:3113)
   at org.eclipse.cdt.internal.core.parser.Parser.translationUnit(Parser.java:3059)
   at org.eclipse.cdt.internal.core.parser.Parser.parse(Parser.java:2970)
   at frysk.dom.cparser.CDTParser.parse(CDTParser.java:174)
   at frysk.dom.DOMFactory.createDOM(DOMFactory.java:111)
   at frysk.gui.srcwin.SourceWindow.generateProcStackTrace(SourceWindow.java:1997)
   at frysk.gui.srcwin.SourceWindow.finishSourceWin(SourceWindow.java:327)
   at frysk.gui.srcwin.SourceWindow.handleTask(SourceWindow.java:1934)
   at frysk.gui.srcwin.SourceWindow$SourceWinBlocker$26.run(SourceWindow.java:2269)
   at org.gnu.glib.CustomEvents.runEvents(libgtkjava-2.8.so)
   at org.gnu.gtk.Gtk.gtk_main(libgtkjava-2.8.so)
   at org.gnu.gtk.Gtk.main(libgtkjava-2.8.so)
   at frysk.gui.Gui.gui(Gui.java:245)
   at frysk.gui.FryskGui.main(FryskGui.java:70)


The following code causes that:

// gcc -g -o test -lpthread tester2.c

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <linux/unistd.h>
#include <errno.h>

_syscall0(pid_t,gettid)

pthread_t tester_thread;

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

static char * myname;

void
*do_it ()
{
  int t = 34543;
  while (t > 0)
    t--;

  fprintf (stderr,"attach %s pid=%d -task tid=%d -cli\n", myname, getpid(),
gettid());

  int d = 0;
  int e = 0;

  while (1)
    {
      d++;
      e++;
      if (d == 3)
        {
          if (e == 3)
            e = 0;
          d = 0;
        }
    }
    
  return NULL;
}

void
bak ()
{
  while (1)
    {
      fprintf (stderr,"attach %s pid=%d -task tid=%d -cli\n", myname, getpid(),
gettid());
      int a = 0;
      int b = 0;
      int c = 0;
      while (1)
        {
          a++;
          b++;
          c++;
          if (a + b > 4)
            {
              a = a - c;
              b = b - c;
              c = 0;
            }
        }
    }
}

void 
baz ()
{
  int a;
  int b = 0;
  bak ();
}

void 
bar ()
{
  close (-1);
  close (-1);
  baz ();
  /*Comment */
}

void
foo ()
{
  bar ();
}


int 
main (int argc, char **argv)
{
  myname = argv[0];
  pthread_attr_t attr;
  pthread_attr_init (&attr);
  pthread_create (&tester_thread, &attr, do_it, NULL);

  /* This is a comment */
  foo ();
  int t = 30;

  exit (0);
}
Comment 1 Rick Moseley 2006-11-09 20:28:14 UTC
Fixed in cvs head.  The enterInclusion method was not fully checking whether or
not the include file it was processing was actually inside the current source
file.  The CDTParser callbacks are called when #include files within include
files are processed and we only want to process the ones inside the source file
since we are marking it up for highlighting.