public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/3] Simplify DAP make_source callers
Date: Thu, 25 Apr 2024 12:09:57 -0600	[thread overview]
Message-ID: <20240425181032.80275-2-tromey@adacore.com> (raw)
In-Reply-To: <20240425181032.80275-1-tromey@adacore.com>

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 | 3 +--
 gdb/python/lib/gdb/dap/bt.py         | 4 +---
 gdb/python/lib/gdb/dap/sources.py    | 8 ++++++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index b2e74277ebd..1380f7decd4 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -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,
                 }
             )
diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py
index e0c2e2a1751..668bcc7ce23 100644
--- a/gdb/python/lib/gdb/dap/bt.py
+++ b/gdb/python/lib/gdb/dap/bt.py
@@ -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
diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py
index ee3464db679..ad0c913c8c1 100644
--- a/gdb/python/lib/gdb/dap/sources.py
+++ b/gdb/python/lib/gdb/dap/sources.py
@@ -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,
-- 
2.44.0


  reply	other threads:[~2024-04-25 18:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 18:09 [PATCH 0/3] Add more info to DAP disassemble response Tom Tromey
2024-04-25 18:09 ` Tom Tromey [this message]
2024-04-25 18:09 ` [PATCH 2/3] Implement tp_richcompare for gdb.Block Tom Tromey
2024-04-25 18:09 ` [PATCH 3/3] Add symbol, line, and location to DAP disassemble result Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240425181032.80275-2-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).