API: improved `GDBFrame >> #file`
...to try to resolve relative paths using source directories.
GDB should do that but somethimes it gets confused so try
ourselves in that case.
--- a/GDBFrame.st Fri Mar 09 12:38:44 2018 +0000
+++ b/GDBFrame.st Tue Mar 27 08:50:56 2018 +0100
@@ -74,20 +74,58 @@
!
file
- "Return filename containing frame's function source."
- ^ fullname notNil ifTrue:[ fullname ] ifFalse:[ file ]
+ "Return filename (path) containing frame's function source."
+
+ | f |
+
+ "/ GDB/MI provides two paths, `file` and `fullname`.
+ "/
+ "/ However, sometimes GDB gets confused and does not return
+ "/ anything directly useful, especially when debug info contains
+ "/ relative paths with multiple segments.
+ "/
+ "/ As a courtesy to the user, in that case try to resolve full
+ "/ path here too. Hence the code below.
+ "/
+ "/ To avoid re-resolving of file each time this method is called,
+ "/ cache resolved Filename in `fullname` instvar.
+
+ fullname isFilename ifTrue:[
+ "/ Already resolved by the code below
+ ^ fullname pathName
+ ].
- "Modified: / 11-06-2017 / 20:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ f := fullname ? file.
+ f isNil ifTrue:[ ^ nil ].
+ f := f copyReplaceAll: $/ with: Filename separator.
+ f := f asFilename.
+
+ "/ check, if GDB returned correctly resolved filename...
+ f exists ifTrue:[
+ fullname := f.
+ ^ fullname pathName
+ ].
+
+ "/ ...if not, try to look it up in source directories...
+ self debugger directories do:[:d |
+ f := d asFilename / (fullname ? file).
+ f exists ifTrue:[
+ fullname := f.
+ ^ fullname pathName.
+ ].
+ ].
+
+ "/ ...if not found there...
+ ^ nil
+
+ "Modified: / 12-03-2018 / 10:32:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-03-2018 / 16:52:52 / jv"
!
from
^ from
!
-fullname
- ^ fullname
-!
-
func
^ func
!