mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Initial contribution of Mac Port from Greg Watson.
This commit is contained in:
parent
7a40c54552
commit
04c74b6af0
44 changed files with 4722 additions and 7 deletions
|
@ -347,7 +347,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
|||
outputPrefix = info.getOutputPrefix(outputExtension);
|
||||
|
||||
// The command to build
|
||||
String buildCmd = cmd + WHITESPACE + buildFlags + WHITESPACE + outflag + outputPrefix + OUT_MACRO + WHITESPACE + IN_MACRO;
|
||||
String buildCmd = cmd + WHITESPACE + buildFlags + WHITESPACE + outflag + WHITESPACE + outputPrefix + OUT_MACRO + WHITESPACE + IN_MACRO;
|
||||
buffer.append(TAB + AT + ECHO + WHITESPACE + buildCmd + NEWLINE);
|
||||
buffer.append(TAB + AT + buildCmd);
|
||||
|
||||
|
@ -583,7 +583,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
|
|||
}
|
||||
buffer.append(NEWLINE);
|
||||
buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + MESSAGE_START_BUILD + WHITESPACE + OUT_MACRO + SINGLE_QUOTE + NEWLINE);
|
||||
buffer.append(TAB + cmd + WHITESPACE + flags + WHITESPACE + outflag + OUT_MACRO + WHITESPACE + "$(OBJS) $(USER_OBJS) $(LIBS)" + NEWLINE); //$NON-NLS-1$
|
||||
buffer.append(TAB + cmd + WHITESPACE + flags + WHITESPACE + outflag + WHITESPACE + OUT_MACRO + WHITESPACE + "$(OBJS) $(USER_OBJS) $(LIBS)" + NEWLINE); //$NON-NLS-1$
|
||||
buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + MESSAGE_FINISH_FILE + WHITESPACE + OUT_MACRO + SINGLE_QUOTE + NEWLINE + NEWLINE);
|
||||
|
||||
// Always add a clean target
|
||||
|
|
|
@ -29,7 +29,9 @@ TargetName.gnu.lib=Static Library (Gnu)
|
|||
TargetName.cygw.exe=Executable (Gnu on Windows)
|
||||
TargetName.cygw.so=Shared Library (Gnu on Windows)
|
||||
TargetName.cygw.lib=Static Library (Gnu on Windows)
|
||||
|
||||
TargetName.macosx.exe=Executable (MacOS X)
|
||||
TargetName.macosx.so=Shared Library (MacOS X)
|
||||
TargetName.macosx.lib=Static Library (MacOS X)
|
||||
|
||||
# No longer needed post-2.0
|
||||
TargetName.cygw=Cygwin
|
||||
|
@ -64,6 +66,10 @@ ToolName.linker.gnu.cpp = GCC C++ Linker
|
|||
ToolName.archiver.gnu = GCC Archiver
|
||||
ToolName.assembler.gnu = GCC Assembler
|
||||
|
||||
# Mach-O tool names
|
||||
ToolName.linker.macosx.c = MacOS X C Linker
|
||||
ToolName.linker.macosx.cpp = MacOS X C++ Linker
|
||||
|
||||
# Generic Category Names
|
||||
OptionCategory.Symbols = Symbols
|
||||
OptionCategory.Preproc = Preprocessor
|
||||
|
@ -138,4 +144,5 @@ Option.Gnu.Assembler.version=Announce version (-v)
|
|||
Option.Windows.Windres.OutputFormat = Output format
|
||||
Option.Windows.Windres.OutputFormat.Coff = coff (--output-format coff)
|
||||
Option.Windows.Windres.OutputFormat.RC = rc (--output-format rc)
|
||||
Option.Windows.Windres.OutputFormat.Res = res (--output-format res)
|
||||
Option.Windows.Windres.OutputFormat.Res = res (--output-format res)
|
||||
Option.MacOSX.Linker.Shared=Shared (-Wl,-dylib)
|
|
@ -479,6 +479,224 @@
|
|||
name="%Option.Gnu.Assembler.version"
|
||||
id="gnu.both.asm.option.version"/>
|
||||
</tool>
|
||||
<tool
|
||||
natureFilter="cnature"
|
||||
sources="o"
|
||||
name="%ToolName.linker.macosx.c"
|
||||
outputFlag="-o"
|
||||
command="gcc"
|
||||
dependencyCalculator="org.eclipse.cdt.managedbuilder.makegen.internal.DefaultNoDependencyCalculator"
|
||||
id="cdt.managedbuild.tool.macosx.c.linker">
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.c.linker"
|
||||
name="%OptionCategory.General"
|
||||
id="macosx.c.link.category.general">
|
||||
</optionCategory>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoStartFiles"
|
||||
category="macosx.c.link.category.general"
|
||||
command="-nostartfiles"
|
||||
id="macosx.c.link.option.nostart"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoDefLibs"
|
||||
category="macosx.c.link.category.general"
|
||||
command="-nodefaultlibs"
|
||||
id="macosx.c.link.option.nodeflibs"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoStdLibs"
|
||||
category="macosx.c.link.category.general"
|
||||
command="-nostdlib"
|
||||
id="macosx.c.link.option.nostdlibs"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.Strip"
|
||||
category="macosx.c.link.category.general"
|
||||
command="--strip-all"
|
||||
id="macosx.c.link.option.strip"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.Static"
|
||||
category="macosx.c.link.category.general"
|
||||
command="-static"
|
||||
id="macosx.c.link.option.noshared"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.c.linker"
|
||||
name="%OptionCategory.Libs"
|
||||
id="macosx.c.link.category.libs">
|
||||
</optionCategory>
|
||||
<option
|
||||
name="%Option.Posix.Libs"
|
||||
category="macosx.c.link.category.libs"
|
||||
command="-l"
|
||||
id="macosx.c.link.option.libs"
|
||||
browseType="file"
|
||||
valueType="libs">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.Libsearch"
|
||||
category="macosx.c.link.category.libs"
|
||||
command="-L"
|
||||
id="macosx.c.link.option.paths"
|
||||
browseType="directory"
|
||||
valueType="stringList">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.c.linker"
|
||||
name="%OptionCategory.Misc"
|
||||
id="macosx.c.link.category.other">
|
||||
</optionCategory>
|
||||
<option
|
||||
name="%Option.Posix.Linker.Flags"
|
||||
category="macosx.c.link.category.other"
|
||||
valueType="string"
|
||||
id="macosx.c.link.option.ldflags">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.Linker.XLinker"
|
||||
category="macosx.c.link.category.other"
|
||||
command="-Xlinker,"
|
||||
valueType="stringList"
|
||||
id="macosx.c.link.option.other">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.UserObjs"
|
||||
category="macosx.c.link.category.other"
|
||||
browseType="file"
|
||||
valueType="userObjs"
|
||||
id="macosx.c.link.option.userobjs">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.c.linker"
|
||||
name="%OptionCategory.Shared.Settings"
|
||||
id="macosx.c.link.category.shared">
|
||||
</optionCategory>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.MacOSX.Linker.Shared"
|
||||
category="macosx.c.link.category.shared"
|
||||
command="-Wl,-dylib"
|
||||
id="macosx.c.link.option.shared"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
</tool>
|
||||
<tool
|
||||
natureFilter="ccnature"
|
||||
sources="o"
|
||||
name="%ToolName.linker.macosx.cpp"
|
||||
outputFlag="-o"
|
||||
command="g++"
|
||||
dependencyCalculator="org.eclipse.cdt.managedbuilder.makegen.internal.DefaultNoDependencyCalculator"
|
||||
id="cdt.managedbuild.tool.macosx.cpp.linker">
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.cpp.linker"
|
||||
name="%OptionCategory.General"
|
||||
id="macosx.cpp.link.category.options">
|
||||
</optionCategory>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoStartFiles"
|
||||
category="macosx.cpp.link.category.options"
|
||||
command="-nostartfiles"
|
||||
id="macosx.cpp.link.option.nostart"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoDefLibs"
|
||||
category="macosx.cpp.link.category.options"
|
||||
command="-nodefaultlibs"
|
||||
id="macosx.cpp.link.option.nodeflibs"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.NoStdLibs"
|
||||
category="macosx.cpp.link.category.options"
|
||||
command="-nostdlib"
|
||||
id="macosx.cpp.link.option.nostdlibs"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.Posix.Linker.Strip"
|
||||
category="macosx.cpp.link.category.options"
|
||||
command="--strip-all"
|
||||
id="macosx.cpp.link.option.strip"
|
||||
valueType="boolean">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.cpp.linker"
|
||||
name="%OptionCategory.Libs"
|
||||
id="macosx.cpp.link.category.libs">
|
||||
</optionCategory>
|
||||
<option
|
||||
name="%Option.Posix.Libs"
|
||||
category="macosx.cpp.link.category.libs"
|
||||
command="-l"
|
||||
id="macosx.cpp.link.option.libs"
|
||||
browseType="file"
|
||||
valueType="libs">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.Libsearch"
|
||||
category="macosx.cpp.link.category.libs"
|
||||
command="-L"
|
||||
id="macosx.cpp.link.option.paths"
|
||||
browseType="directory"
|
||||
valueType="stringList">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.cpp.linker"
|
||||
name="%OptionCategory.Misc"
|
||||
id="macosx.cpp.link.category.other">
|
||||
</optionCategory>
|
||||
<option
|
||||
name="%Option.Posix.Linker.Flags"
|
||||
category="macosx.cpp.link.category.other"
|
||||
valueType="string"
|
||||
id="macosx.cpp.link.option.flags">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.Linker.XLinker"
|
||||
category="macosx.cpp.link.category.other"
|
||||
command="-Xlinker "
|
||||
valueType="stringList"
|
||||
id="macosx.cpp.link.option.other">
|
||||
</option>
|
||||
<option
|
||||
name="%Option.Posix.UserObjs"
|
||||
category="macosx.cpp.link.category.other"
|
||||
browseType="file"
|
||||
valueType="userObjs"
|
||||
id="macosx.cpp.link.option.userobjs">
|
||||
</option>
|
||||
<optionCategory
|
||||
owner="cdt.managedbuild.tool.macosx.cpp.linker"
|
||||
name="%OptionCategory.Shared.Settings"
|
||||
id="macosx.cpp.link.category.shared">
|
||||
</optionCategory>
|
||||
<option
|
||||
defaultValue="false"
|
||||
name="%Option.MacOSX.Linker.Shared"
|
||||
category="macosx.cpp.link.category.shared"
|
||||
command="-Wl,-dylib"
|
||||
valueType="boolean"
|
||||
id="macosx.cpp.link.option.shared">
|
||||
</option>
|
||||
</tool>
|
||||
<target
|
||||
name="%TargetName.gnu"
|
||||
id="cdt.managedbuild.target.gnu"
|
||||
|
@ -959,7 +1177,7 @@
|
|||
</target>
|
||||
<target
|
||||
isAbstract="false"
|
||||
osList="solaris,linux,hpux,aix,macosx,qnx"
|
||||
osList="solaris,linux,hpux,aix,qnx"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
isTest="false"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
|
@ -1027,7 +1245,7 @@
|
|||
</target>
|
||||
<target
|
||||
isTest="false"
|
||||
osList="solaris,linux,hpux,aix,macosx,qnx"
|
||||
osList="solaris,linux,hpux,aix,qnx"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
name="%TargetName.gnu.so"
|
||||
|
@ -1106,7 +1324,7 @@
|
|||
</target>
|
||||
<target
|
||||
isTest="false"
|
||||
osList="solaris,linux,hpux,aix,macosx,qnx"
|
||||
osList="solaris,linux,hpux,aix,qnx"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
name="%TargetName.gnu.lib"
|
||||
|
@ -1392,6 +1610,231 @@
|
|||
id="cdt.managedbuild.tool.gnu.archiver">
|
||||
</toolReference>
|
||||
</target>
|
||||
<target
|
||||
name="%TargetName.macosx.exe"
|
||||
id="cdt.managedbuild.target.macosx.exe"
|
||||
isTest="false"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
isAbstract="false"
|
||||
binaryParser="org.eclipse.cdt.core.MachO"
|
||||
parent="cdt.managedbuild.target.gnu"
|
||||
osList="macosx">
|
||||
<configuration
|
||||
name="%ConfigName.Dbg"
|
||||
id="cdt.managedbuild.config.gnu.macosx.exe.debug">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.none"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.max"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.none"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.max"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<configuration
|
||||
name="%ConfigName.Rel"
|
||||
id="cdt.managedbuild.config.macosx.exe.release">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.most"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.none"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.most"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.none"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<toolReference
|
||||
outputs="exe"
|
||||
id="cdt.managedbuild.tool.macosx.c.linker">
|
||||
</toolReference>
|
||||
<toolReference
|
||||
outputs="exe"
|
||||
id="cdt.managedbuild.tool.macosx.cpp.linker">
|
||||
</toolReference>
|
||||
</target>
|
||||
<target
|
||||
name="%TargetName.macosx.so"
|
||||
id="cdt.managedbuild.target.macosx.so"
|
||||
isTest="false"
|
||||
defaultExtension="dylib"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
isAbstract="false"
|
||||
binaryParser="org.eclipse.cdt.core.MachO"
|
||||
parent="cdt.managedbuild.target.gnu"
|
||||
osList="macosx">
|
||||
<configuration
|
||||
name="%ConfigName.Dbg"
|
||||
id="cdt.managedbuild.config.macosx.so.debug">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.none"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.max"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.none"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.max"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<configuration
|
||||
name="%ConfigName.Rel"
|
||||
id="cdt.managedbuild.config.macosx.so.release">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.most"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.none"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.most"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.none"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<toolReference
|
||||
outputs="dylib"
|
||||
outputPrefix="lib"
|
||||
id="cdt.managedbuild.tool.macosx.c.linker">
|
||||
<optionReference
|
||||
defaultValue="true"
|
||||
id="macosx.c.link.option.shared"/>
|
||||
<optionReference
|
||||
defaultValue="true"
|
||||
id="macosx.c.link.option.nostart"/>
|
||||
<optionReference
|
||||
defaultValue="true"
|
||||
id="macosx.c.link.option.nodeflibs"/>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
outputs="dylib"
|
||||
id="cdt.managedbuild.tool.macosx.cpp.linker">
|
||||
<optionReference
|
||||
defaultValue="true"
|
||||
id="macosx.cpp.link.option.shared"/>
|
||||
</toolReference>
|
||||
</target>
|
||||
<target
|
||||
name="%TargetName.macosx.lib"
|
||||
id="cdt.managedbuild.target.macosx.lib"
|
||||
isTest="false"
|
||||
makefileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator"
|
||||
defaultExtension="a"
|
||||
scannerInfoCollector="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
|
||||
isAbstract="false"
|
||||
binaryParser="org.eclipse.cdt.core.MachO"
|
||||
parent="cdt.managedbuild.target.gnu"
|
||||
osList="macosx">
|
||||
<configuration
|
||||
name="%ConfigName.Dbg"
|
||||
id="cdt.managedbuild.config.macosx.lib.debug">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.none"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.max"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.none"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.max"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<configuration
|
||||
name="%ConfigName.Rel"
|
||||
id="cdt.managedbuild.config.macosxlib.release">
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.c.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.c.optimization.level.most"
|
||||
id="gnu.c.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.c.debugging.level.none"
|
||||
id="gnu.c.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
<toolReference
|
||||
id="cdt.managedbuild.tool.gnu.cpp.compiler">
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.optimization.level.most"
|
||||
id="gnu.cpp.compiler.option.optimization.level">
|
||||
</optionReference>
|
||||
<optionReference
|
||||
defaultValue="gnu.cpp.compiler.debugging.level.none"
|
||||
id="gnu.cpp.compiler.option.debugging.level">
|
||||
</optionReference>
|
||||
</toolReference>
|
||||
</configuration>
|
||||
<toolReference
|
||||
outputPrefix="lib"
|
||||
outputs="a"
|
||||
id="cdt.managedbuild.tool.gnu.archiver">
|
||||
</toolReference>
|
||||
</target>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
6
core/org.eclipse.cdt.core.macosx/.cdtproject
Normal file
6
core/org.eclipse.cdt.core.macosx/.cdtproject
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse-cdt version="2.0"?>
|
||||
|
||||
<cdtproject>
|
||||
<data/>
|
||||
</cdtproject>
|
7
core/org.eclipse.cdt.core.macosx/.classpath
Normal file
7
core/org.eclipse.cdt.core.macosx/.classpath
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
2
core/org.eclipse.cdt.core.macosx/.cvsignore
Normal file
2
core/org.eclipse.cdt.core.macosx/.cvsignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
bin
|
||||
doc
|
29
core/org.eclipse.cdt.core.macosx/.project
Normal file
29
core/org.eclipse.cdt.core.macosx/.project
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.cdt.core.macosx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>org.eclipse.cdt.core</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
3
core/org.eclipse.cdt.core.macosx/ChangeLog
Normal file
3
core/org.eclipse.cdt.core.macosx/ChangeLog
Normal file
|
@ -0,0 +1,3 @@
|
|||
2004-04-25 Greg Watson
|
||||
|
||||
Converted to MacOSX
|
8
core/org.eclipse.cdt.core.macosx/build.properties
Normal file
8
core/org.eclipse.cdt.core.macosx/build.properties
Normal file
|
@ -0,0 +1,8 @@
|
|||
bin.includes = fragment.xml,\
|
||||
fragment.properties,\
|
||||
about.html,\
|
||||
cdt_macosx.jar,\
|
||||
os/
|
||||
src.includes = about.html,\
|
||||
library/
|
||||
source.cdt_macosx.jar = src/
|
23
core/org.eclipse.cdt.core.macosx/fragment.xml
Normal file
23
core/org.eclipse.cdt.core.macosx/fragment.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.0"?>
|
||||
<fragment
|
||||
id="org.eclipse.cdt.core.macosx"
|
||||
name="%fragmentName.macosx"
|
||||
version="2.0.0"
|
||||
provider-name="%providerName"
|
||||
plugin-id="org.eclipse.cdt.core"
|
||||
plugin-version="2.0.0">
|
||||
|
||||
<runtime>
|
||||
<library name="cdt_macosx.jar"/>
|
||||
</runtime>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.ProcessList">
|
||||
<processList
|
||||
platform="macosx"
|
||||
class="org.eclipse.cdt.internal.core.macosx.ProcessList">
|
||||
</processList>
|
||||
</extension>
|
||||
</fragment>
|
1
core/org.eclipse.cdt.core.macosx/library/.cvsignore
Normal file
1
core/org.eclipse.cdt.core.macosx/library/.cvsignore
Normal file
|
@ -0,0 +1 @@
|
|||
*.o
|
46
core/org.eclipse.cdt.core.macosx/library/Makefile
Normal file
46
core/org.eclipse.cdt.core.macosx/library/Makefile
Normal file
|
@ -0,0 +1,46 @@
|
|||
# makefile for libspawner.so
|
||||
# See http://developer.apple.com/documentation/Java/Conceptual/Java141Development/Core_APIs/chapter_6_section_4.html
|
||||
|
||||
JAVA_HOME = /Library/Java/Home
|
||||
ifeq ($(JAVA_HOME),)
|
||||
$(warning JAVA_HOME not set in environment)
|
||||
endif
|
||||
|
||||
# Defaults which can be overridden.
|
||||
OS = macosx
|
||||
ARCH = ppc
|
||||
|
||||
JDK_INCLUDES= $(JAVA_HOME)/include
|
||||
|
||||
CC=gcc
|
||||
LD=libtool
|
||||
CPPFLAGS = -I. -I$(JDK_INCLUDES) #-I$(JDK_OS_INCLUDES)
|
||||
CFLAGS +=-fPIC -D_REENTRANT
|
||||
|
||||
INSTALL_DIR = ../os/$(OS)/$(ARCH)
|
||||
|
||||
LIB_NAME_SPAWNER = libspawner.dylib
|
||||
LIB_NAME_FULL_SPAWNER = $(INSTALL_DIR)/libspawner.jnilib
|
||||
OBJS_SPAWNER=spawner.o io.o exec_unix.o pfind.o
|
||||
|
||||
LIB_NAME_PTY = libpty.so
|
||||
LIB_NAME_FULL_PTY = $(INSTALL_DIR)/libpty.jnilib
|
||||
OBJS_PTY= openpty.o pty.o ptyio.o
|
||||
|
||||
OBJS = $(OBJS_SPAWNER) $(OBJS_PTY)
|
||||
|
||||
all: $(LIB_NAME_FULL_SPAWNER) $(LIB_NAME_FULL_PTY)
|
||||
|
||||
rebuild: clean all
|
||||
|
||||
$(LIB_NAME_FULL_SPAWNER) : $(OBJS_SPAWNER)
|
||||
mkdir -p $(INSTALL_DIR)
|
||||
$(CC) -dynamiclib -o $(LIB_NAME_FULL_SPAWNER) $(OBJS_SPAWNER) -lc -framework JavaVM
|
||||
|
||||
$(LIB_NAME_FULL_PTY): $(OBJS_PTY)
|
||||
mkdir -p $(INSTALL_DIR)
|
||||
$(CC) -dynamiclib -o $(LIB_NAME_FULL_PTY) $(OBJS_PTY) -lc -framework JavaVM
|
||||
|
||||
clean :
|
||||
$(RM) $(OBJS_SPAWNER) $(LIB_NAME_FULL_SPAWNER)
|
||||
$(RM) $(OBJS_PTY) $(LIB_NAME_FULL_PTY)
|
21
core/org.eclipse.cdt.core.macosx/library/PTY.h
Normal file
21
core/org.eclipse.cdt.core.macosx/library/PTY.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTY */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTY
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTY
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTY
|
||||
* Method: forkpty
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_pty_PTY_forkpty
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
32
core/org.eclipse.cdt.core.macosx/library/PTYInputStream.h
Normal file
32
core/org.eclipse.cdt.core.macosx/library/PTYInputStream.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTYInputStream */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE
|
||||
#define org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE 2048L
|
||||
/* Inaccessible static: skipBuffer */
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: read0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
29
core/org.eclipse.cdt.core.macosx/library/PTYOutputStream.h
Normal file
29
core/org.eclipse.cdt.core.macosx/library/PTYOutputStream.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTYOutputStream */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: write0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
45
core/org.eclipse.cdt.core.macosx/library/Spawner.h
Normal file
45
core/org.eclipse.cdt.core.macosx/library/Spawner.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_qnx_tools_utils_spawner_Spawner */
|
||||
|
||||
#ifndef _Included_com_qnx_tools_utils_spawner_Spawner
|
||||
#define _Included_com_qnx_tools_utils_spawner_Spawner
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: exec0
|
||||
* Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0
|
||||
(JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: exec0
|
||||
* Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1
|
||||
(JNIEnv *, jobject, jobjectArray, jobjectArray, jstring);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: raise
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: waitFor
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_qnx_tools_utils_spawner_SpawnerInputStream */
|
||||
|
||||
#ifndef _Included_com_qnx_tools_utils_spawner_SpawnerInputStream
|
||||
#define _Included_com_qnx_tools_utils_spawner_SpawnerInputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE
|
||||
#define com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE 2048L
|
||||
/* Inaccessible static: skipBuffer */
|
||||
/*
|
||||
* Class: org_elipse_cdt_utils_spawner_SpawnerInputStream
|
||||
* Method: read0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,29 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_qnx_tools_utils_spawner_SpawnerOutputStream */
|
||||
|
||||
#ifndef _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream
|
||||
#define _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
|
||||
* Method: write0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
11
core/org.eclipse.cdt.core.macosx/library/exec0.h
Normal file
11
core/org.eclipse.cdt.core.macosx/library/exec0.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern pid_t exec0(const char *path, char *const argv[],
|
||||
char *const envp[], const char *dirpath,
|
||||
int channels[3] );
|
||||
|
||||
extern int wait0(pid_t pid);
|
135
core/org.eclipse.cdt.core.macosx/library/exec_unix.c
Normal file
135
core/org.eclipse.cdt.core.macosx/library/exec_unix.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
#include "exec0.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* from pfind.c */
|
||||
extern char *pfind(const char *name);
|
||||
|
||||
pid_t
|
||||
exec0(const char *path, char *const argv[], char *const envp[],
|
||||
const char *dirpath, int channels[3])
|
||||
{
|
||||
int pipe0[2], pipe1[2], pipe2[2];
|
||||
pid_t childpid;
|
||||
char *full_path;
|
||||
|
||||
/*
|
||||
* We use pfind() to check that the program exists and is an executable.
|
||||
* If not pass the error up. Also execve() wants a full path.
|
||||
*/
|
||||
full_path = pfind(path);
|
||||
if (full_path == NULL) {
|
||||
fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : "");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure we can create our pipes before forking.
|
||||
*/
|
||||
if (channels != NULL) {
|
||||
if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
|
||||
fprintf(stderr, "%s(%d): returning due to error.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
free(full_path);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
childpid = fork();
|
||||
|
||||
if (childpid < 0) {
|
||||
fprintf(stderr, "%s(%d): returning due to error: %s\n",
|
||||
__FUNCTION__, __LINE__, strerror(errno));
|
||||
free(full_path);
|
||||
return -1;
|
||||
} else if (childpid == 0) { /* child */
|
||||
char *ptr;
|
||||
|
||||
chdir(dirpath);
|
||||
|
||||
if (channels != NULL) {
|
||||
/* Close the write end of pipe0 */
|
||||
if (close(pipe0[1]) == -1)
|
||||
perror("close(pipe0[1])");
|
||||
|
||||
/* Close the read end of pipe1 */
|
||||
if (close(pipe1[0]) == -1)
|
||||
perror("close(pipe1[0])");
|
||||
|
||||
/* Close the read end of pipe2 */
|
||||
if (close(pipe2[0]) == -1)
|
||||
perror("close(pipe2[0]))");
|
||||
|
||||
/* redirections */
|
||||
dup2(pipe0[0], STDIN_FILENO); /* dup stdin */
|
||||
dup2(pipe1[1], STDOUT_FILENO); /* dup stdout */
|
||||
dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
|
||||
}
|
||||
|
||||
/* Close all the fd's in the child */
|
||||
{
|
||||
int fdlimit = sysconf(_SC_OPEN_MAX);
|
||||
int fd = 3;
|
||||
|
||||
while (fd < fdlimit)
|
||||
close(fd++);
|
||||
}
|
||||
|
||||
if (envp[0] == NULL) {
|
||||
execv(full_path, argv);
|
||||
} else {
|
||||
execve(full_path, argv, envp);
|
||||
}
|
||||
|
||||
_exit(127);
|
||||
|
||||
} else if (childpid != 0) { /* parent */
|
||||
|
||||
char b;
|
||||
|
||||
if (channels != NULL) {
|
||||
/* close the read end of pipe1 */
|
||||
if (close(pipe0[0]) == -1)
|
||||
perror("close(pipe0[0])");
|
||||
|
||||
/* close the write end of pipe2 */
|
||||
if (close(pipe1[1]) == -1)
|
||||
perror("close(pipe1[1])");
|
||||
|
||||
/* close the write end of pipe2 */
|
||||
if (close(pipe2[1]) == -1)
|
||||
perror("close(pipe2[1])");
|
||||
|
||||
channels[0] = pipe0[1]; /* Output Stream. */
|
||||
channels[1] = pipe1[0]; /* Input Stream. */
|
||||
channels[2] = pipe2[0]; /* Input Stream. */
|
||||
}
|
||||
|
||||
free(full_path);
|
||||
return childpid;
|
||||
}
|
||||
|
||||
free(full_path);
|
||||
return -1; /*NOT REACHED */
|
||||
}
|
||||
|
||||
|
||||
int wait0(pid_t pid)
|
||||
{
|
||||
int status;
|
||||
int val = -1;
|
||||
|
||||
if (pid < 0 || waitpid(pid, &status, 0) < 0)
|
||||
return -1;
|
||||
|
||||
if (WIFEXITED(status)) {
|
||||
val = WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
103
core/org.eclipse.cdt.core.macosx/library/io.c
Normal file
103
core/org.eclipse.cdt.core.macosx/library/io.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <SpawnerInputStream.h>
|
||||
#include <SpawnerOutputStream.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Header for class _org_eclipse_cdt_utils_spawner_SpawnerInputStream */
|
||||
/* Header for class _org_eclipse_cdt_utils_spawner_SpawnerOutputStream */
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
|
||||
* Method: read0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = read( fd, data, data_len );
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
if (status == 0) {
|
||||
/* EOF. */
|
||||
status = -1;
|
||||
} else if (status == -1) {
|
||||
/* Error, toss an exception */
|
||||
jclass exception = (*env)->FindClass(env, "java/io/IOException");
|
||||
if (exception == NULL) {
|
||||
/* Give up. */
|
||||
return -1;
|
||||
}
|
||||
(*env)->ThrowNew(env, exception, "read error");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
|
||||
* Method: write0
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = write(fd, data, data_len);
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
104
core/org.eclipse.cdt.core.macosx/library/openpty.c
Normal file
104
core/org.eclipse.cdt.core.macosx/library/openpty.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* This is taken from R. W. Stevens book.
|
||||
* Alain Magloire.
|
||||
*/
|
||||
|
||||
int ptym_open (char *pts_name);
|
||||
int ptys_open (int fdm, char * pts_name);
|
||||
|
||||
int
|
||||
openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
|
||||
{
|
||||
char line[20];
|
||||
line[0]=0;
|
||||
*amaster = ptym_open(line);
|
||||
if (*amaster < 0)
|
||||
return -1;
|
||||
*aslave = ptys_open(*amaster, line);
|
||||
if (*aslave < 0) {
|
||||
close(*amaster);
|
||||
return -1;
|
||||
}
|
||||
if (name)
|
||||
strcpy(name, line);
|
||||
#ifndef TCSAFLUSH
|
||||
#define TCSAFLUSH TCSETAF
|
||||
#endif
|
||||
if (termp)
|
||||
(void) tcsetattr(*aslave, TCSAFLUSH, termp);
|
||||
#ifdef TIOCSWINSZ
|
||||
if (winp)
|
||||
(void) ioctl(*aslave, TIOCSWINSZ, (char *)winp);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ptym_open(char * pts_name)
|
||||
{
|
||||
char *ptr1, *ptr2;
|
||||
int fdm;
|
||||
|
||||
strcpy(pts_name, "/dev/ptyXY");
|
||||
/* array index: 012345689 (for references in following code) */
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
|
||||
pts_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
|
||||
pts_name[9] = *ptr2;
|
||||
/* try to open master */
|
||||
fdm = open(pts_name, O_RDWR);
|
||||
if (fdm < 0) {
|
||||
if (errno == ENOENT) {/* different from EIO */
|
||||
return -1; /* out of pty devices */
|
||||
} else {
|
||||
continue; /* try next pty device */
|
||||
}
|
||||
}
|
||||
pts_name[5] = 't'; /* chage "pty" to "tty" */
|
||||
return fdm; /* got it, return fd of master */
|
||||
}
|
||||
}
|
||||
return -1; /* out of pty devices */
|
||||
}
|
||||
|
||||
int
|
||||
ptys_open(int fdm, char * pts_name)
|
||||
{
|
||||
int gid, fds;
|
||||
struct group *grptr;
|
||||
|
||||
grptr = getgrnam("tty");
|
||||
if (grptr != NULL) {
|
||||
gid = grptr->gr_gid;
|
||||
} else {
|
||||
gid = -1; /* group tty is not in the group file */
|
||||
}
|
||||
|
||||
/* following two functions don't work unless we're root */
|
||||
chown(pts_name, getuid(), gid);
|
||||
chmod(pts_name, S_IRUSR | S_IWUSR | S_IWGRP);
|
||||
fds = open(pts_name, O_RDWR);
|
||||
if (fds < 0) {
|
||||
close(fdm);
|
||||
return -1;
|
||||
}
|
||||
return fds;
|
||||
}
|
10
core/org.eclipse.cdt.core.macosx/library/openpty.h
Normal file
10
core/org.eclipse.cdt.core.macosx/library/openpty.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
#ifndef _OPENPTY_H
|
||||
#define _OPENPTY_H
|
||||
int ptym_open (char *pts_name);
|
||||
int ptys_open (int fdm, char * pts_name);
|
||||
#endif
|
78
core/org.eclipse.cdt.core.macosx/library/pfind.c
Normal file
78
core/org.eclipse.cdt.core.macosx/library/pfind.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* pfind.c - Search for a binary in $PATH.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
|
||||
char * pfind(const char *name)
|
||||
{
|
||||
char *tok;
|
||||
char *sp;
|
||||
char *path;
|
||||
char fullpath[PATH_MAX+1];
|
||||
|
||||
/* Sanity check. */
|
||||
if (name == NULL) {
|
||||
fprintf(stderr, "pfind(): Null argument.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* For absolute name or name with a path, check if it is an executable. */
|
||||
if (name[0] == '/' || name[0] == '.') {
|
||||
if (access(name, X_OK | R_OK) == 0) {
|
||||
return strdup(name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Search in the PATH environment. */
|
||||
path = getenv("PATH" );
|
||||
|
||||
if (path == NULL || strlen(path) <= 0) {
|
||||
fprintf(stderr, "Unable to get $PATH.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The value return by getenv() is readonly */
|
||||
path = strdup(path);
|
||||
|
||||
tok = strtok_r(path, ":", &sp);
|
||||
while (tok != NULL) {
|
||||
snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
|
||||
|
||||
if (access(fullpath, X_OK | R_OK) == 0) {
|
||||
free(path);
|
||||
return strdup(fullpath);
|
||||
}
|
||||
|
||||
tok = strtok_r( NULL, ":", &sp );
|
||||
}
|
||||
|
||||
free(path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef BUILD_WITH_MAIN
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *fullpath;
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
fullpath = pfind(argv[i]);
|
||||
if (fullpath == NULL)
|
||||
printf("Unable to find %s in $PATH.\n", argv[i]);
|
||||
else
|
||||
printf("Found %s @ %s.\n", argv[i], fullpath);
|
||||
}
|
||||
}
|
||||
#endif
|
35
core/org.eclipse.cdt.core.macosx/library/pty.c
Normal file
35
core/org.eclipse.cdt.core.macosx/library/pty.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "PTY.h"
|
||||
#include "openpty.h"
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTY
|
||||
* Method: forkpty
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTY_forkpty (JNIEnv *env, jobject jobj) {
|
||||
jfieldID fid; /* Store the field ID */
|
||||
jstring jstr = NULL;
|
||||
int master = -1;
|
||||
char line[1024]; /* FIXME: Should be enough */
|
||||
jclass cls;
|
||||
|
||||
line[0] = '\0';
|
||||
|
||||
master = ptym_open(line);
|
||||
if (master >= 0) {
|
||||
/* Get a reference to the obj's class */
|
||||
cls = (*env)->GetObjectClass(env, jobj);
|
||||
|
||||
/* Set the master fd. */
|
||||
fid = (*env)->GetFieldID(env, cls, "master", "I");
|
||||
if (fid == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(*env)->SetIntField(env, jobj, fid, (jint)master);
|
||||
|
||||
/* Create a new String for the slave. */
|
||||
jstr = (*env)->NewStringUTF(env, line);
|
||||
}
|
||||
return jstr;
|
||||
}
|
107
core/org.eclipse.cdt.core.macosx/library/ptyio.c
Normal file
107
core/org.eclipse.cdt.core.macosx/library/ptyio.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <PTYInputStream.h>
|
||||
#include <PTYOutputStream.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Header for class _org_eclipse_cdt_utils_pty_PTYInputStream */
|
||||
/* Header for class _org_eclipse_cdt_utils_pty_PTYOutputStream */
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: read0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = read( fd, data, data_len );
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
if (status == 0) {
|
||||
/* EOF. */
|
||||
status = -1;
|
||||
} else if (status == -1) {
|
||||
/* Error, toss an exception */
|
||||
/* Ignore the error for now, the debugger will attempt
|
||||
* to close this multiple time. */
|
||||
#if 0
|
||||
jclass exception = (*env)->FindClass(env, "java/io/IOException");
|
||||
if (exception == NULL) {
|
||||
/* Give up. */
|
||||
return -1;
|
||||
}
|
||||
(*env)->ThrowNew(env, exception, "read error");
|
||||
#endif
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: write0
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = write(fd, data, data_len);
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
218
core/org.eclipse.cdt.core.macosx/library/spawner.c
Normal file
218
core/org.eclipse.cdt.core.macosx/library/spawner.c
Normal file
|
@ -0,0 +1,218 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "exec0.h"
|
||||
#include <Spawner.h>
|
||||
|
||||
|
||||
#define DEBUGIT 0
|
||||
|
||||
|
||||
/*
|
||||
* Header for class org_eclipse_cdt_utils_spawner_Spawner
|
||||
*/
|
||||
|
||||
|
||||
#if DEBUGIT
|
||||
static void print_array(char **c_array)
|
||||
{
|
||||
if (c_array) {
|
||||
char **p = c_array;
|
||||
for (; *p; p++) {
|
||||
if (*p) {
|
||||
fprintf(stderr, " %s", *p);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "null");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static char **alloc_c_array(JNIEnv * env, jobjectArray j_array)
|
||||
{
|
||||
int i;
|
||||
jint c_array_size = (*env)->GetArrayLength(env, j_array);
|
||||
char **c_array = calloc(c_array_size + 1, sizeof(*c_array));
|
||||
|
||||
if (c_array == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < c_array_size; i++) {
|
||||
jstring j_str =
|
||||
(jstring) (*env)->GetObjectArrayElement(env, j_array, i);
|
||||
const char *c_str = (*env)->GetStringUTFChars(env, j_str, NULL);
|
||||
c_array[i] = (char *) strdup(c_str);
|
||||
(*env)->ReleaseStringUTFChars(env, j_str, c_str);
|
||||
(*env)->DeleteLocalRef(env, j_str);
|
||||
}
|
||||
|
||||
return c_array;
|
||||
}
|
||||
|
||||
|
||||
static void free_c_array(char **c_array)
|
||||
{
|
||||
if (c_array) {
|
||||
char **p = c_array;
|
||||
for (; *p; p++) {
|
||||
if (*p) {
|
||||
free(*p);
|
||||
}
|
||||
}
|
||||
free(c_array);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_Spawner_exec1(JNIEnv * env, jobject jobj,
|
||||
jobjectArray jcmd,
|
||||
jobjectArray jenv,
|
||||
jstring jdir)
|
||||
{
|
||||
const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
|
||||
char **cmd;
|
||||
char **envp;
|
||||
pid_t pid = -1;
|
||||
|
||||
cmd = alloc_c_array(env, jcmd);
|
||||
if (cmd == NULL)
|
||||
goto bail_out;
|
||||
|
||||
envp = alloc_c_array(env, jenv);
|
||||
if (envp == NULL)
|
||||
goto bail_out;
|
||||
|
||||
#if DEBUGIT
|
||||
fprintf(stderr, "command:");
|
||||
print_array(cmd);
|
||||
fprintf(stderr, "Envp:");
|
||||
print_array(envp);
|
||||
fprintf(stderr, "dirpath: %s\n", dirpath);
|
||||
#endif
|
||||
|
||||
pid = exec0(cmd[0], cmd, envp, dirpath, NULL);
|
||||
if (pid < 0)
|
||||
goto bail_out;
|
||||
|
||||
bail_out:
|
||||
(*env)->ReleaseStringUTFChars(env, jdir, dirpath);
|
||||
if (cmd)
|
||||
free_c_array(cmd);
|
||||
if (envp)
|
||||
free_c_array(envp);
|
||||
return pid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: exec0
|
||||
* Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_Spawner_exec0(JNIEnv * env, jobject jobj,
|
||||
jobjectArray jcmd,
|
||||
jobjectArray jenv,
|
||||
jstring jdir,
|
||||
jintArray jchannels)
|
||||
{
|
||||
jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0);
|
||||
const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
|
||||
char **cmd;
|
||||
char **envp;
|
||||
int fd[3];
|
||||
pid_t pid = -1;
|
||||
|
||||
if (channels == NULL)
|
||||
goto bail_out;
|
||||
|
||||
cmd = alloc_c_array(env, jcmd);
|
||||
if (cmd == NULL)
|
||||
goto bail_out;
|
||||
|
||||
envp = alloc_c_array(env, jenv);
|
||||
if (envp == NULL)
|
||||
goto bail_out;
|
||||
|
||||
#if DEBUGIT
|
||||
fprintf(stderr, "command:");
|
||||
print_array(cmd);
|
||||
fprintf(stderr, "Envp:");
|
||||
print_array(envp);
|
||||
fprintf(stderr, "dirpath: %s\n", dirpath);
|
||||
#endif
|
||||
|
||||
pid = exec0(cmd[0], cmd, envp, dirpath, fd);
|
||||
if (pid < 0)
|
||||
goto bail_out;
|
||||
|
||||
channels[0] = fd[0];
|
||||
channels[1] = fd[1];
|
||||
channels[2] = fd[2];
|
||||
|
||||
bail_out:
|
||||
(*env)->ReleaseIntArrayElements(env, jchannels, channels, 0);
|
||||
(*env)->ReleaseStringUTFChars(env, jdir, dirpath);
|
||||
if (cmd)
|
||||
free_c_array(cmd);
|
||||
if (envp)
|
||||
free_c_array(envp);
|
||||
return pid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: raise
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_Spawner_raise(JNIEnv * env, jobject jobj,
|
||||
jint pid, jint sig)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
switch (sig) {
|
||||
case 0: /* NOOP */
|
||||
status = kill(pid, 0);
|
||||
break;
|
||||
|
||||
case 2: /* INTERRUPT */
|
||||
status = kill(pid, SIGINT);
|
||||
break;
|
||||
|
||||
case 9: /* KILL */
|
||||
status = kill(pid, SIGKILL);
|
||||
break;
|
||||
|
||||
case 15: /* TERM */
|
||||
status = kill(pid, SIGTERM);
|
||||
break;
|
||||
|
||||
default:
|
||||
status = kill(pid, sig); /* WHAT ?? */
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_spawner_Spawner
|
||||
* Method: waitFor
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor(JNIEnv * env,
|
||||
jobject jobj, jint pid)
|
||||
{
|
||||
return wait0(pid);
|
||||
}
|
BIN
core/org.eclipse.cdt.core.macosx/os/macosx/ppc/libpty.jnilib
Normal file
BIN
core/org.eclipse.cdt.core.macosx/os/macosx/ppc/libpty.jnilib
Normal file
Binary file not shown.
BIN
core/org.eclipse.cdt.core.macosx/os/macosx/ppc/libspawner.jnilib
Normal file
BIN
core/org.eclipse.cdt.core.macosx/os/macosx/ppc/libspawner.jnilib
Normal file
Binary file not shown.
|
@ -0,0 +1,45 @@
|
|||
package org.eclipse.cdt.internal.core.macosx;
|
||||
|
||||
import org.eclipse.cdt.core.IProcessInfo;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class ProcessInfo implements IProcessInfo {
|
||||
|
||||
int pid;
|
||||
String name;
|
||||
|
||||
public ProcessInfo(String pidString, String name) {
|
||||
try {
|
||||
pid = Integer.parseInt(pidString);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ProcessInfo(int pid, String name) {
|
||||
this.pid = pid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.IProcessInfo#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.IProcessInfo#getPid()
|
||||
*/
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package org.eclipse.cdt.internal.core.macosx;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.IProcessInfo;
|
||||
import org.eclipse.cdt.core.IProcessList;
|
||||
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
||||
|
||||
/**
|
||||
* Insert the type's description here.
|
||||
* @see IProcessList
|
||||
*/
|
||||
public class ProcessList implements IProcessList {
|
||||
|
||||
ProcessInfo[] empty = new ProcessInfo[0];
|
||||
|
||||
public ProcessList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the method's description here.
|
||||
* @see IProcessList#getProcessList
|
||||
*/
|
||||
public IProcessInfo [] getProcessList() {
|
||||
Process ps;
|
||||
BufferedReader psOutput;
|
||||
String[] args = {"/bin/ps", "-a", "-o", "pid,command"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
|
||||
try {
|
||||
ps = ProcessFactory.getFactory().exec(args);
|
||||
psOutput = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
||||
} catch(Exception e) {
|
||||
return new IProcessInfo[0];
|
||||
}
|
||||
|
||||
//Read the output and parse it into an array list
|
||||
ArrayList procInfo = new ArrayList();
|
||||
|
||||
try {
|
||||
String lastline;
|
||||
while ((lastline = psOutput.readLine()) != null) {
|
||||
//The format of the output should be
|
||||
//PID space name
|
||||
|
||||
lastline = lastline.trim();
|
||||
int index = lastline.indexOf(' ');
|
||||
if (index != -1) {
|
||||
String pidString = lastline.substring(0, index).trim();
|
||||
try {
|
||||
int pid = Integer.parseInt(pidString);
|
||||
String arg = lastline.substring(index + 1);
|
||||
procInfo.add(new ProcessInfo(pid, arg));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
/* Ignore */
|
||||
}
|
||||
|
||||
ps.destroy();
|
||||
return (IProcessInfo [])procInfo.toArray(new IProcessInfo[procInfo.size()]);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ GNUElfParser.name=GNU Elf Parser
|
|||
PEWindowsParser.name=PE Windows Parser
|
||||
CygwinPEParser.name=Cygwin PE Parser
|
||||
XCOFF32Parser.name=AIX XCOFF32 Parser
|
||||
MachOParser.name=Mach-O Parser
|
||||
|
||||
CDTGNUCErrorParser.name=CDT GNU C/C++ Error Parser
|
||||
CDTGNUAssemblerErrorParser.name=CDT GNU Assembler Error Parser
|
||||
|
@ -50,3 +51,4 @@ fragmentName.linux = C/C++ Development Tools Core for Linux
|
|||
fragmentName.qnx = C/C++ Development Tools Core for QNX
|
||||
fragmentName.solaris = C/C++ Development Tools Core for Solaris
|
||||
fragmentName.win32 = C/C++ Development Tools Core for Windows
|
||||
fragmentName.macosx = C/C++ Development Tools Core for MacOS X
|
||||
|
|
|
@ -123,6 +123,20 @@
|
|||
</run>
|
||||
</cextension>
|
||||
</extension>
|
||||
<extension
|
||||
id="MachO"
|
||||
name="%MachOParser.name"
|
||||
point="org.eclipse.cdt.core.BinaryParser">
|
||||
<cextension>
|
||||
<filter
|
||||
name = "visibility"
|
||||
value = "private">
|
||||
</filter>
|
||||
<run
|
||||
class="org.eclipse.cdt.utils.macho.parser.MachOParser">
|
||||
</run>
|
||||
</cextension>
|
||||
</extension>
|
||||
<!-- =================================================================================== -->
|
||||
<!-- Define the list of Error Parser provided by the CDT -->
|
||||
<!-- =================================================================================== -->
|
||||
|
@ -371,6 +385,10 @@
|
|||
enabled="true"
|
||||
pattern="*.exe">
|
||||
</ignore>
|
||||
<ignore
|
||||
enabled="true"
|
||||
pattern="*.dylib">
|
||||
</ignore>
|
||||
</extension>
|
||||
<!-- =================================================================================== -->
|
||||
<!-- =================================================================================== -->
|
||||
|
|
|
@ -0,0 +1,336 @@
|
|||
package org.eclipse.cdt.utils.macho;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
|
||||
/**
|
||||
* The <code>AR</code> class is used for parsing standard archive (ar) files.
|
||||
*
|
||||
* Each object within the archive is represented by an ARHeader class. Each of
|
||||
* of these objects can then be turned into an Elf object for performing Elf
|
||||
* class operations.
|
||||
* @see ARHeader
|
||||
*/
|
||||
public class AR {
|
||||
|
||||
protected String filename;
|
||||
protected ERandomAccessFile efile;
|
||||
protected long strtbl_pos = -1;
|
||||
private ARHeader[] headers;
|
||||
|
||||
public void dispose() {
|
||||
try {
|
||||
if (efile != null) {
|
||||
efile.close();
|
||||
efile = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
dispose();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ARHeader</code> class is used to store the per-object file
|
||||
* archive headers. It can also create an Mach-O object for inspecting
|
||||
* the object file data.
|
||||
*/
|
||||
public class ARHeader {
|
||||
|
||||
private String object_name;
|
||||
private String modification_time;
|
||||
private String uid;
|
||||
private String gid;
|
||||
private String mode;
|
||||
private long size;
|
||||
private long file_offset;
|
||||
private long macho_offset;
|
||||
|
||||
/**
|
||||
* Remove the padding from the archive header strings.
|
||||
*/
|
||||
private String removeBlanks(String str) {
|
||||
while (str.charAt(str.length() - 1) == ' ')
|
||||
str = str.substring(0, str.length() - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the name stored in the archive's string table based
|
||||
* on the offset given.
|
||||
*
|
||||
* Maintains <code>efile</code> file location.
|
||||
*
|
||||
* @param offset
|
||||
* Offset into the string table for first character of the name.
|
||||
* @throws IOException
|
||||
* <code>offset</code> not in string table bounds.
|
||||
*/
|
||||
private String nameFromStringTable(long offset) throws IOException {
|
||||
StringBuffer name = new StringBuffer(0);
|
||||
long pos = efile.getFilePointer();
|
||||
|
||||
try {
|
||||
if (strtbl_pos != -1) {
|
||||
byte temp;
|
||||
efile.seek(strtbl_pos + offset);
|
||||
while ((temp = efile.readByte()) != '\n')
|
||||
name.append((char) temp);
|
||||
}
|
||||
} finally {
|
||||
efile.seek(pos);
|
||||
}
|
||||
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new archive header object.
|
||||
*
|
||||
* Assumes that efile is already at the correct location in the file.
|
||||
*
|
||||
* @throws IOException
|
||||
* There was an error processing the header data from the file.
|
||||
*/
|
||||
public ARHeader() throws IOException {
|
||||
byte[] object_name = new byte[16];
|
||||
byte[] modification_time = new byte[12];
|
||||
byte[] uid = new byte[6];
|
||||
byte[] gid = new byte[6];
|
||||
byte[] mode = new byte[8];
|
||||
byte[] size = new byte[10];
|
||||
byte[] trailer = new byte[2];
|
||||
|
||||
//
|
||||
// Read in the archive header data. Fixed sizes.
|
||||
//
|
||||
efile.read(object_name);
|
||||
efile.read(modification_time);
|
||||
efile.read(uid);
|
||||
efile.read(gid);
|
||||
efile.read(mode);
|
||||
efile.read(size);
|
||||
efile.read(trailer);
|
||||
|
||||
//
|
||||
// Save this location so we can create the Mach-O object later.
|
||||
//
|
||||
macho_offset = efile.getFilePointer();
|
||||
|
||||
//
|
||||
// Convert the raw bytes into strings and numbers.
|
||||
//
|
||||
this.object_name = removeBlanks(new String(object_name));
|
||||
this.modification_time = new String(modification_time);
|
||||
this.uid = new String(uid);
|
||||
this.gid = new String(gid);
|
||||
this.mode = new String(mode);
|
||||
this.size = Long.parseLong(removeBlanks(new String(size)));
|
||||
|
||||
//
|
||||
// If the name is of the format "#1/<number>", real name directly follows the
|
||||
// header.
|
||||
//
|
||||
if (this.object_name.length() > 3
|
||||
&& this.object_name.charAt(0) == '#'
|
||||
&& this.object_name.charAt(1) == '1'
|
||||
&& this.object_name.charAt(2) == '/') {
|
||||
try {
|
||||
int len = Integer.parseInt(this.object_name.substring(3));
|
||||
byte[] real_name = new byte[len];
|
||||
efile.read(real_name);
|
||||
this.object_name = new String(real_name);
|
||||
long pos = efile.getFilePointer();
|
||||
efile.seek(macho_offset);
|
||||
macho_offset = pos;
|
||||
} catch (java.lang.Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Strip the trailing / from the object name.
|
||||
//
|
||||
int len = this.object_name.length();
|
||||
if (len > 2 && this.object_name.charAt(len - 1) == '/') {
|
||||
this.object_name = this.object_name.substring(0, len - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Get the name of the object file */
|
||||
public String getObjectName() {
|
||||
return object_name;
|
||||
}
|
||||
|
||||
/** Get the size of the object file . */
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getArchiveName() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an new MachO object for the object file.
|
||||
*
|
||||
* @throws IOException
|
||||
* Not a valid MachO object file.
|
||||
* @return A new MachO object.
|
||||
* @see MachO#MachO( String, long )
|
||||
*/
|
||||
public MachO getMachO() throws IOException {
|
||||
return new MachO(filename, macho_offset);
|
||||
}
|
||||
|
||||
public MachO getMachO(boolean filter_on) throws IOException {
|
||||
return new MachO(filename, macho_offset, filter_on);
|
||||
}
|
||||
|
||||
public byte[] getObjectData() throws IOException {
|
||||
byte[] temp = new byte[(int) size];
|
||||
if (efile != null) {
|
||||
efile.seek(macho_offset);
|
||||
efile.read(temp);
|
||||
} else {
|
||||
efile = new ERandomAccessFile(filename, "r"); //$NON-NLS-1$
|
||||
efile.seek(macho_offset);
|
||||
efile.read(temp);
|
||||
efile.close();
|
||||
efile = null;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isARHeader(byte[] ident) {
|
||||
if (ident.length < 7
|
||||
|| ident[0] != '!'
|
||||
|| ident[1] != '<'
|
||||
|| ident[2] != 'a'
|
||||
|| ident[3] != 'r'
|
||||
|| ident[4] != 'c'
|
||||
|| ident[5] != 'h'
|
||||
|| ident[6] != '>')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>AR</code> object from the contents of
|
||||
* the given file.
|
||||
*
|
||||
* @param filename The file to process.
|
||||
* @throws IOException The file is not a valid archive.
|
||||
*/
|
||||
public AR(String filename) throws IOException {
|
||||
this.filename = filename;
|
||||
efile = new ERandomAccessFile(filename, "r"); //$NON-NLS-1$
|
||||
String hdr = efile.readLine();
|
||||
if (hdr == null || hdr.compareTo("!<arch>") != 0) { //$NON-NLS-1$
|
||||
efile.close();
|
||||
throw new IOException(CCorePlugin.getResourceString("Util.exception.invalidArchive")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the headers from the file (if required). */
|
||||
private void loadHeaders() throws IOException {
|
||||
if (headers != null)
|
||||
return;
|
||||
|
||||
Vector v = new Vector();
|
||||
try {
|
||||
//
|
||||
// Check for EOF condition
|
||||
//
|
||||
while (efile.getFilePointer() < efile.length()) {
|
||||
ARHeader header = new ARHeader();
|
||||
String name = header.getObjectName();
|
||||
|
||||
long pos = efile.getFilePointer();
|
||||
|
||||
v.add(header);
|
||||
|
||||
//
|
||||
// Compute the location of the next header in the archive.
|
||||
//
|
||||
pos += header.getSize();
|
||||
if ((pos % 2) != 0)
|
||||
pos++;
|
||||
|
||||
efile.seek(pos);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
// strtbl_pos = ???;
|
||||
headers = (ARHeader[]) v.toArray(new ARHeader[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all the object file headers for this archive.
|
||||
*
|
||||
* @throws IOException
|
||||
* Unable to process the archive file.
|
||||
* @return An array of headers, one for each object within the archive.
|
||||
* @see ARHeader
|
||||
*/
|
||||
public ARHeader[] getHeaders() throws IOException {
|
||||
loadHeaders();
|
||||
return headers;
|
||||
}
|
||||
|
||||
private boolean stringInStrings(String str, String[] set) {
|
||||
for (int i = 0; i < set.length; i++)
|
||||
if (str.compareTo(set[i]) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] extractFiles(String outdir, String[] names) throws IOException {
|
||||
Vector names_used = new Vector();
|
||||
String object_name;
|
||||
int count;
|
||||
|
||||
loadHeaders();
|
||||
|
||||
count = 0;
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
object_name = headers[i].getObjectName();
|
||||
if (names != null && !stringInStrings(object_name, names))
|
||||
continue;
|
||||
|
||||
object_name = "" + count + "_" + object_name; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
count++;
|
||||
|
||||
byte[] data = headers[i].getObjectData();
|
||||
File output = new File(outdir, object_name);
|
||||
names_used.add(object_name);
|
||||
|
||||
RandomAccessFile rfile = new RandomAccessFile(output, "rw"); //$NON-NLS-1$
|
||||
rfile.write(data);
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
return (String[]) names_used.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public String[] extractFiles(String outdir) throws IOException {
|
||||
return extractFiles(outdir, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package org.eclipse.cdt.utils.macho;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
public class ERandomAccessFile extends RandomAccessFile {
|
||||
private boolean isle;
|
||||
private long ptr_offset;
|
||||
int val[] = new int[4];
|
||||
|
||||
public ERandomAccessFile(String file, String mode) throws IOException {
|
||||
super(file, mode);
|
||||
}
|
||||
|
||||
public ERandomAccessFile(File file, String mode) throws IOException {
|
||||
super(file, mode);
|
||||
}
|
||||
|
||||
public void setEndian(boolean le)
|
||||
{
|
||||
isle = le;
|
||||
}
|
||||
|
||||
public final short readShortE() throws IOException {
|
||||
val[0] = read();
|
||||
val[1] = read();
|
||||
if ((val[0] | val[1]) < 0)
|
||||
throw new EOFException();
|
||||
if ( isle ) {
|
||||
return (short)((val[1] << 8) + val[0]);
|
||||
} else {
|
||||
return (short)((val[0] << 8) + val[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public final int readIntE() throws IOException
|
||||
{
|
||||
val[0] = read();
|
||||
val[1] = read();
|
||||
val[2] = read();
|
||||
val[3] = read();
|
||||
if ((val[0] | val[1] | val[2] | val[3]) < 0)
|
||||
throw new EOFException();
|
||||
if ( isle ) {
|
||||
return ((val[3] << 24) + (val[2] << 16) + (val[1] << 8) + val[0]);
|
||||
} else {
|
||||
return ((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
|
||||
}
|
||||
}
|
||||
|
||||
public final long readLongE() throws IOException
|
||||
{
|
||||
return (long)readIntE();
|
||||
}
|
||||
|
||||
public void setFileOffset( long offset ) throws IOException {
|
||||
ptr_offset = offset;
|
||||
super.seek( offset );
|
||||
}
|
||||
|
||||
public long getFilePointer() throws IOException {
|
||||
long ptr = super.getFilePointer();
|
||||
ptr = ptr - ptr_offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
public void seek( long pos ) throws IOException {
|
||||
long real_pos = pos + ptr_offset;
|
||||
super.seek( real_pos );
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,315 @@
|
|||
package org.eclipse.cdt.utils.macho;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <code>MachOHelper</code> is a wrapper class for the <code>MachO</code> class
|
||||
* to provide higher level API for sorting/searching the MachO data.
|
||||
*
|
||||
* @see MachO
|
||||
*/
|
||||
public class MachOHelper {
|
||||
|
||||
private MachO macho;
|
||||
private MachO.MachOhdr hdr;
|
||||
private MachO.Attribute attrib;
|
||||
private MachO.Symbol[] dynsyms;
|
||||
private MachO.Symbol[] symbols;
|
||||
private MachO.Section[] sections;
|
||||
private MachO.DyLib[] needed;
|
||||
private MachO.DyLib[] sonames;
|
||||
|
||||
public void dispose() {
|
||||
if (macho != null) {
|
||||
macho.dispose();
|
||||
macho = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Sizes {
|
||||
public long text;
|
||||
public long data;
|
||||
public long bss;
|
||||
public long total;
|
||||
public Sizes(long t, long d, long b) {
|
||||
text = t;
|
||||
data = d;
|
||||
bss = b;
|
||||
total = text + data + bss;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBinary() throws IOException {
|
||||
if (symbols == null) {
|
||||
macho.loadBinary();
|
||||
symbols = macho.getSymtabSymbols();
|
||||
dynsyms = macho.getDynamicSymbols();
|
||||
sections = macho.getSections();
|
||||
needed = macho.getDyLibs(MachO.LoadCommand.LC_LOAD_DYLIB);
|
||||
sonames = macho.getDyLibs(MachO.LoadCommand.LC_ID_DYLIB);
|
||||
|
||||
if (dynsyms == null)
|
||||
dynsyms = symbols;
|
||||
}
|
||||
}
|
||||
|
||||
/** Common code used by all constructors */
|
||||
private void commonSetup() throws IOException {
|
||||
hdr = macho.getMachOhdr();
|
||||
attrib = macho.getAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>MachOHelper</code> using an existing <code>MachO</code>
|
||||
* object.
|
||||
* @param macho An existing MachO object to wrap.
|
||||
* @throws IOException Error processing the MachO file.
|
||||
*/
|
||||
public MachOHelper(MachO macho) throws IOException {
|
||||
this.macho = macho;
|
||||
commonSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>MachOHelper</code> based on the given filename.
|
||||
*
|
||||
* @param filename The file to use for creating a new MachO object.
|
||||
* @throws IOException Error processing the MachO file.
|
||||
* @see MachO#MachO( String )
|
||||
*/
|
||||
public MachOHelper(String filename) throws IOException {
|
||||
macho = new MachO(filename);
|
||||
commonSetup();
|
||||
}
|
||||
|
||||
public MachOHelper(String filename, boolean filton) throws IOException {
|
||||
macho = new MachO(filename, filton);
|
||||
commonSetup();
|
||||
}
|
||||
|
||||
/** Give back the MachO object that this helper is wrapping */
|
||||
public MachO getMachO() {
|
||||
return macho;
|
||||
}
|
||||
|
||||
public MachO.Symbol[] getExternalFunctions() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
MachO.Symbol sym = dynsyms[i];
|
||||
if ((sym.n_type_mask(MachO.Symbol.N_PEXT)
|
||||
|| sym.n_type_mask(MachO.Symbol.N_EXT))
|
||||
&& sym.n_desc(MachO.Symbol.REFERENCE_FLAG_UNDEFINED_LAZY)) {
|
||||
String name = sym.toString();
|
||||
if (name != null && name.trim().length() > 0)
|
||||
v.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public MachO.Symbol[] getExternalObjects() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
MachO.Symbol sym = dynsyms[i];
|
||||
if ((sym.n_type_mask(MachO.Symbol.N_PEXT)
|
||||
|| sym.n_type_mask(MachO.Symbol.N_EXT))
|
||||
&& sym.n_desc(MachO.Symbol.REFERENCE_FLAG_UNDEFINED_NON_LAZY)) {
|
||||
String name = sym.toString();
|
||||
if (name != null && name.trim().length() > 0)
|
||||
v.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public MachO.Symbol[] getUndefined() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
if (dynsyms[i].n_type(MachO.Symbol.N_UNDF))
|
||||
v.add(dynsyms[i]);
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: I'm not sure if this are correct. Need to check
|
||||
*/
|
||||
public MachO.Symbol[] getLocalFunctions() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
MachO.Symbol sym = dynsyms[i];
|
||||
if ((!sym.n_type_mask(MachO.Symbol.N_PEXT)
|
||||
&& !sym.n_type_mask(MachO.Symbol.N_EXT))
|
||||
&& sym.n_desc(MachO.Symbol.REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY)) {
|
||||
String name = sym.toString();
|
||||
if (name != null && name.trim().length() > 0)
|
||||
v.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: I'm not sure if this are correct. Need to check
|
||||
*/
|
||||
public MachO.Symbol[] getLocalObjects() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
MachO.Symbol sym = dynsyms[i];
|
||||
if ((!sym.n_type_mask(MachO.Symbol.N_PEXT)
|
||||
&& !sym.n_type_mask(MachO.Symbol.N_EXT))
|
||||
&& sym.n_desc(MachO.Symbol.REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY)) {
|
||||
String name = sym.toString();
|
||||
if (name != null && name.trim().length() > 0)
|
||||
v.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public MachO.Symbol[] getCommonObjects() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < dynsyms.length; i++) {
|
||||
MachO.Symbol sym = dynsyms[i];
|
||||
if (sym.n_type_mask(MachO.Symbol.N_EXT)
|
||||
&& sym.n_type(MachO.Symbol.N_UNDF)
|
||||
&& sym.n_value != 0) {
|
||||
v.add(symbols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
MachO.Symbol[] ret = (MachO.Symbol[]) v.toArray(new MachO.Symbol[0]);
|
||||
Arrays.sort(ret, new SymbolSortCompare());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String[] getNeeded() throws IOException {
|
||||
Vector v = new Vector();
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < needed.length; i++) {
|
||||
v.add(needed[i].toString());
|
||||
}
|
||||
return (String[]) v.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public String getSoname() throws IOException {
|
||||
String soname = ""; //$NON-NLS-1$
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < sonames.length; i++) {
|
||||
soname = sonames[i].toString();
|
||||
}
|
||||
return soname;
|
||||
}
|
||||
|
||||
private String getSubUsage(String full, String name) {
|
||||
int start, end;
|
||||
//boolean has_names = false;
|
||||
//boolean has_languages = false;
|
||||
start = 0;
|
||||
end = 0;
|
||||
|
||||
for (int i = 0; i < full.length(); i++) {
|
||||
if (full.charAt(i) == '%') {
|
||||
if (full.charAt(i + 1) == '-') {
|
||||
if (start == 0) {
|
||||
int eol = full.indexOf('\n', i + 2);
|
||||
String temp = full.substring(i + 2, eol);
|
||||
if (temp.compareTo(name) == 0)
|
||||
start = eol;
|
||||
|
||||
//has_names = true;
|
||||
} else if (end == 0) {
|
||||
end = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
//if( full.charAt( i+1 ) == '=' )
|
||||
//has_languages = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (end == 0)
|
||||
end = full.length();
|
||||
|
||||
if (start == 0)
|
||||
return full;
|
||||
|
||||
return full.substring(start, end);
|
||||
}
|
||||
|
||||
public String getQnxUsage() throws IOException {
|
||||
return new String(""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public Sizes getSizes() throws IOException {
|
||||
long text, data, bss;
|
||||
|
||||
text = 0;
|
||||
data = 0;
|
||||
bss = 0;
|
||||
|
||||
loadBinary();
|
||||
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
MachO.SegmentCommand seg = sections[i].segment;
|
||||
if (sections[i].flags(MachO.Section.SECTION_TYP) != MachO.Section.S_ZEROFILL) {
|
||||
if (seg.prot(MachO.SegmentCommand.VM_PROT_EXECUTE)) {
|
||||
text += sections[i].size;
|
||||
} else if (!seg.prot(MachO.SegmentCommand.VM_PROT_WRITE)) {
|
||||
data += sections[i].size;
|
||||
}
|
||||
} else {
|
||||
if (seg.prot(MachO.SegmentCommand.VM_PROT_WRITE)) {
|
||||
bss += sections[i].size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Sizes(text, data, bss);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.eclipse.cdt.utils.macho;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class SymbolSortCompare implements Comparator {
|
||||
public int compare( Object o1, Object o2 ) {
|
||||
String s1 = o1.toString().toLowerCase();
|
||||
String s2 = o2.toString().toLowerCase();
|
||||
|
||||
while( s1.length() > 0 && s1.charAt( 0 ) == '_' )
|
||||
s1 = s1.substring( 1 );
|
||||
|
||||
while( s2.length() > 0 && s2.charAt( 0 ) == '_' )
|
||||
s2 = s2.substring( 1 );
|
||||
|
||||
return s1.compareTo( s2 );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.macho.parser;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.utils.Addr2line;
|
||||
import org.eclipse.cdt.utils.CPPFilt;
|
||||
import org.eclipse.cdt.utils.Symbol;
|
||||
import org.eclipse.cdt.utils.macho.AR;
|
||||
import org.eclipse.cdt.utils.macho.MachO;
|
||||
import org.eclipse.cdt.utils.macho.MachOHelper;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* ARMember
|
||||
*/
|
||||
public class ARMember extends MachOBinaryObject {
|
||||
AR.ARHeader header;
|
||||
|
||||
public ARMember(IBinaryParser parser, IPath p, AR.ARHeader h) throws IOException {
|
||||
super(parser, p);
|
||||
header = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getContents()
|
||||
*/
|
||||
public InputStream getContents() {
|
||||
InputStream stream = null;
|
||||
if (path != null && header != null) {
|
||||
try {
|
||||
stream = new ByteArrayInputStream(header.getObjectData());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = super.getContents();
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryObject#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
if (header != null) {
|
||||
return header.getObjectName();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected MachOHelper getMachOHelper() throws IOException {
|
||||
if (header != null) {
|
||||
return new MachOHelper(header.getMachO());
|
||||
}
|
||||
throw new IOException(CCorePlugin.getResourceString("Util.exception.noFileAssociation")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void addSymbols(MachO.Symbol[] array, int type, Addr2line addr2line, CPPFilt cppfilt, List list) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Symbol sym = new Symbol(this);
|
||||
sym.type = type;
|
||||
sym.name = array[i].toString();
|
||||
sym.addr = array[i].n_value;
|
||||
list.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.macho.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||
import org.eclipse.cdt.utils.BinaryFile;
|
||||
import org.eclipse.cdt.utils.macho.AR;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class BinaryArchive extends BinaryFile implements IBinaryArchive {
|
||||
|
||||
ArrayList children;
|
||||
|
||||
public BinaryArchive(IBinaryParser parser, IPath p) throws IOException {
|
||||
super(parser, p);
|
||||
new AR(p.toOSString()).dispose(); // check file type
|
||||
children = new ArrayList(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#getObjects()
|
||||
*/
|
||||
public IBinaryObject[] getObjects() {
|
||||
if (hasChanged()) {
|
||||
children.clear();
|
||||
AR ar = null;
|
||||
try {
|
||||
ar = new AR(getPath().toOSString());
|
||||
AR.ARHeader[] headers = ar.getHeaders();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
IBinaryObject bin = new ARMember(getBinaryParser(), getPath(), headers[i]);
|
||||
children.add(bin);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
if (ar != null) {
|
||||
ar.dispose();
|
||||
}
|
||||
children.trimToSize();
|
||||
}
|
||||
return (IBinaryObject[]) children.toArray(new IBinaryObject[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return IBinaryFile.ARCHIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[])
|
||||
*/
|
||||
public void add(IBinaryObject[] objs) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#delete(IBinaryObject[])
|
||||
*/
|
||||
public void delete(IBinaryObject[] objs) throws IOException {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.macho.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
|
||||
import org.eclipse.cdt.utils.*;
|
||||
import org.eclipse.cdt.utils.BinaryObjectAdapter;
|
||||
import org.eclipse.cdt.utils.CPPFilt;
|
||||
import org.eclipse.cdt.utils.macho.MachO;
|
||||
import org.eclipse.cdt.utils.macho.MachOHelper;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/*
|
||||
* MachOBinaryObject
|
||||
*/
|
||||
public class MachOBinaryObject extends BinaryObjectAdapter {
|
||||
|
||||
private BinaryObjectInfo info;
|
||||
private ISymbol[] symbols;
|
||||
|
||||
public MachOBinaryObject(IBinaryParser parser, IPath path) {
|
||||
super(parser, path);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryFile#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return IBinaryFile.OBJECT;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser.IBinaryObject#getSymbols()
|
||||
*/
|
||||
public ISymbol[] getSymbols() {
|
||||
// Call the hasChanged first, to initialize the timestamp
|
||||
if (hasChanged() || symbols == null) {
|
||||
try {
|
||||
loadAll();
|
||||
} catch (IOException e) {
|
||||
symbols = NO_SYMBOLS;
|
||||
}
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.BinaryObjectAdapter#getBinaryObjectInfo()
|
||||
*/
|
||||
protected BinaryObjectInfo getBinaryObjectInfo() {
|
||||
// Call the hasChanged first, to initialize the timestamp
|
||||
if (hasChanged() || info == null) {
|
||||
try {
|
||||
loadInfo();
|
||||
} catch (IOException e) {
|
||||
info = new BinaryObjectInfo();
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
protected MachOHelper getMachOHelper() throws IOException {
|
||||
return new MachOHelper(getPath().toOSString());
|
||||
}
|
||||
|
||||
protected void loadAll() throws IOException {
|
||||
MachOHelper helper = null;
|
||||
try {
|
||||
helper = getMachOHelper();
|
||||
loadInfo(helper);
|
||||
loadSymbols(helper);
|
||||
} finally {
|
||||
if (helper != null) {
|
||||
helper.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadInfo() throws IOException {
|
||||
MachOHelper helper = null;
|
||||
try {
|
||||
helper = getMachOHelper();
|
||||
loadInfo(helper);
|
||||
} finally {
|
||||
if (helper != null) {
|
||||
helper.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadInfo(MachOHelper helper) throws IOException {
|
||||
info = new BinaryObjectInfo();
|
||||
info.needed = helper.getNeeded();
|
||||
MachOHelper.Sizes sizes = helper.getSizes();
|
||||
info.bss = sizes.bss;
|
||||
info.data = sizes.data;
|
||||
info.text = sizes.text;
|
||||
|
||||
info.soname = helper.getSoname();
|
||||
|
||||
MachO.Attribute attribute = helper.getMachO().getAttributes();
|
||||
info.isLittleEndian = attribute.isLittleEndian();
|
||||
info.hasDebug = attribute.hasDebug();
|
||||
info.cpu = attribute.getCPU();
|
||||
}
|
||||
|
||||
protected void loadSymbols(MachOHelper helper) throws IOException {
|
||||
ArrayList list = new ArrayList();
|
||||
// Hack should be remove when Elf is clean
|
||||
helper.getMachO().setCppFilter(false);
|
||||
|
||||
CPPFilt cppfilt = getCPPFilt();
|
||||
|
||||
addSymbols(helper.getExternalFunctions(), ISymbol.FUNCTION, cppfilt, list);
|
||||
addSymbols(helper.getLocalFunctions(), ISymbol.FUNCTION, cppfilt, list);
|
||||
addSymbols(helper.getExternalObjects(), ISymbol.VARIABLE, cppfilt, list);
|
||||
addSymbols(helper.getLocalObjects(), ISymbol.VARIABLE, cppfilt, list);
|
||||
list.trimToSize();
|
||||
|
||||
if (cppfilt != null) {
|
||||
cppfilt.dispose();
|
||||
}
|
||||
|
||||
symbols = (ISymbol[])list.toArray(NO_SYMBOLS);
|
||||
Arrays.sort(symbols);
|
||||
list.clear();
|
||||
}
|
||||
|
||||
protected void addSymbols(MachO.Symbol[] array, int type, CPPFilt cppfilt, List list) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Symbol sym = new Symbol(this);
|
||||
sym.type = type;
|
||||
sym.name = array[i].toString();
|
||||
if (cppfilt != null) {
|
||||
try {
|
||||
sym.name = cppfilt.getFunction(sym.name);
|
||||
} catch (IOException e1) {
|
||||
cppfilt = null;
|
||||
}
|
||||
}
|
||||
sym.addr = array[i].n_value;
|
||||
sym.size = 0;
|
||||
sym.filename = null;
|
||||
sym.startLine = 0;
|
||||
sym.endLine = sym.startLine;
|
||||
String filename = array[i].getFilename();
|
||||
sym.filename = (filename != null) ? new Path(filename) : null; //$NON-NLS-1$
|
||||
sym.startLine = array[i].getLineNumber(sym.addr);
|
||||
sym.endLine = array[i].getLineNumber(sym.addr + sym.size - 1);
|
||||
list.add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.utils.macho.parser;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.utils.ToolsProvider;
|
||||
import org.eclipse.cdt.utils.macho.AR;
|
||||
import org.eclipse.cdt.utils.macho.MachO;
|
||||
import org.eclipse.cdt.utils.macho.MachO.Attribute;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MachOParser extends ToolsProvider implements IBinaryParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IBinaryFile getBinary(IPath path) throws IOException {
|
||||
return getBinary(null, path);
|
||||
}
|
||||
|
||||
|
||||
public IBinaryFile getBinary(byte[] hints, IPath path) throws IOException {
|
||||
if (path == null) {
|
||||
throw new IOException(CCorePlugin.getResourceString("Util.exception.nullPath")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IBinaryFile binary = null;
|
||||
try {
|
||||
MachO.Attribute attribute = null;
|
||||
if (hints != null && hints.length > 0) {
|
||||
try {
|
||||
attribute = MachO.getAttributes(hints);
|
||||
} catch (EOFException eof) {
|
||||
// continue, the array was to small.
|
||||
}
|
||||
}
|
||||
|
||||
//Take a second run at it if the data array failed.
|
||||
if(attribute == null) {
|
||||
attribute = MachO.getAttributes(path.toOSString());
|
||||
}
|
||||
|
||||
if (attribute != null) {
|
||||
switch (attribute.getType()) {
|
||||
case Attribute.MACHO_TYPE_EXE :
|
||||
binary = createBinaryExecutable(path);
|
||||
break;
|
||||
|
||||
case Attribute.MACHO_TYPE_SHLIB :
|
||||
binary = createBinaryShared(path);
|
||||
break;
|
||||
|
||||
case Attribute.MACHO_TYPE_OBJ :
|
||||
binary = createBinaryObject(path);
|
||||
break;
|
||||
|
||||
case Attribute.MACHO_TYPE_CORE :
|
||||
binary = createBinaryCore(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
binary = createBinaryArchive(path);
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinaryParser#getFormat()
|
||||
*/
|
||||
public String getFormat() {
|
||||
return "MACHO"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public boolean isBinary(byte[] array, IPath path) {
|
||||
return MachO.isMachOHeader(array) || AR.isARHeader(array);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.IBinaryParser#getBufferSize()
|
||||
*/
|
||||
public int getHintBufferSize() {
|
||||
return 128;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
protected IBinaryArchive createBinaryArchive(IPath path) throws IOException {
|
||||
return new BinaryArchive(this, path);
|
||||
}
|
||||
|
||||
protected IBinaryObject createBinaryObject(IPath path) throws IOException {
|
||||
return new MachOBinaryObject(this, path);
|
||||
}
|
||||
|
||||
protected IBinaryExecutable createBinaryExecutable(IPath path) throws IOException {
|
||||
return new MachOBinaryObject(this, path) {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return IBinaryFile.EXECUTABLE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected IBinaryShared createBinaryShared(IPath path) throws IOException {
|
||||
return new MachOBinaryObject(this, path) {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return IBinaryFile.SHARED;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected IBinaryObject createBinaryCore(IPath path) throws IOException {
|
||||
return new MachOBinaryObject(this, path) {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.macho.parser.MachOBinaryObject#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return IBinaryFile.CORE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -703,6 +703,11 @@
|
|||
parserID="org.eclipse.cdt.core.XCOFF32"
|
||||
id="XcoffBinaryParserPage">
|
||||
</parserPage>
|
||||
<parserPage
|
||||
class="org.eclipse.cdt.ui.dialogs.MachOBinaryParserPage"
|
||||
parserID="org.eclipse.cdt.core.MachO"
|
||||
id="MachOBinaryParserPage">
|
||||
</parserPage>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.workingSets">
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.dialogs;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.ICExtensionReference;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MachOBinaryParserPage extends AbstractCOptionPage {
|
||||
|
||||
public final static String PREF_CPPFILT_PATH = CUIPlugin.PLUGIN_ID + ".cppfilt"; //$NON-NLS-1$
|
||||
|
||||
protected Text fCPPFiltCommandText;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String cppfilt = fCPPFiltCommandText.getText().trim();
|
||||
|
||||
monitor.beginTask(CUIMessages.getString("BinaryParserPage.task.savingAttributes"), 1); //$NON-NLS-1$
|
||||
IProject proj = getContainer().getProject();
|
||||
if (proj != null) {
|
||||
String parserID = ""; //$NON-NLS-1$
|
||||
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj);
|
||||
ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID);
|
||||
if (cext.length > 0) {
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$
|
||||
IConfigurationElement[] infos = point.getConfigurationElements();
|
||||
for (int i = 0; i < infos.length; i++) {
|
||||
String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$
|
||||
String clazz = infos[i].getAttribute("class"); //$NON-NLS-1$
|
||||
String ego = getRealBinaryParserPage().getClass().getName();
|
||||
if (clazz != null && clazz.equals(ego)) {
|
||||
parserID = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < cext.length; i++) {
|
||||
if (cext[i].getID().equals(parserID)) {
|
||||
|
||||
String orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$
|
||||
if (orig == null || !orig.equals(cppfilt)) {
|
||||
cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Preferences store = getContainer().getPreferences();
|
||||
if (store != null) {
|
||||
store.setValue(PREF_CPPFILT_PATH, cppfilt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this class is inherited from then this method MUST be implemented
|
||||
* in the derived class.
|
||||
*/
|
||||
protected Object getRealBinaryParserPage() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
|
||||
*/
|
||||
public void performDefaults() {
|
||||
String addr2line = null;
|
||||
String cppfilt = null;
|
||||
IProject proj = getContainer().getProject();
|
||||
Preferences store = getContainer().getPreferences();
|
||||
if (store != null) {
|
||||
if (proj != null) {
|
||||
cppfilt = store.getString(PREF_CPPFILT_PATH);
|
||||
} else {
|
||||
cppfilt = store.getDefaultString(PREF_CPPFILT_PATH);
|
||||
}
|
||||
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
public void createControl(Composite parent) {
|
||||
Group comp = new Group(parent, SWT.SHADOW_ETCHED_IN);
|
||||
comp.setText(CUIMessages.getString("BinaryParserBlock.binaryParserOptions")); //$NON-NLS-1$
|
||||
comp.setLayout(new GridLayout(2, true));
|
||||
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
((GridLayout) comp.getLayout()).makeColumnsEqualWidth = false;
|
||||
|
||||
Label label = ControlFactory.createLabel(comp, CUIMessages.getString("BinaryParserPage.label.addr2lineCommand")); //$NON-NLS-1$
|
||||
GridData gd = new GridData();
|
||||
gd.horizontalSpan = 2;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
Button button = ControlFactory.createPushButton(comp, CUIMessages.getString("BinaryParserPage.label.browse")); //$NON-NLS-1$
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
public void widgetSelected(SelectionEvent evt) {
|
||||
//updateLaunchConfigurationDialog();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
label = ControlFactory.createLabel(comp, CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$
|
||||
gd = new GridData();
|
||||
gd.horizontalSpan = 2;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
fCPPFiltCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER);
|
||||
gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
fCPPFiltCommandText.setLayoutData(gd);
|
||||
fCPPFiltCommandText.addModifyListener(new ModifyListener() {
|
||||
|
||||
public void modifyText(ModifyEvent evt) {
|
||||
//updateLaunchConfigurationDialog();
|
||||
}
|
||||
});
|
||||
button = ControlFactory.createPushButton(comp, CUIMessages.getString("BinaryParserPage.label.browse")); //$NON-NLS-1$
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
public void widgetSelected(SelectionEvent evt) {
|
||||
handleCPPFiltButtonSelected();
|
||||
//updateLaunchConfigurationDialog();
|
||||
}
|
||||
|
||||
private void handleCPPFiltButtonSelected() {
|
||||
FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
|
||||
dialog.setText(CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$
|
||||
String command = fCPPFiltCommandText.getText().trim();
|
||||
int lastSeparatorIndex = command.lastIndexOf(File.separator);
|
||||
if (lastSeparatorIndex != -1) {
|
||||
dialog.setFilterPath(command.substring(0, lastSeparatorIndex));
|
||||
}
|
||||
String res = dialog.open();
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
fCPPFiltCommandText.setText(res);
|
||||
}
|
||||
});
|
||||
|
||||
setControl(comp);
|
||||
initialziedValues();
|
||||
}
|
||||
|
||||
private void initialziedValues() {
|
||||
String cppfilt = null;
|
||||
IProject proj = getContainer().getProject();
|
||||
if (proj != null) {
|
||||
try {
|
||||
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj);
|
||||
ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID);
|
||||
if (cext.length > 0) {
|
||||
cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
} else {
|
||||
Preferences store = getContainer().getPreferences();
|
||||
if (store != null) {
|
||||
cppfilt = store.getString(PREF_CPPFILT_PATH);
|
||||
}
|
||||
}
|
||||
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue