added lib/debugsup

added      lib/debugsup/debugsup-ntos.def
added      lib/debugsup/debugsup.rbuild
modified   lib/lib.rbuild
   New import-only library. Links modules that need low-level debugging functions (DbgBreakPoint, DbgBreakPointWithStatus, DbgPrint, DbgPrompt, DbgPrintEx, RtlAssert, RtlUnwind) to the correct low-level library (ntdll for user mode and ntoskrnl for kernel mode). This ensures debugging macros will always work, everywhere, and it doesn't force all modules with debugging information to link to ntdll/ntoskrnl. TODO: link RtlUnwind to kernel32 for Win32 modules

modified   tools/rbuild/backend/mingw/modulehandler.cpp
modified   tools/rbuild/backend/mingw/modulehandler.h
   Add debugsup_ntdll/debugsup_ntoskrnl as an implicit library for all executable modules (minus the kernel)


svn path=/trunk/; revision=26051
This commit is contained in:
KJK::Hyperion 2007-03-10 03:51:27 +00:00
parent 2ce0a2f2ed
commit f5891f221e
5 changed files with 107 additions and 28 deletions

View file

@ -0,0 +1,10 @@
EXPORTS
DbgBreakPoint@0
DbgBreakPointWithStatus@4
DbgPrint
DbgPrompt@12
DbgPrintEx
RtlAssert@16
RtlUnwind@16
;EOF

View file

@ -0,0 +1,8 @@
<group>
<module name="debugsup_ntoskrnl" type="staticlibrary">
<importlibrary definition="debugsup-ntos.def" dllname="ntoskrnl.exe" />
</module>
<module name="debugsup_ntdll" type="staticlibrary">
<importlibrary definition="debugsup-ntos.def" dllname="ntdll.dll" />
</module>
</group>

View file

@ -64,5 +64,8 @@
<directory name="wdmguid"> <directory name="wdmguid">
<xi:include href="wdmguid/wdmguid.rbuild" /> <xi:include href="wdmguid/wdmguid.rbuild" />
</directory> </directory>
<directory name="debugsup">
<xi:include href="debugsup/debugsup.rbuild" />
</directory>
</group> </group>

View file

