extractSourceFilePath extracts the package/file:line from a PC
(pc uintptr)
| 136 | |
| 137 | // extractSourceFilePath extracts the package/file:line from a PC |
| 138 | func extractSourceFilePath(pc uintptr) string { |
| 139 | if pc == 0 { |
| 140 | return "" |
| 141 | } |
| 142 | |
| 143 | fs := runtime.CallersFrames([]uintptr{pc}) |
| 144 | f, _ := fs.Next() |
| 145 | if f.File == "" { |
| 146 | return "" |
| 147 | } |
| 148 | |
| 149 | // Extract just filename, not full path |
| 150 | idx := strings.LastIndexByte(f.File, '/') |
| 151 | if idx == -1 { |
| 152 | return fmt.Sprintf("%s:%d", f.File, f.Line) |
| 153 | } |
| 154 | |
| 155 | // Get package/file:line |
| 156 | idx2 := strings.LastIndexByte(f.File[:idx], '/') |
| 157 | if idx2 == -1 { |
| 158 | return fmt.Sprintf("%s:%d", f.File[idx+1:], f.Line) |
| 159 | } |
| 160 | |
| 161 | return fmt.Sprintf("%s:%d", f.File[idx2+1:], f.Line) |
| 162 | } |