@@ -20,7 +20,7 @@ use crate::{
2020
2121use binaryninja:: {
2222 binary_view:: { BinaryView , BinaryViewBase } ,
23- debuginfo:: { DebugFunctionInfo , DebugInfo } ,
23+ debuginfo:: { DebugFunctionInfo , DebugInfo , DebugSourceLineInfo } ,
2424 platform:: Platform ,
2525 rc:: * ,
2626 symbol:: SymbolType ,
@@ -54,6 +54,14 @@ pub(crate) struct FunctionInfoBuilder {
5454 pub ( crate ) frame_base : Option < FrameBase > ,
5555}
5656
57+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
58+ pub ( crate ) struct SourceLineInfoBuilder {
59+ pub ( crate ) source_file : String ,
60+ pub ( crate ) address : u64 ,
61+ pub ( crate ) line : u32 ,
62+ pub ( crate ) column : u32 ,
63+ }
64+
5765impl FunctionInfoBuilder {
5866 pub ( crate ) fn update (
5967 & mut self ,
@@ -217,6 +225,7 @@ pub(crate) struct DebugInfoBuilder {
217225 full_function_name_indices : HashMap < String , usize > ,
218226 types : IndexMap < TypeUID , DebugType > ,
219227 data_variables : HashMap < u64 , ( Option < String > , TypeUID ) > ,
228+ source_lines : Vec < SourceLineInfoBuilder > ,
220229 range_data_offsets : iset:: IntervalMap < u64 , i64 > ,
221230}
222231
@@ -228,6 +237,7 @@ impl DebugInfoBuilder {
228237 full_function_name_indices : HashMap :: new ( ) ,
229238 types : IndexMap :: new ( ) ,
230239 data_variables : HashMap :: new ( ) ,
240+ source_lines : vec ! [ ] ,
231241 range_data_offsets : iset:: IntervalMap :: new ( ) ,
232242 }
233243 }
@@ -358,6 +368,21 @@ impl DebugInfoBuilder {
358368 & self . functions
359369 }
360370
371+ pub ( crate ) fn insert_source_line (
372+ & mut self ,
373+ source_file : String ,
374+ address : u64 ,
375+ line : u32 ,
376+ column : u32 ,
377+ ) {
378+ self . source_lines . push ( SourceLineInfoBuilder {
379+ source_file,
380+ address,
381+ line,
382+ column,
383+ } ) ;
384+ }
385+
361386 #[ allow( dead_code) ]
362387 pub ( crate ) fn types ( & self ) -> Values < ' _ , TypeUID , DebugType > {
363388 self . types . values ( )
@@ -706,6 +731,17 @@ impl DebugInfoBuilder {
706731 }
707732 }
708733
734+ fn commit_source_lines ( & self , debug_info : & mut DebugInfo ) {
735+ for source_line in & self . source_lines {
736+ debug_info. add_source_line ( & DebugSourceLineInfo :: new (
737+ source_line. source_file . clone ( ) ,
738+ source_line. address ,
739+ source_line. line ,
740+ source_line. column ,
741+ ) ) ;
742+ }
743+ }
744+
709745 pub ( crate ) fn post_process ( & mut self , bv : & BinaryView , _debug_info : & mut DebugInfo ) -> & Self {
710746 // When originally resolving names, we need to check:
711747 // If there's already a name from binja that's "more correct" than what we found (has more namespaces)
@@ -762,12 +798,20 @@ impl DebugInfoBuilder {
762798 }
763799 }
764800
801+ let ( diff, overflowed) = bv. start ( ) . overflowing_sub ( bv. original_image_base ( ) ) ;
802+ if !overflowed {
803+ for source_line in & mut self . source_lines {
804+ source_line. address = source_line. address . overflowing_add ( diff) . 0 ;
805+ }
806+ }
807+
765808 self
766809 }
767810
768811 pub ( crate ) fn commit_info ( & self , debug_info : & mut DebugInfo ) {
769812 self . commit_types ( debug_info) ;
770813 self . commit_data_variables ( debug_info) ;
771814 self . commit_functions ( debug_info) ;
815+ self . commit_source_lines ( debug_info) ;
772816 }
773817}
0 commit comments