funcscan
Version 1.0.0

de.ovgu.cs.funcscan
Class Worker

java.lang.Object
  extended by de.ovgu.cs.funcscan.Worker

public class Worker
extends Object

The analyzer.

Version:
$Revision: 577 $
Author:
Jens Elkner

Constructor Summary
Worker(File basedir, File nmList, String rm, String cppFlags, boolean isGnu)
          Create a new worker for analyzing information collected by nm and generating several reports.
 
Method Summary
static void destroy()
          Cleanup resources and shutdown all worker thread pools in the VM immediately.
static String extractFuncDef(String name, String code)
          Try to find the definition for a global function with the given name and return it in ANSI notation.
 Map<String,de.ovgu.cs.funcscan.Module.CP> getCallers(boolean vars, boolean sort)
          Get a list of all function or variables names, its provider and potential callers.
 String getDefinition(boolean isVar, String name, Module module)
          Get the definition for the given variable or function.
 Collection<Module> getModules()
          Get all available modules.
 boolean isWorking()
          Check, whether the worker is still scanning/modifying its internal database.
static void redirectErrors(InputStream is)
          Read the given stream in a separate thread line-wise and echo each line to stderr.
 boolean scanNM()
          Remove all currently collected information and rescan the nm info file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Worker

public Worker(File basedir,
              File nmList,
              String rm,
              String cppFlags,
              boolean isGnu)
Create a new worker for analyzing information collected by nm and generating several reports.

Parameters:
basedir - base directory to which the module names aka "*.o" refer.
nmList - object information list produced by nm and mangled by the internal possibly modified awk script.
rm - String to remove from all encountered module filenames to generate the real C source code filename. Might be null.
cppFlags - C pre-processor flags to use (e.g. -I path/include)
isGnu - if true it indicates, that the 'cc' is not a Sun Studio C Compiler. It usually causes much more memory consumption and has a negative impact wrt. the performance of source file scanning.
Method Detail

isWorking

public boolean isWorking()
Check, whether the worker is still scanning/modifying its internal database.

Returns:
false if it is not in a state, which requirtes writing to its internal database.

scanNM

public boolean scanNM()
               throws FileNotFoundException
Remove all currently collected information and rescan the nm info file.

Returns:
true on success.
Throws:
FileNotFoundException
ConcurrentModificationException
See Also:
isWorking()

getCallers

public Map<String,de.ovgu.cs.funcscan.Module.CP> getCallers(boolean vars,
                                                            boolean sort)
                                                     throws FileNotFoundException
Get a list of all function or variables names, its provider and potential callers.

Parameters:
vars - if true find variables, otherwise find functions
sort - if true, sort the result by function/variable names
Returns:
a possibly empty list. Each map in the list has the called function name as its key, and the callers as its values. The first entry in the caller list is always the module, which provides the function.
Throws:
FileNotFoundException

getModules

public Collection<Module> getModules()
                              throws FileNotFoundException
Get all available modules.

Returns:
a possible empty list of modules.
Throws:
FileNotFoundException

redirectErrors

public static void redirectErrors(InputStream is)
Read the given stream in a separate thread line-wise and echo each line to stderr. The thread gets stopped, when the InputStream indicates the end of the input stream.

Parameters:
is - stream to read.

extractFuncDef

public static String extractFuncDef(String name,
                                    String code)
Try to find the definition for a global function with the given name and return it in ANSI notation.

Parameters:
name - the name of the function to find
code - the source code, which contains the function incl. its body
Returns:
null if not found or the appropriate code snippet code not be parsed, the function definition otherwise.
See Also:
getDefinition(boolean, String, Module)

getDefinition

public String getDefinition(boolean isVar,
                            String name,
                            Module module)
Get the definition for the given variable or function.

If necessary, this method invokes the C pre-processor as 'cc -E' and the pre-processor flags given in the constructor of this instance. If cc is not a Sun Studio C compiler, one should set the isGnu flag in the workers constructor (otherwise the worker will find almost nothing).

Since source file scanning is based on a 90:10 is good enough approach, the scanner will not find complex or tricky definitions like function pointers parameters.

Parameters:
isVar - if true the given name is assumed to be a variable name, a function name otherwise.
name - the name of the function or variable in question
module - the module, which owns this global function or variable.
Returns:
null if the name or module is null. Otherwise an empty string, if the source code could not be found or pre-processed or the definition could not be found, the definition otherwise.

destroy

public static void destroy()
Cleanup resources and shutdown all worker thread pools in the VM immediately.


funcscan
Version 1.0.0

Created by Jens Elkner