Generate debugging information during compilation (bug 5227, r=ds).

This commit is contained in:
Asher Baker 2013-03-17 21:00:28 +00:00
parent 4e7a9cf30b
commit 0f62a8ec2f
20 changed files with 52 additions and 3 deletions

View File

@ -1,8 +1,28 @@
# vim: set ts=2 sw=2 tw=99 noet ft=python: # vim: set ts=2 sw=2 tw=99 noet ft=python:
import os import os
import sys import sys
from ambuild.command import Command
from ambuild.command import ShellCommand
from ambuild.command import SymlinkCommand from ambuild.command import SymlinkCommand
class ExtractDebugInfoCommand(Command):
def __init__(self, binary, outfile):
Command.__init__(self)
self.binary = binary
self.outfile = outfile
def run(self, runner, job):
if not self.binary.NeedsRelink(self.outfile):
return
if AMBuild.target['platform'] == 'linux':
job.AddCommand(ShellCommand('objcopy --only-keep-debug ' + self.outfile + ' ' + self.outfile + '.dbg'))
job.AddCommand(ShellCommand('objcopy --strip-debug ' + self.outfile))
job.AddCommand(ShellCommand('objcopy --add-gnu-debuglink=' + os.path.basename(self.outfile) + '.dbg ' + self.outfile))
elif AMBuild.target['platform'] == 'darwin':
job.AddCommand(ShellCommand('dsymutil ' + self.outfile))
job.AddCommand(ShellCommand('strip -S ' + self.outfile))
class SM: class SM:
def __init__(self): def __init__(self):
self.compiler = Cpp.Compiler() self.compiler = Cpp.Compiler()
@ -117,6 +137,7 @@ class SM:
self.compiler.AddToListVar('CFLAGS', '-Wno-unused') self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
self.compiler.AddToListVar('CFLAGS', '-Wno-switch') self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
self.compiler.AddToListVar('CFLAGS', '-msse') self.compiler.AddToListVar('CFLAGS', '-msse')
self.compiler.AddToListVar('CFLAGS', '-g3')
self.compiler.AddToListVar('CFLAGS', '-m32') self.compiler.AddToListVar('CFLAGS', '-m32')
self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
@ -176,9 +197,7 @@ class SM:
if AMBuild.options.debug == '1': if AMBuild.options.debug == '1':
self.compiler.AddToListVar('CDEFINES', 'DEBUG') self.compiler.AddToListVar('CDEFINES', 'DEBUG')
self.compiler.AddToListVar('CDEFINES', '_DEBUG') self.compiler.AddToListVar('CDEFINES', '_DEBUG')
if self.vendor == 'gcc' or self.vendor == 'clang': if self.vendor == 'msvc':
self.compiler.AddToListVar('CFLAGS', '-g3')
elif self.vendor == 'msvc':
self.compiler.AddToListVar('CFLAGS', '/Od') self.compiler.AddToListVar('CFLAGS', '/Od')
self.compiler.AddToListVar('CFLAGS', '/RTC1') self.compiler.AddToListVar('CFLAGS', '/RTC1')
@ -265,6 +284,10 @@ class SM:
else: else:
return return
def ExtractDebugInfo(self, job, binary):
src = os.path.join('..', AMBuild.outputFolder, job.workFolder, binary.binaryFile)
job.AddCommand(ExtractDebugInfoCommand(binary, src))
def PreSetupHL2Job(self, job, builder, sdk): def PreSetupHL2Job(self, job, builder, sdk):
info = self.sdkInfo[sdk] info = self.sdkInfo[sdk]
sdkPath = AMBuild.cache[info['sdk']] sdkPath = AMBuild.cache[info['sdk']]

View File

