Skip to content

Commit

Permalink
Reset source dirs on load/attach
Browse files Browse the repository at this point in the history
  • Loading branch information
AlEscher committed Jul 7, 2023
1 parent d97b06c commit bcc5fb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 0 additions & 2 deletions gui/TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-Wipe source code dirs when attaching/loading file (otherwise unpredictable vuln.c)

Test:
-Shell spawn / multiple threads
-Docker setup + attach
Expand Down
6 changes: 6 additions & 0 deletions gui/pwndbg_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def select_file(self):
# Before loading the file we want to set the correct tty for the inferior
self.set_gdb_tty.emit(self.inferior_handler.tty)
self.set_gdb_file_target_signal.emit([file_name])
# Reset dir so that GDB doesn't get confused when we load multiple programs with the same name / source
# file name
self.set_gdb_source_dir_signal.emit([""])
# GDB only looks for source files in the cwd, so we additionally add the directory of the executable
self.set_gdb_source_dir_signal.emit([str(Path(file_name).parent)])
self.main_context.inferior_attached = False
Expand Down Expand Up @@ -341,6 +344,9 @@ def attach_to_pid(self, pid: int):
Attach to the given (valid) PID. Also sets the search directories and updates the contexts after attaching
:param pid: The PID of a running program
"""
# Reset dir so that GDB doesn't get confused when we load multiple programs with the same name / source
# file name
self.set_gdb_source_dir_signal.emit([""])
# Add the directory of the executable as a search directory for source files for GDB
process_path = Path(psutil.Process(pid).exe()).parent.resolve()
self.set_gdb_source_dir_signal.emit([str(process_path)])
Expand Down

0 comments on commit bcc5fb0

Please sign in to comment.