]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #23074 - michaelwoerister:constants-debug-locs, r=alexcrichton
authorManish Goregaokar <manishsmail@gmail.com>
Fri, 6 Mar 2015 03:31:23 +0000 (09:01 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Fri, 6 Mar 2015 03:31:23 +0000 (09:01 +0530)
 With this PR in-place constants are handled correctly with respect to debug location assignment.
The PR also adds an (unrelated) test case for debug locations in `extern \"C\"` functions.

Fixes #22432

1  2 
src/librustc_trans/trans/debuginfo.rs

index 142262a25bd437982e5f299ec93ac7c240e43d36,ab35a33cfdd5bf56097a149a6df14c5111c80287..95c39270cc6d9f18c56dd2e98145009c39f74ae3
@@@ -206,12 -206,10 +206,12 @@@ use middle::pat_util
  use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
  use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
  use util::ppaux;
 +use util::common::path2cstr;
  
  use libc::{c_uint, c_longlong};
 -use std::ffi::CString;
  use std::cell::{Cell, RefCell};
 +use std::ffi::CString;
 +use std::path::Path;
  use std::ptr;
  use std::rc::{Rc, Weak};
  use syntax::util::interner::Interner;
@@@ -697,6 -695,7 +697,7 @@@ struct FunctionDebugContextData 
      fn_metadata: DISubprogram,
      argument_counter: Cell<uint>,
      source_locations_enabled: Cell<bool>,
+     source_location_override: Cell<bool>,
  }
  
  enum VariableAccess<'a> {
@@@ -1176,6 -1175,12 +1177,12 @@@ pub fn set_source_location(fcx: &Functi
              return;
          }
          FunctionDebugContext::RegularContext(box ref function_debug_context) => {
+             if function_debug_context.source_location_override.get() {
+                 // Just ignore any attempts to set a new debug location while
+                 // the override is active.
+                 return;
+             }
              let cx = fcx.ccx;
  
              debug!("set_source_location: {}", cx.sess().codemap().span_to_string(span));
      }
  }
  
+ /// This function makes sure that all debug locations emitted while executing
+ /// `wrapped_function` are set to the given `debug_loc`.
+ pub fn with_source_location_override<F, R>(fcx: &FunctionContext,
+                                            debug_loc: DebugLoc,
+                                            wrapped_function: F) -> R
+     where F: FnOnce() -> R
+ {
+     match fcx.debug_context {
+         FunctionDebugContext::DebugInfoDisabled => {
+             wrapped_function()
+         }
+         FunctionDebugContext::FunctionWithoutDebugInfo => {
+             set_debug_location(fcx.ccx, UnknownLocation);
+             wrapped_function()
+         }
+         FunctionDebugContext::RegularContext(box ref function_debug_context) => {
+             if function_debug_context.source_location_override.get() {
+                 wrapped_function()
+             } else {
+                 debug_loc.apply(fcx);
+                 function_debug_context.source_location_override.set(true);
+                 let result = wrapped_function();
+                 function_debug_context.source_location_override.set(false);
+                 result
+             }
+         }
+     }
+ }
  /// Clears the current debug location.
  ///
  /// Instructions generated hereafter won't be assigned a source location.
@@@ -1414,6 -1448,7 +1450,7 @@@ pub fn create_function_debug_context<'a
          fn_metadata: fn_metadata,
          argument_counter: Cell::new(1),
          source_locations_enabled: Cell::new(false),
+         source_location_override: Cell::new(false),
      };
  
  
@@@ -1590,13 -1625,20 +1627,13 @@@ fn compile_unit_metadata(cx: &CrateCont
                  cx.sess().warn("debuginfo: Invalid path to crate's local root source file!");
                  fallback_path(cx)
              } else {
 -                match abs_path.path_relative_from(work_dir) {
 +                match abs_path.relative_from(work_dir) {
                      Some(ref p) if p.is_relative() => {
 -                        // prepend "./" if necessary
 -                        let dotdot = b"..";
 -                        let prefix: &[u8] = &[dotdot[0], ::std::old_path::SEP_BYTE];
 -                        let mut path_bytes = p.as_vec().to_vec();
 -
 -                        if &path_bytes[..2] != prefix &&
 -                           &path_bytes[..2] != dotdot {
 -                            path_bytes.insert(0, prefix[0]);
 -                            path_bytes.insert(1, prefix[1]);
 +                        if p.starts_with(Path::new("./")) {
 +                            path2cstr(p)
 +                        } else {
 +                            path2cstr(&Path::new(".").join(p))
                          }
 -
 -                        CString::new(path_bytes).unwrap()
                      }
                      _ => fallback_path(cx)
                  }
                             (option_env!("CFG_VERSION")).expect("CFG_VERSION"));
  
      let compile_unit_name = compile_unit_name.as_ptr();
 -    let work_dir = CString::new(work_dir.as_vec()).unwrap();
 +    let work_dir = path2cstr(&work_dir);
      let producer = CString::new(producer).unwrap();
      let flags = "\0";
      let split_name = "\0";
@@@ -1711,7 -1753,7 +1748,7 @@@ fn file_metadata(cx: &CrateContext, ful
      debug!("file_metadata: {}", full_path);
  
      // FIXME (#9639): This needs to handle non-utf8 paths
 -    let work_dir = cx.sess().working_dir.as_str().unwrap();
 +    let work_dir = cx.sess().working_dir.to_str().unwrap();
      let file_name =
          if full_path.starts_with(work_dir) {
              &full_path[work_dir.len() + 1..full_path.len()]