diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-22 13:21:54 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-22 14:21:19 -0700 |
commit | 369167ebda362eb0c76081976ae0a48d2d3c1cbd (patch) | |
tree | ac29adc3fffd6604ba2101dac6e328bdacba5fcf /emcc | |
parent | 8f1a7e5546f5b10263c176e507dba8d548161c86 (diff) |
-gLEVEL ; support varying degrees of debuggability
Diffstat (limited to 'emcc')
-rwxr-xr-x | emcc | 76 |
1 files changed, 42 insertions, 34 deletions
@@ -182,16 +182,31 @@ Options that are modified or new in %s include: ). Note that the path must be absolute, not relative. - -g Use debug info. Note that you need this during - the last compilation phase from bitcode to - JavaScript, or else we will remove it by - default in -O1 and above. - In -O0, line numbers wil be shown in the - generated code. In -O1 and above, the optimizer - removes those comments. This flag does however - have the effect of disabling anything that - causes name mangling or minification (closure - or the registerize pass). + -g Use debug info. When compiling to bitcode, + this is the same as in clang and gcc, it + adds debug info to the object files. When + compiling from source to JS or bitcode to JS, + it is equivalent to -g3 (keep code as debuggable + as possible, except for discarding LLVM + debug info, so no C/C++ line numbers; use + -g4 to get line number debugging info in JS). + + -g<level> When compiling from bitcode to JS, we can + keep the code debuggable to different + degrees. Each of these levels builds on the + previous: + + -g0 Make no effort to keep code debuggable. + Will discard LLVM debug info. (default + in -O1+) + -g1 Preserve (do not minify) whitespace + -g2 Preserve function names + -g3 Preserve variable names + -g4 Preserve LLVM debug info (if -g was + used when compiling the C/C++ sources) + and show line number debug comments. + This is the highest level of debuggability. + (default in -O0) --typed-arrays <mode> 0: No typed arrays 1: Parallel typed arrays @@ -303,12 +318,7 @@ Options that are modified or new in %s include: archive, which is given the same name as the output HTML but with suffix .data.compress - --minify <on> 0: Do not minify the generated JavaScript's - whitespace (default in -O0, -O1, or if - -g is used) - 1: Minify the generated JavaScript's - whitespace (default in -O2+, assuming - -g is not used) + --minify 0 Identical to -g1 --split <size> Splits the resulting javascript file into pieces to ease debugging. This option only works if @@ -689,13 +699,13 @@ try: newargs = sys.argv[1:] opt_level = 0 + debug_level = 0 llvm_opts = None llvm_lto = None closure = None js_transform = None pre_js = '' post_js = '' - minify_whitespace = None split_js_file = None preload_files = [] embed_files = [] @@ -703,8 +713,6 @@ try: ignore_dynamic_linking = False shell_path = shared.path_from_root('src', 'shell.html') js_libraries = [] - keep_llvm_debug = False - keep_js_debug = False bind = False jcache = False save_bc = False @@ -769,7 +777,7 @@ try: newargs[i+1] = '' elif newargs[i].startswith('--minify'): check_bad_eq(newargs[i]) - minify_whitespace = int(newargs[i+1]) + debug_level = max(1, debug_level) newargs[i] = '' newargs[i+1] = '' elif newargs[i].startswith('--split'): @@ -777,9 +785,14 @@ try: split_js_file = int(newargs[i+1]) newargs[i] = '' newargs[i+1] = '' - elif newargs[i] == '-g': - keep_llvm_debug = True - keep_js_debug = True + elif newargs[i].startswith('-g'): + requested_level = newargs[i][2:] or '3' + try: + debug_level = int(requested_level) + assert 0 <= debug_level <= 4 + except: + raise Exception('Invalid debug level: ' + newargs[i]) + newargs[i] = '-g' # discard level for clang args elif newargs[i] == '--bind': bind = True newargs[i] = '' @@ -868,8 +881,7 @@ try: if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level] if llvm_lto is None: llvm_lto = opt_level >= 3 - if opt_level <= 0: keep_llvm_debug = keep_js_debug = True # always keep debug in -O0 - if opt_level > 0: keep_llvm_debug = False # JS optimizer wipes out llvm debug info from being visible + if opt_level == 0: debug_level = 4 if closure is None and opt_level == 3: closure = True if DEBUG: start_time = time.time() # done after parsing arguments, which might affect debug state @@ -1019,15 +1031,12 @@ try: logging.warning('ALIASING_FUNCTION_POINTERS is on, function pointer comparisons may be invalid across types') if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2: - keep_llvm_debug = True # must keep debug info to do line-by-line operations + debug_level = 4 # must keep debug info to do line-by-line operations - if (keep_llvm_debug or keep_js_debug) and closure: + if debug_level > 0 and closure: logging.warning('disabling closure because debug info was requested') closure = False - if minify_whitespace is None: - minify_whitespace = opt_level >= 2 and not keep_js_debug - assert shared.LLVM_TARGET in shared.COMPILER_OPTS if shared.LLVM_TARGET == 'i386-pc-linux-gnu': shared.Settings.TARGET_X86 = 1 @@ -1398,7 +1407,7 @@ try: # Optimize, if asked to if not LEAVE_INPUTS_RAW: - link_opts = [] if keep_llvm_debug else ['-strip-debug'] # remove LLVM debug info in -O1+, since the optimizer removes it anyhow + link_opts = [] if debug_level >= 4 else ['-strip-debug'] # remove LLVM debug if we are not asked for it if llvm_opts > 0: if not os.environ.get('EMCC_OPTIMIZE_NORMALLY'): shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts) @@ -1540,11 +1549,10 @@ try: logging.debug('running post-closure post-opts') js_optimizer_queue += ['simplifyExpressionsPost'] - if (not closure or shared.Settings.ASM_JS) and shared.Settings.RELOOP and not keep_js_debug: - # do this if closure is not enabled (it gives similar speedups), and we do not need to keep debug info around + if (not closure or shared.Settings.ASM_JS) and shared.Settings.RELOOP and debug_level < 3: js_optimizer_queue += ['registerize'] - if minify_whitespace: + if debug_level == 0 and opt_level > 0: js_optimizer_queue += ['compress'] if closure and shared.Settings.ASM_JS: |