diff --git a/ptlsim/SConstruct b/ptlsim/SConstruct
index e427c93..a409bb9 100644
--- a/ptlsim/SConstruct
+++ b/ptlsim/SConstruct
@@ -4,6 +4,7 @@ import os
 import platform
 import subprocess
 import config_helper
+import re
 
 # List of subdirectories where we have source code
 dirs = ['cache', 'core', 'lib', 'sim', 'stats', 'tools', 'x86']
@@ -29,13 +30,22 @@ env['CPPPATH'].append("%s/%s" % (qemu_dir, "x86_64-softmmu"))
 optimization_defs = '-fno-trapping-math -fstack-protector -fno-exceptions '
 optimization_defs += '-fno-rtti -funroll-loops -fstrict-aliasing '
 
+GCC_VERSION = subprocess.Popen([env['CC'], '-dumpversion'],
+				stdout=subprocess.PIPE).communicate()[0].strip()
+GCC_MAJOR_MINOR_VERSION = re.match(r'\d*\.\d+',GCC_VERSION).group() #e.g. returns 4.2 for 4.2.2
 debug = ARGUMENTS.get('debug', 0)
 if int(debug):
-    env.Append(CCFLAGS = '-g')
 
     # If debugging level is 1 then do optimize
     if int(debug) == 1:
+    	env.Append(CCFLAGS = '-g')
         env.Append(CCFLAGS = '-O')
+    elif int(debug) == 2: #For more detailed debugging information
+		env.Append(CCFLAGS = '-ggdb3')
+		if float(GCC_MAJOR_MINOR_VERSION) >= 4.8:
+			env.Append(CCFLAGS = '-Og')
+		else: #Possibly slow
+			env.Append(CCFLAGS = '-O0')
 
     # Enable tests
     env.Append(CCFLAGS = '-DENABLE_TESTS')
diff --git a/qemu/SConstruct b/qemu/SConstruct
index 62e0a5c..8295466 100644
--- a/qemu/SConstruct
+++ b/qemu/SConstruct
@@ -6,6 +6,8 @@ Import('qemu_target')
 Import('ptlsim_lib')
 Import('plugins')
 Import('ptlsim_inc_dir')
+import subprocess
+import re
 env = qemu_env
 target = qemu_target
 
@@ -26,13 +28,23 @@ env.Append(CCFLAGS = "-DMARSS_QEMU")
 num_sim_cores = ARGUMENTS.get('c', 1)
 env.Append(CCFLAGS = '-DNUM_SIM_CORES=%d' % int(num_sim_cores))
 
+GCC_VERSION = subprocess.Popen([env['CC'], '-dumpversion'],
+				stdout=subprocess.PIPE).communicate()[0].strip()
+GCC_MAJOR_MINOR_VERSION = re.match(r'\d*\.\d+',GCC_VERSION).group() #e.g. returns 4.2 for 4.2.2
+
 debug = ARGUMENTS.get('debug', 0)
 if int(debug):
-    env.Append(CCFLAGS = '-g')
 
     # If debugging level is 1 then do optimize
     if int(debug) == 1:
+    	env.Append(CCFLAGS = '-g')
         env.Append(CCFLAGS = '-O')
+    elif int(debug) == 2: #For more detailed debugging information
+		env.Append(CCFLAGS = '-ggdb3')
+		if float(GCC_MAJOR_MINOR_VERSION) >= 4.8:
+			env.Append(CCFLAGS = '-Og')
+		else: #Possibly slow
+			env.Append(CCFLAGS = '-O0')
 else:
     env.Append(CCFLAGS = '-g3')
     env.Append(CCFLAGS = '-O3 -march=native -mtune=native')
