diff options
author | Tom Tromey <tromey@adacore.com> | 2024-04-24 09:53:55 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-05-10 12:09:32 -0600 |
commit | 4b09134a09ea6663850091c6a8da614cf3902fe1 (patch) | |
tree | 8306076816f95a49df56533b10f0ee6cfedddcd4 | |
parent | 674dea05e3bf2a4b68820adfa4f9e9510b4c1c8c (diff) | |
download | gdb-4b09134a09ea6663850091c6a8da614cf3902fe1.zip gdb-4b09134a09ea6663850091c6a8da614cf3902fe1.tar.gz gdb-4b09134a09ea6663850091c6a8da614cf3902fe1.tar.bz2 |
Simplify DAP make_source callers
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.
-rw-r--r-- | gdb/python/lib/gdb/dap/breakpoint.py | 3 | ||||
-rw-r--r-- | gdb/python/lib/gdb/dap/bt.py | 4 | ||||
-rw-r--r-- | 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 1da754e..e60265b 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 e0c2e2a..668bcc7 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 ee3464d..ad0c913 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, |