[m-rev.] for review: make --c-debug work with MSVC

Peter Ross pro at missioncriticalit.com
Thu Oct 31 03:08:21 AEDT 2002


Hi,

For fjh or stayl to review.


===================================================================


Estimated hours taken: 1
Branches: main

Make --c-debug work correctly when using MSVC as your C compiler.

compiler/compile_target_code.m:
scripts/mgnuc.in:
	Use /Zi when --c-debug is enabled.
	
scripts/ml.in:
	Pass /DEBUG to the linker when --c-debug is enabled.

runtime/Mmakefile:
	Pass --c-debug to mgnuc rather than passing -g through to the
	underlying C compiler.


Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.23
diff -u -r1.23 compile_target_code.m
--- compiler/compile_target_code.m	1 Sep 2002 06:04:58 -0000	1.23
+++ compiler/compile_target_code.m	30 Oct 2002 16:04:15 -0000
@@ -297,7 +297,7 @@
 % WARNING: The code here duplicates the functionality of scripts/mgnuc.in.
 % Any changes there may also require changes here, and vice versa.
 
-:- type compiler_type ---> gcc ; lcc ; unknown.
+:- type compiler_type ---> gcc ; lcc ; cl ; unknown.
 
 compile_c_file(ErrorStream, PIC, ModuleName, Succeeded) -->
 	module_name_to_file_name(ModuleName, ".c", yes, C_File),
@@ -323,6 +323,16 @@
 	globals__io_lookup_accumulating_option(cflags, C_Flags_List),
 	{ join_string_list(C_Flags_List, "", "", " ", CFLAGS) },
 	
+	{ string__sub_string_search(CC, "gcc", _) ->
+		CompilerType = gcc
+	; string__sub_string_search(CC, "lcc", _) ->
+		CompilerType = lcc
+	; string__sub_string_search(string__to_lower(CC), "cl", _) ->
+		CompilerType = cl
+	;
+		CompilerType = unknown
+	},
+
 	(
 		{ PIC = pic },
 		globals__io_lookup_string_option(cflags_for_pic,
@@ -478,7 +488,15 @@
 	},
 	globals__io_lookup_bool_option(target_debug, Target_Debug),
 	{ Target_Debug = yes ->
-		Target_DebugOpt = "-g "
+		( CompilerType = gcc,
+			Target_DebugOpt = "-g "
+		; CompilerType = lcc,
+			Target_DebugOpt = "-g "
+		; CompilerType = cl,
+			Target_DebugOpt = "/Zi "
+		; CompilerType = unknown,
+			Target_DebugOpt = "-g "
+		)
 	;
 		Target_DebugOpt = ""
 	},
@@ -487,13 +505,6 @@
 		LL_DebugOpt = "-DMR_LOW_LEVEL_DEBUG "
 	;
 		LL_DebugOpt = ""
-	},
-	{ string__sub_string_search(CC, "gcc", _) ->
-		CompilerType = gcc
-	; string__sub_string_search(CC, "lcc", _) ->
-		CompilerType = lcc
-	;
-		CompilerType = unknown
 	},
 	globals__io_lookup_bool_option(use_trail, UseTrail),
 	{ UseTrail = yes ->
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.96
diff -u -r1.96 Mmakefile
--- runtime/Mmakefile	18 Oct 2002 04:16:12 -0000	1.96
+++ runtime/Mmakefile	30 Oct 2002 16:04:19 -0000
@@ -193,8 +193,8 @@
 
 #-----------------------------------------------------------------------------#
 
-CFLAGS	+= -g $(DLL_CFLAGS) -DMERCURY_BOOTSTRAP_H -DMERCURY_CONF_BOOTSTRAP_H
-MGNUCFLAGS	+= --no-ansi
+CFLAGS	+= $(DLL_CFLAGS) -DMERCURY_BOOTSTRAP_H -DMERCURY_CONF_BOOTSTRAP_H
+MGNUCFLAGS	+= --c-debug --no-ansi
 
 #-----------------------------------------------------------------------------#
 
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.94
diff -u -r1.94 mgnuc.in
--- scripts/mgnuc.in	6 Oct 2002 15:45:30 -0000	1.94
+++ scripts/mgnuc.in	30 Oct 2002 16:04:26 -0000
@@ -52,24 +52,28 @@
 # -Wunused		causes various spurious warnings
 
 	OPT_OPTS="-O2 -fomit-frame-pointer"
+	DEBUG_OPT="-g"
 	COMPILER=gcc
 	;;
     *lcc*)
 	ANSI_OPTS=
 	CHECK_OPTS="-w"     # turn off all warnings due to spurious warnings.
 	OPT_OPTS=""
+	DEBUG_OPT="-g"
 	COMPILER=lcc
 	;;
     *cl* | *CL*)
 	ANSI_OPTS=""
 	CHECK_OPTS=""
 	OPT_OPTS=""
+	DEBUG_OPT="/Zi"
 	COMPILER=cl
 	;;
     *)
 	ANSI_OPTS=
 	CHECK_OPTS=
 	OPT_OPTS="-O"
+	DEBUG_OPT="-g"
 	COMPILER=unknown
 	;;
 esac
@@ -243,7 +247,7 @@
 #
 
 case $c_debug in
-	true)		C_DEBUG_OPTS="-g" ;;
+	true)		C_DEBUG_OPTS="$DEBUG_OPT" ;;
 	false)		C_DEBUG_OPTS="" ;;
 esac
 
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.100
diff -u -r1.100 ml.in
--- scripts/ml.in	24 Oct 2002 07:36:19 -0000	1.100
+++ scripts/ml.in	30 Oct 2002 16:04:26 -0000
@@ -436,8 +436,17 @@
     true) demangle=false ;;
 esac
 
+# Determine whether to link the executable with debugging symbols when using
+# MSVC.
+if [ $strip = "false" -a $COMPILER = "cl" ]
+then
+    DEBUG_FLAG="/DEBUG"
+else
+    DEBUG_FLAG=""
+fi
+
 LINKER_PRE_FLAGS="$UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS"
-LINKER_POST_FLAGS="@LINK_OPT_SEP@ $LIBDIR_OPTS $RPATH_OPT_LIST $LIBS"
+LINKER_POST_FLAGS="@LINK_OPT_SEP@ $DEBUG_FLAG $LIBDIR_OPTS $RPATH_OPT_LIST $LIBS"
 
 case $verbose in
     true)

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list