@ -418,7 +418,7 @@ MingwModuleHandler::GetModuleDependencies (
if ( iend == 0 ) if ( iend == 0 )
return; return;
for ( size_t i = 0; i < iend; i++ ) for ( size_t i = 0; i < iend; i++ )
{ {
const Dependency& dependency = *module.dependencies[i]; const Dependency& dependency = *module.dependencies[i];
@ -506,7 +506,7 @@ MingwModuleHandler::GetObjectFilename (
} }
else else
newExtension = ".o"; newExtension = ".o";
if ( module.type == BootSector ) if ( module.type == BootSector )
directoryTree = backend->outputDirectory; directoryTree = backend->outputDirectory;
else else
@ -547,7 +547,7 @@ MingwModuleHandler::GenerateCleanTarget () const
{ {
if ( module.type == Alias ) if ( module.type == Alias )
return; return;
fprintf ( fMakefile, fprintf ( fMakefile,
".PHONY: %s_clean\n", ".PHONY: %s_clean\n",
module.name.c_str() ); module.name.c_str() );
@ -604,7 +604,7 @@ MingwModuleHandler::GetObjectFilenames ()
const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits; const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits;
if ( compilationUnits.size () == 0 ) if ( compilationUnits.size () == 0 )
return ""; return "";
string objectFilenames ( "" ); string objectFilenames ( "" );
for ( size_t i = 0; i < compilationUnits.size (); i++ ) for ( size_t i = 0; i < compilationUnits.size (); i++ )
{ {
@ -636,7 +636,7 @@ MingwModuleHandler::GenerateGccDefineParametersFromVector (
return parameters; return parameters;
} }
string string
MingwModuleHandler::GenerateGccDefineParameters () const MingwModuleHandler::GenerateGccDefineParameters () const
{ {
string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines ); string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
@ -824,7 +824,7 @@ MingwModuleHandler::GenerateMacros (
GenerateMacro ( assignmentOperation, GenerateMacro ( assignmentOperation,
windresflagsMacro, windresflagsMacro,
data ); data );
if ( linkerFlags != NULL ) if ( linkerFlags != NULL )
{ {
string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags ); string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
@ -874,7 +874,7 @@ MingwModuleHandler::GenerateMacros (
"+=", "+=",
rIf.data, rIf.data,
NULL ); NULL );
fprintf ( fprintf (
fMakefile, fMakefile,
"endif\n\n" ); "endif\n\n" );
} }
@ -957,7 +957,7 @@ MingwModuleHandler::GenerateObjectMacros (
"+=", "+=",
rIf.data, rIf.data,
NULL ); NULL );
fprintf ( fprintf (
fMakefile, fMakefile,
"endif\n\n" ); "endif\n\n" );
} }
@ -997,7 +997,7 @@ MingwModuleHandler::GenerateGccCommand (
dependencies += " " + extraDependencies; dependencies += " " + extraDependencies;
if ( module.pch && use_pch ) if ( module.pch && use_pch )
dependencies += " " + GetPrecompiledHeaderFilename (); dependencies += " " + GetPrecompiledHeaderFilename ();
/* WIDL generated headers may be used */ /* WIDL generated headers may be used */
vector<string> rpcDependencies; vector<string> rpcDependencies;
GetRpcHeaderDependencies ( rpcDependencies ); GetRpcHeaderDependencies ( rpcDependencies );
@ -1172,7 +1172,7 @@ MingwModuleHandler::GetRpcServerHeaderFilename ( string basename ) const
return PassThruCacheDirectory ( basename + "_s.h", return PassThruCacheDirectory ( basename + "_s.h",
backend->intermediateDirectory ); backend->intermediateDirectory );
} }
void void
MingwModuleHandler::GenerateWidlCommandsServer ( MingwModuleHandler::GenerateWidlCommandsServer (
const CompilationUnit& compilationUnit, const CompilationUnit& compilationUnit,
@ -1397,7 +1397,7 @@ MingwModuleHandler::GenerateBuildMapCode ( const char *mapTarget )
GetBasename ( module.GetPath () ) + ".map", GetBasename ( module.GetPath () ) + ".map",
backend->outputDirectory ); backend->outputDirectory );
CLEAN_FILE ( mapFilename ); CLEAN_FILE ( mapFilename );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t$(ECHO_OBJDUMP)\n" ); "\t$(ECHO_OBJDUMP)\n" );
fprintf ( fMakefile, fprintf ( fMakefile,
@ -1438,14 +1438,14 @@ MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ), GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ),
backend->outputDirectory ); backend->outputDirectory );
CLEAN_FILE ( nostripFilename ); CLEAN_FILE ( nostripFilename );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t$(ECHO_CP)\n" ); "\t$(ECHO_CP)\n" );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t${cp} %s %s 1>$(NUL)\n", "\t${cp} %s %s 1>$(NUL)\n",
outputFilename.c_str (), outputFilename.c_str (),
nostripFilename.c_str () ); nostripFilename.c_str () );
fprintf ( fMakefile, fprintf ( fMakefile,
"endif\n" ); "endif\n" );
} }
@ -1562,14 +1562,14 @@ MingwModuleHandler::GenerateLinkerCommand (
{ {
string temp_exp = ros_temp + module.name + ".temp.exp"; string temp_exp = ros_temp + module.name + ".temp.exp";
CLEAN_FILE ( temp_exp ); CLEAN_FILE ( temp_exp );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t${dlltool} --dllname %s --def %s --output-exp %s %s\n", "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
targetName.c_str (), targetName.c_str (),
definitionFilename.c_str (), definitionFilename.c_str (),
temp_exp.c_str (), temp_exp.c_str (),
killAt.c_str () ); killAt.c_str () );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t%s %s %s %s -o %s %s %s %s\n", "\t%s %s %s %s -o %s %s %s %s\n",
linker.c_str (), linker.c_str (),
@ -1580,7 +1580,7 @@ MingwModuleHandler::GenerateLinkerCommand (
objectsMacro.c_str (), objectsMacro.c_str (),
libsMacro.c_str (), libsMacro.c_str (),
GetLinkerMacro ().c_str () ); GetLinkerMacro ().c_str () );
fprintf ( fMakefile, fprintf ( fMakefile,
"\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n", "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
target.c_str (), target.c_str (),
@ -1601,7 +1601,7 @@ MingwModuleHandler::GenerateLinkerCommand (
objectsMacro.c_str (), objectsMacro.c_str (),
libsMacro.c_str (), libsMacro.c_str (),
GetLinkerMacro ().c_str () ); GetLinkerMacro ().c_str () );
#if 0 // causes crashes sometimes #if 0 // causes crashes sometimes
fprintf ( fMakefile, fprintf ( fMakefile,
"\t${objcopy} -R .edata %s\n", "\t${objcopy} -R .edata %s\n",
@ -1639,7 +1639,7 @@ MingwModuleHandler::GenerateObjectFileTargets (
const string& widlflagsMacro ) const string& widlflagsMacro )
{ {
size_t i; size_t i;
const vector<CompilationUnit*>& compilationUnits = data.compilationUnits; const vector<CompilationUnit*>& compilationUnits = data.compilationUnits;
for ( i = 0; i < compilationUnits.size (); i++ ) for ( i = 0; i < compilationUnits.size (); i++ )
{ {
@ -1728,7 +1728,7 @@ MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
const string& objs_macro ) const const string& objs_macro ) const
{ {
string archiveFilename ( GetModuleArchiveFilename () ); string archiveFilename ( GetModuleArchiveFilename () );
fprintf ( fMakefile, fprintf ( fMakefile,
"%s: %s | %s\n", "%s: %s | %s\n",
archiveFilename.c_str (), archiveFilename.c_str (),
@ -1908,7 +1908,7 @@ MingwModuleHandler::GenerateOtherMacros ()
// Always force disabling of sibling calls optimisation for GCC // Always force disabling of sibling calls optimisation for GCC
// (TODO: Move to version-specific once this bug is fixed in GCC) // (TODO: Move to version-specific once this bug is fixed in GCC)
globalCflags += " -fno-optimize-sibling-calls"; globalCflags += " -fno-optimize-sibling-calls";
fprintf ( fprintf (
fMakefile, fMakefile,
"%s += $(PROJECT_CFLAGS) %s\n", "%s += $(PROJECT_CFLAGS) %s\n",
@ -2047,7 +2047,7 @@ MingwModuleHandler::GenerateInvocations () const
{ {
if ( module.invocations.size () == 0 ) if ( module.invocations.size () == 0 )
return; return;
size_t iend = module.invocations.size (); size_t iend = module.invocations.size ();
for ( size_t i = 0; i < iend; i++ ) for ( size_t i = 0; i < iend; i++ )
{ {
@ -2122,7 +2122,7 @@ MingwModuleHandler::GeneratePreconditionDependencies ()
GetModuleDependencies ( dependencies ); GetModuleDependencies ( dependencies );
GetInvocationDependencies ( module, dependencies ); GetInvocationDependencies ( module, dependencies );
if ( dependencies.size() ) if ( dependencies.size() )
{ {
fprintf ( fMakefile, fprintf ( fMakefile,
@ -2179,7 +2179,7 @@ MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
string library_target ( string library_target (
GetImportLibraryFilename ( module, &clean_files ) ); GetImportLibraryFilename ( module, &clean_files ) );
string defFilename = GetDefinitionFilename (); string defFilename = GetDefinitionFilename ();
string_list deps; string_list deps;
GetDefinitionDependencies ( deps ); GetDefinitionDependencies ( deps );
@ -2256,6 +2256,33 @@ MingwModuleHandler::GetDefinitionDependencies (
} }
} }
enum DebugSupportType
{
DebugKernelMode,
DebugUserMode
};
static void
MingwAddDebugSupportLibraries ( Module& module, DebugSupportType type )
{
Library* pLibrary;
switch(type)
{
case DebugKernelMode:
pLibrary = new Library ( module, "debugsup_ntoskrnl" );
break;
case DebugUserMode:
pLibrary = new Library ( module, "debugsup_ntdll" );
break;
default:
assert(0);
}
module.non_if_data.libraries.push_back(pLibrary);
}
MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ ) MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
: MingwModuleHandler ( module_ ) : MingwModuleHandler ( module_ )
@ -2283,7 +2310,7 @@ MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
linker = "${host_gpp}"; linker = "${host_gpp}";
else else
linker = "${host_gcc}"; linker = "${host_gcc}";
fprintf ( fMakefile, "%s: %s %s | %s\n", fprintf ( fMakefile, "%s: %s %s | %s\n",
targetMacro.c_str (), targetMacro.c_str (),
objectsMacro.c_str (), objectsMacro.c_str (),
@ -2395,6 +2422,12 @@ MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
{ {
} }
void
MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module& module )
{
MingwAddDebugSupportLibraries ( module, DebugKernelMode );
}
void void
MingwKernelModeDLLModuleHandler::Process () MingwKernelModeDLLModuleHandler::Process ()
{ {
@ -2442,6 +2475,12 @@ MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
{ {
} }
void
MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module& module )
{
MingwAddDebugSupportLibraries ( module, DebugKernelMode );
}
void void
MingwKernelModeDriverModuleHandler::Process () MingwKernelModeDriverModuleHandler::Process ()
{ {
@ -2490,6 +2529,12 @@ MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
{ {
} }
void
MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module& module )
{
MingwAddDebugSupportLibraries ( module, DebugUserMode );
}
void void
MingwNativeDLLModuleHandler::Process () MingwNativeDLLModuleHandler::Process ()
{ {
@ -2504,7 +2549,7 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
string objectsMacro = GetObjectsMacro ( module ); string objectsMacro = GetObjectsMacro ( module );
string linkDepsMacro = GetLinkingDependenciesMacro (); string linkDepsMacro = GetLinkingDependenciesMacro ();
string libsMacro = GetLibsMacro (); string libsMacro = GetLibsMacro ();
GenerateImportLibraryTargetIfNeeded (); GenerateImportLibraryTargetIfNeeded ();
if ( module.non_if_data.compilationUnits.size () > 0 ) if ( module.non_if_data.compilationUnits.size () > 0 )
@ -2537,6 +2582,12 @@ MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
{ {
} }
void
MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module& module )
{
MingwAddDebugSupportLibraries ( module, DebugUserMode );
}
void void
MingwNativeCUIModuleHandler::Process () MingwNativeCUIModuleHandler::Process ()
{ {
@ -2551,7 +2602,7 @@ MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
string objectsMacro = GetObjectsMacro ( module ); string objectsMacro = GetObjectsMacro ( module );
string linkDepsMacro = GetLinkingDependenciesMacro (); string linkDepsMacro = GetLinkingDependenciesMacro ();
string libsMacro = GetLibsMacro (); string libsMacro = GetLibsMacro ();
GenerateImportLibraryTargetIfNeeded (); GenerateImportLibraryTargetIfNeeded ();
if ( module.non_if_data.compilationUnits.size () > 0 ) if ( module.non_if_data.compilationUnits.size () > 0 )
@ -2618,6 +2669,7 @@ void
MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module& module ) MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module& module )
{ {
MingwAddImplicitLibraries ( module ); MingwAddImplicitLibraries ( module );
MingwAddDebugSupportLibraries ( module, DebugUserMode );
} }
void void
@ -2677,6 +2729,7 @@ void
MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module& module ) MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module& module )
{ {
MingwAddImplicitLibraries ( module ); MingwAddImplicitLibraries ( module );
MingwAddDebugSupportLibraries ( module, DebugUserMode );
} }
void void
@ -2736,6 +2789,7 @@ void
MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module& module ) MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module& module )
{ {
MingwAddImplicitLibraries ( module ); MingwAddImplicitLibraries ( module );
MingwAddDebugSupportLibraries ( module, DebugUserMode );
} }
void void
@ -2901,7 +2955,7 @@ MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
linkDepsMacro.c_str (), linkDepsMacro.c_str (),
payload->name.c_str (), payload->name.c_str (),
GetDirectory(GetTargetFilename(module,NULL)).c_str () ); GetDirectory(GetTargetFilename(module,NULL)).c_str () );
fprintf ( fMakefile, "\t$(ECHO_BOOTPROG)\n" ); fprintf ( fMakefile, "\t$(ECHO_BOOTPROG)\n" );
fprintf ( fMakefile, "\t$(BOOTPROG_PREPARE) $(OUTPUT)$(SEP)%s %s\n", fprintf ( fMakefile, "\t$(BOOTPROG_PREPARE) $(OUTPUT)$(SEP)%s %s\n",

View file

@ -104,7 +104,7 @@ protected:
string_list* pclean_files ) const; string_list* pclean_files ) const;
std::string GetObjectFilenames (); std::string GetObjectFilenames ();
std::string GetPreconditionDependenciesName () const; std::string GetPreconditionDependenciesName () const;
std::string GetCFlagsMacro () const; std::string GetCFlagsMacro () const;
static std::string GetObjectsMacro ( const Module& ); static std::string GetObjectsMacro ( const Module& );
@ -280,6 +280,7 @@ public:
virtual void Process (); virtual void Process ();
std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; } std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; } std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
void AddImplicitLibraries ( Module& module );
private: private:
void GenerateKernelModeDLLModuleTarget (); void GenerateKernelModeDLLModuleTarget ();
}; };
@ -293,6 +294,7 @@ public:
virtual void Process (); virtual void Process ();
std::string TypeSpecificCFlags() { return "-D__NTDRIVER__ -D_SEH_NO_NATIVE_NLG"; } std::string TypeSpecificCFlags() { return "-D__NTDRIVER__ -D_SEH_NO_NATIVE_NLG"; }
std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; } std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
void AddImplicitLibraries ( Module& module );
private: private:
void GenerateKernelModeDriverModuleTarget (); void GenerateKernelModeDriverModuleTarget ();
}; };
@ -306,6 +308,7 @@ public:
virtual void Process (); virtual void Process ();
std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; } std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; } std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
void AddImplicitLibraries ( Module& module );
private: private:
void GenerateNativeDLLModuleTarget (); void GenerateNativeDLLModuleTarget ();
}; };
@ -319,6 +322,7 @@ public:
virtual void Process (); virtual void Process ();
std::string TypeSpecificCFlags() { return "-D__NTAPP__ -D_SEH_NO_NATIVE_NLG"; } std::string TypeSpecificCFlags() { return "-D__NTAPP__ -D_SEH_NO_NATIVE_NLG"; }
std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; } std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
void AddImplicitLibraries ( Module& module );
private: private:
void GenerateNativeCUIModuleTarget (); void GenerateNativeCUIModuleTarget ();
}; };