@ -120,5 +120,6 @@ for i in SM.sdkInfo:
binary.AddObjectFiles(['libprotobuf.a']) binary.AddObjectFiles(['libprotobuf.a'])
SM.AutoVersion('core', binary) SM.AutoVersion('core', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -58,5 +58,6 @@ else:
files.append('thread/PosixThreads.cpp') files.append('thread/PosixThreads.cpp')
binary.AddSourceFiles('core/logic', files) binary.AddSourceFiles('core/logic', files)
SM.AutoVersion('core/logic', binary) SM.AutoVersion('core/logic', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -19,6 +19,7 @@ binary.AddSourceFiles('extensions/bintools', [
'sdk/smsdk_ext.cpp' 'sdk/smsdk_ext.cpp'
]) ])
SM.AutoVersion('extensions/bintools', binary) SM.AutoVersion('extensions/bintools', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -15,5 +15,6 @@ binary.AddSourceFiles('extensions/clientprefs', [
'sdk/smsdk_ext.cpp' 'sdk/smsdk_ext.cpp'
]) ])
SM.AutoVersion('extensions/clientprefs', binary) SM.AutoVersion('extensions/clientprefs', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -29,4 +29,5 @@ for i in SM.sdkInfo:
]) ])
SM.PostSetupHL2Job(extension, binary, i) SM.PostSetupHL2Job(extension, binary, i)
SM.AutoVersion('extensions/cstrike', binary) SM.AutoVersion('extensions/cstrike', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -82,5 +82,6 @@ elif AMBuild.target['platform'] == 'windows':
binary['POSTLINKFLAGS'].extend([path, 'ws2_32.lib']) binary['POSTLINKFLAGS'].extend([path, 'ws2_32.lib'])
SM.AutoVersion('extensions/curl', binary) SM.AutoVersion('extensions/curl', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -11,5 +11,6 @@ binary.AddSourceFiles('extensions/geoip', [
if AMBuild.target['platform'] == 'windows': if AMBuild.target['platform'] == 'windows':
binary['POSTLINKFLAGS'].append('wsock32.lib') binary['POSTLINKFLAGS'].append('wsock32.lib')
SM.AutoVersion('extensions/geoip', binary) SM.AutoVersion('extensions/geoip', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -34,5 +34,6 @@ binary.AddSourceFiles('extensions/mysql', [
'extension.cpp' 'extension.cpp'
]) ])
SM.AutoVersion('extensions/mysql', binary) SM.AutoVersion('extensions/mysql', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -23,5 +23,6 @@ binary.AddSourceFiles('extensions/regex', [
'sdk/smsdk_ext.cpp', 'sdk/smsdk_ext.cpp',
]) ])
SM.AutoVersion('extensions/regex', binary) SM.AutoVersion('extensions/regex', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -26,5 +26,6 @@ for i in SM.sdkInfo:
]) ])
SM.PostSetupHL2Job(extension, binary, i) SM.PostSetupHL2Job(extension, binary, i)
SM.AutoVersion('extensions/sdkhooks', binary) SM.AutoVersion('extensions/sdkhooks', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -48,5 +48,6 @@ for i in SM.sdkInfo:
]) ])
SM.PostSetupHL2Job(extension, binary, i) SM.PostSetupHL2Job(extension, binary, i)
SM.AutoVersion('extensions/sdktools', binary) SM.AutoVersion('extensions/sdktools', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -17,5 +17,6 @@ files = [
] ]
binary.AddSourceFiles('extensions/sqlite', files) binary.AddSourceFiles('extensions/sqlite', files)
SM.AutoVersion('extensions/sqlite', binary) SM.AutoVersion('extensions/sqlite', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -26,5 +26,6 @@ if 'ep2v' in SM.sdkInfo:
]) ])
SM.PostSetupHL2Job(extension, binary, 'ep2v') SM.PostSetupHL2Job(extension, binary, 'ep2v')
SM.AutoVersion('extensions/tf2', binary) SM.AutoVersion('extensions/tf2', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -15,5 +15,6 @@ binary.AddSourceFiles('extensions/topmenus', [
'sdk/sm_memtable.cpp' 'sdk/sm_memtable.cpp'
]) ])
SM.AutoVersion('extensions/topmenus', binary) SM.AutoVersion('extensions/topmenus', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -14,5 +14,6 @@ binary.AddSourceFiles('extensions/updater', [
'sdk/smsdk_ext.cpp' 'sdk/smsdk_ext.cpp'
]) ])
SM.AutoVersion('extensions/updater', binary) SM.AutoVersion('extensions/updater', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -17,5 +17,6 @@ binary.AddSourceFiles('loader', [
'loader.cpp' 'loader.cpp'
]) ])
SM.AutoVersion('loader', binary) SM.AutoVersion('loader', binary)
SM.ExtractDebugInfo(loader, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -67,5 +67,6 @@ elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBu
binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0']) binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']]) binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -40,5 +40,6 @@ binary.AddSourceFiles('sourcepawn/jit', [
'../../knight/shared/KeCodeAllocator.cpp' '../../knight/shared/KeCodeAllocator.cpp'
]) ])
SM.AutoVersion('sourcepawn/jit', binary) SM.AutoVersion('sourcepawn/jit', binary)
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob() binary.SendToJob()

View File

@ -255,6 +255,14 @@ AddHL2Library('sdktools.ext', 'extensions')
bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()), bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
os.path.join('addons', 'sourcemod', 'scripting'))) os.path.join('addons', 'sourcemod', 'scripting')))
# Each platform's version of dump_syms needs the path in a different format.
if AMBuild.target['platform'] == 'linux':
debug_info.append('spcomp' + '/' + 'spcomp')
elif AMBuild.target['platform'] == 'darwin':
debug_info.append('spcomp' + '/' + 'spcomp' + '.dSYM')
elif AMBuild.target['platform'] == 'windows':
debug_info.append('spcomp' + '\\' + 'spcomp' + '.pdb'
job.AddCommandGroup(bincopies) job.AddCommandGroup(bincopies)
if AMBuild.target['platform'] == 'windows': if AMBuild.target['platform'] == 'windows':