mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Adds a trace option for logging exceptions caught and ignored by the parser.
This commit is contained in:
parent
7b43f74317
commit
45fecb58d9
11 changed files with 138 additions and 71 deletions
|
@ -6,6 +6,9 @@ org.eclipse.cdt.core/debug/model=false
|
|||
# Reports parser activity
|
||||
org.eclipse.cdt.core/debug/parser=false
|
||||
|
||||
# Prints parser stack traces
|
||||
org.eclipse.cdt.core/debug/parser/exceptions=false
|
||||
|
||||
# Reports scanner activity
|
||||
org.eclipse.cdt.core/debug/scanner=false
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
@ -33,6 +34,7 @@ public class Util implements ICLogConstants {
|
|||
public static boolean VERBOSE_PARSER = false;
|
||||
public static boolean VERBOSE_SCANNER = false;
|
||||
public static boolean VERBOSE_MODEL = false;
|
||||
public static boolean PARSER_EXCEPTIONS= false;
|
||||
|
||||
public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
|
||||
|
@ -207,7 +209,7 @@ public class Util implements ICLogConstants {
|
|||
// Time stamp
|
||||
if (addTimeStamp)
|
||||
message = MessageFormat.format("[{0}] {1}", new Object[]{ //$NON-NLS-1$
|
||||
new Long(System.currentTimeMillis()), message}); //$NON-NLS-1$
|
||||
new Long(System.currentTimeMillis()), message});
|
||||
while (message.length() > 100) {
|
||||
String partial = message.substring(0, 100);
|
||||
message = message.substring(100);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
public abstract class AbstractParserLogService implements IParserLogService {
|
||||
|
||||
public void traceLog(String message) {
|
||||
}
|
||||
|
||||
public void errorLog(String message) {
|
||||
}
|
||||
|
||||
public boolean isTracing(){
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean traceExceptions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void traceException(Throwable th) {
|
||||
if (traceExceptions()) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,27 +14,6 @@ package org.eclipse.cdt.core.parser;
|
|||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class DefaultLogService implements IParserLogService
|
||||
public class DefaultLogService extends AbstractParserLogService
|
||||
{
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String)
|
||||
*/
|
||||
public void traceLog(String message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String)
|
||||
*/
|
||||
public void errorLog(String message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public boolean isTracing(){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,21 +13,5 @@ package org.eclipse.cdt.core.parser;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class NullLogService implements IParserLogService {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String)
|
||||
*/
|
||||
public void traceLog(String message) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String)
|
||||
*/
|
||||
public void errorLog(String message) {
|
||||
}
|
||||
|
||||
public boolean isTracing(){
|
||||
return false;
|
||||
}
|
||||
public class NullLogService extends AbstractParserLogService {
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -58,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.parser.AbstractParserLogService;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
|
@ -72,7 +74,7 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
*/
|
||||
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||
|
||||
protected final IParserLogService log;
|
||||
protected final AbstractParserLogService log;
|
||||
|
||||
protected final IScanner scanner;
|
||||
|
||||
|
@ -97,7 +99,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
boolean supportKnRC, boolean supportGCCOtherBuiltinSymbols,
|
||||
boolean supportAttributeSpecifiers) {
|
||||
this.scanner = scanner;
|
||||
this.log = logService;
|
||||
this.log = wrapLogService(logService);
|
||||
this.mode = parserMode;
|
||||
this.supportStatementsInExpressions = supportStatementsInExpressions;
|
||||
this.supportTypeOfUnaries = supportTypeOfUnaries;
|
||||
|
@ -107,12 +109,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
this.supportAttributeSpecifiers = supportAttributeSpecifiers;
|
||||
}
|
||||
|
||||
protected boolean parsePassed = true;
|
||||
protected boolean parsePassed = true;
|
||||
|
||||
protected BacktrackException backtrack = new BacktrackException();
|
||||
|
||||
protected int backtrackCount = 0;
|
||||
|
||||
private AbstractParserLogService wrapLogService(IParserLogService logService) {
|
||||
if (logService instanceof AbstractParserLogService) {
|
||||
return (AbstractParserLogService) logService;
|
||||
}
|
||||
else {
|
||||
return new ParserLogServiceWrapper(logService);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void throwBacktrack(int offset, int length)
|
||||
throws BacktrackException {
|
||||
++backtrackCount;
|
||||
|
@ -355,18 +366,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* @param e
|
||||
*/
|
||||
protected void logThrowable(String methodName, Throwable e) {
|
||||
if (e != null && log.isTracing()) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Parser: Unexpected throwable in "); //$NON-NLS-1$
|
||||
buffer.append(methodName);
|
||||
buffer.append(":"); //$NON-NLS-1$
|
||||
buffer.append(e.getClass().getName());
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
buffer.append(e.getMessage());
|
||||
buffer.append(". w/"); //$NON-NLS-1$
|
||||
buffer.append(scanner.toString());
|
||||
log.traceLog(buffer.toString());
|
||||
// log.errorLog( buffer.toString() );
|
||||
if (e != null) {
|
||||
if (log.isTracing()) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Parser: Unexpected throwable in "); //$NON-NLS-1$
|
||||
buffer.append(methodName);
|
||||
buffer.append(":"); //$NON-NLS-1$
|
||||
buffer.append(e.getClass().getName());
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
buffer.append(e.getMessage());
|
||||
buffer.append(". w/"); //$NON-NLS-1$
|
||||
buffer.append(scanner.toString());
|
||||
log.traceLog(buffer.toString());
|
||||
}
|
||||
log.traceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,18 +392,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* @param e
|
||||
*/
|
||||
protected void logException(String methodName, Exception e) {
|
||||
if (!(e instanceof EndOfFileException) && e != null && log.isTracing()) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$
|
||||
buffer.append(methodName);
|
||||
buffer.append(":"); //$NON-NLS-1$
|
||||
buffer.append(e.getClass().getName());
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
buffer.append(e.getMessage());
|
||||
buffer.append(". w/"); //$NON-NLS-1$
|
||||
buffer.append(scanner.toString());
|
||||
log.traceLog(buffer.toString());
|
||||
// log.errorLog(buffer.toString());
|
||||
if (!(e instanceof EndOfFileException) && e != null) {
|
||||
if (log.isTracing()) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$
|
||||
buffer.append(methodName);
|
||||
buffer.append(":"); //$NON-NLS-1$
|
||||
buffer.append(e.getClass().getName());
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
buffer.append(e.getMessage());
|
||||
buffer.append(". w/"); //$NON-NLS-1$
|
||||
buffer.append(scanner.toString());
|
||||
log.traceLog(buffer.toString());
|
||||
// log.errorLog(buffer.toString());
|
||||
}
|
||||
log.traceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.AbstractParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
|
||||
public class ParserLogServiceWrapper extends AbstractParserLogService {
|
||||
|
||||
private IParserLogService fDelegate;
|
||||
|
||||
public ParserLogServiceWrapper(IParserLogService log) {
|
||||
fDelegate= log;
|
||||
}
|
||||
public boolean isTracing() {
|
||||
return fDelegate.isTracing();
|
||||
}
|
||||
|
||||
public void traceLog(String message) {
|
||||
fDelegate.traceLog(message);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.eclipse.osgi.util.NLS;
|
|||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.indexer.messages"; //$NON-NLS-1$
|
||||
public static String PDOMIndexerTask_collectingFilesTask;
|
||||
public static String PDOMIndexerTask_errorWhileParsing;
|
||||
public static String PDOMIndexerTask_parsingFileTask;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
PDOMIndexerTask_collectingFilesTask=Collecting files to parse
|
||||
PDOMIndexerTask_parsingFileTask=parsing {0} ({1})
|
||||
PDOMIndexerTask_errorWhileParsing=Error while parsing {0}.
|
||||
|
|
|
@ -947,6 +947,7 @@ public class CCorePlugin extends Plugin {
|
|||
|
||||
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$
|
||||
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
|
||||
private static final String PARSER_EXCEPTIONS = CCorePlugin.PLUGIN_ID + "/debug/parser/exceptions" ; //$NON-NLS-1$
|
||||
private static final String SCANNER = CCorePlugin.PLUGIN_ID + "/debug/scanner"; //$NON-NLS-1$
|
||||
private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ; //$NON-NLS-1$
|
||||
//private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$
|
||||
|
@ -959,7 +960,10 @@ public class CCorePlugin extends Plugin {
|
|||
if(CCorePlugin.getDefault().isDebugging()) {
|
||||
String option = Platform.getDebugOption(PARSER);
|
||||
if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
|
||||
|
||||
|
||||
option = Platform.getDebugOption(PARSER_EXCEPTIONS);
|
||||
if( option != null ) Util.PARSER_EXCEPTIONS = option.equalsIgnoreCase("true"); //$NON-NLS-1$
|
||||
|
||||
option = Platform.getDebugOption(SCANNER);
|
||||
if( option != null ) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true"); //$NON-NLS-1$
|
||||
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.AbstractParserLogService;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
|
||||
|
||||
|
@ -20,15 +21,25 @@ import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
|
|||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class ParserLogService implements IParserLogService
|
||||
public class ParserLogService extends AbstractParserLogService
|
||||
{
|
||||
|
||||
final DebugLogConstant topic;
|
||||
final DebugLogConstant topic;
|
||||
final boolean fIsTracing;
|
||||
final boolean fIsTracingExceptions;
|
||||
|
||||
/**
|
||||
* @param constant
|
||||
*/
|
||||
public ParserLogService(DebugLogConstant constant) {
|
||||
topic = constant;
|
||||
if (CCorePlugin.getDefault() == null) {
|
||||
fIsTracing= fIsTracingExceptions= false;
|
||||
}
|
||||
else {
|
||||
fIsTracingExceptions= Util.PARSER_EXCEPTIONS;
|
||||
fIsTracing= Util.isActive(topic);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue