11
11
// See doc.rs for documentation.
12
12
mod doc;
13
13
14
+ pub mod gdb;
15
+
14
16
use self :: VariableAccess :: * ;
15
17
use self :: VariableKind :: * ;
16
18
use self :: MemberOffset :: * ;
@@ -25,9 +27,8 @@ use llvm::debuginfo::*;
25
27
use metadata:: csearch;
26
28
use middle:: subst:: { self , Substs } ;
27
29
use trans:: { self , adt, machine, type_of} ;
28
- use trans:: common:: { self , NodeIdAndSpan , CrateContext , FunctionContext , Block , C_bytes ,
30
+ use trans:: common:: { self , NodeIdAndSpan , CrateContext , FunctionContext , Block ,
29
31
NormalizingClosureTyper } ;
30
- use trans:: declare;
31
32
use trans:: _match:: { BindingInfo , TrByCopy , TrByMove , TrByRef } ;
32
33
use trans:: monomorphize;
33
34
use trans:: type_:: Type ;
@@ -46,7 +47,7 @@ use std::ptr;
46
47
use std:: rc:: { Rc , Weak } ;
47
48
use syntax:: util:: interner:: Interner ;
48
49
use syntax:: codemap:: { Span , Pos } ;
49
- use syntax:: { ast, codemap, ast_util, ast_map, attr } ;
50
+ use syntax:: { ast, codemap, ast_util, ast_map} ;
50
51
use syntax:: parse:: token:: { self , special_idents} ;
51
52
52
53
const DW_LANG_RUST : c_uint = 0x9000 ;
@@ -552,12 +553,12 @@ pub fn finalize(cx: &CrateContext) {
552
553
debug ! ( "finalize" ) ;
553
554
let _ = compile_unit_metadata ( cx) ;
554
555
555
- if needs_gdb_debug_scripts_section ( cx) {
556
+ if gdb :: needs_gdb_debug_scripts_section ( cx) {
556
557
// Add a .debug_gdb_scripts section to this compile-unit. This will
557
558
// cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
558
559
// which activates the Rust pretty printers for binary this section is
559
560
// contained in.
560
- get_or_insert_gdb_debug_scripts_section_global ( cx) ;
561
+ gdb :: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
561
562
}
562
563
563
564
unsafe {
@@ -3866,77 +3867,3 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTree
3866
3867
}
3867
3868
} )
3868
3869
}
3869
-
3870
-
3871
- //=-----------------------------------------------------------------------------
3872
- // .debug_gdb_scripts binary section
3873
- //=-----------------------------------------------------------------------------
3874
-
3875
- /// Inserts a side-effect free instruction sequence that makes sure that the
3876
- /// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
3877
- pub fn insert_reference_to_gdb_debug_scripts_section_global ( ccx : & CrateContext ) {
3878
- if needs_gdb_debug_scripts_section ( ccx) {
3879
- let empty = CString :: new ( "" ) . unwrap ( ) ;
3880
- let gdb_debug_scripts_section_global =
3881
- get_or_insert_gdb_debug_scripts_section_global ( ccx) ;
3882
- unsafe {
3883
- let volative_load_instruction =
3884
- llvm:: LLVMBuildLoad ( ccx. raw_builder ( ) ,
3885
- gdb_debug_scripts_section_global,
3886
- empty. as_ptr ( ) ) ;
3887
- llvm:: LLVMSetVolatile ( volative_load_instruction, llvm:: True ) ;
3888
- }
3889
- }
3890
- }
3891
-
3892
- /// Allocates the global variable responsible for the .debug_gdb_scripts binary
3893
- /// section.
3894
- fn get_or_insert_gdb_debug_scripts_section_global ( ccx : & CrateContext )
3895
- -> llvm:: ValueRef {
3896
- let section_var_name = "__rustc_debug_gdb_scripts_section__" ;
3897
-
3898
- let section_var = unsafe {
3899
- llvm:: LLVMGetNamedGlobal ( ccx. llmod ( ) ,
3900
- section_var_name. as_ptr ( ) as * const _ )
3901
- } ;
3902
-
3903
- if section_var == ptr:: null_mut ( ) {
3904
- let section_name = b".debug_gdb_scripts\0 " ;
3905
- let section_contents = b"\x01 gdb_load_rust_pretty_printers.py\0 " ;
3906
-
3907
- unsafe {
3908
- let llvm_type = Type :: array ( & Type :: i8 ( ccx) ,
3909
- section_contents. len ( ) as u64 ) ;
3910
-
3911
- let section_var = declare:: define_global ( ccx, section_var_name,
3912
- llvm_type) . unwrap_or_else ( ||{
3913
- ccx. sess ( ) . bug ( & format ! ( "symbol `{}` is already defined" , section_var_name) )
3914
- } ) ;
3915
- llvm:: LLVMSetSection ( section_var, section_name. as_ptr ( ) as * const _ ) ;
3916
- llvm:: LLVMSetInitializer ( section_var, C_bytes ( ccx, section_contents) ) ;
3917
- llvm:: LLVMSetGlobalConstant ( section_var, llvm:: True ) ;
3918
- llvm:: LLVMSetUnnamedAddr ( section_var, llvm:: True ) ;
3919
- llvm:: SetLinkage ( section_var, llvm:: Linkage :: LinkOnceODRLinkage ) ;
3920
- // This should make sure that the whole section is not larger than
3921
- // the string it contains. Otherwise we get a warning from GDB.
3922
- llvm:: LLVMSetAlignment ( section_var, 1 ) ;
3923
- section_var
3924
- }
3925
- } else {
3926
- section_var
3927
- }
3928
- }
3929
-
3930
- fn needs_gdb_debug_scripts_section ( ccx : & CrateContext ) -> bool {
3931
- let omit_gdb_pretty_printer_section =
3932
- attr:: contains_name ( & ccx. tcx ( )
3933
- . map
3934
- . krate ( )
3935
- . attrs ,
3936
- "omit_gdb_pretty_printer_section" ) ;
3937
-
3938
- !omit_gdb_pretty_printer_section &&
3939
- !ccx. sess ( ) . target . target . options . is_like_osx &&
3940
- !ccx. sess ( ) . target . target . options . is_like_windows &&
3941
- ccx. sess ( ) . opts . debuginfo != NoDebugInfo
3942
- }
0 commit comments