]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Simplify DAP make_source callers
authorTom Tromey <tromey@adacore.com>
Wed, 24 Apr 2024 15:53:55 +0000 (09:53 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 10 May 2024 18:09:32 +0000 (12:09 -0600)
A couple callers of make_source call basename by hand.  Rather than
add another caller like this, I thought it would be better to put this
ability into make_source itself.

gdb/python/lib/gdb/dap/breakpoint.py
gdb/python/lib/gdb/dap/bt.py
gdb/python/lib/gdb/dap/sources.py

index 1da754e4ddc2551bf0766c8b209b88b3f9421399..e60265b2f69d83c8e4a9d33f2286a947d2d77884 100644 (file)
@@ -13,7 +13,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
 import re
 from contextlib import contextmanager
 
@@ -116,7 +115,7 @@ def _breakpoint_descriptor(bp):
 
             result.update(
                 {
-                    "source": make_source(filename, os.path.basename(filename)),
+                    "source": make_source(filename),
                     "line": line,
                 }
             )
index e0c2e2a1751d6e8e05e2ab13af15d72d2a4630c7..668bcc7ce238d8c4e4a9e2d0c1323c74b12af227 100644 (file)
@@ -13,8 +13,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
-
 # This is deprecated in 3.9, but required in older versions.
 from typing import Optional
 
@@ -98,7 +96,7 @@ def _backtrace(thread_id, levels, startFrame, stack_format):
                     name += ", module " + objfile.username
             filename = current_frame.filename()
             if filename is not None:
-                newframe["source"] = make_source(filename, os.path.basename(filename))
+                newframe["source"] = make_source(filename)
             newframe["name"] = name
             frames.append(newframe)
         # Note that we do not calculate totalFrames here.  Its absence
index ee3464db6795ddf688118dabf3091152ff3dc368..ad0c913c8c1fd3ebb731f5c239dec01c6d6f1c72 100644 (file)
@@ -32,16 +32,20 @@ _id_map = {}
 
 
 @in_gdb_thread
-def make_source(fullname, filename):
+def make_source(fullname, filename=None):
     """Return the Source for a given file name.
 
     FULLNAME is the full name.  This is used as the key.
-    FILENAME is the base name.
+    FILENAME is the base name; if None (the default), then it is
+    computed from FULLNAME.
     """
     global _source_map
     if fullname in _source_map:
         result = _source_map[fullname]
     else:
+        if filename is None:
+            filename = os.path.basename(fullname)
+
         result = {
             "name": filename,
             "path": fullname,