Skip to content

Commit

Permalink
Handle bad filepaths better
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed May 24, 2024
1 parent c8073eb commit 7a66e0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion decomp2dbg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.9.1"
__version__ = "3.9.2"

try:
from .clients.client import DecompilerClient
Expand Down
29 changes: 18 additions & 11 deletions decomp2dbg/clients/gdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import tempfile
import hashlib
from pathlib import Path

from elftools.elf.elffile import ELFFile

Expand Down Expand Up @@ -191,30 +192,36 @@ def pid() -> int:
def get_filepath() -> Optional[str]:
"""Return the local absolute path of the file currently debugged."""
filename = gdb.current_progspace().filename

filepath = None
if is_remote_debug():
# if no filename specified, try downloading target from /proc
if filename is None:
pid_ = pid()
if pid_ > 0:
return download_file(f"/proc/{pid_:d}/exe", use_cache=True)
return None

filepath = download_file(f"/proc/{pid_:d}/exe", use_cache=True)
# if target is remote file, download
elif filename.startswith("target:"):
fname = filename[len("target:") :]
return download_file(fname, use_cache=True, local_name=fname)
filepath = download_file(fname, use_cache=True, local_name=fname)

elif filename.startswith(".gnu_debugdata for target:"):
fname = filename[len(".gnu_debugdata for target:") :]
return download_file(fname, use_cache=True, local_name=fname)

return filename
filepath = download_file(fname, use_cache=True, local_name=fname)
else:
filepath = filename
else:
if filename is not None:
return filename
# inferior probably did not have name, extract cmdline from info proc
return get_path_from_info_proc()
filepath = filename
else:
# inferior probably did not have name, extract cmdline from info proc
filepath = get_path_from_info_proc()

try:
filepath = Path(filepath).resolve()
except Exception:
err(f"Failed to resolve path in get_filepath(): {filepath}, this error is fatal.")

return str(filepath) if filepath else None


def get_path_from_info_proc() -> Optional[str]:
Expand Down

0 comments on commit 7a66e0f

Please sign in to comment.