sbpf-coverage 0.2.8

Maps SBPF execution traces to source code for test coverage and trace disassembly of Solana programs
Documentation
diff --git a/src/lib.rs b/src/lib.rs
index 88e6f26..8937f0c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -278,14 +278,15 @@ fn process_pcs_path(dwarfs: &[Dwarf], pcs_path: &Path) -> Result<Outcome> {
         GotoNotTaken,
     }
 
-    fn write_branch_lcov(file: &str, line: u32, taken: Branch) {
+    fn write_branch_lcov(file: &str, line: u32, branch_num: u64, taken: Branch) {
+        let next_branch_num = branch_num + 1;
         let content = if taken == Branch::NextNotTaken {
             format!(
                 "
 SF:{file}
 DA:{line},1
-BRDA:{line},0,0,0
-BRDA:{line},0,1,1
+BRDA:{line},0,{branch_num},0
+BRDA:{line},0,{next_branch_num},1
 end_of_record
 "
             )
@@ -294,8 +295,8 @@ end_of_record
                 "
 SF:{file}
 DA:{line},1
-BRDA:{line},0,0,1
-BRDA:{line},0,1,0
+BRDA:{line},0,{branch_num},1
+BRDA:{line},0,{next_branch_num},0
 end_of_record
 "
             )
@@ -319,11 +320,13 @@ end_of_record
 
     for (i, vaddr) in vaddrs.iter().enumerate() {
         let mut indent = 0;
+        let mut branch_num = 0;
         let frames = dwarf.loader.find_frames(*vaddr);
         if let Ok(frames) = frames {
             let mut frames = frames.peekable();
             while let Some(Some(frame)) = frames.next().ok() {
                 indent += 1;
+                branch_num += 2;
                 let outer_frame_details = get_frame_details(&frame);
                 eprintln!(
                             "{}⛳ 0x{:08x}({}) [{:016x}]=> frame 0x{:08x?}#{:?}@{:?}:{:?}:{:?}\n{}VM regs: {:08x?}\n",
@@ -402,7 +405,7 @@ end_of_record
                                             }
                                         }
 
-                                        write_branch_lcov(file, line, branch_not_taken);
+                                        write_branch_lcov(file, line, branch_num, branch_not_taken);
                                     } else if goto_taken == false {
                                         let next_is_taken =
                                             get_frame_details_by_vaddr(&dwarf, next_pc);
@@ -433,7 +436,7 @@ end_of_record
                                                 );
                                             }
                                         }
-                                        write_branch_lcov(file, line, branch_not_taken);
+                                        write_branch_lcov(file, line, branch_num, branch_not_taken);
                                     }
                                 }
                                 _ => {}
@@ -462,7 +465,7 @@ end_of_record
                                 if let (Some(file), Some(line)) =
                                     (outer_frame_details.file_name, outer_frame_details.line_num)
                                 {
-                                    write_branch_lcov(file, line, branch_not_taken);
+                                    write_branch_lcov(file, line, branch_num, branch_not_taken);
                                 }
                             } else if goto_taken == false {
                                 eprintln!(
@@ -487,7 +490,7 @@ end_of_record
                                 if let (Some(file), Some(line)) =
                                     (outer_frame_details.file_name, outer_frame_details.line_num)
                                 {
-                                    write_branch_lcov(file, line, branch_not_taken);
+                                    write_branch_lcov(file, line, branch_num, branch_not_taken);
                                 }
                             }
                         }